Roberto Andrade Roberto Andrade - 1 year ago 409
Android Question

Android MediaCodec Format/Resolution Change mid-stream

I'm processing a live stream via

and have a scenario where the
changes mid-stream (ie: resolution of the video being decoded changes). Given I'm attaching the decoder to a
to render it as soon as I detect the change in resolution on the incoming stream I recreate the decoder before feeding it the new resolution buffer (providing it with the proper new

I've been getting some weird errors which don't give me too much info as to what could be wrong, ie when calling
with the new format and same
:$CodecException: Error 0xffffffea
at Method)

Which when fetching the
it shows nothing that I can really use to understand the reason for the failure:

I've also noted the following on the logs and found some related information and am wondering if there's something I need to do regarding the
itself (like detaching it from the old instance of the decoder being giving it 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...

Answer Source

Looks like calling stop() and release() as well as reinitializing any references I had to the getInputBuffers() and getOutputBuffers() did the trick. At least I don't get the messages/exceptions anymore. Now I just need to figure out the Surface reference part as it seems the resized stream (when resolution changes) is still being fit in the original surface dimensions instead of adjusting the Surface for the new resolution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download