Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple MediaCodec instances

i made a Video Player using the MediaCodec library, and i wanted to add a playlist feature. I tried to have two instances of MediaCodec in order to make a smoother transition between two consecutive videos, however this seems to be dangerous, in some devices (i tried an S4 with cyanogen) it worked perfectly, however in a S4 with TouchWiz the same code crashed on the Media Codec declaration. This is the code snippet:

 MediaExtractor extractor = new MediaExtractor();
 extractor.setDataSource(path1);

 MediaFormat format = extractor.getTrackFormat(0);
 String mime = format.getString(MediaFormat.KEY_MIME);

 extractor.selectTrack(0);
 MediaCodec decoder = MediaCodec.createDecoderByType(mime);
 decoder.configure(format, null, null, 0);

 MediaExtractor extractor2 = new MediaExtractor();
 extractor2.setDataSource(path2);

 MediaFormat format2 = extractor2.getTrackFormat(0);
 String mime2 = format.getString(MediaFormat.KEY_MIME);

 extractor2.selectTrack(0);
 MediaCodec decoder2 = MediaCodec.createDecoderByType(mime2);
 decoder2.configure(format2, null, null, 0);

and the exception i got on the TouchWiz S4 is

E/ACodec(17651):  configureCodec multi window instance fail  appPid : 17651
E/ACodec(17651): [OMX.qcom.video.decoder.avc] configureCodec returning error -38
E/MediaCodec(17651): Codec reported an error. (omx error 0x80001001, internalError -38)

Can anyone point me some guidelines on how to do this correctly? Maybe different threads? I really would like to make a smooth transition between different videos, but i need it to work consistently in some devices at least.

Thanks a lot

like image 550
roimatola Avatar asked Oct 31 '13 20:10

roimatola


People also ask

What is Android MediaCodec?

MediaCodec class can be used to access low-level media codecs, i.e. encoder/decoder components. It is part of the Android low-level multimedia support infrastructure (normally used together with MediaExtractor , MediaSync , MediaMuxer , MediaCrypto , MediaDrm , Image , Surface , and AudioTrack .)

How does MediaCodec work?

It processes data asynchronously and uses a set of input and output buffers. At a simplistic level, you request (or receive) an empty input buffer, fill it up with data and send it to the codec for processing. The codec uses up the data and transforms it into one of its empty output buffers.

What is a media codec?

A codec is a hardware- or software-based process that compresses and decompresses large amounts of data. Codecs are used in applications to play and create media files for users, as well as to send media files over a network. The term is a blend of the words coder and decoder, as well as compression and decompression.


1 Answers

From my experience, your issue appears when there are not enough resources so that two instances of the same codec are created. For example, I got it on S3 when trying to configure two 1080p, h264 decoders in parallel, but having one 720p and one 1080p, or two 720p decoders, run just fine. What you could do, although no solution is perfect:

  • The obvious one, in those situations wait for first codec to finish and only then configure the second one.

  • Search the decoders list for an alternative decoder for the same file. This may work on some devices, but on others not or it just finds a sw decoder which might not decode realtime (as is the case on S3)

like image 200
user1592546 Avatar answered Oct 28 '22 07:10

user1592546