Loading media/libaaudio/src/client/AudioStreamInternal.cpp +29 −12 Original line number Diff line number Diff line Loading @@ -61,7 +61,6 @@ AudioStreamInternal::AudioStreamInternal(AAudioServiceInterface &serviceInterfa , mClockModel() , mAudioEndpoint() , mServiceStreamHandle(AAUDIO_HANDLE_INVALID) , mFramesPerBurst(16) , mInService(inService) , mServiceInterface(serviceInterface) , mAtomicTimestamp() Loading @@ -79,6 +78,7 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) { aaudio_result_t result = AAUDIO_OK; int32_t capacity; int32_t framesPerBurst; AAudioStreamRequest request; AAudioStreamConfiguration configurationOutput; Loading Loading @@ -151,16 +151,18 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) { goto error; } mFramesPerBurst = mEndpointDescriptor.dataQueueDescriptor.framesPerBurst; capacity = mEndpointDescriptor.dataQueueDescriptor.capacityInFrames; // Validate result from server. if (mFramesPerBurst < 16 || mFramesPerBurst > 16 * 1024) { ALOGE("%s - framesPerBurst out of range = %d", __func__, mFramesPerBurst); framesPerBurst = mEndpointDescriptor.dataQueueDescriptor.framesPerBurst; if (framesPerBurst < MIN_FRAMES_PER_BURST || framesPerBurst > MAX_FRAMES_PER_BURST) { ALOGE("%s - framesPerBurst out of range = %d", __func__, framesPerBurst); result = AAUDIO_ERROR_OUT_OF_RANGE; goto error; } if (capacity < mFramesPerBurst || capacity > 32 * 1024) { mFramesPerBurst = framesPerBurst; // only save good value capacity = mEndpointDescriptor.dataQueueDescriptor.capacityInFrames; if (capacity < mFramesPerBurst || capacity > MAX_BUFFER_CAPACITY_IN_FRAMES) { ALOGE("%s - bufferCapacity out of range = %d", __func__, capacity); result = AAUDIO_ERROR_OUT_OF_RANGE; goto error; Loading Loading @@ -649,14 +651,29 @@ void AudioStreamInternal::processTimestamp(uint64_t position, int64_t time) { } aaudio_result_t AudioStreamInternal::setBufferSize(int32_t requestedFrames) { int32_t adjustedFrames = requestedFrames; int32_t actualFrames = 0; int32_t maximumSize = getBufferCapacity(); // Clip to minimum size so that rounding up will work better. if (adjustedFrames < 1) { adjustedFrames = 1; } if (adjustedFrames > maximumSize) { // Clip to maximum size. adjustedFrames = maximumSize; } else { // Round to the next highest burst size. if (getFramesPerBurst() > 0) { int32_t numBursts = (requestedFrames + getFramesPerBurst() - 1) / getFramesPerBurst(); requestedFrames = numBursts * getFramesPerBurst(); int32_t numBursts = (adjustedFrames + mFramesPerBurst - 1) / mFramesPerBurst; adjustedFrames = numBursts * mFramesPerBurst; // Rounding may have gone above maximum. if (adjustedFrames > maximumSize) { adjustedFrames = maximumSize; } } aaudio_result_t result = mAudioEndpoint.setBufferSizeInFrames(requestedFrames, &actualFrames); aaudio_result_t result = mAudioEndpoint.setBufferSizeInFrames(adjustedFrames, &actualFrames); ALOGD("setBufferSize() req = %d => %d", requestedFrames, actualFrames); if (result < 0) { return result; Loading @@ -674,7 +691,7 @@ int32_t AudioStreamInternal::getBufferCapacity() const { } int32_t AudioStreamInternal::getFramesPerBurst() const { return mEndpointDescriptor.dataQueueDescriptor.framesPerBurst; return mFramesPerBurst; } aaudio_result_t AudioStreamInternal::joinThread(void** returnArg) { Loading media/libaaudio/src/client/AudioStreamInternal.h +7 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,12 @@ using android::IAAudioService; namespace aaudio { // These are intended to be outside the range of what is normally encountered. // TODO MAXes should probably be much bigger. constexpr int32_t MIN_FRAMES_PER_BURST = 16; // arbitrary constexpr int32_t MAX_FRAMES_PER_BURST = 16 * 1024; // arbitrary constexpr int32_t MAX_BUFFER_CAPACITY_IN_FRAMES = 32 * 1024; // arbitrary // A stream that talks to the AAudioService or directly to a HAL. class AudioStreamInternal : public AudioStream { Loading Loading @@ -141,7 +147,7 @@ protected: AudioEndpoint mAudioEndpoint; // source for reads or sink for writes aaudio_handle_t mServiceStreamHandle; // opaque handle returned from service int32_t mFramesPerBurst; // frames per HAL transfer int32_t mFramesPerBurst = MIN_FRAMES_PER_BURST; // frames per HAL transfer int32_t mXRunCount = 0; // how many underrun events? // Offset from underlying frame position. Loading Loading
media/libaaudio/src/client/AudioStreamInternal.cpp +29 −12 Original line number Diff line number Diff line Loading @@ -61,7 +61,6 @@ AudioStreamInternal::AudioStreamInternal(AAudioServiceInterface &serviceInterfa , mClockModel() , mAudioEndpoint() , mServiceStreamHandle(AAUDIO_HANDLE_INVALID) , mFramesPerBurst(16) , mInService(inService) , mServiceInterface(serviceInterface) , mAtomicTimestamp() Loading @@ -79,6 +78,7 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) { aaudio_result_t result = AAUDIO_OK; int32_t capacity; int32_t framesPerBurst; AAudioStreamRequest request; AAudioStreamConfiguration configurationOutput; Loading Loading @@ -151,16 +151,18 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) { goto error; } mFramesPerBurst = mEndpointDescriptor.dataQueueDescriptor.framesPerBurst; capacity = mEndpointDescriptor.dataQueueDescriptor.capacityInFrames; // Validate result from server. if (mFramesPerBurst < 16 || mFramesPerBurst > 16 * 1024) { ALOGE("%s - framesPerBurst out of range = %d", __func__, mFramesPerBurst); framesPerBurst = mEndpointDescriptor.dataQueueDescriptor.framesPerBurst; if (framesPerBurst < MIN_FRAMES_PER_BURST || framesPerBurst > MAX_FRAMES_PER_BURST) { ALOGE("%s - framesPerBurst out of range = %d", __func__, framesPerBurst); result = AAUDIO_ERROR_OUT_OF_RANGE; goto error; } if (capacity < mFramesPerBurst || capacity > 32 * 1024) { mFramesPerBurst = framesPerBurst; // only save good value capacity = mEndpointDescriptor.dataQueueDescriptor.capacityInFrames; if (capacity < mFramesPerBurst || capacity > MAX_BUFFER_CAPACITY_IN_FRAMES) { ALOGE("%s - bufferCapacity out of range = %d", __func__, capacity); result = AAUDIO_ERROR_OUT_OF_RANGE; goto error; Loading Loading @@ -649,14 +651,29 @@ void AudioStreamInternal::processTimestamp(uint64_t position, int64_t time) { } aaudio_result_t AudioStreamInternal::setBufferSize(int32_t requestedFrames) { int32_t adjustedFrames = requestedFrames; int32_t actualFrames = 0; int32_t maximumSize = getBufferCapacity(); // Clip to minimum size so that rounding up will work better. if (adjustedFrames < 1) { adjustedFrames = 1; } if (adjustedFrames > maximumSize) { // Clip to maximum size. adjustedFrames = maximumSize; } else { // Round to the next highest burst size. if (getFramesPerBurst() > 0) { int32_t numBursts = (requestedFrames + getFramesPerBurst() - 1) / getFramesPerBurst(); requestedFrames = numBursts * getFramesPerBurst(); int32_t numBursts = (adjustedFrames + mFramesPerBurst - 1) / mFramesPerBurst; adjustedFrames = numBursts * mFramesPerBurst; // Rounding may have gone above maximum. if (adjustedFrames > maximumSize) { adjustedFrames = maximumSize; } } aaudio_result_t result = mAudioEndpoint.setBufferSizeInFrames(requestedFrames, &actualFrames); aaudio_result_t result = mAudioEndpoint.setBufferSizeInFrames(adjustedFrames, &actualFrames); ALOGD("setBufferSize() req = %d => %d", requestedFrames, actualFrames); if (result < 0) { return result; Loading @@ -674,7 +691,7 @@ int32_t AudioStreamInternal::getBufferCapacity() const { } int32_t AudioStreamInternal::getFramesPerBurst() const { return mEndpointDescriptor.dataQueueDescriptor.framesPerBurst; return mFramesPerBurst; } aaudio_result_t AudioStreamInternal::joinThread(void** returnArg) { Loading
media/libaaudio/src/client/AudioStreamInternal.h +7 −1 Original line number Diff line number Diff line Loading @@ -34,6 +34,12 @@ using android::IAAudioService; namespace aaudio { // These are intended to be outside the range of what is normally encountered. // TODO MAXes should probably be much bigger. constexpr int32_t MIN_FRAMES_PER_BURST = 16; // arbitrary constexpr int32_t MAX_FRAMES_PER_BURST = 16 * 1024; // arbitrary constexpr int32_t MAX_BUFFER_CAPACITY_IN_FRAMES = 32 * 1024; // arbitrary // A stream that talks to the AAudioService or directly to a HAL. class AudioStreamInternal : public AudioStream { Loading Loading @@ -141,7 +147,7 @@ protected: AudioEndpoint mAudioEndpoint; // source for reads or sink for writes aaudio_handle_t mServiceStreamHandle; // opaque handle returned from service int32_t mFramesPerBurst; // frames per HAL transfer int32_t mFramesPerBurst = MIN_FRAMES_PER_BURST; // frames per HAL transfer int32_t mXRunCount = 0; // how many underrun events? // Offset from underlying frame position. Loading