1 #ifndef _VIDEO_PRODUCER_H 2 #define _VIDEO_PRODUCER_H 3 4 #include <kernel/OS.h> 5 #include <media/BufferProducer.h> 6 #include <media/Controllable.h> 7 #include <media/MediaDefs.h> 8 #include <media/MediaEventLooper.h> 9 #include <media/MediaNode.h> 10 #include <support/Locker.h> 11 12 class CamDevice; 13 14 class VideoProducer : 15 public virtual BMediaEventLooper, 16 public virtual BBufferProducer, 17 public virtual BControllable 18 { 19 public: 20 VideoProducer(BMediaAddOn *addon, CamDevice *dev, 21 const char *name, int32 internal_id); 22 virtual ~VideoProducer(); 23 24 virtual status_t InitCheck() const { return fInitStatus; } 25 26 /* BMediaNode */ 27 public: 28 virtual port_id ControlPort() const; 29 virtual BMediaAddOn *AddOn(int32 * internal_id) const; 30 virtual status_t HandleMessage(int32 message, const void *data, 31 size_t size); 32 protected: 33 virtual void Preroll(); 34 virtual void SetTimeSource(BTimeSource * time_source); 35 virtual status_t RequestCompleted(const media_request_info & info); 36 37 /* BMediaEventLooper */ 38 protected: 39 virtual void NodeRegistered(); 40 virtual void Start(bigtime_t performance_time); 41 virtual void Stop(bigtime_t performance_time, bool immediate); 42 virtual void Seek(bigtime_t media_time, bigtime_t performance_time); 43 virtual void TimeWarp(bigtime_t at_real_time, 44 bigtime_t to_performance_time); 45 virtual status_t AddTimer(bigtime_t at_performance_time, int32 cookie); 46 virtual void SetRunMode(run_mode mode); 47 virtual void HandleEvent(const media_timed_event *event, 48 bigtime_t lateness, bool realTimeEvent = false); 49 virtual void CleanUpEvent(const media_timed_event *event); 50 virtual bigtime_t OfflineTime(); 51 virtual void ControlLoop(); 52 virtual status_t DeleteHook(BMediaNode * node); 53 54 /* BBufferProducer */ 55 protected: 56 virtual status_t FormatSuggestionRequested(media_type type, int32 quality, 57 media_format * format); 58 virtual status_t FormatProposal(const media_source &output, 59 media_format *format); 60 virtual status_t FormatChangeRequested(const media_source &source, 61 const media_destination &destination, 62 media_format *io_format, int32 *_deprecated_); 63 virtual status_t GetNextOutput(int32 * cookie, media_output * out_output); 64 virtual status_t DisposeOutputCookie(int32 cookie); 65 virtual status_t SetBufferGroup(const media_source &for_source, 66 BBufferGroup * group); 67 virtual status_t VideoClippingChanged(const media_source &for_source, 68 int16 num_shorts, int16 *clip_data, 69 const media_video_display_info &display, 70 int32 * _deprecated_); 71 virtual status_t GetLatency(bigtime_t * out_latency); 72 virtual status_t PrepareToConnect(const media_source &what, 73 const media_destination &where, 74 media_format *format, 75 media_source *out_source, char *out_name); 76 virtual void Connect(status_t error, const media_source &source, 77 const media_destination &destination, 78 const media_format & format, char *io_name); 79 virtual void Disconnect(const media_source & what, 80 const media_destination & where); 81 virtual void LateNoticeReceived(const media_source & what, 82 bigtime_t how_much, bigtime_t performance_time); 83 virtual void EnableOutput(const media_source & what, bool enabled, 84 int32 * _deprecated_); 85 virtual status_t SetPlayRate(int32 numer,int32 denom); 86 virtual void AdditionalBufferRequested(const media_source & source, 87 media_buffer_id prev_buffer, bigtime_t prev_time, 88 const media_seek_tag * prev_tag); 89 virtual void LatencyChanged(const media_source & source, 90 const media_destination & destination, 91 bigtime_t new_latency, uint32 flags); 92 93 /* BControllable */ 94 protected: 95 virtual status_t GetParameterValue(int32 id, bigtime_t *last_change, 96 void *value, size_t *size); 97 virtual void SetParameterValue(int32 id, bigtime_t when, 98 const void *value, size_t size); 99 virtual status_t StartControlPanel(BMessenger *out_messenger); 100 101 /* state */ 102 private: 103 void HandleStart(bigtime_t performance_time); 104 void HandleStop(); 105 void HandleTimeWarp(bigtime_t performance_time); 106 void HandleSeek(bigtime_t performance_time); 107 108 static int32 fInstances; 109 110 status_t fInitStatus; 111 112 int32 fInternalID; 113 BMediaAddOn *fAddOn; 114 CamDevice *fCamDevice; 115 116 BLocker fLock; 117 BBufferGroup *fBufferGroup; 118 119 thread_id fThread; 120 sem_id fFrameSync; 121 static int32 _frame_generator_(void *data); 122 int32 FrameGenerator(); 123 124 /* The remaining variables should be declared volatile, but they 125 * are not here to improve the legibility of the sample code. */ 126 uint32 fFrame; 127 uint32 fFrameBase; 128 bigtime_t fPerformanceTimeBase; 129 bigtime_t fProcessingLatency; 130 media_output fOutput; 131 media_raw_video_format fConnectedFormat; 132 bool fRunning; 133 bool fConnected; 134 bool fEnabled; 135 136 enum { P_COLOR }; 137 uint32 fColor; 138 bigtime_t fLastColorChange; 139 }; 140 141 #endif 142