Refactor AudioIoDescriptor
The following changes were made:
1. Make the class mostly immutable (except for the 'mPatch' field).
2. Provide constructors for specific use cases.
3. Add 'isInput' field instead of deducing it by patch data.
4. Provide conversion to string for logging.
5. Rename 'audio_io_config_event' to 'audio_io_config_event_t'
to conform to other enum type names.
Bug: 188932434
Test: m
Change-Id: I35e5c83bcb917f60d01ee977eef9b869c3894074
diff --git a/media/libaudioclient/AidlConversion.cpp b/media/libaudioclient/AidlConversion.cpp
index 2cfb916..60df8d5 100644
--- a/media/libaudioclient/AidlConversion.cpp
+++ b/media/libaudioclient/AidlConversion.cpp
@@ -289,7 +289,7 @@
return convertReinterpret<media::AudioChannelMask>(legacy);
}
-ConversionResult<audio_io_config_event> aidl2legacy_AudioIoConfigEvent_audio_io_config_event(
+ConversionResult<audio_io_config_event_t> aidl2legacy_AudioIoConfigEvent_audio_io_config_event_t(
media::AudioIoConfigEvent aidl) {
switch (aidl) {
case media::AudioIoConfigEvent::OUTPUT_REGISTERED:
@@ -314,8 +314,8 @@
return unexpected(BAD_VALUE);
}
-ConversionResult<media::AudioIoConfigEvent> legacy2aidl_audio_io_config_event_AudioIoConfigEvent(
- audio_io_config_event legacy) {
+ConversionResult<media::AudioIoConfigEvent> legacy2aidl_audio_io_config_event_t_AudioIoConfigEvent(
+ audio_io_config_event_t legacy) {
switch (legacy) {
case AUDIO_OUTPUT_REGISTERED:
return media::AudioIoConfigEvent::OUTPUT_REGISTERED;
@@ -1962,35 +1962,40 @@
ConversionResult<sp<AudioIoDescriptor>> aidl2legacy_AudioIoDescriptor_AudioIoDescriptor(
const media::AudioIoDescriptor& aidl) {
- sp<AudioIoDescriptor> legacy(new AudioIoDescriptor());
- legacy->mIoHandle = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_io_handle_t(aidl.ioHandle));
- legacy->mPatch = VALUE_OR_RETURN(aidl2legacy_AudioPatch_audio_patch(aidl.patch));
- legacy->mSamplingRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.samplingRate));
- legacy->mFormat = VALUE_OR_RETURN(
+ const audio_io_handle_t io_handle = VALUE_OR_RETURN(
+ aidl2legacy_int32_t_audio_io_handle_t(aidl.ioHandle));
+ const struct audio_patch patch = VALUE_OR_RETURN(
+ aidl2legacy_AudioPatch_audio_patch(aidl.patch));
+ const bool isInput = aidl.isInput;
+ const uint32_t sampling_rate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.samplingRate));
+ const audio_format_t format = VALUE_OR_RETURN(
aidl2legacy_AudioFormatDescription_audio_format_t(aidl.format));
- legacy->mChannelMask =
- VALUE_OR_RETURN(aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask));
- legacy->mFrameCount = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
- legacy->mFrameCountHAL = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCountHAL));
- legacy->mLatency = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.latency));
- legacy->mPortId = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
- return legacy;
+ const audio_channel_mask_t channel_mask = VALUE_OR_RETURN(
+ aidl2legacy_AudioChannelMask_audio_channel_mask_t(aidl.channelMask));
+ const size_t frame_count = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCount));
+ const size_t frame_count_hal = VALUE_OR_RETURN(convertIntegral<size_t>(aidl.frameCountHAL));
+ const uint32_t latency = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.latency));
+ const audio_port_handle_t port_id = VALUE_OR_RETURN(
+ aidl2legacy_int32_t_audio_port_handle_t(aidl.portId));
+ return sp<AudioIoDescriptor>::make(io_handle, patch, isInput, sampling_rate, format,
+ channel_mask, frame_count, frame_count_hal, latency, port_id);
}
ConversionResult<media::AudioIoDescriptor> legacy2aidl_AudioIoDescriptor_AudioIoDescriptor(
const sp<AudioIoDescriptor>& legacy) {
media::AudioIoDescriptor aidl;
- aidl.ioHandle = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(legacy->mIoHandle));
- aidl.patch = VALUE_OR_RETURN(legacy2aidl_audio_patch_AudioPatch(legacy->mPatch));
- aidl.samplingRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->mSamplingRate));
+ aidl.ioHandle = VALUE_OR_RETURN(legacy2aidl_audio_io_handle_t_int32_t(legacy->getIoHandle()));
+ aidl.patch = VALUE_OR_RETURN(legacy2aidl_audio_patch_AudioPatch(legacy->getPatch()));
+ aidl.isInput = legacy->getIsInput();
+ aidl.samplingRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->getSamplingRate()));
aidl.format = VALUE_OR_RETURN(
- legacy2aidl_audio_format_t_AudioFormatDescription(legacy->mFormat));
+ legacy2aidl_audio_format_t_AudioFormatDescription(legacy->getFormat()));
aidl.channelMask = VALUE_OR_RETURN(
- legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy->mChannelMask));
- aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->mFrameCount));
- aidl.frameCountHAL = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->mFrameCountHAL));
- aidl.latency = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->mLatency));
- aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy->mPortId));
+ legacy2aidl_audio_channel_mask_t_AudioChannelMask(legacy->getChannelMask()));
+ aidl.frameCount = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->getFrameCount()));
+ aidl.frameCountHAL = VALUE_OR_RETURN(convertIntegral<int64_t>(legacy->getFrameCountHAL()));
+ aidl.latency = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy->getLatency()));
+ aidl.portId = VALUE_OR_RETURN(legacy2aidl_audio_port_handle_t_int32_t(legacy->getPortId()));
return aidl;
}
diff --git a/media/libaudioclient/AudioSystem.cpp b/media/libaudioclient/AudioSystem.cpp
index 1d47e3a..b9de92a 100644
--- a/media/libaudioclient/AudioSystem.cpp
+++ b/media/libaudioclient/AudioSystem.cpp
@@ -336,7 +336,7 @@
if (desc == 0) {
*samplingRate = af->sampleRate(ioHandle);
} else {
- *samplingRate = desc->mSamplingRate;
+ *samplingRate = desc->getSamplingRate();
}
if (*samplingRate == 0) {
ALOGE("AudioSystem::getSamplingRate failed for ioHandle %d", ioHandle);
@@ -371,7 +371,7 @@
if (desc == 0) {
*frameCount = af->frameCount(ioHandle);
} else {
- *frameCount = desc->mFrameCount;
+ *frameCount = desc->getFrameCount();
}
if (*frameCount == 0) {
ALOGE("AudioSystem::getFrameCount failed for ioHandle %d", ioHandle);
@@ -406,7 +406,7 @@
if (outputDesc == 0) {
*latency = af->latency(output);
} else {
- *latency = outputDesc->mLatency;
+ *latency = outputDesc->getLatency();
}
ALOGV("getLatency() output %d, latency %d", output, *latency);
@@ -494,7 +494,7 @@
if (desc == 0) {
*frameCount = af->frameCountHAL(ioHandle);
} else {
- *frameCount = desc->mFrameCountHAL;
+ *frameCount = desc->getFrameCountHAL();
}
if (*frameCount == 0) {
ALOGE("AudioSystem::getFrameCountHAL failed for ioHandle %d", ioHandle);
@@ -535,15 +535,15 @@
Status AudioSystem::AudioFlingerClient::ioConfigChanged(
media::AudioIoConfigEvent _event,
const media::AudioIoDescriptor& _ioDesc) {
- audio_io_config_event event = VALUE_OR_RETURN_BINDER_STATUS(
- aidl2legacy_AudioIoConfigEvent_audio_io_config_event(_event));
+ audio_io_config_event_t event = VALUE_OR_RETURN_BINDER_STATUS(
+ aidl2legacy_AudioIoConfigEvent_audio_io_config_event_t(_event));
sp<AudioIoDescriptor> ioDesc(
VALUE_OR_RETURN_BINDER_STATUS(
aidl2legacy_AudioIoDescriptor_AudioIoDescriptor(_ioDesc)));
ALOGV("ioConfigChanged() event %d", event);
- if (ioDesc->mIoHandle == AUDIO_IO_HANDLE_NONE) return Status::ok();
+ if (ioDesc->getIoHandle() == AUDIO_IO_HANDLE_NONE) return Status::ok();
audio_port_handle_t deviceId = AUDIO_PORT_HANDLE_NONE;
std::vector<sp<AudioDeviceCallback>> callbacksToCall;
@@ -556,93 +556,88 @@
case AUDIO_OUTPUT_REGISTERED:
case AUDIO_INPUT_OPENED:
case AUDIO_INPUT_REGISTERED: {
- sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle);
+ sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->getIoHandle());
if (oldDesc == 0) {
- mIoDescriptors.add(ioDesc->mIoHandle, ioDesc);
+ mIoDescriptors.add(ioDesc->getIoHandle(), ioDesc);
} else {
deviceId = oldDesc->getDeviceId();
- mIoDescriptors.replaceValueFor(ioDesc->mIoHandle, ioDesc);
+ mIoDescriptors.replaceValueFor(ioDesc->getIoHandle(), ioDesc);
}
if (ioDesc->getDeviceId() != AUDIO_PORT_HANDLE_NONE) {
deviceId = ioDesc->getDeviceId();
if (event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED) {
- auto it = mAudioDeviceCallbacks.find(ioDesc->mIoHandle);
+ auto it = mAudioDeviceCallbacks.find(ioDesc->getIoHandle());
if (it != mAudioDeviceCallbacks.end()) {
callbacks = it->second;
}
}
}
- ALOGV("ioConfigChanged() new %s %s %d samplingRate %u, format %#x channel mask %#x "
- "frameCount %zu deviceId %d",
+ ALOGV("ioConfigChanged() new %s %s %s",
event == AUDIO_OUTPUT_OPENED || event == AUDIO_OUTPUT_REGISTERED ?
"output" : "input",
event == AUDIO_OUTPUT_OPENED || event == AUDIO_INPUT_OPENED ?
"opened" : "registered",
- ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat,
- ioDesc->mChannelMask,
- ioDesc->mFrameCount, ioDesc->getDeviceId());
+ ioDesc->toDebugString().c_str());
}
break;
case AUDIO_OUTPUT_CLOSED:
case AUDIO_INPUT_CLOSED: {
- if (getIoDescriptor_l(ioDesc->mIoHandle) == 0) {
+ if (getIoDescriptor_l(ioDesc->getIoHandle()) == 0) {
ALOGW("ioConfigChanged() closing unknown %s %d",
- event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle);
+ event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->getIoHandle());
break;
}
ALOGV("ioConfigChanged() %s %d closed",
- event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->mIoHandle);
+ event == AUDIO_OUTPUT_CLOSED ? "output" : "input", ioDesc->getIoHandle());
- mIoDescriptors.removeItem(ioDesc->mIoHandle);
- mAudioDeviceCallbacks.erase(ioDesc->mIoHandle);
+ mIoDescriptors.removeItem(ioDesc->getIoHandle());
+ mAudioDeviceCallbacks.erase(ioDesc->getIoHandle());
}
break;
case AUDIO_OUTPUT_CONFIG_CHANGED:
case AUDIO_INPUT_CONFIG_CHANGED: {
- sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle);
+ sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->getIoHandle());
if (oldDesc == 0) {
ALOGW("ioConfigChanged() modifying unknown %s! %d",
event == AUDIO_OUTPUT_CONFIG_CHANGED ? "output" : "input",
- ioDesc->mIoHandle);
+ ioDesc->getIoHandle());
break;
}
deviceId = oldDesc->getDeviceId();
- mIoDescriptors.replaceValueFor(ioDesc->mIoHandle, ioDesc);
+ mIoDescriptors.replaceValueFor(ioDesc->getIoHandle(), ioDesc);
if (deviceId != ioDesc->getDeviceId()) {
deviceId = ioDesc->getDeviceId();
- auto it = mAudioDeviceCallbacks.find(ioDesc->mIoHandle);
+ auto it = mAudioDeviceCallbacks.find(ioDesc->getIoHandle());
if (it != mAudioDeviceCallbacks.end()) {
callbacks = it->second;
}
}
- ALOGV("ioConfigChanged() new config for %s %d samplingRate %u, format %#x "
- "channel mask %#x frameCount %zu frameCountHAL %zu deviceId %d",
+ ALOGV("ioConfigChanged() new config for %s %s",
event == AUDIO_OUTPUT_CONFIG_CHANGED ? "output" : "input",
- ioDesc->mIoHandle, ioDesc->mSamplingRate, ioDesc->mFormat,
- ioDesc->mChannelMask, ioDesc->mFrameCount, ioDesc->mFrameCountHAL,
- ioDesc->getDeviceId());
+ ioDesc->toDebugString().c_str());
}
break;
case AUDIO_CLIENT_STARTED: {
- sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->mIoHandle);
+ sp<AudioIoDescriptor> oldDesc = getIoDescriptor_l(ioDesc->getIoHandle());
if (oldDesc == 0) {
- ALOGW("ioConfigChanged() start client on unknown io! %d", ioDesc->mIoHandle);
+ ALOGW("ioConfigChanged() start client on unknown io! %d",
+ ioDesc->getIoHandle());
break;
}
ALOGV("ioConfigChanged() AUDIO_CLIENT_STARTED io %d port %d num callbacks %zu",
- ioDesc->mIoHandle, ioDesc->mPortId, mAudioDeviceCallbacks.size());
- oldDesc->mPatch = ioDesc->mPatch;
- auto it = mAudioDeviceCallbacks.find(ioDesc->mIoHandle);
+ ioDesc->getIoHandle(), ioDesc->getPortId(), mAudioDeviceCallbacks.size());
+ oldDesc->setPatch(ioDesc->getPatch());
+ auto it = mAudioDeviceCallbacks.find(ioDesc->getIoHandle());
if (it != mAudioDeviceCallbacks.end()) {
auto cbks = it->second;
- auto it2 = cbks.find(ioDesc->mPortId);
+ auto it2 = cbks.find(ioDesc->getPortId());
if (it2 != cbks.end()) {
- callbacks.emplace(ioDesc->mPortId, it2->second);
+ callbacks.emplace(ioDesc->getPortId(), it2->second);
deviceId = oldDesc->getDeviceId();
}
}
@@ -661,8 +656,8 @@
// Callbacks must be called without mLock held. May lead to dead lock if calling for
// example getRoutedDevice that updates the device and tries to acquire mLock.
for (auto cb : callbacksToCall) {
- // If callbacksToCall is not empty, it implies ioDesc->mIoHandle and deviceId are valid
- cb->onAudioDeviceUpdate(ioDesc->mIoHandle, deviceId);
+ // If callbacksToCall is not empty, it implies ioDesc->getIoHandle() and deviceId are valid
+ cb->onAudioDeviceUpdate(ioDesc->getIoHandle(), deviceId);
}
return Status::ok();
diff --git a/media/libaudioclient/aidl/android/media/AudioIoDescriptor.aidl b/media/libaudioclient/aidl/android/media/AudioIoDescriptor.aidl
index 84f928f..ea8ec32 100644
--- a/media/libaudioclient/aidl/android/media/AudioIoDescriptor.aidl
+++ b/media/libaudioclient/aidl/android/media/AudioIoDescriptor.aidl
@@ -27,6 +27,7 @@
/** Interpreted as audio_io_handle_t. */
int ioHandle;
AudioPatch patch;
+ boolean isInput;
int samplingRate;
AudioFormatDescription format;
AudioChannelMask channelMask;
diff --git a/media/libaudioclient/include/media/AidlConversion.h b/media/libaudioclient/include/media/AidlConversion.h
index 9e606a0..e56106a 100644
--- a/media/libaudioclient/include/media/AidlConversion.h
+++ b/media/libaudioclient/include/media/AidlConversion.h
@@ -121,10 +121,10 @@
ConversionResult<std::optional<std::string_view>>
legacy2aidl_optional_String16_optional_string(std::optional<String16> legacy);
-ConversionResult<audio_io_config_event> aidl2legacy_AudioIoConfigEvent_audio_io_config_event(
+ConversionResult<audio_io_config_event_t> aidl2legacy_AudioIoConfigEvent_audio_io_config_event_t(
media::AudioIoConfigEvent aidl);
-ConversionResult<media::AudioIoConfigEvent> legacy2aidl_audio_io_config_event_AudioIoConfigEvent(
- audio_io_config_event legacy);
+ConversionResult<media::AudioIoConfigEvent> legacy2aidl_audio_io_config_event_t_AudioIoConfigEvent(
+ audio_io_config_event_t legacy);
ConversionResult<audio_port_role_t> aidl2legacy_AudioPortRole_audio_port_role_t(
media::AudioPortRole aidl);
diff --git a/media/libaudioclient/include/media/AudioIoDescriptor.h b/media/libaudioclient/include/media/AudioIoDescriptor.h
index 981d33a..ef729ed 100644
--- a/media/libaudioclient/include/media/AudioIoDescriptor.h
+++ b/media/libaudioclient/include/media/AudioIoDescriptor.h
@@ -17,9 +17,15 @@
#ifndef ANDROID_AUDIO_IO_DESCRIPTOR_H
#define ANDROID_AUDIO_IO_DESCRIPTOR_H
+#include <sstream>
+#include <string>
+
+#include <system/audio.h>
+#include <utils/RefBase.h>
+
namespace android {
-enum audio_io_config_event {
+enum audio_io_config_event_t {
AUDIO_OUTPUT_REGISTERED,
AUDIO_OUTPUT_OPENED,
AUDIO_OUTPUT_CLOSED,
@@ -35,39 +41,68 @@
// frequent calls through IAudioFlinger
class AudioIoDescriptor : public RefBase {
public:
- AudioIoDescriptor() :
- mIoHandle(AUDIO_IO_HANDLE_NONE),
- mSamplingRate(0), mFormat(AUDIO_FORMAT_DEFAULT), mChannelMask(AUDIO_CHANNEL_NONE),
- mFrameCount(0), mFrameCountHAL(0), mLatency(0), mPortId(AUDIO_PORT_HANDLE_NONE)
- {
- memset(&mPatch, 0, sizeof(struct audio_patch));
- }
+ AudioIoDescriptor() = default;
+ // For AUDIO_{INPUT|OUTPUT}_CLOSED events.
+ AudioIoDescriptor(audio_io_handle_t ioHandle) : mIoHandle(ioHandle) {}
+ // For AUDIO_CLIENT_STARTED events.
+ AudioIoDescriptor(
+ audio_io_handle_t ioHandle, const audio_patch& patch, audio_port_handle_t portId) :
+ mIoHandle(ioHandle), mPatch(patch), mPortId(portId) {}
+ // For everything else.
+ AudioIoDescriptor(
+ audio_io_handle_t ioHandle, const audio_patch& patch, bool isInput,
+ uint32_t samplingRate, audio_format_t format, audio_channel_mask_t channelMask,
+ size_t frameCount, size_t frameCountHal, uint32_t latency = 0,
+ audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) :
+ mIoHandle(ioHandle), mPatch(patch), mIsInput(isInput),
+ mSamplingRate(samplingRate), mFormat(format), mChannelMask(channelMask),
+ mFrameCount(frameCount), mFrameCountHAL(frameCountHal), mLatency(latency),
+ mPortId(portId) {}
- virtual ~AudioIoDescriptor() {}
-
- audio_port_handle_t getDeviceId() {
+ audio_io_handle_t getIoHandle() const { return mIoHandle; }
+ const audio_patch& getPatch() const { return mPatch; }
+ bool getIsInput() const { return mIsInput; }
+ uint32_t getSamplingRate() const { return mSamplingRate; }
+ audio_format_t getFormat() const { return mFormat; }
+ audio_channel_mask_t getChannelMask() const { return mChannelMask; }
+ size_t getFrameCount() const { return mFrameCount; }
+ size_t getFrameCountHAL() const { return mFrameCountHAL; }
+ uint32_t getLatency() const { return mLatency; }
+ audio_port_handle_t getPortId() const { return mPortId; }
+ audio_port_handle_t getDeviceId() const {
if (mPatch.num_sources != 0 && mPatch.num_sinks != 0) {
- if (mPatch.sources[0].type == AUDIO_PORT_TYPE_MIX) {
- // this is an output mix
- // FIXME: the API only returns the first device in case of multiple device selection
- return mPatch.sinks[0].id;
- } else {
- // this is an input mix
- return mPatch.sources[0].id;
- }
+ // FIXME: the API only returns the first device in case of multiple device selection
+ return mIsInput ? mPatch.sources[0].id : mPatch.sinks[0].id;
}
return AUDIO_PORT_HANDLE_NONE;
}
+ void setPatch(const audio_patch& patch) { mPatch = patch; }
- audio_io_handle_t mIoHandle;
- struct audio_patch mPatch;
- uint32_t mSamplingRate;
- audio_format_t mFormat;
- audio_channel_mask_t mChannelMask;
- size_t mFrameCount;
- size_t mFrameCountHAL;
- uint32_t mLatency; // only valid for output
- audio_port_handle_t mPortId; // valid for event AUDIO_CLIENT_STARTED
+ std::string toDebugString() const {
+ std::ostringstream ss;
+ ss << mIoHandle << ", samplingRate " << mSamplingRate << ", "
+ << audio_format_to_string(mFormat) << ", "
+ << (audio_channel_mask_get_representation(mChannelMask) ==
+ AUDIO_CHANNEL_REPRESENTATION_INDEX ?
+ audio_channel_index_mask_to_string(mChannelMask) :
+ (mIsInput ? audio_channel_in_mask_to_string(mChannelMask) :
+ audio_channel_out_mask_to_string(mChannelMask)))
+ << ", frameCount " << mFrameCount << ", frameCountHAL " << mFrameCountHAL
+ << ", deviceId " << getDeviceId();
+ return ss.str();
+ }
+
+ private:
+ const audio_io_handle_t mIoHandle = AUDIO_IO_HANDLE_NONE;
+ struct audio_patch mPatch = {};
+ const bool mIsInput = false;
+ const uint32_t mSamplingRate = 0;
+ const audio_format_t mFormat = AUDIO_FORMAT_DEFAULT;
+ const audio_channel_mask_t mChannelMask = AUDIO_CHANNEL_NONE;
+ const size_t mFrameCount = 0;
+ const size_t mFrameCountHAL = 0;
+ const uint32_t mLatency = 0;
+ const audio_port_handle_t mPortId = AUDIO_PORT_HANDLE_NONE;
};
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 3b99e02..1e1db31 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1873,13 +1873,13 @@
}
}
-void AudioFlinger::ioConfigChanged(audio_io_config_event event,
+void AudioFlinger::ioConfigChanged(audio_io_config_event_t event,
const sp<AudioIoDescriptor>& ioDesc,
pid_t pid) {
media::AudioIoDescriptor descAidl = VALUE_OR_FATAL(
legacy2aidl_AudioIoDescriptor_AudioIoDescriptor(ioDesc));
media::AudioIoConfigEvent eventAidl = VALUE_OR_FATAL(
- legacy2aidl_audio_io_config_event_AudioIoConfigEvent(event));
+ legacy2aidl_audio_io_config_event_t_AudioIoConfigEvent(event));
Mutex::Autolock _l(mClientLock);
size_t size = mNotificationClients.size();
@@ -2752,9 +2752,7 @@
mMmapThreads.removeItem(output);
ALOGD("closing mmapThread %p", mmapThread.get());
}
- const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor();
- ioDesc->mIoHandle = output;
- ioConfigChanged(AUDIO_OUTPUT_CLOSED, ioDesc);
+ ioConfigChanged(AUDIO_OUTPUT_CLOSED, sp<AudioIoDescriptor>::make(output));
mPatchPanel.notifyStreamClosed(output);
}
// The thread entity (active unit of execution) is no longer running here,
@@ -3012,9 +3010,7 @@
dumpToThreadLog_l(mmapThread);
mMmapThreads.removeItem(input);
}
- const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor();
- ioDesc->mIoHandle = input;
- ioConfigChanged(AUDIO_INPUT_CLOSED, ioDesc);
+ ioConfigChanged(AUDIO_INPUT_CLOSED, sp<AudioIoDescriptor>::make(input));
}
// FIXME: calling thread->exit() without mLock held should not be needed anymore now that
// we have a different lock for notification client
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 8fcd6e4..d6bf0ae 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -750,7 +750,7 @@
// no range check, AudioFlinger::mLock held
bool streamMute_l(audio_stream_type_t stream) const
{ return mStreamTypes[stream].mute; }
- void ioConfigChanged(audio_io_config_event event,
+ void ioConfigChanged(audio_io_config_event_t event,
const sp<AudioIoDescriptor>& ioDesc,
pid_t pid = 0);
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 7292527..9665424 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -626,7 +626,7 @@
return status;
}
-void AudioFlinger::ThreadBase::sendIoConfigEvent(audio_io_config_event event, pid_t pid,
+void AudioFlinger::ThreadBase::sendIoConfigEvent(audio_io_config_event_t event, pid_t pid,
audio_port_handle_t portId)
{
Mutex::Autolock _l(mLock);
@@ -634,7 +634,7 @@
}
// sendIoConfigEvent_l() must be called with ThreadBase::mLock held
-void AudioFlinger::ThreadBase::sendIoConfigEvent_l(audio_io_config_event event, pid_t pid,
+void AudioFlinger::ThreadBase::sendIoConfigEvent_l(audio_io_config_event_t event, pid_t pid,
audio_port_handle_t portId)
{
// The audio statistics history is exponentially weighted to forget events
@@ -2772,36 +2772,26 @@
return mOutput->stream->selectPresentation(presentationId, programId);
}
-void AudioFlinger::PlaybackThread::ioConfigChanged(audio_io_config_event event, pid_t pid,
+void AudioFlinger::PlaybackThread::ioConfigChanged(audio_io_config_event_t event, pid_t pid,
audio_port_handle_t portId) {
- sp<AudioIoDescriptor> desc = new AudioIoDescriptor();
ALOGV("PlaybackThread::ioConfigChanged, thread %p, event %d", this, event);
-
- desc->mIoHandle = mId;
- struct audio_patch patch = mPatch;
- if (isMsdDevice()) {
- patch = mDownStreamPatch;
- }
-
+ sp<AudioIoDescriptor> desc;
+ const struct audio_patch patch = isMsdDevice() ? mDownStreamPatch : mPatch;
switch (event) {
case AUDIO_OUTPUT_OPENED:
case AUDIO_OUTPUT_REGISTERED:
case AUDIO_OUTPUT_CONFIG_CHANGED:
- desc->mPatch = patch;
- desc->mChannelMask = mChannelMask;
- desc->mSamplingRate = mSampleRate;
- desc->mFormat = mFormat;
- desc->mFrameCount = mNormalFrameCount; // FIXME see
- // AudioFlinger::frameCount(audio_io_handle_t)
- desc->mFrameCountHAL = mFrameCount;
- desc->mLatency = latency_l();
+ desc = sp<AudioIoDescriptor>::make(mId, patch, false /*isInput*/,
+ mSampleRate, mFormat, mChannelMask,
+ // FIXME AudioFlinger::frameCount(audio_io_handle_t) instead of mNormalFrameCount?
+ mNormalFrameCount, mFrameCount, latency_l());
break;
case AUDIO_CLIENT_STARTED:
- desc->mPatch = patch;
- desc->mPortId = portId;
+ desc = sp<AudioIoDescriptor>::make(mId, patch, portId);
break;
case AUDIO_OUTPUT_CLOSED:
default:
+ desc = sp<AudioIoDescriptor>::make(mId);
break;
}
mAudioFlinger->ioConfigChanged(event, desc, pid);
@@ -8784,30 +8774,22 @@
return String8();
}
-void AudioFlinger::RecordThread::ioConfigChanged(audio_io_config_event event, pid_t pid,
+void AudioFlinger::RecordThread::ioConfigChanged(audio_io_config_event_t event, pid_t pid,
audio_port_handle_t portId) {
- sp<AudioIoDescriptor> desc = new AudioIoDescriptor();
-
- desc->mIoHandle = mId;
-
+ sp<AudioIoDescriptor> desc;
switch (event) {
case AUDIO_INPUT_OPENED:
case AUDIO_INPUT_REGISTERED:
case AUDIO_INPUT_CONFIG_CHANGED:
- desc->mPatch = mPatch;
- desc->mChannelMask = mChannelMask;
- desc->mSamplingRate = mSampleRate;
- desc->mFormat = mFormat;
- desc->mFrameCount = mFrameCount;
- desc->mFrameCountHAL = mFrameCount;
- desc->mLatency = 0;
+ desc = sp<AudioIoDescriptor>::make(mId, mPatch, true /*isInput*/,
+ mSampleRate, mFormat, mChannelMask, mFrameCount, mFrameCount);
break;
case AUDIO_CLIENT_STARTED:
- desc->mPatch = mPatch;
- desc->mPortId = portId;
+ desc = sp<AudioIoDescriptor>::make(mId, mPatch, portId);
break;
case AUDIO_INPUT_CLOSED:
default:
+ desc = sp<AudioIoDescriptor>::make(mId);
break;
}
mAudioFlinger->ioConfigChanged(event, desc, pid);
@@ -9650,31 +9632,26 @@
return String8();
}
-void AudioFlinger::MmapThread::ioConfigChanged(audio_io_config_event event, pid_t pid,
+void AudioFlinger::MmapThread::ioConfigChanged(audio_io_config_event_t event, pid_t pid,
audio_port_handle_t portId __unused) {
- sp<AudioIoDescriptor> desc = new AudioIoDescriptor();
-
- desc->mIoHandle = mId;
-
+ sp<AudioIoDescriptor> desc;
+ bool isInput = false;
switch (event) {
case AUDIO_INPUT_OPENED:
case AUDIO_INPUT_REGISTERED:
case AUDIO_INPUT_CONFIG_CHANGED:
+ isInput = true;
+ FALLTHROUGH_INTENDED;
case AUDIO_OUTPUT_OPENED:
case AUDIO_OUTPUT_REGISTERED:
case AUDIO_OUTPUT_CONFIG_CHANGED:
- desc->mPatch = mPatch;
- desc->mChannelMask = mChannelMask;
- desc->mSamplingRate = mSampleRate;
- desc->mFormat = mFormat;
- desc->mFrameCount = mFrameCount;
- desc->mFrameCountHAL = mFrameCount;
- desc->mLatency = 0;
+ desc = sp<AudioIoDescriptor>::make(mId, mPatch, isInput,
+ mSampleRate, mFormat, mChannelMask, mFrameCount, mFrameCount);
break;
-
case AUDIO_INPUT_CLOSED:
case AUDIO_OUTPUT_CLOSED:
default:
+ desc = sp<AudioIoDescriptor>::make(mId);
break;
}
mAudioFlinger->ioConfigChanged(event, desc, pid);
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index 3001863..38e55a3 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -113,7 +113,7 @@
class IoConfigEventData : public ConfigEventData {
public:
- IoConfigEventData(audio_io_config_event event, pid_t pid,
+ IoConfigEventData(audio_io_config_event_t event, pid_t pid,
audio_port_handle_t portId) :
mEvent(event), mPid(pid), mPortId(portId) {}
@@ -121,14 +121,14 @@
snprintf(buffer, size, "- IO event: event %d\n", mEvent);
}
- const audio_io_config_event mEvent;
+ const audio_io_config_event_t mEvent;
const pid_t mPid;
const audio_port_handle_t mPortId;
};
class IoConfigEvent : public ConfigEvent {
public:
- IoConfigEvent(audio_io_config_event event, pid_t pid, audio_port_handle_t portId) :
+ IoConfigEvent(audio_io_config_event_t event, pid_t pid, audio_port_handle_t portId) :
ConfigEvent(CFG_EVENT_IO) {
mData = new IoConfigEventData(event, pid, portId);
}
@@ -332,15 +332,15 @@
status_t& status) = 0;
virtual status_t setParameters(const String8& keyValuePairs);
virtual String8 getParameters(const String8& keys) = 0;
- virtual void ioConfigChanged(audio_io_config_event event, pid_t pid = 0,
+ virtual void ioConfigChanged(audio_io_config_event_t event, pid_t pid = 0,
audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) = 0;
// sendConfigEvent_l() must be called with ThreadBase::mLock held
// Can temporarily release the lock if waiting for a reply from
// processConfigEvents_l().
status_t sendConfigEvent_l(sp<ConfigEvent>& event);
- void sendIoConfigEvent(audio_io_config_event event, pid_t pid = 0,
+ void sendIoConfigEvent(audio_io_config_event_t event, pid_t pid = 0,
audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
- void sendIoConfigEvent_l(audio_io_config_event event, pid_t pid = 0,
+ void sendIoConfigEvent_l(audio_io_config_event_t event, pid_t pid = 0,
audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp);
void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio, bool forApp);
@@ -972,7 +972,7 @@
{ return android_atomic_acquire_load(&mSuspended) > 0; }
virtual String8 getParameters(const String8& keys);
- virtual void ioConfigChanged(audio_io_config_event event, pid_t pid = 0,
+ virtual void ioConfigChanged(audio_io_config_event_t event, pid_t pid = 0,
audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames);
// Consider also removing and passing an explicit mMainBuffer initialization
@@ -1785,7 +1785,7 @@
status_t& status);
virtual void cacheParameters_l() {}
virtual String8 getParameters(const String8& keys);
- virtual void ioConfigChanged(audio_io_config_event event, pid_t pid = 0,
+ virtual void ioConfigChanged(audio_io_config_event_t event, pid_t pid = 0,
audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
virtual status_t createAudioPatch_l(const struct audio_patch *patch,
audio_patch_handle_t *handle);
@@ -1994,7 +1994,7 @@
virtual bool checkForNewParameter_l(const String8& keyValuePair,
status_t& status);
virtual String8 getParameters(const String8& keys);
- virtual void ioConfigChanged(audio_io_config_event event, pid_t pid = 0,
+ virtual void ioConfigChanged(audio_io_config_event_t event, pid_t pid = 0,
audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE);
void readHalParameters_l();
virtual void cacheParameters_l() {}