MediaDefs.h revision 46e6b9b7
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
28enum {	/* 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 */
63enum {
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
82enum 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
101enum 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
114enum 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
120enum 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
127enum 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
134enum 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
141enum 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 */
152enum 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};
172enum media_multi_matrix {
173	B_MATRIX_PROLOGIC_LR = 0x1,
174	B_MATRIX_AMBISONIC_WXYZ = 0x4
175};
176#endif
177
178
179typedef int32 media_node_id;
180typedef int32 media_buffer_id;
181typedef int32 media_addon_id;
182
183
184#if defined(__cplusplus)
185struct 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;
193static media_destination null;
194private:
195	uint32 _reserved_media_destination_[2];
196};
197
198struct 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;
206static media_source null;
207private:
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
229enum {
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
239struct media_multi_audio_format;
240
241struct 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
257static media_multi_audio_format wildcard;
258};
259
260struct media_audio_header {
261	// please put actual data at the end
262	int32		_reserved_[16];		// gotta have something
263};
264
265struct 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)
274struct media_multi_audio_format : public media_raw_audio_format, public media_multi_audio_info {
275static media_multi_audio_format wildcard;
276};
277#else
278struct media_multi_audio_format {
279	media_raw_audio_format	raw;
280	media_multi_audio_info	multi;
281};
282#endif
283
284
285struct 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
299static media_encoded_audio_format wildcard;
300};
301
302struct 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
311enum 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};
317struct 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];
327static media_video_display_info wildcard;
328};
329
330struct 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
342static media_raw_video_format wildcard;
343};
344
345struct 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
355struct 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
369static media_encoded_video_format wildcard;
370};
371
372struct 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
390struct 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
439static media_multistream_format wildcard;
440};
441
442struct 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
454extern const type_code B_CODEC_TYPE_INFO;
455
456enum 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" */
465struct 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	const 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
505	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; }
506
507	bool			Matches(const media_format *otherFormat) const;
508	void			SpecializeTo(const media_format *otherFormat);
509
510	status_t		SetMetaData(const void *data, size_t size);
511	const void *	MetaData() const;
512	int32			MetaDataSize() const;
513
514					media_format();
515					media_format(const media_format &other);
516					~media_format();
517	media_format &	operator=(const media_format & clone);
518};
519
520_IMPEXP_MEDIA bool operator==(const media_raw_audio_format & a, const media_raw_audio_format & b);
521_IMPEXP_MEDIA bool operator==(const media_multi_audio_info & a, const media_multi_audio_info & b);
522_IMPEXP_MEDIA bool operator==(const media_multi_audio_format & a, const media_multi_audio_format & b);
523_IMPEXP_MEDIA bool operator==(const media_encoded_audio_format & a, const media_encoded_audio_format & b);
524_IMPEXP_MEDIA bool operator==(const media_video_display_info & a, const media_video_display_info & b);
525_IMPEXP_MEDIA bool operator==(const media_raw_video_format & a, const media_raw_video_format & b);
526_IMPEXP_MEDIA bool operator==(const media_encoded_video_format & a, const media_encoded_video_format & b);
527_IMPEXP_MEDIA bool operator==(const media_multistream_format::vid_info & a, const media_multistream_format::vid_info & b);
528_IMPEXP_MEDIA bool operator==(const media_multistream_format::avi_info & a, const media_multistream_format::avi_info & b);
529_IMPEXP_MEDIA bool operator==(const media_multistream_format & a, const media_multistream_format & b);
530_IMPEXP_MEDIA bool operator==(const media_format & a, const media_format & b);
531
532/* return true if a and b are compatible (accounting for wildcards) */
533_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 */
534_IMPEXP_MEDIA bool string_for_format(const media_format & f, char * buf, size_t size);
535
536struct media_seek_tag {
537	char data[16];
538};
539
540struct media_header_time_code {
541	int8	type;		//	See TimeCode.h; don't use the "DEFAULT" value
542	int8	_reserved;
543	int8	hours;
544	int8	minutes;
545	int8	seconds;
546	int8	frames;
547	int16	subframes;	//	-1 if not available
548};
549
550struct media_header {		// Broadcast() fills in fields marked with "//+"
551	media_type		type;			// what kind of data (for union)
552	media_buffer_id buffer;			//+ what buffer does this header go with?
553	int32			destination;	//+ what 'socket' is this intended for?
554	media_node_id	time_source;	// node that encoded start_time
555	uint32			_deprecated_;	// used to be change_tag
556	uint32			size_used;		// size within buffer that is used
557	bigtime_t		start_time;		// performance time
558	area_id			owner;			//+ buffer owner info area
559	enum {
560		B_SEEK_TAG = 'TRST',			// user data type of the codec seek
561									// protocol. size of seek tag is 16 bytes
562		B_TIME_CODE = 'TRTC'			//	user data is media_header_time_code
563	};
564	type_code		user_data_type;
565	uchar			user_data[64];	// user_data_type indicates what this is
566	uint32			_reserved_[2];
567
568	off_t			file_pos;		// where in a file this data came from
569	size_t			orig_size;		// and how big it was.  if unused, zero out
570
571	uint32			data_offset;	// offset within buffer (already reflected in Data())
572
573	union {
574		media_audio_header			raw_audio;
575		media_video_header			raw_video;
576		media_multistream_header	multistream;
577		media_encoded_audio_header	encoded_audio;
578		media_encoded_video_header	encoded_video;
579		char						_reserved_[64];		// pad to 64 bytes
580	} u;
581};
582
583
584struct media_file_format_id {
585	ino_t	node;
586	dev_t	device;
587	uint32	internal_id;
588};
589_IMPEXP_MEDIA bool operator==(const media_file_format_id & a, const media_file_format_id & b);
590_IMPEXP_MEDIA bool operator<(const media_file_format_id & a, const media_file_format_id & b);
591
592typedef enum {
593	B_ANY_FORMAT_FAMILY = 0,
594	B_BEOS_FORMAT_FAMILY = 1,
595	B_QUICKTIME_FORMAT_FAMILY = 2,	/* QuickTime is a registered trademark of Apple Computer */
596	B_AVI_FORMAT_FAMILY = 3,
597	B_ASF_FORMAT_FAMILY = 4,
598	B_MPEG_FORMAT_FAMILY = 5,
599	B_WAV_FORMAT_FAMILY = 6,
600	B_AIFF_FORMAT_FAMILY = 7,
601	B_AVR_FORMAT_FAMILY = 8,
602	B_OGG_FORMAT_FAMILY = 9,
603	B_MISC_FORMAT_FAMILY = 99999,
604	B_META_FORMAT_FAMILY = 100000
605} media_format_family;
606
607struct media_file_format {
608		enum {	/* flags */
609			B_READABLE = 0x1,
610			B_WRITABLE = 0x2,
611			B_PERFECTLY_SEEKABLE = 0x4,
612			B_IMPERFECTLY_SEEKABLE = 0x8,
613			B_KNOWS_RAW_VIDEO = 0x10,
614			B_KNOWS_RAW_AUDIO = 0x20,
615			B_KNOWS_MIDI = 0x40,
616			B_KNOWS_ENCODED_VIDEO = 0x80,
617			B_KNOWS_ENCODED_AUDIO = 0x100,
618			B_KNOWS_OTHER = 0x1000000,	/* clipping, text, control, ... */
619			B_KNOWS_ANYTHING = 0x2000000
620		};
621	uint32	capabilities;			// can this format support audio, video, etc
622	media_file_format_id	id;		// opaque id used to construct a BMediaFile
623	media_format_family family;		// one of the family enums
624	int32	version;				// 100 for 1.0
625
626	uint32		_reserved_[25];
627
628	char	mime_type[64];			// eg: "video/quicktime", "audio/aiff", etc
629	char	pretty_name[64];		// eg: "QuickTime File Format"
630	char	short_name[32];			// eg: "quicktime", "avi", "mpeg"
631	char	file_extension[8];		// eg: "mov", "avi", "mpg"
632	char	reserved[88];
633};
634
635
636//
637// Use this function iterate through available file format writers
638//
639status_t get_next_file_format(int32 *cookie, media_file_format *mfi);
640
641
642
643/* This struct is guaranteed to be large enough for any message your service */
644/* thread will get for any media_node -- 16k is an upper-bound size limit. */
645/* In your thread, read_port() into this struct, and call HandleMessage() on it. */
646const size_t B_MEDIA_MESSAGE_SIZE = 16384;
647
648_IMPEXP_MEDIA extern const char * B_MEDIA_SERVER_SIGNATURE;
649
650class media_node;	/* found in MediaNode.h */
651struct media_input;
652struct media_output;
653struct live_node_info;
654struct dormant_node_info;
655struct buffer_clone_info;
656
657
658//	If you for some reason need to get rid of the media_server (and friends)
659//	use these functions, rather than sending messages yourself.
660//	The callback will be called for various stages of the process, with 100 meaning completely done
661//	The callback should always return TRUE for the time being.
662status_t shutdown_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT, bool (*progress)(int stage, const char * message, void * cookie) = NULL, void * cookie = NULL);
663status_t launch_media_server(uint32 flags = 0);
664
665//	Given an image_id, prepare that image_id for realtime media
666//	If the kind of media indicated by "flags" is not enabled for real-time,
667//	B_MEDIA_REALTIME_DISABLED is returned.
668//	If there are not enough system resources to enable real-time performance,
669//	B_MEDIA_REALTIME_UNAVAILABLE is returned.
670status_t media_realtime_init_image(image_id image, uint32 flags);
671
672//	Given a thread ID, and an optional indication of what the thread is
673//	doing in "flags", prepare the thread for real-time media performance.
674//	Currently, this means locking the thread stack, up to size_used bytes,
675//	or all of it if 0 is passed. Typically, you will not be using all
676//	256 kB of the stack, so you should pass some smaller value you determine
677//	from profiling the thread; typically in the 32-64kB range.
678//	Return values are the same as for media_prepare_realtime_image().
679status_t media_realtime_init_thread(thread_id thread, size_t stack_used, uint32 flags);
680
681//	A teeny bit of legacy preserved for BSoundFile from R3.
682//	These came from the old MediaDefs.h; don't use them
683//	unless you get them from BSoundFile.
684
685/* values for byte_ordering */
686enum { B_BIG_ENDIAN, B_LITTLE_ENDIAN };
687
688/* values for sample_format */
689enum {
690  B_UNDEFINED_SAMPLES,
691  B_LINEAR_SAMPLES,
692  B_FLOAT_SAMPLES,
693  B_MULAW_SAMPLES
694  };
695
696
697/* for encoders and file writers */
698
699struct media_encode_info {
700	uint32		flags;					/* B_MEDIA_KEY_FRAME, set before every use */
701	int32		used_data_size;			/* data size used by other tracks */
702										/* add output size used by this encoder */
703	bigtime_t	start_time;				/* us from start of file */
704	bigtime_t	time_to_encode;			/* 0 - hurry up, B_INFINITE_TIMEOUT - don't care */
705	int32		_pad[22];
706	void		*file_format_data;		/* file format specific info */
707	size_t		file_format_data_size;
708	void		*codec_data;			/* codec specific info */
709	size_t		codec_data_size;
710
711	media_encode_info();
712};
713
714struct encode_parameters {
715	float		quality;				// 0.0-1.0 , 1.0 is high quality
716	int32		avg_field_size;			// in bytes
717	int32		max_field_size;			// in bytes
718	int32		_pad[27];
719	void		*user_data;				// codec specific info
720	size_t		user_data_size;
721};
722
723struct media_decode_info {
724	bigtime_t	time_to_decode;			/* 0 - hurry up, B_INFINITE_TIMEOUT - don't care */
725	int32		_pad[26];
726	void		*file_format_data;		/* file format specific info */
727	size_t		file_format_data_size;
728	void		*codec_data;			/* codec specific info */
729	size_t		codec_data_size;
730
731	media_decode_info();
732};
733
734
735#endif	//	__cplusplus
736
737#endif /* MEDIA_DEFS_H */
738