The following code generates java.lang.IllegalStateException once in a while:
int iInputBufIndex = _mcDecoder.dequeueInputBuffer(TIMEOUT_USEC);
where _mcDecoder is an instance of MediaCodec. The decoded stream is H.264 video. The code works well most of the time. Is there a way to check the state of MediaCodec proactively to avoid this exception?
The stack trace:
java.lang.IllegalStateException
at android.media.MediaCodec.dequeueInputBuffer(Native Method)
at net.mydomain.android.MYNAMESPACE.MYCLASS.MyMethod0(Unknown Source)
at net.mydomain.android.MYNAMESPACE.MYCLASS.ProcessH264(Unknown Source)
at net.mydomain.android.MYNAMESPACE.MYCLASS.MyMethod1(Unknown Source)
at net.mydomain.android.MYNAMESPACE.MYCLASS.MyMethod2(Unknown Source)
at net.mydomain.android.MYNAMESPACE.MYCLASS.MyMethod3(Unknown Source)
at net.mydomain.android.MYNAMESPACE.MYCLASS.access$5(Unknown Source)
at net.mydomain.android.MYNAMESPACE.MYCLASS$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:841)
This exception is thrown if the codec internally has returned an error. This can e.g. be caused by an erroneous bitstream (although the decoders mostly should handle that I think) or perhaps by passing packets incorrectly. (Trying to decode interlaced H.264 video via MediaCodec on modern Qualcomm chipsets also causes the object to get into the error state, see e.g. https://code.google.com/p/android/issues/detail?id=72336 - and this one is particularly nasty because it crashes the whole process when trying to shut down the codec.)
There's no way of knowing that this has happened (other than perhaps reading the system log) other than noticing the exceptions. (Perhaps that'd be a good addition as a new API?) I'm not quite sure if it ever works to just keep on trying to feed the decoder if it would manage to recover, or if it's a lost cause and the whole decoder should be closed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With