ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

CryptoException thrown when attempting to begin playback from middle of video

Open jschools opened this issue 10 years ago • 9 comments

I am experiencing an issue in my application when attempting to begin playback from somewhere other than the beginning of a video asset. It seems to be related to the secure avc decoder on some devices. This issue may be related to https://github.com/google/ExoPlayer/issues/603.

When seekTo is called before the first frame of video is visible, the player sometimes throws the following exception:

E/EventLogger: Internal track renderer error.
    com.google.android.exoplayer.ExoPlaybackException: android.media.MediaCodec$CryptoException: Unknown Error
      at com.google.android.exoplayer.MediaCodecTrackRenderer.feedInputBuffer(MediaCodecTrackRenderer.java:680)
      at com.google.android.exoplayer.MediaCodecTrackRenderer.doSomeWork(MediaCodecTrackRenderer.java:492)
      at com.google.android.exoplayer.SampleSourceTrackRenderer.doSomeWork(SampleSourceTrackRenderer.java:129)
      at com.google.android.exoplayer.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:431)
      at com.google.android.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:213)
      at android.os.Handler.dispatchMessage(Handler.java:98)
      at android.os.Looper.loop(Looper.java:148)
      at android.os.HandlerThread.run(HandlerThread.java:61)
      at com.google.android.exoplayer.util.PriorityHandlerThread.run(PriorityHandlerThread.java:40)
    Caused by: android.media.MediaCodec$CryptoException: Unknown Error
      at android.media.MediaCodec.native_queueSecureInputBuffer(Native Method)
      at android.media.MediaCodec.queueSecureInputBuffer(MediaCodec.java:2305)
      at com.google.android.exoplayer.MediaCodecTrackRenderer.feedInputBuffer(MediaCodecTrackRenderer.java:670)
      at com.google.android.exoplayer.MediaCodecTrackRenderer.doSomeWork(MediaCodecTrackRenderer.java:492) 
      at com.google.android.exoplayer.SampleSourceTrackRenderer.doSomeWork(SampleSourceTrackRenderer.java:129) 
      at com.google.android.exoplayer.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:431) 
      at com.google.android.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:213) 
      at android.os.Handler.dispatchMessage(Handler.java:98) 
      at android.os.Looper.loop(Looper.java:148) 
      at android.os.HandlerThread.run(HandlerThread.java:61) 
      at com.google.android.exoplayer.util.PriorityHandlerThread.run(PriorityHandlerThread.java:40) 

Steps to reproduce:

  • Build ExoPlayer Demo app at r1.5.6 tag
  • Launch app and play "WV: Secure SD & HD (MP4,H264)"
  • Seek somewhere in the middle of the video
  • Allow video to play for a few seconds
  • Without pausing, press device Home button
  • Tap Recent Apps button and tap the player activity

Alternate steps (more difficult to reproduce):

  • Launch app and tap "WV: Secure SD & HD (MP4,H264)"
  • Before a single video frame is visible, immediately tap twice quickly near the bottom of the screen where the SeekBar is: once to show the SeekBar and once to seek somewhere in the middle

Expected outcome: Video continues to play Actual outcome: Video fails to play and Retry button appears in player chrome. Exception is thrown in log.

Works as expected on these devices:

  • Nexus 6 (6.0.1/MMB29Q)
  • Nexus 5X (6.0.1/MMB29Q)
  • Nexus 9 (6.0.1/MMB29S)
  • Sony Xperia Z3 D6603 (5.1.1/23.4.A.1.232)
  • Galaxy Nexus (4.3/JWR66Y)

Fails on these devices:

  • AT&T Moto X 2nd Gen (5.1/LPE23.32-21.9)
  • Samsung Galaxy Note 4 (5.1.1/LMY47X)
  • Samsung Galaxy S6 Active (5.0.2/LRX22G.G890AUCU2AOF3)
  • LG G4 (6.0/MRA58K)

Notes:

  • Tapping the Retry button in the demo app sometimes causes playback to resume successfully. It usually takes about 4 or 5 retries before it works.
  • Sometimes, letting the demo player sit in the error/idle state for a few minutes will cause the video to miraculously start playing again (maybe a load is timing out in the background?)
  • Rebooting the device seems to stop the issue for a few hours. Not sure if attempting to play many videos causes the issue.
  • Even when codecNeedsFlushWorkaround is changed to always return true so that the workaround referenced in https://github.com/google/ExoPlayer/issues/603 is used for all devices, the error occurs.
  • I have never been able to reproduce the issue using the unprotected version of the video.
  • The issue occurs on both devices with "OMX.Exynos.avc.dec.secure" and devices with "OMX.qcom.video.decoder.avc.secure" decoders.
  • On some devices, the message "Decrypt error result in session sid3 during encrypted block: 1" is written to the logs.

Bugreports attached: exoplayer_seek_issue_bugreports.zip

jschools avatar Feb 23 '16 20:02 jschools

Thanks for the detailed report. I tried to reproduce this with a Galaxy Note 4 running LMY47X, using the first set of steps that you describe in the demo app. Playback resumed successfully in all cases for me.

Does it definitely reproduce reliably on Galaxy Note 4? Is it 100% reproducible for you? Could you provide a bug report taken from that device, since that'll be most similar to the device I'm trying with. Thanks!

ojw28 avatar Feb 24 '16 12:02 ojw28

I guess "Rebooting the device seems to stop the issue for a few hours. Not sure if attempting to play many videos causes the issue." could explain why I'm currently unable to reproduce, given I've only just turned the device on.

ojw28 avatar Feb 24 '16 12:02 ojw28

It was much harder to reproduce, but I finally got a bug report on the Note 4. Interrupting the player in various states by forcing the surface to be destroyed and recreated seems to make it more likely to fail, such as pressing Home and resuming or hitting the Recent Apps button. I also added some code to suck up CPU cycles on the main thread, which is what finally did it.

exoplayer_seek_issue_samsung_note4.txt.zip

jschools avatar Feb 24 '16 18:02 jschools

Any progress on this? I just got this issue on Nexus Player with 1.5.10 (it seems to be in the start of the media, seeking a few minutes and there's no problem). Our media is DASH with widevine.

gvidda avatar Aug 22 '16 09:08 gvidda

Have a similar issue with com.devbrackets.android:exomedia:3.0.1 on a rk3188 running 4.4.2. Wether i'm calling restart, start or seekTo in my setOnCompletionListener() the video is just played once and doesn't playback on completion. The VideoView seems not to be able to find the video any more and shows the inProgress animation. Appreciate any suggestions.

Greatings

Btw: By calling seekTo(0) the progress bar will be changed to the start but the video still isn't loading. Nore by calling start() after seeking O_o

ghost avatar Sep 30 '16 11:09 ghost

The logs do not provide a lot of information, but things look to be working as intended. There is a timing issue, in both the logs for 'G4' and in the 'Note 4'. There is a decrypt call as keys are being loaded. This can/will cause decrypt errors.

There are methods to determine when keys are available for decrypt, these are include in API #23 and newer. Register for MediaDRM.OnKeyStatusChangeListener.

wvpaf avatar Feb 14 '17 23:02 wvpaf

@wvpaf - After ExoPlayer calls MediaDrm.provideKeyResponse, it assumes that the keys provided will be available straight away. Are you saying that's not the case (i.e. that MediaDrm.provideKeyResponse is asynchronous and we need to wait for a callback)? Where is that documented if so, and how can we know when the keys become available prior to API level 23? If not, then I'm not quite sure what "being loaded" means. Could you clarify? Thanks.

ojw28 avatar Feb 15 '17 00:02 ojw28

Co-ask and wait for clarification.

linhai326 avatar Mar 03 '17 00:03 linhai326

MediaDrm.provideKeyResponse is synchronous and keys will be available before the call returns for all API levels where WV is present. If decrypt is called before provideKeyResponse returns this will result in CryptoException.

Hope this helps.

wvpaf avatar Mar 14 '17 22:03 wvpaf