• 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 "AudioAttributes"
18 //#define LOG_NDEBUG 0
19 #include <utils/Log.h>
20 
21 #include <binder/Parcel.h>
22 
23 #include <media/AidlConversion.h>
24 #include <media/AudioAttributes.h>
25 #include <media/PolicyAidlConversion.h>
26 
27 #define RETURN_STATUS_IF_ERROR(x) \
28     { auto _tmp = (x); if (_tmp != OK) return _tmp; }
29 
30 namespace android {
31 
readFromParcel(const Parcel * parcel)32 status_t AudioAttributes::readFromParcel(const Parcel* parcel) {
33     media::AudioAttributesEx aidl;
34     RETURN_STATUS_IF_ERROR(aidl.readFromParcel(parcel));
35     *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioAttributesEx_AudioAttributes(aidl));
36     return OK;
37 }
38 
writeToParcel(Parcel * parcel) const39 status_t AudioAttributes::writeToParcel(Parcel* parcel) const {
40     media::AudioAttributesEx aidl = VALUE_OR_RETURN_STATUS(
41             legacy2aidl_AudioAttributes_AudioAttributesEx(*this));
42     return aidl.writeToParcel(parcel);
43 }
44 
45 ConversionResult<media::AudioAttributesEx>
legacy2aidl_AudioAttributes_AudioAttributesEx(const AudioAttributes & legacy)46 legacy2aidl_AudioAttributes_AudioAttributesEx(const AudioAttributes& legacy) {
47     media::AudioAttributesEx aidl;
48     aidl.attributes = VALUE_OR_RETURN(
49             legacy2aidl_audio_attributes_t_AudioAttributesInternal(legacy.getAttributes()));
50     aidl.streamType = VALUE_OR_RETURN(
51             legacy2aidl_audio_stream_type_t_AudioStreamType(legacy.getStreamType()));
52     aidl.groupId = VALUE_OR_RETURN(legacy2aidl_volume_group_t_int32_t(legacy.getGroupId()));
53     return aidl;
54 }
55 
56 ConversionResult<AudioAttributes>
aidl2legacy_AudioAttributesEx_AudioAttributes(const media::AudioAttributesEx & aidl)57 aidl2legacy_AudioAttributesEx_AudioAttributes(const media::AudioAttributesEx& aidl) {
58     return AudioAttributes(VALUE_OR_RETURN(aidl2legacy_int32_t_volume_group_t(aidl.groupId)),
59                            VALUE_OR_RETURN(aidl2legacy_AudioStreamType_audio_stream_type_t(
60                                    aidl.streamType)),
61                            VALUE_OR_RETURN(aidl2legacy_AudioAttributesInternal_audio_attributes_t(
62                                    aidl.attributes)));
63 }
64 
65 } // namespace android
66