shogo4405 / SRTHaishinKit.swift

Camera and Microphone streaming library via SRT for iOS, macOS.
BSD 3-Clause "New" or "Revised" License
70 stars 25 forks source link

Connecting to srt-live-server v1.4.x or ffplay endpoint fails/disconnect #13

Closed mazz closed 2 years ago

mazz commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

When using the Example iOS app on a physical iPhone 8(14.4), connecting to srt-live-server results in a socket connection but immediate disconnect.

To Reproduce Steps to reproduce the behavior:

  1. run srt-live-server locally(on ZeroTier VPN) on mac with this config:
srt {                #SRT
    worker_threads  1;
    worker_connections 300 ;

    log_file logs/error.log ; 
    log_level info;

    #stat_post_url http://192.168.31.106:8001/sls/stat;
    #stat_post_interval  5;#s

    record_hls_path_prefix /tmp/mov/sls; 
    #vod  file name: /tmp/mov/sls/$listen/$domain_publisher/$app_publisher/$stream_name/vod.m3u8

    server {
        listen 3000; 
        latency 200; #ms

        domain_player output;
        domain_publisher input;
        backlog 100; #accept connections at the same time
        idle_streams_timeout 10;#s -1: unlimited
        #on_event_url http://192.168.31.106:8000/sls/on_event; #?method=on_connect|on_close&role_name=&srt_url=%s
        app {
            app_player live ;           
            app_publisher live ; 

            record_hls off;#on, off 
            record_hls_segment_duration 10; #unit s

            #relay {
            #    type pull;
            #    mode loop;#loop; hash;
            #    reconnect_interval 10;
            #    idle_streams_timeout -1;#s -1: unlimited
            #    upstreams 127.0.0.1:9090?streamid=live.sls.com/live 192.168.1.100:8080/?streamid=live.test.com/live;
            #}
            #relay {
            #    type push;
            #    mode all; #all; hash
            #    reconnect_interval 10;
            #    idle_streams_timeout 10;#s -1: unlimited
            #    upstreams 192.168.31.106:8080?streamid=uplive.sls.com/live ;
            #}          
        }
    }
}
  1. run Example iOS app with this connection string:
    var url: String = "srt://172.27.125.195:3000?streamid=input/live/iphone8"
  1. log from srt-live-server
2021-05-18 19:36:31:764 SLS INFO: [0x7ff94480bc00]CSLSSrt::libsrt_accept ok, new sock=652293637, 172.27.23.118:50589.
2021-05-18 19:36:31:764 SLS INFO: [0x7ff943d29000]CSLSListener::handler, new client[172.27.23.118:50589], fd=652293637.
2021-05-18 19:36:31:764 SLS INFO: [0x7ff943d29000]CSLSListener::handler, [172.27.23.118:50589], sid 'input/live/iphone8'
2021-05-18 19:36:31:764 SLS INFO: [0x7ff943d29000]CSLSListener::handler, new pub=0x7ff943da4000, key_stream_name=input/live/iphone8.
2021-05-18 19:36:31:764 SLS INFO: [0x7ff943e04768]CSLSMapData::add ok, key='input/live/iphone8'.
2021-05-18 19:36:31:764 SLS INFO: [0x7ff943e04878]CSLSMapPublisher::set_push_2_pushlisher, ok, publisher=0x7ff943da4000, app_streamname=input/live/iphone8, m_map_push_2_pushlisher.size()=1.
2021-05-18 19:36:31:764 SLS INFO: [0x7ff943d29000]CSLSListener::handler, new publisher[172.27.23.118:50589], key_stream_name=input/live/iphone8.
2021-05-18 19:36:31:764 SLS INFO: [0x7ff943e04b38]CSLSMapRelay::add_relay_manager, no relay conf info, app_uplive=input/live, stream_name=iphone8.
2021-05-18 19:36:31:764 SLS INFO: [0x7ff943d29000]CSLSListener::handler, m_map_pusher->add_relay_manager failed, new role[172.27.23.118:50589], key_stream_name=input/live/iphone8.
2021-05-18 19:36:31:764 SLS INFO: [0x7ff943da4000]CSLSRole::add_to_epoll, publisher, sock=652293637, m_is_write=0, ret=0.
2021-05-18 19:36:31:764 SLS INFO: [0x7ff94401ca00]CSLSGroup::check_new_role, worker_number=0, publisher=0x7ff943da4000, add_to_epoll fd=652293637, role_map.size=2.
2021-05-18 19:36:31:775 SLS INFO: [0x7ff94480bc00]CSLSSrt::libsrt_accept ok, new sock=652293636, 172.27.23.118:53705.
2021-05-18 19:36:31:775 SLS INFO: [0x7ff943d29000]CSLSListener::handler, new client[172.27.23.118:53705], fd=652293636.
2021-05-18 19:36:31:775 SLS INFO: [0x7ff943d29000]CSLSListener::handler, [172.27.23.118:53705], sid 'input/live/iphone8'
2021-05-18 19:36:31:775 SLS ERROR: [0x7ff943d29000]CSLSListener::handler, refused, new role[172.27.23.118:53705], stream='input/live/iphone8',but publisher=0x7ff943da4000 is not NULL.
2021-05-18 19:36:31:775 SLS INFO: [0x7ff944812a00]CSLSSrt::libsrt_close, fd=652293636.
19:36:35.494052/T0x70000bdc9000!W:SRT.br: @652293637:RCV-DROPPED 1 packet(s), packet seqno %1140470064 delayed for 4.877 ms
2021-05-18 19:36:47:031 SLS INFO: [0x7ff943da4000]CSLSRole::get_state, check_idle_streams_duration is true, cur m_state=1, m_idle_streams_timeout=10s, call invalid_srt.
2021-05-18 19:36:47:031 SLS INFO: [0x7ff943da4000]CSLSRole::invalid_srt, close sock=652293637, m_state=2.
2021-05-18 19:36:47:031 SLS INFO: [0x7ff94680e200]CSLSSrt::libsrt_close, fd=652293637.
2021-05-18 19:36:47:031 SLS INFO: [0x7ff94401ca00]CSLSGroup::check_invalid_sock, worker_number=0, publisher=0x7ff943da4000, invalid sock=0, state=2, role_map.size=2.
2021-05-18 19:36:47:031 SLS INFO: [0x7ff943e04768]CSLSMapData::remove, key='input/live/iphone8' delete array_data=0x7ff945105270.
2021-05-18 19:36:47:031 SLS INFO: [0x7ff943da4000]CSLSPublisher::uninit, removed publisher from m_map_data, ret=0.
2021-05-18 19:36:47:031 SLS INFO: [0x7ff943e04878]CSLSMapPublisher::remove, publisher=0x7ff943da4000, live_key=input/live/iphone8.
2021-05-18 19:36:47:031 SLS INFO: [0x7ff943da4000]CSLSPublisher::uninit, removed publisher from m_map_publisher, ret=0.
2021-05-18 19:36:47:031 SLS INFO: [0x7ff94401ca00]CSLSGroup::check_invalid_sock, worker_number=0, publisher=0x7ff943da4000, delete.
  1. log from Xcode console(12.4):
2021-05-18 19:35:27.022439-0400 Example iOS[6443:803303] Could not load the "first" image referenced from a nib in the bundle with identifier "com.haishinkit.srt.SRTHaishinKit"
2021-05-18 19:35:27.023813-0400 Example iOS[6443:803303] Could not load the "second" image referenced from a nib in the bundle with identifier "com.haishinkit.srt.SRTHaishinKit"
2021-05-18 19:35:27.134315-0400 Example iOS[6443:803303] Metal API Validation Enabled
2021-18-05 19:35:27.175 [Warn] [com.haishinkit.HaishinKit] [VideoIOComponent.swift:163] continuousAutofocus > focusMode(2) is not supported
2021-18-05 19:35:27.176 [Warn] [com.haishinkit.HaishinKit] [VideoIOComponent.swift:222] continuousExposure > exposureMode(2) is not supported
2021-18-05 19:35:36.257 [Info] [com.haishinkit.HaishinKit] [VideoIOComponent.swift:96] fps > (fps: 30.0, duration: __C.CMTime(value: 100, timescale: 3000, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0))
2021-18-05 19:36:31.551 [Info] [com.haishinkit.SRTHaishinKit] [SRTSocket.swift:42] status > SRT Socket Connected
2021-18-05 19:36:31.559 [Info] [com.haishinkit.SRTHaishinKit] [SRTSocket.swift:42] status > SRT Socket Connected
2021-18-05 19:36:31.570 [Info] [com.haishinkit.HaishinKit] [AudioCodec.swift:94] inSourceFormat > AudioStreamBasicDescription(mSampleRate: 44100.0, mFormatID: 1819304813, mFormatFlags: 12, mBytesPerPacket: 2, mFramesPerPacket: 1, mBytesPerFrame: 2, mChannelsPerFrame: 1, mBitsPerChannel: 16, mReserved: 0)
2021-18-05 19:36:31.593 [Info] [com.haishinkit.HaishinKit] [AudioCodec.swift:81] formatDescription > Optional(<CMAudioFormatDescription 0x281550500 [0x1f7fc9b20]> {
    mediaType:'soun' 
    mediaSubType:'aac ' 
    mediaSpecific: {
        ASBD: {
            mSampleRate: 44100.000000 
            mFormatID: 'aac ' 
            mFormatFlags: 0x2 
            mBytesPerPacket: 0 
            mFramesPerPacket: 1024 
            mBytesPerFrame: 0 
            mChannelsPerFrame: 1 
            mBitsPerChannel: 0  } 
        cookie: {(null)} 
        ACL: {(null)}
        FormatList Array: {
            Index: 0 
            ChannelLayoutTag: 0x640001 
            ASBD: {
            mSampleRate: 44100.000000 
            mFormatID: 'aac ' 
            mFormatFlags: 0x2 
            mBytesPerPacket: 0 
            mFramesPerPacket: 1024 
            mBytesPerFrame: 0 
            mChannelsPerFrame: 1 
            mBitsPerChannel: 0  }} 
    } 
    extensions: {(null)}
})
2021-18-05 19:36:31.617 [Info] [com.haishinkit.HaishinKit] [AudioCodec.swift:72] actualBitrate > 32000
2021-18-05 19:36:36.700 [Warn] [com.haishinkit.SRTHaishinKit] [SRTSocket.swift:45] status > SRT Socket Broken
2021-18-05 19:36:36.700 [Info] [com.haishinkit.HaishinKit] [AudioCodec.swift:81] formatDescription > nil
2021-18-05 19:36:36.737 [Warn] [com.haishinkit.SRTHaishinKit] [SRTSocket.swift:54] status > SRT Socket Not Exist
2021-18-05 19:36:46.864 [Warn] [com.haishinkit.SRTHaishinKit] [SRTSocket.swift:45] status > SRT Socket Broken
2021-18-05 19:36:46.899 [Warn] [com.haishinkit.SRTHaishinKit] [SRTSocket.swift:54] status > SRT Socket Not Exist

Expected behavior Expected to connect to srt-live-server with SRTHaishinKit without ERROR but received: 2021-05-18 19:36:31:775 SLS ERROR: [0x7ff943d29000]CSLSListener::handler, refused, new role[172.27.23.118:53705], stream='input/live/iphone8',but publisher=0x7ff943da4000 is not NULL.

Screenshots n/a

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

checked-out latest master headrev: 82d81398092f21652efab2e7f14df223af5a281f

NOTE: Connecting to server with ffmpeg as publisher:

ffmpeg -f lavfi -i testsrc=duration=1000:size=1280x720:rate=30 -f mpegts "srt://localhost:3000?streamid=input/live/somename"

and ffplay as playback:

ffplay -fflags nobuffer -i "srt://172.27.125.195:3000?streamid=output/live/somename

worked successfully.

BUT:

Connecting to server to playback iphone8 with ffplay resulted in "Input/output error": ffplay -fflags nobuffer -i "srt://172.27.125.195:3000?streamid=output/live/iphone8" srt://172.27.125.195:3000?streamid=output/live/iphone8: Input/output error

NOTE: Using ffplay as an endpoint(instead of srt-live-server) ALSO resulted in an error:

ffplay -analyzeduration 100 -i 'srt://172.27.125.195:3000?mode=listener' srt://172.27.125.195:3000?mode=listener: Unknown error: 316

shogo4405 commented 2 years ago

might be fixed it