How to get PCM bit depth from MediaCodec decoder output MediaFormat?

151 views Asked by At

I'm decoding an online AAC stream with MediaCodec and trying to play it with AudioTrack. AudioTrack requires an AudioFormat which requires knowing the details of PCM encoding. I was able to get the audio to play correctly by configuring it as ENCODING_PCM_16BIT but is that guaranteed to always be 16-bit PCM encoding? I want to avoid making that assumption.

I would expect MediaCodec.Callback.onOutputFormatChanged to get the encoding information as part of it's MediaFormat parameter, which seems like it should be the case by this https://stackoverflow.com/a/49812393/2399236, but this is all the information I get out of the media format by calling toString() on it:

aac-drc-heavy-compression=1
sample-rate=48000
aac-drc-boost-level=127
aac-drc-output-loudness=-1
mime=audio/raw
channel-count=2
aac-drc-effect-type=3
aac-drc-cut-level=127
aac-encoded-target-level=-1
aac-max-output-channel_count=8
aac-target-ref-level=64
aac-drc-album-mode=0

Should I just assume that it's 16-bit PCM, or is there any way to get that information?

Note: I'm targetting min SDK 28, currently testing in debugger on emulated Pixel 2 API 30.

0

There are 0 answers