google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

rtsp.MediaDescription.getFmtpParametersAsMap failed and crashed. #9114

Closed zhbhhh closed 3 years ago

zhbhhh commented 3 years ago

When I to play RTSP APP crashed

2021-06-25 14:46:52.448 6458-6565/com.rokid.rtspclient E/okid.rtspclien: [qarth_debug:]  get PatchStore::createDisableExceptionQarthFile method fail.
2021-06-25 14:46:52.451 6458-6565/com.rokid.rtspclient E/AndroidRuntime: FATAL EXCEPTION: ExoPlayer:Playback
    Process: com.rokid.rtspclient, PID: 6458
    java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
        at com.google.android.exoplayer2.source.rtsp.MediaDescription.getFmtpParametersAsMap(MediaDescription.java:323)
        at com.google.android.exoplayer2.source.rtsp.RtspMediaTrack.generatePayloadFormat(RtspMediaTrack.java:120)
        at com.google.android.exoplayer2.source.rtsp.RtspMediaTrack.<init>(RtspMediaTrack.java:64)
        at com.google.android.exoplayer2.source.rtsp.RtspClient.buildTrackList(RtspClient.java:291)
        at com.google.android.exoplayer2.source.rtsp.RtspClient.access$1400(RtspClient.java:66)
        at com.google.android.exoplayer2.source.rtsp.RtspClient$MessageListener.onDescribeResponseReceived(RtspClient.java:553)
        at com.google.android.exoplayer2.source.rtsp.RtspClient$MessageListener.handleRtspMessage(RtspClient.java:473)
        at com.google.android.exoplayer2.source.rtsp.RtspClient$MessageListener.lambda$onRtspMessageReceived$0$RtspClient$MessageListener(RtspClient.java:420)
        at com.google.android.exoplayer2.source.rtsp.-$$Lambda$RtspClient$MessageListener$dJPB0r-FyeWq7xUwLx0FyxTnUk0.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:907)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:216)
        at android.os.HandlerThread.run(HandlerThread.java:65)
claincly commented 3 years ago

Please provide a log of RTSP messages.

Add logs at

https://github.com/google/ExoPlayer/blob/b2333c86c1eac9a1f95992960a8495f1e5b79200/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/RtspMessageChannel.java#L182

and

https://github.com/google/ExoPlayer/blob/b2333c86c1eac9a1f95992960a8495f1e5b79200/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/RtspClient.java#L423

The easiest way is to use

Log.d("RTSP", message)

google-oss-bot commented 3 years ago

Hey @zhbhhh. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

colinbarr commented 3 years ago

I've also come across the same exception as shown above, and (at least in my case) it appears to be related to RTSP implementations not strictly adhering to section 4.4.1 of RFC3640. I was attempting to stream from UniFi Protect, which looks to be running an embedded version of EvoStream Media Server.

From a packet capture, I can see that there's a trailing semicolon on the a=fmtp line as shown below:

a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1408; SizeLength=13; IndexLength=3; IndexDeltaLength=3;

... which then causes the following line to have an empty string as the last array element: https://github.com/google/ExoPlayer/blob/80332f7f1be7f0ea59440b4888560d228f405789/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/MediaDescription.java#L318

...which then means parameterPair is a single element array, resulting in an out of bounds exception when attempting to access [1]: https://github.com/google/ExoPlayer/blob/80332f7f1be7f0ea59440b4888560d228f405789/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/MediaDescription.java#L322-L323

Although the following format definition does not indicate trailing semicolons are permitted, RFC5691 (section 4.1) does contain an example where a trailing delimiter is present, so there are likely other implementations where this is the case.

a=fmtp:<format> <parameter name>=<value>[; <parameter name>=<value>]

I'm happy to submit a PR for this to optionally handle a trailing ;, if it's acceptable to deviate slightly from the RFC?

claincly commented 3 years ago

Thanks for providing the detail!

Handling the extra semicolon seems straightforward in this case. For now I don't think we have the intention for support all slightly erroneous RTSP servers. That said, please submit a PR if there are more people complaining about this specific issue.

colinbarr commented 3 years ago

Thanks @claincly, I've submitted https://github.com/google/ExoPlayer/pull/9247!