Use size_t for frame size
except in the control block, where we don't have room.
In AudioFlinger::ThreadBase::TrackBase::getBuffer,
read the frame size from control block only once.
Change-Id: Id6c4bccd4ed3e07d91df6bbea43bae45524f9f4e
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index 2fb69b6..84a8f1c 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -206,7 +206,7 @@
int channelCount() const;
int channels() const;
uint32_t frameCount() const;
- int frameSize() const;
+ size_t frameSize() const;
int inputSource() const;
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 60b052bd9..01a9d05 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -219,7 +219,12 @@
audio_format_t format() const;
int channelCount() const;
uint32_t frameCount() const;
- int frameSize() const;
+
+ /* Return channelCount * (bit depth per channel / 8).
+ * channelCount is determined from channelMask, and bit depth comes from format.
+ */
+ size_t frameSize() const;
+
sp<IMemory>& sharedBuffer();
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
index 046d5e9..b661cb9 100644
--- a/include/private/media/AudioTrackShared.h
+++ b/include/private/media/AudioTrackShared.h
@@ -80,7 +80,7 @@
// 8 bit PCM data: in this case, mCblk->frameSize is based on a sample size of
// 16 bit because data is converted to 16 bit before being stored in buffer
- uint8_t frameSize;
+ uint8_t frameSize; // would normally be size_t, but 8 bits is plenty
uint8_t pad1;
uint16_t bufferTimeoutMs; // Maximum cumulated timeout before restarting audioflinger
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 8e4a9d6..32b5bac 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -263,7 +263,7 @@
return mFrameCount;
}
-int AudioRecord::frameSize() const
+size_t AudioRecord::frameSize() const
{
if (audio_is_linear_pcm(mFormat)) {
return channelCount()*audio_bytes_per_sample(mFormat);
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 9c650ad..a66a1dd 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -295,7 +295,7 @@
return mCblk->frameCount;
}
-int AudioTrack::frameSize() const
+size_t AudioTrack::frameSize() const
{
if (audio_is_linear_pcm(mFormat)) {
return channelCount()*audio_bytes_per_sample(mFormat);
@@ -979,7 +979,7 @@
ssize_t written = 0;
const int8_t *src = (const int8_t *)buffer;
Buffer audioBuffer;
- size_t frameSz = (size_t)frameSize();
+ size_t frameSz = frameSize();
do {
audioBuffer.frameCount = userSize/frameSz;
@@ -1137,7 +1137,7 @@
audioBuffer.size = writtenSize;
// NOTE: mCblk->frameSize is not equal to AudioTrack::frameSize() for
- // 8 bit PCM data: in this case, mCblk->frameSize is based on a sampel size of
+ // 8 bit PCM data: in this case, mCblk->frameSize is based on a sample size of
// 16 bit.
audioBuffer.frameCount = writtenSize/mCblk->frameSize;
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 9fb666e..3f3163e 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1118,7 +1118,7 @@
result.append(buffer);
snprintf(buffer, SIZE, "Format: %d\n", mFormat);
result.append(buffer);
- snprintf(buffer, SIZE, "Frame size: %d\n", mFrameSize);
+ snprintf(buffer, SIZE, "Frame size: %u\n", mFrameSize);
result.append(buffer);
snprintf(buffer, SIZE, "\nPending setParameters commands: \n");
@@ -1727,7 +1727,7 @@
mChannelMask = mOutput->stream->common.get_channels(&mOutput->stream->common);
mChannelCount = (uint16_t)popcount(mChannelMask);
mFormat = mOutput->stream->common.get_format(&mOutput->stream->common);
- mFrameSize = (uint16_t)audio_stream_frame_size(&mOutput->stream->common);
+ mFrameSize = audio_stream_frame_size(&mOutput->stream->common);
mFrameCount = mOutput->stream->common.get_buffer_size(&mOutput->stream->common) / mFrameSize;
// FIXME - Current mixer implementation only supports stereo output: Always
@@ -3324,12 +3324,13 @@
void* AudioFlinger::ThreadBase::TrackBase::getBuffer(uint32_t offset, uint32_t frames) const {
audio_track_cblk_t* cblk = this->cblk();
- int8_t *bufferStart = (int8_t *)mBuffer + (offset-cblk->serverBase)*cblk->frameSize;
- int8_t *bufferEnd = bufferStart + frames * cblk->frameSize;
+ size_t frameSize = cblk->frameSize;
+ int8_t *bufferStart = (int8_t *)mBuffer + (offset-cblk->serverBase)*frameSize;
+ int8_t *bufferEnd = bufferStart + frames * frameSize;
// Check validity of returned pointer in case the track control block would have been corrupted.
if (bufferStart < mBuffer || bufferStart > bufferEnd || bufferEnd > mBufferEnd ||
- ((unsigned long)bufferStart & (unsigned long)(cblk->frameSize - 1))) {
+ ((unsigned long)bufferStart & (unsigned long)(frameSize - 1))) {
ALOGE("TrackBase::getBuffer buffer out of range:\n start: %p, end %p , mBuffer %p mBufferEnd %p\n \
server %d, serverBase %d, user %d, userBase %d",
bufferStart, bufferEnd, mBuffer, mBufferEnd,
@@ -4800,7 +4801,7 @@
mChannelMask = mInput->stream->common.get_channels(&mInput->stream->common);
mChannelCount = (uint16_t)popcount(mChannelMask);
mFormat = mInput->stream->common.get_format(&mInput->stream->common);
- mFrameSize = (uint16_t)audio_stream_frame_size(&mInput->stream->common);
+ mFrameSize = audio_stream_frame_size(&mInput->stream->common);
mInputBytes = mInput->stream->common.get_buffer_size(&mInput->stream->common);
mFrameCount = mInputBytes / mFrameSize;
mRsmpInBuffer = new int16_t[mFrameCount * mChannelCount];
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index f99e764..cd5f56d 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -536,7 +536,7 @@
size_t mFrameCount;
uint32_t mChannelMask;
uint16_t mChannelCount;
- uint16_t mFrameSize;
+ size_t mFrameSize;
uint32_t mFormat;
Condition mParamCond;
Vector<String8> mNewParameters;