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