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