AAudioServiceInterface.h revision c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fb
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef AAUDIO_BINDING_AAUDIO_SERVICE_INTERFACE_H
18#define AAUDIO_BINDING_AAUDIO_SERVICE_INTERFACE_H
19
20#include "binding/AAudioServiceDefinitions.h"
21#include "binding/AAudioStreamRequest.h"
22#include "binding/AAudioStreamConfiguration.h"
23#include "binding/AudioEndpointParcelable.h"
24
25/**
26 * This has the same methods as IAAudioService but without the Binder features.
27 *
28 * It allows us to abstract the Binder interface and use an AudioStreamInternal
29 * both in the client and in the service.
30 */
31namespace aaudio {
32
33class AAudioServiceInterface {
34public:
35
36    AAudioServiceInterface() {};
37    virtual ~AAudioServiceInterface() = default;
38
39    /**
40     * @param request info needed to create the stream
41     * @param configuration contains information about the created stream
42     * @return handle to the stream or a negative error
43     */
44    virtual aaudio_handle_t openStream(const AAudioStreamRequest &request,
45                                       AAudioStreamConfiguration &configuration) = 0;
46
47    virtual aaudio_result_t closeStream(aaudio_handle_t streamHandle) = 0;
48
49    /* Get an immutable description of the in-memory queues
50    * used to communicate with the underlying HAL or Service.
51    */
52    virtual aaudio_result_t getStreamDescription(aaudio_handle_t streamHandle,
53                                                 AudioEndpointParcelable &parcelable) = 0;
54
55    /**
56     * Start the flow of data.
57     */
58    virtual aaudio_result_t startStream(aaudio_handle_t streamHandle) = 0;
59
60    /**
61     * Stop the flow of data such that start() can resume without loss of data.
62     */
63    virtual aaudio_result_t pauseStream(aaudio_handle_t streamHandle) = 0;
64
65    /**
66     *  Discard any data held by the underlying HAL or Service.
67     */
68    virtual aaudio_result_t flushStream(aaudio_handle_t streamHandle) = 0;
69
70    /**
71     * Manage the specified thread as a low latency audio thread.
72     */
73    virtual aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle,
74                                                pid_t clientProcessId,
75                                                pid_t clientThreadId,
76                                                int64_t periodNanoseconds) = 0;
77
78    virtual aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
79                                                  pid_t clientProcessId,
80                                                  pid_t clientThreadId) = 0;
81};
82
83} /* namespace aaudio */
84
85#endif //AAUDIO_BINDING_AAUDIO_SERVICE_INTERFACE_H
86