AudioFlinger.cpp revision d21bcd272d43285baa32ffd48c909b4a29c614a4
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 22153b9fe667e6e78e0218ff0159353097428c7657Glenn Kasten#include "Configuration.h" 23da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten#include <dirent.h> 2465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <math.h> 2565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <signal.h> 2665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <sys/time.h> 2765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <sys/resource.h> 2865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 299ee159b79022b2e1a050acb3890ce948e99e9ccbGloria Wang#include <binder/IPCThreadState.h> 3065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <binder/IServiceManager.h> 3165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/Log.h> 32d8e6fd35ec2b59ee7d873daf1f1d9d348221c7bcGlenn Kasten#include <utils/Trace.h> 3365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <binder/Parcel.h> 3435fec5f61393124c9e13958941637b8fe386385eAndy Hung#include <memunreachable/memunreachable.h> 3565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/String16.h> 3665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <utils/threads.h> 3738ccae2c0324daa305f3fe77d25fdf5edec0b0e1Eric Laurent#include <utils/Atomic.h> 3865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 39fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin#include <cutils/bitops.h> 4065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include <cutils/properties.h> 4165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 4264760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h> 437394a4f358fa9908a9f0a7c954b65c399f4268e6Dima Zavin#include <hardware/audio.h> 4465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 4565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include "AudioMixer.h" 4665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian#include "AudioFlinger.h" 4744deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten#include "ServiceUtilities.h" 4865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 496770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung#include <media/AudioResamplerPublic.h> 506770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung 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 609e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten#include <media/IMediaLogService.h> 6107b745e166ee62030960ccea37e117caadf71c32Andy Hung#include <media/MemoryLeakTrackUtil.h> 62da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten#include <media/nbaio/Pipe.h> 63da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten#include <media/nbaio/PipeReader.h> 641ab85ec401801ef9a9184650d0f5a1639b45eeb9Glenn Kasten#include <media/AudioParameter.h> 653f273d10817ddb2f792ae043de692efcdf1988aeWei Jia#include <mediautils/BatteryNotifier.h> 664182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten#include <private/android_filesystem_config.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"; 87021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurentstatic const char kClientLockedString[] = "Client lock is taken\n"; 8865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 8958912562617941964939a4182cda71eaeb153d4bGlenn Kasten 904ff14bae91075eb274eb1c2975982358946e7e63John Grossmannsecs_t AudioFlinger::mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs; 917cafbb32999049873d4746ba83bd20c88abe6ce6Eric Laurent 9281784c37c61b09289654b979567a42bf73cd2b12Eric Laurentuint32_t AudioFlinger::mScreenState; 933ed292031dc50c56110cdadb1e3778117e3be76aGlenn Kasten 9446909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 95da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenbool AudioFlinger::mTeeSinkInputEnabled = false; 96da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenbool AudioFlinger::mTeeSinkOutputEnabled = false; 97da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenbool AudioFlinger::mTeeSinkTrackEnabled = false; 98da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 99da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastensize_t AudioFlinger::mTeeSinkInputFrames = kTeeSinkInputFramesDefault; 100da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastensize_t AudioFlinger::mTeeSinkOutputFrames = kTeeSinkOutputFramesDefault; 101da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastensize_t AudioFlinger::mTeeSinkTrackFrames = kTeeSinkTrackFramesDefault; 10246909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 103da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 104813e2a74853bde19e37d878c596a044b3f299efcEric Laurent// In order to avoid invalidating offloaded tracks each time a Visualizer is turned on and off 105813e2a74853bde19e37d878c596a044b3f299efcEric Laurent// we define a minimum time during which a global effect is considered enabled. 106813e2a74853bde19e37d878c596a044b3f299efcEric Laurentstatic const nsecs_t kMinGlobalEffectEnabletimeNs = seconds(7200); 107813e2a74853bde19e37d878c596a044b3f299efcEric Laurent 10865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 10965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 110b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissenconst char *formatToString(audio_format_t format) { 111fdb3c07db5d44535eb8c3ec46dc78ad8446c01ebPhil Burk switch (audio_get_main_format(format)) { 1122829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_PCM: 1132829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad switch (format) { 1142829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_PCM_16_BIT: return "pcm16"; 1152829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_PCM_8_BIT: return "pcm8"; 1162829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_PCM_32_BIT: return "pcm32"; 1172829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_PCM_8_24_BIT: return "pcm8.24"; 1182829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_PCM_FLOAT: return "pcmfloat"; 1192829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_PCM_24_BIT_PACKED: return "pcm24"; 1202829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad default: 1212829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad break; 1222829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad } 1232829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad break; 124b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen case AUDIO_FORMAT_MP3: return "mp3"; 125b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen case AUDIO_FORMAT_AMR_NB: return "amr-nb"; 126b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen case AUDIO_FORMAT_AMR_WB: return "amr-wb"; 127b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen case AUDIO_FORMAT_AAC: return "aac"; 128b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen case AUDIO_FORMAT_HE_AAC_V1: return "he-aac-v1"; 129b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen case AUDIO_FORMAT_HE_AAC_V2: return "he-aac-v2"; 130b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen case AUDIO_FORMAT_VORBIS: return "vorbis"; 1312829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_OPUS: return "opus"; 1322829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_AC3: return "ac-3"; 1332829edccd7d2bb8244246f316face82b650b8949aarti jadhav-gaikwad case AUDIO_FORMAT_E_AC3: return "e-ac-3"; 134fdb3c07db5d44535eb8c3ec46dc78ad8446c01ebPhil Burk case AUDIO_FORMAT_IEC61937: return "iec61937"; 135e30f20963751c07860bfbc92b5ff8948fc55797fEric Laurent case AUDIO_FORMAT_DTS: return "dts"; 136e30f20963751c07860bfbc92b5ff8948fc55797fEric Laurent case AUDIO_FORMAT_DTS_HD: return "dts-hd"; 137e30f20963751c07860bfbc92b5ff8948fc55797fEric Laurent case AUDIO_FORMAT_DOLBY_TRUEHD: return "dolby-truehd"; 138b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen default: 139b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen break; 140b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen } 141b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen return "unknown"; 142b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen} 143b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen 144f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurentstatic int load_audio_interface(const char *if_name, audio_hw_device_t **dev) 145799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin{ 146f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent const hw_module_t *mod; 147799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin int rc; 148799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin 149f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent rc = hw_get_module_by_class(AUDIO_HARDWARE_MODULE_ID, if_name, &mod); 150f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent ALOGE_IF(rc, "%s couldn't load audio hw module %s.%s (%s)", __func__, 151f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc)); 152f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent if (rc) { 153799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin goto out; 154f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent } 155f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent rc = audio_hw_device_open(mod, dev); 156f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent ALOGE_IF(rc, "%s couldn't open audio hw device in %s.%s (%s)", __func__, 157f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent AUDIO_HARDWARE_MODULE_ID, if_name, strerror(-rc)); 158f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent if (rc) { 159799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin goto out; 160f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent } 1615806b3533437e3d83208e8e9d6bd74ed304e51ecEric Laurent if ((*dev)->common.version < AUDIO_DEVICE_API_VERSION_MIN) { 162f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent ALOGE("%s wrong audio hw device version %04x", __func__, (*dev)->common.version); 163f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent rc = BAD_VALUE; 164f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent goto out; 165f7ffb8bf0a58037f0bc9662c5275005a4e539948Eric Laurent } 166799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin return 0; 167799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin 168799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavinout: 169799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin *dev = NULL; 170799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin return rc; 171799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin} 172799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin 17365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 17465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 17565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioFlinger::AudioFlinger() 17665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian : BnAudioFlinger(), 1774ff14bae91075eb274eb1c2975982358946e7e63John Grossman mPrimaryHardwareDev(NULL), 1789ea65d0f4a564478343b1a722fae4ce5883670c3Glenn Kasten mAudioHwDevs(NULL), 1797d6c35bf132a46c0a8a9826491882495fc98bd8cGlenn Kasten mHardwareStatus(AUDIO_HW_IDLE), 1804ff14bae91075eb274eb1c2975982358946e7e63John Grossman mMasterVolume(1.0f), 1814ff14bae91075eb274eb1c2975982358946e7e63John Grossman mMasterMute(false), 182d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten // mNextUniqueId(AUDIO_UNIQUE_ID_USE_MAX), 1834ff14bae91075eb274eb1c2975982358946e7e63John Grossman mMode(AUDIO_MODE_INVALID), 1844182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten mBtNrecIsOff(false), 1854182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten mIsLowRamDevice(true), 186813e2a74853bde19e37d878c596a044b3f299efcEric Laurent mIsDeviceTypeKnown(false), 1874ea00a25cf85877b48ebd1e15a657cfaab29af58Glenn Kasten mGlobalEffectEnableTime(0), 18872e3f39146fce4686bd96f11057c051bea376dfbEric Laurent mSystemReady(false) 18965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 190d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten // unsigned instead of audio_unique_id_use_t, because ++ operator is unavailable for enum 191d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten for (unsigned use = AUDIO_UNIQUE_ID_USE_UNSPECIFIED; use < AUDIO_UNIQUE_ID_USE_MAX; use++) { 192d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten // zero ID has a special meaning, so unavailable 193d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten mNextUniqueIds[use] = AUDIO_UNIQUE_ID_USE_MAX; 194d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten } 195d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten 196949a926cadbc961fbb649c91d76d7aee8ea4d7bdGlenn Kasten getpid_cached = getpid(); 197ae0cff1d48b2cd10aeff9627398faf684894eeceGlenn Kasten const bool doLog = property_get_bool("ro.test_harness", false); 1989e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (doLog) { 199b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten mLogMemoryDealer = new MemoryDealer(kLogMemorySize, "LogWriters", 200b187de1ada34a9023c05d020a4592686ba761278Glenn Kasten MemoryHeapBase::READ_ONLY); 2019e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 2021c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 2033f273d10817ddb2f792ae043de692efcdf1988aeWei Jia // reset battery stats. 2043f273d10817ddb2f792ae043de692efcdf1988aeWei Jia // if the audio service has crashed, battery stats could be left 2053f273d10817ddb2f792ae043de692efcdf1988aeWei Jia // in bad state, reset the state upon service start. 2063f273d10817ddb2f792ae043de692efcdf1988aeWei Jia BatteryNotifier::getInstance().noteResetAudio(); 2073f273d10817ddb2f792ae043de692efcdf1988aeWei Jia 20846909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 2099a00399340c7c129714dff96f1ab59045fe43056Glenn Kasten char value[PROPERTY_VALUE_MAX]; 210da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten (void) property_get("ro.debuggable", value, "0"); 211da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten int debuggable = atoi(value); 212da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten int teeEnabled = 0; 213da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (debuggable) { 214da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten (void) property_get("af.tee", value, "0"); 215da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten teeEnabled = atoi(value); 216da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 217f66b42242342017c26eb97de544dae31dd2537caGlenn Kasten // FIXME symbolic constants here 2186e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten if (teeEnabled & 1) { 219da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten mTeeSinkInputEnabled = true; 2206e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten } 2216e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten if (teeEnabled & 2) { 222da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten mTeeSinkOutputEnabled = true; 2236e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten } 2246e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten if (teeEnabled & 4) { 225da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten mTeeSinkTrackEnabled = true; 2266e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten } 22746909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 2285a61d2f277af3098fc10b2881babca16391362daDima Zavin} 2295a61d2f277af3098fc10b2881babca16391362daDima Zavin 2305a61d2f277af3098fc10b2881babca16391362daDima Zavinvoid AudioFlinger::onFirstRef() 2315a61d2f277af3098fc10b2881babca16391362daDima Zavin{ 232935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent Mutex::Autolock _l(mLock); 233935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent 234799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin /* TODO: move all this work into an Init() function */ 2354ff14bae91075eb274eb1c2975982358946e7e63John Grossman char val_str[PROPERTY_VALUE_MAX] = { 0 }; 2364ff14bae91075eb274eb1c2975982358946e7e63John Grossman if (property_get("ro.audio.flinger_standbytime_ms", val_str, NULL) >= 0) { 2374ff14bae91075eb274eb1c2975982358946e7e63John Grossman uint32_t int_val; 2384ff14bae91075eb274eb1c2975982358946e7e63John Grossman if (1 == sscanf(val_str, "%u", &int_val)) { 2394ff14bae91075eb274eb1c2975982358946e7e63John Grossman mStandbyTimeInNsecs = milliseconds(int_val); 2404ff14bae91075eb274eb1c2975982358946e7e63John Grossman ALOGI("Using %u mSec as standby time.", int_val); 2414ff14bae91075eb274eb1c2975982358946e7e63John Grossman } else { 2424ff14bae91075eb274eb1c2975982358946e7e63John Grossman mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs; 2434ff14bae91075eb274eb1c2975982358946e7e63John Grossman ALOGI("Using default %u mSec as standby time.", 2444ff14bae91075eb274eb1c2975982358946e7e63John Grossman (uint32_t)(mStandbyTimeInNsecs / 1000000)); 2454ff14bae91075eb274eb1c2975982358946e7e63John Grossman } 2464ff14bae91075eb274eb1c2975982358946e7e63John Grossman } 24765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2481c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent mPatchPanel = new PatchPanel(this); 249deb0335714cabc906098fb1d971d992027267fc6Andy Hung 250a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent mMode = AUDIO_MODE_NORMAL; 25165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 25265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 25365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianAudioFlinger::~AudioFlinger() 25465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 25565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian while (!mRecordThreads.isEmpty()) { 256c3ae93f21280859086ae371428ffd32f39e76d50Glenn Kasten // closeInput_nonvirtual() will remove specified entry from mRecordThreads 257d96c5724818fb47917bb5e7abe37799735e1ec0eGlenn Kasten closeInput_nonvirtual(mRecordThreads.keyAt(0)); 25865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 25965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian while (!mPlaybackThreads.isEmpty()) { 260c3ae93f21280859086ae371428ffd32f39e76d50Glenn Kasten // closeOutput_nonvirtual() will remove specified entry from mPlaybackThreads 261d96c5724818fb47917bb5e7abe37799735e1ec0eGlenn Kasten closeOutput_nonvirtual(mPlaybackThreads.keyAt(0)); 26265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 263799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin 2642b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 2652b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten // no mHardwareLock needed, as there are no other references to this 266a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent audio_hw_device_close(mAudioHwDevs.valueAt(i)->hwDevice()); 267a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent delete mAudioHwDevs.valueAt(i); 26865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 269481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten 270481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // Tell media.log service about any old writers that still need to be unregistered 271ce7176868977b0d44b245735bd8d3d8e54e61035Andy Hung if (mLogMemoryDealer != 0) { 272ce7176868977b0d44b245735bd8d3d8e54e61035Andy Hung sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log")); 273ce7176868977b0d44b245735bd8d3d8e54e61035Andy Hung if (binder != 0) { 274ce7176868977b0d44b245735bd8d3d8e54e61035Andy Hung sp<IMediaLogService> mediaLogService(interface_cast<IMediaLogService>(binder)); 275ce7176868977b0d44b245735bd8d3d8e54e61035Andy Hung for (size_t count = mUnregisteredWriters.size(); count > 0; count--) { 276ce7176868977b0d44b245735bd8d3d8e54e61035Andy Hung sp<IMemory> iMemory(mUnregisteredWriters.top()->getIMemory()); 277ce7176868977b0d44b245735bd8d3d8e54e61035Andy Hung mUnregisteredWriters.pop(); 278ce7176868977b0d44b245735bd8d3d8e54e61035Andy Hung mediaLogService->unregisterWriter(iMemory); 279ce7176868977b0d44b245735bd8d3d8e54e61035Andy Hung } 280481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten } 281481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten } 28265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 28365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 284a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurentstatic const char * const audio_interfaces[] = { 285a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent AUDIO_HARDWARE_MODULE_ID_PRIMARY, 286a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent AUDIO_HARDWARE_MODULE_ID_A2DP, 287a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent AUDIO_HARDWARE_MODULE_ID_USB, 288a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent}; 289a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent#define ARRAY_SIZE(x) (sizeof((x))/sizeof(((x)[0]))) 290a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent 291062e67a26e0553dd142be622821f493df541f0c6Phil BurkAudioHwDevice* AudioFlinger::findSuitableHwDev_l( 292ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_module_handle_t module, 293ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_devices_t devices) 294799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin{ 295a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent // if module is 0, the request comes from an old policy manager and we should load 296a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent // well known modules 297a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent if (module == 0) { 298a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent ALOGW("findSuitableHwDev_l() loading well know audio hw modules"); 299a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent for (size_t i = 0; i < ARRAY_SIZE(audio_interfaces); i++) { 300a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent loadHwModule_l(audio_interfaces[i]); 301a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } 302f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent // then try to find a module supporting the requested device. 303f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 304f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent AudioHwDevice *audioHwDevice = mAudioHwDevs.valueAt(i); 305f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent audio_hw_device_t *dev = audioHwDevice->hwDevice(); 306f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent if ((dev->get_supported_devices != NULL) && 307f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent (dev->get_supported_devices(dev) & devices) == devices) 308f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent return audioHwDevice; 309f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent } 310a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } else { 311a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent // check a match for the requested module handle 312ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AudioHwDevice *audioHwDevice = mAudioHwDevs.valueFor(module); 313ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman if (audioHwDevice != NULL) { 314ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman return audioHwDevice; 315a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } 316a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } 317a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent 318799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin return NULL; 319799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin} 32065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 3210f11b51a57bc9062c4fe8af73747319cedabc5d6Glenn Kastenvoid AudioFlinger::dumpClients(int fd, const Vector<String16>& args __unused) 32265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 32365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 32465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 32565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 32665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 32765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append("Clients:\n"); 32865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < mClients.size(); ++i) { 32977c1119ea0b5cb32287088ceeeb7e3b6bd14a85dGlenn Kasten sp<Client> client = mClients.valueAt(i).promote(); 33077c1119ea0b5cb32287088ceeeb7e3b6bd14a85dGlenn Kasten if (client != 0) { 33177c1119ea0b5cb32287088ceeeb7e3b6bd14a85dGlenn Kasten snprintf(buffer, SIZE, " pid: %d\n", client->pid()); 33277c1119ea0b5cb32287088ceeeb7e3b6bd14a85dGlenn Kasten result.append(buffer); 33365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 33465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 3353a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen 336d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent result.append("Notification Clients:\n"); 337d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent for (size_t i = 0; i < mNotificationClients.size(); ++i) { 338d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent snprintf(buffer, SIZE, " pid: %d\n", mNotificationClients.keyAt(i)); 339d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent result.append(buffer); 340d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent } 341d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent 3423a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen result.append("Global session refs:\n"); 343b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen result.append(" session pid count\n"); 3443a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen for (size_t i = 0; i < mAudioSessionRefs.size(); i++) { 3453a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen AudioSessionRef *r = mAudioSessionRefs[i]; 346b220884bf3129253cc5bc8d030bc475411ea4911Marco Nelissen snprintf(buffer, SIZE, " %7d %5d %5d\n", r->mSessionid, r->mPid, r->mCnt); 3473a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen result.append(buffer); 3483a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen } 34965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 35065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 35165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 35265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 3530f11b51a57bc9062c4fe8af73747319cedabc5d6Glenn Kastenvoid AudioFlinger::dumpInternals(int fd, const Vector<String16>& args __unused) 35465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 35565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 35665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 35765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 358a4454b4765c5905f14186893b0688be375642283Glenn Kasten hardware_call_state hardwareStatus = mHardwareStatus; 35965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 3604ff14bae91075eb274eb1c2975982358946e7e63John Grossman snprintf(buffer, SIZE, "Hardware status: %d\n" 3614ff14bae91075eb274eb1c2975982358946e7e63John Grossman "Standby Time mSec: %u\n", 3624ff14bae91075eb274eb1c2975982358946e7e63John Grossman hardwareStatus, 3634ff14bae91075eb274eb1c2975982358946e7e63John Grossman (uint32_t)(mStandbyTimeInNsecs / 1000000)); 36465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 36565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 36665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 36765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 3680f11b51a57bc9062c4fe8af73747319cedabc5d6Glenn Kastenvoid AudioFlinger::dumpPermissionDenial(int fd, const Vector<String16>& args __unused) 36965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 37065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const size_t SIZE = 256; 37165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian char buffer[SIZE]; 37265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result; 37365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian snprintf(buffer, SIZE, "Permission Denial: " 37465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian "can't dump AudioFlinger from pid=%d, uid=%d\n", 37565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian IPCThreadState::self()->getCallingPid(), 37665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian IPCThreadState::self()->getCallingUid()); 37765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian result.append(buffer); 37865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 37965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 38065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 38181784c37c61b09289654b979567a42bf73cd2b12Eric Laurentbool AudioFlinger::dumpTryLock(Mutex& mutex) 38265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 38365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian bool locked = false; 38465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (int i = 0; i < kDumpLockRetries; ++i) { 38565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (mutex.tryLock() == NO_ERROR) { 38665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian locked = true; 38765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian break; 38865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 3897dede876998ff56351d495ec3a798c1b131193e8Glenn Kasten usleep(kDumpLockSleepUs); 39065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 39165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return locked; 39265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 39365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 39465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::dump(int fd, const Vector<String16>& args) 39565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 39644deb053252a3bd2f57a007ab9560f4924f62394Glenn Kasten if (!dumpAllowed()) { 39765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpPermissionDenial(fd, args); 39865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 39965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // get state of hardware lock 40081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool hardwareLocked = dumpTryLock(mHardwareLock); 40165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!hardwareLocked) { 40265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result(kHardwareLockedString); 40365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 40465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 40565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareLock.unlock(); 40665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 40765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 40881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool locked = dumpTryLock(mLock); 40965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 41065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // failed to lock - AudioFlinger is probably deadlocked 41165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!locked) { 41265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian String8 result(kDeadlockedString); 41365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian write(fd, result.string(), result.size()); 41465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 41565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 416021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent bool clientLocked = dumpTryLock(mClientLock); 417021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent if (!clientLocked) { 418021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent String8 result(kClientLockedString); 419021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent write(fd, result.string(), result.size()); 420021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent } 421d89eaddd1544dc9f6665e2578583e8083cac00daMarco Nelissen 422d89eaddd1544dc9f6665e2578583e8083cac00daMarco Nelissen EffectDumpEffects(fd); 423d89eaddd1544dc9f6665e2578583e8083cac00daMarco Nelissen 42465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpClients(fd, args); 425021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent if (clientLocked) { 426021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent mClientLock.unlock(); 427021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent } 428021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent 42965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian dumpInternals(fd, args); 43065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 43165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // dump playback threads 43265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 43365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mPlaybackThreads.valueAt(i)->dump(fd, args); 43465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 43565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 43665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // dump record threads 43765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < mRecordThreads.size(); i++) { 43865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mRecordThreads.valueAt(i)->dump(fd, args); 43965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 44065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 441aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent // dump orphan effect chains 442aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent if (mOrphanEffectChains.size() != 0) { 443aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent write(fd, " Orphan Effect Chains\n", strlen(" Orphan Effect Chains\n")); 444aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent for (size_t i = 0; i < mOrphanEffectChains.size(); i++) { 445aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent mOrphanEffectChains.valueAt(i)->dump(fd, args); 446aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } 447aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } 448799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin // dump all hardware devs 449799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 450a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice(); 451799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin dev->dump(dev, fd); 45265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 453d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten 45446909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 455d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten // dump the serially shared record tee sink 456d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten if (mRecordTeeSource != 0) { 457d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten dumpTee(fd, mRecordTeeSource); 458d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten } 45946909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 460d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten 461d65d73c4ae74d084751b417615a78cbe7a51372aGlenn Kasten if (locked) { 462d65d73c4ae74d084751b417615a78cbe7a51372aGlenn Kasten mLock.unlock(); 463d65d73c4ae74d084751b417615a78cbe7a51372aGlenn Kasten } 4649e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten 4659e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten // append a copy of media.log here by forwarding fd to it, but don't attempt 4669e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten // to lookup the service if it's not running, as it will block for a second 4679e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (mLogMemoryDealer != 0) { 4689e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log")); 4699e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (binder != 0) { 4708b5f642eb2364ea7fe46a5b3af51b48b58f12183Elliott Hughes dprintf(fd, "\nmedia.log:\n"); 4719e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten Vector<String16> args; 4729e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten binder->dump(fd, args); 4739e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 4749e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 47535fec5f61393124c9e13958941637b8fe386385eAndy Hung 47635fec5f61393124c9e13958941637b8fe386385eAndy Hung // check for optional arguments 47707b745e166ee62030960ccea37e117caadf71c32Andy Hung bool dumpMem = false; 47835fec5f61393124c9e13958941637b8fe386385eAndy Hung bool unreachableMemory = false; 47935fec5f61393124c9e13958941637b8fe386385eAndy Hung for (const auto &arg : args) { 48007b745e166ee62030960ccea37e117caadf71c32Andy Hung if (arg == String16("-m")) { 48107b745e166ee62030960ccea37e117caadf71c32Andy Hung dumpMem = true; 48207b745e166ee62030960ccea37e117caadf71c32Andy Hung } else if (arg == String16("--unreachable")) { 48335fec5f61393124c9e13958941637b8fe386385eAndy Hung unreachableMemory = true; 48435fec5f61393124c9e13958941637b8fe386385eAndy Hung } 48535fec5f61393124c9e13958941637b8fe386385eAndy Hung } 48635fec5f61393124c9e13958941637b8fe386385eAndy Hung 48707b745e166ee62030960ccea37e117caadf71c32Andy Hung if (dumpMem) { 48807b745e166ee62030960ccea37e117caadf71c32Andy Hung dprintf(fd, "\nDumping memory:\n"); 48907b745e166ee62030960ccea37e117caadf71c32Andy Hung std::string s = dumpMemoryAddresses(100 /* limit */); 49007b745e166ee62030960ccea37e117caadf71c32Andy Hung write(fd, s.c_str(), s.size()); 49107b745e166ee62030960ccea37e117caadf71c32Andy Hung } 49235fec5f61393124c9e13958941637b8fe386385eAndy Hung if (unreachableMemory) { 49335fec5f61393124c9e13958941637b8fe386385eAndy Hung dprintf(fd, "\nDumping unreachable memory:\n"); 49435fec5f61393124c9e13958941637b8fe386385eAndy Hung // TODO - should limit be an argument parameter? 49507b745e166ee62030960ccea37e117caadf71c32Andy Hung std::string s = GetUnreachableMemoryString(true /* contents */, 100 /* limit */); 49635fec5f61393124c9e13958941637b8fe386385eAndy Hung write(fd, s.c_str(), s.size()); 49735fec5f61393124c9e13958941637b8fe386385eAndy Hung } 49865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 49965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 50065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 50165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 502021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurentsp<AudioFlinger::Client> AudioFlinger::registerPid(pid_t pid) 50398ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten{ 504021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent Mutex::Autolock _cl(mClientLock); 50598ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten // If pid is already in the mClients wp<> map, then use that entry 50698ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten // (for which promote() is always != 0), otherwise create a new entry and Client. 50798ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten sp<Client> client = mClients.valueFor(pid).promote(); 50898ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten if (client == 0) { 50998ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten client = new Client(this, pid); 51098ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten mClients.add(pid, client); 51198ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten } 51298ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten 51398ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten return client; 51498ec94c5854daccc3474758524e7f4adfe535ce0Glenn Kasten} 51565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 5169e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kastensp<NBLog::Writer> AudioFlinger::newWriter_l(size_t size, const char *name) 5179e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten{ 518481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // If there is no memory allocated for logs, return a dummy writer that does nothing 5199e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (mLogMemoryDealer == 0) { 5209e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten return new NBLog::Writer(); 5219e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 5229e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten sp<IBinder> binder = defaultServiceManager()->getService(String16("media.log")); 523481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // Similarly if we can't contact the media.log service, also return a dummy writer 524481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten if (binder == 0) { 525481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten return new NBLog::Writer(); 5269e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 527481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten sp<IMediaLogService> mediaLogService(interface_cast<IMediaLogService>(binder)); 528481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten sp<IMemory> shared = mLogMemoryDealer->allocate(NBLog::Timeline::sharedSize(size)); 529481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // If allocation fails, consult the vector of previously unregistered writers 530481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // and garbage-collect one or more them until an allocation succeeds 531481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten if (shared == 0) { 532481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten Mutex::Autolock _l(mUnregisteredWritersLock); 533481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten for (size_t count = mUnregisteredWriters.size(); count > 0; count--) { 534481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten { 535481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // Pick the oldest stale writer to garbage-collect 536481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten sp<IMemory> iMemory(mUnregisteredWriters[0]->getIMemory()); 537481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten mUnregisteredWriters.removeAt(0); 538481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten mediaLogService->unregisterWriter(iMemory); 539481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // Now the media.log remote reference to IMemory is gone. When our last local 540481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // reference to IMemory also drops to zero at end of this block, 541481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // the IMemory destructor will deallocate the region from mLogMemoryDealer. 542481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten } 543481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // Re-attempt the allocation 544481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten shared = mLogMemoryDealer->allocate(NBLog::Timeline::sharedSize(size)); 545481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten if (shared != 0) { 546481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten goto success; 547481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten } 548481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten } 549481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // Even after garbage-collecting all old writers, there is still not enough memory, 550481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // so return a dummy writer 551481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten return new NBLog::Writer(); 552481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten } 553481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kastensuccess: 554481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten mediaLogService->registerWriter(shared, size, name); 555481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten return new NBLog::Writer(size, shared); 5569e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten} 5579e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten 5589e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kastenvoid AudioFlinger::unregisterWriter(const sp<NBLog::Writer>& writer) 5599e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten{ 560685ef09bcaf5de6abf2064d552296f70eaec6761Glenn Kasten if (writer == 0) { 561685ef09bcaf5de6abf2064d552296f70eaec6761Glenn Kasten return; 562685ef09bcaf5de6abf2064d552296f70eaec6761Glenn Kasten } 5639e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten sp<IMemory> iMemory(writer->getIMemory()); 5649e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten if (iMemory == 0) { 5659e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten return; 5669e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten } 567481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // Rather than removing the writer immediately, append it to a queue of old writers to 568481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten // be garbage-collected later. This allows us to continue to view old logs for a while. 569481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten Mutex::Autolock _l(mUnregisteredWritersLock); 570481fb67a595f23c5b7f5be84b06db9b84a41a42fGlenn Kasten mUnregisteredWriters.push(writer); 5719e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten} 5729e58b552f51b00b3b674102876bd6c77ef3da806Glenn Kasten 57365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// IAudioFlinger interface 57465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 57565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 57665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopiansp<IAudioTrack> AudioFlinger::createTrack( 577fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kasten audio_stream_type_t streamType, 57865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t sampleRate, 57958f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten audio_format_t format, 580254af180475346b6186b49c297f340c9c4817511Glenn Kasten audio_channel_mask_t channelMask, 58174935e44734c1ec235c2b6677db3e0dbefa5ddb8Glenn Kasten size_t *frameCount, 582050677873c10d4da308ac222f8533c96cca3207eEric Laurent audio_output_flags_t *flags, 58365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian const sp<IMemory>& sharedBuffer, 58472ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten audio_io_handle_t output, 5859ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George pid_t pid, 5863acbd053c842e76e1a40fc8a0bf62de87eebf00fGlenn Kasten pid_t tid, 587d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t *sessionId, 588462fd2fa9eef642b0574aa7409de0bde3fec8d43Marco Nelissen int clientUid, 58965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t *status) 59065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 59165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<PlaybackThread::Track> track; 59265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<TrackHandle> trackHandle; 59365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<Client> client; 59465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian status_t lStatus; 595d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t lSessionId; 59665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 5979ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George const uid_t callingUid = IPCThreadState::self()->getCallingUid(); 5989ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George if (pid == -1 || !isTrustedCallingUid(callingUid)) { 5999ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George const pid_t callingPid = IPCThreadState::self()->getCallingPid(); 6009ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George ALOGW_IF(pid != -1 && pid != callingPid, 6019ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George "%s uid %d pid %d tried to pass itself off as pid %d", 6029ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George __func__, callingUid, callingPid, pid); 6039ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George pid = callingPid; 6049ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George } 6059ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George 606263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten // client AudioTrack::set already implements AUDIO_STREAM_DEFAULT => AUDIO_STREAM_MUSIC, 607263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten // but if someone uses binder directly they could bypass that and cause us to crash 608263709e7be37c7040aaef385bc5c9389a9b5f514Glenn Kasten if (uint32_t(streamType) >= AUDIO_STREAM_CNT) { 60929357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("createTrack() invalid stream type %d", streamType); 61065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian lStatus = BAD_VALUE; 61165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian goto Exit; 61265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 61365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 61453b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten // further sample rate checks are performed by createTrack_l() depending on the thread type 61553b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten if (sampleRate == 0) { 61653b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten ALOGE("createTrack() invalid sample rate %u", sampleRate); 61753b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten lStatus = BAD_VALUE; 61853b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten goto Exit; 61953b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten } 62053b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten 62153b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten // further channel mask checks are performed by createTrack_l() depending on the thread type 62253b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten if (!audio_is_output_channel(channelMask)) { 62353b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten ALOGE("createTrack() invalid channel mask %#x", channelMask); 62453b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten lStatus = BAD_VALUE; 62553b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten goto Exit; 62653b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten } 62753b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten 628c4b88a8d0f524666bf0f390075c334d047a104f2Glenn Kasten // further format checks are performed by createTrack_l() depending on the thread type 629c4b88a8d0f524666bf0f390075c334d047a104f2Glenn Kasten if (!audio_is_valid_format(format)) { 630cac3daa6332bf6d1f7d26adc4a9915f3d7992dd9Glenn Kasten ALOGE("createTrack() invalid format %#x", format); 63160a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten lStatus = BAD_VALUE; 632663c2247b71086e30bfd3192979d1dd7f15c539eGlenn Kasten goto Exit; 633663c2247b71086e30bfd3192979d1dd7f15c539eGlenn Kasten } 634663c2247b71086e30bfd3192979d1dd7f15c539eGlenn Kasten 635663c2247b71086e30bfd3192979d1dd7f15c539eGlenn Kasten if (sharedBuffer != 0 && sharedBuffer->pointer() == NULL) { 636663c2247b71086e30bfd3192979d1dd7f15c539eGlenn Kasten ALOGE("createTrack() sharedBuffer is non-0 but has NULL pointer()"); 637663c2247b71086e30bfd3192979d1dd7f15c539eGlenn Kasten lStatus = BAD_VALUE; 63860a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten goto Exit; 63960a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten } 64060a839204713e0f8258d082af83262b1eb33a6c3Glenn Kasten 64165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { 64265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 64365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 64465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 645c9b2e20f7c9a71e07ef398152709c76079decbcdGlenn Kasten ALOGE("no playback thread found for output handle %d", output); 64665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian lStatus = BAD_VALUE; 64765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian goto Exit; 64865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 64965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 650021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent client = registerPid(pid); 65165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 652e848bd9abb3bbbd4c66f9fb9d1442f7663d7ba40Glenn Kasten PlaybackThread *effectThread = NULL; 653aea7ea06394bcb155972d82055d4ea59962e4051Glenn Kasten if (sessionId != NULL && *sessionId != AUDIO_SESSION_ALLOCATE) { 654eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten if (audio_unique_id_get_use(*sessionId) != AUDIO_UNIQUE_ID_USE_SESSION) { 655eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten ALOGE("createTrack() invalid session ID %d", *sessionId); 656eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten lStatus = BAD_VALUE; 657eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten goto Exit; 658eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten } 659570f633e0b02d1bc25f3312b92e72cc29a40ca38Glenn Kasten lSessionId = *sessionId; 660f436fdcf93bd417fd3c9d2a8b19fd221d894b5e3Eric Laurent // check if an effect chain with the same session ID is present on another 661f436fdcf93bd417fd3c9d2a8b19fd221d894b5e3Eric Laurent // output thread and move it here. 662de070137f11d346fba77605bd76a44c040a618fcEric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 66339e94f8f723d445447fdee0822291e664b631f60Eric Laurent sp<PlaybackThread> t = mPlaybackThreads.valueAt(i); 66439e94f8f723d445447fdee0822291e664b631f60Eric Laurent if (mPlaybackThreads.keyAt(i) != output) { 665570f633e0b02d1bc25f3312b92e72cc29a40ca38Glenn Kasten uint32_t sessions = t->hasAudioSession(lSessionId); 6664c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent if (sessions & ThreadBase::EFFECT_SESSION) { 66739e94f8f723d445447fdee0822291e664b631f60Eric Laurent effectThread = t.get(); 668f436fdcf93bd417fd3c9d2a8b19fd221d894b5e3Eric Laurent break; 66939e94f8f723d445447fdee0822291e664b631f60Eric Laurent } 670de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 671de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 67265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 673de070137f11d346fba77605bd76a44c040a618fcEric Laurent // if no audio session id is provided, create one here 674d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten lSessionId = (audio_session_t) nextUniqueId(AUDIO_UNIQUE_ID_USE_SESSION); 67565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (sessionId != NULL) { 67665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian *sessionId = lSessionId; 67765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 67865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 6793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("createTrack() lSessionId: %d", lSessionId); 68065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 68165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian track = thread->createTrack_l(client, streamType, sampleRate, format, 682462fd2fa9eef642b0574aa7409de0bde3fec8d43Marco Nelissen channelMask, frameCount, sharedBuffer, lSessionId, flags, tid, clientUid, &lStatus); 68303e9e83c47ab4a518da0a1f36b8f702f59221c95Haynes Mathew George LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (track == 0)); 6842fc14730e4697a6f456b4631549c9981f6b0b115Glenn Kasten // we don't abort yet if lStatus != NO_ERROR; there is still work to be done regardless 68539e94f8f723d445447fdee0822291e664b631f60Eric Laurent 68639e94f8f723d445447fdee0822291e664b631f60Eric Laurent // move effect chain to this output thread if an effect on same session was waiting 68739e94f8f723d445447fdee0822291e664b631f60Eric Laurent // for a track to be created 68839e94f8f723d445447fdee0822291e664b631f60Eric Laurent if (lStatus == NO_ERROR && effectThread != NULL) { 6892fc14730e4697a6f456b4631549c9981f6b0b115Glenn Kasten // no risk of deadlock because AudioFlinger::mLock is held 69039e94f8f723d445447fdee0822291e664b631f60Eric Laurent Mutex::Autolock _dl(thread->mLock); 69139e94f8f723d445447fdee0822291e664b631f60Eric Laurent Mutex::Autolock _sl(effectThread->mLock); 69239e94f8f723d445447fdee0822291e664b631f60Eric Laurent moveEffectChain_l(lSessionId, effectThread, thread, true); 69339e94f8f723d445447fdee0822291e664b631f60Eric Laurent } 694a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent 695a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent // Look for sync events awaiting for a session to be used. 6963ab368e0810d894dcbc0971350c095049478a055Mark Salyzyn for (size_t i = 0; i < mPendingSyncEvents.size(); i++) { 697a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent if (mPendingSyncEvents[i]->triggerSession() == lSessionId) { 698a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent if (thread->isValidSyncEvent(mPendingSyncEvents[i])) { 6992986460984580833161bdaabc7f17da1005a8961Eric Laurent if (lStatus == NO_ERROR) { 700d23eedca9b5a1812891c05d89850ab7ee707040dGlenn Kasten (void) track->setSyncEvent(mPendingSyncEvents[i]); 7012986460984580833161bdaabc7f17da1005a8961Eric Laurent } else { 7022986460984580833161bdaabc7f17da1005a8961Eric Laurent mPendingSyncEvents[i]->cancel(); 7032986460984580833161bdaabc7f17da1005a8961Eric Laurent } 704a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent mPendingSyncEvents.removeAt(i); 705a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent i--; 706a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 707a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 708a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 709e198c360d5e75a9b2097844c495c10902e7e8500Glenn Kasten 710d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten setAudioHwSyncForSession_l(thread, lSessionId); 71165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 712e198c360d5e75a9b2097844c495c10902e7e8500Glenn Kasten 7133ef14ef30359376006a233f6a21a165d4b65a7dfGlenn Kasten if (lStatus != NO_ERROR) { 7143ef14ef30359376006a233f6a21a165d4b65a7dfGlenn Kasten // remove local strong reference to Client before deleting the Track so that the 715021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent // Client destructor is called by the TrackBase destructor with mClientLock held 716fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent // Don't hold mClientLock when releasing the reference on the track as the 717fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent // destructor will acquire it. 718fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent { 719fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent Mutex::Autolock _cl(mClientLock); 720fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent client.clear(); 721fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent } 72265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian track.clear(); 7233ef14ef30359376006a233f6a21a165d4b65a7dfGlenn Kasten goto Exit; 72465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 72565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 7263ef14ef30359376006a233f6a21a165d4b65a7dfGlenn Kasten // return handle to client 7273ef14ef30359376006a233f6a21a165d4b65a7dfGlenn Kasten trackHandle = new TrackHandle(track); 7283ef14ef30359376006a233f6a21a165d4b65a7dfGlenn Kasten 72965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias AgopianExit: 7309156ef3e11b68cc4b6d3cea77f1f63673855a6d1Glenn Kasten *status = lStatus; 73165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return trackHandle; 73265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 73365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 7342c073da0f02c3cf7cd4795af2d861222cbcab72aGlenn Kastenuint32_t AudioFlinger::sampleRate(audio_io_handle_t ioHandle) const 73565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 73665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 7372c073da0f02c3cf7cd4795af2d861222cbcab72aGlenn Kasten ThreadBase *thread = checkThread_l(ioHandle); 73865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 7392c073da0f02c3cf7cd4795af2d861222cbcab72aGlenn Kasten ALOGW("sampleRate() unknown thread %d", ioHandle); 74065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 74165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 74265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return thread->sampleRate(); 74365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 74465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 74572ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenaudio_format_t AudioFlinger::format(audio_io_handle_t output) const 74665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 74765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 74865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 74965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 7505ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block ALOGW("format() unknown thread %d", output); 75158f30210ea540b6ce5aa6a46330cd3499483cb97Glenn Kasten return AUDIO_FORMAT_INVALID; 75265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 75365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return thread->format(); 75465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 75565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 7562c073da0f02c3cf7cd4795af2d861222cbcab72aGlenn Kastensize_t AudioFlinger::frameCount(audio_io_handle_t ioHandle) const 75765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 75865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 7592c073da0f02c3cf7cd4795af2d861222cbcab72aGlenn Kasten ThreadBase *thread = checkThread_l(ioHandle); 76065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 7612c073da0f02c3cf7cd4795af2d861222cbcab72aGlenn Kasten ALOGW("frameCount() unknown thread %d", ioHandle); 76265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 76365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 76458912562617941964939a4182cda71eaeb153d4bGlenn Kasten // FIXME currently returns the normal mixer's frame count to avoid confusing legacy callers; 76558912562617941964939a4182cda71eaeb153d4bGlenn Kasten // should examine all callers and fix them to handle smaller counts 76665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return thread->frameCount(); 76765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 76865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 7694a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kastensize_t AudioFlinger::frameCountHAL(audio_io_handle_t ioHandle) const 7704a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten{ 7714a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten Mutex::Autolock _l(mLock); 7724a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten ThreadBase *thread = checkThread_l(ioHandle); 7734a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten if (thread == NULL) { 7744a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten ALOGW("frameCountHAL() unknown thread %d", ioHandle); 7754a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten return 0; 7764a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten } 7774a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten return thread->frameCountHAL(); 7784a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten} 7794a8308b11b92e608cdaf29f73f7919e75706f9a2Glenn Kasten 78072ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenuint32_t AudioFlinger::latency(audio_io_handle_t output) const 78165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 78265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 78365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 78465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 785c9b2e20f7c9a71e07ef398152709c76079decbcdGlenn Kasten ALOGW("latency(): no playback thread found for output handle %d", output); 78665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 78765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 78865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return thread->latency(); 78965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 79065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 79165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::setMasterVolume(float value) 79265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 793a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 794a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 795a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return ret; 796a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 797a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent 79865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 79965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 80065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 80165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 80265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 803a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent Mutex::Autolock _l(mLock); 804ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mMasterVolume = value; 805a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent 806ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // Set master volume in the HALs which support it. 807ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 808ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AutoMutex lock(mHardwareLock); 809ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AudioHwDevice *dev = mAudioHwDevs.valueAt(i); 8104ff14bae91075eb274eb1c2975982358946e7e63John Grossman 811ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME; 812ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman if (dev->canSetMasterVolume()) { 813ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman dev->hwDevice()->set_master_volume(dev->hwDevice(), value); 814935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent } 815ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mHardwareStatus = AUDIO_HW_IDLE; 81665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 81765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 818ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // Now set the master volume in each playback thread. Playback threads 819ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // assigned to HALs which do not have master volume support will apply 820ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // master volume during the mix operation. Threads with HALs which do 821ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // support master volume will simply ignore the setting. 822f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 823f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent if (mPlaybackThreads.valueAt(i)->isDuplicating()) { 824f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent continue; 825f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent } 826ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mPlaybackThreads.valueAt(i)->setMasterVolume(value); 827f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent } 82865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 82965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 83065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 83165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 832f78aee70d15daf4690de7e7b4983ee68b0d1381dGlenn Kastenstatus_t AudioFlinger::setMode(audio_mode_t mode) 83365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 834a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 835a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 836a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return ret; 837a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 83865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 83965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 84065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 84165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 84265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 843930f4caa1e311ef7ff538c421a324396157eb24fGlenn Kasten if (uint32_t(mode) >= AUDIO_MODE_CNT) { 8445ff1dd576bb93c45b44088a51544a18fc43ebf58Steve Block ALOGW("Illegal value: setMode(%d)", mode); 84565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 84665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 84765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 84865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { // scope for the lock 84965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mHardwareLock); 850ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); 85165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_SET_MODE; 852ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman ret = dev->set_mode(dev, mode); 85365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_IDLE; 85465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 85565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 85665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (NO_ERROR == ret) { 85765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 85865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mMode = mode; 8598d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten for (size_t i = 0; i < mPlaybackThreads.size(); i++) 860e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten mPlaybackThreads.valueAt(i)->setMode(mode); 86165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 86265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 86365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return ret; 86465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 86565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 86665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::setMicMute(bool state) 86765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 868a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 869a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 870a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return ret; 871a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 872a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent 87365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 87465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 87565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 87665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 87765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 87865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mHardwareLock); 87965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_SET_MIC_MUTE; 8802f035f59d1e28728d38d18a7f0f7a9c6e8b0c11bEric Laurent for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 8812f035f59d1e28728d38d18a7f0f7a9c6e8b0c11bEric Laurent audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice(); 8822f035f59d1e28728d38d18a7f0f7a9c6e8b0c11bEric Laurent status_t result = dev->set_mic_mute(dev, state); 8832f035f59d1e28728d38d18a7f0f7a9c6e8b0c11bEric Laurent if (result != NO_ERROR) { 8842f035f59d1e28728d38d18a7f0f7a9c6e8b0c11bEric Laurent ret = result; 8852f035f59d1e28728d38d18a7f0f7a9c6e8b0c11bEric Laurent } 8862f035f59d1e28728d38d18a7f0f7a9c6e8b0c11bEric Laurent } 88765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_IDLE; 88865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return ret; 88965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 89065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 89165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianbool AudioFlinger::getMicMute() const 89265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 893a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 894a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 895a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return false; 896a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 8973e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia bool mute = true; 898fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin bool state = AUDIO_MODE_INVALID; 8992b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten AutoMutex lock(mHardwareLock); 90065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_GET_MIC_MUTE; 9013e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 9023e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice(); 9033e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia status_t result = dev->get_mic_mute(dev, &state); 9043e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia if (result == NO_ERROR) { 9053e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia mute = mute && state; 9063e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia } 9073e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia } 90865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_IDLE; 9093e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia 9103e91b5d11866599e8f33e63fb3b6c1d81ce1a1d2Ricardo Garcia return mute; 91165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 91265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 91365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::setMasterMute(bool muted) 91465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 915d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman status_t ret = initCheck(); 916d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman if (ret != NO_ERROR) { 917d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman return ret; 918d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman } 919d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 92065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 92165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 92265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 92365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 92465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 925ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman Mutex::Autolock _l(mLock); 926ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mMasterMute = muted; 927d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 928ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // Set master mute in the HALs which support it. 929ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 930ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AutoMutex lock(mHardwareLock); 931ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman AudioHwDevice *dev = mAudioHwDevs.valueAt(i); 932d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 933ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE; 934ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman if (dev->canSetMasterMute()) { 935ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman dev->hwDevice()->set_master_mute(dev->hwDevice(), muted); 936d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman } 937ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mHardwareStatus = AUDIO_HW_IDLE; 938d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman } 939d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 940ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // Now set the master mute in each playback thread. Playback threads 941ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // assigned to HALs which do not have master mute support will apply master 942ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // mute during the mix operation. Threads with HALs which do support master 943ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman // mute will simply ignore the setting. 944f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 945f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent if (mPlaybackThreads.valueAt(i)->isDuplicating()) { 946f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent continue; 947f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent } 948ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman mPlaybackThreads.valueAt(i)->setMasterMute(muted); 949f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent } 95065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 95165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 95265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 95365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 95465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianfloat AudioFlinger::masterVolume() const 95565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 9569806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten Mutex::Autolock _l(mLock); 9579806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten return masterVolume_l(); 95865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 95965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 96065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianbool AudioFlinger::masterMute() const 96165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 9629806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten Mutex::Autolock _l(mLock); 9639806710f5d6722cfc5783c7eca3512451a0f2035Glenn Kasten return masterMute_l(); 96465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 96565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 9664ff14bae91075eb274eb1c2975982358946e7e63John Grossmanfloat AudioFlinger::masterVolume_l() const 9674ff14bae91075eb274eb1c2975982358946e7e63John Grossman{ 9684ff14bae91075eb274eb1c2975982358946e7e63John Grossman return mMasterVolume; 9694ff14bae91075eb274eb1c2975982358946e7e63John Grossman} 9704ff14bae91075eb274eb1c2975982358946e7e63John Grossman 971d8f178d613821c3f61a5c5e391eb275339e526a9John Grossmanbool AudioFlinger::masterMute_l() const 972d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman{ 973ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman return mMasterMute; 974d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman} 975d8f178d613821c3f61a5c5e391eb275339e526a9John Grossman 976223fd5c9738e9665e495904d37d4632414b68c1eEric Laurentstatus_t AudioFlinger::checkStreamType(audio_stream_type_t stream) const 977223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent{ 978223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent if (uint32_t(stream) >= AUDIO_STREAM_CNT) { 979223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent ALOGW("setStreamVolume() invalid stream %d", stream); 980223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent return BAD_VALUE; 981223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent } 982223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent pid_t caller = IPCThreadState::self()->getCallingPid(); 983223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT && caller != getpid_cached) { 984223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent ALOGW("setStreamVolume() pid %d cannot use internal stream type %d", caller, stream); 985223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent return PERMISSION_DENIED; 986223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent } 987223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent 988223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent return NO_ERROR; 989223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent} 990223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent 99172ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenstatus_t AudioFlinger::setStreamVolume(audio_stream_type_t stream, float value, 99272ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten audio_io_handle_t output) 99365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 99465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 99565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 99665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 99765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 99865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 999223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent status_t status = checkStreamType(stream); 1000223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent if (status != NO_ERROR) { 1001223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent return status; 100265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 1003223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent ALOG_ASSERT(stream != AUDIO_STREAM_PATCH, "attempt to change AUDIO_STREAM_PATCH volume"); 100465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 100565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mLock); 100665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = NULL; 1007142f519aa1acd5804d111e60d100f170fed28405Glenn Kasten if (output != AUDIO_IO_HANDLE_NONE) { 100865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian thread = checkPlaybackThread_l(output); 100965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 101065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 101165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 101265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 101365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 101465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mStreamTypes[stream].volume = value; 101565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 101665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 10178d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 1018e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten mPlaybackThreads.valueAt(i)->setStreamVolume(stream, value); 101965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 102065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 102165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian thread->setStreamVolume(stream, value); 102265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 102365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 102465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 102565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 102665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1027fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kastenstatus_t AudioFlinger::setStreamMute(audio_stream_type_t stream, bool muted) 102865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 102965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 103065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 103165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 103265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 103365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1034223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent status_t status = checkStreamType(stream); 1035223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent if (status != NO_ERROR) { 1036223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent return status; 1037223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent } 1038223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent ALOG_ASSERT(stream != AUDIO_STREAM_PATCH, "attempt to mute AUDIO_STREAM_PATCH"); 1039223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent 1040223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent if (uint32_t(stream) == AUDIO_STREAM_ENFORCED_AUDIBLE) { 104129357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("setStreamMute() invalid stream %d", stream); 104265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 104365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 104465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1045935752053ef2691dbb6d5a6d149e0e362c6e3c74Eric Laurent AutoMutex lock(mLock); 104665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mStreamTypes[stream].mute = muted; 10473ab368e0810d894dcbc0971350c095049478a055Mark Salyzyn for (size_t i = 0; i < mPlaybackThreads.size(); i++) 1048e53b9ead781c36e96d6b6f012ddffc93a3d80f0dGlenn Kasten mPlaybackThreads.valueAt(i)->setStreamMute(stream, muted); 104965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 105065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return NO_ERROR; 105165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 105265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 105372ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenfloat AudioFlinger::streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const 105465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1055223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent status_t status = checkStreamType(stream); 1056223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent if (status != NO_ERROR) { 105765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0.0f; 105865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 105965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 106065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mLock); 106165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian float volume; 1062142f519aa1acd5804d111e60d100f170fed28405Glenn Kasten if (output != AUDIO_IO_HANDLE_NONE) { 106365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *thread = checkPlaybackThread_l(output); 106465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (thread == NULL) { 106565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0.0f; 106665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 106765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian volume = thread->streamVolume(stream); 106865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } else { 10696637baae4244aec731c4014da72418d330636ae1Glenn Kasten volume = streamVolume_l(stream); 107065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 107165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 107265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return volume; 107365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 107465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1075fff6d715a8db0daf08a50634f242c40268de3d49Glenn Kastenbool AudioFlinger::streamMute(audio_stream_type_t stream) const 107665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1077223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent status_t status = checkStreamType(stream); 1078223fd5c9738e9665e495904d37d4632414b68c1eEric Laurent if (status != NO_ERROR) { 107965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return true; 108065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 108165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 10826637baae4244aec731c4014da72418d330636ae1Glenn Kasten AutoMutex lock(mLock); 10836637baae4244aec731c4014da72418d330636ae1Glenn Kasten return streamMute_l(stream); 108465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 108565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1086054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent 1087054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurentvoid AudioFlinger::broacastParametersToRecordThreads_l(const String8& keyValuePairs) 1088054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent{ 1089054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 1090054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent mRecordThreads.valueAt(i)->setParameters(keyValuePairs); 1091054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent } 1092054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent} 1093054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent 109472ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kastenstatus_t AudioFlinger::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) 109565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1096827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ALOGV("setParameters(): io %d, keyvalue %s, calling pid %d", 1097827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ioHandle, keyValuePairs.string(), IPCThreadState::self()->getCallingPid()); 109881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 109965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 110065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 110165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 110265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 110365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1104142f519aa1acd5804d111e60d100f170fed28405Glenn Kasten // AUDIO_IO_HANDLE_NONE means the parameters are global to the audio hardware interface 1105142f519aa1acd5804d111e60d100f170fed28405Glenn Kasten if (ioHandle == AUDIO_IO_HANDLE_NONE) { 1106a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent Mutex::Autolock _l(mLock); 1107d21bcd272d43285baa32ffd48c909b4a29c614a4Eric Laurent // result will remain NO_INIT if no audio device is present 1108d21bcd272d43285baa32ffd48c909b4a29c614a4Eric Laurent status_t final_result = NO_INIT; 11098abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten { 1110a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent AutoMutex lock(mHardwareLock); 1111a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent mHardwareStatus = AUDIO_HW_SET_PARAMETER; 1112a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 1113a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice(); 1114a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent status_t result = dev->set_parameters(dev, keyValuePairs.string()); 1115d21bcd272d43285baa32ffd48c909b4a29c614a4Eric Laurent // return success if at least one audio device accepts the parameters as not all 1116d21bcd272d43285baa32ffd48c909b4a29c614a4Eric Laurent // HALs are requested to support all parameters. If no audio device supports the 1117d21bcd272d43285baa32ffd48c909b4a29c614a4Eric Laurent // requested parameters, the last error is reported. 1118d21bcd272d43285baa32ffd48c909b4a29c614a4Eric Laurent if (final_result != NO_ERROR) { 1119d21bcd272d43285baa32ffd48c909b4a29c614a4Eric Laurent final_result = result; 1120d21bcd272d43285baa32ffd48c909b4a29c614a4Eric Laurent } 1121a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent } 1122a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 11238abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten } 112459bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent // disable AEC and NS if the device is a BT SCO headset supporting those pre processings 112559bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent AudioParameter param = AudioParameter(keyValuePairs); 112659bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent String8 value; 112759bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent if (param.get(String8(AUDIO_PARAMETER_KEY_BT_NREC), value) == NO_ERROR) { 1128bee5337da7659b3b7128622ba1f42618b11df5beEric Laurent bool btNrecIsOff = (value == AUDIO_PARAMETER_VALUE_OFF); 1129bee5337da7659b3b7128622ba1f42618b11df5beEric Laurent if (mBtNrecIsOff != btNrecIsOff) { 113059bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 113159bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent sp<RecordThread> thread = mRecordThreads.valueAt(i); 1132f1c04f952916cf70407051c9f824ab84fb2b6e09Eric Laurent audio_devices_t device = thread->inDevice(); 1133510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten bool suspend = audio_is_bluetooth_sco_device(device) && btNrecIsOff; 1134510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten // collect all of the thread's session IDs 1135d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten KeyedVector<audio_session_t, bool> ids = thread->sessionIds(); 1136510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten // suspend effects associated with those session IDs 1137510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten for (size_t j = 0; j < ids.size(); ++j) { 1138d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t sessionId = ids.keyAt(j); 113959bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent thread->setEffectSuspended(FX_IID_AEC, 114059bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent suspend, 1141510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten sessionId); 114259bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent thread->setEffectSuspended(FX_IID_NS, 114359bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent suspend, 1144510a3d6b8018a77683dac466127ffd0af34bef6eGlenn Kasten sessionId); 114559bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent } 114659bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent } 1147bee5337da7659b3b7128622ba1f42618b11df5beEric Laurent mBtNrecIsOff = btNrecIsOff; 114859bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent } 114959bd0da8373af0e5159b799495fda51e03120ea4Eric Laurent } 115028ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten String8 screenState; 115128ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten if (param.get(String8(AudioParameter::keyScreenState), screenState) == NO_ERROR) { 115228ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten bool isOff = screenState == "off"; 115381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (isOff != (AudioFlinger::mScreenState & 1)) { 115481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioFlinger::mScreenState = ((AudioFlinger::mScreenState & ~1) + 2) | isOff; 115528ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten } 115628ed2f93324988767b5658eba7c1fa781a275183Glenn Kasten } 1157799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin return final_result; 115865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 115965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 116065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // hold a strong ref on thread in case closeOutput() or closeInput() is called 116165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // and the thread is exited once the lock is released 116265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian sp<ThreadBase> thread; 116365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian { 116465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 116565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian thread = checkPlaybackThread_l(ioHandle); 1166d5903ec1332630f2992a6f0d5ca69d13a185c665Glenn Kasten if (thread == 0) { 116765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian thread = checkRecordThread_l(ioHandle); 11687fc9a6fdf146ded90b51c52f4a05d797294dcb85Glenn Kasten } else if (thread == primaryPlaybackThread_l()) { 11697c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent // indicate output device change to all input threads for pre processing 11707c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent AudioParameter param = AudioParameter(keyValuePairs); 11717c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent int value; 117289d94e79dad032fb18ddc655e6068e4231d3f0aaEric Laurent if ((param.getInt(String8(AudioParameter::keyRouting), value) == NO_ERROR) && 117389d94e79dad032fb18ddc655e6068e4231d3f0aaEric Laurent (value != 0)) { 1174054d9d3dea1390294650ac704acb4aa0a0731217Eric Laurent broacastParametersToRecordThreads_l(keyValuePairs); 11757c7f10bd4fda9a084e5e7f0eb3a040dfcbf01745Eric Laurent } 117665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 117765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 11787378ca506e4e20c2b2d4e94a131cf1b95831adb5Glenn Kasten if (thread != 0) { 11797378ca506e4e20c2b2d4e94a131cf1b95831adb5Glenn Kasten return thread->setParameters(keyValuePairs); 118065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 118165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 118265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 118365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 118472ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn KastenString8 AudioFlinger::getParameters(audio_io_handle_t ioHandle, const String8& keys) const 118565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1186827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ALOGVV("getParameters() io %d, keys %s, calling pid %d", 1187827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ioHandle, keys.string(), IPCThreadState::self()->getCallingPid()); 118865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1189a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent Mutex::Autolock _l(mLock); 1190a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent 1191142f519aa1acd5804d111e60d100f170fed28405Glenn Kasten if (ioHandle == AUDIO_IO_HANDLE_NONE) { 1192fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin String8 out_s8; 1193fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 1194799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 11958abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten char *s; 11968abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten { 11978abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten AutoMutex lock(mHardwareLock); 11988abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten mHardwareStatus = AUDIO_HW_GET_PARAMETER; 1199a4c5a550e2a3bc237179b8684e51718e05894492Eric Laurent audio_hw_device_t *dev = mAudioHwDevs.valueAt(i)->hwDevice(); 12008abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten s = dev->get_parameters(dev, keys.string()); 12018abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten mHardwareStatus = AUDIO_HW_IDLE; 12028abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten } 1203ef7740be67a4d7b6b033ebed59c3d4a9c74a2c18John Grossman out_s8 += String8(s ? s : ""); 1204799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin free(s); 1205799a70e7028a4d714436c3a744a775acfbd31aaeDima Zavin } 1206fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin return out_s8; 120765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 120865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 120965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *playbackThread = checkPlaybackThread_l(ioHandle); 121065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (playbackThread != NULL) { 121165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return playbackThread->getParameters(keys); 121265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 121365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian RecordThread *recordThread = checkRecordThread_l(ioHandle); 121465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (recordThread != NULL) { 121565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return recordThread->getParameters(keys); 121665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 121765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return String8(""); 121865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 121965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1220dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kastensize_t AudioFlinger::getInputBufferSize(uint32_t sampleRate, audio_format_t format, 1221dd8104cc5367262f0e5f13df4e79f131e8d560bbGlenn Kasten audio_channel_mask_t channelMask) const 122265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1223a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 1224a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 1225a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return 0; 1226a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 1227cdf924a32579e92ea456e8e7d5c14ed5920b620fEric Laurent if ((sampleRate == 0) || 1228fdb3c07db5d44535eb8c3ec46dc78ad8446c01ebPhil Burk !audio_is_valid_format(format) || !audio_has_proportional_frames(format) || 1229cdf924a32579e92ea456e8e7d5c14ed5920b620fEric Laurent !audio_is_input_channel(channelMask)) { 12306770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung return 0; 12316770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung } 1232a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent 12332b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten AutoMutex lock(mHardwareLock); 12342b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten mHardwareStatus = AUDIO_HW_GET_INPUT_BUFFER_SIZE; 12356770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung audio_config_t config, proposed; 12366770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung memset(&proposed, 0, sizeof(proposed)); 12376770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung proposed.sample_rate = sampleRate; 12386770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung proposed.channel_mask = channelMask; 12396770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung proposed.format = format; 1240ad3af3305f024bcbbd55c894a4995e449498e1baRichard Fitzgerald 1241ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); 12426770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung size_t frames; 12436770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung for (;;) { 12446770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung // Note: config is currently a const parameter for get_input_buffer_size() 12456770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung // but we use a copy from proposed in case config changes from the call. 12466770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung config = proposed; 12476770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung frames = dev->get_input_buffer_size(dev, &config); 12486770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung if (frames != 0) { 12496770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung break; // hal success, config is the result 12506770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung } 12516770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung // change one parameter of the configuration each iteration to a more "common" value 12526770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung // to see if the device will support it. 12536770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung if (proposed.format != AUDIO_FORMAT_PCM_16_BIT) { 12546770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung proposed.format = AUDIO_FORMAT_PCM_16_BIT; 12556770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung } else if (proposed.sample_rate != 44100) { // 44.1 is claimed as must in CDD as well as 12566770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung proposed.sample_rate = 44100; // legacy AudioRecord.java. TODO: Query hw? 12576770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung } else { 12586770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung ALOGW("getInputBufferSize failed with minimum buffer size sampleRate %u, " 12596770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung "format %#x, channelMask 0x%X", 12606770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung sampleRate, format, channelMask); 12616770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung break; // retries failed, break out of loop with frames == 0. 12626770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung } 12636770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung } 12642b213bc220768d2b984239511cd4554a96bc0079Glenn Kasten mHardwareStatus = AUDIO_HW_IDLE; 12656770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung if (frames > 0 && config.sample_rate != sampleRate) { 12666770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung frames = destinationFramesPossible(frames, sampleRate, config.sample_rate); 12676770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung } 12686770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung return frames; // may be converted to bytes at the Java level. 126965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 127065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 12715f972c031d4061f4f037c9fda1ea4bd9b6a756cdGlenn Kastenuint32_t AudioFlinger::getInputFramesLost(audio_io_handle_t ioHandle) const 127265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 127365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 127465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 127565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian RecordThread *recordThread = checkRecordThread_l(ioHandle); 127665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (recordThread != NULL) { 127765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return recordThread->getInputFramesLost(); 127865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 127965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return 0; 128065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 128165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 128265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::setVoiceVolume(float value) 128365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1284a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent status_t ret = initCheck(); 1285a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent if (ret != NO_ERROR) { 1286a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent return ret; 1287a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent } 1288a1884f9e9ec3836683efd7eb333ee442e8bc9d56Eric Laurent 128965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian // check calling permissions 129065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (!settingsAllowed()) { 129165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return PERMISSION_DENIED; 129265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 129365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 129465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian AutoMutex lock(mHardwareLock); 1295ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); 12968abf44d2f2bcd20a2835570efe89d89c19db426aGlenn Kasten mHardwareStatus = AUDIO_HW_SET_VOICE_VOLUME; 1297ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman ret = dev->set_voice_volume(dev, value); 129865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mHardwareStatus = AUDIO_HW_IDLE; 129965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 130065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return ret; 130165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 130265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1303377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETITstatus_t AudioFlinger::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, 130472ef00de10fa95bfcb948ed88ab9b7a177ed0b48Glenn Kasten audio_io_handle_t output) const 130565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 130665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 130765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 130865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian PlaybackThread *playbackThread = checkPlaybackThread_l(output); 130965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian if (playbackThread != NULL) { 131065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return playbackThread->getRenderPosition(halFrames, dspFrames); 131165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 131265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 131365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BAD_VALUE; 131465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 131565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 131665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioFlinger::registerClient(const sp<IAudioFlingerClient>& client) 131765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 131865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 131944622db93a24219123facbbe14259000f90de728Eric Laurent if (client == 0) { 132044622db93a24219123facbbe14259000f90de728Eric Laurent return; 132144622db93a24219123facbbe14259000f90de728Eric Laurent } 13227c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent pid_t pid = IPCThreadState::self()->getCallingPid(); 1323021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent { 1324021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent Mutex::Autolock _cl(mClientLock); 1325021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent if (mNotificationClients.indexOfKey(pid) < 0) { 1326021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent sp<NotificationClient> notificationClient = new NotificationClient(this, 1327021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent client, 1328021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent pid); 1329021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent ALOGV("registerClient() client %p, pid %d", notificationClient.get(), pid); 133065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1331021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent mNotificationClients.add(pid, notificationClient); 133265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 133306b46062d2f8bc82ca3061a23d197734ae51918bMarco Nelissen sp<IBinder> binder = IInterface::asBinder(client); 1334021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent binder->linkToDeath(notificationClient); 1335021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent } 1336021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent } 133765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1338021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent // mClientLock should not be held here because ThreadBase::sendIoConfigEvent() will lock the 1339fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent // ThreadBase mutex and the locking order is ThreadBase::mLock then AudioFlinger::mClientLock. 13407c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent // the config change is always sent from playback or record threads to avoid deadlock 13417c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent // with AudioSystem::gLock 13427c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 13437c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AUDIO_OUTPUT_OPENED, pid); 13447c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent } 134565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 13467c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 13477c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent mRecordThreads.valueAt(i)->sendIoConfigEvent(AUDIO_INPUT_OPENED, pid); 134865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 134965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 135065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 135165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioFlinger::removeNotificationClient(pid_t pid) 135265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 135365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 1354021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent { 1355021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent Mutex::Autolock _cl(mClientLock); 1356021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent mNotificationClients.removeItem(pid); 1357021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent } 13583a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen 13593856b090cd04ba5dd4a59a12430ed724d5995909Steve Block ALOGV("%d died, releasing its sessions", pid); 13608d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten size_t num = mAudioSessionRefs.size(); 13613a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen bool removed = false; 13628d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten for (size_t i = 0; i< num; ) { 13633a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen AudioSessionRef *ref = mAudioSessionRefs.itemAt(i); 1364c42e9b462661673dff480ee71757a58b0f806370Glenn Kasten ALOGV(" pid %d @ %zu", ref->mPid, i); 1365012ca6b4f69fb24385025c0e84b8f816525a3032Glenn Kasten if (ref->mPid == pid) { 1366012ca6b4f69fb24385025c0e84b8f816525a3032Glenn Kasten ALOGV(" removing entry for pid %d session %d", pid, ref->mSessionid); 13673a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen mAudioSessionRefs.removeAt(i); 13683a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen delete ref; 13693a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen removed = true; 13703a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen num--; 13718d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten } else { 13728d6a2449a91f5116d7243ab039393195ebd663feGlenn Kasten i++; 13733a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen } 13743a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen } 13753a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen if (removed) { 13763a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen purgeStaleEffects_l(); 13773a34befc6fb04a4945a849e8bda8b84e4bf973feMarco Nelissen } 137865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 137965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 138073e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurentvoid AudioFlinger::ioConfigChanged(audio_io_config_event event, 13817c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent const sp<AudioIoDescriptor>& ioDesc, 13827c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent pid_t pid) 138365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1384021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent Mutex::Autolock _l(mClientLock); 1385021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent size_t size = mNotificationClients.size(); 138665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian for (size_t i = 0; i < size; i++) { 13877c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent if ((pid == 0) || (mNotificationClients.keyAt(i) == pid)) { 13887c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, ioDesc); 13897c1ec5f038e63a5eb8b04434577c25bc23f5f410Eric Laurent } 139065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 139165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 139265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1393021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent// removeClient_l() must be called with AudioFlinger::mClientLock held 139465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianvoid AudioFlinger::removeClient_l(pid_t pid) 139565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1396827e5f1237757aee78b677efcf0f7c44fd0dd3d8Glenn Kasten ALOGV("removeClient_l() pid %d, calling pid %d", pid, 139785ab62c4b433df3f1a9826bed1c9bec07a86c750Glenn Kasten IPCThreadState::self()->getCallingPid()); 139865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian mClients.removeItem(pid); 139965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 140065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1401717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent// getEffectThread_l() must be called with AudioFlinger::mLock held 1402d848eb48c121c119e8ba7583efc75415fe102570Glenn Kastensp<AudioFlinger::PlaybackThread> AudioFlinger::getEffectThread_l(audio_session_t sessionId, 1403d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten int EffectId) 1404717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent{ 1405717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent sp<PlaybackThread> thread; 1406717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent 1407717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 1408717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent if (mPlaybackThreads.valueAt(i)->getEffect(sessionId, EffectId) != 0) { 1409717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent ALOG_ASSERT(thread == 0); 1410717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent thread = mPlaybackThreads.valueAt(i); 1411717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent } 1412717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent } 1413717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent 1414717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent return thread; 1415717e128691f083a9469a1d0e363ac6ecd5c65d58Eric Laurent} 141665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 141781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 141881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 141965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 142065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 142181784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::Client::Client(const sp<AudioFlinger>& audioFlinger, pid_t pid) 142281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent : RefBase(), 142381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioFlinger(audioFlinger), 1424d79072e9dff59f767cce2cda1caab80ce5a0815bGlenn Kasten mPid(pid) 142565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 1426da73b6c7474aaa5616f0214e238776f12717f32bEric Laurent size_t heapSize = kClientSharedHeapSizeBytes; 1427da73b6c7474aaa5616f0214e238776f12717f32bEric Laurent // Increase heap size on non low ram devices to limit risk of reconnection failure for 1428da73b6c7474aaa5616f0214e238776f12717f32bEric Laurent // invalidated tracks 1429da73b6c7474aaa5616f0214e238776f12717f32bEric Laurent if (!audioFlinger->isLowRamDevice()) { 1430da73b6c7474aaa5616f0214e238776f12717f32bEric Laurent heapSize *= kClientSharedHeapSizeMultiplier; 1431da73b6c7474aaa5616f0214e238776f12717f32bEric Laurent } 1432da73b6c7474aaa5616f0214e238776f12717f32bEric Laurent mMemoryDealer = new MemoryDealer(heapSize, "AudioFlinger::Client"); 143365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 143465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1435021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent// Client destructor must be called with AudioFlinger::mClientLock held 143681784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::Client::~Client() 143765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 143881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioFlinger->removeClient_l(mPid); 143965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 144065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 144181784c37c61b09289654b979567a42bf73cd2b12Eric Laurentsp<MemoryDealer> AudioFlinger::Client::heap() const 144265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 144381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return mMemoryDealer; 144465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 144565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 144681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 144781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 144881784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::NotificationClient::NotificationClient(const sp<AudioFlinger>& audioFlinger, 144981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent const sp<IAudioFlingerClient>& client, 145081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid_t pid) 145181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent : mAudioFlinger(audioFlinger), mPid(pid), mAudioFlingerClient(client) 1452896adcd3ae6a1c7010e526327eff54e16179987bEric Laurent{ 145365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 145465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 145581784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::NotificationClient::~NotificationClient() 145665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 145765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 145865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 14590f11b51a57bc9062c4fe8af73747319cedabc5d6Glenn Kastenvoid AudioFlinger::NotificationClient::binderDied(const wp<IBinder>& who __unused) 146065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 146181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<NotificationClient> keep(this); 146281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioFlinger->removeNotificationClient(mPid); 146381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent} 146465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 146565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 146681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 146765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 146881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentsp<IAudioRecord> AudioFlinger::openRecord( 146981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t input, 147081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t sampleRate, 147181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_format_t format, 147281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_channel_mask_t channelMask, 1473be71aa29a3c86d2e01cd17839d2a72ab09a1bce5Svet Ganov const String16& opPackageName, 147474935e44734c1ec235c2b6677db3e0dbefa5ddb8Glenn Kasten size_t *frameCount, 1475050677873c10d4da308ac222f8533c96cca3207eEric Laurent audio_input_flags_t *flags, 14769ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George pid_t pid, 147781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid_t tid, 14784cb668392ee0433462251afbee109405c6efacc8Jean-Michel Trivi int clientUid, 1479d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t *sessionId, 14807df8c0b799d8f52d6386e03313286dbd7d5cdc7cGlenn Kasten size_t *notificationFrames, 1481d776ac63ce9c013c9626226e43f7db606e035838Glenn Kasten sp<IMemory>& cblk, 1482d776ac63ce9c013c9626226e43f7db606e035838Glenn Kasten sp<IMemory>& buffers, 148381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t *status) 14841d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent{ 148581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<RecordThread::RecordTrack> recordTrack; 148681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<RecordHandle> recordHandle; 148781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<Client> client; 148881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t lStatus; 1489d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t lSessionId; 14901d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent 1491d776ac63ce9c013c9626226e43f7db606e035838Glenn Kasten cblk.clear(); 1492d776ac63ce9c013c9626226e43f7db606e035838Glenn Kasten buffers.clear(); 1493d776ac63ce9c013c9626226e43f7db606e035838Glenn Kasten 14949ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George bool updatePid = (pid == -1); 1495dcb346b7dc5b88c3e85db8a70bbd6a2fee8192b9Marco Nelissen const uid_t callingUid = IPCThreadState::self()->getCallingUid(); 1496dcb346b7dc5b88c3e85db8a70bbd6a2fee8192b9Marco Nelissen if (!isTrustedCallingUid(callingUid)) { 1497879db19219c120d424f7d7ad7164c3cfe56124e4Andy Hung ALOGW_IF((uid_t)clientUid != callingUid, 1498dcb346b7dc5b88c3e85db8a70bbd6a2fee8192b9Marco Nelissen "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, clientUid); 1499dcb346b7dc5b88c3e85db8a70bbd6a2fee8192b9Marco Nelissen clientUid = callingUid; 15009ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George updatePid = true; 15019ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George } 15029ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George 15039ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George if (updatePid) { 15049ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George const pid_t callingPid = IPCThreadState::self()->getCallingPid(); 15059ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George ALOGW_IF(pid != -1 && pid != callingPid, 15069ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George "%s uid %d pid %d tried to pass itself off as pid %d", 15079ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George __func__, callingUid, callingPid, pid); 15089ea77cdba8c422940adb57a790b44ac04fe0353fHaynes Mathew George pid = callingPid; 1509dcb346b7dc5b88c3e85db8a70bbd6a2fee8192b9Marco Nelissen } 1510dcb346b7dc5b88c3e85db8a70bbd6a2fee8192b9Marco Nelissen 151181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // check calling permissions 1512dcb346b7dc5b88c3e85db8a70bbd6a2fee8192b9Marco Nelissen if (!recordingAllowed(opPackageName, tid, clientUid)) { 1513e93cf2ca27ae6f4a81d4ef548bbf10a34db6d98fGlenn Kasten ALOGE("openRecord() permission denied: recording not allowed"); 151481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = PERMISSION_DENIED; 151581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 151681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 15171d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent 151853b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten // further sample rate checks are performed by createRecordTrack_l() 151953b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten if (sampleRate == 0) { 152053b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten ALOGE("openRecord() invalid sample rate %u", sampleRate); 152153b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten lStatus = BAD_VALUE; 152253b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten goto Exit; 152353b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten } 152453b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten 15256770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung // we don't yet support anything other than linear PCM 15266770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung if (!audio_is_valid_format(format) || !audio_is_linear_pcm(format)) { 1527cac3daa6332bf6d1f7d26adc4a9915f3d7992dd9Glenn Kasten ALOGE("openRecord() invalid format %#x", format); 1528291bb6d8947c5b0c062f0895d623c529259bfa39Glenn Kasten lStatus = BAD_VALUE; 152953b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten goto Exit; 153053b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten } 153153b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten 153253b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten // further channel mask checks are performed by createRecordTrack_l() 153353b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten if (!audio_is_input_channel(channelMask)) { 153453b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten ALOGE("openRecord() invalid channel mask %#x", channelMask); 153553b5d098b7d5d4412b9b9fe08daaf84c56b716e9Glenn Kasten lStatus = BAD_VALUE; 1536291bb6d8947c5b0c062f0895d623c529259bfa39Glenn Kasten goto Exit; 1537291bb6d8947c5b0c062f0895d623c529259bfa39Glenn Kasten } 1538291bb6d8947c5b0c062f0895d623c529259bfa39Glenn Kasten 153905997e21af6c4517f375def6563af4b9ebe95f39Glenn Kasten { 154081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 1541e848bd9abb3bbbd4c66f9fb9d1442f7663d7ba40Glenn Kasten RecordThread *thread = checkRecordThread_l(input); 154281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 1543e93cf2ca27ae6f4a81d4ef548bbf10a34db6d98fGlenn Kasten ALOGE("openRecord() checkRecordThread_l failed"); 154481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 154581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 15461d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent } 15471d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent 1548021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent client = registerPid(pid); 1549feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 1550aea7ea06394bcb155972d82055d4ea59962e4051Glenn Kasten if (sessionId != NULL && *sessionId != AUDIO_SESSION_ALLOCATE) { 1551eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten if (audio_unique_id_get_use(*sessionId) != AUDIO_UNIQUE_ID_USE_SESSION) { 1552eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten lStatus = BAD_VALUE; 1553eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten goto Exit; 1554eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten } 155581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lSessionId = *sessionId; 1556feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent } else { 1557570f633e0b02d1bc25f3312b92e72cc29a40ca38Glenn Kasten // if no audio session id is provided, create one here 1558d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten lSessionId = (audio_session_t) nextUniqueId(AUDIO_UNIQUE_ID_USE_SESSION); 155981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId != NULL) { 156081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *sessionId = lSessionId; 156181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 1562feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent } 1563aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent ALOGV("openRecord() lSessionId: %d input %d", lSessionId, input); 1564570f633e0b02d1bc25f3312b92e72cc29a40ca38Glenn Kasten 156581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent recordTrack = thread->createRecordTrack_l(client, sampleRate, format, channelMask, 15667df8c0b799d8f52d6386e03313286dbd7d5cdc7cGlenn Kasten frameCount, lSessionId, notificationFrames, 15674cb668392ee0433462251afbee109405c6efacc8Jean-Michel Trivi clientUid, flags, tid, &lStatus); 156803e9e83c47ab4a518da0a1f36b8f702f59221c95Haynes Mathew George LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (recordTrack == 0)); 15691b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent 15701b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent if (lStatus == NO_ERROR) { 15711b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // Check if one effect chain was awaiting for an AudioRecord to be created on this 15721b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // session and move it to this thread. 1573d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten sp<EffectChain> chain = getOrphanEffectChain_l(lSessionId); 15741b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent if (chain != 0) { 15751b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent Mutex::Autolock _l(thread->mLock); 15761b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent thread->addEffectChain_l(chain); 15771b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent } 15781b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent } 1579feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent } 1580e198c360d5e75a9b2097844c495c10902e7e8500Glenn Kasten 158181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (lStatus != NO_ERROR) { 158281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // remove local strong reference to Client before deleting the RecordTrack so that the 1583021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent // Client destructor is called by the TrackBase destructor with mClientLock held 1584fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent // Don't hold mClientLock when releasing the reference on the track as the 1585fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent // destructor will acquire it. 1586fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent { 1587fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent Mutex::Autolock _cl(mClientLock); 1588fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent client.clear(); 1589fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent } 159081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent recordTrack.clear(); 159181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 1592feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent } 1593feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 1594d776ac63ce9c013c9626226e43f7db606e035838Glenn Kasten cblk = recordTrack->getCblk(); 1595d776ac63ce9c013c9626226e43f7db606e035838Glenn Kasten buffers = recordTrack->getBuffers(); 1596d776ac63ce9c013c9626226e43f7db606e035838Glenn Kasten 15972fc14730e4697a6f456b4631549c9981f6b0b115Glenn Kasten // return handle to client 159881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent recordHandle = new RecordHandle(recordTrack); 1599feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 160081784c37c61b09289654b979567a42bf73cd2b12Eric LaurentExit: 16019156ef3e11b68cc4b6d3cea77f1f63673855a6d1Glenn Kasten *status = lStatus; 160281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return recordHandle; 1603feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent} 1604feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 1605feb0db689c17dced50afaee54c659f1676e2d505Eric Laurent 16061d2bff0e588afe183a1baaae731519b4e957bbdbEric Laurent 160781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 160881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 160981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_module_handle_t AudioFlinger::loadHwModule(const char *name) 161059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent{ 161144622db93a24219123facbbe14259000f90de728Eric Laurent if (name == NULL) { 1612a13cde98a880341f0a56d91da6364b093fb5d24eGlenn Kasten return AUDIO_MODULE_HANDLE_NONE; 161344622db93a24219123facbbe14259000f90de728Eric Laurent } 161481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (!settingsAllowed()) { 1615a13cde98a880341f0a56d91da6364b093fb5d24eGlenn Kasten return AUDIO_MODULE_HANDLE_NONE; 161681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 161759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent Mutex::Autolock _l(mLock); 161881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return loadHwModule_l(name); 161959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent} 162059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 162181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// loadHwModule_l() must be called with AudioFlinger::mLock held 162281784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_module_handle_t AudioFlinger::loadHwModule_l(const char *name) 162359255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent{ 162481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mAudioHwDevs.size(); i++) { 162581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (strncmp(mAudioHwDevs.valueAt(i)->moduleName(), name, strlen(name)) == 0) { 162681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("loadHwModule() module %s already loaded", name); 162781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return mAudioHwDevs.keyAt(i); 162859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 162959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 163059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 163181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_hw_device_t *dev; 163259255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 163381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int rc = load_audio_interface(name, &dev); 163481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (rc) { 1635c42e9b462661673dff480ee71757a58b0f806370Glenn Kasten ALOGE("loadHwModule() error %d loading module %s", rc, name); 1636a13cde98a880341f0a56d91da6364b093fb5d24eGlenn Kasten return AUDIO_MODULE_HANDLE_NONE; 163759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 163859255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 163981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_INIT; 164081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent rc = dev->init_check(dev); 164181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 164281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (rc) { 1643c42e9b462661673dff480ee71757a58b0f806370Glenn Kasten ALOGE("loadHwModule() init check error %d for module %s", rc, name); 1644a13cde98a880341f0a56d91da6364b093fb5d24eGlenn Kasten return AUDIO_MODULE_HANDLE_NONE; 164559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 164659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 164781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Check and cache this HAL's level of support for master mute and master 164881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // volume. If this is the first HAL opened, and it supports the get 164981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // methods, use the initial values provided by the HAL as the current 165081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // master mute and volume settings. 165159255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 165281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioHwDevice::Flags flags = static_cast<AudioHwDevice::Flags>(0); 165381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent { // scope for auto-lock pattern 165481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AutoMutex lock(mHardwareLock); 165559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 165681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (0 == mAudioHwDevs.size()) { 165781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_GET_MASTER_VOLUME; 165881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (NULL != dev->get_master_volume) { 165981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent float mv; 166081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (OK == dev->get_master_volume(dev, &mv)) { 166181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mMasterVolume = mv; 166281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 166381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 166481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 166581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_GET_MASTER_MUTE; 166681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (NULL != dev->get_master_mute) { 166781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool mm; 166881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (OK == dev->get_master_mute(dev, &mm)) { 166981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mMasterMute = mm; 167081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 167181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 167259255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 167381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 167481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME; 167581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if ((NULL != dev->set_master_volume) && 167681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (OK == dev->set_master_volume(dev, mMasterVolume))) { 167781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent flags = static_cast<AudioHwDevice::Flags>(flags | 167881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioHwDevice::AHWD_CAN_SET_MASTER_VOLUME); 167959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 168059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 168181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE; 168281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if ((NULL != dev->set_master_mute) && 168381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (OK == dev->set_master_mute(dev, mMasterMute))) { 168481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent flags = static_cast<AudioHwDevice::Flags>(flags | 168581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioHwDevice::AHWD_CAN_SET_MASTER_MUTE); 168681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 168759255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 168881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 168959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent } 169059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 1691a13cde98a880341f0a56d91da6364b093fb5d24eGlenn Kasten audio_module_handle_t handle = (audio_module_handle_t) nextUniqueId(AUDIO_UNIQUE_ID_USE_MODULE); 169283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent mAudioHwDevs.add(handle, new AudioHwDevice(handle, name, dev, flags)); 169381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 169481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGI("loadHwModule() Loaded %s audio interface from %s (%s) handle %d", 169581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent name, dev->common.module->name, dev->common.module->id, handle); 169681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 169781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return handle; 169881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 169959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent} 170059255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 170181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 170281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 170381784c37c61b09289654b979567a42bf73cd2b12Eric Laurentuint32_t AudioFlinger::getPrimaryOutputSamplingRate() 170459255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent{ 170559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent Mutex::Autolock _l(mLock); 1706a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten PlaybackThread *thread = fastPlaybackThread_l(); 170781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread != NULL ? thread->sampleRate() : 0; 1708a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3Eric Laurent} 170959255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 171081784c37c61b09289654b979567a42bf73cd2b12Eric Laurentsize_t AudioFlinger::getPrimaryOutputFrameCount() 1711a85a74a8219c03f2b1d1ef98f3f02e55f89f89a3Eric Laurent{ 171281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 1713a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten PlaybackThread *thread = fastPlaybackThread_l(); 171481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread != NULL ? thread->frameCountHAL() : 0; 171559255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent} 171659255e4fc7d8ff52874b85b1988dc0785140cf81Eric Laurent 171765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 171865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 17194182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kastenstatus_t AudioFlinger::setLowRamDevice(bool isLowRamDevice) 17204182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten{ 17214182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten uid_t uid = IPCThreadState::self()->getCallingUid(); 17224182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten if (uid != AID_SYSTEM) { 17234182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten return PERMISSION_DENIED; 17244182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten } 17254182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten Mutex::Autolock _l(mLock); 17264182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten if (mIsDeviceTypeKnown) { 17274182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten return INVALID_OPERATION; 17284182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten } 17294182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten mIsLowRamDevice = isLowRamDevice; 17304182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten mIsDeviceTypeKnown = true; 17314182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten return NO_ERROR; 17324182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten} 17334182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten 173493c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurentaudio_hw_sync_t AudioFlinger::getAudioHwSyncForSession(audio_session_t sessionId) 173593c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurent{ 173693c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurent Mutex::Autolock _l(mLock); 1737fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent 1738fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent ssize_t index = mHwAvSyncIds.indexOfKey(sessionId); 1739fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent if (index >= 0) { 1740fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent ALOGV("getAudioHwSyncForSession found ID %d for session %d", 1741fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent mHwAvSyncIds.valueAt(index), sessionId); 1742fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent return mHwAvSyncIds.valueAt(index); 1743fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent } 1744fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent 1745fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent audio_hw_device_t *dev = mPrimaryHardwareDev->hwDevice(); 1746fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent if (dev == NULL) { 1747fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent return AUDIO_HW_SYNC_INVALID; 1748fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent } 1749fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent char *reply = dev->get_parameters(dev, AUDIO_PARAMETER_HW_AV_SYNC); 1750fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent AudioParameter param = AudioParameter(String8(reply)); 1751fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent free(reply); 1752fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent 1753fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent int value; 1754fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent if (param.getInt(String8(AUDIO_PARAMETER_HW_AV_SYNC), value) != NO_ERROR) { 1755fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent ALOGW("getAudioHwSyncForSession error getting sync for session %d", sessionId); 1756fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent return AUDIO_HW_SYNC_INVALID; 1757fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent } 1758fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent 1759fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent // allow only one session for a given HW A/V sync ID. 1760fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent for (size_t i = 0; i < mHwAvSyncIds.size(); i++) { 1761fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent if (mHwAvSyncIds.valueAt(i) == (audio_hw_sync_t)value) { 1762fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent ALOGV("getAudioHwSyncForSession removing ID %d for session %d", 1763fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent value, mHwAvSyncIds.keyAt(i)); 1764fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent mHwAvSyncIds.removeItemsAt(i); 1765fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent break; 1766fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent } 1767fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent } 1768fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent 1769fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent mHwAvSyncIds.add(sessionId, value); 1770fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent 177193c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 177293c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurent sp<PlaybackThread> thread = mPlaybackThreads.valueAt(i); 1773fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent uint32_t sessions = thread->hasAudioSession(sessionId); 17744c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent if (sessions & ThreadBase::TRACK_SESSION) { 1775fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent AudioParameter param = AudioParameter(); 1776fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent param.addInt(String8(AUDIO_PARAMETER_STREAM_HW_AV_SYNC), value); 1777fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent thread->setParameters(param.toString()); 177893c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurent break; 177993c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurent } 178093c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurent } 1781fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent 1782fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent ALOGV("getAudioHwSyncForSession adding ID %d for session %d", value, sessionId); 1783fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent return (audio_hw_sync_t)value; 1784fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent} 1785fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent 178672e3f39146fce4686bd96f11057c051bea376dfbEric Laurentstatus_t AudioFlinger::systemReady() 178772e3f39146fce4686bd96f11057c051bea376dfbEric Laurent{ 178872e3f39146fce4686bd96f11057c051bea376dfbEric Laurent Mutex::Autolock _l(mLock); 178972e3f39146fce4686bd96f11057c051bea376dfbEric Laurent ALOGI("%s", __FUNCTION__); 179072e3f39146fce4686bd96f11057c051bea376dfbEric Laurent if (mSystemReady) { 179172e3f39146fce4686bd96f11057c051bea376dfbEric Laurent ALOGW("%s called twice", __FUNCTION__); 179272e3f39146fce4686bd96f11057c051bea376dfbEric Laurent return NO_ERROR; 179372e3f39146fce4686bd96f11057c051bea376dfbEric Laurent } 179472e3f39146fce4686bd96f11057c051bea376dfbEric Laurent mSystemReady = true; 179572e3f39146fce4686bd96f11057c051bea376dfbEric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 179672e3f39146fce4686bd96f11057c051bea376dfbEric Laurent ThreadBase *thread = (ThreadBase *)mPlaybackThreads.valueAt(i).get(); 179772e3f39146fce4686bd96f11057c051bea376dfbEric Laurent thread->systemReady(); 179872e3f39146fce4686bd96f11057c051bea376dfbEric Laurent } 179972e3f39146fce4686bd96f11057c051bea376dfbEric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 180072e3f39146fce4686bd96f11057c051bea376dfbEric Laurent ThreadBase *thread = (ThreadBase *)mRecordThreads.valueAt(i).get(); 180172e3f39146fce4686bd96f11057c051bea376dfbEric Laurent thread->systemReady(); 180272e3f39146fce4686bd96f11057c051bea376dfbEric Laurent } 180372e3f39146fce4686bd96f11057c051bea376dfbEric Laurent return NO_ERROR; 180472e3f39146fce4686bd96f11057c051bea376dfbEric Laurent} 180572e3f39146fce4686bd96f11057c051bea376dfbEric Laurent 1806fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent// setAudioHwSyncForSession_l() must be called with AudioFlinger::mLock held 1807fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurentvoid AudioFlinger::setAudioHwSyncForSession_l(PlaybackThread *thread, audio_session_t sessionId) 1808fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent{ 1809fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent ssize_t index = mHwAvSyncIds.indexOfKey(sessionId); 1810fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent if (index >= 0) { 1811fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent audio_hw_sync_t syncId = mHwAvSyncIds.valueAt(index); 1812fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent ALOGV("setAudioHwSyncForSession_l found ID %d for session %d", syncId, sessionId); 1813fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent AudioParameter param = AudioParameter(); 1814fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent param.addInt(String8(AUDIO_PARAMETER_STREAM_HW_AV_SYNC), syncId); 1815fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent thread->setParameters(param.toString()); 1816fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent } 181793c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurent} 181893c3d41bdb15e39dac0faea9c5b60f1637cd477cEric Laurent 1819fa90e84ed0cb2abdc0e0873a06d10ccf2b3c34f6Eric Laurent 18204182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten// ---------------------------------------------------------------------------- 18214182c4e2a07e2441fcd5c22eaff0ddfe7f826f61Glenn Kasten 182265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 182383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurentsp<AudioFlinger::PlaybackThread> AudioFlinger::openOutput_l(audio_module_handle_t module, 1824cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_io_handle_t *output, 1825cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_config_t *config, 1826cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_devices_t devices, 1827cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent const String8& address, 182883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent audio_output_flags_t flags) 182983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent{ 1830cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent AudioHwDevice *outHwDev = findSuitableHwDev_l(module, devices); 18316e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten if (outHwDev == NULL) { 1832cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent return 0; 18336e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten } 183465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1835cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent if (*output == AUDIO_IO_HANDLE_NONE) { 1836eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten *output = nextUniqueId(AUDIO_UNIQUE_ID_USE_OUTPUT); 1837eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten } else { 1838eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten // Audio Policy does not currently request a specific output handle. 1839eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten // If this is ever needed, see openInput_l() for example code. 1840eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten ALOGE("openOutput_l requested output handle %d is not AUDIO_IO_HANDLE_NONE", *output); 1841eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten return 0; 1842cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent } 184365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 184481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_OUTPUT_OPEN; 184565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 18466146c08f0c3dd8b9e5788063aa433f304a810602Andy Hung // FOR TESTING ONLY: 18479a59276fb465e492138e0576523b54079671e8f4Andy Hung // This if statement allows overriding the audio policy settings 18489a59276fb465e492138e0576523b54079671e8f4Andy Hung // and forcing a specific format or channel mask to the HAL/Sink device for testing. 18499a59276fb465e492138e0576523b54079671e8f4Andy Hung if (!(flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT))) { 18509a59276fb465e492138e0576523b54079671e8f4Andy Hung // Check only for Normal Mixing mode 18519a59276fb465e492138e0576523b54079671e8f4Andy Hung if (kEnableExtendedPrecision) { 18529a59276fb465e492138e0576523b54079671e8f4Andy Hung // Specify format (uncomment one below to choose) 18539a59276fb465e492138e0576523b54079671e8f4Andy Hung //config->format = AUDIO_FORMAT_PCM_FLOAT; 18549a59276fb465e492138e0576523b54079671e8f4Andy Hung //config->format = AUDIO_FORMAT_PCM_24_BIT_PACKED; 18559a59276fb465e492138e0576523b54079671e8f4Andy Hung //config->format = AUDIO_FORMAT_PCM_32_BIT; 18569a59276fb465e492138e0576523b54079671e8f4Andy Hung //config->format = AUDIO_FORMAT_PCM_8_24_BIT; 1857cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent // ALOGV("openOutput_l() upgrading format to %#08x", config->format); 18589a59276fb465e492138e0576523b54079671e8f4Andy Hung } 18599a59276fb465e492138e0576523b54079671e8f4Andy Hung if (kEnableExtendedChannels) { 18609a59276fb465e492138e0576523b54079671e8f4Andy Hung // Specify channel mask (uncomment one below to choose) 18619a59276fb465e492138e0576523b54079671e8f4Andy Hung //config->channel_mask = audio_channel_out_mask_from_count(4); // for USB 4ch 18629a59276fb465e492138e0576523b54079671e8f4Andy Hung //config->channel_mask = audio_channel_mask_from_representation_and_bits( 18639a59276fb465e492138e0576523b54079671e8f4Andy Hung // AUDIO_CHANNEL_REPRESENTATION_INDEX, (1 << 4) - 1); // another 4ch example 18649a59276fb465e492138e0576523b54079671e8f4Andy Hung } 18656146c08f0c3dd8b9e5788063aa433f304a810602Andy Hung } 18666146c08f0c3dd8b9e5788063aa433f304a810602Andy Hung 1867062e67a26e0553dd142be622821f493df541f0c6Phil Burk AudioStreamOut *outputStream = NULL; 1868062e67a26e0553dd142be622821f493df541f0c6Phil Burk status_t status = outHwDev->openOutputStream( 1869062e67a26e0553dd142be622821f493df541f0c6Phil Burk &outputStream, 1870062e67a26e0553dd142be622821f493df541f0c6Phil Burk *output, 1871062e67a26e0553dd142be622821f493df541f0c6Phil Burk devices, 1872062e67a26e0553dd142be622821f493df541f0c6Phil Burk flags, 1873062e67a26e0553dd142be622821f493df541f0c6Phil Burk config, 1874062e67a26e0553dd142be622821f493df541f0c6Phil Burk address.string()); 187565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 187681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 187758912562617941964939a4182cda71eaeb153d4bGlenn Kasten 1878062e67a26e0553dd142be622821f493df541f0c6Phil Burk if (status == NO_ERROR) { 187965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 18803255095af6677caeeebf81c8891ce8db745617ffGlenn Kasten PlaybackThread *thread; 1881bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent if (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { 1882e93cc03da360a1a0d2ad937c745ce8c8e8be81c2Eric Laurent thread = new OffloadThread(this, outputStream, *output, devices, mSystemReady); 1883cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent ALOGV("openOutput_l() created offload output: ID %d thread %p", *output, thread); 18846146c08f0c3dd8b9e5788063aa433f304a810602Andy Hung } else if ((flags & AUDIO_OUTPUT_FLAG_DIRECT) 188583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent || !isValidPcmSinkFormat(config->format) 18869a59276fb465e492138e0576523b54079671e8f4Andy Hung || !isValidPcmSinkChannelMask(config->channel_mask)) { 188772e3f39146fce4686bd96f11057c051bea376dfbEric Laurent thread = new DirectOutputThread(this, outputStream, *output, devices, mSystemReady); 1888cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent ALOGV("openOutput_l() created direct output: ID %d thread %p", *output, thread); 188981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else { 189072e3f39146fce4686bd96f11057c051bea376dfbEric Laurent thread = new MixerThread(this, outputStream, *output, devices, mSystemReady); 1891cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent ALOGV("openOutput_l() created mixer output: ID %d thread %p", *output, thread); 189265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 1893cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent mPlaybackThreads.add(*output, thread); 189483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent return thread; 189583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent } 189683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 189783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent return 0; 189883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent} 189983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 1900cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurentstatus_t AudioFlinger::openOutput(audio_module_handle_t module, 1901cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_io_handle_t *output, 1902cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_config_t *config, 1903cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_devices_t *devices, 1904cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent const String8& address, 1905cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent uint32_t *latencyMs, 1906cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_output_flags_t flags) 190783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent{ 1908062e67a26e0553dd142be622821f493df541f0c6Phil Burk ALOGI("openOutput(), module %d Device %x, SamplingRate %d, Format %#08x, Channels %x, flags %x", 190983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent module, 1910cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent (devices != NULL) ? *devices : 0, 1911cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent config->sample_rate, 1912cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent config->format, 1913cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent config->channel_mask, 191483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent flags); 191583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 1916cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent if (*devices == AUDIO_DEVICE_NONE) { 1917cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent return BAD_VALUE; 191883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent } 191983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 192083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent Mutex::Autolock _l(mLock); 192183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 1922cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent sp<PlaybackThread> thread = openOutput_l(module, output, config, *devices, address, flags); 192383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent if (thread != 0) { 1924cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent *latencyMs = thread->latency(); 192565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 192681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // notify client processes of the new output creation 192773e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent thread->ioConfigChanged(AUDIO_OUTPUT_OPENED); 192865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 192981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // the first primary output opened designates the primary hw device 193081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if ((mPrimaryHardwareDev == NULL) && (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) { 193181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGI("Using module %d has the primary audio interface", module); 193283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent mPrimaryHardwareDev = thread->getOutput()->audioHwDev; 193381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 193481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AutoMutex lock(mHardwareLock); 193581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_SET_MODE; 193683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent mPrimaryHardwareDev->hwDevice()->set_mode(mPrimaryHardwareDev->hwDevice(), mMode); 193781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mHardwareStatus = AUDIO_HW_IDLE; 193881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 1939cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent return NO_ERROR; 194081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 194165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1942cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent return NO_INIT; 194365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 194465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 194581784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_io_handle_t AudioFlinger::openDuplicateOutput(audio_io_handle_t output1, 194681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t output2) 194765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 194881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 194981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent MixerThread *thread1 = checkMixerThread_l(output1); 195081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent MixerThread *thread2 = checkMixerThread_l(output2); 195181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 195281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread1 == NULL || thread2 == NULL) { 195381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("openDuplicateOutput() wrong output mixer type for output %d or %d", output1, 195481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent output2); 1955142f519aa1acd5804d111e60d100f170fed28405Glenn Kasten return AUDIO_IO_HANDLE_NONE; 195665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 195765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 1958eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten audio_io_handle_t id = nextUniqueId(AUDIO_UNIQUE_ID_USE_OUTPUT); 195972e3f39146fce4686bd96f11057c051bea376dfbEric Laurent DuplicatingThread *thread = new DuplicatingThread(this, thread1, id, mSystemReady); 196081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->addOutputTrack(thread2); 196181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPlaybackThreads.add(id, thread); 196281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // notify client processes of the new output creation 196373e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent thread->ioConfigChanged(AUDIO_OUTPUT_OPENED); 196481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return id; 196565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 196665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 196781784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::closeOutput(audio_io_handle_t output) 19682bfc6b42b3733c12485dd51ed95191956abc3e4eJean-Michel Trivi{ 196981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return closeOutput_nonvirtual(output); 19702bfc6b42b3733c12485dd51ed95191956abc3e4eJean-Michel Trivi} 19712bfc6b42b3733c12485dd51ed95191956abc3e4eJean-Michel Trivi 197281784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output) 197365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 197481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // keep strong reference on the playback thread so that 197581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // it is not destroyed while exit() is executed 197681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<PlaybackThread> thread; 197781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent { 197881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 197981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = checkPlaybackThread_l(output); 198081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 198181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 198265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 198365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 198481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("closeOutput() %d", output); 1985de070137f11d346fba77605bd76a44c040a618fcEric Laurent 198681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread->type() == ThreadBase::MIXER) { 198781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 1988f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent if (mPlaybackThreads.valueAt(i)->isDuplicating()) { 198981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent DuplicatingThread *dupThread = 199081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (DuplicatingThread *)mPlaybackThreads.valueAt(i).get(); 199181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent dupThread->removeOutputTrack((MixerThread *)thread.get()); 1992de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 1993de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 1994de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 1995bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent 1996bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent 199781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPlaybackThreads.removeItem(output); 1998bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent // save all effects to the default thread 1999bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent if (mPlaybackThreads.size()) { 2000bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent PlaybackThread *dstThread = checkPlaybackThread_l(mPlaybackThreads.keyAt(0)); 2001bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent if (dstThread != NULL) { 2002bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent // audioflinger lock is held here so the acquisition order of thread locks does not 2003bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent // matter 2004bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent Mutex::Autolock _dl(dstThread->mLock); 2005bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent Mutex::Autolock _sl(thread->mLock); 2006bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent Vector< sp<EffectChain> > effectChains = thread->getEffectChains_l(); 2007bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent for (size_t i = 0; i < effectChains.size(); i ++) { 2008bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent moveEffectChain_l(effectChains[i]->sessionId(), thread.get(), dstThread, true); 2009bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent } 2010bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent } 2011bfb1b832079bbb9426f72f3863199a54aefd02daEric Laurent } 201273e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor(); 201373e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent ioDesc->mIoHandle = output; 201473e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent ioConfigChanged(AUDIO_OUTPUT_CLOSED, ioDesc); 20153acbd053c842e76e1a40fc8a0bf62de87eebf00fGlenn Kasten } 201681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->exit(); 201781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // The thread entity (active unit of execution) is no longer running here, 201881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // but the ThreadBase container still exists. 20193acbd053c842e76e1a40fc8a0bf62de87eebf00fGlenn Kasten 2020f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent if (!thread->isDuplicating()) { 202183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent closeOutputFinish(thread); 202265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 202383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 202481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 202565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 202665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 202783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurentvoid AudioFlinger::closeOutputFinish(sp<PlaybackThread> thread) 202883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent{ 202983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent AudioStreamOut *out = thread->clearOutput(); 203083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent ALOG_ASSERT(out != NULL, "out shouldn't be NULL"); 203183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent // from now on thread->mOutput is NULL 203283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent out->hwDev()->close_output_stream(out->hwDev(), out->stream); 203383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent delete out; 203483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent} 203583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 203683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurentvoid AudioFlinger::closeOutputInternal_l(sp<PlaybackThread> thread) 203783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent{ 203883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent mPlaybackThreads.removeItem(thread->mId); 203983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent thread->exit(); 204083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent closeOutputFinish(thread); 204183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent} 204283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 204381784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::suspendOutput(audio_io_handle_t output) 2044e737cda649acbfa43fc1b74612a83f2fac9aa449Eric Laurent{ 204581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 204681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = checkPlaybackThread_l(output); 204781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 204881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 204981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 2050e737cda649acbfa43fc1b74612a83f2fac9aa449Eric Laurent } 2051e737cda649acbfa43fc1b74612a83f2fac9aa449Eric Laurent 205281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("suspendOutput() %d", output); 205381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->suspend(); 2054e737cda649acbfa43fc1b74612a83f2fac9aa449Eric Laurent 205581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 205665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 205765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 205881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::restoreOutput(audio_io_handle_t output) 205965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 20606637baae4244aec731c4014da72418d330636ae1Glenn Kasten Mutex::Autolock _l(mLock); 206181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = checkPlaybackThread_l(output); 206265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 206381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 206481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 2065ee578c0330319f04a48bccbdb26b53fea0388d04John Grossman } 206665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 206781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("restoreOutput() %d", output); 206865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 206981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->restore(); 207065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 207181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 207265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 207365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2074cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurentstatus_t AudioFlinger::openInput(audio_module_handle_t module, 2075cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_io_handle_t *input, 2076cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_config_t *config, 2077e7d6671c1ab1fea7ab1c4a9ebd1cd8f899c87628Glenn Kasten audio_devices_t *devices, 2078cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent const String8& address, 2079cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_source_t source, 2080ec40d284218466d8f0e832e7eb88e6ea6c479c88Glenn Kasten audio_input_flags_t flags) 208165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 208283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent Mutex::Autolock _l(mLock); 208383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 2084e7d6671c1ab1fea7ab1c4a9ebd1cd8f899c87628Glenn Kasten if (*devices == AUDIO_DEVICE_NONE) { 2085cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent return BAD_VALUE; 208683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent } 208783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 2088e7d6671c1ab1fea7ab1c4a9ebd1cd8f899c87628Glenn Kasten sp<RecordThread> thread = openInput_l(module, input, config, *devices, address, source, flags); 208983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 209083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent if (thread != 0) { 209183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent // notify client processes of the new input creation 209273e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent thread->ioConfigChanged(AUDIO_INPUT_OPENED); 2093cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent return NO_ERROR; 2094b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent } 2095cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent return NO_INIT; 209683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent} 2097b469b9490b3cd9e0f0466d9b9ab228f6c793b82eEric Laurent 209883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurentsp<AudioFlinger::RecordThread> AudioFlinger::openInput_l(audio_module_handle_t module, 2099cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_io_handle_t *input, 2100cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_config_t *config, 2101e7d6671c1ab1fea7ab1c4a9ebd1cd8f899c87628Glenn Kasten audio_devices_t devices, 2102cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent const String8& address, 2103cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_source_t source, 210483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent audio_input_flags_t flags) 210583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent{ 2106e7d6671c1ab1fea7ab1c4a9ebd1cd8f899c87628Glenn Kasten AudioHwDevice *inHwDev = findSuitableHwDev_l(module, devices); 21076e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten if (inHwDev == NULL) { 2108cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent *input = AUDIO_IO_HANDLE_NONE; 210981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 21106e2ebe97f2ad0a21907f20f9ee644c4eacbb7a40Glenn Kasten } 2111fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 2112eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten // Audio Policy can request a specific handle for hardware hotword. 2113eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten // The goal here is not to re-open an already opened input. 2114eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten // It is to use a pre-assigned I/O handle. 2115cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent if (*input == AUDIO_IO_HANDLE_NONE) { 2116eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten *input = nextUniqueId(AUDIO_UNIQUE_ID_USE_INPUT); 2117eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten } else if (audio_unique_id_get_use(*input) != AUDIO_UNIQUE_ID_USE_INPUT) { 2118eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten ALOGE("openInput_l() requested input handle %d is invalid", *input); 2119eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten return 0; 2120eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten } else if (mRecordThreads.indexOfKey(*input) >= 0) { 2121eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten // This should not happen in a transient state with current design. 2122eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten ALOGE("openInput_l() requested input handle %d is already assigned", *input); 2123eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten return 0; 2124cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent } 2125b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent 2126cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_config_t halconfig = *config; 2127cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent audio_hw_device_t *inHwHal = inHwDev->hwDevice(); 21283255095af6677caeeebf81c8891ce8db745617ffGlenn Kasten audio_stream_in_t *inStream = NULL; 2129e7d6671c1ab1fea7ab1c4a9ebd1cd8f899c87628Glenn Kasten status_t status = inHwHal->open_input_stream(inHwHal, *input, devices, &halconfig, 2130cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent &inStream, flags, address.string(), source); 2131cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent ALOGV("openInput_l() openInputStream returned input %p, SamplingRate %d" 2132fd4c14883b268a0bc5514da135fe6b7d1ce2071bJean-Michel Trivi ", Format %#x, Channels %x, flags %#x, status %d addr %s", 213381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent inStream, 2134cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent halconfig.sample_rate, 2135cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent halconfig.format, 2136cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent halconfig.channel_mask, 2137ec40d284218466d8f0e832e7eb88e6ea6c479c88Glenn Kasten flags, 2138fd4c14883b268a0bc5514da135fe6b7d1ce2071bJean-Michel Trivi status, address.string()); 213965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 214081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If the input could not be opened with the requested parameters and we can handle the 21416770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung // conversion internally, try to open again with the proposed parameters. 214281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (status == BAD_VALUE && 21436770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung audio_is_linear_pcm(config->format) && 21446770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung audio_is_linear_pcm(halconfig.format) && 21456770c6faa3467c92eabc5ec9b23d60eb556a0d03Andy Hung (halconfig.sample_rate <= AUDIO_RESAMPLER_DOWN_RATIO_MAX * config->sample_rate) && 2146753466603a88f1ea3d966d17ab79256519553759vivek mehta (audio_channel_count_from_in_mask(halconfig.channel_mask) <= FCC_8) && 2147753466603a88f1ea3d966d17ab79256519553759vivek mehta (audio_channel_count_from_in_mask(config->channel_mask) <= FCC_8)) { 21488594843c15b4722ced39436fe9e64f3e57e7ace4Glenn Kasten // FIXME describe the change proposed by HAL (save old values so we can log them here) 2149cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent ALOGV("openInput_l() reopening with proposed sampling rate and channel mask"); 215081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent inStream = NULL; 2151e7d6671c1ab1fea7ab1c4a9ebd1cd8f899c87628Glenn Kasten status = inHwHal->open_input_stream(inHwHal, *input, devices, &halconfig, 2152cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent &inStream, flags, address.string(), source); 21538594843c15b4722ced39436fe9e64f3e57e7ace4Glenn Kasten // FIXME log this new status; HAL should not propose any further changes 215465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 215565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 215681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (status == NO_ERROR && inStream != NULL) { 215758912562617941964939a4182cda71eaeb153d4bGlenn Kasten 215846909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 215981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Try to re-use most recently used Pipe to archive a copy of input for dumpsys, 216081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // or (re-)create if current Pipe is idle and does not match the new format 216181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<NBAIO_Sink> teeSink; 216281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent enum { 216381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent TEE_SINK_NO, // don't copy input 216481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent TEE_SINK_NEW, // copy input using a new pipe 216581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent TEE_SINK_OLD, // copy input using an existing pipe 216681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } kind; 2167329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten NBAIO_Format format = Format_from_SR_C(halconfig.sample_rate, 2168329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten audio_channel_count_from_in_mask(halconfig.channel_mask), halconfig.format); 2169da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (!mTeeSinkInputEnabled) { 2170da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten kind = TEE_SINK_NO; 21716e0d67d7b496ce17c0970a4ffd3a6f808860949cGlenn Kasten } else if (!Format_isValid(format)) { 217281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_NO; 217381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else if (mRecordTeeSink == 0) { 217481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_NEW; 217581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else if (mRecordTeeSink->getStrongCount() != 1) { 217681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_NO; 2177f66b42242342017c26eb97de544dae31dd2537caGlenn Kasten } else if (Format_isEqual(format, mRecordTeeSink->format())) { 217881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_OLD; 21794adcede0dc54a85c31abaf139921aebd7a072d8eGlenn Kasten } else { 218081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent kind = TEE_SINK_NEW; 218181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 218281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent switch (kind) { 218381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent case TEE_SINK_NEW: { 2184da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten Pipe *pipe = new Pipe(mTeeSinkInputFrames, format); 218581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t numCounterOffers = 0; 218681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent const NBAIO_Format offers[1] = {format}; 218781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ssize_t index = pipe->negotiate(offers, 1, NULL, numCounterOffers); 218881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOG_ASSERT(index == 0); 218981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PipeReader *pipeReader = new PipeReader(*pipe); 219081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent numCounterOffers = 0; 219181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent index = pipeReader->negotiate(offers, 1, NULL, numCounterOffers); 219281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOG_ASSERT(index == 0); 219381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mRecordTeeSink = pipe; 219481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mRecordTeeSource = pipeReader; 219581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent teeSink = pipe; 21964adcede0dc54a85c31abaf139921aebd7a072d8eGlenn Kasten } 219781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 219881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent case TEE_SINK_OLD: 219981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent teeSink = mRecordTeeSink; 220081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 220181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent case TEE_SINK_NO: 220281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent default: 220381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 220458912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 220546909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 2206da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 2207050677873c10d4da308ac222f8533c96cca3207eEric Laurent AudioStreamIn *inputStream = new AudioStreamIn(inHwDev, inStream, flags); 220865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 220981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Start record thread 221034af02647b387a252fb02bab8e2cb9f7bd9c8abbGlenn Kasten // RecordThread requires both input and output device indication to forward to audio 221181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // pre processing modules 221283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent sp<RecordThread> thread = new RecordThread(this, 2213cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent inputStream, 2214cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent *input, 2215d3922f72601d82c6fc067a98916fda0bd1291c5fEric Laurent primaryOutputDevice_l(), 221672e3f39146fce4686bd96f11057c051bea376dfbEric Laurent devices, 221772e3f39146fce4686bd96f11057c051bea376dfbEric Laurent mSystemReady 221846909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 221946909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten , teeSink 222046909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 222146909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten ); 2222cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent mRecordThreads.add(*input, thread); 2223cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent ALOGV("openInput_l() created record thread: ID %d thread %p", *input, thread.get()); 222483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent return thread; 22251afc26db11b71c43f63a0f72a45a803f1a7910ddEric Laurent } 222681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 2227cf2c0210c8afbe7d0661ccbbae3835b5ce73c0bfEric Laurent *input = AUDIO_IO_HANDLE_NONE; 222881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 222965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 223065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 223181784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::closeInput(audio_io_handle_t input) 223265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 223381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return closeInput_nonvirtual(input); 223465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 223565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 223681784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::closeInput_nonvirtual(audio_io_handle_t input) 2237de070137f11d346fba77605bd76a44c040a618fcEric Laurent{ 223881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // keep strong reference on the record thread so that 223981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // it is not destroyed while exit() is executed 224081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<RecordThread> thread; 224181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent { 224281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 224381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = checkRecordThread_l(input); 224481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == 0) { 224581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 2246de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 224781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 224881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("closeInput() %d", input); 22491b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent 22501b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // If we still have effect chains, it means that a client still holds a handle 22511b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // on at least one effect. We must either move the chain to an existing thread with the 22521b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // same session ID or put it aside in case a new record thread is opened for a 22531b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // new capture on the same session 22541b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent sp<EffectChain> chain; 2255aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent { 2256aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent Mutex::Autolock _sl(thread->mLock); 2257aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent Vector< sp<EffectChain> > effectChains = thread->getEffectChains_l(); 22581b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // Note: maximum one chain per record thread 22591b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent if (effectChains.size() != 0) { 22601b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent chain = effectChains[0]; 22611b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent } 22621b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent } 22631b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent if (chain != 0) { 22641b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // first check if a record thread is already opened with a client on the same session. 22651b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // This should only happen in case of overlap between one thread tear down and the 22661b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // creation of its replacement 22671b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent size_t i; 22681b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent for (i = 0; i < mRecordThreads.size(); i++) { 22691b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent sp<RecordThread> t = mRecordThreads.valueAt(i); 22701b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent if (t == thread) { 22711b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent continue; 22721b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent } 22731b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent if (t->hasAudioSession(chain->sessionId()) != 0) { 22741b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent Mutex::Autolock _l(t->mLock); 22751b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent ALOGV("closeInput() found thread %d for effect session %d", 22761b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent t->id(), chain->sessionId()); 22771b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent t->addEffectChain_l(chain); 22781b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent break; 22791b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent } 22801b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent } 22811b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent // put the chain aside if we could not find a record thread with the same session id. 22821b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent if (i == mRecordThreads.size()) { 22831b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent putOrphanEffectChain_l(chain); 2284aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } 2285aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } 228673e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor(); 228773e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent ioDesc->mIoHandle = input; 228873e26b661af50be2c0a4ff6c9ac85f7347a8b235Eric Laurent ioConfigChanged(AUDIO_INPUT_CLOSED, ioDesc); 228981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mRecordThreads.removeItem(input); 2290de070137f11d346fba77605bd76a44c040a618fcEric Laurent } 229183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent // FIXME: calling thread->exit() without mLock held should not be needed anymore now that 229283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent // we have a different lock for notification client 229383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent closeInputFinish(thread); 229483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent return NO_ERROR; 229583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent} 2296de070137f11d346fba77605bd76a44c040a618fcEric Laurent 229783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurentvoid AudioFlinger::closeInputFinish(sp<RecordThread> thread) 229883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent{ 229983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent thread->exit(); 230081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioStreamIn *in = thread->clearInput(); 230181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOG_ASSERT(in != NULL, "in shouldn't be NULL"); 230281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // from now on thread->mInput is NULL 230381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent in->hwDev()->close_input_stream(in->hwDev(), in->stream); 230481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent delete in; 230583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent} 230665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 230783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurentvoid AudioFlinger::closeInputInternal_l(sp<RecordThread> thread) 230883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent{ 230983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent mRecordThreads.removeItem(thread->mId); 231083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent closeInputFinish(thread); 2311b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent} 2312b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent 2313d2304db2fcb5112292105a0949a55986a4c9875fGlenn Kastenstatus_t AudioFlinger::invalidateStream(audio_stream_type_t stream) 2314b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent{ 2315b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent Mutex::Autolock _l(mLock); 2316d2304db2fcb5112292105a0949a55986a4c9875fGlenn Kasten ALOGV("invalidateStream() stream %d", stream); 2317b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent 231881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 231981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = mPlaybackThreads.valueAt(i).get(); 232081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread->invalidateTracks(stream); 2321b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent } 232281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 232381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 2324b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent} 2325b8ba0a979067a4efb0b3819bf17770793e41c15eEric Laurent 232681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 2327eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kastenaudio_unique_id_t AudioFlinger::newAudioUniqueId(audio_unique_id_use_t use) 2328162b40bbaf3c3a24f61a6636bef6f80a9c0a31ddEric Laurent{ 23299d003131329450081c8129b3fddd85cf20d2d9d9Glenn Kasten // This is a binder API, so a malicious client could pass in a bad parameter. 23309d003131329450081c8129b3fddd85cf20d2d9d9Glenn Kasten // Check for that before calling the internal API nextUniqueId(). 23319d003131329450081c8129b3fddd85cf20d2d9d9Glenn Kasten if ((unsigned) use >= (unsigned) AUDIO_UNIQUE_ID_USE_MAX) { 23329d003131329450081c8129b3fddd85cf20d2d9d9Glenn Kasten ALOGE("newAudioUniqueId invalid use %d", use); 23339d003131329450081c8129b3fddd85cf20d2d9d9Glenn Kasten return AUDIO_UNIQUE_ID_ALLOCATE; 23349d003131329450081c8129b3fddd85cf20d2d9d9Glenn Kasten } 2335eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten return nextUniqueId(use); 2336162b40bbaf3c3a24f61a6636bef6f80a9c0a31ddEric Laurent} 2337162b40bbaf3c3a24f61a6636bef6f80a9c0a31ddEric Laurent 2338d848eb48c121c119e8ba7583efc75415fe102570Glenn Kastenvoid AudioFlinger::acquireAudioSessionId(audio_session_t audioSession, pid_t pid) 2339a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent{ 2340a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent Mutex::Autolock _l(mLock); 234181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid_t caller = IPCThreadState::self()->getCallingPid(); 2342d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen ALOGV("acquiring %d from %d, for %d", audioSession, caller, pid); 2343d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen if (pid != -1 && (caller == getpid_cached)) { 2344d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen caller = pid; 2345d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen } 2346d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent 2347021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent { 2348021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent Mutex::Autolock _cl(mClientLock); 2349021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent // Ignore requests received from processes not known as notification client. The request 2350021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent // is likely proxied by mediaserver (e.g CameraService) and releaseAudioSessionId() can be 2351021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent // called from a different pid leaving a stale session reference. Also we don't know how 2352021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent // to clear this reference if the client process dies. 2353021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent if (mNotificationClients.indexOfKey(caller) < 0) { 2354021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent ALOGW("acquireAudioSessionId() unknown client %d for session %d", caller, audioSession); 2355021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent return; 2356021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent } 2357d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent } 2358d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent 235981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t num = mAudioSessionRefs.size(); 236081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i< num; i++) { 236181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSessionRef *ref = mAudioSessionRefs.editItemAt(i); 236281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ref->mSessionid == audioSession && ref->mPid == caller) { 236381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ref->mCnt++; 236481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV(" incremented refcount to %d", ref->mCnt); 236581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return; 2366a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 2367a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent } 236881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioSessionRefs.push(new AudioSessionRef(audioSession, caller)); 236981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV(" added new entry for %d", audioSession); 2370a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent} 2371a011e35b22f95f558d81dc9c94b68b1465c4661dEric Laurent 2372d848eb48c121c119e8ba7583efc75415fe102570Glenn Kastenvoid AudioFlinger::releaseAudioSessionId(audio_session_t audioSession, pid_t pid) 237344a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent{ 237481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 237581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid_t caller = IPCThreadState::self()->getCallingPid(); 2376d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen ALOGV("releasing %d from %d for %d", audioSession, caller, pid); 2377d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen if (pid != -1 && (caller == getpid_cached)) { 2378d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen caller = pid; 2379d457c970c8d08519cd77280a90b61ae1e342cfe3Marco Nelissen } 238081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t num = mAudioSessionRefs.size(); 238181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i< num; i++) { 238281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSessionRef *ref = mAudioSessionRefs.itemAt(i); 238381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ref->mSessionid == audioSession && ref->mPid == caller) { 238481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ref->mCnt--; 238581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV(" decremented refcount to %d", ref->mCnt); 238681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ref->mCnt == 0) { 238781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mAudioSessionRefs.removeAt(i); 238881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent delete ref; 238981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent purgeStaleEffects_l(); 239044a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent } 239181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return; 239244a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent } 239344a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent } 2394d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent // If the caller is mediaserver it is likely that the session being released was acquired 2395d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent // on behalf of a process not in notification clients and we ignore the warning. 2396d1b28d41dbda203ffb420ba2e36cbe736b163ff8Eric Laurent ALOGW_IF(caller != getpid_cached, "session id %d not found for pid %d", audioSession, caller); 239744a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent} 239844a957f06400a338e7af20b3d16c4c4ae22a673cEric Laurent 239981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentvoid AudioFlinger::purgeStaleEffects_l() { 240065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 240181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("purging stale effects"); 2402fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten 240381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Vector< sp<EffectChain> > chains; 240458912562617941964939a4182cda71eaeb153d4bGlenn Kasten 240581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 240681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<PlaybackThread> t = mPlaybackThreads.valueAt(i); 240781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t j = 0; j < t->mEffectChains.size(); j++) { 240881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> ec = t->mEffectChains[j]; 240981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ec->sessionId() > AUDIO_SESSION_OUTPUT_MIX) { 241081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent chains.push(ec); 241181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 2412c15d6657a17d7cef91f800f40d11760e2e7340afGlenn Kasten } 241358912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 241481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 241581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<RecordThread> t = mRecordThreads.valueAt(i); 241681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t j = 0; j < t->mEffectChains.size(); j++) { 241781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> ec = t->mEffectChains[j]; 241881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent chains.push(ec); 241981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 2420300a2ee9327c05fbf9d3a5fd595b558097c7c5e8Glenn Kasten } 242165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 242281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < chains.size(); i++) { 242381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> ec = chains[i]; 242481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int sessionid = ec->sessionId(); 242581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<ThreadBase> t = ec->mThread.promote(); 242681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (t == 0) { 242781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent continue; 242881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 242981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent size_t numsessionrefs = mAudioSessionRefs.size(); 243081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool found = false; 243181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t k = 0; k < numsessionrefs; k++) { 243281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSessionRef *ref = mAudioSessionRefs.itemAt(k); 243381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (ref->mSessionid == sessionid) { 243481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV(" session %d still exists for %d with %d refs", 243581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionid, ref->mPid, ref->mCnt); 243681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent found = true; 243781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 243858912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 243958912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 244081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (!found) { 2441e198c360d5e75a9b2097844c495c10902e7e8500Glenn Kasten Mutex::Autolock _l(t->mLock); 244281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // remove all effects from the chain 244381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent while (ec->mEffects.size()) { 244481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectModule> effect = ec->mEffects[0]; 244581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect->unPin(); 244681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent t->removeEffect_l(effect); 244781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (effect->purgeHandles()) { 244881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent t->checkSuspendOnEffectEnabled_l(effect, false, effect->sessionId()); 244981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 245081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSystem::unregisterEffect(effect->id()); 245181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 2452c15d6657a17d7cef91f800f40d11760e2e7340afGlenn Kasten } 245358912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 245481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return; 245565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 245665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 2457eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten// checkThread_l() must be called with AudioFlinger::mLock held 2458eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn KastenAudioFlinger::ThreadBase *AudioFlinger::checkThread_l(audio_io_handle_t ioHandle) const 2459eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten{ 2460eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten ThreadBase *thread = NULL; 2461eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten switch (audio_unique_id_get_use(ioHandle)) { 2462eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten case AUDIO_UNIQUE_ID_USE_OUTPUT: 2463eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten thread = checkPlaybackThread_l(ioHandle); 2464eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten break; 2465eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten case AUDIO_UNIQUE_ID_USE_INPUT: 2466eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten thread = checkRecordThread_l(ioHandle); 2467eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten break; 2468eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten default: 2469eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten break; 2470eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten } 2471eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten return thread; 2472eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten} 2473eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten 247481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// checkPlaybackThread_l() must be called with AudioFlinger::mLock held 247581784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::PlaybackThread *AudioFlinger::checkPlaybackThread_l(audio_io_handle_t output) const 2476190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten{ 247781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return mPlaybackThreads.valueFor(output).get(); 2478190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten} 2479190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten 248081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// checkMixerThread_l() must be called with AudioFlinger::mLock held 248181784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::MixerThread *AudioFlinger::checkMixerThread_l(audio_io_handle_t output) const 248281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent{ 248381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = checkPlaybackThread_l(output); 248481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread != NULL && thread->type() != ThreadBase::DIRECT ? (MixerThread *) thread : NULL; 248581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent} 2486190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten 248781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// checkRecordThread_l() must be called with AudioFlinger::mLock held 248881784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::RecordThread *AudioFlinger::checkRecordThread_l(audio_io_handle_t input) const 248981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent{ 249081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return mRecordThreads.valueFor(input).get(); 249181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent} 2492190a46f7c84e160386610c0c4cecb9767fb5503bGlenn Kasten 2493eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kastenaudio_unique_id_t AudioFlinger::nextUniqueId(audio_unique_id_use_t use) 249481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent{ 24959d003131329450081c8129b3fddd85cf20d2d9d9Glenn Kasten // This is the internal API, so it is OK to assert on bad parameter. 2496eeecb980ff4c202d0a3c4b0bfe040dce2f73336dGlenn Kasten LOG_ALWAYS_FATAL_IF((unsigned) use >= (unsigned) AUDIO_UNIQUE_ID_USE_MAX); 2497d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten const int maxRetries = use == AUDIO_UNIQUE_ID_USE_SESSION ? 3 : 1; 2498d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten for (int retry = 0; retry < maxRetries; retry++) { 2499d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten // The cast allows wraparound from max positive to min negative instead of abort 2500d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten uint32_t base = (uint32_t) atomic_fetch_add_explicit(&mNextUniqueIds[use], 2501d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten (uint_fast32_t) AUDIO_UNIQUE_ID_USE_MAX, memory_order_acq_rel); 2502d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten ALOG_ASSERT(audio_unique_id_get_use(base) == AUDIO_UNIQUE_ID_USE_UNSPECIFIED); 2503d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten // allow wrap by skipping 0 and -1 for session ids 2504d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten if (!(base == 0 || base == (~0u & ~AUDIO_UNIQUE_ID_USE_MASK))) { 2505d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten ALOGW_IF(retry != 0, "unique ID overflow for use %d", use); 2506d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten return (audio_unique_id_t) (base | use); 2507d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten } 2508d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten } 2509d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten // We have no way of recovering from wraparound 2510d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten LOG_ALWAYS_FATAL("unique ID overflow for use %d", use); 2511d2e67e1ef59921101fd7b047e2acf84e5d16d66eGlenn Kasten // TODO Use a floor after wraparound. This may need a mutex. 251281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent} 251383efdd0fc08cd5aedf50b45741a8a87be8dc4b41Glenn Kasten 251481784c37c61b09289654b979567a42bf73cd2b12Eric LaurentAudioFlinger::PlaybackThread *AudioFlinger::primaryPlaybackThread_l() const 251537d825e72a6c606553a745da1212590a425996d3Glenn Kasten{ 251681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 251781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = mPlaybackThreads.valueAt(i).get(); 2518f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent if(thread->isDuplicating()) { 2519f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent continue; 2520f6870aefc5e31d4220f3778c4e79ff34a61f48adEric Laurent } 252181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioStreamOut *output = thread->getOutput(); 252281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (output != NULL && output->audioHwDev == mPrimaryHardwareDev) { 252381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread; 252437d825e72a6c606553a745da1212590a425996d3Glenn Kasten } 252537d825e72a6c606553a745da1212590a425996d3Glenn Kasten } 252681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NULL; 252737d825e72a6c606553a745da1212590a425996d3Glenn Kasten} 252837d825e72a6c606553a745da1212590a425996d3Glenn Kasten 252981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentaudio_devices_t AudioFlinger::primaryOutputDevice_l() const 253065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 253181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *thread = primaryPlaybackThread_l(); 2532000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 253381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 253481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return 0; 25359f34a36d9cdb9595c288e50ffe00da038bc8abb9Glenn Kasten } 2536000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 253781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return thread->outDevice(); 2538000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten} 2539688a64030834ea2f52cc9765676ddf6aa34df767Glenn Kasten 2540a73356393315ad3ad7cd9196640823d1a9a620ddGlenn KastenAudioFlinger::PlaybackThread *AudioFlinger::fastPlaybackThread_l() const 2541a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten{ 2542a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten size_t minFrameCount = 0; 2543a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten PlaybackThread *minThread = NULL; 2544a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 2545a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten PlaybackThread *thread = mPlaybackThreads.valueAt(i).get(); 2546a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten if (!thread->isDuplicating()) { 2547a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten size_t frameCount = thread->frameCountHAL(); 2548a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten if (frameCount != 0 && (minFrameCount == 0 || frameCount < minFrameCount || 2549a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten (frameCount == minFrameCount && thread->hasFastMixer() && 2550a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten /*minThread != NULL &&*/ !minThread->hasFastMixer()))) { 2551a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten minFrameCount = frameCount; 2552a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten minThread = thread; 2553a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten } 2554a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten } 2555a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten } 2556a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten return minThread; 2557a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten} 2558a73356393315ad3ad7cd9196640823d1a9a620ddGlenn Kasten 255981784c37c61b09289654b979567a42bf73cd2b12Eric Laurentsp<AudioFlinger::SyncEvent> AudioFlinger::createSyncEvent(AudioSystem::sync_event_t type, 2560d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t triggerSession, 2561d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t listenerSession, 256281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sync_event_callback_t callBack, 25638ea16e4b0a7d398d26887c18675b3899de5d779dEric Laurent wp<RefBase> cookie) 256481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent{ 256581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 256673ca0f5837d5448f7a5eb159a09cd0ebe82b4de9Glenn Kasten 256781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<SyncEvent> event = new SyncEvent(type, triggerSession, listenerSession, callBack, cookie); 256881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t playStatus = NAME_NOT_FOUND; 256981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t recStatus = NAME_NOT_FOUND; 257081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 257181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent playStatus = mPlaybackThreads.valueAt(i)->setSyncEvent(event); 257281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (playStatus == NO_ERROR) { 257381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return event; 257481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 257565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 257681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 257781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent recStatus = mRecordThreads.valueAt(i)->setSyncEvent(event); 257881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (recStatus == NO_ERROR) { 257981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return event; 25809f34a36d9cdb9595c288e50ffe00da038bc8abb9Glenn Kasten } 258165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 258281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (playStatus == NAME_NOT_FOUND || recStatus == NAME_NOT_FOUND) { 258381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent mPendingSyncEvents.add(event); 258481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else { 258581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("createSyncEvent() invalid event %d", event->type()); 258681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent event.clear(); 258781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 258881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return event; 258965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 259065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 259181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 259281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// Effect management 259381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// ---------------------------------------------------------------------------- 259458912562617941964939a4182cda71eaeb153d4bGlenn Kasten 259558912562617941964939a4182cda71eaeb153d4bGlenn Kasten 259681784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::queryNumberEffects(uint32_t *numEffects) const 2597000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten{ 259881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 259981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return EffectQueryNumberEffects(numEffects); 2600000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten} 2601000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 260281784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::queryEffect(uint32_t index, effect_descriptor_t *descriptor) const 260358912562617941964939a4182cda71eaeb153d4bGlenn Kasten{ 260481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 260581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return EffectQueryEffect(index, descriptor); 260658912562617941964939a4182cda71eaeb153d4bGlenn Kasten} 260758912562617941964939a4182cda71eaeb153d4bGlenn Kasten 260881784c37c61b09289654b979567a42bf73cd2b12Eric Laurentstatus_t AudioFlinger::getEffectDescriptor(const effect_uuid_t *pUuid, 260981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect_descriptor_t *descriptor) const 2610000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten{ 261181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _l(mLock); 261281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return EffectGetDescriptor(pUuid, descriptor); 2613000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten} 2614000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 261581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent 26168d6cc842e8d525405c68e57fdf3bc5da0b4d7e87Glenn Kastensp<IEffect> AudioFlinger::createEffect( 261781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect_descriptor_t *pDesc, 261881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent const sp<IEffectClient>& effectClient, 261981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int32_t priority, 262081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t io, 2621d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t sessionId, 2622be71aa29a3c86d2e01cd17839d2a72ab09a1bce5Svet Ganov const String16& opPackageName, 262381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t *status, 262481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int *id, 262581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent int *enabled) 2626000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten{ 262781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent status_t lStatus = NO_ERROR; 262881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectHandle> handle; 262981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect_descriptor_t desc; 2630000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 26318d6cc842e8d525405c68e57fdf3bc5da0b4d7e87Glenn Kasten pid_t pid = IPCThreadState::self()->getCallingPid(); 263281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("createEffect pid %d, effectClient %p, priority %d, sessionId %d, io %d", 263381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent pid, effectClient.get(), priority, sessionId, io); 2634000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 263581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (pDesc == NULL) { 263681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 263781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 2638952eeb27682a9b2ddfa761f24b6eb5e18fe5d814Glenn Kasten } 2639000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 264081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // check audio settings permission for global effects 264181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId == AUDIO_SESSION_OUTPUT_MIX && !settingsAllowed()) { 264281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = PERMISSION_DENIED; 264381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 2644952eeb27682a9b2ddfa761f24b6eb5e18fe5d814Glenn Kasten } 2645000f0e39b4d0c88441297a05ab5f8da6832c1640Glenn Kasten 264681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Session AUDIO_SESSION_OUTPUT_STAGE is reserved for output stage effects 264781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // that can only be created by audio policy manager (running in same process) 264881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId == AUDIO_SESSION_OUTPUT_STAGE && getpid_cached != pid) { 264981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = PERMISSION_DENIED; 265081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 2651952eeb27682a9b2ddfa761f24b6eb5e18fe5d814Glenn Kasten } 265265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 265381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent { 265481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (!EffectIsNullUuid(&pDesc->uuid)) { 265581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // if uuid is specified, request effect descriptor 265681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = EffectGetDescriptor(&pDesc->uuid, &desc); 265781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (lStatus < 0) { 265881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() error %d from EffectGetDescriptor", lStatus); 265981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 266081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 266181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } else { 266281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // if uuid is not specified, look for an available implementation 266381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // of the required type in effect factory 266481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (EffectIsNullUuid(&pDesc->type)) { 266581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() no effect type"); 266681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 266781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 2668288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten } 266981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t numEffects = 0; 267081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect_descriptor_t d; 267181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent d.flags = 0; // prevent compiler warning 267281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool found = false; 2673288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten 267481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = EffectQueryNumberEffects(&numEffects); 267581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (lStatus < 0) { 267681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() error %d from EffectQueryNumberEffects", lStatus); 267781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 267881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 267981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent for (uint32_t i = 0; i < numEffects; i++) { 268081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = EffectQueryEffect(i, &desc); 268181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (lStatus < 0) { 268281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() error %d from EffectQueryEffect", lStatus); 268381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent continue; 2684d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten } 268581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (memcmp(&desc.type, &pDesc->type, sizeof(effect_uuid_t)) == 0) { 268681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If matching type found save effect descriptor. If the session is 268781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // 0 and the effect is not auxiliary, continue enumeration in case 268881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // an auxiliary version of this effect type is available 268981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent found = true; 269081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent d = desc; 269181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId != AUDIO_SESSION_OUTPUT_MIX || 269281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { 2693d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten break; 2694d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten } 2695d08f48c2ad2941d62b313007955c7145075d562cGlenn Kasten } 2696288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten } 269781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (!found) { 269881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 269981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("createEffect() effect not found"); 270081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 270181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 270281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // For same effect type, chose auxiliary version over insert version if 270381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // connect to output mix (Compliance to OpenSL ES) 270481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId == AUDIO_SESSION_OUTPUT_MIX && 270581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (d.flags & EFFECT_FLAG_TYPE_MASK) != EFFECT_FLAG_TYPE_AUXILIARY) { 270681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent desc = d; 270758912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 270858912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 270958912562617941964939a4182cda71eaeb153d4bGlenn Kasten 271081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Do not allow auxiliary effects on a session different from 0 (output mix) 271181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (sessionId != AUDIO_SESSION_OUTPUT_MIX && 271281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent (desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { 271381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = INVALID_OPERATION; 271481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 27153dbe3201479828e84abe02e1fdd0a5d414c0ddb8Eric Laurent } 271665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 271781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // check recording permission for visualizer 271881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if ((memcmp(&desc.type, SL_IID_VISUALIZATION, sizeof(effect_uuid_t)) == 0) && 2719dcb346b7dc5b88c3e85db8a70bbd6a2fee8192b9Marco Nelissen !recordingAllowed(opPackageName, pid, IPCThreadState::self()->getCallingUid())) { 272081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = PERMISSION_DENIED; 272181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 272281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 272365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 272481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // return effect descriptor 272581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *pDesc = desc; 2726142f519aa1acd5804d111e60d100f170fed28405Glenn Kasten if (io == AUDIO_IO_HANDLE_NONE && sessionId == AUDIO_SESSION_OUTPUT_MIX) { 2727eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent // if the output returned by getOutputForEffect() is removed before we lock the 2728eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent // mutex below, the call to checkPlaybackThread_l(io) below will detect it 2729eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent // and we will exit safely 2730eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent io = AudioSystem::getOutputForEffect(&desc); 2731eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent ALOGV("createEffect got output %d", io); 2732eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent } 2733eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent 2734eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent Mutex::Autolock _l(mLock); 273565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 273681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If output is not specified try to find a matching audio session ID in one of the 273781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // output threads. 273881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If output is 0 here, sessionId is neither SESSION_OUTPUT_STAGE nor SESSION_OUTPUT_MIX 273981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // because of code checking output when entering the function. 274081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // Note: io is never 0 when creating an effect on an input 2741142f519aa1acd5804d111e60d100f170fed28405Glenn Kasten if (io == AUDIO_IO_HANDLE_NONE) { 27425baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent if (sessionId == AUDIO_SESSION_OUTPUT_STAGE) { 27435baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent // output must be specified by AudioPolicyManager when using session 27445baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent // AUDIO_SESSION_OUTPUT_STAGE 27455baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent lStatus = BAD_VALUE; 27465baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent goto Exit; 27475baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent } 2748eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent // look for the thread where the specified audio session is present 2749eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 2750eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent if (mPlaybackThreads.valueAt(i)->hasAudioSession(sessionId) != 0) { 2751eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent io = mPlaybackThreads.keyAt(i); 2752eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent break; 2753eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent } 2754d65d73c4ae74d084751b417615a78cbe7a51372aGlenn Kasten } 275581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (io == 0) { 2756eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent for (size_t i = 0; i < mRecordThreads.size(); i++) { 2757eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent if (mRecordThreads.valueAt(i)->hasAudioSession(sessionId) != 0) { 2758eb3c337a3d6c74ec857dfc8be7eeafe634614bcdEric Laurent io = mRecordThreads.keyAt(i); 275981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent break; 27602986460984580833161bdaabc7f17da1005a8961Eric Laurent } 276165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 276265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 276381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // If no output thread contains the requested session ID, default to 276481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // first output. The effect chain will be moved to the correct output 276581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // thread when a track with the same session ID is created 2766142f519aa1acd5804d111e60d100f170fed28405Glenn Kasten if (io == AUDIO_IO_HANDLE_NONE && mPlaybackThreads.size() > 0) { 276781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent io = mPlaybackThreads.keyAt(0); 276881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 276981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("createEffect() got io %d for effect %s", io, desc.name); 277065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 277181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ThreadBase *thread = checkRecordThread_l(io); 277281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 277381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent thread = checkPlaybackThread_l(io); 277481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (thread == NULL) { 277581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGE("createEffect() unknown output thread"); 277681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent lStatus = BAD_VALUE; 277781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent goto Exit; 2778288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten } 2779aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } else { 2780aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent // Check if one effect chain was awaiting for an effect to be created on this 2781aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent // session and used it instead of creating a new one. 2782d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten sp<EffectChain> chain = getOrphanEffectChain_l(sessionId); 2783aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent if (chain != 0) { 27841b92868010b5c1409692a86f6b27e4a265b64c1aEric Laurent Mutex::Autolock _l(thread->mLock); 2785aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent thread->addEffectChain_l(chain); 2786aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } 2787288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten } 2788288ed2103d96f3aabd7e6bea3c080ab6db164049Glenn Kasten 2789021cf9634ab09c0753a40b7c9ef4ba603be5c3daEric Laurent sp<Client> client = registerPid(pid); 279058912562617941964939a4182cda71eaeb153d4bGlenn Kasten 279181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // create effect on selected output thread 279281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent handle = thread->createEffect_l(client, effectClient, priority, sessionId, 279381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent &desc, enabled, &lStatus); 279481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (handle != 0 && id != NULL) { 279581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent *id = handle->id(); 279665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 2797fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent if (handle == 0) { 2798fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent // remove local strong reference to Client with mClientLock held 2799fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent Mutex::Autolock _cl(mClientLock); 2800fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent client.clear(); 2801fe1a94e68e173fe4dfe7699112422a94eddacb4eEric Laurent } 280265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 280365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 280481784c37c61b09289654b979567a42bf73cd2b12Eric LaurentExit: 28059156ef3e11b68cc4b6d3cea77f1f63673855a6d1Glenn Kasten *status = lStatus; 280681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return handle; 280766fcab972e9218d47c58a915f391b2f48a09903aGlenn Kasten} 280866fcab972e9218d47c58a915f391b2f48a09903aGlenn Kasten 2809d848eb48c121c119e8ba7583efc75415fe102570Glenn Kastenstatus_t AudioFlinger::moveEffects(audio_session_t sessionId, audio_io_handle_t srcOutput, 281081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent audio_io_handle_t dstOutput) 281165ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 281281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("moveEffects() session %d, srcOutput %d, dstOutput %d", 281381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionId, srcOutput, dstOutput); 281465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian Mutex::Autolock _l(mLock); 281581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (srcOutput == dstOutput) { 281681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffects() same dst and src outputs %d", dstOutput); 281781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return NO_ERROR; 281881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 281981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *srcThread = checkPlaybackThread_l(srcOutput); 282081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (srcThread == NULL) { 282181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffects() bad srcOutput %d", srcOutput); 282281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 282381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 282481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent PlaybackThread *dstThread = checkPlaybackThread_l(dstOutput); 282581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (dstThread == NULL) { 282681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffects() bad dstOutput %d", dstOutput); 282781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return BAD_VALUE; 282865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 282965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 283081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _dl(dstThread->mLock); 283181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent Mutex::Autolock _sl(srcThread->mLock); 28325baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent return moveEffectChain_l(sessionId, srcThread, dstThread, false); 283365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 283465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 283581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent// moveEffectChain_l must be called with both srcThread and dstThread mLocks held 2836d848eb48c121c119e8ba7583efc75415fe102570Glenn Kastenstatus_t AudioFlinger::moveEffectChain_l(audio_session_t sessionId, 283781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioFlinger::PlaybackThread *srcThread, 283881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioFlinger::PlaybackThread *dstThread, 283981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent bool reRegister) 284065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 284181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGV("moveEffectChain_l() session %d from thread %p to thread %p", 284281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionId, srcThread, dstThread); 284365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 284481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> chain = srcThread->getEffectChain_l(sessionId); 284581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (chain == 0) { 284681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffectChain_l() effect chain for session %d not on source thread %p", 284781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionId, srcThread); 284881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent return INVALID_OPERATION; 284981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 28509ee159b79022b2e1a050acb3890ce948e99e9ccbGloria Wang 28514c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent // Check whether the destination thread and all effects in the chain are compatible 28524c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent if (!chain->isCompatibleWithThread_l(dstThread)) { 28539a59276fb465e492138e0576523b54079671e8f4Andy Hung ALOGW("moveEffectChain_l() effect chain failed because" 28544c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent " destination thread %p is not compatible with effects in the chain", 28554c415062ad1bb53e9af8f644d8215837262b79bbEric Laurent dstThread); 28569a59276fb465e492138e0576523b54079671e8f4Andy Hung return INVALID_OPERATION; 28579a59276fb465e492138e0576523b54079671e8f4Andy Hung } 28589a59276fb465e492138e0576523b54079671e8f4Andy Hung 285981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // remove chain first. This is useful only if reconfiguring effect chain on same output thread, 286081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // so that a new chain is created with correct parameters when first effect is added. This is 286181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // otherwise unnecessary as removeEffect_l() will remove the chain when last effect is 286281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // removed. 286381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent srcThread->removeEffectChain_l(chain); 28649ee159b79022b2e1a050acb3890ce948e99e9ccbGloria Wang 286581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // transfer all effects one by one so that new effect chain is created on new thread with 286681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // correct buffer sizes and audio parameters and effect engines reconfigured accordingly 286781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectChain> dstChain; 286881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent uint32_t strategy = 0; // prevent compiler warning 286981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sp<EffectModule> effect = chain->getEffectFromId_l(0); 28705baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent Vector< sp<EffectModule> > removed; 28715baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent status_t status = NO_ERROR; 287281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent while (effect != 0) { 287381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent srcThread->removeEffect_l(effect); 28745baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent removed.add(effect); 28755baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent status = dstThread->addEffect_l(effect); 28765baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent if (status != NO_ERROR) { 28775baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent break; 28785baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent } 287981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // removeEffect_l() has stopped the effect if it was active so it must be restarted 288081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (effect->state() == EffectModule::ACTIVE || 288181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect->state() == EffectModule::STOPPING) { 288281784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect->start(); 288365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 288481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // if the move request is not received from audio policy manager, the effect must be 288581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent // re-registered with the new strategy and output 288681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (dstChain == 0) { 288781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent dstChain = effect->chain().promote(); 288881784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (dstChain == 0) { 288981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent ALOGW("moveEffectChain_l() cannot get chain from effect %p", effect.get()); 28905baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent status = NO_INIT; 28915baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent break; 289265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 289381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent strategy = dstChain->strategy(); 289465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian } 289581784c37c61b09289654b979567a42bf73cd2b12Eric Laurent if (reRegister) { 289681784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSystem::unregisterEffect(effect->id()); 289781784c37c61b09289654b979567a42bf73cd2b12Eric Laurent AudioSystem::registerEffect(&effect->desc(), 28985baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent dstThread->id(), 289981784c37c61b09289654b979567a42bf73cd2b12Eric Laurent strategy, 290081784c37c61b09289654b979567a42bf73cd2b12Eric Laurent sessionId, 290181784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect->id()); 2902d72b7c0180ee83fc3754629ed68fc5887a125c4cEric Laurent AudioSystem::setEffectEnabled(effect->id(), effect->isEnabled()); 290381784c37c61b09289654b979567a42bf73cd2b12Eric Laurent } 290481784c37c61b09289654b979567a42bf73cd2b12Eric Laurent effect = chain->getEffectFromId_l(0); 290558912562617941964939a4182cda71eaeb153d4bGlenn Kasten } 290658912562617941964939a4182cda71eaeb153d4bGlenn Kasten 29075baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent if (status != NO_ERROR) { 29085baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent for (size_t i = 0; i < removed.size(); i++) { 29095baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent srcThread->addEffect_l(removed[i]); 29105baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent if (dstChain != 0 && reRegister) { 29115baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent AudioSystem::unregisterEffect(removed[i]->id()); 29125baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent AudioSystem::registerEffect(&removed[i]->desc(), 29135baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent srcThread->id(), 29145baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent strategy, 29155baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent sessionId, 29165baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent removed[i]->id()); 2917d72b7c0180ee83fc3754629ed68fc5887a125c4cEric Laurent AudioSystem::setEffectEnabled(effect->id(), effect->isEnabled()); 29185baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent } 29195baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent } 29205baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent } 29215baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent 29225baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent return status; 292365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 292465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 29255baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurentbool AudioFlinger::isNonOffloadableGlobalEffectEnabled_l() 2926813e2a74853bde19e37d878c596a044b3f299efcEric Laurent{ 2927813e2a74853bde19e37d878c596a044b3f299efcEric Laurent if (mGlobalEffectEnableTime != 0 && 2928813e2a74853bde19e37d878c596a044b3f299efcEric Laurent ((systemTime() - mGlobalEffectEnableTime) < kMinGlobalEffectEnabletimeNs)) { 2929813e2a74853bde19e37d878c596a044b3f299efcEric Laurent return true; 2930813e2a74853bde19e37d878c596a044b3f299efcEric Laurent } 2931813e2a74853bde19e37d878c596a044b3f299efcEric Laurent 2932813e2a74853bde19e37d878c596a044b3f299efcEric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 2933813e2a74853bde19e37d878c596a044b3f299efcEric Laurent sp<EffectChain> ec = 2934813e2a74853bde19e37d878c596a044b3f299efcEric Laurent mPlaybackThreads.valueAt(i)->getEffectChain_l(AUDIO_SESSION_OUTPUT_MIX); 29355baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurent if (ec != 0 && ec->isNonOffloadableEnabled()) { 2936813e2a74853bde19e37d878c596a044b3f299efcEric Laurent return true; 2937813e2a74853bde19e37d878c596a044b3f299efcEric Laurent } 2938813e2a74853bde19e37d878c596a044b3f299efcEric Laurent } 2939813e2a74853bde19e37d878c596a044b3f299efcEric Laurent return false; 2940813e2a74853bde19e37d878c596a044b3f299efcEric Laurent} 2941813e2a74853bde19e37d878c596a044b3f299efcEric Laurent 29425baf2af52cd186633b7173196c1e4a4cd3435f22Eric Laurentvoid AudioFlinger::onNonOffloadableGlobalEffectEnable() 2943813e2a74853bde19e37d878c596a044b3f299efcEric Laurent{ 2944813e2a74853bde19e37d878c596a044b3f299efcEric Laurent Mutex::Autolock _l(mLock); 2945813e2a74853bde19e37d878c596a044b3f299efcEric Laurent 2946813e2a74853bde19e37d878c596a044b3f299efcEric Laurent mGlobalEffectEnableTime = systemTime(); 2947813e2a74853bde19e37d878c596a044b3f299efcEric Laurent 2948813e2a74853bde19e37d878c596a044b3f299efcEric Laurent for (size_t i = 0; i < mPlaybackThreads.size(); i++) { 2949813e2a74853bde19e37d878c596a044b3f299efcEric Laurent sp<PlaybackThread> t = mPlaybackThreads.valueAt(i); 2950813e2a74853bde19e37d878c596a044b3f299efcEric Laurent if (t->mType == ThreadBase::OFFLOAD) { 2951813e2a74853bde19e37d878c596a044b3f299efcEric Laurent t->invalidateTracks(AUDIO_STREAM_MUSIC); 2952813e2a74853bde19e37d878c596a044b3f299efcEric Laurent } 2953813e2a74853bde19e37d878c596a044b3f299efcEric Laurent } 2954813e2a74853bde19e37d878c596a044b3f299efcEric Laurent 2955813e2a74853bde19e37d878c596a044b3f299efcEric Laurent} 2956813e2a74853bde19e37d878c596a044b3f299efcEric Laurent 2957aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurentstatus_t AudioFlinger::putOrphanEffectChain_l(const sp<AudioFlinger::EffectChain>& chain) 2958aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent{ 2959d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t session = chain->sessionId(); 2960aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent ssize_t index = mOrphanEffectChains.indexOfKey(session); 2961c42e9b462661673dff480ee71757a58b0f806370Glenn Kasten ALOGV("putOrphanEffectChain_l session %d index %zd", session, index); 2962aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent if (index >= 0) { 2963aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent ALOGW("putOrphanEffectChain_l chain for session %d already present", session); 2964aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent return ALREADY_EXISTS; 2965aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } 2966aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent mOrphanEffectChains.add(session, chain); 2967aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent return NO_ERROR; 2968aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent} 2969aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent 2970aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurentsp<AudioFlinger::EffectChain> AudioFlinger::getOrphanEffectChain_l(audio_session_t session) 2971aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent{ 2972aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent sp<EffectChain> chain; 2973aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent ssize_t index = mOrphanEffectChains.indexOfKey(session); 2974c42e9b462661673dff480ee71757a58b0f806370Glenn Kasten ALOGV("getOrphanEffectChain_l session %d index %zd", session, index); 2975aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent if (index >= 0) { 2976aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent chain = mOrphanEffectChains.valueAt(index); 2977aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent mOrphanEffectChains.removeItemsAt(index); 2978aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } 2979aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent return chain; 2980aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent} 2981aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent 2982aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurentbool AudioFlinger::updateOrphanEffectChains(const sp<AudioFlinger::EffectModule>& effect) 2983aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent{ 2984aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent Mutex::Autolock _l(mLock); 2985d848eb48c121c119e8ba7583efc75415fe102570Glenn Kasten audio_session_t session = effect->sessionId(); 2986aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent ssize_t index = mOrphanEffectChains.indexOfKey(session); 2987c42e9b462661673dff480ee71757a58b0f806370Glenn Kasten ALOGV("updateOrphanEffectChains session %d index %zd", session, index); 2988aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent if (index >= 0) { 2989aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent sp<EffectChain> chain = mOrphanEffectChains.valueAt(index); 2990aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent if (chain->removeEffect_l(effect) == 0) { 2991c42e9b462661673dff480ee71757a58b0f806370Glenn Kasten ALOGV("updateOrphanEffectChains removing effect chain at index %zd", index); 2992aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent mOrphanEffectChains.removeItemsAt(index); 2993aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } 2994aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent return true; 2995aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent } 2996aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent return false; 2997aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent} 2998aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent 2999aaa44478a373232d8416657035a9020f9c7aa7c3Eric Laurent 3000da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenstruct Entry { 30012f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten#define TEE_MAX_FILENAME 32 // %Y%m%d%H%M%S_%d.wav = 4+2+2+2+2+2+1+1+4+1 = 21 30022f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten char mFileName[TEE_MAX_FILENAME]; 3003da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten}; 3004da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 3005da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kastenint comparEntry(const void *p1, const void *p2) 3006da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten{ 30072f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten return strcmp(((const Entry *) p1)->mFileName, ((const Entry *) p2)->mFileName); 3008da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten} 3009da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten 301046909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#ifdef TEE_SINK 3011d06785bebf7e43d4a011b62a252771373ada910cGlenn Kastenvoid AudioFlinger::dumpTee(int fd, const sp<NBAIO_Source>& source, audio_io_handle_t id) 301265ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 3013d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten NBAIO_Source *teeSource = source.get(); 3014fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten if (teeSource != NULL) { 3015da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // .wav rotation 3016da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // There is a benign race condition if 2 threads call this simultaneously. 3017da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // They would both traverse the directory, but the result would simply be 3018da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // failures at unlink() which are ignored. It's also unlikely since 3019da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // normally dumpsys is only done by bugreport or from the command line. 3020da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten char teePath[32+256]; 30219a00399340c7c129714dff96f1ab59045fe43056Glenn Kasten strcpy(teePath, "/data/misc/audioserver"); 3022da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten size_t teePathLen = strlen(teePath); 3023da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten DIR *dir = opendir(teePath); 3024da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten teePath[teePathLen++] = '/'; 3025da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (dir != NULL) { 30262f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten#define TEE_MAX_SORT 20 // number of entries to sort 30272f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten#define TEE_MAX_KEEP 10 // number of entries to keep 30282f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten struct Entry entries[TEE_MAX_SORT]; 3029da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten size_t entryCount = 0; 30302f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten while (entryCount < TEE_MAX_SORT) { 3031da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten struct dirent de; 3032da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten struct dirent *result = NULL; 3033da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten int rc = readdir_r(dir, &de, &result); 3034da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (rc != 0) { 3035da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten ALOGW("readdir_r failed %d", rc); 3036da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten break; 3037da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3038da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (result == NULL) { 3039da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten break; 3040da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3041da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (result != &de) { 3042da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten ALOGW("readdir_r returned unexpected result %p != %p", result, &de); 3043da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten break; 3044da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3045da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // ignore non .wav file entries 3046da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten size_t nameLen = strlen(de.d_name); 30472f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten if (nameLen <= 4 || nameLen >= TEE_MAX_FILENAME || 3048da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten strcmp(&de.d_name[nameLen - 4], ".wav")) { 3049da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten continue; 3050da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 30512f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten strcpy(entries[entryCount++].mFileName, de.d_name); 3052da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3053da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten (void) closedir(dir); 30542f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten if (entryCount > TEE_MAX_KEEP) { 3055da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten qsort(entries, entryCount, sizeof(Entry), comparEntry); 30562f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten for (size_t i = 0; i < entryCount - TEE_MAX_KEEP; ++i) { 30572f55e7632dfa0dafde58efd8cb2af6593217fd91Glenn Kasten strcpy(&teePath[teePathLen], entries[i].mFileName); 3058da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten (void) unlink(teePath); 3059da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3060da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3061da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } else { 3062da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (fd >= 0) { 3063fbd87e8b685d1b1511bc40e232f9e7674271d57bGlenn Kasten dprintf(fd, "unable to rotate tees in %.*s: %s\n", (int) teePathLen, teePath, 30649a00399340c7c129714dff96f1ab59045fe43056Glenn Kasten strerror(errno)); 3065da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3066da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3067d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten char teeTime[16]; 3068fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten struct timeval tv; 3069fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten gettimeofday(&tv, NULL); 3070fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten struct tm tm; 3071fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten localtime_r(&tv.tv_sec, &tm); 3072da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten strftime(teeTime, sizeof(teeTime), "%Y%m%d%H%M%S", &tm); 3073da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten snprintf(&teePath[teePathLen], sizeof(teePath) - teePathLen, "%s_%d.wav", teeTime, id); 3074da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten // if 2 dumpsys are done within 1 second, and rotation didn't work, then discard 2nd 3075da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten int teeFd = open(teePath, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, S_IRUSR | S_IWUSR); 3076fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten if (teeFd >= 0) { 3077329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten // FIXME use libsndfile 3078fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten char wavHeader[44]; 3079fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten memcpy(wavHeader, 3080fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn 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", 3081fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten sizeof(wavHeader)); 3082fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten NBAIO_Format format = teeSource->format(); 3083fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten unsigned channelCount = Format_channelCount(format); 30843b16c766d1ae2cfd8487e8ffb2b23936fc0a8e17Glenn Kasten uint32_t sampleRate = Format_sampleRate(format); 3085329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten size_t frameSize = Format_frameSize(format); 3086fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten wavHeader[22] = channelCount; // number of channels 3087fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten wavHeader[24] = sampleRate; // sample rate 3088fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten wavHeader[25] = sampleRate >> 8; 3089329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten wavHeader[32] = frameSize; // block alignment 3090329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten wavHeader[33] = frameSize >> 8; 3091fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten write(teeFd, wavHeader, sizeof(wavHeader)); 3092fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten size_t total = 0; 3093fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten bool firstRead = true; 3094329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten#define TEE_SINK_READ 1024 // frames per I/O operation 3095329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten void *buffer = malloc(TEE_SINK_READ * frameSize); 3096fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten for (;;) { 3097fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten size_t count = TEE_SINK_READ; 3098d79072e9dff59f767cce2cda1caab80ce5a0815bGlenn Kasten ssize_t actual = teeSource->read(buffer, count); 3099fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten bool wasFirstRead = firstRead; 3100fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten firstRead = false; 3101fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten if (actual <= 0) { 3102fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten if (actual == (ssize_t) OVERRUN && wasFirstRead) { 3103fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten continue; 3104fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 3105fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten break; 3106fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 3107a5f44ebaf58911805b4fb7fb479b19fd89d2e39bEric Laurent ALOG_ASSERT(actual <= (ssize_t)count); 3108329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten write(teeFd, buffer, actual * frameSize); 3109fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten total += actual; 3110fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 3111329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten free(buffer); 3112fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten lseek(teeFd, (off_t) 4, SEEK_SET); 3113329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten uint32_t temp = 44 + total * frameSize - 8; 3114329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten // FIXME not big-endian safe 3115fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten write(teeFd, &temp, sizeof(temp)); 3116fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten lseek(teeFd, (off_t) 40, SEEK_SET); 3117329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten temp = total * frameSize; 3118329f6511ee4e03a4605c70bbda8d3a96d2544884Glenn Kasten // FIXME not big-endian safe 3119fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten write(teeFd, &temp, sizeof(temp)); 3120fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten close(teeFd); 3121da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (fd >= 0) { 31228b5f642eb2364ea7fe46a5b3af51b48b58f12183Elliott Hughes dprintf(fd, "tee copied to %s\n", teePath); 3123da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3124fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } else { 3125da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten if (fd >= 0) { 31268b5f642eb2364ea7fe46a5b3af51b48b58f12183Elliott Hughes dprintf(fd, "unable to create tee %s: %s\n", teePath, strerror(errno)); 3127da6ef1320d0161b1640dc84d7a9c5a25860c3619Glenn Kasten } 3128fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 3129fbae5dae5187aca9d974cbe15ec818e9c6f56705Glenn Kasten } 3130d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten} 313146909e7eb074ce1b95b8a411eb71154f53f84f77Glenn Kasten#endif 3132d06785bebf7e43d4a011b62a252771373ada910cGlenn Kasten 313365ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian// ---------------------------------------------------------------------------- 313465ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 313565ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopianstatus_t AudioFlinger::onTransact( 313665ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 313765ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian{ 313865ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian return BnAudioFlinger::onTransact(code, data, reply, flags); 313965ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian} 314065ab47156e1c7dfcd8cc4266253a5ff30219e7f0Mathias Agopian 314163238efb0d674758902918e3cdaac322126484b7Glenn Kasten} // namespace android 3142