1dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie/* 2dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * Copyright (C) 2015 The Android Open Source Project 3dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * 4dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * Licensed under the Apache License, Version 2.0 (the "License"); 5dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * you may not use this file except in compliance with the License. 6dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * You may obtain a copy of the License at 7dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * 8dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * http://www.apache.org/licenses/LICENSE-2.0 9dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * 10dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * Unless required by applicable law or agreed to in writing, software 11dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * distributed under the License is distributed on an "AS IS" BASIS, 12dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * See the License for the specific language governing permissions and 14dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * limitations under the License. 15dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie */ 16dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 17dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie#pragma once 18dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 19d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie#include "IVolumeCurvesCollection.h" 20dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie#include <utils/KeyedVector.h> 21dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie#include <utils/StrongPointer.h> 22dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie#include <utils/SortedVector.h> 23dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie#include <hardware/audio.h> 24dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 25dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffienamespace android { 26dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 27dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie// stream descriptor used for volume control 28dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffieclass StreamDescriptor 29dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie{ 30dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffiepublic: 31dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie StreamDescriptor(); 32dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 33dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie int getVolumeIndex(audio_devices_t device) const; 34dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie bool canBeMuted() const { return mCanBeMuted; } 35dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie void clearCurrentVolumeIndex(); 36dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie void addCurrentVolumeIndex(audio_devices_t device, int index); 37dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie int getVolumeIndexMin() const { return mIndexMin; } 38dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie int getVolumeIndexMax() const { return mIndexMax; } 39dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie void setVolumeIndexMin(int volIndexMin); 40dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie void setVolumeIndexMax(int volIndexMax); 411fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent bool hasVolumeIndexForDevice(audio_devices_t device) const 421fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent { 431fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent device = Volume::getDeviceForVolume(device); 441fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent return mIndexCur.indexOfKey(device) >= 0; 451fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent } 46dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 47dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie void dump(int fd) const; 48dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 49d0609ad390ff8bb1cafebdf363bf1d15e63b949fFrançois Gaffie void setVolumeCurvePoint(device_category deviceCategory, const VolumeCurvePoint *point); 50d0609ad390ff8bb1cafebdf363bf1d15e63b949fFrançois Gaffie const VolumeCurvePoint *getVolumeCurvePoint(device_category deviceCategory) const 51dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie { 52dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie return mVolumeCurve[deviceCategory]; 53dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie } 54dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 55dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffieprivate: 56d0609ad390ff8bb1cafebdf363bf1d15e63b949fFrançois Gaffie const VolumeCurvePoint *mVolumeCurve[DEVICE_CATEGORY_CNT]; 57dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie KeyedVector<audio_devices_t, int> mIndexCur; /**< current volume index per device. */ 58dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie int mIndexMin; /**< min volume index. */ 59dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie int mIndexMax; /**< max volume index. */ 60dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie bool mCanBeMuted; /**< true is the stream can be muted. */ 61dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie}; 62dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 63dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie/** 64dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie * stream descriptors collection for volume control 65dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie */ 66d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffieclass StreamDescriptorCollection : public DefaultKeyedVector<audio_stream_type_t, StreamDescriptor>, 67d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie public IVolumeCurvesCollection 68dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie{ 69dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffiepublic: 70dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie StreamDescriptorCollection(); 71dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 72d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual void clearCurrentVolumeIndex(audio_stream_type_t stream); 73d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual void addCurrentVolumeIndex(audio_stream_type_t stream, audio_devices_t device, 74d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie int index); 75d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual bool canBeMuted(audio_stream_type_t stream); 76d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual int getVolumeIndexMin(audio_stream_type_t stream) const 77d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie { 78d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie return valueFor(stream).getVolumeIndexMin(); 79d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie } 80d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual int getVolumeIndex(audio_stream_type_t stream, audio_devices_t device) 81d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie { 82d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie return valueFor(stream).getVolumeIndex(device); 83d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie } 84d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual int getVolumeIndexMax(audio_stream_type_t stream) const 85d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie { 86d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie return valueFor(stream).getVolumeIndexMax(); 87d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie } 88d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual float volIndexToDb(audio_stream_type_t stream, device_category device, 89d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie int indexInUi) const; 90d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual status_t initStreamVolume(audio_stream_type_t stream, int indexMin, int indexMax); 91d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual void initializeVolumeCurves(bool isSpeakerDrcEnabled); 92d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual void switchVolumeCurve(audio_stream_type_t streamSrc, audio_stream_type_t streamDst); 931fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent virtual bool hasVolumeIndexForDevice(audio_stream_type_t stream, 941fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent audio_devices_t device) const 951fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent { 961fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent return valueFor(stream).hasVolumeIndexForDevice(device); 971fd372e40ef40643fa9d036a0c9db043475b1b02Eric Laurent } 98dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 99d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie virtual status_t dump(int fd) const; 100dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 101d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffieprivate: 102d1ab2bd4f1ea166a7e9e81cfd7f3e5dd47135d4dFrançois Gaffie void setVolumeCurvePoint(audio_stream_type_t stream, device_category deviceCategory, 103dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie const VolumeCurvePoint *point); 104dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie const VolumeCurvePoint *getVolumeCurvePoint(audio_stream_type_t stream, 105d0609ad390ff8bb1cafebdf363bf1d15e63b949fFrançois Gaffie device_category deviceCategory) const; 106dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie void setVolumeIndexMin(audio_stream_type_t stream,int volIndexMin); 107dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie void setVolumeIndexMax(audio_stream_type_t stream,int volIndexMax); 108dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie}; 109dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie 110dfd7409c1b708f6c429aa43722ca8493a91d8df0François Gaffie}; // namespace android 111