androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.61k stars 380 forks source link

ExoPlayer - RTSP UDP->TCP failover produces error 401 #522

Closed milan-fabian closed 10 months ago

milan-fabian commented 1 year ago

Version

Media3 1.1.0

More version details

No response

Devices that reproduce the issue

Tested on several Android boxes with Rockchip RK3588 and RK3399

RTSP source: HiWatch / Hikvision IP camera (for example DS-I213)

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

I am trying to play a video stream from HiWatch IP camera using RTSP.

If I create RTSP Media Source like this:

new RtspMediaSource.Factory()
      .createMediaSource(MediaItem.fromUri("rtsp://username:password@10.42.111.3:554/Streaming/Channels/102"));

there is a black screen for 8 seconds and ExoPlayer throws androidx.media3.exoplayer.rtsp.RtspMediaSource$RtspPlaybackException: SETUP 401 afterwards.

Full RtspClient log (UDP->TCP failover produces 401)

``` 09:02:10.861 10058 10149 D RtspClient: OPTIONS rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0 09:02:10.861 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:02:10.861 10058 10149 D RtspClient: CSeq: 0 09:02:11.388 10058 10149 D RtspClient: RTSP/1.0 200 OK 09:02:11.388 10058 10149 D RtspClient: CSeq: 0 09:02:11.388 10058 10149 D RtspClient: Public: OPTIONS, DESCRIBE, PLAY, PAUSE, SETUP, TEARDOWN, SET_PARAMETER, GET_PARAMETER 09:02:11.388 10058 10149 D RtspClient: Date: Fri, Jul 14 2023 10:02:09 GMT 09:02:11.390 10058 10149 D RtspClient: DESCRIBE rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0 09:02:11.390 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:02:11.390 10058 10149 D RtspClient: CSeq: 1 09:02:11.413 10058 10149 D RtspClient: RTSP/1.0 401 Unauthorized 09:02:11.413 10058 10149 D RtspClient: CSeq: 1 09:02:11.413 10058 10149 D RtspClient: WWW-Authenticate: Digest realm="1868cbb42b82", nonce="c937caef59e2658b0be8cb51a20670be", stale="FALSE" 09:02:11.413 10058 10149 D RtspClient: WWW-Authenticate: Basic realm="1868cbb42b82" 09:02:11.413 10058 10149 D RtspClient: Date: Fri, Jul 14 2023 10:02:09 GMT 09:02:11.414 10058 10149 D RtspClient: DESCRIBE rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0 09:02:11.414 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:02:11.414 10058 10149 D RtspClient: CSeq: 2 09:02:11.414 10058 10149 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="c937caef59e2658b0be8cb51a20670be", uri="rtsp://10.42.111.3:554/Streaming/Channels/102", response="xx" 09:02:11.441 10058 10149 D RtspClient: RTSP/1.0 200 OK 09:02:11.441 10058 10149 D RtspClient: CSeq: 2 09:02:11.441 10058 10149 D RtspClient: Content-Type: application/sdp 09:02:11.441 10058 10149 D RtspClient: Content-Base: rtsp://10.42.111.3:554/Streaming/Channels/102/ 09:02:11.441 10058 10149 D RtspClient: Content-Length: 562 09:02:11.441 10058 10149 D RtspClient: 09:02:11.441 10058 10149 D RtspClient: v=0 09:02:11.441 10058 10149 D RtspClient: o=- 1689328929878074 1689328929878074 IN IP4 10.42.111.3 09:02:11.441 10058 10149 D RtspClient: s=Media Presentation 09:02:11.441 10058 10149 D RtspClient: e=NONE 09:02:11.441 10058 10149 D RtspClient: b=AS:5050 09:02:11.441 10058 10149 D RtspClient: t=0 0 09:02:11.441 10058 10149 D RtspClient: a=control:rtsp://10.42.111.3:554/Streaming/Channels/102/ 09:02:11.441 10058 10149 D RtspClient: m=video 0 RTP/AVP 96 09:02:11.441 10058 10149 D RtspClient: c=IN IP4 0.0.0.0 09:02:11.441 10058 10149 D RtspClient: b=AS:5000 09:02:11.441 10058 10149 D RtspClient: a=recvonly 09:02:11.441 10058 10149 D RtspClient: a=control:rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1 09:02:11.441 10058 10149 D RtspClient: a=rtpmap:96 H264/90000 09:02:11.441 10058 10149 D RtspClient: a=fmtp:96 profile-level-id=420029; packetization-mode=1; sprop-parameter-sets=Z00AFJWoUH6EAAA6mAAFfkAQ,aO48gA== 09:02:11.441 10058 10149 D RtspClient: a=Media_header:MEDIAINFO=494D4B48010200000400000100000000000000000000000000000000000000000000000000000000; 09:02:11.441 10058 10149 D RtspClient: a=appversion:1.0 09:02:11.472 10058 10149 D RtspClient: SETUP rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1 RTSP/1.0 09:02:11.472 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:02:11.472 10058 10149 D RtspClient: CSeq: 3 09:02:11.472 10058 10149 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="c937caef59e2658b0be8cb51a20670be", uri="rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1", response="xx" 09:02:11.472 10058 10149 D RtspClient: Transport: RTP/AVP;unicast;client_port=56766-56767 09:02:11.510 10058 10149 D RtspClient: RTSP/1.0 200 OK 09:02:11.510 10058 10149 D RtspClient: CSeq: 3 09:02:11.510 10058 10149 D RtspClient: Session: 1822977514;timeout=60 09:02:11.510 10058 10149 D RtspClient: Transport: RTP/AVP;unicast;client_port=56766-56767;server_port=8284-8285;ssrc=4ff1faa5;mode="play" 09:02:11.510 10058 10149 D RtspClient: Date: Fri, Jul 14 2023 10:02:09 GMT 09:02:11.511 10058 10149 D RtspClient: PLAY rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0 09:02:11.511 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:02:11.511 10058 10149 D RtspClient: CSeq: 4 09:02:11.511 10058 10149 D RtspClient: Session: 1822977514 09:02:11.511 10058 10149 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="c937caef59e2658b0be8cb51a20670be", uri="rtsp://10.42.111.3:554/Streaming/Channels/102", response="xx" 09:02:11.511 10058 10149 D RtspClient: Range: npt=0.000- 09:02:11.657 10058 10149 D RtspClient: RTSP/1.0 200 OK 09:02:11.657 10058 10149 D RtspClient: CSeq: 4 09:02:11.657 10058 10149 D RtspClient: Session: 1822977514 09:02:11.657 10058 10149 D RtspClient: RTP-Info: url=rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1;seq=39511;rtptime=3807562100 09:02:11.657 10058 10149 D RtspClient: Date: Fri, Jul 14 2023 10:02:10 GMT 09:02:19.457 10058 10149 D RtspClient: TEARDOWN rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0 09:02:19.457 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:02:19.457 10058 10149 D RtspClient: CSeq: 5 09:02:19.457 10058 10149 D RtspClient: Session: 1822977514 09:02:19.457 10058 10149 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="c937caef59e2658b0be8cb51a20670be", uri="rtsp://10.42.111.3:554/Streaming/Channels/102", response="xx" 09:02:19.482 10058 10149 D RtspClient: SETUP rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1 RTSP/1.0 09:02:19.482 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:02:19.482 10058 10149 D RtspClient: CSeq: 6 09:02:19.482 10058 10149 D RtspClient: Transport: RTP/AVP/TCP;unicast;interleaved=0-1 09:02:19.508 10058 10149 D RtspClient: RTSP/1.0 401 Unauthorized 09:02:19.508 10058 10149 D RtspClient: CSeq: 6 09:02:19.508 10058 10149 D RtspClient: WWW-Authenticate: Digest realm="1868cbb42b82", nonce="14dc011bcafd561132ecdcdc645673f3", stale="FALSE" 09:02:19.508 10058 10149 D RtspClient: WWW-Authenticate: Basic realm="1868cbb42b82" 09:02:19.508 10058 10149 D RtspClient: Date: Fri, Jul 14 2023 10:02:17 GMT 09:02:19.510 10058 10149 D RtspClient: SETUP rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1 RTSP/1.0 09:02:19.510 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:02:19.510 10058 10149 D RtspClient: CSeq: 7 09:02:19.510 10058 10149 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="14dc011bcafd561132ecdcdc645673f3", uri="rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1", response="xx" 09:02:19.510 10058 10149 D RtspClient: Transport: RTP/AVP/TCP;unicast;interleaved=0-1 09:02:19.536 10058 10149 D RtspClient: RTSP/1.0 401 Unauthorized 09:02:19.536 10058 10149 D RtspClient: CSeq: 7 09:02:19.536 10058 10149 D RtspClient: WWW-Authenticate: Digest realm="1868cbb42b82", nonce="ea3470d26a69ed29e785e29394962dc2", stale="FALSE" 09:02:19.536 10058 10149 D RtspClient: WWW-Authenticate: Basic realm="1868cbb42b82" 09:02:19.536 10058 10149 D RtspClient: Date: Fri, Jul 14 2023 10:02:17 GMT 09:02:19.542 10058 10149 E ExoPlayerImplInternal: Playback error 09:02:19.542 10058 10149 E ExoPlayerImplInternal: androidx.media3.exoplayer.ExoPlaybackException: Source error 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at androidx.media3.exoplayer.ExoPlayerImplInternal.handleIoException(Unknown Source:16) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(Unknown Source:335) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at android.os.Handler.dispatchMessage(Handler.java:102) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at android.os.Looper.loopOnce(Looper.java:201) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at android.os.Looper.loop(Looper.java:288) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at android.os.HandlerThread.run(HandlerThread.java:67) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: Caused by: androidx.media3.exoplayer.rtsp.RtspMediaSource$RtspPlaybackException: SETUP 401 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspResponse(Unknown Source:373) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.handleRtspMessage(Unknown Source:11) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.lambda$onRtspMessageReceived$0(Unknown Source:0) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at androidx.media3.exoplayer.rtsp.RtspClient$MessageListener.a(Unknown Source:0) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at androidx.media3.exoplayer.rtsp.c.run(Unknown Source:4) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at android.os.Handler.handleCallback(Handler.java:938) 09:02:19.542 10058 10149 E ExoPlayerImplInternal: at android.os.Handler.dispatchMessage(Handler.java:99) ```

If I create RTSP media source with forceUseRtpTcp set to true, video playback works correctly:

new RtspMediaSource.Factory().setForceUseRtpTcp(true)
      .createMediaSource(MediaItem.fromUri("rtsp://username:password@10.42.111.3:554/Streaming/Channels/102"));
Full RtspClient log (working through TCP)

``` 09:08:35.030 10972 11079 D RtspClient: OPTIONS rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0 09:08:35.030 10972 11079 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:08:35.030 10972 11079 D RtspClient: CSeq: 0 09:08:35.579 10972 11079 D RtspClient: RTSP/1.0 200 OK 09:08:35.579 10972 11079 D RtspClient: CSeq: 0 09:08:35.579 10972 11079 D RtspClient: Public: OPTIONS, DESCRIBE, PLAY, PAUSE, SETUP, TEARDOWN, SET_PARAMETER, GET_PARAMETER 09:08:35.579 10972 11079 D RtspClient: Date: Fri, Jul 14 2023 10:08:34 GMT 09:08:35.581 10972 11079 D RtspClient: DESCRIBE rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0 09:08:35.581 10972 11079 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:08:35.581 10972 11079 D RtspClient: CSeq: 1 09:08:35.608 10972 11079 D RtspClient: RTSP/1.0 401 Unauthorized 09:08:35.608 10972 11079 D RtspClient: CSeq: 1 09:08:35.608 10972 11079 D RtspClient: WWW-Authenticate: Digest realm="1868cbb42b82", nonce="078a07b6c6c1c2a85f2f34612f24cec3", stale="FALSE" 09:08:35.608 10972 11079 D RtspClient: WWW-Authenticate: Basic realm="1868cbb42b82" 09:08:35.608 10972 11079 D RtspClient: Date: Fri, Jul 14 2023 10:08:34 GMT 09:08:35.609 10972 11079 D RtspClient: DESCRIBE rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0 09:08:35.609 10972 11079 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:08:35.609 10972 11079 D RtspClient: CSeq: 2 09:08:35.609 10972 11079 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="078a07b6c6c1c2a85f2f34612f24cec3", uri="rtsp://10.42.111.3:554/Streaming/Channels/102", response="xx" 09:08:35.636 10972 11079 D RtspClient: RTSP/1.0 200 OK 09:08:35.636 10972 11079 D RtspClient: CSeq: 2 09:08:35.636 10972 11079 D RtspClient: Content-Type: application/sdp 09:08:35.636 10972 11079 D RtspClient: Content-Base: rtsp://10.42.111.3:554/Streaming/Channels/102/ 09:08:35.636 10972 11079 D RtspClient: Content-Length: 562 09:08:35.636 10972 11079 D RtspClient: 09:08:35.636 10972 11079 D RtspClient: v=0 09:08:35.636 10972 11079 D RtspClient: o=- 1689329314079391 1689329314079391 IN IP4 10.42.111.3 09:08:35.636 10972 11079 D RtspClient: s=Media Presentation 09:08:35.636 10972 11079 D RtspClient: e=NONE 09:08:35.636 10972 11079 D RtspClient: b=AS:5050 09:08:35.636 10972 11079 D RtspClient: t=0 0 09:08:35.636 10972 11079 D RtspClient: a=control:rtsp://10.42.111.3:554/Streaming/Channels/102/ 09:08:35.636 10972 11079 D RtspClient: m=video 0 RTP/AVP 96 09:08:35.636 10972 11079 D RtspClient: c=IN IP4 0.0.0.0 09:08:35.636 10972 11079 D RtspClient: b=AS:5000 09:08:35.636 10972 11079 D RtspClient: a=recvonly 09:08:35.636 10972 11079 D RtspClient: a=control:rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1 09:08:35.636 10972 11079 D RtspClient: a=rtpmap:96 H264/90000 09:08:35.636 10972 11079 D RtspClient: a=fmtp:96 profile-level-id=420029; packetization-mode=1; sprop-parameter-sets=Z00AFJWoUH6EAAA6mAAFfkAQ,aO48gA== 09:08:35.636 10972 11079 D RtspClient: a=Media_header:MEDIAINFO=494D4B48010200000400000100000000000000000000000000000000000000000000000000000000; 09:08:35.636 10972 11079 D RtspClient: a=appversion:1.0 09:08:35.660 10972 11079 D RtspClient: SETUP rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1 RTSP/1.0 09:08:35.660 10972 11079 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:08:35.660 10972 11079 D RtspClient: CSeq: 3 09:08:35.660 10972 11079 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="078a07b6c6c1c2a85f2f34612f24cec3", uri="rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1", response="xx" 09:08:35.660 10972 11079 D RtspClient: Transport: RTP/AVP/TCP;unicast;interleaved=0-1 09:08:35.697 10972 11079 D RtspClient: RTSP/1.0 200 OK 09:08:35.697 10972 11079 D RtspClient: CSeq: 3 09:08:35.697 10972 11079 D RtspClient: Session: 1648304005;timeout=60 09:08:35.697 10972 11079 D RtspClient: Transport: RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=0c5881d5;mode="play" 09:08:35.697 10972 11079 D RtspClient: Date: Fri, Jul 14 2023 10:08:34 GMT 09:08:35.699 10972 11079 D RtspClient: PLAY rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0 09:08:35.699 10972 11079 D RtspClient: User-Agent: AndroidXMedia3/1.1.0 09:08:35.699 10972 11079 D RtspClient: CSeq: 4 09:08:35.699 10972 11079 D RtspClient: Session: 1648304005 09:08:35.699 10972 11079 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="078a07b6c6c1c2a85f2f34612f24cec3", uri="rtsp://10.42.111.3:554/Streaming/Channels/102", response="xx" 09:08:35.699 10972 11079 D RtspClient: Range: npt=0.000- 09:08:35.861 10972 11079 D RtspClient: RTSP/1.0 200 OK 09:08:35.861 10972 11079 D RtspClient: CSeq: 4 09:08:35.861 10972 11079 D RtspClient: Session: 1648304005 09:08:35.861 10972 11079 D RtspClient: RTP-Info: url=rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1;seq=39895;rtptime=3842140100 09:08:35.861 10972 11079 D RtspClient: Date: Fri, Jul 14 2023 10:08:34 GMT ```

For some reason, ExoPlayer can't authenticate when sending the second SETUP request during failover. There might be a bug in the camera, but as I got a similar report from two other users, I would like to ask whether there is something that can be done in ExoPlayer to solve this?

Expected result

Video stream is started after 8 seconds thanks to UDP->TCP failover.

Actual result

androidx.media3.exoplayer.rtsp.RtspMediaSource$RtspPlaybackException: SETUP 401 is thrown after 8 seconds.

Media

RTSP stream from HiWatch IP camera

Bug Report

tonihei commented 1 year ago

@claincly Could you take a look? We already have a UDP->TCP failover, but I wonder why it doesn't activate in this case.

claincly commented 1 year ago

I feel this could be an RTSP server issue - looking at the log we transition from UDP to TCP commenting inline

Teardown after playback with UDP is unsuccessful

09:02:19.457 10058 10149 D RtspClient: TEARDOWN rtsp://10.42.111.3:554/Streaming/Channels/102 RTSP/1.0
09:02:19.457 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0
09:02:19.457 10058 10149 D RtspClient: CSeq: 5
09:02:19.457 10058 10149 D RtspClient: Session: 1822977514
09:02:19.457 10058 10149 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="c937caef59e2658b0be8cb51a20670be", uri="rtsp://10.42.111.3:554/Streaming/Channels/102", response="xx"

Trying to setup a track1 with TCP. We don't have the authentication info now, as the previous session is torn down.

09:02:19.482 10058 10149 D RtspClient: SETUP rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1 RTSP/1.0
09:02:19.482 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0
09:02:19.482 10058 10149 D RtspClient: CSeq: 6
09:02:19.482 10058 10149 D RtspClient: Transport: RTP/AVP/TCP;unicast;interleaved=0-1

Server responds with 401, which is expected. Also provides authentication info.

09:02:19.508 10058 10149 D RtspClient: RTSP/1.0 401 Unauthorized
09:02:19.508 10058 10149 D RtspClient: CSeq: 6
09:02:19.508 10058 10149 D RtspClient: WWW-Authenticate: Digest realm="1868cbb42b82", nonce="14dc011bcafd561132ecdcdc645673f3", stale="FALSE"
09:02:19.508 10058 10149 D RtspClient: WWW-Authenticate: Basic realm="1868cbb42b82"
09:02:19.508 10058 10149 D RtspClient: Date: Fri, Jul 14 2023 10:02:17 GMT

We setup track1 again with the new auth info, notice the realm/nonce match the previous server response (CSeq6)

09:02:19.510 10058 10149 D RtspClient: SETUP rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1 RTSP/1.0
09:02:19.510 10058 10149 D RtspClient: User-Agent: AndroidXMedia3/1.1.0
09:02:19.510 10058 10149 D RtspClient: CSeq: 7
09:02:19.510 10058 10149 D RtspClient: Authorization: Digest username="admin", realm="1868cbb42b82", nonce="14dc011bcafd561132ecdcdc645673f3", uri="rtsp://10.42.111.3:554/Streaming/Channels/102/trackID=1", response="xx"
09:02:19.510 10058 10149 D RtspClient: Transport: RTP/AVP/TCP;unicast;interleaved=0-1

This server reply caused failure. But the setup should not fail because it has attached the correct auth info.

09:02:19.536 10058 10149 D RtspClient: RTSP/1.0 401 Unauthorized
09:02:19.536 10058 10149 D RtspClient: CSeq: 7
09:02:19.536 10058 10149 D RtspClient: WWW-Authenticate: Digest realm="1868cbb42b82", nonce="ea3470d26a69ed29e785e29394962dc2", stale="FALSE"
09:02:19.536 10058 10149 D RtspClient: WWW-Authenticate: Basic realm="1868cbb42b82"
09:02:19.536 10058 10149 D RtspClient: Date: Fri, Jul 14 2023 10:02:17 GMT

For the time being, can you always set forceUseRtpTcp to true so that it plays? Also it would be useful to see if VLC plays the content.

milan-fabian commented 1 year ago

VLC plays the content only in case setting Live555 stream transport is set to RTP over RTSP (TCP) (as recommended in https://www.reddit.com/r/reolink/comments/yzhlxp/found_a_solution_for_rtsp_blackno_video_in_vlc/).

If Live555 stream transport is set to HTTP (default), VLC doesn't produce any error, the timestamp is changing each second, but there is no picture and the bitrate in statistics is zero.

I assume VLC doesn't have any failover and RTP over RTSP (TCP) acts basically as an equivalent of forceUseRtpTcp in ExoPlayer.

claincly commented 10 months ago

Maybe VLC is using TCP as a default in the first try - one could confirm that looking at detailed VLC log.

Could you confirm that setting forceUseRtpTcp worked for you?

skogl commented 10 months ago

I'm experiencing something similar with an Ubiquiti camera stream but I have no authentication activated so instead of 401 message I get endless buffering. If I set setForceUseRtpTcp(true) then it works. And I'm behind NAT so it's expected but even after retryWithRtpTcp() it does not seem to be switching over to TCP properly.

milan-fabian commented 10 months ago

Maybe VLC is using TCP as a default in the first try - one could confirm that looking at detailed VLC log.

Could you confirm that setting forceUseRtpTcp worked for you?

Yes, setting forceUseRtpTcp works with the particular RTSP stream

claincly commented 10 months ago

@skogl I think it's at least nice it's working for you. If you have time, could you try log the message exchange between ExoPlayer and the webcam and paste it here? (when setForceUseRtpTcp is false)

The easiest way is to use the RtspMediaSource.Factory method setDebugLoggingEnabled()

That is, set the media source factory when building the ExoPlayer instance, like this:

     ExoPlayer player =
          new ExoPlayer.Builder(/* context= */ this)
              .set... // all other customization
              .setMediaSourceFactory(new RtspMediaSource.Factory().setDebugLoggingEnabled(true))
              .build()
skogl commented 10 months ago

Of course, here it is:

17:55:05.781 16730-16778 RtspClient                           D  OPTIONS rtsp://192.168.x.x:1234/abc RTSP/1.0
                                                                 User-Agent: AndroidXMedia3/1.2.0
                                                                 CSeq: 0
17:55:05.883 16730-16778 RtspClient                           D  RTSP/1.0 200 OK
                                                                 CSeq: 0
                                                                 Cache-Control: no-store
                                                                 Date: Tue, 12 Dec 2023 16:55:07 UTC
                                                                 Expires: Tue, 12 Dec 2023 16:55:07 UTC
                                                                 Pragma: no-cache
                                                                 Public: DESCRIBE, OPTIONS, PAUSE, PLAY, SETUP, TEARDOWN, ANNOUNCE, RECORD
                                                                 Server: EvoStream Media Server (www.evostream.com)
17:55:05.937 16730-16778 RtspClient                           D  DESCRIBE rtsp://192.168.x.x:1234/abc RTSP/1.0
                                                                 User-Agent: AndroidXMedia3/1.2.0
                                                                 CSeq: 1
17:55:07.018 16730-16778 RtspClient                           D  RTSP/1.0 200 OK
                                                                 CSeq: 1
                                                                 Cache-Control: no-store
                                                                 Content-Base: rtsp://192.168.x.x:1234/abc/
                                                                 Content-Length: 592
                                                                 Content-Type: application/sdp
                                                                 Date: Tue, 12 Dec 2023 16:55:08 UTC
                                                                 Expires: Tue, 12 Dec 2023 16:55:08 UTC
                                                                 Pragma: no-cache
                                                                 Server: EvoStream Media Server (www.evostream.com)

                                                                 v=0
                                                                 o=- 505 0 IN IP4 192.168.x.x
                                                                 s=F09FC27FC303_2
                                                                 u=www.evostream.com
                                                                 e=contact@evostream.com
                                                                 c=IN IP4 192.168.x.x
                                                                 t=0 0
                                                                 a=recvonly
                                                                 a=control:*
                                                                 a=range:npt=now-
                                                                 m=audio 0 RTP/AVP 96
                                                                 a=recvonly
                                                                 a=rtpmap:96 mpeg4-generic/11025/1
                                                                 a=control:trackID=1
                                                                 a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1508; SizeLength=13; IndexLength=3; IndexDeltaLength=3;
                                                                 m=video 0 RTP/AVP 97
                                                                 a=recvonly
                                                                 a=control:trackID=2
                                                                 a=rtpmap:97 H264/90000
                                                                 a=fmtp:97 profile-level-id=4d401e; packetization-mode=1; sprop-parameter-sets=Z01AHppkBQF/y/+AXoBfNwEBAUAAAPoAAB1MJQ==,aO48gA==
17:55:07.756 16730-16778 RtspClient                           D  SETUP rtsp://192.168.x.x:1234/abc/trackID=2 RTSP/1.0
                                                                 User-Agent: AndroidXMedia3/1.2.0
                                                                 CSeq: 2
                                                                 Transport: RTP/AVP;unicast;client_port=46768-46769
17:55:08.099 16730-16778 RtspClient                           D  RTSP/1.0 200 OK
                                                                 CSeq: 2
                                                                 Cache-Control: no-store
                                                                 Date: Tue, 12 Dec 2023 16:55:09 UTC
                                                                 Expires: Tue, 12 Dec 2023 16:55:09 UTC
                                                                 Pragma: no-cache
                                                                 Server: EvoStream Media Server (www.evostream.com)
                                                                 Session: Tx8NzBWZ
                                                                 Transport: RTP/AVP/UDP;unicast;source=192.168.x.x;client_port=46768-46769;server_port=60894-60895;ssrc=800029c9
17:55:08.153 16730-16778 RtspClient                           D  SETUP rtsp://192.168.x.x:1234/abc/trackID=1 RTSP/1.0
                                                                 User-Agent: AndroidXMedia3/1.2.0
                                                                 CSeq: 3
                                                                 Session: Tx8NzBWZ
                                                                 Transport: RTP/AVP;unicast;client_port=60350-60351
17:55:08.272 16730-16778 RtspClient                           D  RTSP/1.0 200 OK
                                                                 CSeq: 3
                                                                 Cache-Control: no-store
                                                                 Date: Tue, 12 Dec 2023 16:55:10 UTC
                                                                 Expires: Tue, 12 Dec 2023 16:55:10 UTC
                                                                 Pragma: no-cache
                                                                 Server: EvoStream Media Server (www.evostream.com)
                                                                 Session: Tx8NzBWZ
                                                                 Transport: RTP/AVP/UDP;unicast;source=192.168.x.x;client_port=60350-60351;server_port=60896-60897;ssrc=800029c8
17:55:08.299 16730-16778 RtspClient                           D  PLAY rtsp://192.168.x.x:1234/abc RTSP/1.0
                                                                 User-Agent: AndroidXMedia3/1.2.0
                                                                 CSeq: 4
                                                                 Session: Tx8NzBWZ
                                                                 Range: npt=0.000-
17:55:08.386 16730-16778 RtspClient                           D  RTSP/1.0 200 OK
                                                                 CSeq: 4
                                                                 Cache-Control: no-store
                                                                 Date: Tue, 12 Dec 2023 16:55:10 UTC
                                                                 Expires: Tue, 12 Dec 2023 16:55:10 UTC
                                                                 Pragma: no-cache
                                                                 RTP-Info: url=rtsp://192.168.x.x:1234/abc/trackID=1;seq=17714;rtptime=0,url=rtsp://192.168.x.x:1234/abc/trackID=2;seq=9606;rtptime=0
                                                                 Range: npt=now-
                                                                 Server: EvoStream Media Server (www.evostream.com)
                                                                 Session: Tx8NzBWZ
17:55:15.323 16730-16778 RtspClient                           D  TEARDOWN rtsp://192.168.x.x:1234/abc RTSP/1.0
                                                                 User-Agent: AndroidXMedia3/1.2.0
                                                                 CSeq: 5
                                                                 Session: Tx8NzBWZ
17:55:15.397 16730-16778 RtspClient                           D  SETUP rtsp://192.168.x.x:1234/abc/trackID=1 RTSP/1.0
                                                                 User-Agent: AndroidXMedia3/1.2.0
                                                                 CSeq: 6
                                                                 Transport: RTP/AVP/TCP;unicast;interleaved=0-1
claincly commented 10 months ago

It seems the server never replied to the SETUP request in the TCP retry (that's the last print out in the log you posted), and that will cause the never ending loading you see, (if the log is complete)

skogl commented 10 months ago

I let the "buffering" stay on for a while so it's the end of the log. Are you saying this is an issue with the camera/stream then? Like that it can't handle retries or something?

claincly commented 10 months ago

Yes it seems like the server is the issue here - it doesn't reply to ExoPlayer's SETUP request, this one specifically

17:55:15.397 16730-16778 RtspClient                           D  SETUP rtsp://192.168.x.x:1234/abc/trackID=1 RTSP/1.0
                                                                 User-Agent: AndroidXMedia3/1.2.0
                                                                 CSeq: 6
                                                                 Transport: RTP/AVP/TCP;unicast;interleaved=0-1
skogl commented 10 months ago

Considering the existence of this thread my cameras doesn't seem to be the only ones doing this and I really need for a stable playback and cannot always assume that TCP should be used over UDP so the existence (if working) of the retryWithRtpTcp is great.

I haven't read up on RTSP protocol but my guess is that the camera's rtsp service has some kind of state engine that does not allow a new SETUP being sent immediately after TEARDOWN. What does the specs say? Should this be allowed or should we have to start from the beginning with a new OPTIONS command?

claincly commented 10 months ago

The fact ExoPlayer retried means UDP cannot be used to playback this stream, this is usually because the camera or the player is behind NATs.

In fact the server didn't even respond to the TEARDOWN. And yes, SETUP after TEARDOWN is allowed (https://datatracker.ietf.org/doc/html/rfc2326#appendix-A.2)

skogl commented 10 months ago

Absolutely, it's in NAT network and I really would like it to work by retrying with TCP.

You are correct, isn't it strange that it doesn't respond to TEARDOWN? I'll look into the camera server and see if I can find some logs.

claincly commented 10 months ago

We've added the option setForceUseRtpTcp to work around this so it'll set up TCP from the get go. Honestly I think this is probably the only way most RTSP links should work now, as cameras are all behind NATs.

skogl commented 10 months ago

You're probably right. But what about the other way around? What if I've set setForceUseRtpTcp and only udp is supported and not tcp? Is it even possible you think?

claincly commented 10 months ago

I think in theory it's possible - but I doubt any modern RTSP server doesn't support using TCP.

skogl commented 10 months ago

Ok, thank you! I just want to make sure I maintain compatibility even if I use setForceUseRtpTcp.

claincly commented 10 months ago

Glad to help!

I'll close the issue for now, please open another if anything else happens.