blob: 4e609ca4fd53773e03a4d925cd1077504d3f3ca0 [file] [log] [blame]
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -08001/*
Kevin Rocard96d2cd92018-11-14 16:22:07 -08002 * Copyright (C) 2018 The Android Open Source Project
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -08003 *
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
Kevin Rocard96d2cd92018-11-14 16:22:07 -080017#ifndef android_hardware_audio_Hidl_Utils_H_
18#define android_hardware_audio_Hidl_Utils_H_
19
20#include PATH(android/hardware/audio/common/FILE_VERSION/types.h)
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080021
22#include <memory>
23
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080024#include <system/audio.h>
25
Kevin Rocard55b10612018-11-12 12:33:16 -080026using ::android::hardware::hidl_vec;
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080027
28namespace android {
Kevin Rocard6891d7e2017-12-14 18:39:39 -080029namespace hardware {
30namespace audio {
31namespace common {
Kevin Rocard96d2cd92018-11-14 16:22:07 -080032namespace CPP_VERSION {
Mikhail Naganov543bf9c2018-12-11 16:36:53 -080033namespace implementation {
34
35using namespace ::android::hardware::audio::common::CPP_VERSION;
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080036
Mikhail Naganov1b444a52020-10-29 13:08:05 -070037struct HidlUtils {
38#if MAJOR_VERSION < 7
Andy Hung7aab1012020-02-14 15:39:55 -080039 static status_t audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config);
Kevin Rocarddc874e02017-12-14 18:50:12 -080040 static void audioGainConfigFromHal(const struct audio_gain_config& halConfig,
41 AudioGainConfig* config);
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080042 static void audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain);
Mikhail Naganov1b444a52020-10-29 13:08:05 -070043#else
44 static status_t audioConfigFromHal(const audio_config_t& halConfig, bool isInput,
45 AudioConfig* config);
46 static status_t audioGainConfigFromHal(const struct audio_gain_config& halConfig, bool isInput,
47 AudioGainConfig* config);
48 static status_t audioGainFromHal(const struct audio_gain& halGain, bool isInput,
49 AudioGain* gain);
50#endif
51 static status_t audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig);
52 static status_t audioGainConfigToHal(const AudioGainConfig& config,
53 struct audio_gain_config* halConfig);
54 static status_t audioGainToHal(const AudioGain& gain, struct audio_gain* halGain);
55 static status_t audioUsageFromHal(audio_usage_t halUsage, AudioUsage* usage);
56 static status_t audioUsageToHal(const AudioUsage& usage, audio_usage_t* halUsage);
Andy Hung7aab1012020-02-14 15:39:55 -080057 static status_t audioOffloadInfoFromHal(const audio_offload_info_t& halOffload,
58 AudioOffloadInfo* offload);
Mikhail Naganov1b444a52020-10-29 13:08:05 -070059 static status_t audioOffloadInfoToHal(const AudioOffloadInfo& offload,
60 audio_offload_info_t* halOffload);
61 static status_t audioPortConfigFromHal(const struct audio_port_config& halConfig,
62 AudioPortConfig* config);
63 static status_t audioPortConfigToHal(const AudioPortConfig& config,
64 struct audio_port_config* halConfig);
65 static status_t audioPortConfigsFromHal(unsigned int numHalConfigs,
66 const struct audio_port_config* halConfigs,
67 hidl_vec<AudioPortConfig>* configs) {
68 status_t result = NO_ERROR;
69 configs->resize(numHalConfigs);
70 for (unsigned int i = 0; i < numHalConfigs; ++i) {
71 if (status_t status = audioPortConfigFromHal(halConfigs[i], &(*configs)[i]);
72 status != NO_ERROR) {
73 result = status;
74 }
75 }
76 return result;
77 }
78 static status_t audioPortConfigsToHal(const hidl_vec<AudioPortConfig>& configs,
79 std::unique_ptr<audio_port_config[]>* halConfigs) {
80 status_t result = NO_ERROR;
81 halConfigs->reset(new audio_port_config[configs.size()]);
82 for (size_t i = 0; i < configs.size(); ++i) {
83 if (status_t status = audioPortConfigToHal(configs[i], &(*halConfigs)[i]);
84 status != NO_ERROR) {
85 result = status;
86 }
87 }
88 return result;
89 }
90
91 // PLEASE DO NOT USE, will be removed in a couple of days
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080092 static std::unique_ptr<audio_port_config[]> audioPortConfigsToHal(
Mikhail Naganov1b444a52020-10-29 13:08:05 -070093 const hidl_vec<AudioPortConfig>& configs) {
94 std::unique_ptr<audio_port_config[]> halConfigs;
95 (void)audioPortConfigsToHal(configs, &halConfigs);
96 return halConfigs;
97 }
98
99 static status_t audioPortFromHal(const struct audio_port& halPort, AudioPort* port);
100 static status_t audioPortToHal(const AudioPort& port, struct audio_port* halPort);
101#if MAJOR_VERSION >= 7
102 static status_t audioChannelMaskFromHal(audio_channel_mask_t halChannelMask, bool isInput,
103 AudioChannelMask* channelMask);
104 static status_t audioChannelMaskToHal(const AudioChannelMask& channelMask,
105 audio_channel_mask_t* halChannelMask);
106 static status_t audioConfigBaseFromHal(const audio_config_base_t& halConfigBase, bool isInput,
107 AudioConfigBase* configBase);
108 static status_t audioConfigBaseToHal(const AudioConfigBase& configBase,
109 audio_config_base_t* halConfigBase);
110 static status_t audioDeviceTypeFromHal(audio_devices_t halDevice, AudioDevice* device);
111 static status_t audioDeviceTypeToHal(const AudioDevice& device, audio_devices_t* halDevice);
112 static status_t audioFormatFromHal(audio_format_t halFormat, AudioFormat* format);
113 static status_t audioFormatToHal(const AudioFormat& format, audio_format_t* halFormat);
114 static status_t audioGainModeMaskFromHal(audio_gain_mode_t halGainModeMask,
115 hidl_vec<AudioGainMode>* gainModeMask);
116 static status_t audioGainModeMaskToHal(const hidl_vec<AudioGainMode>& gainModeMask,
117 audio_gain_mode_t* halGainModeMask);
118 static status_t audioPortFromHal(const struct audio_port_v7& halPort, AudioPort* port);
119 static status_t audioPortToHal(const AudioPort& port, struct audio_port_v7* halPort);
120 static status_t audioProfileFromHal(const struct audio_profile& halProfile, bool isInput,
121 AudioProfile* profile);
122 static status_t audioProfileToHal(const AudioProfile& profile,
123 struct audio_profile* halProfile);
124 static status_t audioSourceFromHal(audio_source_t halSource, AudioSource* source);
125 static status_t audioSourceToHal(const AudioSource& source, audio_source_t* halSource);
126 static status_t audioStreamTypeFromHal(audio_stream_type_t halStreamType,
127 AudioStreamType* streamType);
128 static status_t audioStreamTypeToHal(const AudioStreamType& streamType,
129 audio_stream_type_t* halStreamType);
130 static status_t deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType,
131 char* halDeviceAddress);
132 static status_t deviceAddressFromHal(audio_devices_t halDeviceType,
133 const char* halDeviceAddress, DeviceAddress* device);
134
135 private:
136 static status_t audioIndexChannelMaskFromHal(audio_channel_mask_t halChannelMask,
137 AudioChannelMask* channelMask);
138 static status_t audioInputChannelMaskFromHal(audio_channel_mask_t halChannelMask,
139 AudioChannelMask* channelMask);
140 static status_t audioOutputChannelMaskFromHal(audio_channel_mask_t halChannelMask,
141 AudioChannelMask* channelMask);
142 static status_t audioPortExtendedInfoFromHal(
143 audio_port_role_t role, audio_port_type_t type,
144 const struct audio_port_config_device_ext& device,
145 const struct audio_port_config_mix_ext& mix,
146 const struct audio_port_config_session_ext& session, AudioPortExtendedInfo* ext,
147 bool* isInput);
148 static status_t audioPortExtendedInfoToHal(const AudioPortExtendedInfo& ext,
149 audio_port_role_t* role, audio_port_type_t* type,
150 struct audio_port_config_device_ext* device,
151 struct audio_port_config_mix_ext* mix,
152 struct audio_port_config_session_ext* session);
153#endif
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -0800154};
155
Mikhail Naganov543bf9c2018-12-11 16:36:53 -0800156} // namespace implementation
Kevin Rocard96d2cd92018-11-14 16:22:07 -0800157} // namespace CPP_VERSION
Kevin Rocard6891d7e2017-12-14 18:39:39 -0800158} // namespace common
159} // namespace audio
160} // namespace hardware
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -0800161} // namespace android
Kevin Rocard96d2cd92018-11-14 16:22:07 -0800162
163#endif // android_hardware_audio_Hidl_Utils_H_