Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 <utility> |
| 18 | |
| 19 | #define LOG_TAG "AidlConversionNdk" |
| 20 | //#define LOG_NDEBUG 0 |
| 21 | #include <utils/Log.h> |
| 22 | |
| 23 | #include <media/AidlConversionCppNdk.h> |
| 24 | #include <media/AidlConversionNdk.h> |
| 25 | |
| 26 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 | // AIDL NDK backend to legacy audio data structure conversion utilities. |
| 28 | |
| 29 | namespace aidl { |
| 30 | namespace android { |
| 31 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 32 | // buffer_provider_t is not supported thus skipped |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 33 | ConversionResult<buffer_config_t> aidl2legacy_AudioConfigBase_buffer_config_t( |
| 34 | const media::audio::common::AudioConfigBase& aidl, bool isInput) { |
| 35 | buffer_config_t legacy; |
| 36 | |
| 37 | legacy.samplingRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate)); |
| 38 | legacy.mask |= EFFECT_CONFIG_SMP_RATE; |
| 39 | |
| 40 | legacy.channels = VALUE_OR_RETURN( |
| 41 | aidl2legacy_AudioChannelLayout_audio_channel_mask_t(aidl.channelMask, isInput)); |
| 42 | legacy.mask |= EFFECT_CONFIG_CHANNELS; |
| 43 | |
| 44 | legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormatDescription_audio_format_t(aidl.format)); |
| 45 | legacy.mask |= EFFECT_CONFIG_FORMAT; |
| 46 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 47 | // TODO: add accessMode and mask |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 48 | return legacy; |
| 49 | } |
| 50 | |
| 51 | ConversionResult<media::audio::common::AudioConfigBase> |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 52 | legacy2aidl_buffer_config_t_AudioConfigBase(const buffer_config_t& legacy, bool isInput) { |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 53 | media::audio::common::AudioConfigBase aidl; |
| 54 | |
| 55 | if (legacy.mask & EFFECT_CONFIG_SMP_RATE) { |
| 56 | aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.samplingRate)); |
| 57 | } |
| 58 | if (legacy.mask & EFFECT_CONFIG_CHANNELS) { |
| 59 | aidl.channelMask = VALUE_OR_RETURN(legacy2aidl_audio_channel_mask_t_AudioChannelLayout( |
| 60 | static_cast<audio_channel_mask_t>(legacy.channels), isInput)); |
| 61 | } |
| 62 | if (legacy.mask & EFFECT_CONFIG_FORMAT) { |
| 63 | aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormatDescription( |
| 64 | static_cast<audio_format_t>(legacy.format))); |
| 65 | } |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 66 | |
| 67 | // TODO: add accessMode and mask |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 68 | return aidl; |
| 69 | } |
| 70 | |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 71 | } // namespace android |
| 72 | } // aidl |