Android : How do we test the end of stream in MediaCodec decoding in Android?

on Sunday, March 29, 2015


I have the following code



While(true){
....
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
if (!endOfStream) {
Log.w(TAG, "reached end of stream unexpectedly");
} else {
Log.d(TAG, "end of stream reached");
}
break; // out of while
}
}


The above condition "bufferInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0" doesn't work for me.


On Android Deveopers site, I see: "Buffer flags associated with the buffer. A combination of BUFFER_FLAG_KEY_FRAME and BUFFER_FLAG_END_OF_STREAM." However, BUFFER_FLAG_KEY_FRAME is added on API level 21.


On my test phone, the bufferInfo.flags value is always 0, I'm not sure if it's because my phone's API level is 19, which makes BUFFER_FLAG_KEY_FRAME constant unavailable and in turn makes the bufferInfo.flags value 0.


So how can we detect the end of stream?


Thank you so much in advance.


0 comments:

Post a Comment