blob: e23aec9283e5af2ec94c6dc05d0d83fb034c612b [file] [log] [blame]
Kevin Rocardd4de2882018-02-28 14:33:38 -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
17#define LOG_TAG "EffectsFactoryHalHidl"
18//#define LOG_NDEBUG 0
19
20#include <cutils/native_handle.h>
21
Kevin Rocarddf9b4202018-05-10 19:56:08 -070022#include "EffectsFactoryHalHidl.h"
Kevin Rocardd4de2882018-02-28 14:33:38 -080023#include "ConversionHelperHidl.h"
24#include "EffectBufferHalHidl.h"
25#include "EffectHalHidl.h"
Kevin Rocardd4de2882018-02-28 14:33:38 -080026#include "HidlUtils.h"
27
Kevin Rocard2390b5d2018-02-28 14:36:53 -080028using ::android::hardware::audio::common::V4_0::HidlUtils;
29using ::android::hardware::audio::common::V4_0::Uuid;
30using ::android::hardware::audio::effect::V4_0::IEffect;
31using ::android::hardware::audio::effect::V4_0::Result;
Kevin Rocardd4de2882018-02-28 14:33:38 -080032using ::android::hardware::Return;
33
34namespace android {
Kevin Rocard2390b5d2018-02-28 14:36:53 -080035namespace V4_0 {
Kevin Rocardd4de2882018-02-28 14:33:38 -080036
37EffectsFactoryHalHidl::EffectsFactoryHalHidl() : ConversionHelperHidl("EffectsFactory") {
38 mEffectsFactory = IEffectsFactory::getService();
39 if (mEffectsFactory == 0) {
40 ALOGE("Failed to obtain IEffectsFactory service, terminating process.");
41 exit(1);
42 }
43}
44
Kevin Rocardd4de2882018-02-28 14:33:38 -080045status_t EffectsFactoryHalHidl::queryAllDescriptors() {
46 if (mEffectsFactory == 0) return NO_INIT;
47 Result retval = Result::NOT_INITIALIZED;
48 Return<void> ret = mEffectsFactory->getAllDescriptors(
49 [&](Result r, const hidl_vec<EffectDescriptor>& result) {
50 retval = r;
51 if (retval == Result::OK) {
52 mLastDescriptors = result;
53 }
54 });
55 if (ret.isOk()) {
56 return retval == Result::OK ? OK : NO_INIT;
57 }
58 mLastDescriptors.resize(0);
59 return processReturn(__FUNCTION__, ret);
60}
61
62status_t EffectsFactoryHalHidl::queryNumberEffects(uint32_t *pNumEffects) {
63 status_t queryResult = queryAllDescriptors();
64 if (queryResult == OK) {
65 *pNumEffects = mLastDescriptors.size();
66 }
67 return queryResult;
68}
69
70status_t EffectsFactoryHalHidl::getDescriptor(
71 uint32_t index, effect_descriptor_t *pDescriptor) {
72 // TODO: We need somehow to track the changes on the server side
73 // or figure out how to convert everybody to query all the descriptors at once.
74 // TODO: check for nullptr
75 if (mLastDescriptors.size() == 0) {
76 status_t queryResult = queryAllDescriptors();
77 if (queryResult != OK) return queryResult;
78 }
79 if (index >= mLastDescriptors.size()) return NAME_NOT_FOUND;
80 EffectHalHidl::effectDescriptorToHal(mLastDescriptors[index], pDescriptor);
81 return OK;
82}
83
84status_t EffectsFactoryHalHidl::getDescriptor(
85 const effect_uuid_t *pEffectUuid, effect_descriptor_t *pDescriptor) {
86 // TODO: check for nullptr
87 if (mEffectsFactory == 0) return NO_INIT;
88 Uuid hidlUuid;
89 HidlUtils::uuidFromHal(*pEffectUuid, &hidlUuid);
90 Result retval = Result::NOT_INITIALIZED;
91 Return<void> ret = mEffectsFactory->getDescriptor(hidlUuid,
92 [&](Result r, const EffectDescriptor& result) {
93 retval = r;
94 if (retval == Result::OK) {
95 EffectHalHidl::effectDescriptorToHal(result, pDescriptor);
96 }
97 });
98 if (ret.isOk()) {
99 if (retval == Result::OK) return OK;
100 else if (retval == Result::INVALID_ARGUMENTS) return NAME_NOT_FOUND;
101 else return NO_INIT;
102 }
103 return processReturn(__FUNCTION__, ret);
104}
105
106status_t EffectsFactoryHalHidl::createEffect(
107 const effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t ioId,
108 sp<EffectHalInterface> *effect) {
109 if (mEffectsFactory == 0) return NO_INIT;
110 Uuid hidlUuid;
111 HidlUtils::uuidFromHal(*pEffectUuid, &hidlUuid);
112 Result retval = Result::NOT_INITIALIZED;
113 Return<void> ret = mEffectsFactory->createEffect(
114 hidlUuid, sessionId, ioId,
115 [&](Result r, const sp<IEffect>& result, uint64_t effectId) {
116 retval = r;
117 if (retval == Result::OK) {
118 *effect = new EffectHalHidl(result, effectId);
119 }
120 });
121 if (ret.isOk()) {
122 if (retval == Result::OK) return OK;
123 else if (retval == Result::INVALID_ARGUMENTS) return NAME_NOT_FOUND;
124 else return NO_INIT;
125 }
126 return processReturn(__FUNCTION__, ret);
127}
128
129status_t EffectsFactoryHalHidl::dumpEffects(int fd) {
130 if (mEffectsFactory == 0) return NO_INIT;
131 native_handle_t* hidlHandle = native_handle_create(1, 0);
132 hidlHandle->data[0] = fd;
Kevin Rocard4a7484bd2018-02-23 19:11:06 -0800133 Return<void> ret = mEffectsFactory->debug(hidlHandle, {} /* options */);
Kevin Rocardd4de2882018-02-28 14:33:38 -0800134 native_handle_delete(hidlHandle);
135 return processReturn(__FUNCTION__, ret);
136}
137
138status_t EffectsFactoryHalHidl::allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) {
139 return EffectBufferHalHidl::allocate(size, buffer);
140}
141
142status_t EffectsFactoryHalHidl::mirrorBuffer(void* external, size_t size,
143 sp<EffectBufferHalInterface>* buffer) {
144 return EffectBufferHalHidl::mirror(external, size, buffer);
145}
146
147
Kevin Rocard2390b5d2018-02-28 14:36:53 -0800148} // namespace V4_0
Kevin Rocardd4de2882018-02-28 14:33:38 -0800149} // namespace android