blob: ab95246150e0b4f96d9e82c1e3c52baa32fb4178 [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
François Gaffie4b2018b2018-11-07 11:18:59 +010029namespace android {
30
Mikhail Naganovdbf03642021-08-25 18:15:32 -070031using media::audio::common::AudioStreamType;
32
François Gaffie4b2018b2018-11-07 11:18:59 +010033status_t AudioVolumeGroup::readFromParcel(const Parcel *parcel)
34{
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080035 media::AudioVolumeGroup aidl;
36 RETURN_STATUS_IF_ERROR(aidl.readFromParcel(parcel));
37 *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioVolumeGroup(aidl));
38 return OK;
François Gaffie4b2018b2018-11-07 11:18:59 +010039}
40
41status_t AudioVolumeGroup::writeToParcel(Parcel *parcel) const
42{
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080043 media::AudioVolumeGroup aidl = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioVolumeGroup(*this));
44 return aidl.writeToParcel(parcel);
45}
46
47ConversionResult<media::AudioVolumeGroup>
48legacy2aidl_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(
Mikhail Naganovdbf03642021-08-25 18:15:32 -070057 convertContainer<std::vector<AudioStreamType>>(legacy.getStreamTypes(),
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080058 legacy2aidl_audio_stream_type_t_AudioStreamType));
59 return aidl;
60}
61
62ConversionResult<AudioVolumeGroup>
63aidl2legacy_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 );
François Gaffie4b2018b2018-11-07 11:18:59 +010074}
75
76} // namespace android