1 /*
2 * Copyright (C) 2020 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 #include "HidlUtils.h"
18
19 namespace android {
20 namespace hardware {
21 namespace audio {
22 namespace common {
23 namespace CPP_VERSION {
24 namespace implementation {
25
audioPortConfigsFromHal(unsigned int numHalConfigs,const struct audio_port_config * halConfigs,hidl_vec<AudioPortConfig> * configs)26 status_t HidlUtils::audioPortConfigsFromHal(unsigned int numHalConfigs,
27 const struct audio_port_config* halConfigs,
28 hidl_vec<AudioPortConfig>* configs) {
29 status_t result = NO_ERROR;
30 configs->resize(numHalConfigs);
31 for (unsigned int i = 0; i < numHalConfigs; ++i) {
32 if (status_t status = audioPortConfigFromHal(halConfigs[i], &(*configs)[i]);
33 status != NO_ERROR) {
34 result = status;
35 }
36 }
37 return result;
38 }
39
audioPortConfigsToHal(const hidl_vec<AudioPortConfig> & configs,std::unique_ptr<audio_port_config[]> * halConfigs)40 status_t HidlUtils::audioPortConfigsToHal(const hidl_vec<AudioPortConfig>& configs,
41 std::unique_ptr<audio_port_config[]>* halConfigs) {
42 status_t result = NO_ERROR;
43 halConfigs->reset(new audio_port_config[configs.size()]);
44 for (size_t i = 0; i < configs.size(); ++i) {
45 if (status_t status = audioPortConfigToHal(configs[i], &(*halConfigs)[i]);
46 status != NO_ERROR) {
47 result = status;
48 }
49 }
50 return result;
51 }
52
53 } // namespace implementation
54 } // namespace CPP_VERSION
55 } // namespace common
56 } // namespace audio
57 } // namespace hardware
58 } // namespace android
59