blob: e79a362f9f3d0343fd7e7fa768d22144433eca32 [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
24#include <media/AudioVolumeGroup.h>
25#include <media/AudioAttributes.h>
26
27namespace android {
28
29status_t AudioVolumeGroup::readFromParcel(const Parcel *parcel)
30{
31 status_t ret = parcel->readUtf8FromUtf16(&mName);
32 if (ret != NO_ERROR) {
33 return ret;
34 }
35 mGroupId = static_cast<volume_group_t>(parcel->readInt32());
36 size_t size = static_cast<size_t>(parcel->readInt32());
37 for (size_t i = 0; i < size; i++) {
38 AudioAttributes attribute;
39 attribute.readFromParcel(parcel);
40 if (ret != NO_ERROR) {
41 mAudioAttributes.clear();
42 return ret;
43 }
44 mAudioAttributes.push_back(attribute.getAttributes());
45 }
46 size = static_cast<size_t>(parcel->readInt32());
47 for (size_t i = 0; i < size; i++) {
48 audio_stream_type_t stream = static_cast<audio_stream_type_t>(parcel->readInt32());
49 mStreams.push_back(stream);
50 }
51 return NO_ERROR;
52}
53
54status_t AudioVolumeGroup::writeToParcel(Parcel *parcel) const
55{
56 parcel->writeUtf8AsUtf16(mName);
57 parcel->writeInt32(static_cast<int32_t>(mGroupId));
58 size_t size = mAudioAttributes.size();
59 size_t sizePosition = parcel->dataPosition();
60 parcel->writeInt32(size);
61 size_t finalSize = size;
62 for (const auto &attributes : mAudioAttributes) {
63 size_t position = parcel->dataPosition();
64 AudioAttributes attribute(attributes);
65 status_t ret = attribute.writeToParcel(parcel);
66 if (ret != NO_ERROR) {
67 parcel->setDataPosition(position);
68 finalSize--;
69 }
70 }
71 if (size != finalSize) {
72 size_t position = parcel->dataPosition();
73 parcel->setDataPosition(sizePosition);
74 parcel->writeInt32(finalSize);
75 parcel->setDataPosition(position);
76 }
77 parcel->writeInt32(mStreams.size());
78 for (const auto &stream : mStreams) {
79 parcel->writeInt32(static_cast<int32_t>(stream));
80 }
81 return NO_ERROR;
82}
83
84} // namespace android