1/*
2 * Copyright (C) 2014 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_CAPTURE_H
18#define ANDROID_AUDIO_FAST_CAPTURE_H
19
20#include "FastThread.h"
21#include "StateQueue.h"
22#include "FastCaptureState.h"
23
24namespace android {
25
26typedef StateQueue<FastCaptureState> FastCaptureStateQueue;
27
28struct FastCaptureDumpState : FastThreadDumpState {
29    FastCaptureDumpState();
30    /*virtual*/ ~FastCaptureDumpState();
31
32    // FIXME by renaming, could pull up many of these to FastThreadDumpState
33    uint32_t mReadSequence;     // incremented before and after each read()
34    uint32_t mFramesRead;       // total number of frames read successfully
35    uint32_t mReadErrors;       // total number of read() errors
36    uint32_t mSampleRate;
37    size_t   mFrameCount;
38};
39
40class FastCapture : public FastThread {
41
42public:
43            FastCapture();
44    virtual ~FastCapture();
45
46            FastCaptureStateQueue*  sq();
47
48private:
49            FastCaptureStateQueue   mSQ;
50
51    // callouts
52    virtual const FastThreadState *poll();
53    virtual void setLog(NBLog::Writer *logWriter);
54    virtual void onIdle();
55    virtual void onExit();
56    virtual bool isSubClassCommand(FastThreadState::Command command);
57    virtual void onStateChange();
58    virtual void onWork();
59
60    static const FastCaptureState initial;
61    FastCaptureState preIdle; // copy of state before we went into idle
62    // FIXME by renaming, could pull up many of these to FastThread
63    NBAIO_Source *inputSource;
64    int inputSourceGen;
65    NBAIO_Sink *pipeSink;
66    int pipeSinkGen;
67    short *readBuffer;
68    ssize_t readBufferState;    // number of initialized frames in readBuffer, or -1 to clear
69    NBAIO_Format format;
70    unsigned sampleRate;
71    FastCaptureDumpState dummyDumpState;
72    uint32_t totalNativeFramesRead; // copied to dumpState->mFramesRead
73
74};  // class FastCapture
75
76}   // namespace android
77
78#endif  // ANDROID_AUDIO_FAST_CAPTURE_H
79