1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_AUDIO_FAST_MIXER_H 18 #define ANDROID_AUDIO_FAST_MIXER_H 19 20 #include <linux/futex.h> 21 #include <sys/syscall.h> 22 #include <utils/Debug.h> 23 #include "FastThread.h" 24 #include <utils/Thread.h> 25 #include "StateQueue.h" 26 #include "FastMixerState.h" 27 #include "FastMixerDumpState.h" 28 29 namespace android { 30 31 class AudioMixer; 32 33 typedef StateQueue<FastMixerState> FastMixerStateQueue; 34 35 class FastMixer : public FastThread { 36 37 public: 38 FastMixer(); 39 virtual ~FastMixer(); 40 41 FastMixerStateQueue* sq(); 42 43 private: 44 FastMixerStateQueue mSQ; 45 46 // callouts 47 virtual const FastThreadState *poll(); 48 virtual void setLog(NBLog::Writer *logWriter); 49 virtual void onIdle(); 50 virtual void onExit(); 51 virtual bool isSubClassCommand(FastThreadState::Command command); 52 virtual void onStateChange(); 53 virtual void onWork(); 54 55 // FIXME these former local variables need comments and to be renamed to have "m" prefix 56 static const FastMixerState initial; 57 FastMixerState preIdle; // copy of state before we went into idle 58 long slopNs; // accumulated time we've woken up too early (> 0) or too late (< 0) 59 int fastTrackNames[FastMixerState::kMaxFastTracks]; // handles used by mixer to identify tracks 60 int generations[FastMixerState::kMaxFastTracks]; // last observed mFastTracks[i].mGeneration 61 NBAIO_Sink *outputSink; 62 int outputSinkGen; 63 AudioMixer* mixer; 64 65 // mSinkBuffer audio format is stored in format.mFormat. 66 void* mSinkBuffer; // used for mixer output format translation 67 // if sink format is different than mixer output. 68 size_t mSinkBufferSize; 69 uint32_t mSinkChannelCount; 70 audio_channel_mask_t mSinkChannelMask; 71 void* mMixerBuffer; // mixer output buffer. 72 size_t mMixerBufferSize; 73 audio_format_t mMixerBufferFormat; // mixer output format: AUDIO_FORMAT_PCM_(16_BIT|FLOAT). 74 75 enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState; 76 NBAIO_Format format; 77 unsigned sampleRate; 78 int fastTracksGen; 79 FastMixerDumpState dummyDumpState; 80 uint32_t totalNativeFramesWritten; // copied to dumpState->mFramesWritten 81 82 // next 2 fields are valid only when timestampStatus == NO_ERROR 83 AudioTimestamp timestamp; 84 uint32_t nativeFramesWrittenButNotPresented; 85 86 }; // class FastMixer 87 88 } // namespace android 89 90 #endif // ANDROID_AUDIO_FAST_MIXER_H 91