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); |
The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 177 | #ifdef WITH_A2DP |
The Android Open Source Project | 4f68be1 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 178 | void handleRouteDisablesA2dp_l(int routes); |
The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 179 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | |
| 181 | // Internal dump utilites. |
| 182 | status_t dumpPermissionDenial(int fd, const Vector<String16>& args); |
| 183 | status_t dumpClients(int fd, const Vector<String16>& args); |
| 184 | status_t dumpInternals(int fd, const Vector<String16>& args); |
| 185 | |
| 186 | // --- Client --- |
| 187 | class Client : public RefBase { |
| 188 | public: |
| 189 | Client(const sp<AudioFlinger>& audioFlinger, pid_t pid); |
| 190 | virtual ~Client(); |
| 191 | const sp<MemoryDealer>& heap() const; |
| 192 | pid_t pid() const { return mPid; } |
| 193 | private: |
| 194 | Client(const Client&); |
| 195 | Client& operator = (const Client&); |
| 196 | sp<AudioFlinger> mAudioFlinger; |
| 197 | sp<MemoryDealer> mMemoryDealer; |
| 198 | pid_t mPid; |
| 199 | }; |
| 200 | |
| 201 | |
| 202 | class TrackHandle; |
| 203 | class RecordHandle; |
| 204 | class AudioRecordThread; |
| 205 | |
| 206 | |
| 207 | // --- MixerThread --- |
| 208 | class MixerThread : public Thread { |
| 209 | public: |
| 210 | |
| 211 | // --- Track --- |
| 212 | |
| 213 | // base for record and playback |
| 214 | class TrackBase : public AudioBufferProvider, public RefBase { |
| 215 | |
| 216 | public: |
| 217 | enum track_state { |
| 218 | IDLE, |
| 219 | TERMINATED, |
| 220 | STOPPED, |
| 221 | RESUMING, |
| 222 | ACTIVE, |
| 223 | PAUSING, |
| 224 | PAUSED |
| 225 | }; |
| 226 | |
| 227 | enum track_flags { |
| 228 | STEPSERVER_FAILED = 0x01, // StepServer could not acquire cblk->lock mutex |
| 229 | SYSTEM_FLAGS_MASK = 0x0000ffffUL, |
| 230 | // The upper 16 bits are used for track-specific flags. |
| 231 | }; |
| 232 | |
| 233 | TrackBase(const sp<MixerThread>& mixerThread, |
| 234 | const sp<Client>& client, |
| 235 | int streamType, |
| 236 | uint32_t sampleRate, |
| 237 | int format, |
| 238 | int channelCount, |
| 239 | int frameCount, |
| 240 | uint32_t flags, |
| 241 | const sp<IMemory>& sharedBuffer); |
| 242 | ~TrackBase(); |
| 243 | |
| 244 | virtual status_t start() = 0; |
| 245 | virtual void stop() = 0; |
| 246 | sp<IMemory> getCblk() const; |
| 247 | |
| 248 | protected: |
| 249 | friend class MixerThread; |
| 250 | friend class RecordHandle; |
| 251 | friend class AudioRecordThread; |
| 252 | |
| 253 | TrackBase(const TrackBase&); |
| 254 | TrackBase& operator = (const TrackBase&); |
| 255 | |
| 256 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0; |
| 257 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 258 | |
| 259 | audio_track_cblk_t* cblk() const { |
| 260 | return mCblk; |
| 261 | } |
| 262 | |
| 263 | int type() const { |
| 264 | return mStreamType; |
| 265 | } |
| 266 | |
| 267 | int format() const { |
| 268 | return mFormat; |
| 269 | } |
| 270 | |
| 271 | int channelCount() const ; |
| 272 | |
| 273 | int sampleRate() const; |
| 274 | |
| 275 | void* getBuffer(uint32_t offset, uint32_t frames) const; |
| 276 | |
| 277 | int name() const { |
| 278 | return mName; |
| 279 | } |
| 280 | |
| 281 | bool isStopped() const { |
| 282 | return mState == STOPPED; |
| 283 | } |
| 284 | |
| 285 | bool isTerminated() const { |
| 286 | return mState == TERMINATED; |
| 287 | } |
| 288 | |
| 289 | bool step(); |
| 290 | void reset(); |
| 291 | |
| 292 | sp<MixerThread> mMixerThread; |
| 293 | sp<Client> mClient; |
| 294 | sp<IMemory> mCblkMemory; |
| 295 | audio_track_cblk_t* mCblk; |
| 296 | int mStreamType; |
| 297 | void* mBuffer; |
| 298 | void* mBufferEnd; |
| 299 | uint32_t mFrameCount; |
| 300 | int mName; |
| 301 | // we don't really need a lock for these |
| 302 | int mState; |
| 303 | int mClientTid; |
| 304 | uint8_t mFormat; |
| 305 | uint32_t mFlags; |
| 306 | }; |
| 307 | |
| 308 | // playback track |
| 309 | class Track : public TrackBase { |
| 310 | public: |
| 311 | Track( const sp<MixerThread>& mixerThread, |
| 312 | const sp<Client>& client, |
| 313 | int streamType, |
| 314 | uint32_t sampleRate, |
| 315 | int format, |
| 316 | int channelCount, |
| 317 | int frameCount, |
| 318 | const sp<IMemory>& sharedBuffer); |
| 319 | ~Track(); |
| 320 | |
| 321 | void dump(char* buffer, size_t size); |
| 322 | virtual status_t start(); |
| 323 | virtual void stop(); |
| 324 | void pause(); |
| 325 | |
| 326 | void flush(); |
| 327 | void destroy(); |
| 328 | void mute(bool); |
| 329 | void setVolume(float left, float right); |
| 330 | |
| 331 | protected: |
| 332 | friend class MixerThread; |
| 333 | friend class AudioFlinger; |
| 334 | friend class AudioFlinger::TrackHandle; |
| 335 | |
| 336 | Track(const Track&); |
| 337 | Track& operator = (const Track&); |
| 338 | |
| 339 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 340 | |
| 341 | bool isMuted() const { |
| 342 | return (mMute || mMixerThread->mStreamTypes[mStreamType].mute); |
| 343 | } |
| 344 | |
| 345 | bool isPausing() const { |
| 346 | return mState == PAUSING; |
| 347 | } |
| 348 | |
| 349 | bool isPaused() const { |
| 350 | return mState == PAUSED; |
| 351 | } |
| 352 | |
| 353 | bool isReady() const; |
| 354 | |
| 355 | void setPaused() { mState = PAUSED; } |
| 356 | void reset(); |
| 357 | |
| 358 | // we don't really need a lock for these |
| 359 | float mVolume[2]; |
| 360 | volatile bool mMute; |
| 361 | // FILLED state is used for suppressing volume ramp at begin of playing |
| 362 | enum {FS_FILLING, FS_FILLED, FS_ACTIVE}; |
| 363 | mutable uint8_t mFillingUpStatus; |
| 364 | int8_t mRetryCount; |
| 365 | sp<IMemory> mSharedBuffer; |
| 366 | bool mResetDone; |
| 367 | }; // end of Track |
| 368 | |
| 369 | // record track |
| 370 | class RecordTrack : public TrackBase { |
| 371 | public: |
| 372 | RecordTrack(const sp<MixerThread>& mixerThread, |
| 373 | const sp<Client>& client, |
| 374 | int streamType, |
| 375 | uint32_t sampleRate, |
| 376 | int format, |
| 377 | int channelCount, |
| 378 | int frameCount, |
| 379 | uint32_t flags); |
| 380 | ~RecordTrack(); |
| 381 | |
| 382 | virtual status_t start(); |
| 383 | virtual void stop(); |
| 384 | |
| 385 | bool overflow() { bool tmp = mOverflow; mOverflow = false; return tmp; } |
| 386 | bool setOverflow() { bool tmp = mOverflow; mOverflow = true; return tmp; } |
| 387 | |
| 388 | private: |
| 389 | friend class AudioFlinger; |
| 390 | friend class AudioFlinger::RecordHandle; |
| 391 | friend class AudioFlinger::AudioRecordThread; |
| 392 | friend class MixerThread; |
| 393 | |
| 394 | RecordTrack(const Track&); |
| 395 | RecordTrack& operator = (const Track&); |
| 396 | |
| 397 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 398 | |
| 399 | bool mOverflow; |
| 400 | }; |
| 401 | |
| 402 | // playback track |
| 403 | class OutputTrack : public Track { |
| 404 | public: |
| 405 | |
| 406 | class Buffer: public AudioBufferProvider::Buffer { |
| 407 | public: |
| 408 | int16_t *mBuffer; |
| 409 | }; |
| 410 | |
| 411 | OutputTrack( const sp<MixerThread>& mixerThread, |
| 412 | uint32_t sampleRate, |
| 413 | int format, |
| 414 | int channelCount, |
| 415 | int frameCount); |
| 416 | ~OutputTrack(); |
| 417 | |
| 418 | virtual status_t start(); |
| 419 | virtual void stop(); |
| 420 | void write(int16_t* data, uint32_t frames); |
| 421 | bool bufferQueueEmpty() { return (mBufferQueue.size() == 0) ? true : false; } |
| 422 | |
| 423 | private: |
| 424 | |
| 425 | status_t obtainBuffer(AudioBufferProvider::Buffer* buffer); |
| 426 | void clearBufferQueue(); |
| 427 | |
| 428 | sp<MixerThread> mOutputMixerThread; |
| 429 | Vector < Buffer* > mBufferQueue; |
| 430 | AudioBufferProvider::Buffer mOutBuffer; |
| 431 | uint32_t mFramesWritten; |
| 432 | |
| 433 | }; // end of OutputTrack |
| 434 | |
| 435 | MixerThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int outputType); |
| 436 | virtual ~MixerThread(); |
| 437 | |
| 438 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 439 | |
| 440 | // Thread virtuals |
| 441 | virtual bool threadLoop(); |
| 442 | virtual status_t readyToRun(); |
| 443 | virtual void onFirstRef(); |
| 444 | |
| 445 | virtual uint32_t sampleRate() const; |
| 446 | virtual int channelCount() const; |
| 447 | virtual int format() const; |
| 448 | virtual size_t frameCount() const; |
| 449 | virtual uint32_t latency() const; |
| 450 | |
| 451 | virtual status_t setMasterVolume(float value); |
| 452 | virtual status_t setMasterMute(bool muted); |
| 453 | |
| 454 | virtual float masterVolume() const; |
| 455 | virtual bool masterMute() const; |
| 456 | |
| 457 | virtual status_t setStreamVolume(int stream, float value); |
| 458 | virtual status_t setStreamMute(int stream, bool muted); |
| 459 | |
| 460 | virtual float streamVolume(int stream) const; |
| 461 | virtual bool streamMute(int stream) const; |
| 462 | |
| 463 | bool isMusicActive() const; |
| 464 | |
| 465 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 466 | sp<Track> createTrack_l( |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 467 | const sp<AudioFlinger::Client>& client, |
| 468 | int streamType, |
| 469 | uint32_t sampleRate, |
| 470 | int format, |
| 471 | int channelCount, |
| 472 | int frameCount, |
| 473 | const sp<IMemory>& sharedBuffer, |
| 474 | status_t *status); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 475 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 476 | void getTracks_l(SortedVector < sp<Track> >& tracks, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | SortedVector < wp<Track> >& activeTracks); |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 478 | void putTracks_l(SortedVector < sp<Track> >& tracks, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | SortedVector < wp<Track> >& activeTracks); |
| 480 | void setOuputTrack(OutputTrack *track) { mOutputTrack = track; } |
| 481 | |
| 482 | struct stream_type_t { |
| 483 | stream_type_t() |
| 484 | : volume(1.0f), |
| 485 | mute(false) |
| 486 | { |
| 487 | } |
| 488 | float volume; |
| 489 | bool mute; |
| 490 | }; |
| 491 | |
| 492 | private: |
| 493 | |
| 494 | |
| 495 | friend class AudioFlinger; |
| 496 | friend class Track; |
| 497 | friend class TrackBase; |
| 498 | friend class RecordTrack; |
| 499 | |
| 500 | MixerThread(const Client&); |
| 501 | MixerThread& operator = (const MixerThread&); |
| 502 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 503 | status_t addTrack_l(const sp<Track>& track); |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 504 | void destroyTrack_l(const sp<Track>& track); |
| 505 | int getTrackName_l(); |
| 506 | void deleteTrackName_l(int name); |
| 507 | void addActiveTrack_l(const wp<Track>& t); |
| 508 | void removeActiveTrack_l(const wp<Track>& t); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | size_t getOutputFrameCount(); |
| 510 | |
| 511 | status_t dumpInternals(int fd, const Vector<String16>& args); |
| 512 | status_t dumpTracks(int fd, const Vector<String16>& args); |
| 513 | |
| 514 | sp<AudioFlinger> mAudioFlinger; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | SortedVector< wp<Track> > mActiveTracks; |
| 516 | SortedVector< sp<Track> > mTracks; |
| 517 | stream_type_t mStreamTypes[AudioSystem::NUM_STREAM_TYPES]; |
| 518 | AudioMixer* mAudioMixer; |
| 519 | AudioStreamOut* mOutput; |
| 520 | int mOutputType; |
| 521 | uint32_t mSampleRate; |
| 522 | size_t mFrameCount; |
| 523 | int mChannelCount; |
| 524 | int mFormat; |
| 525 | int16_t* mMixBuffer; |
| 526 | float mMasterVolume; |
| 527 | bool mMasterMute; |
| 528 | nsecs_t mLastWriteTime; |
| 529 | int mNumWrites; |
| 530 | int mNumDelayedWrites; |
| 531 | bool mStandby; |
| 532 | bool mInWrite; |
| 533 | sp <OutputTrack> mOutputTrack; |
| 534 | }; |
| 535 | |
| 536 | |
| 537 | friend class AudioBuffer; |
| 538 | |
| 539 | class TrackHandle : public android::BnAudioTrack { |
| 540 | public: |
| 541 | TrackHandle(const sp<MixerThread::Track>& track); |
| 542 | virtual ~TrackHandle(); |
| 543 | virtual status_t start(); |
| 544 | virtual void stop(); |
| 545 | virtual void flush(); |
| 546 | virtual void mute(bool); |
| 547 | virtual void pause(); |
| 548 | virtual void setVolume(float left, float right); |
| 549 | virtual sp<IMemory> getCblk() const; |
| 550 | virtual status_t onTransact( |
| 551 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 552 | private: |
| 553 | sp<MixerThread::Track> mTrack; |
| 554 | }; |
| 555 | |
| 556 | friend class Client; |
| 557 | friend class MixerThread::Track; |
| 558 | |
| 559 | |
| 560 | void removeClient(pid_t pid); |
| 561 | |
| 562 | |
| 563 | |
| 564 | class RecordHandle : public android::BnAudioRecord { |
| 565 | public: |
| 566 | RecordHandle(const sp<MixerThread::RecordTrack>& recordTrack); |
| 567 | virtual ~RecordHandle(); |
| 568 | virtual status_t start(); |
| 569 | virtual void stop(); |
| 570 | virtual sp<IMemory> getCblk() const; |
| 571 | virtual status_t onTransact( |
| 572 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 573 | private: |
| 574 | sp<MixerThread::RecordTrack> mRecordTrack; |
| 575 | }; |
| 576 | |
| 577 | // record thread |
| 578 | class AudioRecordThread : public Thread |
| 579 | { |
| 580 | public: |
The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 581 | AudioRecordThread(AudioHardwareInterface* audioHardware, const sp<AudioFlinger>& audioFlinger); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | virtual ~AudioRecordThread(); |
| 583 | virtual bool threadLoop(); |
| 584 | virtual status_t readyToRun() { return NO_ERROR; } |
| 585 | virtual void onFirstRef() {} |
| 586 | |
| 587 | status_t start(MixerThread::RecordTrack* recordTrack); |
| 588 | void stop(MixerThread::RecordTrack* recordTrack); |
| 589 | void exit(); |
| 590 | status_t dump(int fd, const Vector<String16>& args); |
| 591 | |
| 592 | private: |
| 593 | AudioRecordThread(); |
| 594 | AudioHardwareInterface *mAudioHardware; |
The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 595 | sp<AudioFlinger> mAudioFlinger; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | sp<MixerThread::RecordTrack> mRecordTrack; |
| 597 | Mutex mLock; |
| 598 | Condition mWaitWorkCV; |
| 599 | Condition mStopped; |
| 600 | volatile bool mActive; |
| 601 | status_t mStartStatus; |
| 602 | }; |
| 603 | |
| 604 | friend class AudioRecordThread; |
| 605 | friend class MixerThread; |
| 606 | |
| 607 | status_t startRecord(MixerThread::RecordTrack* recordTrack); |
| 608 | void stopRecord(MixerThread::RecordTrack* recordTrack); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 610 | mutable Mutex mHardwareLock; |
| 611 | mutable Mutex mLock; |
| 612 | mutable Condition mWaitWorkCV; |
| 613 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | DefaultKeyedVector< pid_t, wp<Client> > mClients; |
| 615 | |
| 616 | sp<MixerThread> mA2dpMixerThread; |
| 617 | sp<MixerThread> mHardwareMixerThread; |
| 618 | AudioHardwareInterface* mAudioHardware; |
| 619 | AudioHardwareInterface* mA2dpAudioInterface; |
| 620 | sp<AudioRecordThread> mAudioRecordThread; |
| 621 | bool mA2dpEnabled; |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 622 | bool mNotifyA2dpChange; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 623 | mutable int mHardwareStatus; |
| 624 | SortedVector< wp<IBinder> > mNotificationClients; |
| 625 | int mForcedSpeakerCount; |
The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 626 | int mA2dpDisableCount; |
| 627 | |
| 628 | // true if A2DP should resume when mA2dpDisableCount returns to zero |
| 629 | bool mA2dpSuppressed; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | uint32_t mSavedRoute; |
| 631 | uint32_t mForcedRoute; |
| 632 | nsecs_t mRouteRestoreTime; |
| 633 | bool mMusicMuteSaved; |
| 634 | }; |
| 635 | |
| 636 | // ---------------------------------------------------------------------------- |
| 637 | |
| 638 | }; // namespace android |
| 639 | |
| 640 | #endif // ANDROID_AUDIO_FLINGER_H |