FastMixer.h revision 2234002b0710c8db73f82d397cb945cd541c6bbb
180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright (C) 2012 The Android Open Source Project 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Licensed under the Apache License, Version 2.0 (the "License"); 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * you may not use this file except in compliance with the License. 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * You may obtain a copy of the License at 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * http://www.apache.org/licenses/LICENSE-2.0 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Unless required by applicable law or agreed to in writing, software 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * distributed under the License is distributed on an "AS IS" BASIS, 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * See the License for the specific language governing permissions and 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * limitations under the License. 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef ANDROID_AUDIO_FAST_MIXER_H 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define ANDROID_AUDIO_FAST_MIXER_H 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include <utils/Debug.h> 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if 1 // FIXME move to where used 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruextern "C" { 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "../private/bionic_futex.h" 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "FastThread.h" 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "StateQueue.h" 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "FastMixerState.h" 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "FastMixerDumpState.h" 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querunamespace android { 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass AudioMixer; 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querutypedef StateQueue<FastMixerState> FastMixerStateQueue; 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass FastMixer : public FastThread { 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru FastMixer(); 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru virtual ~FastMixer(); 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru FastMixerStateQueue* sq(); 44 45private: 46 FastMixerStateQueue mSQ; 47 48 // callouts 49 virtual const FastThreadState *poll(); 50 virtual void setLog(NBLog::Writer *logWriter); 51 virtual void onIdle(); 52 virtual void onExit(); 53 virtual bool isSubClassCommand(FastThreadState::Command command); 54 virtual void onStateChange(); 55 virtual void onWork(); 56 57 // FIXME these former local variables need comments and to be renamed to have "m" prefix 58 static const FastMixerState initial; 59 FastMixerState preIdle; // copy of state before we went into idle 60 long slopNs; // accumulated time we've woken up too early (> 0) or too late (< 0) 61 int fastTrackNames[FastMixerState::kMaxFastTracks]; // handles used by mixer to identify tracks 62 int generations[FastMixerState::kMaxFastTracks]; // last observed mFastTracks[i].mGeneration 63 NBAIO_Sink *outputSink; 64 int outputSinkGen; 65 AudioMixer* mixer; 66 short *mixBuffer; 67 enum {UNDEFINED, MIXED, ZEROED} mixBufferState; 68 NBAIO_Format format; 69 unsigned sampleRate; 70 int fastTracksGen; 71 FastMixerDumpState dummyDumpState; 72 uint32_t totalNativeFramesWritten; // copied to dumpState->mFramesWritten 73 74 // next 2 fields are valid only when timestampStatus == NO_ERROR 75 AudioTimestamp timestamp; 76 uint32_t nativeFramesWrittenButNotPresented; 77 78}; // class FastMixer 79 80} // namespace android 81 82#endif // ANDROID_AUDIO_FAST_MIXER_H 83