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

Commit eeb656cf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "aaudio: process callbacks asynchronously" into rvc-dev am: e3469d1d

Change-Id: Ica98c344e7e12080cd8994322f3219bca5521563
parents e630488d e3469d1d
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -23,10 +23,10 @@
#include <map>
#include <mutex>
#include <sstream>
#include <thread>
#include <utils/Singleton.h>
#include <vector>


#include "AAudioEndpointManager.h"
#include "AAudioServiceEndpoint.h"

@@ -36,7 +36,6 @@
#include "AAudioServiceEndpointPlay.h"
#include "AAudioServiceEndpointMMAP.h"


#define AAUDIO_BUFFER_CAPACITY_MIN    4 * 512
#define AAUDIO_SAMPLE_RATE_DEFAULT    48000

@@ -48,7 +47,6 @@
using namespace android;  // TODO just import names needed
using namespace aaudio;   // TODO just import names needed


AAudioServiceEndpointMMAP::AAudioServiceEndpointMMAP(AAudioService &audioService)
        : mMmapStream(nullptr)
        , mAAudioService(audioService) {}
@@ -318,9 +316,8 @@ aaudio_result_t AAudioServiceEndpointMMAP::getTimestamp(int64_t *positionFrames,
    return 0; // TODO
}

// This is called by AudioFlinger when it wants to destroy a stream.
void AAudioServiceEndpointMMAP::onTearDown(audio_port_handle_t portHandle) {
    ALOGD("%s(portHandle = %d) called", __func__, portHandle);
// This is called by onTearDown() in a separate thread to avoid deadlocks.
void AAudioServiceEndpointMMAP::handleTearDownAsync(audio_port_handle_t portHandle) {
    // Are we tearing down the EXCLUSIVE MMAP stream?
    if (isStreamRegistered(portHandle)) {
        ALOGD("%s(%d) tearing down this entire MMAP endpoint", __func__, portHandle);
@@ -333,6 +330,13 @@ void AAudioServiceEndpointMMAP::onTearDown(audio_port_handle_t portHandle) {
    }
};

// This is called by AudioFlinger when it wants to destroy a stream.
void AAudioServiceEndpointMMAP::onTearDown(audio_port_handle_t portHandle) {
    ALOGD("%s(portHandle = %d) called", __func__, portHandle);
    std::thread asyncTask(&AAudioServiceEndpointMMAP::handleTearDownAsync, this, portHandle);
    asyncTask.detach();
}

void AAudioServiceEndpointMMAP::onVolumeChanged(audio_channel_mask_t channels,
                                              android::Vector<float> values) {
    // TODO Do we really need a different volume for each channel?
@@ -345,12 +349,20 @@ void AAudioServiceEndpointMMAP::onVolumeChanged(audio_channel_mask_t channels,
    }
};

void AAudioServiceEndpointMMAP::onRoutingChanged(audio_port_handle_t deviceId) {
void AAudioServiceEndpointMMAP::onRoutingChanged(audio_port_handle_t portHandle) {
    const int32_t deviceId = static_cast<int32_t>(portHandle);
    ALOGD("%s() called with dev %d, old = %d", __func__, deviceId, getDeviceId());
    if (getDeviceId() != AUDIO_PORT_HANDLE_NONE  && getDeviceId() != deviceId) {
    if (getDeviceId() != deviceId) {
        if (getDeviceId() != AUDIO_PORT_HANDLE_NONE) {
            std::thread asyncTask([this, deviceId]() {
                disconnectRegisteredStreams();
    }
                setDeviceId(deviceId);
            });
            asyncTask.detach();
        } else {
            setDeviceId(deviceId);
        }
    }
};

/**
+4 −2
Original line number Diff line number Diff line
@@ -68,13 +68,15 @@ public:

    aaudio_result_t getTimestamp(int64_t *positionFrames, int64_t *timeNanos) override;

    void handleTearDownAsync(audio_port_handle_t portHandle);

    // -------------- Callback functions for MmapStreamCallback ---------------------
    void onTearDown(audio_port_handle_t handle) override;
    void onTearDown(audio_port_handle_t portHandle) override;

    void onVolumeChanged(audio_channel_mask_t channels,
                         android::Vector<float> values) override;

    void onRoutingChanged(audio_port_handle_t deviceId) override;
    void onRoutingChanged(audio_port_handle_t portHandle) override;
    // ------------------------------------------------------------------------------

    aaudio_result_t getDownDataDescription(AudioEndpointParcelable &parcelable);