summaryrefslogtreecommitdiffstats
path: root/services/audiopolicy/common/include
diff options
context:
space:
mode:
authorFrançois Gaffie <francois.gaffie@intel.com>2015-03-19 12:10:59 +0100
committerJean-Michel Trivi <jmtrivi@google.com>2015-04-01 10:22:42 -0700
commitdfd7409c1b708f6c429aa43722ca8493a91d8df0 (patch)
tree527972dbd2a5ad014137b57128ca5100d7ca07a2 /services/audiopolicy/common/include
parentdf37269852ea92bafd939fe793209d0581c4a574 (diff)
downloadframeworks_av-dfd7409c1b708f6c429aa43722ca8493a91d8df0.zip
frameworks_av-dfd7409c1b708f6c429aa43722ca8493a91d8df0.tar.gz
frameworks_av-dfd7409c1b708f6c429aa43722ca8493a91d8df0.tar.bz2
Create StreamDescriptor and associated collection within common
Create StreamDescriptor and associated collection within common common policy pillar elements. It moves the code from managerdefault and creates helpers function within the collection. It also split the AudioGain in a common volume header and AudioGain class. Change-Id: I1bb80e4219506f8c9042367085db328d317cb668 Signed-off-by: François Gaffie <francois.gaffie@intel.com>
Diffstat (limited to 'services/audiopolicy/common/include')
-rwxr-xr-xservices/audiopolicy/common/include/Volume.h137
1 files changed, 137 insertions, 0 deletions
diff --git a/services/audiopolicy/common/include/Volume.h b/services/audiopolicy/common/include/Volume.h
new file mode 100755
index 0000000..a4cc759
--- /dev/null
+++ b/services/audiopolicy/common/include/Volume.h
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <system/audio.h>
+#include <utils/Log.h>
+
+class VolumeCurvePoint
+{
+public:
+ int mIndex;
+ float mDBAttenuation;
+};
+
+class Volume
+{
+public:
+ /**
+ * 4 points to define the volume attenuation curve, each characterized by the volume
+ * index (from 0 to 100) at which they apply, and the attenuation in dB at that index.
+ * we use 100 steps to avoid rounding errors when computing the volume in volIndexToAmpl()
+ *
+ * @todo shall become configurable
+ */
+ enum {
+ VOLMIN = 0,
+ VOLKNEE1 = 1,
+ VOLKNEE2 = 2,
+ VOLMAX = 3,
+
+ VOLCNT = 4
+ };
+
+ /**
+ * device categories used for volume curve management.
+ */
+ enum device_category {
+ DEVICE_CATEGORY_HEADSET,
+ DEVICE_CATEGORY_SPEAKER,
+ DEVICE_CATEGORY_EARPIECE,
+ DEVICE_CATEGORY_EXT_MEDIA,
+ DEVICE_CATEGORY_CNT
+ };
+
+ /**
+ * extract one device relevant for volume control from multiple device selection
+ *
+ * @param[in] device for which the volume category is associated
+ *
+ * @return subset of device required to limit the number of volume category per device
+ */
+ static audio_devices_t getDeviceForVolume(audio_devices_t device)
+ {
+ if (device == AUDIO_DEVICE_NONE) {
+ // this happens when forcing a route update and no track is active on an output.
+ // In this case the returned category is not important.
+ device = AUDIO_DEVICE_OUT_SPEAKER;
+ } else if (popcount(device) > 1) {
+ // Multiple device selection is either:
+ // - speaker + one other device: give priority to speaker in this case.
+ // - one A2DP device + another device: happens with duplicated output. In this case
+ // retain the device on the A2DP output as the other must not correspond to an active
+ // selection if not the speaker.
+ // - HDMI-CEC system audio mode only output: give priority to available item in order.
+ if (device & AUDIO_DEVICE_OUT_SPEAKER) {
+ device = AUDIO_DEVICE_OUT_SPEAKER;
+ } else if (device & AUDIO_DEVICE_OUT_HDMI_ARC) {
+ device = AUDIO_DEVICE_OUT_HDMI_ARC;
+ } else if (device & AUDIO_DEVICE_OUT_AUX_LINE) {
+ device = AUDIO_DEVICE_OUT_AUX_LINE;
+ } else if (device & AUDIO_DEVICE_OUT_SPDIF) {
+ device = AUDIO_DEVICE_OUT_SPDIF;
+ } else {
+ device = (audio_devices_t)(device & AUDIO_DEVICE_OUT_ALL_A2DP);
+ }
+ }
+
+ /*SPEAKER_SAFE is an alias of SPEAKER for purposes of volume control*/
+ if (device == AUDIO_DEVICE_OUT_SPEAKER_SAFE)
+ device = AUDIO_DEVICE_OUT_SPEAKER;
+
+ ALOGW_IF(popcount(device) != 1,
+ "getDeviceForVolume() invalid device combination: %08x",
+ device);
+
+ return device;
+ }
+
+ /**
+ * returns the category the device belongs to with regard to volume curve management
+ *
+ * @param[in] device to check upon the category to whom it belongs to.
+ *
+ * @return device category.
+ */
+ static device_category getDeviceCategory(audio_devices_t device)
+ {
+ switch(getDeviceForVolume(device)) {
+ case AUDIO_DEVICE_OUT_EARPIECE:
+ return DEVICE_CATEGORY_EARPIECE;
+ case AUDIO_DEVICE_OUT_WIRED_HEADSET:
+ case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES:
+ return DEVICE_CATEGORY_HEADSET;
+ case AUDIO_DEVICE_OUT_LINE:
+ case AUDIO_DEVICE_OUT_AUX_DIGITAL:
+ /*USB? Remote submix?*/
+ return DEVICE_CATEGORY_EXT_MEDIA;
+ case AUDIO_DEVICE_OUT_SPEAKER:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
+ case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
+ case AUDIO_DEVICE_OUT_USB_ACCESSORY:
+ case AUDIO_DEVICE_OUT_USB_DEVICE:
+ case AUDIO_DEVICE_OUT_REMOTE_SUBMIX:
+ default:
+ return DEVICE_CATEGORY_SPEAKER;
+ }
+ }
+
+};