Home | History | Annotate | Download | only in source
      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 
     11 namespace android {
     12 
     13 // This MediaSource delivers frames at a constant rate by repeating buffers
     14 // if necessary.
     15 struct 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 
     31     double getFrameRate() const;
     32     void setFrameRate(double rateHz);
     33 
     34 protected:
     35     virtual ~RepeaterSource();
     36 
     37 private:
     38     enum {
     39         kWhatRead,
     40     };
     41 
     42     Mutex mLock;
     43     Condition mCondition;
     44 
     45     bool mStarted;
     46 
     47     sp<MediaSource> mSource;
     48     double mRateHz;
     49 
     50     sp<ALooper> mLooper;
     51     sp<AHandlerReflector<RepeaterSource> > mReflector;
     52 
     53     MediaBuffer *mBuffer;
     54     status_t mResult;
     55     int64_t mLastBufferUpdateUs;
     56 
     57     int64_t mStartTimeUs;
     58     int32_t mFrameCount;
     59 
     60     void postRead();
     61 
     62     DISALLOW_EVIL_CONSTRUCTORS(RepeaterSource);
     63 };
     64 
     65 }  // namespace android
     66 
     67 #endif // REPEATER_SOURCE_H_
     68