FastMixer.h revision e4a7ce250cb94a00aa2f76e5edca1c4479dc5401
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 "FastThread.h"
21#include "StateQueue.h"
22#include "FastMixerState.h"
23#include "FastMixerDumpState.h"
24
25namespace android {
26
27class AudioMixer;
28
29typedef StateQueue<FastMixerState> FastMixerStateQueue;
30
31class FastMixer : public FastThread {
32
33public:
34            FastMixer();
35    virtual ~FastMixer();
36
37            FastMixerStateQueue* sq();
38
39private:
40            FastMixerStateQueue mSQ;
41
42    // callouts
43    virtual const FastThreadState *poll();
44    virtual void setLog(NBLog::Writer *logWriter);
45    virtual void onIdle();
46    virtual void onExit();
47    virtual bool isSubClassCommand(FastThreadState::Command command);
48    virtual void onStateChange();
49    virtual void onWork();
50
51    // FIXME these former local variables need comments
52    static const FastMixerState sInitial;
53
54    FastMixerState  mPreIdle;   // copy of state before we went into idle
55    long            mSlopNs;    // accumulated time we've woken up too early (> 0) or too late (< 0)
56    int             mFastTrackNames[FastMixerState::kMaxFastTracks];
57                                // handles used by mixer to identify tracks
58    int             mGenerations[FastMixerState::kMaxFastTracks];
59                                // last observed mFastTracks[i].mGeneration
60    NBAIO_Sink*     mOutputSink;
61    int             mOutputSinkGen;
62    AudioMixer*     mMixer;
63
64    // mSinkBuffer audio format is stored in format.mFormat.
65    void*           mSinkBuffer;        // used for mixer output format translation
66                                        // if sink format is different than mixer output.
67    size_t          mSinkBufferSize;
68    uint32_t        mSinkChannelCount;
69    audio_channel_mask_t mSinkChannelMask;
70    void*           mMixerBuffer;       // mixer output buffer.
71    size_t          mMixerBufferSize;
72    audio_format_t  mMixerBufferFormat; // mixer output format: AUDIO_FORMAT_PCM_(16_BIT|FLOAT).
73
74    enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState;
75    NBAIO_Format    mFormat;
76    unsigned        mSampleRate;
77    int             mFastTracksGen;
78    FastMixerDumpState mDummyFastMixerDumpState;
79    uint32_t        mTotalNativeFramesWritten;  // copied to dumpState->mFramesWritten
80
81    // next 2 fields are valid only when timestampStatus == NO_ERROR
82    AudioTimestamp  mTimestamp;
83    uint32_t        mNativeFramesWrittenButNotPresented;
84
85};  // class FastMixer
86
87}   // namespace android
88
89#endif  // ANDROID_AUDIO_FAST_MIXER_H
90