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