blob: 7c63339318b23d08fee7493e2e40af8ba9106c13 [file] [log] [blame]
Shunkai Yao51202502022-12-12 06:11:46 +00001/*
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
29namespace aidl {
30namespace android {
31
Shunkai Yao44bdbad2023-01-14 05:11:58 +000032// buffer_provider_t is not supported thus skipped
Shunkai Yao51202502022-12-12 06:11:46 +000033ConversionResult<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 Yao44bdbad2023-01-14 05:11:58 +000047 // TODO: add accessMode and mask
Shunkai Yao51202502022-12-12 06:11:46 +000048 return legacy;
49}
50
51ConversionResult<media::audio::common::AudioConfigBase>
Shunkai Yao284bb0d2023-01-10 00:42:36 +000052legacy2aidl_buffer_config_t_AudioConfigBase(const buffer_config_t& legacy, bool isInput) {
Shunkai Yao51202502022-12-12 06:11:46 +000053 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 Yao44bdbad2023-01-14 05:11:58 +000066
67 // TODO: add accessMode and mask
Shunkai Yao51202502022-12-12 06:11:46 +000068 return aidl;
69}
70
Shunkai Yao51202502022-12-12 06:11:46 +000071} // namespace android
72} // aidl