• 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 #define RETURN_STATUS_IF_ERROR(x) \
30     { auto _tmp = (x); if (_tmp != OK) return _tmp; }
31 
32 namespace android {
33 
readFromParcel(const Parcel * parcel)34 status_t AudioVolumeGroup::readFromParcel(const Parcel *parcel)
35 {
36     media::AudioVolumeGroup aidl;
37     RETURN_STATUS_IF_ERROR(aidl.readFromParcel(parcel));
38     *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioVolumeGroup(aidl));
39     return OK;
40 }
41 
writeToParcel(Parcel * parcel) const42 status_t AudioVolumeGroup::writeToParcel(Parcel *parcel) const
43 {
44     media::AudioVolumeGroup aidl = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioVolumeGroup(*this));
45     return aidl.writeToParcel(parcel);
46 }
47 
48 ConversionResult<media::AudioVolumeGroup>
legacy2aidl_AudioVolumeGroup(const AudioVolumeGroup & legacy)49 legacy2aidl_AudioVolumeGroup(const AudioVolumeGroup& legacy) {
50     media::AudioVolumeGroup aidl;
51     aidl.groupId = VALUE_OR_RETURN(legacy2aidl_volume_group_t_int32_t(legacy.getId()));
52     aidl.name = legacy.getName();
53     aidl.audioAttributes = VALUE_OR_RETURN(
54             convertContainer<std::vector<media::AudioAttributesInternal>>(
55                     legacy.getAudioAttributes(),
56                     legacy2aidl_audio_attributes_t_AudioAttributesInternal));
57     aidl.streams = VALUE_OR_RETURN(
58             convertContainer<std::vector<media::AudioStreamType>>(legacy.getStreamTypes(),
59             legacy2aidl_audio_stream_type_t_AudioStreamType));
60     return aidl;
61 }
62 
63 ConversionResult<AudioVolumeGroup>
aidl2legacy_AudioVolumeGroup(const media::AudioVolumeGroup & aidl)64 aidl2legacy_AudioVolumeGroup(const media::AudioVolumeGroup& aidl) {
65     return AudioVolumeGroup(
66             aidl.name,
67             VALUE_OR_RETURN(aidl2legacy_int32_t_volume_group_t(aidl.groupId)),
68             VALUE_OR_RETURN(convertContainer<AttributesVector>(
69                     aidl.audioAttributes,
70                     aidl2legacy_AudioAttributesInternal_audio_attributes_t)),
71             VALUE_OR_RETURN(convertContainer<StreamTypeVector>(
72                     aidl.streams,
73                     aidl2legacy_AudioStreamType_audio_stream_type_t))
74     );
75 }
76 
77 } // namespace android
78