Skip to content

Commit

Permalink
ffmpeg: Add support for high resolution audio
Browse files Browse the repository at this point in the history
 * Output interleaved 24-bit (32-bit packed) PCM at up to 192KHz for
   use with PCM offload. Falls back to resampling if disabled.

Change-Id: Ie1bd3066c0459fb99a9d4ff9e28d6a65e234408a
  • Loading branch information
hyperb1iss committed Aug 7, 2014
1 parent 45e0d61 commit 0d37b03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 3 additions & 2 deletions libstagefright/FFmpegExtractor/FFmpegExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ sp<MetaData> FFmpegExtractor::setAudioFormat(AVStream *stream)

meta->setInt32(kKeyChannelCount, avctx->channels);
meta->setInt32(kKeyBitRate, avctx->bit_rate);
meta->setInt32(kKeyBitspersample, avctx->bits_per_coded_sample);
meta->setInt32(kKeySampleBits, avctx->bits_per_coded_sample);
meta->setInt32(kKeySampleRate, avctx->sample_rate);
meta->setInt32(kKeyBlockAlign, avctx->block_align);
meta->setInt32(kKeySampleFormat, avctx->sample_fmt);
Expand Down Expand Up @@ -1601,7 +1601,8 @@ static void adjustMPEG2TSConfidence(AVFormatContext *ic, float *confidence)
codec_id = getCodecId(ic, AVMEDIA_TYPE_AUDIO);
if (codec_id != AV_CODEC_ID_NONE
&& codec_id != AV_CODEC_ID_AAC
&& codec_id != AV_CODEC_ID_PCM_S16LE //FIXME, AV_CODEC_ID_PCM_S24LE, AV_CODEC_ID_PCM_S32LE?
&& codec_id != AV_CODEC_ID_PCM_S16LE
&& codec_id != AV_CODEC_ID_PCM_S24LE
&& codec_id != AV_CODEC_ID_MP1
&& codec_id != AV_CODEC_ID_MP2
&& codec_id != AV_CODEC_ID_MP3) {
Expand Down
20 changes: 15 additions & 5 deletions libstagefright/codecs/ffmpegdec/adec/SoftFFmpegAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "SoftFFmpegAudio"
#include <utils/Log.h>
#include <cutils/properties.h>

#include "SoftFFmpegAudio.h"

Expand Down Expand Up @@ -92,7 +93,12 @@ SoftFFmpegAudio::SoftFFmpegAudio(

setMode(name);

ALOGD("SoftFFmpegAudio component: %s mMode: %d", name, mMode);
char value[PROPERTY_VALUE_MAX] = {0};
property_get("audio.offload.24bit.enable", value, "0");
mHighResAudioEnabled = atoi(value);

ALOGD("SoftFFmpegAudio component: %s mMode: %d mHighResAudioEnabled: %d",
name, mMode, mHighResAudioEnabled);

initPorts();
CHECK_EQ(initDecoder(), (status_t)OK);
Expand Down Expand Up @@ -700,16 +706,20 @@ void SoftFFmpegAudio::adjustAudioParams() {

channels = mCtx->channels;

//4000 <= sampling rate <= 48000
int32_t max_rate = mHighResAudioEnabled ? 192000 : 48000;

//4000 <= sampling rate <= 48000/192000
if (sampling_rate < 4000) {
sampling_rate = 4000;
} else if (sampling_rate > 48000) {
sampling_rate = 48000;
} else if (sampling_rate > max_rate) {
sampling_rate = max_rate;
}

mAudioSrcChannels = mAudioTgtChannels = channels;
mAudioSrcFreq = mAudioTgtFreq = sampling_rate;
mAudioSrcFmt = mAudioTgtFmt = AV_SAMPLE_FMT_S16;
mAudioSrcFmt = mAudioTgtFmt =
(mHighResAudioEnabled && (mCtx->bits_per_coded_sample == 24))
? AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S16;
mAudioSrcChannelLayout = mAudioTgtChannelLayout =
av_get_default_channel_layout(channels);
}
Expand Down
4 changes: 3 additions & 1 deletion libstagefright/codecs/ffmpegdec/adec/SoftFFmpegAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct SoftFFmpegAudio : public SimpleSoftOMXComponent {
kOutputPortIndex = 1,
kNumInputBuffers = 4,
kNumOutputBuffers = 4,
kOutputBufferSize = 4608 * 2
kOutputBufferSize = 9216 * 2
};

enum {
Expand Down Expand Up @@ -129,6 +129,8 @@ struct SoftFFmpegAudio : public SimpleSoftOMXComponent {
enum AVSampleFormat mAudioSrcFmt;
enum AVSampleFormat mAudioTgtFmt;

bool mHighResAudioEnabled;

enum {
NONE,
AWAITING_DISABLED,
Expand Down

0 comments on commit 0d37b03

Please sign in to comment.