Skip to content

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

Description

@milan-fabian

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions