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