xref: /haiku/headers/os/media/MediaDefs.h (revision ab4411e89a079bc0a40d901995f3418d998c51b3)
1 /*
2  * Copyright 2009, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _MEDIA_DEFS_H
6 #define _MEDIA_DEFS_H
7 
8 
9 /*! Basic data types and defines for the Media Kit. */
10 
11 
12 #include <OS.h>
13 #include <ByteOrder.h>
14 
15 #if defined(__cplusplus)
16 #	include <GraphicsDefs.h>
17 #	include <Looper.h>
18 #endif
19 
20 
21 struct media_node;
22 
23 #define B_MEDIA_NAME_LENGTH 64
24 
25 
26 /* Notification messages 'what' fields */
27 enum {
28 	/* Note that BMediaNode::node_error also belongs in here! */
29 	B_MEDIA_WILDCARD		= 'TRWC',
30 									/* Used to match any notification in */
31 									/* Start/StopWatching */
32 	B_MEDIA_NODE_CREATED	= 'TRIA',
33 									/* "media_node_id" (multiple items) */
34 	B_MEDIA_NODE_DELETED,			/* "media_node_id" (multiple items) */
35 	B_MEDIA_CONNECTION_MADE,		/* "output", "input", "format" */
36 	B_MEDIA_CONNECTION_BROKEN,		/* "source", "destination" */
37 	B_MEDIA_BUFFER_CREATED,			/* "clone_info" -- handled by */
38 									/* BMediaRoster */
39 	B_MEDIA_BUFFER_DELETED,			/* "media_buffer_id" -- handled by */
40 									/* BMediaRoster */
41 	B_MEDIA_TRANSPORT_STATE,		/* "state", "location", "realtime" */
42 	B_MEDIA_PARAMETER_CHANGED,		/* N "node", "parameter" */
43 	B_MEDIA_FORMAT_CHANGED,			/* N "source", "destination", "format" */
44 	B_MEDIA_WEB_CHANGED,			/* N "node" */
45 	B_MEDIA_DEFAULT_CHANGED,		/* "default", "node" -- handled by */
46 									/* BMediaRoster */
47 	B_MEDIA_NEW_PARAMETER_VALUE,	/* N "node", "parameter", "when", */
48 									/* "value" */
49 	B_MEDIA_NODE_STOPPED,			/* N "node", "when" */
50 	B_MEDIA_FLAVORS_CHANGED			/* "be:addon_id", "be:new_count", */
51 									/* "be:gone_count" */
52 };
53 
54 
55 enum media_type {
56 	B_MEDIA_NO_TYPE			= -1,
57 	B_MEDIA_UNKNOWN_TYPE	= 0,
58 	B_MEDIA_RAW_AUDIO		= 1,	/* uncompressed raw_audio */
59 	B_MEDIA_RAW_VIDEO,				/* uncompressed raw_video */
60 	B_MEDIA_VBL,					/* raw data from VBL area, 1600/line */
61 	B_MEDIA_TIMECODE,				/* data format TBD */
62 	B_MEDIA_MIDI,
63 	B_MEDIA_TEXT,					/* typically closed captioning */
64 	B_MEDIA_HTML,
65 	B_MEDIA_MULTISTREAM,			/* AVI, etc */
66 	B_MEDIA_PARAMETERS,				/* BControllable change data */
67 	B_MEDIA_ENCODED_AUDIO,			/* MP3, AC-3, ... */
68 	B_MEDIA_ENCODED_VIDEO,			/* H.264, Theora, ... */
69 	B_MEDIA_PRIVATE			= 90000,
70 									/* This are reserved. */
71 	B_MEDIA_FIRST_USER_TYPE	= 100000
72 									/* Use something bigger than this for */
73 									/* experimentation with your own media */
74 									/* formats. */
75 };
76 
77 
78 enum node_kind {
79 	B_BUFFER_PRODUCER		= 0x1,
80 	B_BUFFER_CONSUMER		= 0x2,
81 	B_TIME_SOURCE			= 0x4,
82 	B_CONTROLLABLE			= 0x8,
83 	B_FILE_INTERFACE		= 0x10,
84 	B_ENTITY_INTERFACE		= 0x20,
85 
86 	/* Set these flags for nodes that are suitable as default system nodes. */
87 	B_PHYSICAL_INPUT		= 0x10000,
88 	B_PHYSICAL_OUTPUT		= 0x20000,
89 	B_SYSTEM_MIXER			= 0x40000
90 };
91 
92 
93 enum video_orientation {
94 	/* Which pixel is first and how do we scan each "line"? */
95 	B_VIDEO_TOP_LEFT_RIGHT	= 1,	/* This is the typical progressive scan */
96 									/* format */
97 	B_VIDEO_BOTTOM_LEFT_RIGHT		/* This is how BMP and TGA might scan */
98 };
99 
100 
101 /* data */
102 enum media_flags
103 {
104 	B_MEDIA_FLAGS_VERSION			= 1,
105 									/* uint32, greater for newer versions */
106 	B_MEDIA_FLAGS_PRIVATE			= 0x40000000
107 									/* private to Haiku */
108 };
109 
110 
111 /* for producer status */
112 enum media_producer_status {
113 	B_DATA_NOT_AVAILABLE			= 1,
114 	B_DATA_AVAILABLE				= 2,
115 	B_PRODUCER_STOPPED				= 3
116 };
117 
118 
119 /* realtime flags */
120 enum media_realtime_flags {
121 	B_MEDIA_REALTIME_ALLOCATOR		= 0x1,
122 	B_MEDIA_REALTIME_AUDIO			= 0x2,
123 	B_MEDIA_REALTIME_VIDEO			= 0x4,
124 	B_MEDIA_REALTIME_ANYKIND		= 0xffff
125 };
126 
127 enum media_frame_flags {
128 	B_MEDIA_KEY_FRAME				= 0x1
129 };
130 
131 #define B_MEDIA_ANY_QUALITY			0.0f
132 #define B_MEDIA_LOW_QUALITY			0.1f
133 #define B_MEDIA_MEDIUM_QUALITY		0.5f
134 #define B_MEDIA_HIGH_QUALITY		1.0f
135 
136 
137 #ifndef _MULTI_AUDIO_H	/* #define in protocol header */
138 enum media_multi_channels {
139 	B_CHANNEL_LEFT					= 0x00001,
140 	B_CHANNEL_RIGHT					= 0x00002,
141 	B_CHANNEL_CENTER				= 0x00004,	/* 5.1+ or fake surround */
142 	B_CHANNEL_SUB					= 0x00008,	/* 5.1+ */
143 	B_CHANNEL_REARLEFT				= 0x00010,	/* quad surround or 5.1+ */
144 	B_CHANNEL_REARRIGHT				= 0x00020,	/* quad surround or 5.1+ */
145 	B_CHANNEL_FRONT_LEFT_CENTER		= 0x00040,
146 	B_CHANNEL_FRONT_RIGHT_CENTER	= 0x00080,
147 	B_CHANNEL_BACK_CENTER			= 0x00100,	/* 6.1 or fake surround */
148 	B_CHANNEL_SIDE_LEFT				= 0x00200,
149 	B_CHANNEL_SIDE_RIGHT			= 0x00400,
150 	B_CHANNEL_TOP_CENTER			= 0x00800,
151 	B_CHANNEL_TOP_FRONT_LEFT		= 0x01000,
152 	B_CHANNEL_TOP_FRONT_CENTER		= 0x02000,
153 	B_CHANNEL_TOP_FRONT_RIGHT		= 0x04000,
154 	B_CHANNEL_TOP_BACK_LEFT			= 0x08000,
155 	B_CHANNEL_TOP_BACK_CENTER		= 0x10000,
156 	B_CHANNEL_TOP_BACK_RIGHT		= 0x20000
157 };
158 
159 
160 enum media_multi_matrix {
161 	B_MATRIX_PROLOGIC_LR			= 0x1,
162 	B_MATRIX_AMBISONIC_WXYZ			= 0x4
163 };
164 #endif // !_MULTI_AUDIO_H
165 
166 
167 typedef int32 media_node_id;
168 typedef int32 media_buffer_id;
169 typedef int32 media_addon_id;
170 
171 
172 #if defined(__cplusplus)
173 struct media_destination {
174 								media_destination();
175 								media_destination(port_id, int32);
176 								media_destination(
177 									const media_destination& other);
178 								~media_destination();
179 
180 			media_destination&	operator=(const media_destination& other);
181 
182 			port_id				port;	/* can be different from */
183 										/* media_node.port */
184 			int32				id;
185 	static	media_destination	null;
186 
187 private:
188 			uint32				_reserved_media_destination_[2];
189 };
190 
191 
192 struct media_source {
193 								media_source();
194 								media_source(port_id, int32);
195 								media_source(const media_source& other);
196 								~media_source();
197 
198 			media_source&		operator=(const media_source& other);
199 			port_id				port;	/* must be the same as */
200 										/* media_node.port for owner */
201 			int32				id;
202 	static	media_source		null;
203 
204 private:
205 			uint32				_reserved_media_source_[2];
206 };
207 
208 
209 bool operator==(const media_destination& a, const media_destination& b);
210 bool operator!=(const media_destination& a, const media_destination& b);
211 bool operator<(const media_destination& a, const media_destination& b);
212 bool operator==(const media_source& a, const media_source& b);
213 bool operator!=(const media_source& a, const media_source& b);
214 bool operator<(const media_source& a, const media_source& b);
215 bool operator==(const media_node& a, const media_node& b);
216 bool operator!=(const media_node& a, const media_node& b);
217 bool operator<(const media_node& a, const media_node& b);
218 
219 
220 
221 /* Buffers are low-level constructs identified by an ID. */
222 /* Buffers consist of the actual data area, plus a 64-byte */
223 /* header area that is different for each type. */
224 /* Buffers contain typed data. Type is not part of the */
225 /* buffer header; it's negotiated out-of-bounds by nodes. */
226 
227 enum {
228 	B_MEDIA_BIG_ENDIAN			= 1,
229 	B_MEDIA_LITTLE_ENDIAN		= 2,
230 #if B_HOST_IS_BENDIAN
231 	B_MEDIA_HOST_ENDIAN			= B_MEDIA_BIG_ENDIAN
232 #else
233 	B_MEDIA_HOST_ENDIAN			= B_MEDIA_LITTLE_ENDIAN
234 #endif
235 };
236 
237 
238 struct media_multi_audio_format;
239 
240 
241 struct media_raw_audio_format {
242 	// possible values for "format"
243 	enum {
244 		B_AUDIO_FLOAT		= 0x24,
245 			// 0 == mid, -1.0 == bottom, 1.0 == top
246 			// (the preferred format for non-game audio)
247 
248 		B_AUDIO_DOUBLE		= 0x28,
249 			// 0 == mid, -1.0 == bottom, 1.0 == top
250 			// (only useful for pro audio)
251 
252 		B_AUDIO_INT			= 0x4,
253 			// 0 == mid, 0x80000001 == bottom, 0x7fffffff == top
254 			// (all >16-bit formats, left-adjusted)
255 
256 		B_AUDIO_SHORT		= 0x2,
257 			// 0 == mid, -32767 == bottom, +32767 == top
258 
259 		B_AUDIO_UCHAR		= 0x11,
260 			// 128 == mid, 1 == bottom, 255 == top
261 			// (discouraged but supported format)
262 
263 		B_AUDIO_CHAR		= 0x1,
264 			// 0 == mid, -127 == bottom, +127 == top
265 			// (not officially supported format)
266 
267 		B_AUDIO_SIZE_MASK	= 0xf
268 			// This mask can be used to obtain the sample size
269 			// for raw formats: (format & 0xf) == sizeof(sample)
270 	};
271 
272 	float		frame_rate;
273 	uint32		channel_count;
274 	uint32		format;			// see possible values above
275 	uint32		byte_order;		// B_MEDIA_LITTLE_ENDIAN or B_MEDIA_BIG_ENDIAN
276 	size_t		buffer_size;	// size of each buffer
277 
278 	static media_multi_audio_format wildcard;
279 };
280 
281 
282 struct media_audio_header {
283 	// TODO: Refine this structure and put actual data at the end
284 	int32		_reserved_[14];
285 	float       frame_rate;
286 	uint32      channel_count;
287 
288 };
289 
290 
291 struct media_multi_audio_info {
292 	uint32		channel_mask;	// bitmask
293 	int16		valid_bits;		// if < 32, for B_AUDIO_INT
294 	uint16		matrix_mask;	// each of these bits may mean more than one
295 								// channel
296 
297 	uint32		_reserved_b[3];
298 };
299 
300 
301 struct media_multi_audio_format : public media_raw_audio_format,
302 	public media_multi_audio_info {
303 
304 	static media_multi_audio_format wildcard;
305 };
306 
307 
308 struct media_encoded_audio_format {
309 	enum audio_encoding {
310 		B_ANY
311 	};
312 
313 	media_raw_audio_format	output;
314 	audio_encoding			encoding;
315 
316 	float					bit_rate;
317 	size_t					frame_size;
318 
319 	media_multi_audio_info	multi_info;
320 
321 	uint32					_reserved_[3];
322 
323 	static media_encoded_audio_format wildcard;
324 };
325 
326 
327 struct media_encoded_audio_header {
328 	// NOTE: More data fields need to go to the end
329 	int32		_reserved_0[14];
330 
331 	uint32		buffer_flags;
332 		// B_MEDIA_KEY_FRAME for key frame chunks
333 	uchar		unused_mask;
334 		// mask of unused bits for the last byte of data
335 	uchar		_reserved_2[3];
336 
337 };
338 
339 enum media_display_flags {
340 	B_F1_DOMINANT		= 0x1,	// The first buffer sent (temporally) will
341 								// be an F1 field.
342 	B_F2_DOMINANT		= 0x2,	// The first buffer sent (temporally) will
343 								// be an F2 field.
344 	B_TOP_SCANLINE_F1	= 0x4,	// The topmost scanline of the output buffer
345 								// belongs to F1.
346 	B_TOP_SCANLINE_F2	= 0x8	// The topmost scanline of the output buffer
347 								// belongs to F2.
348 };
349 
350 
351 struct media_video_display_info {
352 	color_space	format;
353 	uint32		line_width;
354 	uint32		line_count;		// sum of all interlace fields lines
355 	uint32		bytes_per_row;	// bytes_per_row is in format, not header,
356 								// because it's part of SetBuffers
357 	uint32		pixel_offset;	// (in pixels) Offset from the start of the
358 								// buffer (see below).
359 	uint32		line_offset;	// (in lines) Offset to the start of the field.
360 								// Think "buffer == framebuffer" when the
361 								// window displaying the active field moves
362 								// on screen.
363 	uint32		flags;
364 	uint32		_reserved_[3];
365 
366 	static media_video_display_info wildcard;
367 };
368 
369 
370 struct media_raw_video_format {
371 	float		field_rate;
372 	uint32		interlace;		// Number of fields per frame: 1 means
373 								// progressive (non-interlaced) frames.
374 	uint32		first_active;	// Index of first active line. 0, typically
375 								// (wildcard, or "don't care")
376 	uint32		last_active;	// Index of last active line (typically
377 								// line_count - 1, if first_active is 0.
378 	uint32		orientation;	// B_VIDEO_TOP_LEFT_RIGHT is preferred.
379 
380 	// This is the display aspect ratio (DAR). Usually, you would reduce the
381 	// width and height of the intended output frame size as far as possible
382 	// without changing their ratio. Note that you should not put 1 in both
383 	// fields to mean "undistorted pixels", unless you really intend square
384 	// video output!
385 	uint16		pixel_width_aspect;		// 1:1 has 1 here, 4:3 has 4 here
386 										// 16:9 has 16 here!
387 	uint16		pixel_height_aspect;	// 1:1 has 1 here, 4:3 has 3 here
388 										// 16:9 has 9 here!
389 
390 	media_video_display_info	display;
391 
392 	static media_raw_video_format wildcard;
393 };
394 
395 
396 struct media_video_header {
397 	uint32		_reserved_[8];		// NOTE: Keep reserved data at the top!
398 
399 	uint32      display_line_width; // Number of pixels per display_line
400 	uint32      display_line_count;	// Sum of all interlace fields lines
401 	uint32      bytes_per_row;		// Number of bytes in a display_line
402 									// (padding bytes excluded)
403 	uint16      pixel_width_aspect;	// 1:1 has 1 here, 4:3 has 4 here
404 									// 16:9 has 16 here!
405 	uint16      pixel_height_aspect;// 1:1 has 1 here, 4:3 has 3 here
406 									// 16:9 has 9 here!
407 	float		field_gamma;
408 	uint32		field_sequence;		// Sequence number since start of capture
409 									// May roll over if machine is on for a
410 									// LONG time.
411 	uint16		field_number;		// 0 .. {interlace-1}; F1 == 0 ("odd"),
412 									// F2 == 1 ("even")
413 	uint16		pulldown_number;	// 0..2 for pulldown duplicated sequence
414 	uint16		first_active_line;	// The NTSC/PAL line number (1-based) of
415 									// the first line in this field
416 	uint16		line_count;			// The number of active lines in buffer.
417 };
418 
419 
420 struct media_encoded_video_format {
421 	enum video_encoding {
422 		B_ANY
423 	};
424 
425 	media_raw_video_format	output;				// set unknowns to wildcard
426 
427 	float					avg_bit_rate;
428 	float					max_bit_rate;
429 
430 	video_encoding			encoding;
431 	size_t					frame_size;
432 
433 	int16					forward_history;	// maximum forward memory
434 												// required by codec
435 
436 	int16					backward_history;	// maximum backward memory
437 												// required by codec
438 
439 	uint32					_reserved_[3];		// This structure cannot grow
440 												// more than this (embedded)
441 												// in media_format union
442 
443 	static media_encoded_video_format wildcard;
444 };
445 
446 
447 struct media_encoded_video_header {
448 	// NOTE: More data fields need to go at the end of this structure.
449 	int32		_reserved_1[9];
450 
451 	uint32		field_flags;		//	B_MEDIA_KEY_FRAME
452 
453 	int16		forward_history;	// forward memory required by this buffer
454 									// (0 for key frames)
455 
456 	int16		backward_history;	// backward memory required by this buffer
457 									// (0 for key frames)
458 
459 	uchar		unused_mask;		// mask of unused bits for the last byte
460 									// of data
461 	uchar		_reserved_2[3];
462 	float		field_gamma;
463 	uint32		field_sequence;		// sequence since start of capture
464 	uint16		field_number;		// 0 .. {interlace-1};  F1 == 0, F2 == 1
465 	uint16		pulldown_number;	// 0..2 for pulldown duplicated sequence
466 	uint16		first_active_line;	// 0 or 1, typically, but could be 10 or
467 									// 11 for full-NTSC formats
468 	uint16		line_count;			// number of actual lines in buffer
469 };
470 
471 struct media_multistream_format {
472 	enum {
473 		B_ANY					= 0,
474 		B_VID					= 1,	// raw raw_video/raw_audio buffers
475 		B_AVI,
476 		B_MPEG1,
477 		B_MPEG2,
478 		B_QUICKTIME,
479 		B_PRIVATE				= 90000,
480 		B_FIRST_USER_TYPE		= 100000
481 	};
482 	float		avg_bit_rate;			// 8 * byte rate, on average
483 	float		max_bit_rate;			// 8 * byte rate, tops
484 	uint32		avg_chunk_size;			// == max_chunk_size for fixed-size
485 										// chunks
486 	uint32		max_chunk_size;			// max buffer size
487 	enum {
488 		B_HEADER_HAS_FLAGS		= 0x1,	// are flags important?
489 		B_CLEAN_BUFFERS			= 0x2,	// each buffer represents an integral
490 										// number of "frames"
491 		B_HOMOGENOUS_BUFFERS	= 0x4	// a buffer has only one format in it
492 	};
493 	uint32		flags;
494 	int32		format;
495 	uint32		_reserved_[2];
496 
497 	struct vid_info {
498 		float		frame_rate;
499 		uint16		width;
500 		uint16		height;
501 		color_space	space;
502 
503 		float		sampling_rate;
504 		uint32		sample_format;
505 		uint16		byte_order;
506 		uint16		channel_count;
507 	};
508 	struct avi_info {
509 		uint32		us_per_frame;
510 		uint16		width;
511 		uint16		height;
512 		uint16		_reserved_;
513 		uint16		type_count;
514 		media_type	types[5];
515 	};
516 
517 	union {
518 		vid_info	vid;
519 		avi_info	avi;
520 	} 			u;
521 
522 	static media_multistream_format wildcard;
523 };
524 
525 
526 struct media_multistream_header {
527 	uint32	_reserved_[14];
528 	uchar	unused_mask;			// mask of unused bits for the last byte
529 									// of data
530 	uchar	_reserved_2[3];
531 	enum {
532 		B_MASTER_HEADER		= 0x1,	// for master stream header data in buffer
533 		B_SUBSTREAM_HEADER	= 0x2,	// for sub-stream header data in buffer
534 		B_COMPLETE_BUFFER	= 0x4	// data is an integral number of "frames"
535 	};
536 	uint32 	flags;
537 };
538 
539 
540 extern const type_code B_CODEC_TYPE_INFO;
541 
542 
543 enum media_format_flags {
544 	B_MEDIA_RETAINED_DATA			= 0x1,
545 	B_MEDIA_MULTIPLE_BUFFERS		= 0x2,
546 	B_MEDIA_CONTIGUOUS_BUFFER		= 0x4,
547 	B_MEDIA_LINEAR_UPDATES			= 0x8,
548 	B_MEDIA_MAUI_UNDEFINED_FLAGS	= ~0xf	// NOTE: Always deny these flags
549 											// in new code.
550 };
551 
552 // NOTE: A field of 0 typically means "anything" or "wildcard".
553 // NOTE: This structure should not be bigger than 192 bytes!
554 struct media_format {
555 	media_type						type;
556 	type_code						user_data_type;
557 	uchar							user_data[48];
558 	uint32							_reserved_[3];
559 	uint16							require_flags;	//	media_format_flags
560 	uint16							deny_flags;		//	media_format_flags
561 
562 private:
563 	void*							meta_data;
564 	int32							meta_data_size;
565 	area_id							meta_data_area;
566 	area_id							__unused_was_use_area;
567 	team_id							__unused_was_team;
568 	void*							__unused_was_thisPtr;
569 
570 public:
571 	union {
572 		media_multi_audio_format	raw_audio;
573 		media_raw_video_format		raw_video;
574 		media_multistream_format	multistream;
575 		media_encoded_audio_format	encoded_audio;
576 		media_encoded_video_format	encoded_video;
577 		char						_reserved_[96];	 // pad to 96 bytes
578 	} u;
579 
580 	bool 			IsVideo() const;
581 
582 	uint32  		Width() const;
583 	uint32 			Height() const;
584 	color_space  	ColorSpace() const;
585 
586 	uint32& 		Width();
587 	uint32& 		Height();
588 	color_space& 	ColorSpace();
589 
590 	bool 			IsAudio() const;
591 	uint32 			AudioFormat() const;
592 	uint32& 		AudioFormat();
593 	uint32 			AudioFrameSize() const;
594 
595 	uint32			Encoding() const;
596 
597 	bool			Matches(const media_format* other) const;
598 	void			SpecializeTo(const media_format* other);
599 
600 	status_t		SetMetaData(const void* data, size_t size);
601 	const void*		MetaData() const;
602 	int32			MetaDataSize() const;
603 
604 					media_format();
605 					media_format(const media_format& other);
606 					~media_format();
607 
608 	media_format&	operator=(const media_format& other);
609 };
610 
611 
612 bool operator==(const media_raw_audio_format& a,
613 	const media_raw_audio_format& b);
614 
615 bool operator==(const media_multi_audio_info& a,
616 	const media_multi_audio_info& b);
617 
618 bool operator==(const media_multi_audio_format& a,
619 	const media_multi_audio_format& b);
620 
621 bool operator==(const media_encoded_audio_format& a,
622 	const media_encoded_audio_format& b);
623 
624 bool operator==(const media_video_display_info& a,
625 	const media_video_display_info& b);
626 
627 bool operator==(const media_raw_video_format& a,
628 	const media_raw_video_format& b);
629 
630 bool operator==(const media_encoded_video_format& a,
631 	const media_encoded_video_format& b);
632 
633 bool operator==(const media_multistream_format::vid_info& a,
634 	const media_multistream_format::vid_info& b);
635 
636 bool operator==(const media_multistream_format::avi_info& a,
637 	const media_multistream_format::avi_info & b);
638 
639 bool operator==(const media_multistream_format& a,
640 	const media_multistream_format& b);
641 
642 bool operator==(const media_format& a, const media_format& b);
643 
644 
645 bool format_is_compatible(const media_format & a, const media_format & b);
646 	// Returns true if a and b are compatible (accounting for wildcards)
647 	// (a is the format you want to feed to something accepting b
648 
649 bool string_for_format(const media_format & f, char * buf, size_t size);
650 
651 
652 struct media_seek_tag {
653 	char	data[16];
654 };
655 
656 
657 struct media_header_time_code {
658 	int8	type;		//	See TimeCode.h; don't use the "DEFAULT" value
659 	int8	_reserved;
660 	int8	hours;
661 	int8	minutes;
662 	int8	seconds;
663 	int8	frames;
664 	int16	subframes;	//	Set to -1 if not available
665 };
666 
667 
668 // Broadcast() fills in fields marked with "//+"
669 struct media_header {
670 	media_type		type;			// what kind of data (for union)
671 	media_buffer_id buffer;			//+ what buffer does this header go with?
672 	int32			destination;	//+ what 'socket' is this intended for?
673 	media_node_id	time_source;	// node that encoded start_time
674 	uint32			_deprecated_;	// used to be change_tag
675 	uint32			size_used;		// size within buffer that is used
676 	bigtime_t		start_time;		// performance time
677 	area_id			owner;			//+ buffer owner info area
678 	enum {
679 		B_SEEK_TAG	= 'TRST',		// user data type of the codec seek
680 									// protocol. size of seek tag is 16 bytes
681 		B_TIME_CODE	= 'TRTC'		// user data is media_header_time_code
682 	};
683 	type_code		user_data_type;
684 	uchar			user_data[64];	// user_data_type indicates what this is
685 	int32			source;
686 	port_id			source_port;
687 
688 	off_t			file_pos;		// where in a file this data came from
689 	size_t			orig_size;		// and how big it was.  if unused, zero out
690 
691 	uint32			data_offset;	// offset within buffer (already reflected in Data())
692 
693 	union {
694 		media_audio_header			raw_audio;
695 		media_video_header			raw_video;
696 		media_multistream_header	multistream;
697 		media_encoded_audio_header	encoded_audio;
698 		media_encoded_video_header	encoded_video;
699 		char						_reserved_[64];	// pad to 64 bytes
700 	}				u;
701 };
702 
703 
704 struct media_file_format_id {
705 	ino_t	node;
706 	dev_t	device;
707 	uint32	internal_id;
708 };
709 
710 
711 bool operator==(const media_file_format_id& a, const media_file_format_id& b);
712 bool operator<(const media_file_format_id& a, const media_file_format_id& b);
713 
714 
715 typedef enum {
716 	B_ANY_FORMAT_FAMILY			= 0,
717 	B_BEOS_FORMAT_FAMILY		= 1,
718 	B_QUICKTIME_FORMAT_FAMILY	= 2,	// QuickTime is a registered
719 										// trademark of Apple Computer.
720 	B_AVI_FORMAT_FAMILY			= 3,
721 	B_ASF_FORMAT_FAMILY			= 4,
722 	B_MPEG_FORMAT_FAMILY		= 5,
723 	B_WAV_FORMAT_FAMILY			= 6,
724 	B_AIFF_FORMAT_FAMILY		= 7,
725 	B_AVR_FORMAT_FAMILY			= 8,
726 
727 	B_MISC_FORMAT_FAMILY		= 99999,
728 } media_format_family;
729 
730 
731 struct media_file_format {
732 	// Possible flags for capabilities bitmask
733 	enum {
734 		B_READABLE				= 0x1,
735 		B_WRITABLE				= 0x2,
736 		B_PERFECTLY_SEEKABLE	= 0x4,
737 		B_IMPERFECTLY_SEEKABLE	= 0x8,
738 		B_KNOWS_RAW_VIDEO		= 0x10,
739 		B_KNOWS_RAW_AUDIO		= 0x20,
740 		B_KNOWS_MIDI			= 0x40,
741 		B_KNOWS_ENCODED_VIDEO	= 0x80,
742 		B_KNOWS_ENCODED_AUDIO	= 0x100,
743 		B_KNOWS_OTHER			= 0x1000000, // For example sub-title streams
744 		B_KNOWS_ANYTHING		= 0x2000000
745 	};
746 	uint32					capabilities;	// Bitmask, see flags above
747 	media_file_format_id	id;				// Opaque id used to construct a
748 											// BMediaFile
749 	media_format_family		family;			// One of the family enums
750 	int32					version;		// 100 for 1.0
751 
752 	uint32					_reserved_[25];
753 
754 	char					mime_type[64];
755 	char					pretty_name[64];	// "QuickTime File Format"
756 	char					short_name[32];		// "quicktime", "avi", "mpeg"
757 	char					file_extension[8];	// "mov", "avi", "mpg"
758 
759 	char					reserved[88];
760 };
761 
762 
763 // Initialize the cookie to 0 and keep calling this function to iterate
764 // over all available media file format writers.
765 status_t get_next_file_format(int32* cookie, media_file_format* mfi);
766 
767 
768 // A buffer of this size is guaranteed to be large enough to hold any
769 // message, which your service thread can read from read_port() and
770 // passes on to HandleMessage().
771 const size_t B_MEDIA_MESSAGE_SIZE = 16384;
772 
773 
774 extern const char* B_MEDIA_SERVER_SIGNATURE;
775 
776 class media_node;
777 struct media_input;
778 struct media_output;
779 struct live_node_info;
780 struct dormant_node_info;
781 struct buffer_clone_info;
782 
783 
784 // Functions which control the shutdown and launching process of the
785 // media_server and it's friends. You can provide a call back hook which
786 // will be called during various steps of the process. This callback should
787 // currently always return TRUE. A 'stage' value of 100 means the process is
788 // completely finished.
789 status_t shutdown_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT,
790 	bool (*progress)(int stage, const char* message, void* cookie) = NULL,
791 	void* cookie = NULL);
792 status_t launch_media_server(uint32 flags = 0);
793 
794 
795 // Given an image_id, prepare that image_id for realtime media
796 // If the kind of media indicated by 'flags' is not enabled for real-time,
797 // B_MEDIA_REALTIME_DISABLED is returned.
798 // If there are not enough system resources to enable real-time performance,
799 // B_MEDIA_REALTIME_UNAVAILABLE is returned.
800 status_t media_realtime_init_image(image_id image, uint32 flags);
801 
802 
803 // Given a thread ID, and an optional indication of what the thread is
804 // doing in "flags", prepare the thread for real-time media performance.
805 // Currently, this means locking the thread stack, up to size_used bytes,
806 // or all of it if 0 is passed. Typically, you will not be using all
807 // 256 kB of the stack, so you should pass some smaller value you determine
808 // from profiling the thread; typically in the 32-64kB range.
809 // Return values are the same as for media_prepare_realtime_image().
810 status_t media_realtime_init_thread(thread_id thread, size_t stack_used,
811 	uint32 flags);
812 
813 
814 // A teeny bit of legacy preserved for BSoundFile from R3.
815 // These came from the old MediaDefs.h; don't use them
816 // unless you get them from BSoundFile.
817 
818 
819 // values for byte_ordering
820 enum {
821 	B_BIG_ENDIAN,
822 	B_LITTLE_ENDIAN
823 };
824 
825 
826 // values for sample_format
827 enum {
828 	B_UNDEFINED_SAMPLES,
829 	B_LINEAR_SAMPLES,
830 	B_FLOAT_SAMPLES,
831 	B_MULAW_SAMPLES
832 };
833 
834 
835 // #pragma mark - encoders and file writers
836 
837 
838 struct media_encode_info {
839 	uint32		flags;					// B_MEDIA_KEY_FRAME, set before every
840 										// use
841 
842 	int32		used_data_size;			// data size used by other tracks
843 										// add output size used by this encoder
844 
845 	bigtime_t	start_time;				// us from start of file
846 	bigtime_t	time_to_encode;			// 0 - hurry up, B_INFINITE_TIMEOUT
847 										// - don't care
848 	int32		_pad[22];
849 
850 	void*		file_format_data;		// file format specific info
851 	size_t		file_format_data_size;
852 
853 	void*		codec_data;				// codec specific info
854 	size_t		codec_data_size;
855 
856 	media_encode_info();
857 };
858 
859 
860 struct encode_parameters {
861 	float		quality;				// 0.0-1.0 , 1.0 is high quality
862 
863 	int32		avg_field_size;			// in bytes
864 	int32		max_field_size;			// in bytes
865 
866 	int32		_pad[27];
867 
868 	void*		user_data;				// codec specific info
869 	size_t		user_data_size;
870 };
871 
872 
873 struct media_decode_info {
874 	bigtime_t	time_to_decode;			// 0 - hurry up, B_INFINITE_TIMEOUT
875 										// - don't care
876 
877 	int32		_pad[26];
878 
879 	void*		file_format_data;		// file format specific info
880 	size_t		file_format_data_size;
881 
882 	void*		codec_data;				// codec specific info
883 	size_t		codec_data_size;
884 
885 	media_decode_info();
886 };
887 
888 
889 // #pragma mark - inline implementations
890 
891 
892 inline bool
893 media_format::IsVideo() const
894 {
895 	return type == B_MEDIA_ENCODED_VIDEO || type == B_MEDIA_RAW_VIDEO;
896 }
897 
898 
899 inline uint32
900 media_format::Width() const
901 {
902 	return type == B_MEDIA_ENCODED_VIDEO
903 		? u.encoded_video.output.display.line_width
904 		: u.raw_video.display.line_width;
905 }
906 
907 
908 inline uint32
909 media_format::Height() const
910 {
911 	return type == B_MEDIA_ENCODED_VIDEO
912 		? u.encoded_video.output.display.line_count
913 		: u.raw_video.display.line_count;
914 }
915 
916 
917 inline color_space
918 media_format::ColorSpace() const
919 {
920 	return type == B_MEDIA_ENCODED_VIDEO
921 		? u.encoded_video.output.display.format
922 		: u.raw_video.display.format;
923 }
924 
925 
926 inline uint32&
927 media_format::Width()
928 {
929 	return type == B_MEDIA_ENCODED_VIDEO
930 		? u.encoded_video.output.display.line_width
931 		: u.raw_video.display.line_width;
932 }
933 
934 
935 inline uint32&
936 media_format::Height()
937 {
938 	return type == B_MEDIA_ENCODED_VIDEO
939 		? u.encoded_video.output.display.line_count
940 		: u.raw_video.display.line_count;
941 }
942 
943 
944 inline color_space&
945 media_format::ColorSpace()
946 {
947 	return type == B_MEDIA_ENCODED_VIDEO
948 		? u.encoded_video.output.display.format
949 		: u.raw_video.display.format;
950 }
951 
952 
953 inline bool
954 media_format::IsAudio() const
955 {
956 	return type == B_MEDIA_ENCODED_AUDIO || type == B_MEDIA_RAW_AUDIO;
957 }
958 
959 
960 inline uint32
961 media_format::AudioFormat() const
962 {
963 	return type == B_MEDIA_ENCODED_AUDIO
964 		? u.encoded_audio.output.format : u.raw_audio.format;
965 }
966 
967 
968 inline uint32&
969 media_format::AudioFormat()
970 {
971 	return type == B_MEDIA_ENCODED_AUDIO
972 		? u.encoded_audio.output.format : u.raw_audio.format;
973 }
974 
975 
976 inline uint32
977 media_format::AudioFrameSize() const
978 {
979 	return type == B_MEDIA_ENCODED_AUDIO
980 		? (u.encoded_audio.output.format
981 			& media_raw_audio_format::B_AUDIO_SIZE_MASK)
982 			* u.encoded_audio.output.channel_count
983 		: (u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK)
984 			* u.raw_audio.channel_count;
985 }
986 
987 
988 inline uint32
989 media_format::Encoding() const
990 {
991 	return type == B_MEDIA_ENCODED_VIDEO
992 		? u.encoded_video.encoding : type == B_MEDIA_ENCODED_AUDIO
993 			? u.encoded_audio.encoding : type == B_MEDIA_MULTISTREAM
994 				? u.multistream.format : 0UL;
995 }
996 
997 
998 #endif /* end of __cplusplus section */
999 
1000 
1001 #endif /* MEDIA_DEFS_H */
1002