Andreas Huber | 35213f1 | 2012-08-29 11:41:50 -0700 | [diff] [blame] | 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 | namespace android { |
| 10 | |
| 11 | // This MediaSource delivers frames at a constant rate by repeating buffers |
| 12 | // if necessary. |
| 13 | struct 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 Huber | 77c887a | 2012-10-02 12:49:33 -0700 | [diff] [blame^] | 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 | |
Andreas Huber | 35213f1 | 2012-08-29 11:41:50 -0700 | [diff] [blame] | 29 | protected: |
| 30 | virtual ~RepeaterSource(); |
| 31 | |
| 32 | private: |
| 33 | enum { |
| 34 | kWhatRead, |
| 35 | }; |
| 36 | |
| 37 | Mutex mLock; |
| 38 | Condition mCondition; |
| 39 | |
Andreas Huber | 9fcc8ce | 2012-09-28 16:34:38 -0700 | [diff] [blame] | 40 | bool mStarted; |
| 41 | |
Andreas Huber | 35213f1 | 2012-08-29 11:41:50 -0700 | [diff] [blame] | 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; |
Andreas Huber | 77c887a | 2012-10-02 12:49:33 -0700 | [diff] [blame^] | 50 | int64_t mLastBufferUpdateUs; |
Andreas Huber | 35213f1 | 2012-08-29 11:41:50 -0700 | [diff] [blame] | 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_ |