Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1 | /* //device/include/server/AudioFlinger/AudioFlinger.h |
| 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 | #ifndef ANDROID_AUDIO_FLINGER_H |
| 19 | #define ANDROID_AUDIO_FLINGER_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <limits.h> |
| 24 | |
| 25 | #include <media/IAudioFlinger.h> |
| 26 | #include <media/IAudioFlingerClient.h> |
| 27 | #include <media/IAudioTrack.h> |
| 28 | #include <media/IAudioRecord.h> |
| 29 | #include <media/AudioTrack.h> |
| 30 | |
| 31 | #include <utils/Atomic.h> |
| 32 | #include <utils/Errors.h> |
| 33 | #include <utils/threads.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 34 | #include <utils/SortedVector.h> |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 35 | #include <utils/TypeHelpers.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 36 | #include <utils/Vector.h> |
| 37 | |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 38 | #include <binder/BinderService.h> |
| 39 | #include <binder/MemoryDealer.h> |
| 40 | |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 41 | #include <system/audio.h> |
Dima Zavin | 7394a4f | 2011-06-13 18:16:26 -0700 | [diff] [blame] | 42 | #include <hardware/audio.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 43 | |
| 44 | #include "AudioBufferProvider.h" |
| 45 | |
| 46 | namespace android { |
| 47 | |
| 48 | class audio_track_cblk_t; |
| 49 | class effect_param_cblk_t; |
| 50 | class AudioMixer; |
| 51 | class AudioBuffer; |
| 52 | class AudioResampler; |
| 53 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 54 | // ---------------------------------------------------------------------------- |
| 55 | |
| 56 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 57 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 58 | |
| 59 | |
| 60 | // ---------------------------------------------------------------------------- |
| 61 | |
| 62 | static const nsecs_t kStandbyTimeInNsecs = seconds(3); |
| 63 | |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 64 | class AudioFlinger : |
| 65 | public BinderService<AudioFlinger>, |
| 66 | public BnAudioFlinger |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 67 | { |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 68 | friend class BinderService<AudioFlinger>; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 69 | public: |
Mathias Agopian | 5462fc9 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 70 | static char const* getServiceName() { return "media.audio_flinger"; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 71 | |
| 72 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 73 | |
| 74 | // IAudioFlinger interface |
| 75 | virtual sp<IAudioTrack> createTrack( |
| 76 | pid_t pid, |
| 77 | int streamType, |
| 78 | uint32_t sampleRate, |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 79 | uint32_t format, |
| 80 | uint32_t channelMask, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 81 | int frameCount, |
| 82 | uint32_t flags, |
| 83 | const sp<IMemory>& sharedBuffer, |
| 84 | int output, |
| 85 | int *sessionId, |
| 86 | status_t *status); |
| 87 | |
| 88 | virtual uint32_t sampleRate(int output) const; |
| 89 | virtual int channelCount(int output) const; |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 90 | virtual uint32_t format(int output) const; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 91 | virtual size_t frameCount(int output) const; |
| 92 | virtual uint32_t latency(int output) const; |
| 93 | |
| 94 | virtual status_t setMasterVolume(float value); |
| 95 | virtual status_t setMasterMute(bool muted); |
| 96 | |
| 97 | virtual float masterVolume() const; |
| 98 | virtual bool masterMute() const; |
| 99 | |
| 100 | virtual status_t setStreamVolume(int stream, float value, int output); |
| 101 | virtual status_t setStreamMute(int stream, bool muted); |
| 102 | |
| 103 | virtual float streamVolume(int stream, int output) const; |
| 104 | virtual bool streamMute(int stream) const; |
| 105 | |
| 106 | virtual status_t setMode(int mode); |
| 107 | |
| 108 | virtual status_t setMicMute(bool state); |
| 109 | virtual bool getMicMute() const; |
| 110 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 111 | virtual status_t setParameters(int ioHandle, const String8& keyValuePairs); |
| 112 | virtual String8 getParameters(int ioHandle, const String8& keys); |
| 113 | |
| 114 | virtual void registerClient(const sp<IAudioFlingerClient>& client); |
| 115 | |
| 116 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); |
| 117 | virtual unsigned int getInputFramesLost(int ioHandle); |
| 118 | |
| 119 | virtual int openOutput(uint32_t *pDevices, |
| 120 | uint32_t *pSamplingRate, |
| 121 | uint32_t *pFormat, |
| 122 | uint32_t *pChannels, |
| 123 | uint32_t *pLatencyMs, |
| 124 | uint32_t flags); |
| 125 | |
| 126 | virtual int openDuplicateOutput(int output1, int output2); |
| 127 | |
| 128 | virtual status_t closeOutput(int output); |
| 129 | |
| 130 | virtual status_t suspendOutput(int output); |
| 131 | |
| 132 | virtual status_t restoreOutput(int output); |
| 133 | |
| 134 | virtual int openInput(uint32_t *pDevices, |
| 135 | uint32_t *pSamplingRate, |
| 136 | uint32_t *pFormat, |
| 137 | uint32_t *pChannels, |
| 138 | uint32_t acoustics); |
| 139 | |
| 140 | virtual status_t closeInput(int input); |
| 141 | |
| 142 | virtual status_t setStreamOutput(uint32_t stream, int output); |
| 143 | |
| 144 | virtual status_t setVoiceVolume(float volume); |
| 145 | |
| 146 | virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output); |
| 147 | |
| 148 | virtual int newAudioSessionId(); |
| 149 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 150 | virtual status_t queryNumberEffects(uint32_t *numEffects); |
| 151 | |
| 152 | virtual status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor); |
| 153 | |
| 154 | virtual status_t getEffectDescriptor(effect_uuid_t *pUuid, effect_descriptor_t *descriptor); |
| 155 | |
| 156 | virtual sp<IEffect> createEffect(pid_t pid, |
| 157 | effect_descriptor_t *pDesc, |
| 158 | const sp<IEffectClient>& effectClient, |
| 159 | int32_t priority, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 160 | int io, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 161 | int sessionId, |
| 162 | status_t *status, |
| 163 | int *id, |
| 164 | int *enabled); |
| 165 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 166 | virtual status_t moveEffects(int session, int srcOutput, int dstOutput); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 167 | |
| 168 | enum hardware_call_state { |
| 169 | AUDIO_HW_IDLE = 0, |
| 170 | AUDIO_HW_INIT, |
| 171 | AUDIO_HW_OUTPUT_OPEN, |
| 172 | AUDIO_HW_OUTPUT_CLOSE, |
| 173 | AUDIO_HW_INPUT_OPEN, |
| 174 | AUDIO_HW_INPUT_CLOSE, |
| 175 | AUDIO_HW_STANDBY, |
| 176 | AUDIO_HW_SET_MASTER_VOLUME, |
| 177 | AUDIO_HW_GET_ROUTING, |
| 178 | AUDIO_HW_SET_ROUTING, |
| 179 | AUDIO_HW_GET_MODE, |
| 180 | AUDIO_HW_SET_MODE, |
| 181 | AUDIO_HW_GET_MIC_MUTE, |
| 182 | AUDIO_HW_SET_MIC_MUTE, |
| 183 | AUDIO_SET_VOICE_VOLUME, |
| 184 | AUDIO_SET_PARAMETER, |
| 185 | }; |
| 186 | |
| 187 | // record interface |
| 188 | virtual sp<IAudioRecord> openRecord( |
| 189 | pid_t pid, |
| 190 | int input, |
| 191 | uint32_t sampleRate, |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 192 | uint32_t format, |
| 193 | uint32_t channelMask, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 194 | int frameCount, |
| 195 | uint32_t flags, |
| 196 | int *sessionId, |
| 197 | status_t *status); |
| 198 | |
| 199 | virtual status_t onTransact( |
| 200 | uint32_t code, |
| 201 | const Parcel& data, |
| 202 | Parcel* reply, |
| 203 | uint32_t flags); |
| 204 | |
| 205 | uint32_t getMode() { return mMode; } |
| 206 | |
| 207 | private: |
| 208 | AudioFlinger(); |
| 209 | virtual ~AudioFlinger(); |
| 210 | |
Dima Zavin | 5a61d2f | 2011-04-19 19:04:32 -0700 | [diff] [blame] | 211 | status_t initCheck() const; |
| 212 | virtual void onFirstRef(); |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 213 | audio_hw_device_t* findSuitableHwDev_l(uint32_t devices); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 214 | |
| 215 | // Internal dump utilites. |
| 216 | status_t dumpPermissionDenial(int fd, const Vector<String16>& args); |
| 217 | status_t dumpClients(int fd, const Vector<String16>& args); |
| 218 | status_t dumpInternals(int fd, const Vector<String16>& args); |
| 219 | |
| 220 | // --- Client --- |
| 221 | class Client : public RefBase { |
| 222 | public: |
| 223 | Client(const sp<AudioFlinger>& audioFlinger, pid_t pid); |
| 224 | virtual ~Client(); |
| 225 | const sp<MemoryDealer>& heap() const; |
| 226 | pid_t pid() const { return mPid; } |
| 227 | sp<AudioFlinger> audioFlinger() { return mAudioFlinger; } |
| 228 | |
| 229 | private: |
| 230 | Client(const Client&); |
| 231 | Client& operator = (const Client&); |
| 232 | sp<AudioFlinger> mAudioFlinger; |
| 233 | sp<MemoryDealer> mMemoryDealer; |
| 234 | pid_t mPid; |
| 235 | }; |
| 236 | |
| 237 | // --- Notification Client --- |
| 238 | class NotificationClient : public IBinder::DeathRecipient { |
| 239 | public: |
| 240 | NotificationClient(const sp<AudioFlinger>& audioFlinger, |
| 241 | const sp<IAudioFlingerClient>& client, |
| 242 | pid_t pid); |
| 243 | virtual ~NotificationClient(); |
| 244 | |
| 245 | sp<IAudioFlingerClient> client() { return mClient; } |
| 246 | |
| 247 | // IBinder::DeathRecipient |
| 248 | virtual void binderDied(const wp<IBinder>& who); |
| 249 | |
| 250 | private: |
| 251 | NotificationClient(const NotificationClient&); |
| 252 | NotificationClient& operator = (const NotificationClient&); |
| 253 | |
| 254 | sp<AudioFlinger> mAudioFlinger; |
| 255 | pid_t mPid; |
| 256 | sp<IAudioFlingerClient> mClient; |
| 257 | }; |
| 258 | |
| 259 | class TrackHandle; |
| 260 | class RecordHandle; |
| 261 | class RecordThread; |
| 262 | class PlaybackThread; |
| 263 | class MixerThread; |
| 264 | class DirectOutputThread; |
| 265 | class DuplicatingThread; |
| 266 | class Track; |
| 267 | class RecordTrack; |
| 268 | class EffectModule; |
| 269 | class EffectHandle; |
| 270 | class EffectChain; |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 271 | struct AudioStreamOut; |
| 272 | struct AudioStreamIn; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 273 | |
| 274 | class ThreadBase : public Thread { |
| 275 | public: |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 276 | ThreadBase (const sp<AudioFlinger>& audioFlinger, int id, uint32_t device); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 277 | virtual ~ThreadBase(); |
| 278 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 279 | |
| 280 | enum type { |
| 281 | MIXER, // Thread class is MixerThread |
| 282 | DIRECT, // Thread class is DirectOutputThread |
| 283 | DUPLICATING, // Thread class is DuplicatingThread |
| 284 | RECORD // Thread class is RecordThread |
| 285 | }; |
| 286 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 287 | status_t dumpBase(int fd, const Vector<String16>& args); |
| 288 | |
| 289 | // base for record and playback |
| 290 | class TrackBase : public AudioBufferProvider, public RefBase { |
| 291 | |
| 292 | public: |
| 293 | enum track_state { |
| 294 | IDLE, |
| 295 | TERMINATED, |
| 296 | STOPPED, |
| 297 | RESUMING, |
| 298 | ACTIVE, |
| 299 | PAUSING, |
| 300 | PAUSED |
| 301 | }; |
| 302 | |
| 303 | enum track_flags { |
| 304 | STEPSERVER_FAILED = 0x01, // StepServer could not acquire cblk->lock mutex |
| 305 | SYSTEM_FLAGS_MASK = 0x0000ffffUL, |
| 306 | // The upper 16 bits are used for track-specific flags. |
| 307 | }; |
| 308 | |
| 309 | TrackBase(const wp<ThreadBase>& thread, |
| 310 | const sp<Client>& client, |
| 311 | uint32_t sampleRate, |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 312 | uint32_t format, |
| 313 | uint32_t channelMask, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 314 | int frameCount, |
| 315 | uint32_t flags, |
| 316 | const sp<IMemory>& sharedBuffer, |
| 317 | int sessionId); |
| 318 | ~TrackBase(); |
| 319 | |
| 320 | virtual status_t start() = 0; |
| 321 | virtual void stop() = 0; |
| 322 | sp<IMemory> getCblk() const; |
| 323 | audio_track_cblk_t* cblk() const { return mCblk; } |
| 324 | int sessionId() { return mSessionId; } |
| 325 | |
| 326 | protected: |
| 327 | friend class ThreadBase; |
| 328 | friend class RecordHandle; |
| 329 | friend class PlaybackThread; |
| 330 | friend class RecordThread; |
| 331 | friend class MixerThread; |
| 332 | friend class DirectOutputThread; |
| 333 | |
| 334 | TrackBase(const TrackBase&); |
| 335 | TrackBase& operator = (const TrackBase&); |
| 336 | |
| 337 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0; |
| 338 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 339 | |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 340 | uint32_t format() const { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 341 | return mFormat; |
| 342 | } |
| 343 | |
| 344 | int channelCount() const ; |
| 345 | |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 346 | uint32_t channelMask() const; |
| 347 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 348 | int sampleRate() const; |
| 349 | |
| 350 | void* getBuffer(uint32_t offset, uint32_t frames) const; |
| 351 | |
| 352 | bool isStopped() const { |
| 353 | return mState == STOPPED; |
| 354 | } |
| 355 | |
| 356 | bool isTerminated() const { |
| 357 | return mState == TERMINATED; |
| 358 | } |
| 359 | |
| 360 | bool step(); |
| 361 | void reset(); |
| 362 | |
| 363 | wp<ThreadBase> mThread; |
| 364 | sp<Client> mClient; |
| 365 | sp<IMemory> mCblkMemory; |
| 366 | audio_track_cblk_t* mCblk; |
| 367 | void* mBuffer; |
| 368 | void* mBufferEnd; |
| 369 | uint32_t mFrameCount; |
| 370 | // we don't really need a lock for these |
| 371 | int mState; |
| 372 | int mClientTid; |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 373 | uint32_t mFormat; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 374 | uint32_t mFlags; |
| 375 | int mSessionId; |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 376 | uint8_t mChannelCount; |
| 377 | uint32_t mChannelMask; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | class ConfigEvent { |
| 381 | public: |
| 382 | ConfigEvent() : mEvent(0), mParam(0) {} |
| 383 | |
| 384 | int mEvent; |
| 385 | int mParam; |
| 386 | }; |
| 387 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 388 | virtual status_t initCheck() const = 0; |
| 389 | int type() const { return mType; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 390 | uint32_t sampleRate() const; |
| 391 | int channelCount() const; |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 392 | uint32_t format() const; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 393 | size_t frameCount() const; |
| 394 | void wakeUp() { mWaitWorkCV.broadcast(); } |
| 395 | void exit(); |
| 396 | virtual bool checkForNewParameters_l() = 0; |
| 397 | virtual status_t setParameters(const String8& keyValuePairs); |
| 398 | virtual String8 getParameters(const String8& keys) = 0; |
| 399 | virtual void audioConfigChanged_l(int event, int param = 0) = 0; |
| 400 | void sendConfigEvent(int event, int param = 0); |
| 401 | void sendConfigEvent_l(int event, int param = 0); |
| 402 | void processConfigEvents(); |
| 403 | int id() const { return mId;} |
| 404 | bool standby() { return mStandby; } |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 405 | uint32_t device() { return mDevice; } |
| 406 | virtual audio_stream_t* stream() = 0; |
| 407 | |
| 408 | sp<EffectHandle> createEffect_l( |
| 409 | const sp<AudioFlinger::Client>& client, |
| 410 | const sp<IEffectClient>& effectClient, |
| 411 | int32_t priority, |
| 412 | int sessionId, |
| 413 | effect_descriptor_t *desc, |
| 414 | int *enabled, |
| 415 | status_t *status); |
| 416 | void disconnectEffect(const sp< EffectModule>& effect, |
| 417 | const wp<EffectHandle>& handle); |
| 418 | |
| 419 | // return values for hasAudioSession (bit field) |
| 420 | enum effect_state { |
| 421 | EFFECT_SESSION = 0x1, // the audio session corresponds to at least one |
| 422 | // effect |
| 423 | TRACK_SESSION = 0x2 // the audio session corresponds to at least one |
| 424 | // track |
| 425 | }; |
| 426 | |
| 427 | // get effect chain corresponding to session Id. |
| 428 | sp<EffectChain> getEffectChain(int sessionId); |
| 429 | // same as getEffectChain() but must be called with ThreadBase mutex locked |
| 430 | sp<EffectChain> getEffectChain_l(int sessionId); |
| 431 | // add an effect chain to the chain list (mEffectChains) |
| 432 | virtual status_t addEffectChain_l(const sp<EffectChain>& chain) = 0; |
| 433 | // remove an effect chain from the chain list (mEffectChains) |
| 434 | virtual size_t removeEffectChain_l(const sp<EffectChain>& chain) = 0; |
| 435 | // lock mall effect chains Mutexes. Must be called before releasing the |
| 436 | // ThreadBase mutex before processing the mixer and effects. This guarantees the |
| 437 | // integrity of the chains during the process. |
| 438 | void lockEffectChains_l(Vector<sp <EffectChain> >& effectChains); |
| 439 | // unlock effect chains after process |
| 440 | void unlockEffectChains(Vector<sp <EffectChain> >& effectChains); |
| 441 | // set audio mode to all effect chains |
| 442 | void setMode(uint32_t mode); |
| 443 | // get effect module with corresponding ID on specified audio session |
| 444 | sp<AudioFlinger::EffectModule> getEffect_l(int sessionId, int effectId); |
| 445 | // add and effect module. Also creates the effect chain is none exists for |
| 446 | // the effects audio session |
| 447 | status_t addEffect_l(const sp< EffectModule>& effect); |
| 448 | // remove and effect module. Also removes the effect chain is this was the last |
| 449 | // effect |
| 450 | void removeEffect_l(const sp< EffectModule>& effect); |
| 451 | // detach all tracks connected to an auxiliary effect |
| 452 | virtual void detachAuxEffect_l(int effectId) {} |
| 453 | // returns either EFFECT_SESSION if effects on this audio session exist in one |
| 454 | // chain, or TRACK_SESSION if tracks on this audio session exist, or both |
| 455 | virtual uint32_t hasAudioSession(int sessionId) = 0; |
| 456 | // the value returned by default implementation is not important as the |
| 457 | // strategy is only meaningful for PlaybackThread which implements this method |
| 458 | virtual uint32_t getStrategyForSession_l(int sessionId) { return 0; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 459 | |
| 460 | mutable Mutex mLock; |
| 461 | |
| 462 | protected: |
| 463 | |
| 464 | friend class Track; |
| 465 | friend class TrackBase; |
| 466 | friend class PlaybackThread; |
| 467 | friend class MixerThread; |
| 468 | friend class DirectOutputThread; |
| 469 | friend class DuplicatingThread; |
| 470 | friend class RecordThread; |
| 471 | friend class RecordTrack; |
| 472 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 473 | int mType; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 474 | Condition mWaitWorkCV; |
| 475 | sp<AudioFlinger> mAudioFlinger; |
| 476 | uint32_t mSampleRate; |
| 477 | size_t mFrameCount; |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 478 | uint32_t mChannelMask; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 479 | uint16_t mChannelCount; |
| 480 | uint16_t mFrameSize; |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 481 | uint32_t mFormat; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 482 | Condition mParamCond; |
| 483 | Vector<String8> mNewParameters; |
| 484 | status_t mParamStatus; |
| 485 | Vector<ConfigEvent *> mConfigEvents; |
| 486 | bool mStandby; |
| 487 | int mId; |
| 488 | bool mExiting; |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 489 | Vector< sp<EffectChain> > mEffectChains; |
| 490 | uint32_t mDevice; // output device for PlaybackThread |
| 491 | // input + output devices for RecordThread |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 492 | }; |
| 493 | |
| 494 | // --- PlaybackThread --- |
| 495 | class PlaybackThread : public ThreadBase { |
| 496 | public: |
| 497 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 498 | enum mixer_state { |
| 499 | MIXER_IDLE, |
| 500 | MIXER_TRACKS_ENABLED, |
| 501 | MIXER_TRACKS_READY |
| 502 | }; |
| 503 | |
| 504 | // playback track |
| 505 | class Track : public TrackBase { |
| 506 | public: |
| 507 | Track( const wp<ThreadBase>& thread, |
| 508 | const sp<Client>& client, |
| 509 | int streamType, |
| 510 | uint32_t sampleRate, |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 511 | uint32_t format, |
| 512 | uint32_t channelMask, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 513 | int frameCount, |
| 514 | const sp<IMemory>& sharedBuffer, |
| 515 | int sessionId); |
| 516 | ~Track(); |
| 517 | |
| 518 | void dump(char* buffer, size_t size); |
| 519 | virtual status_t start(); |
| 520 | virtual void stop(); |
| 521 | void pause(); |
| 522 | |
| 523 | void flush(); |
| 524 | void destroy(); |
| 525 | void mute(bool); |
| 526 | void setVolume(float left, float right); |
| 527 | int name() const { |
| 528 | return mName; |
| 529 | } |
| 530 | |
| 531 | int type() const { |
| 532 | return mStreamType; |
| 533 | } |
| 534 | status_t attachAuxEffect(int EffectId); |
| 535 | void setAuxBuffer(int EffectId, int32_t *buffer); |
| 536 | int32_t *auxBuffer() { return mAuxBuffer; } |
| 537 | void setMainBuffer(int16_t *buffer) { mMainBuffer = buffer; } |
| 538 | int16_t *mainBuffer() { return mMainBuffer; } |
| 539 | int auxEffectId() { return mAuxEffectId; } |
| 540 | |
| 541 | |
| 542 | protected: |
| 543 | friend class ThreadBase; |
| 544 | friend class AudioFlinger; |
| 545 | friend class TrackHandle; |
| 546 | friend class PlaybackThread; |
| 547 | friend class MixerThread; |
| 548 | friend class DirectOutputThread; |
| 549 | |
| 550 | Track(const Track&); |
| 551 | Track& operator = (const Track&); |
| 552 | |
| 553 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 554 | bool isMuted() { return mMute; } |
| 555 | bool isPausing() const { |
| 556 | return mState == PAUSING; |
| 557 | } |
| 558 | bool isPaused() const { |
| 559 | return mState == PAUSED; |
| 560 | } |
| 561 | bool isReady() const; |
| 562 | void setPaused() { mState = PAUSED; } |
| 563 | void reset(); |
| 564 | |
| 565 | bool isOutputTrack() const { |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 566 | return (mStreamType == AUDIO_STREAM_CNT); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | // we don't really need a lock for these |
| 570 | float mVolume[2]; |
| 571 | volatile bool mMute; |
| 572 | // FILLED state is used for suppressing volume ramp at begin of playing |
| 573 | enum {FS_FILLING, FS_FILLED, FS_ACTIVE}; |
| 574 | mutable uint8_t mFillingUpStatus; |
| 575 | int8_t mRetryCount; |
| 576 | sp<IMemory> mSharedBuffer; |
| 577 | bool mResetDone; |
| 578 | int mStreamType; |
| 579 | int mName; |
| 580 | int16_t *mMainBuffer; |
| 581 | int32_t *mAuxBuffer; |
| 582 | int mAuxEffectId; |
Eric Laurent | 8f45bd7 | 2010-08-31 13:50:07 -0700 | [diff] [blame] | 583 | bool mHasVolumeController; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 584 | }; // end of Track |
| 585 | |
| 586 | |
| 587 | // playback track |
| 588 | class OutputTrack : public Track { |
| 589 | public: |
| 590 | |
| 591 | class Buffer: public AudioBufferProvider::Buffer { |
| 592 | public: |
| 593 | int16_t *mBuffer; |
| 594 | }; |
| 595 | |
| 596 | OutputTrack( const wp<ThreadBase>& thread, |
| 597 | DuplicatingThread *sourceThread, |
| 598 | uint32_t sampleRate, |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 599 | uint32_t format, |
| 600 | uint32_t channelMask, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 601 | int frameCount); |
| 602 | ~OutputTrack(); |
| 603 | |
| 604 | virtual status_t start(); |
| 605 | virtual void stop(); |
| 606 | bool write(int16_t* data, uint32_t frames); |
| 607 | bool bufferQueueEmpty() { return (mBufferQueue.size() == 0) ? true : false; } |
| 608 | bool isActive() { return mActive; } |
| 609 | wp<ThreadBase>& thread() { return mThread; } |
| 610 | |
| 611 | private: |
| 612 | |
| 613 | status_t obtainBuffer(AudioBufferProvider::Buffer* buffer, uint32_t waitTimeMs); |
| 614 | void clearBufferQueue(); |
| 615 | |
| 616 | // Maximum number of pending buffers allocated by OutputTrack::write() |
| 617 | static const uint8_t kMaxOverFlowBuffers = 10; |
| 618 | |
| 619 | Vector < Buffer* > mBufferQueue; |
| 620 | AudioBufferProvider::Buffer mOutBuffer; |
| 621 | bool mActive; |
| 622 | DuplicatingThread* mSourceThread; |
| 623 | }; // end of OutputTrack |
| 624 | |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 625 | PlaybackThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 626 | virtual ~PlaybackThread(); |
| 627 | |
| 628 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 629 | |
| 630 | // Thread virtuals |
| 631 | virtual status_t readyToRun(); |
| 632 | virtual void onFirstRef(); |
| 633 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 634 | virtual status_t initCheck() const { return (mOutput == 0) ? NO_INIT : NO_ERROR; } |
| 635 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 636 | virtual uint32_t latency() const; |
| 637 | |
| 638 | virtual status_t setMasterVolume(float value); |
| 639 | virtual status_t setMasterMute(bool muted); |
| 640 | |
| 641 | virtual float masterVolume() const; |
| 642 | virtual bool masterMute() const; |
| 643 | |
| 644 | virtual status_t setStreamVolume(int stream, float value); |
| 645 | virtual status_t setStreamMute(int stream, bool muted); |
| 646 | |
| 647 | virtual float streamVolume(int stream) const; |
| 648 | virtual bool streamMute(int stream) const; |
| 649 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 650 | sp<Track> createTrack_l( |
| 651 | const sp<AudioFlinger::Client>& client, |
| 652 | int streamType, |
| 653 | uint32_t sampleRate, |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 654 | uint32_t format, |
| 655 | uint32_t channelMask, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 656 | int frameCount, |
| 657 | const sp<IMemory>& sharedBuffer, |
| 658 | int sessionId, |
| 659 | status_t *status); |
| 660 | |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 661 | AudioStreamOut* getOutput() { return mOutput; } |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 662 | virtual audio_stream_t* stream() { return &mOutput->stream->common; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 663 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 664 | void suspend() { mSuspended++; } |
| 665 | void restore() { if (mSuspended) mSuspended--; } |
| 666 | bool isSuspended() { return (mSuspended != 0); } |
| 667 | virtual String8 getParameters(const String8& keys); |
| 668 | virtual void audioConfigChanged_l(int event, int param = 0); |
| 669 | virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames); |
| 670 | int16_t *mixBuffer() { return mMixBuffer; }; |
| 671 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 672 | virtual void detachAuxEffect_l(int effectId); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 673 | status_t attachAuxEffect(const sp<AudioFlinger::PlaybackThread::Track> track, |
| 674 | int EffectId); |
| 675 | status_t attachAuxEffect_l(const sp<AudioFlinger::PlaybackThread::Track> track, |
| 676 | int EffectId); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 677 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 678 | virtual status_t addEffectChain_l(const sp<EffectChain>& chain); |
| 679 | virtual size_t removeEffectChain_l(const sp<EffectChain>& chain); |
| 680 | virtual uint32_t hasAudioSession(int sessionId); |
| 681 | virtual uint32_t getStrategyForSession_l(int sessionId); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 682 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 683 | struct stream_type_t { |
| 684 | stream_type_t() |
| 685 | : volume(1.0f), |
| 686 | mute(false) |
| 687 | { |
| 688 | } |
| 689 | float volume; |
| 690 | bool mute; |
| 691 | }; |
| 692 | |
| 693 | protected: |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 694 | int16_t* mMixBuffer; |
| 695 | int mSuspended; |
| 696 | int mBytesWritten; |
| 697 | bool mMasterMute; |
| 698 | SortedVector< wp<Track> > mActiveTracks; |
| 699 | |
| 700 | virtual int getTrackName_l() = 0; |
| 701 | virtual void deleteTrackName_l(int name) = 0; |
| 702 | virtual uint32_t activeSleepTimeUs() = 0; |
| 703 | virtual uint32_t idleSleepTimeUs() = 0; |
Eric Laurent | 25cbe0e | 2010-08-18 18:13:17 -0700 | [diff] [blame] | 704 | virtual uint32_t suspendSleepTimeUs() = 0; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 705 | |
| 706 | private: |
| 707 | |
| 708 | friend class AudioFlinger; |
| 709 | friend class OutputTrack; |
| 710 | friend class Track; |
| 711 | friend class TrackBase; |
| 712 | friend class MixerThread; |
| 713 | friend class DirectOutputThread; |
| 714 | friend class DuplicatingThread; |
| 715 | |
| 716 | PlaybackThread(const Client&); |
| 717 | PlaybackThread& operator = (const PlaybackThread&); |
| 718 | |
| 719 | status_t addTrack_l(const sp<Track>& track); |
| 720 | void destroyTrack_l(const sp<Track>& track); |
Eric Laurent | b469b94 | 2011-05-09 12:09:06 -0700 | [diff] [blame] | 721 | void removeTrack_l(const sp<Track>& track); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 722 | |
| 723 | void readOutputParameters(); |
| 724 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 725 | virtual status_t dumpInternals(int fd, const Vector<String16>& args); |
| 726 | status_t dumpTracks(int fd, const Vector<String16>& args); |
| 727 | status_t dumpEffectChains(int fd, const Vector<String16>& args); |
| 728 | |
| 729 | SortedVector< sp<Track> > mTracks; |
| 730 | // mStreamTypes[] uses 1 additionnal stream type internally for the OutputTrack used by DuplicatingThread |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 731 | stream_type_t mStreamTypes[AUDIO_STREAM_CNT + 1]; |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 732 | AudioStreamOut* mOutput; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 733 | float mMasterVolume; |
| 734 | nsecs_t mLastWriteTime; |
| 735 | int mNumWrites; |
| 736 | int mNumDelayedWrites; |
| 737 | bool mInWrite; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 738 | }; |
| 739 | |
| 740 | class MixerThread : public PlaybackThread { |
| 741 | public: |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 742 | MixerThread (const sp<AudioFlinger>& audioFlinger, |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 743 | AudioStreamOut* output, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 744 | int id, |
| 745 | uint32_t device); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 746 | virtual ~MixerThread(); |
| 747 | |
| 748 | // Thread virtuals |
| 749 | virtual bool threadLoop(); |
| 750 | |
| 751 | void invalidateTracks(int streamType); |
| 752 | virtual bool checkForNewParameters_l(); |
| 753 | virtual status_t dumpInternals(int fd, const Vector<String16>& args); |
| 754 | |
| 755 | protected: |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 756 | uint32_t prepareTracks_l(const SortedVector< wp<Track> >& activeTracks, |
| 757 | Vector< sp<Track> > *tracksToRemove); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 758 | virtual int getTrackName_l(); |
| 759 | virtual void deleteTrackName_l(int name); |
| 760 | virtual uint32_t activeSleepTimeUs(); |
| 761 | virtual uint32_t idleSleepTimeUs(); |
Eric Laurent | 25cbe0e | 2010-08-18 18:13:17 -0700 | [diff] [blame] | 762 | virtual uint32_t suspendSleepTimeUs(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 763 | |
| 764 | AudioMixer* mAudioMixer; |
| 765 | }; |
| 766 | |
| 767 | class DirectOutputThread : public PlaybackThread { |
| 768 | public: |
| 769 | |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 770 | DirectOutputThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 771 | ~DirectOutputThread(); |
| 772 | |
| 773 | // Thread virtuals |
| 774 | virtual bool threadLoop(); |
| 775 | |
| 776 | virtual bool checkForNewParameters_l(); |
| 777 | |
| 778 | protected: |
| 779 | virtual int getTrackName_l(); |
| 780 | virtual void deleteTrackName_l(int name); |
| 781 | virtual uint32_t activeSleepTimeUs(); |
| 782 | virtual uint32_t idleSleepTimeUs(); |
Eric Laurent | 25cbe0e | 2010-08-18 18:13:17 -0700 | [diff] [blame] | 783 | virtual uint32_t suspendSleepTimeUs(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 784 | |
| 785 | private: |
| 786 | void applyVolume(uint16_t leftVol, uint16_t rightVol, bool ramp); |
| 787 | |
| 788 | float mLeftVolFloat; |
| 789 | float mRightVolFloat; |
| 790 | uint16_t mLeftVolShort; |
| 791 | uint16_t mRightVolShort; |
| 792 | }; |
| 793 | |
| 794 | class DuplicatingThread : public MixerThread { |
| 795 | public: |
| 796 | DuplicatingThread (const sp<AudioFlinger>& audioFlinger, MixerThread* mainThread, int id); |
| 797 | ~DuplicatingThread(); |
| 798 | |
| 799 | // Thread virtuals |
| 800 | virtual bool threadLoop(); |
| 801 | void addOutputTrack(MixerThread* thread); |
| 802 | void removeOutputTrack(MixerThread* thread); |
| 803 | uint32_t waitTimeMs() { return mWaitTimeMs; } |
| 804 | protected: |
| 805 | virtual uint32_t activeSleepTimeUs(); |
| 806 | |
| 807 | private: |
| 808 | bool outputsReady(SortedVector< sp<OutputTrack> > &outputTracks); |
| 809 | void updateWaitTime(); |
| 810 | |
| 811 | SortedVector < sp<OutputTrack> > mOutputTracks; |
| 812 | uint32_t mWaitTimeMs; |
| 813 | }; |
| 814 | |
| 815 | PlaybackThread *checkPlaybackThread_l(int output) const; |
| 816 | MixerThread *checkMixerThread_l(int output) const; |
| 817 | RecordThread *checkRecordThread_l(int input) const; |
| 818 | float streamVolumeInternal(int stream) const { return mStreamTypes[stream].volume; } |
| 819 | void audioConfigChanged_l(int event, int ioHandle, void *param2); |
| 820 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 821 | uint32_t nextUniqueId(); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 822 | status_t moveEffectChain_l(int session, |
| 823 | AudioFlinger::PlaybackThread *srcThread, |
Eric Laurent | 39e94f8 | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 824 | AudioFlinger::PlaybackThread *dstThread, |
| 825 | bool reRegister); |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 826 | PlaybackThread *primaryPlaybackThread_l(); |
| 827 | uint32_t primaryOutputDevice_l(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 828 | |
| 829 | friend class AudioBuffer; |
| 830 | |
| 831 | class TrackHandle : public android::BnAudioTrack { |
| 832 | public: |
| 833 | TrackHandle(const sp<PlaybackThread::Track>& track); |
| 834 | virtual ~TrackHandle(); |
| 835 | virtual status_t start(); |
| 836 | virtual void stop(); |
| 837 | virtual void flush(); |
| 838 | virtual void mute(bool); |
| 839 | virtual void pause(); |
| 840 | virtual void setVolume(float left, float right); |
| 841 | virtual sp<IMemory> getCblk() const; |
| 842 | virtual status_t attachAuxEffect(int effectId); |
| 843 | virtual status_t onTransact( |
| 844 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 845 | private: |
| 846 | sp<PlaybackThread::Track> mTrack; |
| 847 | }; |
| 848 | |
| 849 | friend class Client; |
| 850 | friend class PlaybackThread::Track; |
| 851 | |
| 852 | |
| 853 | void removeClient_l(pid_t pid); |
| 854 | void removeNotificationClient(pid_t pid); |
| 855 | |
| 856 | |
| 857 | // record thread |
| 858 | class RecordThread : public ThreadBase, public AudioBufferProvider |
| 859 | { |
| 860 | public: |
| 861 | |
| 862 | // record track |
| 863 | class RecordTrack : public TrackBase { |
| 864 | public: |
| 865 | RecordTrack(const wp<ThreadBase>& thread, |
| 866 | const sp<Client>& client, |
| 867 | uint32_t sampleRate, |
Jean-Michel Trivi | 0d255b2 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 868 | uint32_t format, |
| 869 | uint32_t channelMask, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 870 | int frameCount, |
| 871 | uint32_t flags, |
| 872 | int sessionId); |
| 873 | ~RecordTrack(); |
| 874 | |
| 875 | virtual status_t start(); |
| 876 | virtual void stop(); |
| 877 | |
| 878 | bool overflow() { bool tmp = mOverflow; mOverflow = false; return tmp; } |
| 879 | bool setOverflow() { bool tmp = mOverflow; mOverflow = true; return tmp; } |
| 880 | |
| 881 | void dump(char* buffer, size_t size); |
| 882 | private: |
| 883 | friend class AudioFlinger; |
| 884 | friend class RecordThread; |
| 885 | |
| 886 | RecordTrack(const RecordTrack&); |
| 887 | RecordTrack& operator = (const RecordTrack&); |
| 888 | |
| 889 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 890 | |
| 891 | bool mOverflow; |
| 892 | }; |
| 893 | |
| 894 | |
| 895 | RecordThread(const sp<AudioFlinger>& audioFlinger, |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 896 | AudioStreamIn *input, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 897 | uint32_t sampleRate, |
| 898 | uint32_t channels, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 899 | int id, |
| 900 | uint32_t device); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 901 | ~RecordThread(); |
| 902 | |
| 903 | virtual bool threadLoop(); |
| 904 | virtual status_t readyToRun() { return NO_ERROR; } |
| 905 | virtual void onFirstRef(); |
| 906 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 907 | virtual status_t initCheck() const { return (mInput == 0) ? NO_INIT : NO_ERROR; } |
| 908 | sp<AudioFlinger::RecordThread::RecordTrack> createRecordTrack_l( |
| 909 | const sp<AudioFlinger::Client>& client, |
| 910 | uint32_t sampleRate, |
| 911 | int format, |
| 912 | int channelMask, |
| 913 | int frameCount, |
| 914 | uint32_t flags, |
| 915 | int sessionId, |
| 916 | status_t *status); |
| 917 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 918 | status_t start(RecordTrack* recordTrack); |
| 919 | void stop(RecordTrack* recordTrack); |
| 920 | status_t dump(int fd, const Vector<String16>& args); |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 921 | AudioStreamIn* getInput() { return mInput; } |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 922 | virtual audio_stream_t* stream() { return &mInput->stream->common; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 923 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 924 | |
| 925 | void setTrack(RecordTrack *recordTrack) { mTrack = recordTrack; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 926 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 927 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 928 | virtual bool checkForNewParameters_l(); |
| 929 | virtual String8 getParameters(const String8& keys); |
| 930 | virtual void audioConfigChanged_l(int event, int param = 0); |
| 931 | void readInputParameters(); |
| 932 | virtual unsigned int getInputFramesLost(); |
| 933 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 934 | virtual status_t addEffectChain_l(const sp<EffectChain>& chain); |
| 935 | virtual size_t removeEffectChain_l(const sp<EffectChain>& chain); |
| 936 | virtual uint32_t hasAudioSession(int sessionId); |
| 937 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 938 | private: |
| 939 | RecordThread(); |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 940 | AudioStreamIn *mInput; |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 941 | RecordTrack* mTrack; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 942 | sp<RecordTrack> mActiveTrack; |
| 943 | Condition mStartStopCond; |
| 944 | AudioResampler *mResampler; |
| 945 | int32_t *mRsmpOutBuffer; |
| 946 | int16_t *mRsmpInBuffer; |
| 947 | size_t mRsmpInIndex; |
| 948 | size_t mInputBytes; |
| 949 | int mReqChannelCount; |
| 950 | uint32_t mReqSampleRate; |
| 951 | ssize_t mBytesRead; |
| 952 | }; |
| 953 | |
| 954 | class RecordHandle : public android::BnAudioRecord { |
| 955 | public: |
| 956 | RecordHandle(const sp<RecordThread::RecordTrack>& recordTrack); |
| 957 | virtual ~RecordHandle(); |
| 958 | virtual status_t start(); |
| 959 | virtual void stop(); |
| 960 | virtual sp<IMemory> getCblk() const; |
| 961 | virtual status_t onTransact( |
| 962 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 963 | private: |
| 964 | sp<RecordThread::RecordTrack> mRecordTrack; |
| 965 | }; |
| 966 | |
| 967 | //--- Audio Effect Management |
| 968 | |
| 969 | // EffectModule and EffectChain classes both have their own mutex to protect |
| 970 | // state changes or resource modifications. Always respect the following order |
| 971 | // if multiple mutexes must be acquired to avoid cross deadlock: |
| 972 | // AudioFlinger -> ThreadBase -> EffectChain -> EffectModule |
| 973 | |
| 974 | // The EffectModule class is a wrapper object controlling the effect engine implementation |
| 975 | // in the effect library. It prevents concurrent calls to process() and command() functions |
| 976 | // from different client threads. It keeps a list of EffectHandle objects corresponding |
| 977 | // to all client applications using this effect and notifies applications of effect state, |
| 978 | // control or parameter changes. It manages the activation state machine to send appropriate |
| 979 | // reset, enable, disable commands to effect engine and provide volume |
| 980 | // ramping when effects are activated/deactivated. |
| 981 | // When controlling an auxiliary effect, the EffectModule also provides an input buffer used by |
| 982 | // the attached track(s) to accumulate their auxiliary channel. |
| 983 | class EffectModule: public RefBase { |
| 984 | public: |
| 985 | EffectModule(const wp<ThreadBase>& wThread, |
| 986 | const wp<AudioFlinger::EffectChain>& chain, |
| 987 | effect_descriptor_t *desc, |
| 988 | int id, |
| 989 | int sessionId); |
| 990 | ~EffectModule(); |
| 991 | |
| 992 | enum effect_state { |
| 993 | IDLE, |
| 994 | RESTART, |
| 995 | STARTING, |
| 996 | ACTIVE, |
| 997 | STOPPING, |
| 998 | STOPPED |
| 999 | }; |
| 1000 | |
| 1001 | int id() { return mId; } |
| 1002 | void process(); |
| 1003 | void updateState(); |
Eric Laurent | 25f4395 | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 1004 | status_t command(uint32_t cmdCode, |
| 1005 | uint32_t cmdSize, |
| 1006 | void *pCmdData, |
| 1007 | uint32_t *replySize, |
| 1008 | void *pReplyData); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1009 | |
| 1010 | void reset_l(); |
| 1011 | status_t configure(); |
| 1012 | status_t init(); |
| 1013 | uint32_t state() { |
| 1014 | return mState; |
| 1015 | } |
| 1016 | uint32_t status() { |
| 1017 | return mStatus; |
| 1018 | } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1019 | int sessionId() { |
| 1020 | return mSessionId; |
| 1021 | } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1022 | status_t setEnabled(bool enabled); |
| 1023 | bool isEnabled(); |
Eric Laurent | 8f45bd7 | 2010-08-31 13:50:07 -0700 | [diff] [blame] | 1024 | bool isProcessEnabled(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1025 | |
| 1026 | void setInBuffer(int16_t *buffer) { mConfig.inputCfg.buffer.s16 = buffer; } |
| 1027 | int16_t *inBuffer() { return mConfig.inputCfg.buffer.s16; } |
| 1028 | void setOutBuffer(int16_t *buffer) { mConfig.outputCfg.buffer.s16 = buffer; } |
| 1029 | int16_t *outBuffer() { return mConfig.outputCfg.buffer.s16; } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1030 | void setChain(const wp<EffectChain>& chain) { mChain = chain; } |
| 1031 | void setThread(const wp<ThreadBase>& thread) { mThread = thread; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1032 | |
| 1033 | status_t addHandle(sp<EffectHandle>& handle); |
| 1034 | void disconnect(const wp<EffectHandle>& handle); |
| 1035 | size_t removeHandle (const wp<EffectHandle>& handle); |
| 1036 | |
| 1037 | effect_descriptor_t& desc() { return mDescriptor; } |
| 1038 | wp<EffectChain>& chain() { return mChain; } |
| 1039 | |
| 1040 | status_t setDevice(uint32_t device); |
| 1041 | status_t setVolume(uint32_t *left, uint32_t *right, bool controller); |
| 1042 | status_t setMode(uint32_t mode); |
| 1043 | |
| 1044 | status_t dump(int fd, const Vector<String16>& args); |
| 1045 | |
| 1046 | protected: |
| 1047 | |
| 1048 | // Maximum time allocated to effect engines to complete the turn off sequence |
| 1049 | static const uint32_t MAX_DISABLE_TIME_MS = 10000; |
| 1050 | |
| 1051 | EffectModule(const EffectModule&); |
| 1052 | EffectModule& operator = (const EffectModule&); |
| 1053 | |
| 1054 | status_t start_l(); |
| 1055 | status_t stop_l(); |
| 1056 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1057 | Mutex mLock; // mutex for process, commands and handles list protection |
| 1058 | wp<ThreadBase> mThread; // parent thread |
| 1059 | wp<EffectChain> mChain; // parent effect chain |
| 1060 | int mId; // this instance unique ID |
| 1061 | int mSessionId; // audio session ID |
| 1062 | effect_descriptor_t mDescriptor;// effect descriptor received from effect engine |
| 1063 | effect_config_t mConfig; // input and output audio configuration |
Eric Laurent | e1315cf | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 1064 | effect_handle_t mEffectInterface; // Effect module C API |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1065 | status_t mStatus; // initialization status |
| 1066 | uint32_t mState; // current activation state (effect_state) |
| 1067 | Vector< wp<EffectHandle> > mHandles; // list of client handles |
| 1068 | uint32_t mMaxDisableWaitCnt; // maximum grace period before forcing an effect off after |
| 1069 | // sending disable command. |
| 1070 | uint32_t mDisableWaitCnt; // current process() calls count during disable period. |
| 1071 | }; |
| 1072 | |
| 1073 | // The EffectHandle class implements the IEffect interface. It provides resources |
| 1074 | // to receive parameter updates, keeps track of effect control |
| 1075 | // ownership and state and has a pointer to the EffectModule object it is controlling. |
| 1076 | // There is one EffectHandle object for each application controlling (or using) |
| 1077 | // an effect module. |
| 1078 | // The EffectHandle is obtained by calling AudioFlinger::createEffect(). |
| 1079 | class EffectHandle: public android::BnEffect { |
| 1080 | public: |
| 1081 | |
| 1082 | EffectHandle(const sp<EffectModule>& effect, |
| 1083 | const sp<AudioFlinger::Client>& client, |
| 1084 | const sp<IEffectClient>& effectClient, |
| 1085 | int32_t priority); |
| 1086 | virtual ~EffectHandle(); |
| 1087 | |
| 1088 | // IEffect |
| 1089 | virtual status_t enable(); |
| 1090 | virtual status_t disable(); |
Eric Laurent | 25f4395 | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 1091 | virtual status_t command(uint32_t cmdCode, |
| 1092 | uint32_t cmdSize, |
| 1093 | void *pCmdData, |
| 1094 | uint32_t *replySize, |
| 1095 | void *pReplyData); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1096 | virtual void disconnect(); |
| 1097 | virtual sp<IMemory> getCblk() const; |
| 1098 | virtual status_t onTransact(uint32_t code, const Parcel& data, |
| 1099 | Parcel* reply, uint32_t flags); |
| 1100 | |
| 1101 | |
| 1102 | // Give or take control of effect module |
| 1103 | void setControl(bool hasControl, bool signal); |
Eric Laurent | 25f4395 | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 1104 | void commandExecuted(uint32_t cmdCode, |
| 1105 | uint32_t cmdSize, |
| 1106 | void *pCmdData, |
| 1107 | uint32_t replySize, |
| 1108 | void *pReplyData); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1109 | void setEnabled(bool enabled); |
| 1110 | |
| 1111 | // Getters |
| 1112 | int id() { return mEffect->id(); } |
| 1113 | int priority() { return mPriority; } |
| 1114 | bool hasControl() { return mHasControl; } |
| 1115 | sp<EffectModule> effect() { return mEffect; } |
| 1116 | |
| 1117 | void dump(char* buffer, size_t size); |
| 1118 | |
| 1119 | protected: |
| 1120 | |
| 1121 | EffectHandle(const EffectHandle&); |
| 1122 | EffectHandle& operator =(const EffectHandle&); |
| 1123 | |
| 1124 | sp<EffectModule> mEffect; // pointer to controlled EffectModule |
| 1125 | sp<IEffectClient> mEffectClient; // callback interface for client notifications |
| 1126 | sp<Client> mClient; // client for shared memory allocation |
| 1127 | sp<IMemory> mCblkMemory; // shared memory for control block |
| 1128 | effect_param_cblk_t* mCblk; // control block for deferred parameter setting via shared memory |
| 1129 | uint8_t* mBuffer; // pointer to parameter area in shared memory |
| 1130 | int mPriority; // client application priority to control the effect |
| 1131 | bool mHasControl; // true if this handle is controlling the effect |
| 1132 | }; |
| 1133 | |
| 1134 | // the EffectChain class represents a group of effects associated to one audio session. |
| 1135 | // There can be any number of EffectChain objects per output mixer thread (PlaybackThread). |
| 1136 | // The EffecChain with session ID 0 contains global effects applied to the output mix. |
| 1137 | // Effects in this chain can be insert or auxiliary. Effects in other chains (attached to tracks) |
| 1138 | // are insert only. The EffectChain maintains an ordered list of effect module, the order corresponding |
| 1139 | // in the effect process order. When attached to a track (session ID != 0), it also provide it's own |
| 1140 | // input buffer used by the track as accumulation buffer. |
| 1141 | class EffectChain: public RefBase { |
| 1142 | public: |
| 1143 | EffectChain(const wp<ThreadBase>& wThread, int sessionId); |
| 1144 | ~EffectChain(); |
| 1145 | |
| 1146 | void process_l(); |
| 1147 | |
| 1148 | void lock() { |
| 1149 | mLock.lock(); |
| 1150 | } |
| 1151 | void unlock() { |
| 1152 | mLock.unlock(); |
| 1153 | } |
| 1154 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1155 | status_t addEffect_l(const sp<EffectModule>& handle); |
Eric Laurent | cab1124 | 2010-07-15 12:50:15 -0700 | [diff] [blame] | 1156 | size_t removeEffect_l(const sp<EffectModule>& handle); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1157 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame^] | 1158 | int sessionId() { return mSessionId; } |
| 1159 | void setSessionId(int sessionId) { mSessionId = sessionId; } |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1160 | |
Eric Laurent | cab1124 | 2010-07-15 12:50:15 -0700 | [diff] [blame] | 1161 | sp<EffectModule> getEffectFromDesc_l(effect_descriptor_t *descriptor); |
| 1162 | sp<EffectModule> getEffectFromId_l(int id); |
| 1163 | bool setVolume_l(uint32_t *left, uint32_t *right); |
| 1164 | void setDevice_l(uint32_t device); |
| 1165 | void setMode_l(uint32_t mode); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1166 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1167 | void setInBuffer(int16_t *buffer, bool ownsBuffer = false) { |
| 1168 | mInBuffer = buffer; |
| 1169 | mOwnInBuffer = ownsBuffer; |
| 1170 | } |
| 1171 | int16_t *inBuffer() { |
| 1172 | return mInBuffer; |
| 1173 | } |
| 1174 | void setOutBuffer(int16_t *buffer) { |
| 1175 | mOutBuffer = buffer; |
| 1176 | } |
| 1177 | int16_t *outBuffer() { |
| 1178 | return mOutBuffer; |
| 1179 | } |
| 1180 | |
Eric Laurent | b469b94 | 2011-05-09 12:09:06 -0700 | [diff] [blame] | 1181 | void incTrackCnt() { android_atomic_inc(&mTrackCnt); } |
| 1182 | void decTrackCnt() { android_atomic_dec(&mTrackCnt); } |
| 1183 | int32_t trackCnt() { return mTrackCnt;} |
| 1184 | |
| 1185 | void incActiveTrackCnt() { android_atomic_inc(&mActiveTrackCnt); } |
| 1186 | void decActiveTrackCnt() { android_atomic_dec(&mActiveTrackCnt); } |
| 1187 | int32_t activeTrackCnt() { return mActiveTrackCnt;} |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1188 | |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1189 | uint32_t strategy() { return mStrategy; } |
| 1190 | void setStrategy(uint32_t strategy) |
| 1191 | { mStrategy = strategy; } |
| 1192 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1193 | status_t dump(int fd, const Vector<String16>& args); |
| 1194 | |
| 1195 | protected: |
| 1196 | |
| 1197 | EffectChain(const EffectChain&); |
| 1198 | EffectChain& operator =(const EffectChain&); |
| 1199 | |
| 1200 | wp<ThreadBase> mThread; // parent mixer thread |
| 1201 | Mutex mLock; // mutex protecting effect list |
| 1202 | Vector<sp<EffectModule> > mEffects; // list of effect modules |
| 1203 | int mSessionId; // audio session ID |
| 1204 | int16_t *mInBuffer; // chain input buffer |
| 1205 | int16_t *mOutBuffer; // chain output buffer |
Eric Laurent | b469b94 | 2011-05-09 12:09:06 -0700 | [diff] [blame] | 1206 | volatile int32_t mActiveTrackCnt; // number of active tracks connected |
| 1207 | volatile int32_t mTrackCnt; // number of tracks connected |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1208 | bool mOwnInBuffer; // true if the chain owns its input buffer |
Eric Laurent | cab1124 | 2010-07-15 12:50:15 -0700 | [diff] [blame] | 1209 | int mVolumeCtrlIdx; // index of insert effect having control over volume |
| 1210 | uint32_t mLeftVolume; // previous volume on left channel |
| 1211 | uint32_t mRightVolume; // previous volume on right channel |
Eric Laurent | f997cab | 2010-07-19 06:24:46 -0700 | [diff] [blame] | 1212 | uint32_t mNewLeftVolume; // new volume on left channel |
| 1213 | uint32_t mNewRightVolume; // new volume on right channel |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1214 | uint32_t mStrategy; // strategy for this effect chain |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1215 | }; |
| 1216 | |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1217 | struct AudioStreamOut { |
| 1218 | audio_hw_device_t *hwDev; |
| 1219 | audio_stream_out_t *stream; |
| 1220 | |
| 1221 | AudioStreamOut(audio_hw_device_t *dev, audio_stream_out_t *out) : |
| 1222 | hwDev(dev), stream(out) {} |
| 1223 | }; |
| 1224 | |
| 1225 | struct AudioStreamIn { |
| 1226 | audio_hw_device_t *hwDev; |
| 1227 | audio_stream_in_t *stream; |
| 1228 | |
| 1229 | AudioStreamIn(audio_hw_device_t *dev, audio_stream_in_t *in) : |
| 1230 | hwDev(dev), stream(in) {} |
| 1231 | }; |
| 1232 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1233 | friend class RecordThread; |
| 1234 | friend class PlaybackThread; |
| 1235 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1236 | mutable Mutex mLock; |
| 1237 | |
| 1238 | DefaultKeyedVector< pid_t, wp<Client> > mClients; |
| 1239 | |
| 1240 | mutable Mutex mHardwareLock; |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1241 | audio_hw_device_t* mPrimaryHardwareDev; |
| 1242 | Vector<audio_hw_device_t*> mAudioHwDevs; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1243 | mutable int mHardwareStatus; |
| 1244 | |
| 1245 | |
| 1246 | DefaultKeyedVector< int, sp<PlaybackThread> > mPlaybackThreads; |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 1247 | PlaybackThread::stream_type_t mStreamTypes[AUDIO_STREAM_CNT]; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1248 | float mMasterVolume; |
| 1249 | bool mMasterMute; |
| 1250 | |
| 1251 | DefaultKeyedVector< int, sp<RecordThread> > mRecordThreads; |
| 1252 | |
| 1253 | DefaultKeyedVector< pid_t, sp<NotificationClient> > mNotificationClients; |
| 1254 | volatile int32_t mNextUniqueId; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1255 | uint32_t mMode; |
| 1256 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1257 | }; |
| 1258 | |
Dima Zavin | 799a70e | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1259 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1260 | // ---------------------------------------------------------------------------- |
| 1261 | |
| 1262 | }; // namespace android |
| 1263 | |
| 1264 | #endif // ANDROID_AUDIO_FLINGER_H |