blob: e4aa2b6a3fcba022500e6c658a77d14eeac4cc48 [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
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
Andreas Huber77c887a2012-10-02 12:49:33 -070025 // If RepeaterSource is currently dormant, because SurfaceFlinger didn't
26 // send updates in a while, this is its wakeup call.
27 void wakeUp();
28
Andreas Huber35213f12012-08-29 11:41:50 -070029protected:
30 virtual ~RepeaterSource();
31
32private:
33 enum {
34 kWhatRead,
35 };
36
37 Mutex mLock;
38 Condition mCondition;
39
Andreas Huber9fcc8ce2012-09-28 16:34:38 -070040 bool mStarted;
41
Andreas Huber35213f12012-08-29 11:41:50 -070042 sp<MediaSource> mSource;
43 double mRateHz;
44
45 sp<ALooper> mLooper;
46 sp<AHandlerReflector<RepeaterSource> > mReflector;
47
48 MediaBuffer *mBuffer;
49 status_t mResult;
Andreas Huber77c887a2012-10-02 12:49:33 -070050 int64_t mLastBufferUpdateUs;
Andreas Huber35213f12012-08-29 11:41:50 -070051
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_