AlexxIT / go2rtc

Ultimate camera streaming application with support RTSP, RTMP, HTTP-FLV, WebRTC, MSE, HLS, MP4, MJPEG, HomeKit, FFmpeg, etc.
https://github.com/AlexxIT/Blog
MIT License
7.06k stars 505 forks source link

2 way audio in mobile #1170

Open copbr opened 5 months ago

copbr commented 5 months ago

RTC is working fine both Android and iOS connection is fast and nice. Mobile browsers can hear audio from camera, but cannot send audio to camera. Its mandatory use HTTPS to enable 2 way audio? Safari and Chrome do not even prompt for permission to use the microphone.

My probe:

{
  "producers": [
    {
      "type": "RTSP active producer",
      "url": "rtsp://192.168.200.22:554/live/ch00_0/",
      "remote_addr": "192.168.200.22:554",
      "user_agent": "go2rtc/1.9.3",
      "sdp": "v=0\r\no=- 1 1 IN IP4 127.0.0.1\r\ns=Easy Rtsp 1.0\r\ni=Easy\r\nc=IN IP4 0.0.0.0\r\nt=0 0\r\nm=video 0 RTP/AVP 96\r\nb=AS:5000\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 profile-level-id=4D401F;packetization-mode=1;sprop-parameter-sets=Z01AH52oFAFuhAAAAwAEAAADAMoQ,aO48gA==\r\na=control:trackID=0\r\nm=audio 0 RTP/AVP 0\r\na=rtpmap:0 PCMU/8000\r\na=fmtp:0\r\na=control:trackID=1\r\n",
      "medias": [
        "video, recvonly, H264",
        "audio, recvonly, PCMU/8000"
      ],
      "receivers": [
        {
          "codec": {
            "codec_name": "h264",
            "codec_type": "video",
            "level": 31,
            "profile": "Main"
          },
          "bytes": 185026324,
          "packets": 152309
        },
        {
          "codec": {
            "codec_name": "pcm_mulaw",
            "codec_type": "audio",
            "sample_rate": 8000
          },
          "bytes": 5608480,
          "packets": 35053
        }
      ],
      "recv": 192883148
    },
    {
      "url": "ffmpeg:porteiro#audio=pcmu"
    }
  ],
  "consumers": [
    {
      "type": "WebRTC/WebSocket async passive consumer",
      "remote_addr": "udp4 prflx 192.168.65.1:31246 related :0",
      "user_agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Mobile Safari/537.36",
      "medias": [
        "video, sendonly, VP8, VP9, AV1, H264",
        "audio, sendonly, OPUS/48000/2, G722/8000, PCMU/8000, PCMA/8000, L16, PCML"
      ],
      "senders": [
        {
          "codec": {
            "codec_name": "h264",
            "codec_type": "video"
          },
          "bytes": 185026324,
          "packets": 152309
        },
        {
          "codec": {
            "codec_name": "pcm_mulaw",
            "codec_type": "audio",
            "sample_rate": 8000
          },
          "bytes": 5577920,
          "packets": 34862,
          "drops": 191
        }
      ],
      "send": 192682717
    },
    {
      "type": "RTSP passive consumer",
      "url": "rtsp://127.0.0.1:8554/porteiro?audio",
      "remote_addr": "127.0.0.1:40636",
      "user_agent": "go2rtc/ffmpeg",
      "sdp": "v=0\r\no=- 1 1 IN IP4 0.0.0.0\r\ns=go2rtc/1.9.3\r\nc=IN IP4 0.0.0.0\r\nt=0 0\r\nm=audio 0 RTP/AVP 96\r\na=rtpmap:96 PCMU/8000\r\na=control:trackID=0\r\n",
      "medias": [
        "audio, sendonly, ANY"
      ],
      "senders": [
        {
          "codec": {
            "codec_name": "pcm_mulaw",
            "codec_type": "audio",
            "sample_rate": 8000
          },
          "bytes": 320,
          "packets": 2
        }
      ],
      "send": 352
    },
    {
      "type": "probe",
      "remote_addr": "192.168.65.1:20156",
      "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
      "medias": [
        "video, sendonly, ALL",
        "audio, sendonly, ALL",
        "audio, recvonly, ANY"
      ],
      "senders": [
        {
          "codec": {
            "codec_name": "h264",
            "codec_type": "video",
            "level": 31,
            "profile": "Main"
          },
          "bytes": 10150,
          "packets": 9
        },
        {
          "codec": {
            "codec_name": "pcm_mulaw",
            "codec_type": "audio",
            "sample_rate": 8000
          }
        }
      ]
    }
  ]
}

192.168.200.123

My config

streams:
  porteiro:
    - rtsp://192.168.200.22:554/cam/realmonitor?channel=1&subtype=1

ffmpeg:
  bin: "ffmpeg"
  global: "-hide_banner"
  file: "-re -stream_loop -1 -i {input}"
  http: "-fflags nobuffer -flags low_delay -i {input}"
  rtsp: "-fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_transport tcp -i {input}"
  output: "-user_agent ffmpeg/go2rtc -rtsp_transport tcp -f rtsp {output}"

webrtc:
  listen: ":8555"
  candidates:
    - 192.168.200.123:8555  # if you have static public IP-address
    - stun:8555
  ice_servers:
    - urls: [ "stun:stun.l.google.com:19302" ]
      username: ""
      credential: ""
  mode: "auto"
AlexxIT commented 5 months ago

I don't think your camera support two way audio via well known protocols. /live/ch00_0/ - this is usually a cheap, noname Chinese cameras with not best RTSP realisation.

copbr commented 5 months ago

Is there any way to find out if the camera supports 2-way audio without looking at the RTSP URL? Is there any response in the probe that could indicate whether it allows 2-way audio or not? Anyway, I will look for a camera that uses a different URL to try to move away from /live/ch00_0/

Thank you AlexxIT! Nice job with go2rtc!

AlexxIT commented 5 months ago

List of medias from your camera. It has only recv items.