The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [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 | |
| 24 | #include <media/IAudioFlinger.h> |
| 25 | #include <media/IAudioFlingerClient.h> |
| 26 | #include <media/IAudioTrack.h> |
| 27 | #include <media/IAudioRecord.h> |
| 28 | #include <media/AudioTrack.h> |
| 29 | |
| 30 | #include <utils/Atomic.h> |
| 31 | #include <utils/Errors.h> |
| 32 | #include <utils/threads.h> |
| 33 | #include <utils/MemoryDealer.h> |
| 34 | #include <utils/KeyedVector.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 AudioMixer; |
| 46 | class AudioBuffer; |
| 47 | |
| 48 | |
| 49 | // ---------------------------------------------------------------------------- |
| 50 | |
| 51 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 52 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 53 | |
| 54 | |
| 55 | // ---------------------------------------------------------------------------- |
| 56 | |
| 57 | static const nsecs_t kStandbyTimeInNsecs = seconds(3); |
| 58 | |
| 59 | class AudioFlinger : public BnAudioFlinger, public IBinder::DeathRecipient |
| 60 | { |
| 61 | public: |
| 62 | static void instantiate(); |
| 63 | |
| 64 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 65 | |
| 66 | // IAudioFlinger interface |
| 67 | virtual sp<IAudioTrack> createTrack( |
| 68 | pid_t pid, |
| 69 | int streamType, |
| 70 | uint32_t sampleRate, |
| 71 | int format, |
| 72 | int channelCount, |
| 73 | int frameCount, |
| 74 | uint32_t flags, |
| 75 | const sp<IMemory>& sharedBuffer, |
| 76 | status_t *status); |
| 77 | |
| 78 | virtual uint32_t sampleRate(int output) const; |
| 79 | virtual int channelCount(int output) const; |
| 80 | virtual int format(int output) const; |
| 81 | virtual size_t frameCount(int output) const; |
| 82 | virtual uint32_t latency(int output) const; |
| 83 | |
| 84 | virtual status_t setMasterVolume(float value); |
| 85 | virtual status_t setMasterMute(bool muted); |
| 86 | |
| 87 | virtual float masterVolume() const; |
| 88 | virtual bool masterMute() const; |
| 89 | |
| 90 | virtual status_t setStreamVolume(int stream, float value); |
| 91 | virtual status_t setStreamMute(int stream, bool muted); |
| 92 | |
| 93 | virtual float streamVolume(int stream) const; |
| 94 | virtual bool streamMute(int stream) const; |
| 95 | |
| 96 | virtual status_t setRouting(int mode, uint32_t routes, uint32_t mask); |
| 97 | virtual uint32_t getRouting(int mode) const; |
| 98 | |
| 99 | virtual status_t setMode(int mode); |
| 100 | virtual int getMode() const; |
| 101 | |
| 102 | virtual status_t setMicMute(bool state); |
| 103 | virtual bool getMicMute() const; |
| 104 | |
| 105 | virtual bool isMusicActive() const; |
| 106 | |
| 107 | virtual bool isA2dpEnabled() const; |
| 108 | |
| 109 | virtual status_t setParameter(const char* key, const char* value); |
| 110 | |
| 111 | virtual void registerClient(const sp<IAudioFlingerClient>& client); |
| 112 | |
| 113 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); |
| 114 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame^] | 115 | virtual void wakeUp() { mWaitWorkCV.broadcast(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | |
| 117 | // IBinder::DeathRecipient |
| 118 | virtual void binderDied(const wp<IBinder>& who); |
| 119 | |
| 120 | enum hardware_call_state { |
| 121 | AUDIO_HW_IDLE = 0, |
| 122 | AUDIO_HW_INIT, |
| 123 | AUDIO_HW_OUTPUT_OPEN, |
| 124 | AUDIO_HW_OUTPUT_CLOSE, |
| 125 | AUDIO_HW_INPUT_OPEN, |
| 126 | AUDIO_HW_INPUT_CLOSE, |
| 127 | AUDIO_HW_STANDBY, |
| 128 | AUDIO_HW_SET_MASTER_VOLUME, |
| 129 | AUDIO_HW_GET_ROUTING, |
| 130 | AUDIO_HW_SET_ROUTING, |
| 131 | AUDIO_HW_GET_MODE, |
| 132 | AUDIO_HW_SET_MODE, |
| 133 | AUDIO_HW_GET_MIC_MUTE, |
| 134 | AUDIO_HW_SET_MIC_MUTE, |
| 135 | AUDIO_SET_VOICE_VOLUME, |
| 136 | AUDIO_SET_PARAMETER, |
| 137 | }; |
| 138 | |
| 139 | // record interface |
| 140 | virtual sp<IAudioRecord> openRecord( |
| 141 | pid_t pid, |
| 142 | int streamType, |
| 143 | uint32_t sampleRate, |
| 144 | int format, |
| 145 | int channelCount, |
| 146 | int frameCount, |
| 147 | uint32_t flags, |
| 148 | status_t *status); |
| 149 | |
| 150 | virtual status_t onTransact( |
| 151 | uint32_t code, |
| 152 | const Parcel& data, |
| 153 | Parcel* reply, |
| 154 | uint32_t flags); |
| 155 | |
| 156 | private: |
| 157 | AudioFlinger(); |
| 158 | virtual ~AudioFlinger(); |
| 159 | |
| 160 | void setOutput(int outputType); |
| 161 | void doSetOutput(int outputType); |
| 162 | |
| 163 | #ifdef WITH_A2DP |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame^] | 164 | void setA2dpEnabled_l(bool enable); |
| 165 | void checkA2dpEnabledChange_l(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | #endif |
| 167 | static bool streamForcedToSpeaker(int streamType); |
| 168 | |
| 169 | // Management of forced route to speaker for certain track types. |
| 170 | enum force_speaker_command { |
| 171 | ACTIVE_TRACK_ADDED = 0, |
| 172 | ACTIVE_TRACK_REMOVED, |
| 173 | CHECK_ROUTE_RESTORE_TIME, |
| 174 | FORCE_ROUTE_RESTORE |
| 175 | }; |
| 176 | void handleForcedSpeakerRoute(int command); |
| 177 | |
| 178 | // Internal dump utilites. |
| 179 | status_t dumpPermissionDenial(int fd, const Vector<String16>& args); |
| 180 | status_t dumpClients(int fd, const Vector<String16>& args); |
| 181 | status_t dumpInternals(int fd, const Vector<String16>& args); |
| 182 | |
| 183 | // --- Client --- |
| 184 | class Client : public RefBase { |
| 185 | public: |
| 186 | Client(const sp<AudioFlinger>& audioFlinger, pid_t pid); |
| 187 | virtual ~Client(); |
| 188 | const sp<MemoryDealer>& heap() const; |
| 189 | pid_t pid() const { return mPid; } |
| 190 | private: |
| 191 | Client(const Client&); |
| 192 | Client& operator = (const Client&); |
| 193 | sp<AudioFlinger> mAudioFlinger; |
| 194 | sp<MemoryDealer> mMemoryDealer; |
| 195 | pid_t mPid; |
| 196 | }; |
| 197 | |
| 198 | |
| 199 | class TrackHandle; |
| 200 | class RecordHandle; |
| 201 | class AudioRecordThread; |
| 202 | |
| 203 | |
| 204 | // --- MixerThread --- |
| 205 | class MixerThread : public Thread { |
| 206 | public: |
| 207 | |
| 208 | // --- Track --- |
| 209 | |
| 210 | // base for record and playback |
| 211 | class TrackBase : public AudioBufferProvider, public RefBase { |
| 212 | |
| 213 | public: |
| 214 | enum track_state { |
| 215 | IDLE, |
| 216 | TERMINATED, |
| 217 | STOPPED, |
| 218 | RESUMING, |
| 219 | ACTIVE, |
| 220 | PAUSING, |
| 221 | PAUSED |
| 222 | }; |
| 223 | |
| 224 | enum track_flags { |
| 225 | STEPSERVER_FAILED = 0x01, // StepServer could not acquire cblk->lock mutex |
| 226 | SYSTEM_FLAGS_MASK = 0x0000ffffUL, |
| 227 | // The upper 16 bits are used for track-specific flags. |
| 228 | }; |
| 229 | |
| 230 | TrackBase(const sp<MixerThread>& mixerThread, |
| 231 | const sp<Client>& client, |
| 232 | int streamType, |
| 233 | uint32_t sampleRate, |
| 234 | int format, |
| 235 | int channelCount, |
| 236 | int frameCount, |
| 237 | uint32_t flags, |
| 238 | const sp<IMemory>& sharedBuffer); |
| 239 | ~TrackBase(); |
| 240 | |
| 241 | virtual status_t start() = 0; |
| 242 | virtual void stop() = 0; |
| 243 | sp<IMemory> getCblk() const; |
| 244 | |
| 245 | protected: |
| 246 | friend class MixerThread; |
| 247 | friend class RecordHandle; |
| 248 | friend class AudioRecordThread; |
| 249 | |
| 250 | TrackBase(const TrackBase&); |
| 251 | TrackBase& operator = (const TrackBase&); |
| 252 | |
| 253 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0; |
| 254 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 255 | |
| 256 | audio_track_cblk_t* cblk() const { |
| 257 | return mCblk; |
| 258 | } |
| 259 | |
| 260 | int type() const { |
| 261 | return mStreamType; |
| 262 | } |
| 263 | |
| 264 | int format() const { |
| 265 | return mFormat; |
| 266 | } |
| 267 | |
| 268 | int channelCount() const ; |
| 269 | |
| 270 | int sampleRate() const; |
| 271 | |
| 272 | void* getBuffer(uint32_t offset, uint32_t frames) const; |
| 273 | |
| 274 | int name() const { |
| 275 | return mName; |
| 276 | } |
| 277 | |
| 278 | bool isStopped() const { |
| 279 | return mState == STOPPED; |
| 280 | } |
| 281 | |
| 282 | bool isTerminated() const { |
| 283 | return mState == TERMINATED; |
| 284 | } |
| 285 | |
| 286 | bool step(); |
| 287 | void reset(); |
| 288 | |
| 289 | sp<MixerThread> mMixerThread; |
| 290 | sp<Client> mClient; |
| 291 | sp<IMemory> mCblkMemory; |
| 292 | audio_track_cblk_t* mCblk; |
| 293 | int mStreamType; |
| 294 | void* mBuffer; |
| 295 | void* mBufferEnd; |
| 296 | uint32_t mFrameCount; |
| 297 | int mName; |
| 298 | // we don't really need a lock for these |
| 299 | int mState; |
| 300 | int mClientTid; |
| 301 | uint8_t mFormat; |
| 302 | uint32_t mFlags; |
| 303 | }; |
| 304 | |
| 305 | // playback track |
| 306 | class Track : public TrackBase { |
| 307 | public: |
| 308 | Track( const sp<MixerThread>& mixerThread, |
| 309 | const sp<Client>& client, |
| 310 | int streamType, |
| 311 | uint32_t sampleRate, |
| 312 | int format, |
| 313 | int channelCount, |
| 314 | int frameCount, |
| 315 | const sp<IMemory>& sharedBuffer); |
| 316 | ~Track(); |
| 317 | |
| 318 | void dump(char* buffer, size_t size); |
| 319 | virtual status_t start(); |
| 320 | virtual void stop(); |
| 321 | void pause(); |
| 322 | |
| 323 | void flush(); |
| 324 | void destroy(); |
| 325 | void mute(bool); |
| 326 | void setVolume(float left, float right); |
| 327 | |
| 328 | protected: |
| 329 | friend class MixerThread; |
| 330 | friend class AudioFlinger; |
| 331 | friend class AudioFlinger::TrackHandle; |
| 332 | |
| 333 | Track(const Track&); |
| 334 | Track& operator = (const Track&); |
| 335 | |
| 336 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 337 | |
| 338 | bool isMuted() const { |
| 339 | return (mMute || mMixerThread->mStreamTypes[mStreamType].mute); |
| 340 | } |
| 341 | |
| 342 | bool isPausing() const { |
| 343 | return mState == PAUSING; |
| 344 | } |
| 345 | |
| 346 | bool isPaused() const { |
| 347 | return mState == PAUSED; |
| 348 | } |
| 349 | |
| 350 | bool isReady() const; |
| 351 | |
| 352 | void setPaused() { mState = PAUSED; } |
| 353 | void reset(); |
| 354 | |
| 355 | // we don't really need a lock for these |
| 356 | float mVolume[2]; |
| 357 | volatile bool mMute; |
| 358 | // FILLED state is used for suppressing volume ramp at begin of playing |
| 359 | enum {FS_FILLING, FS_FILLED, FS_ACTIVE}; |
| 360 | mutable uint8_t mFillingUpStatus; |
| 361 | int8_t mRetryCount; |
| 362 | sp<IMemory> mSharedBuffer; |
| 363 | bool mResetDone; |
| 364 | }; // end of Track |
| 365 | |
| 366 | // record track |
| 367 | class RecordTrack : public TrackBase { |
| 368 | public: |
| 369 | RecordTrack(const sp<MixerThread>& mixerThread, |
| 370 | const sp<Client>& client, |
| 371 | int streamType, |
| 372 | uint32_t sampleRate, |
| 373 | int format, |
| 374 | int channelCount, |
| 375 | int frameCount, |
| 376 | uint32_t flags); |
| 377 | ~RecordTrack(); |
| 378 | |
| 379 | virtual status_t start(); |
| 380 | virtual void stop(); |
| 381 | |
| 382 | bool overflow() { bool tmp = mOverflow; mOverflow = false; return tmp; } |
| 383 | bool setOverflow() { bool tmp = mOverflow; mOverflow = true; return tmp; } |
| 384 | |
| 385 | private: |
| 386 | friend class AudioFlinger; |
| 387 | friend class AudioFlinger::RecordHandle; |
| 388 | friend class AudioFlinger::AudioRecordThread; |
| 389 | friend class MixerThread; |
| 390 | |
| 391 | RecordTrack(const Track&); |
| 392 | RecordTrack& operator = (const Track&); |
| 393 | |
| 394 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 395 | |
| 396 | bool mOverflow; |
| 397 | }; |
| 398 | |
| 399 | // playback track |
| 400 | class OutputTrack : public Track { |
| 401 | public: |
| 402 | |
| 403 | class Buffer: public AudioBufferProvider::Buffer { |
| 404 | public: |
| 405 | int16_t *mBuffer; |
| 406 | }; |
| 407 | |
| 408 | OutputTrack( const sp<MixerThread>& mixerThread, |
| 409 | uint32_t sampleRate, |
| 410 | int format, |
| 411 | int channelCount, |
| 412 | int frameCount); |
| 413 | ~OutputTrack(); |
| 414 | |
| 415 | virtual status_t start(); |
| 416 | virtual void stop(); |
| 417 | void write(int16_t* data, uint32_t frames); |
| 418 | bool bufferQueueEmpty() { return (mBufferQueue.size() == 0) ? true : false; } |
| 419 | |
| 420 | private: |
| 421 | |
| 422 | status_t obtainBuffer(AudioBufferProvider::Buffer* buffer); |
| 423 | void clearBufferQueue(); |
| 424 | |
| 425 | sp<MixerThread> mOutputMixerThread; |
| 426 | Vector < Buffer* > mBufferQueue; |
| 427 | AudioBufferProvider::Buffer mOutBuffer; |
| 428 | uint32_t mFramesWritten; |
| 429 | |
| 430 | }; // end of OutputTrack |
| 431 | |
| 432 | MixerThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int outputType); |
| 433 | virtual ~MixerThread(); |
| 434 | |
| 435 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 436 | |
| 437 | // Thread virtuals |
| 438 | virtual bool threadLoop(); |
| 439 | virtual status_t readyToRun(); |
| 440 | virtual void onFirstRef(); |
| 441 | |
| 442 | virtual uint32_t sampleRate() const; |
| 443 | virtual int channelCount() const; |
| 444 | virtual int format() const; |
| 445 | virtual size_t frameCount() const; |
| 446 | virtual uint32_t latency() const; |
| 447 | |
| 448 | virtual status_t setMasterVolume(float value); |
| 449 | virtual status_t setMasterMute(bool muted); |
| 450 | |
| 451 | virtual float masterVolume() const; |
| 452 | virtual bool masterMute() const; |
| 453 | |
| 454 | virtual status_t setStreamVolume(int stream, float value); |
| 455 | virtual status_t setStreamMute(int stream, bool muted); |
| 456 | |
| 457 | virtual float streamVolume(int stream) const; |
| 458 | virtual bool streamMute(int stream) const; |
| 459 | |
| 460 | bool isMusicActive() const; |
| 461 | |
| 462 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame^] | 463 | sp<Track> createTrack_l( |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | const sp<AudioFlinger::Client>& client, |
| 465 | int streamType, |
| 466 | uint32_t sampleRate, |
| 467 | int format, |
| 468 | int channelCount, |
| 469 | int frameCount, |
| 470 | const sp<IMemory>& sharedBuffer, |
| 471 | status_t *status); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 472 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame^] | 473 | void getTracks_l(SortedVector < sp<Track> >& tracks, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | SortedVector < wp<Track> >& activeTracks); |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame^] | 475 | void putTracks_l(SortedVector < sp<Track> >& tracks, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | SortedVector < wp<Track> >& activeTracks); |
| 477 | void setOuputTrack(OutputTrack *track) { mOutputTrack = track; } |
| 478 | |
| 479 | struct stream_type_t { |
| 480 | stream_type_t() |
| 481 | : volume(1.0f), |
| 482 | mute(false) |
| 483 | { |
| 484 | } |
| 485 | float volume; |
| 486 | bool mute; |
| 487 | }; |
| 488 | |
| 489 | private: |
| 490 | |
| 491 | |
| 492 | friend class AudioFlinger; |
| 493 | friend class Track; |
| 494 | friend class TrackBase; |
| 495 | friend class RecordTrack; |
| 496 | |
| 497 | MixerThread(const Client&); |
| 498 | MixerThread& operator = (const MixerThread&); |
| 499 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame^] | 500 | status_t addTrack_l(const sp<Track>& track); |
| 501 | void removeTrack_l(wp<Track> track, int name); |
| 502 | void destroyTrack_l(const sp<Track>& track); |
| 503 | int getTrackName_l(); |
| 504 | void deleteTrackName_l(int name); |
| 505 | void addActiveTrack_l(const wp<Track>& t); |
| 506 | void removeActiveTrack_l(const wp<Track>& t); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | size_t getOutputFrameCount(); |
| 508 | |
| 509 | status_t dumpInternals(int fd, const Vector<String16>& args); |
| 510 | status_t dumpTracks(int fd, const Vector<String16>& args); |
| 511 | |
| 512 | sp<AudioFlinger> mAudioFlinger; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | SortedVector< wp<Track> > mActiveTracks; |
| 514 | SortedVector< sp<Track> > mTracks; |
| 515 | stream_type_t mStreamTypes[AudioSystem::NUM_STREAM_TYPES]; |
| 516 | AudioMixer* mAudioMixer; |
| 517 | AudioStreamOut* mOutput; |
| 518 | int mOutputType; |
| 519 | uint32_t mSampleRate; |
| 520 | size_t mFrameCount; |
| 521 | int mChannelCount; |
| 522 | int mFormat; |
| 523 | int16_t* mMixBuffer; |
| 524 | float mMasterVolume; |
| 525 | bool mMasterMute; |
| 526 | nsecs_t mLastWriteTime; |
| 527 | int mNumWrites; |
| 528 | int mNumDelayedWrites; |
| 529 | bool mStandby; |
| 530 | bool mInWrite; |
| 531 | sp <OutputTrack> mOutputTrack; |
| 532 | }; |
| 533 | |
| 534 | |
| 535 | friend class AudioBuffer; |
| 536 | |
| 537 | class TrackHandle : public android::BnAudioTrack { |
| 538 | public: |
| 539 | TrackHandle(const sp<MixerThread::Track>& track); |
| 540 | virtual ~TrackHandle(); |
| 541 | virtual status_t start(); |
| 542 | virtual void stop(); |
| 543 | virtual void flush(); |
| 544 | virtual void mute(bool); |
| 545 | virtual void pause(); |
| 546 | virtual void setVolume(float left, float right); |
| 547 | virtual sp<IMemory> getCblk() const; |
| 548 | virtual status_t onTransact( |
| 549 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 550 | private: |
| 551 | sp<MixerThread::Track> mTrack; |
| 552 | }; |
| 553 | |
| 554 | friend class Client; |
| 555 | friend class MixerThread::Track; |
| 556 | |
| 557 | |
| 558 | void removeClient(pid_t pid); |
| 559 | |
| 560 | |
| 561 | |
| 562 | class RecordHandle : public android::BnAudioRecord { |
| 563 | public: |
| 564 | RecordHandle(const sp<MixerThread::RecordTrack>& recordTrack); |
| 565 | virtual ~RecordHandle(); |
| 566 | virtual status_t start(); |
| 567 | virtual void stop(); |
| 568 | virtual sp<IMemory> getCblk() const; |
| 569 | virtual status_t onTransact( |
| 570 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 571 | private: |
| 572 | sp<MixerThread::RecordTrack> mRecordTrack; |
| 573 | }; |
| 574 | |
| 575 | // record thread |
| 576 | class AudioRecordThread : public Thread |
| 577 | { |
| 578 | public: |
| 579 | AudioRecordThread(AudioHardwareInterface* audioHardware); |
| 580 | virtual ~AudioRecordThread(); |
| 581 | virtual bool threadLoop(); |
| 582 | virtual status_t readyToRun() { return NO_ERROR; } |
| 583 | virtual void onFirstRef() {} |
| 584 | |
| 585 | status_t start(MixerThread::RecordTrack* recordTrack); |
| 586 | void stop(MixerThread::RecordTrack* recordTrack); |
| 587 | void exit(); |
| 588 | status_t dump(int fd, const Vector<String16>& args); |
| 589 | |
| 590 | private: |
| 591 | AudioRecordThread(); |
| 592 | AudioHardwareInterface *mAudioHardware; |
| 593 | sp<MixerThread::RecordTrack> mRecordTrack; |
| 594 | Mutex mLock; |
| 595 | Condition mWaitWorkCV; |
| 596 | Condition mStopped; |
| 597 | volatile bool mActive; |
| 598 | status_t mStartStatus; |
| 599 | }; |
| 600 | |
| 601 | friend class AudioRecordThread; |
| 602 | friend class MixerThread; |
| 603 | |
| 604 | status_t startRecord(MixerThread::RecordTrack* recordTrack); |
| 605 | void stopRecord(MixerThread::RecordTrack* recordTrack); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame^] | 607 | mutable Mutex mHardwareLock; |
| 608 | mutable Mutex mLock; |
| 609 | mutable Condition mWaitWorkCV; |
| 610 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 611 | DefaultKeyedVector< pid_t, wp<Client> > mClients; |
| 612 | |
| 613 | sp<MixerThread> mA2dpMixerThread; |
| 614 | sp<MixerThread> mHardwareMixerThread; |
| 615 | AudioHardwareInterface* mAudioHardware; |
| 616 | AudioHardwareInterface* mA2dpAudioInterface; |
| 617 | sp<AudioRecordThread> mAudioRecordThread; |
| 618 | bool mA2dpEnabled; |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame^] | 619 | bool mNotifyA2dpChange; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | mutable int mHardwareStatus; |
| 621 | SortedVector< wp<IBinder> > mNotificationClients; |
| 622 | int mForcedSpeakerCount; |
| 623 | uint32_t mSavedRoute; |
| 624 | uint32_t mForcedRoute; |
| 625 | nsecs_t mRouteRestoreTime; |
| 626 | bool mMusicMuteSaved; |
| 627 | }; |
| 628 | |
| 629 | // ---------------------------------------------------------------------------- |
| 630 | |
| 631 | }; // namespace android |
| 632 | |
| 633 | #endif // ANDROID_AUDIO_FLINGER_H |