AudioFlinger.cpp revision 949a926cadbc961fbb649c91d76d7aee8ea4d7bd
199e53b86eebb605b70dd7591b89bf61a9414ed0eGlenn Kasten/* 265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** 365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** Copyright 2007, The Android Open Source Project 465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** 565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** Licensed under the Apache License, Version 2.0 (the "License"); 665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** you may not use this file except in compliance with the License. 765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** You may obtain a copy of the License at 865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** 965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** http://www.apache.org/licenses/LICENSE-2.0 1065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** 1165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** Unless required by applicable law or agreed to in writing, software 1265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** distributed under the License is distributed on an "AS IS" BASIS, 1365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** See the License for the specific language governing permissions and 1565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian** limitations under the License. 1665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian*/ 1765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#define LOG_TAG "AudioFlinger" 2065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian//#define LOG_NDEBUG 0 2165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 22da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten#include <dirent.h> 2365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <math.h> 2465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <signal.h> 2565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <sys/time.h> 2665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <sys/resource.h> 2765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 289ee159b79022b2e1a050acb3890ce948e99e9ccbGloria Wang#include <binder/IPCThreadState.h> 2965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <binder/IServiceManager.h> 3065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Log.h> 31d8e6fd35ec2b59ee7d873daf1f1d9d348221c7bcGlenn Kasten#include <utils/Trace.h> 3265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <binder/Parcel.h> 3365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/String16.h> 3465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/threads.h> 3538ccae2c0324daa305f3fe77d25fdf5edec0b0e1Eric Laurent#include <utils/Atomic.h> 3665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 37fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin#include <cutils/bitops.h> 3865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <cutils/properties.h> 39f6b1678f8f508b447155a81b44e214475ab634a8Glenn Kasten#include <cutils/compiler.h> 4065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 4181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent//#include <private/media/AudioTrackShared.h> 4281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent//#include <private/media/AudioEffectShared.h> 43fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 4464760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h> 457394a4f358fa9908a9f0a7c954b65c399f4268e6Dima Zavin#include <hardware/audio.h> 4665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 4765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include "AudioMixer.h" 4865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include "AudioFlinger.h" 4944deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten#include "ServiceUtilities.h" 5065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 5165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <media/EffectsFactoryApi.h> 526d8b694d999e9be7d5dcc336535832a80fb6f61fEric Laurent#include <audio_effects/effect_visualizer.h> 5359bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent#include <audio_effects/effect_ns.h> 5459bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent#include <audio_effects/effect_aec.h> 5565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 563b21c50ef95fe4e7ac3426ca14b365749e66ff08Glenn Kasten#include <audio_utils/primitives.h> 573b21c50ef95fe4e7ac3426ca14b365749e66ff08Glenn Kasten 58feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent#include <powermanager/PowerManager.h> 59190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten 604ff14bae91075eb274eb1c2975982358946e7e63John Grossman#include <common_time/cc_helper.h> 6181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent//#include <common_time/local_clock.h> 6258912562617941964939a4182cda71eaeb153d4bGlenn Kasten 639e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten#include <media/IMediaLogService.h> 649e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten 65da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten#include <media/nbaio/Pipe.h> 66da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten#include <media/nbaio/PipeReader.h> 67da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 6865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 6965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 701c345196edc61694f29307a1826a64a0d26028dcJohn Grossman// Note: the following macro is used for extremely verbose logging message. In 711c345196edc61694f29307a1826a64a0d26028dcJohn Grossman// order to run with ALOG_ASSERT turned on, we need to have LOG_NDEBUG set to 721c345196edc61694f29307a1826a64a0d26028dcJohn Grossman// 0; but one side effect of this is to turn all LOGV's as well. Some messages 731c345196edc61694f29307a1826a64a0d26028dcJohn Grossman// are so verbose that we want to suppress them even when we have ALOG_ASSERT 741c345196edc61694f29307a1826a64a0d26028dcJohn Grossman// turned on. Do not uncomment the #def below unless you really know what you 751c345196edc61694f29307a1826a64a0d26028dcJohn Grossman// are doing and want to see all of the extremely verbose messages. 761c345196edc61694f29307a1826a64a0d26028dcJohn Grossman//#define VERY_VERY_VERBOSE_LOGGING 771c345196edc61694f29307a1826a64a0d26028dcJohn Grossman#ifdef VERY_VERY_VERBOSE_LOGGING 781c345196edc61694f29307a1826a64a0d26028dcJohn Grossman#define ALOGVV ALOGV 791c345196edc61694f29307a1826a64a0d26028dcJohn Grossman#else 801c345196edc61694f29307a1826a64a0d26028dcJohn Grossman#define ALOGVV(a...) do { } while(0) 811c345196edc61694f29307a1826a64a0d26028dcJohn Grossman#endif 82de070137f11d346fba77605bd76a44c040a618fcEric Laurent 8365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiannamespace android { 8465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 85ec1d6b5e17281a066d618f7fcd2b63b3ce11f421Glenn Kastenstatic const char kDeadlockedString[] = "AudioFlinger may be deadlocked\n"; 86ec1d6b5e17281a066d618f7fcd2b63b3ce11f421Glenn Kastenstatic const char kHardwareLockedString[] = "Hardware lock is taken\n"; 8765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 8858912562617941964939a4182cda71eaeb153d4bGlenn Kasten 894ff14bae91075eb274eb1c2975982358946e7e63John Grossmannsecs_t AudioFlinger::mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs; 907cafbb32999049873d4746ba83bd20c88abe6ce6Eric Laurent 9181784c37c61b09289654b979567a42bf73cd2b12Eric Laurentuint32_t AudioFlinger::mScreenState; 923ed292031dc50c56110cdadb1e3778117e3be76aGlenn Kasten 9346909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 94da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenbool AudioFlinger::mTeeSinkInputEnabled = false; 95da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenbool AudioFlinger::mTeeSinkOutputEnabled = false; 96da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenbool AudioFlinger::mTeeSinkTrackEnabled = false; 97da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 98da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastensize_t AudioFlinger::mTeeSinkInputFrames = kTeeSinkInputFramesDefault; 99da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastensize_t AudioFlinger::mTeeSinkOutputFrames = kTeeSinkOutputFramesDefault; 100da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastensize_t AudioFlinger::mTeeSinkTrackFrames = kTeeSinkTrackFramesDefault; 10146909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 102da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 10365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 10465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 105f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurentstatic int load_audio_interface(const char *if_name, audio_hw_device_t **dev) 106799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin{ 107f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent const hw_module_t *mod; 108799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin int rc; 109799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin 110f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent rc = hw_get_module_by_class(AUDIO_HARDWARE_MODULE_ID, if_name, &mod); 111f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent ALOGE_IF(rc, "%s couldn't load audio hw module %s.%s (%s)", __func__, 112f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc)); 113f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent if (rc) { 114799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin goto out; 115f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent } 116f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent rc = audio_hw_device_open(mod, dev); 117f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent ALOGE_IF(rc, "%s couldn't open audio hw device in %s.%s (%s)", __func__, 118f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc)); 119f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent if (rc) { 120799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin goto out; 121f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent } 122f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent if ((*dev)->common.version != AUDIO_DEVICE_API_VERSION_CURRENT) { 123f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent ALOGE("%s wrong audio hw device version %04x", __func__, (*dev)->common.version); 124f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent rc = BAD_VALUE; 125f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent goto out; 126f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent } 127799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin return 0; 128799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin 129799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavinout: 130799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin *dev = NULL; 131799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin return rc; 132799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin} 133799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin 13465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 13565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 13665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioFlinger::AudioFlinger() 13765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian : BnAudioFlinger(), 1384ff14bae91075eb274eb1c2975982358946e7e63John Grossman mPrimaryHardwareDev(NULL), 1397d6c35bf132a46c0a8a9826491882495fc98bd8cGlenn Kasten mHardwareStatus(AUDIO_HW_IDLE), 1404ff14bae91075eb274eb1c2975982358946e7e63John Grossman mMasterVolume(1.0f), 1414ff14bae91075eb274eb1c2975982358946e7e63John Grossman mMasterMute(false), 1424ff14bae91075eb274eb1c2975982358946e7e63John Grossman mNextUniqueId(1), 1434ff14bae91075eb274eb1c2975982358946e7e63John Grossman mMode(AUDIO_MODE_INVALID), 1444ff14bae91075eb274eb1c2975982358946e7e63John Grossman mBtNrecIsOff(false) 14565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 146949a926cadbc961fbb649c91d76d7aee8ea4d7bdGlenn Kasten getpid_cached = getpid(); 1479e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten char value[PROPERTY_VALUE_MAX]; 1489e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten bool doLog = (property_get("ro.test_harness", value, "0") > 0) && (atoi(value) == 1); 1499e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (doLog) { 1509e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten mLogMemoryDealer = new MemoryDealer(kLogMemorySize, "LogWriters"); 1519e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 15246909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 153da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten (void) property_get("ro.debuggable", value, "0"); 154da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten int debuggable = atoi(value); 155da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten int teeEnabled = 0; 156da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (debuggable) { 157da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten (void) property_get("af.tee", value, "0"); 158da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten teeEnabled = atoi(value); 159da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 160da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (teeEnabled & 1) 161da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten mTeeSinkInputEnabled = true; 162da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (teeEnabled & 2) 163da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten mTeeSinkOutputEnabled = true; 164da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (teeEnabled & 4) 165da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten mTeeSinkTrackEnabled = true; 16646909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 1675a61d2f277af3098fc10b2881babca16391362daDima Zavin} 1685a61d2f277af3098fc10b2881babca16391362daDima Zavin 1695a61d2f277af3098fc10b2881babca16391362daDima Zavinvoid AudioFlinger::onFirstRef() 1705a61d2f277af3098fc10b2881babca16391362daDima Zavin{ 171799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin int rc = 0; 172fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 173935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent Mutex::Autolock _l(mLock); 174935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent 175799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin /* TODO: move all this work into an Init() function */ 1764ff14bae91075eb274eb1c2975982358946e7e63John Grossman char val_str[PROPERTY_VALUE_MAX] = { 0 }; 1774ff14bae91075eb274eb1c2975982358946e7e63John Grossman if (property_get("ro.audio.flinger_standbytime_ms", val_str, NULL) >= 0) { 1784ff14bae91075eb274eb1c2975982358946e7e63John Grossman uint32_t int_val; 1794ff14bae91075eb274eb1c2975982358946e7e63John Grossman if (1 == sscanf(val_str, "%u", &int_val)) { 1804ff14bae91075eb274eb1c2975982358946e7e63John Grossman mStandbyTimeInNsecs = milliseconds(int_val); 1814ff14bae91075eb274eb1c2975982358946e7e63John Grossman ALOGI("Using %u mSec as standby time.", int_val); 1824ff14bae91075eb274eb1c2975982358946e7e63John Grossman } else { 1834ff14bae91075eb274eb1c2975982358946e7e63John Grossman mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs; 1844ff14bae91075eb274eb1c2975982358946e7e63John Grossman ALOGI("Using default %u mSec as standby time.", 1854ff14bae91075eb274eb1c2975982358946e7e63John Grossman (uint32_t)(mStandbyTimeInNsecs / 1000000)); 1864ff14bae91075eb274eb1c2975982358946e7e63John Grossman } 1874ff14bae91075eb274eb1c2975982358946e7e63John Grossman } 18865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 189a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent mMode = AUDIO_MODE_NORMAL; 19065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 19165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 19265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioFlinger::~AudioFlinger() 19365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 19465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian while (!mRecordThreads.isEmpty()) { 195c3ae93f21280859086ae371428ffd32f39e76d50Glenn Kasten // closeInput_nonvirtual() will remove specified entry from mRecordThreads 196d96c5724818fb47917bb5e7abe37799735e1ec0eGlenn Kasten closeInput_nonvirtual(mRecordThreads.keyAt(0)); 19765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 19865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian while (!mPlaybackThreads.isEmpty()) { 199c3ae93f21280859086ae371428ffd32f39e76d50Glenn Kasten // closeOutput_nonvirtual() will remove specified entry from mPlaybackThreads 200d96c5724818fb47917bb5e7abe37799735e1ec0eGlenn Kasten closeOutput_nonvirtual(mPlaybackThreads.keyAt(0)); 20165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 202799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin 2032b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 2042b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten // no mHardwareLock needed, as there are no other references to this 205a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent audio_hw_device_close(mAudioHwDevs.valueAt(i)->hwDevice()); 206a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent delete mAudioHwDevs.valueAt(i); 20765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 20865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 20965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 210a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurentstatic const char * const audio_interfaces[] = { 211a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent AUDIO_HARDWARE_MODULE_ID_PRIMARY, 212a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent AUDIO_HARDWARE_MODULE_ID_A2DP, 213a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent AUDIO_HARDWARE_MODULE_ID_USB, 214a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent}; 215a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent#define ARRAY_SIZE(x) (sizeof((x))/sizeof(((x)[0]))) 216a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent 217ee578c0330319f04a48bccbdb26b53fea0388d04John GrossmanAudioFlinger::AudioHwDevice* AudioFlinger::findSuitableHwDev_l( 218ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_module_handle_t module, 219ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_devices_t devices) 220799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin{ 221a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent // if module is 0, the request comes from an old policy manager and we should load 222a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent // well known modules 223a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent if (module == 0) { 224a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent ALOGW("findSuitableHwDev_l() loading well know audio hw modules"); 225a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent for (size_t i = 0; i < ARRAY_SIZE(audio_interfaces); i++) { 226a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent loadHwModule_l(audio_interfaces[i]); 227a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } 228f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent // then try to find a module supporting the requested device. 229f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 230f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent AudioHwDevice *audioHwDevice = mAudioHwDevs.valueAt(i); 231f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent audio_hw_device_t *dev = audioHwDevice->hwDevice(); 232f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent if ((dev->get_supported_devices != NULL) && 233f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent (dev->get_supported_devices(dev) & devices) == devices) 234f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent return audioHwDevice; 235f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent } 236a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } else { 237a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent // check a match for the requested module handle 238ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AudioHwDevice *audioHwDevice = mAudioHwDevs.valueFor(module); 239ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman if (audioHwDevice != NULL) { 240ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman return audioHwDevice; 241a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } 242a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } 243a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent 244799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin return NULL; 245799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin} 24665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 247be5f05e0fdfc4e3799653702187861a2afa072eeGlenn Kastenvoid AudioFlinger::dumpClients(int fd, const Vector<String16>& args) 24865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 24965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 25065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 25165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 25265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 25365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append("Clients:\n"); 25465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < mClients.size(); ++i) { 25577c1119ea0b5cb32287088ceeeb7e3b6bd14a85dGlenn Kasten sp<Client> client = mClients.valueAt(i).promote(); 25677c1119ea0b5cb32287088ceeeb7e3b6bd14a85dGlenn Kasten if (client != 0) { 25777c1119ea0b5cb32287088ceeeb7e3b6bd14a85dGlenn Kasten snprintf(buffer, SIZE, " pid: %d\n", client->pid()); 25877c1119ea0b5cb32287088ceeeb7e3b6bd14a85dGlenn Kasten result.append(buffer); 25965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 26065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 2613a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen 2623a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen result.append("Global session refs:\n"); 263012ca6b4f69fb24385025c0e84b8f816525a3032Glenn Kasten result.append(" session pid count\n"); 2643a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen for (size_t i = 0; i < mAudioSessionRefs.size(); i++) { 2653a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen AudioSessionRef *r = mAudioSessionRefs[i]; 266012ca6b4f69fb24385025c0e84b8f816525a3032Glenn Kasten snprintf(buffer, SIZE, " %7d %3d %3d\n", r->mSessionid, r->mPid, r->mCnt); 2673a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen result.append(buffer); 2683a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen } 26965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 27065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 27165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 27265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 273be5f05e0fdfc4e3799653702187861a2afa072eeGlenn Kastenvoid AudioFlinger::dumpInternals(int fd, const Vector<String16>& args) 27465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 27565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 27665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 27765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 278a4454b4765c5905f14186893b0688be375642283Glenn Kasten hardware_call_state hardwareStatus = mHardwareStatus; 27965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2804ff14bae91075eb274eb1c2975982358946e7e63John Grossman snprintf(buffer, SIZE, "Hardware status: %d\n" 2814ff14bae91075eb274eb1c2975982358946e7e63John Grossman "Standby Time mSec: %u\n", 2824ff14bae91075eb274eb1c2975982358946e7e63John Grossman hardwareStatus, 2834ff14bae91075eb274eb1c2975982358946e7e63John Grossman (uint32_t)(mStandbyTimeInNsecs / 1000000)); 28465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 28565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 28665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 28765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 288be5f05e0fdfc4e3799653702187861a2afa072eeGlenn Kastenvoid AudioFlinger::dumpPermissionDenial(int fd, const Vector<String16>& args) 28965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 29065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 29165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 29265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 29365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "Permission Denial: " 29465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian "can't dump AudioFlinger from pid=%d, uid=%d\n", 29565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian IPCThreadState::self()->getCallingPid(), 29665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian IPCThreadState::self()->getCallingUid()); 29765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 29865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 29965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 30065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 30181784c37c61b09289654b979567a42bf73cd2b12Eric Laurentbool AudioFlinger::dumpTryLock(Mutex& mutex) 30265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 30365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian bool locked = false; 30465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (int i = 0; i < kDumpLockRetries; ++i) { 30565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mutex.tryLock() == NO_ERROR) { 30665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian locked = true; 30765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 30865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 3097dede876998ff56351d495ec3a798c1b131193e8Glenn Kasten usleep(kDumpLockSleepUs); 31065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 31165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return locked; 31265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 31365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 31465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::dump(int fd, const Vector<String16>& args) 31565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 31644deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten if (!dumpAllowed()) { 31765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpPermissionDenial(fd, args); 31865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 31965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // get state of hardware lock 32081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool hardwareLocked = dumpTryLock(mHardwareLock); 32165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!hardwareLocked) { 32265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result(kHardwareLockedString); 32365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 32465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 32565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareLock.unlock(); 32665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 32765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 32881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool locked = dumpTryLock(mLock); 32965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 33065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // failed to lock - AudioFlinger is probably deadlocked 33165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!locked) { 33265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result(kDeadlockedString); 33365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 33465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 33565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 33665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpClients(fd, args); 33765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpInternals(fd, args); 33865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 33965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // dump playback threads 34065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 34165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mPlaybackThreads.valueAt(i)->dump(fd, args); 34265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 34365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 34465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // dump record threads 34565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < mRecordThreads.size(); i++) { 34665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mRecordThreads.valueAt(i)->dump(fd, args); 34765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 34865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 349799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin // dump all hardware devs 350799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 351a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice(); 352799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin dev->dump(dev, fd); 35365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 354d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten 35546909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 356d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten // dump the serially shared record tee sink 357d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten if (mRecordTeeSource != 0) { 358d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten dumpTee(fd, mRecordTeeSource); 359d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten } 36046909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 361d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten 362d65d73c4ae74d084751b417615a78cbe7a51372aGlenn Kasten if (locked) { 363d65d73c4ae74d084751b417615a78cbe7a51372aGlenn Kasten mLock.unlock(); 364d65d73c4ae74d084751b417615a78cbe7a51372aGlenn Kasten } 3659e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten 3669e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten // append a copy of media.log here by forwarding fd to it, but don't attempt 3679e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten // to lookup the service if it's not running, as it will block for a second 3689e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (mLogMemoryDealer != 0) { 3699e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log")); 3709e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (binder != 0) { 3719e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten fdprintf(fd, "\nmedia.log:\n"); 3729e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten Vector<String16> args; 3739e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten binder->dump(fd, args); 3749e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 3759e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 37665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 37765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 37865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 37965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 38098ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kastensp<AudioFlinger::Client> AudioFlinger::registerPid_l(pid_t pid) 38198ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten{ 38298ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten // If pid is already in the mClients wp<> map, then use that entry 38398ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten // (for which promote() is always != 0), otherwise create a new entry and Client. 38498ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten sp<Client> client = mClients.valueFor(pid).promote(); 38598ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten if (client == 0) { 38698ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten client = new Client(this, pid); 38798ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten mClients.add(pid, client); 38898ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten } 38998ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten 39098ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten return client; 39198ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten} 39265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 3939e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kastensp<NBLog::Writer> AudioFlinger::newWriter_l(size_t size, const char *name) 3949e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten{ 3959e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (mLogMemoryDealer == 0) { 3969e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten return new NBLog::Writer(); 3979e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 3989e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten sp<IMemory> shared = mLogMemoryDealer->allocate(NBLog::Timeline::sharedSize(size)); 3999e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten sp<NBLog::Writer> writer = new NBLog::Writer(size, shared); 4009e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log")); 4019e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (binder != 0) { 4029e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten interface_cast<IMediaLogService>(binder)->registerWriter(shared, size, name); 4039e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 4049e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten return writer; 4059e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten} 4069e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten 4079e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kastenvoid AudioFlinger::unregisterWriter(const sp<NBLog::Writer>& writer) 4089e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten{ 409685ef09bcaf5de6abf2064d552296f70eaec6761Glenn Kasten if (writer == 0) { 410685ef09bcaf5de6abf2064d552296f70eaec6761Glenn Kasten return; 411685ef09bcaf5de6abf2064d552296f70eaec6761Glenn Kasten } 4129e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten sp<IMemory> iMemory(writer->getIMemory()); 4139e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (iMemory == 0) { 4149e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten return; 4159e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 4169e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log")); 4179e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (binder != 0) { 4189e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten interface_cast<IMediaLogService>(binder)->unregisterWriter(iMemory); 4199e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten // Now the media.log remote reference to IMemory is gone. 4209e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten // When our last local reference to IMemory also drops to zero, 4219e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten // the IMemory destructor will deallocate the region from mMemoryDealer. 4229e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 4239e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten} 4249e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten 42565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// IAudioFlinger interface 42665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 42765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 42865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiansp<IAudioTrack> AudioFlinger::createTrack( 429fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten audio_stream_type_t streamType, 43065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t sampleRate, 43158f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten audio_format_t format, 432254af180475346b6186b49c297f340c9c4817511Glenn Kasten audio_channel_mask_t channelMask, 433e33054eb968cbf8ccaee1b0ff0301403902deed6Glenn Kasten size_t frameCount, 434e0b07179a48ee50fda931d2aa1b3c751d167e4d7Glenn Kasten IAudioFlinger::track_flags_t *flags, 43565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const sp<IMemory>& sharedBuffer, 43672ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten audio_io_handle_t output, 4373acbd053c842e76e1a40fc8a0bf62de87eebf00fGlenn Kasten pid_t tid, 43865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian int *sessionId, 43965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t *status) 44065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 44165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<PlaybackThread::Track> track; 44265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<TrackHandle> trackHandle; 44365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<Client> client; 44465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t lStatus; 44565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian int lSessionId; 44665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 447263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten // client AudioTrack::set already implements AUDIO_STREAM_DEFAULT => AUDIO_STREAM_MUSIC, 448263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten // but if someone uses binder directly they could bypass that and cause us to crash 449263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten if (uint32_t(streamType) >= AUDIO_STREAM_CNT) { 45029357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("createTrack() invalid stream type %d", streamType); 45165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian lStatus = BAD_VALUE; 45265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian goto Exit; 45365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 45465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 45560a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten // client is responsible for conversion of 8-bit PCM to 16-bit PCM, 45660a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten // and we don't yet support 8.24 or 32-bit PCM 45760a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten if (audio_is_linear_pcm(format) && format != AUDIO_FORMAT_PCM_16_BIT) { 45860a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten ALOGE("createTrack() invalid format %d", format); 45960a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten lStatus = BAD_VALUE; 46060a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten goto Exit; 46160a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten } 46260a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten 46365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { 46465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 46565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 46639e94f8f723d445447fdee0822291e664b631f60Eric Laurent PlaybackThread *effectThread = NULL; 46765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 468c9b2e20f7c9a71e07ef398152709c76079decbcdGlenn Kasten ALOGE("no playback thread found for output handle %d", output); 46965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian lStatus = BAD_VALUE; 47065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian goto Exit; 47165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 47265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 4738d6cc842e8d525405c68e57fdf3bc5da0b4d7e87Glenn Kasten pid_t pid = IPCThreadState::self()->getCallingPid(); 47498ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten client = registerPid_l(pid); 47565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 4763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("createTrack() sessionId: %d", (sessionId == NULL) ? -2 : *sessionId); 477fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { 478f436fdcf93bd417fd3c9d2a8b19fd221d894b5e3Eric Laurent // check if an effect chain with the same session ID is present on another 479f436fdcf93bd417fd3c9d2a8b19fd221d894b5e3Eric Laurent // output thread and move it here. 480de070137f11d346fba77605bd76a44c040a618fcEric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 48139e94f8f723d445447fdee0822291e664b631f60Eric Laurent sp<PlaybackThread> t = mPlaybackThreads.valueAt(i); 48239e94f8f723d445447fdee0822291e664b631f60Eric Laurent if (mPlaybackThreads.keyAt(i) != output) { 48339e94f8f723d445447fdee0822291e664b631f60Eric Laurent uint32_t sessions = t->hasAudioSession(*sessionId); 48439e94f8f723d445447fdee0822291e664b631f60Eric Laurent if (sessions & PlaybackThread::EFFECT_SESSION) { 48539e94f8f723d445447fdee0822291e664b631f60Eric Laurent effectThread = t.get(); 486f436fdcf93bd417fd3c9d2a8b19fd221d894b5e3Eric Laurent break; 48739e94f8f723d445447fdee0822291e664b631f60Eric Laurent } 488de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 489de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 49065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian lSessionId = *sessionId; 49165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 492de070137f11d346fba77605bd76a44c040a618fcEric Laurent // if no audio session id is provided, create one here 4937c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent lSessionId = nextUniqueId(); 49465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (sessionId != NULL) { 49565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *sessionId = lSessionId; 49665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 49765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 4983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("createTrack() lSessionId: %d", lSessionId); 49965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 50065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian track = thread->createTrack_l(client, streamType, sampleRate, format, 5013acbd053c842e76e1a40fc8a0bf62de87eebf00fGlenn Kasten channelMask, frameCount, sharedBuffer, lSessionId, flags, tid, &lStatus); 50239e94f8f723d445447fdee0822291e664b631f60Eric Laurent 50339e94f8f723d445447fdee0822291e664b631f60Eric Laurent // move effect chain to this output thread if an effect on same session was waiting 50439e94f8f723d445447fdee0822291e664b631f60Eric Laurent // for a track to be created 50539e94f8f723d445447fdee0822291e664b631f60Eric Laurent if (lStatus == NO_ERROR && effectThread != NULL) { 50639e94f8f723d445447fdee0822291e664b631f60Eric Laurent Mutex::Autolock _dl(thread->mLock); 50739e94f8f723d445447fdee0822291e664b631f60Eric Laurent Mutex::Autolock _sl(effectThread->mLock); 50839e94f8f723d445447fdee0822291e664b631f60Eric Laurent moveEffectChain_l(lSessionId, effectThread, thread, true); 50939e94f8f723d445447fdee0822291e664b631f60Eric Laurent } 510a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent 511a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent // Look for sync events awaiting for a session to be used. 512a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent for (int i = 0; i < (int)mPendingSyncEvents.size(); i++) { 513a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent if (mPendingSyncEvents[i]->triggerSession() == lSessionId) { 514a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent if (thread->isValidSyncEvent(mPendingSyncEvents[i])) { 5152986460984580833161bdaabc7f17da1005a8961Eric Laurent if (lStatus == NO_ERROR) { 516d23eedca9b5a1812891c05d89850ab7ee707040dGlenn Kasten (void) track->setSyncEvent(mPendingSyncEvents[i]); 5172986460984580833161bdaabc7f17da1005a8961Eric Laurent } else { 5182986460984580833161bdaabc7f17da1005a8961Eric Laurent mPendingSyncEvents[i]->cancel(); 5192986460984580833161bdaabc7f17da1005a8961Eric Laurent } 520a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent mPendingSyncEvents.removeAt(i); 521a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent i--; 522a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 523a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 524a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 52565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 52665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (lStatus == NO_ERROR) { 52765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian trackHandle = new TrackHandle(track); 52865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 52965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // remove local strong reference to Client before deleting the Track so that the Client 53065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // destructor is called by the TrackBase destructor with mLock held 53165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian client.clear(); 53265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian track.clear(); 53365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 53465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 53565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianExit: 536e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten if (status != NULL) { 53765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *status = lStatus; 53865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 53965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return trackHandle; 54065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 54165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 54272ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenuint32_t AudioFlinger::sampleRate(audio_io_handle_t output) const 54365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 54465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 54565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 54665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 5475ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block ALOGW("sampleRate() unknown thread %d", output); 54865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 54965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 55065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return thread->sampleRate(); 55165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 55265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 55372ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenint AudioFlinger::channelCount(audio_io_handle_t output) const 55465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 55565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 55665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 55765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 5585ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block ALOGW("channelCount() unknown thread %d", output); 55965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 56065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 56165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return thread->channelCount(); 56265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 56365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 56472ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenaudio_format_t AudioFlinger::format(audio_io_handle_t output) const 56565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 56665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 56765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 56865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 5695ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block ALOGW("format() unknown thread %d", output); 57058f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten return AUDIO_FORMAT_INVALID; 57165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 57265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return thread->format(); 57365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 57465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 57572ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastensize_t AudioFlinger::frameCount(audio_io_handle_t output) const 57665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 57765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 57865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 57965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 5805ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block ALOGW("frameCount() unknown thread %d", output); 58165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 58265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 58358912562617941964939a4182cda71eaeb153d4bGlenn Kasten // FIXME currently returns the normal mixer's frame count to avoid confusing legacy callers; 58458912562617941964939a4182cda71eaeb153d4bGlenn Kasten // should examine all callers and fix them to handle smaller counts 58565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return thread->frameCount(); 58665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 58765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 58872ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenuint32_t AudioFlinger::latency(audio_io_handle_t output) const 58965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 59065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 59165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 59265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 593c9b2e20f7c9a71e07ef398152709c76079decbcdGlenn Kasten ALOGW("latency(): no playback thread found for output handle %d", output); 59465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 59565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 59665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return thread->latency(); 59765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 59865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 59965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::setMasterVolume(float value) 60065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 601a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 602a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 603a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return ret; 604a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 605a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent 60665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 60765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 60865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 60965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 61065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 611a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent Mutex::Autolock _l(mLock); 612ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mMasterVolume = value; 613a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent 614ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // Set master volume in the HALs which support it. 615ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 616ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AutoMutex lock(mHardwareLock); 617ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AudioHwDevice *dev = mAudioHwDevs.valueAt(i); 6184ff14bae91075eb274eb1c2975982358946e7e63John Grossman 619ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME; 620ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman if (dev->canSetMasterVolume()) { 621ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman dev->hwDevice()->set_master_volume(dev->hwDevice(), value); 622935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent } 623ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mHardwareStatus = AUDIO_HW_IDLE; 62465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 62565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 626ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // Now set the master volume in each playback thread. Playback threads 627ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // assigned to HALs which do not have master volume support will apply 628ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // master volume during the mix operation. Threads with HALs which do 629ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // support master volume will simply ignore the setting. 6308d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten for (size_t i = 0; i < mPlaybackThreads.size(); i++) 631ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mPlaybackThreads.valueAt(i)->setMasterVolume(value); 63265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 63365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 63465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 63565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 636f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kastenstatus_t AudioFlinger::setMode(audio_mode_t mode) 63765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 638a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 639a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 640a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return ret; 641a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 64265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 64365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 64465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 64565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 64665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 647930f4caa1e311ef7ff538c421a324396157eb24fGlenn Kasten if (uint32_t(mode) >= AUDIO_MODE_CNT) { 6485ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block ALOGW("Illegal value: setMode(%d)", mode); 64965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 65065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 65165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 65265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { // scope for the lock 65365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mHardwareLock); 654ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); 65565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_SET_MODE; 656ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman ret = dev->set_mode(dev, mode); 65765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_IDLE; 65865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 65965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 66065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (NO_ERROR == ret) { 66165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 66265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mMode = mode; 6638d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten for (size_t i = 0; i < mPlaybackThreads.size(); i++) 664e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten mPlaybackThreads.valueAt(i)->setMode(mode); 66565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 66665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 66765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return ret; 66865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 66965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 67065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::setMicMute(bool state) 67165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 672a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 673a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 674a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return ret; 675a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 676a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent 67765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 67865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 67965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 68065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 68165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 68265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mHardwareLock); 683ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); 68465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_SET_MIC_MUTE; 685ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman ret = dev->set_mic_mute(dev, state); 68665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_IDLE; 68765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return ret; 68865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 68965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 69065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianbool AudioFlinger::getMicMute() const 69165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 692a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 693a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 694a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return false; 695a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 696a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent 697fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin bool state = AUDIO_MODE_INVALID; 6982b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten AutoMutex lock(mHardwareLock); 699ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); 70065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_GET_MIC_MUTE; 701ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman dev->get_mic_mute(dev, &state); 70265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_IDLE; 70365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return state; 70465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 70565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 70665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::setMasterMute(bool muted) 70765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 708d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman status_t ret = initCheck(); 709d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman if (ret != NO_ERROR) { 710d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman return ret; 711d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman } 712d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 71365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 71465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 71565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 71665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 71765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 718ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman Mutex::Autolock _l(mLock); 719ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mMasterMute = muted; 720d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 721ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // Set master mute in the HALs which support it. 722ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 723ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AutoMutex lock(mHardwareLock); 724ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AudioHwDevice *dev = mAudioHwDevs.valueAt(i); 725d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 726ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE; 727ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman if (dev->canSetMasterMute()) { 728ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman dev->hwDevice()->set_master_mute(dev->hwDevice(), muted); 729d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman } 730ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mHardwareStatus = AUDIO_HW_IDLE; 731d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman } 732d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 733ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // Now set the master mute in each playback thread. Playback threads 734ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // assigned to HALs which do not have master mute support will apply master 735ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // mute during the mix operation. Threads with HALs which do support master 736ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // mute will simply ignore the setting. 7378d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten for (size_t i = 0; i < mPlaybackThreads.size(); i++) 738ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mPlaybackThreads.valueAt(i)->setMasterMute(muted); 73965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 74065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 74165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 74265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 74365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianfloat AudioFlinger::masterVolume() const 74465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 7459806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten Mutex::Autolock _l(mLock); 7469806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten return masterVolume_l(); 74765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 74865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 74965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianbool AudioFlinger::masterMute() const 75065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 7519806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten Mutex::Autolock _l(mLock); 7529806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten return masterMute_l(); 75365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 75465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 7554ff14bae91075eb274eb1c2975982358946e7e63John Grossmanfloat AudioFlinger::masterVolume_l() const 7564ff14bae91075eb274eb1c2975982358946e7e63John Grossman{ 7574ff14bae91075eb274eb1c2975982358946e7e63John Grossman return mMasterVolume; 7584ff14bae91075eb274eb1c2975982358946e7e63John Grossman} 7594ff14bae91075eb274eb1c2975982358946e7e63John Grossman 760d8f178d613821c3f61a5c5e391eb275339e526a9John Grossmanbool AudioFlinger::masterMute_l() const 761d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman{ 762ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman return mMasterMute; 763d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman} 764d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 76572ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenstatus_t AudioFlinger::setStreamVolume(audio_stream_type_t stream, float value, 76672ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten audio_io_handle_t output) 76765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 76865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 76965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 77065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 77165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 77265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 773263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten if (uint32_t(stream) >= AUDIO_STREAM_CNT) { 77429357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("setStreamVolume() invalid stream %d", stream); 77565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 77665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 77765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 77865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mLock); 77965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = NULL; 78065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (output) { 78165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian thread = checkPlaybackThread_l(output); 78265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 78365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 78465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 78565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 78665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 78765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mStreamTypes[stream].volume = value; 78865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 78965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 7908d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 791e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten mPlaybackThreads.valueAt(i)->setStreamVolume(stream, value); 79265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 79365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 79465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian thread->setStreamVolume(stream, value); 79565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 79665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 79765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 79865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 79965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 800fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kastenstatus_t AudioFlinger::setStreamMute(audio_stream_type_t stream, bool muted) 80165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 80265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 80365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 80465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 80565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 80665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 807263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten if (uint32_t(stream) >= AUDIO_STREAM_CNT || 808fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin uint32_t(stream) == AUDIO_STREAM_ENFORCED_AUDIBLE) { 80929357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("setStreamMute() invalid stream %d", stream); 81065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 81165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 81265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 813935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent AutoMutex lock(mLock); 81465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mStreamTypes[stream].mute = muted; 81565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (uint32_t i = 0; i < mPlaybackThreads.size(); i++) 816e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten mPlaybackThreads.valueAt(i)->setStreamMute(stream, muted); 81765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 81865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 81965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 82065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 82172ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenfloat AudioFlinger::streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const 82265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 823263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten if (uint32_t(stream) >= AUDIO_STREAM_CNT) { 82465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0.0f; 82565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 82665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 82765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mLock); 82865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian float volume; 82965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (output) { 83065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 83165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 83265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0.0f; 83365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 83465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian volume = thread->streamVolume(stream); 83565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 8366637baae4244aec731c4014da72418d330636ae1Glenn Kasten volume = streamVolume_l(stream); 83765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 83865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 83965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return volume; 84065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 84165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 842fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kastenbool AudioFlinger::streamMute(audio_stream_type_t stream) const 84365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 844263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten if (uint32_t(stream) >= AUDIO_STREAM_CNT) { 84565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return true; 84665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 84765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 8486637baae4244aec731c4014da72418d330636ae1Glenn Kasten AutoMutex lock(mLock); 8496637baae4244aec731c4014da72418d330636ae1Glenn Kasten return streamMute_l(stream); 85065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 85165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 85272ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenstatus_t AudioFlinger::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) 85365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 854827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ALOGV("setParameters(): io %d, keyvalue %s, calling pid %d", 855827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ioHandle, keyValuePairs.string(), IPCThreadState::self()->getCallingPid()); 85681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 85765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 85865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 85965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 86065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 86165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 86265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // ioHandle == 0 means the parameters are global to the audio hardware interface 86365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (ioHandle == 0) { 864a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent Mutex::Autolock _l(mLock); 865799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin status_t final_result = NO_ERROR; 8668abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten { 867a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent AutoMutex lock(mHardwareLock); 868a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent mHardwareStatus = AUDIO_HW_SET_PARAMETER; 869a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 870a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice(); 871a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent status_t result = dev->set_parameters(dev, keyValuePairs.string()); 872a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent final_result = result ?: final_result; 873a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } 874a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 8758abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten } 87659bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent // disable AEC and NS if the device is a BT SCO headset supporting those pre processings 87759bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent AudioParameter param = AudioParameter(keyValuePairs); 87859bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent String8 value; 87959bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent if (param.get(String8(AUDIO_PARAMETER_KEY_BT_NREC), value) == NO_ERROR) { 880bee5337da7659b3b7128622ba1f42618b11df5beEric Laurent bool btNrecIsOff = (value == AUDIO_PARAMETER_VALUE_OFF); 881bee5337da7659b3b7128622ba1f42618b11df5beEric Laurent if (mBtNrecIsOff != btNrecIsOff) { 88259bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 88359bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent sp<RecordThread> thread = mRecordThreads.valueAt(i); 884f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent audio_devices_t device = thread->inDevice(); 885510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten bool suspend = audio_is_bluetooth_sco_device(device) && btNrecIsOff; 886510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten // collect all of the thread's session IDs 887510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten KeyedVector<int, bool> ids = thread->sessionIds(); 888510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten // suspend effects associated with those session IDs 889510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten for (size_t j = 0; j < ids.size(); ++j) { 890510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten int sessionId = ids.keyAt(j); 89159bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent thread->setEffectSuspended(FX_IID_AEC, 89259bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent suspend, 893510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten sessionId); 89459bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent thread->setEffectSuspended(FX_IID_NS, 89559bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent suspend, 896510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten sessionId); 89759bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent } 89859bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent } 899bee5337da7659b3b7128622ba1f42618b11df5beEric Laurent mBtNrecIsOff = btNrecIsOff; 90059bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent } 90159bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent } 90228ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten String8 screenState; 90328ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten if (param.get(String8(AudioParameter::keyScreenState), screenState) == NO_ERROR) { 90428ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten bool isOff = screenState == "off"; 90581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (isOff != (AudioFlinger::mScreenState & 1)) { 90681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioFlinger::mScreenState = ((AudioFlinger::mScreenState & ~1) + 2) | isOff; 90728ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten } 90828ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten } 909799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin return final_result; 91065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 91165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 91265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // hold a strong ref on thread in case closeOutput() or closeInput() is called 91365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // and the thread is exited once the lock is released 91465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<ThreadBase> thread; 91565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { 91665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 91765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian thread = checkPlaybackThread_l(ioHandle); 918d5903ec1332630f2992a6f0d5ca69d13a185c665Glenn Kasten if (thread == 0) { 91965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian thread = checkRecordThread_l(ioHandle); 9207fc9a6fdf146ded90b51c52f4a05d797294dcb85Glenn Kasten } else if (thread == primaryPlaybackThread_l()) { 9217c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // indicate output device change to all input threads for pre processing 9227c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent AudioParameter param = AudioParameter(keyValuePairs); 9237c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int value; 92489d94e79dad032fb18ddc655e6068e4231d3f0aaEric Laurent if ((param.getInt(String8(AudioParameter::keyRouting), value) == NO_ERROR) && 92589d94e79dad032fb18ddc655e6068e4231d3f0aaEric Laurent (value != 0)) { 9267c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 9277c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent mRecordThreads.valueAt(i)->setParameters(keyValuePairs); 9287c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 9297c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 93065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 93165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 9327378ca506e4e20c2b2d4e94a131cf1b95831adb5Glenn Kasten if (thread != 0) { 9337378ca506e4e20c2b2d4e94a131cf1b95831adb5Glenn Kasten return thread->setParameters(keyValuePairs); 93465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 93565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 93665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 93765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 93872ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn KastenString8 AudioFlinger::getParameters(audio_io_handle_t ioHandle, const String8& keys) const 93965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 940827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ALOGVV("getParameters() io %d, keys %s, calling pid %d", 941827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ioHandle, keys.string(), IPCThreadState::self()->getCallingPid()); 94265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 943a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent Mutex::Autolock _l(mLock); 944a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent 94565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (ioHandle == 0) { 946fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin String8 out_s8; 947fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 948799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 9498abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten char *s; 9508abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten { 9518abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten AutoMutex lock(mHardwareLock); 9528abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten mHardwareStatus = AUDIO_HW_GET_PARAMETER; 953a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice(); 9548abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten s = dev->get_parameters(dev, keys.string()); 9558abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten mHardwareStatus = AUDIO_HW_IDLE; 9568abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten } 957ef7740be67a4d7b6b033ebed59c3d4a9c74a2c18John Grossman out_s8 += String8(s ? s : ""); 958799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin free(s); 959799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin } 960fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return out_s8; 96165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 96265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 96365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *playbackThread = checkPlaybackThread_l(ioHandle); 96465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (playbackThread != NULL) { 96565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return playbackThread->getParameters(keys); 96665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 96765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian RecordThread *recordThread = checkRecordThread_l(ioHandle); 96865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (recordThread != NULL) { 96965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return recordThread->getParameters(keys); 97065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 97165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return String8(""); 97265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 97365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 974dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kastensize_t AudioFlinger::getInputBufferSize(uint32_t sampleRate, audio_format_t format, 975dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten audio_channel_mask_t channelMask) const 97665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 977a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 978a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 979a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return 0; 980a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 981a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent 9822b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten AutoMutex lock(mHardwareLock); 9832b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten mHardwareStatus = AUDIO_HW_GET_INPUT_BUFFER_SIZE; 984f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent struct audio_config config = { 985f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent sample_rate: sampleRate, 986dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten channel_mask: channelMask, 987f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent format: format, 988f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent }; 989ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); 990ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman size_t size = dev->get_input_buffer_size(dev, &config); 9912b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten mHardwareStatus = AUDIO_HW_IDLE; 9922b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten return size; 99365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 99465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 99572ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenunsigned int AudioFlinger::getInputFramesLost(audio_io_handle_t ioHandle) const 99665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 99765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 99865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 99965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian RecordThread *recordThread = checkRecordThread_l(ioHandle); 100065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (recordThread != NULL) { 100165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return recordThread->getInputFramesLost(); 100265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 100365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 100465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 100565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 100665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::setVoiceVolume(float value) 100765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1008a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 1009a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 1010a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return ret; 1011a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 1012a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent 101365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 101465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 101565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 101665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 101765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 101865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mHardwareLock); 1019ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); 10208abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten mHardwareStatus = AUDIO_HW_SET_VOICE_VOLUME; 1021ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman ret = dev->set_voice_volume(dev, value); 102265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_IDLE; 102365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 102465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return ret; 102565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 102665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 102726c77556efc30800466b60b3975bc35a70c8c28bGlenn Kastenstatus_t AudioFlinger::getRenderPosition(size_t *halFrames, size_t *dspFrames, 102872ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten audio_io_handle_t output) const 102965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 103065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t status; 103165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 103265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 103365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 103465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *playbackThread = checkPlaybackThread_l(output); 103565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (playbackThread != NULL) { 103665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return playbackThread->getRenderPosition(halFrames, dspFrames); 103765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 103865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 103965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 104065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 104165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 104265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioFlinger::registerClient(const sp<IAudioFlingerClient>& client) 104365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 104465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 104565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 104665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1047bb001926447d0b7dc71ca8bb3c9856f3136d8f4cGlenn Kasten pid_t pid = IPCThreadState::self()->getCallingPid(); 104865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mNotificationClients.indexOfKey(pid) < 0) { 104965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<NotificationClient> notificationClient = new NotificationClient(this, 105065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian client, 105165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian pid); 10523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("registerClient() client %p, pid %d", notificationClient.get(), pid); 105365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 105465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mNotificationClients.add(pid, notificationClient); 105565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 105665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<IBinder> binder = client->asBinder(); 105765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian binder->linkToDeath(notificationClient); 105865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 105965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // the config change is always sent from playback or record threads to avoid deadlock 106065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // with AudioSystem::gLock 106165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 1062896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AudioSystem::OUTPUT_OPENED); 106365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 106465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 106565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < mRecordThreads.size(); i++) { 1066896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent mRecordThreads.valueAt(i)->sendIoConfigEvent(AudioSystem::INPUT_OPENED); 106765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 106865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 106965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 107065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 107165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioFlinger::removeNotificationClient(pid_t pid) 107265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 107365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 107465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1075a3b09254d44cd8d66ec947abe547538c4cfeaa89Glenn Kasten mNotificationClients.removeItem(pid); 10763a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen 10773856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("%d died, releasing its sessions", pid); 10788d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten size_t num = mAudioSessionRefs.size(); 10793a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen bool removed = false; 10808d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten for (size_t i = 0; i< num; ) { 10813a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen AudioSessionRef *ref = mAudioSessionRefs.itemAt(i); 1082012ca6b4f69fb24385025c0e84b8f816525a3032Glenn Kasten ALOGV(" pid %d @ %d", ref->mPid, i); 1083012ca6b4f69fb24385025c0e84b8f816525a3032Glenn Kasten if (ref->mPid == pid) { 1084012ca6b4f69fb24385025c0e84b8f816525a3032Glenn Kasten ALOGV(" removing entry for pid %d session %d", pid, ref->mSessionid); 10853a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen mAudioSessionRefs.removeAt(i); 10863a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen delete ref; 10873a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen removed = true; 10883a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen num--; 10898d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten } else { 10908d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten i++; 10913a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen } 10923a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen } 10933a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen if (removed) { 10943a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen purgeStaleEffects_l(); 10953a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen } 109665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 109765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 109865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// audioConfigChanged_l() must be called with AudioFlinger::mLock held 1099b81cc8c6f3eec9edb255ea99b6a6f243585b1e38Glenn Kastenvoid AudioFlinger::audioConfigChanged_l(int event, audio_io_handle_t ioHandle, const void *param2) 110065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 110165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian size_t size = mNotificationClients.size(); 110265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < size; i++) { 110384afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, ioHandle, 110484afa3b51ac48f84ed62489529ce78cba7fca00eGlenn Kasten param2); 110565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 110665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 110765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 110865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// removeClient_l() must be called with AudioFlinger::mLock held 110965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioFlinger::removeClient_l(pid_t pid) 111065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1111827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ALOGV("removeClient_l() pid %d, calling pid %d", pid, 111285ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten IPCThreadState::self()->getCallingPid()); 111365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mClients.removeItem(pid); 111465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 111565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1116717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent// getEffectThread_l() must be called with AudioFlinger::mLock held 1117717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurentsp<AudioFlinger::PlaybackThread> AudioFlinger::getEffectThread_l(int sessionId, int EffectId) 1118717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent{ 1119717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent sp<PlaybackThread> thread; 1120717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent 1121717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 1122717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent if (mPlaybackThreads.valueAt(i)->getEffect(sessionId, EffectId) != 0) { 1123717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent ALOG_ASSERT(thread == 0); 1124717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent thread = mPlaybackThreads.valueAt(i); 1125717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent } 1126717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent } 1127717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent 1128717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent return thread; 1129717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent} 113065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 113181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 113281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 113365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 113465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 113581784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::Client::Client(const sp<AudioFlinger>& audioFlinger, pid_t pid) 113681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent : RefBase(), 113781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioFlinger(audioFlinger), 113881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // FIXME should be a "k" constant not hard-coded, in .h or ro. property, see 4 lines below 113981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mMemoryDealer(new MemoryDealer(1024*1024, "AudioFlinger::Client")), 114081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPid(pid), 114181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mTimedTrackCount(0) 114265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 114381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // 1 MB of address space is good for 32 tracks, 8 buffers each, 4 KB/buffer 114465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 114565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 114681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// Client destructor must be called with AudioFlinger::mLock held 114781784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::Client::~Client() 114865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 114981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioFlinger->removeClient_l(mPid); 115065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 115165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 115281784c37c61b09289654b979567a42bf73cd2b12Eric Laurentsp<MemoryDealer> AudioFlinger::Client::heap() const 115365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 115481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return mMemoryDealer; 115565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 115665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 115781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// Reserve one of the limited slots for a timed audio track associated 115881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// with this client 115981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentbool AudioFlinger::Client::reserveTimedTrack() 116065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 116181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent const int kMaxTimedTracksPerClient = 4; 116265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 116381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mTimedTrackLock); 116465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 116581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (mTimedTrackCount >= kMaxTimedTracksPerClient) { 116681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("can not create timed track - pid %d has exceeded the limit", 116781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPid); 116881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return false; 116965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 117065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 117181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mTimedTrackCount++; 117281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return true; 117365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 117465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 117581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// Release a slot for a timed audio track 117681784c37c61b09289654b979567a42bf73cd2b12Eric Laurentvoid AudioFlinger::Client::releaseTimedTrack() 117765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 117881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mTimedTrackLock); 117981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mTimedTrackCount--; 1180896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent} 1181896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent 118281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 118381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 118481784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::NotificationClient::NotificationClient(const sp<AudioFlinger>& audioFlinger, 118581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent const sp<IAudioFlingerClient>& client, 118681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid_t pid) 118781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent : mAudioFlinger(audioFlinger), mPid(pid), mAudioFlingerClient(client) 1188896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent{ 118965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 119065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 119181784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::NotificationClient::~NotificationClient() 119265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 119365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 119465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 119581784c37c61b09289654b979567a42bf73cd2b12Eric Laurentvoid AudioFlinger::NotificationClient::binderDied(const wp<IBinder>& who) 119665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 119781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<NotificationClient> keep(this); 119881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioFlinger->removeNotificationClient(mPid); 119981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent} 120065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 120165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 120281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 120365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 120481784c37c61b09289654b979567a42bf73cd2b12Eric Laurentsp<IAudioRecord> AudioFlinger::openRecord( 120581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t input, 120681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t sampleRate, 120781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_format_t format, 120881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_channel_mask_t channelMask, 120981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t frameCount, 121081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent IAudioFlinger::track_flags_t flags, 121181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid_t tid, 121281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int *sessionId, 121381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t *status) 12141d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent{ 121581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<RecordThread::RecordTrack> recordTrack; 121681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<RecordHandle> recordHandle; 121781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<Client> client; 121881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t lStatus; 121981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent RecordThread *thread; 122081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t inFrameCount; 122181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int lSessionId; 12221d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent 122381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // check calling permissions 122481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (!recordingAllowed()) { 122581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = PERMISSION_DENIED; 122681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 122781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 12281d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent 122981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // add client to list 123081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent { // scope for mLock 123181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 123281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = checkRecordThread_l(input); 123381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 123481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 123581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 12361d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent } 12371d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent 12388d6cc842e8d525405c68e57fdf3bc5da0b4d7e87Glenn Kasten pid_t pid = IPCThreadState::self()->getCallingPid(); 123981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent client = registerPid_l(pid); 1240feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 124181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If no audio session id is provided, create one here 124281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId != NULL && *sessionId != AUDIO_SESSION_OUTPUT_MIX) { 124381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lSessionId = *sessionId; 1244feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent } else { 124581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lSessionId = nextUniqueId(); 124681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId != NULL) { 124781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *sessionId = lSessionId; 124881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 1249feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent } 125081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // create new record track. 125181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // The record track uses one track in mHardwareMixerThread by convention. 125281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent recordTrack = thread->createRecordTrack_l(client, sampleRate, format, channelMask, 125381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent frameCount, lSessionId, flags, tid, &lStatus); 1254feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent } 125581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (lStatus != NO_ERROR) { 125681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // remove local strong reference to Client before deleting the RecordTrack so that the 125781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Client destructor is called by the TrackBase destructor with mLock held 125881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent client.clear(); 125981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent recordTrack.clear(); 126081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 1261feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent } 1262feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 126381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // return to handle to client 126481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent recordHandle = new RecordHandle(recordTrack); 126581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = NO_ERROR; 1266feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 126781784c37c61b09289654b979567a42bf73cd2b12Eric LaurentExit: 126881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (status) { 126981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *status = lStatus; 1270feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent } 127181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return recordHandle; 1272feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent} 1273feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 1274feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 12751d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent 127681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 127781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 127881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_module_handle_t AudioFlinger::loadHwModule(const char *name) 127959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent{ 128081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (!settingsAllowed()) { 128181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 128281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 128359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent Mutex::Autolock _l(mLock); 128481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return loadHwModule_l(name); 128559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent} 128659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 128781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// loadHwModule_l() must be called with AudioFlinger::mLock held 128881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_module_handle_t AudioFlinger::loadHwModule_l(const char *name) 128959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent{ 129081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 129181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (strncmp(mAudioHwDevs.valueAt(i)->moduleName(), name, strlen(name)) == 0) { 129281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("loadHwModule() module %s already loaded", name); 129381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return mAudioHwDevs.keyAt(i); 129459255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 129559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 129659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 129781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_hw_device_t *dev; 129859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 129981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int rc = load_audio_interface(name, &dev); 130081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (rc) { 130181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGI("loadHwModule() error %d loading module %s ", rc, name); 130281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 130359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 130459255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 130581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_INIT; 130681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent rc = dev->init_check(dev); 130781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 130881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (rc) { 130981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGI("loadHwModule() init check error %d for module %s ", rc, name); 131081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 131159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 131259255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 131381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Check and cache this HAL's level of support for master mute and master 131481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // volume. If this is the first HAL opened, and it supports the get 131581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // methods, use the initial values provided by the HAL as the current 131681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // master mute and volume settings. 131759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 131881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioHwDevice::Flags flags = static_cast<AudioHwDevice::Flags>(0); 131981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent { // scope for auto-lock pattern 132081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AutoMutex lock(mHardwareLock); 132159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 132281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (0 == mAudioHwDevs.size()) { 132381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_GET_MASTER_VOLUME; 132481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (NULL != dev->get_master_volume) { 132581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent float mv; 132681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (OK == dev->get_master_volume(dev, &mv)) { 132781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mMasterVolume = mv; 132881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 132981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 133081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 133181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_GET_MASTER_MUTE; 133281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (NULL != dev->get_master_mute) { 133381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool mm; 133481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (OK == dev->get_master_mute(dev, &mm)) { 133581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mMasterMute = mm; 133681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 133781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 133859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 133981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 134081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME; 134181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if ((NULL != dev->set_master_volume) && 134281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (OK == dev->set_master_volume(dev, mMasterVolume))) { 134381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent flags = static_cast<AudioHwDevice::Flags>(flags | 134481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioHwDevice::AHWD_CAN_SET_MASTER_VOLUME); 134559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 134659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 134781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE; 134881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if ((NULL != dev->set_master_mute) && 134981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (OK == dev->set_master_mute(dev, mMasterMute))) { 135081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent flags = static_cast<AudioHwDevice::Flags>(flags | 135181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioHwDevice::AHWD_CAN_SET_MASTER_MUTE); 135281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 135359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 135481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 135559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 135659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 135781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_module_handle_t handle = nextUniqueId(); 135881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioHwDevs.add(handle, new AudioHwDevice(name, dev, flags)); 135981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 136081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGI("loadHwModule() Loaded %s audio interface from %s (%s) handle %d", 136181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent name, dev->common.module->name, dev->common.module->id, handle); 136281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 136381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return handle; 136481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 136559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent} 136659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 136781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 136881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 136981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentuint32_t AudioFlinger::getPrimaryOutputSamplingRate() 137059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent{ 137159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent Mutex::Autolock _l(mLock); 137281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = primaryPlaybackThread_l(); 137381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread != NULL ? thread->sampleRate() : 0; 1374a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3Eric Laurent} 137559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 137681784c37c61b09289654b979567a42bf73cd2b12Eric Laurentsize_t AudioFlinger::getPrimaryOutputFrameCount() 1377a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3Eric Laurent{ 137881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 137981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = primaryPlaybackThread_l(); 138081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread != NULL ? thread->frameCountHAL() : 0; 138159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent} 138259255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 138365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 138465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 138581784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_io_handle_t AudioFlinger::openOutput(audio_module_handle_t module, 138681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_devices_t *pDevices, 138781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t *pSamplingRate, 138881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_format_t *pFormat, 138981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_channel_mask_t *pChannelMask, 139081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t *pLatencyMs, 139181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_output_flags_t flags) 139265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 139381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t status; 139481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = NULL; 139581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent struct audio_config config = { 139681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sample_rate: pSamplingRate ? *pSamplingRate : 0, 139781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent channel_mask: pChannelMask ? *pChannelMask : 0, 139881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent format: pFormat ? *pFormat : AUDIO_FORMAT_DEFAULT, 139981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent }; 140081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_stream_out_t *outStream = NULL; 140181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioHwDevice *outHwDev; 1402ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman 140381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("openOutput(), module %d Device %x, SamplingRate %d, Format %d, Channels %x, flags %x", 140481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent module, 140581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (pDevices != NULL) ? *pDevices : 0, 140681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent config.sample_rate, 140781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent config.format, 140881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent config.channel_mask, 140981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent flags); 141081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 141181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pDevices == NULL || *pDevices == 0) { 141281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 1413ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman } 1414ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman 141581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 141665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 141781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent outHwDev = findSuitableHwDev_l(module, *pDevices); 141881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (outHwDev == NULL) 141981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 142065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 142181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_hw_device_t *hwDevHal = outHwDev->hwDevice(); 142281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t id = nextUniqueId(); 142365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 142481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_OUTPUT_OPEN; 142565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 142681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status = hwDevHal->open_output_stream(hwDevHal, 142781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent id, 142881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *pDevices, 142981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (audio_output_flags_t)flags, 143081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent &config, 143181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent &outStream); 143265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 143381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 143481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("openOutput() openOutputStream returned output %p, SamplingRate %d, Format %d, " 143581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent "Channels %x, status %d", 143681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent outStream, 143781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent config.sample_rate, 143881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent config.format, 143981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent config.channel_mask, 144081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status); 144158912562617941964939a4182cda71eaeb153d4bGlenn Kasten 144281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (status == NO_ERROR && outStream != NULL) { 144381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioStreamOut *output = new AudioStreamOut(outHwDev, outStream); 144465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 144581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if ((flags & AUDIO_OUTPUT_FLAG_DIRECT) || 144681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (config.format != AUDIO_FORMAT_PCM_16_BIT) || 144781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (config.channel_mask != AUDIO_CHANNEL_OUT_STEREO)) { 144881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = new DirectOutputThread(this, output, id, *pDevices); 144981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("openOutput() created direct output: ID %d thread %p", id, thread); 145081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else { 145181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = new MixerThread(this, output, id, *pDevices); 145281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("openOutput() created mixer output: ID %d thread %p", id, thread); 145365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 145481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPlaybackThreads.add(id, thread); 145588cbea8a918bbaf5e06e48aadd5af5e81d58d232Glenn Kasten 145681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pSamplingRate != NULL) *pSamplingRate = config.sample_rate; 145781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pFormat != NULL) *pFormat = config.format; 145881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pChannelMask != NULL) *pChannelMask = config.channel_mask; 145981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pLatencyMs != NULL) *pLatencyMs = thread->latency(); 146065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 146181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // notify client processes of the new output creation 146281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->audioConfigChanged_l(AudioSystem::OUTPUT_OPENED); 146365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 146481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // the first primary output opened designates the primary hw device 146581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if ((mPrimaryHardwareDev == NULL) && (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) { 146681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGI("Using module %d has the primary audio interface", module); 146781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPrimaryHardwareDev = outHwDev; 146881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 146981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AutoMutex lock(mHardwareLock); 147081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_SET_MODE; 147181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent hwDevHal->set_mode(hwDevHal, mMode); 147281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 147381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 147481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return id; 147581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 147665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 147781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 147865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 147965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 148081784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_io_handle_t AudioFlinger::openDuplicateOutput(audio_io_handle_t output1, 148181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t output2) 148265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 148381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 148481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent MixerThread *thread1 = checkMixerThread_l(output1); 148581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent MixerThread *thread2 = checkMixerThread_l(output2); 148681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 148781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread1 == NULL || thread2 == NULL) { 148881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("openDuplicateOutput() wrong output mixer type for output %d or %d", output1, 148981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent output2); 149081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 149165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 149265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 149381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t id = nextUniqueId(); 149481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent DuplicatingThread *thread = new DuplicatingThread(this, thread1, id); 149581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->addOutputTrack(thread2); 149681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPlaybackThreads.add(id, thread); 149781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // notify client processes of the new output creation 149881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->audioConfigChanged_l(AudioSystem::OUTPUT_OPENED); 149981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return id; 150065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 150165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 150281784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::closeOutput(audio_io_handle_t output) 15032bfc6b42b3733c12485dd51ed95191956abc3e4eJean-Michel Trivi{ 150481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return closeOutput_nonvirtual(output); 15052bfc6b42b3733c12485dd51ed95191956abc3e4eJean-Michel Trivi} 15062bfc6b42b3733c12485dd51ed95191956abc3e4eJean-Michel Trivi 150781784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output) 150865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 150981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // keep strong reference on the playback thread so that 151081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // it is not destroyed while exit() is executed 151181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<PlaybackThread> thread; 151281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent { 151381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 151481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = checkPlaybackThread_l(output); 151581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 151681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 151765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 151865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 151981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("closeOutput() %d", output); 1520de070137f11d346fba77605bd76a44c040a618fcEric Laurent 152181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread->type() == ThreadBase::MIXER) { 152281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 152381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (mPlaybackThreads.valueAt(i)->type() == ThreadBase::DUPLICATING) { 152481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent DuplicatingThread *dupThread = 152581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (DuplicatingThread *)mPlaybackThreads.valueAt(i).get(); 152681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent dupThread->removeOutputTrack((MixerThread *)thread.get()); 1527de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 1528de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 1529de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 153081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audioConfigChanged_l(AudioSystem::OUTPUT_CLOSED, output, NULL); 153181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPlaybackThreads.removeItem(output); 15323acbd053c842e76e1a40fc8a0bf62de87eebf00fGlenn Kasten } 153381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->exit(); 153481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // The thread entity (active unit of execution) is no longer running here, 153581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // but the ThreadBase container still exists. 15363acbd053c842e76e1a40fc8a0bf62de87eebf00fGlenn Kasten 153781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread->type() != ThreadBase::DUPLICATING) { 153881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioStreamOut *out = thread->clearOutput(); 153981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOG_ASSERT(out != NULL, "out shouldn't be NULL"); 154081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // from now on thread->mOutput is NULL 154181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent out->hwDev()->close_output_stream(out->hwDev(), out->stream); 154281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent delete out; 154365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 154481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 154565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 154665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 154781784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::suspendOutput(audio_io_handle_t output) 1548e737cda649acbfa43fc1b74612a83f2fac9aa449Eric Laurent{ 154981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 155081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = checkPlaybackThread_l(output); 155181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 155281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 155381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 1554e737cda649acbfa43fc1b74612a83f2fac9aa449Eric Laurent } 1555e737cda649acbfa43fc1b74612a83f2fac9aa449Eric Laurent 155681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("suspendOutput() %d", output); 155781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->suspend(); 1558e737cda649acbfa43fc1b74612a83f2fac9aa449Eric Laurent 155981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 156065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 156165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 156281784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::restoreOutput(audio_io_handle_t output) 156365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 15646637baae4244aec731c4014da72418d330636ae1Glenn Kasten Mutex::Autolock _l(mLock); 156581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = checkPlaybackThread_l(output); 156665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 156781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 156881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 1569ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman } 157065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 157181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("restoreOutput() %d", output); 157265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 157381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->restore(); 157465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 157581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 157665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 157765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 157881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_io_handle_t AudioFlinger::openInput(audio_module_handle_t module, 157981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_devices_t *pDevices, 158081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t *pSamplingRate, 158181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_format_t *pFormat, 158281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_channel_mask_t *pChannelMask) 158365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 158481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t status; 158581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent RecordThread *thread = NULL; 158681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent struct audio_config config = { 158781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sample_rate: pSamplingRate ? *pSamplingRate : 0, 158881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent channel_mask: pChannelMask ? *pChannelMask : 0, 158981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent format: pFormat ? *pFormat : AUDIO_FORMAT_DEFAULT, 159081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent }; 159181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t reqSamplingRate = config.sample_rate; 159281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_format_t reqFormat = config.format; 159381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_channel_mask_t reqChannels = config.channel_mask; 159481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_stream_in_t *inStream = NULL; 159581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioHwDevice *inHwDev; 159665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 159781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pDevices == NULL || *pDevices == 0) { 159881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 1599b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent } 1600b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent 160181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 160265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 160381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent inHwDev = findSuitableHwDev_l(module, *pDevices); 160481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (inHwDev == NULL) 160581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 1606fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 160781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_hw_device_t *inHwHal = inHwDev->hwDevice(); 160881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t id = nextUniqueId(); 1609b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent 161081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status = inHwHal->open_input_stream(inHwHal, id, *pDevices, &config, 161181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent &inStream); 161281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("openInput() openInputStream returned input %p, SamplingRate %d, Format %d, Channels %x, " 161381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent "status %d", 161481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent inStream, 161581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent config.sample_rate, 161681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent config.format, 161781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent config.channel_mask, 161881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status); 161965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 162081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If the input could not be opened with the requested parameters and we can handle the 162181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // conversion internally, try to open again with the proposed parameters. The AudioFlinger can 162281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // resample the input and do mono to stereo or stereo to mono conversions on 16 bit PCM inputs. 162381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (status == BAD_VALUE && 162481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent reqFormat == config.format && config.format == AUDIO_FORMAT_PCM_16_BIT && 162581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (config.sample_rate <= 2 * reqSamplingRate) && 162681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (popcount(config.channel_mask) <= FCC_2) && (popcount(reqChannels) <= FCC_2)) { 162781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("openInput() reopening with proposed sampling rate and channel mask"); 162881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent inStream = NULL; 162981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status = inHwHal->open_input_stream(inHwHal, id, *pDevices, &config, &inStream); 163065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 163165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 163281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (status == NO_ERROR && inStream != NULL) { 163358912562617941964939a4182cda71eaeb153d4bGlenn Kasten 163446909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 163581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Try to re-use most recently used Pipe to archive a copy of input for dumpsys, 163681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // or (re-)create if current Pipe is idle and does not match the new format 163781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<NBAIO_Sink> teeSink; 163881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent enum { 163981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent TEE_SINK_NO, // don't copy input 164081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent TEE_SINK_NEW, // copy input using a new pipe 164181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent TEE_SINK_OLD, // copy input using an existing pipe 164281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } kind; 164381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent NBAIO_Format format = Format_from_SR_C(inStream->common.get_sample_rate(&inStream->common), 164481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent popcount(inStream->common.get_channels(&inStream->common))); 1645da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (!mTeeSinkInputEnabled) { 1646da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten kind = TEE_SINK_NO; 1647da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } else if (format == Format_Invalid) { 164881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_NO; 164981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else if (mRecordTeeSink == 0) { 165081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_NEW; 165181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else if (mRecordTeeSink->getStrongCount() != 1) { 165281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_NO; 165381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else if (format == mRecordTeeSink->format()) { 165481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_OLD; 16554adcede0dc54a85c31abaf139921aebd7a072d8eGlenn Kasten } else { 165681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_NEW; 165781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 165881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent switch (kind) { 165981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent case TEE_SINK_NEW: { 1660da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten Pipe *pipe = new Pipe(mTeeSinkInputFrames, format); 166181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t numCounterOffers = 0; 166281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent const NBAIO_Format offers[1] = {format}; 166381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ssize_t index = pipe->negotiate(offers, 1, NULL, numCounterOffers); 166481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOG_ASSERT(index == 0); 166581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PipeReader *pipeReader = new PipeReader(*pipe); 166681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent numCounterOffers = 0; 166781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent index = pipeReader->negotiate(offers, 1, NULL, numCounterOffers); 166881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOG_ASSERT(index == 0); 166981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mRecordTeeSink = pipe; 167081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mRecordTeeSource = pipeReader; 167181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent teeSink = pipe; 16724adcede0dc54a85c31abaf139921aebd7a072d8eGlenn Kasten } 167381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 167481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent case TEE_SINK_OLD: 167581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent teeSink = mRecordTeeSink; 167681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 167781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent case TEE_SINK_NO: 167881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent default: 167981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 168058912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 168146909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 1682da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 168381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioStreamIn *input = new AudioStreamIn(inHwDev, inStream); 168465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 168581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Start record thread 168681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // RecorThread require both input and output device indication to forward to audio 168781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // pre processing modules 168881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = new RecordThread(this, 168981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent input, 169081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent reqSamplingRate, 169181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent reqChannels, 169281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent id, 1693d3922f72601d82c6fc067a98916fda0bd1291c5fEric Laurent primaryOutputDevice_l(), 169446909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten *pDevices 169546909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 169646909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten , teeSink 169746909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 169846909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten ); 169981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mRecordThreads.add(id, thread); 170081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("openInput() created record thread: ID %d thread %p", id, thread); 170181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pSamplingRate != NULL) *pSamplingRate = reqSamplingRate; 170281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pFormat != NULL) *pFormat = config.format; 170381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pChannelMask != NULL) *pChannelMask = reqChannels; 170465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 170581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // notify client processes of the new input creation 170681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->audioConfigChanged_l(AudioSystem::INPUT_OPENED); 170781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return id; 17081afc26db11b71c43f63a0f72a45a803f1a7910ddEric Laurent } 170981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 171081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 171165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 171265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 171381784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::closeInput(audio_io_handle_t input) 171465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 171581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return closeInput_nonvirtual(input); 171665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 171765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 171881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::closeInput_nonvirtual(audio_io_handle_t input) 1719de070137f11d346fba77605bd76a44c040a618fcEric Laurent{ 172081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // keep strong reference on the record thread so that 172181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // it is not destroyed while exit() is executed 172281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<RecordThread> thread; 172381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent { 172481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 172581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = checkRecordThread_l(input); 172681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == 0) { 172781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 1728de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 172981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 173081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("closeInput() %d", input); 173181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audioConfigChanged_l(AudioSystem::INPUT_CLOSED, input, NULL); 173281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mRecordThreads.removeItem(input); 1733de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 173481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->exit(); 173581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // The thread entity (active unit of execution) is no longer running here, 173681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // but the ThreadBase container still exists. 1737de070137f11d346fba77605bd76a44c040a618fcEric Laurent 173881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioStreamIn *in = thread->clearInput(); 173981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOG_ASSERT(in != NULL, "in shouldn't be NULL"); 174081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // from now on thread->mInput is NULL 174181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent in->hwDev()->close_input_stream(in->hwDev(), in->stream); 174281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent delete in; 174365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 174481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 1745b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent} 1746b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent 174781784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) 1748b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent{ 1749b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent Mutex::Autolock _l(mLock); 175081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("setStreamOutput() stream %d to output %d", stream, output); 1751b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent 175281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 175381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = mPlaybackThreads.valueAt(i).get(); 175481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->invalidateTracks(stream); 1755b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent } 175681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 175781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 1758b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent} 1759b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent 176081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 176181784c37c61b09289654b979567a42bf73cd2b12Eric Laurentint AudioFlinger::newAudioSessionId() 1762162b40bbaf3c3a24f61a6636bef6f80a9c0a31ddEric Laurent{ 176381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return nextUniqueId(); 1764162b40bbaf3c3a24f61a6636bef6f80a9c0a31ddEric Laurent} 1765162b40bbaf3c3a24f61a6636bef6f80a9c0a31ddEric Laurent 176681784c37c61b09289654b979567a42bf73cd2b12Eric Laurentvoid AudioFlinger::acquireAudioSessionId(int audioSession) 1767a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent{ 1768a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent Mutex::Autolock _l(mLock); 176981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid_t caller = IPCThreadState::self()->getCallingPid(); 177081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("acquiring %d from %d", audioSession, caller); 177181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t num = mAudioSessionRefs.size(); 177281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i< num; i++) { 177381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSessionRef *ref = mAudioSessionRefs.editItemAt(i); 177481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ref->mSessionid == audioSession && ref->mPid == caller) { 177581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ref->mCnt++; 177681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV(" incremented refcount to %d", ref->mCnt); 177781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return; 1778a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 1779a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 178081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioSessionRefs.push(new AudioSessionRef(audioSession, caller)); 178181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV(" added new entry for %d", audioSession); 1782a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent} 1783a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent 178481784c37c61b09289654b979567a42bf73cd2b12Eric Laurentvoid AudioFlinger::releaseAudioSessionId(int audioSession) 178544a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent{ 178681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 178781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid_t caller = IPCThreadState::self()->getCallingPid(); 178881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("releasing %d from %d", audioSession, caller); 178981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t num = mAudioSessionRefs.size(); 179081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i< num; i++) { 179181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSessionRef *ref = mAudioSessionRefs.itemAt(i); 179281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ref->mSessionid == audioSession && ref->mPid == caller) { 179381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ref->mCnt--; 179481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV(" decremented refcount to %d", ref->mCnt); 179581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ref->mCnt == 0) { 179681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioSessionRefs.removeAt(i); 179781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent delete ref; 179881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent purgeStaleEffects_l(); 179944a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent } 180081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return; 180144a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent } 180244a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent } 180381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("session id %d not found for pid %d", audioSession, caller); 180444a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent} 180544a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent 180681784c37c61b09289654b979567a42bf73cd2b12Eric Laurentvoid AudioFlinger::purgeStaleEffects_l() { 180765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 180881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("purging stale effects"); 1809fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten 181081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Vector< sp<EffectChain> > chains; 181158912562617941964939a4182cda71eaeb153d4bGlenn Kasten 181281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 181381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<PlaybackThread> t = mPlaybackThreads.valueAt(i); 181481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t j = 0; j < t->mEffectChains.size(); j++) { 181581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> ec = t->mEffectChains[j]; 181681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ec->sessionId() > AUDIO_SESSION_OUTPUT_MIX) { 181781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent chains.push(ec); 181881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 1819c15d6657a17d7cef91f800f40d11760e2e7340afGlenn Kasten } 182058912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 182181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 182281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<RecordThread> t = mRecordThreads.valueAt(i); 182381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t j = 0; j < t->mEffectChains.size(); j++) { 182481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> ec = t->mEffectChains[j]; 182581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent chains.push(ec); 182681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 1827300a2ee9327c05fbf9d3a5fd595b558097c7c5e8Glenn Kasten } 182865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 182981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < chains.size(); i++) { 183081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> ec = chains[i]; 183181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int sessionid = ec->sessionId(); 183281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<ThreadBase> t = ec->mThread.promote(); 183381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (t == 0) { 183481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent continue; 183581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 183681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t numsessionrefs = mAudioSessionRefs.size(); 183781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool found = false; 183881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t k = 0; k < numsessionrefs; k++) { 183981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSessionRef *ref = mAudioSessionRefs.itemAt(k); 184081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ref->mSessionid == sessionid) { 184181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV(" session %d still exists for %d with %d refs", 184281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionid, ref->mPid, ref->mCnt); 184381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent found = true; 184481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 184558912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 184658912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 184781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (!found) { 184881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l (t->mLock); 184981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // remove all effects from the chain 185081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent while (ec->mEffects.size()) { 185181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectModule> effect = ec->mEffects[0]; 185281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect->unPin(); 185381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent t->removeEffect_l(effect); 185481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (effect->purgeHandles()) { 185581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent t->checkSuspendOnEffectEnabled_l(effect, false, effect->sessionId()); 185681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 185781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSystem::unregisterEffect(effect->id()); 185881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 1859c15d6657a17d7cef91f800f40d11760e2e7340afGlenn Kasten } 186058912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 186181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return; 186265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 186365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 186481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// checkPlaybackThread_l() must be called with AudioFlinger::mLock held 186581784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::PlaybackThread *AudioFlinger::checkPlaybackThread_l(audio_io_handle_t output) const 1866190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten{ 186781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return mPlaybackThreads.valueFor(output).get(); 1868190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten} 1869190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten 187081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// checkMixerThread_l() must be called with AudioFlinger::mLock held 187181784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::MixerThread *AudioFlinger::checkMixerThread_l(audio_io_handle_t output) const 187281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent{ 187381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = checkPlaybackThread_l(output); 187481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread != NULL && thread->type() != ThreadBase::DIRECT ? (MixerThread *) thread : NULL; 187581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent} 1876190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten 187781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// checkRecordThread_l() must be called with AudioFlinger::mLock held 187881784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::RecordThread *AudioFlinger::checkRecordThread_l(audio_io_handle_t input) const 187981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent{ 188081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return mRecordThreads.valueFor(input).get(); 188181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent} 1882190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten 188381784c37c61b09289654b979567a42bf73cd2b12Eric Laurentuint32_t AudioFlinger::nextUniqueId() 188481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent{ 188581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return android_atomic_inc(&mNextUniqueId); 188681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent} 188783efdd0fc08cd5aedf50b45741a8a87be8dc4b41Glenn Kasten 188881784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::PlaybackThread *AudioFlinger::primaryPlaybackThread_l() const 188937d825e72a6c606553a745da1212590a425996d3Glenn Kasten{ 189081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 189181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = mPlaybackThreads.valueAt(i).get(); 189281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioStreamOut *output = thread->getOutput(); 189381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (output != NULL && output->audioHwDev == mPrimaryHardwareDev) { 189481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread; 189537d825e72a6c606553a745da1212590a425996d3Glenn Kasten } 189637d825e72a6c606553a745da1212590a425996d3Glenn Kasten } 189781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NULL; 189837d825e72a6c606553a745da1212590a425996d3Glenn Kasten} 189937d825e72a6c606553a745da1212590a425996d3Glenn Kasten 190081784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_devices_t AudioFlinger::primaryOutputDevice_l() const 190165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 190281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = primaryPlaybackThread_l(); 1903000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 190481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 190581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 19069f34a36d9cdb9595c288e50ffe00da038bc8abb9Glenn Kasten } 1907000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 190881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread->outDevice(); 1909000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten} 1910688a64030834ea2f52cc9765676ddf6aa34df767Glenn Kasten 191181784c37c61b09289654b979567a42bf73cd2b12Eric Laurentsp<AudioFlinger::SyncEvent> AudioFlinger::createSyncEvent(AudioSystem::sync_event_t type, 191281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int triggerSession, 191381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int listenerSession, 191481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sync_event_callback_t callBack, 191581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent void *cookie) 191681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent{ 191781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 191873ca0f5837d5448f7a5eb159a09cd0ebe82b4de9Glenn Kasten 191981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<SyncEvent> event = new SyncEvent(type, triggerSession, listenerSession, callBack, cookie); 192081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t playStatus = NAME_NOT_FOUND; 192181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t recStatus = NAME_NOT_FOUND; 192281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 192381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent playStatus = mPlaybackThreads.valueAt(i)->setSyncEvent(event); 192481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (playStatus == NO_ERROR) { 192581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return event; 192681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 192765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 192881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 192981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent recStatus = mRecordThreads.valueAt(i)->setSyncEvent(event); 193081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (recStatus == NO_ERROR) { 193181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return event; 19329f34a36d9cdb9595c288e50ffe00da038bc8abb9Glenn Kasten } 193365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 193481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (playStatus == NAME_NOT_FOUND || recStatus == NAME_NOT_FOUND) { 193581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPendingSyncEvents.add(event); 193681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else { 193781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("createSyncEvent() invalid event %d", event->type()); 193881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent event.clear(); 193981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 194081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return event; 194165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 194265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 194381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 194481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// Effect management 194581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 194658912562617941964939a4182cda71eaeb153d4bGlenn Kasten 194758912562617941964939a4182cda71eaeb153d4bGlenn Kasten 194881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::queryNumberEffects(uint32_t *numEffects) const 1949000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten{ 195081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 195181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return EffectQueryNumberEffects(numEffects); 1952000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten} 1953000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 195481784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::queryEffect(uint32_t index, effect_descriptor_t *descriptor) const 195558912562617941964939a4182cda71eaeb153d4bGlenn Kasten{ 195681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 195781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return EffectQueryEffect(index, descriptor); 195858912562617941964939a4182cda71eaeb153d4bGlenn Kasten} 195958912562617941964939a4182cda71eaeb153d4bGlenn Kasten 196081784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::getEffectDescriptor(const effect_uuid_t *pUuid, 196181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect_descriptor_t *descriptor) const 1962000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten{ 196381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 196481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return EffectGetDescriptor(pUuid, descriptor); 1965000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten} 1966000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 196781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 19688d6cc842e8d525405c68e57fdf3bc5da0b4d7e87Glenn Kastensp<IEffect> AudioFlinger::createEffect( 196981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect_descriptor_t *pDesc, 197081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent const sp<IEffectClient>& effectClient, 197181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int32_t priority, 197281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t io, 197381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int sessionId, 197481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t *status, 197581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int *id, 197681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int *enabled) 1977000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten{ 197881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t lStatus = NO_ERROR; 197981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectHandle> handle; 198081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect_descriptor_t desc; 1981000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 19828d6cc842e8d525405c68e57fdf3bc5da0b4d7e87Glenn Kasten pid_t pid = IPCThreadState::self()->getCallingPid(); 198381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("createEffect pid %d, effectClient %p, priority %d, sessionId %d, io %d", 198481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid, effectClient.get(), priority, sessionId, io); 1985000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 198681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pDesc == NULL) { 198781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 198881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 1989952eeb27682a9b2ddfa761f24b6eb5e18fe5d814Glenn Kasten } 1990000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 199181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // check audio settings permission for global effects 199281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId == AUDIO_SESSION_OUTPUT_MIX && !settingsAllowed()) { 199381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = PERMISSION_DENIED; 199481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 1995952eeb27682a9b2ddfa761f24b6eb5e18fe5d814Glenn Kasten } 1996000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 199781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Session AUDIO_SESSION_OUTPUT_STAGE is reserved for output stage effects 199881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // that can only be created by audio policy manager (running in same process) 199981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId == AUDIO_SESSION_OUTPUT_STAGE && getpid_cached != pid) { 200081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = PERMISSION_DENIED; 200181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 2002952eeb27682a9b2ddfa761f24b6eb5e18fe5d814Glenn Kasten } 200365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 200481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (io == 0) { 200581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId == AUDIO_SESSION_OUTPUT_STAGE) { 200681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // output must be specified by AudioPolicyManager when using session 200781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // AUDIO_SESSION_OUTPUT_STAGE 200881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 200981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 201081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else if (sessionId == AUDIO_SESSION_OUTPUT_MIX) { 201181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // if the output returned by getOutputForEffect() is removed before we lock the 201281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // mutex below, the call to checkPlaybackThread_l(io) below will detect it 201381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // and we will exit safely 201481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent io = AudioSystem::getOutputForEffect(&desc); 201581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 201665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 201765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 201881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent { 201981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 2020288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten 202165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 202281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (!EffectIsNullUuid(&pDesc->uuid)) { 202381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // if uuid is specified, request effect descriptor 202481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = EffectGetDescriptor(&pDesc->uuid, &desc); 202581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (lStatus < 0) { 202681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() error %d from EffectGetDescriptor", lStatus); 202781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 202881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 202981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else { 203081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // if uuid is not specified, look for an available implementation 203181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // of the required type in effect factory 203281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (EffectIsNullUuid(&pDesc->type)) { 203381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() no effect type"); 203481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 203581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 2036288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten } 203781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t numEffects = 0; 203881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect_descriptor_t d; 203981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent d.flags = 0; // prevent compiler warning 204081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool found = false; 2041288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten 204281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = EffectQueryNumberEffects(&numEffects); 204381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (lStatus < 0) { 204481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() error %d from EffectQueryNumberEffects", lStatus); 204581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 204681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 204781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (uint32_t i = 0; i < numEffects; i++) { 204881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = EffectQueryEffect(i, &desc); 204981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (lStatus < 0) { 205081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() error %d from EffectQueryEffect", lStatus); 205181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent continue; 2052d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten } 205381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (memcmp(&desc.type, &pDesc->type, sizeof(effect_uuid_t)) == 0) { 205481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If matching type found save effect descriptor. If the session is 205581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // 0 and the effect is not auxiliary, continue enumeration in case 205681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // an auxiliary version of this effect type is available 205781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent found = true; 205881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent d = desc; 205981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId != AUDIO_SESSION_OUTPUT_MIX || 206081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { 2061d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten break; 2062d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten } 2063d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten } 2064288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten } 206581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (!found) { 206681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 206781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() effect not found"); 206881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 206981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 207081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // For same effect type, chose auxiliary version over insert version if 207181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // connect to output mix (Compliance to OpenSL ES) 207281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId == AUDIO_SESSION_OUTPUT_MIX && 207381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (d.flags & EFFECT_FLAG_TYPE_MASK) != EFFECT_FLAG_TYPE_AUXILIARY) { 207481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent desc = d; 207558912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 207658912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 207758912562617941964939a4182cda71eaeb153d4bGlenn Kasten 207881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Do not allow auxiliary effects on a session different from 0 (output mix) 207981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId != AUDIO_SESSION_OUTPUT_MIX && 208081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { 208181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = INVALID_OPERATION; 208281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 20833dbe3201479828e84abe02e1fdd0a5d414c0ddb8Eric Laurent } 208465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 208581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // check recording permission for visualizer 208681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if ((memcmp(&desc.type, SL_IID_VISUALIZATION, sizeof(effect_uuid_t)) == 0) && 208781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent !recordingAllowed()) { 208881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = PERMISSION_DENIED; 208981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 209081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 209165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 209281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // return effect descriptor 209381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *pDesc = desc; 209465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 209581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If output is not specified try to find a matching audio session ID in one of the 209681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // output threads. 209781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If output is 0 here, sessionId is neither SESSION_OUTPUT_STAGE nor SESSION_OUTPUT_MIX 209881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // because of code checking output when entering the function. 209981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Note: io is never 0 when creating an effect on an input 210081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (io == 0) { 210181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // look for the thread where the specified audio session is present 210281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 210381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (mPlaybackThreads.valueAt(i)->hasAudioSession(sessionId) != 0) { 210481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent io = mPlaybackThreads.keyAt(i); 210581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 210665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 2107d65d73c4ae74d084751b417615a78cbe7a51372aGlenn Kasten } 210881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (io == 0) { 210981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 211081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (mRecordThreads.valueAt(i)->hasAudioSession(sessionId) != 0) { 211181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent io = mRecordThreads.keyAt(i); 211281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 21132986460984580833161bdaabc7f17da1005a8961Eric Laurent } 211465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 211565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 211681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If no output thread contains the requested session ID, default to 211781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // first output. The effect chain will be moved to the correct output 211881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // thread when a track with the same session ID is created 211981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (io == 0 && mPlaybackThreads.size()) { 212081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent io = mPlaybackThreads.keyAt(0); 212181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 212281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("createEffect() got io %d for effect %s", io, desc.name); 212365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 212481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ThreadBase *thread = checkRecordThread_l(io); 212581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 212681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = checkPlaybackThread_l(io); 212781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 212881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGE("createEffect() unknown output thread"); 212981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 213081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 2131288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten } 2132288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten } 2133288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten 213481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<Client> client = registerPid_l(pid); 213558912562617941964939a4182cda71eaeb153d4bGlenn Kasten 213681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // create effect on selected output thread 213781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent handle = thread->createEffect_l(client, effectClient, priority, sessionId, 213881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent &desc, enabled, &lStatus); 213981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (handle != 0 && id != NULL) { 214081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *id = handle->id(); 214165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 214265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 214365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 214481784c37c61b09289654b979567a42bf73cd2b12Eric LaurentExit: 214581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (status != NULL) { 214681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *status = lStatus; 214758912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 214881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return handle; 214966fcab972e9218d47c58a915f391b2f48a09903aGlenn Kasten} 215066fcab972e9218d47c58a915f391b2f48a09903aGlenn Kasten 215181784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::moveEffects(int sessionId, audio_io_handle_t srcOutput, 215281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t dstOutput) 215365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 215481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("moveEffects() session %d, srcOutput %d, dstOutput %d", 215581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionId, srcOutput, dstOutput); 215665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 215781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (srcOutput == dstOutput) { 215881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffects() same dst and src outputs %d", dstOutput); 215981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 216081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 216181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *srcThread = checkPlaybackThread_l(srcOutput); 216281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (srcThread == NULL) { 216381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffects() bad srcOutput %d", srcOutput); 216481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 216581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 216681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *dstThread = checkPlaybackThread_l(dstOutput); 216781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (dstThread == NULL) { 216881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffects() bad dstOutput %d", dstOutput); 216981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 217065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 217165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 217281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _dl(dstThread->mLock); 217381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _sl(srcThread->mLock); 217481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent moveEffectChain_l(sessionId, srcThread, dstThread, false); 217565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 217681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 217765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 217865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 217981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// moveEffectChain_l must be called with both srcThread and dstThread mLocks held 218081784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::moveEffectChain_l(int sessionId, 218181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioFlinger::PlaybackThread *srcThread, 218281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioFlinger::PlaybackThread *dstThread, 218381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool reRegister) 218465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 218581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("moveEffectChain_l() session %d from thread %p to thread %p", 218681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionId, srcThread, dstThread); 218765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 218881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> chain = srcThread->getEffectChain_l(sessionId); 218981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (chain == 0) { 219081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffectChain_l() effect chain for session %d not on source thread %p", 219181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionId, srcThread); 219281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return INVALID_OPERATION; 219381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 21949ee159b79022b2e1a050acb3890ce948e99e9ccbGloria Wang 219581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // remove chain first. This is useful only if reconfiguring effect chain on same output thread, 219681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // so that a new chain is created with correct parameters when first effect is added. This is 219781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // otherwise unnecessary as removeEffect_l() will remove the chain when last effect is 219881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // removed. 219981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent srcThread->removeEffectChain_l(chain); 22009ee159b79022b2e1a050acb3890ce948e99e9ccbGloria Wang 220181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // transfer all effects one by one so that new effect chain is created on new thread with 220281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // correct buffer sizes and audio parameters and effect engines reconfigured accordingly 220381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t dstOutput = dstThread->id(); 220481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> dstChain; 220581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t strategy = 0; // prevent compiler warning 220681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectModule> effect = chain->getEffectFromId_l(0); 220781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent while (effect != 0) { 220881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent srcThread->removeEffect_l(effect); 220981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent dstThread->addEffect_l(effect); 221081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // removeEffect_l() has stopped the effect if it was active so it must be restarted 221181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (effect->state() == EffectModule::ACTIVE || 221281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect->state() == EffectModule::STOPPING) { 221381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect->start(); 221465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 221581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // if the move request is not received from audio policy manager, the effect must be 221681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // re-registered with the new strategy and output 221781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (dstChain == 0) { 221881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent dstChain = effect->chain().promote(); 221981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (dstChain == 0) { 222081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffectChain_l() cannot get chain from effect %p", effect.get()); 222181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent srcThread->addEffect_l(effect); 222281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_INIT; 222365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 222481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent strategy = dstChain->strategy(); 222565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 222681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (reRegister) { 222781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSystem::unregisterEffect(effect->id()); 222881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSystem::registerEffect(&effect->desc(), 222981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent dstOutput, 223081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent strategy, 223181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionId, 223281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect->id()); 223381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 223481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect = chain->getEffectFromId_l(0); 223558912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 223658912562617941964939a4182cda71eaeb153d4bGlenn Kasten 223781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 223865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 223965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2240da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenstruct Entry { 2241da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten#define MAX_NAME 32 // %Y%m%d%H%M%S_%d.wav 2242da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten char mName[MAX_NAME]; 2243da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten}; 2244da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 2245da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenint comparEntry(const void *p1, const void *p2) 2246da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten{ 2247da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten return strcmp(((const Entry *) p1)->mName, ((const Entry *) p2)->mName); 2248da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten} 2249da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 225046909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 2251d06785bebf7e43d4a011b62a252771373ada910cGlenn Kastenvoid AudioFlinger::dumpTee(int fd, const sp<NBAIO_Source>& source, audio_io_handle_t id) 225265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 2253d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten NBAIO_Source *teeSource = source.get(); 2254fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten if (teeSource != NULL) { 2255da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // .wav rotation 2256da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // There is a benign race condition if 2 threads call this simultaneously. 2257da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // They would both traverse the directory, but the result would simply be 2258da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // failures at unlink() which are ignored. It's also unlikely since 2259da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // normally dumpsys is only done by bugreport or from the command line. 2260da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten char teePath[32+256]; 2261da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten strcpy(teePath, "/data/misc/media"); 2262da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten size_t teePathLen = strlen(teePath); 2263da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten DIR *dir = opendir(teePath); 2264da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten teePath[teePathLen++] = '/'; 2265da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (dir != NULL) { 2266da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten#define MAX_SORT 20 // number of entries to sort 2267da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten#define MAX_KEEP 10 // number of entries to keep 2268da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten struct Entry entries[MAX_SORT]; 2269da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten size_t entryCount = 0; 2270da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten while (entryCount < MAX_SORT) { 2271da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten struct dirent de; 2272da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten struct dirent *result = NULL; 2273da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten int rc = readdir_r(dir, &de, &result); 2274da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (rc != 0) { 2275da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten ALOGW("readdir_r failed %d", rc); 2276da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten break; 2277da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2278da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (result == NULL) { 2279da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten break; 2280da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2281da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (result != &de) { 2282da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten ALOGW("readdir_r returned unexpected result %p != %p", result, &de); 2283da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten break; 2284da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2285da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // ignore non .wav file entries 2286da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten size_t nameLen = strlen(de.d_name); 2287da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (nameLen <= 4 || nameLen >= MAX_NAME || 2288da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten strcmp(&de.d_name[nameLen - 4], ".wav")) { 2289da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten continue; 2290da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2291da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten strcpy(entries[entryCount++].mName, de.d_name); 2292da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2293da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten (void) closedir(dir); 2294da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (entryCount > MAX_KEEP) { 2295da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten qsort(entries, entryCount, sizeof(Entry), comparEntry); 2296da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten for (size_t i = 0; i < entryCount - MAX_KEEP; ++i) { 2297da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten strcpy(&teePath[teePathLen], entries[i].mName); 2298da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten (void) unlink(teePath); 2299da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2300da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2301da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } else { 2302da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (fd >= 0) { 2303da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten fdprintf(fd, "unable to rotate tees in %s: %s\n", teePath, strerror(errno)); 2304da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2305da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2306d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten char teeTime[16]; 2307fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten struct timeval tv; 2308fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten gettimeofday(&tv, NULL); 2309fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten struct tm tm; 2310fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten localtime_r(&tv.tv_sec, &tm); 2311da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten strftime(teeTime, sizeof(teeTime), "%Y%m%d%H%M%S", &tm); 2312da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten snprintf(&teePath[teePathLen], sizeof(teePath) - teePathLen, "%s_%d.wav", teeTime, id); 2313da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // if 2 dumpsys are done within 1 second, and rotation didn't work, then discard 2nd 2314da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten int teeFd = open(teePath, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, S_IRUSR | S_IWUSR); 2315fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten if (teeFd >= 0) { 2316fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten char wavHeader[44]; 2317fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten memcpy(wavHeader, 2318fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten "RIFF\0\0\0\0WAVEfmt \20\0\0\0\1\0\2\0\104\254\0\0\0\0\0\0\4\0\20\0data\0\0\0\0", 2319fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten sizeof(wavHeader)); 2320fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten NBAIO_Format format = teeSource->format(); 2321fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten unsigned channelCount = Format_channelCount(format); 2322fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten ALOG_ASSERT(channelCount <= FCC_2); 23233b16c766d1ae2cfd8487e8ffb2b23936fc0a8e17Glenn Kasten uint32_t sampleRate = Format_sampleRate(format); 2324fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten wavHeader[22] = channelCount; // number of channels 2325fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten wavHeader[24] = sampleRate; // sample rate 2326fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten wavHeader[25] = sampleRate >> 8; 2327fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten wavHeader[32] = channelCount * 2; // block alignment 2328fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten write(teeFd, wavHeader, sizeof(wavHeader)); 2329fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten size_t total = 0; 2330fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten bool firstRead = true; 2331fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten for (;;) { 2332fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten#define TEE_SINK_READ 1024 2333fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten short buffer[TEE_SINK_READ * FCC_2]; 2334fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten size_t count = TEE_SINK_READ; 23352c3b2da3049627264b7c6b449a1622f002210f03John Grossman ssize_t actual = teeSource->read(buffer, count, 23362c3b2da3049627264b7c6b449a1622f002210f03John Grossman AudioBufferProvider::kInvalidPTS); 2337fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten bool wasFirstRead = firstRead; 2338fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten firstRead = false; 2339fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten if (actual <= 0) { 2340fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten if (actual == (ssize_t) OVERRUN && wasFirstRead) { 2341fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten continue; 2342fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 2343fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten break; 2344fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 2345a5f44ebaf58911805b4fb7fb479b19fd89d2e39bEric Laurent ALOG_ASSERT(actual <= (ssize_t)count); 2346fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten write(teeFd, buffer, actual * channelCount * sizeof(short)); 2347fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten total += actual; 2348fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 2349fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten lseek(teeFd, (off_t) 4, SEEK_SET); 2350fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten uint32_t temp = 44 + total * channelCount * sizeof(short) - 8; 2351fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten write(teeFd, &temp, sizeof(temp)); 2352fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten lseek(teeFd, (off_t) 40, SEEK_SET); 2353fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten temp = total * channelCount * sizeof(short); 2354fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten write(teeFd, &temp, sizeof(temp)); 2355fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten close(teeFd); 2356da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (fd >= 0) { 2357da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten fdprintf(fd, "tee copied to %s\n", teePath); 2358da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2359fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } else { 2360da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (fd >= 0) { 2361da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten fdprintf(fd, "unable to create tee %s: %s\n", teePath, strerror(errno)); 2362da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 2363fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 2364fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 2365d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten} 236646909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 2367d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten 236865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 236965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 237065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::onTransact( 237165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 237265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 237365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BnAudioFlinger::onTransact(code, data, reply, flags); 237465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 237565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 237665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian}; // namespace android 2377