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 18 #pragma once 19 20 #include <android/media/AudioAttributesEx.h> 21 #include <media/AudioCommonTypes.h> 22 #include <media/AidlConversionUtil.h> 23 #include <system/audio.h> 24 #include <system/audio_policy.h> 25 #include <binder/Parcelable.h> 26 27 namespace android { 28 29 class VolumeGroupAttributes : public Parcelable 30 { 31 public: 32 VolumeGroupAttributes() = default; VolumeGroupAttributes(const audio_attributes_t & attributes)33 VolumeGroupAttributes(const audio_attributes_t &attributes) 34 : mAttributes(attributes) {} // NOLINT VolumeGroupAttributes(volume_group_t groupId,audio_stream_type_t stream,const audio_attributes_t & attributes)35 VolumeGroupAttributes(volume_group_t groupId, 36 audio_stream_type_t stream, 37 const audio_attributes_t &attributes) : 38 mAttributes(attributes), mStreamType(stream), mGroupId(groupId) { 39 // TODO: align native & JAVA source initializer. 40 // As far as this class concerns attributes for volume group, it applies only to playback. 41 mAttributes.source = AUDIO_SOURCE_INVALID; 42 } 43 44 int matchesScore(const audio_attributes_t &attributes) const; 45 getAttributes()46 audio_attributes_t getAttributes() const { return mAttributes; } 47 48 status_t readFromParcel(const Parcel *parcel) override; 49 status_t writeToParcel(Parcel *parcel) const override; 50 getStreamType()51 audio_stream_type_t getStreamType() const { return mStreamType; } getGroupId()52 volume_group_t getGroupId() const { return mGroupId; } 53 54 private: 55 audio_attributes_t mAttributes = AUDIO_ATTRIBUTES_INITIALIZER; 56 /** 57 * @brief mStreamType: for legacy volume management, we need to be able to convert an attribute 58 * to a given stream type. 59 */ 60 audio_stream_type_t mStreamType = AUDIO_STREAM_DEFAULT; 61 62 /** 63 * @brief mGroupId: for future volume management, define groups within a strategy that follows 64 * the same curves of volume (extension of stream types to manage volume) 65 */ 66 volume_group_t mGroupId = VOLUME_GROUP_NONE; 67 }; 68 69 // AIDL conversion routines. 70 ConversionResult<media::AudioAttributesEx> 71 legacy2aidl_VolumeGroupAttributes_AudioAttributesEx(const VolumeGroupAttributes& legacy); 72 ConversionResult<VolumeGroupAttributes> 73 aidl2legacy_AudioAttributesEx_VolumeGroupAttributes(const media::AudioAttributesEx& aidl); 74 75 } // namespace android 76