2

I have used MediaCodec for playing avc video files. now I am trying to play video from a stream, I couldn't find any example or good documentations regarding using MediaCodec for adaptive streaming. I was wondering if anyone can lead me to a good example or just post what I need to do?

some code:

...
codec = MediaCodec.createDecoderByType(type);
format = new MediaFormat();
format.setString(MediaFormat.KEY_MIME, type);
format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, track.getInt("maxsize"));
format.setInteger(MediaFormat.KEY_WIDTH, videoWidth);
format.setInteger(MediaFormat.KEY_HEIGHT, videoHeight);
format.setInteger(MediaFormat.KEY_MAX_WIDTH, videoWidth);
format.setInteger(MediaFormat.KEY_MAX_HEIGHT, videoHeight);
...
mSurface = new Surface(mSurfaceTexture);
codec.configure(format, mSurface, null, 0);
codec.start();
...

Notice that I don't have csd-0 and csd1 at init time, I'd like to submit them after the codec is started. How can I do that?

now when I call

int index = codec.dequeueInputBuffer(timeout * 1000);

index is always -1.

Any help would be appreciated.

Saeid Farivar
  • 1,667
  • 24
  • 43
  • @fadden I was wondering if you could give me some lead on this? – Saeid Farivar Apr 24 '16 at 20:49
  • why is "adaptive" relevant for incoming stream? – Alex Cohn Apr 24 '16 at 21:26
  • @AlexCohn because the frame size can change, so the codec specific data (csd0 and csd1) should be handled once this happened. I might be wrong? – Saeid Farivar Apr 25 '16 at 00:19
  • 2
    Instead of passing the csd-0 and csd-1 at init via `MediaFormat`, you can provide them (both concatenated in one buffer) via `queueInputBuffer` by including `BUFFER_FLAG_CODEC_CONFIG` in the `flags` parameter. – mstorsjo Apr 25 '16 at 06:53
  • 2
    But in general, you can only rely on a decoder supporting resolution changes on the fly if it has got `FEATURE_AdaptivePlayback` set in the `MediaCodecInfo.CodecCapabilities`. If not, you need to close and reinitialize the decoder once you get the new csd-0 and csd-1 data. – mstorsjo Apr 25 '16 at 06:55
  • @mstorsjo could you elaborate on how do I use queueInputBuffer when the index that I get from dequeueInputBuffer is -1? and yes the decoder that I am using supports FEATURE_AdaptivePlayback. – Saeid Farivar Apr 25 '16 at 14:46
  • @AlexCohn see "Seeking & Adaptive Playback Support" on http://developer.android.com/reference/android/media/MediaCodec.html . – fadden Apr 25 '16 at 20:01
  • @mstorsjo, I ended up not initializing/starting the codec until the first config packet is arrived. then the dequeued index is not -1 anymore, and I can push new config packets using the flag that you suggested. I still would like to know how I can start the codec without passing csd-0? – Saeid Farivar Apr 27 '16 at 17:17

0 Answers0