I need to decode data from interleave stream (like AVI).
So, it is means that I have a container that build in such shape(sequence)
mp4 --> other data --> mp4 --> other data --> so on...
For this moment I have a basic implementation of MediaCodec
decoder. I have MediaExtractor
where I call setDataSource()
and it get mp4 file uri as param. Then in order to get a decode result I need queue/dequeue buffer.
So, it means that byte producer is MediaExtractor
which know how to extract bytes from uri.
But in my purpose I have a file(container), that consist a few types of data in sequence...
What I want to do - I will read just a mp4 chunk(one video frame) and then I need to pass this chunk(frame) to MediaCodec
to process with decoding. I want to be a supplier myself.
So, question is how to pass byte buffer to MediaCodec
in order to process with decoding?
P.S. There is still no decision if our interleave container will have each mp4 chunk as separate mp4 file (including headers), or just first frame in sequence...
Or maybe for this reason I need to use ffmpeg lib?
I hope I didn't miss noting anyway feel free to ask
EDIT
Meanwhile I found such solution (not final)
AMediaExtractor *ex = AMediaExtractor_new();
FILE *fp = fopen(filename.c_str(), "rb");
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
fseek(fp, 0, SEEK_SET);
auto err = AMediaExtractor_setDataSourceFd(ex, fileno(fp), 0, size);
setDataSourceFd()
this method knows how to work with file descriptor. He get such params as extractor, descriptor, offset and size of data.
So in my case as I told I have such data sequence
mp4 --> other data --> mp4 --> other data --> so on...
Let's first mp4 data starts at the begging, so it is means no offset, so setDataSourceFd(ex, fileno(fp), 0, dataSize), let's say second mp4 data starts after 5000 bytes... so
setDataSourceFd(ex, fileno(fp), 5000, dataSize)
It is means that if you have for exapmle 3000 mp4 parts everytime you need to create new MediaExtractor
and setDataSourceFd()
...
I am not sure if it is a right way to make it...