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