go2rtc icon indicating copy to clipboard operation
go2rtc copied to clipboard

WebRTC stream suddenly stops working from time to time

Open nicoverali opened this issue 1 year ago • 7 comments
trafficstars

Hello, I'm using go2rtc to get the stream of a Reolink Doorbell camera, and then I consume that from HomeAssistant. It works for about a week, and then it usually crashes and stops working, so I have to restart the server manually.

This is the config:

api:
  listen: "0.0.0.0:1984"    # default ":1984", HTTP API port ("" - disabled)
  username: ""  # default "", Basic auth for WebUI
  password: ""   # default "", Basic auth for WebUI
  origin: "*"        # default "", allow CORS requests (only * supported)

streams:
  doorbell-sub:
    - rtsp://user:[email protected]:554/h264Preview_01_sub
    - ffmpeg:doorbell-sub#audio=opus#audio=volume
    
ffmpeg:
  bin: ffmpeg  # path to ffmpeg binary
  volume: "-af \"volume=10\""

And then this is what I'm seeing in the info page of that stream:

{
  "producers": [
    {
      "id": 307,
      "format_name": "rtsp",
      "protocol": "rtsp+tcp",
      "remote_addr": "192.168.2.102:554",
      "url": "rtsp://user:[email protected]:554/h264Preview_01_sub",
      "sdp": "v=0\r\no=- 1731214857266085 1 IN IP4 192.168.2.102\r\ns=Session streamed by \"preview\"\r\nt=0 0\r\na=tool:BC Streaming Media v202210012022.10.01\r\na=type:broadcast\r\na=control:*\r\na=range:npt=now-\r\na=x-qt-text-nam:Session streamed by \"preview\"\r\nm=video 0 RTP/AVP 96\r\nc=IN IP4 0.0.0.0\r\nb=AS:8192\r\na=rtpmap:96 H264/90000\r\na=range:npt=now-\r\na=fmtp:96 packetization-mode=1;profile-level-id=640033;sprop-parameter-sets=Z2QAM6wVFKCgPZA=,aO48sA==\r\na=recvonly\r\na=control:track1\r\nm=audio 0 RTP/AVP 97\r\nc=IN IP4 0.0.0.0\r\nb=AS:8192\r\na=rtpmap:97 MPEG4-GENERIC/16000\r\na=fmtp:97 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1408;\r\na=recvonly\r\na=control:track2\r\nm=audio 0 RTP/AVP 8\r\na=control:track3\r\na=rtpmap:8 PCMA/8000\r\na=sendonly",
      "user_agent": "go2rtc/1.9.6",
      "medias": [
        "video, recvonly, H264",
        "audio, recvonly, MPEG4-GENERIC/16000",
        "audio, sendonly, PCMA/8000"
      ],
      "receivers": [
        {
          "id": 309,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video",
            "level": 51,
            "profile": "High"
          },
          "childs": [
            320,
            322,
            324,
            326,
            328,
            330,
            332,
            334,
            336,
            338,
            340,
            342,
            344,
            346,
            348,
            350,
            352,
            354,
            356,
            358,
            360,
            362,
            364,
            366,
            368,
            370,
            372,
            374,
            376,
            378,
            380,
            382,
            384,
            386,
            388,
            390,
            393,
            396
          ],
          "bytes": 7443497585,
          "packets": 6559290
        },
        {
          "id": 313,
          "codec": {
            "codec_name": "aac",
            "codec_type": "audio",
            "sample_rate": 16000
          },
          "childs": [
            394
          ],
          "bytes": 1220498412,
          "packets": 2365307
        }
      ],
      "bytes_recv": 8773997369
    },
    {
      "id": 315,
      "format_name": "rtsp",
      "protocol": "rtsp+tcp",
      "remote_addr": "127.0.0.1:38130 forwarded 127.0.0.1:8554",
      "source": "exec:ffmpeg -hide_banner -v error -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://127.0.0.1:8554/doorbell-sub?audio -map 0:a:0? -c:a:0 libopus -application:a:0 lowdelay -min_comp 0 -af \"volume=10\" -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/70acbc2b73c69b4881ece3dea1070b68",
      "url": "rtsp://127.0.0.1:8554/doorbell-sub?audio",
      "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=go2rtc/1.9.6\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=tool:libavformat 60.16.100\r\nm=audio 0 RTP/AVP 96\r\nb=AS:64\r\na=rtpmap:96 opus/48000/2\r\na=control:streamid=0\r\n",
      "user_agent": "ffmpeg/go2rtc",
      "medias": [
        "audio, recvonly, OPUS/48000/2"
      ],
      "receivers": [
        {
          "id": 316,
          "codec": {
            "channels": 2,
            "codec_name": "opus",
            "codec_type": "audio",
            "sample_rate": 48000
          },
          "bytes": 2287111,
          "packets": 13212
        }
      ],
      "bytes_recv": 2447139
    }
  ],
  "consumers": [
    {
      "id": 312,
      "format_name": "rtsp",
      "protocol": "rtsp+tcp",
      "remote_addr": "127.0.0.1:38120",
      "sdp": "v=0\r\no=- 1 1 IN IP4 0.0.0.0\r\ns=go2rtc/1.9.6\r\nc=IN IP4 0.0.0.0\r\nt=0 0\r\nm=audio 0 RTP/AVP 96\r\na=rtpmap:96 MPEG4-GENERIC/16000\r\na=fmtp:96 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1408;\r\na=control:trackID=0\r\n",
      "user_agent": "go2rtc/ffmpeg",
      "medias": [
        "audio, sendonly, ANY"
      ],
      "senders": [
        {
          "id": 314,
          "codec": {
            "codec_name": "aac",
            "codec_type": "audio",
            "sample_rate": 16000
          },
          "parent": 313,
          "bytes": 2131080,
          "packets": 4130
        }
      ],
      "bytes_send": 2197160
    }
  ]
}
}

We can probably remove HomeAssistant from the formula, because although that's what I'm using to consume the stream, if I go to the go2rtc panel, and click on stream it also fails to load, it keeps loading forever.

Screenshot 2024-11-14 at 11 28 05 AM

It looks like the websocket connection is not responding, maybe ?

nicoverali avatar Nov 14 '24 14:11 nicoverali

So many childs is a big problem. Don't know yet why this can happen.

AlexxIT avatar Nov 14 '24 16:11 AlexxIT

I can provide some more details:

  • I'm currently using version 1.9.6, before I was using version 1.8.2, and this issue was not present
  • Most consumers are mobile, using HomeAssistant app, specifically iOS devices
  • The common use pattern is: open HomeAssistant -> tap on a button to show the Camera dashboard -> then move to another iOS app. The HomeAssistant app is usually not explicitly closed

I can also send you the HomeAssistant card configuration in case it helps, but I believe it's pretty straightforward

type: custom:webrtc-camera
url: doorbell-sub
mode: webrtc
media: video,audio

nicoverali avatar Nov 14 '24 17:11 nicoverali

So many childs is a big problem. Don't know yet why this can happen.

Its related to self referencing streams i think which should be fixed in v1.9.7. After closing the stream, the rtsp consumer from ffmpeg is still present. And if there is an issue with ffmpeg, the childs are not cleaned up

seydx avatar Nov 14 '24 18:11 seydx

So many childs is a big problem. Don't know yet why this can happen.

Its related to self referencing streams i think which should be fixed in v1.9.7. After closing the stream, the rtsp consumer from ffmpeg is still present. And if there is an issue with ffmpeg, the childs are not cleaned up

I can try upgrading to v1.9.7 and check if it happens again. I'll let you know in a few days

nicoverali avatar Nov 14 '24 21:11 nicoverali

@AlexxIT @seydx I've upgrade to v1.9.7 and the same thing happened again

{
   "producers":[
      {
         "id":2,
         "format_name":"rtsp",
         "protocol":"rtsp+tcp",
         "remote_addr":"192.168.2.102:554",
         "url":"rtsp://user:[email protected]:554/h264Preview_01_sub",
         "sdp":"v=0\r\no=- 1731922670403090 1 IN IP4 192.168.0.3\r\ns=Session streamed by \"preview\"\r\nt=0 0\r\na=tool:BC Streaming Media v202210012022.10.01\r\na=type:broadcast\r\na=control:*\r\na=range:npt=now-\r\na=x-qt-text-nam:Session streamed by \"preview\"\r\nm=video 0 RTP/AVP 96\r\nc=IN IP4 0.0.0.0\r\nb=AS:8192\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1;profile-level-id=640033;sprop-parameter-sets=Z2QAM6wVFKCgPZA=,aO48sA==\r\na=recvonly\r\na=control:track1\r\nm=audio 0 RTP/AVP 97\r\nc=IN IP4 0.0.0.0\r\nb=AS:8192\r\na=rtpmap:97 MPEG4-GENERIC/16000\r\na=fmtp:97 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1408;\r\na=recvonly\r\na=control:track2\r\nm=audio 0 RTP/AVP 8\r\na=control:track3\r\na=rtpmap:8 PCMA/8000\r\na=sendonly",
         "user_agent":"go2rtc/1.9.7",
         "medias":[
            "video, recvonly, H264",
            "audio, recvonly, MPEG4-GENERIC/16000",
            "audio, sendonly, PCMA/8000"
         ],
         "receivers":[
            {
               "id":3,
               "codec":{
                  "codec_name":"h264",
                  "codec_type":"video",
                  "level":51,
                  "profile":"High"
               },
               "childs":[
                  21,
                  23,
                  25,
                  27,
                  29,
                  31,
                  33,
                  37,
                  41,
                  45,
                  47,
                  49,
                  51,
                  53,
                  55,
                  57,
                  59,
                  61,
                  63,
                  65,
                  67,
                  71,
                  76,
                  77,
                  81,
                  83,
                  85,
                  88,
                  91
               ],
               "bytes":2206397467,
               "packets":1960259
            },
            {
               "id":6,
               "codec":{
                  "codec_name":"aac",
                  "codec_type":"audio",
                  "sample_rate":16000
               },
               "childs":[
                  89
               ],
               "bytes":361735092,
               "packets":701037
            }
         ],
         "senders":[
            {
               "id":14,
               "codec":{
                  "codec_name":"pcm_alaw",
                  "codec_type":"audio",
                  "sample_rate":8000
               },
               "parent":13,
               "bytes":100000,
               "packets":625
            },
            {
               "id":35,
               "codec":{
                  "codec_name":"pcm_alaw",
                  "codec_type":"audio",
                  "sample_rate":8000
               },
               "parent":34
            },
            {
               "id":40,
               "codec":{
                  "codec_name":"pcm_alaw",
                  "codec_type":"audio",
                  "sample_rate":8000
               },
               "parent":38
            },
            {
               "id":43,
               "codec":{
                  "codec_name":"pcm_alaw",
                  "codec_type":"audio",
                  "sample_rate":8000
               },
               "parent":42
            },
            {
               "id":69,
               "codec":{
                  "codec_name":"pcm_alaw",
                  "codec_type":"audio",
                  "sample_rate":8000
               },
               "parent":68
            },
            {
               "id":75,
               "codec":{
                  "codec_name":"pcm_alaw",
                  "codec_type":"audio",
                  "sample_rate":8000
               },
               "parent":72
            },
            {
               "id":79,
               "codec":{
                  "codec_name":"pcm_alaw",
                  "codec_type":"audio",
                  "sample_rate":8000
               },
               "parent":78
            }
         ],
         "bytes_recv":2601180131,
         "bytes_send":100880
      },
      {
         "id":8,
         "format_name":"rtsp",
         "protocol":"rtsp+tcp",
         "remote_addr":"127.0.0.1:48772 forwarded 127.0.0.1:8554",
         "source":"exec:ffmpeg -hide_banner -v error -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://127.0.0.1:8554/doorbell-sub?audio&source=ffmpeg:doorbell-sub%23audio%3Dopus%23audio%3Dvolume -map 0:a:0? -c:a:0 libopus -application:a:0 lowdelay -min_comp 0 -af \"volume=10\" -vn -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/08ad235e02668038fe4c37b715dfb357",
         "url":"rtsp://127.0.0.1:8554/doorbell-sub?audio&source=ffmpeg:doorbell-sub%23audio%3Dopus%23audio%3Dvolume",
         "sdp":"v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=go2rtc/1.9.7\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=tool:libavformat 60.16.100\r\nm=audio 0 RTP/AVP 96\r\nb=AS:64\r\na=rtpmap:96 opus/48000/2\r\na=control:streamid=0\r\n",
         "user_agent":"ffmpeg/go2rtc",
         "medias":[
            "audio, recvonly, OPUS/48000/2"
         ],
         "receivers":[
            {
               "id":9,
               "codec":{
                  "channels":2,
                  "codec_name":"opus",
                  "codec_type":"audio",
                  "sample_rate":48000
               },
               "bytes":69736,
               "packets":358
            }
         ],
         "bytes_recv":74088
      }
   ],
   "consumers":[
      {
         "id":16,
         "format_name":"rtsp",
         "protocol":"rtsp+tcp",
         "remote_addr":"127.0.0.1:55860",
         "source":"ffmpeg:doorbell-sub#audio=opus#audio=volume",
         "sdp":"v=0\r\no=- 1 1 IN IP4 0.0.0.0\r\ns=go2rtc/1.9.7\r\nc=IN IP4 0.0.0.0\r\nt=0 0\r\nm=audio 0 RTP/AVP 96\r\na=rtpmap:96 MPEG4-GENERIC/16000\r\na=fmtp:96 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1408;\r\na=control:trackID=0\r\n",
         "user_agent":"go2rtc/ffmpeg",
         "medias":[
            "audio, sendonly, ANY"
         ],
         "senders":[
            {
               "id":17,
               "codec":{
                  "codec_name":"aac",
                  "codec_type":"audio",
                  "sample_rate":16000
               },
               "parent":6,
               "bytes":1910748,
               "packets":3703
            }
         ],
         "bytes_send":1969996
      }
   ]
}

nicoverali avatar Nov 19 '24 01:11 nicoverali

@nicoverali

can you try this one: https://github.com/seydx/go2rtc/actions/runs/11920040811

seydx avatar Nov 19 '24 19:11 seydx

@nicoverali

can you try this one: https://github.com/seydx/go2rtc/actions/runs/11920040811

Sure. It took like 3 days to crash last time, so I'll let you know in a couple of days.

nicoverali avatar Nov 19 '24 20:11 nicoverali

Hey, I am having similar issues on 1.9.7. I started using go2rtc today and similiar issue happened multiple times for me. I have multiple RTSP cameras, fed trough ffmpeg into HA webRTC panel. (It happens to the integrated viewer aswell) e.g. of my config camera1: ffmpeg:rtsp://ID:PW@{CameraIP}:554/unicast/c1/s1/live#backchannel=0#video=copy

Sending H264 stream from nvr to clients. I have them streamed on all devices using the integrated API streaming website. iOS, Android & PC.

I noticed that after while WebRTC ceases to work. Mainly when I watch on mobile devices(Put them to sleep, keep it running) and on PC aswell. (It seems to happen more frequently) And the browser switches to play from MSE (It then tries to connect using RTC, only to refresh like a frame of video but in the meantime the ws closes?) In log I see closed websockets: undefined error=websocket: close 1000 (normal) caller=github.com/AlexxIT/go2rtc/internal/api/ws/ws.go:124 I noticed ~~different (handshake?) messages in websocket~~ no handshakes in the websocket when the WebRTC fails.

Situation 1 (Both WebRTC & MSE doesn't work):

So I tried MSE player, but even MSE wont get anything back from the websocket: image. The amount of childs is 0 and the stream is dead. (The rtsp stream works, ffmpeg on different machine keeps streaming) image This is the last log entry of the stream( The ws connection is not closed)

15:26:49.163 TRC [api] ws msg type=mse
15:26:49.163 TRC [mp4] new WS/MSE consumer codecs=avc1.640029,avc1.64002A,avc1.640033,hvc1.1.6.L153.B0,mp4a.40.2,mp4a.40.5,flac,opus
15:26:49.164 TRC [streams] check cons=7 media=video, sendonly, H264, H265

api/streams for that camera:

{
  "producers": [
    {
      "id": 9,
      "format_name": "rtsp",
      "protocol": "rtsp+tcp",
      "remote_addr": "127.0.0.1:36538 forwarded 192.168.1.10:554",
      "source": "exec:ffmpeg -hide_banner -v error -allowed_media_types video -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://username:[email protected]:554/unicast/c1/s1/live -c:v copy -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/randomhash1",
      "url": "rtsp://username:[email protected]:554/unicast/c1/s1/live",
      "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=ONVIF RTSP Server\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=tool:libavformat 60.16.100\r\nm=video 0 RTP/AVP 96\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z01AH524FAFumyAAAAMAIAAABRCA,aOpDyA==; profile-level-id=4D401F\r\na=control:streamid=0\r\n",
      "user_agent": "ffmpeg/go2rtc",
      "medias": [
        "video, recvonly, H264"
      ],
      "receivers": [
        {
          "id": 13,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video",
            "level": 31,
            "profile": "Main"
          },
          "bytes": 3355689,
          "packets": 2818
        }
      ],
      "bytes_recv": 3389841
    }
  ],
  "consumers": []
}

I noticed that data values are not increasing. So I assume some connection problem in the ffmpeg(Different issue than the WebRTC) "bytes": 3355689, "packets": 2818 } ], "bytes_recv": 3389841

Situation 2 (WebRTC doesn't work but MSE is working):

I get this high amount of childs that dont correspond to the consumers? image Log from the api/streams:

{
  "producers": [
    {
      "id": 9,
      "format_name": "rtsp",
      "protocol": "rtsp+tcp",
      "remote_addr": "127.0.0.1:55930 forwarded 192.168.1.9:554",
      "source": "exec:ffmpeg -hide_banner -v error -allowed_media_types video -fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i rtsp://user:[email protected]:554/unicast/c1/s1/live -c:v copy -an -user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp rtsp://127.0.0.1:8554/a55f8cfe4ce17f60881df3d6f9086af9",
      "url": "rtsp://user:[email protected]:554/unicast/c1/s1/live",
      "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=ONVIF RTSP Server\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\na=tool:libavformat 60.16.100\r\nm=video 0 RTP/AVP 96\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z01AH524FAFumyAAAAMAIAAABRCA,aOpDyA==; profile-level-id=4D401F\r\na=control:streamid=0\r\n",
      "user_agent": "ffmpeg/go2rtc",
      "medias": [
        "video, recvonly, H264"
      ],
      "receivers": [
        {
          "id": 14,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video",
            "level": 31,
            "profile": "Main"
          },
          "childs": [
            49,
            138,
            142,
            144,
            148,
            150,
            152,
            154,
            156,
            158,
            160,
            162,
            164,
            166,
            168,
            170,
            172,
            174,
            176,
            178,
            181,
            182,
            184,
            186,
            188,
            190
          ],
          "bytes": 139619346,
          "packets": 112129
        }
      ],
      "bytes_recv": 140971726
    }
  ],
  "consumers": [
    {
      "id": 48,
      "format_name": "webrtc",
      "protocol": "ws+udp",
      "remote_addr": "10.0.0.1:58069 srflx 0.0.0.0:0",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
      "medias": [
        "video, sendonly, VP8, VP9, H264, AV1"
      ],
      "senders": [
        {
          "id": 49,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video"
          },
          "parent": 14,
          "bytes": 57777308,
          "packets": 46515
        }
      ],
      "bytes_send": 58419959
    },
    {
      "id": 135,
      "format_name": "webrtc",
      "protocol": "ws+udp",
      "remote_addr": "10.0.0.1:51059 srflx 0.0.0.0:0",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
      "medias": [
        "video, sendonly, VP8, VP9, H264, AV1"
      ],
      "senders": [
        {
          "id": 138,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video"
          },
          "parent": 14,
          "bytes": 12423483,
          "packets": 9617
        }
      ],
      "bytes_send": 12561755
    },
    {
      "id": 141,
      "format_name": "mse/fmp4",
      "protocol": "ws",
      "remote_addr": "192.168.1.5:51296 forwarded 192.168.1.50",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
      "medias": [
        "video, sendonly, H264, H265"
      ],
      "senders": [
        {
          "id": 142,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video",
            "level": 31,
            "profile": "Main"
          },
          "parent": 14,
          "bytes": 4348755,
          "packets": 3274
        }
      ],
      "bytes_send": 4216493
    },
    {
      "id": 143,
      "format_name": "webrtc",
      "protocol": "ws+udp",
      "remote_addr": "10.0.0.1:54290 srflx 0.0.0.0:0",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
      "medias": [
        "video, sendonly, VP8, VP9, H264, AV1"
      ],
      "senders": [
        {
          "id": 144,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video"
          },
          "parent": 14,
          "bytes": 4338516,
          "packets": 3266
        }
      ],
      "bytes_send": 4386863
    },
    {
      "id": 147,
      "format_name": "mse/fmp4",
      "protocol": "ws",
      "remote_addr": "192.168.1.5:41290 forwarded 192.168.1.50",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
      "medias": [
        "video, sendonly, H264, H265"
      ],
      "senders": [
        {
          "id": 148,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video",
            "level": 31,
            "profile": "Main"
          },
          "parent": 14,
          "bytes": 2674411,
          "packets": 2030
        }
      ],
      "bytes_send": 1818288
    },
    {
      "id": 149,
      "format_name": "webrtc",
      "protocol": "ws+udp",
      "remote_addr": "10.0.0.1:63447 srflx 0.0.0.0:0",
      "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
      "medias": [
        "video, sendonly, VP8, VP9, H264, AV1"
      ],
      "senders": [
        {
          "id": 150,
          "codec": {
            "codec_name": "h264",
            "codec_type": "video"
          },
          "parent": 14,
          "bytes": 2674411,
          "packets": 2030
        }
      ],
      "bytes_send": 2704436
    }
  ]
}

MSE continues to work but later stops due to more buffering (Pausing the playback, data keep flowing)

After while when trying to watch using WebRTC in the integrated html viewer It started working. Seems that go2rtc has autofixing abilities. Well from the logs it seems to crash & restart fixing the issue (without having me manually restart to fix it): (From logs I have in docker it crashed 8 times so far) (Stripped them from most of the trace logs)


panic: close of closed channel

goroutine 4972 [running]:
github.com/AlexxIT/go2rtc/pkg/core.(*Sender).Close(0x35d0a50)
        github.com/AlexxIT/go2rtc/pkg/core/track.go:174 +0xb4
github.com/AlexxIT/go2rtc/pkg/core.(*Connection).Stop(0x42d0188)
        github.com/AlexxIT/go2rtc/pkg/core/connection.go:75 +0x88
github.com/AlexxIT/go2rtc/internal/streams.(*Stream).RemoveConsumer(0x20a2120, {0x98b948, 0x42d0188})
        github.com/AlexxIT/go2rtc/internal/streams/stream.go:64 +0x24
github.com/AlexxIT/go2rtc/internal/webrtc.asyncHandler.func1({0x7de850, 0xd83cf0})
        github.com/AlexxIT/go2rtc/internal/webrtc/webrtc.go:157 +0x9c
github.com/AlexxIT/go2rtc/pkg/core.(*Listener).Fire(...)
        github.com/AlexxIT/go2rtc/pkg/core/listener.go:16
github.com/AlexxIT/go2rtc/pkg/webrtc.NewConn.func5(0x6)
        github.com/AlexxIT/go2rtc/pkg/webrtc/conn.go:129 +0x68
created by github.com/pion/webrtc/v3.(*PeerConnection).onConnectionStateChange in goroutine 5012
        github.com/pion/webrtc/[email protected]/peerconnection.go:496 +0x158
14:34:28.600 INF go2rtc platform=linux/arm revision=dbe9e4a version=1.9.7
14:34:28.600 DBG build vcs.time=2024-11-11T17:20:53Z version=go1.22.9
14:34:28.601 INF config path=/config/go2rtc.yaml
14:34:28.602 TRC [api] register path path=/
14:34:28.602 TRC [api] register path path=/api
14:34:28.602 TRC [api] register path path=/api/config
14:34:28.602 TRC [api] register path path=/api/exit
14:34:28.602 TRC [api] register path path=/api/restart
14:34:28.603 TRC [api] register path path=/api/log
14:34:28.604 INF [api] listen addr=:1984
14:34:28.605 TRC [api] register path path=/api/ws
14:34:28.606 TRC [api] register path path=/api/streams
14:34:28.606 TRC [api] register path path=/api/streams.dot
14:34:28.607 INF [rtsp] listen addr=:8554
14:34:28.610 INF [webrtc] listen addr=:8555
14:34:28.610 TRC [api] register path path=/api/webrtc

and

panic: runtime error: index out of range [8] with length 8

goroutine 3185 [running]:
github.com/AlexxIT/go2rtc/internal/app.(*circularBuffer).Write(0x2526420, {0x3ccf500, 0x6d, 0x1500})
        github.com/AlexxIT/go2rtc/internal/app/log.go:120 +0x2c4
github.com/rs/zerolog.LevelWriterAdapter.WriteLevel(...)
        github.com/rs/[email protected]/writer.go:27
github.com/rs/zerolog.multiLevelWriter.WriteLevel({{0x250e870, 0x2, 0x2}}, 0xff, {0x3ccf500, 0x6d, 0x1500})
        github.com/rs/[email protected]/writer.go:98 +0x98
github.com/rs/zerolog.(*Event).write(0x273c280)
        github.com/rs/[email protected]/event.go:80 +0x15c
github.com/rs/zerolog.(*Event).msg(0x273c280, {0x3e69480, 0x39})
        github.com/rs/[email protected]/event.go:151 +0x264
github.com/rs/zerolog.(*Event).Msgf(0x273c280, {0x89e020, 0x28}, {0x4f03e70, 0x3, 0x3})
        github.com/rs/[email protected]/event.go:131 +0x64
github.com/AlexxIT/go2rtc/internal/streams.(*Stream).AddConsumer(0x2400270, {0x98b948, 0x25a0608})
        github.com/AlexxIT/go2rtc/internal/streams/add_consumer.go:44 +0x900
github.com/AlexxIT/go2rtc/internal/webrtc.asyncHandler(0x3a0e5a0, 0x2e3c050)
        github.com/AlexxIT/go2rtc/internal/webrtc/webrtc.go:185 +0x7a8
github.com/AlexxIT/go2rtc/internal/api/ws.apiWS.func2()
        github.com/AlexxIT/go2rtc/internal/api/ws/ws.go:134 +0x40
created by github.com/AlexxIT/go2rtc/internal/api/ws.apiWS in goroutine 3162
        github.com/AlexxIT/go2rtc/internal/api/ws/ws.go:133 +0x3d0

Hope this helps and is related to the original issue :)

akaspeh1 avatar Dec 15 '24 15:12 akaspeh1

@seydx Hey, sorry I forgot to give you an update, this setup is at my mom's house so I'm not constantly aware of it. The version you send me seems to fix the issue, the stream didn't break anymore, but I'm having a new issue, the WebRTC stream doesn't have sound, MSE does. I've compared it with 1.9.7 and it does provide sound, any idea what could be happening ?

EDIT: Please let me know if you believe that the changes made on the version you sent me can't break sound, it may be an issue on my end. I tried to spin up the updated version the same way as the other ones, but I may have messed it up at some point.

nicoverali avatar Dec 15 '24 16:12 nicoverali

Hey! @AlexxIT @seydx I've been running the ad-hoc solution provided above (11920040811) since last November. No issues so far, the camera haven't crashed anymore. I would like to update to the latest 1.9.9 version but I also would like to know if this fix has been added to it. Thank you!

nicoverali avatar Jul 15 '25 04:07 nicoverali