The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -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 | |
| 24 | #include <media/IAudioFlinger.h> |
The Android Open Source Project | a6938ba | 2009-02-10 15:44:00 -0800 | [diff] [blame^] | 25 | #include <media/IAudioFlingerClient.h> |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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 | |
The Android Open Source Project | 8a7a675 | 2009-01-15 16:12:10 -0800 | [diff] [blame] | 37 | #include <hardware_legacy/AudioHardwareInterface.h> |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 38 | |
| 39 | #include "AudioBufferProvider.h" |
| 40 | |
| 41 | namespace android { |
| 42 | |
| 43 | class audio_track_cblk_t; |
| 44 | class AudioMixer; |
| 45 | class AudioBuffer; |
| 46 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 47 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 48 | // ---------------------------------------------------------------------------- |
| 49 | |
| 50 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 51 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 52 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 53 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 54 | // ---------------------------------------------------------------------------- |
| 55 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 56 | static const nsecs_t kStandbyTimeInNsecs = seconds(3); |
| 57 | |
The Android Open Source Project | a6938ba | 2009-02-10 15:44:00 -0800 | [diff] [blame^] | 58 | class AudioFlinger : public BnAudioFlinger, protected Thread, public IBinder::DeathRecipient |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 59 | { |
| 60 | public: |
| 61 | static void instantiate(); |
| 62 | |
| 63 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 64 | |
| 65 | // Thread virtuals |
| 66 | virtual bool threadLoop(); |
| 67 | virtual status_t readyToRun(); |
| 68 | virtual void onFirstRef(); |
| 69 | |
| 70 | // IAudioFlinger interface |
| 71 | virtual sp<IAudioTrack> createTrack( |
| 72 | pid_t pid, |
| 73 | int streamType, |
| 74 | uint32_t sampleRate, |
| 75 | int format, |
| 76 | int channelCount, |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 77 | int frameCount, |
| 78 | uint32_t flags, |
| 79 | const sp<IMemory>& sharedBuffer, |
| 80 | status_t *status); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 81 | |
| 82 | virtual uint32_t sampleRate() const; |
| 83 | virtual int channelCount() const; |
| 84 | virtual int format() const; |
| 85 | virtual size_t frameCount() const; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 86 | virtual size_t latency() const; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 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); |
| 95 | virtual status_t setStreamMute(int stream, bool muted); |
| 96 | |
| 97 | virtual float streamVolume(int stream) const; |
| 98 | virtual bool streamMute(int stream) const; |
| 99 | |
| 100 | virtual status_t setRouting(int mode, uint32_t routes, uint32_t mask); |
| 101 | virtual uint32_t getRouting(int mode) const; |
| 102 | |
| 103 | virtual status_t setMode(int mode); |
| 104 | virtual int getMode() const; |
| 105 | |
| 106 | virtual status_t setMicMute(bool state); |
| 107 | virtual bool getMicMute() const; |
| 108 | |
| 109 | virtual bool isMusicActive() const; |
| 110 | |
| 111 | virtual status_t setParameter(const char* key, const char* value); |
| 112 | |
The Android Open Source Project | a6938ba | 2009-02-10 15:44:00 -0800 | [diff] [blame^] | 113 | virtual void registerClient(const sp<IAudioFlingerClient>& client); |
| 114 | |
| 115 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); |
| 116 | |
| 117 | virtual void wakeUp(); |
| 118 | |
| 119 | // IBinder::DeathRecipient |
| 120 | virtual void binderDied(const wp<IBinder>& who); |
| 121 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 122 | enum hardware_call_state { |
| 123 | AUDIO_HW_IDLE = 0, |
| 124 | AUDIO_HW_INIT, |
| 125 | AUDIO_HW_OUTPUT_OPEN, |
| 126 | AUDIO_HW_OUTPUT_CLOSE, |
| 127 | AUDIO_HW_INPUT_OPEN, |
| 128 | AUDIO_HW_INPUT_CLOSE, |
| 129 | AUDIO_HW_STANDBY, |
| 130 | AUDIO_HW_SET_MASTER_VOLUME, |
| 131 | AUDIO_HW_GET_ROUTING, |
| 132 | AUDIO_HW_SET_ROUTING, |
| 133 | AUDIO_HW_GET_MODE, |
| 134 | AUDIO_HW_SET_MODE, |
| 135 | AUDIO_HW_GET_MIC_MUTE, |
| 136 | AUDIO_HW_SET_MIC_MUTE, |
| 137 | AUDIO_SET_VOICE_VOLUME, |
| 138 | AUDIO_SET_PARAMETER, |
| 139 | }; |
| 140 | |
| 141 | // record interface |
| 142 | virtual sp<IAudioRecord> openRecord( |
| 143 | pid_t pid, |
| 144 | int streamType, |
| 145 | uint32_t sampleRate, |
| 146 | int format, |
| 147 | int channelCount, |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 148 | int frameCount, |
| 149 | uint32_t flags, |
| 150 | status_t *status); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 151 | |
| 152 | virtual status_t onTransact( |
| 153 | uint32_t code, |
| 154 | const Parcel& data, |
| 155 | Parcel* reply, |
| 156 | uint32_t flags); |
| 157 | |
| 158 | private: |
| 159 | AudioFlinger(); |
| 160 | virtual ~AudioFlinger(); |
| 161 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 162 | void setOutput(AudioStreamOut* output); |
The Android Open Source Project | 2762932 | 2009-01-09 17:51:23 -0800 | [diff] [blame] | 163 | void doSetOutput(AudioStreamOut* output); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 164 | size_t getOutputFrameCount(AudioStreamOut* output); |
| 165 | |
The Android Open Source Project | e41dd75 | 2009-01-22 00:13:42 -0800 | [diff] [blame] | 166 | #ifdef WITH_A2DP |
| 167 | static bool streamDisablesA2dp(int streamType); |
| 168 | inline bool isA2dpEnabled() const { |
| 169 | return (mRequestedOutput == mA2dpOutput || |
| 170 | (mOutput && mOutput == mA2dpOutput)); |
| 171 | } |
| 172 | void setA2dpEnabled(bool enable); |
| 173 | #endif |
| 174 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 175 | // Internal dump utilites. |
| 176 | status_t dumpPermissionDenial(int fd, const Vector<String16>& args); |
| 177 | status_t dumpClients(int fd, const Vector<String16>& args); |
| 178 | status_t dumpTracks(int fd, const Vector<String16>& args); |
| 179 | status_t dumpInternals(int fd, const Vector<String16>& args); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 180 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 181 | // --- Client --- |
| 182 | class Client : public RefBase { |
| 183 | public: |
| 184 | Client(const sp<AudioFlinger>& audioFlinger, pid_t pid); |
| 185 | virtual ~Client(); |
| 186 | const sp<MemoryDealer>& heap() const; |
| 187 | pid_t pid() const { return mPid; } |
| 188 | private: |
| 189 | Client(const Client&); |
| 190 | Client& operator = (const Client&); |
| 191 | sp<AudioFlinger> mAudioFlinger; |
| 192 | sp<MemoryDealer> mMemoryDealer; |
| 193 | pid_t mPid; |
| 194 | }; |
| 195 | |
| 196 | |
| 197 | // --- Track --- |
| 198 | class TrackHandle; |
| 199 | class RecordHandle; |
| 200 | class AudioRecordThread; |
| 201 | |
| 202 | // base for record and playback |
| 203 | class TrackBase : public AudioBufferProvider, public RefBase { |
| 204 | |
| 205 | public: |
| 206 | enum track_state { |
| 207 | IDLE, |
| 208 | TERMINATED, |
| 209 | STOPPED, |
| 210 | RESUMING, |
| 211 | ACTIVE, |
| 212 | PAUSING, |
| 213 | PAUSED |
| 214 | }; |
| 215 | |
| 216 | enum track_flags { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 217 | STEPSERVER_FAILED = 0x01 // StepServer could not acquire cblk->lock mutex |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 218 | }; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 219 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 220 | TrackBase( const sp<AudioFlinger>& audioFlinger, |
| 221 | const sp<Client>& client, |
| 222 | int streamType, |
| 223 | uint32_t sampleRate, |
| 224 | int format, |
| 225 | int channelCount, |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 226 | int frameCount, |
| 227 | const sp<IMemory>& sharedBuffer); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 228 | ~TrackBase(); |
| 229 | |
| 230 | virtual status_t start() = 0; |
| 231 | virtual void stop() = 0; |
| 232 | sp<IMemory> getCblk() const; |
| 233 | |
| 234 | protected: |
| 235 | friend class AudioFlinger; |
| 236 | friend class RecordHandle; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 237 | friend class AudioRecordThread; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 238 | |
| 239 | TrackBase(const TrackBase&); |
| 240 | TrackBase& operator = (const TrackBase&); |
| 241 | |
| 242 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0; |
| 243 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 244 | |
| 245 | audio_track_cblk_t* cblk() const { |
| 246 | return mCblk; |
| 247 | } |
| 248 | |
| 249 | int type() const { |
| 250 | return mStreamType; |
| 251 | } |
| 252 | |
| 253 | int format() const { |
| 254 | return mFormat; |
| 255 | } |
| 256 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 257 | int channelCount() const ; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 258 | |
| 259 | int sampleRate() const; |
| 260 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 261 | void* getBuffer(uint32_t offset, uint32_t frames) const; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 262 | |
| 263 | int name() const { |
| 264 | return mName; |
| 265 | } |
| 266 | |
| 267 | bool isStopped() const { |
| 268 | return mState == STOPPED; |
| 269 | } |
| 270 | |
| 271 | bool isTerminated() const { |
| 272 | return mState == TERMINATED; |
| 273 | } |
| 274 | |
| 275 | bool step(); |
| 276 | void reset(); |
| 277 | |
| 278 | sp<AudioFlinger> mAudioFlinger; |
| 279 | sp<Client> mClient; |
| 280 | sp<IMemory> mCblkMemory; |
| 281 | audio_track_cblk_t* mCblk; |
| 282 | int mStreamType; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 283 | void* mBuffer; |
| 284 | void* mBufferEnd; |
| 285 | uint32_t mFrameCount; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 286 | int mName; |
| 287 | // we don't really need a lock for these |
| 288 | int mState; |
| 289 | int mClientTid; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 290 | uint8_t mFormat; |
| 291 | uint8_t mFlags; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | // playback track |
| 295 | class Track : public TrackBase { |
| 296 | public: |
| 297 | Track( const sp<AudioFlinger>& audioFlinger, |
| 298 | const sp<Client>& client, |
| 299 | int streamType, |
| 300 | uint32_t sampleRate, |
| 301 | int format, |
| 302 | int channelCount, |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 303 | int frameCount, |
| 304 | const sp<IMemory>& sharedBuffer); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 305 | ~Track(); |
| 306 | |
| 307 | void dump(char* buffer, size_t size); |
| 308 | virtual status_t start(); |
| 309 | virtual void stop(); |
| 310 | void pause(); |
| 311 | |
| 312 | void flush(); |
| 313 | void destroy(); |
| 314 | void mute(bool); |
| 315 | void setVolume(float left, float right); |
| 316 | |
| 317 | private: |
| 318 | friend class AudioFlinger; |
| 319 | friend class TrackHandle; |
| 320 | |
| 321 | Track(const Track&); |
| 322 | Track& operator = (const Track&); |
| 323 | |
| 324 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 325 | |
| 326 | bool isMuted() const { |
The Android Open Source Project | a6938ba | 2009-02-10 15:44:00 -0800 | [diff] [blame^] | 327 | return (mMute || mAudioFlinger->mStreamTypes[mStreamType].mute); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | bool isPausing() const { |
| 331 | return mState == PAUSING; |
| 332 | } |
| 333 | |
| 334 | bool isPaused() const { |
| 335 | return mState == PAUSED; |
| 336 | } |
| 337 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 338 | bool isReady() const; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 339 | |
| 340 | void setPaused() { mState = PAUSED; } |
| 341 | void reset(); |
| 342 | |
| 343 | // we don't really need a lock for these |
| 344 | float mVolume[2]; |
| 345 | volatile bool mMute; |
| 346 | // FILLED state is used for suppressing volume ramp at begin of playing |
| 347 | enum {FS_FILLING, FS_FILLED, FS_ACTIVE}; |
| 348 | mutable uint8_t mFillingUpStatus; |
| 349 | int8_t mRetryCount; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 350 | sp<IMemory> mSharedBuffer; |
| 351 | bool mResetDone; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 352 | }; // end of Track |
| 353 | |
| 354 | friend class AudioBuffer; |
| 355 | |
| 356 | class TrackHandle : public android::BnAudioTrack { |
| 357 | public: |
| 358 | TrackHandle(const sp<Track>& track); |
| 359 | virtual ~TrackHandle(); |
| 360 | virtual status_t start(); |
| 361 | virtual void stop(); |
| 362 | virtual void flush(); |
| 363 | virtual void mute(bool); |
| 364 | virtual void pause(); |
| 365 | virtual void setVolume(float left, float right); |
| 366 | virtual sp<IMemory> getCblk() const; |
| 367 | virtual status_t onTransact( |
| 368 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 369 | private: |
| 370 | sp<Track> mTrack; |
| 371 | }; |
| 372 | |
| 373 | struct stream_type_t { |
| 374 | stream_type_t() |
| 375 | : volume(1.0f), |
| 376 | mute(false) |
| 377 | { |
| 378 | } |
| 379 | float volume; |
| 380 | bool mute; |
| 381 | }; |
| 382 | |
| 383 | friend class Client; |
| 384 | friend class Track; |
| 385 | |
| 386 | |
| 387 | void removeClient(pid_t pid); |
| 388 | |
| 389 | status_t addTrack(const sp<Track>& track); |
| 390 | void removeTrack(wp<Track> track, int name); |
| 391 | void remove_track_l(wp<Track> track, int name); |
| 392 | void destroyTrack(const sp<Track>& track); |
The Android Open Source Project | e41dd75 | 2009-01-22 00:13:42 -0800 | [diff] [blame] | 393 | void addActiveTrack(const wp<Track>& track); |
| 394 | void removeActiveTrack(const wp<Track>& track); |
The Android Open Source Project | a6938ba | 2009-02-10 15:44:00 -0800 | [diff] [blame^] | 395 | int getTrackName(); |
| 396 | void deleteTrackName(int name); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 397 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 398 | AudioMixer* audioMixer() { |
| 399 | return mAudioMixer; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | // record track |
| 403 | class RecordTrack : public TrackBase { |
| 404 | public: |
| 405 | RecordTrack( const sp<AudioFlinger>& audioFlinger, |
| 406 | const sp<Client>& client, |
| 407 | int streamType, |
| 408 | uint32_t sampleRate, |
| 409 | int format, |
| 410 | int channelCount, |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 411 | int frameCount); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 412 | ~RecordTrack(); |
| 413 | |
| 414 | virtual status_t start(); |
| 415 | virtual void stop(); |
| 416 | |
| 417 | bool overflow() { bool tmp = mOverflow; mOverflow = false; return tmp; } |
| 418 | bool setOverflow() { bool tmp = mOverflow; mOverflow = true; return tmp; } |
| 419 | |
| 420 | private: |
| 421 | friend class AudioFlinger; |
| 422 | friend class RecordHandle; |
| 423 | friend class AudioRecordThread; |
| 424 | |
| 425 | RecordTrack(const Track&); |
| 426 | RecordTrack& operator = (const Track&); |
| 427 | |
| 428 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 429 | |
| 430 | bool mOverflow; |
| 431 | }; |
| 432 | |
| 433 | class RecordHandle : public android::BnAudioRecord { |
| 434 | public: |
| 435 | RecordHandle(const sp<RecordTrack>& recordTrack); |
| 436 | virtual ~RecordHandle(); |
| 437 | virtual status_t start(); |
| 438 | virtual void stop(); |
| 439 | virtual sp<IMemory> getCblk() const; |
| 440 | virtual status_t onTransact( |
| 441 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 442 | private: |
| 443 | sp<RecordTrack> mRecordTrack; |
| 444 | }; |
| 445 | |
| 446 | // record thread |
| 447 | class AudioRecordThread : public Thread |
| 448 | { |
| 449 | public: |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 450 | AudioRecordThread(AudioHardwareInterface* audioHardware); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 451 | virtual ~AudioRecordThread(); |
| 452 | virtual bool threadLoop(); |
| 453 | virtual status_t readyToRun() { return NO_ERROR; } |
| 454 | virtual void onFirstRef() {} |
| 455 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 456 | status_t start(RecordTrack* recordTrack); |
| 457 | void stop(RecordTrack* recordTrack); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 458 | void exit(); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 459 | |
| 460 | private: |
| 461 | AudioRecordThread(); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 462 | AudioHardwareInterface *mAudioHardware; |
| 463 | sp<RecordTrack> mRecordTrack; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 464 | Mutex mLock; |
| 465 | Condition mWaitWorkCV; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 466 | volatile bool mActive; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 467 | status_t mStartStatus; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 468 | }; |
| 469 | |
| 470 | friend class AudioRecordThread; |
| 471 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 472 | status_t startRecord(RecordTrack* recordTrack); |
| 473 | void stopRecord(RecordTrack* recordTrack); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 474 | |
The Android Open Source Project | a6938ba | 2009-02-10 15:44:00 -0800 | [diff] [blame^] | 475 | void notifyOutputChange_l(); |
| 476 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 477 | mutable Mutex mHardwareLock; |
| 478 | mutable Mutex mLock; |
| 479 | mutable Condition mWaitWorkCV; |
| 480 | DefaultKeyedVector< pid_t, wp<Client> > mClients; |
| 481 | SortedVector< wp<Track> > mActiveTracks; |
| 482 | SortedVector< sp<Track> > mTracks; |
| 483 | float mMasterVolume; |
| 484 | uint32_t mMasterRouting; |
| 485 | bool mMasterMute; |
| 486 | stream_type_t mStreamTypes[AudioTrack::NUM_STREAM_TYPES]; |
| 487 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 488 | AudioMixer* mHardwareAudioMixer; |
| 489 | AudioMixer* mA2dpAudioMixer; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 490 | AudioMixer* mAudioMixer; |
| 491 | AudioHardwareInterface* mAudioHardware; |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame] | 492 | AudioHardwareInterface* mA2dpAudioInterface; |
| 493 | AudioStreamOut* mHardwareOutput; |
| 494 | AudioStreamOut* mA2dpOutput; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 495 | AudioStreamOut* mOutput; |
The Android Open Source Project | 2762932 | 2009-01-09 17:51:23 -0800 | [diff] [blame] | 496 | AudioStreamOut* mRequestedOutput; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 497 | sp<AudioRecordThread> mAudioRecordThread; |
| 498 | uint32_t mSampleRate; |
| 499 | size_t mFrameCount; |
| 500 | int mChannelCount; |
| 501 | int mFormat; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 502 | int16_t* mMixBuffer; |
| 503 | mutable int mHardwareStatus; |
| 504 | nsecs_t mLastWriteTime; |
| 505 | int mNumWrites; |
| 506 | int mNumDelayedWrites; |
| 507 | bool mStandby; |
| 508 | bool mInWrite; |
The Android Open Source Project | e41dd75 | 2009-01-22 00:13:42 -0800 | [diff] [blame] | 509 | int mA2dpDisableCount; |
| 510 | bool mA2dpSuppressed; |
The Android Open Source Project | a6938ba | 2009-02-10 15:44:00 -0800 | [diff] [blame^] | 511 | bool mMusicMuteSaved; |
| 512 | SortedVector< wp<IBinder> > mNotificationClients; |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 513 | }; |
| 514 | |
| 515 | // ---------------------------------------------------------------------------- |
| 516 | |
| 517 | }; // namespace android |
| 518 | |
| 519 | #endif // ANDROID_AUDIO_FLINGER_H |