blob: c4ca5b9bffbdeeccdb73c6255dd19272a0874765 [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>
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080026#include <media/PolicyAidlConversion.h>
27
François Gaffie4b2018b2018-11-07 11:18:59 +010028namespace android {
29
Mikhail Naganovdbf03642021-08-25 18:15:32 -070030using media::audio::common::AudioStreamType;
31
François Gaffie4b2018b2018-11-07 11:18:59 +010032status_t AudioVolumeGroup::readFromParcel(const Parcel *parcel)
33{
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080034 media::AudioVolumeGroup aidl;
35 RETURN_STATUS_IF_ERROR(aidl.readFromParcel(parcel));
36 *this = VALUE_OR_RETURN_STATUS(aidl2legacy_AudioVolumeGroup(aidl));
37 return OK;
François Gaffie4b2018b2018-11-07 11:18:59 +010038}
39
40status_t AudioVolumeGroup::writeToParcel(Parcel *parcel) const
41{
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080042 media::AudioVolumeGroup aidl = VALUE_OR_RETURN_STATUS(legacy2aidl_AudioVolumeGroup(*this));
43 return aidl.writeToParcel(parcel);
44}
45
46ConversionResult<media::AudioVolumeGroup>
47legacy2aidl_AudioVolumeGroup(const AudioVolumeGroup& legacy) {
48 media::AudioVolumeGroup aidl;
49 aidl.groupId = VALUE_OR_RETURN(legacy2aidl_volume_group_t_int32_t(legacy.getId()));
50 aidl.name = legacy.getName();
51 aidl.audioAttributes = VALUE_OR_RETURN(
Mikhail Naganov1c400902023-05-17 11:48:43 -070052 convertContainer<std::vector<media::audio::common::AudioAttributes>>(
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080053 legacy.getAudioAttributes(),
Mikhail Naganov1c400902023-05-17 11:48:43 -070054 legacy2aidl_audio_attributes_t_AudioAttributes));
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080055 aidl.streams = VALUE_OR_RETURN(
Mikhail Naganovdbf03642021-08-25 18:15:32 -070056 convertContainer<std::vector<AudioStreamType>>(legacy.getStreamTypes(),
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080057 legacy2aidl_audio_stream_type_t_AudioStreamType));
58 return aidl;
59}
60
61ConversionResult<AudioVolumeGroup>
62aidl2legacy_AudioVolumeGroup(const media::AudioVolumeGroup& aidl) {
63 return AudioVolumeGroup(
64 aidl.name,
65 VALUE_OR_RETURN(aidl2legacy_int32_t_volume_group_t(aidl.groupId)),
66 VALUE_OR_RETURN(convertContainer<AttributesVector>(
67 aidl.audioAttributes,
Mikhail Naganov1c400902023-05-17 11:48:43 -070068 aidl2legacy_AudioAttributes_audio_attributes_t)),
Ytai Ben-Tsvi0a4904a2021-01-06 12:57:05 -080069 VALUE_OR_RETURN(convertContainer<StreamTypeVector>(
70 aidl.streams,
71 aidl2legacy_AudioStreamType_audio_stream_type_t))
72 );
François Gaffie4b2018b2018-11-07 11:18:59 +010073}
74
75} // namespace android