xref: /haiku/src/add-ons/media/media-add-ons/usb_vision/Producer.h (revision b3d94504c208adafebbf2ba62ae7fc4e0b7d68f7)
1 /*
2  * This file is a part of BeOS USBVision driver project.
3  * Copyright (c) 2003 by Siarzuk Zharski <imker@gmx.li>
4  *
5  * This file may be used under the terms of the BSD License
6  *
7  * Skeletal part of this code was inherired from original BeOS sample code,
8  * that is distributed under the terms of the Be Sample Code License.
9  *
10  */
11 
12 #ifndef _USBVISION_PRODUCER_H
13 #define _USBVISION_PRODUCER_H
14 
15 #include <kernel/OS.h>
16 #include <media/BufferProducer.h>
17 #include <media/Controllable.h>
18 #include <media/MediaDefs.h>
19 #include <media/MediaEventLooper.h>
20 #include <media/MediaNode.h>
21 #include <support/Locker.h>
22 
23 #include "TunerLocale.h"
24 
25 class VideoProducer :
26 	public virtual BMediaEventLooper,
27 	public virtual BBufferProducer,
28 	public virtual BControllable
29 {
30 public:
31 						VideoProducer(BMediaAddOn *addon,
32 								const char *name, int32 internal_id);
33 virtual					~VideoProducer();
34 
InitCheck()35 virtual	status_t		InitCheck() const { return fInitStatus; }
36 
37 /* BMediaNode */
38 public:
39 virtual port_id		ControlPort() const;
40 virtual	BMediaAddOn	*AddOn(int32 * internal_id) const;
41 virtual	status_t 	HandleMessage(int32 message, const void *data,
42 							size_t size);
43 protected:
44 virtual	void 		Preroll();
45 virtual void		SetTimeSource(BTimeSource * time_source);
46 virtual status_t	RequestCompleted(const media_request_info & info);
47 
48 /* BMediaEventLooper */
49 protected:
50 virtual	void 		NodeRegistered();
51 virtual void		Start(bigtime_t performance_time);
52 virtual void		Stop(bigtime_t performance_time, bool immediate);
53 virtual void		Seek(bigtime_t media_time, bigtime_t performance_time);
54 virtual void		TimeWarp(bigtime_t at_real_time,
55 							bigtime_t to_performance_time);
56 virtual status_t	AddTimer(bigtime_t at_performance_time, int32 cookie);
57 virtual void		SetRunMode(run_mode mode);
58 virtual void		HandleEvent(const media_timed_event *event,
59 							bigtime_t lateness, bool realTimeEvent = false);
60 virtual void		CleanUpEvent(const media_timed_event *event);
61 virtual bigtime_t	OfflineTime();
62 virtual void		ControlLoop();
63 virtual status_t	DeleteHook(BMediaNode * node);
64 
65 /* BBufferProducer */
66 protected:
67 virtual	status_t	FormatSuggestionRequested(media_type type, int32 quality,
68 							media_format * format);
69 virtual	status_t 	FormatProposal(const media_source &output,
70 							media_format *format);
71 virtual	status_t	FormatChangeRequested(const media_source &source,
72 							const media_destination &destination,
73 							media_format *io_format, int32 *_deprecated_);
74 virtual	status_t 	GetNextOutput(int32 * cookie, media_output * out_output);
75 virtual	status_t	DisposeOutputCookie(int32 cookie);
76 virtual	status_t	SetBufferGroup(const media_source &for_source,
77 							BBufferGroup * group);
78 virtual	status_t 	VideoClippingChanged(const media_source &for_source,
79 							int16 num_shorts, int16 *clip_data,
80 							const media_video_display_info &display,
81 							int32 * _deprecated_);
82 virtual	status_t	GetLatency(bigtime_t * out_latency);
83 virtual	status_t	PrepareToConnect(const media_source &what,
84 							const media_destination &where,
85 							media_format *format,
86 							media_source *out_source, char *out_name);
87 virtual	void		Connect(status_t error, const media_source &source,
88 							const media_destination &destination,
89 							const media_format & format, char *io_name);
90 virtual	void 		Disconnect(const media_source & what,
91 							const media_destination & where);
92 virtual	void 		LateNoticeReceived(const media_source & what,
93 							bigtime_t how_much, bigtime_t performance_time);
94 virtual	void 		EnableOutput(const media_source & what, bool enabled,
95 							int32 * _deprecated_);
96 virtual	status_t	SetPlayRate(int32 numer,int32 denom);
97 virtual	void 		AdditionalBufferRequested(const media_source & source,
98 							media_buffer_id prev_buffer, bigtime_t prev_time,
99 							const media_seek_tag * prev_tag);
100 virtual	void		LatencyChanged(const media_source & source,
101 							const media_destination & destination,
102 							bigtime_t new_latency, uint32 flags);
103 
104 /* BControllable */
105 protected:
106 virtual status_t	GetParameterValue(int32 id, bigtime_t *last_change,
107 							void *value, size_t *size);
108 virtual void		SetParameterValue(int32 id, bigtime_t when,
109 							const void *value, size_t size);
110 virtual status_t	StartControlPanel(BMessenger *out_messenger);
111 
112 /* state */
113 private:
114 		void				HandleStart(bigtime_t performance_time);
115 		void				HandleStop();
116 		void				HandleTimeWarp(bigtime_t performance_time);
117 		void				HandleSeek(bigtime_t performance_time);
118         void                HandleParameter(uint32 parameter);
119 
120 static	int32				fInstances;
121 
122 		status_t			fInitStatus;
123 
124 		int32				fInternalID;
125 		BMediaAddOn			*fAddOn;
126 
127 		BLocker				fLock;
128 			BBufferGroup	*fBufferGroup;
129 
130 		thread_id			fThread;
131 		sem_id				fFrameSync;
132 static	int32				_frame_generator_(void *data);
133 		int32				FrameGenerator();
134 
135 		/* The remaining variables should be declared volatile, but they
136 		 * are not here to improve the legibility of the sample code. */
137 		uint32				fFrame;
138 		uint32				fFrameBase;
139 		bigtime_t			fPerformanceTimeBase;
140 		bigtime_t			fProcessingLatency;
141 		media_output		fOutput;
142 		media_raw_video_format	fConnectedFormat;
143 		bool				fRunning;
144 		bool				fConnected;
145 		bool				fEnabled;
146 
147 		enum				{ P_CHANNEL,
148 		                      P_VIDEO_INPUT,
149 		                      P_AUDIO_INPUT,
150 		                      P_BRIGHTNESS,
151 		                      P_CONTRAST,
152 		                      P_SATURATION,
153 		                      P_HUE,
154 		                      P_CAPTURE_SIZE,
155 		                      P_CAPTURE_FORMAT,
156 		                      P_STANDART,
157 		                      P_BANDWIDTH,
158 		                      P_LOCALE,
159 		                      P_VERT_OFFSET,
160 		                      P_HORZ_OFFSET,
161 		                      P_COLOR };
162 enum		{ P_VI_TUNER,
163 					  P_VI_COMPOSITE,
164 					  P_VI_SVIDEO};
165 enum	{ P_VF_NTSC_M,
166 					  P_VF_NTSC_MJ,
167 					  P_VF_PAL_BDGHI,
168 					  P_VF_PAL_M,
169 					  P_VF_PAL_N,
170 					  P_VF_SECAM};
171 		BParameterWeb  *CreateParameterWeb();
172 
173 		uint32        fChannel;
174 		bigtime_t     fLastChannelChange;
175 		uint32        fVideoInput;
176 		bigtime_t     fLastVideoInputChange;
177 		uint32        fAudioInput;
178 		bigtime_t     fLastAudioInputChange;
179 		float         fBrightness;
180 		bigtime_t     fLastBrightnessChange;
181 		float         fContrast;
182 		bigtime_t     fLastContrastChange;
183 		float         fSaturation;
184 		bigtime_t     fLastSaturationChange;
185 		float         fHue;
186 		bigtime_t     fLastHueChange;
187 		uint32        fCaptureSize;
188 		bigtime_t     fLastCaptureSizeChange;
189 		uint32        fCaptureFormat;
190 		bigtime_t     fLastCaptureFormatChange;
191 		uint32        fStandard;
192 		bigtime_t     fLastStandardChange;
193 		float         fBandwidth;
194 		bigtime_t     fLastBandwidthChange;
195 		uint32        fLocale;
196 		bigtime_t     fLastLocaleChange;
197 		float         fVertOffset;
198 		bigtime_t     fLastVertOffsetChange;
199 		float         fHorzOffset;
200 		bigtime_t     fLastHorzOffsetChange;
201 
202     uint32				fColor;
203 		bigtime_t			fLastColorChange;
204 
205         Locale::Locales fLocales;
206 };
207 
208 #endif /*_USBVISION_PRODUCER_H*/
209