xref: /haiku/headers/os/media/ParameterWeb.h (revision 2ff47e1785c4596d1a85c7d5bb79138f8c816023)
1 /*
2  * Copyright 2009, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT license.
4  */
5 #ifndef _CONTROL_WEB_H
6 #define _CONTROL_WEB_H
7 
8 
9 #include <Flattenable.h>
10 #include <MediaDefs.h>
11 #include <MediaNode.h>
12 #include <TypeConstants.h>
13 
14 
15 // Parameter Kinds
16 
17 extern const char* const B_GENERIC;
18 
19 // slider controls
20 extern const char* const B_MASTER_GAIN;
21 extern const char* const B_GAIN;
22 extern const char* const B_BALANCE;
23 extern const char* const B_FREQUENCY;
24 extern const char* const B_LEVEL;
25 extern const char* const B_SHUTTLE_SPEED;
26 extern const char* const B_CROSSFADE;		// 0-100 (first - second)
27 extern const char* const B_EQUALIZATION;	// dB
28 
29 // compression controls
30 extern const char* const B_COMPRESSION;
31 extern const char* const B_QUALITY;
32 extern const char* const B_BITRATE;			// bits/s
33 extern const char* const B_GOP_SIZE;
34 
35 // selector controls
36 extern const char* const B_MUTE;
37 extern const char* const B_ENABLE;
38 extern const char* const B_INPUT_MUX;
39 extern const char* const B_OUTPUT_MUX;
40 extern const char* const B_TUNER_CHANNEL;
41 extern const char* const B_TRACK;
42 extern const char* const B_RECSTATE;
43 extern const char* const B_SHUTTLE_MODE;
44 extern const char* const B_RESOLUTION;
45 extern const char* const B_COLOR_SPACE;
46 extern const char* const B_FRAME_RATE;
47 extern const char* const B_VIDEO_FORMAT;
48 	// 1 = NTSC-M, 2 = NTSC-J, 3 = PAL-BDGHI, 4 = PAL-M, 5 = PAL-N, 6 = SECAM,
49 	// 7 = MPEG-1, 8 = MPEG-2
50 
51 // junction controls
52 extern const char* const B_WEB_PHYSICAL_INPUT;
53 extern const char* const B_WEB_PHYSICAL_OUTPUT;
54 extern const char* const B_WEB_ADC_CONVERTER;
55 extern const char* const B_WEB_DAC_CONVERTER;
56 extern const char* const B_WEB_LOGICAL_INPUT;
57 extern const char* const B_WEB_LOGICAL_OUTPUT;
58 extern const char* const B_WEB_LOGICAL_BUS;
59 extern const char* const B_WEB_BUFFER_INPUT;
60 extern const char* const B_WEB_BUFFER_OUTPUT;
61 
62 // transport control
63 extern const char* const B_SIMPLE_TRANSPORT;
64 	// 0-4: rewind, stop, play, pause, fast-forward
65 
66 class BContinuousParameter;
67 class BDiscreteParameter;
68 class BList;
69 class BNullParameter;
70 class BParameter;
71 class BParameterGroup;
72 class BTextParameter;
73 
74 // Parameter flags for influencing Media Themes
75 enum media_parameter_flags {
76 	B_HIDDEN_PARAMETER		= 1,
77 	B_ADVANCED_PARAMETER	= 2
78 };
79 
80 class BParameterWeb : public BFlattenable {
81 public:
82 								BParameterWeb();
83 								~BParameterWeb();
84 
85 			media_node			Node();
86 
87 			BParameterGroup*	MakeGroup(const char* name);
88 			int32				CountGroups();
89 			BParameterGroup*	GroupAt(int32 index);
90 
91 			int32				CountParameters();
92 			BParameter*			ParameterAt(int32 index);
93 
94 	// BFlattenable implementation
95 	virtual	bool				IsFixedSize() const;
96 	virtual type_code			TypeCode() const;
97 	virtual	ssize_t				FlattenedSize() const;
98 	virtual	status_t			Flatten(void* buffer, ssize_t size) const;
99 	virtual	bool				AllowsTypeCode(type_code code) const;
100 	virtual	status_t			Unflatten(type_code code, const void* buffer,
101 									ssize_t size);
102 
103 private:
104 	friend class BParameterGroup;
105 	friend class BControllable;
106 
107 								BParameterWeb(const BParameterWeb& other);
108 			BParameterWeb&		operator=(const BParameterWeb& other);
109 
110 	// reserved
111 	virtual	status_t			_Reserved_ControlWeb_0(void*);
112 	virtual	status_t			_Reserved_ControlWeb_1(void*);
113 	virtual	status_t			_Reserved_ControlWeb_2(void*);
114 	virtual	status_t			_Reserved_ControlWeb_3(void*);
115 	virtual	status_t			_Reserved_ControlWeb_4(void*);
116 	virtual	status_t			_Reserved_ControlWeb_5(void*);
117 	virtual	status_t			_Reserved_ControlWeb_6(void*);
118 	virtual	status_t			_Reserved_ControlWeb_7(void*);
119 
120 			void				AddRefFix(void* oldItem, void* newItem);
121 
122 private:
123 			BList*				fGroups;
124 			media_node			fNode;
125 			uint32				_reserved[8];
126 			BList*				fOldRefs;
127 			BList*				fNewRefs;
128 };
129 
130 
131 class BParameterGroup : public BFlattenable {
132 private:
133 								BParameterGroup(BParameterWeb* web,
134 									const char* name);
135 	virtual						~BParameterGroup();
136 
137 public:
138 			BParameterWeb*		Web() const;
139 			const char*			Name() const;
140 
141 			void				SetFlags(uint32 flags);
142 			uint32				Flags() const;
143 
144 			BNullParameter*		MakeNullParameter(int32 id, media_type type,
145 									const char* name, const char* kind);
146 			BContinuousParameter* MakeContinuousParameter(int32 id,
147 									media_type type, const char* name,
148 									const char* kind, const char* unit,
149 									float min, float max, float step);
150 			BDiscreteParameter*	MakeDiscreteParameter(int32 id, media_type type,
151 									const char* name, const char* kind);
152 			BTextParameter*		MakeTextParameter(int32 id, media_type type,
153 									const char* name, const char* kind,
154 									size_t maxBytes);
155 
156 			BParameterGroup*	MakeGroup(const char* name);
157 
158 			int32				CountParameters();
159 			BParameter*			ParameterAt(int32 index);
160 
161 			int32				CountGroups();
162 			BParameterGroup*	GroupAt(int32 index);
163 
164 	// BFlattenable implementation
165 	virtual	bool				IsFixedSize() const;
166 	virtual type_code			TypeCode() const;
167 	virtual	ssize_t				FlattenedSize() const;
168 	virtual	status_t			Flatten(void* buffer, ssize_t size) const;
169 	virtual	bool				AllowsTypeCode(type_code code) const;
170 	virtual	status_t			Unflatten(type_code code, const void* buffer,
171 									ssize_t size);
172 
173 private:
174 	friend class BParameterWeb;
175 
176 								BParameterGroup();
177 								BParameterGroup(const BParameterGroup& other);
178 			BParameterGroup&	operator=(const BParameterGroup& other);
179 
180 			BParameter*			MakeControl(int32 type);
181 
182 	// reserved
183 	virtual	status_t			_Reserved_ControlGroup_0(void*);
184 	virtual	status_t			_Reserved_ControlGroup_1(void*);
185 	virtual	status_t			_Reserved_ControlGroup_2(void*);
186 	virtual	status_t			_Reserved_ControlGroup_3(void*);
187 	virtual	status_t			_Reserved_ControlGroup_4(void*);
188 	virtual	status_t			_Reserved_ControlGroup_5(void*);
189 	virtual	status_t			_Reserved_ControlGroup_6(void*);
190 	virtual	status_t			_Reserved_ControlGroup_7(void*);
191 
192 private:
193 			BParameterWeb*		fWeb;
194 			BList*				fControls;
195 			BList*				fGroups;
196 			char*				fName;
197 			uint32				fFlags;
198 			uint32				_reserved[7];
199 };
200 
201 
202 class BParameter : public BFlattenable {
203 public:
204 	enum media_parameter_type {
205 		B_NULL_PARAMETER,
206 		B_DISCRETE_PARAMETER,
207 		B_CONTINUOUS_PARAMETER,
208 		B_TEXT_PARAMETER
209 	};
210 
211 			media_parameter_type Type() const;
212 			BParameterWeb*		Web() const;
213 			BParameterGroup*	Group() const;
214 			const char*			Name() const;
215 			const char*			Kind() const;
216 			const char*			Unit() const;
217 			int32				ID() const;
218 
219 			void				SetFlags(uint32 flags);
220 			uint32				Flags() const;
221 
222 	virtual	type_code			ValueType() = 0;
223 
224 			status_t			GetValue(void* buffer, size_t* _size,
225 									bigtime_t* _when);
226 			status_t			SetValue(const void* buffer, size_t size,
227 									bigtime_t when);
228 
229 			int32				CountChannels();
230 			void				SetChannelCount(int32 count);
231 
232 			media_type			MediaType();
233 			void				SetMediaType(media_type type);
234 
235 			int32				CountInputs();
236 			BParameter*			InputAt(int32 index);
237 			void				AddInput(BParameter* input);
238 
239 			int32				CountOutputs();
240 			BParameter*			OutputAt(int32 index);
241 			void				AddOutput(BParameter* output);
242 
243 	// BFlattenable implementation
244 	virtual	bool				IsFixedSize() const;
245 	virtual type_code			TypeCode() const;
246 	virtual	ssize_t				FlattenedSize() const;
247 	virtual	status_t			Flatten(void* buffer, ssize_t size) const;
248 	virtual	bool				AllowsTypeCode(type_code code) const;
249 	virtual	status_t			Unflatten(type_code code, const void* buffer,
250 									ssize_t size);
251 
252 private:
253 	friend class BNullParameter;
254 	friend class BContinuousParameter;
255 	friend class BDiscreteParameter;
256 	friend class BTextParameter;
257 	friend class BParameterGroup;
258 	friend class BParameterWeb;
259 
260 								BParameter(int32 id, media_type mediaType,
261 									media_parameter_type type,
262 									BParameterWeb* web, const char* name,
263 									const char* kind, const char* unit);
264 								~BParameter();
265 
266 	// reserved
267 	virtual	status_t			_Reserved_Control_0(void*);
268 	virtual	status_t			_Reserved_Control_1(void*);
269 	virtual	status_t			_Reserved_Control_2(void*);
270 	virtual	status_t			_Reserved_Control_3(void*);
271 	virtual	status_t			_Reserved_Control_4(void*);
272 	virtual	status_t			_Reserved_Control_5(void*);
273 	virtual	status_t			_Reserved_Control_6(void*);
274 	virtual	status_t			_Reserved_Control_7(void*);
275 
SwapOnUnflatten()276 			bool				SwapOnUnflatten() { return fSwapDetected; }
277 	virtual	void				FixRefs(BList& old, BList& updated);
278 
279 private:
280 			int32				fID;
281 			media_parameter_type fType;
282 			BParameterWeb*		fWeb;
283 			BParameterGroup*	fGroup;
284 			char*				fName;
285 			char*				fKind;
286 			char*				fUnit;
287 			BList*				fInputs;
288 			BList*				fOutputs;
289 			bool				fSwapDetected;
290 			media_type			fMediaType;
291 			int32				fChannels;
292 			uint32				fFlags;
293 
294 			uint32				_reserved[7];
295 };
296 
297 
298 class BContinuousParameter : public BParameter {
299 public:
300 	enum response {
301 		B_UNKNOWN = 0,
302 		B_LINEAR,
303 		B_POLYNOMIAL,
304 		B_EXPONENTIAL,
305 		B_LOGARITHMIC
306 	};
307 
308 	virtual	type_code			ValueType();
309 
310 			float				MinValue();
311 			float				MaxValue();
312 			float				ValueStep();
313 
314 			void				SetResponse(int response, float factor,
315 									float offset);
316 			void				GetResponse(int* _response, float* factor,
317 									float* offset);
318 
319 	virtual	ssize_t				FlattenedSize() const;
320 	virtual	status_t			Flatten(void* buffer, ssize_t size) const;
321 	virtual	status_t			Unflatten(type_code code, const void* buffer,
322 									ssize_t size);
323 
324 private:
325 	friend class BParameterGroup;
326 
327 								BContinuousParameter(int32 id,
328 									media_type mediaType,
329 									BParameterWeb* web, const char* name,
330 									const char* kind, const char* unit,
331 									float min, float max, float step);
332 								~BContinuousParameter();
333 
334 	// reserved
335 	virtual	status_t			_Reserved_ContinuousParameter_0(void*);
336 	virtual	status_t			_Reserved_ContinuousParameter_1(void*);
337 	virtual	status_t			_Reserved_ContinuousParameter_2(void*);
338 	virtual	status_t			_Reserved_ContinuousParameter_3(void*);
339 	virtual	status_t			_Reserved_ContinuousParameter_4(void*);
340 	virtual	status_t			_Reserved_ContinuousParameter_5(void*);
341 	virtual	status_t			_Reserved_ContinuousParameter_6(void*);
342 	virtual	status_t			_Reserved_ContinuousParameter_7(void*);
343 
344 private:
345 			float				fMinimum;
346 			float				fMaximum;
347 			float				fStepping;
348 			response			fResponse;
349 			float				fFactor;
350 			float				fOffset;
351 
352 			uint32				_reserved[8];
353 };
354 
355 
356 class BDiscreteParameter : public BParameter {
357 public:
358 	virtual	type_code			ValueType();
359 
360 			int32				CountItems();
361 			const char*			ItemNameAt(int32 index);
362 			int32				ItemValueAt(int32 index);
363 			status_t			AddItem(int32 value, const char* name);
364 
365 			status_t			MakeItemsFromInputs();
366 			status_t			MakeItemsFromOutputs();
367 
368 			void				MakeEmpty();
369 
370 	virtual	ssize_t				FlattenedSize() const;
371 	virtual	status_t			Flatten(void* buffer, ssize_t size) const;
372 	virtual	status_t			Unflatten(type_code code, const void* buffer,
373 									ssize_t size);
374 
375 private:
376 	friend class BParameterGroup;
377 
378 								BDiscreteParameter(int32 id,
379 									media_type mediaType,
380 									BParameterWeb* web, const char* name,
381 									const char* kind);
382 								~BDiscreteParameter();
383 
384 	// reserved
385 	virtual	status_t			_Reserved_DiscreteParameter_0(void*);
386 	virtual	status_t			_Reserved_DiscreteParameter_1(void*);
387 	virtual	status_t			_Reserved_DiscreteParameter_2(void*);
388 	virtual	status_t			_Reserved_DiscreteParameter_3(void*);
389 	virtual	status_t			_Reserved_DiscreteParameter_4(void*);
390 	virtual	status_t			_Reserved_DiscreteParameter_5(void*);
391 	virtual	status_t			_Reserved_DiscreteParameter_6(void*);
392 	virtual	status_t			_Reserved_DiscreteParameter_7(void*);
393 
394 private:
395 			BList*				fSelections;
396 			BList*				fValues;
397 
398 			uint32				_reserved[8];
399 };
400 
401 
402 class BTextParameter : public BParameter {
403 public:
404 	virtual	type_code			ValueType();
405 
406 			size_t				MaxBytes() const;
407 
408 	virtual	ssize_t				FlattenedSize() const;
409 	virtual	status_t			Flatten(void* buffer, ssize_t size) const;
410 	virtual	status_t			Unflatten(type_code code, const void* buffer,
411 									ssize_t size);
412 
413 private:
414 	friend class BParameterGroup;
415 
416 								BTextParameter(int32 id,
417 									media_type mediaType,
418 									BParameterWeb* web, const char* name,
419 									const char* kind, size_t maxBytes);
420 								~BTextParameter();
421 
422 	// reserved
423 	virtual	status_t			_Reserved_TextParameter_0(void*);
424 	virtual	status_t			_Reserved_TextParameter_1(void*);
425 	virtual	status_t			_Reserved_TextParameter_2(void*);
426 	virtual	status_t			_Reserved_TextParameter_3(void*);
427 	virtual	status_t			_Reserved_TextParameter_4(void*);
428 	virtual	status_t			_Reserved_TextParameter_5(void*);
429 	virtual	status_t			_Reserved_TextParameter_6(void*);
430 	virtual	status_t			_Reserved_TextParameter_7(void*);
431 
432 private:
433 			uint32				fMaxBytes;
434 
435 			uint32				_reserved[8];
436 };
437 
438 
439 class BNullParameter : public BParameter {
440 public:
441 	virtual	type_code			ValueType();
442 
443 	virtual	ssize_t				FlattenedSize() const;
444 	virtual	status_t			Flatten(void* buffer, ssize_t size) const;
445 	virtual	status_t			Unflatten(type_code code, const void* buffer,
446 									ssize_t size);
447 
448 private:
449 	friend class BParameterGroup;
450 
451 								BNullParameter(int32 id,
452 									media_type mediaType,
453 									BParameterWeb* web, const char* name,
454 									const char* kind);
455 								~BNullParameter();
456 
457 	// reserved
458 	virtual	status_t			_Reserved_NullParameter_0(void*);
459 	virtual	status_t			_Reserved_NullParameter_1(void*);
460 	virtual	status_t			_Reserved_NullParameter_2(void*);
461 	virtual	status_t			_Reserved_NullParameter_3(void*);
462 	virtual	status_t			_Reserved_NullParameter_4(void*);
463 	virtual	status_t			_Reserved_NullParameter_5(void*);
464 	virtual	status_t			_Reserved_NullParameter_6(void*);
465 	virtual	status_t			_Reserved_NullParameter_7(void*);
466 
467 private:
468 			uint32				_reserved[8];
469 };
470 
471 
472 #endif	// _CONTROL_WEB_H
473