diff options
| author | 2018-12-11 17:03:58 +0000 | |
|---|---|---|
| committer | 2018-12-11 17:03:58 +0000 | |
| commit | 47b82309d428bf4424ae9722bf61e0dea6a7fef8 (patch) | |
| tree | d5423f6324c49dc71a2b76d1296b6e5406ac0688 | |
| parent | 8a8430bff0fe521a7e866b4963cafa81eab7019f (diff) | |
| parent | a0129612ed5a335de8838f88ddddfaf948a5993c (diff) | |
Merge "Add channel mask in SoundPool sample."
| -rw-r--r-- | media/jni/soundpool/SoundPool.cpp | 17 | ||||
| -rw-r--r-- | media/jni/soundpool/SoundPool.h | 26 |
2 files changed, 28 insertions, 15 deletions
diff --git a/media/jni/soundpool/SoundPool.cpp b/media/jni/soundpool/SoundPool.cpp index ed2afdd84a7c..5f513207bd5f 100644 --- a/media/jni/soundpool/SoundPool.cpp +++ b/media/jni/soundpool/SoundPool.cpp @@ -513,7 +513,8 @@ Sample::~Sample() static status_t decode(int fd, int64_t offset, int64_t length, uint32_t *rate, int *numChannels, audio_format_t *audioFormat, - sp<MemoryHeapBase> heap, size_t *memsize) { + audio_channel_mask_t *channelMask, sp<MemoryHeapBase> heap, + size_t *memsize) { ALOGV("fd %d, offset %" PRId64 ", size %" PRId64, fd, offset, length); AMediaExtractor *ex = AMediaExtractor_new(); @@ -650,6 +651,10 @@ static status_t decode(int fd, int64_t offset, int64_t length, (void)AMediaFormat_delete(format); return UNKNOWN_ERROR; } + if (!AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_CHANNEL_MASK, + (int32_t*) channelMask)) { + *channelMask = AUDIO_CHANNEL_NONE; + } (void)AMediaFormat_delete(format); *memsize = written; return OK; @@ -665,12 +670,13 @@ status_t Sample::doLoad() uint32_t sampleRate; int numChannels; audio_format_t format; + audio_channel_mask_t channelMask; status_t status; mHeap = new MemoryHeapBase(kDefaultHeapSize); ALOGV("Start decode"); status = decode(mFd, mOffset, mLength, &sampleRate, &numChannels, &format, - mHeap, &mSize); + &channelMask, mHeap, &mSize); ALOGV("close(%d)", mFd); ::close(mFd); mFd = -1; @@ -697,6 +703,7 @@ status_t Sample::doLoad() mSampleRate = sampleRate; mNumChannels = numChannels; mFormat = format; + mChannelMask = channelMask; mState = READY; return NO_ERROR; @@ -781,7 +788,11 @@ void SoundChannel::play(const sp<Sample>& sample, int nextChannelID, float leftV // wrong audio audio buffer size (mAudioBufferSize) unsigned long toggle = mToggle ^ 1; void *userData = (void *)((unsigned long)this | toggle); - audio_channel_mask_t channelMask = audio_channel_out_mask_from_count(numChannels); + audio_channel_mask_t sampleChannelMask = sample->channelMask(); + // When sample contains a not none channel mask, use it as is. + // Otherwise, use channel count to calculate channel mask. + audio_channel_mask_t channelMask = sampleChannelMask != AUDIO_CHANNEL_NONE + ? sampleChannelMask : audio_channel_out_mask_from_count(numChannels); // do not create a new audio track if current track is compatible with sample parameters #ifdef USE_SHARED_MEM_BUFFER diff --git a/media/jni/soundpool/SoundPool.h b/media/jni/soundpool/SoundPool.h index 5c48a907c832..9d7410305c2c 100644 --- a/media/jni/soundpool/SoundPool.h +++ b/media/jni/soundpool/SoundPool.h @@ -58,6 +58,7 @@ public: int numChannels() { return mNumChannels; } int sampleRate() { return mSampleRate; } audio_format_t format() { return mFormat; } + audio_channel_mask_t channelMask() { return mChannelMask; } size_t size() { return mSize; } int state() { return mState; } uint8_t* data() { return static_cast<uint8_t*>(mData->pointer()); } @@ -68,18 +69,19 @@ public: private: void init(); - size_t mSize; - volatile int32_t mRefCount; - uint16_t mSampleID; - uint16_t mSampleRate; - uint8_t mState; - uint8_t mNumChannels; - audio_format_t mFormat; - int mFd; - int64_t mOffset; - int64_t mLength; - sp<IMemory> mData; - sp<MemoryHeapBase> mHeap; + size_t mSize; + volatile int32_t mRefCount; + uint16_t mSampleID; + uint16_t mSampleRate; + uint8_t mState; + uint8_t mNumChannels; + audio_format_t mFormat; + audio_channel_mask_t mChannelMask; + int mFd; + int64_t mOffset; + int64_t mLength; + sp<IMemory> mData; + sp<MemoryHeapBase> mHeap; }; // stores pending events for stolen channels |