Android MediaCodec Format / Resolution Change Average Stream
I am processing a live stream through MediaCodec
and have a scenario where the MediaFormat
average stream changes (i.e. the resolution of the video change being decoded). Given that I attach a decoder to Surface
to render it, as soon as I detect a resolution change in the incoming stream, I recreate the decoder before feeding it a new resolution buffer (giving it a new one MediaFormat
).
I am getting some weird errors that don't give me too much information about what might be wrong, i.e. when called MediaCodec.configure
with a new format and the same Surface
:
android.media.MediaCodec$CodecException: Error 0xffffffea
at android.media.MediaCodec.native_configure(Native Method)
at android.media.MediaCodec.configure(MediaCodec.java:577)
That when retrieving CodecException.getDiagnosticInfo
it doesn't show anything, which I can actually use to understand the reason for the failure:android.media.MediaCodec.error_neg_22
I also noted the following in the logs and found some related information and I am wondering if there is something I need to do in regards to myself Surface
(for example, detaching it from the old decoder instance passing it on to the new one):
07-09 15:00:17.217 E/BufferQueueProducer( 139): [SurfaceView] connect(P): already connected (cur=3 req=3)
07-09 15:00:17.217 E/MediaCodec( 5388): native_window_api_connect returned an error: Invalid argument (-22)
07-09 15:00:17.218 E/MediaCodec( 5388): configure failed with err 0xffffffea, resetting...
source to share
Looks like calling stop()
and release()
, as well as reinitializing any links I had on getInputBuffers()
and getOutputBuffers()
, and the trick. At least I don't get any more messages / exceptions. Now I just need to figure out the reference part Surface
, as it seems that the resized stream (when resizing the resolution) still fits into the original dimensions of the surface, not to adjust the surface for the new resolution.
source to share