1828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk/*
2828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * Copyright (C) 2016 The Android Open Source Project
3828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *
4828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * Licensed under the Apache License, Version 2.0 (the "License");
5828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * you may not use this file except in compliance with the License.
6828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * You may obtain a copy of the License at
7828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *
8828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *      http://www.apache.org/licenses/LICENSE-2.0
9828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *
10828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * Unless required by applicable law or agreed to in writing, software
11828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * distributed under the License is distributed on an "AS IS" BASIS,
12828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * See the License for the specific language governing permissions and
14828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * limitations under the License.
15828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk */
16828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
175204d315c6c6f53188f8d1414dd1b55b6c90142bPhil Burk#ifndef ANDROID_AAUDIO_IAAUDIO_SERVICE_H
185204d315c6c6f53188f8d1414dd1b55b6c90142bPhil Burk#define ANDROID_AAUDIO_IAAUDIO_SERVICE_H
19828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
20828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <stdint.h>
21828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <utils/RefBase.h>
22828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <binder/TextOutput.h>
23828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <binder/IInterface.h>
24828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
255ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#include <aaudio/AAudio.h>
26828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
275ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#include "binding/AAudioServiceDefinitions.h"
28828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include "binding/AudioEndpointParcelable.h"
295ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#include "binding/AAudioStreamRequest.h"
305ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#include "binding/AAudioStreamConfiguration.h"
31c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#include "utility/HandleTracker.h"
32828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
33828bea5f61f3c40d24759cd8739dd95570883b56Phil Burknamespace android {
34828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
35c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#define AAUDIO_SERVICE_NAME  "media.aaudio"
36c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
37828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk// Interface (our AIDL) - Shared by server and client
385ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burkclass IAAudioService : public IInterface {
39828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkpublic:
40828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
415ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk    DECLARE_META_INTERFACE(AAudioService);
42828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
433df348fbaca567ca891503213ff8c344a1ea2e05Phil Burk    /**
443df348fbaca567ca891503213ff8c344a1ea2e05Phil Burk     * @param request info needed to create the stream
453df348fbaca567ca891503213ff8c344a1ea2e05Phil Burk     * @param configuration contains information about the created stream
463df348fbaca567ca891503213ff8c344a1ea2e05Phil Burk     * @return handle to the stream or a negative error
473df348fbaca567ca891503213ff8c344a1ea2e05Phil Burk     */
48c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    virtual aaudio_handle_t openStream(const aaudio::AAudioStreamRequest &request,
49c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                     aaudio::AAudioStreamConfiguration &configurationOutput) = 0;
50828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
513316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk    virtual aaudio_result_t closeStream(aaudio::aaudio_handle_t streamHandle) = 0;
52828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
53828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    /* Get an immutable description of the in-memory queues
54828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    * used to communicate with the underlying HAL or Service.
55828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    */
563316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk    virtual aaudio_result_t getStreamDescription(aaudio::aaudio_handle_t streamHandle,
575ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk                                               aaudio::AudioEndpointParcelable &parcelable) = 0;
58828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
59828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    /**
60828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     * Start the flow of data.
61c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * This is asynchronous. When complete, the service will send a STARTED event.
62828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     */
633316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk    virtual aaudio_result_t startStream(aaudio::aaudio_handle_t streamHandle) = 0;
64828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
65828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    /**
66828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     * Stop the flow of data such that start() can resume without loss of data.
67c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * This is asynchronous. When complete, the service will send a PAUSED event.
68828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     */
693316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk    virtual aaudio_result_t pauseStream(aaudio::aaudio_handle_t streamHandle) = 0;
70828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
71828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    /**
7271f35bb687476694882a617ba4a810a0bb56fe23Phil Burk     * Stop the flow of data such that the data currently in the buffer is played.
7371f35bb687476694882a617ba4a810a0bb56fe23Phil Burk     * This is asynchronous. When complete, the service will send a STOPPED event.
7471f35bb687476694882a617ba4a810a0bb56fe23Phil Burk     */
7571f35bb687476694882a617ba4a810a0bb56fe23Phil Burk    virtual aaudio_result_t stopStream(aaudio::aaudio_handle_t streamHandle) = 0;
7671f35bb687476694882a617ba4a810a0bb56fe23Phil Burk
7771f35bb687476694882a617ba4a810a0bb56fe23Phil Burk    /**
78828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     *  Discard any data held by the underlying HAL or Service.
79c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * This is asynchronous. When complete, the service will send a FLUSHED event.
80828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     */
813316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk    virtual aaudio_result_t flushStream(aaudio::aaudio_handle_t streamHandle) = 0;
82828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
83828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    /**
84828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     * Manage the specified thread as a low latency audio thread.
85c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * TODO Consider passing this information as part of the startStream() call.
86828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     */
87c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    virtual aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle,
88c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                              pid_t clientProcessId,
89c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                              pid_t clientThreadId,
903316d5e6d375a4f09c681205e9094d30a0bfc4a2Phil Burk                                              int64_t periodNanoseconds) = 0;
91828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
92c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    virtual aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
93c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                                pid_t clientProcessId,
94828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk                                                pid_t clientThreadId) = 0;
95828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk};
96828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
975ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burkclass BnAAudioService : public BnInterface<IAAudioService> {
98828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkpublic:
99828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    virtual status_t onTransact(uint32_t code, const Parcel& data,
100828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk                                Parcel* reply, uint32_t flags = 0);
101828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
102828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk};
103828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
104828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk} /* namespace android */
105828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
1065204d315c6c6f53188f8d1414dd1b55b6c90142bPhil Burk#endif //ANDROID_AAUDIO_IAAUDIO_SERVICE_H
107