FastMixer.h revision b9e722bdf00333557578497c5abfc77c5d779ecb
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
29namespace android {
30
31class AudioMixer;
32
33typedef StateQueue<FastMixerState> FastMixerStateQueue;
34
35class FastMixer : public FastThread {
36
37public:
38            FastMixer();
39    virtual ~FastMixer();
40
41            FastMixerStateQueue* sq();
42
43private:
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    short *mMixerBuffer;
65    enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState;
66    NBAIO_Format format;
67    unsigned sampleRate;
68    int fastTracksGen;
69    FastMixerDumpState dummyDumpState;
70    uint32_t totalNativeFramesWritten;  // copied to dumpState->mFramesWritten
71
72    // next 2 fields are valid only when timestampStatus == NO_ERROR
73    AudioTimestamp timestamp;
74    uint32_t nativeFramesWrittenButNotPresented;
75
76};  // class FastMixer
77
78}   // namespace android
79
80#endif  // ANDROID_AUDIO_FAST_MIXER_H
81