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