Loading media/libaaudio/src/client/AudioStreamInternal.cpp +12 −42 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ #define ATRACE_TAG ATRACE_TAG_AUDIO #include <stdint.h> #include <assert.h> #include <binder/IServiceManager.h> Loading Loading @@ -63,7 +62,6 @@ AudioStreamInternal::AudioStreamInternal(AAudioServiceInterface &serviceInterfa , mAudioEndpoint() , mServiceStreamHandle(AAUDIO_HANDLE_INVALID) , mFramesPerBurst(16) , mStreamVolume(1.0f) , mInService(inService) , mServiceInterface(serviceInterface) , mAtomicTimestamp() Loading Loading @@ -196,10 +194,6 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) { } setState(AAUDIO_STREAM_STATE_OPEN); // Only connect to AudioManager if this is a playback stream running in client process. if (!mInService && getDirection() == AAUDIO_DIRECTION_OUTPUT) { init(android::PLAYER_TYPE_AAUDIO, AUDIO_USAGE_MEDIA); } return result; Loading @@ -209,7 +203,8 @@ error: } aaudio_result_t AudioStreamInternal::close() { ALOGD("AudioStreamInternal::close(): mServiceStreamHandle = 0x%08X", aaudio_result_t result = AAUDIO_OK; ALOGD("close(): mServiceStreamHandle = 0x%08X", mServiceStreamHandle); if (mServiceStreamHandle != AAUDIO_HANDLE_INVALID) { // Don't close a stream while it is running. Loading @@ -218,10 +213,10 @@ aaudio_result_t AudioStreamInternal::close() { requestStop(); aaudio_stream_state_t nextState; int64_t timeoutNanoseconds = MIN_TIMEOUT_NANOS; aaudio_result_t result = waitForStateChange(currentState, &nextState, result = waitForStateChange(currentState, &nextState, timeoutNanoseconds); if (result != AAUDIO_OK) { ALOGE("AudioStreamInternal::close() waitForStateChange() returned %d %s", ALOGE("close() waitForStateChange() returned %d %s", result, AAudio_convertResultToText(result)); } } Loading @@ -232,8 +227,11 @@ aaudio_result_t AudioStreamInternal::close() { mServiceInterface.closeStream(serviceStreamHandle); delete[] mCallbackBuffer; mCallbackBuffer = nullptr; setState(AAUDIO_STREAM_STATE_CLOSED); return mEndPointParcelable.close(); result = mEndPointParcelable.close(); aaudio_result_t result2 = AudioStream::close(); return (result != AAUDIO_OK) ? result : result2; } else { return AAUDIO_ERROR_INVALID_HANDLE; } Loading Loading @@ -283,13 +281,13 @@ aaudio_result_t AudioStreamInternal::requestStart() // Clear any stale timestamps from the previous run. drainTimestampsFromService(); status_t status = startWithStatus(); // Call PlayerBase, which will start the device stream. aaudio_result_t result = AAudioConvert_androidToAAudioResult(status); aaudio_result_t result = mServiceInterface.startStream(mServiceStreamHandle); startTime = AudioClock::getNanoseconds(); mClockModel.start(startTime); mNeedCatchUp.request(); // Ask data processing code to catch up when first timestamp received. // Start data callback thread. if (result == AAUDIO_OK && getDataCallbackProc() != nullptr) { // Launch the callback loop thread. int64_t periodNanos = mCallbackFrames Loading Loading @@ -342,7 +340,8 @@ aaudio_result_t AudioStreamInternal::requestStopInternal() mClockModel.stop(AudioClock::getNanoseconds()); setState(AAUDIO_STREAM_STATE_STOPPING); mAtomicTimestamp.clear(); return AAudioConvert_androidToAAudioResult(stopWithStatus()); return mServiceInterface.stopStream(mServiceStreamHandle); } aaudio_result_t AudioStreamInternal::requestStop() Loading Loading @@ -687,32 +686,3 @@ int32_t AudioStreamInternal::getFramesPerBurst() const { aaudio_result_t AudioStreamInternal::joinThread(void** returnArg) { return AudioStream::joinThread(returnArg, calculateReasonableTimeout(getFramesPerBurst())); } void AudioStreamInternal::doSetVolume() { // No pan and only left volume is taken into account from IPLayer interface mVolumeRamp.setTarget(mStreamVolume * mVolumeMultiplierL /* * mPanMultiplierL */); } //------------------------------------------------------------------------------ // Implementation of PlayerBase status_t AudioStreamInternal::playerStart() { return AAudioConvert_aaudioToAndroidStatus(mServiceInterface.startStream(mServiceStreamHandle)); } status_t AudioStreamInternal::playerPause() { return AAudioConvert_aaudioToAndroidStatus(mServiceInterface.pauseStream(mServiceStreamHandle)); } status_t AudioStreamInternal::playerStop() { return AAudioConvert_aaudioToAndroidStatus(mServiceInterface.stopStream(mServiceStreamHandle)); } status_t AudioStreamInternal::playerSetVolume() { doSetVolume(); return NO_ERROR; } void AudioStreamInternal::destroy() { baseDestroy(); } media/libaaudio/src/client/AudioStreamInternal.h +3 −17 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ #define ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_H #include <stdint.h> #include <media/PlayerBase.h> #include <aaudio/AAudio.h> #include "binding/IAAudioService.h" Loading @@ -36,7 +35,7 @@ using android::IAAudioService; namespace aaudio { // A stream that talks to the AAudioService or directly to a HAL. class AudioStreamInternal : public AudioStream, public android::PlayerBase { class AudioStreamInternal : public AudioStream { public: AudioStreamInternal(AAudioServiceInterface &serviceInterface, bool inService); Loading Loading @@ -85,9 +84,6 @@ public: // Calculate timeout based on framesPerBurst int64_t calculateReasonableTimeout(); //PlayerBase virtuals virtual void destroy(); aaudio_result_t startClient(const android::AudioClient& client, audio_port_handle_t *clientHandle); Loading Loading @@ -138,14 +134,6 @@ protected: // Calculate timeout for an operation involving framesPerOperation. int64_t calculateReasonableTimeout(int32_t framesPerOperation); void doSetVolume(); //PlayerBase virtuals virtual status_t playerStart(); virtual status_t playerPause(); virtual status_t playerStop(); virtual status_t playerSetVolume(); aaudio_format_t mDeviceFormat = AAUDIO_FORMAT_UNSPECIFIED; IsochronousClockModel mClockModel; // timing model for chasing the HAL Loading @@ -156,9 +144,6 @@ protected: int32_t mFramesPerBurst; // frames per HAL transfer int32_t mXRunCount = 0; // how many underrun events? LinearRamp mVolumeRamp; float mStreamVolume; // Offset from underlying frame position. int64_t mFramesOffsetFromService = 0; // offset for timestamps Loading @@ -174,6 +159,8 @@ protected: AtomicRequestor mNeedCatchUp; // Ask read() or write() to sync on first timestamp. float mStreamVolume = 1.0f; private: /* * Asynchronous write with data conversion. Loading @@ -196,7 +183,6 @@ private: EndpointDescriptor mEndpointDescriptor; // buffer description with resolved addresses int64_t mServiceLatencyNanos = 0; }; } /* namespace aaudio */ Loading media/libaaudio/src/client/AudioStreamInternalPlay.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ aaudio_result_t AudioStreamInternalPlay::requestPauseInternal() mClockModel.stop(AudioClock::getNanoseconds()); setState(AAUDIO_STREAM_STATE_PAUSING); mAtomicTimestamp.clear(); return AAudioConvert_androidToAAudioResult(pauseWithStatus()); return mServiceInterface.pauseStream(mServiceStreamHandle); } aaudio_result_t AudioStreamInternalPlay::requestPause() Loading Loading @@ -290,7 +290,6 @@ aaudio_result_t AudioStreamInternalPlay::writeNowWithConversion(const void *buff return framesWritten; } int64_t AudioStreamInternalPlay::getFramesRead() { int64_t framesReadHardware; Loading Loading @@ -364,3 +363,10 @@ void *AudioStreamInternalPlay::callbackLoop() { result, (int) isActive()); return NULL; } //------------------------------------------------------------------------------ // Implementation of PlayerBase status_t AudioStreamInternalPlay::doSetVolume() { mVolumeRamp.setTarget(mStreamVolume * getDuckAndMuteVolume()); return android::NO_ERROR; } media/libaaudio/src/client/AudioStreamInternalPlay.h +8 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,9 @@ public: return AAUDIO_DIRECTION_OUTPUT; } // Only register client side streams. bool needsSystemRegistration() override { return !mInService; } protected: aaudio_result_t requestPauseInternal(); Loading @@ -58,6 +61,8 @@ protected: void onFlushFromServer() override; android::status_t doSetVolume() override; /** * Low level write that will not block. It will just write as much as it can. * Loading @@ -80,6 +85,9 @@ private: int32_t numFrames); int64_t mLastFramesRead = 0; // used to prevent retrograde motion LinearRamp mVolumeRamp; }; } /* namespace aaudio */ Loading media/libaaudio/src/core/AAudioAudio.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -219,6 +219,7 @@ AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* ALOGD("AAudioStreamBuilder_openStream() returns %d = %s for (%p) ----------------", result, AAudio_convertResultToText(result), audioStream); if (result == AAUDIO_OK) { audioStream->systemRegister(); *streamPtr = (AAudioStream*) audioStream; } else { *streamPtr = nullptr; Loading @@ -242,6 +243,7 @@ AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) ALOGD("AAudioStream_close(%p)", stream); if (audioStream != nullptr) { audioStream->close(); audioStream->systemUnRegister(); delete audioStream; return AAUDIO_OK; } Loading @@ -252,7 +254,7 @@ AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); ALOGD("AAudioStream_requestStart(%p) called --------------", stream); aaudio_result_t result = audioStream->requestStart(); aaudio_result_t result = audioStream->systemStart(); ALOGD("AAudioStream_requestStart(%p) returned %d ---------", stream, result); return result; } Loading @@ -261,7 +263,7 @@ AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); ALOGD("AAudioStream_requestPause(%p)", stream); return audioStream->requestPause(); return audioStream->systemPause(); } AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) Loading @@ -275,7 +277,7 @@ AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); ALOGD("AAudioStream_requestStop(%p)", stream); return audioStream->requestStop(); return audioStream->systemStop(); } AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream, Loading Loading
media/libaaudio/src/client/AudioStreamInternal.cpp +12 −42 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ #define ATRACE_TAG ATRACE_TAG_AUDIO #include <stdint.h> #include <assert.h> #include <binder/IServiceManager.h> Loading Loading @@ -63,7 +62,6 @@ AudioStreamInternal::AudioStreamInternal(AAudioServiceInterface &serviceInterfa , mAudioEndpoint() , mServiceStreamHandle(AAUDIO_HANDLE_INVALID) , mFramesPerBurst(16) , mStreamVolume(1.0f) , mInService(inService) , mServiceInterface(serviceInterface) , mAtomicTimestamp() Loading Loading @@ -196,10 +194,6 @@ aaudio_result_t AudioStreamInternal::open(const AudioStreamBuilder &builder) { } setState(AAUDIO_STREAM_STATE_OPEN); // Only connect to AudioManager if this is a playback stream running in client process. if (!mInService && getDirection() == AAUDIO_DIRECTION_OUTPUT) { init(android::PLAYER_TYPE_AAUDIO, AUDIO_USAGE_MEDIA); } return result; Loading @@ -209,7 +203,8 @@ error: } aaudio_result_t AudioStreamInternal::close() { ALOGD("AudioStreamInternal::close(): mServiceStreamHandle = 0x%08X", aaudio_result_t result = AAUDIO_OK; ALOGD("close(): mServiceStreamHandle = 0x%08X", mServiceStreamHandle); if (mServiceStreamHandle != AAUDIO_HANDLE_INVALID) { // Don't close a stream while it is running. Loading @@ -218,10 +213,10 @@ aaudio_result_t AudioStreamInternal::close() { requestStop(); aaudio_stream_state_t nextState; int64_t timeoutNanoseconds = MIN_TIMEOUT_NANOS; aaudio_result_t result = waitForStateChange(currentState, &nextState, result = waitForStateChange(currentState, &nextState, timeoutNanoseconds); if (result != AAUDIO_OK) { ALOGE("AudioStreamInternal::close() waitForStateChange() returned %d %s", ALOGE("close() waitForStateChange() returned %d %s", result, AAudio_convertResultToText(result)); } } Loading @@ -232,8 +227,11 @@ aaudio_result_t AudioStreamInternal::close() { mServiceInterface.closeStream(serviceStreamHandle); delete[] mCallbackBuffer; mCallbackBuffer = nullptr; setState(AAUDIO_STREAM_STATE_CLOSED); return mEndPointParcelable.close(); result = mEndPointParcelable.close(); aaudio_result_t result2 = AudioStream::close(); return (result != AAUDIO_OK) ? result : result2; } else { return AAUDIO_ERROR_INVALID_HANDLE; } Loading Loading @@ -283,13 +281,13 @@ aaudio_result_t AudioStreamInternal::requestStart() // Clear any stale timestamps from the previous run. drainTimestampsFromService(); status_t status = startWithStatus(); // Call PlayerBase, which will start the device stream. aaudio_result_t result = AAudioConvert_androidToAAudioResult(status); aaudio_result_t result = mServiceInterface.startStream(mServiceStreamHandle); startTime = AudioClock::getNanoseconds(); mClockModel.start(startTime); mNeedCatchUp.request(); // Ask data processing code to catch up when first timestamp received. // Start data callback thread. if (result == AAUDIO_OK && getDataCallbackProc() != nullptr) { // Launch the callback loop thread. int64_t periodNanos = mCallbackFrames Loading Loading @@ -342,7 +340,8 @@ aaudio_result_t AudioStreamInternal::requestStopInternal() mClockModel.stop(AudioClock::getNanoseconds()); setState(AAUDIO_STREAM_STATE_STOPPING); mAtomicTimestamp.clear(); return AAudioConvert_androidToAAudioResult(stopWithStatus()); return mServiceInterface.stopStream(mServiceStreamHandle); } aaudio_result_t AudioStreamInternal::requestStop() Loading Loading @@ -687,32 +686,3 @@ int32_t AudioStreamInternal::getFramesPerBurst() const { aaudio_result_t AudioStreamInternal::joinThread(void** returnArg) { return AudioStream::joinThread(returnArg, calculateReasonableTimeout(getFramesPerBurst())); } void AudioStreamInternal::doSetVolume() { // No pan and only left volume is taken into account from IPLayer interface mVolumeRamp.setTarget(mStreamVolume * mVolumeMultiplierL /* * mPanMultiplierL */); } //------------------------------------------------------------------------------ // Implementation of PlayerBase status_t AudioStreamInternal::playerStart() { return AAudioConvert_aaudioToAndroidStatus(mServiceInterface.startStream(mServiceStreamHandle)); } status_t AudioStreamInternal::playerPause() { return AAudioConvert_aaudioToAndroidStatus(mServiceInterface.pauseStream(mServiceStreamHandle)); } status_t AudioStreamInternal::playerStop() { return AAudioConvert_aaudioToAndroidStatus(mServiceInterface.stopStream(mServiceStreamHandle)); } status_t AudioStreamInternal::playerSetVolume() { doSetVolume(); return NO_ERROR; } void AudioStreamInternal::destroy() { baseDestroy(); }
media/libaaudio/src/client/AudioStreamInternal.h +3 −17 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ #define ANDROID_AAUDIO_AUDIO_STREAM_INTERNAL_H #include <stdint.h> #include <media/PlayerBase.h> #include <aaudio/AAudio.h> #include "binding/IAAudioService.h" Loading @@ -36,7 +35,7 @@ using android::IAAudioService; namespace aaudio { // A stream that talks to the AAudioService or directly to a HAL. class AudioStreamInternal : public AudioStream, public android::PlayerBase { class AudioStreamInternal : public AudioStream { public: AudioStreamInternal(AAudioServiceInterface &serviceInterface, bool inService); Loading Loading @@ -85,9 +84,6 @@ public: // Calculate timeout based on framesPerBurst int64_t calculateReasonableTimeout(); //PlayerBase virtuals virtual void destroy(); aaudio_result_t startClient(const android::AudioClient& client, audio_port_handle_t *clientHandle); Loading Loading @@ -138,14 +134,6 @@ protected: // Calculate timeout for an operation involving framesPerOperation. int64_t calculateReasonableTimeout(int32_t framesPerOperation); void doSetVolume(); //PlayerBase virtuals virtual status_t playerStart(); virtual status_t playerPause(); virtual status_t playerStop(); virtual status_t playerSetVolume(); aaudio_format_t mDeviceFormat = AAUDIO_FORMAT_UNSPECIFIED; IsochronousClockModel mClockModel; // timing model for chasing the HAL Loading @@ -156,9 +144,6 @@ protected: int32_t mFramesPerBurst; // frames per HAL transfer int32_t mXRunCount = 0; // how many underrun events? LinearRamp mVolumeRamp; float mStreamVolume; // Offset from underlying frame position. int64_t mFramesOffsetFromService = 0; // offset for timestamps Loading @@ -174,6 +159,8 @@ protected: AtomicRequestor mNeedCatchUp; // Ask read() or write() to sync on first timestamp. float mStreamVolume = 1.0f; private: /* * Asynchronous write with data conversion. Loading @@ -196,7 +183,6 @@ private: EndpointDescriptor mEndpointDescriptor; // buffer description with resolved addresses int64_t mServiceLatencyNanos = 0; }; } /* namespace aaudio */ Loading
media/libaaudio/src/client/AudioStreamInternalPlay.cpp +8 −2 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ aaudio_result_t AudioStreamInternalPlay::requestPauseInternal() mClockModel.stop(AudioClock::getNanoseconds()); setState(AAUDIO_STREAM_STATE_PAUSING); mAtomicTimestamp.clear(); return AAudioConvert_androidToAAudioResult(pauseWithStatus()); return mServiceInterface.pauseStream(mServiceStreamHandle); } aaudio_result_t AudioStreamInternalPlay::requestPause() Loading Loading @@ -290,7 +290,6 @@ aaudio_result_t AudioStreamInternalPlay::writeNowWithConversion(const void *buff return framesWritten; } int64_t AudioStreamInternalPlay::getFramesRead() { int64_t framesReadHardware; Loading Loading @@ -364,3 +363,10 @@ void *AudioStreamInternalPlay::callbackLoop() { result, (int) isActive()); return NULL; } //------------------------------------------------------------------------------ // Implementation of PlayerBase status_t AudioStreamInternalPlay::doSetVolume() { mVolumeRamp.setTarget(mStreamVolume * getDuckAndMuteVolume()); return android::NO_ERROR; }
media/libaaudio/src/client/AudioStreamInternalPlay.h +8 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,9 @@ public: return AAUDIO_DIRECTION_OUTPUT; } // Only register client side streams. bool needsSystemRegistration() override { return !mInService; } protected: aaudio_result_t requestPauseInternal(); Loading @@ -58,6 +61,8 @@ protected: void onFlushFromServer() override; android::status_t doSetVolume() override; /** * Low level write that will not block. It will just write as much as it can. * Loading @@ -80,6 +85,9 @@ private: int32_t numFrames); int64_t mLastFramesRead = 0; // used to prevent retrograde motion LinearRamp mVolumeRamp; }; } /* namespace aaudio */ Loading
media/libaaudio/src/core/AAudioAudio.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -219,6 +219,7 @@ AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* ALOGD("AAudioStreamBuilder_openStream() returns %d = %s for (%p) ----------------", result, AAudio_convertResultToText(result), audioStream); if (result == AAUDIO_OK) { audioStream->systemRegister(); *streamPtr = (AAudioStream*) audioStream; } else { *streamPtr = nullptr; Loading @@ -242,6 +243,7 @@ AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) ALOGD("AAudioStream_close(%p)", stream); if (audioStream != nullptr) { audioStream->close(); audioStream->systemUnRegister(); delete audioStream; return AAUDIO_OK; } Loading @@ -252,7 +254,7 @@ AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); ALOGD("AAudioStream_requestStart(%p) called --------------", stream); aaudio_result_t result = audioStream->requestStart(); aaudio_result_t result = audioStream->systemStart(); ALOGD("AAudioStream_requestStart(%p) returned %d ---------", stream, result); return result; } Loading @@ -261,7 +263,7 @@ AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); ALOGD("AAudioStream_requestPause(%p)", stream); return audioStream->requestPause(); return audioStream->systemPause(); } AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) Loading @@ -275,7 +277,7 @@ AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) { AudioStream *audioStream = convertAAudioStreamToAudioStream(stream); ALOGD("AAudioStream_requestStop(%p)", stream); return audioStream->requestStop(); return audioStream->systemStop(); } AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream, Loading