AAudioService: integrated with audioserver
Call the MmapStreamInterface from AudioFlinger instead of the FakeHAL.
Fix sending timestamps from the thread.
Add shared mode in service.
Bug: 35260844
Bug: 33398120
Test: CTS test_aaudio.cpp
Change-Id: I44c7e4ecae4ce205611b6b73a72e0ae8a5b243e5
Signed-off-by: Phil Burk <philburk@google.com>
(cherry picked from commit 7f6b40d78b1976c78d1300e8a51fda36eeb50c5d)
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 7eb179a..2a7194b 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -2133,7 +2133,7 @@
return BAD_VALUE;
}
mMmapThreads.removeItem(output);
- ALOGV("closing mmapThread %p", mmapThread.get());
+ ALOGD("closing mmapThread %p", mmapThread.get());
}
const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor();
ioDesc->mIoHandle = output;
@@ -2148,7 +2148,7 @@
closeOutputFinish(playbackThread);
}
} else if (mmapThread != 0) {
- ALOGV("mmapThread exit()");
+ ALOGD("mmapThread exit()");
mmapThread->exit();
AudioStreamOut *out = mmapThread->clearOutput();
ALOG_ASSERT(out != NULL, "out shouldn't be NULL");
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 3b1edec..3a72c3c 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -7585,7 +7585,11 @@
if (mActiveTracks.size() == 0) {
// for the first track, reuse portId and session allocated when the stream was opened
- mHalStream->start();
+ ret = mHalStream->start();
+ if (ret != NO_ERROR) {
+ ALOGE("%s: error mHalStream->start() = %d for first track", __FUNCTION__, ret);
+ return ret;
+ }
portId = mPortId;
sessionId = mSessionId;
mStandby = false;
@@ -7640,6 +7644,7 @@
// abort if start is rejected by audio policy manager
if (ret != NO_ERROR) {
+ ALOGE("%s: error start rejected by AudioPolicyManager = %d", __FUNCTION__, ret);
if (mActiveTracks.size() != 0) {
if (isOutput()) {
AudioSystem::releaseOutput(mId, streamType(), sessionId);
@@ -7935,15 +7940,17 @@
if (isOutput() && mPrevOutDevice != mOutDevice) {
mPrevOutDevice = type;
sendIoConfigEvent_l(AUDIO_OUTPUT_CONFIG_CHANGED);
- if (mCallback != 0) {
- mCallback->onRoutingChanged(deviceId);
+ sp<MmapStreamCallback> callback = mCallback.promote();
+ if (callback != 0) {
+ callback->onRoutingChanged(deviceId);
}
}
if (!isOutput() && mPrevInDevice != mInDevice) {
mPrevInDevice = type;
sendIoConfigEvent_l(AUDIO_INPUT_CONFIG_CHANGED);
- if (mCallback != 0) {
- mCallback->onRoutingChanged(deviceId);
+ sp<MmapStreamCallback> callback = mCallback.promote();
+ if (callback != 0) {
+ callback->onRoutingChanged(deviceId);
}
}
return status;
@@ -8058,8 +8065,9 @@
void AudioFlinger::MmapThread::threadLoop_exit()
{
- if (mCallback != 0) {
- mCallback->onTearDown();
+ sp<MmapStreamCallback> callback = mCallback.promote();
+ if (callback != 0) {
+ callback->onTearDown();
}
}
@@ -8107,8 +8115,9 @@
{
for (const sp<MmapTrack> &track : mActiveTracks) {
if (track->isInvalid()) {
- if (mCallback != 0) {
- mCallback->onTearDown();
+ sp<MmapStreamCallback> callback = mCallback.promote();
+ if (callback != 0) {
+ callback->onTearDown();
}
break;
}
@@ -8285,7 +8294,8 @@
mOutput->stream->setVolume(volume, volume);
- if (mCallback != 0) {
+ sp<MmapStreamCallback> callback = mCallback.promote();
+ if (callback != 0) {
int channelCount;
if (isOutput()) {
channelCount = audio_channel_count_from_out_mask(mChannelMask);
@@ -8296,7 +8306,7 @@
for (int i = 0; i < channelCount; i++) {
values.add(volume);
}
- mCallback->onVolumeChanged(mChannelMask, values);
+ callback->onVolumeChanged(mChannelMask, values);
}
}
}
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index 8270e74..fbbfad7 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -1527,7 +1527,7 @@
audio_session_t mSessionId;
audio_port_handle_t mPortId;
- sp<MmapStreamCallback> mCallback;
+ wp<MmapStreamCallback> mCallback;
sp<StreamHalInterface> mHalStream;
sp<DeviceHalInterface> mHalDevice;
AudioHwDevice* const mAudioHwDev;