blob: 36696cdedc11f7eabd9c616f7a677536ed52e856 [file] [log] [blame]
François Gaffie4b2018b2018-11-07 11:18:59 +01001/*
2 * Copyright (C) 2018 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#define LOG_TAG "AudioVolumeGroup"
18
19//#define LOG_NDEBUG 0
20
21#include <utils/Log.h>
22#include <binder/Parcel.h>
23
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080024#include <media/AidlConversion.h>
François Gaffie4b2018b2018-11-07 11:18:59 +010025#include <media/AudioVolumeGroup.h>
26#include <media/AudioAttributes.h>
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080027#include <media/PolicyAidlConversion.h>
28
29#define RETURN_STATUS_IF_ERROR(x) \
30 { auto _tmp = (x); if (_tmp != OK) return _tmp; }
François Gaffie4b2018b2018-11-07 11:18:59 +010031
32namespace android {
33
Mikhail Naganovdbf03642021-08-25 18:15:32 -070034using media::audio::common::AudioStreamType;
35
François Gaffie4b2018b2018-11-07 11:18:59 +010036status_t AudioVolumeGroup::readFromParcel(const Parcel *parcel)
37{
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080038 media::AudioVolumeGroup aidl;
39 RETURN_STATUS_IF_ERROR(aidl.readFromParcel(parcel));
40 *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioVolumeGroup(aidl));
41 return OK;
François Gaffie4b2018b2018-11-07 11:18:59 +010042}
43
44status_t AudioVolumeGroup::writeToParcel(Parcel *parcel) const
45{
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080046 media::AudioVolumeGroup aidl = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioVolumeGroup(*this));
47 return aidl.writeToParcel(parcel);
48}
49
50ConversionResult<media::AudioVolumeGroup>
51legacy2aidl_AudioVolumeGroup(const AudioVolumeGroup& legacy) {
52 media::AudioVolumeGroup aidl;
53 aidl.groupId = VALUE_OR_RETURN(legacy2aidl_volume_group_t_int32_t(legacy.getId()));
54 aidl.name = legacy.getName();
55 aidl.audioAttributes = VALUE_OR_RETURN(
56 convertContainer<std::vector<media::AudioAttributesInternal>>(
57 legacy.getAudioAttributes(),
58 legacy2aidl_audio_attributes_t_AudioAttributesInternal));
59 aidl.streams = VALUE_OR_RETURN(
Mikhail Naganovdbf03642021-08-25 18:15:32 -070060 convertContainer<std::vector<AudioStreamType>>(legacy.getStreamTypes(),
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080061 legacy2aidl_audio_stream_type_t_AudioStreamType));
62 return aidl;
63}
64
65ConversionResult<AudioVolumeGroup>
66aidl2legacy_AudioVolumeGroup(const media::AudioVolumeGroup& aidl) {
67 return AudioVolumeGroup(
68 aidl.name,
69 VALUE_OR_RETURN(aidl2legacy_int32_t_volume_group_t(aidl.groupId)),
70 VALUE_OR_RETURN(convertContainer<AttributesVector>(
71 aidl.audioAttributes,
72 aidl2legacy_AudioAttributesInternal_audio_attributes_t)),
73 VALUE_OR_RETURN(convertContainer<StreamTypeVector>(
74 aidl.streams,
75 aidl2legacy_AudioStreamType_audio_stream_type_t))
76 );
François Gaffie4b2018b2018-11-07 11:18:59 +010077}
78
79} // namespace android