Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afd4cea4 authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

audiopolicy: apm: factorize internal patch creation/release



This CL removes duplicated code for patch creation for
-voice call
-system API to create patches.
-system API to start/stop AudioSource

It creates internal methods to create/release Audio Patches.

The benefit of this rework is to have startAudioSource now working
whatever Sw or HW bridging is used.

Test: Voice Call
Bug: 136294538
Change-Id: I82738d116abd94f7738fce8ca3a1c3466942060a
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 0bc6f60e
Loading
Loading
Loading
Loading
+14 −2
Original line number Original line Diff line number Diff line
@@ -31,12 +31,24 @@ class AudioPatch : public RefBase, private HandleGenerator<audio_patch_handle_t>
public:
public:
    AudioPatch(const struct audio_patch *patch, uid_t uid);
    AudioPatch(const struct audio_patch *patch, uid_t uid);


    audio_patch_handle_t getHandle() const { return mHandle; }

    audio_patch_handle_t getAfHandle() const { return mAfPatchHandle; }

    void setAfHandle(audio_patch_handle_t afHandle) { mAfPatchHandle = afHandle; }

    uid_t getUid() const { return mUid; }

    void setUid(uid_t uid) { mUid = uid; }

    void dump(String8 *dst, int spaces, int index) const;
    void dump(String8 *dst, int spaces, int index) const;


    audio_patch_handle_t mHandle;
    struct audio_patch mPatch;
    struct audio_patch mPatch;

private:
    const audio_patch_handle_t mHandle;
    uid_t mUid;
    uid_t mUid;
    audio_patch_handle_t mAfPatchHandle;
    audio_patch_handle_t mAfPatchHandle = AUDIO_PATCH_HANDLE_NONE;
};
};


class AudioPatchCollection : public DefaultKeyedVector<audio_patch_handle_t, sp<AudioPatch> >
class AudioPatchCollection : public DefaultKeyedVector<audio_patch_handle_t, sp<AudioPatch> >
+8 −4
Original line number Original line Diff line number Diff line
@@ -183,13 +183,17 @@ class SourceClientDescriptor: public TrackClientDescriptor
{
{
public:
public:
    SourceClientDescriptor(audio_port_handle_t portId, uid_t uid, audio_attributes_t attributes,
    SourceClientDescriptor(audio_port_handle_t portId, uid_t uid, audio_attributes_t attributes,
                           const sp<AudioPatch>& patchDesc, const sp<DeviceDescriptor>& srcDevice,
                           const struct audio_port_config &config,
                           const sp<DeviceDescriptor>& srcDevice,
                           audio_stream_type_t stream, product_strategy_t strategy,
                           audio_stream_type_t stream, product_strategy_t strategy,
                           VolumeSource volumeSource);
                           VolumeSource volumeSource);

    ~SourceClientDescriptor() override = default;
    ~SourceClientDescriptor() override = default;


    sp<AudioPatch> patchDesc() const { return mPatchDesc; }
    audio_patch_handle_t getPatchHandle() const { return mPatchHandle; }
    sp<DeviceDescriptor> srcDevice() const { return mSrcDevice; };
    void setPatchHandle(audio_patch_handle_t patchHandle) { mPatchHandle = patchHandle; }

    sp<DeviceDescriptor> srcDevice() const { return mSrcDevice; }
    wp<SwAudioOutputDescriptor> swOutput() const { return mSwOutput; }
    wp<SwAudioOutputDescriptor> swOutput() const { return mSwOutput; }
    void setSwOutput(const sp<SwAudioOutputDescriptor>& swOutput);
    void setSwOutput(const sp<SwAudioOutputDescriptor>& swOutput);
    wp<HwAudioOutputDescriptor> hwOutput() const { return mHwOutput; }
    wp<HwAudioOutputDescriptor> hwOutput() const { return mHwOutput; }
@@ -199,7 +203,7 @@ public:
    void dump(String8 *dst, int spaces, int index) const override;
    void dump(String8 *dst, int spaces, int index) const override;


 private:
 private:
    const sp<AudioPatch> mPatchDesc;
    audio_patch_handle_t mPatchHandle = AUDIO_PATCH_HANDLE_NONE;
    const sp<DeviceDescriptor> mSrcDevice;
    const sp<DeviceDescriptor> mSrcDevice;
    wp<SwAudioOutputDescriptor> mSwOutput;
    wp<SwAudioOutputDescriptor> mSwOutput;
    wp<HwAudioOutputDescriptor> mHwOutput;
    wp<HwAudioOutputDescriptor> mHwOutput;
+5 −6
Original line number Original line Diff line number Diff line
@@ -26,10 +26,9 @@
namespace android {
namespace android {


AudioPatch::AudioPatch(const struct audio_patch *patch, uid_t uid) :
AudioPatch::AudioPatch(const struct audio_patch *patch, uid_t uid) :
    mHandle(HandleGenerator<audio_patch_handle_t>::getNextHandle()),
    mPatch(*patch),
    mPatch(*patch),
    mUid(uid),
    mHandle(HandleGenerator<audio_patch_handle_t>::getNextHandle()),
    mAfPatchHandle(AUDIO_PATCH_HANDLE_NONE)
    mUid(uid)
{
{
}
}


@@ -68,7 +67,7 @@ status_t AudioPatchCollection::addAudioPatch(audio_patch_handle_t handle,
    add(handle, patch);
    add(handle, patch);
    ALOGV("addAudioPatch() handle %d af handle %d num_sources %d num_sinks %d source handle %d"
    ALOGV("addAudioPatch() handle %d af handle %d num_sources %d num_sinks %d source handle %d"
            "sink handle %d",
            "sink handle %d",
          handle, patch->mAfPatchHandle, patch->mPatch.num_sources, patch->mPatch.num_sinks,
          handle, patch->getAfHandle(), patch->mPatch.num_sources, patch->mPatch.num_sinks,
          patch->mPatch.sources[0].id, patch->mPatch.sinks[0].id);
          patch->mPatch.sources[0].id, patch->mPatch.sinks[0].id);
    return NO_ERROR;
    return NO_ERROR;
}
}
@@ -81,7 +80,7 @@ status_t AudioPatchCollection::removeAudioPatch(audio_patch_handle_t handle)
        ALOGW("removeAudioPatch() patch %d not in", handle);
        ALOGW("removeAudioPatch() patch %d not in", handle);
        return ALREADY_EXISTS;
        return ALREADY_EXISTS;
    }
    }
    ALOGV("removeAudioPatch() handle %d af handle %d", handle, valueAt(index)->mAfPatchHandle);
    ALOGV("removeAudioPatch() handle %d af handle %d", handle, valueAt(index)->getAfHandle());
    removeItemsAt(index);
    removeItemsAt(index);
    return NO_ERROR;
    return NO_ERROR;
}
}
@@ -123,7 +122,7 @@ status_t AudioPatchCollection::listAudioPatches(unsigned int *num_patches,
        }
        }
        if (patchesWritten < patchesMax) {
        if (patchesWritten < patchesMax) {
            patches[patchesWritten] = patch->mPatch;
            patches[patchesWritten] = patch->mPatch;
            patches[patchesWritten++].id = patch->mHandle;
            patches[patchesWritten++].id = patch->getHandle();
        }
        }
        (*num_patches)++;
        (*num_patches)++;
        ALOGV("listAudioPatches() patch %zu num_sources %d num_sinks %d",
        ALOGV("listAudioPatches() patch %zu num_sources %d num_sinks %d",
+3 −4
Original line number Original line Diff line number Diff line
@@ -82,14 +82,13 @@ void RecordClientDescriptor::dump(String8 *dst, int spaces, int index) const
}
}


SourceClientDescriptor::SourceClientDescriptor(audio_port_handle_t portId, uid_t uid,
SourceClientDescriptor::SourceClientDescriptor(audio_port_handle_t portId, uid_t uid,
         audio_attributes_t attributes, const sp<AudioPatch>& patchDesc,
         audio_attributes_t attributes, const struct audio_port_config &config,
         const sp<DeviceDescriptor>& srcDevice, audio_stream_type_t stream,
         const sp<DeviceDescriptor>& srcDevice, audio_stream_type_t stream,
         product_strategy_t strategy, VolumeSource volumeSource) :
         product_strategy_t strategy, VolumeSource volumeSource) :
    TrackClientDescriptor::TrackClientDescriptor(portId, uid, AUDIO_SESSION_NONE, attributes,
    TrackClientDescriptor::TrackClientDescriptor(portId, uid, AUDIO_SESSION_NONE, attributes,
        AUDIO_CONFIG_BASE_INITIALIZER, AUDIO_PORT_HANDLE_NONE,
        {config.sample_rate, config.channel_mask, config.format}, AUDIO_PORT_HANDLE_NONE,
        stream, strategy, volumeSource, AUDIO_OUTPUT_FLAG_NONE, false,
        stream, strategy, volumeSource, AUDIO_OUTPUT_FLAG_NONE, false,
        {} /* Sources do not support secondary outputs*/),
        {} /* Sources do not support secondary outputs*/), mSrcDevice(srcDevice)
        mPatchDesc(patchDesc), mSrcDevice(srcDevice)
{
{
}
}


+205 −223

File changed.

Preview size limit exceeded, changes collapsed.

Loading