diff options
Diffstat (limited to 'libs/audioflinger/A2dpAudioInterface.cpp')
-rw-r--r-- | libs/audioflinger/A2dpAudioInterface.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/libs/audioflinger/A2dpAudioInterface.cpp b/libs/audioflinger/A2dpAudioInterface.cpp index eb00f8c..d1b7af3 100644 --- a/libs/audioflinger/A2dpAudioInterface.cpp +++ b/libs/audioflinger/A2dpAudioInterface.cpp @@ -131,7 +131,8 @@ status_t A2dpAudioInterface::dump(int fd, const Vector<String16>& args) // ---------------------------------------------------------------------------- A2dpAudioInterface::A2dpAudioStreamOut::A2dpAudioStreamOut() : - mFd(-1), mStandby(true), mStartCount(0), mRetryCount(0), mData(NULL) + mFd(-1), mStandby(true), mStartCount(0), mRetryCount(0), mData(NULL), + mInitialized(false) { // use any address by default strncpy(mA2dpAddress, "00:00:00:00:00:00", sizeof(mA2dpAddress)); @@ -166,14 +167,13 @@ ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t status_t status = NO_INIT; size_t remaining = bytes; - if (!mData) { - status = a2dp_init(44100, 2, &mData); + if (!mInitialized) { + status = a2dp_init(mA2dpAddress, 44100, 2, &mData); if (status < 0) { LOGE("a2dp_init failed err: %d\n", status); - mData = NULL; goto Error; } - a2dp_set_sink(mData, mA2dpAddress); + mInitialized = true; } while (remaining > 0) { @@ -191,6 +191,7 @@ ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t return bytes; Error: + close(); // Simulate audio output timing in case of error usleep(bytes * 1000000 / frameSize() / sampleRate()); @@ -217,8 +218,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setAddress(const char* address) if (strcmp(address, mA2dpAddress)) { strcpy(mA2dpAddress, address); - if (mData) - a2dp_set_sink(mData, mA2dpAddress); + close(); } return NO_ERROR; @@ -229,6 +229,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::close() if (mData) { a2dp_cleanup(mData); mData = NULL; + mInitialized = false; } return NO_ERROR; } |