blob: 361f7b834d76acaa39b8f7182582bc218ad5beff [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
34status_t AudioVolumeGroup::readFromParcel(const Parcel *parcel)
35{
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080036 media::AudioVolumeGroup aidl;
37 RETURN_STATUS_IF_ERROR(aidl.readFromParcel(parcel));
38 *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioVolumeGroup(aidl));
39 return OK;
François Gaffie4b2018b2018-11-07 11:18:59 +010040}
41
42status_t AudioVolumeGroup::writeToParcel(Parcel *parcel) const
43{
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080044 media::AudioVolumeGroup aidl = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioVolumeGroup(*this));
45 return aidl.writeToParcel(parcel);
46}
47
48ConversionResult<media::AudioVolumeGroup>
49legacy2aidl_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
63ConversionResult<AudioVolumeGroup>
64aidl2legacy_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 );
François Gaffie4b2018b2018-11-07 11:18:59 +010075}
76
77} // namespace android