1 // Copyright (C) 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "HidlTypeUtil.h"
16 
17 #include <error.h>
18 
19 using ::android::hardware::hidl_bitfield;
20 
21 namespace audio_proxy {
22 namespace CPP_VERSION {
23 
toResult(int res)24 Result toResult(int res) {
25   switch (res) {
26     case 0:
27       return Result::OK;
28     case EINVAL:
29       return Result::INVALID_ARGUMENTS;
30     case ENOSYS:
31       return Result::NOT_SUPPORTED;
32     default:
33       return Result::INVALID_STATE;
34   }
35 }
36 
toHidlAudioConfig(const audio_proxy_config_t & config)37 AudioConfig toHidlAudioConfig(const audio_proxy_config_t& config) {
38   AudioConfig hidlConfig;
39   hidlConfig.sampleRateHz = config.sample_rate;
40   hidlConfig.channelMask = hidl_bitfield<AudioChannelMask>(config.channel_mask);
41   hidlConfig.format = AudioFormat(config.format);
42   hidlConfig.frameCount = config.frame_count;
43   return hidlConfig;
44 }
45 
toAudioProxyConfig(const AudioConfig & hidlConfig)46 audio_proxy_config_t toAudioProxyConfig(const AudioConfig& hidlConfig) {
47   audio_proxy_config_t config = {};
48   config.sample_rate = hidlConfig.sampleRateHz;
49   config.channel_mask =
50       static_cast<audio_proxy_channel_mask_t>(hidlConfig.channelMask);
51   config.format = static_cast<audio_proxy_format_t>(hidlConfig.format);
52   config.frame_count = hidlConfig.frameCount;
53   return config;
54 }
55 
56 }  // namespace CPP_VERSION
57 }  // namespace audio_proxy