RepeaterSource.h revision a556c4822fc205db0d27834ba5b637c351d73ffa
1#ifndef REPEATER_SOURCE_H_
2
3#define REPEATER_SOURCE_H_
4
5#include <media/stagefright/foundation/ABase.h>
6#include <media/stagefright/foundation/AHandlerReflector.h>
7#include <media/stagefright/MediaSource.h>
8
9#define SUSPEND_VIDEO_IF_IDLE   0
10
11namespace android {
12
13// This MediaSource delivers frames at a constant rate by repeating buffers
14// if necessary.
15struct RepeaterSource : public MediaSource {
16    RepeaterSource(const sp<MediaSource> &source, double rateHz);
17
18    virtual status_t start(MetaData *params);
19    virtual status_t stop();
20    virtual sp<MetaData> getFormat();
21
22    virtual status_t read(
23            MediaBuffer **buffer, const ReadOptions *options);
24
25    void onMessageReceived(const sp<AMessage> &msg);
26
27    // If RepeaterSource is currently dormant, because SurfaceFlinger didn't
28    // send updates in a while, this is its wakeup call.
29    void wakeUp();
30
31protected:
32    virtual ~RepeaterSource();
33
34private:
35    enum {
36        kWhatRead,
37    };
38
39    Mutex mLock;
40    Condition mCondition;
41
42    bool mStarted;
43
44    sp<MediaSource> mSource;
45    double mRateHz;
46
47    sp<ALooper> mLooper;
48    sp<AHandlerReflector<RepeaterSource> > mReflector;
49
50    MediaBuffer *mBuffer;
51    status_t mResult;
52    int64_t mLastBufferUpdateUs;
53
54    int64_t mStartTimeUs;
55    int32_t mFrameCount;
56
57    void postRead();
58
59    DISALLOW_EVIL_CONSTRUCTORS(RepeaterSource);
60};
61
62}  // namespace android
63
64#endif // REPEATER_SOURCE_H_
65