blob: ffaf53854caafc119b5e5720d829ca1f0668fd66 [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>
27#include "utility/HandleTracker.h"
Phil Burkc0c70e32017-02-09 13:18:38 -080028#include "binding/IAAudioService.h"
29#include "binding/AAudioServiceInterface.h"
30
Phil Burk39f02dd2017-08-04 09:13:31 -070031namespace aaudio {
32 class AAudioServiceStreamBase;
33};
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 Burkc0c70e32017-02-09 13:18:38 -080054 virtual aaudio_handle_t openStream(const aaudio::AAudioStreamRequest &request,
Phil Burk11e8d332017-05-24 09:59:02 -070055 aaudio::AAudioStreamConfiguration &configurationOutput);
Phil Burk5ed503c2017-02-01 09:38:15 -080056
57 virtual aaudio_result_t closeStream(aaudio_handle_t streamHandle);
58
59 virtual aaudio_result_t getStreamDescription(
60 aaudio_handle_t streamHandle,
61 aaudio::AudioEndpointParcelable &parcelable);
62
63 virtual aaudio_result_t startStream(aaudio_handle_t streamHandle);
64
65 virtual aaudio_result_t pauseStream(aaudio_handle_t streamHandle);
66
Phil Burk71f35bb2017-04-13 16:05:07 -070067 virtual aaudio_result_t stopStream(aaudio_handle_t streamHandle);
68
Phil Burk5ed503c2017-02-01 09:38:15 -080069 virtual aaudio_result_t flushStream(aaudio_handle_t streamHandle);
70
71 virtual aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle,
Phil Burk2ac035f2017-06-23 14:51:14 -070072 pid_t tid,
73 int64_t periodNanoseconds) ;
Phil Burk5ed503c2017-02-01 09:38:15 -080074
Phil Burkc0c70e32017-02-09 13:18:38 -080075 virtual aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
Phil Burk2ac035f2017-06-23 14:51:14 -070076 pid_t tid);
Phil Burk5ed503c2017-02-01 09:38:15 -080077
Eric Laurenta54f1282017-07-01 19:39:32 -070078 virtual aaudio_result_t startClient(aaudio_handle_t streamHandle,
79 const android::AudioClient& client,
80 audio_port_handle_t *clientHandle);
81
82 virtual aaudio_result_t stopClient(aaudio_handle_t streamHandle,
83 audio_port_handle_t clientHandle);
84
Phil Burk5ed503c2017-02-01 09:38:15 -080085private:
86
87 aaudio::AAudioServiceStreamBase *convertHandleToServiceStream(aaudio_handle_t streamHandle) const;
88
89 HandleTracker mHandleTracker;
90
Eric Laurenta54f1282017-07-01 19:39:32 -070091 android::AudioClient mAudioClient;
Phil Burk2ac035f2017-06-23 14:51:14 -070092
Phil Burkc0c70e32017-02-09 13:18:38 -080093 enum constants {
94 DEFAULT_AUDIO_PRIORITY = 2
95 };
Phil Burk5ed503c2017-02-01 09:38:15 -080096};
97
98} /* namespace android */
99
Phil Burk3316d5e2017-02-15 11:23:01 -0800100#endif //AAUDIO_AAUDIO_SERVICE_H