5

I am trying to stream incoming AMR_NB. I can't use MediaPlayer directly because it requires a seekable file. I would like to use MediaCodec, but to use MediaCodec I need (I think... please correct me!) MediaExtractor to give me things like the presentationTime. Is that true? Can I use MediaCodec without MediaExtractor?

MediaExtractor seems to require seekable files. The documentation only specifically says so for one of the setDataSource operations but when I tried to use any of the others it failed due to failed seek attempts.

So, what can I do to get my incoming AMR stream to play? I am aware of a scheme where by you save incoming data to a file and periodically make a copy of that file to feed to MediaPlayer but I'd really prefer to find a real honest streaming solution.

Is it possible to use MediaCodec without using MediaExtractor? If so how do I find presentation time and the string to pass to MediaCodec.createDecoderByType? The documentation SAYS that "audio/3gpp" is what I want but when I attempt to use that I get the following error:

codec = MediaCodec.createDecoderByType("audio/3gpp");

01-02 03:59:36.980: E/OMXMaster(21605): A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one.

So I'm not sure how to get at MediaCodec either.

djc6535
  • 1,944
  • 4
  • 18
  • 26
  • Something has to identify the NAL (https://stackoverflow.com/a/24890903/294248) units. If you start with a .mp4, that means splitting out the elementary streams, and then parsing the video stream into packets. Normally MediaExtractor does this. MediaExtractor and MediaCodec don't talk to each other; your code passes the output of ME into MC (see e.g. all examples on bigflake.com/mediacodec). If you want to replace ME with your own code that finds NAL units and PTS values, you can. The source code for MediaExtractor is part of AOSP, so you can clone that and modify it how you want. – Sirop4ik Sep 19 '19 at 10:05

1 Answers1

0

"I can't use MediaPlayer directly because it requires a seekable file" This is not generally true. I would like you to try it on your stream and report exactly what happens.

"Can I use MediaCodec without MediaExtractor?" I doubt it: I believe they are designed to be used together.

I have used these components to play streams. However, the MediaExtractor has limitations that are not documented ( as far as I know ). So use a little proxy server to feed it things it can digest. And I have 1 thread to run the MediaExtractor and another to take output from the the MediaCodec. Then i have to avoid deadlocks and cope with snchronization. But it is not that bad provided you just want to play forwards only. Then you have only the problem of how to stop!

I advise that you try MediaPlayer first. Otherwise, if you are keen enough to try the MediaExtractor, we could share our discoveries about what it will and wont digest. Don't take anything for granted. For example it seems it will play my MP3 files, but cannot discover their duration, or seek on them!

  • I did try it on my stream: The result was a failure on the 'Set data source' when 'seek' failed. I fed it the file descriptor taken from a socket. Have you tried this? Numerous other stack overflow discussions I've run into all seem to indicate that it is generally true. – djc6535 Jan 31 '13 at 18:08
  • I've run into this also, I wish that the MediaExtractor could take a byte array / buffer as a data source. – Paul Gregoire Aug 04 '13 at 17:01