diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2012-03-02 14:54:07 -0800 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2012-03-02 17:26:49 -0800 |
commit | 4ed260feda32f6c51dd018e1c012e39aa63e61d4 (patch) | |
tree | 92aad9d9328987cc7b44e039f3f04695fd802e3c /media/libstagefright | |
parent | e6e47f0517b98055625abc21a85eaa702374495a (diff) | |
download | frameworks_base-4ed260feda32f6c51dd018e1c012e39aa63e61d4.zip frameworks_base-4ed260feda32f6c51dd018e1c012e39aa63e61d4.tar.gz frameworks_base-4ed260feda32f6c51dd018e1c012e39aa63e61d4.tar.bz2 |
Add channel mask in AudioSink
Add support for specifying a channel mask when opening an AudioSink.
This parameter does not replace the channel count parameter in order
to not have to duplicate the logic to derive a mask from the
channel count everywhere an AudioSink is used without a known mask.
A mask of 0 (CHANNEL_MASK_USE_CHANNEL_ORDER) means a mask will
be automatically derived from the number of channels.
Update existing AudioSink implementations to use the channel mask,
and users of AudioSink to specify the mask if available, and
CHANNEL_MASK_USE_CHANNEL_ORDER otherwise.
Change-Id: Ifa9bd259874816dbc25ead2b03ea52e873cff474
Diffstat (limited to 'media/libstagefright')
-rw-r--r-- | media/libstagefright/AudioPlayer.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp index df27566..9427ef7 100644 --- a/media/libstagefright/AudioPlayer.cpp +++ b/media/libstagefright/AudioPlayer.cpp @@ -110,13 +110,18 @@ status_t AudioPlayer::start(bool sourceAlreadyStarted) { success = format->findInt32(kKeySampleRate, &mSampleRate); CHECK(success); - int32_t numChannels; + int32_t numChannels, channelMask; success = format->findInt32(kKeyChannelCount, &numChannels); CHECK(success); + if(!format->findInt32(kKeyChannelMask, &channelMask)) { + ALOGW("source format didn't specify channel mask, using channel order"); + channelMask = CHANNEL_MASK_USE_CHANNEL_ORDER; + } + if (mAudioSink.get() != NULL) { status_t err = mAudioSink->open( - mSampleRate, numChannels, AUDIO_FORMAT_PCM_16_BIT, + mSampleRate, numChannels, channelMask, AUDIO_FORMAT_PCM_16_BIT, DEFAULT_AUDIOSINK_BUFFERCOUNT, &AudioPlayer::AudioSinkCallback, this); if (err != OK) { @@ -137,11 +142,15 @@ status_t AudioPlayer::start(bool sourceAlreadyStarted) { mAudioSink->start(); } else { + // playing to an AudioTrack, set up mask if necessary + audio_channel_mask_t audioMask = channelMask == CHANNEL_MASK_USE_CHANNEL_ORDER ? + audio_channel_mask_from_count(numChannels) : channelMask; + if (0 == audioMask) { + return BAD_VALUE; + } + mAudioTrack = new AudioTrack( - AUDIO_STREAM_MUSIC, mSampleRate, AUDIO_FORMAT_PCM_16_BIT, - (numChannels == 2) - ? AUDIO_CHANNEL_OUT_STEREO - : AUDIO_CHANNEL_OUT_MONO, + AUDIO_STREAM_MUSIC, mSampleRate, AUDIO_FORMAT_PCM_16_BIT, audioMask, 0, 0, &AudioCallback, this, 0); if ((err = mAudioTrack->initCheck()) != OK) { |