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