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
21struct media_node;
22
23#define B_MEDIA_NAME_LENGTH 64
24
25
26/* Notification messages 'what' fields */
27enum {
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
55enum 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
78enum 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
93enum 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 */
102enum 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 */
112enum 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 */
120enum 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
127enum 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 */
138enum 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
160enum media_multi_matrix {
161	B_MATRIX_PROLOGIC_LR			= 0x1,
162	B_MATRIX_AMBISONIC_WXYZ			= 0x4
163};
164#endif // !_MULTI_AUDIO_H
165
166
167typedef int32 media_node_id;
168typedef int32 media_buffer_id;
169typedef int32 media_addon_id;
170
171
172#if defined(__cplusplus)
173struct 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
187private:
188			uint32				_reserved_media_destination_[2];
189};
190
191
192struct 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
204private:
205			uint32				_reserved_media_source_[2];
206};
207
208
209bool operator==(const media_destination& a, const media_destination& b);
210bool operator!=(const media_destination& a, const media_destination& b);
211bool operator<(const media_destination& a, const media_destination& b);
212bool operator==(const media_source& a, const media_source& b);
213bool operator!=(const media_source& a, const media_source& b);
214bool operator<(const media_source& a, const media_source& b);
215bool operator==(const media_node& a, const media_node& b);
216bool operator!=(const media_node& a, const media_node& b);
217bool 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
227enum {
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
238struct media_multi_audio_format;
239
240
241struct 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
282struct media_audio_header {
283	// TODO: Define this structure, put actual data at the end
284	int32		_reserved_[16];
285};
286
287
288struct media_multi_audio_info {
289	uint32		channel_mask;	// bitmask
290	int16		valid_bits;		// if < 32, for B_AUDIO_INT
291	uint16		matrix_mask;	// each of these bits may mean more than one
292								// channel
293
294	uint32		_reserved_b[3];
295};
296
297
298struct media_multi_audio_format : public media_raw_audio_format,
299	public media_multi_audio_info {
300
301	static media_multi_audio_format wildcard;
302};
303
304
305struct media_encoded_audio_format {
306	enum audio_encoding {
307		B_ANY
308	};
309
310	media_raw_audio_format	output;
311	audio_encoding			encoding;
312
313	float					bit_rate;
314	size_t					frame_size;
315
316	media_multi_audio_info	multi_info;
317
318	uint32					_reserved_[3];
319
320	static media_encoded_audio_format wildcard;
321};
322
323
324struct media_encoded_audio_header {
325	// NOTE: More data fields need to go to the end
326	int32		_reserved_0[14];
327
328	uint32		buffer_flags;
329		// B_MEDIA_KEY_FRAME for key frame chunks
330	uchar		unused_mask;
331		// mask of unused bits for the last byte of data
332	uchar		_reserved_2[3];
333
334};
335
336enum media_display_flags {
337	B_F1_DOMINANT		= 0x1,	// The first buffer sent (temporally) will
338								// be an F1 field.
339	B_F2_DOMINANT		= 0x2,	// The first buffer sent (temporally) will
340								// be an F2 field.
341	B_TOP_SCANLINE_F1	= 0x4,	// The topmost scanline of the output buffer
342								// belongs to F1.
343	B_TOP_SCANLINE_F2	= 0x8	// The topmost scanline of the output buffer
344								// belongs to F2.
345};
346
347
348struct media_video_display_info {
349	color_space	format;
350	uint32		line_width;
351	uint32		line_count;		// sum of all interlace fields lines
352	uint32		bytes_per_row;	// bytes_per_row is in format, not header,
353								// because it's part of SetBuffers
354	uint32		pixel_offset;	// (in pixels) Offset from the start of the
355								// buffer (see below).
356	uint32		line_offset;	// (in lines) Offset to the start of the field.
357								// Think "buffer == framebuffer" when the
358								// window displaying the active field moves
359								// on screen.
360	uint32		flags;
361	uint32		_reserved_[3];
362
363	static media_video_display_info wildcard;
364};
365
366
367struct media_raw_video_format {
368	float		field_rate;
369	uint32		interlace;		// Number of fields per frame: 1 means
370								// progressive (non-interlaced) frames.
371	uint32		first_active;	// Index of first active line. 0, typically
372								// (wildcard, or "don't care")
373	uint32		last_active;	// Index of last active line (typically
374								// line_count - 1, if first_active is 0.
375	uint32		orientation;	// B_VIDEO_TOP_LEFT_RIGHT is preferred.
376
377	// This is the display aspect ratio (DAR). Usually, you would reduce the
378	// width and height of the intended output frame size as far as possible
379	// without changing their ratio. Note that you should not put 1 in both
380	// fields to mean "undistorted pixels", unless you really intend square
381	// video output!
382	uint16		pixel_width_aspect;		// 1:1 has 1 here, 4:3 has 4 here
383										// 16:9 has 16 here!
384	uint16		pixel_height_aspect;	// 1:1 has 1 here, 4:3 has 3 here
385										// 16:9 has 9 here!
386
387	media_video_display_info	display;
388
389	static media_raw_video_format wildcard;
390};
391
392
393struct media_video_header {
394	uint32		_reserved_[12];		// NOTE: Keep reserved data at the top!
395
396	float		field_gamma;
397	uint32		field_sequence;		// Sequence number since start of capture
398									// May roll over if machine is on for a
399									// LONG time.
400	uint16		field_number;		// 0 .. {interlace-1}; F1 == 0 ("odd"),
401									// F2 == 1 ("even")
402	uint16		pulldown_number;	// 0..2 for pulldown duplicated sequence
403	uint16		first_active_line;	// The NTSC/PAL line number (1-based) of
404									// the first line in this field
405	uint16		line_count;			// The number of active lines in buffer.
406};
407
408
409struct media_encoded_video_format {
410	enum video_encoding {
411		B_ANY
412	};
413
414	media_raw_video_format	output;				// set unknowns to wildcard
415
416	float					avg_bit_rate;
417	float					max_bit_rate;
418
419	video_encoding			encoding;
420	size_t					frame_size;
421
422	int16					forward_history;	// maximum forward memory
423												// required by codec
424
425	int16					backward_history;	// maximum backward memory
426												// required by codec
427
428	uint32					_reserved_[3];		// This structure cannot grow
429												// more than this (embedded)
430												// in media_format union
431
432	static media_encoded_video_format wildcard;
433};
434
435
436struct media_encoded_video_header {
437	// NOTE: More data fields need to go at the end of this structure.
438	int32		_reserved_1[9];
439
440	uint32		field_flags;		//	B_MEDIA_KEY_FRAME
441
442	int16		forward_history;	// forward memory required by this buffer
443									// (0 for key frames)
444
445	int16		backward_history;	// backward memory required by this buffer
446									// (0 for key frames)
447
448	uchar		unused_mask;		// mask of unused bits for the last byte
449									// of data
450	uchar		_reserved_2[3];
451	float		field_gamma;
452	uint32		field_sequence;		// sequence since start of capture
453	uint16		field_number;		// 0 .. {interlace-1};  F1 == 0, F2 == 1
454	uint16		pulldown_number;	// 0..2 for pulldown duplicated sequence
455	uint16		first_active_line;	// 0 or 1, typically, but could be 10 or
456									// 11 for full-NTSC formats
457	uint16		line_count;			// number of actual lines in buffer
458};
459
460struct media_multistream_format {
461	enum {
462		B_ANY					= 0,
463		B_VID					= 1,	// raw raw_video/raw_audio buffers
464		B_AVI,
465		B_MPEG1,
466		B_MPEG2,
467		B_QUICKTIME,
468		B_PRIVATE				= 90000,
469		B_FIRST_USER_TYPE		= 100000
470	};
471	float		avg_bit_rate;			// 8 * byte rate, on average
472	float		max_bit_rate;			// 8 * byte rate, tops
473	uint32		avg_chunk_size;			// == max_chunk_size for fixed-size
474										// chunks
475	uint32		max_chunk_size;			// max buffer size
476	enum {
477		B_HEADER_HAS_FLAGS		= 0x1,	// are flags important?
478		B_CLEAN_BUFFERS			= 0x2,	// each buffer represents an integral
479										// number of "frames"
480		B_HOMOGENOUS_BUFFERS	= 0x4	// a buffer has only one format in it
481	};
482	uint32		flags;
483	int32		format;
484	uint32		_reserved_[2];
485
486	struct vid_info {
487		float		frame_rate;
488		uint16		width;
489		uint16		height;
490		color_space	space;
491
492		float		sampling_rate;
493		uint32		sample_format;
494		uint16		byte_order;
495		uint16		channel_count;
496	};
497	struct avi_info {
498		uint32		us_per_frame;
499		uint16		width;
500		uint16		height;
501		uint16		_reserved_;
502		uint16		type_count;
503		media_type	types[5];
504	};
505
506	union {
507		vid_info	vid;
508		avi_info	avi;
509	} 			u;
510
511	static media_multistream_format wildcard;
512};
513
514
515struct media_multistream_header {
516	uint32	_reserved_[14];
517	uchar	unused_mask;			// mask of unused bits for the last byte
518									// of data
519	uchar	_reserved_2[3];
520	enum {
521		B_MASTER_HEADER		= 0x1,	// for master stream header data in buffer
522		B_SUBSTREAM_HEADER	= 0x2,	// for sub-stream header data in buffer
523		B_COMPLETE_BUFFER	= 0x4	// data is an integral number of "frames"
524	};
525	uint32 	flags;
526};
527
528
529extern const type_code B_CODEC_TYPE_INFO;
530
531
532enum media_format_flags {
533	B_MEDIA_RETAINED_DATA			= 0x1,
534	B_MEDIA_MULTIPLE_BUFFERS		= 0x2,
535	B_MEDIA_CONTIGUOUS_BUFFER		= 0x4,
536	B_MEDIA_LINEAR_UPDATES			= 0x8,
537	B_MEDIA_MAUI_UNDEFINED_FLAGS	= ~0xf	// NOTE: Always deny these flags
538											// in new code.
539};
540
541// NOTE: A field of 0 typically means "anything" or "wildcard".
542// NOTE: This structure should not be bigger than 192 bytes!
543struct media_format {
544	media_type						type;
545	type_code						user_data_type;
546	uchar							user_data[48];
547	uint32							_reserved_[3];
548	uint16							require_flags;	//	media_format_flags
549	uint16							deny_flags;		//	media_format_flags
550
551private:
552	void*							meta_data;
553	int32							meta_data_size;
554	area_id							meta_data_area;
555	area_id							__unused_was_use_area;
556	team_id							__unused_was_team;
557	void*							__unused_was_thisPtr;
558
559public:
560	union {
561		media_multi_audio_format	raw_audio;
562		media_raw_video_format		raw_video;
563		media_multistream_format	multistream;
564		media_encoded_audio_format	encoded_audio;
565		media_encoded_video_format	encoded_video;
566		char						_reserved_[96];	 // pad to 96 bytes
567	} u;
568
569	bool 			IsVideo() const;
570
571	uint32  		Width() const;
572	uint32 			Height() const;
573	color_space  	ColorSpace() const;
574
575	uint32& 		Width();
576	uint32& 		Height();
577	color_space& 	ColorSpace();
578
579	bool 			IsAudio() const;
580	uint32 			AudioFormat() const;
581	uint32& 		AudioFormat();
582	uint32 			AudioFrameSize() const;
583
584	uint32			Encoding() const;
585
586	bool			Matches(const media_format* other) const;
587	void			SpecializeTo(const media_format* other);
588
589	status_t		SetMetaData(const void* data, size_t size);
590	const void*		MetaData() const;
591	int32			MetaDataSize() const;
592
593					media_format();
594					media_format(const media_format& other);
595					~media_format();
596
597	media_format&	operator=(const media_format& other);
598};
599
600
601bool operator==(const media_raw_audio_format& a,
602	const media_raw_audio_format& b);
603
604bool operator==(const media_multi_audio_info& a,
605	const media_multi_audio_info& b);
606
607bool operator==(const media_multi_audio_format& a,
608	const media_multi_audio_format& b);
609
610bool operator==(const media_encoded_audio_format& a,
611	const media_encoded_audio_format& b);
612
613bool operator==(const media_video_display_info& a,
614	const media_video_display_info& b);
615
616bool operator==(const media_raw_video_format& a,
617	const media_raw_video_format& b);
618
619bool operator==(const media_encoded_video_format& a,
620	const media_encoded_video_format& b);
621
622bool operator==(const media_multistream_format::vid_info& a,
623	const media_multistream_format::vid_info& b);
624
625bool operator==(const media_multistream_format::avi_info& a,
626	const media_multistream_format::avi_info & b);
627
628bool operator==(const media_multistream_format& a,
629	const media_multistream_format& b);
630
631bool operator==(const media_format& a, const media_format& b);
632
633
634bool format_is_compatible(const media_format & a, const media_format & b);
635	// Returns true if a and b are compatible (accounting for wildcards)
636	// (a is the format you want to feed to something accepting b
637
638bool string_for_format(const media_format & f, char * buf, size_t size);
639
640
641struct media_seek_tag {
642	char	data[16];
643};
644
645
646struct media_header_time_code {
647	int8	type;		//	See TimeCode.h; don't use the "DEFAULT" value
648	int8	_reserved;
649	int8	hours;
650	int8	minutes;
651	int8	seconds;
652	int8	frames;
653	int16	subframes;	//	Set to -1 if not available
654};
655
656
657// Broadcast() fills in fields marked with "//+"
658struct media_header {
659	media_type		type;			// what kind of data (for union)
660	media_buffer_id buffer;			//+ what buffer does this header go with?
661	int32			destination;	//+ what 'socket' is this intended for?
662	media_node_id	time_source;	// node that encoded start_time
663	uint32			_deprecated_;	// used to be change_tag
664	uint32			size_used;		// size within buffer that is used
665	bigtime_t		start_time;		// performance time
666	area_id			owner;			//+ buffer owner info area
667	enum {
668		B_SEEK_TAG	= 'TRST',		// user data type of the codec seek
669									// protocol. size of seek tag is 16 bytes
670		B_TIME_CODE	= 'TRTC'		// user data is media_header_time_code
671	};
672	type_code		user_data_type;
673	uchar			user_data[64];	// user_data_type indicates what this is
674	int32			source;
675	port_id			source_port;
676
677	off_t			file_pos;		// where in a file this data came from
678	size_t			orig_size;		// and how big it was.  if unused, zero out
679
680	uint32			data_offset;	// offset within buffer (already reflected in Data())
681
682	union {
683		media_audio_header			raw_audio;
684		media_video_header			raw_video;
685		media_multistream_header	multistream;
686		media_encoded_audio_header	encoded_audio;
687		media_encoded_video_header	encoded_video;
688		char						_reserved_[64];	// pad to 64 bytes
689	}				u;
690};
691
692
693struct media_file_format_id {
694	ino_t	node;
695	dev_t	device;
696	uint32	internal_id;
697};
698
699
700bool operator==(const media_file_format_id& a, const media_file_format_id& b);
701bool operator<(const media_file_format_id& a, const media_file_format_id& b);
702
703
704typedef enum {
705	B_ANY_FORMAT_FAMILY			= 0,
706	B_BEOS_FORMAT_FAMILY		= 1,
707	B_QUICKTIME_FORMAT_FAMILY	= 2,	// QuickTime is a registered
708										// trademark of Apple Computer.
709	B_AVI_FORMAT_FAMILY			= 3,
710	B_ASF_FORMAT_FAMILY			= 4,
711	B_MPEG_FORMAT_FAMILY		= 5,
712	B_WAV_FORMAT_FAMILY			= 6,
713	B_AIFF_FORMAT_FAMILY		= 7,
714	B_AVR_FORMAT_FAMILY			= 8,
715
716	B_MISC_FORMAT_FAMILY		= 99999,
717} media_format_family;
718
719
720struct media_file_format {
721	// Possible flags for capabilities bitmask
722	enum {
723		B_READABLE				= 0x1,
724		B_WRITABLE				= 0x2,
725		B_PERFECTLY_SEEKABLE	= 0x4,
726		B_IMPERFECTLY_SEEKABLE	= 0x8,
727		B_KNOWS_RAW_VIDEO		= 0x10,
728		B_KNOWS_RAW_AUDIO		= 0x20,
729		B_KNOWS_MIDI			= 0x40,
730		B_KNOWS_ENCODED_VIDEO	= 0x80,
731		B_KNOWS_ENCODED_AUDIO	= 0x100,
732		B_KNOWS_OTHER			= 0x1000000, // For example sub-title streams
733		B_KNOWS_ANYTHING		= 0x2000000
734	};
735	uint32					capabilities;	// Bitmask, see flags above
736	media_file_format_id	id;				// Opaque id used to construct a
737											// BMediaFile
738	media_format_family		family;			// One of the family enums
739	int32					version;		// 100 for 1.0
740
741	uint32					_reserved_[25];
742
743	char					mime_type[64];
744	char					pretty_name[64];	// "QuickTime File Format"
745	char					short_name[32];		// "quicktime", "avi", "mpeg"
746	char					file_extension[8];	// "mov", "avi", "mpg"
747
748	char					reserved[88];
749};
750
751
752// Initialize the cookie to 0 and keep calling this function to iterate
753// over all available media file format writers.
754status_t get_next_file_format(int32* cookie, media_file_format* mfi);
755
756
757// A buffer of this size is guaranteed to be large enough to hold any
758// message, which your service thread can read from read_port() and
759// passes on to HandleMessage().
760const size_t B_MEDIA_MESSAGE_SIZE = 16384;
761
762
763extern const char* B_MEDIA_SERVER_SIGNATURE;
764
765class media_node;
766struct media_input;
767struct media_output;
768struct live_node_info;
769struct dormant_node_info;
770struct buffer_clone_info;
771
772
773// Functions which control the shutdown and launching process of the
774// media_server and it's friends. You can provide a call back hook which
775// will be called during various steps of the process. This callback should
776// currently always return TRUE. A 'stage' value of 100 means the process is
777// completely finished.
778status_t shutdown_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT,
779	bool (*progress)(int stage, const char* message, void* cookie) = NULL,
780	void* cookie = NULL);
781status_t launch_media_server(uint32 flags = 0);
782
783
784// Given an image_id, prepare that image_id for realtime media
785// If the kind of media indicated by 'flags' is not enabled for real-time,
786// B_MEDIA_REALTIME_DISABLED is returned.
787// If there are not enough system resources to enable real-time performance,
788// B_MEDIA_REALTIME_UNAVAILABLE is returned.
789status_t media_realtime_init_image(image_id image, uint32 flags);
790
791
792// Given a thread ID, and an optional indication of what the thread is
793// doing in "flags", prepare the thread for real-time media performance.
794// Currently, this means locking the thread stack, up to size_used bytes,
795// or all of it if 0 is passed. Typically, you will not be using all
796// 256 kB of the stack, so you should pass some smaller value you determine
797// from profiling the thread; typically in the 32-64kB range.
798// Return values are the same as for media_prepare_realtime_image().
799status_t media_realtime_init_thread(thread_id thread, size_t stack_used,
800	uint32 flags);
801
802
803// A teeny bit of legacy preserved for BSoundFile from R3.
804// These came from the old MediaDefs.h; don't use them
805// unless you get them from BSoundFile.
806
807
808// values for byte_ordering
809enum {
810	B_BIG_ENDIAN,
811	B_LITTLE_ENDIAN
812};
813
814
815// values for sample_format
816enum {
817	B_UNDEFINED_SAMPLES,
818	B_LINEAR_SAMPLES,
819	B_FLOAT_SAMPLES,
820	B_MULAW_SAMPLES
821};
822
823
824// #pragma mark - encoders and file writers
825
826
827struct media_encode_info {
828	uint32		flags;					// B_MEDIA_KEY_FRAME, set before every
829										// use
830
831	int32		used_data_size;			// data size used by other tracks
832										// add output size used by this encoder
833
834	bigtime_t	start_time;				// us from start of file
835	bigtime_t	time_to_encode;			// 0 - hurry up, B_INFINITE_TIMEOUT
836										// - don't care
837	int32		_pad[22];
838
839	void*		file_format_data;		// file format specific info
840	size_t		file_format_data_size;
841
842	void*		codec_data;				// codec specific info
843	size_t		codec_data_size;
844
845	media_encode_info();
846};
847
848
849struct encode_parameters {
850	float		quality;				// 0.0-1.0 , 1.0 is high quality
851
852	int32		avg_field_size;			// in bytes
853	int32		max_field_size;			// in bytes
854
855	int32		_pad[27];
856
857	void*		user_data;				// codec specific info
858	size_t		user_data_size;
859};
860
861
862struct media_decode_info {
863	bigtime_t	time_to_decode;			// 0 - hurry up, B_INFINITE_TIMEOUT
864										// - don't care
865
866	int32		_pad[26];
867
868	void*		file_format_data;		// file format specific info
869	size_t		file_format_data_size;
870
871	void*		codec_data;				// codec specific info
872	size_t		codec_data_size;
873
874	media_decode_info();
875};
876
877
878// #pragma mark - inline implementations
879
880
881inline bool
882media_format::IsVideo() const
883{
884	return type == B_MEDIA_ENCODED_VIDEO || type == B_MEDIA_RAW_VIDEO;
885}
886
887
888inline uint32
889media_format::Width() const
890{
891	return type == B_MEDIA_ENCODED_VIDEO
892		? u.encoded_video.output.display.line_width
893		: u.raw_video.display.line_width;
894}
895
896
897inline uint32
898media_format::Height() const
899{
900	return type == B_MEDIA_ENCODED_VIDEO
901		? u.encoded_video.output.display.line_count
902		: u.raw_video.display.line_count;
903}
904
905
906inline color_space
907media_format::ColorSpace() const
908{
909	return type == B_MEDIA_ENCODED_VIDEO
910		? u.encoded_video.output.display.format
911		: u.raw_video.display.format;
912}
913
914
915inline uint32&
916media_format::Width()
917{
918	return type == B_MEDIA_ENCODED_VIDEO
919		? u.encoded_video.output.display.line_width
920		: u.raw_video.display.line_width;
921}
922
923
924inline uint32&
925media_format::Height()
926{
927	return type == B_MEDIA_ENCODED_VIDEO
928		? u.encoded_video.output.display.line_count
929		: u.raw_video.display.line_count;
930}
931
932
933inline color_space&
934media_format::ColorSpace()
935{
936	return type == B_MEDIA_ENCODED_VIDEO
937		? u.encoded_video.output.display.format
938		: u.raw_video.display.format;
939}
940
941
942inline bool
943media_format::IsAudio() const
944{
945	return type == B_MEDIA_ENCODED_AUDIO || type == B_MEDIA_RAW_AUDIO;
946}
947
948
949inline uint32
950media_format::AudioFormat() const
951{
952	return type == B_MEDIA_ENCODED_AUDIO
953		? u.encoded_audio.output.format : u.raw_audio.format;
954}
955
956
957inline uint32&
958media_format::AudioFormat()
959{
960	return type == B_MEDIA_ENCODED_AUDIO
961		? u.encoded_audio.output.format : u.raw_audio.format;
962}
963
964
965inline uint32
966media_format::AudioFrameSize() const
967{
968	return type == B_MEDIA_ENCODED_AUDIO
969		? (u.encoded_audio.output.format
970			& media_raw_audio_format::B_AUDIO_SIZE_MASK)
971			* u.encoded_audio.output.channel_count
972		: (u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK)
973			* u.raw_audio.channel_count;
974}
975
976
977inline uint32
978media_format::Encoding() const
979{
980	return type == B_MEDIA_ENCODED_VIDEO
981		? u.encoded_video.encoding : type == B_MEDIA_ENCODED_AUDIO
982			? u.encoded_audio.encoding : type == B_MEDIA_MULTISTREAM
983				? u.multistream.format : 0UL;
984}
985
986
987#endif /* end of __cplusplus section */
988
989
990#endif /* MEDIA_DEFS_H */
991