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> |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 23 | #include <limits.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 34 | #include <binder/MemoryDealer.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 47 | class AudioResampler; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | |
| 49 | |
| 50 | // ---------------------------------------------------------------------------- |
| 51 | |
| 52 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 53 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 54 | |
| 55 | |
| 56 | // ---------------------------------------------------------------------------- |
| 57 | |
| 58 | static const nsecs_t kStandbyTimeInNsecs = seconds(3); |
| 59 | |
Eric Laurent | d878cd8 | 2010-05-12 02:05:53 -0700 | [diff] [blame^] | 60 | class AudioFlinger : public BnAudioFlinger |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | { |
| 62 | public: |
| 63 | static void instantiate(); |
| 64 | |
| 65 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 66 | |
| 67 | // IAudioFlinger interface |
| 68 | virtual sp<IAudioTrack> createTrack( |
| 69 | pid_t pid, |
| 70 | int streamType, |
| 71 | uint32_t sampleRate, |
| 72 | int format, |
| 73 | int channelCount, |
| 74 | int frameCount, |
| 75 | uint32_t flags, |
| 76 | const sp<IMemory>& sharedBuffer, |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 77 | int output, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | status_t *status); |
| 79 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 80 | virtual uint32_t sampleRate(int output) const; |
| 81 | virtual int channelCount(int output) const; |
| 82 | virtual int format(int output) const; |
| 83 | virtual size_t frameCount(int output) const; |
| 84 | virtual uint32_t latency(int output) const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | |
| 86 | virtual status_t setMasterVolume(float value); |
| 87 | virtual status_t setMasterMute(bool muted); |
| 88 | |
| 89 | virtual float masterVolume() const; |
| 90 | virtual bool masterMute() const; |
| 91 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 92 | virtual status_t setStreamVolume(int stream, float value, int output); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | virtual status_t setStreamMute(int stream, bool muted); |
| 94 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 95 | virtual float streamVolume(int stream, int output) const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | virtual bool streamMute(int stream) const; |
| 97 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | virtual status_t setMode(int mode); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | |
| 100 | virtual status_t setMicMute(bool state); |
| 101 | virtual bool getMicMute() const; |
| 102 | |
Eric Laurent | 43c0b0a | 2010-01-25 08:49:09 -0800 | [diff] [blame] | 103 | virtual bool isStreamActive(int stream) const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 105 | virtual status_t setParameters(int ioHandle, const String8& keyValuePairs); |
| 106 | virtual String8 getParameters(int ioHandle, const String8& keys); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | |
| 108 | virtual void registerClient(const sp<IAudioFlingerClient>& client); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 109 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); |
Eric Laurent | 134ccbd | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 111 | virtual unsigned int getInputFramesLost(int ioHandle); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 112 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 113 | virtual int openOutput(uint32_t *pDevices, |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 114 | uint32_t *pSamplingRate, |
| 115 | uint32_t *pFormat, |
| 116 | uint32_t *pChannels, |
| 117 | uint32_t *pLatencyMs, |
| 118 | uint32_t flags); |
| 119 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 120 | virtual int openDuplicateOutput(int output1, int output2); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 121 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 122 | virtual status_t closeOutput(int output); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 123 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 124 | virtual status_t suspendOutput(int output); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 125 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 126 | virtual status_t restoreOutput(int output); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 127 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 128 | virtual int openInput(uint32_t *pDevices, |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 129 | uint32_t *pSamplingRate, |
| 130 | uint32_t *pFormat, |
| 131 | uint32_t *pChannels, |
| 132 | uint32_t acoustics); |
| 133 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 134 | virtual status_t closeInput(int input); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 135 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 136 | virtual status_t setStreamOutput(uint32_t stream, int output); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 137 | |
Eric Laurent | 63da2b6 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 138 | virtual status_t setVoiceVolume(float volume); |
| 139 | |
Eric Laurent | e9ed272 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 140 | virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, int output); |
| 141 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | enum hardware_call_state { |
| 143 | AUDIO_HW_IDLE = 0, |
| 144 | AUDIO_HW_INIT, |
| 145 | AUDIO_HW_OUTPUT_OPEN, |
| 146 | AUDIO_HW_OUTPUT_CLOSE, |
| 147 | AUDIO_HW_INPUT_OPEN, |
| 148 | AUDIO_HW_INPUT_CLOSE, |
| 149 | AUDIO_HW_STANDBY, |
| 150 | AUDIO_HW_SET_MASTER_VOLUME, |
| 151 | AUDIO_HW_GET_ROUTING, |
| 152 | AUDIO_HW_SET_ROUTING, |
| 153 | AUDIO_HW_GET_MODE, |
| 154 | AUDIO_HW_SET_MODE, |
| 155 | AUDIO_HW_GET_MIC_MUTE, |
| 156 | AUDIO_HW_SET_MIC_MUTE, |
| 157 | AUDIO_SET_VOICE_VOLUME, |
| 158 | AUDIO_SET_PARAMETER, |
| 159 | }; |
| 160 | |
| 161 | // record interface |
| 162 | virtual sp<IAudioRecord> openRecord( |
| 163 | pid_t pid, |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 164 | int input, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | uint32_t sampleRate, |
| 166 | int format, |
| 167 | int channelCount, |
| 168 | int frameCount, |
| 169 | uint32_t flags, |
| 170 | status_t *status); |
| 171 | |
| 172 | virtual status_t onTransact( |
| 173 | uint32_t code, |
| 174 | const Parcel& data, |
| 175 | Parcel* reply, |
| 176 | uint32_t flags); |
| 177 | |
| 178 | private: |
| 179 | AudioFlinger(); |
| 180 | virtual ~AudioFlinger(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | |
| 183 | // Internal dump utilites. |
| 184 | status_t dumpPermissionDenial(int fd, const Vector<String16>& args); |
| 185 | status_t dumpClients(int fd, const Vector<String16>& args); |
| 186 | status_t dumpInternals(int fd, const Vector<String16>& args); |
| 187 | |
| 188 | // --- Client --- |
| 189 | class Client : public RefBase { |
| 190 | public: |
| 191 | Client(const sp<AudioFlinger>& audioFlinger, pid_t pid); |
| 192 | virtual ~Client(); |
| 193 | const sp<MemoryDealer>& heap() const; |
| 194 | pid_t pid() const { return mPid; } |
Eric Laurent | 0f8ab67 | 2009-09-17 05:12:56 -0700 | [diff] [blame] | 195 | sp<AudioFlinger> audioFlinger() { return mAudioFlinger; } |
| 196 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | private: |
| 198 | Client(const Client&); |
| 199 | Client& operator = (const Client&); |
| 200 | sp<AudioFlinger> mAudioFlinger; |
| 201 | sp<MemoryDealer> mMemoryDealer; |
| 202 | pid_t mPid; |
| 203 | }; |
| 204 | |
Eric Laurent | d878cd8 | 2010-05-12 02:05:53 -0700 | [diff] [blame^] | 205 | // --- Notification Client --- |
| 206 | class NotificationClient : public IBinder::DeathRecipient { |
| 207 | public: |
| 208 | NotificationClient(const sp<AudioFlinger>& audioFlinger, |
| 209 | const sp<IAudioFlingerClient>& client, |
| 210 | pid_t pid); |
| 211 | virtual ~NotificationClient(); |
| 212 | |
| 213 | sp<IAudioFlingerClient> client() { return mClient; } |
| 214 | |
| 215 | // IBinder::DeathRecipient |
| 216 | virtual void binderDied(const wp<IBinder>& who); |
| 217 | |
| 218 | private: |
| 219 | NotificationClient(const NotificationClient&); |
| 220 | NotificationClient& operator = (const NotificationClient&); |
| 221 | |
| 222 | sp<AudioFlinger> mAudioFlinger; |
| 223 | pid_t mPid; |
| 224 | sp<IAudioFlingerClient> mClient; |
| 225 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | |
| 227 | class TrackHandle; |
| 228 | class RecordHandle; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 229 | class RecordThread; |
| 230 | class PlaybackThread; |
| 231 | class MixerThread; |
| 232 | class DirectOutputThread; |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 233 | class DuplicatingThread; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 234 | class Track; |
| 235 | class RecordTrack; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 237 | class ThreadBase : public Thread { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | public: |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 239 | ThreadBase (const sp<AudioFlinger>& audioFlinger, int id); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 240 | virtual ~ThreadBase(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | |
Eric Laurent | ee47d43 | 2009-11-07 00:01:32 -0800 | [diff] [blame] | 242 | status_t dumpBase(int fd, const Vector<String16>& args); |
| 243 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | // base for record and playback |
| 245 | class TrackBase : public AudioBufferProvider, public RefBase { |
| 246 | |
| 247 | public: |
| 248 | enum track_state { |
| 249 | IDLE, |
| 250 | TERMINATED, |
| 251 | STOPPED, |
| 252 | RESUMING, |
| 253 | ACTIVE, |
| 254 | PAUSING, |
| 255 | PAUSED |
| 256 | }; |
| 257 | |
| 258 | enum track_flags { |
| 259 | STEPSERVER_FAILED = 0x01, // StepServer could not acquire cblk->lock mutex |
| 260 | SYSTEM_FLAGS_MASK = 0x0000ffffUL, |
| 261 | // The upper 16 bits are used for track-specific flags. |
| 262 | }; |
| 263 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 264 | TrackBase(const wp<ThreadBase>& thread, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | const sp<Client>& client, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | uint32_t sampleRate, |
| 267 | int format, |
| 268 | int channelCount, |
| 269 | int frameCount, |
| 270 | uint32_t flags, |
| 271 | const sp<IMemory>& sharedBuffer); |
| 272 | ~TrackBase(); |
| 273 | |
| 274 | virtual status_t start() = 0; |
| 275 | virtual void stop() = 0; |
| 276 | sp<IMemory> getCblk() const; |
Eric Laurent | f5aba82 | 2009-08-10 23:22:32 -0700 | [diff] [blame] | 277 | audio_track_cblk_t* cblk() const { return mCblk; } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | |
| 279 | protected: |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 280 | friend class ThreadBase; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | friend class RecordHandle; |
Eric Laurent | 9395d9b | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 282 | friend class PlaybackThread; |
| 283 | friend class RecordThread; |
| 284 | friend class MixerThread; |
| 285 | friend class DirectOutputThread; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | |
| 287 | TrackBase(const TrackBase&); |
| 288 | TrackBase& operator = (const TrackBase&); |
| 289 | |
| 290 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0; |
| 291 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 292 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | int format() const { |
| 294 | return mFormat; |
| 295 | } |
| 296 | |
| 297 | int channelCount() const ; |
| 298 | |
| 299 | int sampleRate() const; |
| 300 | |
| 301 | void* getBuffer(uint32_t offset, uint32_t frames) const; |
| 302 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | bool isStopped() const { |
| 304 | return mState == STOPPED; |
| 305 | } |
| 306 | |
| 307 | bool isTerminated() const { |
| 308 | return mState == TERMINATED; |
| 309 | } |
| 310 | |
| 311 | bool step(); |
| 312 | void reset(); |
| 313 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 314 | wp<ThreadBase> mThread; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | sp<Client> mClient; |
| 316 | sp<IMemory> mCblkMemory; |
| 317 | audio_track_cblk_t* mCblk; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | void* mBuffer; |
| 319 | void* mBufferEnd; |
| 320 | uint32_t mFrameCount; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | // we don't really need a lock for these |
| 322 | int mState; |
| 323 | int mClientTid; |
| 324 | uint8_t mFormat; |
| 325 | uint32_t mFlags; |
| 326 | }; |
| 327 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 328 | class ConfigEvent { |
| 329 | public: |
| 330 | ConfigEvent() : mEvent(0), mParam(0) {} |
| 331 | |
| 332 | int mEvent; |
| 333 | int mParam; |
| 334 | }; |
| 335 | |
| 336 | uint32_t sampleRate() const; |
| 337 | int channelCount() const; |
| 338 | int format() const; |
| 339 | size_t frameCount() const; |
| 340 | void wakeUp() { mWaitWorkCV.broadcast(); } |
| 341 | void exit(); |
| 342 | virtual bool checkForNewParameters_l() = 0; |
| 343 | virtual status_t setParameters(const String8& keyValuePairs); |
| 344 | virtual String8 getParameters(const String8& keys) = 0; |
| 345 | virtual void audioConfigChanged(int event, int param = 0) = 0; |
| 346 | void sendConfigEvent(int event, int param = 0); |
Eric Laurent | 3464c01 | 2009-08-04 09:45:33 -0700 | [diff] [blame] | 347 | void sendConfigEvent_l(int event, int param = 0); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 348 | void processConfigEvents(); |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 349 | int id() const { return mId;} |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 350 | bool standby() { return mStandby; } |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 351 | |
Eric Laurent | 9395d9b | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 352 | mutable Mutex mLock; |
| 353 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 354 | protected: |
| 355 | |
| 356 | friend class Track; |
| 357 | friend class TrackBase; |
| 358 | friend class PlaybackThread; |
| 359 | friend class MixerThread; |
| 360 | friend class DirectOutputThread; |
| 361 | friend class DuplicatingThread; |
| 362 | friend class RecordThread; |
| 363 | friend class RecordTrack; |
| 364 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 365 | Condition mWaitWorkCV; |
| 366 | sp<AudioFlinger> mAudioFlinger; |
| 367 | uint32_t mSampleRate; |
| 368 | size_t mFrameCount; |
| 369 | int mChannelCount; |
| 370 | int mFormat; |
| 371 | uint32_t mFrameSize; |
| 372 | Condition mParamCond; |
Eric Laurent | 3464c01 | 2009-08-04 09:45:33 -0700 | [diff] [blame] | 373 | Vector<String8> mNewParameters; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 374 | status_t mParamStatus; |
| 375 | Vector<ConfigEvent *> mConfigEvents; |
| 376 | bool mStandby; |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 377 | int mId; |
| 378 | bool mExiting; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 379 | }; |
| 380 | |
| 381 | // --- PlaybackThread --- |
| 382 | class PlaybackThread : public ThreadBase { |
| 383 | public: |
| 384 | |
| 385 | enum type { |
| 386 | MIXER, |
| 387 | DIRECT, |
| 388 | DUPLICATING |
| 389 | }; |
| 390 | |
Eric Laurent | 0e49d35 | 2009-11-09 23:32:22 -0800 | [diff] [blame] | 391 | enum mixer_state { |
| 392 | MIXER_IDLE, |
| 393 | MIXER_TRACKS_ENABLED, |
| 394 | MIXER_TRACKS_READY |
| 395 | }; |
| 396 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 397 | // playback track |
| 398 | class Track : public TrackBase { |
| 399 | public: |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 400 | Track( const wp<ThreadBase>& thread, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 401 | const sp<Client>& client, |
| 402 | int streamType, |
| 403 | uint32_t sampleRate, |
| 404 | int format, |
| 405 | int channelCount, |
| 406 | int frameCount, |
| 407 | const sp<IMemory>& sharedBuffer); |
| 408 | ~Track(); |
| 409 | |
| 410 | void dump(char* buffer, size_t size); |
| 411 | virtual status_t start(); |
| 412 | virtual void stop(); |
| 413 | void pause(); |
| 414 | |
| 415 | void flush(); |
| 416 | void destroy(); |
| 417 | void mute(bool); |
| 418 | void setVolume(float left, float right); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 419 | int name() const { |
| 420 | return mName; |
| 421 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | |
Eric Laurent | 570dd0b | 2009-05-22 09:18:15 -0700 | [diff] [blame] | 423 | int type() const { |
| 424 | return mStreamType; |
| 425 | } |
| 426 | |
| 427 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | protected: |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 429 | friend class ThreadBase; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 430 | friend class AudioFlinger; |
Eric Laurent | 9395d9b | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 431 | friend class TrackHandle; |
| 432 | friend class PlaybackThread; |
| 433 | friend class MixerThread; |
| 434 | friend class DirectOutputThread; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | |
| 436 | Track(const Track&); |
| 437 | Track& operator = (const Track&); |
| 438 | |
| 439 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 440 | bool isMuted() { return mMute; } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | bool isPausing() const { |
| 442 | return mState == PAUSING; |
| 443 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 444 | bool isPaused() const { |
| 445 | return mState == PAUSED; |
| 446 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | bool isReady() const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | void setPaused() { mState = PAUSED; } |
| 449 | void reset(); |
| 450 | |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 451 | bool isOutputTrack() const { |
| 452 | return (mStreamType == AudioSystem::NUM_STREAM_TYPES); |
| 453 | } |
| 454 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | // we don't really need a lock for these |
| 456 | float mVolume[2]; |
| 457 | volatile bool mMute; |
| 458 | // FILLED state is used for suppressing volume ramp at begin of playing |
| 459 | enum {FS_FILLING, FS_FILLED, FS_ACTIVE}; |
| 460 | mutable uint8_t mFillingUpStatus; |
| 461 | int8_t mRetryCount; |
| 462 | sp<IMemory> mSharedBuffer; |
| 463 | bool mResetDone; |
Eric Laurent | 570dd0b | 2009-05-22 09:18:15 -0700 | [diff] [blame] | 464 | int mStreamType; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 465 | int mName; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | }; // end of Track |
| 467 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | |
| 469 | // playback track |
| 470 | class OutputTrack : public Track { |
| 471 | public: |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 472 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | class Buffer: public AudioBufferProvider::Buffer { |
| 474 | public: |
| 475 | int16_t *mBuffer; |
| 476 | }; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 477 | |
| 478 | OutputTrack( const wp<ThreadBase>& thread, |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 479 | DuplicatingThread *sourceThread, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | uint32_t sampleRate, |
| 481 | int format, |
| 482 | int channelCount, |
| 483 | int frameCount); |
| 484 | ~OutputTrack(); |
| 485 | |
| 486 | virtual status_t start(); |
| 487 | virtual void stop(); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 488 | bool write(int16_t* data, uint32_t frames); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | bool bufferQueueEmpty() { return (mBufferQueue.size() == 0) ? true : false; } |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 490 | bool isActive() { return mActive; } |
| 491 | wp<ThreadBase>& thread() { return mThread; } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | |
| 493 | private: |
| 494 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 495 | status_t obtainBuffer(AudioBufferProvider::Buffer* buffer, uint32_t waitTimeMs); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | void clearBufferQueue(); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 497 | |
| 498 | // Maximum number of pending buffers allocated by OutputTrack::write() |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 499 | static const uint8_t kMaxOverFlowBuffers = 10; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 500 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | Vector < Buffer* > mBufferQueue; |
| 502 | AudioBufferProvider::Buffer mOutBuffer; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 503 | bool mActive; |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 504 | DuplicatingThread* mSourceThread; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 505 | }; // end of OutputTrack |
| 506 | |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 507 | PlaybackThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 508 | virtual ~PlaybackThread(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | |
| 510 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 511 | |
| 512 | // Thread virtuals |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | virtual status_t readyToRun(); |
| 514 | virtual void onFirstRef(); |
| 515 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | virtual uint32_t latency() const; |
| 517 | |
| 518 | virtual status_t setMasterVolume(float value); |
| 519 | virtual status_t setMasterMute(bool muted); |
| 520 | |
| 521 | virtual float masterVolume() const; |
| 522 | virtual bool masterMute() const; |
| 523 | |
| 524 | virtual status_t setStreamVolume(int stream, float value); |
| 525 | virtual status_t setStreamMute(int stream, bool muted); |
| 526 | |
| 527 | virtual float streamVolume(int stream) const; |
| 528 | virtual bool streamMute(int stream) const; |
| 529 | |
Eric Laurent | 43c0b0a | 2010-01-25 08:49:09 -0800 | [diff] [blame] | 530 | bool isStreamActive(int stream) const; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 531 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 532 | sp<Track> createTrack_l( |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | const sp<AudioFlinger::Client>& client, |
| 534 | int streamType, |
| 535 | uint32_t sampleRate, |
| 536 | int format, |
| 537 | int channelCount, |
| 538 | int frameCount, |
| 539 | const sp<IMemory>& sharedBuffer, |
| 540 | status_t *status); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 541 | |
| 542 | AudioStreamOut* getOutput() { return mOutput; } |
| 543 | |
| 544 | virtual int type() const { return mType; } |
Eric Laurent | f9df249 | 2009-08-06 08:49:39 -0700 | [diff] [blame] | 545 | void suspend() { mSuspended++; } |
| 546 | void restore() { if (mSuspended) mSuspended--; } |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 547 | bool isSuspended() { return (mSuspended != 0); } |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 548 | virtual String8 getParameters(const String8& keys); |
| 549 | virtual void audioConfigChanged(int event, int param = 0); |
Eric Laurent | e9ed272 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 550 | virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 551 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | struct stream_type_t { |
| 553 | stream_type_t() |
| 554 | : volume(1.0f), |
| 555 | mute(false) |
| 556 | { |
| 557 | } |
| 558 | float volume; |
| 559 | bool mute; |
| 560 | }; |
| 561 | |
Eric Laurent | 9395d9b | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 562 | protected: |
| 563 | int mType; |
| 564 | int16_t* mMixBuffer; |
Eric Laurent | f9df249 | 2009-08-06 08:49:39 -0700 | [diff] [blame] | 565 | int mSuspended; |
Eric Laurent | 9395d9b | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 566 | int mBytesWritten; |
| 567 | bool mMasterMute; |
| 568 | SortedVector< wp<Track> > mActiveTracks; |
| 569 | |
Eric Laurent | f5e868b | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 570 | virtual int getTrackName_l() = 0; |
| 571 | virtual void deleteTrackName_l(int name) = 0; |
Eric Laurent | 0e49d35 | 2009-11-09 23:32:22 -0800 | [diff] [blame] | 572 | virtual uint32_t activeSleepTimeUs() = 0; |
| 573 | virtual uint32_t idleSleepTimeUs() = 0; |
Eric Laurent | f5e868b | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 574 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | private: |
| 576 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 577 | friend class AudioFlinger; |
Eric Laurent | f5aba82 | 2009-08-10 23:22:32 -0700 | [diff] [blame] | 578 | friend class OutputTrack; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | friend class Track; |
| 580 | friend class TrackBase; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 581 | friend class MixerThread; |
| 582 | friend class DirectOutputThread; |
| 583 | friend class DuplicatingThread; |
| 584 | |
| 585 | PlaybackThread(const Client&); |
| 586 | PlaybackThread& operator = (const PlaybackThread&); |
| 587 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 588 | status_t addTrack_l(const sp<Track>& track); |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 589 | void destroyTrack_l(const sp<Track>& track); |
Eric Laurent | f5e868b | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 590 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 591 | void readOutputParameters(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 592 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 593 | virtual status_t dumpInternals(int fd, const Vector<String16>& args); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | status_t dumpTracks(int fd, const Vector<String16>& args); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 595 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | SortedVector< sp<Track> > mTracks; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 597 | // mStreamTypes[] uses 1 additionnal stream type internally for the OutputTrack used by DuplicatingThread |
| 598 | stream_type_t mStreamTypes[AudioSystem::NUM_STREAM_TYPES + 1]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 599 | AudioStreamOut* mOutput; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | float mMasterVolume; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | nsecs_t mLastWriteTime; |
| 602 | int mNumWrites; |
| 603 | int mNumDelayedWrites; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | bool mInWrite; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | }; |
| 606 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 607 | class MixerThread : public PlaybackThread { |
| 608 | public: |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 609 | MixerThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 610 | virtual ~MixerThread(); |
| 611 | |
| 612 | // Thread virtuals |
| 613 | virtual bool threadLoop(); |
| 614 | |
| 615 | void getTracks(SortedVector < sp<Track> >& tracks, |
| 616 | SortedVector < wp<Track> >& activeTracks, |
| 617 | int streamType); |
| 618 | void putTracks(SortedVector < sp<Track> >& tracks, |
| 619 | SortedVector < wp<Track> >& activeTracks); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 620 | virtual bool checkForNewParameters_l(); |
| 621 | virtual status_t dumpInternals(int fd, const Vector<String16>& args); |
| 622 | |
| 623 | protected: |
Eric Laurent | 0e49d35 | 2009-11-09 23:32:22 -0800 | [diff] [blame] | 624 | uint32_t prepareTracks_l(const SortedVector< wp<Track> >& activeTracks, Vector< sp<Track> > *tracksToRemove); |
Eric Laurent | f5e868b | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 625 | virtual int getTrackName_l(); |
| 626 | virtual void deleteTrackName_l(int name); |
Eric Laurent | 0e49d35 | 2009-11-09 23:32:22 -0800 | [diff] [blame] | 627 | virtual uint32_t activeSleepTimeUs(); |
| 628 | virtual uint32_t idleSleepTimeUs(); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 629 | |
| 630 | AudioMixer* mAudioMixer; |
| 631 | }; |
| 632 | |
| 633 | class DirectOutputThread : public PlaybackThread { |
| 634 | public: |
| 635 | |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 636 | DirectOutputThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 637 | ~DirectOutputThread(); |
| 638 | |
| 639 | // Thread virtuals |
| 640 | virtual bool threadLoop(); |
| 641 | |
Eric Laurent | f5e868b | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 642 | virtual bool checkForNewParameters_l(); |
| 643 | |
| 644 | protected: |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 645 | virtual int getTrackName_l(); |
| 646 | virtual void deleteTrackName_l(int name); |
Eric Laurent | 0e49d35 | 2009-11-09 23:32:22 -0800 | [diff] [blame] | 647 | virtual uint32_t activeSleepTimeUs(); |
| 648 | virtual uint32_t idleSleepTimeUs(); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 649 | |
| 650 | private: |
| 651 | float mLeftVolume; |
| 652 | float mRightVolume; |
| 653 | }; |
| 654 | |
| 655 | class DuplicatingThread : public MixerThread { |
| 656 | public: |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 657 | DuplicatingThread (const sp<AudioFlinger>& audioFlinger, MixerThread* mainThread, int id); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 658 | ~DuplicatingThread(); |
| 659 | |
| 660 | // Thread virtuals |
| 661 | virtual bool threadLoop(); |
| 662 | void addOutputTrack(MixerThread* thread); |
| 663 | void removeOutputTrack(MixerThread* thread); |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 664 | uint32_t waitTimeMs() { return mWaitTimeMs; } |
| 665 | protected: |
| 666 | virtual uint32_t activeSleepTimeUs(); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 667 | |
| 668 | private: |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 669 | bool outputsReady(SortedVector< sp<OutputTrack> > &outputTracks); |
| 670 | void updateWaitTime(); |
| 671 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 672 | SortedVector < sp<OutputTrack> > mOutputTracks; |
Eric Laurent | 7e2aad1 | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 673 | uint32_t mWaitTimeMs; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 674 | }; |
| 675 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 676 | PlaybackThread *checkPlaybackThread_l(int output) const; |
| 677 | MixerThread *checkMixerThread_l(int output) const; |
| 678 | RecordThread *checkRecordThread_l(int input) const; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 679 | float streamVolumeInternal(int stream) const { return mStreamTypes[stream].volume; } |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 680 | void audioConfigChanged_l(int event, int ioHandle, void *param2); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 681 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | friend class AudioBuffer; |
| 683 | |
| 684 | class TrackHandle : public android::BnAudioTrack { |
| 685 | public: |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 686 | TrackHandle(const sp<PlaybackThread::Track>& track); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | virtual ~TrackHandle(); |
| 688 | virtual status_t start(); |
| 689 | virtual void stop(); |
| 690 | virtual void flush(); |
| 691 | virtual void mute(bool); |
| 692 | virtual void pause(); |
| 693 | virtual void setVolume(float left, float right); |
| 694 | virtual sp<IMemory> getCblk() const; |
| 695 | virtual status_t onTransact( |
| 696 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 697 | private: |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 698 | sp<PlaybackThread::Track> mTrack; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | }; |
| 700 | |
| 701 | friend class Client; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 702 | friend class PlaybackThread::Track; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | |
| 704 | |
Eric Laurent | 0f8ab67 | 2009-09-17 05:12:56 -0700 | [diff] [blame] | 705 | void removeClient_l(pid_t pid); |
Eric Laurent | d878cd8 | 2010-05-12 02:05:53 -0700 | [diff] [blame^] | 706 | void removeNotificationClient(pid_t pid); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | |
| 708 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 709 | // record thread |
| 710 | class RecordThread : public ThreadBase, public AudioBufferProvider |
| 711 | { |
| 712 | public: |
| 713 | |
| 714 | // record track |
| 715 | class RecordTrack : public TrackBase { |
| 716 | public: |
| 717 | RecordTrack(const wp<ThreadBase>& thread, |
| 718 | const sp<Client>& client, |
| 719 | uint32_t sampleRate, |
| 720 | int format, |
| 721 | int channelCount, |
| 722 | int frameCount, |
| 723 | uint32_t flags); |
| 724 | ~RecordTrack(); |
| 725 | |
| 726 | virtual status_t start(); |
| 727 | virtual void stop(); |
| 728 | |
| 729 | bool overflow() { bool tmp = mOverflow; mOverflow = false; return tmp; } |
| 730 | bool setOverflow() { bool tmp = mOverflow; mOverflow = true; return tmp; } |
| 731 | |
Eric Laurent | ee47d43 | 2009-11-07 00:01:32 -0800 | [diff] [blame] | 732 | void dump(char* buffer, size_t size); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 733 | private: |
| 734 | friend class AudioFlinger; |
Eric Laurent | 9395d9b | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 735 | friend class RecordThread; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 736 | |
| 737 | RecordTrack(const RecordTrack&); |
| 738 | RecordTrack& operator = (const RecordTrack&); |
| 739 | |
| 740 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 741 | |
| 742 | bool mOverflow; |
| 743 | }; |
| 744 | |
| 745 | |
| 746 | RecordThread(const sp<AudioFlinger>& audioFlinger, |
| 747 | AudioStreamIn *input, |
| 748 | uint32_t sampleRate, |
Eric Laurent | 09b4ba8 | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 749 | uint32_t channels, |
| 750 | int id); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 751 | ~RecordThread(); |
| 752 | |
| 753 | virtual bool threadLoop(); |
| 754 | virtual status_t readyToRun() { return NO_ERROR; } |
| 755 | virtual void onFirstRef(); |
| 756 | |
| 757 | status_t start(RecordTrack* recordTrack); |
| 758 | void stop(RecordTrack* recordTrack); |
| 759 | status_t dump(int fd, const Vector<String16>& args); |
| 760 | AudioStreamIn* getInput() { return mInput; } |
| 761 | |
| 762 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 763 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 764 | virtual bool checkForNewParameters_l(); |
| 765 | virtual String8 getParameters(const String8& keys); |
| 766 | virtual void audioConfigChanged(int event, int param = 0); |
| 767 | void readInputParameters(); |
Eric Laurent | 134ccbd | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 768 | virtual unsigned int getInputFramesLost(); |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 769 | |
| 770 | private: |
| 771 | RecordThread(); |
| 772 | AudioStreamIn *mInput; |
| 773 | sp<RecordTrack> mActiveTrack; |
| 774 | Condition mStartStopCond; |
| 775 | AudioResampler *mResampler; |
| 776 | int32_t *mRsmpOutBuffer; |
| 777 | int16_t *mRsmpInBuffer; |
| 778 | size_t mRsmpInIndex; |
| 779 | size_t mInputBytes; |
| 780 | int mReqChannelCount; |
| 781 | uint32_t mReqSampleRate; |
Eric Laurent | 5291095 | 2009-12-05 05:20:01 -0800 | [diff] [blame] | 782 | ssize_t mBytesRead; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 783 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | |
| 785 | class RecordHandle : public android::BnAudioRecord { |
| 786 | public: |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 787 | RecordHandle(const sp<RecordThread::RecordTrack>& recordTrack); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | virtual ~RecordHandle(); |
| 789 | virtual status_t start(); |
| 790 | virtual void stop(); |
| 791 | virtual sp<IMemory> getCblk() const; |
| 792 | virtual status_t onTransact( |
| 793 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 794 | private: |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 795 | sp<RecordThread::RecordTrack> mRecordTrack; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | }; |
| 797 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 798 | friend class RecordThread; |
| 799 | friend class PlaybackThread; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 802 | mutable Mutex mLock; |
The Android Open Source Project | 22f8def | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 803 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 804 | DefaultKeyedVector< pid_t, wp<Client> > mClients; |
| 805 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 806 | mutable Mutex mHardwareLock; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 807 | AudioHardwareInterface* mAudioHardware; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | mutable int mHardwareStatus; |
The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 809 | |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 810 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 811 | DefaultKeyedVector< int, sp<PlaybackThread> > mPlaybackThreads; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 812 | PlaybackThread::stream_type_t mStreamTypes[AudioSystem::NUM_STREAM_TYPES]; |
| 813 | float mMasterVolume; |
| 814 | bool mMasterMute; |
| 815 | |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 816 | DefaultKeyedVector< int, sp<RecordThread> > mRecordThreads; |
Eric Laurent | 9d91ad5 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 817 | |
Eric Laurent | d878cd8 | 2010-05-12 02:05:53 -0700 | [diff] [blame^] | 818 | DefaultKeyedVector< pid_t, sp<NotificationClient> > mNotificationClients; |
Eric Laurent | e0e9ecc | 2009-07-28 08:44:33 -0700 | [diff] [blame] | 819 | int mNextThreadId; |
Eric Laurent | d878cd8 | 2010-05-12 02:05:53 -0700 | [diff] [blame^] | 820 | #ifdef LVMX |
| 821 | int mLifeVibesClientPid; |
| 822 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | }; |
| 824 | |
| 825 | // ---------------------------------------------------------------------------- |
| 826 | |
| 827 | }; // namespace android |
| 828 | |
| 829 | #endif // ANDROID_AUDIO_FLINGER_H |