Fix issue 1743700: AudioTrack: setPlaybackRate can not set the playback rate to twice of the ouputSR
Store sample rate on 32 bits instead of 16 bits in audio_track_cblk_t.
Removed sampleRate() methods from AudioTrack and AudioRecord: replaced by getSampleRate().
AudioTrack::setSampleRate() no returns a status.
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 4c8b02a..e56efbb 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -185,7 +185,6 @@
mCblk = static_cast<audio_track_cblk_t*>(cblk->pointer());
mCblk->buffers = (char*)mCblk + sizeof(audio_track_cblk_t);
mCblk->out = 0;
- mSampleRate = sampleRate;
mFormat = format;
// Update buffer size in case it has been limited by AudioFlinger during track creation
mFrameCount = mCblk->frameCount;
@@ -196,7 +195,7 @@
mRemainingFrames = notificationFrames;
mUserData = user;
// TODO: add audio hardware input latency here
- mLatency = (1000*mFrameCount) / mSampleRate;
+ mLatency = (1000*mFrameCount) / sampleRate;
mMarkerPosition = 0;
mMarkerReached = false;
mNewPosition = 0;
@@ -218,11 +217,6 @@
return mLatency;
}
-uint32_t AudioRecord::sampleRate() const
-{
- return mSampleRate;
-}
-
int AudioRecord::format() const
{
return mFormat;
@@ -321,6 +315,11 @@
return !mActive;
}
+uint32_t AudioRecord::getSampleRate()
+{
+ return mCblk->sampleRate;
+}
+
status_t AudioRecord::setMarkerPosition(uint32_t marker)
{
if (mCbf == 0) return INVALID_OPERATION;
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 289bd75..b2c067b 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -243,7 +243,6 @@
mCblk->volume[0] = mCblk->volume[1] = 0x1000;
mVolume[LEFT] = 1.0f;
mVolume[RIGHT] = 1.0f;
- mSampleRate = sampleRate;
mStreamType = streamType;
mFormat = format;
mChannelCount = channelCount;
@@ -254,7 +253,7 @@
mNotificationFrames = notificationFrames;
mRemainingFrames = notificationFrames;
mUserData = user;
- mLatency = afLatency + (1000*mFrameCount) / mSampleRate;
+ mLatency = afLatency + (1000*mFrameCount) / sampleRate;
mLoopCount = 0;
mMarkerPosition = 0;
mMarkerReached = false;
@@ -281,11 +280,6 @@
return mStreamType;
}
-uint32_t AudioTrack::sampleRate() const
-{
- return mSampleRate;
-}
-
int AudioTrack::format() const
{
return mFormat;
@@ -438,24 +432,23 @@
*right = mVolume[RIGHT];
}
-void AudioTrack::setSampleRate(int rate)
+status_t AudioTrack::setSampleRate(int rate)
{
int afSamplingRate;
if (AudioSystem::getOutputSamplingRate(&afSamplingRate, mStreamType) != NO_ERROR) {
- return;
+ return NO_INIT;
}
// Resampler implementation limits input sampling rate to 2 x output sampling rate.
- if (rate <= 0) rate = 1;
- if (rate > afSamplingRate*2) rate = afSamplingRate*2;
- if (rate > MAX_SAMPLE_RATE) rate = MAX_SAMPLE_RATE;
+ if (rate <= 0 || rate > afSamplingRate*2 ) return BAD_VALUE;
- mCblk->sampleRate = (uint16_t)rate;
+ mCblk->sampleRate = rate;
+ return NO_ERROR;
}
uint32_t AudioTrack::getSampleRate()
{
- return uint32_t(mCblk->sampleRate);
+ return mCblk->sampleRate;
}
status_t AudioTrack::setLoop(uint32_t loopStart, uint32_t loopEnd, int loopCount)
@@ -866,7 +859,7 @@
result.append(buffer);
snprintf(buffer, 255, " format(%d), channel count(%d), frame count(%d)\n", mFormat, mChannelCount, mFrameCount);
result.append(buffer);
- snprintf(buffer, 255, " sample rate(%d), status(%d), muted(%d)\n", mSampleRate, mStatus, mMuted);
+ snprintf(buffer, 255, " sample rate(%d), status(%d), muted(%d)\n", (mCblk == 0) ? 0 : mCblk->sampleRate, mStatus, mMuted);
result.append(buffer);
snprintf(buffer, 255, " active(%d), latency (%d)\n", mActive, mLatency);
result.append(buffer);