HaishinKit.swift icon indicating copy to clipboard operation
HaishinKit.swift copied to clipboard

SRT no video track

Open MishaMgla opened this issue 8 months ago • 0 comments

Describe the bug

I am having trouble to publish stream using SRT. I am using SRS as media server, I can see that stream started, but no video track publishing. Any clues how to resolve it? I believe SRS working properly and I have valid srt url, as I can make it work with OBS.

To Reproduce

Publish SRT stream. Code:

let srtConnection = SRTConnection()
let srtStream = SRTStream(connection: srtConnection)
srtStream?.sessionPreset = AVCaptureSession.Preset.hd1920x1080
        srtStream?.videoSettings = .init(
            videoSize: .init(width: 1080, height: 1920),
            bitRate: currentBitrate * 1000,
            profileLevel: kVTProfileLevel_H264_High_4_1 as String,
            scalingMode: .trim,
            bitRateMode: .constant,
            maxKeyFrameIntervalDuration: 2,
            allowFrameReordering: false,
            isHardwareEncoderEnabled: true
        )
srtStream?.attachCamera(AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back), track: 0)
srtConnection.addObserver(self, forKeyPath: "connected", options: .new, context: nil)
srtConnection?.open(URL(string: "srt://*********:10080?streamid=#!::r=live/livestream,m=publish"))

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if let connection = object as? SRTConnection {
            if keyPath == "connected" {
                if connection.connected {
                    print("SRT connection established")
                    srtStream?.publish()
                } else {
                    print("SRT connection not established")
                }
            }
        }
    }

Expected behavior

Validate that stream is published to SRS server

Version

1.8.0

Smartphone info.

No response

Additional context

Also, I cant make it work with SRT example in the readme, so I used SRTConnection.open() to establish connection and observer for connected state (as if I publish stream before the connection established, app fails with 'Socket broken' error). Previously I published stream with RTMP and it worked.

Screenshots

SRS status image

Relevant log output

No response

MishaMgla avatar Jun 25 '24 17:06 MishaMgla