blob: 2a6571b9e32f553548f3fbc363b56ef948ff9c88 [file] [log] [blame]
Eric Laurent27ef4d82016-10-14 15:46:06 -07001/*
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
Mikhail Naganov10548292016-10-31 10:39:47 -070017#define LOG_TAG "audiohalservice"
Eric Laurent27ef4d82016-10-14 15:46:06 -070018
Mikhail Naganov10548292016-10-31 10:39:47 -070019#include <android/hardware/audio/2.0/IDevicesFactory.h>
Kevin Rocard91a73b42018-03-01 18:56:58 -080020#include <android/hardware/audio/4.0/IDevicesFactory.h>
Kevin Rocard20614ba2018-11-10 07:20:17 -080021#include <android/hardware/audio/5.0/IDevicesFactory.h>
Mikhail Naganov10548292016-10-31 10:39:47 -070022#include <android/hardware/audio/effect/2.0/IEffectsFactory.h>
Kevin Rocard91a73b42018-03-01 18:56:58 -080023#include <android/hardware/audio/effect/4.0/IEffectsFactory.h>
Kevin Rocard20614ba2018-11-10 07:20:17 -080024#include <android/hardware/audio/effect/5.0/IEffectsFactory.h>
Aniket Kumar Latac5a52032018-01-31 20:17:30 -080025#include <android/hardware/bluetooth/a2dp/1.0/IBluetoothAudioOffload.h>
Cheney Ni4f6882f2018-11-27 16:23:27 +080026#include <android/hardware/bluetooth/audio/2.0/IBluetoothAudioProvidersFactory.h>
Mikhail Naganovce8d65b2018-01-22 13:25:09 -080027#include <android/hardware/soundtrigger/2.0/ISoundTriggerHw.h>
Mikhail Naganov5697a9b2017-12-28 13:29:59 -080028#include <android/hardware/soundtrigger/2.1/ISoundTriggerHw.h>
mike dooley2f0da262018-12-18 19:59:14 +010029#include <android/hardware/soundtrigger/2.2/ISoundTriggerHw.h>
Haynes Mathew Georgea57f41d2018-02-21 14:45:20 -080030#include <binder/ProcessState.h>
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070031#include <cutils/properties.h>
Mikhail Naganov5697a9b2017-12-28 13:29:59 -080032#include <hidl/HidlTransportSupport.h>
33#include <hidl/LegacySupport.h>
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070034#include <hwbinder/ProcessState.h>
Eric Laurent27ef4d82016-10-14 15:46:06 -070035
Kevin Rocard91a73b42018-03-01 18:56:58 -080036using namespace android::hardware;
Mikhail Naganov3c256462017-02-08 16:34:22 -080037using android::OK;
38
Kevin Rocard5261dce2019-06-18 12:40:48 -070039/** Try to register the provided factories in the provided order.
40 * If any registers successfully, do not register any other and return true.
41 * If all fail, return false.
42 */
43template <class... Factories>
44bool registerPassthroughServiceImplementations() {
45 return ((registerPassthroughServiceImplementation<Factories>() != OK) && ...);
46}
47
Eric Laurent27ef4d82016-10-14 15:46:06 -070048int main(int /* argc */, char* /* argv */ []) {
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070049 ::android::ProcessState::initWithDriver("/dev/vndbinder");
Haynes Mathew Georgea57f41d2018-02-21 14:45:20 -080050 // start a threadpool for vndbinder interactions
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070051 ::android::ProcessState::self()->startThreadPool();
52
53 const int32_t defaultValue = -1;
54 int32_t value =
55 property_get_int32("persist.vendor.audio.service.hwbinder.size_kbyte", defaultValue);
56 if (value != defaultValue) {
57 ALOGD("Configuring hwbinder with mmap size %d KBytes", value);
58 ProcessState::initWithMmapSize(static_cast<size_t>(value) * 1024);
59 }
Martijn Coenen02822372016-12-29 14:03:41 +010060 configureRpcThreadpool(16, true /*callerWillJoin*/);
Kevin Rocard91a73b42018-03-01 18:56:58 -080061
Kevin Rocard5261dce2019-06-18 12:40:48 -070062 LOG_ALWAYS_FATAL_IF((registerPassthroughServiceImplementations<audio::V5_0::IDevicesFactory,
63 audio::V4_0::IDevicesFactory,
64 audio::V2_0::IDevicesFactory>()),
65 "Could not register audio core API");
Kevin Rocard91a73b42018-03-01 18:56:58 -080066
Kevin Rocard5261dce2019-06-18 12:40:48 -070067 LOG_ALWAYS_FATAL_IF(
68 (registerPassthroughServiceImplementations<audio::effect::V5_0::IEffectsFactory,
69 audio::effect::V4_0::IEffectsFactory,
70 audio::effect::V2_0::IEffectsFactory>()),
71 "Could not register audio effect API");
Kevin Rocard91a73b42018-03-01 18:56:58 -080072
Kevin Rocard5261dce2019-06-18 12:40:48 -070073 ALOGW_IF((registerPassthroughServiceImplementations<soundtrigger::V2_2::ISoundTriggerHw,
74 soundtrigger::V2_1::ISoundTriggerHw,
75 soundtrigger::V2_0::ISoundTriggerHw>()),
76 "Could not register soundtrigger API");
Kevin Rocard91a73b42018-03-01 18:56:58 -080077
Kevin Rocard5261dce2019-06-18 12:40:48 -070078 ALOGW_IF(registerPassthroughServiceImplementations<
79 bluetooth::audio::V2_0::IBluetoothAudioProvidersFactory>(),
80 "Could not register Bluetooth audio API");
Cheney Ni4f6882f2018-11-27 16:23:27 +080081
82 // remove the old HIDL when Bluetooth Audio Hal V2 has offloading supported
Kevin Rocard5261dce2019-06-18 12:40:48 -070083 ALOGW_IF(registerPassthroughServiceImplementations<
84 bluetooth::a2dp::V1_0::IBluetoothAudioOffload>(),
85 "Could not register Bluetooth audio offload API");
Aniket Kumar Latac5a52032018-01-31 20:17:30 -080086
Martijn Coenen02822372016-12-29 14:03:41 +010087 joinRpcThreadpool();
Eric Laurent27ef4d82016-10-14 15:46:06 -070088}