Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE: audiopolicy: Remove raw pointer references to AudioMix #2

Open
wants to merge 1 commit into
base: n7.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace android {

class IOProfile;
class AudioMix;
class AudioPolicyMix;

// descriptor for audio inputs. Used to maintain current configuration of each opened audio input
// and keep track of the usage of this input.
Expand All @@ -44,7 +44,7 @@ class AudioInputDescriptor: public AudioPortConfig, public AudioSessionInfoProvi

audio_io_handle_t mIoHandle; // input handle
audio_devices_t mDevice; // current device this input is routed to
AudioMix *mPolicyMix; // non NULL when used by a dynamic policy
wp<AudioPolicyMix> mPolicyMix; // non NULL when used by a dynamic policy
const sp<IOProfile> mProfile; // I/O profile this output derives from

virtual void toAudioPortConfig(struct audio_port_config *dstConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
namespace android {

class IOProfile;
class AudioMix;
class AudioPolicyMix;
class AudioPolicyClientInterface;
class DeviceDescriptor;

Expand Down Expand Up @@ -124,7 +124,7 @@ class SwAudioOutputDescriptor: public AudioOutputDescriptor
const sp<IOProfile> mProfile; // I/O profile this output derives from
uint32_t mLatency; //
audio_output_flags_t mFlags; //
AudioMix *mPolicyMix; // non NULL when used by a dynamic policy
wp<AudioPolicyMix> mPolicyMix; // non NULL when used by a dynamic policy
sp<SwAudioOutputDescriptor> mOutput1; // used by duplicated outputs: first output
sp<SwAudioOutputDescriptor> mOutput2; // used by duplicated outputs: second output
uint32_t mDirectOpenCount; // number of clients using this output (direct outputs only)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,19 @@ class SwAudioOutputDescriptor;
/**
* custom mix entry in mPolicyMixes
*/
class AudioPolicyMix : public RefBase {
class AudioPolicyMix : public AudioMix, public RefBase {
public:
AudioPolicyMix() {}
AudioPolicyMix(const AudioMix &mix);
AudioPolicyMix(const AudioPolicyMix&) = delete;
AudioPolicyMix& operator=(const AudioPolicyMix&) = delete;

const sp<SwAudioOutputDescriptor> &getOutput() const;

void setOutput(sp<SwAudioOutputDescriptor> &output);

void clearOutput();

android::AudioMix *getMix();

void setMix(AudioMix &mix);

private:
AudioMix mMix; // Audio policy mix descriptor
sp<SwAudioOutputDescriptor> mOutput; // Corresponding output stream
};

Expand Down Expand Up @@ -74,9 +71,9 @@ class AudioPolicyMixCollection : public DefaultKeyedVector<String8, sp<AudioPoli

audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource,
audio_devices_t availableDeviceTypes,
AudioMix **policyMix);
sp<AudioPolicyMix> *policyMix);

status_t getInputMixForAttr(audio_attributes_t attr, AudioMix **policyMix);
status_t getInputMixForAttr(audio_attributes_t attr, sp<AudioPolicyMix> *policyMix);
};

}; // namespace android
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace android {

class AudioPolicyClientInterface;
class AudioPolicyMix;

class AudioSession : public RefBase, public AudioSessionInfoUpdateListener
{
Expand All @@ -39,7 +40,7 @@ class AudioSession : public RefBase, public AudioSessionInfoUpdateListener
audio_input_flags_t flags,
uid_t uid,
bool isSoundTrigger,
AudioMix* policyMix,
const sp<AudioPolicyMix> &policyMix,
AudioPolicyClientInterface *clientInterface);

status_t dump(int fd, int spaces, int index) const;
Expand Down Expand Up @@ -72,7 +73,7 @@ class AudioSession : public RefBase, public AudioSessionInfoUpdateListener
bool mIsSoundTrigger;
uint32_t mOpenCount;
uint32_t mActiveCount;
AudioMix* mPolicyMix; // non NULL when used by a dynamic policy
wp<AudioPolicyMix> mPolicyMix; // non NULL when used by a dynamic policy
AudioPolicyClientInterface* mClientInterface;
const AudioSessionInfoProvider* mInfoProvider;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "AudioInputDescriptor.h"
#include "IOProfile.h"
#include "AudioGain.h"
#include "AudioPolicyMix.h"
#include "HwModule.h"
#include <media/AudioPolicy.h>
#include <policy.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <AudioPolicyInterface.h>
#include "AudioOutputDescriptor.h"
#include "AudioPolicyMix.h"
#include "IOProfile.h"
#include "AudioGain.h"
#include "Volume.h"
Expand Down Expand Up @@ -312,17 +313,18 @@ void SwAudioOutputDescriptor::changeRefCount(audio_stream_type_t stream,
} else {
mGlobalRefCount += delta;
}
sp<AudioPolicyMix> policyMix = mPolicyMix.promote();
if ((oldGlobalRefCount == 0) && (mGlobalRefCount > 0)) {
if ((mPolicyMix != NULL) && ((mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
if ((policyMix != NULL) && ((policyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
{
mClientInterface->onDynamicPolicyMixStateUpdate(mPolicyMix->mDeviceAddress,
mClientInterface->onDynamicPolicyMixStateUpdate(policyMix->mDeviceAddress,
MIX_STATE_MIXING);
}

} else if ((oldGlobalRefCount > 0) && (mGlobalRefCount == 0)) {
if ((mPolicyMix != NULL) && ((mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
if ((policyMix != NULL) && ((policyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
{
mClientInterface->onDynamicPolicyMixStateUpdate(mPolicyMix->mDeviceAddress,
mClientInterface->onDynamicPolicyMixStateUpdate(policyMix->mDeviceAddress,
MIX_STATE_IDLE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

namespace android {

AudioPolicyMix::AudioPolicyMix(const AudioMix &mix) : AudioMix(mix)
{
}

void AudioPolicyMix::setOutput(sp<SwAudioOutputDescriptor> &output)
{
mOutput = output;
Expand All @@ -41,16 +45,6 @@ void AudioPolicyMix::clearOutput()
mOutput.clear();
}

void AudioPolicyMix::setMix(AudioMix &mix)
{
mMix = mix;
}

android::AudioMix *AudioPolicyMix::getMix()
{
return &mMix;
}

status_t AudioPolicyMixCollection::registerMix(String8 address, AudioMix mix,
sp<SwAudioOutputDescriptor> desc)
{
Expand All @@ -59,12 +53,11 @@ status_t AudioPolicyMixCollection::registerMix(String8 address, AudioMix mix,
ALOGE("registerPolicyMixes(): mix for address %s already registered", address.string());
return BAD_VALUE;
}
sp<AudioPolicyMix> policyMix = new AudioPolicyMix();
policyMix->setMix(mix);
sp<AudioPolicyMix> policyMix = new AudioPolicyMix(mix);
add(address, policyMix);

if (desc != 0) {
desc->mPolicyMix = policyMix->getMix();
desc->mPolicyMix = policyMix;
policyMix->setOutput(desc);
}
return NO_ERROR;
Expand Down Expand Up @@ -110,8 +103,7 @@ status_t AudioPolicyMixCollection::getOutputForAttr(audio_attributes_t attribute
ALOGV("getOutputForAttr() querying %zu mixes:", size());
desc = 0;
for (size_t i = 0; i < size(); i++) {
sp<AudioPolicyMix> policyMix = valueAt(i);
AudioMix *mix = policyMix->getMix();
sp<AudioPolicyMix> mix = valueAt(i);

if (mix->mMixType == MIX_TYPE_PLAYERS) {
// TODO if adding more player rules (currently only 2), make rule handling "generic"
Expand Down Expand Up @@ -208,7 +200,7 @@ status_t AudioPolicyMixCollection::getOutputForAttr(audio_attributes_t attribute
(hasUidExcludeRules && uidExclusionFound) ||
(hasUidMatchRules && !uidMatchFound))) {
ALOGV("\tgetOutputForAttr will use mix %zu", i);
desc = policyMix->getOutput();
desc = mix->getOutput();
}

} else if (mix->mMixType == MIX_TYPE_RECORDERS) {
Expand All @@ -217,7 +209,7 @@ status_t AudioPolicyMixCollection::getOutputForAttr(audio_attributes_t attribute
strncmp(attributes.tags + strlen("addr="),
mix->mDeviceAddress.string(),
AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - strlen("addr=") - 1) == 0) {
desc = policyMix->getOutput();
desc = mix->getOutput();
}
}
if (desc != 0) {
Expand All @@ -228,12 +220,13 @@ status_t AudioPolicyMixCollection::getOutputForAttr(audio_attributes_t attribute
return BAD_VALUE;
}

audio_devices_t AudioPolicyMixCollection::getDeviceAndMixForInputSource(audio_source_t inputSource,
audio_devices_t availDevices,
AudioMix **policyMix)
audio_devices_t AudioPolicyMixCollection::getDeviceAndMixForInputSource(
audio_source_t inputSource,
audio_devices_t availDevices,
sp<AudioPolicyMix> *policyMix)
{
for (size_t i = 0; i < size(); i++) {
AudioMix *mix = valueAt(i)->getMix();
AudioPolicyMix *mix = valueAt(i).get();

if (mix->mMixType != MIX_TYPE_RECORDERS) {
continue;
Expand All @@ -256,7 +249,8 @@ audio_devices_t AudioPolicyMixCollection::getDeviceAndMixForInputSource(audio_so
return AUDIO_DEVICE_NONE;
}

status_t AudioPolicyMixCollection::getInputMixForAttr(audio_attributes_t attr, AudioMix **policyMix)
status_t AudioPolicyMixCollection::getInputMixForAttr(
audio_attributes_t attr, sp<AudioPolicyMix> *policyMix)
{
if (strncmp(attr.tags, "addr=", strlen("addr=")) != 0) {
return BAD_VALUE;
Expand All @@ -266,8 +260,7 @@ status_t AudioPolicyMixCollection::getInputMixForAttr(audio_attributes_t attr, A
#ifdef LOG_NDEBUG
ALOGV("getInputMixForAttr looking for address %s\n mixes available:", address.string());
for (size_t i = 0; i < size(); i++) {
sp<AudioPolicyMix> policyMix = valueAt(i);
AudioMix *mix = policyMix->getMix();
sp<AudioPolicyMix> mix = valueAt(i);
ALOGV("\tmix %zu address=%s", i, mix->mDeviceAddress.string());
}
#endif
Expand All @@ -278,13 +271,14 @@ status_t AudioPolicyMixCollection::getInputMixForAttr(audio_attributes_t attr, A
return BAD_VALUE;
}
sp<AudioPolicyMix> audioPolicyMix = valueAt(index);
AudioMix *mix = audioPolicyMix->getMix();

if (mix->mMixType != MIX_TYPE_PLAYERS) {
if (audioPolicyMix->mMixType != MIX_TYPE_PLAYERS) {
ALOGW("getInputMixForAttr() bad policy mix type for address %s", address.string());
return BAD_VALUE;
}
*policyMix = mix;
if (policyMix != nullptr) {
*policyMix = audioPolicyMix;
}
return NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//#define LOG_NDEBUG 0

#include <AudioPolicyInterface.h>
#include "AudioPolicyMix.h"
#include "AudioSession.h"
#include "AudioGain.h"
#include "TypeConverter.h"
Expand All @@ -34,7 +35,7 @@ AudioSession::AudioSession(audio_session_t session,
audio_input_flags_t flags,
uid_t uid,
bool isSoundTrigger,
AudioMix* policyMix,
const sp<AudioPolicyMix> &policyMix,
AudioPolicyClientInterface *clientInterface) :
mSession(session), mInputSource(inputSource),
mConfig({ .format = format, .sample_rate = sampleRate, .channel_mask = channelMask}),
Expand Down Expand Up @@ -77,9 +78,10 @@ uint32_t AudioSession::changeActiveCount(int delta)
if (event != RECORD_CONFIG_EVENT_NONE) {
// Dynamic policy callback:
// if input maps to a dynamic policy with an activity listener, notify of state change
if ((mPolicyMix != NULL) && ((mPolicyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
sp<AudioPolicyMix> policyMix = mPolicyMix.promote();
if ((policyMix != NULL) && ((policyMix->mCbFlags & AudioMix::kCbFlagNotifyActivity) != 0))
{
mClientInterface->onDynamicPolicyMixStateUpdate(mPolicyMix->mDeviceAddress,
mClientInterface->onDynamicPolicyMixStateUpdate(policyMix->mDeviceAddress,
(event == RECORD_CONFIG_EVENT_START) ? MIX_STATE_MIXING : MIX_STATE_IDLE);
}

Expand Down
Loading