diff options
author | Glenn Kasten <gkasten@google.com> | 2012-11-05 13:39:09 -0800 |
---|---|---|
committer | Glenn Kasten <gkasten@google.com> | 2012-11-05 16:41:14 -0800 |
commit | ac65726b26a63635d3461f96b4b979add5a8f7dc (patch) | |
tree | 880824001a51fedfb0a2cd7d72b29b42a3272679 /services/audioflinger | |
parent | fda32926cfbdad0aae5a3e0bf88b2a218f9e7f6c (diff) | |
download | frameworks_av-ac65726b26a63635d3461f96b4b979add5a8f7dc.zip frameworks_av-ac65726b26a63635d3461f96b4b979add5a8f7dc.tar.gz frameworks_av-ac65726b26a63635d3461f96b4b979add5a8f7dc.tar.bz2 |
Merge duplicate code in TrackBase::TrackBase()
Change-Id: Id8a7db4d94888796a9dcbed4cac99941705cd174
Diffstat (limited to 'services/audioflinger')
-rw-r--r-- | services/audioflinger/AudioFlinger.cpp | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 5f2f441..cb44114 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -4195,6 +4195,9 @@ AudioFlinger::ThreadBase::TrackBase::TrackBase( // mChannelCount // mChannelMask { + // client == 0 implies sharedBuffer == 0 + ALOG_ASSERT(!(client == 0 && sharedBuffer != 0)); + ALOGV_IF(sharedBuffer != 0, "sharedBuffer: %p, size: %d", sharedBuffer->pointer(), sharedBuffer->size()); @@ -4206,33 +4209,11 @@ AudioFlinger::ThreadBase::TrackBase::TrackBase( size += bufferSize; } - if (client != NULL) { + if (client != 0) { mCblkMemory = client->heap()->allocate(size); if (mCblkMemory != 0) { mCblk = static_cast<audio_track_cblk_t *>(mCblkMemory->pointer()); - if (mCblk != NULL) { // construct the shared structure in-place. - new(mCblk) audio_track_cblk_t(); - // clear all buffers - mCblk->frameCount = frameCount; - mCblk->sampleRate = sampleRate; -// uncomment the following lines to quickly test 32-bit wraparound -// mCblk->user = 0xffff0000; -// mCblk->server = 0xffff0000; -// mCblk->userBase = 0xffff0000; -// mCblk->serverBase = 0xffff0000; - mChannelCount = channelCount; - mChannelMask = channelMask; - if (sharedBuffer == 0) { - mBuffer = (char*)mCblk + sizeof(audio_track_cblk_t); - memset(mBuffer, 0, frameCount*channelCount*sizeof(int16_t)); - // Force underrun condition to avoid false underrun callback until first data is - // written to buffer (other flags are cleared) - mCblk->flags = CBLK_UNDERRUN; - } else { - mBuffer = sharedBuffer->pointer(); - } - mBufferEnd = (uint8_t *)mBuffer + bufferSize; - } + // can't assume mCblk != NULL } else { ALOGE("not enough memory for AudioTrack size=%u", size); client->heap()->dump("AudioTrack"); @@ -4240,23 +4221,31 @@ AudioFlinger::ThreadBase::TrackBase::TrackBase( } } else { mCblk = (audio_track_cblk_t *)(new uint8_t[size]); - // construct the shared structure in-place. + // assume mCblk != NULL + } + + // construct the shared structure in-place. + if (mCblk != NULL) { new(mCblk) audio_track_cblk_t(); // clear all buffers mCblk->frameCount = frameCount; mCblk->sampleRate = sampleRate; // uncomment the following lines to quickly test 32-bit wraparound -// mCblk->user = 0xffff0000; -// mCblk->server = 0xffff0000; -// mCblk->userBase = 0xffff0000; -// mCblk->serverBase = 0xffff0000; +// mCblk->user = 0xffff0000; +// mCblk->server = 0xffff0000; +// mCblk->userBase = 0xffff0000; +// mCblk->serverBase = 0xffff0000; mChannelCount = channelCount; mChannelMask = channelMask; - mBuffer = (char*)mCblk + sizeof(audio_track_cblk_t); - memset(mBuffer, 0, frameCount*channelCount*sizeof(int16_t)); - // Force underrun condition to avoid false underrun callback until first data is - // written to buffer (other flags are cleared) - mCblk->flags = CBLK_UNDERRUN; + if (sharedBuffer == 0) { + mBuffer = (char*)mCblk + sizeof(audio_track_cblk_t); + memset(mBuffer, 0, frameCount*channelCount*sizeof(int16_t)); + // Force underrun condition to avoid false underrun callback until first data is + // written to buffer (other flags are cleared) + mCblk->flags = CBLK_UNDERRUN; + } else { + mBuffer = sharedBuffer->pointer(); + } mBufferEnd = (uint8_t *)mBuffer + bufferSize; } } |