1c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk/*
2c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * Copyright (C) 2017 The Android Open Source Project
3c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk *
4c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * Licensed under the Apache License, Version 2.0 (the "License");
5c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * you may not use this file except in compliance with the License.
6c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * You may obtain a copy of the License at
7c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk *
8c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk *      http://www.apache.org/licenses/LICENSE-2.0
9c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk *
10c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * Unless required by applicable law or agreed to in writing, software
11c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * distributed under the License is distributed on an "AS IS" BASIS,
12c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * See the License for the specific language governing permissions and
14c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * limitations under the License.
15c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk */
16c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
175204d315c6c6f53188f8d1414dd1b55b6c90142bPhil Burk#ifndef ANDROID_AAUDIO_AAUDIO_BINDER_CLIENT_H
185204d315c6c6f53188f8d1414dd1b55b6c90142bPhil Burk#define ANDROID_AAUDIO_AAUDIO_BINDER_CLIENT_H
19c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
209b3f8ef290bd5ad392f5eba8a0f0a8ddd331b54fPhil Burk#include <utils/Singleton.h>
219b3f8ef290bd5ad392f5eba8a0f0a8ddd331b54fPhil Burk
22a4eb0d86a29be2763be5fac51727858d5095794bPhil Burk#include <aaudio/AAudio.h>
23c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#include "AAudioServiceDefinitions.h"
24c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#include "AAudioServiceInterface.h"
25c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#include "binding/AAudioStreamRequest.h"
26c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#include "binding/AAudioStreamConfiguration.h"
27c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk#include "binding/AudioEndpointParcelable.h"
28c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
29c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk/**
30c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk * Implements the AAudioServiceInterface by talking to the actual service through Binder.
31c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk */
32c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
33c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burknamespace aaudio {
34c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
359b3f8ef290bd5ad392f5eba8a0f0a8ddd331b54fPhil Burkclass AAudioBinderClient : public AAudioServiceInterface
369b3f8ef290bd5ad392f5eba8a0f0a8ddd331b54fPhil Burk        , public android::Singleton<AAudioBinderClient> {
37c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
38c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burkpublic:
39c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
40c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    AAudioBinderClient();
41c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
42c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    virtual ~AAudioBinderClient();
43c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
44c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    /**
45c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * @param request info needed to create the stream
46c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * @param configuration contains resulting information about the created stream
47c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * @return handle to the stream or a negative error
48c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     */
49c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    aaudio_handle_t openStream(const AAudioStreamRequest &request,
50c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                               AAudioStreamConfiguration &configurationOutput) override;
51c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
52c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    aaudio_result_t closeStream(aaudio_handle_t streamHandle) override;
53c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
54c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    /* Get an immutable description of the in-memory queues
55c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    * used to communicate with the underlying HAL or Service.
56c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    */
57c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    aaudio_result_t getStreamDescription(aaudio_handle_t streamHandle,
58c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                                 AudioEndpointParcelable &parcelable) override;
59c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
60c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    /**
61c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * Start the flow of data.
62c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * This is asynchronous. When complete, the service will send a STARTED event.
63c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     */
64c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    aaudio_result_t startStream(aaudio_handle_t streamHandle) override;
65c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
66c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    /**
67c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * Stop the flow of data such that start() can resume without loss of data.
68c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * This is asynchronous. When complete, the service will send a PAUSED event.
69c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     */
70c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    aaudio_result_t pauseStream(aaudio_handle_t streamHandle) override;
7171f35bb687476694882a617ba4a810a0bb56fe23Phil Burk
7271f35bb687476694882a617ba4a810a0bb56fe23Phil Burk    aaudio_result_t stopStream(aaudio_handle_t streamHandle) override;
73c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
74c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    /**
75c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     *  Discard any data held by the underlying HAL or Service.
76c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * This is asynchronous. When complete, the service will send a FLUSHED event.
77c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     */
78c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    aaudio_result_t flushStream(aaudio_handle_t streamHandle) override;
79c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
80c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    /**
81c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * Manage the specified thread as a low latency audio thread.
82c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     * TODO Consider passing this information as part of the startStream() call.
83c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk     */
84c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle,
85c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                                pid_t clientProcessId,
86c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                                pid_t clientThreadId,
87c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                                int64_t periodNanoseconds) override;
88c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
89c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk    aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
90c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                                  pid_t clientProcessId,
91c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk                                                  pid_t clientThreadId) override;
92c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk};
93c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
94c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
95c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk} /* namespace aaudio */
96c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fbPhil Burk
975204d315c6c6f53188f8d1414dd1b55b6c90142bPhil Burk#endif //ANDROID_AAUDIO_AAUDIO_BINDER_CLIENT_H
98