1 /*
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 
24 #include <media/AidlConversion.h>
25 #include <media/AudioVolumeGroup.h>
26 #include <media/PolicyAidlConversion.h>
27 
28 namespace android {
29 
30 using media::audio::common::AudioStreamType;
31 
readFromParcel(const Parcel * parcel)32 status_t AudioVolumeGroup::readFromParcel(const Parcel *parcel)
33 {
34     media::AudioVolumeGroup aidl;
35     RETURN_STATUS_IF_ERROR(aidl.readFromParcel(parcel));
36     *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioVolumeGroup(aidl));
37     return OK;
38 }
39 
writeToParcel(Parcel * parcel) const40 status_t AudioVolumeGroup::writeToParcel(Parcel *parcel) const
41 {
42     media::AudioVolumeGroup aidl = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioVolumeGroup(*this));
43     return aidl.writeToParcel(parcel);
44 }
45 
46 ConversionResult<media::AudioVolumeGroup>
legacy2aidl_AudioVolumeGroup(const AudioVolumeGroup & legacy)47 legacy2aidl_AudioVolumeGroup(const AudioVolumeGroup& legacy) {
48     media::AudioVolumeGroup aidl;
49     aidl.groupId = VALUE_OR_RETURN(legacy2aidl_volume_group_t_int32_t(legacy.getId()));
50     aidl.name = legacy.getName();
51     aidl.audioAttributes = VALUE_OR_RETURN(
52             convertContainer<std::vector<media::audio::common::AudioAttributes>>(
53                     legacy.getAudioAttributes(),
54                     legacy2aidl_audio_attributes_t_AudioAttributes));
55     aidl.streams = VALUE_OR_RETURN(
56             convertContainer<std::vector<AudioStreamType>>(legacy.getStreamTypes(),
57             legacy2aidl_audio_stream_type_t_AudioStreamType));
58     return aidl;
59 }
60 
61 ConversionResult<AudioVolumeGroup>
aidl2legacy_AudioVolumeGroup(const media::AudioVolumeGroup & aidl)62 aidl2legacy_AudioVolumeGroup(const media::AudioVolumeGroup& aidl) {
63     return AudioVolumeGroup(
64             aidl.name,
65             VALUE_OR_RETURN(aidl2legacy_int32_t_volume_group_t(aidl.groupId)),
66             VALUE_OR_RETURN(convertContainer<AttributesVector>(
67                     aidl.audioAttributes,
68                     aidl2legacy_AudioAttributes_audio_attributes_t)),
69             VALUE_OR_RETURN(convertContainer<StreamTypeVector>(
70                     aidl.streams,
71                     aidl2legacy_AudioStreamType_audio_stream_type_t))
72     );
73 }
74 
75 } // namespace android
76