Glenn Kasten | 99e53b8 | 2012-01-19 08:59:58 -0800 | [diff] [blame] | 1 | /* |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2 | ** |
| 3 | ** Copyright 2007, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | #define LOG_TAG "AudioFlinger" |
| 20 | //#define LOG_NDEBUG 0 |
| 21 | |
jiabin | a392a55 | 2019-09-23 10:34:20 -0700 | [diff] [blame] | 22 | // Define AUDIO_ARRAYS_STATIC_CHECK to check all audio arrays are correct |
| 23 | #define AUDIO_ARRAYS_STATIC_CHECK 1 |
| 24 | |
Glenn Kasten | 153b9fe | 2013-07-15 11:23:36 -0700 | [diff] [blame] | 25 | #include "Configuration.h" |
Glenn Kasten | da6ef13 | 2013-01-10 12:31:01 -0800 | [diff] [blame] | 26 | #include <dirent.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 27 | #include <math.h> |
| 28 | #include <signal.h> |
Eric Tan | 7b65115 | 2018-07-13 10:17:19 -0700 | [diff] [blame] | 29 | #include <string> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 30 | #include <sys/time.h> |
| 31 | #include <sys/resource.h> |
| 32 | |
jiabin | 57303cc | 2018-12-18 15:45:57 -0800 | [diff] [blame] | 33 | #include <android/os/IExternalVibratorService.h> |
Gloria Wang | 9ee159b | 2011-02-24 14:51:45 -0800 | [diff] [blame] | 34 | #include <binder/IPCThreadState.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 35 | #include <binder/IServiceManager.h> |
| 36 | #include <utils/Log.h> |
Glenn Kasten | d8e6fd3 | 2012-05-07 11:07:57 -0700 | [diff] [blame] | 37 | #include <utils/Trace.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 38 | #include <binder/Parcel.h> |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 39 | #include <media/audiohal/DeviceHalInterface.h> |
| 40 | #include <media/audiohal/DevicesFactoryHalInterface.h> |
| 41 | #include <media/audiohal/EffectsFactoryHalInterface.h> |
Mikhail Naganov | 00260b5 | 2016-10-13 12:54:24 -0700 | [diff] [blame] | 42 | #include <media/AudioParameter.h> |
Mikhail Naganov | 913d06c | 2016-11-01 12:49:22 -0700 | [diff] [blame] | 43 | #include <media/TypeConverter.h> |
Andy Hung | 35fec5f | 2016-04-13 14:21:48 -0700 | [diff] [blame] | 44 | #include <memunreachable/memunreachable.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 45 | #include <utils/String16.h> |
| 46 | #include <utils/threads.h> |
| 47 | |
Steven Moreland | f0c02ce | 2018-02-23 14:53:55 -0800 | [diff] [blame] | 48 | #include <cutils/atomic.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 49 | #include <cutils/properties.h> |
| 50 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 51 | #include <system/audio.h> |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 52 | #include <audiomanager/AudioManager.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 53 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 54 | #include "AudioFlinger.h" |
Andy Hung | 8946a28 | 2018-04-19 20:04:56 -0700 | [diff] [blame] | 55 | #include "NBAIO_Tee.h" |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 56 | |
Andy Hung | 6770c6f | 2015-04-07 13:43:36 -0700 | [diff] [blame] | 57 | #include <media/AudioResamplerPublic.h> |
| 58 | |
Mikhail Naganov | 9fe9401 | 2016-10-14 14:57:40 -0700 | [diff] [blame] | 59 | #include <system/audio_effects/effect_visualizer.h> |
| 60 | #include <system/audio_effects/effect_ns.h> |
| 61 | #include <system/audio_effects/effect_aec.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 62 | |
Glenn Kasten | 3b21c50 | 2011-12-15 09:52:39 -0800 | [diff] [blame] | 63 | #include <audio_utils/primitives.h> |
| 64 | |
Eric Laurent | feb0db6 | 2011-07-22 09:04:31 -0700 | [diff] [blame] | 65 | #include <powermanager/PowerManager.h> |
Glenn Kasten | 190a46f | 2012-03-06 11:27:10 -0800 | [diff] [blame] | 66 | |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 67 | #include <media/IMediaLogService.h> |
Andy Hung | 07b745e | 2016-05-23 16:21:07 -0700 | [diff] [blame] | 68 | #include <media/MemoryLeakTrackUtil.h> |
Glenn Kasten | da6ef13 | 2013-01-10 12:31:01 -0800 | [diff] [blame] | 69 | #include <media/nbaio/Pipe.h> |
| 70 | #include <media/nbaio/PipeReader.h> |
Wei Jia | 3f273d1 | 2015-11-24 09:06:49 -0800 | [diff] [blame] | 71 | #include <mediautils/BatteryNotifier.h> |
Andy Hung | ab7ef30 | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 72 | #include <mediautils/ServiceUtilities.h> |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 73 | #include <mediautils/TimeCheck.h> |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 74 | #include <private/android_filesystem_config.h> |
Glenn Kasten | da6ef13 | 2013-01-10 12:31:01 -0800 | [diff] [blame] | 75 | |
rago | 3bd1c87 | 2016-09-26 12:58:14 -0700 | [diff] [blame] | 76 | //#define BUFLOG_NDEBUG 0 |
| 77 | #include <BufLog.h> |
| 78 | |
Nicolas Roulet | fe1e144 | 2017-01-30 12:02:03 -0800 | [diff] [blame] | 79 | #include "TypedLogger.h" |
| 80 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 81 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 82 | |
John Grossman | 1c34519 | 2012-03-27 14:00:17 -0700 | [diff] [blame] | 83 | // Note: the following macro is used for extremely verbose logging message. In |
| 84 | // order to run with ALOG_ASSERT turned on, we need to have LOG_NDEBUG set to |
| 85 | // 0; but one side effect of this is to turn all LOGV's as well. Some messages |
| 86 | // are so verbose that we want to suppress them even when we have ALOG_ASSERT |
| 87 | // turned on. Do not uncomment the #def below unless you really know what you |
| 88 | // are doing and want to see all of the extremely verbose messages. |
| 89 | //#define VERY_VERY_VERBOSE_LOGGING |
| 90 | #ifdef VERY_VERY_VERBOSE_LOGGING |
| 91 | #define ALOGVV ALOGV |
| 92 | #else |
| 93 | #define ALOGVV(a...) do { } while(0) |
| 94 | #endif |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 95 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 96 | namespace android { |
| 97 | |
Glenn Kasten | ec1d6b5 | 2011-12-12 09:04:45 -0800 | [diff] [blame] | 98 | static const char kDeadlockedString[] = "AudioFlinger may be deadlocked\n"; |
| 99 | static const char kHardwareLockedString[] = "Hardware lock is taken\n"; |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 100 | static const char kClientLockedString[] = "Client lock is taken\n"; |
Mikhail Naganov | 4a3d5c2 | 2016-08-15 13:47:42 -0700 | [diff] [blame] | 101 | static const char kNoEffectsFactory[] = "Effects Factory is absent\n"; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 102 | |
Glenn Kasten | 5891256 | 2012-04-03 10:45:00 -0700 | [diff] [blame] | 103 | |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 104 | nsecs_t AudioFlinger::mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs; |
Eric Laurent | 7cafbb3 | 2011-11-22 18:50:29 -0800 | [diff] [blame] | 105 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 106 | uint32_t AudioFlinger::mScreenState; |
Glenn Kasten | 3ed2920 | 2012-08-07 15:24:44 -0700 | [diff] [blame] | 107 | |
Eric Laurent | 813e2a7 | 2013-08-31 12:59:48 -0700 | [diff] [blame] | 108 | // In order to avoid invalidating offloaded tracks each time a Visualizer is turned on and off |
| 109 | // we define a minimum time during which a global effect is considered enabled. |
| 110 | static const nsecs_t kMinGlobalEffectEnabletimeNs = seconds(7200); |
| 111 | |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 112 | Mutex gLock; |
| 113 | wp<AudioFlinger> gAudioFlinger; |
| 114 | |
Glenn Kasten | 04b96fc | 2017-04-10 14:58:47 -0700 | [diff] [blame] | 115 | // Keep a strong reference to media.log service around forever. |
| 116 | // The service is within our parent process so it can never die in a way that we could observe. |
| 117 | // These two variables are const after initialization. |
| 118 | static sp<IBinder> sMediaLogServiceAsBinder; |
| 119 | static sp<IMediaLogService> sMediaLogService; |
| 120 | |
| 121 | static pthread_once_t sMediaLogOnce = PTHREAD_ONCE_INIT; |
| 122 | |
| 123 | static void sMediaLogInit() |
| 124 | { |
| 125 | sMediaLogServiceAsBinder = defaultServiceManager()->getService(String16("media.log")); |
| 126 | if (sMediaLogServiceAsBinder != 0) { |
| 127 | sMediaLogService = interface_cast<IMediaLogService>(sMediaLogServiceAsBinder); |
| 128 | } |
| 129 | } |
| 130 | |
jiabin | 57303cc | 2018-12-18 15:45:57 -0800 | [diff] [blame] | 131 | // Keep a strong reference to external vibrator service |
| 132 | static sp<os::IExternalVibratorService> sExternalVibratorService; |
| 133 | |
| 134 | static sp<os::IExternalVibratorService> getExternalVibratorService() { |
| 135 | if (sExternalVibratorService == 0) { |
| 136 | sp <IBinder> binder = defaultServiceManager()->getService( |
| 137 | String16("external_vibrator_service")); |
| 138 | if (binder != 0) { |
| 139 | sExternalVibratorService = |
| 140 | interface_cast<os::IExternalVibratorService>(binder); |
| 141 | } |
| 142 | } |
| 143 | return sExternalVibratorService; |
| 144 | } |
| 145 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 146 | // ---------------------------------------------------------------------------- |
| 147 | |
Mikhail Naganov | 913d06c | 2016-11-01 12:49:22 -0700 | [diff] [blame] | 148 | std::string formatToString(audio_format_t format) { |
| 149 | std::string result; |
| 150 | FormatConverter::toString(format, result); |
| 151 | return result; |
Marco Nelissen | b220884 | 2014-02-07 14:00:50 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 154 | // ---------------------------------------------------------------------------- |
| 155 | |
| 156 | AudioFlinger::AudioFlinger() |
| 157 | : BnAudioFlinger(), |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 158 | mMediaLogNotifier(new AudioFlinger::MediaLogNotifier()), |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 159 | mPrimaryHardwareDev(NULL), |
Glenn Kasten | 9ea65d0 | 2014-01-17 10:21:24 -0800 | [diff] [blame] | 160 | mAudioHwDevs(NULL), |
Glenn Kasten | 7d6c35b | 2012-07-02 12:45:10 -0700 | [diff] [blame] | 161 | mHardwareStatus(AUDIO_HW_IDLE), |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 162 | mMasterVolume(1.0f), |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 163 | mMasterMute(false), |
Glenn Kasten | d2e67e1 | 2016-04-11 08:26:37 -0700 | [diff] [blame] | 164 | // mNextUniqueId(AUDIO_UNIQUE_ID_USE_MAX), |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 165 | mMode(AUDIO_MODE_INVALID), |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 166 | mBtNrecIsOff(false), |
| 167 | mIsLowRamDevice(true), |
Eric Laurent | 813e2a7 | 2013-08-31 12:59:48 -0700 | [diff] [blame] | 168 | mIsDeviceTypeKnown(false), |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 169 | mTotalMemory(0), |
| 170 | mClientSharedHeapSize(kMinimumClientSharedHeapSizeBytes), |
Glenn Kasten | 4ea00a2 | 2014-06-02 08:29:22 -0700 | [diff] [blame] | 171 | mGlobalEffectEnableTime(0), |
Mikhail Naganov | dea5304 | 2018-04-26 13:10:21 -0700 | [diff] [blame] | 172 | mPatchPanel(this), |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 173 | mSystemReady(false) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 174 | { |
Glenn Kasten | d2e67e1 | 2016-04-11 08:26:37 -0700 | [diff] [blame] | 175 | // unsigned instead of audio_unique_id_use_t, because ++ operator is unavailable for enum |
| 176 | for (unsigned use = AUDIO_UNIQUE_ID_USE_UNSPECIFIED; use < AUDIO_UNIQUE_ID_USE_MAX; use++) { |
| 177 | // zero ID has a special meaning, so unavailable |
| 178 | mNextUniqueIds[use] = AUDIO_UNIQUE_ID_USE_MAX; |
| 179 | } |
| 180 | |
Glenn Kasten | ae0cff1 | 2016-02-24 13:57:49 -0800 | [diff] [blame] | 181 | const bool doLog = property_get_bool("ro.test_harness", false); |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 182 | if (doLog) { |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 183 | mLogMemoryDealer = new MemoryDealer(kLogMemorySize, "LogWriters", |
| 184 | MemoryHeapBase::READ_ONLY); |
Glenn Kasten | 04b96fc | 2017-04-10 14:58:47 -0700 | [diff] [blame] | 185 | (void) pthread_once(&sMediaLogOnce, sMediaLogInit); |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 186 | } |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 187 | |
Wei Jia | 3f273d1 | 2015-11-24 09:06:49 -0800 | [diff] [blame] | 188 | // reset battery stats. |
| 189 | // if the audio service has crashed, battery stats could be left |
| 190 | // in bad state, reset the state upon service start. |
| 191 | BatteryNotifier::getInstance().noteResetAudio(); |
| 192 | |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 193 | mDevicesFactoryHal = DevicesFactoryHalInterface::create(); |
Mikhail Naganov | 4a3d5c2 | 2016-08-15 13:47:42 -0700 | [diff] [blame] | 194 | mEffectsFactoryHal = EffectsFactoryHalInterface::create(); |
| 195 | |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 196 | mMediaLogNotifier->run("MediaLogNotifier"); |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 197 | std::vector<pid_t> halPids; |
| 198 | mDevicesFactoryHal->getHalPids(&halPids); |
| 199 | TimeCheck::setAudioHalPids(halPids); |
Dima Zavin | 5a61d2f | 2011-04-19 19:04:32 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void AudioFlinger::onFirstRef() |
| 203 | { |
Eric Laurent | 9357520 | 2011-01-18 18:39:02 -0800 | [diff] [blame] | 204 | Mutex::Autolock _l(mLock); |
| 205 | |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 206 | /* TODO: move all this work into an Init() function */ |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 207 | char val_str[PROPERTY_VALUE_MAX] = { 0 }; |
| 208 | if (property_get("ro.audio.flinger_standbytime_ms", val_str, NULL) >= 0) { |
| 209 | uint32_t int_val; |
| 210 | if (1 == sscanf(val_str, "%u", &int_val)) { |
| 211 | mStandbyTimeInNsecs = milliseconds(int_val); |
| 212 | ALOGI("Using %u mSec as standby time.", int_val); |
| 213 | } else { |
| 214 | mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs; |
| 215 | ALOGI("Using default %u mSec as standby time.", |
| 216 | (uint32_t)(mStandbyTimeInNsecs / 1000000)); |
| 217 | } |
| 218 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 219 | |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 220 | mMode = AUDIO_MODE_NORMAL; |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 221 | |
| 222 | gAudioFlinger = this; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Eric Laurent | 42896a0 | 2019-09-27 15:40:33 -0700 | [diff] [blame] | 225 | status_t AudioFlinger::setAudioHalPids(const std::vector<pid_t>& pids) { |
| 226 | TimeCheck::setAudioHalPids(pids); |
| 227 | return NO_ERROR; |
| 228 | } |
| 229 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 230 | AudioFlinger::~AudioFlinger() |
| 231 | { |
| 232 | while (!mRecordThreads.isEmpty()) { |
Glenn Kasten | c3ae93f | 2012-07-30 10:59:30 -0700 | [diff] [blame] | 233 | // closeInput_nonvirtual() will remove specified entry from mRecordThreads |
Glenn Kasten | d96c572 | 2012-04-25 13:44:49 -0700 | [diff] [blame] | 234 | closeInput_nonvirtual(mRecordThreads.keyAt(0)); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 235 | } |
| 236 | while (!mPlaybackThreads.isEmpty()) { |
Glenn Kasten | c3ae93f | 2012-07-30 10:59:30 -0700 | [diff] [blame] | 237 | // closeOutput_nonvirtual() will remove specified entry from mPlaybackThreads |
Glenn Kasten | d96c572 | 2012-04-25 13:44:49 -0700 | [diff] [blame] | 238 | closeOutput_nonvirtual(mPlaybackThreads.keyAt(0)); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 239 | } |
Andy Hung | b4946b6 | 2019-03-14 11:19:28 -0700 | [diff] [blame] | 240 | while (!mMmapThreads.isEmpty()) { |
| 241 | const audio_io_handle_t io = mMmapThreads.keyAt(0); |
| 242 | if (mMmapThreads.valueAt(0)->isOutput()) { |
| 243 | closeOutput_nonvirtual(io); // removes entry from mMmapThreads |
| 244 | } else { |
| 245 | closeInput_nonvirtual(io); // removes entry from mMmapThreads |
| 246 | } |
| 247 | } |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 248 | |
Glenn Kasten | 2b213bc | 2012-02-02 14:05:20 -0800 | [diff] [blame] | 249 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
| 250 | // no mHardwareLock needed, as there are no other references to this |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 251 | delete mAudioHwDevs.valueAt(i); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 252 | } |
Glenn Kasten | 481fb67 | 2013-09-30 14:39:28 -0700 | [diff] [blame] | 253 | |
| 254 | // Tell media.log service about any old writers that still need to be unregistered |
Glenn Kasten | 04b96fc | 2017-04-10 14:58:47 -0700 | [diff] [blame] | 255 | if (sMediaLogService != 0) { |
| 256 | for (size_t count = mUnregisteredWriters.size(); count > 0; count--) { |
| 257 | sp<IMemory> iMemory(mUnregisteredWriters.top()->getIMemory()); |
| 258 | mUnregisteredWriters.pop(); |
| 259 | sMediaLogService->unregisterWriter(iMemory); |
Glenn Kasten | 481fb67 | 2013-09-30 14:39:28 -0700 | [diff] [blame] | 260 | } |
| 261 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 264 | //static |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 265 | __attribute__ ((visibility ("default"))) |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 266 | status_t MmapStreamInterface::openMmapStream(MmapStreamInterface::stream_direction_t direction, |
| 267 | const audio_attributes_t *attr, |
| 268 | audio_config_base_t *config, |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 269 | const AudioClient& client, |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 270 | audio_port_handle_t *deviceId, |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 271 | audio_session_t *sessionId, |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 272 | const sp<MmapStreamCallback>& callback, |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 273 | sp<MmapStreamInterface>& interface, |
| 274 | audio_port_handle_t *handle) |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 275 | { |
| 276 | sp<AudioFlinger> af; |
| 277 | { |
| 278 | Mutex::Autolock _l(gLock); |
| 279 | af = gAudioFlinger.promote(); |
| 280 | } |
| 281 | status_t ret = NO_INIT; |
| 282 | if (af != 0) { |
| 283 | ret = af->openMmapStream( |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 284 | direction, attr, config, client, deviceId, |
| 285 | sessionId, callback, interface, handle); |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 286 | } |
| 287 | return ret; |
| 288 | } |
| 289 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 290 | status_t AudioFlinger::openMmapStream(MmapStreamInterface::stream_direction_t direction, |
| 291 | const audio_attributes_t *attr, |
| 292 | audio_config_base_t *config, |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 293 | const AudioClient& client, |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 294 | audio_port_handle_t *deviceId, |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 295 | audio_session_t *sessionId, |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 296 | const sp<MmapStreamCallback>& callback, |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 297 | sp<MmapStreamInterface>& interface, |
| 298 | audio_port_handle_t *handle) |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 299 | { |
| 300 | status_t ret = initCheck(); |
| 301 | if (ret != NO_ERROR) { |
| 302 | return ret; |
| 303 | } |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 304 | audio_session_t actualSessionId = *sessionId; |
| 305 | if (actualSessionId == AUDIO_SESSION_ALLOCATE) { |
| 306 | actualSessionId = (audio_session_t) newAudioUniqueId(AUDIO_UNIQUE_ID_USE_SESSION); |
| 307 | } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 308 | audio_stream_type_t streamType = AUDIO_STREAM_DEFAULT; |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 309 | audio_io_handle_t io = AUDIO_IO_HANDLE_NONE; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 310 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 311 | audio_attributes_t localAttr = *attr; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 312 | if (direction == MmapStreamInterface::DIRECTION_OUTPUT) { |
| 313 | audio_config_t fullConfig = AUDIO_CONFIG_INITIALIZER; |
| 314 | fullConfig.sample_rate = config->sample_rate; |
| 315 | fullConfig.channel_mask = config->channel_mask; |
| 316 | fullConfig.format = config->format; |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 317 | std::vector<audio_io_handle_t> secondaryOutputs; |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 318 | |
| 319 | ret = AudioSystem::getOutputForAttr(&localAttr, &io, |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 320 | actualSessionId, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 321 | &streamType, client.clientPid, client.clientUid, |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 322 | &fullConfig, |
Glenn Kasten | d3bb645 | 2016-12-05 18:14:37 -0800 | [diff] [blame] | 323 | (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_MMAP_NOIRQ | |
| 324 | AUDIO_OUTPUT_FLAG_DIRECT), |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 325 | deviceId, &portId, &secondaryOutputs); |
| 326 | ALOGW_IF(!secondaryOutputs.empty(), |
| 327 | "%s does not support secondary outputs, ignoring them", __func__); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 328 | } else { |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 329 | ret = AudioSystem::getInputForAttr(&localAttr, &io, |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 330 | RECORD_RIID_INVALID, |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 331 | actualSessionId, |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 332 | client.clientPid, |
| 333 | client.clientUid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 334 | client.packageName, |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 335 | config, |
Eric Laurent | 2ac7694 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 336 | AUDIO_INPUT_FLAG_MMAP_NOIRQ, deviceId, &portId); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 337 | } |
| 338 | if (ret != NO_ERROR) { |
| 339 | return ret; |
| 340 | } |
| 341 | |
| 342 | // at this stage, a MmapThread was created when openOutput() or openInput() was called by |
| 343 | // audio policy manager and we can retrieve it |
| 344 | sp<MmapThread> thread = mMmapThreads.valueFor(io); |
| 345 | if (thread != 0) { |
| 346 | interface = new MmapThreadHandle(thread); |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 347 | thread->configure(&localAttr, streamType, actualSessionId, callback, *deviceId, portId); |
Eric Laurent | cb4dae2 | 2017-07-01 19:39:32 -0700 | [diff] [blame] | 348 | *handle = portId; |
Phil Burk | 4e1af9f | 2018-01-03 15:54:35 -0800 | [diff] [blame] | 349 | *sessionId = actualSessionId; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 350 | } else { |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 351 | if (direction == MmapStreamInterface::DIRECTION_OUTPUT) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 352 | AudioSystem::releaseOutput(portId); |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 353 | } else { |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 354 | AudioSystem::releaseInput(portId); |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 355 | } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 356 | ret = NO_INIT; |
| 357 | } |
| 358 | |
| 359 | ALOGV("%s done status %d portId %d", __FUNCTION__, ret, portId); |
| 360 | |
Eric Laurent | fc23520 | 2016-12-20 18:48:17 -0800 | [diff] [blame] | 361 | return ret; |
| 362 | } |
| 363 | |
jiabin | 57303cc | 2018-12-18 15:45:57 -0800 | [diff] [blame] | 364 | /* static */ |
| 365 | int AudioFlinger::onExternalVibrationStart(const sp<os::ExternalVibration>& externalVibration) { |
| 366 | sp<os::IExternalVibratorService> evs = getExternalVibratorService(); |
| 367 | if (evs != 0) { |
| 368 | int32_t ret; |
| 369 | binder::Status status = evs->onExternalVibrationStart(*externalVibration, &ret); |
| 370 | if (status.isOk()) { |
| 371 | return ret; |
| 372 | } |
| 373 | } |
jiabin | bf6b0ec | 2019-02-12 12:30:12 -0800 | [diff] [blame] | 374 | return AudioMixer::HAPTIC_SCALE_MUTE; |
jiabin | 57303cc | 2018-12-18 15:45:57 -0800 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /* static */ |
| 378 | void AudioFlinger::onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration) { |
| 379 | sp<os::IExternalVibratorService> evs = getExternalVibratorService(); |
| 380 | if (evs != 0) { |
| 381 | evs->onExternalVibrationStop(*externalVibration); |
| 382 | } |
| 383 | } |
| 384 | |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 385 | static const char * const audio_interfaces[] = { |
| 386 | AUDIO_HARDWARE_MODULE_ID_PRIMARY, |
| 387 | AUDIO_HARDWARE_MODULE_ID_A2DP, |
| 388 | AUDIO_HARDWARE_MODULE_ID_USB, |
| 389 | }; |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 390 | |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 391 | AudioHwDevice* AudioFlinger::findSuitableHwDev_l( |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 392 | audio_module_handle_t module, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 393 | audio_devices_t deviceType) |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 394 | { |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 395 | // if module is 0, the request comes from an old policy manager and we should load |
| 396 | // well known modules |
| 397 | if (module == 0) { |
| 398 | ALOGW("findSuitableHwDev_l() loading well know audio hw modules"); |
Mikhail Naganov | bf49308 | 2017-04-17 17:37:12 -0700 | [diff] [blame] | 399 | for (size_t i = 0; i < arraysize(audio_interfaces); i++) { |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 400 | loadHwModule_l(audio_interfaces[i]); |
| 401 | } |
Eric Laurent | f1c04f9 | 2012-08-28 14:26:53 -0700 | [diff] [blame] | 402 | // then try to find a module supporting the requested device. |
| 403 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
| 404 | AudioHwDevice *audioHwDevice = mAudioHwDevs.valueAt(i); |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 405 | sp<DeviceHalInterface> dev = audioHwDevice->hwDevice(); |
| 406 | uint32_t supportedDevices; |
| 407 | if (dev->getSupportedDevices(&supportedDevices) == OK && |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 408 | (supportedDevices & deviceType) == deviceType) { |
Eric Laurent | f1c04f9 | 2012-08-28 14:26:53 -0700 | [diff] [blame] | 409 | return audioHwDevice; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 410 | } |
Eric Laurent | f1c04f9 | 2012-08-28 14:26:53 -0700 | [diff] [blame] | 411 | } |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 412 | } else { |
| 413 | // check a match for the requested module handle |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 414 | AudioHwDevice *audioHwDevice = mAudioHwDevs.valueFor(module); |
| 415 | if (audioHwDevice != NULL) { |
| 416 | return audioHwDevice; |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 417 | } |
| 418 | } |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 419 | |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 420 | return NULL; |
| 421 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 422 | |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 423 | void AudioFlinger::dumpClients(int fd, const Vector<String16>& args __unused) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 424 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 425 | String8 result; |
| 426 | |
| 427 | result.append("Clients:\n"); |
| 428 | for (size_t i = 0; i < mClients.size(); ++i) { |
Glenn Kasten | 77c1119 | 2012-01-25 14:27:41 -0800 | [diff] [blame] | 429 | sp<Client> client = mClients.valueAt(i).promote(); |
| 430 | if (client != 0) { |
Andy Hung | 5bdc535 | 2019-12-23 14:36:31 -0800 | [diff] [blame] | 431 | result.appendFormat(" pid: %d\n", client->pid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 432 | } |
| 433 | } |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 434 | |
Eric Laurent | d1b28d4 | 2013-09-18 18:47:13 -0700 | [diff] [blame] | 435 | result.append("Notification Clients:\n"); |
Andy Hung | 5bdc535 | 2019-12-23 14:36:31 -0800 | [diff] [blame] | 436 | result.append(" pid uid name\n"); |
Eric Laurent | d1b28d4 | 2013-09-18 18:47:13 -0700 | [diff] [blame] | 437 | for (size_t i = 0; i < mNotificationClients.size(); ++i) { |
Andy Hung | 5bdc535 | 2019-12-23 14:36:31 -0800 | [diff] [blame] | 438 | const pid_t pid = mNotificationClients[i]->getPid(); |
| 439 | const uid_t uid = mNotificationClients[i]->getUid(); |
| 440 | const mediautils::UidInfo::Info info = mUidInfo.getInfo(uid); |
| 441 | result.appendFormat("%6d %6u %s\n", pid, uid, info.package.c_str()); |
Eric Laurent | d1b28d4 | 2013-09-18 18:47:13 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 444 | result.append("Global session refs:\n"); |
Andy Hung | 5bdc535 | 2019-12-23 14:36:31 -0800 | [diff] [blame] | 445 | result.append(" session cnt pid\n"); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 446 | for (size_t i = 0; i < mAudioSessionRefs.size(); i++) { |
| 447 | AudioSessionRef *r = mAudioSessionRefs[i]; |
Andy Hung | 5bdc535 | 2019-12-23 14:36:31 -0800 | [diff] [blame] | 448 | result.appendFormat(" %7d %4d %7d\n", r->mSessionid, r->mCnt, r->mPid); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 449 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 450 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 454 | void AudioFlinger::dumpInternals(int fd, const Vector<String16>& args __unused) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 455 | { |
| 456 | const size_t SIZE = 256; |
| 457 | char buffer[SIZE]; |
| 458 | String8 result; |
Glenn Kasten | a4454b4 | 2012-01-04 11:02:33 -0800 | [diff] [blame] | 459 | hardware_call_state hardwareStatus = mHardwareStatus; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 460 | |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 461 | snprintf(buffer, SIZE, "Hardware status: %d\n" |
| 462 | "Standby Time mSec: %u\n", |
| 463 | hardwareStatus, |
| 464 | (uint32_t)(mStandbyTimeInNsecs / 1000000)); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 465 | result.append(buffer); |
| 466 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 469 | void AudioFlinger::dumpPermissionDenial(int fd, const Vector<String16>& args __unused) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 470 | { |
| 471 | const size_t SIZE = 256; |
| 472 | char buffer[SIZE]; |
| 473 | String8 result; |
| 474 | snprintf(buffer, SIZE, "Permission Denial: " |
| 475 | "can't dump AudioFlinger from pid=%d, uid=%d\n", |
| 476 | IPCThreadState::self()->getCallingPid(), |
| 477 | IPCThreadState::self()->getCallingUid()); |
| 478 | result.append(buffer); |
| 479 | write(fd, result.string(), result.size()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 482 | bool AudioFlinger::dumpTryLock(Mutex& mutex) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 483 | { |
Mikhail Naganov | 959e2d0 | 2019-03-28 11:08:19 -0700 | [diff] [blame] | 484 | status_t err = mutex.timedLock(kDumpLockTimeoutNs); |
| 485 | return err == NO_ERROR; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | status_t AudioFlinger::dump(int fd, const Vector<String16>& args) |
| 489 | { |
Glenn Kasten | 44deb05 | 2012-02-05 18:09:08 -0800 | [diff] [blame] | 490 | if (!dumpAllowed()) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 491 | dumpPermissionDenial(fd, args); |
| 492 | } else { |
| 493 | // get state of hardware lock |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 494 | bool hardwareLocked = dumpTryLock(mHardwareLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 495 | if (!hardwareLocked) { |
| 496 | String8 result(kHardwareLockedString); |
| 497 | write(fd, result.string(), result.size()); |
| 498 | } else { |
| 499 | mHardwareLock.unlock(); |
| 500 | } |
| 501 | |
Eric Tan | 7b65115 | 2018-07-13 10:17:19 -0700 | [diff] [blame] | 502 | const bool locked = dumpTryLock(mLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 503 | |
| 504 | // failed to lock - AudioFlinger is probably deadlocked |
| 505 | if (!locked) { |
| 506 | String8 result(kDeadlockedString); |
| 507 | write(fd, result.string(), result.size()); |
| 508 | } |
| 509 | |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 510 | bool clientLocked = dumpTryLock(mClientLock); |
| 511 | if (!clientLocked) { |
| 512 | String8 result(kClientLockedString); |
| 513 | write(fd, result.string(), result.size()); |
| 514 | } |
Marco Nelissen | d89eadd | 2014-10-07 13:28:44 -0700 | [diff] [blame] | 515 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 516 | if (mEffectsFactoryHal != 0) { |
Mikhail Naganov | 4a3d5c2 | 2016-08-15 13:47:42 -0700 | [diff] [blame] | 517 | mEffectsFactoryHal->dumpEffects(fd); |
| 518 | } else { |
| 519 | String8 result(kNoEffectsFactory); |
| 520 | write(fd, result.string(), result.size()); |
| 521 | } |
Marco Nelissen | d89eadd | 2014-10-07 13:28:44 -0700 | [diff] [blame] | 522 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 523 | dumpClients(fd, args); |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 524 | if (clientLocked) { |
| 525 | mClientLock.unlock(); |
| 526 | } |
| 527 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 528 | dumpInternals(fd, args); |
| 529 | |
| 530 | // dump playback threads |
| 531 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 532 | mPlaybackThreads.valueAt(i)->dump(fd, args); |
| 533 | } |
| 534 | |
| 535 | // dump record threads |
| 536 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
| 537 | mRecordThreads.valueAt(i)->dump(fd, args); |
| 538 | } |
| 539 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 540 | // dump mmap threads |
| 541 | for (size_t i = 0; i < mMmapThreads.size(); i++) { |
| 542 | mMmapThreads.valueAt(i)->dump(fd, args); |
| 543 | } |
| 544 | |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 545 | // dump orphan effect chains |
| 546 | if (mOrphanEffectChains.size() != 0) { |
| 547 | write(fd, " Orphan Effect Chains\n", strlen(" Orphan Effect Chains\n")); |
| 548 | for (size_t i = 0; i < mOrphanEffectChains.size(); i++) { |
| 549 | mOrphanEffectChains.valueAt(i)->dump(fd, args); |
| 550 | } |
| 551 | } |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 552 | // dump all hardware devs |
| 553 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 554 | sp<DeviceHalInterface> dev = mAudioHwDevs.valueAt(i)->hwDevice(); |
| 555 | dev->dump(fd); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 556 | } |
Glenn Kasten | d06785b | 2012-09-30 12:29:28 -0700 | [diff] [blame] | 557 | |
Mikhail Naganov | 201369b | 2018-05-16 16:52:32 -0700 | [diff] [blame] | 558 | mPatchPanel.dump(fd); |
| 559 | |
Kevin Rocard | a0a5d2a | 2018-08-06 15:03:18 -0700 | [diff] [blame] | 560 | // dump external setParameters |
| 561 | auto dumpLogger = [fd](SimpleLog& logger, const char* name) { |
| 562 | dprintf(fd, "\n%s setParameters:\n", name); |
| 563 | logger.dump(fd, " " /* prefix */); |
| 564 | }; |
| 565 | dumpLogger(mRejectedSetParameterLog, "Rejected"); |
| 566 | dumpLogger(mAppSetParameterLog, "App"); |
| 567 | dumpLogger(mSystemSetParameterLog, "System"); |
| 568 | |
Andy Hung | a8115dc | 2018-08-24 15:51:59 -0700 | [diff] [blame] | 569 | // dump historical threads in the last 10 seconds |
| 570 | const std::string threadLog = mThreadLog.dumpToString( |
| 571 | "Historical Thread Log ", 0 /* lines */, |
| 572 | audio_utils_get_real_time_ns() - 10 * 60 * NANOS_PER_SECOND); |
| 573 | write(fd, threadLog.c_str(), threadLog.size()); |
| 574 | |
rago | 3bd1c87 | 2016-09-26 12:58:14 -0700 | [diff] [blame] | 575 | BUFLOG_RESET; |
| 576 | |
Glenn Kasten | d65d73c | 2012-06-22 17:21:07 -0700 | [diff] [blame] | 577 | if (locked) { |
| 578 | mLock.unlock(); |
| 579 | } |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 580 | |
Andy Hung | 8946a28 | 2018-04-19 20:04:56 -0700 | [diff] [blame] | 581 | #ifdef TEE_SINK |
| 582 | // NBAIO_Tee dump is safe to call outside of AF lock. |
| 583 | NBAIO_Tee::dumpAll(fd, "_DUMP"); |
| 584 | #endif |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 585 | // append a copy of media.log here by forwarding fd to it, but don't attempt |
| 586 | // to lookup the service if it's not running, as it will block for a second |
Glenn Kasten | 04b96fc | 2017-04-10 14:58:47 -0700 | [diff] [blame] | 587 | if (sMediaLogServiceAsBinder != 0) { |
| 588 | dprintf(fd, "\nmedia.log:\n"); |
| 589 | Vector<String16> args; |
| 590 | sMediaLogServiceAsBinder->dump(fd, args); |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 591 | } |
Andy Hung | 35fec5f | 2016-04-13 14:21:48 -0700 | [diff] [blame] | 592 | |
| 593 | // check for optional arguments |
Andy Hung | 07b745e | 2016-05-23 16:21:07 -0700 | [diff] [blame] | 594 | bool dumpMem = false; |
Andy Hung | 35fec5f | 2016-04-13 14:21:48 -0700 | [diff] [blame] | 595 | bool unreachableMemory = false; |
| 596 | for (const auto &arg : args) { |
Andy Hung | 07b745e | 2016-05-23 16:21:07 -0700 | [diff] [blame] | 597 | if (arg == String16("-m")) { |
| 598 | dumpMem = true; |
| 599 | } else if (arg == String16("--unreachable")) { |
Andy Hung | 35fec5f | 2016-04-13 14:21:48 -0700 | [diff] [blame] | 600 | unreachableMemory = true; |
| 601 | } |
| 602 | } |
| 603 | |
Andy Hung | 07b745e | 2016-05-23 16:21:07 -0700 | [diff] [blame] | 604 | if (dumpMem) { |
| 605 | dprintf(fd, "\nDumping memory:\n"); |
| 606 | std::string s = dumpMemoryAddresses(100 /* limit */); |
| 607 | write(fd, s.c_str(), s.size()); |
| 608 | } |
Andy Hung | 35fec5f | 2016-04-13 14:21:48 -0700 | [diff] [blame] | 609 | if (unreachableMemory) { |
| 610 | dprintf(fd, "\nDumping unreachable memory:\n"); |
| 611 | // TODO - should limit be an argument parameter? |
Andy Hung | 07b745e | 2016-05-23 16:21:07 -0700 | [diff] [blame] | 612 | std::string s = GetUnreachableMemoryString(true /* contents */, 100 /* limit */); |
Andy Hung | 35fec5f | 2016-04-13 14:21:48 -0700 | [diff] [blame] | 613 | write(fd, s.c_str(), s.size()); |
| 614 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 615 | } |
| 616 | return NO_ERROR; |
| 617 | } |
| 618 | |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 619 | sp<AudioFlinger::Client> AudioFlinger::registerPid(pid_t pid) |
Glenn Kasten | 98ec94c | 2012-01-25 14:28:29 -0800 | [diff] [blame] | 620 | { |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 621 | Mutex::Autolock _cl(mClientLock); |
Glenn Kasten | 98ec94c | 2012-01-25 14:28:29 -0800 | [diff] [blame] | 622 | // If pid is already in the mClients wp<> map, then use that entry |
| 623 | // (for which promote() is always != 0), otherwise create a new entry and Client. |
| 624 | sp<Client> client = mClients.valueFor(pid).promote(); |
| 625 | if (client == 0) { |
| 626 | client = new Client(this, pid); |
| 627 | mClients.add(pid, client); |
| 628 | } |
| 629 | |
| 630 | return client; |
| 631 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 632 | |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 633 | sp<NBLog::Writer> AudioFlinger::newWriter_l(size_t size, const char *name) |
| 634 | { |
Glenn Kasten | 04b96fc | 2017-04-10 14:58:47 -0700 | [diff] [blame] | 635 | // If there is no memory allocated for logs, return a dummy writer that does nothing. |
| 636 | // Similarly if we can't contact the media.log service, also return a dummy writer. |
| 637 | if (mLogMemoryDealer == 0 || sMediaLogService == 0) { |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 638 | return new NBLog::Writer(); |
| 639 | } |
Glenn Kasten | 481fb67 | 2013-09-30 14:39:28 -0700 | [diff] [blame] | 640 | sp<IMemory> shared = mLogMemoryDealer->allocate(NBLog::Timeline::sharedSize(size)); |
| 641 | // If allocation fails, consult the vector of previously unregistered writers |
| 642 | // and garbage-collect one or more them until an allocation succeeds |
| 643 | if (shared == 0) { |
| 644 | Mutex::Autolock _l(mUnregisteredWritersLock); |
| 645 | for (size_t count = mUnregisteredWriters.size(); count > 0; count--) { |
| 646 | { |
| 647 | // Pick the oldest stale writer to garbage-collect |
| 648 | sp<IMemory> iMemory(mUnregisteredWriters[0]->getIMemory()); |
| 649 | mUnregisteredWriters.removeAt(0); |
Glenn Kasten | 04b96fc | 2017-04-10 14:58:47 -0700 | [diff] [blame] | 650 | sMediaLogService->unregisterWriter(iMemory); |
Glenn Kasten | 481fb67 | 2013-09-30 14:39:28 -0700 | [diff] [blame] | 651 | // Now the media.log remote reference to IMemory is gone. When our last local |
| 652 | // reference to IMemory also drops to zero at end of this block, |
| 653 | // the IMemory destructor will deallocate the region from mLogMemoryDealer. |
| 654 | } |
| 655 | // Re-attempt the allocation |
| 656 | shared = mLogMemoryDealer->allocate(NBLog::Timeline::sharedSize(size)); |
| 657 | if (shared != 0) { |
| 658 | goto success; |
| 659 | } |
| 660 | } |
| 661 | // Even after garbage-collecting all old writers, there is still not enough memory, |
| 662 | // so return a dummy writer |
| 663 | return new NBLog::Writer(); |
| 664 | } |
| 665 | success: |
Ytai Ben-Tsvi | 7dd3972 | 2019-09-05 15:14:30 -0700 | [diff] [blame] | 666 | NBLog::Shared *sharedRawPtr = (NBLog::Shared *) shared->unsecurePointer(); |
Glenn Kasten | 535e161 | 2016-12-05 12:19:36 -0800 | [diff] [blame] | 667 | new((void *) sharedRawPtr) NBLog::Shared(); // placement new here, but the corresponding |
| 668 | // explicit destructor not needed since it is POD |
Glenn Kasten | 04b96fc | 2017-04-10 14:58:47 -0700 | [diff] [blame] | 669 | sMediaLogService->registerWriter(shared, size, name); |
Glenn Kasten | 535e161 | 2016-12-05 12:19:36 -0800 | [diff] [blame] | 670 | return new NBLog::Writer(shared, size); |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | void AudioFlinger::unregisterWriter(const sp<NBLog::Writer>& writer) |
| 674 | { |
Glenn Kasten | 685ef09 | 2013-02-04 08:15:34 -0800 | [diff] [blame] | 675 | if (writer == 0) { |
| 676 | return; |
| 677 | } |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 678 | sp<IMemory> iMemory(writer->getIMemory()); |
| 679 | if (iMemory == 0) { |
| 680 | return; |
| 681 | } |
Glenn Kasten | 481fb67 | 2013-09-30 14:39:28 -0700 | [diff] [blame] | 682 | // Rather than removing the writer immediately, append it to a queue of old writers to |
| 683 | // be garbage-collected later. This allows us to continue to view old logs for a while. |
| 684 | Mutex::Autolock _l(mUnregisteredWritersLock); |
| 685 | mUnregisteredWriters.push(writer); |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 686 | } |
| 687 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 688 | // IAudioFlinger interface |
| 689 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 690 | sp<IAudioTrack> AudioFlinger::createTrack(const CreateTrackInput& input, |
| 691 | CreateTrackOutput& output, |
| 692 | status_t *status) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 693 | { |
| 694 | sp<PlaybackThread::Track> track; |
| 695 | sp<TrackHandle> trackHandle; |
| 696 | sp<Client> client; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 697 | status_t lStatus; |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 698 | audio_stream_type_t streamType; |
Eric Laurent | 77881cd | 2018-02-09 16:01:31 -0800 | [diff] [blame] | 699 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 700 | std::vector<audio_io_handle_t> secondaryOutputs; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 701 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 702 | bool updatePid = (input.clientInfo.clientPid == -1); |
Haynes Mathew George | 9ea77cd | 2016-04-06 17:07:48 -0700 | [diff] [blame] | 703 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 704 | uid_t clientUid = input.clientInfo.clientUid; |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 705 | audio_io_handle_t effectThreadId = AUDIO_IO_HANDLE_NONE; |
| 706 | std::vector<int> effectIds; |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 707 | audio_attributes_t localAttr = input.attr; |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 708 | |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 709 | if (!isAudioServerOrMediaServerUid(callingUid)) { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 710 | ALOGW_IF(clientUid != callingUid, |
| 711 | "%s uid %d tried to pass itself off as %d", |
| 712 | __FUNCTION__, callingUid, clientUid); |
| 713 | clientUid = callingUid; |
| 714 | updatePid = true; |
| 715 | } |
| 716 | pid_t clientPid = input.clientInfo.clientPid; |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 717 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 718 | if (updatePid) { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 719 | ALOGW_IF(clientPid != -1 && clientPid != callingPid, |
Haynes Mathew George | 9ea77cd | 2016-04-06 17:07:48 -0700 | [diff] [blame] | 720 | "%s uid %d pid %d tried to pass itself off as pid %d", |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 721 | __func__, callingUid, callingPid, clientPid); |
| 722 | clientPid = callingPid; |
Haynes Mathew George | 9ea77cd | 2016-04-06 17:07:48 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 725 | audio_session_t sessionId = input.sessionId; |
| 726 | if (sessionId == AUDIO_SESSION_ALLOCATE) { |
| 727 | sessionId = (audio_session_t) newAudioUniqueId(AUDIO_UNIQUE_ID_USE_SESSION); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 728 | } else if (audio_unique_id_get_use(sessionId) != AUDIO_UNIQUE_ID_USE_SESSION) { |
| 729 | lStatus = BAD_VALUE; |
| 730 | goto Exit; |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 731 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 732 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 733 | output.sessionId = sessionId; |
| 734 | output.outputId = AUDIO_IO_HANDLE_NONE; |
| 735 | output.selectedDeviceId = input.selectedDeviceId; |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 736 | lStatus = AudioSystem::getOutputForAttr(&localAttr, &output.outputId, sessionId, &streamType, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 737 | clientPid, clientUid, &input.config, input.flags, |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 738 | &output.selectedDeviceId, &portId, &secondaryOutputs); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 739 | |
| 740 | if (lStatus != NO_ERROR || output.outputId == AUDIO_IO_HANDLE_NONE) { |
| 741 | ALOGE("createTrack() getOutputForAttr() return error %d or invalid output handle", lStatus); |
| 742 | goto Exit; |
| 743 | } |
Glenn Kasten | 263709e | 2012-01-06 08:40:01 -0800 | [diff] [blame] | 744 | // client AudioTrack::set already implements AUDIO_STREAM_DEFAULT => AUDIO_STREAM_MUSIC, |
| 745 | // but if someone uses binder directly they could bypass that and cause us to crash |
| 746 | if (uint32_t(streamType) >= AUDIO_STREAM_CNT) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 747 | ALOGE("createTrack() invalid stream type %d", streamType); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 748 | lStatus = BAD_VALUE; |
| 749 | goto Exit; |
| 750 | } |
| 751 | |
Glenn Kasten | 53b5d09 | 2014-02-05 10:00:23 -0800 | [diff] [blame] | 752 | // further channel mask checks are performed by createTrack_l() depending on the thread type |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 753 | if (!audio_is_output_channel(input.config.channel_mask)) { |
| 754 | ALOGE("createTrack() invalid channel mask %#x", input.config.channel_mask); |
Glenn Kasten | 53b5d09 | 2014-02-05 10:00:23 -0800 | [diff] [blame] | 755 | lStatus = BAD_VALUE; |
| 756 | goto Exit; |
| 757 | } |
| 758 | |
Glenn Kasten | c4b88a8 | 2014-04-30 16:54:30 -0700 | [diff] [blame] | 759 | // further format checks are performed by createTrack_l() depending on the thread type |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 760 | if (!audio_is_valid_format(input.config.format)) { |
| 761 | ALOGE("createTrack() invalid format %#x", input.config.format); |
Glenn Kasten | 663c224 | 2013-09-24 11:52:37 -0700 | [diff] [blame] | 762 | lStatus = BAD_VALUE; |
| 763 | goto Exit; |
| 764 | } |
| 765 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 766 | { |
| 767 | Mutex::Autolock _l(mLock); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 768 | PlaybackThread *thread = checkPlaybackThread_l(output.outputId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 769 | if (thread == NULL) { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 770 | ALOGE("no playback thread found for output handle %d", output.outputId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 771 | lStatus = BAD_VALUE; |
| 772 | goto Exit; |
| 773 | } |
| 774 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 775 | client = registerPid(clientPid); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 776 | |
Glenn Kasten | e848bd9 | 2014-03-13 15:00:32 -0700 | [diff] [blame] | 777 | PlaybackThread *effectThread = NULL; |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 778 | // check if an effect chain with the same session ID is present on another |
| 779 | // output thread and move it here. |
| 780 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 781 | sp<PlaybackThread> t = mPlaybackThreads.valueAt(i); |
| 782 | if (mPlaybackThreads.keyAt(i) != output.outputId) { |
| 783 | uint32_t sessions = t->hasAudioSession(sessionId); |
| 784 | if (sessions & ThreadBase::EFFECT_SESSION) { |
| 785 | effectThread = t.get(); |
| 786 | break; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 789 | } |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 790 | ALOGV("createTrack() sessionId: %d", sessionId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 791 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 792 | output.sampleRate = input.config.sample_rate; |
| 793 | output.frameCount = input.frameCount; |
| 794 | output.notificationFrameCount = input.notificationFrameCount; |
| 795 | output.flags = input.flags; |
| 796 | |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 797 | track = thread->createTrack_l(client, streamType, localAttr, &output.sampleRate, |
Kevin Rocard | 1f564ac | 2018-03-29 13:53:10 -0700 | [diff] [blame] | 798 | input.config.format, input.config.channel_mask, |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 799 | &output.frameCount, &output.notificationFrameCount, |
| 800 | input.notificationsPerBuffer, input.speed, |
| 801 | input.sharedBuffer, sessionId, &output.flags, |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 802 | callingPid, input.clientInfo.clientTid, clientUid, |
| 803 | &lStatus, portId); |
Haynes Mathew George | 03e9e83 | 2013-12-13 15:40:13 -0800 | [diff] [blame] | 804 | LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (track == 0)); |
Glenn Kasten | 2fc1473 | 2013-08-05 14:58:14 -0700 | [diff] [blame] | 805 | // we don't abort yet if lStatus != NO_ERROR; there is still work to be done regardless |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 806 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 807 | output.afFrameCount = thread->frameCount(); |
| 808 | output.afSampleRate = thread->sampleRate(); |
| 809 | output.afLatencyMs = thread->latency(); |
Eric Laurent | 973db02 | 2018-11-20 14:54:31 -0800 | [diff] [blame] | 810 | output.portId = portId; |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 811 | |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 812 | if (lStatus == NO_ERROR) { |
| 813 | // Connect secondary outputs. Failure on a secondary output must not imped the primary |
| 814 | // Any secondary output setup failure will lead to a desync between the AP and AF until |
| 815 | // the track is destroyed. |
| 816 | TeePatches teePatches; |
| 817 | for (audio_io_handle_t secondaryOutput : secondaryOutputs) { |
| 818 | PlaybackThread *secondaryThread = checkPlaybackThread_l(secondaryOutput); |
| 819 | if (secondaryThread == NULL) { |
| 820 | ALOGE("no playback thread found for secondary output %d", output.outputId); |
| 821 | continue; |
| 822 | } |
| 823 | |
Kevin Rocard | 01c7d9e | 2019-09-18 11:24:52 +0100 | [diff] [blame] | 824 | size_t sourceFrameCount = thread->frameCount() * output.sampleRate |
| 825 | / thread->sampleRate(); |
| 826 | size_t sinkFrameCount = secondaryThread->frameCount() * output.sampleRate |
| 827 | / secondaryThread->sampleRate(); |
| 828 | // If the secondary output has just been opened, the first secondaryThread write |
| 829 | // will not block as it will fill the empty startup buffer of the HAL, |
| 830 | // so a second sink buffer needs to be ready for the immediate next blocking write. |
| 831 | // Additionally, have a margin of one main thread buffer as the scheduling jitter |
| 832 | // can reorder the writes (eg if thread A&B have the same write intervale, |
| 833 | // the scheduler could schedule AB...BA) |
| 834 | size_t frameCountToBeReady = 2 * sinkFrameCount + sourceFrameCount; |
| 835 | // Total secondary output buffer must be at least as the read frames plus |
| 836 | // the margin of a few buffers on both sides in case the |
| 837 | // threads scheduling has some jitter. |
| 838 | // That value should not impact latency as the secondary track is started before |
| 839 | // its buffer is full, see frameCountToBeReady. |
| 840 | size_t frameCount = frameCountToBeReady + 2 * (sourceFrameCount + sinkFrameCount); |
| 841 | // The frameCount should also not be smaller than the secondary thread min frame |
| 842 | // count |
| 843 | size_t minFrameCount = AudioSystem::calculateMinFrameCount( |
| 844 | [&] { Mutex::Autolock _l(secondaryThread->mLock); |
| 845 | return secondaryThread->latency_l(); }(), |
| 846 | secondaryThread->mNormalFrameCount, |
| 847 | secondaryThread->mSampleRate, |
| 848 | output.sampleRate, |
| 849 | input.speed); |
| 850 | frameCount = std::max(frameCount, minFrameCount); |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 851 | |
| 852 | using namespace std::chrono_literals; |
| 853 | auto inChannelMask = audio_channel_mask_out_to_in(input.config.channel_mask); |
| 854 | sp patchRecord = new RecordThread::PatchRecord(nullptr /* thread */, |
| 855 | output.sampleRate, |
| 856 | inChannelMask, |
| 857 | input.config.format, |
| 858 | frameCount, |
| 859 | NULL /* buffer */, |
| 860 | (size_t)0 /* bufferSize */, |
| 861 | AUDIO_INPUT_FLAG_DIRECT, |
| 862 | 0ns /* timeout */); |
| 863 | status_t status = patchRecord->initCheck(); |
| 864 | if (status != NO_ERROR) { |
| 865 | ALOGE("Secondary output patchRecord init failed: %d", status); |
| 866 | continue; |
| 867 | } |
Andy Hung | ae22b48 | 2019-05-09 15:38:55 -0700 | [diff] [blame] | 868 | |
| 869 | // TODO: We could check compatibility of the secondaryThread with the PatchTrack |
| 870 | // for fast usage: thread has fast mixer, sample rate matches, etc.; |
| 871 | // for now, we exclude fast tracks by removing the Fast flag. |
| 872 | const audio_output_flags_t outputFlags = |
| 873 | (audio_output_flags_t)(output.flags & ~AUDIO_OUTPUT_FLAG_FAST); |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 874 | sp patchTrack = new PlaybackThread::PatchTrack(secondaryThread, |
| 875 | streamType, |
| 876 | output.sampleRate, |
| 877 | input.config.channel_mask, |
| 878 | input.config.format, |
| 879 | frameCount, |
| 880 | patchRecord->buffer(), |
| 881 | patchRecord->bufferSize(), |
Andy Hung | ae22b48 | 2019-05-09 15:38:55 -0700 | [diff] [blame] | 882 | outputFlags, |
Kevin Rocard | 01c7d9e | 2019-09-18 11:24:52 +0100 | [diff] [blame] | 883 | 0ns /* timeout */, |
| 884 | frameCountToBeReady); |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 885 | status = patchTrack->initCheck(); |
| 886 | if (status != NO_ERROR) { |
| 887 | ALOGE("Secondary output patchTrack init failed: %d", status); |
| 888 | continue; |
| 889 | } |
| 890 | teePatches.push_back({patchRecord, patchTrack}); |
| 891 | secondaryThread->addPatchTrack(patchTrack); |
Andy Hung | abfab20 | 2019-03-07 19:45:54 -0800 | [diff] [blame] | 892 | // In case the downstream patchTrack on the secondaryThread temporarily outlives |
| 893 | // our created track, ensure the corresponding patchRecord is still alive. |
| 894 | patchTrack->setPeerProxy(patchRecord, true /* holdReference */); |
| 895 | patchRecord->setPeerProxy(patchTrack, false /* holdReference */); |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 896 | } |
| 897 | track->setTeePatches(std::move(teePatches)); |
| 898 | } |
| 899 | |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 900 | // move effect chain to this output thread if an effect on same session was waiting |
| 901 | // for a track to be created |
| 902 | if (lStatus == NO_ERROR && effectThread != NULL) { |
Glenn Kasten | 2fc1473 | 2013-08-05 14:58:14 -0700 | [diff] [blame] | 903 | // no risk of deadlock because AudioFlinger::mLock is held |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 904 | Mutex::Autolock _dl(thread->mLock); |
| 905 | Mutex::Autolock _sl(effectThread->mLock); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 906 | if (moveEffectChain_l(sessionId, effectThread, thread) == NO_ERROR) { |
| 907 | effectThreadId = thread->id(); |
| 908 | effectIds = thread->getEffectIds_l(sessionId); |
| 909 | } |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 910 | } |
Eric Laurent | a011e35 | 2012-03-29 15:51:43 -0700 | [diff] [blame] | 911 | |
| 912 | // Look for sync events awaiting for a session to be used. |
Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 913 | for (size_t i = 0; i < mPendingSyncEvents.size(); i++) { |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 914 | if (mPendingSyncEvents[i]->triggerSession() == sessionId) { |
Eric Laurent | a011e35 | 2012-03-29 15:51:43 -0700 | [diff] [blame] | 915 | if (thread->isValidSyncEvent(mPendingSyncEvents[i])) { |
Eric Laurent | 2986460 | 2012-05-08 18:57:51 -0700 | [diff] [blame] | 916 | if (lStatus == NO_ERROR) { |
Glenn Kasten | d23eedc | 2012-08-02 13:35:47 -0700 | [diff] [blame] | 917 | (void) track->setSyncEvent(mPendingSyncEvents[i]); |
Eric Laurent | 2986460 | 2012-05-08 18:57:51 -0700 | [diff] [blame] | 918 | } else { |
| 919 | mPendingSyncEvents[i]->cancel(); |
| 920 | } |
Eric Laurent | a011e35 | 2012-03-29 15:51:43 -0700 | [diff] [blame] | 921 | mPendingSyncEvents.removeAt(i); |
| 922 | i--; |
| 923 | } |
| 924 | } |
| 925 | } |
Glenn Kasten | e198c36 | 2013-08-13 09:13:36 -0700 | [diff] [blame] | 926 | |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 927 | setAudioHwSyncForSession_l(thread, sessionId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 928 | } |
Glenn Kasten | e198c36 | 2013-08-13 09:13:36 -0700 | [diff] [blame] | 929 | |
Glenn Kasten | 3ef14ef | 2014-03-13 15:08:51 -0700 | [diff] [blame] | 930 | if (lStatus != NO_ERROR) { |
| 931 | // remove local strong reference to Client before deleting the Track so that the |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 932 | // Client destructor is called by the TrackBase destructor with mClientLock held |
Eric Laurent | fe1a94e | 2014-05-26 16:03:08 -0700 | [diff] [blame] | 933 | // Don't hold mClientLock when releasing the reference on the track as the |
| 934 | // destructor will acquire it. |
| 935 | { |
| 936 | Mutex::Autolock _cl(mClientLock); |
| 937 | client.clear(); |
| 938 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 939 | track.clear(); |
Glenn Kasten | 3ef14ef | 2014-03-13 15:08:51 -0700 | [diff] [blame] | 940 | goto Exit; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 943 | // effectThreadId is not NONE if an effect chain corresponding to the track session |
| 944 | // was found on another thread and must be moved on this thread |
| 945 | if (effectThreadId != AUDIO_IO_HANDLE_NONE) { |
| 946 | AudioSystem::moveEffectsToIo(effectIds, effectThreadId); |
| 947 | } |
| 948 | |
Glenn Kasten | 3ef14ef | 2014-03-13 15:08:51 -0700 | [diff] [blame] | 949 | // return handle to client |
| 950 | trackHandle = new TrackHandle(track); |
| 951 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 952 | Exit: |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 953 | if (lStatus != NO_ERROR && output.outputId != AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 954 | AudioSystem::releaseOutput(portId); |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 955 | } |
Glenn Kasten | 9156ef3 | 2013-08-06 15:39:08 -0700 | [diff] [blame] | 956 | *status = lStatus; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 957 | return trackHandle; |
| 958 | } |
| 959 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 960 | uint32_t AudioFlinger::sampleRate(audio_io_handle_t ioHandle) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 961 | { |
| 962 | Mutex::Autolock _l(mLock); |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 963 | ThreadBase *thread = checkThread_l(ioHandle); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 964 | if (thread == NULL) { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 965 | ALOGW("sampleRate() unknown thread %d", ioHandle); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 966 | return 0; |
| 967 | } |
| 968 | return thread->sampleRate(); |
| 969 | } |
| 970 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 971 | audio_format_t AudioFlinger::format(audio_io_handle_t output) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 972 | { |
| 973 | Mutex::Autolock _l(mLock); |
| 974 | PlaybackThread *thread = checkPlaybackThread_l(output); |
| 975 | if (thread == NULL) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 976 | ALOGW("format() unknown thread %d", output); |
Glenn Kasten | 58f3021 | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 977 | return AUDIO_FORMAT_INVALID; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 978 | } |
| 979 | return thread->format(); |
| 980 | } |
| 981 | |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 982 | size_t AudioFlinger::frameCount(audio_io_handle_t ioHandle) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 983 | { |
| 984 | Mutex::Autolock _l(mLock); |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 985 | ThreadBase *thread = checkThread_l(ioHandle); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 986 | if (thread == NULL) { |
Glenn Kasten | 2c073da | 2016-02-26 09:14:08 -0800 | [diff] [blame] | 987 | ALOGW("frameCount() unknown thread %d", ioHandle); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 988 | return 0; |
| 989 | } |
Glenn Kasten | 5891256 | 2012-04-03 10:45:00 -0700 | [diff] [blame] | 990 | // FIXME currently returns the normal mixer's frame count to avoid confusing legacy callers; |
| 991 | // should examine all callers and fix them to handle smaller counts |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 992 | return thread->frameCount(); |
| 993 | } |
| 994 | |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 995 | size_t AudioFlinger::frameCountHAL(audio_io_handle_t ioHandle) const |
| 996 | { |
| 997 | Mutex::Autolock _l(mLock); |
| 998 | ThreadBase *thread = checkThread_l(ioHandle); |
| 999 | if (thread == NULL) { |
| 1000 | ALOGW("frameCountHAL() unknown thread %d", ioHandle); |
| 1001 | return 0; |
| 1002 | } |
| 1003 | return thread->frameCountHAL(); |
| 1004 | } |
| 1005 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1006 | uint32_t AudioFlinger::latency(audio_io_handle_t output) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1007 | { |
| 1008 | Mutex::Autolock _l(mLock); |
| 1009 | PlaybackThread *thread = checkPlaybackThread_l(output); |
| 1010 | if (thread == NULL) { |
Glenn Kasten | c9b2e20 | 2013-02-26 11:32:32 -0800 | [diff] [blame] | 1011 | ALOGW("latency(): no playback thread found for output handle %d", output); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1012 | return 0; |
| 1013 | } |
| 1014 | return thread->latency(); |
| 1015 | } |
| 1016 | |
| 1017 | status_t AudioFlinger::setMasterVolume(float value) |
| 1018 | { |
Eric Laurent | a1884f9 | 2011-08-23 08:25:03 -0700 | [diff] [blame] | 1019 | status_t ret = initCheck(); |
| 1020 | if (ret != NO_ERROR) { |
| 1021 | return ret; |
| 1022 | } |
| 1023 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1024 | // check calling permissions |
| 1025 | if (!settingsAllowed()) { |
| 1026 | return PERMISSION_DENIED; |
| 1027 | } |
| 1028 | |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1029 | Mutex::Autolock _l(mLock); |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1030 | mMasterVolume = value; |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1031 | |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1032 | // Set master volume in the HALs which support it. |
| 1033 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
| 1034 | AutoMutex lock(mHardwareLock); |
| 1035 | AudioHwDevice *dev = mAudioHwDevs.valueAt(i); |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 1036 | |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1037 | mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME; |
| 1038 | if (dev->canSetMasterVolume()) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1039 | dev->hwDevice()->setMasterVolume(value); |
Eric Laurent | 9357520 | 2011-01-18 18:39:02 -0800 | [diff] [blame] | 1040 | } |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1041 | mHardwareStatus = AUDIO_HW_IDLE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1042 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1043 | |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1044 | // Now set the master volume in each playback thread. Playback threads |
| 1045 | // assigned to HALs which do not have master volume support will apply |
| 1046 | // master volume during the mix operation. Threads with HALs which do |
| 1047 | // support master volume will simply ignore the setting. |
Eric Laurent | f6870ae | 2015-05-08 10:50:03 -0700 | [diff] [blame] | 1048 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 1049 | if (mPlaybackThreads.valueAt(i)->isDuplicating()) { |
| 1050 | continue; |
| 1051 | } |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1052 | mPlaybackThreads.valueAt(i)->setMasterVolume(value); |
Eric Laurent | f6870ae | 2015-05-08 10:50:03 -0700 | [diff] [blame] | 1053 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1054 | |
| 1055 | return NO_ERROR; |
| 1056 | } |
| 1057 | |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1058 | status_t AudioFlinger::setMasterBalance(float balance) |
| 1059 | { |
| 1060 | status_t ret = initCheck(); |
| 1061 | if (ret != NO_ERROR) { |
| 1062 | return ret; |
| 1063 | } |
| 1064 | |
| 1065 | // check calling permissions |
| 1066 | if (!settingsAllowed()) { |
| 1067 | return PERMISSION_DENIED; |
| 1068 | } |
| 1069 | |
| 1070 | // check range |
| 1071 | if (isnan(balance) || fabs(balance) > 1.f) { |
| 1072 | return BAD_VALUE; |
| 1073 | } |
| 1074 | |
| 1075 | Mutex::Autolock _l(mLock); |
| 1076 | |
| 1077 | // short cut. |
| 1078 | if (mMasterBalance == balance) return NO_ERROR; |
| 1079 | |
| 1080 | mMasterBalance = balance; |
| 1081 | |
| 1082 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 1083 | if (mPlaybackThreads.valueAt(i)->isDuplicating()) { |
| 1084 | continue; |
| 1085 | } |
| 1086 | mPlaybackThreads.valueAt(i)->setMasterBalance(balance); |
| 1087 | } |
| 1088 | |
| 1089 | return NO_ERROR; |
| 1090 | } |
| 1091 | |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 1092 | status_t AudioFlinger::setMode(audio_mode_t mode) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1093 | { |
Eric Laurent | a1884f9 | 2011-08-23 08:25:03 -0700 | [diff] [blame] | 1094 | status_t ret = initCheck(); |
| 1095 | if (ret != NO_ERROR) { |
| 1096 | return ret; |
| 1097 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1098 | |
| 1099 | // check calling permissions |
| 1100 | if (!settingsAllowed()) { |
| 1101 | return PERMISSION_DENIED; |
| 1102 | } |
Glenn Kasten | 930f4ca | 2012-01-06 16:47:31 -0800 | [diff] [blame] | 1103 | if (uint32_t(mode) >= AUDIO_MODE_CNT) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 1104 | ALOGW("Illegal value: setMode(%d)", mode); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1105 | return BAD_VALUE; |
| 1106 | } |
| 1107 | |
| 1108 | { // scope for the lock |
| 1109 | AutoMutex lock(mHardwareLock); |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1110 | sp<DeviceHalInterface> dev = mPrimaryHardwareDev->hwDevice(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1111 | mHardwareStatus = AUDIO_HW_SET_MODE; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1112 | ret = dev->setMode(mode); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1113 | mHardwareStatus = AUDIO_HW_IDLE; |
| 1114 | } |
| 1115 | |
| 1116 | if (NO_ERROR == ret) { |
| 1117 | Mutex::Autolock _l(mLock); |
| 1118 | mMode = mode; |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 1119 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1120 | mPlaybackThreads.valueAt(i)->setMode(mode); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | return ret; |
| 1124 | } |
| 1125 | |
| 1126 | status_t AudioFlinger::setMicMute(bool state) |
| 1127 | { |
Eric Laurent | a1884f9 | 2011-08-23 08:25:03 -0700 | [diff] [blame] | 1128 | status_t ret = initCheck(); |
| 1129 | if (ret != NO_ERROR) { |
| 1130 | return ret; |
| 1131 | } |
| 1132 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1133 | // check calling permissions |
| 1134 | if (!settingsAllowed()) { |
| 1135 | return PERMISSION_DENIED; |
| 1136 | } |
| 1137 | |
| 1138 | AutoMutex lock(mHardwareLock); |
| 1139 | mHardwareStatus = AUDIO_HW_SET_MIC_MUTE; |
Eric Laurent | 2f035f5 | 2014-09-14 12:11:52 -0700 | [diff] [blame] | 1140 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1141 | sp<DeviceHalInterface> dev = mAudioHwDevs.valueAt(i)->hwDevice(); |
| 1142 | status_t result = dev->setMicMute(state); |
Eric Laurent | 2f035f5 | 2014-09-14 12:11:52 -0700 | [diff] [blame] | 1143 | if (result != NO_ERROR) { |
| 1144 | ret = result; |
| 1145 | } |
| 1146 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1147 | mHardwareStatus = AUDIO_HW_IDLE; |
| 1148 | return ret; |
| 1149 | } |
| 1150 | |
| 1151 | bool AudioFlinger::getMicMute() const |
| 1152 | { |
Eric Laurent | a1884f9 | 2011-08-23 08:25:03 -0700 | [diff] [blame] | 1153 | status_t ret = initCheck(); |
| 1154 | if (ret != NO_ERROR) { |
| 1155 | return false; |
| 1156 | } |
Ricardo Garcia | 3e91b5d | 2015-02-19 10:54:52 -0800 | [diff] [blame] | 1157 | bool mute = true; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1158 | bool state = AUDIO_MODE_INVALID; |
Glenn Kasten | 2b213bc | 2012-02-02 14:05:20 -0800 | [diff] [blame] | 1159 | AutoMutex lock(mHardwareLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1160 | mHardwareStatus = AUDIO_HW_GET_MIC_MUTE; |
Ricardo Garcia | 3e91b5d | 2015-02-19 10:54:52 -0800 | [diff] [blame] | 1161 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1162 | sp<DeviceHalInterface> dev = mAudioHwDevs.valueAt(i)->hwDevice(); |
| 1163 | status_t result = dev->getMicMute(&state); |
Ricardo Garcia | 3e91b5d | 2015-02-19 10:54:52 -0800 | [diff] [blame] | 1164 | if (result == NO_ERROR) { |
| 1165 | mute = mute && state; |
| 1166 | } |
| 1167 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1168 | mHardwareStatus = AUDIO_HW_IDLE; |
Ricardo Garcia | 3e91b5d | 2015-02-19 10:54:52 -0800 | [diff] [blame] | 1169 | |
| 1170 | return mute; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 1173 | void AudioFlinger::setRecordSilenced(audio_port_handle_t portId, bool silenced) |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1174 | { |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 1175 | ALOGV("AudioFlinger::setRecordSilenced(portId:%d, silenced:%d)", portId, silenced); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1176 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1177 | AutoMutex lock(mLock); |
| 1178 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 1179 | mRecordThreads[i]->setRecordSilenced(portId, silenced); |
Eric Laurent | 331679c | 2018-04-16 17:03:16 -0700 | [diff] [blame] | 1180 | } |
| 1181 | for (size_t i = 0; i < mMmapThreads.size(); i++) { |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 1182 | mMmapThreads[i]->setRecordSilenced(portId, silenced); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1186 | status_t AudioFlinger::setMasterMute(bool muted) |
| 1187 | { |
John Grossman | d8f178d | 2012-07-20 14:51:35 -0700 | [diff] [blame] | 1188 | status_t ret = initCheck(); |
| 1189 | if (ret != NO_ERROR) { |
| 1190 | return ret; |
| 1191 | } |
| 1192 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1193 | // check calling permissions |
| 1194 | if (!settingsAllowed()) { |
| 1195 | return PERMISSION_DENIED; |
| 1196 | } |
| 1197 | |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1198 | Mutex::Autolock _l(mLock); |
| 1199 | mMasterMute = muted; |
John Grossman | d8f178d | 2012-07-20 14:51:35 -0700 | [diff] [blame] | 1200 | |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1201 | // Set master mute in the HALs which support it. |
| 1202 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
| 1203 | AutoMutex lock(mHardwareLock); |
| 1204 | AudioHwDevice *dev = mAudioHwDevs.valueAt(i); |
John Grossman | d8f178d | 2012-07-20 14:51:35 -0700 | [diff] [blame] | 1205 | |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1206 | mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE; |
| 1207 | if (dev->canSetMasterMute()) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1208 | dev->hwDevice()->setMasterMute(muted); |
John Grossman | d8f178d | 2012-07-20 14:51:35 -0700 | [diff] [blame] | 1209 | } |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1210 | mHardwareStatus = AUDIO_HW_IDLE; |
John Grossman | d8f178d | 2012-07-20 14:51:35 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1213 | // Now set the master mute in each playback thread. Playback threads |
| 1214 | // assigned to HALs which do not have master mute support will apply master |
| 1215 | // mute during the mix operation. Threads with HALs which do support master |
| 1216 | // mute will simply ignore the setting. |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 1217 | Vector<VolumeInterface *> volumeInterfaces = getAllVolumeInterfaces_l(); |
| 1218 | for (size_t i = 0; i < volumeInterfaces.size(); i++) { |
| 1219 | volumeInterfaces[i]->setMasterMute(muted); |
Eric Laurent | f6870ae | 2015-05-08 10:50:03 -0700 | [diff] [blame] | 1220 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1221 | |
| 1222 | return NO_ERROR; |
| 1223 | } |
| 1224 | |
| 1225 | float AudioFlinger::masterVolume() const |
| 1226 | { |
Glenn Kasten | 9806710 | 2011-12-13 11:47:54 -0800 | [diff] [blame] | 1227 | Mutex::Autolock _l(mLock); |
| 1228 | return masterVolume_l(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1231 | status_t AudioFlinger::getMasterBalance(float *balance) const |
| 1232 | { |
| 1233 | Mutex::Autolock _l(mLock); |
| 1234 | *balance = getMasterBalance_l(); |
| 1235 | return NO_ERROR; // if called through binder, may return a transactional error |
| 1236 | } |
| 1237 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1238 | bool AudioFlinger::masterMute() const |
| 1239 | { |
Glenn Kasten | 9806710 | 2011-12-13 11:47:54 -0800 | [diff] [blame] | 1240 | Mutex::Autolock _l(mLock); |
| 1241 | return masterMute_l(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 1244 | float AudioFlinger::masterVolume_l() const |
| 1245 | { |
John Grossman | 4ff14ba | 2012-02-08 16:37:41 -0800 | [diff] [blame] | 1246 | return mMasterVolume; |
| 1247 | } |
| 1248 | |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1249 | float AudioFlinger::getMasterBalance_l() const |
| 1250 | { |
| 1251 | return mMasterBalance; |
| 1252 | } |
| 1253 | |
John Grossman | d8f178d | 2012-07-20 14:51:35 -0700 | [diff] [blame] | 1254 | bool AudioFlinger::masterMute_l() const |
| 1255 | { |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 1256 | return mMasterMute; |
John Grossman | d8f178d | 2012-07-20 14:51:35 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1259 | status_t AudioFlinger::checkStreamType(audio_stream_type_t stream) const |
| 1260 | { |
| 1261 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 1262 | ALOGW("checkStreamType() invalid stream %d", stream); |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1263 | return BAD_VALUE; |
| 1264 | } |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 1265 | const uid_t callerUid = IPCThreadState::self()->getCallingUid(); |
| 1266 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT && !isAudioServerUid(callerUid)) { |
| 1267 | ALOGW("checkStreamType() uid %d cannot use internal stream type %d", callerUid, stream); |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1268 | return PERMISSION_DENIED; |
| 1269 | } |
| 1270 | |
| 1271 | return NO_ERROR; |
| 1272 | } |
| 1273 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1274 | status_t AudioFlinger::setStreamVolume(audio_stream_type_t stream, float value, |
| 1275 | audio_io_handle_t output) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1276 | { |
| 1277 | // check calling permissions |
| 1278 | if (!settingsAllowed()) { |
| 1279 | return PERMISSION_DENIED; |
| 1280 | } |
| 1281 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1282 | status_t status = checkStreamType(stream); |
| 1283 | if (status != NO_ERROR) { |
| 1284 | return status; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1285 | } |
Eric Laurent | 98e3819 | 2018-02-15 18:31:53 -0800 | [diff] [blame] | 1286 | if (output == AUDIO_IO_HANDLE_NONE) { |
| 1287 | return BAD_VALUE; |
| 1288 | } |
François Gaffie | 9e1533c | 2019-04-11 16:07:36 +0200 | [diff] [blame] | 1289 | LOG_ALWAYS_FATAL_IF(stream == AUDIO_STREAM_PATCH && value != 1.0f, |
| 1290 | "AUDIO_STREAM_PATCH must have full scale volume"); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1291 | |
| 1292 | AutoMutex lock(mLock); |
Eric Laurent | 98e3819 | 2018-02-15 18:31:53 -0800 | [diff] [blame] | 1293 | VolumeInterface *volumeInterface = getVolumeInterface_l(output); |
| 1294 | if (volumeInterface == NULL) { |
| 1295 | return BAD_VALUE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1296 | } |
Eric Laurent | 98e3819 | 2018-02-15 18:31:53 -0800 | [diff] [blame] | 1297 | volumeInterface->setStreamVolume(stream, value); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1298 | |
| 1299 | return NO_ERROR; |
| 1300 | } |
| 1301 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1302 | status_t AudioFlinger::setStreamMute(audio_stream_type_t stream, bool muted) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1303 | { |
| 1304 | // check calling permissions |
| 1305 | if (!settingsAllowed()) { |
| 1306 | return PERMISSION_DENIED; |
| 1307 | } |
| 1308 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1309 | status_t status = checkStreamType(stream); |
| 1310 | if (status != NO_ERROR) { |
| 1311 | return status; |
| 1312 | } |
| 1313 | ALOG_ASSERT(stream != AUDIO_STREAM_PATCH, "attempt to mute AUDIO_STREAM_PATCH"); |
| 1314 | |
| 1315 | if (uint32_t(stream) == AUDIO_STREAM_ENFORCED_AUDIBLE) { |
Steve Block | 29357bc | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 1316 | ALOGE("setStreamMute() invalid stream %d", stream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1317 | return BAD_VALUE; |
| 1318 | } |
| 1319 | |
Eric Laurent | 9357520 | 2011-01-18 18:39:02 -0800 | [diff] [blame] | 1320 | AutoMutex lock(mLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1321 | mStreamTypes[stream].mute = muted; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 1322 | Vector<VolumeInterface *> volumeInterfaces = getAllVolumeInterfaces_l(); |
| 1323 | for (size_t i = 0; i < volumeInterfaces.size(); i++) { |
| 1324 | volumeInterfaces[i]->setStreamMute(stream, muted); |
| 1325 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1326 | |
| 1327 | return NO_ERROR; |
| 1328 | } |
| 1329 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1330 | float AudioFlinger::streamVolume(audio_stream_type_t stream, audio_io_handle_t output) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1331 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1332 | status_t status = checkStreamType(stream); |
| 1333 | if (status != NO_ERROR) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1334 | return 0.0f; |
| 1335 | } |
Eric Laurent | 98e3819 | 2018-02-15 18:31:53 -0800 | [diff] [blame] | 1336 | if (output == AUDIO_IO_HANDLE_NONE) { |
| 1337 | return 0.0f; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
Eric Laurent | 98e3819 | 2018-02-15 18:31:53 -0800 | [diff] [blame] | 1340 | AutoMutex lock(mLock); |
| 1341 | VolumeInterface *volumeInterface = getVolumeInterface_l(output); |
| 1342 | if (volumeInterface == NULL) { |
| 1343 | return 0.0f; |
| 1344 | } |
| 1345 | |
| 1346 | return volumeInterface->streamVolume(stream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 1349 | bool AudioFlinger::streamMute(audio_stream_type_t stream) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1350 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1351 | status_t status = checkStreamType(stream); |
| 1352 | if (status != NO_ERROR) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1353 | return true; |
| 1354 | } |
| 1355 | |
Glenn Kasten | 6637baa | 2012-01-09 09:40:36 -0800 | [diff] [blame] | 1356 | AutoMutex lock(mLock); |
| 1357 | return streamMute_l(stream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 1360 | |
| 1361 | void AudioFlinger::broacastParametersToRecordThreads_l(const String8& keyValuePairs) |
| 1362 | { |
| 1363 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
| 1364 | mRecordThreads.valueAt(i)->setParameters(keyValuePairs); |
| 1365 | } |
| 1366 | } |
| 1367 | |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 1368 | void AudioFlinger::updateOutDevicesForRecordThreads_l(const DeviceDescriptorBaseVector& devices) |
| 1369 | { |
| 1370 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
| 1371 | mRecordThreads.valueAt(i)->updateOutDevices(devices); |
| 1372 | } |
| 1373 | } |
| 1374 | |
Mikhail Naganov | b261ef5 | 2018-07-16 13:34:38 -0700 | [diff] [blame] | 1375 | // forwardAudioHwSyncToDownstreamPatches_l() must be called with AudioFlinger::mLock held |
| 1376 | void AudioFlinger::forwardParametersToDownstreamPatches_l( |
| 1377 | audio_io_handle_t upStream, const String8& keyValuePairs, |
| 1378 | std::function<bool(const sp<PlaybackThread>&)> useThread) |
| 1379 | { |
| 1380 | std::vector<PatchPanel::SoftwarePatch> swPatches; |
| 1381 | if (mPatchPanel.getDownstreamSoftwarePatches(upStream, &swPatches) != OK) return; |
| 1382 | ALOGV_IF(!swPatches.empty(), "%s found %zu downstream patches for stream ID %d", |
| 1383 | __func__, swPatches.size(), upStream); |
| 1384 | for (const auto& swPatch : swPatches) { |
| 1385 | sp<PlaybackThread> downStream = checkPlaybackThread_l(swPatch.getPlaybackThreadHandle()); |
| 1386 | if (downStream != NULL && (useThread == nullptr || useThread(downStream))) { |
| 1387 | downStream->setParameters(keyValuePairs); |
| 1388 | } |
| 1389 | } |
| 1390 | } |
| 1391 | |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1392 | // Filter reserved keys from setParameters() before forwarding to audio HAL or acting upon. |
| 1393 | // Some keys are used for audio routing and audio path configuration and should be reserved for use |
| 1394 | // by audio policy and audio flinger for functional, privacy and security reasons. |
| 1395 | void AudioFlinger::filterReservedParameters(String8& keyValuePairs, uid_t callingUid) |
| 1396 | { |
| 1397 | static const String8 kReservedParameters[] = { |
| 1398 | String8(AudioParameter::keyRouting), |
| 1399 | String8(AudioParameter::keySamplingRate), |
| 1400 | String8(AudioParameter::keyFormat), |
| 1401 | String8(AudioParameter::keyChannels), |
| 1402 | String8(AudioParameter::keyFrameCount), |
| 1403 | String8(AudioParameter::keyInputSource), |
| 1404 | String8(AudioParameter::keyMonoOutput), |
Mikhail Naganov | f23fcf6 | 2019-07-08 15:28:43 -0700 | [diff] [blame] | 1405 | String8(AudioParameter::keyDeviceConnect), |
| 1406 | String8(AudioParameter::keyDeviceDisconnect), |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1407 | String8(AudioParameter::keyStreamSupportedFormats), |
| 1408 | String8(AudioParameter::keyStreamSupportedChannels), |
| 1409 | String8(AudioParameter::keyStreamSupportedSamplingRates), |
| 1410 | }; |
| 1411 | |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 1412 | if (isAudioServerUid(callingUid)) { |
| 1413 | return; // no need to filter if audioserver. |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | AudioParameter param = AudioParameter(keyValuePairs); |
| 1417 | String8 value; |
Kevin Rocard | a0a5d2a | 2018-08-06 15:03:18 -0700 | [diff] [blame] | 1418 | AudioParameter rejectedParam; |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1419 | for (auto& key : kReservedParameters) { |
| 1420 | if (param.get(key, value) == NO_ERROR) { |
Kevin Rocard | a0a5d2a | 2018-08-06 15:03:18 -0700 | [diff] [blame] | 1421 | rejectedParam.add(key, value); |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1422 | param.remove(key); |
| 1423 | } |
| 1424 | } |
Kevin Rocard | a0a5d2a | 2018-08-06 15:03:18 -0700 | [diff] [blame] | 1425 | logFilteredParameters(param.size() + rejectedParam.size(), keyValuePairs, |
| 1426 | rejectedParam.size(), rejectedParam.toString(), callingUid); |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1427 | keyValuePairs = param.toString(); |
| 1428 | } |
| 1429 | |
Kevin Rocard | a0a5d2a | 2018-08-06 15:03:18 -0700 | [diff] [blame] | 1430 | void AudioFlinger::logFilteredParameters(size_t originalKVPSize, const String8& originalKVPs, |
| 1431 | size_t rejectedKVPSize, const String8& rejectedKVPs, |
| 1432 | uid_t callingUid) { |
| 1433 | auto prefix = String8::format("UID %5d", callingUid); |
| 1434 | auto suffix = String8::format("%zu KVP received: %s", originalKVPSize, originalKVPs.c_str()); |
| 1435 | if (rejectedKVPSize != 0) { |
| 1436 | auto error = String8::format("%zu KVP rejected: %s", rejectedKVPSize, rejectedKVPs.c_str()); |
| 1437 | ALOGW("%s: %s, %s, %s", __func__, prefix.c_str(), error.c_str(), suffix.c_str()); |
| 1438 | mRejectedSetParameterLog.log("%s, %s, %s", prefix.c_str(), error.c_str(), suffix.c_str()); |
| 1439 | } else { |
| 1440 | auto& logger = (isServiceUid(callingUid) ? mSystemSetParameterLog : mAppSetParameterLog); |
| 1441 | logger.log("%s, %s", prefix.c_str(), suffix.c_str()); |
| 1442 | } |
| 1443 | } |
| 1444 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1445 | status_t AudioFlinger::setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1446 | { |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1447 | ALOGV("setParameters(): io %d, keyvalue %s, calling pid %d calling uid %d", |
| 1448 | ioHandle, keyValuePairs.string(), |
| 1449 | IPCThreadState::self()->getCallingPid(), IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1450 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1451 | // check calling permissions |
| 1452 | if (!settingsAllowed()) { |
| 1453 | return PERMISSION_DENIED; |
| 1454 | } |
| 1455 | |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1456 | String8 filteredKeyValuePairs = keyValuePairs; |
| 1457 | filterReservedParameters(filteredKeyValuePairs, IPCThreadState::self()->getCallingUid()); |
| 1458 | |
| 1459 | ALOGV("%s: filtered keyvalue %s", __func__, filteredKeyValuePairs.string()); |
| 1460 | |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 1461 | // AUDIO_IO_HANDLE_NONE means the parameters are global to the audio hardware interface |
| 1462 | if (ioHandle == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1463 | Mutex::Autolock _l(mLock); |
Eric Laurent | d21bcd2 | 2016-09-08 18:25:54 -0700 | [diff] [blame] | 1464 | // result will remain NO_INIT if no audio device is present |
| 1465 | status_t final_result = NO_INIT; |
Glenn Kasten | 8abf44d | 2012-02-02 14:16:03 -0800 | [diff] [blame] | 1466 | { |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1467 | AutoMutex lock(mHardwareLock); |
| 1468 | mHardwareStatus = AUDIO_HW_SET_PARAMETER; |
| 1469 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1470 | sp<DeviceHalInterface> dev = mAudioHwDevs.valueAt(i)->hwDevice(); |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1471 | status_t result = dev->setParameters(filteredKeyValuePairs); |
Eric Laurent | d21bcd2 | 2016-09-08 18:25:54 -0700 | [diff] [blame] | 1472 | // return success if at least one audio device accepts the parameters as not all |
| 1473 | // HALs are requested to support all parameters. If no audio device supports the |
| 1474 | // requested parameters, the last error is reported. |
| 1475 | if (final_result != NO_ERROR) { |
| 1476 | final_result = result; |
| 1477 | } |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1478 | } |
| 1479 | mHardwareStatus = AUDIO_HW_IDLE; |
Glenn Kasten | 8abf44d | 2012-02-02 14:16:03 -0800 | [diff] [blame] | 1480 | } |
Eric Laurent | 59bd0da | 2011-08-01 09:52:20 -0700 | [diff] [blame] | 1481 | // disable AEC and NS if the device is a BT SCO headset supporting those pre processings |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1482 | AudioParameter param = AudioParameter(filteredKeyValuePairs); |
Eric Laurent | 59bd0da | 2011-08-01 09:52:20 -0700 | [diff] [blame] | 1483 | String8 value; |
Mikhail Naganov | 00260b5 | 2016-10-13 12:54:24 -0700 | [diff] [blame] | 1484 | if (param.get(String8(AudioParameter::keyBtNrec), value) == NO_ERROR) { |
| 1485 | bool btNrecIsOff = (value == AudioParameter::valueOff); |
Eric Laurent | d8365c5 | 2017-07-16 15:27:05 -0700 | [diff] [blame] | 1486 | if (mBtNrecIsOff.exchange(btNrecIsOff) != btNrecIsOff) { |
Eric Laurent | 59bd0da | 2011-08-01 09:52:20 -0700 | [diff] [blame] | 1487 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
Eric Laurent | d8365c5 | 2017-07-16 15:27:05 -0700 | [diff] [blame] | 1488 | mRecordThreads.valueAt(i)->checkBtNrec(); |
Eric Laurent | 59bd0da | 2011-08-01 09:52:20 -0700 | [diff] [blame] | 1489 | } |
Eric Laurent | 59bd0da | 2011-08-01 09:52:20 -0700 | [diff] [blame] | 1490 | } |
| 1491 | } |
Glenn Kasten | 28ed2f9 | 2012-06-07 10:17:54 -0700 | [diff] [blame] | 1492 | String8 screenState; |
| 1493 | if (param.get(String8(AudioParameter::keyScreenState), screenState) == NO_ERROR) { |
Mikhail Naganov | 00260b5 | 2016-10-13 12:54:24 -0700 | [diff] [blame] | 1494 | bool isOff = (screenState == AudioParameter::valueOff); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1495 | if (isOff != (AudioFlinger::mScreenState & 1)) { |
| 1496 | AudioFlinger::mScreenState = ((AudioFlinger::mScreenState & ~1) + 2) | isOff; |
Glenn Kasten | 28ed2f9 | 2012-06-07 10:17:54 -0700 | [diff] [blame] | 1497 | } |
| 1498 | } |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1499 | return final_result; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | // hold a strong ref on thread in case closeOutput() or closeInput() is called |
| 1503 | // and the thread is exited once the lock is released |
| 1504 | sp<ThreadBase> thread; |
| 1505 | { |
| 1506 | Mutex::Autolock _l(mLock); |
| 1507 | thread = checkPlaybackThread_l(ioHandle); |
Glenn Kasten | d5903ec | 2012-03-18 10:33:27 -0700 | [diff] [blame] | 1508 | if (thread == 0) { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1509 | thread = checkRecordThread_l(ioHandle); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 1510 | if (thread == 0) { |
| 1511 | thread = checkMmapThread_l(ioHandle); |
| 1512 | } |
Glenn Kasten | 7fc9a6f | 2012-01-10 10:46:34 -0800 | [diff] [blame] | 1513 | } else if (thread == primaryPlaybackThread_l()) { |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1514 | // indicate output device change to all input threads for pre processing |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1515 | AudioParameter param = AudioParameter(filteredKeyValuePairs); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1516 | int value; |
Eric Laurent | 89d94e7 | 2012-03-16 20:37:59 -0700 | [diff] [blame] | 1517 | if ((param.getInt(String8(AudioParameter::keyRouting), value) == NO_ERROR) && |
| 1518 | (value != 0)) { |
Eric Laurent | f1047e8 | 2018-04-16 19:18:20 -0700 | [diff] [blame] | 1519 | broacastParametersToRecordThreads_l(filteredKeyValuePairs); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1520 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1521 | } |
| 1522 | } |
Glenn Kasten | 7378ca5 | 2012-01-20 13:44:40 -0800 | [diff] [blame] | 1523 | if (thread != 0) { |
Mikhail Naganov | b261ef5 | 2018-07-16 13:34:38 -0700 | [diff] [blame] | 1524 | status_t result = thread->setParameters(filteredKeyValuePairs); |
| 1525 | forwardParametersToDownstreamPatches_l(thread->id(), filteredKeyValuePairs); |
| 1526 | return result; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1527 | } |
| 1528 | return BAD_VALUE; |
| 1529 | } |
| 1530 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1531 | String8 AudioFlinger::getParameters(audio_io_handle_t ioHandle, const String8& keys) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1532 | { |
Glenn Kasten | 827e5f1 | 2012-11-02 10:00:06 -0700 | [diff] [blame] | 1533 | ALOGVV("getParameters() io %d, keys %s, calling pid %d", |
| 1534 | ioHandle, keys.string(), IPCThreadState::self()->getCallingPid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1535 | |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 1536 | Mutex::Autolock _l(mLock); |
| 1537 | |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 1538 | if (ioHandle == AUDIO_IO_HANDLE_NONE) { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1539 | String8 out_s8; |
| 1540 | |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1541 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1542 | String8 s; |
| 1543 | status_t result; |
Glenn Kasten | 8abf44d | 2012-02-02 14:16:03 -0800 | [diff] [blame] | 1544 | { |
| 1545 | AutoMutex lock(mHardwareLock); |
| 1546 | mHardwareStatus = AUDIO_HW_GET_PARAMETER; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1547 | sp<DeviceHalInterface> dev = mAudioHwDevs.valueAt(i)->hwDevice(); |
| 1548 | result = dev->getParameters(keys, &s); |
Glenn Kasten | 8abf44d | 2012-02-02 14:16:03 -0800 | [diff] [blame] | 1549 | mHardwareStatus = AUDIO_HW_IDLE; |
| 1550 | } |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1551 | if (result == OK) out_s8 += s; |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1552 | } |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1553 | return out_s8; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 1556 | ThreadBase *thread = (ThreadBase *)checkPlaybackThread_l(ioHandle); |
| 1557 | if (thread == NULL) { |
| 1558 | thread = (ThreadBase *)checkRecordThread_l(ioHandle); |
| 1559 | if (thread == NULL) { |
| 1560 | thread = (ThreadBase *)checkMmapThread_l(ioHandle); |
| 1561 | if (thread == NULL) { |
Mikhail Naganov | aa165e5 | 2017-07-12 10:39:16 -0700 | [diff] [blame] | 1562 | return String8(""); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 1563 | } |
| 1564 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1565 | } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 1566 | return thread->getParameters(keys); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1567 | } |
| 1568 | |
Glenn Kasten | dd8104c | 2012-07-02 12:42:44 -0700 | [diff] [blame] | 1569 | size_t AudioFlinger::getInputBufferSize(uint32_t sampleRate, audio_format_t format, |
| 1570 | audio_channel_mask_t channelMask) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1571 | { |
Eric Laurent | a1884f9 | 2011-08-23 08:25:03 -0700 | [diff] [blame] | 1572 | status_t ret = initCheck(); |
| 1573 | if (ret != NO_ERROR) { |
| 1574 | return 0; |
| 1575 | } |
Eric Laurent | cdf924a | 2016-02-04 15:57:56 -0800 | [diff] [blame] | 1576 | if ((sampleRate == 0) || |
Phil Burk | fdb3c07 | 2016-02-09 10:47:02 -0800 | [diff] [blame] | 1577 | !audio_is_valid_format(format) || !audio_has_proportional_frames(format) || |
Eric Laurent | cdf924a | 2016-02-04 15:57:56 -0800 | [diff] [blame] | 1578 | !audio_is_input_channel(channelMask)) { |
Andy Hung | 6770c6f | 2015-04-07 13:43:36 -0700 | [diff] [blame] | 1579 | return 0; |
| 1580 | } |
Eric Laurent | a1884f9 | 2011-08-23 08:25:03 -0700 | [diff] [blame] | 1581 | |
Glenn Kasten | 2b213bc | 2012-02-02 14:05:20 -0800 | [diff] [blame] | 1582 | AutoMutex lock(mHardwareLock); |
| 1583 | mHardwareStatus = AUDIO_HW_GET_INPUT_BUFFER_SIZE; |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 1584 | |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1585 | sp<DeviceHalInterface> dev = mPrimaryHardwareDev->hwDevice(); |
Judy Hsiao | abab522 | 2019-11-09 18:14:58 +0800 | [diff] [blame] | 1586 | std::vector<audio_channel_mask_t> channelMasks = {channelMask}; |
| 1587 | if (channelMask != AUDIO_CHANNEL_IN_MONO) |
| 1588 | channelMasks.push_back(AUDIO_CHANNEL_IN_MONO); |
| 1589 | if (channelMask != AUDIO_CHANNEL_IN_STEREO) |
| 1590 | channelMasks.push_back(AUDIO_CHANNEL_IN_STEREO); |
| 1591 | |
| 1592 | std::vector<audio_format_t> formats = {format}; |
| 1593 | if (format != AUDIO_FORMAT_PCM_16_BIT) |
| 1594 | formats.push_back(AUDIO_FORMAT_PCM_16_BIT); |
| 1595 | |
| 1596 | std::vector<uint32_t> sampleRates = {sampleRate}; |
| 1597 | static const uint32_t SR_44100 = 44100; |
| 1598 | static const uint32_t SR_48000 = 48000; |
| 1599 | |
| 1600 | if (sampleRate != SR_48000) |
| 1601 | sampleRates.push_back(SR_48000); |
| 1602 | if (sampleRate != SR_44100) |
| 1603 | sampleRates.push_back(SR_44100); |
| 1604 | |
Glenn Kasten | 2b213bc | 2012-02-02 14:05:20 -0800 | [diff] [blame] | 1605 | mHardwareStatus = AUDIO_HW_IDLE; |
Judy Hsiao | abab522 | 2019-11-09 18:14:58 +0800 | [diff] [blame] | 1606 | |
Robin Lee | 9899ff7 | 2019-12-24 22:02:08 +0100 | [diff] [blame] | 1607 | // Change parameters of the configuration each iteration until we find a |
| 1608 | // configuration that the device will support. |
| 1609 | audio_config_t config = AUDIO_CONFIG_INITIALIZER; |
Judy Hsiao | abab522 | 2019-11-09 18:14:58 +0800 | [diff] [blame] | 1610 | for (auto testChannelMask : channelMasks) { |
| 1611 | config.channel_mask = testChannelMask; |
| 1612 | for (auto testFormat : formats) { |
| 1613 | config.format = testFormat; |
| 1614 | for (auto testSampleRate : sampleRates) { |
| 1615 | config.sample_rate = testSampleRate; |
Robin Lee | 9899ff7 | 2019-12-24 22:02:08 +0100 | [diff] [blame] | 1616 | |
Judy Hsiao | abab522 | 2019-11-09 18:14:58 +0800 | [diff] [blame] | 1617 | size_t bytes = 0; |
| 1618 | status_t result = dev->getInputBufferSize(&config, &bytes); |
| 1619 | if (result != OK || bytes == 0) { |
| 1620 | continue; |
| 1621 | } |
| 1622 | |
| 1623 | if (config.sample_rate != sampleRate || config.channel_mask != channelMask || |
| 1624 | config.format != format) { |
| 1625 | uint32_t dstChannelCount = audio_channel_count_from_in_mask(channelMask); |
| 1626 | uint32_t srcChannelCount = |
| 1627 | audio_channel_count_from_in_mask(config.channel_mask); |
| 1628 | size_t srcFrames = |
| 1629 | bytes / audio_bytes_per_frame(srcChannelCount, config.format); |
| 1630 | size_t dstFrames = destinationFramesPossible( |
| 1631 | srcFrames, config.sample_rate, sampleRate); |
| 1632 | bytes = dstFrames * audio_bytes_per_frame(dstChannelCount, format); |
| 1633 | } |
| 1634 | return bytes; |
| 1635 | } |
| 1636 | } |
Andy Hung | 6770c6f | 2015-04-07 13:43:36 -0700 | [diff] [blame] | 1637 | } |
Judy Hsiao | abab522 | 2019-11-09 18:14:58 +0800 | [diff] [blame] | 1638 | |
| 1639 | ALOGW("getInputBufferSize failed with minimum buffer size sampleRate %u, " |
| 1640 | "format %#x, channelMask %#x",sampleRate, format, channelMask); |
| 1641 | return 0; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1642 | } |
| 1643 | |
Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 1644 | uint32_t AudioFlinger::getInputFramesLost(audio_io_handle_t ioHandle) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1645 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1646 | Mutex::Autolock _l(mLock); |
| 1647 | |
| 1648 | RecordThread *recordThread = checkRecordThread_l(ioHandle); |
| 1649 | if (recordThread != NULL) { |
| 1650 | return recordThread->getInputFramesLost(); |
| 1651 | } |
| 1652 | return 0; |
| 1653 | } |
| 1654 | |
| 1655 | status_t AudioFlinger::setVoiceVolume(float value) |
| 1656 | { |
Eric Laurent | a1884f9 | 2011-08-23 08:25:03 -0700 | [diff] [blame] | 1657 | status_t ret = initCheck(); |
| 1658 | if (ret != NO_ERROR) { |
| 1659 | return ret; |
| 1660 | } |
| 1661 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1662 | // check calling permissions |
| 1663 | if (!settingsAllowed()) { |
| 1664 | return PERMISSION_DENIED; |
| 1665 | } |
| 1666 | |
| 1667 | AutoMutex lock(mHardwareLock); |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1668 | sp<DeviceHalInterface> dev = mPrimaryHardwareDev->hwDevice(); |
Glenn Kasten | 8abf44d | 2012-02-02 14:16:03 -0800 | [diff] [blame] | 1669 | mHardwareStatus = AUDIO_HW_SET_VOICE_VOLUME; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 1670 | ret = dev->setVoiceVolume(value); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1671 | mHardwareStatus = AUDIO_HW_IDLE; |
| 1672 | |
| 1673 | return ret; |
| 1674 | } |
| 1675 | |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 1676 | status_t AudioFlinger::getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1677 | audio_io_handle_t output) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1678 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1679 | Mutex::Autolock _l(mLock); |
| 1680 | |
| 1681 | PlaybackThread *playbackThread = checkPlaybackThread_l(output); |
| 1682 | if (playbackThread != NULL) { |
| 1683 | return playbackThread->getRenderPosition(halFrames, dspFrames); |
| 1684 | } |
| 1685 | |
| 1686 | return BAD_VALUE; |
| 1687 | } |
| 1688 | |
| 1689 | void AudioFlinger::registerClient(const sp<IAudioFlingerClient>& client) |
| 1690 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1691 | Mutex::Autolock _l(mLock); |
Eric Laurent | 44622db | 2014-08-01 19:00:33 -0700 | [diff] [blame] | 1692 | if (client == 0) { |
| 1693 | return; |
| 1694 | } |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1695 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
Andy Hung | 5bdc535 | 2019-12-23 14:36:31 -0800 | [diff] [blame] | 1696 | const uid_t uid = IPCThreadState::self()->getCallingUid(); |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1697 | { |
| 1698 | Mutex::Autolock _cl(mClientLock); |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1699 | if (mNotificationClients.indexOfKey(pid) < 0) { |
| 1700 | sp<NotificationClient> notificationClient = new NotificationClient(this, |
| 1701 | client, |
Andy Hung | 5bdc535 | 2019-12-23 14:36:31 -0800 | [diff] [blame] | 1702 | pid, |
| 1703 | uid); |
| 1704 | ALOGV("registerClient() client %p, pid %d, uid %u", |
| 1705 | notificationClient.get(), pid, uid); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1706 | |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1707 | mNotificationClients.add(pid, notificationClient); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1708 | |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 1709 | sp<IBinder> binder = IInterface::asBinder(client); |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1710 | binder->linkToDeath(notificationClient); |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1711 | } |
| 1712 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1713 | |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1714 | // mClientLock should not be held here because ThreadBase::sendIoConfigEvent() will lock the |
Eric Laurent | fe1a94e | 2014-05-26 16:03:08 -0700 | [diff] [blame] | 1715 | // ThreadBase mutex and the locking order is ThreadBase::mLock then AudioFlinger::mClientLock. |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1716 | // the config change is always sent from playback or record threads to avoid deadlock |
| 1717 | // with AudioSystem::gLock |
| 1718 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 1719 | mPlaybackThreads.valueAt(i)->sendIoConfigEvent(AUDIO_OUTPUT_REGISTERED, pid); |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1720 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1721 | |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1722 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
Eric Laurent | ad2e7b9 | 2017-09-14 20:06:42 -0700 | [diff] [blame] | 1723 | mRecordThreads.valueAt(i)->sendIoConfigEvent(AUDIO_INPUT_REGISTERED, pid); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1724 | } |
| 1725 | } |
| 1726 | |
| 1727 | void AudioFlinger::removeNotificationClient(pid_t pid) |
| 1728 | { |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1729 | std::vector< sp<AudioFlinger::EffectModule> > removedEffects; |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1730 | { |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1731 | Mutex::Autolock _l(mLock); |
| 1732 | { |
| 1733 | Mutex::Autolock _cl(mClientLock); |
| 1734 | mNotificationClients.removeItem(pid); |
| 1735 | } |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1736 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1737 | ALOGV("%d died, releasing its sessions", pid); |
| 1738 | size_t num = mAudioSessionRefs.size(); |
| 1739 | bool removed = false; |
| 1740 | for (size_t i = 0; i < num; ) { |
| 1741 | AudioSessionRef *ref = mAudioSessionRefs.itemAt(i); |
| 1742 | ALOGV(" pid %d @ %zu", ref->mPid, i); |
| 1743 | if (ref->mPid == pid) { |
| 1744 | ALOGV(" removing entry for pid %d session %d", pid, ref->mSessionid); |
| 1745 | mAudioSessionRefs.removeAt(i); |
| 1746 | delete ref; |
| 1747 | removed = true; |
| 1748 | num--; |
| 1749 | } else { |
| 1750 | i++; |
| 1751 | } |
| 1752 | } |
| 1753 | if (removed) { |
| 1754 | removedEffects = purgeStaleEffects_l(); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1755 | } |
| 1756 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1757 | for (auto& effect : removedEffects) { |
| 1758 | effect->updatePolicyState(); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1759 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 1762 | void AudioFlinger::ioConfigChanged(audio_io_config_event event, |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1763 | const sp<AudioIoDescriptor>& ioDesc, |
| 1764 | pid_t pid) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1765 | { |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1766 | Mutex::Autolock _l(mClientLock); |
| 1767 | size_t size = mNotificationClients.size(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1768 | for (size_t i = 0; i < size; i++) { |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 1769 | if ((pid == 0) || (mNotificationClients.keyAt(i) == pid)) { |
| 1770 | mNotificationClients.valueAt(i)->audioFlingerClient()->ioConfigChanged(event, ioDesc); |
| 1771 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1772 | } |
| 1773 | } |
| 1774 | |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1775 | // removeClient_l() must be called with AudioFlinger::mClientLock held |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1776 | void AudioFlinger::removeClient_l(pid_t pid) |
| 1777 | { |
Glenn Kasten | 827e5f1 | 2012-11-02 10:00:06 -0700 | [diff] [blame] | 1778 | ALOGV("removeClient_l() pid %d, calling pid %d", pid, |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 1779 | IPCThreadState::self()->getCallingPid()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1780 | mClients.removeItem(pid); |
| 1781 | } |
| 1782 | |
Eric Laurent | 717e128 | 2012-06-29 16:36:52 -0700 | [diff] [blame] | 1783 | // getEffectThread_l() must be called with AudioFlinger::mLock held |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1784 | sp<AudioFlinger::ThreadBase> AudioFlinger::getEffectThread_l(audio_session_t sessionId, |
| 1785 | int effectId) |
Eric Laurent | 717e128 | 2012-06-29 16:36:52 -0700 | [diff] [blame] | 1786 | { |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1787 | sp<ThreadBase> thread; |
Eric Laurent | 717e128 | 2012-06-29 16:36:52 -0700 | [diff] [blame] | 1788 | |
| 1789 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1790 | if (mPlaybackThreads.valueAt(i)->getEffect(sessionId, effectId) != 0) { |
Eric Laurent | 717e128 | 2012-06-29 16:36:52 -0700 | [diff] [blame] | 1791 | ALOG_ASSERT(thread == 0); |
| 1792 | thread = mPlaybackThreads.valueAt(i); |
| 1793 | } |
| 1794 | } |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 1795 | if (thread != nullptr) { |
| 1796 | return thread; |
| 1797 | } |
| 1798 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
| 1799 | if (mRecordThreads.valueAt(i)->getEffect(sessionId, effectId) != 0) { |
| 1800 | ALOG_ASSERT(thread == 0); |
| 1801 | thread = mRecordThreads.valueAt(i); |
| 1802 | } |
| 1803 | } |
| 1804 | if (thread != nullptr) { |
| 1805 | return thread; |
| 1806 | } |
| 1807 | for (size_t i = 0; i < mMmapThreads.size(); i++) { |
| 1808 | if (mMmapThreads.valueAt(i)->getEffect(sessionId, effectId) != 0) { |
| 1809 | ALOG_ASSERT(thread == 0); |
| 1810 | thread = mMmapThreads.valueAt(i); |
| 1811 | } |
| 1812 | } |
Eric Laurent | 717e128 | 2012-06-29 16:36:52 -0700 | [diff] [blame] | 1813 | return thread; |
| 1814 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1815 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1816 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1817 | |
| 1818 | // ---------------------------------------------------------------------------- |
| 1819 | |
| 1820 | AudioFlinger::Client::Client(const sp<AudioFlinger>& audioFlinger, pid_t pid) |
| 1821 | : RefBase(), |
| 1822 | mAudioFlinger(audioFlinger), |
Glenn Kasten | d79072e | 2016-01-06 08:41:20 -0800 | [diff] [blame] | 1823 | mPid(pid) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1824 | { |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 1825 | mMemoryDealer = new MemoryDealer( |
| 1826 | audioFlinger->getClientSharedHeapSize(), |
| 1827 | (std::string("AudioFlinger::Client(") + std::to_string(pid) + ")").c_str()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 1830 | // Client destructor must be called with AudioFlinger::mClientLock held |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1831 | AudioFlinger::Client::~Client() |
| 1832 | { |
| 1833 | mAudioFlinger->removeClient_l(mPid); |
| 1834 | } |
| 1835 | |
Glenn Kasten | 435dbe6 | 2012-01-30 10:15:48 -0800 | [diff] [blame] | 1836 | sp<MemoryDealer> AudioFlinger::Client::heap() const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1837 | { |
| 1838 | return mMemoryDealer; |
| 1839 | } |
| 1840 | |
| 1841 | // ---------------------------------------------------------------------------- |
| 1842 | |
| 1843 | AudioFlinger::NotificationClient::NotificationClient(const sp<AudioFlinger>& audioFlinger, |
| 1844 | const sp<IAudioFlingerClient>& client, |
Andy Hung | 5bdc535 | 2019-12-23 14:36:31 -0800 | [diff] [blame] | 1845 | pid_t pid, |
| 1846 | uid_t uid) |
| 1847 | : mAudioFlinger(audioFlinger), mPid(pid), mUid(uid), mAudioFlingerClient(client) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1848 | { |
| 1849 | } |
| 1850 | |
| 1851 | AudioFlinger::NotificationClient::~NotificationClient() |
| 1852 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 1855 | void AudioFlinger::NotificationClient::binderDied(const wp<IBinder>& who __unused) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1856 | { |
| 1857 | sp<NotificationClient> keep(this); |
Glenn Kasten | a111792 | 2012-01-26 10:53:32 -0800 | [diff] [blame] | 1858 | mAudioFlinger->removeNotificationClient(mPid); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 1861 | // ---------------------------------------------------------------------------- |
| 1862 | AudioFlinger::MediaLogNotifier::MediaLogNotifier() |
| 1863 | : mPendingRequests(false) {} |
| 1864 | |
| 1865 | |
| 1866 | void AudioFlinger::MediaLogNotifier::requestMerge() { |
| 1867 | AutoMutex _l(mMutex); |
| 1868 | mPendingRequests = true; |
| 1869 | mCond.signal(); |
| 1870 | } |
| 1871 | |
| 1872 | bool AudioFlinger::MediaLogNotifier::threadLoop() { |
Glenn Kasten | 04b96fc | 2017-04-10 14:58:47 -0700 | [diff] [blame] | 1873 | // Should already have been checked, but just in case |
| 1874 | if (sMediaLogService == 0) { |
| 1875 | return false; |
| 1876 | } |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 1877 | // Wait until there are pending requests |
| 1878 | { |
| 1879 | AutoMutex _l(mMutex); |
| 1880 | mPendingRequests = false; // to ignore past requests |
| 1881 | while (!mPendingRequests) { |
| 1882 | mCond.wait(mMutex); |
| 1883 | // TODO may also need an exitPending check |
| 1884 | } |
| 1885 | mPendingRequests = false; |
| 1886 | } |
| 1887 | // Execute the actual MediaLogService binder call and ignore extra requests for a while |
Glenn Kasten | 04b96fc | 2017-04-10 14:58:47 -0700 | [diff] [blame] | 1888 | sMediaLogService->requestMergeWakeup(); |
Nicolas Roulet | dcdfaec | 2017-02-14 10:18:39 -0800 | [diff] [blame] | 1889 | usleep(kPostTriggerSleepPeriod); |
| 1890 | return true; |
| 1891 | } |
| 1892 | |
| 1893 | void AudioFlinger::requestLogMerge() { |
| 1894 | mMediaLogNotifier->requestMerge(); |
| 1895 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1896 | |
| 1897 | // ---------------------------------------------------------------------------- |
| 1898 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1899 | sp<media::IAudioRecord> AudioFlinger::createRecord(const CreateRecordInput& input, |
| 1900 | CreateRecordOutput& output, |
| 1901 | status_t *status) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1902 | { |
| 1903 | sp<RecordThread::RecordTrack> recordTrack; |
| 1904 | sp<RecordHandle> recordHandle; |
| 1905 | sp<Client> client; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1906 | status_t lStatus; |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1907 | audio_session_t sessionId = input.sessionId; |
Eric Laurent | 77881cd | 2018-02-09 16:01:31 -0800 | [diff] [blame] | 1908 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1909 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1910 | output.cblk.clear(); |
| 1911 | output.buffers.clear(); |
Eric Laurent | 896c967 | 2017-12-08 14:08:45 -0800 | [diff] [blame] | 1912 | output.inputId = AUDIO_IO_HANDLE_NONE; |
Glenn Kasten | d776ac6 | 2014-05-07 09:16:09 -0700 | [diff] [blame] | 1913 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1914 | bool updatePid = (input.clientInfo.clientPid == -1); |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 1915 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1916 | uid_t clientUid = input.clientInfo.clientUid; |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 1917 | if (!isAudioServerOrMediaServerUid(callingUid)) { |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1918 | ALOGW_IF(clientUid != callingUid, |
| 1919 | "%s uid %d tried to pass itself off as %d", |
| 1920 | __FUNCTION__, callingUid, clientUid); |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 1921 | clientUid = callingUid; |
Haynes Mathew George | 9ea77cd | 2016-04-06 17:07:48 -0700 | [diff] [blame] | 1922 | updatePid = true; |
| 1923 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1924 | pid_t clientPid = input.clientInfo.clientPid; |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1925 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Haynes Mathew George | 9ea77cd | 2016-04-06 17:07:48 -0700 | [diff] [blame] | 1926 | if (updatePid) { |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1927 | ALOGW_IF(clientPid != -1 && clientPid != callingPid, |
Haynes Mathew George | 9ea77cd | 2016-04-06 17:07:48 -0700 | [diff] [blame] | 1928 | "%s uid %d pid %d tried to pass itself off as pid %d", |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1929 | __func__, callingUid, callingPid, clientPid); |
| 1930 | clientPid = callingPid; |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Andy Hung | 6770c6f | 2015-04-07 13:43:36 -0700 | [diff] [blame] | 1933 | // we don't yet support anything other than linear PCM |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1934 | if (!audio_is_valid_format(input.config.format) || !audio_is_linear_pcm(input.config.format)) { |
| 1935 | ALOGE("createRecord() invalid format %#x", input.config.format); |
Glenn Kasten | 291bb6d | 2013-07-16 17:23:39 -0700 | [diff] [blame] | 1936 | lStatus = BAD_VALUE; |
| 1937 | goto Exit; |
| 1938 | } |
| 1939 | |
Glenn Kasten | 53b5d09 | 2014-02-05 10:00:23 -0800 | [diff] [blame] | 1940 | // further channel mask checks are performed by createRecordTrack_l() |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1941 | if (!audio_is_input_channel(input.config.channel_mask)) { |
| 1942 | ALOGE("createRecord() invalid channel mask %#x", input.config.channel_mask); |
Glenn Kasten | 53b5d09 | 2014-02-05 10:00:23 -0800 | [diff] [blame] | 1943 | lStatus = BAD_VALUE; |
| 1944 | goto Exit; |
| 1945 | } |
| 1946 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1947 | if (sessionId == AUDIO_SESSION_ALLOCATE) { |
| 1948 | sessionId = (audio_session_t) newAudioUniqueId(AUDIO_UNIQUE_ID_USE_SESSION); |
| 1949 | } else if (audio_unique_id_get_use(sessionId) != AUDIO_UNIQUE_ID_USE_SESSION) { |
| 1950 | lStatus = BAD_VALUE; |
| 1951 | goto Exit; |
| 1952 | } |
| 1953 | |
| 1954 | output.sessionId = sessionId; |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1955 | output.selectedDeviceId = input.selectedDeviceId; |
| 1956 | output.flags = input.flags; |
| 1957 | |
| 1958 | client = registerPid(clientPid); |
| 1959 | |
| 1960 | // Not a conventional loop, but a retry loop for at most two iterations total. |
| 1961 | // Try first maybe with FAST flag then try again without FAST flag if that fails. |
| 1962 | // Exits loop via break on no error of got exit on error |
| 1963 | // The sp<> references will be dropped when re-entering scope. |
| 1964 | // The lack of indentation is deliberate, to reduce code churn and ease merges. |
| 1965 | for (;;) { |
Eric Laurent | 896c967 | 2017-12-08 14:08:45 -0800 | [diff] [blame] | 1966 | // release previously opened input if retrying. |
| 1967 | if (output.inputId != AUDIO_IO_HANDLE_NONE) { |
| 1968 | recordTrack.clear(); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1969 | AudioSystem::releaseInput(portId); |
Eric Laurent | 896c967 | 2017-12-08 14:08:45 -0800 | [diff] [blame] | 1970 | output.inputId = AUDIO_IO_HANDLE_NONE; |
Yung Ti Su | 5fac9c6 | 2018-05-15 15:07:43 +0800 | [diff] [blame] | 1971 | output.selectedDeviceId = input.selectedDeviceId; |
Eric Laurent | 77881cd | 2018-02-09 16:01:31 -0800 | [diff] [blame] | 1972 | portId = AUDIO_PORT_HANDLE_NONE; |
Eric Laurent | 896c967 | 2017-12-08 14:08:45 -0800 | [diff] [blame] | 1973 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1974 | lStatus = AudioSystem::getInputForAttr(&input.attr, &output.inputId, |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 1975 | input.riid, |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1976 | sessionId, |
| 1977 | // FIXME compare to AudioTrack |
| 1978 | clientPid, |
| 1979 | clientUid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1980 | input.opPackageName, |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1981 | &input.config, |
| 1982 | output.flags, &output.selectedDeviceId, &portId); |
jiabin | c1de2df | 2019-05-07 14:26:40 -0700 | [diff] [blame] | 1983 | if (lStatus != NO_ERROR) { |
| 1984 | ALOGE("createRecord() getInputForAttr return error %d", lStatus); |
| 1985 | goto Exit; |
| 1986 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1987 | |
Glenn Kasten | 05997e2 | 2014-03-13 15:08:33 -0700 | [diff] [blame] | 1988 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1989 | Mutex::Autolock _l(mLock); |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1990 | RecordThread *thread = checkRecordThread_l(output.inputId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1991 | if (thread == NULL) { |
jiabin | c1de2df | 2019-05-07 14:26:40 -0700 | [diff] [blame] | 1992 | ALOGE("createRecord() checkRecordThread_l failed, input handle %d", output.inputId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1993 | lStatus = BAD_VALUE; |
| 1994 | goto Exit; |
| 1995 | } |
| 1996 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1997 | ALOGV("createRecord() lSessionId: %d input %d", sessionId, output.inputId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1998 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1999 | output.sampleRate = input.config.sample_rate; |
| 2000 | output.frameCount = input.frameCount; |
| 2001 | output.notificationFrameCount = input.notificationFrameCount; |
Glenn Kasten | 570f633 | 2014-03-13 15:01:06 -0700 | [diff] [blame] | 2002 | |
Kevin Rocard | 1f564ac | 2018-03-29 13:53:10 -0700 | [diff] [blame] | 2003 | recordTrack = thread->createRecordTrack_l(client, input.attr, &output.sampleRate, |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 2004 | input.config.format, input.config.channel_mask, |
| 2005 | &output.frameCount, sessionId, |
| 2006 | &output.notificationFrameCount, |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 2007 | callingPid, clientUid, &output.flags, |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 2008 | input.clientInfo.clientTid, |
Jean-Michel Trivi | ddf87ef | 2019-08-20 15:42:04 -0700 | [diff] [blame] | 2009 | &lStatus, portId, |
| 2010 | input.opPackageName); |
Haynes Mathew George | 03e9e83 | 2013-12-13 15:40:13 -0800 | [diff] [blame] | 2011 | LOG_ALWAYS_FATAL_IF((lStatus == NO_ERROR) && (recordTrack == 0)); |
Eric Laurent | 1b92868 | 2014-10-02 19:41:47 -0700 | [diff] [blame] | 2012 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 2013 | // lStatus == BAD_TYPE means FAST flag was rejected: request a new input from |
| 2014 | // audio policy manager without FAST constraint |
| 2015 | if (lStatus == BAD_TYPE) { |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 2016 | continue; |
Eric Laurent | 1b92868 | 2014-10-02 19:41:47 -0700 | [diff] [blame] | 2017 | } |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 2018 | |
| 2019 | if (lStatus != NO_ERROR) { |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 2020 | goto Exit; |
| 2021 | } |
| 2022 | |
| 2023 | // Check if one effect chain was awaiting for an AudioRecord to be created on this |
| 2024 | // session and move it to this thread. |
| 2025 | sp<EffectChain> chain = getOrphanEffectChain_l(sessionId); |
| 2026 | if (chain != 0) { |
| 2027 | Mutex::Autolock _l(thread->mLock); |
| 2028 | thread->addEffectChain_l(chain); |
| 2029 | } |
| 2030 | break; |
| 2031 | } |
| 2032 | // End of retry loop. |
| 2033 | // The lack of indentation is deliberate, to reduce code churn and ease merges. |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2034 | } |
Glenn Kasten | e198c36 | 2013-08-13 09:13:36 -0700 | [diff] [blame] | 2035 | |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 2036 | output.cblk = recordTrack->getCblk(); |
| 2037 | output.buffers = recordTrack->getBuffers(); |
Eric Laurent | 973db02 | 2018-11-20 14:54:31 -0800 | [diff] [blame] | 2038 | output.portId = portId; |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 2039 | |
| 2040 | // return handle to client |
| 2041 | recordHandle = new RecordHandle(recordTrack); |
| 2042 | |
| 2043 | Exit: |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 2044 | if (lStatus != NO_ERROR) { |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 2045 | // remove local strong reference to Client before deleting the RecordTrack so that the |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 2046 | // Client destructor is called by the TrackBase destructor with mClientLock held |
Eric Laurent | fe1a94e | 2014-05-26 16:03:08 -0700 | [diff] [blame] | 2047 | // Don't hold mClientLock when releasing the reference on the track as the |
| 2048 | // destructor will acquire it. |
| 2049 | { |
| 2050 | Mutex::Autolock _cl(mClientLock); |
| 2051 | client.clear(); |
| 2052 | } |
Eric Laurent | 896c967 | 2017-12-08 14:08:45 -0800 | [diff] [blame] | 2053 | recordTrack.clear(); |
| 2054 | if (output.inputId != AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 2055 | AudioSystem::releaseInput(portId); |
Eric Laurent | 896c967 | 2017-12-08 14:08:45 -0800 | [diff] [blame] | 2056 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
Glenn Kasten | 9156ef3 | 2013-08-06 15:39:08 -0700 | [diff] [blame] | 2059 | *status = lStatus; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2060 | return recordHandle; |
| 2061 | } |
| 2062 | |
Eric Laurent | b8ba0a9 | 2011-08-07 16:32:26 -0700 | [diff] [blame] | 2063 | |
| 2064 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2065 | // ---------------------------------------------------------------------------- |
| 2066 | |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2067 | audio_module_handle_t AudioFlinger::loadHwModule(const char *name) |
| 2068 | { |
Eric Laurent | 44622db | 2014-08-01 19:00:33 -0700 | [diff] [blame] | 2069 | if (name == NULL) { |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 2070 | return AUDIO_MODULE_HANDLE_NONE; |
Eric Laurent | 44622db | 2014-08-01 19:00:33 -0700 | [diff] [blame] | 2071 | } |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2072 | if (!settingsAllowed()) { |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 2073 | return AUDIO_MODULE_HANDLE_NONE; |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2074 | } |
| 2075 | Mutex::Autolock _l(mLock); |
| 2076 | return loadHwModule_l(name); |
| 2077 | } |
| 2078 | |
| 2079 | // loadHwModule_l() must be called with AudioFlinger::mLock held |
| 2080 | audio_module_handle_t AudioFlinger::loadHwModule_l(const char *name) |
| 2081 | { |
| 2082 | for (size_t i = 0; i < mAudioHwDevs.size(); i++) { |
| 2083 | if (strncmp(mAudioHwDevs.valueAt(i)->moduleName(), name, strlen(name)) == 0) { |
| 2084 | ALOGW("loadHwModule() module %s already loaded", name); |
| 2085 | return mAudioHwDevs.keyAt(i); |
| 2086 | } |
| 2087 | } |
| 2088 | |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2089 | sp<DeviceHalInterface> dev; |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2090 | |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2091 | int rc = mDevicesFactoryHal->openDevice(name, &dev); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2092 | if (rc) { |
Glenn Kasten | c42e9b4 | 2016-03-21 11:35:03 -0700 | [diff] [blame] | 2093 | ALOGE("loadHwModule() error %d loading module %s", rc, name); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 2094 | return AUDIO_MODULE_HANDLE_NONE; |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | mHardwareStatus = AUDIO_HW_INIT; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2098 | rc = dev->initCheck(); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2099 | mHardwareStatus = AUDIO_HW_IDLE; |
| 2100 | if (rc) { |
Glenn Kasten | c42e9b4 | 2016-03-21 11:35:03 -0700 | [diff] [blame] | 2101 | ALOGE("loadHwModule() init check error %d for module %s", rc, name); |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 2102 | return AUDIO_MODULE_HANDLE_NONE; |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2103 | } |
| 2104 | |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 2105 | // Check and cache this HAL's level of support for master mute and master |
| 2106 | // volume. If this is the first HAL opened, and it supports the get |
| 2107 | // methods, use the initial values provided by the HAL as the current |
| 2108 | // master mute and volume settings. |
| 2109 | |
| 2110 | AudioHwDevice::Flags flags = static_cast<AudioHwDevice::Flags>(0); |
| 2111 | { // scope for auto-lock pattern |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2112 | AutoMutex lock(mHardwareLock); |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 2113 | |
| 2114 | if (0 == mAudioHwDevs.size()) { |
| 2115 | mHardwareStatus = AUDIO_HW_GET_MASTER_VOLUME; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2116 | float mv; |
| 2117 | if (OK == dev->getMasterVolume(&mv)) { |
| 2118 | mMasterVolume = mv; |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | mHardwareStatus = AUDIO_HW_GET_MASTER_MUTE; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2122 | bool mm; |
| 2123 | if (OK == dev->getMasterMute(&mm)) { |
| 2124 | mMasterMute = mm; |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 2125 | } |
| 2126 | } |
| 2127 | |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2128 | mHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2129 | if (OK == dev->setMasterVolume(mMasterVolume)) { |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 2130 | flags = static_cast<AudioHwDevice::Flags>(flags | |
| 2131 | AudioHwDevice::AHWD_CAN_SET_MASTER_VOLUME); |
| 2132 | } |
| 2133 | |
| 2134 | mHardwareStatus = AUDIO_HW_SET_MASTER_MUTE; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2135 | if (OK == dev->setMasterMute(mMasterMute)) { |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 2136 | flags = static_cast<AudioHwDevice::Flags>(flags | |
| 2137 | AudioHwDevice::AHWD_CAN_SET_MASTER_MUTE); |
| 2138 | } |
| 2139 | |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2140 | mHardwareStatus = AUDIO_HW_IDLE; |
| 2141 | } |
Mikhail Naganov | 97373b0 | 2018-07-23 13:27:24 -0700 | [diff] [blame] | 2142 | if (strcmp(name, AUDIO_HARDWARE_MODULE_ID_MSD) == 0) { |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 2143 | // An MSD module is inserted before hardware modules in order to mix encoded streams. |
| 2144 | flags = static_cast<AudioHwDevice::Flags>(flags | AudioHwDevice::AHWD_IS_INSERT); |
| 2145 | } |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2146 | |
Glenn Kasten | a13cde9 | 2016-03-28 15:26:02 -0700 | [diff] [blame] | 2147 | audio_module_handle_t handle = (audio_module_handle_t) nextUniqueId(AUDIO_UNIQUE_ID_USE_MODULE); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2148 | mAudioHwDevs.add(handle, new AudioHwDevice(handle, name, dev, flags)); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2149 | |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2150 | ALOGI("loadHwModule() Loaded %s audio interface, handle %d", name, handle); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2151 | |
| 2152 | return handle; |
| 2153 | |
| 2154 | } |
| 2155 | |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 2156 | // ---------------------------------------------------------------------------- |
| 2157 | |
Glenn Kasten | 3b16c76 | 2012-11-14 08:44:39 -0800 | [diff] [blame] | 2158 | uint32_t AudioFlinger::getPrimaryOutputSamplingRate() |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 2159 | { |
| 2160 | Mutex::Autolock _l(mLock); |
Glenn Kasten | a733563 | 2016-06-09 17:09:53 -0700 | [diff] [blame] | 2161 | PlaybackThread *thread = fastPlaybackThread_l(); |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 2162 | return thread != NULL ? thread->sampleRate() : 0; |
| 2163 | } |
| 2164 | |
Glenn Kasten | e33054e | 2012-11-14 12:54:39 -0800 | [diff] [blame] | 2165 | size_t AudioFlinger::getPrimaryOutputFrameCount() |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 2166 | { |
| 2167 | Mutex::Autolock _l(mLock); |
Glenn Kasten | a733563 | 2016-06-09 17:09:53 -0700 | [diff] [blame] | 2168 | PlaybackThread *thread = fastPlaybackThread_l(); |
Glenn Kasten | cc0f1cf | 2012-09-24 11:27:18 -0700 | [diff] [blame] | 2169 | return thread != NULL ? thread->frameCountHAL() : 0; |
| 2170 | } |
| 2171 | |
| 2172 | // ---------------------------------------------------------------------------- |
| 2173 | |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 2174 | status_t AudioFlinger::setLowRamDevice(bool isLowRamDevice, int64_t totalMemory) |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 2175 | { |
| 2176 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 2177 | if (!isAudioServerOrSystemServerUid(uid)) { |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 2178 | return PERMISSION_DENIED; |
| 2179 | } |
| 2180 | Mutex::Autolock _l(mLock); |
| 2181 | if (mIsDeviceTypeKnown) { |
| 2182 | return INVALID_OPERATION; |
| 2183 | } |
| 2184 | mIsLowRamDevice = isLowRamDevice; |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 2185 | mTotalMemory = totalMemory; |
| 2186 | // mIsLowRamDevice and mTotalMemory are obtained through ActivityManager; |
| 2187 | // see ActivityManager.isLowRamDevice() and ActivityManager.getMemoryInfo(). |
| 2188 | // mIsLowRamDevice generally represent devices with less than 1GB of memory, |
| 2189 | // though actual setting is determined through device configuration. |
| 2190 | constexpr int64_t GB = 1024 * 1024 * 1024; |
| 2191 | mClientSharedHeapSize = |
| 2192 | isLowRamDevice ? kMinimumClientSharedHeapSizeBytes |
| 2193 | : mTotalMemory < 2 * GB ? 4 * kMinimumClientSharedHeapSizeBytes |
| 2194 | : mTotalMemory < 3 * GB ? 8 * kMinimumClientSharedHeapSizeBytes |
| 2195 | : mTotalMemory < 4 * GB ? 16 * kMinimumClientSharedHeapSizeBytes |
| 2196 | : 32 * kMinimumClientSharedHeapSizeBytes; |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 2197 | mIsDeviceTypeKnown = true; |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 2198 | |
| 2199 | // TODO: Cache the client shared heap size in a persistent property. |
| 2200 | // It's possible that a native process or Java service or app accesses audioserver |
| 2201 | // after it is registered by system server, but before AudioService updates |
| 2202 | // the memory info. This would occur immediately after boot or an audioserver |
| 2203 | // crash and restore. Before update from AudioService, the client would get the |
| 2204 | // minimum heap size. |
| 2205 | |
| 2206 | ALOGD("isLowRamDevice:%s totalMemory:%lld mClientSharedHeapSize:%zu", |
| 2207 | (isLowRamDevice ? "true" : "false"), |
| 2208 | (long long)mTotalMemory, |
| 2209 | mClientSharedHeapSize.load()); |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 2210 | return NO_ERROR; |
| 2211 | } |
| 2212 | |
Andy Hung | 6f248bb | 2018-01-23 14:04:37 -0800 | [diff] [blame] | 2213 | size_t AudioFlinger::getClientSharedHeapSize() const |
| 2214 | { |
| 2215 | size_t heapSizeInBytes = property_get_int32("ro.af.client_heap_size_kbyte", 0) * 1024; |
| 2216 | if (heapSizeInBytes != 0) { // read-only property overrides all. |
| 2217 | return heapSizeInBytes; |
| 2218 | } |
| 2219 | return mClientSharedHeapSize; |
| 2220 | } |
| 2221 | |
Mikhail Naganov | dea5304 | 2018-04-26 13:10:21 -0700 | [diff] [blame] | 2222 | status_t AudioFlinger::setAudioPortConfig(const struct audio_port_config *config) |
| 2223 | { |
| 2224 | ALOGV(__func__); |
| 2225 | |
| 2226 | audio_module_handle_t module; |
| 2227 | if (config->type == AUDIO_PORT_TYPE_DEVICE) { |
| 2228 | module = config->ext.device.hw_module; |
| 2229 | } else { |
| 2230 | module = config->ext.mix.hw_module; |
| 2231 | } |
| 2232 | |
| 2233 | Mutex::Autolock _l(mLock); |
| 2234 | ssize_t index = mAudioHwDevs.indexOfKey(module); |
| 2235 | if (index < 0) { |
| 2236 | ALOGW("%s() bad hw module %d", __func__, module); |
| 2237 | return BAD_VALUE; |
| 2238 | } |
| 2239 | |
| 2240 | AudioHwDevice *audioHwDevice = mAudioHwDevs.valueAt(index); |
| 2241 | return audioHwDevice->hwDevice()->setAudioPortConfig(config); |
| 2242 | } |
| 2243 | |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 2244 | audio_hw_sync_t AudioFlinger::getAudioHwSyncForSession(audio_session_t sessionId) |
| 2245 | { |
| 2246 | Mutex::Autolock _l(mLock); |
Eric Laurent | fa90e84 | 2014-10-17 18:12:31 -0700 | [diff] [blame] | 2247 | |
| 2248 | ssize_t index = mHwAvSyncIds.indexOfKey(sessionId); |
| 2249 | if (index >= 0) { |
| 2250 | ALOGV("getAudioHwSyncForSession found ID %d for session %d", |
| 2251 | mHwAvSyncIds.valueAt(index), sessionId); |
| 2252 | return mHwAvSyncIds.valueAt(index); |
| 2253 | } |
| 2254 | |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2255 | sp<DeviceHalInterface> dev = mPrimaryHardwareDev->hwDevice(); |
Eric Laurent | fa90e84 | 2014-10-17 18:12:31 -0700 | [diff] [blame] | 2256 | if (dev == NULL) { |
| 2257 | return AUDIO_HW_SYNC_INVALID; |
| 2258 | } |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2259 | String8 reply; |
| 2260 | AudioParameter param; |
Mikhail Naganov | 00260b5 | 2016-10-13 12:54:24 -0700 | [diff] [blame] | 2261 | if (dev->getParameters(String8(AudioParameter::keyHwAvSync), &reply) == OK) { |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2262 | param = AudioParameter(reply); |
| 2263 | } |
Eric Laurent | fa90e84 | 2014-10-17 18:12:31 -0700 | [diff] [blame] | 2264 | |
| 2265 | int value; |
Mikhail Naganov | 00260b5 | 2016-10-13 12:54:24 -0700 | [diff] [blame] | 2266 | if (param.getInt(String8(AudioParameter::keyHwAvSync), value) != NO_ERROR) { |
Eric Laurent | fa90e84 | 2014-10-17 18:12:31 -0700 | [diff] [blame] | 2267 | ALOGW("getAudioHwSyncForSession error getting sync for session %d", sessionId); |
| 2268 | return AUDIO_HW_SYNC_INVALID; |
| 2269 | } |
| 2270 | |
| 2271 | // allow only one session for a given HW A/V sync ID. |
| 2272 | for (size_t i = 0; i < mHwAvSyncIds.size(); i++) { |
| 2273 | if (mHwAvSyncIds.valueAt(i) == (audio_hw_sync_t)value) { |
| 2274 | ALOGV("getAudioHwSyncForSession removing ID %d for session %d", |
| 2275 | value, mHwAvSyncIds.keyAt(i)); |
| 2276 | mHwAvSyncIds.removeItemsAt(i); |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 2277 | break; |
| 2278 | } |
| 2279 | } |
Eric Laurent | fa90e84 | 2014-10-17 18:12:31 -0700 | [diff] [blame] | 2280 | |
| 2281 | mHwAvSyncIds.add(sessionId, value); |
| 2282 | |
| 2283 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 2284 | sp<PlaybackThread> thread = mPlaybackThreads.valueAt(i); |
| 2285 | uint32_t sessions = thread->hasAudioSession(sessionId); |
Eric Laurent | 4c41506 | 2016-06-17 16:14:16 -0700 | [diff] [blame] | 2286 | if (sessions & ThreadBase::TRACK_SESSION) { |
Eric Laurent | fa90e84 | 2014-10-17 18:12:31 -0700 | [diff] [blame] | 2287 | AudioParameter param = AudioParameter(); |
Mikhail Naganov | 00260b5 | 2016-10-13 12:54:24 -0700 | [diff] [blame] | 2288 | param.addInt(String8(AudioParameter::keyStreamHwAvSync), value); |
Mikhail Naganov | b261ef5 | 2018-07-16 13:34:38 -0700 | [diff] [blame] | 2289 | String8 keyValuePairs = param.toString(); |
| 2290 | thread->setParameters(keyValuePairs); |
| 2291 | forwardParametersToDownstreamPatches_l(thread->id(), keyValuePairs, |
| 2292 | [](const sp<PlaybackThread>& thread) { return thread->usesHwAvSync(); }); |
Eric Laurent | fa90e84 | 2014-10-17 18:12:31 -0700 | [diff] [blame] | 2293 | break; |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | ALOGV("getAudioHwSyncForSession adding ID %d for session %d", value, sessionId); |
| 2298 | return (audio_hw_sync_t)value; |
Eric Laurent | 93c3d41 | 2014-08-01 14:48:35 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 2301 | status_t AudioFlinger::systemReady() |
| 2302 | { |
| 2303 | Mutex::Autolock _l(mLock); |
| 2304 | ALOGI("%s", __FUNCTION__); |
| 2305 | if (mSystemReady) { |
| 2306 | ALOGW("%s called twice", __FUNCTION__); |
| 2307 | return NO_ERROR; |
| 2308 | } |
| 2309 | mSystemReady = true; |
| 2310 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 2311 | ThreadBase *thread = (ThreadBase *)mPlaybackThreads.valueAt(i).get(); |
| 2312 | thread->systemReady(); |
| 2313 | } |
| 2314 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
| 2315 | ThreadBase *thread = (ThreadBase *)mRecordThreads.valueAt(i).get(); |
| 2316 | thread->systemReady(); |
| 2317 | } |
| 2318 | return NO_ERROR; |
| 2319 | } |
| 2320 | |
jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 2321 | status_t AudioFlinger::getMicrophones(std::vector<media::MicrophoneInfo> *microphones) |
| 2322 | { |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 2323 | AutoMutex lock(mHardwareLock); |
| 2324 | sp<DeviceHalInterface> dev = mPrimaryHardwareDev->hwDevice(); |
| 2325 | status_t status = dev->getMicrophones(microphones); |
| 2326 | return status; |
jiabin | 46a76fa | 2018-01-05 10:18:21 -0800 | [diff] [blame] | 2327 | } |
| 2328 | |
Eric Laurent | fa90e84 | 2014-10-17 18:12:31 -0700 | [diff] [blame] | 2329 | // setAudioHwSyncForSession_l() must be called with AudioFlinger::mLock held |
| 2330 | void AudioFlinger::setAudioHwSyncForSession_l(PlaybackThread *thread, audio_session_t sessionId) |
| 2331 | { |
| 2332 | ssize_t index = mHwAvSyncIds.indexOfKey(sessionId); |
| 2333 | if (index >= 0) { |
| 2334 | audio_hw_sync_t syncId = mHwAvSyncIds.valueAt(index); |
| 2335 | ALOGV("setAudioHwSyncForSession_l found ID %d for session %d", syncId, sessionId); |
| 2336 | AudioParameter param = AudioParameter(); |
Mikhail Naganov | 00260b5 | 2016-10-13 12:54:24 -0700 | [diff] [blame] | 2337 | param.addInt(String8(AudioParameter::keyStreamHwAvSync), syncId); |
Mikhail Naganov | b261ef5 | 2018-07-16 13:34:38 -0700 | [diff] [blame] | 2338 | String8 keyValuePairs = param.toString(); |
| 2339 | thread->setParameters(keyValuePairs); |
| 2340 | forwardParametersToDownstreamPatches_l(thread->id(), keyValuePairs, |
| 2341 | [](const sp<PlaybackThread>& thread) { return thread->usesHwAvSync(); }); |
Eric Laurent | fa90e84 | 2014-10-17 18:12:31 -0700 | [diff] [blame] | 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | |
Glenn Kasten | 4182c4e | 2013-07-15 14:45:07 -0700 | [diff] [blame] | 2346 | // ---------------------------------------------------------------------------- |
| 2347 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2348 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2349 | sp<AudioFlinger::ThreadBase> AudioFlinger::openOutput_l(audio_module_handle_t module, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 2350 | audio_io_handle_t *output, |
| 2351 | audio_config_t *config, |
| 2352 | audio_devices_t deviceType, |
| 2353 | const String8& address, |
| 2354 | audio_output_flags_t flags) |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2355 | { |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 2356 | AudioHwDevice *outHwDev = findSuitableHwDev_l(module, deviceType); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2357 | if (outHwDev == NULL) { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2358 | return 0; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2361 | if (*output == AUDIO_IO_HANDLE_NONE) { |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 2362 | *output = nextUniqueId(AUDIO_UNIQUE_ID_USE_OUTPUT); |
| 2363 | } else { |
| 2364 | // Audio Policy does not currently request a specific output handle. |
| 2365 | // If this is ever needed, see openInput_l() for example code. |
| 2366 | ALOGE("openOutput_l requested output handle %d is not AUDIO_IO_HANDLE_NONE", *output); |
| 2367 | return 0; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2368 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2369 | |
| 2370 | mHardwareStatus = AUDIO_HW_OUTPUT_OPEN; |
| 2371 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2372 | // FOR TESTING ONLY: |
Andy Hung | 9a59276 | 2014-07-21 21:56:01 -0700 | [diff] [blame] | 2373 | // This if statement allows overriding the audio policy settings |
| 2374 | // and forcing a specific format or channel mask to the HAL/Sink device for testing. |
| 2375 | if (!(flags & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD | AUDIO_OUTPUT_FLAG_DIRECT))) { |
| 2376 | // Check only for Normal Mixing mode |
| 2377 | if (kEnableExtendedPrecision) { |
| 2378 | // Specify format (uncomment one below to choose) |
| 2379 | //config->format = AUDIO_FORMAT_PCM_FLOAT; |
| 2380 | //config->format = AUDIO_FORMAT_PCM_24_BIT_PACKED; |
| 2381 | //config->format = AUDIO_FORMAT_PCM_32_BIT; |
| 2382 | //config->format = AUDIO_FORMAT_PCM_8_24_BIT; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2383 | // ALOGV("openOutput_l() upgrading format to %#08x", config->format); |
Andy Hung | 9a59276 | 2014-07-21 21:56:01 -0700 | [diff] [blame] | 2384 | } |
| 2385 | if (kEnableExtendedChannels) { |
| 2386 | // Specify channel mask (uncomment one below to choose) |
| 2387 | //config->channel_mask = audio_channel_out_mask_from_count(4); // for USB 4ch |
| 2388 | //config->channel_mask = audio_channel_mask_from_representation_and_bits( |
| 2389 | // AUDIO_CHANNEL_REPRESENTATION_INDEX, (1 << 4) - 1); // another 4ch example |
| 2390 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2391 | } |
| 2392 | |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 2393 | AudioStreamOut *outputStream = NULL; |
| 2394 | status_t status = outHwDev->openOutputStream( |
| 2395 | &outputStream, |
| 2396 | *output, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 2397 | deviceType, |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 2398 | flags, |
| 2399 | config, |
| 2400 | address.string()); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2401 | |
| 2402 | mHardwareStatus = AUDIO_HW_IDLE; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2403 | |
Phil Burk | 062e67a | 2015-02-11 13:40:50 -0800 | [diff] [blame] | 2404 | if (status == NO_ERROR) { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2405 | if (flags & AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) { |
| 2406 | sp<MmapPlaybackThread> thread = |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2407 | new MmapPlaybackThread(this, *output, outHwDev, outputStream, mSystemReady); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2408 | mMmapThreads.add(*output, thread); |
| 2409 | ALOGV("openOutput_l() created mmap playback thread: ID %d thread %p", |
| 2410 | *output, thread.get()); |
| 2411 | return thread; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2412 | } else { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2413 | sp<PlaybackThread> thread; |
| 2414 | if (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) { |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2415 | thread = new OffloadThread(this, outputStream, *output, mSystemReady); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2416 | ALOGV("openOutput_l() created offload output: ID %d thread %p", |
| 2417 | *output, thread.get()); |
| 2418 | } else if ((flags & AUDIO_OUTPUT_FLAG_DIRECT) |
| 2419 | || !isValidPcmSinkFormat(config->format) |
| 2420 | || !isValidPcmSinkChannelMask(config->channel_mask)) { |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2421 | thread = new DirectOutputThread(this, outputStream, *output, mSystemReady); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2422 | ALOGV("openOutput_l() created direct output: ID %d thread %p", |
| 2423 | *output, thread.get()); |
| 2424 | } else { |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2425 | thread = new MixerThread(this, outputStream, *output, mSystemReady); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2426 | ALOGV("openOutput_l() created mixer output: ID %d thread %p", |
| 2427 | *output, thread.get()); |
| 2428 | } |
| 2429 | mPlaybackThreads.add(*output, thread); |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 2430 | mPatchPanel.notifyStreamOpened(outHwDev, *output); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2431 | return thread; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2432 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | return 0; |
| 2436 | } |
| 2437 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2438 | status_t AudioFlinger::openOutput(audio_module_handle_t module, |
| 2439 | audio_io_handle_t *output, |
| 2440 | audio_config_t *config, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 2441 | const sp<DeviceDescriptorBase>& device, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2442 | uint32_t *latencyMs, |
| 2443 | audio_output_flags_t flags) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2444 | { |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 2445 | ALOGI("openOutput() this %p, module %d Device %s, SamplingRate %d, Format %#08x, " |
Glenn Kasten | 49f36ba | 2017-12-06 13:02:02 -0800 | [diff] [blame] | 2446 | "Channels %#x, flags %#x", |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2447 | this, module, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 2448 | device->toString().c_str(), |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2449 | config->sample_rate, |
| 2450 | config->format, |
| 2451 | config->channel_mask, |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2452 | flags); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2453 | |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 2454 | audio_devices_t deviceType = device->type(); |
| 2455 | const String8 address = String8(device->address().c_str()); |
| 2456 | |
| 2457 | if (deviceType == AUDIO_DEVICE_NONE) { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2458 | return BAD_VALUE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2459 | } |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 2460 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2461 | Mutex::Autolock _l(mLock); |
| 2462 | |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 2463 | sp<ThreadBase> thread = openOutput_l(module, output, config, deviceType, address, flags); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2464 | if (thread != 0) { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2465 | if ((flags & AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) == 0) { |
| 2466 | PlaybackThread *playbackThread = (PlaybackThread *)thread.get(); |
| 2467 | *latencyMs = playbackThread->latency(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2468 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2469 | // notify client processes of the new output creation |
| 2470 | playbackThread->ioConfigChanged(AUDIO_OUTPUT_OPENED); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2471 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2472 | // the first primary output opened designates the primary hw device |
| 2473 | if ((mPrimaryHardwareDev == NULL) && (flags & AUDIO_OUTPUT_FLAG_PRIMARY)) { |
Glenn Kasten | 1bfe09a | 2017-02-21 13:05:56 -0800 | [diff] [blame] | 2474 | ALOGI("Using module %d as the primary audio interface", module); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2475 | mPrimaryHardwareDev = playbackThread->getOutput()->audioHwDev; |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2476 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2477 | AutoMutex lock(mHardwareLock); |
| 2478 | mHardwareStatus = AUDIO_HW_SET_MODE; |
| 2479 | mPrimaryHardwareDev->hwDevice()->setMode(mMode); |
| 2480 | mHardwareStatus = AUDIO_HW_IDLE; |
| 2481 | } |
| 2482 | } else { |
| 2483 | MmapThread *mmapThread = (MmapThread *)thread.get(); |
| 2484 | mmapThread->ioConfigChanged(AUDIO_OUTPUT_OPENED); |
Eric Laurent | a4c5a55 | 2012-03-29 10:12:40 -0700 | [diff] [blame] | 2485 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2486 | return NO_ERROR; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2487 | } |
| 2488 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2489 | return NO_INIT; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2490 | } |
| 2491 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 2492 | audio_io_handle_t AudioFlinger::openDuplicateOutput(audio_io_handle_t output1, |
| 2493 | audio_io_handle_t output2) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2494 | { |
| 2495 | Mutex::Autolock _l(mLock); |
| 2496 | MixerThread *thread1 = checkMixerThread_l(output1); |
| 2497 | MixerThread *thread2 = checkMixerThread_l(output2); |
| 2498 | |
| 2499 | if (thread1 == NULL || thread2 == NULL) { |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 2500 | ALOGW("openDuplicateOutput() wrong output mixer type for output %d or %d", output1, |
| 2501 | output2); |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 2502 | return AUDIO_IO_HANDLE_NONE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 2505 | audio_io_handle_t id = nextUniqueId(AUDIO_UNIQUE_ID_USE_OUTPUT); |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 2506 | DuplicatingThread *thread = new DuplicatingThread(this, thread1, id, mSystemReady); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2507 | thread->addOutputTrack(thread2); |
| 2508 | mPlaybackThreads.add(id, thread); |
| 2509 | // notify client processes of the new output creation |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 2510 | thread->ioConfigChanged(AUDIO_OUTPUT_OPENED); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2511 | return id; |
| 2512 | } |
| 2513 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 2514 | status_t AudioFlinger::closeOutput(audio_io_handle_t output) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2515 | { |
Glenn Kasten | d96c572 | 2012-04-25 13:44:49 -0700 | [diff] [blame] | 2516 | return closeOutput_nonvirtual(output); |
| 2517 | } |
| 2518 | |
| 2519 | status_t AudioFlinger::closeOutput_nonvirtual(audio_io_handle_t output) |
| 2520 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2521 | // keep strong reference on the playback thread so that |
| 2522 | // it is not destroyed while exit() is executed |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2523 | sp<PlaybackThread> playbackThread; |
| 2524 | sp<MmapPlaybackThread> mmapThread; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2525 | { |
| 2526 | Mutex::Autolock _l(mLock); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2527 | playbackThread = checkPlaybackThread_l(output); |
| 2528 | if (playbackThread != NULL) { |
| 2529 | ALOGV("closeOutput() %d", output); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2530 | |
Andy Hung | dc099c2 | 2018-09-18 13:46:39 -0700 | [diff] [blame] | 2531 | dumpToThreadLog_l(playbackThread); |
Andy Hung | a8115dc | 2018-08-24 15:51:59 -0700 | [diff] [blame] | 2532 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2533 | if (playbackThread->type() == ThreadBase::MIXER) { |
| 2534 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 2535 | if (mPlaybackThreads.valueAt(i)->isDuplicating()) { |
| 2536 | DuplicatingThread *dupThread = |
| 2537 | (DuplicatingThread *)mPlaybackThreads.valueAt(i).get(); |
| 2538 | dupThread->removeOutputTrack((MixerThread *)playbackThread.get()); |
| 2539 | } |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 2540 | } |
| 2541 | } |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 2542 | |
| 2543 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2544 | mPlaybackThreads.removeItem(output); |
| 2545 | // save all effects to the default thread |
| 2546 | if (mPlaybackThreads.size()) { |
| 2547 | PlaybackThread *dstThread = checkPlaybackThread_l(mPlaybackThreads.keyAt(0)); |
| 2548 | if (dstThread != NULL) { |
Glenn Kasten | d3bb645 | 2016-12-05 18:14:37 -0800 | [diff] [blame] | 2549 | // audioflinger lock is held so order of thread lock acquisition doesn't matter |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2550 | Mutex::Autolock _dl(dstThread->mLock); |
| 2551 | Mutex::Autolock _sl(playbackThread->mLock); |
| 2552 | Vector< sp<EffectChain> > effectChains = playbackThread->getEffectChains_l(); |
| 2553 | for (size_t i = 0; i < effectChains.size(); i ++) { |
Glenn Kasten | d3bb645 | 2016-12-05 18:14:37 -0800 | [diff] [blame] | 2554 | moveEffectChain_l(effectChains[i]->sessionId(), playbackThread.get(), |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 2555 | dstThread); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2556 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2557 | } |
| 2558 | } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2559 | } else { |
| 2560 | mmapThread = (MmapPlaybackThread *)checkMmapThread_l(output); |
| 2561 | if (mmapThread == 0) { |
| 2562 | return BAD_VALUE; |
| 2563 | } |
Andy Hung | dc099c2 | 2018-09-18 13:46:39 -0700 | [diff] [blame] | 2564 | dumpToThreadLog_l(mmapThread); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2565 | mMmapThreads.removeItem(output); |
Phil Burk | 7f6b40d | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 2566 | ALOGD("closing mmapThread %p", mmapThread.get()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2567 | } |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 2568 | const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor(); |
| 2569 | ioDesc->mIoHandle = output; |
| 2570 | ioConfigChanged(AUDIO_OUTPUT_CLOSED, ioDesc); |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 2571 | mPatchPanel.notifyStreamClosed(output); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2572 | } |
Glenn Kasten | b28686f | 2012-01-06 08:39:38 -0800 | [diff] [blame] | 2573 | // The thread entity (active unit of execution) is no longer running here, |
| 2574 | // but the ThreadBase container still exists. |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2575 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2576 | if (playbackThread != 0) { |
| 2577 | playbackThread->exit(); |
| 2578 | if (!playbackThread->isDuplicating()) { |
| 2579 | closeOutputFinish(playbackThread); |
| 2580 | } |
| 2581 | } else if (mmapThread != 0) { |
Phil Burk | 7f6b40d | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 2582 | ALOGD("mmapThread exit()"); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2583 | mmapThread->exit(); |
| 2584 | AudioStreamOut *out = mmapThread->clearOutput(); |
| 2585 | ALOG_ASSERT(out != NULL, "out shouldn't be NULL"); |
| 2586 | // from now on thread->mOutput is NULL |
| 2587 | delete out; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2588 | } |
| 2589 | return NO_ERROR; |
| 2590 | } |
| 2591 | |
Chih-Hung Hsieh | 36d0ca1 | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 2592 | void AudioFlinger::closeOutputFinish(const sp<PlaybackThread>& thread) |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2593 | { |
| 2594 | AudioStreamOut *out = thread->clearOutput(); |
| 2595 | ALOG_ASSERT(out != NULL, "out shouldn't be NULL"); |
| 2596 | // from now on thread->mOutput is NULL |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2597 | delete out; |
| 2598 | } |
| 2599 | |
Mikhail Naganov | 444ecc3 | 2018-05-01 17:40:05 -0700 | [diff] [blame] | 2600 | void AudioFlinger::closeThreadInternal_l(const sp<PlaybackThread>& thread) |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2601 | { |
| 2602 | mPlaybackThreads.removeItem(thread->mId); |
| 2603 | thread->exit(); |
| 2604 | closeOutputFinish(thread); |
| 2605 | } |
| 2606 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 2607 | status_t AudioFlinger::suspendOutput(audio_io_handle_t output) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2608 | { |
| 2609 | Mutex::Autolock _l(mLock); |
| 2610 | PlaybackThread *thread = checkPlaybackThread_l(output); |
| 2611 | |
| 2612 | if (thread == NULL) { |
| 2613 | return BAD_VALUE; |
| 2614 | } |
| 2615 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2616 | ALOGV("suspendOutput() %d", output); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2617 | thread->suspend(); |
| 2618 | |
| 2619 | return NO_ERROR; |
| 2620 | } |
| 2621 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 2622 | status_t AudioFlinger::restoreOutput(audio_io_handle_t output) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2623 | { |
| 2624 | Mutex::Autolock _l(mLock); |
| 2625 | PlaybackThread *thread = checkPlaybackThread_l(output); |
| 2626 | |
| 2627 | if (thread == NULL) { |
| 2628 | return BAD_VALUE; |
| 2629 | } |
| 2630 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2631 | ALOGV("restoreOutput() %d", output); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2632 | |
| 2633 | thread->restore(); |
| 2634 | |
| 2635 | return NO_ERROR; |
| 2636 | } |
| 2637 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2638 | status_t AudioFlinger::openInput(audio_module_handle_t module, |
| 2639 | audio_io_handle_t *input, |
| 2640 | audio_config_t *config, |
Glenn Kasten | e7d6671 | 2015-03-05 13:46:52 -0800 | [diff] [blame] | 2641 | audio_devices_t *devices, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2642 | const String8& address, |
| 2643 | audio_source_t source, |
Glenn Kasten | ec40d28 | 2014-07-15 15:31:26 -0700 | [diff] [blame] | 2644 | audio_input_flags_t flags) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2645 | { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2646 | Mutex::Autolock _l(mLock); |
| 2647 | |
Glenn Kasten | e7d6671 | 2015-03-05 13:46:52 -0800 | [diff] [blame] | 2648 | if (*devices == AUDIO_DEVICE_NONE) { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2649 | return BAD_VALUE; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2650 | } |
| 2651 | |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 2652 | sp<ThreadBase> thread = openInput_l( |
| 2653 | module, input, config, *devices, address, source, flags, AUDIO_DEVICE_NONE, String8{}); |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2654 | |
| 2655 | if (thread != 0) { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2656 | // notify client processes of the new input creation |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 2657 | thread->ioConfigChanged(AUDIO_INPUT_OPENED); |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2658 | return NO_ERROR; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2659 | } |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2660 | return NO_INIT; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2661 | } |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 2662 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2663 | sp<AudioFlinger::ThreadBase> AudioFlinger::openInput_l(audio_module_handle_t module, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2664 | audio_io_handle_t *input, |
| 2665 | audio_config_t *config, |
Glenn Kasten | e7d6671 | 2015-03-05 13:46:52 -0800 | [diff] [blame] | 2666 | audio_devices_t devices, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2667 | const String8& address, |
| 2668 | audio_source_t source, |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 2669 | audio_input_flags_t flags, |
| 2670 | audio_devices_t outputDevice, |
| 2671 | const String8& outputDeviceAddress) |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2672 | { |
Glenn Kasten | e7d6671 | 2015-03-05 13:46:52 -0800 | [diff] [blame] | 2673 | AudioHwDevice *inHwDev = findSuitableHwDev_l(module, devices); |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 2674 | if (inHwDev == NULL) { |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2675 | *input = AUDIO_IO_HANDLE_NONE; |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 2676 | return 0; |
Glenn Kasten | 6e2ebe9 | 2013-08-13 09:14:51 -0700 | [diff] [blame] | 2677 | } |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 2678 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 2679 | // Audio Policy can request a specific handle for hardware hotword. |
| 2680 | // The goal here is not to re-open an already opened input. |
| 2681 | // It is to use a pre-assigned I/O handle. |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2682 | if (*input == AUDIO_IO_HANDLE_NONE) { |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 2683 | *input = nextUniqueId(AUDIO_UNIQUE_ID_USE_INPUT); |
| 2684 | } else if (audio_unique_id_get_use(*input) != AUDIO_UNIQUE_ID_USE_INPUT) { |
| 2685 | ALOGE("openInput_l() requested input handle %d is invalid", *input); |
| 2686 | return 0; |
| 2687 | } else if (mRecordThreads.indexOfKey(*input) >= 0) { |
| 2688 | // This should not happen in a transient state with current design. |
| 2689 | ALOGE("openInput_l() requested input handle %d is already assigned", *input); |
| 2690 | return 0; |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2691 | } |
Eric Laurent | f7ffb8b | 2012-04-14 09:06:57 -0700 | [diff] [blame] | 2692 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2693 | audio_config_t halconfig = *config; |
Mikhail Naganov | e4f1f63 | 2016-08-31 11:35:10 -0700 | [diff] [blame] | 2694 | sp<DeviceHalInterface> inHwHal = inHwDev->hwDevice(); |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 2695 | sp<StreamInHalInterface> inStream; |
| 2696 | status_t status = inHwHal->openInputStream( |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 2697 | *input, devices, &halconfig, flags, address.string(), source, |
| 2698 | outputDevice, outputDeviceAddress, &inStream); |
Glenn Kasten | 49f36ba | 2017-12-06 13:02:02 -0800 | [diff] [blame] | 2699 | ALOGV("openInput_l() openInputStream returned input %p, devices %#x, SamplingRate %d" |
| 2700 | ", Format %#x, Channels %#x, flags %#x, status %d addr %s", |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 2701 | inStream.get(), |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 2702 | devices, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2703 | halconfig.sample_rate, |
| 2704 | halconfig.format, |
| 2705 | halconfig.channel_mask, |
Glenn Kasten | ec40d28 | 2014-07-15 15:31:26 -0700 | [diff] [blame] | 2706 | flags, |
Jean-Michel Trivi | fd4c148 | 2014-08-06 16:02:28 -0700 | [diff] [blame] | 2707 | status, address.string()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2708 | |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 2709 | // If the input could not be opened with the requested parameters and we can handle the |
Andy Hung | 6770c6f | 2015-04-07 13:43:36 -0700 | [diff] [blame] | 2710 | // conversion internally, try to open again with the proposed parameters. |
Eric Laurent | f7ffb8b | 2012-04-14 09:06:57 -0700 | [diff] [blame] | 2711 | if (status == BAD_VALUE && |
Andy Hung | 6770c6f | 2015-04-07 13:43:36 -0700 | [diff] [blame] | 2712 | audio_is_linear_pcm(config->format) && |
| 2713 | audio_is_linear_pcm(halconfig.format) && |
| 2714 | (halconfig.sample_rate <= AUDIO_RESAMPLER_DOWN_RATIO_MAX * config->sample_rate) && |
vivek mehta | 7534666 | 2016-05-04 18:45:46 -0700 | [diff] [blame] | 2715 | (audio_channel_count_from_in_mask(halconfig.channel_mask) <= FCC_8) && |
| 2716 | (audio_channel_count_from_in_mask(config->channel_mask) <= FCC_8)) { |
Glenn Kasten | 8594843 | 2013-08-19 12:09:05 -0700 | [diff] [blame] | 2717 | // FIXME describe the change proposed by HAL (save old values so we can log them here) |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2718 | ALOGV("openInput_l() reopening with proposed sampling rate and channel mask"); |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 2719 | inStream.clear(); |
| 2720 | status = inHwHal->openInputStream( |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 2721 | *input, devices, &halconfig, flags, address.string(), source, |
| 2722 | outputDevice, outputDeviceAddress, &inStream); |
Glenn Kasten | 8594843 | 2013-08-19 12:09:05 -0700 | [diff] [blame] | 2723 | // FIXME log this new status; HAL should not propose any further changes |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 2726 | if (status == NO_ERROR && inStream != 0) { |
Eric Laurent | 0506778 | 2016-06-01 18:27:28 -0700 | [diff] [blame] | 2727 | AudioStreamIn *inputStream = new AudioStreamIn(inHwDev, inStream, flags); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2728 | if ((flags & AUDIO_INPUT_FLAG_MMAP_NOIRQ) != 0) { |
| 2729 | sp<MmapCaptureThread> thread = |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2730 | new MmapCaptureThread(this, *input, inHwDev, inputStream, mSystemReady); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2731 | mMmapThreads.add(*input, thread); |
Glenn Kasten | d3bb645 | 2016-12-05 18:14:37 -0800 | [diff] [blame] | 2732 | ALOGV("openInput_l() created mmap capture thread: ID %d thread %p", *input, |
| 2733 | thread.get()); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2734 | return thread; |
| 2735 | } else { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2736 | // Start record thread |
| 2737 | // RecordThread requires both input and output device indication to forward to audio |
| 2738 | // pre processing modules |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2739 | sp<RecordThread> thread = new RecordThread(this, inputStream, *input, mSystemReady); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2740 | mRecordThreads.add(*input, thread); |
| 2741 | ALOGV("openInput_l() created record thread: ID %d thread %p", *input, thread.get()); |
| 2742 | return thread; |
| 2743 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 2746 | *input = AUDIO_IO_HANDLE_NONE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2747 | return 0; |
| 2748 | } |
| 2749 | |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 2750 | status_t AudioFlinger::closeInput(audio_io_handle_t input) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2751 | { |
Glenn Kasten | d96c572 | 2012-04-25 13:44:49 -0700 | [diff] [blame] | 2752 | return closeInput_nonvirtual(input); |
| 2753 | } |
| 2754 | |
| 2755 | status_t AudioFlinger::closeInput_nonvirtual(audio_io_handle_t input) |
| 2756 | { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2757 | // keep strong reference on the record thread so that |
| 2758 | // it is not destroyed while exit() is executed |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2759 | sp<RecordThread> recordThread; |
| 2760 | sp<MmapCaptureThread> mmapThread; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2761 | { |
| 2762 | Mutex::Autolock _l(mLock); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2763 | recordThread = checkRecordThread_l(input); |
| 2764 | if (recordThread != 0) { |
| 2765 | ALOGV("closeInput() %d", input); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2766 | |
Andy Hung | dc099c2 | 2018-09-18 13:46:39 -0700 | [diff] [blame] | 2767 | dumpToThreadLog_l(recordThread); |
Andy Hung | 0264e7d | 2018-09-17 19:30:46 -0700 | [diff] [blame] | 2768 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2769 | // If we still have effect chains, it means that a client still holds a handle |
| 2770 | // on at least one effect. We must either move the chain to an existing thread with the |
| 2771 | // same session ID or put it aside in case a new record thread is opened for a |
| 2772 | // new capture on the same session |
| 2773 | sp<EffectChain> chain; |
| 2774 | { |
| 2775 | Mutex::Autolock _sl(recordThread->mLock); |
| 2776 | Vector< sp<EffectChain> > effectChains = recordThread->getEffectChains_l(); |
| 2777 | // Note: maximum one chain per record thread |
| 2778 | if (effectChains.size() != 0) { |
| 2779 | chain = effectChains[0]; |
Eric Laurent | 1b92868 | 2014-10-02 19:41:47 -0700 | [diff] [blame] | 2780 | } |
| 2781 | } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2782 | if (chain != 0) { |
Glenn Kasten | d3bb645 | 2016-12-05 18:14:37 -0800 | [diff] [blame] | 2783 | // first check if a record thread is already opened with a client on same session. |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2784 | // This should only happen in case of overlap between one thread tear down and the |
| 2785 | // creation of its replacement |
| 2786 | size_t i; |
| 2787 | for (i = 0; i < mRecordThreads.size(); i++) { |
| 2788 | sp<RecordThread> t = mRecordThreads.valueAt(i); |
| 2789 | if (t == recordThread) { |
| 2790 | continue; |
| 2791 | } |
| 2792 | if (t->hasAudioSession(chain->sessionId()) != 0) { |
| 2793 | Mutex::Autolock _l(t->mLock); |
| 2794 | ALOGV("closeInput() found thread %d for effect session %d", |
| 2795 | t->id(), chain->sessionId()); |
| 2796 | t->addEffectChain_l(chain); |
| 2797 | break; |
| 2798 | } |
| 2799 | } |
Glenn Kasten | d3bb645 | 2016-12-05 18:14:37 -0800 | [diff] [blame] | 2800 | // put the chain aside if we could not find a record thread with the same session id |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2801 | if (i == mRecordThreads.size()) { |
| 2802 | putOrphanEffectChain_l(chain); |
| 2803 | } |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 2804 | } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2805 | mRecordThreads.removeItem(input); |
| 2806 | } else { |
| 2807 | mmapThread = (MmapCaptureThread *)checkMmapThread_l(input); |
| 2808 | if (mmapThread == 0) { |
| 2809 | return BAD_VALUE; |
| 2810 | } |
Andy Hung | dc099c2 | 2018-09-18 13:46:39 -0700 | [diff] [blame] | 2811 | dumpToThreadLog_l(mmapThread); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2812 | mMmapThreads.removeItem(input); |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 2813 | } |
Eric Laurent | 73e26b6 | 2015-04-27 16:55:58 -0700 | [diff] [blame] | 2814 | const sp<AudioIoDescriptor> ioDesc = new AudioIoDescriptor(); |
| 2815 | ioDesc->mIoHandle = input; |
| 2816 | ioConfigChanged(AUDIO_INPUT_CLOSED, ioDesc); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2817 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2818 | // FIXME: calling thread->exit() without mLock held should not be needed anymore now that |
| 2819 | // we have a different lock for notification client |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2820 | if (recordThread != 0) { |
| 2821 | closeInputFinish(recordThread); |
| 2822 | } else if (mmapThread != 0) { |
| 2823 | mmapThread->exit(); |
| 2824 | AudioStreamIn *in = mmapThread->clearInput(); |
| 2825 | ALOG_ASSERT(in != NULL, "in shouldn't be NULL"); |
| 2826 | // from now on thread->mInput is NULL |
| 2827 | delete in; |
| 2828 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2829 | return NO_ERROR; |
| 2830 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2831 | |
Chih-Hung Hsieh | 36d0ca1 | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 2832 | void AudioFlinger::closeInputFinish(const sp<RecordThread>& thread) |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2833 | { |
| 2834 | thread->exit(); |
Eric Laurent | b8ba0a9 | 2011-08-07 16:32:26 -0700 | [diff] [blame] | 2835 | AudioStreamIn *in = thread->clearInput(); |
Glenn Kasten | 5798d4e | 2012-03-08 12:18:35 -0800 | [diff] [blame] | 2836 | ALOG_ASSERT(in != NULL, "in shouldn't be NULL"); |
Eric Laurent | b8ba0a9 | 2011-08-07 16:32:26 -0700 | [diff] [blame] | 2837 | // from now on thread->mInput is NULL |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 2838 | delete in; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2839 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2840 | |
Mikhail Naganov | 444ecc3 | 2018-05-01 17:40:05 -0700 | [diff] [blame] | 2841 | void AudioFlinger::closeThreadInternal_l(const sp<RecordThread>& thread) |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 2842 | { |
| 2843 | mRecordThreads.removeItem(thread->mId); |
| 2844 | closeInputFinish(thread); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
Glenn Kasten | d2304db | 2014-02-03 07:40:31 -0800 | [diff] [blame] | 2847 | status_t AudioFlinger::invalidateStream(audio_stream_type_t stream) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2848 | { |
| 2849 | Mutex::Autolock _l(mLock); |
Glenn Kasten | d2304db | 2014-02-03 07:40:31 -0800 | [diff] [blame] | 2850 | ALOGV("invalidateStream() stream %d", stream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2851 | |
| 2852 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 2853 | PlaybackThread *thread = mPlaybackThreads.valueAt(i).get(); |
Eric Laurent | 2216785 | 2012-06-20 12:26:32 -0700 | [diff] [blame] | 2854 | thread->invalidateTracks(stream); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 2855 | } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2856 | for (size_t i = 0; i < mMmapThreads.size(); i++) { |
| 2857 | mMmapThreads[i]->invalidateTracks(stream); |
| 2858 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2859 | return NO_ERROR; |
| 2860 | } |
| 2861 | |
| 2862 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 2863 | audio_unique_id_t AudioFlinger::newAudioUniqueId(audio_unique_id_use_t use) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2864 | { |
Glenn Kasten | 9d00313 | 2016-04-06 14:38:09 -0700 | [diff] [blame] | 2865 | // This is a binder API, so a malicious client could pass in a bad parameter. |
| 2866 | // Check for that before calling the internal API nextUniqueId(). |
| 2867 | if ((unsigned) use >= (unsigned) AUDIO_UNIQUE_ID_USE_MAX) { |
| 2868 | ALOGE("newAudioUniqueId invalid use %d", use); |
| 2869 | return AUDIO_UNIQUE_ID_ALLOCATE; |
| 2870 | } |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 2871 | return nextUniqueId(use); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 2874 | void AudioFlinger::acquireAudioSessionId(audio_session_t audioSession, pid_t pid) |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2875 | { |
| 2876 | Mutex::Autolock _l(mLock); |
Glenn Kasten | bb00192 | 2012-02-03 11:10:26 -0800 | [diff] [blame] | 2877 | pid_t caller = IPCThreadState::self()->getCallingPid(); |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 2878 | ALOGV("acquiring %d from %d, for %d", audioSession, caller, pid); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 2879 | const uid_t callerUid = IPCThreadState::self()->getCallingUid(); |
| 2880 | if (pid != -1 && isAudioServerUid(callerUid)) { // check must match releaseAudioSessionId() |
Marco Nelissen | d457c97 | 2014-02-11 08:47:07 -0800 | [diff] [blame] | 2881 | caller = pid; |
| 2882 | } |
Eric Laurent | d1b28d4 | 2013-09-18 18:47:13 -0700 | [diff] [blame] | 2883 | |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 2884 | { |
| 2885 | Mutex::Autolock _cl(mClientLock); |
| 2886 | // Ignore requests received from processes not known as notification client. The request |
| 2887 | // is likely proxied by mediaserver (e.g CameraService) and releaseAudioSessionId() can be |
| 2888 | // called from a different pid leaving a stale session reference. Also we don't know how |
| 2889 | // to clear this reference if the client process dies. |
| 2890 | if (mNotificationClients.indexOfKey(caller) < 0) { |
| 2891 | ALOGW("acquireAudioSessionId() unknown client %d for session %d", caller, audioSession); |
| 2892 | return; |
| 2893 | } |
Eric Laurent | d1b28d4 | 2013-09-18 18:47:13 -0700 | [diff] [blame] | 2894 | } |
| 2895 | |
Glenn Kasten | 8d6a244 | 2012-02-08 14:04:28 -0800 | [diff] [blame] | 2896 | size_t num = mAudioSessionRefs.size(); |
Eric Laurent | 0d5a2ed | 2016-12-01 15:28:29 -0800 | [diff] [blame] | 2897 | for (size_t i = 0; i < num; i++) { |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2898 | AudioSessionRef *ref = mAudioSessionRefs.editItemAt(i); |
Glenn Kasten | 012ca6b | 2012-03-06 11:22:01 -0800 | [diff] [blame] | 2899 | if (ref->mSessionid == audioSession && ref->mPid == caller) { |
| 2900 | ref->mCnt++; |
| 2901 | ALOGV(" incremented refcount to %d", ref->mCnt); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2902 | return; |
| 2903 | } |
| 2904 | } |
Glenn Kasten | 84afa3b | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 2905 | mAudioSessionRefs.push(new AudioSessionRef(audioSession, caller)); |
| 2906 | ALOGV(" added new entry for %d", audioSession); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2907 | } |
| 2908 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 2909 | void AudioFlinger::releaseAudioSessionId(audio_session_t audioSession, pid_t pid) |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2910 | { |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 2911 | std::vector< sp<EffectModule> > removedEffects; |
| 2912 | { |
| 2913 | Mutex::Autolock _l(mLock); |
| 2914 | pid_t caller = IPCThreadState::self()->getCallingPid(); |
| 2915 | ALOGV("releasing %d from %d for %d", audioSession, caller, pid); |
| 2916 | const uid_t callerUid = IPCThreadState::self()->getCallingUid(); |
| 2917 | if (pid != -1 && isAudioServerUid(callerUid)) { // check must match acquireAudioSessionId() |
| 2918 | caller = pid; |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2919 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 2920 | size_t num = mAudioSessionRefs.size(); |
| 2921 | for (size_t i = 0; i < num; i++) { |
| 2922 | AudioSessionRef *ref = mAudioSessionRefs.itemAt(i); |
| 2923 | if (ref->mSessionid == audioSession && ref->mPid == caller) { |
| 2924 | ref->mCnt--; |
| 2925 | ALOGV(" decremented refcount to %d", ref->mCnt); |
| 2926 | if (ref->mCnt == 0) { |
| 2927 | mAudioSessionRefs.removeAt(i); |
| 2928 | delete ref; |
| 2929 | std::vector< sp<EffectModule> > effects = purgeStaleEffects_l(); |
| 2930 | removedEffects.insert(removedEffects.end(), effects.begin(), effects.end()); |
| 2931 | } |
| 2932 | goto Exit; |
| 2933 | } |
| 2934 | } |
| 2935 | // If the caller is audioserver it is likely that the session being released was acquired |
| 2936 | // on behalf of a process not in notification clients and we ignore the warning. |
| 2937 | ALOGW_IF(!isAudioServerUid(callerUid), |
| 2938 | "session id %d not found for pid %d", audioSession, caller); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2939 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 2940 | |
| 2941 | Exit: |
| 2942 | for (auto& effect : removedEffects) { |
| 2943 | effect->updatePolicyState(); |
| 2944 | } |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
Eric Laurent | 0d5a2ed | 2016-12-01 15:28:29 -0800 | [diff] [blame] | 2947 | bool AudioFlinger::isSessionAcquired_l(audio_session_t audioSession) |
| 2948 | { |
| 2949 | size_t num = mAudioSessionRefs.size(); |
| 2950 | for (size_t i = 0; i < num; i++) { |
| 2951 | AudioSessionRef *ref = mAudioSessionRefs.itemAt(i); |
| 2952 | if (ref->mSessionid == audioSession) { |
| 2953 | return true; |
| 2954 | } |
| 2955 | } |
| 2956 | return false; |
| 2957 | } |
| 2958 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 2959 | std::vector<sp<AudioFlinger::EffectModule>> AudioFlinger::purgeStaleEffects_l() { |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2960 | |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2961 | ALOGV("purging stale effects"); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2962 | |
| 2963 | Vector< sp<EffectChain> > chains; |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 2964 | std::vector< sp<EffectModule> > removedEffects; |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2965 | |
| 2966 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 2967 | sp<PlaybackThread> t = mPlaybackThreads.valueAt(i); |
Mateusz Kaplon | 2a6e1b0 | 2017-03-30 16:50:50 +0200 | [diff] [blame] | 2968 | Mutex::Autolock _l(t->mLock); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2969 | for (size_t j = 0; j < t->mEffectChains.size(); j++) { |
| 2970 | sp<EffectChain> ec = t->mEffectChains[j]; |
Eric Laurent | 3f75a5b | 2019-11-12 15:55:51 -0800 | [diff] [blame] | 2971 | if (!audio_is_global_session(ec->sessionId())) { |
Marco Nelissen | 0270b18 | 2011-08-12 14:14:39 -0700 | [diff] [blame] | 2972 | chains.push(ec); |
| 2973 | } |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2974 | } |
| 2975 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 2976 | |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2977 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
| 2978 | sp<RecordThread> t = mRecordThreads.valueAt(i); |
Mateusz Kaplon | 2a6e1b0 | 2017-03-30 16:50:50 +0200 | [diff] [blame] | 2979 | Mutex::Autolock _l(t->mLock); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2980 | for (size_t j = 0; j < t->mEffectChains.size(); j++) { |
| 2981 | sp<EffectChain> ec = t->mEffectChains[j]; |
| 2982 | chains.push(ec); |
| 2983 | } |
| 2984 | } |
| 2985 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 2986 | for (size_t i = 0; i < mMmapThreads.size(); i++) { |
| 2987 | sp<MmapThread> t = mMmapThreads.valueAt(i); |
| 2988 | Mutex::Autolock _l(t->mLock); |
| 2989 | for (size_t j = 0; j < t->mEffectChains.size(); j++) { |
| 2990 | sp<EffectChain> ec = t->mEffectChains[j]; |
| 2991 | chains.push(ec); |
| 2992 | } |
| 2993 | } |
| 2994 | |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2995 | for (size_t i = 0; i < chains.size(); i++) { |
| 2996 | sp<EffectChain> ec = chains[i]; |
| 2997 | int sessionid = ec->sessionId(); |
Eric Laurent | 6b446ce | 2019-12-13 10:56:31 -0800 | [diff] [blame] | 2998 | sp<ThreadBase> t = ec->thread().promote(); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 2999 | if (t == 0) { |
| 3000 | continue; |
| 3001 | } |
| 3002 | size_t numsessionrefs = mAudioSessionRefs.size(); |
| 3003 | bool found = false; |
| 3004 | for (size_t k = 0; k < numsessionrefs; k++) { |
| 3005 | AudioSessionRef *ref = mAudioSessionRefs.itemAt(k); |
Glenn Kasten | 012ca6b | 2012-03-06 11:22:01 -0800 | [diff] [blame] | 3006 | if (ref->mSessionid == sessionid) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3007 | ALOGV(" session %d still exists for %d with %d refs", |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 3008 | sessionid, ref->mPid, ref->mCnt); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 3009 | found = true; |
| 3010 | break; |
| 3011 | } |
| 3012 | } |
| 3013 | if (!found) { |
Glenn Kasten | e198c36 | 2013-08-13 09:13:36 -0700 | [diff] [blame] | 3014 | Mutex::Autolock _l(t->mLock); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 3015 | // remove all effects from the chain |
| 3016 | while (ec->mEffects.size()) { |
| 3017 | sp<EffectModule> effect = ec->mEffects[0]; |
| 3018 | effect->unPin(); |
Mikhail Naganov | 424c4f5 | 2017-07-19 17:54:29 -0700 | [diff] [blame] | 3019 | t->removeEffect_l(effect, /*release*/ true); |
Eric Laurent | a5f44eb | 2012-06-25 11:38:29 -0700 | [diff] [blame] | 3020 | if (effect->purgeHandles()) { |
Eric Laurent | 6b446ce | 2019-12-13 10:56:31 -0800 | [diff] [blame] | 3021 | effect->checkSuspendOnEffectEnabled(false, true /*threadLocked*/); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 3022 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 3023 | removedEffects.push_back(effect); |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 3024 | } |
| 3025 | } |
| 3026 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 3027 | return removedEffects; |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 3028 | } |
| 3029 | |
Andy Hung | dc099c2 | 2018-09-18 13:46:39 -0700 | [diff] [blame] | 3030 | // dumpToThreadLog_l() must be called with AudioFlinger::mLock held |
| 3031 | void AudioFlinger::dumpToThreadLog_l(const sp<ThreadBase> &thread) |
| 3032 | { |
| 3033 | audio_utils::FdToString fdToString; |
| 3034 | const int fd = fdToString.fd(); |
| 3035 | if (fd >= 0) { |
| 3036 | thread->dump(fd, {} /* args */); |
| 3037 | mThreadLog.logs(-1 /* time */, fdToString.getStringAndClose()); |
| 3038 | } |
| 3039 | } |
| 3040 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 3041 | // checkThread_l() must be called with AudioFlinger::mLock held |
| 3042 | AudioFlinger::ThreadBase *AudioFlinger::checkThread_l(audio_io_handle_t ioHandle) const |
| 3043 | { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 3044 | ThreadBase *thread = checkMmapThread_l(ioHandle); |
| 3045 | if (thread == 0) { |
| 3046 | switch (audio_unique_id_get_use(ioHandle)) { |
| 3047 | case AUDIO_UNIQUE_ID_USE_OUTPUT: |
| 3048 | thread = checkPlaybackThread_l(ioHandle); |
| 3049 | break; |
| 3050 | case AUDIO_UNIQUE_ID_USE_INPUT: |
| 3051 | thread = checkRecordThread_l(ioHandle); |
| 3052 | break; |
| 3053 | default: |
| 3054 | break; |
| 3055 | } |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 3056 | } |
| 3057 | return thread; |
| 3058 | } |
| 3059 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3060 | // checkPlaybackThread_l() must be called with AudioFlinger::mLock held |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 3061 | AudioFlinger::PlaybackThread *AudioFlinger::checkPlaybackThread_l(audio_io_handle_t output) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3062 | { |
Glenn Kasten | a111792 | 2012-01-26 10:53:32 -0800 | [diff] [blame] | 3063 | return mPlaybackThreads.valueFor(output).get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | // checkMixerThread_l() must be called with AudioFlinger::mLock held |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 3067 | AudioFlinger::MixerThread *AudioFlinger::checkMixerThread_l(audio_io_handle_t output) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3068 | { |
| 3069 | PlaybackThread *thread = checkPlaybackThread_l(output); |
Glenn Kasten | a111792 | 2012-01-26 10:53:32 -0800 | [diff] [blame] | 3070 | return thread != NULL && thread->type() != ThreadBase::DIRECT ? (MixerThread *) thread : NULL; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | // checkRecordThread_l() must be called with AudioFlinger::mLock held |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 3074 | AudioFlinger::RecordThread *AudioFlinger::checkRecordThread_l(audio_io_handle_t input) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3075 | { |
Glenn Kasten | a111792 | 2012-01-26 10:53:32 -0800 | [diff] [blame] | 3076 | return mRecordThreads.valueFor(input).get(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 3079 | // checkMmapThread_l() must be called with AudioFlinger::mLock held |
| 3080 | AudioFlinger::MmapThread *AudioFlinger::checkMmapThread_l(audio_io_handle_t io) const |
| 3081 | { |
| 3082 | return mMmapThreads.valueFor(io).get(); |
| 3083 | } |
| 3084 | |
| 3085 | |
| 3086 | // checkPlaybackThread_l() must be called with AudioFlinger::mLock held |
| 3087 | AudioFlinger::VolumeInterface *AudioFlinger::getVolumeInterface_l(audio_io_handle_t output) const |
| 3088 | { |
Eric Laurent | 7459b90 | 2017-04-19 18:10:41 -0700 | [diff] [blame] | 3089 | VolumeInterface *volumeInterface = mPlaybackThreads.valueFor(output).get(); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 3090 | if (volumeInterface == nullptr) { |
| 3091 | MmapThread *mmapThread = mMmapThreads.valueFor(output).get(); |
| 3092 | if (mmapThread != nullptr) { |
| 3093 | if (mmapThread->isOutput()) { |
Eric Laurent | 7459b90 | 2017-04-19 18:10:41 -0700 | [diff] [blame] | 3094 | MmapPlaybackThread *mmapPlaybackThread = |
| 3095 | static_cast<MmapPlaybackThread *>(mmapThread); |
| 3096 | volumeInterface = mmapPlaybackThread; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 3097 | } |
| 3098 | } |
| 3099 | } |
| 3100 | return volumeInterface; |
| 3101 | } |
| 3102 | |
| 3103 | Vector <AudioFlinger::VolumeInterface *> AudioFlinger::getAllVolumeInterfaces_l() const |
| 3104 | { |
| 3105 | Vector <VolumeInterface *> volumeInterfaces; |
| 3106 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
Eric Laurent | 7459b90 | 2017-04-19 18:10:41 -0700 | [diff] [blame] | 3107 | volumeInterfaces.add(mPlaybackThreads.valueAt(i).get()); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 3108 | } |
| 3109 | for (size_t i = 0; i < mMmapThreads.size(); i++) { |
| 3110 | if (mMmapThreads.valueAt(i)->isOutput()) { |
Eric Laurent | 7459b90 | 2017-04-19 18:10:41 -0700 | [diff] [blame] | 3111 | MmapPlaybackThread *mmapPlaybackThread = |
| 3112 | static_cast<MmapPlaybackThread *>(mMmapThreads.valueAt(i).get()); |
| 3113 | volumeInterfaces.add(mmapPlaybackThread); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 3114 | } |
| 3115 | } |
| 3116 | return volumeInterfaces; |
| 3117 | } |
| 3118 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 3119 | audio_unique_id_t AudioFlinger::nextUniqueId(audio_unique_id_use_t use) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3120 | { |
Glenn Kasten | 9d00313 | 2016-04-06 14:38:09 -0700 | [diff] [blame] | 3121 | // This is the internal API, so it is OK to assert on bad parameter. |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 3122 | LOG_ALWAYS_FATAL_IF((unsigned) use >= (unsigned) AUDIO_UNIQUE_ID_USE_MAX); |
Glenn Kasten | d2e67e1 | 2016-04-11 08:26:37 -0700 | [diff] [blame] | 3123 | const int maxRetries = use == AUDIO_UNIQUE_ID_USE_SESSION ? 3 : 1; |
| 3124 | for (int retry = 0; retry < maxRetries; retry++) { |
| 3125 | // The cast allows wraparound from max positive to min negative instead of abort |
| 3126 | uint32_t base = (uint32_t) atomic_fetch_add_explicit(&mNextUniqueIds[use], |
| 3127 | (uint_fast32_t) AUDIO_UNIQUE_ID_USE_MAX, memory_order_acq_rel); |
| 3128 | ALOG_ASSERT(audio_unique_id_get_use(base) == AUDIO_UNIQUE_ID_USE_UNSPECIFIED); |
| 3129 | // allow wrap by skipping 0 and -1 for session ids |
| 3130 | if (!(base == 0 || base == (~0u & ~AUDIO_UNIQUE_ID_USE_MASK))) { |
| 3131 | ALOGW_IF(retry != 0, "unique ID overflow for use %d", use); |
| 3132 | return (audio_unique_id_t) (base | use); |
| 3133 | } |
| 3134 | } |
| 3135 | // We have no way of recovering from wraparound |
| 3136 | LOG_ALWAYS_FATAL("unique ID overflow for use %d", use); |
| 3137 | // TODO Use a floor after wraparound. This may need a mutex. |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
Glenn Kasten | 02fe1bf | 2012-02-24 15:42:17 -0800 | [diff] [blame] | 3140 | AudioFlinger::PlaybackThread *AudioFlinger::primaryPlaybackThread_l() const |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 3141 | { |
| 3142 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 3143 | PlaybackThread *thread = mPlaybackThreads.valueAt(i).get(); |
Eric Laurent | f6870ae | 2015-05-08 10:50:03 -0700 | [diff] [blame] | 3144 | if(thread->isDuplicating()) { |
| 3145 | continue; |
| 3146 | } |
Eric Laurent | b8ba0a9 | 2011-08-07 16:32:26 -0700 | [diff] [blame] | 3147 | AudioStreamOut *output = thread->getOutput(); |
John Grossman | ee578c0 | 2012-07-23 17:05:46 -0700 | [diff] [blame] | 3148 | if (output != NULL && output->audioHwDev == mPrimaryHardwareDev) { |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 3149 | return thread; |
| 3150 | } |
| 3151 | } |
| 3152 | return NULL; |
| 3153 | } |
| 3154 | |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 3155 | DeviceTypeSet AudioFlinger::primaryOutputDevice_l() const |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 3156 | { |
| 3157 | PlaybackThread *thread = primaryPlaybackThread_l(); |
| 3158 | |
| 3159 | if (thread == NULL) { |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 3160 | return DeviceTypeSet(); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 3161 | } |
| 3162 | |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 3163 | return thread->outDeviceTypes(); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 3164 | } |
| 3165 | |
Glenn Kasten | a733563 | 2016-06-09 17:09:53 -0700 | [diff] [blame] | 3166 | AudioFlinger::PlaybackThread *AudioFlinger::fastPlaybackThread_l() const |
| 3167 | { |
| 3168 | size_t minFrameCount = 0; |
| 3169 | PlaybackThread *minThread = NULL; |
| 3170 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 3171 | PlaybackThread *thread = mPlaybackThreads.valueAt(i).get(); |
| 3172 | if (!thread->isDuplicating()) { |
| 3173 | size_t frameCount = thread->frameCountHAL(); |
| 3174 | if (frameCount != 0 && (minFrameCount == 0 || frameCount < minFrameCount || |
| 3175 | (frameCount == minFrameCount && thread->hasFastMixer() && |
| 3176 | /*minThread != NULL &&*/ !minThread->hasFastMixer()))) { |
| 3177 | minFrameCount = frameCount; |
| 3178 | minThread = thread; |
| 3179 | } |
| 3180 | } |
| 3181 | } |
| 3182 | return minThread; |
| 3183 | } |
| 3184 | |
Eric Laurent | a011e35 | 2012-03-29 15:51:43 -0700 | [diff] [blame] | 3185 | sp<AudioFlinger::SyncEvent> AudioFlinger::createSyncEvent(AudioSystem::sync_event_t type, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 3186 | audio_session_t triggerSession, |
| 3187 | audio_session_t listenerSession, |
Eric Laurent | a011e35 | 2012-03-29 15:51:43 -0700 | [diff] [blame] | 3188 | sync_event_callback_t callBack, |
Chih-Hung Hsieh | 36d0ca1 | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 3189 | const wp<RefBase>& cookie) |
Eric Laurent | a011e35 | 2012-03-29 15:51:43 -0700 | [diff] [blame] | 3190 | { |
| 3191 | Mutex::Autolock _l(mLock); |
| 3192 | |
| 3193 | sp<SyncEvent> event = new SyncEvent(type, triggerSession, listenerSession, callBack, cookie); |
| 3194 | status_t playStatus = NAME_NOT_FOUND; |
| 3195 | status_t recStatus = NAME_NOT_FOUND; |
| 3196 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 3197 | playStatus = mPlaybackThreads.valueAt(i)->setSyncEvent(event); |
| 3198 | if (playStatus == NO_ERROR) { |
| 3199 | return event; |
| 3200 | } |
| 3201 | } |
| 3202 | for (size_t i = 0; i < mRecordThreads.size(); i++) { |
| 3203 | recStatus = mRecordThreads.valueAt(i)->setSyncEvent(event); |
| 3204 | if (recStatus == NO_ERROR) { |
| 3205 | return event; |
| 3206 | } |
| 3207 | } |
| 3208 | if (playStatus == NAME_NOT_FOUND || recStatus == NAME_NOT_FOUND) { |
| 3209 | mPendingSyncEvents.add(event); |
| 3210 | } else { |
| 3211 | ALOGV("createSyncEvent() invalid event %d", event->type()); |
| 3212 | event.clear(); |
| 3213 | } |
| 3214 | return event; |
| 3215 | } |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 3216 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3217 | // ---------------------------------------------------------------------------- |
| 3218 | // Effect management |
| 3219 | // ---------------------------------------------------------------------------- |
| 3220 | |
Mikhail Naganov | 4a3d5c2 | 2016-08-15 13:47:42 -0700 | [diff] [blame] | 3221 | sp<EffectsFactoryHalInterface> AudioFlinger::getEffectsFactory() { |
| 3222 | return mEffectsFactoryHal; |
| 3223 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3224 | |
Glenn Kasten | f587ba5 | 2012-01-26 16:25:10 -0800 | [diff] [blame] | 3225 | status_t AudioFlinger::queryNumberEffects(uint32_t *numEffects) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3226 | { |
| 3227 | Mutex::Autolock _l(mLock); |
Mikhail Naganov | 4a3d5c2 | 2016-08-15 13:47:42 -0700 | [diff] [blame] | 3228 | if (mEffectsFactoryHal.get()) { |
| 3229 | return mEffectsFactoryHal->queryNumberEffects(numEffects); |
| 3230 | } else { |
| 3231 | return -ENODEV; |
| 3232 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
Glenn Kasten | f587ba5 | 2012-01-26 16:25:10 -0800 | [diff] [blame] | 3235 | status_t AudioFlinger::queryEffect(uint32_t index, effect_descriptor_t *descriptor) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3236 | { |
| 3237 | Mutex::Autolock _l(mLock); |
Mikhail Naganov | 4a3d5c2 | 2016-08-15 13:47:42 -0700 | [diff] [blame] | 3238 | if (mEffectsFactoryHal.get()) { |
| 3239 | return mEffectsFactoryHal->getDescriptor(index, descriptor); |
| 3240 | } else { |
| 3241 | return -ENODEV; |
| 3242 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
Glenn Kasten | 5e92a78 | 2012-01-30 07:40:52 -0800 | [diff] [blame] | 3245 | status_t AudioFlinger::getEffectDescriptor(const effect_uuid_t *pUuid, |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 3246 | const effect_uuid_t *pTypeUuid, |
| 3247 | uint32_t preferredTypeFlag, |
| 3248 | effect_descriptor_t *descriptor) const |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3249 | { |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 3250 | if (pUuid == NULL || pTypeUuid == NULL || descriptor == NULL) { |
| 3251 | return BAD_VALUE; |
| 3252 | } |
| 3253 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3254 | Mutex::Autolock _l(mLock); |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 3255 | |
| 3256 | if (!mEffectsFactoryHal.get()) { |
Mikhail Naganov | 4a3d5c2 | 2016-08-15 13:47:42 -0700 | [diff] [blame] | 3257 | return -ENODEV; |
| 3258 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3259 | |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 3260 | status_t status = NO_ERROR; |
| 3261 | if (!EffectsFactoryHalInterface::isNullUuid(pUuid)) { |
| 3262 | // If uuid is specified, request effect descriptor from that. |
| 3263 | status = mEffectsFactoryHal->getDescriptor(pUuid, descriptor); |
| 3264 | } else if (!EffectsFactoryHalInterface::isNullUuid(pTypeUuid)) { |
| 3265 | // If uuid is not specified, look for an available implementation |
| 3266 | // of the required type instead. |
| 3267 | |
| 3268 | // Use a temporary descriptor to avoid modifying |descriptor| in the failure case. |
| 3269 | effect_descriptor_t desc; |
| 3270 | desc.flags = 0; // prevent compiler warning |
| 3271 | |
| 3272 | uint32_t numEffects = 0; |
| 3273 | status = mEffectsFactoryHal->queryNumberEffects(&numEffects); |
| 3274 | if (status < 0) { |
| 3275 | ALOGW("getEffectDescriptor() error %d from FactoryHal queryNumberEffects", status); |
| 3276 | return status; |
| 3277 | } |
| 3278 | |
| 3279 | bool found = false; |
| 3280 | for (uint32_t i = 0; i < numEffects; i++) { |
| 3281 | status = mEffectsFactoryHal->getDescriptor(i, &desc); |
| 3282 | if (status < 0) { |
| 3283 | ALOGW("getEffectDescriptor() error %d from FactoryHal getDescriptor", status); |
| 3284 | continue; |
| 3285 | } |
| 3286 | if (memcmp(&desc.type, pTypeUuid, sizeof(effect_uuid_t)) == 0) { |
| 3287 | // If matching type found save effect descriptor. |
| 3288 | found = true; |
| 3289 | *descriptor = desc; |
| 3290 | |
| 3291 | // If there's no preferred flag or this descriptor matches the preferred |
| 3292 | // flag, success! If this descriptor doesn't match the preferred |
| 3293 | // flag, continue enumeration in case a better matching version of this |
| 3294 | // effect type is available. Note that this means if no effect with a |
| 3295 | // correct flag is found, the descriptor returned will correspond to the |
| 3296 | // last effect that at least had a matching type uuid (if any). |
| 3297 | if (preferredTypeFlag == EFFECT_FLAG_TYPE_MASK || |
| 3298 | (desc.flags & EFFECT_FLAG_TYPE_MASK) == preferredTypeFlag) { |
| 3299 | break; |
| 3300 | } |
| 3301 | } |
| 3302 | } |
| 3303 | |
| 3304 | if (!found) { |
| 3305 | status = NAME_NOT_FOUND; |
| 3306 | ALOGW("getEffectDescriptor(): Effect not found by type."); |
| 3307 | } |
| 3308 | } else { |
| 3309 | status = BAD_VALUE; |
| 3310 | ALOGE("getEffectDescriptor(): Either uuid or type uuid must be non-null UUIDs."); |
| 3311 | } |
| 3312 | return status; |
| 3313 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3314 | |
Glenn Kasten | 8d6cc84 | 2012-02-03 11:06:53 -0800 | [diff] [blame] | 3315 | sp<IEffect> AudioFlinger::createEffect( |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3316 | effect_descriptor_t *pDesc, |
| 3317 | const sp<IEffectClient>& effectClient, |
| 3318 | int32_t priority, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 3319 | audio_io_handle_t io, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 3320 | audio_session_t sessionId, |
Eric Laurent | 9487603 | 2019-11-13 12:45:28 -0800 | [diff] [blame] | 3321 | const AudioDeviceTypeAddr& device __unused, |
Svet Ganov | be71aa2 | 2015-04-28 12:06:02 -0700 | [diff] [blame] | 3322 | const String16& opPackageName, |
Eric Laurent | b643627 | 2016-12-07 19:24:50 -0800 | [diff] [blame] | 3323 | pid_t pid, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3324 | status_t *status, |
| 3325 | int *id, |
| 3326 | int *enabled) |
| 3327 | { |
| 3328 | status_t lStatus = NO_ERROR; |
| 3329 | sp<EffectHandle> handle; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3330 | effect_descriptor_t desc; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3331 | |
Eric Laurent | b643627 | 2016-12-07 19:24:50 -0800 | [diff] [blame] | 3332 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 3333 | if (pid == -1 || !isAudioServerOrMediaServerUid(callingUid)) { |
Eric Laurent | b643627 | 2016-12-07 19:24:50 -0800 | [diff] [blame] | 3334 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
| 3335 | ALOGW_IF(pid != -1 && pid != callingPid, |
| 3336 | "%s uid %d pid %d tried to pass itself off as pid %d", |
| 3337 | __func__, callingUid, callingPid, pid); |
| 3338 | pid = callingPid; |
| 3339 | } |
| 3340 | |
Mikhail Naganov | 4a3d5c2 | 2016-08-15 13:47:42 -0700 | [diff] [blame] | 3341 | ALOGV("createEffect pid %d, effectClient %p, priority %d, sessionId %d, io %d, factory %p", |
| 3342 | pid, effectClient.get(), priority, sessionId, io, mEffectsFactoryHal.get()); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3343 | |
| 3344 | if (pDesc == NULL) { |
| 3345 | lStatus = BAD_VALUE; |
| 3346 | goto Exit; |
| 3347 | } |
| 3348 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 3349 | if (mEffectsFactoryHal == 0) { |
Andy Hung | 6096dcd | 2019-03-13 13:20:30 -0700 | [diff] [blame] | 3350 | ALOGE("%s: no effects factory hal", __func__); |
Mikhail Naganov | 4a3d5c2 | 2016-08-15 13:47:42 -0700 | [diff] [blame] | 3351 | lStatus = NO_INIT; |
| 3352 | goto Exit; |
| 3353 | } |
| 3354 | |
Andy Hung | 6096dcd | 2019-03-13 13:20:30 -0700 | [diff] [blame] | 3355 | // check audio settings permission for global effects |
| 3356 | if (sessionId == AUDIO_SESSION_OUTPUT_MIX) { |
| 3357 | if (!settingsAllowed()) { |
| 3358 | ALOGE("%s: no permission for AUDIO_SESSION_OUTPUT_MIX", __func__); |
| 3359 | lStatus = PERMISSION_DENIED; |
| 3360 | goto Exit; |
| 3361 | } |
| 3362 | } else if (sessionId == AUDIO_SESSION_OUTPUT_STAGE) { |
| 3363 | if (!isAudioServerUid(callingUid)) { |
| 3364 | ALOGE("%s: only APM can create using AUDIO_SESSION_OUTPUT_STAGE", __func__); |
| 3365 | lStatus = PERMISSION_DENIED; |
| 3366 | goto Exit; |
| 3367 | } |
| 3368 | |
| 3369 | if (io == AUDIO_IO_HANDLE_NONE) { |
| 3370 | ALOGE("%s: APM must specify output when using AUDIO_SESSION_OUTPUT_STAGE", __func__); |
| 3371 | lStatus = BAD_VALUE; |
| 3372 | goto Exit; |
| 3373 | } |
Eric Laurent | 3f75a5b | 2019-11-12 15:55:51 -0800 | [diff] [blame] | 3374 | } else if (sessionId == AUDIO_SESSION_DEVICE) { |
| 3375 | if (!modifyDefaultAudioEffectsAllowed(pid, callingUid)) { |
| 3376 | ALOGE("%s: device effect permission denied for uid %d", __func__, callingUid); |
| 3377 | lStatus = PERMISSION_DENIED; |
| 3378 | goto Exit; |
| 3379 | } |
Eric Laurent | 9487603 | 2019-11-13 12:45:28 -0800 | [diff] [blame] | 3380 | if (io != AUDIO_IO_HANDLE_NONE) { |
| 3381 | ALOGE("%s: io handle should not be specified for device effect", __func__); |
| 3382 | lStatus = BAD_VALUE; |
| 3383 | goto Exit; |
| 3384 | } |
Eric Laurent | 3f75a5b | 2019-11-12 15:55:51 -0800 | [diff] [blame] | 3385 | //TODO: add check on device ID when added to arguments |
Andy Hung | 6096dcd | 2019-03-13 13:20:30 -0700 | [diff] [blame] | 3386 | } else { |
| 3387 | // general sessionId. |
| 3388 | |
| 3389 | if (audio_unique_id_get_use(sessionId) != AUDIO_UNIQUE_ID_USE_SESSION) { |
| 3390 | ALOGE("%s: invalid sessionId %d", __func__, sessionId); |
| 3391 | lStatus = BAD_VALUE; |
| 3392 | goto Exit; |
| 3393 | } |
| 3394 | |
| 3395 | // TODO: should we check if the callingUid (limited to pid) is in mAudioSessionRefs |
| 3396 | // to prevent creating an effect when one doesn't actually have track with that session? |
| 3397 | } |
| 3398 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3399 | { |
Ari Hausman-Cohen | 2046ec7 | 2018-04-24 14:00:55 -0700 | [diff] [blame] | 3400 | // Get the full effect descriptor from the uuid/type. |
| 3401 | // If the session is the output mix, prefer an auxiliary effect, |
| 3402 | // otherwise no preference. |
| 3403 | uint32_t preferredType = (sessionId == AUDIO_SESSION_OUTPUT_MIX ? |
| 3404 | EFFECT_FLAG_TYPE_AUXILIARY : EFFECT_FLAG_TYPE_MASK); |
| 3405 | lStatus = getEffectDescriptor(&pDesc->uuid, &pDesc->type, preferredType, &desc); |
| 3406 | if (lStatus < 0) { |
| 3407 | ALOGW("createEffect() error %d from getEffectDescriptor", lStatus); |
| 3408 | goto Exit; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | // Do not allow auxiliary effects on a session different from 0 (output mix) |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 3412 | if (sessionId != AUDIO_SESSION_OUTPUT_MIX && |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3413 | (desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { |
| 3414 | lStatus = INVALID_OPERATION; |
| 3415 | goto Exit; |
| 3416 | } |
| 3417 | |
Eric Laurent | 59255e4 | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 3418 | // check recording permission for visualizer |
| 3419 | if ((memcmp(&desc.type, SL_IID_VISUALIZATION, sizeof(effect_uuid_t)) == 0) && |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 3420 | // TODO: Do we need to start/stop op - i.e. is there recording being performed? |
Eric Laurent | 3f75a5b | 2019-11-12 15:55:51 -0800 | [diff] [blame] | 3421 | !recordingAllowed(opPackageName, pid, callingUid)) { |
Eric Laurent | 59255e4 | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 3422 | lStatus = PERMISSION_DENIED; |
| 3423 | goto Exit; |
| 3424 | } |
| 3425 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3426 | // return effect descriptor |
Glenn Kasten | a189a68 | 2012-02-20 12:16:30 -0800 | [diff] [blame] | 3427 | *pDesc = desc; |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 3428 | if (io == AUDIO_IO_HANDLE_NONE && sessionId == AUDIO_SESSION_OUTPUT_MIX) { |
Eric Laurent | eb3c337 | 2013-09-25 12:25:29 -0700 | [diff] [blame] | 3429 | // if the output returned by getOutputForEffect() is removed before we lock the |
| 3430 | // mutex below, the call to checkPlaybackThread_l(io) below will detect it |
| 3431 | // and we will exit safely |
| 3432 | io = AudioSystem::getOutputForEffect(&desc); |
| 3433 | ALOGV("createEffect got output %d", io); |
| 3434 | } |
| 3435 | |
| 3436 | Mutex::Autolock _l(mLock); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3437 | |
| 3438 | // If output is not specified try to find a matching audio session ID in one of the |
| 3439 | // output threads. |
Eric Laurent | 84e9a10 | 2010-09-23 16:10:16 -0700 | [diff] [blame] | 3440 | // If output is 0 here, sessionId is neither SESSION_OUTPUT_STAGE nor SESSION_OUTPUT_MIX |
| 3441 | // because of code checking output when entering the function. |
Andy Hung | 444bb55 | 2019-03-14 17:06:39 -0700 | [diff] [blame] | 3442 | // Note: io is never AUDIO_IO_HANDLE_NONE when creating an effect on an input by APM. |
| 3443 | // An AudioEffect created from the Java API will have io as AUDIO_IO_HANDLE_NONE. |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 3444 | if (io == AUDIO_IO_HANDLE_NONE) { |
Eric Laurent | eb3c337 | 2013-09-25 12:25:29 -0700 | [diff] [blame] | 3445 | // look for the thread where the specified audio session is present |
Andy Hung | e778c42 | 2019-03-14 15:04:30 -0700 | [diff] [blame] | 3446 | io = findIoHandleBySessionId_l(sessionId, mPlaybackThreads); |
| 3447 | if (io == AUDIO_IO_HANDLE_NONE) { |
| 3448 | io = findIoHandleBySessionId_l(sessionId, mRecordThreads); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3449 | } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 3450 | if (io == AUDIO_IO_HANDLE_NONE) { |
Andy Hung | e778c42 | 2019-03-14 15:04:30 -0700 | [diff] [blame] | 3451 | io = findIoHandleBySessionId_l(sessionId, mMmapThreads); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 3452 | } |
Andy Hung | 444bb55 | 2019-03-14 17:06:39 -0700 | [diff] [blame] | 3453 | |
| 3454 | // If you wish to create a Record preprocessing AudioEffect in Java, |
| 3455 | // you MUST create an AudioRecord first and keep it alive so it is picked up above. |
| 3456 | // Otherwise it will fail when created on a Playback thread by legacy |
| 3457 | // handling below. Ditto with Mmap, the associated Mmap track must be created |
| 3458 | // before creating the AudioEffect or the io handle must be specified. |
| 3459 | // |
| 3460 | // Detect if the effect is created after an AudioRecord is destroyed. |
| 3461 | if (getOrphanEffectChain_l(sessionId).get() != nullptr) { |
| 3462 | ALOGE("%s: effect %s with no specified io handle is denied because the AudioRecord" |
| 3463 | " for session %d no longer exists", |
| 3464 | __func__, desc.name, sessionId); |
| 3465 | lStatus = PERMISSION_DENIED; |
| 3466 | goto Exit; |
| 3467 | } |
| 3468 | |
| 3469 | // Legacy handling of creating an effect on an expired or made-up |
| 3470 | // session id. We think that it is a Playback effect. |
| 3471 | // |
Eric Laurent | 84e9a10 | 2010-09-23 16:10:16 -0700 | [diff] [blame] | 3472 | // If no output thread contains the requested session ID, default to |
| 3473 | // first output. The effect chain will be moved to the correct output |
| 3474 | // thread when a track with the same session ID is created |
Glenn Kasten | 142f519 | 2014-03-25 17:44:59 -0700 | [diff] [blame] | 3475 | if (io == AUDIO_IO_HANDLE_NONE && mPlaybackThreads.size() > 0) { |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 3476 | io = mPlaybackThreads.keyAt(0); |
| 3477 | } |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3478 | ALOGV("createEffect() got io %d for effect %s", io, desc.name); |
Andy Hung | 1631f06 | 2019-03-12 19:39:03 -0700 | [diff] [blame] | 3479 | } else if (checkPlaybackThread_l(io) != nullptr) { |
| 3480 | // allow only one effect chain per sessionId on mPlaybackThreads. |
| 3481 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 3482 | const audio_io_handle_t checkIo = mPlaybackThreads.keyAt(i); |
| 3483 | if (io == checkIo) continue; |
| 3484 | const uint32_t sessionType = |
| 3485 | mPlaybackThreads.valueAt(i)->hasAudioSession(sessionId); |
| 3486 | if ((sessionType & ThreadBase::EFFECT_SESSION) != 0) { |
| 3487 | ALOGE("%s: effect %s io %d denied because session %d effect exists on io %d", |
| 3488 | __func__, desc.name, (int)io, (int)sessionId, (int)checkIo); |
| 3489 | android_errorWriteLog(0x534e4554, "123237974"); |
| 3490 | lStatus = BAD_VALUE; |
| 3491 | goto Exit; |
| 3492 | } |
| 3493 | } |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 3494 | } |
| 3495 | ThreadBase *thread = checkRecordThread_l(io); |
| 3496 | if (thread == NULL) { |
| 3497 | thread = checkPlaybackThread_l(io); |
| 3498 | if (thread == NULL) { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 3499 | thread = checkMmapThread_l(io); |
| 3500 | if (thread == NULL) { |
| 3501 | ALOGE("createEffect() unknown output thread"); |
| 3502 | lStatus = BAD_VALUE; |
| 3503 | goto Exit; |
| 3504 | } |
Eric Laurent | 84e9a10 | 2010-09-23 16:10:16 -0700 | [diff] [blame] | 3505 | } |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3506 | } else { |
| 3507 | // Check if one effect chain was awaiting for an effect to be created on this |
| 3508 | // session and used it instead of creating a new one. |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 3509 | sp<EffectChain> chain = getOrphanEffectChain_l(sessionId); |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3510 | if (chain != 0) { |
Eric Laurent | 1b92868 | 2014-10-02 19:41:47 -0700 | [diff] [blame] | 3511 | Mutex::Autolock _l(thread->mLock); |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3512 | thread->addEffectChain_l(chain); |
| 3513 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3514 | } |
Eric Laurent | 84e9a10 | 2010-09-23 16:10:16 -0700 | [diff] [blame] | 3515 | |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame] | 3516 | sp<Client> client = registerPid(pid); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3517 | |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 3518 | // create effect on selected output thread |
Eric Laurent | 3f75a5b | 2019-11-12 15:55:51 -0800 | [diff] [blame] | 3519 | bool pinned = !audio_is_global_session(sessionId) && isSessionAcquired_l(sessionId); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3520 | handle = thread->createEffect_l(client, effectClient, priority, sessionId, |
Eric Laurent | 0d5a2ed | 2016-12-01 15:28:29 -0800 | [diff] [blame] | 3521 | &desc, enabled, &lStatus, pinned); |
haobo10173529 | 5ff7b0d | 2017-03-17 17:44:03 +0800 | [diff] [blame] | 3522 | if (lStatus != NO_ERROR && lStatus != ALREADY_EXISTS) { |
Eric Laurent | fe1a94e | 2014-05-26 16:03:08 -0700 | [diff] [blame] | 3523 | // remove local strong reference to Client with mClientLock held |
| 3524 | Mutex::Autolock _cl(mClientLock); |
| 3525 | client.clear(); |
haobo10173529 | 5ff7b0d | 2017-03-17 17:44:03 +0800 | [diff] [blame] | 3526 | } else { |
| 3527 | // handle must be valid here, but check again to be safe. |
| 3528 | if (handle.get() != nullptr && id != nullptr) *id = handle->id(); |
Eric Laurent | fe1a94e | 2014-05-26 16:03:08 -0700 | [diff] [blame] | 3529 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 3532 | if (lStatus == NO_ERROR || lStatus == ALREADY_EXISTS) { |
| 3533 | // Check CPU and memory usage |
Eric Laurent | 4170955 | 2019-12-16 19:34:05 -0800 | [diff] [blame] | 3534 | sp<EffectBase> effect = handle->effect().promote(); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 3535 | if (effect != nullptr) { |
| 3536 | status_t rStatus = effect->updatePolicyState(); |
| 3537 | if (rStatus != NO_ERROR) { |
| 3538 | lStatus = rStatus; |
| 3539 | } |
| 3540 | } |
| 3541 | } else { |
haobo10173529 | 5ff7b0d | 2017-03-17 17:44:03 +0800 | [diff] [blame] | 3542 | handle.clear(); |
| 3543 | } |
| 3544 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3545 | Exit: |
Glenn Kasten | 9156ef3 | 2013-08-06 15:39:08 -0700 | [diff] [blame] | 3546 | *status = lStatus; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3547 | return handle; |
| 3548 | } |
| 3549 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 3550 | status_t AudioFlinger::moveEffects(audio_session_t sessionId, audio_io_handle_t srcOutput, |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 3551 | audio_io_handle_t dstOutput) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3552 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3553 | ALOGV("moveEffects() session %d, srcOutput %d, dstOutput %d", |
Eric Laurent | 59255e4 | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 3554 | sessionId, srcOutput, dstOutput); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3555 | Mutex::Autolock _l(mLock); |
| 3556 | if (srcOutput == dstOutput) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 3557 | ALOGW("moveEffects() same dst and src outputs %d", dstOutput); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3558 | return NO_ERROR; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3559 | } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3560 | PlaybackThread *srcThread = checkPlaybackThread_l(srcOutput); |
| 3561 | if (srcThread == NULL) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 3562 | ALOGW("moveEffects() bad srcOutput %d", srcOutput); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3563 | return BAD_VALUE; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3564 | } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3565 | PlaybackThread *dstThread = checkPlaybackThread_l(dstOutput); |
| 3566 | if (dstThread == NULL) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 3567 | ALOGW("moveEffects() bad dstOutput %d", dstOutput); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3568 | return BAD_VALUE; |
| 3569 | } |
| 3570 | |
| 3571 | Mutex::Autolock _dl(dstThread->mLock); |
| 3572 | Mutex::Autolock _sl(srcThread->mLock); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 3573 | return moveEffectChain_l(sessionId, srcThread, dstThread); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 3576 | |
| 3577 | void AudioFlinger::setEffectSuspended(int effectId, |
| 3578 | audio_session_t sessionId, |
| 3579 | bool suspended) |
| 3580 | { |
| 3581 | Mutex::Autolock _l(mLock); |
| 3582 | |
| 3583 | sp<ThreadBase> thread = getEffectThread_l(sessionId, effectId); |
| 3584 | if (thread == nullptr) { |
| 3585 | return; |
| 3586 | } |
| 3587 | Mutex::Autolock _sl(thread->mLock); |
| 3588 | sp<EffectModule> effect = thread->getEffect_l(sessionId, effectId); |
| 3589 | thread->setEffectSuspended_l(&effect->desc().type, suspended, sessionId); |
| 3590 | } |
| 3591 | |
| 3592 | |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 3593 | // moveEffectChain_l must be called with both srcThread and dstThread mLocks held |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 3594 | status_t AudioFlinger::moveEffectChain_l(audio_session_t sessionId, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3595 | AudioFlinger::PlaybackThread *srcThread, |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 3596 | AudioFlinger::PlaybackThread *dstThread) |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3597 | { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3598 | ALOGV("moveEffectChain_l() session %d from thread %p to thread %p", |
Eric Laurent | 59255e4 | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 3599 | sessionId, srcThread, dstThread); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3600 | |
Eric Laurent | 59255e4 | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 3601 | sp<EffectChain> chain = srcThread->getEffectChain_l(sessionId); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3602 | if (chain == 0) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 3603 | ALOGW("moveEffectChain_l() effect chain for session %d not on source thread %p", |
Eric Laurent | 59255e4 | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 3604 | sessionId, srcThread); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3605 | return INVALID_OPERATION; |
| 3606 | } |
| 3607 | |
Eric Laurent | 4c41506 | 2016-06-17 16:14:16 -0700 | [diff] [blame] | 3608 | // Check whether the destination thread and all effects in the chain are compatible |
| 3609 | if (!chain->isCompatibleWithThread_l(dstThread)) { |
Andy Hung | 9a59276 | 2014-07-21 21:56:01 -0700 | [diff] [blame] | 3610 | ALOGW("moveEffectChain_l() effect chain failed because" |
Eric Laurent | 4c41506 | 2016-06-17 16:14:16 -0700 | [diff] [blame] | 3611 | " destination thread %p is not compatible with effects in the chain", |
| 3612 | dstThread); |
Andy Hung | 9a59276 | 2014-07-21 21:56:01 -0700 | [diff] [blame] | 3613 | return INVALID_OPERATION; |
| 3614 | } |
| 3615 | |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 3616 | // remove chain first. This is useful only if reconfiguring effect chain on same output thread, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3617 | // so that a new chain is created with correct parameters when first effect is added. This is |
Eric Laurent | ec35a14 | 2011-10-05 17:42:25 -0700 | [diff] [blame] | 3618 | // otherwise unnecessary as removeEffect_l() will remove the chain when last effect is |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3619 | // removed. |
| 3620 | srcThread->removeEffectChain_l(chain); |
| 3621 | |
| 3622 | // transfer all effects one by one so that new effect chain is created on new thread with |
| 3623 | // correct buffer sizes and audio parameters and effect engines reconfigured accordingly |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 3624 | sp<EffectChain> dstChain; |
Marco Nelissen | 3a34bef | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 3625 | uint32_t strategy = 0; // prevent compiler warning |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3626 | sp<EffectModule> effect = chain->getEffectFromId_l(0); |
Eric Laurent | 5baf2af | 2013-09-12 17:37:00 -0700 | [diff] [blame] | 3627 | Vector< sp<EffectModule> > removed; |
| 3628 | status_t status = NO_ERROR; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3629 | while (effect != 0) { |
| 3630 | srcThread->removeEffect_l(effect); |
Eric Laurent | 5baf2af | 2013-09-12 17:37:00 -0700 | [diff] [blame] | 3631 | removed.add(effect); |
| 3632 | status = dstThread->addEffect_l(effect); |
| 3633 | if (status != NO_ERROR) { |
| 3634 | break; |
| 3635 | } |
Eric Laurent | ec35a14 | 2011-10-05 17:42:25 -0700 | [diff] [blame] | 3636 | // removeEffect_l() has stopped the effect if it was active so it must be restarted |
| 3637 | if (effect->state() == EffectModule::ACTIVE || |
| 3638 | effect->state() == EffectModule::STOPPING) { |
| 3639 | effect->start(); |
| 3640 | } |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 3641 | // if the move request is not received from audio policy manager, the effect must be |
| 3642 | // re-registered with the new strategy and output |
| 3643 | if (dstChain == 0) { |
Eric Laurent | 6b446ce | 2019-12-13 10:56:31 -0800 | [diff] [blame] | 3644 | dstChain = effect->callback()->chain().promote(); |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 3645 | if (dstChain == 0) { |
Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 3646 | ALOGW("moveEffectChain_l() cannot get chain from effect %p", effect.get()); |
Eric Laurent | 5baf2af | 2013-09-12 17:37:00 -0700 | [diff] [blame] | 3647 | status = NO_INIT; |
| 3648 | break; |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 3649 | } |
| 3650 | strategy = dstChain->strategy(); |
| 3651 | } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 3652 | effect = chain->getEffectFromId_l(0); |
| 3653 | } |
| 3654 | |
Eric Laurent | 5baf2af | 2013-09-12 17:37:00 -0700 | [diff] [blame] | 3655 | if (status != NO_ERROR) { |
| 3656 | for (size_t i = 0; i < removed.size(); i++) { |
| 3657 | srcThread->addEffect_l(removed[i]); |
Eric Laurent | 5baf2af | 2013-09-12 17:37:00 -0700 | [diff] [blame] | 3658 | } |
| 3659 | } |
| 3660 | |
| 3661 | return status; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3662 | } |
| 3663 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 3664 | status_t AudioFlinger::moveAuxEffectToIo(int EffectId, |
| 3665 | const sp<PlaybackThread>& dstThread, |
| 3666 | sp<PlaybackThread> *srcThread) |
| 3667 | { |
| 3668 | status_t status = NO_ERROR; |
| 3669 | Mutex::Autolock _l(mLock); |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 3670 | sp<PlaybackThread> thread = |
| 3671 | static_cast<PlaybackThread *>(getEffectThread_l(AUDIO_SESSION_OUTPUT_MIX, EffectId).get()); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 3672 | |
| 3673 | if (EffectId != 0 && thread != 0 && dstThread != thread.get()) { |
| 3674 | Mutex::Autolock _dl(dstThread->mLock); |
| 3675 | Mutex::Autolock _sl(thread->mLock); |
| 3676 | sp<EffectChain> srcChain = thread->getEffectChain_l(AUDIO_SESSION_OUTPUT_MIX); |
| 3677 | sp<EffectChain> dstChain; |
| 3678 | if (srcChain == 0) { |
| 3679 | return INVALID_OPERATION; |
| 3680 | } |
| 3681 | |
| 3682 | sp<EffectModule> effect = srcChain->getEffectFromId_l(EffectId); |
| 3683 | if (effect == 0) { |
| 3684 | return INVALID_OPERATION; |
| 3685 | } |
| 3686 | thread->removeEffect_l(effect); |
| 3687 | status = dstThread->addEffect_l(effect); |
| 3688 | if (status != NO_ERROR) { |
| 3689 | thread->addEffect_l(effect); |
| 3690 | status = INVALID_OPERATION; |
| 3691 | goto Exit; |
| 3692 | } |
| 3693 | |
Eric Laurent | 6b446ce | 2019-12-13 10:56:31 -0800 | [diff] [blame] | 3694 | dstChain = effect->callback()->chain().promote(); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 3695 | if (dstChain == 0) { |
| 3696 | thread->addEffect_l(effect); |
| 3697 | status = INVALID_OPERATION; |
| 3698 | } |
| 3699 | |
| 3700 | Exit: |
| 3701 | // removeEffect_l() has stopped the effect if it was active so it must be restarted |
| 3702 | if (effect->state() == EffectModule::ACTIVE || |
| 3703 | effect->state() == EffectModule::STOPPING) { |
| 3704 | effect->start(); |
| 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | if (status == NO_ERROR && srcThread != nullptr) { |
| 3709 | *srcThread = thread; |
| 3710 | } |
| 3711 | return status; |
| 3712 | } |
| 3713 | |
Eric Laurent | 5baf2af | 2013-09-12 17:37:00 -0700 | [diff] [blame] | 3714 | bool AudioFlinger::isNonOffloadableGlobalEffectEnabled_l() |
Eric Laurent | 813e2a7 | 2013-08-31 12:59:48 -0700 | [diff] [blame] | 3715 | { |
| 3716 | if (mGlobalEffectEnableTime != 0 && |
| 3717 | ((systemTime() - mGlobalEffectEnableTime) < kMinGlobalEffectEnabletimeNs)) { |
| 3718 | return true; |
| 3719 | } |
| 3720 | |
| 3721 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 3722 | sp<EffectChain> ec = |
| 3723 | mPlaybackThreads.valueAt(i)->getEffectChain_l(AUDIO_SESSION_OUTPUT_MIX); |
Eric Laurent | 5baf2af | 2013-09-12 17:37:00 -0700 | [diff] [blame] | 3724 | if (ec != 0 && ec->isNonOffloadableEnabled()) { |
Eric Laurent | 813e2a7 | 2013-08-31 12:59:48 -0700 | [diff] [blame] | 3725 | return true; |
| 3726 | } |
| 3727 | } |
| 3728 | return false; |
| 3729 | } |
| 3730 | |
Eric Laurent | 5baf2af | 2013-09-12 17:37:00 -0700 | [diff] [blame] | 3731 | void AudioFlinger::onNonOffloadableGlobalEffectEnable() |
Eric Laurent | 813e2a7 | 2013-08-31 12:59:48 -0700 | [diff] [blame] | 3732 | { |
| 3733 | Mutex::Autolock _l(mLock); |
| 3734 | |
| 3735 | mGlobalEffectEnableTime = systemTime(); |
| 3736 | |
| 3737 | for (size_t i = 0; i < mPlaybackThreads.size(); i++) { |
| 3738 | sp<PlaybackThread> t = mPlaybackThreads.valueAt(i); |
| 3739 | if (t->mType == ThreadBase::OFFLOAD) { |
| 3740 | t->invalidateTracks(AUDIO_STREAM_MUSIC); |
| 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | } |
| 3745 | |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3746 | status_t AudioFlinger::putOrphanEffectChain_l(const sp<AudioFlinger::EffectChain>& chain) |
| 3747 | { |
Eric Laurent | d8365c5 | 2017-07-16 15:27:05 -0700 | [diff] [blame] | 3748 | // clear possible suspended state before parking the chain so that it starts in default state |
| 3749 | // when attached to a new record thread |
| 3750 | chain->setEffectSuspended_l(FX_IID_AEC, false); |
| 3751 | chain->setEffectSuspended_l(FX_IID_NS, false); |
| 3752 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 3753 | audio_session_t session = chain->sessionId(); |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3754 | ssize_t index = mOrphanEffectChains.indexOfKey(session); |
Glenn Kasten | c42e9b4 | 2016-03-21 11:35:03 -0700 | [diff] [blame] | 3755 | ALOGV("putOrphanEffectChain_l session %d index %zd", session, index); |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3756 | if (index >= 0) { |
| 3757 | ALOGW("putOrphanEffectChain_l chain for session %d already present", session); |
| 3758 | return ALREADY_EXISTS; |
| 3759 | } |
| 3760 | mOrphanEffectChains.add(session, chain); |
| 3761 | return NO_ERROR; |
| 3762 | } |
| 3763 | |
| 3764 | sp<AudioFlinger::EffectChain> AudioFlinger::getOrphanEffectChain_l(audio_session_t session) |
| 3765 | { |
| 3766 | sp<EffectChain> chain; |
| 3767 | ssize_t index = mOrphanEffectChains.indexOfKey(session); |
Glenn Kasten | c42e9b4 | 2016-03-21 11:35:03 -0700 | [diff] [blame] | 3768 | ALOGV("getOrphanEffectChain_l session %d index %zd", session, index); |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3769 | if (index >= 0) { |
| 3770 | chain = mOrphanEffectChains.valueAt(index); |
| 3771 | mOrphanEffectChains.removeItemsAt(index); |
| 3772 | } |
| 3773 | return chain; |
| 3774 | } |
| 3775 | |
| 3776 | bool AudioFlinger::updateOrphanEffectChains(const sp<AudioFlinger::EffectModule>& effect) |
| 3777 | { |
| 3778 | Mutex::Autolock _l(mLock); |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 3779 | audio_session_t session = effect->sessionId(); |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3780 | ssize_t index = mOrphanEffectChains.indexOfKey(session); |
Glenn Kasten | c42e9b4 | 2016-03-21 11:35:03 -0700 | [diff] [blame] | 3781 | ALOGV("updateOrphanEffectChains session %d index %zd", session, index); |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3782 | if (index >= 0) { |
| 3783 | sp<EffectChain> chain = mOrphanEffectChains.valueAt(index); |
Eric Laurent | 0d5a2ed | 2016-12-01 15:28:29 -0800 | [diff] [blame] | 3784 | if (chain->removeEffect_l(effect, true) == 0) { |
Glenn Kasten | c42e9b4 | 2016-03-21 11:35:03 -0700 | [diff] [blame] | 3785 | ALOGV("updateOrphanEffectChains removing effect chain at index %zd", index); |
Eric Laurent | aaa4447 | 2014-09-12 17:41:50 -0700 | [diff] [blame] | 3786 | mOrphanEffectChains.removeItemsAt(index); |
| 3787 | } |
| 3788 | return true; |
| 3789 | } |
| 3790 | return false; |
| 3791 | } |
| 3792 | |
| 3793 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 3794 | // ---------------------------------------------------------------------------- |
| 3795 | |
| 3796 | status_t AudioFlinger::onTransact( |
| 3797 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 3798 | { |
| 3799 | return BnAudioFlinger::onTransact(code, data, reply, flags); |
| 3800 | } |
| 3801 | |
Glenn Kasten | 63238ef | 2015-03-02 15:50:29 -0800 | [diff] [blame] | 3802 | } // namespace android |