xref: /haiku/headers/os/media/MediaDefs.h (revision 67bce78b48ed6d01b5a8eef89f5694c372b7e0a1)
1 /*******************************************************************************
2 /
3 /	File:			MediaDefs.h
4 /
5 /   Description:   Basic data types and defines for the Media Kit.
6 /
7 /	Copyright 1997-1999, Be Incorporated, All Rights Reserved
8 /
9 *******************************************************************************/
10 
11 #if !defined(_MEDIA_DEFS_H)
12 #define _MEDIA_DEFS_H
13 
14 #include <BeBuild.h>
15 #include <SupportDefs.h>
16 #include <OS.h>
17 #include <ByteOrder.h>
18 
19 #if defined(__cplusplus)
20 #include <GraphicsDefs.h>
21 #include <Looper.h>
22 #endif
23 
24 
25 #define B_MEDIA_NAME_LENGTH 64
26 
27 
28 enum {	/* maybe migrate these into Errors.h */
29 	B_MEDIA_SYSTEM_FAILURE = (int)B_MEDIA_ERROR_BASE+0x100,	/* 80004100 */
30 	B_MEDIA_BAD_NODE,
31 	B_MEDIA_NODE_BUSY,
32 	B_MEDIA_BAD_FORMAT,
33 	B_MEDIA_BAD_BUFFER,
34 	B_MEDIA_TOO_MANY_NODES,
35 	B_MEDIA_TOO_MANY_BUFFERS,
36 	B_MEDIA_NODE_ALREADY_EXISTS,
37 	B_MEDIA_BUFFER_ALREADY_EXISTS,
38 	B_MEDIA_CANNOT_SEEK,
39 	B_MEDIA_CANNOT_CHANGE_RUN_MODE,
40 	B_MEDIA_APP_ALREADY_REGISTERED,
41 	B_MEDIA_APP_NOT_REGISTERED,
42 	B_MEDIA_CANNOT_RECLAIM_BUFFERS,
43 	B_MEDIA_BUFFERS_NOT_RECLAIMED,
44 	B_MEDIA_TIME_SOURCE_STOPPED,
45 	B_MEDIA_TIME_SOURCE_BUSY,					/* 80004110 */
46 	B_MEDIA_BAD_SOURCE,
47 	B_MEDIA_BAD_DESTINATION,
48 	B_MEDIA_ALREADY_CONNECTED,
49 	B_MEDIA_NOT_CONNECTED,
50 	B_MEDIA_BAD_CLIP_FORMAT,
51 	B_MEDIA_ADDON_FAILED,
52 	B_MEDIA_ADDON_DISABLED,
53 	B_MEDIA_CHANGE_IN_PROGRESS,
54 	B_MEDIA_STALE_CHANGE_COUNT,
55 	B_MEDIA_ADDON_RESTRICTED,
56 	B_MEDIA_NO_HANDLER,
57 	B_MEDIA_DUPLICATE_FORMAT,
58 	B_MEDIA_REALTIME_DISABLED,
59 	B_MEDIA_REALTIME_UNAVAILABLE
60 };
61 
62 /* Notification message 'what's */
63 enum {
64 	// Note that BMediaNode::node_error also belongs in here! */
65 	B_MEDIA_WILDCARD = 'TRWC',		/* used to match any notification in Start/StopWatching */
66 	B_MEDIA_NODE_CREATED = 'TRIA',	/* "media_node_id" (multiple items) */
67 	B_MEDIA_NODE_DELETED,			/* "media_node_id" (multiple items) */
68 	B_MEDIA_CONNECTION_MADE,		/* "output", "input", "format" */
69 	B_MEDIA_CONNECTION_BROKEN,		/* "source", "destination" */
70 	B_MEDIA_BUFFER_CREATED,			/* "clone_info" -- handled by BMediaRoster */
71 	B_MEDIA_BUFFER_DELETED,			/* "media_buffer_id" -- handled by BMediaRoster */
72 	B_MEDIA_TRANSPORT_STATE,		/* "state", "location", "realtime" */
73 	B_MEDIA_PARAMETER_CHANGED,		/* N "node", "parameter" */
74 	B_MEDIA_FORMAT_CHANGED,			/* N "source", "destination", "format" */
75 	B_MEDIA_WEB_CHANGED,			/* N "node" */
76 	B_MEDIA_DEFAULT_CHANGED,		/* "default", "node" -- handled by BMediaRoster */
77 	B_MEDIA_NEW_PARAMETER_VALUE,	/* N "node", "parameter", "when", "value" */
78 	B_MEDIA_NODE_STOPPED,			/* N "node", "when" */
79 	B_MEDIA_FLAVORS_CHANGED			/* "be:addon_id", "be:new_count", "be:gone_count" */
80 };
81 
82 enum media_type {
83 	B_MEDIA_NO_TYPE = -1,
84 	B_MEDIA_UNKNOWN_TYPE = 0,
85 	B_MEDIA_RAW_AUDIO = 1,			/* uncompressed raw_audio -- linear relationship bytes <-> samples */
86 	B_MEDIA_RAW_VIDEO,				/* uncompressed raw_video -- linear relationship bytes <-> pixels */
87 	B_MEDIA_VBL,					/* raw data from VBL area, 1600/line */
88 	B_MEDIA_TIMECODE,				/* data format TBD */
89 	B_MEDIA_MIDI,
90 	B_MEDIA_TEXT,					/* typically closed captioning */
91 	B_MEDIA_HTML,
92 	B_MEDIA_MULTISTREAM,			/* AVI, etc */
93 	B_MEDIA_PARAMETERS,				/* BControllable change data */
94 	B_MEDIA_ENCODED_AUDIO,			/* dts, AC3, ... */
95 	B_MEDIA_ENCODED_VIDEO,			/* Indeo, MPEG, ... */
96 	B_MEDIA_PRIVATE = 90000,		/* Don't touch! */
97 	B_MEDIA_FIRST_USER_TYPE = 100000	/* Use something bigger than this for */
98 										/* experimentation with your own media forms */
99 };
100 
101 enum node_kind {
102 	B_BUFFER_PRODUCER = 0x1,
103 	B_BUFFER_CONSUMER = 0x2,
104 	B_TIME_SOURCE = 0x4,
105 	B_CONTROLLABLE = 0x8,
106 	B_FILE_INTERFACE = 0x10,
107 	B_ENTITY_INTERFACE = 0x20,
108 	/* Set these flags for nodes that are suitable as default entities */
109 	B_PHYSICAL_INPUT = 0x10000,
110 	B_PHYSICAL_OUTPUT = 0x20000,
111 	B_SYSTEM_MIXER = 0x40000
112 };
113 
114 enum video_orientation {	/* for orientation, which pixel is first and how do we scan each "line"? */
115 	B_VIDEO_TOP_LEFT_RIGHT = 1,		/* This is the typical progressive scan format */
116 	B_VIDEO_BOTTOM_LEFT_RIGHT		/* This is how BMP and TGA might scan */
117 };
118 
119 
120 enum media_flags			/* data */
121 {
122 	B_MEDIA_FLAGS_VERSION = 1,			/* uint32, bigger for newer */
123 	B_MEDIA_FLAGS_PRIVATE = 0x40000000	/* private to Be */
124 };
125 
126 
127 enum media_producer_status {	/* for producer status */
128 	B_DATA_NOT_AVAILABLE = 1,
129 	B_DATA_AVAILABLE = 2,
130 	B_PRODUCER_STOPPED = 3
131 };
132 
133 //	realtime flags
134 enum media_realtime_flags {
135 	B_MEDIA_REALTIME_ALLOCATOR = 0x1,
136 	B_MEDIA_REALTIME_AUDIO = 0x2,
137 	B_MEDIA_REALTIME_VIDEO = 0x4,
138 	B_MEDIA_REALTIME_ANYKIND = 0xffff
139 };
140 
141 enum media_frame_flags {
142 	B_MEDIA_KEY_FRAME = 0x1
143 };
144 
145 #define B_MEDIA_ANY_QUALITY 0.0f
146 #define B_MEDIA_LOW_QUALITY 0.1f
147 #define B_MEDIA_MEDIUM_QUALITY 0.5f
148 #define B_MEDIA_HIGH_QUALITY 1.0f
149 
150 
151 #if !defined(_MULTI_AUDIO_H)	/* #define in protocol header */
152 enum media_multi_channels {
153 	B_CHANNEL_LEFT = 0x1,
154 	B_CHANNEL_RIGHT = 0x2,
155 	B_CHANNEL_CENTER = 0x4,				/* 5.1+ or fake surround */
156 	B_CHANNEL_SUB = 0x8,				/* 5.1+ */
157 	B_CHANNEL_REARLEFT = 0x10,			/* quad surround or 5.1+ */
158 	B_CHANNEL_REARRIGHT = 0x20,			/* quad surround or 5.1+ */
159 	B_CHANNEL_FRONT_LEFT_CENTER = 0x40,
160 	B_CHANNEL_FRONT_RIGHT_CENTER = 0x80,
161 	B_CHANNEL_BACK_CENTER = 0x100,		/* 6.1 or fake surround */
162 	B_CHANNEL_SIDE_LEFT = 0x200,
163 	B_CHANNEL_SIDE_RIGHT = 0x400,
164 	B_CHANNEL_TOP_CENTER = 0x800,
165 	B_CHANNEL_TOP_FRONT_LEFT = 0x1000,
166 	B_CHANNEL_TOP_FRONT_CENTER = 0x2000,
167 	B_CHANNEL_TOP_FRONT_RIGHT = 0x4000,
168 	B_CHANNEL_TOP_BACK_LEFT = 0x8000,
169 	B_CHANNEL_TOP_BACK_CENTER = 0x10000,
170 	B_CHANNEL_TOP_BACK_RIGHT = 0x20000
171 };
172 enum media_multi_matrix {
173 	B_MATRIX_PROLOGIC_LR = 0x1,
174 	B_MATRIX_AMBISONIC_WXYZ = 0x4
175 };
176 #endif
177 
178 
179 typedef int32 media_node_id;
180 typedef int32 media_buffer_id;
181 typedef int32 media_addon_id;
182 
183 
184 #if defined(__cplusplus)
185 struct media_destination {
186 	media_destination(port_id, int32);
187 	media_destination(const media_destination & clone);
188 	media_destination & operator=(const media_destination & clone);
189 	media_destination();
190 	~media_destination();
191 	port_id port;	/* can be different from media_node.port */
192 	int32 id;
193 static media_destination null;
194 private:
195 	uint32 _reserved_media_destination_[2];
196 };
197 
198 struct media_source {
199 	media_source(port_id, int32);
200 	media_source(const media_source & clone);
201 	media_source & operator=(const media_source & clone);
202 	media_source();
203 	~media_source();
204 	port_id port;	/* must be the same as media_node.port	for owner */
205 	int32 id;
206 static media_source null;
207 private:
208 	uint32 _reserved_media_source_[2];
209 };
210 
211 _IMPEXP_MEDIA bool operator==(const media_destination & a, const media_destination & b);
212 _IMPEXP_MEDIA bool operator!=(const media_destination & a, const media_destination & b);
213 _IMPEXP_MEDIA bool operator<(const media_destination & a, const media_destination & b);
214 _IMPEXP_MEDIA bool operator==(const media_source & a, const media_source & b);
215 _IMPEXP_MEDIA bool operator!=(const media_source & a, const media_source & b);
216 _IMPEXP_MEDIA bool operator<(const media_source & a, const media_source & b);
217 _IMPEXP_MEDIA bool operator==(const media_node & a, const media_node & b);
218 _IMPEXP_MEDIA bool operator!=(const media_node & a, const media_node & b);
219 _IMPEXP_MEDIA bool operator<(const media_node & a, const media_node & b);
220 
221 
222 
223 /* Buffers are low-level constructs identified by an ID. */
224 /* Buffers consist of the actual data area, plus a 64-byte */
225 /* header area that is different for each type. */
226 /* Buffers contain typed data. Type is not part of the */
227 /* buffer header; it's negotiated out-of-bounds by nodes. */
228 
229 enum {
230 	B_MEDIA_BIG_ENDIAN = 1,
231 	B_MEDIA_LITTLE_ENDIAN = 2,
232 #if B_HOST_IS_BENDIAN
233 	B_MEDIA_HOST_ENDIAN = B_MEDIA_BIG_ENDIAN
234 #else
235 	B_MEDIA_HOST_ENDIAN = B_MEDIA_LITTLE_ENDIAN
236 #endif
237 };
238 
239 struct media_multi_audio_format;
240 
241 struct media_raw_audio_format {
242 	enum {						// for "format"
243 		B_AUDIO_FLOAT = 0x24,	// 0 == mid, -1.0 == bottom, 1.0 == top (the preferred format for non-game audio)
244 		B_AUDIO_INT = 0x4,		// 0 == mid, 0x80000001 == bottom, 0x7fffffff == top (all >16-bit formats, left-adjusted)
245 		B_AUDIO_SHORT = 0x2,	// 0 == mid, -32767 == bottom, +32767 == top
246 		B_AUDIO_UCHAR = 0x11,	// 128 == mid, 1 == bottom, 255 == top (discouraged but supported format)
247 		B_AUDIO_CHAR = 0x1,		// 0 == mid, -127 == bottom, +127 == top (not officially supported format)
248 		B_AUDIO_SIZE_MASK = 0xf
249 	};							// we guarantee that (format&0xf) == sizeof(sample) for raw formats
250 
251 	float		frame_rate;
252 	uint32		channel_count;		// 1 or 2, mostly
253 	uint32		format;				// for compressed formats, go to media_encoded_audio_format
254 	uint32		byte_order;			// 2 for little endian (B_MEDIA_LITTLE_ENDIAN), 1 for big endian (B_MEDIA_BIG_ENDIAN)
255 	size_t		buffer_size;		// size of each buffer
256 
257 static media_multi_audio_format wildcard;
258 };
259 
260 struct media_audio_header {
261 	// please put actual data at the end
262 	int32		_reserved_[16];		// gotta have something
263 };
264 
265 struct media_multi_audio_info {
266 	uint32		channel_mask;		//	bitmask
267 	int16		valid_bits;			//	if < 32, for B_AUDIO_INT
268 	uint16		matrix_mask;		//	each of these bits may mean more than one channel
269 
270 	uint32		_reserved_b[3];
271 };
272 
273 #if defined(__cplusplus)
274 struct media_multi_audio_format : public media_raw_audio_format, public media_multi_audio_info {
275 static media_multi_audio_format wildcard;
276 };
277 #else
278 struct media_multi_audio_format {
279 	media_raw_audio_format	raw;
280 	media_multi_audio_info	multi;
281 };
282 #endif
283 
284 
285 struct media_encoded_audio_format {
286 	enum audio_encoding {
287 		B_ANY
288 	};
289 	media_raw_audio_format	output;
290 	audio_encoding			encoding;
291 
292 	float					bit_rate;		// BIT rate, not byte rate
293 	size_t					frame_size;
294 
295 	media_multi_audio_info	multi_info;
296 
297 	uint32					_reserved_[3];
298 
299 static media_encoded_audio_format wildcard;
300 };
301 
302 struct media_encoded_audio_header {
303 	// please put actual data at the end
304 	int32		_reserved_0[14];	// gotta have something
305 	uint32		buffer_flags;		// B_MEDIA_KEY_FRAME for key buffers (ADPCM etc)
306 	uchar		unused_mask;		// mask of unused bits for the last byte of data
307 	uchar		_reserved_2[3];
308 
309 };
310 
311 enum media_display_flags {
312 	B_F1_DOMINANT = 0x1,		// The first buffer sent (temporally) will be an F1 field
313 	B_F2_DOMINANT = 0x2,		// The first buffer sent (temporally) will be an F2 field
314 	B_TOP_SCANLINE_F1 = 0x4,	// The topmost scanline of the output buffer belongs to F1
315 	B_TOP_SCANLINE_F2 = 0x8		// The topmost scanline of the output buffer belongs to F2
316 };
317 struct media_video_display_info {
318 	color_space	format;
319 	uint32		line_width;
320 	uint32		line_count;		// total of all interlace fields
321 	uint32		bytes_per_row;	// bytes_per_row is in format, not header, because it's part of SetBuffers
322 	uint32		pixel_offset;	// (in pixels) ... These are offsets from the start of the buffer ...
323 	uint32		line_offset;	// (in lines) ... to the start of the field. Think "buffer == framebuffer" ...
324 								// ... when the window displaying the active field moves on screen.
325 	uint32		flags;
326 	uint32		_reserved_[3];
327 static media_video_display_info wildcard;
328 };
329 
330 struct media_raw_video_format {
331 	float		field_rate;
332 	uint32		interlace;		// how many fields per frame -- 1 means progressive (non-interlaced)
333 	uint32		first_active;	// 0, typically (wildcard, or "don't care")
334 	uint32		last_active;	// line_count-1, if first_active is 0.
335 	uint32		orientation;	// B_VIDEO_TOP_LEFT_RIGHT is preferred
336 	// PIXEL aspect ratio; not active area aspect ratio...
337 	uint16		pixel_width_aspect;		// 1:1 has 1 here, 4:3 has 4 here
338 	uint16		pixel_height_aspect;	// 1:1 has 1 here, 4:3 has 3 here
339 
340 	media_video_display_info	display;
341 
342 static media_raw_video_format wildcard;
343 };
344 
345 struct media_video_header {
346 	uint32		_reserved_[12];		// at the top to push used data to the end
347 	float		field_gamma;
348 	uint32		field_sequence;		// sequence since start of capture -- may roll over if machine is on for a LONG time
349 	uint16		field_number;		// 0 .. {interlace-1}; F1 == 0 ("odd"), F2 == 1 ("even")
350 	uint16		pulldown_number;	// 0..2 for pulldown duplicated sequence
351 	uint16		first_active_line;	// the NTSC/PAL line number (1-based) of the first line in this field
352 	uint16		line_count;			// number of active lines in buffer
353 };
354 
355 struct media_encoded_video_format {
356 	enum video_encoding {
357 		B_ANY
358 	};
359 	media_raw_video_format	output;				// set unknowns to wildcard
360 	float					avg_bit_rate;
361 	float					max_bit_rate;
362 	video_encoding			encoding;
363 	size_t					frame_size;
364 	int16					forward_history;	//	maximum forward memory required by algorithm
365 	int16					backward_history;	//	maximum backward memory required by algorithm
366 
367 	uint32					_reserved_[3];		//	can't grow more than this
368 
369 static media_encoded_video_format wildcard;
370 };
371 
372 struct media_encoded_video_header {
373 	/* please put actual data at the end */
374 	int32		_reserved_1[9];		// gotta have something...
375 
376 	uint32		field_flags;		//	B_MEDIA_KEY_FRAME
377 
378 	int16		forward_history;	// forward memory required by this buffer (0 for key frames)
379 	int16		backward_history;	// backward memory required by this buffer (0 for key frames)
380 	uchar		unused_mask;		// mask of unused bits for the last byte of data
381 	uchar		_reserved_2[3];
382 	float		field_gamma;
383 	uint32		field_sequence;		// sequence since start of capture
384 	uint16		field_number;		// 0 .. {interlace-1};  F1 == 0, F2 == 1
385 	uint16		pulldown_number;	// 0..2 for pulldown duplicated sequence
386 	uint16		first_active_line;	// 0 or 1, typically, but could be 10 or 11 for full-NTSC formats
387 	uint16		line_count;			// number of actual lines in buffer
388 };
389 
390 struct media_multistream_format {
391 	enum {
392 		B_ANY = 0,
393 		B_VID = 1,					// raw raw_video/raw_audio buffers
394 		B_AVI,
395 		B_MPEG1,
396 		B_MPEG2,
397 		B_QUICKTIME,
398 		B_PRIVATE = 90000,
399 		B_FIRST_USER_TYPE = 100000	// user formats >= 100000
400 	};
401 	float		avg_bit_rate;		// 8 * byte rate, on average
402 	float		max_bit_rate;		// 8 * byte rate, tops
403 	uint32		avg_chunk_size;		// == max_chunk_size for fixed-size chunks
404 	uint32		max_chunk_size;		// max buffer size
405 	enum {
406 		B_HEADER_HAS_FLAGS = 0x1,	// are flags important?
407 		B_CLEAN_BUFFERS = 0x2,		// each buffer represents an integral number of "frames"
408 		B_HOMOGENOUS_BUFFERS = 0x4	// a buffer has only one format in it
409 	};
410 	uint32		flags;
411 	int32		format;
412 	uint32		_reserved_[2];
413 
414 	struct vid_info {
415 		float frame_rate;
416 		uint16 width;
417 		uint16 height;
418 		color_space space;
419 
420 		float sampling_rate;
421 		uint32 sample_format;
422 		uint16 byte_order;
423 		uint16 channel_count;
424 	};
425 	struct avi_info {
426 		uint32 us_per_frame;
427 		uint16 width;
428 		uint16 height;
429 		uint16 _reserved_;
430 		uint16 type_count;
431 		media_type types[5];
432 	};
433 
434 	union {
435 		vid_info	vid;
436 		avi_info	avi;
437 	}			u;
438 
439 static media_multistream_format wildcard;
440 };
441 
442 struct media_multistream_header {
443 	uint32 _reserved_[14];
444 	uchar	unused_mask;			// mask of unused bits for the last byte of data
445 	uchar	_reserved_2[3];
446 	enum {
447 		B_MASTER_HEADER = 0x1,		// for master stream header data in buffer
448 		B_SUBSTREAM_HEADER = 0x2,	// for sub-stream header data in buffer
449 		B_COMPLETE_BUFFER = 0x4		// data is an integral number of "frames"
450 	};
451 	uint32 	flags;
452 };
453 
454 extern const type_code B_CODEC_TYPE_INFO;
455 
456 enum media_format_flags {
457 	B_MEDIA_RETAINED_DATA = 0x1,
458 	B_MEDIA_MULTIPLE_BUFFERS = 0x2,
459 	B_MEDIA_CONTIGUOUS_BUFFER = 0x4,
460 	B_MEDIA_LINEAR_UPDATES = 0x8,
461 	B_MEDIA_MAUI_UNDEFINED_FLAGS = ~0xf /* always deny these */
462 };
463 
464 /* typically, a field of 0 means "anything" or "wildcard" */
465 struct media_format {	/* no more than 192 bytes */
466 	media_type						type;
467 	type_code						user_data_type;
468 	uchar							user_data[48];
469 	uint32							_reserved_[3];
470 	uint16							require_flags;			//	media_format_flags
471 	uint16							deny_flags;				//	media_format_flags
472 
473 	private:
474 
475 	void *							meta_data;
476 	int32							meta_data_size;
477 	area_id							meta_data_area;
478 	area_id							use_area;
479 	team_id							team;
480 	void *							thisPtr;
481 
482 	public:
483 
484 	union {
485 		media_multi_audio_format	raw_audio;
486 		media_raw_video_format		raw_video;
487 		media_multistream_format	multistream;
488 		media_encoded_audio_format	encoded_audio;
489 		media_encoded_video_format	encoded_video;
490 		char						_reserved_[96];	 // pad to 96 bytes
491 	} u;
492 
493 	bool 			IsVideo() const		{ return (type==B_MEDIA_ENCODED_VIDEO)||(type==B_MEDIA_RAW_VIDEO); };
494 	uint32  		Width() const		{ return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.line_width:u.raw_video.display.line_width; };
495 	uint32 			Height() const		{ return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.line_count:u.raw_video.display.line_count; };
496 	color_space  	ColorSpace() const	{ return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.format:u.raw_video.display.format; };
497 	uint32 & 		Width()				{ return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.line_width:u.raw_video.display.line_width; };
498 	uint32 & 		Height()			{ return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.line_count:u.raw_video.display.line_count; };
499 	color_space & 	ColorSpace()		{ return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.output.display.format:u.raw_video.display.format; };
500 
501 	bool 			IsAudio() const		{ return (type==B_MEDIA_ENCODED_AUDIO)||(type==B_MEDIA_RAW_AUDIO); };
502 	uint32 			AudioFormat() const	{ return (type==B_MEDIA_ENCODED_AUDIO)?u.encoded_audio.output.format:u.raw_audio.format; };
503 	uint32 & 		AudioFormat()		{ return (type==B_MEDIA_ENCODED_AUDIO)?u.encoded_audio.output.format:u.raw_audio.format; };
504 	uint32 			AudioFrameSize() const	{ return (type==B_MEDIA_ENCODED_AUDIO)?(u.encoded_audio.output.format & 0xf)*u.encoded_audio.output.channel_count:(u.raw_audio.format & 0xf)*u.raw_audio.channel_count; };
505 
506 	uint32			Encoding() const	{ return (type==B_MEDIA_ENCODED_VIDEO)?u.encoded_video.encoding:(type==B_MEDIA_ENCODED_AUDIO)?u.encoded_audio.encoding:(type==B_MEDIA_MULTISTREAM)?u.multistream.format:0UL; }
507 
508 	bool			Matches(const media_format *otherFormat) const;
509 	void			SpecializeTo(const media_format *otherFormat);
510 
511 	status_t		SetMetaData(const void *data, size_t size);
512 	const void *	MetaData() const;
513 	int32			MetaDataSize() const;
514 
515 					media_format();
516 					media_format(const media_format &other);
517 					~media_format();
518 	media_format &	operator=(const media_format & clone);
519 };
520 
521 _IMPEXP_MEDIA bool operator==(const media_raw_audio_format & a, const media_raw_audio_format & b);
522 _IMPEXP_MEDIA bool operator==(const media_multi_audio_info & a, const media_multi_audio_info & b);
523 _IMPEXP_MEDIA bool operator==(const media_multi_audio_format & a, const media_multi_audio_format & b);
524 _IMPEXP_MEDIA bool operator==(const media_encoded_audio_format & a, const media_encoded_audio_format & b);
525 _IMPEXP_MEDIA bool operator==(const media_video_display_info & a, const media_video_display_info & b);
526 _IMPEXP_MEDIA bool operator==(const media_raw_video_format & a, const media_raw_video_format & b);
527 _IMPEXP_MEDIA bool operator==(const media_encoded_video_format & a, const media_encoded_video_format & b);
528 _IMPEXP_MEDIA bool operator==(const media_multistream_format::vid_info & a, const media_multistream_format::vid_info & b);
529 _IMPEXP_MEDIA bool operator==(const media_multistream_format::avi_info & a, const media_multistream_format::avi_info & b);
530 _IMPEXP_MEDIA bool operator==(const media_multistream_format & a, const media_multistream_format & b);
531 _IMPEXP_MEDIA bool operator==(const media_format & a, const media_format & b);
532 
533 /* return true if a and b are compatible (accounting for wildcards) */
534 _IMPEXP_MEDIA bool format_is_compatible(const media_format & a, const media_format & b);	/* a is the format you want to feed to something accepting b */
535 _IMPEXP_MEDIA bool string_for_format(const media_format & f, char * buf, size_t size);
536 
537 struct media_seek_tag {
538 	char data[16];
539 };
540 
541 struct media_header_time_code {
542 	int8	type;		//	See TimeCode.h; don't use the "DEFAULT" value
543 	int8	_reserved;
544 	int8	hours;
545 	int8	minutes;
546 	int8	seconds;
547 	int8	frames;
548 	int16	subframes;	//	-1 if not available
549 };
550 
551 struct media_header {		// Broadcast() fills in fields marked with "//+"
552 	media_type		type;			// what kind of data (for union)
553 	media_buffer_id buffer;			//+ what buffer does this header go with?
554 	int32			destination;	//+ what 'socket' is this intended for?
555 	media_node_id	time_source;	// node that encoded start_time
556 	uint32			_deprecated_;	// used to be change_tag
557 	uint32			size_used;		// size within buffer that is used
558 	bigtime_t		start_time;		// performance time
559 	area_id			owner;			//+ buffer owner info area
560 	enum {
561 		B_SEEK_TAG = 'TRST',			// user data type of the codec seek
562 									// protocol. size of seek tag is 16 bytes
563 		B_TIME_CODE = 'TRTC'			//	user data is media_header_time_code
564 	};
565 	type_code		user_data_type;
566 	uchar			user_data[64];	// user_data_type indicates what this is
567 	uint32			_reserved_[2];
568 
569 	off_t			file_pos;		// where in a file this data came from
570 	size_t			orig_size;		// and how big it was.  if unused, zero out
571 
572 	uint32			data_offset;	// offset within buffer (already reflected in Data())
573 
574 	union {
575 		media_audio_header			raw_audio;
576 		media_video_header			raw_video;
577 		media_multistream_header	multistream;
578 		media_encoded_audio_header	encoded_audio;
579 		media_encoded_video_header	encoded_video;
580 		char						_reserved_[64];		// pad to 64 bytes
581 	} u;
582 };
583 
584 
585 struct media_file_format_id {
586 	ino_t	node;
587 	dev_t	device;
588 	uint32	internal_id;
589 };
590 _IMPEXP_MEDIA bool operator==(const media_file_format_id & a, const media_file_format_id & b);
591 _IMPEXP_MEDIA bool operator<(const media_file_format_id & a, const media_file_format_id & b);
592 
593 typedef enum {
594 	B_ANY_FORMAT_FAMILY = 0,
595 	B_BEOS_FORMAT_FAMILY = 1,
596 	B_QUICKTIME_FORMAT_FAMILY = 2,	/* QuickTime is a registered trademark of Apple Computer */
597 	B_AVI_FORMAT_FAMILY = 3,
598 	B_ASF_FORMAT_FAMILY = 4,
599 	B_MPEG_FORMAT_FAMILY = 5,
600 	B_WAV_FORMAT_FAMILY = 6,
601 	B_AIFF_FORMAT_FAMILY = 7,
602 	B_AVR_FORMAT_FAMILY = 8,
603 	B_MISC_FORMAT_FAMILY = 99999,
604 } media_format_family;
605 
606 struct media_file_format {
607 		enum {	/* flags */
608 			B_READABLE = 0x1,
609 			B_WRITABLE = 0x2,
610 			B_PERFECTLY_SEEKABLE = 0x4,
611 			B_IMPERFECTLY_SEEKABLE = 0x8,
612 			B_KNOWS_RAW_VIDEO = 0x10,
613 			B_KNOWS_RAW_AUDIO = 0x20,
614 			B_KNOWS_MIDI = 0x40,
615 			B_KNOWS_ENCODED_VIDEO = 0x80,
616 			B_KNOWS_ENCODED_AUDIO = 0x100,
617 			B_KNOWS_OTHER = 0x1000000,	/* clipping, text, control, ... */
618 			B_KNOWS_ANYTHING = 0x2000000
619 		};
620 	uint32	capabilities;			// can this format support audio, video, etc
621 	media_file_format_id	id;		// opaque id used to construct a BMediaFile
622 	media_format_family family;		// one of the family enums
623 	int32	version;				// 100 for 1.0
624 
625 	uint32		_reserved_[25];
626 
627 	char	mime_type[64];			// eg: "video/quicktime", "audio/aiff", etc
628 	char	pretty_name[64];		// eg: "QuickTime File Format"
629 	char	short_name[32];			// eg: "quicktime", "avi", "mpeg"
630 	char	file_extension[8];		// eg: "mov", "avi", "mpg"
631 	char	reserved[88];
632 };
633 
634 
635 //
636 // Use this function iterate through available file format writers
637 //
638 status_t get_next_file_format(int32 *cookie, media_file_format *mfi);
639 
640 
641 
642 /* This struct is guaranteed to be large enough for any message your service */
643 /* thread will get for any media_node -- 16k is an upper-bound size limit. */
644 /* In your thread, read_port() into this struct, and call HandleMessage() on it. */
645 const size_t B_MEDIA_MESSAGE_SIZE = 16384;
646 
647 _IMPEXP_MEDIA extern const char * B_MEDIA_SERVER_SIGNATURE;
648 
649 class media_node;	/* found in MediaNode.h */
650 struct media_input;
651 struct media_output;
652 struct live_node_info;
653 struct dormant_node_info;
654 struct buffer_clone_info;
655 
656 
657 //	If you for some reason need to get rid of the media_server (and friends)
658 //	use these functions, rather than sending messages yourself.
659 //	The callback will be called for various stages of the process, with 100 meaning completely done
660 //	The callback should always return TRUE for the time being.
661 status_t shutdown_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT, bool (*progress)(int stage, const char * message, void * cookie) = NULL, void * cookie = NULL);
662 status_t launch_media_server(uint32 flags = 0);
663 
664 //	Given an image_id, prepare that image_id for realtime media
665 //	If the kind of media indicated by "flags" is not enabled for real-time,
666 //	B_MEDIA_REALTIME_DISABLED is returned.
667 //	If there are not enough system resources to enable real-time performance,
668 //	B_MEDIA_REALTIME_UNAVAILABLE is returned.
669 status_t media_realtime_init_image(image_id image, uint32 flags);
670 
671 //	Given a thread ID, and an optional indication of what the thread is
672 //	doing in "flags", prepare the thread for real-time media performance.
673 //	Currently, this means locking the thread stack, up to size_used bytes,
674 //	or all of it if 0 is passed. Typically, you will not be using all
675 //	256 kB of the stack, so you should pass some smaller value you determine
676 //	from profiling the thread; typically in the 32-64kB range.
677 //	Return values are the same as for media_prepare_realtime_image().
678 status_t media_realtime_init_thread(thread_id thread, size_t stack_used, uint32 flags);
679 
680 //	A teeny bit of legacy preserved for BSoundFile from R3.
681 //	These came from the old MediaDefs.h; don't use them
682 //	unless you get them from BSoundFile.
683 
684 /* values for byte_ordering */
685 enum { B_BIG_ENDIAN, B_LITTLE_ENDIAN };
686 
687 /* values for sample_format */
688 enum {
689   B_UNDEFINED_SAMPLES,
690   B_LINEAR_SAMPLES,
691   B_FLOAT_SAMPLES,
692   B_MULAW_SAMPLES
693   };
694 
695 
696 /* for encoders and file writers */
697 
698 struct media_encode_info {
699 	uint32		flags;					/* B_MEDIA_KEY_FRAME, set before every use */
700 	int32		used_data_size;			/* data size used by other tracks */
701 										/* add output size used by this encoder */
702 	bigtime_t	start_time;				/* us from start of file */
703 	bigtime_t	time_to_encode;			/* 0 - hurry up, B_INFINITE_TIMEOUT - don't care */
704 	int32		_pad[22];
705 	void		*file_format_data;		/* file format specific info */
706 	size_t		file_format_data_size;
707 	void		*codec_data;			/* codec specific info */
708 	size_t		codec_data_size;
709 
710 	media_encode_info();
711 };
712 
713 struct encode_parameters {
714 	float		quality;				// 0.0-1.0 , 1.0 is high quality
715 	int32		avg_field_size;			// in bytes
716 	int32		max_field_size;			// in bytes
717 	int32		_pad[27];
718 	void		*user_data;				// codec specific info
719 	size_t		user_data_size;
720 };
721 
722 struct media_decode_info {
723 	bigtime_t	time_to_decode;			/* 0 - hurry up, B_INFINITE_TIMEOUT - don't care */
724 	int32		_pad[26];
725 	void		*file_format_data;		/* file format specific info */
726 	size_t		file_format_data_size;
727 	void		*codec_data;			/* codec specific info */
728 	size_t		codec_data_size;
729 
730 	media_decode_info();
731 };
732 
733 
734 #endif	//	__cplusplus
735 
736 #endif /* MEDIA_DEFS_H */
737