Discussion:
How to play MP3 audio buffers
s***@essential.com
2017-07-18 01:24:58 UTC
Permalink
Hi,

I am developing a C++ only library (no java) using the NDK audio library.
One of the functionality I must support is to play MP3 audio buffers (not
files, I already done that).
I can't use mediacodec or another open source decoder (just ndk)

This documentation
(https://developer.android.com/ndk/guides/audio/opensl-for-android.html)
says that I can use the buffer api (Buffer queue data locator) to play PCM
data!
How do you go about playing MP3 audio buffers? Can you point me to a
documentation or an example code?

Thanks in advance.

Regards, Shahriar

P.S. I know this question has been asked before. But I haven't read a
concise answer yet.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/44f4e3a8-e006-4a5f-9d2d-c129bb1633de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Don Turner' via android-ndk
2017-07-18 10:15:53 UTC
Permalink
The NDK has its own extraction and decoding classes: NdkMediaExtractor and
NdkMediaCodec.

Docs
here: https://developer.android.com/ndk/reference/ndk_media_codec_8h.html
Sample code
here: https://github.com/googlesamples/android-ndk/blob/master/native-codec

You'll need to modify the sample code to decode MP3 rather than MP4
(video).

I would advise against using OpenSL ES for MP3 decoding since this
technique has some performance issues.
Post by s***@essential.com
Hi,
I am developing a C++ only library (no java) using the NDK audio library.
One of the functionality I must support is to play MP3 audio buffers (not
files, I already done that).
I can't use mediacodec or another open source decoder (just ndk)
This documentation (
https://developer.android.com/ndk/guides/audio/opensl-for-android.html)
says that I can use the buffer api (Buffer queue data locator) to play
PCM data!
How do you go about playing MP3 audio buffers? Can you point me to a
documentation or an example code?
Thanks in advance.
Regards, Shahriar
P.S. I know this question has been asked before. But I haven't read a
concise answer yet.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/f9a94135-d65f-48e9-a4e4-366b2988a23b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
s***@essential.com
2017-07-18 17:12:54 UTC
Permalink
Hello,

Thanks for the replay. Looking at the header file (NdkMediaExtractor.h) the
API supports either a file or url as the source of data (not a buffer):

media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset, off64_t length);

/**
* Set the URI from which the extractor will read.
*/
media_status_t AMediaExtractor_setDataSource(AMediaExtractor*, const char *location); // TODO support headers



Shahriar
Post by 'Don Turner' via android-ndk
The NDK has its own extraction and decoding classes: NdkMediaExtractor and
NdkMediaCodec.
https://developer.android.com/ndk/reference/ndk_media_codec_8h.html
https://github.com/googlesamples/android-ndk/blob/master/native-codec
You'll need to modify the sample code to decode MP3 rather than MP4
(video).
I would advise against using OpenSL ES for MP3 decoding since this
technique has some performance issues.
Post by s***@essential.com
Hi,
I am developing a C++ only library (no java) using the NDK audio library.
One of the functionality I must support is to play MP3 audio buffers (not
files, I already done that).
I can't use mediacodec or another open source decoder (just ndk)
This documentation (
https://developer.android.com/ndk/guides/audio/opensl-for-android.html)
says that I can use the buffer api (Buffer queue data locator) to play
PCM data!
How do you go about playing MP3 audio buffers? Can you point me to a
documentation or an example code?
Thanks in advance.
Regards, Shahriar
P.S. I know this question has been asked before. But I haven't read a
concise answer yet.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/c8250dae-1e2d-4549-9a8d-2d88e05e65af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Celina Val
2018-05-03 01:08:05 UTC
Permalink
Hi Shahriar,

Did you ever find the solution for your problem? I have the same problem.
The API that Don mentioned is only available for the beta ndk-17 and only
available for API Level 28+. :(

Thanks,
Celina
Post by s***@essential.com
Hello,
Thanks for the replay. Looking at the header file (NdkMediaExtractor.h)
media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor*, int fd, off64_t offset, off64_t length);
/**
* Set the URI from which the extractor will read.
*/
media_status_t AMediaExtractor_setDataSource(AMediaExtractor*, const char *location); // TODO support headers
Shahriar
Post by 'Don Turner' via android-ndk
The NDK has its own extraction and decoding classes: NdkMediaExtractor
and NdkMediaCodec.
https://developer.android.com/ndk/reference/ndk_media_codec_8h.html
https://github.com/googlesamples/android-ndk/blob/master/native-codec
You'll need to modify the sample code to decode MP3 rather than MP4
(video).
I would advise against using OpenSL ES for MP3 decoding since this
technique has some performance issues.
Post by s***@essential.com
Hi,
I am developing a C++ only library (no java) using the NDK audio
library. One of the functionality I must support is to play MP3 audio
buffers (not files, I already done that).
I can't use mediacodec or another open source decoder (just ndk)
This documentation (
https://developer.android.com/ndk/guides/audio/opensl-for-android.html)
says that I can use the buffer api (Buffer queue data locator) to play
PCM data!
How do you go about playing MP3 audio buffers? Can you point me to a
documentation or an example code?
Thanks in advance.
Regards, Shahriar
P.S. I know this question has been asked before. But I haven't read a
concise answer yet.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/6da05d56-7187-4edc-8505-f2f287b4833d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...