xref: /haiku/src/add-ons/media/media-add-ons/radeon/RadeonProducer.h (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1 /******************************************************************************
2 /
3 /	File:			RadeonProducer.h
4 /
5 /	Description:	ATI Radeon Video Producer media node.
6 /
7 /	Copyright 2001, Carlos Hasan
8 /
9 *******************************************************************************/
10 
11 #ifndef __RADEON_PRODUCER_H__
12 #define __RADEON_PRODUCER_H__
13 
14 #include <kernel/OS.h>
15 #include <media/BufferProducer.h>
16 #include <media/Controllable.h>
17 #include <media/MediaDefs.h>
18 #include <media/MediaEventLooper.h>
19 #include <media/MediaNode.h>
20 #include <support/Locker.h>
21 #include "VideoIn.h"
22 
23 class CRadeonAddOn;
24 
25 class CRadeonProducer :
26 	public virtual BMediaEventLooper,
27 	public virtual BBufferProducer,
28 	public virtual BControllable
29 {
30 public:
31 					CRadeonProducer(
32 						CRadeonAddOn *addon, const char *name, const char *device_name,
33 						int32 internal_id, BMessage *config );
34 virtual				~CRadeonProducer();
35 
36 void				setupWeb();
37 virtual	status_t		InitCheck() const { return fInitStatus; }
38 
39 /* BMediaNode */
40 public:
41 virtual port_id		ControlPort() const;
42 virtual	BMediaAddOn	*AddOn(int32 * internal_id) const;
43 virtual	status_t 	HandleMessage(int32 message, const void *data,
44 							size_t size);
45 protected:
46 virtual	void 		Preroll();
47 virtual void		SetTimeSource(BTimeSource * time_source);
48 virtual status_t	RequestCompleted(const media_request_info & info);
49 
50 /* BMediaEventLooper */
51 protected:
52 virtual	void 		NodeRegistered();
53 virtual void		Start(bigtime_t performance_time);
54 virtual void		Stop(bigtime_t performance_time, bool immediate);
55 virtual void		Seek(bigtime_t media_time, bigtime_t performance_time);
56 virtual void		TimeWarp(bigtime_t at_real_time,
57 							bigtime_t to_performance_time);
58 virtual status_t	AddTimer(bigtime_t at_performance_time, int32 cookie);
59 virtual void		SetRunMode(run_mode mode);
60 virtual void		HandleEvent(const media_timed_event *event,
61 							bigtime_t lateness, bool realTimeEvent = false);
62 virtual void		CleanUpEvent(const media_timed_event *event);
63 virtual bigtime_t	OfflineTime();
64 virtual void		ControlLoop();
65 virtual status_t	DeleteHook(BMediaNode * node);
66 
67 /* BBufferProducer */
68 protected:
69 virtual	status_t	FormatSuggestionRequested(media_type type, int32 quality,
70 							media_format * format);
71 virtual	status_t 	FormatProposal(const media_source &output,
72 							media_format *format);
73 virtual	status_t	FormatChangeRequested(const media_source &source,
74 							const media_destination &destination,
75 							media_format *io_format, int32 *_deprecated_);
76 virtual	status_t 	GetNextOutput(int32 * cookie, media_output * out_output);
77 virtual	status_t	DisposeOutputCookie(int32 cookie);
78 virtual	status_t	SetBufferGroup(const media_source &for_source,
79 							BBufferGroup * group);
80 virtual	status_t 	VideoClippingChanged(const media_source &for_source,
81 							int16 num_shorts, int16 *clip_data,
82 							const media_video_display_info &display,
83 							int32 * _deprecated_);
84 virtual	status_t	GetLatency(bigtime_t * out_latency);
85 virtual	status_t	PrepareToConnect(const media_source &what,
86 							const media_destination &where,
87 							media_format *format,
88 							media_source *out_source, char *out_name);
89 virtual	void		Connect(status_t error, const media_source &source,
90 							const media_destination &destination,
91 							const media_format & format, char *io_name);
92 virtual	void 		Disconnect(const media_source & what,
93 							const media_destination & where);
94 virtual	void 		LateNoticeReceived(const media_source & what,
95 							bigtime_t how_much, bigtime_t performance_time);
96 virtual	void 		EnableOutput(const media_source & what, bool enabled,
97 							int32 * _deprecated_);
98 virtual	status_t	SetPlayRate(int32 numer,int32 denom);
99 virtual	void 		AdditionalBufferRequested(const media_source & source,
100 							media_buffer_id prev_buffer, bigtime_t prev_time,
101 							const media_seek_tag * prev_tag);
102 virtual	void		LatencyChanged(const media_source & source,
103 							const media_destination & destination,
104 							bigtime_t new_latency, uint32 flags);
105 
106 /* BControllable */
107 protected:
108 virtual status_t	GetParameterValue(int32 id, bigtime_t *last_change,
109 							void *value, size_t *size);
110 virtual void		SetParameterValue(int32 id, bigtime_t when,
111 							const void *value, size_t size);
112 virtual status_t	StartControlPanel(BMessenger *out_messenger);
113 
114 public:
115 		enum {
116 			C_GET_CONFIGURATION = BTimedEventQueue::B_USER_EVENT,
117 			C_GET_CONFIGURATION_REPLY
118 		};
119 
120 		struct configuration_msg {
121 			port_id reply_port;
122 		};
123 
124 		struct configuration_msg_reply {
125 			status_t 		res;
126 			size_t			config_size;
127 			char			config;
128 		};
129 
130 /* state */
131 private:
132 		void				HandleStart(bigtime_t performance_time);
133 		void				HandleStop();
134 		void				HandleTimeWarp(bigtime_t performance_time);
135 		void				HandleSeek(bigtime_t performance_time);
136 		void				HandleHardware();
137 
138 		// home-brewed extension
139 		status_t			GetConfiguration( BMessage *out );
140 
141 		CVideoIn			fVideoIn;
142 
143 		status_t			fInitStatus;
144 
145 		int32				fInternalID;
146 		CRadeonAddOn		*fAddOn;
147 
148 		BBufferGroup		*fBufferGroup;
149 		//BBufferGroup		*fUsedBufferGroup;
150 
151 static	int32				_frame_generator_(void *data);
152 		int32				FrameGenerator();
153 
154 		/* The remaining variables should be declared volatile, but they
155 		 * are not here to improve the legibility of the sample code. */
156 		//uint32				fFrame;
157 		uint32				fFieldSequenceBase;
158 		//bigtime_t			fPerformanceTimeBase;
159 		bigtime_t			fProcessingLatency;
160 		media_output		fOutput;
161 		//media_raw_video_format	fConnectedFormat;
162 		//bool				fConnected;
163 		bool				fEnabled;
164 
165 		// use fixed names as they are used in settings file
166 		enum EOptions		{
167 			P_SOURCE		= 'VSRC',
168 			P_AUDIO_SOURCE	= 'ASRC',
169 			P_AUDIO_FORMAT	= 'AFMT',
170 			P_VOLUME		= 'VOL ',
171 			P_STANDARD		= 'TVST',
172 			P_MODE			= 'CMOD',
173 			P_FORMAT		= 'VFMT',
174 			P_RESOLUTION	= 'RES ',
175 			P_TUNER			= 'TUNR',
176 			P_BRIGHTNESS	= 'BRGT',
177 			P_CONTRAST		= 'CONT',
178 			P_SATURATION	= 'SATU',
179 			P_HUE			= 'HUE ',
180 			P_SHARPNESS		= 'SHRP'
181 		};
182 
183 		enum { C_RESOLUTION_MAX = 6 };
184 		enum { C_CHANNEL_MAX = 125 };
185 
186 		int32				fSource;
187 		int32				fStandard;
188 		int32				fMode;
189 		int32				fCurMode;	// mode, overwritten by application
190 		int32				fFormat;
191 		int32				fResolution;
192 		int32				fTuner;
193 		int32				fBrightness;
194 		int32				fContrast;
195 		int32				fSaturation;
196 		int32				fHue;
197 		int32				fSharpness;
198 		bigtime_t			fSourceLastChange;
199 		bigtime_t			fStandardLastChange;
200 		bigtime_t			fModeLastChange;
201 		bigtime_t			fFormatLastChange;
202 		bigtime_t			fResolutionLastChange;
203 		bigtime_t			fTunerLastChange;
204 		bigtime_t			fBrightnessLastChange;
205 		bigtime_t			fContrastLastChange;
206 		bigtime_t			fSaturationLastChange;
207 		bigtime_t			fHueLastChange;
208 		bigtime_t			fSharpnessLastChange;
209 
210 		status_t	AddInt32(
211 			BMessage *msg, EOptions option, int32 value );
212 
213 		status_t	FindInt32(
214 			BMessage *config, EOptions option, int32 min_value, int32 max_value,
215 			int32 default_value, int32 *value );
216 
217 	// format negotiation helpers
218 	status_t	verifySetMode( media_format *format );
219 	int32		extractCaptureMode( const media_format *format );
220 	status_t 	verifySetPixelAspect( media_format *format );
221 	status_t 	verifyActiveRange( media_format *format );
222 	void		setActiveRange( media_format *format );
223 	status_t	verifyOrientation( media_format *format );
224 	void		setOrientation( media_format *format );
225 	status_t	verifyPixelFormat( media_format *format );
226 	void		setPixelFormat( media_format *format );
227 	status_t	verifySetSize( media_format *format, int32 mode, bool set_bytes_per_row );
228 	status_t 	verifyFormatOffsets( media_format *format );
229 	void		setFormatOffsets( media_format *format );
230 	status_t	verifyFormatFlags( media_format *format );
231 	void		setFormatFlags( media_format *format );
232 
233 	status_t	finalizeFormat( media_format *format );
234 
235 	void		startCapturing();
236 	void	 	captureField( bigtime_t *capture_time );
237 	void		setDefaultBufferGroup();
238 	void		instantFormatChange( media_format *new_format );
239 };
240 
241 #endif
242