StreamDescriptor.cpp revision dfd7409c1b708f6c429aa43722ca8493a91d8df0
1/* 2 * Copyright (C) 2015 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 "APM::Volumes" 18//#define LOG_NDEBUG 0 19 20//#define VERY_VERBOSE_LOGGING 21#ifdef VERY_VERBOSE_LOGGING 22#define ALOGVV ALOGV 23#else 24#define ALOGVV(a...) do { } while(0) 25#endif 26 27#include "StreamDescriptor.h" 28#include <utils/Log.h> 29#include <utils/String8.h> 30 31namespace android { 32 33// --- StreamDescriptor class implementation 34 35StreamDescriptor::StreamDescriptor() 36 : mIndexMin(0), mIndexMax(1), mCanBeMuted(true) 37{ 38 mIndexCur.add(AUDIO_DEVICE_OUT_DEFAULT, 0); 39} 40 41int StreamDescriptor::getVolumeIndex(audio_devices_t device) const 42{ 43 device = Volume::getDeviceForVolume(device); 44 // there is always a valid entry for AUDIO_DEVICE_OUT_DEFAULT 45 if (mIndexCur.indexOfKey(device) < 0) { 46 device = AUDIO_DEVICE_OUT_DEFAULT; 47 } 48 return mIndexCur.valueFor(device); 49} 50 51void StreamDescriptor::clearCurrentVolumeIndex() 52{ 53 mIndexCur.clear(); 54} 55 56void StreamDescriptor::addCurrentVolumeIndex(audio_devices_t device, int index) 57{ 58 mIndexCur.add(device, index); 59} 60 61void StreamDescriptor::setVolumeIndexMin(int volIndexMin) 62{ 63 mIndexMin = volIndexMin; 64} 65 66void StreamDescriptor::setVolumeIndexMax(int volIndexMax) 67{ 68 mIndexMax = volIndexMax; 69} 70 71void StreamDescriptor::setVolumeCurvePoint(Volume::device_category deviceCategory, 72 const VolumeCurvePoint *point) 73{ 74 mVolumeCurve[deviceCategory] = point; 75} 76 77void StreamDescriptor::dump(int fd) const 78{ 79 const size_t SIZE = 256; 80 char buffer[SIZE]; 81 String8 result; 82 83 snprintf(buffer, SIZE, "%s %02d %02d ", 84 mCanBeMuted ? "true " : "false", mIndexMin, mIndexMax); 85 result.append(buffer); 86 for (size_t i = 0; i < mIndexCur.size(); i++) { 87 snprintf(buffer, SIZE, "%04x : %02d, ", 88 mIndexCur.keyAt(i), 89 mIndexCur.valueAt(i)); 90 result.append(buffer); 91 } 92 result.append("\n"); 93 94 write(fd, result.string(), result.size()); 95} 96 97StreamDescriptorCollection::StreamDescriptorCollection() 98{ 99 for (size_t stream = 0 ; stream < AUDIO_STREAM_CNT; stream++) { 100 add(static_cast<audio_stream_type_t>(stream), StreamDescriptor()); 101 } 102} 103 104bool StreamDescriptorCollection::canBeMuted(audio_stream_type_t stream) 105{ 106 return valueAt(stream).canBeMuted(); 107} 108 109void StreamDescriptorCollection::clearCurrentVolumeIndex(audio_stream_type_t stream) 110{ 111 editValueAt(stream).clearCurrentVolumeIndex(); 112} 113 114void StreamDescriptorCollection::addCurrentVolumeIndex(audio_stream_type_t stream, 115 audio_devices_t device, int index) 116{ 117 editValueAt(stream).addCurrentVolumeIndex(device, index); 118} 119 120void StreamDescriptorCollection::setVolumeCurvePoint(audio_stream_type_t stream, 121 Volume::device_category deviceCategory, 122 const VolumeCurvePoint *point) 123{ 124 editValueAt(stream).setVolumeCurvePoint(deviceCategory, point); 125} 126 127const VolumeCurvePoint *StreamDescriptorCollection::getVolumeCurvePoint(audio_stream_type_t stream, 128 Volume::device_category deviceCategory) const 129{ 130 return valueAt(stream).getVolumeCurvePoint(deviceCategory); 131} 132 133void StreamDescriptorCollection::setVolumeIndexMin(audio_stream_type_t stream,int volIndexMin) 134{ 135 return editValueAt(stream).setVolumeIndexMin(volIndexMin); 136} 137 138void StreamDescriptorCollection::setVolumeIndexMax(audio_stream_type_t stream,int volIndexMax) 139{ 140 return editValueAt(stream).setVolumeIndexMax(volIndexMax); 141} 142 143status_t StreamDescriptorCollection::dump(int fd) const 144{ 145 const size_t SIZE = 256; 146 char buffer[SIZE]; 147 148 snprintf(buffer, SIZE, "\nStreams dump:\n"); 149 write(fd, buffer, strlen(buffer)); 150 snprintf(buffer, SIZE, 151 " Stream Can be muted Index Min Index Max Index Cur [device : index]...\n"); 152 write(fd, buffer, strlen(buffer)); 153 for (size_t i = 0; i < size(); i++) { 154 snprintf(buffer, SIZE, " %02zu ", i); 155 write(fd, buffer, strlen(buffer)); 156 valueAt(i).dump(fd); 157 } 158 159 return NO_ERROR; 160} 161 162}; // namespace android 163