• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ANDROID_AAUDIO_BINDING_AAUDIO_SERVICE_INTERFACE_H
18 #define ANDROID_AAUDIO_BINDING_AAUDIO_SERVICE_INTERFACE_H
19 
20 #include <utils/StrongPointer.h>
21 #include <media/AudioClient.h>
22 
23 #include "binding/AAudioServiceDefinitions.h"
24 #include "binding/AAudioStreamRequest.h"
25 #include "binding/AAudioStreamConfiguration.h"
26 #include "binding/AudioEndpointParcelable.h"
27 #include "binding/IAAudioClient.h"
28 
29 /**
30  * This has the same methods as IAAudioService but without the Binder features.
31  *
32  * It allows us to abstract the Binder interface and use an AudioStreamInternal
33  * both in the client and in the service.
34  */
35 namespace aaudio {
36 
37 class AAudioServiceInterface {
38 public:
39 
AAudioServiceInterface()40     AAudioServiceInterface() {};
41     virtual ~AAudioServiceInterface() = default;
42 
43     virtual void registerClient(const android::sp<android::IAAudioClient>& client) = 0;
44 
45     /**
46      * @param request info needed to create the stream
47      * @param configuration contains information about the created stream
48      * @return handle to the stream or a negative error
49      */
50     virtual aaudio_handle_t openStream(const AAudioStreamRequest &request,
51                                        AAudioStreamConfiguration &configuration) = 0;
52 
53     virtual aaudio_result_t closeStream(aaudio_handle_t streamHandle) = 0;
54 
55     /* Get an immutable description of the in-memory queues
56     * used to communicate with the underlying HAL or Service.
57     */
58     virtual aaudio_result_t getStreamDescription(aaudio_handle_t streamHandle,
59                                                  AudioEndpointParcelable &parcelable) = 0;
60 
61     /**
62      * Start the flow of data.
63      */
64     virtual aaudio_result_t startStream(aaudio_handle_t streamHandle) = 0;
65 
66     /**
67      * Stop the flow of data such that start() can resume without loss of data.
68      */
69     virtual aaudio_result_t pauseStream(aaudio_handle_t streamHandle) = 0;
70 
71     /**
72      * Stop the flow of data after data currently inthe buffer has played.
73      */
74     virtual aaudio_result_t stopStream(aaudio_handle_t streamHandle) = 0;
75 
76     /**
77      *  Discard any data held by the underlying HAL or Service.
78      */
79     virtual aaudio_result_t flushStream(aaudio_handle_t streamHandle) = 0;
80 
81     /**
82      * Manage the specified thread as a low latency audio thread.
83      */
84     virtual aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle,
85                                                 pid_t clientThreadId,
86                                                 int64_t periodNanoseconds) = 0;
87 
88     virtual aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
89                                                   pid_t clientThreadId) = 0;
90 
91     virtual aaudio_result_t startClient(aaudio_handle_t streamHandle,
92                                       const android::AudioClient& client,
93                                       audio_port_handle_t *clientHandle) = 0;
94 
95     virtual aaudio_result_t stopClient(aaudio_handle_t streamHandle,
96                                        audio_port_handle_t clientHandle) = 0;
97 };
98 
99 } /* namespace aaudio */
100 
101 #endif //ANDROID_AAUDIO_BINDING_AAUDIO_SERVICE_INTERFACE_H
102