blob: a13973c35cbf903acb4fdd4efc8726252b276fb8 [file] [log] [blame]
Andreas Huber35213f12012-08-29 11:41:50 -07001#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
Andreas Huber83c9bd12012-11-12 13:08:44 -08009#define SUSPEND_VIDEO_IF_IDLE 1
10
Andreas Huber35213f12012-08-29 11:41:50 -070011namespace 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
Andreas Huber77c887a2012-10-02 12:49:33 -070027 // If RepeaterSource is currently dormant, because SurfaceFlinger didn't
28 // send updates in a while, this is its wakeup call.
29 void wakeUp();
30
Andreas Huber35213f12012-08-29 11:41:50 -070031protected:
32 virtual ~RepeaterSource();
33
34private:
35 enum {
36 kWhatRead,
37 };
38
39 Mutex mLock;
40 Condition mCondition;
41
Andreas Huber9fcc8ce2012-09-28 16:34:38 -070042 bool mStarted;
43
Andreas Huber35213f12012-08-29 11:41:50 -070044 sp<MediaSource> mSource;
45 double mRateHz;
46
47 sp<ALooper> mLooper;
48 sp<AHandlerReflector<RepeaterSource> > mReflector;
49
50 MediaBuffer *mBuffer;
51 status_t mResult;
Andreas Huber77c887a2012-10-02 12:49:33 -070052 int64_t mLastBufferUpdateUs;
Andreas Huber35213f12012-08-29 11:41:50 -070053
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_