blob: eddb5a059380b3f31025d3cab5a775a999388599 [file] [log] [blame]
Phil Burk5ed503c2017-02-01 09:38:15 -08001/*
2 * Copyright (C) 2016 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
Phil Burk3316d5e2017-02-15 11:23:01 -080017#ifndef AAUDIO_AAUDIO_SERVICE_H
18#define AAUDIO_AAUDIO_SERVICE_H
Phil Burk5ed503c2017-02-01 09:38:15 -080019
20#include <time.h>
21#include <pthread.h>
22
23#include <binder/BinderService.h>
Eric Laurenta54f1282017-07-01 19:39:32 -070024#include <media/AudioClient.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080025
Phil Burk5ed503c2017-02-01 09:38:15 -080026#include <aaudio/AAudio.h>
Phil Burkc0c70e32017-02-09 13:18:38 -080027
Phil Burk523b3042017-09-13 13:03:08 -070028#include "binding/AAudioCommon.h"
29#include "binding/AAudioServiceInterface.h"
30#include "binding/IAAudioService.h"
31
32#include "AAudioServiceStreamBase.h"
33#include "AAudioStreamTracker.h"
Phil Burk5ed503c2017-02-01 09:38:15 -080034
35namespace android {
36
37class AAudioService :
38 public BinderService<AAudioService>,
Phil Burkc0c70e32017-02-09 13:18:38 -080039 public BnAAudioService,
40 public aaudio::AAudioServiceInterface
Phil Burk5ed503c2017-02-01 09:38:15 -080041{
42 friend class BinderService<AAudioService>;
43
44public:
45 AAudioService();
46 virtual ~AAudioService();
47
Phil Burkc0c70e32017-02-09 13:18:38 -080048 static const char* getServiceName() { return AAUDIO_SERVICE_NAME; }
Phil Burk5ed503c2017-02-01 09:38:15 -080049
Andy Hung47c5e532017-06-26 18:28:00 -070050 virtual status_t dump(int fd, const Vector<String16>& args) override;
51
Phil Burk11e8d332017-05-24 09:59:02 -070052 virtual void registerClient(const sp<IAAudioClient>& client);
53
Phil Burk523b3042017-09-13 13:03:08 -070054 aaudio::aaudio_handle_t openStream(const aaudio::AAudioStreamRequest &request,
55 aaudio::AAudioStreamConfiguration &configurationOutput)
56 override;
Phil Burk5ed503c2017-02-01 09:38:15 -080057
Phil Burk523b3042017-09-13 13:03:08 -070058 aaudio_result_t closeStream(aaudio::aaudio_handle_t streamHandle) override;
Phil Burk5ed503c2017-02-01 09:38:15 -080059
Phil Burk523b3042017-09-13 13:03:08 -070060 aaudio_result_t getStreamDescription(
61 aaudio::aaudio_handle_t streamHandle,
62 aaudio::AudioEndpointParcelable &parcelable) override;
Phil Burk5ed503c2017-02-01 09:38:15 -080063
Phil Burk523b3042017-09-13 13:03:08 -070064 aaudio_result_t startStream(aaudio::aaudio_handle_t streamHandle) override;
Phil Burk5ed503c2017-02-01 09:38:15 -080065
Phil Burk523b3042017-09-13 13:03:08 -070066 aaudio_result_t pauseStream(aaudio::aaudio_handle_t streamHandle) override;
Phil Burk5ed503c2017-02-01 09:38:15 -080067
Phil Burk523b3042017-09-13 13:03:08 -070068 aaudio_result_t stopStream(aaudio::aaudio_handle_t streamHandle) override;
Phil Burk71f35bb2017-04-13 16:05:07 -070069
Phil Burk523b3042017-09-13 13:03:08 -070070 aaudio_result_t flushStream(aaudio::aaudio_handle_t streamHandle) override;
Phil Burk5ed503c2017-02-01 09:38:15 -080071
Phil Burk523b3042017-09-13 13:03:08 -070072 aaudio_result_t registerAudioThread(aaudio::aaudio_handle_t streamHandle,
Phil Burk2ac035f2017-06-23 14:51:14 -070073 pid_t tid,
Phil Burk523b3042017-09-13 13:03:08 -070074 int64_t periodNanoseconds) override;
Phil Burk5ed503c2017-02-01 09:38:15 -080075
Phil Burk523b3042017-09-13 13:03:08 -070076 aaudio_result_t unregisterAudioThread(aaudio::aaudio_handle_t streamHandle,
77 pid_t tid) override;
Phil Burk5ed503c2017-02-01 09:38:15 -080078
Phil Burk523b3042017-09-13 13:03:08 -070079 aaudio_result_t startClient(aaudio::aaudio_handle_t streamHandle,
jiabind1f1cb62020-03-24 11:57:57 -070080 const android::AudioClient& client,
81 const audio_attributes_t *attr,
82 audio_port_handle_t *clientHandle) override;
Eric Laurenta54f1282017-07-01 19:39:32 -070083
Phil Burk523b3042017-09-13 13:03:08 -070084 aaudio_result_t stopClient(aaudio::aaudio_handle_t streamHandle,
85 audio_port_handle_t clientHandle) override;
Eric Laurenta54f1282017-07-01 19:39:32 -070086
Phil Burkbbd52862018-04-13 11:37:42 -070087 aaudio_result_t disconnectStreamByPortHandle(audio_port_handle_t portHandle);
88
Phil Burk5ed503c2017-02-01 09:38:15 -080089private:
90
Phil Burk2ebf6622019-04-17 11:10:25 -070091 /** @return true if the client is the audioserver
92 */
93 bool isCallerInService();
94
Phil Burk523b3042017-09-13 13:03:08 -070095 /**
96 * Lookup stream and then validate access to the stream.
97 * @param streamHandle
98 * @return
99 */
100 sp<aaudio::AAudioServiceStreamBase> convertHandleToServiceStream(
101 aaudio::aaudio_handle_t streamHandle);
Phil Burk5ed503c2017-02-01 09:38:15 -0800102
Phil Burk5ed503c2017-02-01 09:38:15 -0800103
Phil Burk2ac035f2017-06-23 14:51:14 -0700104
Phil Burk94862522017-09-13 21:31:36 -0700105 bool releaseStream(const sp<aaudio::AAudioServiceStreamBase> &serviceStream);
106
107 aaudio_result_t checkForPendingClose(const sp<aaudio::AAudioServiceStreamBase> &serviceStream,
108 aaudio_result_t defaultResult);
109
110 android::AudioClient mAudioClient;
111
112 aaudio::AAudioStreamTracker mStreamTracker;
Phil Burk523b3042017-09-13 13:03:08 -0700113
Phil Burk2ebf6622019-04-17 11:10:25 -0700114 // TODO Extract the priority constants from services/audioflinger/Threads.cpp
115 // and share them with this code. Look for "kPriorityFastMixer".
116 static constexpr int32_t kRealTimeAudioPriorityClient = 2;
117 static constexpr int32_t kRealTimeAudioPriorityService = 3;
Phil Burk5ed503c2017-02-01 09:38:15 -0800118};
119
120} /* namespace android */
121
Phil Burk3316d5e2017-02-15 11:23:01 -0800122#endif //AAUDIO_AAUDIO_SERVICE_H