6

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

fadden
  • 51,356
  • 5
  • 116
  • 166
roimatola
  • 115
  • 2
  • 8

2 Answers2

4

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)

user1592546
  • 1,480
  • 1
  • 14
  • 30
0

You are using the same extractor instance for format2: MediaFormat format2 = >> extractor <<.getTrackFormat(0);

Were you able to get more than one MediaExtractors running at the same time?

Vin Kemp
  • 301
  • 3
  • 6