Merge "Add GSM 6.10 decoder"
diff --git a/cmds/stagefright/stagefright.cpp b/cmds/stagefright/stagefright.cpp
index b92a8a0..1e0e7f8 100644
--- a/cmds/stagefright/stagefright.cpp
+++ b/cmds/stagefright/stagefright.cpp
@@ -589,7 +589,7 @@
}
static void usage(const char *me) {
- fprintf(stderr, "usage: %s\n", me);
+ fprintf(stderr, "usage: %s [options] [input_filename]\n", me);
fprintf(stderr, " -h(elp)\n");
fprintf(stderr, " -a(udio)\n");
fprintf(stderr, " -n repetitions\n");
@@ -607,8 +607,8 @@
"(video only)\n");
fprintf(stderr, " -S allocate buffers from a surface\n");
fprintf(stderr, " -T allocate buffers from a surface texture\n");
- fprintf(stderr, " -d(ump) filename (raw stream data to a file)\n");
- fprintf(stderr, " -D(ump) filename (decoded PCM data to a file)\n");
+ fprintf(stderr, " -d(ump) output_filename (raw stream data to a file)\n");
+ fprintf(stderr, " -D(ump) output_filename (decoded PCM data to a file)\n");
}
static void dumpCodecProfiles(const sp<IOMX>& omx, bool queryDecoders) {
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index 2672db1..cd7ff92 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -95,7 +95,7 @@
* - BAD_VALUE: unsupported configuration
*/
- static status_t getMinFrameCount(int* frameCount,
+ static status_t getMinFrameCount(size_t* frameCount,
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask);
@@ -184,7 +184,7 @@
audio_format_t format() const;
int channelCount() const;
- uint32_t frameCount() const;
+ size_t frameCount() const;
size_t frameSize() const { return mFrameSize; }
audio_source_t inputSource() const;
@@ -352,7 +352,7 @@
status_t openRecord_l(uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
audio_io_handle_t input);
audio_io_handle_t getInput_l();
status_t restoreRecord_l(audio_track_cblk_t*& cblk);
@@ -375,7 +375,7 @@
uint32_t mUpdatePeriod; // in ms
// constant after constructor or set()
- uint32_t mFrameCount;
+ size_t mFrameCount;
audio_format_t mFormat;
uint8_t mChannelCount;
size_t mFrameSize; // app-level frame size == AudioFlinger frame size
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 2218fad..126ef12 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -87,32 +87,26 @@
static float linearToLog(int volume);
static int logToLinear(float volume);
- static status_t getOutputSamplingRate(int* samplingRate,
+ static status_t getOutputSamplingRate(uint32_t* samplingRate,
audio_stream_type_t stream = AUDIO_STREAM_DEFAULT);
- static status_t getOutputFrameCount(int* frameCount,
+ static status_t getOutputFrameCount(size_t* frameCount,
audio_stream_type_t stream = AUDIO_STREAM_DEFAULT);
static status_t getOutputLatency(uint32_t* latency,
audio_stream_type_t stream = AUDIO_STREAM_DEFAULT);
static status_t getSamplingRate(audio_io_handle_t output,
audio_stream_type_t streamType,
- int* samplingRate);
+ uint32_t* samplingRate);
// returns the number of frames per audio HAL write buffer. Corresponds to
// audio_stream->get_buffer_size()/audio_stream_frame_size()
static status_t getFrameCount(audio_io_handle_t output,
audio_stream_type_t stream,
- int* frameCount);
+ size_t* frameCount);
// returns the audio output stream latency in ms. Corresponds to
// audio_stream_out->get_latency()
static status_t getLatency(audio_io_handle_t output,
audio_stream_type_t stream,
uint32_t* latency);
- // DEPRECATED
- static status_t getOutputSamplingRate(int* samplingRate, int stream = AUDIO_STREAM_DEFAULT);
-
- // DEPRECATED
- static status_t getOutputFrameCount(int* frameCount, int stream = AUDIO_STREAM_DEFAULT);
-
static bool routedToA2dpOutput(audio_stream_type_t streamType);
static status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format,
@@ -129,11 +123,11 @@
// - BAD_VALUE: invalid parameter
// NOTE: this feature is not supported on all hardware platforms and it is
// necessary to check returned status before using the returned values.
- static status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
+ static status_t getRenderPosition(size_t *halFrames, size_t *dspFrames,
audio_stream_type_t stream = AUDIO_STREAM_DEFAULT);
// return the number of input frames lost by HAL implementation, or 0 if the handle is invalid
- static unsigned int getInputFramesLost(audio_io_handle_t ioHandle);
+ static size_t getInputFramesLost(audio_io_handle_t ioHandle);
static int newAudioSessionId();
static void acquireAudioSessionId(int audioSession);
@@ -243,8 +237,8 @@
static const sp<IAudioPolicyService>& get_audio_policy_service();
// helpers for android.media.AudioManager.getProperty(), see description there for meaning
- static int32_t getPrimaryOutputSamplingRate();
- static int32_t getPrimaryOutputFrameCount();
+ static uint32_t getPrimaryOutputSamplingRate();
+ static size_t getPrimaryOutputFrameCount();
// ----------------------------------------------------------------------------
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index 3504f1f..f1b26b5 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -110,7 +110,7 @@
* - NO_INIT: audio server or audio hardware not initialized
*/
- static status_t getMinFrameCount(int* frameCount,
+ static status_t getMinFrameCount(size_t* frameCount,
audio_stream_type_t streamType = AUDIO_STREAM_DEFAULT,
uint32_t sampleRate = 0);
@@ -282,7 +282,9 @@
/* Set sample rate for this track in Hz, mostly used for games' sound effects
*/
- status_t setSampleRate(int sampleRate);
+ status_t setSampleRate(uint32_t sampleRate);
+
+ /* Return current sample rate in Hz, or 0 if unknown */
uint32_t getSampleRate() const;
/* Enables looping and sets the start and end points of looping.
@@ -422,6 +424,7 @@
* After error return:
* frameCount 0
* size 0
+ * raw undefined
* After successful return:
* frameCount actual number of frames available, <= number requested
* size actual number of bytes available
@@ -491,7 +494,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
audio_output_flags_t flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output);
@@ -510,8 +513,14 @@
uint32_t mFrameCount;
audio_track_cblk_t* mCblk; // re-load after mLock.unlock()
- void* mBuffers; // starting address of buffers in shared memory
- audio_format_t mFormat;
+
+ // Starting address of buffers in shared memory. If there is a shared buffer, mBuffers
+ // is the value of pointer() for the shared buffer, otherwise mBuffers points
+ // immediately after the control block. This address is for the mapping within client
+ // address space. AudioFlinger::TrackBase::mBuffer is for the server address space.
+ void* mBuffers;
+
+ audio_format_t mFormat; // as requested by client, not forced to 16-bit
audio_stream_type_t mStreamType;
uint8_t mChannelCount;
uint8_t mMuted;
diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h
index 0aa48c6..9727143 100644
--- a/include/media/IAudioFlinger.h
+++ b/include/media/IAudioFlinger.h
@@ -61,7 +61,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
track_flags_t *flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output,
@@ -75,7 +75,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
track_flags_t flags,
pid_t tid, // -1 means unused, otherwise must be valid non-0
int *sessionId,
@@ -157,10 +157,10 @@
virtual status_t setVoiceVolume(float volume) = 0;
- virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
+ virtual status_t getRenderPosition(size_t *halFrames, size_t *dspFrames,
audio_io_handle_t output) const = 0;
- virtual unsigned int getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
+ virtual size_t getInputFramesLost(audio_io_handle_t ioHandle) const = 0;
virtual int newAudioSessionId() = 0;
@@ -192,8 +192,8 @@
// helpers for android.media.AudioManager.getProperty(), see description there for meaning
// FIXME move these APIs to AudioPolicy to permit a more accurate implementation
// that looks on primary device for a stream with fast flag, primary flag, or first one.
- virtual int32_t getPrimaryOutputSamplingRate() = 0;
- virtual int32_t getPrimaryOutputFrameCount() = 0;
+ virtual uint32_t getPrimaryOutputSamplingRate() = 0;
+ virtual size_t getPrimaryOutputFrameCount() = 0;
};
diff --git a/include/media/ToneGenerator.h b/include/media/ToneGenerator.h
index 29c8fd9..0529bcd 100644
--- a/include/media/ToneGenerator.h
+++ b/include/media/ToneGenerator.h
@@ -263,7 +263,7 @@
unsigned short mLoopCounter; // Current tone loopback count
- int mSamplingRate; // AudioFlinger Sampling rate
+ uint32_t mSamplingRate; // AudioFlinger Sampling rate
AudioTrack *mpAudioTrack; // Pointer to audio track used for playback
Mutex mLock; // Mutex to control concurent access to ToneGenerator object from audio callback and application API
Mutex mCbkCondLock; // Mutex associated to mWaitCbkCond
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
index 3063448..bbc5e26 100644
--- a/include/private/media/AudioTrackShared.h
+++ b/include/private/media/AudioTrackShared.h
@@ -54,9 +54,10 @@
uint32_t serverBase;
int mPad1; // unused, but preserves cache line alignment
+
uint32_t frameCount;
- // Cache line boundary
+ // Cache line boundary (32 bytes)
uint32_t loopStart;
uint32_t loopEnd; // read-only for server, read/write for client
diff --git a/libvideoeditor/lvpp/VideoEditorPlayer.cpp b/libvideoeditor/lvpp/VideoEditorPlayer.cpp
index fc9fb49..a47fc15 100755
--- a/libvideoeditor/lvpp/VideoEditorPlayer.cpp
+++ b/libvideoeditor/lvpp/VideoEditorPlayer.cpp
@@ -406,8 +406,8 @@
}
ALOGV("open(%u, %d, %d, %d)", sampleRate, channelCount, format, bufferCount);
if (mTrack) close();
- int afSampleRate;
- int afFrameCount;
+ uint32_t afSampleRate;
+ size_t afFrameCount;
int frameCount;
if (AudioSystem::getOutputFrameCount(&afFrameCount, mStreamType) !=
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 062f546..0587651 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -36,7 +36,7 @@
// static
status_t AudioRecord::getMinFrameCount(
- int* frameCount,
+ size_t* frameCount,
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask)
@@ -54,7 +54,7 @@
}
if (size == 0) {
- ALOGE("Unsupported configuration: sampleRate %d, format %d, channelMask %#x",
+ ALOGE("Unsupported configuration: sampleRate %u, format %d, channelMask %#x",
sampleRate, format, channelMask);
return BAD_VALUE;
}
@@ -119,15 +119,21 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ int frameCountInt,
callback_t cbf,
void* user,
int notificationFrames,
bool threadCanCallJava,
int sessionId)
{
+ // FIXME "int" here is legacy and will be replaced by size_t later
+ if (frameCountInt < 0) {
+ ALOGE("Invalid frame count %d", frameCountInt);
+ return BAD_VALUE;
+ }
+ size_t frameCount = frameCountInt;
- ALOGV("set(): sampleRate %d, channelMask %#x, frameCount %d",sampleRate, channelMask,
+ ALOGV("set(): sampleRate %u, channelMask %#x, frameCount %u", sampleRate, channelMask,
frameCount);
AutoMutex lock(mLock);
@@ -177,7 +183,7 @@
}
// validate framecount
- int minFrameCount = 0;
+ size_t minFrameCount = 0;
status_t status = getMinFrameCount(&minFrameCount, sampleRate, format, channelMask);
if (status != NO_ERROR) {
return status;
@@ -260,7 +266,7 @@
return mChannelCount;
}
-uint32_t AudioRecord::frameCount() const
+size_t AudioRecord::frameCount() const
{
return mFrameCount;
}
@@ -427,7 +433,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
audio_io_handle_t input)
{
status_t status;
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index 767c452..028e4a3 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -205,12 +205,7 @@
return volume ? 100 - int(dBConvertInverse * log(volume) + 0.5) : 0;
}
-// DEPRECATED
-status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType) {
- return getOutputSamplingRate(samplingRate, (audio_stream_type_t)streamType);
-}
-
-status_t AudioSystem::getOutputSamplingRate(int* samplingRate, audio_stream_type_t streamType)
+status_t AudioSystem::getOutputSamplingRate(uint32_t* samplingRate, audio_stream_type_t streamType)
{
audio_io_handle_t output;
@@ -228,7 +223,7 @@
status_t AudioSystem::getSamplingRate(audio_io_handle_t output,
audio_stream_type_t streamType,
- int* samplingRate)
+ uint32_t* samplingRate)
{
OutputDescriptor *outputDesc;
@@ -246,18 +241,13 @@
gLock.unlock();
}
- ALOGV("getSamplingRate() streamType %d, output %d, sampling rate %d", streamType, output,
+ ALOGV("getSamplingRate() streamType %d, output %d, sampling rate %u", streamType, output,
*samplingRate);
return NO_ERROR;
}
-// DEPRECATED
-status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType) {
- return getOutputFrameCount(frameCount, (audio_stream_type_t)streamType);
-}
-
-status_t AudioSystem::getOutputFrameCount(int* frameCount, audio_stream_type_t streamType)
+status_t AudioSystem::getOutputFrameCount(size_t* frameCount, audio_stream_type_t streamType)
{
audio_io_handle_t output;
@@ -275,7 +265,7 @@
status_t AudioSystem::getFrameCount(audio_io_handle_t output,
audio_stream_type_t streamType,
- int* frameCount)
+ size_t* frameCount)
{
OutputDescriptor *outputDesc;
@@ -371,7 +361,7 @@
return af->setVoiceVolume(value);
}
-status_t AudioSystem::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames,
+status_t AudioSystem::getRenderPosition(size_t *halFrames, size_t *dspFrames,
audio_stream_type_t stream)
{
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
@@ -384,7 +374,7 @@
return af->getRenderPosition(halFrames, dspFrames, getOutput(stream));
}
-unsigned int AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) {
+size_t AudioSystem::getInputFramesLost(audio_io_handle_t ioHandle) {
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
unsigned int result = 0;
if (af == 0) return result;
@@ -452,7 +442,7 @@
OutputDescriptor *outputDesc = new OutputDescriptor(*desc);
gOutputs.add(ioHandle, outputDesc);
- ALOGV("ioConfigChanged() new output samplingRate %d, format %d channels %#x frameCount %d "
+ ALOGV("ioConfigChanged() new output samplingRate %u, format %d channels %#x frameCount %u "
"latency %d",
outputDesc->samplingRate, outputDesc->format, outputDesc->channels,
outputDesc->frameCount, outputDesc->latency);
@@ -476,7 +466,7 @@
if (param2 == NULL) break;
desc = (const OutputDescriptor *)param2;
- ALOGV("ioConfigChanged() new config for output %d samplingRate %d, format %d channels %#x "
+ ALOGV("ioConfigChanged() new config for output %d samplingRate %u, format %d channels %#x "
"frameCount %d latency %d",
ioHandle, desc->samplingRate, desc->format,
desc->channels, desc->frameCount, desc->latency);
@@ -750,14 +740,14 @@
return NO_ERROR;
}
-int32_t AudioSystem::getPrimaryOutputSamplingRate()
+uint32_t AudioSystem::getPrimaryOutputSamplingRate()
{
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
if (af == 0) return 0;
return af->getPrimaryOutputSamplingRate();
}
-int32_t AudioSystem::getPrimaryOutputFrameCount()
+size_t AudioSystem::getPrimaryOutputFrameCount()
{
const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
if (af == 0) return 0;
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 4a4759e..979ee37 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -50,7 +50,7 @@
// static
status_t AudioTrack::getMinFrameCount(
- int* frameCount,
+ size_t* frameCount,
audio_stream_type_t streamType,
uint32_t sampleRate)
{
@@ -65,11 +65,11 @@
// audio_format_t format
// audio_channel_mask_t channelMask
// audio_output_flags_t flags
- int afSampleRate;
+ uint32_t afSampleRate;
if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
return NO_INIT;
}
- int afFrameCount;
+ size_t afFrameCount;
if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != NO_ERROR) {
return NO_INIT;
}
@@ -166,7 +166,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ int frameCountInt,
audio_output_flags_t flags,
callback_t cbf,
void* user,
@@ -175,11 +175,17 @@
bool threadCanCallJava,
int sessionId)
{
+ // FIXME "int" here is legacy and will be replaced by size_t later
+ if (frameCountInt < 0) {
+ ALOGE("Invalid frame count %d", frameCountInt);
+ return BAD_VALUE;
+ }
+ size_t frameCount = frameCountInt;
ALOGV_IF(sharedBuffer != 0, "sharedBuffer: %p, size: %d", sharedBuffer->pointer(),
sharedBuffer->size());
- ALOGV("set() streamType %d frameCount %d flags %04x", streamType, frameCount, flags);
+ ALOGV("set() streamType %d frameCount %u flags %04x", streamType, frameCount, flags);
AutoMutex lock(mLock);
if (mAudioTrack != 0) {
@@ -193,7 +199,7 @@
}
if (sampleRate == 0) {
- int afSampleRate;
+ uint32_t afSampleRate;
if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
return NO_INIT;
}
@@ -336,7 +342,7 @@
return mChannelCount;
}
-uint32_t AudioTrack::frameCount() const
+size_t AudioTrack::frameCount() const
{
return mCblk->frameCount;
}
@@ -390,7 +396,7 @@
}
if (cblk->flags & CBLK_INVALID) {
audio_track_cblk_t* temp = cblk;
- status = restoreTrack_l(temp, true);
+ status = restoreTrack_l(temp, true /*fromStart*/);
cblk = temp;
}
cblk->lock.unlock();
@@ -535,9 +541,9 @@
}
}
-status_t AudioTrack::setSampleRate(int rate)
+status_t AudioTrack::setSampleRate(uint32_t rate)
{
- int afSamplingRate;
+ uint32_t afSamplingRate;
if (mIsTimed) {
return INVALID_OPERATION;
@@ -547,7 +553,7 @@
return NO_INIT;
}
// Resampler implementation limits input sampling rate to 2 x output sampling rate.
- if (rate <= 0 || rate > afSamplingRate*2 ) return BAD_VALUE;
+ if (rate == 0 || rate > afSamplingRate*2 ) return BAD_VALUE;
AutoMutex lock(mLock);
mCblk->sampleRate = rate;
@@ -557,7 +563,7 @@
uint32_t AudioTrack::getSampleRate() const
{
if (mIsTimed) {
- return INVALID_OPERATION;
+ return 0;
}
AutoMutex lock(mLock);
@@ -730,7 +736,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
audio_output_flags_t flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output)
@@ -770,7 +776,7 @@
// Same comment as below about ignoring frameCount parameter for set()
frameCount = sharedBuffer->size();
} else if (frameCount == 0) {
- int afFrameCount;
+ size_t afFrameCount;
if (AudioSystem::getFrameCount(output, streamType, &afFrameCount) != NO_ERROR) {
return NO_INIT;
}
@@ -802,11 +808,11 @@
} else if (!(flags & AUDIO_OUTPUT_FLAG_FAST)) {
// FIXME move these calculations and associated checks to server
- int afSampleRate;
+ uint32_t afSampleRate;
if (AudioSystem::getSamplingRate(output, streamType, &afSampleRate) != NO_ERROR) {
return NO_INIT;
}
- int afFrameCount;
+ size_t afFrameCount;
if (AudioSystem::getFrameCount(output, streamType, &afFrameCount) != NO_ERROR) {
return NO_INIT;
}
@@ -815,8 +821,8 @@
uint32_t minBufCount = afLatency / ((1000 * afFrameCount)/afSampleRate);
if (minBufCount < 2) minBufCount = 2;
- int minFrameCount = (afFrameCount*sampleRate*minBufCount)/afSampleRate;
- ALOGV("minFrameCount: %d, afFrameCount=%d, minBufCount=%d, sampleRate=%d, afSampleRate=%d"
+ size_t minFrameCount = (afFrameCount*sampleRate*minBufCount)/afSampleRate;
+ ALOGV("minFrameCount: %u, afFrameCount=%d, minBufCount=%d, sampleRate=%u, afSampleRate=%u"
", afLatency=%d",
minFrameCount, afFrameCount, minBufCount, sampleRate, afSampleRate, afLatency);
@@ -828,7 +834,7 @@
}
// Make sure that application is notified with sufficient margin
// before underrun
- if (mNotificationFramesAct > (uint32_t)frameCount/2) {
+ if (mNotificationFramesAct > frameCount/2) {
mNotificationFramesAct = frameCount/2;
}
if (frameCount < minFrameCount) {
@@ -858,7 +864,9 @@
sp<IAudioTrack> track = audioFlinger->createTrack(getpid(),
streamType,
sampleRate,
- format,
+ // AudioFlinger only sees 16-bit PCM
+ format == AUDIO_FORMAT_PCM_8_BIT ?
+ AUDIO_FORMAT_PCM_16_BIT : format,
channelMask,
frameCount,
&trackFlags,
@@ -988,7 +996,7 @@
android_atomic_or(CBLK_INVALID, &cblk->flags);
create_new_track:
audio_track_cblk_t* temp = cblk;
- result = restoreTrack_l(temp, false);
+ result = restoreTrack_l(temp, false /*fromStart*/);
cblk = temp;
}
if (result != NO_ERROR) {
@@ -1147,7 +1155,7 @@
if (cblk->flags & CBLK_INVALID) {
cblk->lock.lock();
audio_track_cblk_t* temp = cblk;
- result = restoreTrack_l(temp, false);
+ result = restoreTrack_l(temp, false /*fromStart*/);
cblk = temp;
cblk->lock.unlock();
@@ -1423,7 +1431,7 @@
snprintf(buffer, 255, " format(%d), channel count(%d), frame count(%d)\n", mFormat,
mChannelCount, cblk->frameCount);
result.append(buffer);
- snprintf(buffer, 255, " sample rate(%d), status(%d), muted(%d)\n",
+ snprintf(buffer, 255, " sample rate(%u), status(%d), muted(%d)\n",
(cblk == 0) ? 0 : cblk->sampleRate, mStatus, mMuted);
result.append(buffer);
snprintf(buffer, 255, " active(%d), latency (%d)\n", mActive, mLatency);
diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cpp
index bb936ec..79c3361 100644
--- a/media/libmedia/IAudioFlinger.cpp
+++ b/media/libmedia/IAudioFlinger.cpp
@@ -89,7 +89,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
track_flags_t *flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output,
@@ -106,7 +106,7 @@
data.writeInt32(format);
data.writeInt32(channelMask);
data.writeInt32(frameCount);
- track_flags_t lFlags = flags != NULL ? *flags : TRACK_DEFAULT;
+ track_flags_t lFlags = flags != NULL ? *flags : (track_flags_t) TRACK_DEFAULT;
data.writeInt32(lFlags);
data.writeStrongBinder(sharedBuffer->asBinder());
data.writeInt32((int32_t) output);
@@ -143,7 +143,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
track_flags_t flags,
pid_t tid,
int *sessionId,
@@ -527,7 +527,7 @@
return status;
}
- virtual unsigned int getInputFramesLost(audio_io_handle_t ioHandle) const
+ virtual size_t getInputFramesLost(audio_io_handle_t ioHandle) const
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
@@ -695,7 +695,7 @@
return (audio_module_handle_t) reply.readInt32();
}
- virtual int32_t getPrimaryOutputSamplingRate()
+ virtual uint32_t getPrimaryOutputSamplingRate()
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
@@ -703,7 +703,7 @@
return reply.readInt32();
}
- virtual int32_t getPrimaryOutputFrameCount()
+ virtual size_t getPrimaryOutputFrameCount()
{
Parcel data, reply;
data.writeInterfaceToken(IAudioFlinger::getInterfaceDescriptor());
@@ -728,7 +728,7 @@
uint32_t sampleRate = data.readInt32();
audio_format_t format = (audio_format_t) data.readInt32();
audio_channel_mask_t channelMask = data.readInt32();
- size_t bufferCount = data.readInt32();
+ size_t frameCount = data.readInt32();
track_flags_t flags = (track_flags_t) data.readInt32();
sp<IMemory> buffer = interface_cast<IMemory>(data.readStrongBinder());
audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
@@ -737,7 +737,7 @@
status_t status;
sp<IAudioTrack> track = createTrack(pid,
(audio_stream_type_t) streamType, sampleRate, format,
- channelMask, bufferCount, &flags, buffer, output, tid, &sessionId, &status);
+ channelMask, frameCount, &flags, buffer, output, tid, &sessionId, &status);
reply->writeInt32(flags);
reply->writeInt32(sessionId);
reply->writeInt32(status);
@@ -751,13 +751,13 @@
uint32_t sampleRate = data.readInt32();
audio_format_t format = (audio_format_t) data.readInt32();
audio_channel_mask_t channelMask = data.readInt32();
- size_t bufferCount = data.readInt32();
+ size_t frameCount = data.readInt32();
track_flags_t flags = (track_flags_t) data.readInt32();
pid_t tid = (pid_t) data.readInt32();
int sessionId = data.readInt32();
status_t status;
sp<IAudioRecord> record = openRecord(pid, input,
- sampleRate, format, channelMask, bufferCount, flags, tid, &sessionId, &status);
+ sampleRate, format, channelMask, frameCount, flags, tid, &sessionId, &status);
reply->writeInt32(sessionId);
reply->writeInt32(status);
reply->writeStrongBinder(record->asBinder());
@@ -972,8 +972,8 @@
case GET_RENDER_POSITION: {
CHECK_INTERFACE(IAudioFlinger, data, reply);
audio_io_handle_t output = (audio_io_handle_t) data.readInt32();
- uint32_t halFrames;
- uint32_t dspFrames;
+ size_t halFrames;
+ size_t dspFrames;
status_t status = getRenderPosition(&halFrames, &dspFrames, output);
reply->writeInt32(status);
if (status == NO_ERROR) {
diff --git a/media/libmedia/SoundPool.cpp b/media/libmedia/SoundPool.cpp
index abc8899..204e0ce 100644
--- a/media/libmedia/SoundPool.cpp
+++ b/media/libmedia/SoundPool.cpp
@@ -568,8 +568,8 @@
}
// initialize track
- int afFrameCount;
- int afSampleRate;
+ size_t afFrameCount;
+ uint32_t afSampleRate;
audio_stream_type_t streamType = mSoundPool->streamType();
if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != NO_ERROR) {
afFrameCount = kDefaultFrameCount;
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 9bedff1..c3e5c40 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -1387,8 +1387,8 @@
}
ALOGV("open(%u, %d, 0x%x, %d, %d, %d)", sampleRate, channelCount, channelMask,
format, bufferCount, mSessionId);
- int afSampleRate;
- int afFrameCount;
+ uint32_t afSampleRate;
+ size_t afFrameCount;
uint32_t frameCount;
if (AudioSystem::getOutputFrameCount(&afFrameCount, mStreamType) != NO_ERROR) {
diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp
index 861aebe..3cf4d5c 100644
--- a/media/libstagefright/AudioSource.cpp
+++ b/media/libstagefright/AudioSource.cpp
@@ -58,7 +58,7 @@
ALOGV("sampleRate: %d, channelCount: %d", sampleRate, channelCount);
CHECK(channelCount == 1 || channelCount == 2);
- int minFrameCount;
+ size_t minFrameCount;
status_t status = AudioRecord::getMinFrameCount(&minFrameCount,
sampleRate,
AUDIO_FORMAT_PCM_16_BIT,
diff --git a/media/libstagefright/codecs/on2/dec/SoftVPX.cpp b/media/libstagefright/codecs/on2/dec/SoftVPX.cpp
index bf9ab3a..a400b4c 100644
--- a/media/libstagefright/codecs/on2/dec/SoftVPX.cpp
+++ b/media/libstagefright/codecs/on2/dec/SoftVPX.cpp
@@ -66,7 +66,7 @@
def.eDir = OMX_DirInput;
def.nBufferCountMin = kNumBuffers;
def.nBufferCountActual = def.nBufferCountMin;
- def.nBufferSize = 256 * 1024;
+ def.nBufferSize = 768 * 1024;
def.bEnabled = OMX_TRUE;
def.bPopulated = OMX_FALSE;
def.eDomain = OMX_PortDomainVideo;
diff --git a/media/libstagefright/matroska/MatroskaExtractor.cpp b/media/libstagefright/matroska/MatroskaExtractor.cpp
index 8f7d12b..7fc7037 100644
--- a/media/libstagefright/matroska/MatroskaExtractor.cpp
+++ b/media/libstagefright/matroska/MatroskaExtractor.cpp
@@ -758,31 +758,69 @@
esds = NULL;
}
-void addVorbisCodecInfo(
+status_t addVorbisCodecInfo(
const sp<MetaData> &meta,
const void *_codecPrivate, size_t codecPrivateSize) {
- // printf("vorbis private data follows:\n");
// hexdump(_codecPrivate, codecPrivateSize);
- CHECK(codecPrivateSize >= 3);
+ if (codecPrivateSize < 1) {
+ return ERROR_MALFORMED;
+ }
const uint8_t *codecPrivate = (const uint8_t *)_codecPrivate;
- CHECK(codecPrivate[0] == 0x02);
- size_t len1 = codecPrivate[1];
- size_t len2 = codecPrivate[2];
+ if (codecPrivate[0] != 0x02) {
+ return ERROR_MALFORMED;
+ }
- CHECK(codecPrivateSize > 3 + len1 + len2);
+ // codecInfo starts with two lengths, len1 and len2, that are
+ // "Xiph-style-lacing encoded"...
- CHECK(codecPrivate[3] == 0x01);
- meta->setData(kKeyVorbisInfo, 0, &codecPrivate[3], len1);
+ size_t offset = 1;
+ size_t len1 = 0;
+ while (offset < codecPrivateSize && codecPrivate[offset] == 0xff) {
+ len1 += 0xff;
+ ++offset;
+ }
+ if (offset >= codecPrivateSize) {
+ return ERROR_MALFORMED;
+ }
+ len1 += codecPrivate[offset++];
- CHECK(codecPrivate[len1 + 3] == 0x03);
+ size_t len2 = 0;
+ while (offset < codecPrivateSize && codecPrivate[offset] == 0xff) {
+ len2 += 0xff;
+ ++offset;
+ }
+ if (offset >= codecPrivateSize) {
+ return ERROR_MALFORMED;
+ }
+ len2 += codecPrivate[offset++];
- CHECK(codecPrivate[len1 + len2 + 3] == 0x05);
+ if (codecPrivateSize < offset + len1 + len2) {
+ return ERROR_MALFORMED;
+ }
+
+ if (codecPrivate[offset] != 0x01) {
+ return ERROR_MALFORMED;
+ }
+ meta->setData(kKeyVorbisInfo, 0, &codecPrivate[offset], len1);
+
+ offset += len1;
+ if (codecPrivate[offset] != 0x03) {
+ return ERROR_MALFORMED;
+ }
+
+ offset += len2;
+ if (codecPrivate[offset] != 0x05) {
+ return ERROR_MALFORMED;
+ }
+
meta->setData(
- kKeyVorbisBooks, 0, &codecPrivate[len1 + len2 + 3],
- codecPrivateSize - len1 - len2 - 3);
+ kKeyVorbisBooks, 0, &codecPrivate[offset],
+ codecPrivateSize - offset);
+
+ return OK;
}
void MatroskaExtractor::addTracks() {
@@ -809,6 +847,8 @@
sp<MetaData> meta = new MetaData;
+ status_t err = OK;
+
switch (track->GetType()) {
case VIDEO_TRACK:
{
@@ -855,7 +895,8 @@
} else if (!strcmp("A_VORBIS", codecID)) {
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_VORBIS);
- addVorbisCodecInfo(meta, codecPrivate, codecPrivateSize);
+ err = addVorbisCodecInfo(
+ meta, codecPrivate, codecPrivateSize);
} else if (!strcmp("A_MPEG/L3", codecID)) {
meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG);
} else {
@@ -872,6 +913,11 @@
continue;
}
+ if (err != OK) {
+ ALOGE("skipping track, codec specific data was malformed.");
+ continue;
+ }
+
long long durationNs = mSegment->GetDuration();
meta->setInt64(kKeyDuration, (durationNs + 500) / 1000);
diff --git a/media/libstagefright/wifi-display/sink/TunnelRenderer.cpp b/media/libstagefright/wifi-display/sink/TunnelRenderer.cpp
index bc35aef..b913124 100644
--- a/media/libstagefright/wifi-display/sink/TunnelRenderer.cpp
+++ b/media/libstagefright/wifi-display/sink/TunnelRenderer.cpp
@@ -271,6 +271,7 @@
if (mFirstFailedAttemptUs + 50000ll > ALooper::GetNowUs()) {
// We're willing to wait a little while to get the right packet.
+#if 0
if (!mRequestedRetransmission) {
ALOGI("requesting retransmission of seqNo %d",
(mLastDequeuedExtSeqNo + 1) & 0xffff);
@@ -280,7 +281,9 @@
notify->post();
mRequestedRetransmission = true;
- } else {
+ } else
+#endif
+ {
ALOGI("still waiting for the correct packet to arrive.");
}
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 9353e70..384f268 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -450,7 +450,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
IAudioFlinger::track_flags_t *flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output,
@@ -472,6 +472,14 @@
goto Exit;
}
+ // client is responsible for conversion of 8-bit PCM to 16-bit PCM,
+ // and we don't yet support 8.24 or 32-bit PCM
+ if (audio_is_linear_pcm(format) && format != AUDIO_FORMAT_PCM_16_BIT) {
+ ALOGE("createTrack() invalid format %d", format);
+ lStatus = BAD_VALUE;
+ goto Exit;
+ }
+
{
Mutex::Autolock _l(mLock);
PlaybackThread *thread = checkPlaybackThread_l(output);
@@ -1291,7 +1299,7 @@
result.append(buffer);
snprintf(buffer, SIZE, "standby: %d\n", mStandby);
result.append(buffer);
- snprintf(buffer, SIZE, "Sample rate: %d\n", mSampleRate);
+ snprintf(buffer, SIZE, "Sample rate: %u\n", mSampleRate);
result.append(buffer);
snprintf(buffer, SIZE, "HAL frame count: %d\n", mFrameCount);
result.append(buffer);
@@ -1722,7 +1730,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId,
IAudioFlinger::track_flags_t *flags,
@@ -1776,7 +1784,7 @@
frameCount, mFrameCount);
} else {
ALOGV("AUDIO_OUTPUT_FLAG_FAST denied: isTimed=%d sharedBuffer=%p frameCount=%d "
- "mFrameCount=%d format=%d isLinear=%d channelMask=%#x sampleRate=%d mSampleRate=%d "
+ "mFrameCount=%d format=%d isLinear=%d channelMask=%#x sampleRate=%u mSampleRate=%u "
"hasFastMixer=%d tid=%d fastTrackAvailMask=%#x",
isTimed, sharedBuffer.get(), frameCount, mFrameCount, format,
audio_is_linear_pcm(format),
@@ -1791,7 +1799,7 @@
if (minBufCount < 2) {
minBufCount = 2;
}
- int minFrameCount = mNormalFrameCount * minBufCount;
+ size_t minFrameCount = mNormalFrameCount * minBufCount;
if (frameCount < minFrameCount) {
frameCount = minFrameCount;
}
@@ -1801,7 +1809,7 @@
if (mType == DIRECT) {
if ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM) {
if (sampleRate != mSampleRate || format != mFormat || channelMask != mChannelMask) {
- ALOGE("createTrack_l() Bad parameter: sampleRate %d format %d, channelMask 0x%08x "
+ ALOGE("createTrack_l() Bad parameter: sampleRate %u format %d, channelMask 0x%08x "
"for output %p with format %d",
sampleRate, format, channelMask, mOutput, mFormat);
lStatus = BAD_VALUE;
@@ -1811,7 +1819,7 @@
} else {
// Resampler implementation limits input sampling rate to 2 x output sampling rate.
if (sampleRate > mSampleRate*2) {
- ALOGE("Sample rate out of range: %d mSampleRate %d", sampleRate, mSampleRate);
+ ALOGE("Sample rate out of range: %u mSampleRate %u", sampleRate, mSampleRate);
lStatus = BAD_VALUE;
goto Exit;
}
@@ -2280,7 +2288,7 @@
// mNormalSink below
{
ALOGV("MixerThread() id=%d device=%#x type=%d", id, device, type);
- ALOGV("mSampleRate=%d, mChannelMask=%#x, mChannelCount=%d, mFormat=%d, mFrameSize=%d, "
+ ALOGV("mSampleRate=%u, mChannelMask=%#x, mChannelCount=%d, mFormat=%d, mFrameSize=%u, "
"mFrameCount=%d, mNormalFrameCount=%d",
mSampleRate, mChannelMask, mChannelCount, mFormat, mFrameSize, mFrameCount,
mNormalFrameCount);
@@ -3126,7 +3134,7 @@
uint32_t minFrames = 1;
if ((track->sharedBuffer() == 0) && !track->isStopped() && !track->isPausing() &&
(mMixerStatusIgnoringFastTracks == MIXER_TRACKS_READY)) {
- if (t->sampleRate() == (int)mSampleRate) {
+ if (t->sampleRate() == mSampleRate) {
minFrames = mNormalFrameCount;
} else {
// +1 for rounding and +1 for additional sample needed for interpolation
@@ -3624,7 +3632,7 @@
NBAIO_Format format = teeSource->format();
unsigned channelCount = Format_channelCount(format);
ALOG_ASSERT(channelCount <= FCC_2);
- unsigned sampleRate = Format_sampleRate(format);
+ uint32_t sampleRate = Format_sampleRate(format);
wavHeader[22] = channelCount; // number of channels
wavHeader[24] = sampleRate; // sample rate
wavHeader[25] = sampleRate >> 8;
@@ -4089,7 +4097,7 @@
{
Mutex::Autolock _l(mLock);
// FIXME explain this formula
- int frameCount = (3 * mNormalFrameCount * mSampleRate) / thread->sampleRate();
+ size_t frameCount = (3 * mNormalFrameCount * mSampleRate) / thread->sampleRate();
OutputTrack *outputTrack = new OutputTrack(thread,
this,
mSampleRate,
@@ -4177,7 +4185,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId)
: RefBase(),
@@ -4190,11 +4198,12 @@
mState(IDLE),
mSampleRate(sampleRate),
mFormat(format),
- mFrameSize(0), // will be set to correct value in constructor
+ mChannelMask(channelMask),
+ mChannelCount(popcount(channelMask)),
+ mFrameSize(audio_is_linear_pcm(format) ?
+ mChannelCount * audio_bytes_per_sample(format) : sizeof(int8_t)),
mStepServerFailed(false),
mSessionId(sessionId)
- // mChannelCount
- // mChannelMask
{
// client == 0 implies sharedBuffer == 0
ALOG_ASSERT(!(client == 0 && sharedBuffer != 0));
@@ -4204,8 +4213,7 @@
// ALOGD("Creating track with %d buffers @ %d bytes", bufferCount, bufferSize);
size_t size = sizeof(audio_track_cblk_t);
- uint8_t channelCount = popcount(channelMask);
- size_t bufferSize = frameCount*channelCount*sizeof(int16_t);
+ size_t bufferSize = frameCount * mFrameSize;
if (sharedBuffer == 0) {
size += bufferSize;
}
@@ -4236,11 +4244,9 @@
// 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));
+ memset(mBuffer, 0, bufferSize);
// Force underrun condition to avoid false underrun callback until first data is
// written to buffer (other flags are cleared)
mCblk->flags = CBLK_UNDERRUN;
@@ -4306,23 +4312,22 @@
ALOGV("TrackBase::reset");
}
-int AudioFlinger::ThreadBase::TrackBase::sampleRate() const {
- return (int)mCblk->sampleRate;
+uint32_t AudioFlinger::ThreadBase::TrackBase::sampleRate() const {
+ return mCblk->sampleRate;
}
void* AudioFlinger::ThreadBase::TrackBase::getBuffer(uint32_t offset, uint32_t frames) const {
audio_track_cblk_t* cblk = this->cblk();
- size_t frameSize = mFrameSize;
- int8_t *bufferStart = (int8_t *)mBuffer + (offset-cblk->serverBase)*frameSize;
- int8_t *bufferEnd = bufferStart + frames * frameSize;
+ int8_t *bufferStart = (int8_t *)mBuffer + (offset-cblk->serverBase) * mFrameSize;
+ int8_t *bufferEnd = bufferStart + frames * mFrameSize;
// Check validity of returned pointer in case the track control block would have been corrupted.
ALOG_ASSERT(!(bufferStart < mBuffer || bufferStart > bufferEnd || bufferEnd > mBufferEnd),
"TrackBase::getBuffer buffer out of range:\n"
" start: %p, end %p , mBuffer %p mBufferEnd %p\n"
- " server %u, serverBase %u, user %u, userBase %u, frameSize %d",
+ " server %u, serverBase %u, user %u, userBase %u, frameSize %u",
bufferStart, bufferEnd, mBuffer, mBufferEnd,
- cblk->server, cblk->serverBase, cblk->user, cblk->userBase, frameSize);
+ cblk->server, cblk->serverBase, cblk->user, cblk->userBase, mFrameSize);
return bufferStart;
}
@@ -4343,7 +4348,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId,
IAudioFlinger::track_flags_t flags)
@@ -4364,10 +4369,6 @@
mUnderrunCount(0),
mCachedVolume(1.0)
{
- // NOTE: frame size for 8 bit PCM data is based on a sample size of
- // 16 bit because data is converted to 16 bit before being stored in buffer by AudioTrack
- mFrameSize = audio_is_linear_pcm(format) ? mChannelCount * sizeof(int16_t) :
- sizeof(uint8_t);
if (mCblk != NULL) {
// to avoid leaking a track name, do not allocate one unless there is an mCblk
mName = thread->getTrackName_l(channelMask, sessionId);
@@ -4709,7 +4710,7 @@
if (thread != 0) {
Mutex::Autolock _l(thread->mLock);
if (mState != STOPPING_1 && mState != STOPPING_2 && mState != STOPPED && mState != PAUSED &&
- mState != PAUSING) {
+ mState != PAUSING && mState != IDLE && mState != FLUSHED) {
return;
}
// No point remaining in PAUSED state after a flush => go to
@@ -4891,7 +4892,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId) {
if (!client->reserveTimedTrack())
@@ -4909,7 +4910,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId)
: Track(thread, client, streamType, sampleRate, format, channelMask,
@@ -5404,20 +5405,13 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
int sessionId)
: TrackBase(thread, client, sampleRate, format,
channelMask, frameCount, 0 /*sharedBuffer*/, sessionId),
mOverflow(false)
{
ALOGV("RecordTrack constructor, size %d", (int)mBufferEnd - (int)mBuffer);
- if (format == AUDIO_FORMAT_PCM_16_BIT) {
- mFrameSize = mChannelCount * sizeof(int16_t);
- } else if (format == AUDIO_FORMAT_PCM_8_BIT) {
- mFrameSize = mChannelCount * sizeof(int8_t);
- } else {
- mFrameSize = sizeof(int8_t);
- }
}
AudioFlinger::RecordThread::RecordTrack::~RecordTrack()
@@ -5530,7 +5524,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount)
+ size_t frameCount)
: Track(playbackThread, NULL, AUDIO_STREAM_CNT, sampleRate, format, channelMask, frameCount,
NULL, 0, IAudioFlinger::TRACK_DEFAULT),
mActive(false), mSourceThread(sourceThread), mBuffers(NULL)
@@ -5541,7 +5535,7 @@
mOutBuffer.frameCount = 0;
playbackThread->mTracks.add(this);
ALOGV("OutputTrack constructor mCblk %p, mBuffer %p, mCblk->buffers %p, " \
- "mCblk->frameCount %d, mCblk->sampleRate %d, mChannelMask 0x%08x mBufferEnd %p",
+ "mCblk->frameCount %d, mCblk->sampleRate %u, mChannelMask 0x%08x mBufferEnd %p",
mCblk, mBuffer, mCblk->buffers,
mCblk->frameCount, mCblk->sampleRate, mChannelMask, mBufferEnd);
} else {
@@ -5924,7 +5918,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
IAudioFlinger::track_flags_t flags,
pid_t tid,
int *sessionId,
@@ -6301,7 +6295,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
int sessionId,
IAudioFlinger::track_flags_t flags,
pid_t tid,
@@ -6558,7 +6552,7 @@
result.append(buffer);
snprintf(buffer, SIZE, "Out channel count: %d\n", mReqChannelCount);
result.append(buffer);
- snprintf(buffer, SIZE, "Out sample rate: %d\n", mReqSampleRate);
+ snprintf(buffer, SIZE, "Out sample rate: %u\n", mReqSampleRate);
result.append(buffer);
} else {
result.append("No active record client\n");
@@ -6653,7 +6647,7 @@
AudioParameter param = AudioParameter(keyValuePair);
int value;
audio_format_t reqFormat = mFormat;
- int reqSamplingRate = mReqSampleRate;
+ uint32_t reqSamplingRate = mReqSampleRate;
int reqChannelCount = mReqChannelCount;
if (param.getInt(String8(AudioParameter::keySamplingRate), value) == NO_ERROR) {
@@ -6987,14 +6981,14 @@
// ----------------------------------------------------------------------------
-int32_t AudioFlinger::getPrimaryOutputSamplingRate()
+uint32_t AudioFlinger::getPrimaryOutputSamplingRate()
{
Mutex::Autolock _l(mLock);
PlaybackThread *thread = primaryPlaybackThread_l();
return thread != NULL ? thread->sampleRate() : 0;
}
-int32_t AudioFlinger::getPrimaryOutputFrameCount()
+size_t AudioFlinger::getPrimaryOutputFrameCount()
{
Mutex::Autolock _l(mLock);
PlaybackThread *thread = primaryPlaybackThread_l();
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 8cf58b1..830dfe9 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -92,7 +92,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
IAudioFlinger::track_flags_t *flags,
const sp<IMemory>& sharedBuffer,
audio_io_handle_t output,
@@ -106,7 +106,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
IAudioFlinger::track_flags_t flags,
pid_t tid,
int *sessionId,
@@ -207,8 +207,8 @@
virtual audio_module_handle_t loadHwModule(const char *name);
- virtual int32_t getPrimaryOutputSamplingRate();
- virtual int32_t getPrimaryOutputFrameCount();
+ virtual uint32_t getPrimaryOutputSamplingRate();
+ virtual size_t getPrimaryOutputFrameCount();
virtual status_t onTransact(
uint32_t code,
@@ -390,7 +390,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId);
virtual ~TrackBase();
@@ -423,7 +423,7 @@
audio_channel_mask_t channelMask() const { return mChannelMask; }
- int sampleRate() const; // FIXME inline after cblk sr moved
+ uint32_t sampleRate() const; // FIXME inline after cblk sr moved
// Return a pointer to the start of a contiguous slice of the track buffer.
// Parameter 'offset' is the requested start position, expressed in
@@ -473,14 +473,13 @@
const uint32_t mSampleRate; // initial sample rate only; for tracks which
// support dynamic rates, the current value is in control block
const audio_format_t mFormat;
- size_t mFrameSize; // AudioFlinger's view of frame size in shared memory,
+ const audio_channel_mask_t mChannelMask;
+ const uint8_t mChannelCount;
+ const size_t mFrameSize; // AudioFlinger's view of frame size in shared memory,
// where for AudioTrack (but not AudioRecord),
// 8-bit PCM samples are stored as 16-bit
- // FIXME should be const
bool mStepServerFailed;
const int mSessionId;
- uint8_t mChannelCount;
- audio_channel_mask_t mChannelMask;
Vector < sp<SyncEvent> >mSyncEvents;
};
@@ -791,7 +790,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId,
IAudioFlinger::track_flags_t flags);
@@ -861,6 +860,9 @@
sp<IMemory> sharedBuffer() const { return mSharedBuffer; }
+ // framesWritten is cumulative, never reset, and is shared all tracks
+ // audioHalFrames is derived from output latency
+ // FIXME parameters not needed, could get them from the thread
bool presentationComplete(size_t framesWritten, size_t audioHalFrames);
public:
@@ -893,6 +895,7 @@
bool mHasVolumeController;
size_t mPresentationCompleteFrames; // number of frames written to the
// audio HAL when this track will be fully rendered
+ // zero means not monitoring
private:
IAudioFlinger::track_flags_t mFlags;
@@ -919,7 +922,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId);
virtual ~TimedTrack();
@@ -962,7 +965,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId);
@@ -997,7 +1000,7 @@
};
- // playback track
+ // playback track, used by DuplicatingThread
class OutputTrack : public Track {
public:
@@ -1011,7 +1014,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount);
+ size_t frameCount);
virtual ~OutputTrack();
virtual status_t start(AudioSystem::sync_event_t event =
@@ -1096,7 +1099,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
const sp<IMemory>& sharedBuffer,
int sessionId,
IAudioFlinger::track_flags_t *flags,
@@ -1460,7 +1463,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
int sessionId);
virtual ~RecordTrack();
@@ -1523,7 +1526,7 @@
uint32_t sampleRate,
audio_format_t format,
audio_channel_mask_t channelMask,
- int frameCount,
+ size_t frameCount,
int sessionId,
IAudioFlinger::track_flags_t flags,
pid_t tid,
diff --git a/services/audioflinger/AudioResamplerSinc.cpp b/services/audioflinger/AudioResamplerSinc.cpp
index 7d3681c..d68b839 100644
--- a/services/audioflinger/AudioResamplerSinc.cpp
+++ b/services/audioflinger/AudioResamplerSinc.cpp
@@ -470,6 +470,9 @@
*
*/
+ mVolumeSIMD[0] = 0;
+ mVolumeSIMD[1] = 0;
+
// Load the constants for coefficients
int ok = pthread_once(&once_control, init_routine);
if (ok != 0) {
@@ -494,6 +497,12 @@
mRingFull = mImpulse + (numCoefs+1)*mChannelCount;
}
+void AudioResamplerSinc::setVolume(int16_t left, int16_t right) {
+ AudioResampler::setVolume(left, right);
+ mVolumeSIMD[0] = int32_t(left)<<16;
+ mVolumeSIMD[1] = int32_t(right)<<16;
+}
+
void AudioResamplerSinc::resample(int32_t* out, size_t outFrameCount,
AudioBufferProvider* provider)
{
@@ -568,11 +577,9 @@
}
// handle boundary case
- int32_t l, r;
while (CC_LIKELY(outputIndex < outputSampleCount)) {
- filterCoefficient<CHANNELS>(l, r, phaseFraction, impulse, vRL);
- out[outputIndex++] += l;
- out[outputIndex++] += r;
+ filterCoefficient<CHANNELS>(&out[outputIndex], phaseFraction, impulse, vRL);
+ outputIndex += 2;
phaseFraction += phaseIncrement;
const size_t phaseIndex = phaseFraction >> kNumPhaseBits;
@@ -628,19 +635,22 @@
template<int CHANNELS>
void AudioResamplerSinc::filterCoefficient(
- int32_t& l, int32_t& r, uint32_t phase, const int16_t *samples, uint32_t vRL)
+ int32_t* out, uint32_t phase, const int16_t *samples, uint32_t vRL)
{
+ // NOTE: be very careful when modifying the code here. register
+ // pressure is very high and a small change might cause the compiler
+ // to generate far less efficient code.
+ // Always sanity check the result with objdump or test-resample.
+
// compute the index of the coefficient on the positive side and
// negative side
const Constants& c(*mConstants);
+ const int32_t ONE = c.cMask | c.pMask;
uint32_t indexP = ( phase & c.cMask) >> c.cShift;
- uint32_t indexN = (-phase & c.cMask) >> c.cShift;
uint32_t lerpP = ( phase & c.pMask) >> c.pShift;
- uint32_t lerpN = (-phase & c.pMask) >> c.pShift;
- if ((indexP == 0) && (lerpP == 0)) {
- indexN = c.cMask >> c.cShift;
- lerpN = c.pMask >> c.pShift;
- }
+ uint32_t indexN = ((ONE-phase) & c.cMask) >> c.cShift;
+ uint32_t lerpN = ((ONE-phase) & c.pMask) >> c.pShift;
+
const size_t offset = c.halfNumCoefs;
indexP *= offset;
indexN *= offset;
@@ -650,19 +660,19 @@
int16_t const* sP = samples;
int16_t const* sN = samples + CHANNELS;
- l = 0;
- r = 0;
size_t count = offset;
if (!USE_NEON) {
+ int32_t l = 0;
+ int32_t r = 0;
for (size_t i=0 ; i<count ; i++) {
interpolate<CHANNELS>(l, r, coefsP++, offset, lerpP, sP);
sP -= CHANNELS;
interpolate<CHANNELS>(l, r, coefsN++, offset, lerpN, sN);
sN += CHANNELS;
}
- l = 2 * mulRL(1, l, vRL);
- r = 2 * mulRL(0, r, vRL);
+ out[0] += 2 * mulRL(1, l, vRL);
+ out[1] += 2 * mulRL(0, r, vRL);
} else if (CHANNELS == 1) {
int32_t const* coefsP1 = coefsP + offset;
int32_t const* coefsN1 = coefsN + offset;
@@ -670,15 +680,16 @@
asm (
"vmov.32 d2[0], %[lerpP] \n" // load the positive phase
"vmov.32 d2[1], %[lerpN] \n" // load the negative phase
- "veor q0, q0 \n" // result, initialize to 0
+ "veor q0, q0, q0 \n" // result, initialize to 0
+ "vshl.s32 d2, d2, #16 \n" // convert to 32 bits
"1: \n"
"vld1.16 { d4}, [%[sP]] \n" // load 4 16-bits stereo samples
- "vld1.32 { q8}, [%[coefsP0]]! \n" // load 4 32-bits coefs
- "vld1.32 { q9}, [%[coefsP1]]! \n" // load 4 32-bits coefs for interpolation
+ "vld1.32 { q8}, [%[coefsP0]:128]! \n" // load 4 32-bits coefs
+ "vld1.32 { q9}, [%[coefsP1]:128]! \n" // load 4 32-bits coefs for interpolation
"vld1.16 { d6}, [%[sN]]! \n" // load 4 16-bits stereo samples
- "vld1.32 {q10}, [%[coefsN0]]! \n" // load 4 32-bits coefs
- "vld1.32 {q11}, [%[coefsN1]]! \n" // load 4 32-bits coefs for interpolation
+ "vld1.32 {q10}, [%[coefsN0]:128]! \n" // load 4 32-bits coefs
+ "vld1.32 {q11}, [%[coefsN1]:128]! \n" // load 4 32-bits coefs for interpolation
"vrev64.16 d4, d4 \n" // reverse 2 frames of the positive side
@@ -703,12 +714,16 @@
"bne 1b \n" // loop
+ "vld1.s32 {d2}, [%[vLR]] \n" // load volumes
+ "vld1.s32 {d3}, %[out] \n" // load the output
"vpadd.s32 d0, d0, d1 \n" // add all 4 partial sums
"vpadd.s32 d0, d0, d0 \n" // together
+ "vdup.i32 d0, d0[0] \n" // interleave L,R channels
+ "vqrdmulh.s32 d0, d0, d2 \n" // apply volume
+ "vadd.s32 d3, d3, d0 \n" // accumulate result
+ "vst1.s32 {d0}, %[out] \n" // store result
- "vmov.s32 %[l], d0[0] \n" // save result in ARM register
-
- : [l] "=r" (l),
+ : [out] "=Uv" (out[0]),
[count] "+r" (count),
[coefsP0] "+r" (coefsP),
[coefsP1] "+r" (coefsP1),
@@ -716,16 +731,14 @@
[coefsN1] "+r" (coefsN1),
[sP] "+r" (sP),
[sN] "+r" (sN)
- : [lerpP] "r" (lerpP<<16),
- [lerpN] "r" (lerpN<<16),
- [vRL] "r" (vRL)
+ : [lerpP] "r" (lerpP),
+ [lerpN] "r" (lerpN),
+ [vLR] "r" (mVolumeSIMD)
: "cc", "memory",
"q0", "q1", "q2", "q3",
"q8", "q9", "q10", "q11",
"q12", "q14"
);
- l = 2 * mulRL(1, l, vRL);
- r = l;
} else if (CHANNELS == 2) {
int32_t const* coefsP1 = coefsP + offset;
int32_t const* coefsN1 = coefsN + offset;
@@ -733,16 +746,17 @@
asm (
"vmov.32 d2[0], %[lerpP] \n" // load the positive phase
"vmov.32 d2[1], %[lerpN] \n" // load the negative phase
- "veor q0, q0 \n" // result, initialize to 0
- "veor q4, q4 \n" // result, initialize to 0
+ "veor q0, q0, q0 \n" // result, initialize to 0
+ "veor q4, q4, q4 \n" // result, initialize to 0
+ "vshl.s32 d2, d2, #16 \n" // convert to 32 bits
"1: \n"
"vld2.16 {d4,d5}, [%[sP]] \n" // load 4 16-bits stereo samples
- "vld1.32 { q8}, [%[coefsP0]]! \n" // load 4 32-bits coefs
- "vld1.32 { q9}, [%[coefsP1]]! \n" // load 4 32-bits coefs for interpolation
+ "vld1.32 { q8}, [%[coefsP0]:128]! \n" // load 4 32-bits coefs
+ "vld1.32 { q9}, [%[coefsP1]:128]! \n" // load 4 32-bits coefs for interpolation
"vld2.16 {d6,d7}, [%[sN]]! \n" // load 4 16-bits stereo samples
- "vld1.32 {q10}, [%[coefsN0]]! \n" // load 4 32-bits coefs
- "vld1.32 {q11}, [%[coefsN1]]! \n" // load 4 32-bits coefs for interpolation
+ "vld1.32 {q10}, [%[coefsN0]:128]! \n" // load 4 32-bits coefs
+ "vld1.32 {q11}, [%[coefsN1]:128]! \n" // load 4 32-bits coefs for interpolation
"vrev64.16 d4, d4 \n" // reverse 2 frames of the positive side
"vrev64.16 d5, d5 \n" // reverse 2 frames of the positive side
@@ -774,16 +788,18 @@
"bne 1b \n" // loop
- "vpadd.s32 d0, d0, d1 \n" // add all 4 partial sums
- "vpadd.s32 d8, d8, d9 \n" // add all 4 partial sums
+ "vld1.s32 {d2}, [%[vLR]] \n" // load volumes
+ "vld1.s32 {d3}, %[out] \n" // load the output
+ "vpadd.s32 d0, d0, d1 \n" // add all 4 partial sums from q0
+ "vpadd.s32 d8, d8, d9 \n" // add all 4 partial sums from q4
"vpadd.s32 d0, d0, d0 \n" // together
"vpadd.s32 d8, d8, d8 \n" // together
+ "vtrn.s32 d0, d8 \n" // interlace L,R channels
+ "vqrdmulh.s32 d0, d0, d2 \n" // apply volume
+ "vadd.s32 d3, d3, d0 \n" // accumulate result
+ "vst1.s32 {d0}, %[out] \n" // store result
- "vmov.s32 %[l], d0[0] \n" // save result in ARM register
- "vmov.s32 %[r], d8[0] \n" // save result in ARM register
-
- : [l] "=r" (l),
- [r] "=r" (r),
+ : [out] "=Uv" (out[0]),
[count] "+r" (count),
[coefsP0] "+r" (coefsP),
[coefsP1] "+r" (coefsP1),
@@ -791,16 +807,14 @@
[coefsN1] "+r" (coefsN1),
[sP] "+r" (sP),
[sN] "+r" (sN)
- : [lerpP] "r" (lerpP<<16),
- [lerpN] "r" (lerpN<<16),
- [vRL] "r" (vRL)
+ : [lerpP] "r" (lerpP),
+ [lerpN] "r" (lerpN),
+ [vLR] "r" (mVolumeSIMD)
: "cc", "memory",
"q0", "q1", "q2", "q3", "q4",
"q8", "q9", "q10", "q11",
"q12", "q13", "q14", "q15"
);
- l = 2 * mulRL(1, l, vRL);
- r = 2 * mulRL(0, r, vRL);
}
}
diff --git a/services/audioflinger/AudioResamplerSinc.h b/services/audioflinger/AudioResamplerSinc.h
index 1b14019..09c6866 100644
--- a/services/audioflinger/AudioResamplerSinc.h
+++ b/services/audioflinger/AudioResamplerSinc.h
@@ -44,13 +44,15 @@
private:
void init();
+ virtual void setVolume(int16_t left, int16_t right);
+
template<int CHANNELS>
void resample(int32_t* out, size_t outFrameCount,
AudioBufferProvider* provider);
template<int CHANNELS>
inline void filterCoefficient(
- int32_t& l, int32_t& r, uint32_t phase, const int16_t *samples, uint32_t vRL);
+ int32_t* out, uint32_t phase, const int16_t *samples, uint32_t vRL);
template<int CHANNELS>
inline void interpolate(
@@ -65,6 +67,7 @@
int16_t *mState;
int16_t *mImpulse;
int16_t *mRingFull;
+ int32_t mVolumeSIMD[2];
const int32_t * mFirCoefs;
static const int32_t mFirCoefsDown[];
@@ -75,14 +78,11 @@
static const int32_t RESAMPLE_FIR_LERP_INT_BITS = 7;
struct Constants {
- // we have 16 coefs samples per zero-crossing
int coefsBits;
int cShift;
uint32_t cMask;
-
int pShift;
uint32_t pMask;
-
// number of zero-crossing on each side
unsigned int halfNumCoefs;
};
diff --git a/services/audioflinger/StateQueue.h b/services/audioflinger/StateQueue.h
index c9b5111..e33b3c6 100644
--- a/services/audioflinger/StateQueue.h
+++ b/services/audioflinger/StateQueue.h
@@ -174,7 +174,7 @@
#endif
private:
- static const unsigned kN = 4; // values != 4 are not supported by this code
+ static const unsigned kN = 4; // values < 4 are not supported by this code
T mStates[kN]; // written by mutator, read by observer
// "volatile" is meaningless with SMP, but here it indicates that we're using atomic ops
diff --git a/services/audioflinger/test-resample.cpp b/services/audioflinger/test-resample.cpp
index 3b66530..b082e8c 100644
--- a/services/audioflinger/test-resample.cpp
+++ b/services/audioflinger/test-resample.cpp
@@ -177,7 +177,7 @@
double t = double(i) / input_freq;
double y = sin(M_PI * k * t * t);
int16_t yi = floor(y * 32767.0 + 0.5);
- for (size_t j=0 ; j<channels ; j++) {
+ for (size_t j=0 ; j<(size_t)channels ; j++) {
in[i*channels + j] = yi / (1+j);
}
}