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

Commit 520274a8 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

release-request-9336bb6f-90e7-478e-9d85-062ca3fdf6a3-for-git_oc-dr1-release-41...

release-request-9336bb6f-90e7-478e-9d85-062ca3fdf6a3-for-git_oc-dr1-release-4152361 snap-temp-L91700000079439679

Change-Id: Ie537045bb4fc0728648a86905183bdd8405a0c42
parents 0fc35b08 d51329ec
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -48,8 +48,8 @@ int main(int argc, char **argv)
    //aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE;
    const aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY;
    //aaudio_performance_mode_t requestedPerformanceMode = AAUDIO_PERFORMANCE_MODE_POWER_SAVING;
    const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_SHARED;
    //const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_EXCLUSIVE;
    //const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_SHARED;
    const aaudio_sharing_mode_t requestedSharingMode = AAUDIO_SHARING_MODE_EXCLUSIVE;
    aaudio_sharing_mode_t actualSharingMode;

    AAudioStream *aaudioStream = nullptr;
@@ -70,7 +70,7 @@ int main(int argc, char **argv)

    printf("%s - Monitor input level using AAudio\n", argv[0]);

//    AAudio_setMMapPolicy(AAUDIO_POLICY_ALWAYS);
    AAudio_setMMapPolicy(AAUDIO_POLICY_ALWAYS);

    recorder.setPerformanceMode(requestedPerformanceMode);
    recorder.setSharingMode(requestedSharingMode);
+5 −5
Original line number Diff line number Diff line
@@ -25,17 +25,17 @@
#include "AAudioSimplePlayer.h"

#define SAMPLE_RATE           48000
#define NUM_SECONDS           20
#define NUM_SECONDS           4

#define MMAP_POLICY              AAUDIO_UNSPECIFIED
//#define MMAP_POLICY              AAUDIO_UNSPECIFIED
//#define MMAP_POLICY              AAUDIO_POLICY_NEVER
//#define MMAP_POLICY              AAUDIO_POLICY_AUTO
//#define MMAP_POLICY              AAUDIO_POLICY_ALWAYS
#define MMAP_POLICY              AAUDIO_POLICY_ALWAYS

#define REQUESTED_FORMAT         AAUDIO_FORMAT_PCM_I16

#define REQUESTED_SHARING_MODE   AAUDIO_SHARING_MODE_SHARED
//#define REQUESTED_SHARING_MODE   AAUDIO_SHARING_MODE_EXCLUSIVE
//#define REQUESTED_SHARING_MODE   AAUDIO_SHARING_MODE_SHARED
#define REQUESTED_SHARING_MODE   AAUDIO_SHARING_MODE_EXCLUSIVE


int main(int argc, char **argv)
+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ LOCAL_SRC_FILES = \
    binding/AAudioBinderClient.cpp \
    binding/AAudioStreamRequest.cpp \
    binding/AAudioStreamConfiguration.cpp \
    binding/IAAudioClient.cpp \
    binding/IAAudioService.cpp \
    binding/RingBufferParcelable.cpp \
    binding/SharedMemoryParcelable.cpp \
@@ -109,6 +110,7 @@ LOCAL_SRC_FILES = core/AudioStream.cpp \
    binding/AAudioBinderClient.cpp \
    binding/AAudioStreamRequest.cpp \
    binding/AAudioStreamConfiguration.cpp \
    binding/IAAudioClient.cpp \
    binding/IAAudioService.cpp \
    binding/RingBufferParcelable.cpp \
    binding/SharedMemoryParcelable.cpp \
+62 −40
Original line number Diff line number Diff line
@@ -19,44 +19,64 @@
//#define LOG_NDEBUG 0
#include <utils/Log.h>

#include <binder/IInterface.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <utils/Mutex.h>
#include <utils/RefBase.h>
#include <utils/Singleton.h>
#include <media/AudioSystem.h>

#include <aaudio/AAudio.h>

#include "AudioEndpointParcelable.h"
#include "binding/AAudioStreamRequest.h"
#include "binding/AAudioStreamConfiguration.h"
#include "binding/IAAudioService.h"
#include "binding/AAudioServiceMessage.h"
#include "binding/AAudioBinderClient.h"
//#include "binding/AAudioStreamRequest.h"
//#include "binding/AAudioStreamConfiguration.h"
//#include "binding/IAAudioService.h"
//#include "binding/AAudioServiceMessage.h"

#include "AAudioBinderClient.h"
#include "AAudioServiceInterface.h"
//#include "AAudioServiceInterface.h"

using android::String16;
using android::IServiceManager;
using android::defaultServiceManager;
using android::interface_cast;
using android::IInterface;
using android::IAAudioService;
using android::Mutex;
using android::sp;
using android::wp;

using namespace aaudio;

static android::Mutex gServiceLock;
static sp<IAAudioService>  gAAudioService;

ANDROID_SINGLETON_STATIC_INSTANCE(AAudioBinderClient);

AAudioBinderClient::AAudioBinderClient()
        : AAudioServiceInterface()
        , Singleton<AAudioBinderClient>() {

    mAAudioClient = new AAudioClient(this);
    ALOGD("AAudioBinderClient() created mAAudioClient = %p", mAAudioClient.get());
}

AAudioBinderClient::~AAudioBinderClient() {
    Mutex::Autolock _l(mServiceLock);
    if (mAAudioService != 0) {
        IInterface::asBinder(mAAudioService)->unlinkToDeath(mAAudioClient);
    }
}

// TODO Share code with other service clients.
// Helper function to get access to the "AAudioService" service.
// This code was modeled after frameworks/av/media/libaudioclient/AudioSystem.cpp
static const sp<IAAudioService> getAAudioService() {
const sp<IAAudioService> AAudioBinderClient::getAAudioService() {
    sp<IAAudioService> aaudioService;
    bool needToRegister = false;
    {
        Mutex::Autolock _l(mServiceLock);
        if (mAAudioService == 0) {
            sp<IBinder> binder;
    Mutex::Autolock _l(gServiceLock);
    if (gAAudioService == 0) {
            sp<IServiceManager> sm = defaultServiceManager();
            // Try several times to get the service.
            int retries = 4;
@@ -68,26 +88,32 @@ static const sp<IAAudioService> getAAudioService() {
            } while (retries-- > 0);

            if (binder != 0) {
            // TODO Add linkToDeath() like in frameworks/av/media/libaudioclient/AudioSystem.cpp
            // TODO Create a DeathRecipient that disconnects all active streams.
            gAAudioService = interface_cast<IAAudioService>(binder);
                // Ask for notification if the service dies.
                status_t status = binder->linkToDeath(mAAudioClient);
                ALOGD("getAAudioService: linkToDeath(mAAudioClient = %p) returned %d",
                      mAAudioClient.get(), status);
                mAAudioService = interface_cast<IAAudioService>(binder);
                needToRegister = true;
                // Make sure callbacks can be received by mAAudioClient
                android::ProcessState::self()->startThreadPool();
            } else {
            ALOGE("AudioStreamInternal could not get %s", AAUDIO_SERVICE_NAME);
                ALOGE("AAudioBinderClient could not connect to %s", AAUDIO_SERVICE_NAME);
            }
        }
    return gAAudioService;
        aaudioService = mAAudioService;
    }

static void dropAAudioService() {
    Mutex::Autolock _l(gServiceLock);
    gAAudioService.clear(); // force a reconnect
    // Do this outside the mutex lock.
    if (needToRegister && aaudioService != 0) { // new client?
        aaudioService->registerClient(mAAudioClient);
    }
    return aaudioService;
}

AAudioBinderClient::AAudioBinderClient()
        : AAudioServiceInterface()
        , Singleton<AAudioBinderClient>() {}
void AAudioBinderClient::dropAAudioService() {
    Mutex::Autolock _l(mServiceLock);
    mAAudioService.clear(); // force a reconnect
}

AAudioBinderClient::~AAudioBinderClient() {}

/**
* @param request info needed to create the stream
@@ -159,23 +185,19 @@ aaudio_result_t AAudioBinderClient::flushStream(aaudio_handle_t streamHandle) {
* Manage the specified thread as a low latency audio thread.
*/
aaudio_result_t AAudioBinderClient::registerAudioThread(aaudio_handle_t streamHandle,
                                                        pid_t clientProcessId,
                                                        pid_t clientThreadId,
                                                        int64_t periodNanoseconds) {
    const sp<IAAudioService> &service = getAAudioService();
    if (service == 0) return AAUDIO_ERROR_NO_SERVICE;
    return service->registerAudioThread(streamHandle,
                                        clientProcessId,
                                        clientThreadId,
                                        periodNanoseconds);
}

aaudio_result_t AAudioBinderClient::unregisterAudioThread(aaudio_handle_t streamHandle,
                                                          pid_t clientProcessId,
                                                          pid_t clientThreadId) {
    const sp<IAAudioService> &service = getAAudioService();
    if (service == 0) return AAUDIO_ERROR_NO_SERVICE;
    return service->unregisterAudioThread(streamHandle,
                                          clientProcessId,
                                          clientThreadId);
}
+50 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef ANDROID_AAUDIO_AAUDIO_BINDER_CLIENT_H
#define ANDROID_AAUDIO_AAUDIO_BINDER_CLIENT_H

#include <utils/RefBase.h>
#include <utils/Singleton.h>

#include <aaudio/AAudio.h>
@@ -25,14 +26,16 @@
#include "binding/AAudioStreamRequest.h"
#include "binding/AAudioStreamConfiguration.h"
#include "binding/AudioEndpointParcelable.h"
#include "binding/IAAudioService.h"

/**
 * Implements the AAudioServiceInterface by talking to the actual service through Binder.
 * Implements the AAudioServiceInterface by talking to the service through Binder.
 */

namespace aaudio {

class AAudioBinderClient : public AAudioServiceInterface
class AAudioBinderClient : public virtual android::RefBase
        , public AAudioServiceInterface
        , public android::Singleton<AAudioBinderClient> {

public:
@@ -41,6 +44,12 @@ public:

    virtual ~AAudioBinderClient();

    const android::sp<android::IAAudioService> getAAudioService();

    void dropAAudioService();

    void registerClient(const android::sp<android::IAAudioClient>& client __unused) override {}

    /**
     * @param request info needed to create the stream
     * @param configuration contains resulting information about the created stream
@@ -82,13 +91,50 @@ public:
     * TODO Consider passing this information as part of the startStream() call.
     */
    aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle,
                                                pid_t clientProcessId,
                                                pid_t clientThreadId,
                                                int64_t periodNanoseconds) override;

    aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
                                                  pid_t clientProcessId,
                                                  pid_t clientThreadId) override;

    void onStreamChange(aaudio_handle_t handle, int32_t opcode, int32_t value) {
        // TODO This is just a stub so we can have a client Binder to pass to the service.
        // TODO Implemented in a later CL.
        ALOGW("onStreamChange called!");
    }

    class AAudioClient : public android::IBinder::DeathRecipient , public android::BnAAudioClient
    {
    public:
        AAudioClient(android::wp<AAudioBinderClient> aaudioBinderClient)
            : mBinderClient(aaudioBinderClient) {
        }

        // implement DeathRecipient
        virtual void binderDied(const android::wp<android::IBinder>& who __unused) {
            android::sp<AAudioBinderClient> client = mBinderClient.promote();
            if (client != 0) {
                client->dropAAudioService();
            }
            ALOGW("AAudio service binderDied()!");
        }

        // implement BnAAudioClient
        void onStreamChange(aaudio_handle_t handle, int32_t opcode, int32_t value) {
            android::sp<AAudioBinderClient> client = mBinderClient.promote();
            if (client != 0) {
                client->onStreamChange(handle, opcode, value);
            }
        }
    private:
        android::wp<AAudioBinderClient> mBinderClient;
    };


    android::Mutex               mServiceLock;
    android::sp<android::IAAudioService>  mAAudioService;
    android::sp<AAudioClient>    mAAudioClient;

};


Loading