1d4d27facSStephan Aßmus/*
2d4d27facSStephan Aßmus * Copyright 2009, Haiku, Inc. All rights reserved.
3d4d27facSStephan Aßmus * Distributed under the terms of the MIT License.
4d4d27facSStephan Aßmus */
5d4d27facSStephan Aßmus#ifndef _MEDIA_DEFS_H
652a38012Sejakowatz#define _MEDIA_DEFS_H
8d4d27facSStephan Aßmus
9d4d27facSStephan Aßmus/*! Basic data types and defines for the Media Kit. */
10d4d27facSStephan Aßmus
11d4d27facSStephan Aßmus
1252a38012Sejakowatz#include <OS.h>
1352a38012Sejakowatz#include <ByteOrder.h>
1552a38012Sejakowatz#if defined(__cplusplus)
16d4d27facSStephan Aßmus#	include <GraphicsDefs.h>
17d4d27facSStephan Aßmus#	include <Looper.h>
18841d719fSAugustin Cavalierclass media_node;
19841d719fSAugustin Cavalier#else
20841d719fSAugustin Cavalierstruct media_node;
23d4d27facSStephan Aßmus
2452a38012Sejakowatz#define B_MEDIA_NAME_LENGTH 64
27d4d27facSStephan Aßmus/* Notification messages 'what' fields */
2852a38012Sejakowatzenum {
29d4d27facSStephan Aßmus	/* Note that BMediaNode::node_error also belongs in here! */
30d4d27facSStephan Aßmus	B_MEDIA_WILDCARD		= 'TRWC',
31d4d27facSStephan Aßmus									/* Used to match any notification in */
32d4d27facSStephan Aßmus									/* Start/StopWatching */
33d4d27facSStephan Aßmus	B_MEDIA_NODE_CREATED	= 'TRIA',
34d4d27facSStephan Aßmus									/* "media_node_id" (multiple items) */
3552a38012Sejakowatz	B_MEDIA_NODE_DELETED,			/* "media_node_id" (multiple items) */
3652a38012Sejakowatz	B_MEDIA_CONNECTION_MADE,		/* "output", "input", "format" */
3752a38012Sejakowatz	B_MEDIA_CONNECTION_BROKEN,		/* "source", "destination" */
38d4d27facSStephan Aßmus	B_MEDIA_BUFFER_CREATED,			/* "clone_info" -- handled by */
39d4d27facSStephan Aßmus									/* BMediaRoster */
40d4d27facSStephan Aßmus	B_MEDIA_BUFFER_DELETED,			/* "media_buffer_id" -- handled by */
41d4d27facSStephan Aßmus									/* BMediaRoster */
4252a38012Sejakowatz	B_MEDIA_TRANSPORT_STATE,		/* "state", "location", "realtime" */
4352a38012Sejakowatz	B_MEDIA_PARAMETER_CHANGED,		/* N "node", "parameter" */
4452a38012Sejakowatz	B_MEDIA_FORMAT_CHANGED,			/* N "source", "destination", "format" */
4552a38012Sejakowatz	B_MEDIA_WEB_CHANGED,			/* N "node" */
46d4d27facSStephan Aßmus	B_MEDIA_DEFAULT_CHANGED,		/* "default", "node" -- handled by */
47d4d27facSStephan Aßmus									/* BMediaRoster */
48d4d27facSStephan Aßmus	B_MEDIA_NEW_PARAMETER_VALUE,	/* N "node", "parameter", "when", */
49d4d27facSStephan Aßmus									/* "value" */
5052a38012Sejakowatz	B_MEDIA_NODE_STOPPED,			/* N "node", "when" */
5132afe10aSDario Casalinuovo	B_MEDIA_FLAVORS_CHANGED,		/* "be:addon_id", "be:new_count", */
52d4d27facSStephan Aßmus									/* "be:gone_count" */
5332afe10aSDario Casalinuovo	B_MEDIA_SERVER_STARTED,
5432afe10aSDario Casalinuovo	B_MEDIA_SERVER_QUIT
57d4d27facSStephan Aßmus
5852a38012Sejakowatzenum media_type {
59d4d27facSStephan Aßmus	B_MEDIA_NO_TYPE			= -1,
60d4d27facSStephan Aßmus	B_MEDIA_UNKNOWN_TYPE	= 0,
61d4d27facSStephan Aßmus	B_MEDIA_RAW_AUDIO		= 1,	/* uncompressed raw_audio */
62d4d27facSStephan Aßmus	B_MEDIA_RAW_VIDEO,				/* uncompressed raw_video */
6352a38012Sejakowatz	B_MEDIA_VBL,					/* raw data from VBL area, 1600/line */
6452a38012Sejakowatz	B_MEDIA_TIMECODE,				/* data format TBD */
6552a38012Sejakowatz	B_MEDIA_MIDI,
6652a38012Sejakowatz	B_MEDIA_TEXT,					/* typically closed captioning */
6752a38012Sejakowatz	B_MEDIA_HTML,
6852a38012Sejakowatz	B_MEDIA_MULTISTREAM,			/* AVI, etc */
6952a38012Sejakowatz	B_MEDIA_PARAMETERS,				/* BControllable change data */
70d4d27facSStephan Aßmus	B_MEDIA_ENCODED_AUDIO,			/* MP3, AC-3, ... */
71d4d27facSStephan Aßmus	B_MEDIA_ENCODED_VIDEO,			/* H.264, Theora, ... */
72d4d27facSStephan Aßmus	B_MEDIA_PRIVATE			= 90000,
73d4d27facSStephan Aßmus									/* This are reserved. */
74d4d27facSStephan Aßmus	B_MEDIA_FIRST_USER_TYPE	= 100000
75d4d27facSStephan Aßmus									/* Use something bigger than this for */
76d4d27facSStephan Aßmus									/* experimentation with your own media */
77d4d27facSStephan Aßmus									/* formats. */
80d4d27facSStephan Aßmus
8152a38012Sejakowatzenum node_kind {
82d4d27facSStephan Aßmus	B_BUFFER_PRODUCER		= 0x1,
83d4d27facSStephan Aßmus	B_BUFFER_CONSUMER		= 0x2,
84d4d27facSStephan Aßmus	B_TIME_SOURCE			= 0x4,
85d4d27facSStephan Aßmus	B_CONTROLLABLE			= 0x8,
86d4d27facSStephan Aßmus	B_FILE_INTERFACE		= 0x10,
87d4d27facSStephan Aßmus	B_ENTITY_INTERFACE		= 0x20,
88d4d27facSStephan Aßmus
89d4d27facSStephan Aßmus	/* Set these flags for nodes that are suitable as default system nodes. */
90d4d27facSStephan Aßmus	B_PHYSICAL_INPUT		= 0x10000,
91d4d27facSStephan Aßmus	B_PHYSICAL_OUTPUT		= 0x20000,
92d4d27facSStephan Aßmus	B_SYSTEM_MIXER			= 0x40000
93d4d27facSStephan Aßmus};
94d4d27facSStephan Aßmus
95d4d27facSStephan Aßmus
96d4d27facSStephan Aßmusenum video_orientation {
97d4d27facSStephan Aßmus	/* Which pixel is first and how do we scan each "line"? */
98d4d27facSStephan Aßmus	B_VIDEO_TOP_LEFT_RIGHT	= 1,	/* This is the typical progressive scan */
99d4d27facSStephan Aßmus									/* format */
10052a38012Sejakowatz	B_VIDEO_BOTTOM_LEFT_RIGHT		/* This is how BMP and TGA might scan */
104d4d27facSStephan Aßmus/* data */
105d4d27facSStephan Aßmusenum media_flags
107d4d27facSStephan Aßmus	B_MEDIA_FLAGS_VERSION			= 1,
108d4d27facSStephan Aßmus									/* uint32, greater for newer versions */
109d4d27facSStephan Aßmus	B_MEDIA_FLAGS_PRIVATE			= 0x40000000
110d4d27facSStephan Aßmus									/* private to Haiku */
114d4d27facSStephan Aßmus/* for producer status */
115d4d27facSStephan Aßmusenum media_producer_status {
116d4d27facSStephan Aßmus	B_DATA_NOT_AVAILABLE			= 1,
117d4d27facSStephan Aßmus	B_DATA_AVAILABLE				= 2,
118d4d27facSStephan Aßmus	B_PRODUCER_STOPPED				= 3
121d4d27facSStephan Aßmus
122d4d27facSStephan Aßmus/* realtime flags */
12352a38012Sejakowatzenum media_realtime_flags {
124d4d27facSStephan Aßmus	B_MEDIA_REALTIME_ALLOCATOR		= 0x1,
125d4d27facSStephan Aßmus	B_MEDIA_REALTIME_AUDIO			= 0x2,
126d4d27facSStephan Aßmus	B_MEDIA_REALTIME_VIDEO			= 0x4,
127d4d27facSStephan Aßmus	B_MEDIA_REALTIME_ANYKIND		= 0xffff
13052a38012Sejakowatzenum media_frame_flags {
131d4d27facSStephan Aßmus	B_MEDIA_KEY_FRAME				= 0x1
134d4d27facSStephan Aßmus#define B_MEDIA_ANY_QUALITY			0.0f
135d4d27facSStephan Aßmus#define B_MEDIA_LOW_QUALITY			0.1f
136d4d27facSStephan Aßmus#define B_MEDIA_MEDIUM_QUALITY		0.5f
137d4d27facSStephan Aßmus#define B_MEDIA_HIGH_QUALITY		1.0f
140d4d27facSStephan Aßmus#ifndef _MULTI_AUDIO_H	/* #define in protocol header */
14152a38012Sejakowatzenum media_multi_channels {
142d4d27facSStephan Aßmus	B_CHANNEL_LEFT					= 0x00001,
143d4d27facSStephan Aßmus	B_CHANNEL_RIGHT					= 0x00002,
144d4d27facSStephan Aßmus	B_CHANNEL_CENTER				= 0x00004,	/* 5.1+ or fake surround */
145d4d27facSStephan Aßmus	B_CHANNEL_SUB					= 0x00008,	/* 5.1+ */
146d4d27facSStephan Aßmus	B_CHANNEL_REARLEFT				= 0x00010,	/* quad surround or 5.1+ */
147d4d27facSStephan Aßmus	B_CHANNEL_REARRIGHT				= 0x00020,	/* quad surround or 5.1+ */
148d4d27facSStephan Aßmus	B_CHANNEL_FRONT_LEFT_CENTER		= 0x00040,
149d4d27facSStephan Aßmus	B_CHANNEL_FRONT_RIGHT_CENTER	= 0x00080,
150d4d27facSStephan Aßmus	B_CHANNEL_BACK_CENTER			= 0x00100,	/* 6.1 or fake surround */
151d4d27facSStephan Aßmus	B_CHANNEL_SIDE_LEFT				= 0x00200,
152d4d27facSStephan Aßmus	B_CHANNEL_SIDE_RIGHT			= 0x00400,
153d4d27facSStephan Aßmus	B_CHANNEL_TOP_CENTER			= 0x00800,
154d4d27facSStephan Aßmus	B_CHANNEL_TOP_FRONT_LEFT		= 0x01000,
155d4d27facSStephan Aßmus	B_CHANNEL_TOP_FRONT_CENTER		= 0x02000,
156d4d27facSStephan Aßmus	B_CHANNEL_TOP_FRONT_RIGHT		= 0x04000,
157d4d27facSStephan Aßmus	B_CHANNEL_TOP_BACK_LEFT			= 0x08000,
158d4d27facSStephan Aßmus	B_CHANNEL_TOP_BACK_CENTER		= 0x10000,
159d4d27facSStephan Aßmus	B_CHANNEL_TOP_BACK_RIGHT		= 0x20000
161d4d27facSStephan Aßmus
162d4d27facSStephan Aßmus
16352a38012Sejakowatzenum media_multi_matrix {
164d4d27facSStephan Aßmus	B_MATRIX_PROLOGIC_LR			= 0x1,
165d4d27facSStephan Aßmus	B_MATRIX_AMBISONIC_WXYZ			= 0x4
167d4d27facSStephan Aßmus#endif // !_MULTI_AUDIO_H
17052a38012Sejakowatztypedef int32 media_node_id;
17152a38012Sejakowatztypedef int32 media_buffer_id;
17252a38012Sejakowatztypedef int32 media_addon_id;
17552a38012Sejakowatz#if defined(__cplusplus)
17652a38012Sejakowatzstruct media_destination {
177d4d27facSStephan Aßmus								media_destination();
178d4d27facSStephan Aßmus								media_destination(port_id, int32);
179d4d27facSStephan Aßmus								media_destination(
180d4d27facSStephan Aßmus									const media_destination& other);
181d4d27facSStephan Aßmus								~media_destination();
182d4d27facSStephan Aßmus
183d4d27facSStephan Aßmus			media_destination&	operator=(const media_destination& other);
184d4d27facSStephan Aßmus
185d4d27facSStephan Aßmus			port_id				port;	/* can be different from */
186d4d27facSStephan Aßmus										/* media_node.port */
187d4d27facSStephan Aßmus			int32				id;
188d4d27facSStephan Aßmus	static	media_destination	null;
189d4d27facSStephan Aßmus
191d4d27facSStephan Aßmus			uint32				_reserved_media_destination_[2];
194d4d27facSStephan Aßmus
19552a38012Sejakowatzstruct media_source {
196d4d27facSStephan Aßmus								media_source();
197d4d27facSStephan Aßmus								media_source(port_id, int32);
198d4d27facSStephan Aßmus								media_source(const media_source& other);
199d4d27facSStephan Aßmus								~media_source();
200d4d27facSStephan Aßmus
201d4d27facSStephan Aßmus			media_source&		operator=(const media_source& other);
202d4d27facSStephan Aßmus			port_id				port;	/* must be the same as */
203d4d27facSStephan Aßmus										/* media_node.port for owner */
204d4d27facSStephan Aßmus			int32				id;
205d4d27facSStephan Aßmus	static	media_source		null;
206d4d27facSStephan Aßmus
208d4d27facSStephan Aßmus			uint32				_reserved_media_source_[2];
211d4d27facSStephan Aßmus
212d4d27facSStephan Aßmusbool operator==(const media_destination& a, const media_destination& b);
213d4d27facSStephan Aßmusbool operator!=(const media_destination& a, const media_destination& b);
214d4d27facSStephan Aßmusbool operator<(const media_destination& a, const media_destination& b);
215d4d27facSStephan Aßmusbool operator==(const media_source& a, const media_source& b);
216d4d27facSStephan Aßmusbool operator!=(const media_source& a, const media_source& b);
217d4d27facSStephan Aßmusbool operator<(const media_source& a, const media_source& b);
218d4d27facSStephan Aßmusbool operator==(const media_node& a, const media_node& b);
219d4d27facSStephan Aßmusbool operator!=(const media_node& a, const media_node& b);
220d4d27facSStephan Aßmusbool operator<(const media_node& a, const media_node& b);
22452a38012Sejakowatz/* Buffers are low-level constructs identified by an ID. */
22552a38012Sejakowatz/* Buffers consist of the actual data area, plus a 64-byte */
22652a38012Sejakowatz/* header area that is different for each type. */
22752a38012Sejakowatz/* Buffers contain typed data. Type is not part of the */
22852a38012Sejakowatz/* buffer header; it's negotiated out-of-bounds by nodes. */
23052a38012Sejakowatzenum {
231d4d27facSStephan Aßmus	B_MEDIA_BIG_ENDIAN			= 1,
232d4d27facSStephan Aßmus	B_MEDIA_LITTLE_ENDIAN		= 2,
23352a38012Sejakowatz#if B_HOST_IS_BENDIAN
234d4d27facSStephan Aßmus	B_MEDIA_HOST_ENDIAN			= B_MEDIA_BIG_ENDIAN
240d4d27facSStephan Aßmus
24152a38012Sejakowatzstruct media_multi_audio_format;
243d4d27facSStephan Aßmus
24452a38012Sejakowatzstruct media_raw_audio_format {
245d4d27facSStephan Aßmus	// possible values for "format"
246d4d27facSStephan Aßmus	enum {
247d4d27facSStephan Aßmus		B_AUDIO_FLOAT		= 0x24,
248d4d27facSStephan Aßmus			// 0 == mid, -1.0 == bottom, 1.0 == top
249d4d27facSStephan Aßmus			// (the preferred format for non-game audio)
250d4d27facSStephan Aßmus
251d4d27facSStephan Aßmus		B_AUDIO_DOUBLE		= 0x28,
252d4d27facSStephan Aßmus			// 0 == mid, -1.0 == bottom, 1.0 == top
253d4d27facSStephan Aßmus			// (only useful for pro audio)
254d4d27facSStephan Aßmus
255d4d27facSStephan Aßmus		B_AUDIO_INT			= 0x4,
256d4d27facSStephan Aßmus			// 0 == mid, 0x80000001 == bottom, 0x7fffffff == top
257d4d27facSStephan Aßmus			// (all >16-bit formats, left-adjusted)
258d4d27facSStephan Aßmus
259d4d27facSStephan Aßmus		B_AUDIO_SHORT		= 0x2,
260d4d27facSStephan Aßmus			// 0 == mid, -32767 == bottom, +32767 == top
261d4d27facSStephan Aßmus
262d4d27facSStephan Aßmus		B_AUDIO_UCHAR		= 0x11,
263d4d27facSStephan Aßmus			// 128 == mid, 1 == bottom, 255 == top
264d4d27facSStephan Aßmus			// (discouraged but supported format)
265d4d27facSStephan Aßmus
266d4d27facSStephan Aßmus		B_AUDIO_CHAR		= 0x1,
267d4d27facSStephan Aßmus			// 0 == mid, -127 == bottom, +127 == top
268d4d27facSStephan Aßmus			// (not officially supported format)
269d4d27facSStephan Aßmus
270d4d27facSStephan Aßmus		B_AUDIO_SIZE_MASK	= 0xf
271d4d27facSStephan Aßmus			// This mask can be used to obtain the sample size
272d4d27facSStephan Aßmus			// for raw formats: (format & 0xf) == sizeof(sample)
273d4d27facSStephan Aßmus	};
27552a38012Sejakowatz	float		frame_rate;
276d4d27facSStephan Aßmus	uint32		channel_count;
277d4d27facSStephan Aßmus	uint32		format;			// see possible values above
278d4d27facSStephan Aßmus	uint32		byte_order;		// B_MEDIA_LITTLE_ENDIAN or B_MEDIA_BIG_ENDIAN
279d4d27facSStephan Aßmus	size_t		buffer_size;	// size of each buffer
281d4d27facSStephan Aßmus	static media_multi_audio_format wildcard;
284d4d27facSStephan Aßmus
28552a38012Sejakowatzstruct media_audio_header {
28622ea661bSColin Günther	// TODO: Refine this structure and put actual data at the end
28722ea661bSColin Günther	int32		_reserved_[14];
28822ea661bSColin Günther	float       frame_rate;
28922ea661bSColin Günther	uint32      channel_count;
29022ea661bSColin Günther
293d4d27facSStephan Aßmus
29452a38012Sejakowatzstruct media_multi_audio_info {
295d4d27facSStephan Aßmus	uint32		channel_mask;	// bitmask
296d4d27facSStephan Aßmus	int16		valid_bits;		// if < 32, for B_AUDIO_INT
297d4d27facSStephan Aßmus	uint16		matrix_mask;	// each of these bits may mean more than one
298d4d27facSStephan Aßmus								// channel
30052a38012Sejakowatz	uint32		_reserved_b[3];
303d4d27facSStephan Aßmus
304d4d27facSStephan Aßmusstruct media_multi_audio_format : public media_raw_audio_format,
305d4d27facSStephan Aßmus	public media_multi_audio_info {
306d4d27facSStephan Aßmus
307d4d27facSStephan Aßmus	static media_multi_audio_format wildcard;
31152a38012Sejakowatzstruct media_encoded_audio_format {
31252a38012Sejakowatz	enum audio_encoding {
31352a38012Sejakowatz		B_ANY
31452a38012Sejakowatz	};
315d4d27facSStephan Aßmus
31652a38012Sejakowatz	media_raw_audio_format	output;
31752a38012Sejakowatz	audio_encoding			encoding;
319d4d27facSStephan Aßmus	float					bit_rate;
32052a38012Sejakowatz	size_t					frame_size;
32252a38012Sejakowatz	media_multi_audio_info	multi_info;
32452a38012Sejakowatz	uint32					_reserved_[3];
326d4d27facSStephan Aßmus	static media_encoded_audio_format wildcard;
329d4d27facSStephan Aßmus
33052a38012Sejakowatzstruct media_encoded_audio_header {
331d4d27facSStephan Aßmus	// NOTE: More data fields need to go to the end
332d4d27facSStephan Aßmus	int32		_reserved_0[14];
333d4d27facSStephan Aßmus
334d4d27facSStephan Aßmus	uint32		buffer_flags;
335d4d27facSStephan Aßmus		// B_MEDIA_KEY_FRAME for key frame chunks
336d4d27facSStephan Aßmus	uchar		unused_mask;
337d4d27facSStephan Aßmus		// mask of unused bits for the last byte of data
33852a38012Sejakowatz	uchar		_reserved_2[3];
34252a38012Sejakowatzenum media_display_flags {
343d4d27facSStephan Aßmus	B_F1_DOMINANT		= 0x1,	// The first buffer sent (temporally) will
344d4d27facSStephan Aßmus								// be an F1 field.
345d4d27facSStephan Aßmus	B_F2_DOMINANT		= 0x2,	// The first buffer sent (temporally) will
346d4d27facSStephan Aßmus								// be an F2 field.
347d4d27facSStephan Aßmus	B_TOP_SCANLINE_F1	= 0x4,	// The topmost scanline of the output buffer
348d4d27facSStephan Aßmus								// belongs to F1.
349d4d27facSStephan Aßmus	B_TOP_SCANLINE_F2	= 0x8	// The topmost scanline of the output buffer
350d4d27facSStephan Aßmus								// belongs to F2.
352d4d27facSStephan Aßmus
353d4d27facSStephan Aßmus
35452a38012Sejakowatzstruct media_video_display_info {
35552a38012Sejakowatz	color_space	format;
35652a38012Sejakowatz	uint32		line_width;
357d4d27facSStephan Aßmus	uint32		line_count;		// sum of all interlace fields lines
358d4d27facSStephan Aßmus	uint32		bytes_per_row;	// bytes_per_row is in format, not header,
359d4d27facSStephan Aßmus								// because it's part of SetBuffers
360d4d27facSStephan Aßmus	uint32		pixel_offset;	// (in pixels) Offset from the start of the
361d4d27facSStephan Aßmus								// buffer (see below).
362d4d27facSStephan Aßmus	uint32		line_offset;	// (in lines) Offset to the start of the field.
363d4d27facSStephan Aßmus								// Think "buffer == framebuffer" when the
364d4d27facSStephan Aßmus								// window displaying the active field moves
365d4d27facSStephan Aßmus								// on screen.
36652a38012Sejakowatz	uint32		flags;
36752a38012Sejakowatz	uint32		_reserved_[3];
368d4d27facSStephan Aßmus
369d4d27facSStephan Aßmus	static media_video_display_info wildcard;
372d4d27facSStephan Aßmus
37352a38012Sejakowatzstruct media_raw_video_format {
37452a38012Sejakowatz	float		field_rate;
375d4d27facSStephan Aßmus	uint32		interlace;		// Number of fields per frame: 1 means
376d4d27facSStephan Aßmus								// progressive (non-interlaced) frames.
377d4d27facSStephan Aßmus	uint32		first_active;	// Index of first active line. 0, typically
378d4d27facSStephan Aßmus								// (wildcard, or "don't care")
379d4d27facSStephan Aßmus	uint32		last_active;	// Index of last active line (typically
380d4d27facSStephan Aßmus								// line_count - 1, if first_active is 0.
381d4d27facSStephan Aßmus	uint32		orientation;	// B_VIDEO_TOP_LEFT_RIGHT is preferred.
382d4d27facSStephan Aßmus
383d4d27facSStephan Aßmus	// This is the display aspect ratio (DAR). Usually, you would reduce the
384d4d27facSStephan Aßmus	// width and height of the intended output frame size as far as possible
385d4d27facSStephan Aßmus	// without changing their ratio. Note that you should not put 1 in both
386d4d27facSStephan Aßmus	// fields to mean "undistorted pixels", unless you really intend square
387d4d27facSStephan Aßmus	// video output!
38852a38012Sejakowatz	uint16		pixel_width_aspect;		// 1:1 has 1 here, 4:3 has 4 here
389d4d27facSStephan Aßmus										// 16:9 has 16 here!
39052a38012Sejakowatz	uint16		pixel_height_aspect;	// 1:1 has 1 here, 4:3 has 3 here
391d4d27facSStephan Aßmus										// 16:9 has 9 here!
39352a38012Sejakowatz	media_video_display_info	display;
395d4d27facSStephan Aßmus	static media_raw_video_format wildcard;
398d4d27facSStephan Aßmus
39952a38012Sejakowatzstruct media_video_header {
40022ea661bSColin Günther	uint32		_reserved_[8];		// NOTE: Keep reserved data at the top!
40122ea661bSColin Günther
40222ea661bSColin Günther	uint32      display_line_width; // Number of pixels per display_line
40322ea661bSColin Günther	uint32      display_line_count;	// Sum of all interlace fields lines
40422ea661bSColin Günther	uint32      bytes_per_row;		// Number of bytes in a display_line
4052b1481f0SAugustin Cavalier									// (padding bytes excluded)
40622ea661bSColin Günther	uint16      pixel_width_aspect;	// 1:1 has 1 here, 4:3 has 4 here
40722ea661bSColin Günther									// 16:9 has 16 here!
40822ea661bSColin Günther	uint16      pixel_height_aspect;// 1:1 has 1 here, 4:3 has 3 here
40922ea661bSColin Günther									// 16:9 has 9 here!
41052a38012Sejakowatz	float		field_gamma;
411d4d27facSStephan Aßmus	uint32		field_sequence;		// Sequence number since start of capture
412d4d27facSStephan Aßmus									// May roll over if machine is on for a
413d4d27facSStephan Aßmus									// LONG time.
414d4d27facSStephan Aßmus	uint16		field_number;		// 0 .. {interlace-1}; F1 == 0 ("odd"),
415d4d27facSStephan Aßmus									// F2 == 1 ("even")
41652a38012Sejakowatz	uint16		pulldown_number;	// 0..2 for pulldown duplicated sequence
417d4d27facSStephan Aßmus	uint16		first_active_line;	// The NTSC/PAL line number (1-based) of
418d4d27facSStephan Aßmus									// the first line in this field
419d4d27facSStephan Aßmus	uint16		line_count;			// The number of active lines in buffer.
422d4d27facSStephan Aßmus
42352a38012Sejakowatzstruct media_encoded_video_format {
42452a38012Sejakowatz	enum video_encoding {
42552a38012Sejakowatz		B_ANY
42652a38012Sejakowatz	};
427d4d27facSStephan Aßmus
42852a38012Sejakowatz	media_raw_video_format	output;				// set unknowns to wildcard
429d4d27facSStephan Aßmus
43052a38012Sejakowatz	float					avg_bit_rate;
43152a38012Sejakowatz	float					max_bit_rate;
432d4d27facSStephan Aßmus
43352a38012Sejakowatz	video_encoding			encoding;
43452a38012Sejakowatz	size_t					frame_size;
436d4d27facSStephan Aßmus	int16					forward_history;	// maximum forward memory
437d4d27facSStephan Aßmus												// required by codec
438d4d27facSStephan Aßmus
439d4d27facSStephan Aßmus	int16					backward_history;	// maximum backward memory
440d4d27facSStephan Aßmus												// required by codec
441d4d27facSStephan Aßmus
442d4d27facSStephan Aßmus	uint32					_reserved_[3];		// This structure cannot grow
443d4d27facSStephan Aßmus												// more than this (embedded)
444d4d27facSStephan Aßmus												// in media_format union
446d4d27facSStephan Aßmus	static media_encoded_video_format wildcard;
449d4d27facSStephan Aßmus
45052a38012Sejakowatzstruct media_encoded_video_header {
451d4d27facSStephan Aßmus	// NOTE: More data fields need to go at the end of this structure.
452d4d27facSStephan Aßmus	int32		_reserved_1[9];
45452a38012Sejakowatz	uint32		field_flags;		//	B_MEDIA_KEY_FRAME
456d4d27facSStephan Aßmus	int16		forward_history;	// forward memory required by this buffer
457d4d27facSStephan Aßmus									// (0 for key frames)
458d4d27facSStephan Aßmus
459d4d27facSStephan Aßmus	int16		backward_history;	// backward memory required by this buffer
460d4d27facSStephan Aßmus									// (0 for key frames)
461d4d27facSStephan Aßmus
462d4d27facSStephan Aßmus	uchar		unused_mask;		// mask of unused bits for the last byte
463d4d27facSStephan Aßmus									// of data
46452a38012Sejakowatz	uchar		_reserved_2[3];
46552a38012Sejakowatz	float		field_gamma;
46652a38012Sejakowatz	uint32		field_sequence;		// sequence since start of capture
46752a38012Sejakowatz	uint16		field_number;		// 0 .. {interlace-1};  F1 == 0, F2 == 1
46852a38012Sejakowatz	uint16		pulldown_number;	// 0..2 for pulldown duplicated sequence
469d4d27facSStephan Aßmus	uint16		first_active_line;	// 0 or 1, typically, but could be 10 or
470d4d27facSStephan Aßmus									// 11 for full-NTSC formats
47152a38012Sejakowatz	uint16		line_count;			// number of actual lines in buffer
47452a38012Sejakowatzstruct media_multistream_format {
47552a38012Sejakowatz	enum {
476d4d27facSStephan Aßmus		B_ANY					= 0,
477d4d27facSStephan Aßmus		B_VID					= 1,	// raw raw_video/raw_audio buffers
47852a38012Sejakowatz		B_AVI,
47952a38012Sejakowatz		B_MPEG1,
48052a38012Sejakowatz		B_MPEG2,
48152a38012Sejakowatz		B_QUICKTIME,
482d4d27facSStephan Aßmus		B_PRIVATE				= 90000,
483d4d27facSStephan Aßmus		B_FIRST_USER_TYPE		= 100000
48452a38012Sejakowatz	};
485d4d27facSStephan Aßmus	float		avg_bit_rate;			// 8 * byte rate, on average
486d4d27facSStephan Aßmus	float		max_bit_rate;			// 8 * byte rate, tops
487d4d27facSStephan Aßmus	uint32		avg_chunk_size;			// == max_chunk_size for fixed-size
488d4d27facSStephan Aßmus										// chunks
489d4d27facSStephan Aßmus	uint32		max_chunk_size;			// max buffer size
49052a38012Sejakowatz	enum {
491d4d27facSStephan Aßmus		B_HEADER_HAS_FLAGS		= 0x1,	// are flags important?
492d4d27facSStephan Aßmus		B_CLEAN_BUFFERS			= 0x2,	// each buffer represents an integral
493d4d27facSStephan Aßmus										// number of "frames"
494d4d27facSStephan Aßmus		B_HOMOGENOUS_BUFFERS	= 0x4	// a buffer has only one format in it
49552a38012Sejakowatz	};
49652a38012Sejakowatz	uint32		flags;
49752a38012Sejakowatz	int32		format;
49852a38012Sejakowatz	uint32		_reserved_[2];
50052a38012Sejakowatz	struct vid_info {
501d4d27facSStephan Aßmus		float		frame_rate;
502d4d27facSStephan Aßmus		uint16		width;
503d4d27facSStephan Aßmus		uint16		height;
504d4d27facSStephan Aßmus		color_space	space;
505d4d27facSStephan Aßmus
506d4d27facSStephan Aßmus		float		sampling_rate;
507d4d27facSStephan Aßmus		uint32		sample_format;
508d4d27facSStephan Aßmus		uint16		byte_order;
509d4d27facSStephan Aßmus		uint16		channel_count;
51052a38012Sejakowatz	};
51152a38012Sejakowatz	struct avi_info {
512d4d27facSStephan Aßmus		uint32		us_per_frame;
513d4d27facSStephan Aßmus		uint16		width;
514d4d27facSStephan Aßmus		uint16		height;
515d4d27facSStephan Aßmus		uint16		_reserved_;
516d4d27facSStephan Aßmus		uint16		type_count;
517d4d27facSStephan Aßmus		media_type	types[5];
51852a38012Sejakowatz	};
52052a38012Sejakowatz	union {
52152a38012Sejakowatz		vid_info	vid;
52252a38012Sejakowatz		avi_info	avi;
523d4d27facSStephan Aßmus	} 			u;
525d4d27facSStephan Aßmus	static media_multistream_format wildcard;
528d4d27facSStephan Aßmus
52952a38012Sejakowatzstruct media_multistream_header {
530d4d27facSStephan Aßmus	uint32	_reserved_[14];
531d4d27facSStephan Aßmus	uchar	unused_mask;			// mask of unused bits for the last byte
532d4d27facSStephan Aßmus									// of data
53352a38012Sejakowatz	uchar	_reserved_2[3];
53452a38012Sejakowatz	enum {
535d4d27facSStephan Aßmus		B_MASTER_HEADER		= 0x1,	// for master stream header data in buffer
536d4d27facSStephan Aßmus		B_SUBSTREAM_HEADER	= 0x2,	// for sub-stream header data in buffer
537d4d27facSStephan Aßmus		B_COMPLETE_BUFFER	= 0x4	// data is an integral number of "frames"
53852a38012Sejakowatz	};
53952a38012Sejakowatz	uint32 	flags;
542d4d27facSStephan Aßmus
54352a38012Sejakowatzextern const type_code B_CODEC_TYPE_INFO;
545d4d27facSStephan Aßmus
54652a38012Sejakowatzenum media_format_flags {
547d4d27facSStephan Aßmus	B_MEDIA_RETAINED_DATA			= 0x1,
548d4d27facSStephan Aßmus	B_MEDIA_MULTIPLE_BUFFERS		= 0x2,
549d4d27facSStephan Aßmus	B_MEDIA_CONTIGUOUS_BUFFER		= 0x4,
550d4d27facSStephan Aßmus	B_MEDIA_LINEAR_UPDATES			= 0x8,
551d4d27facSStephan Aßmus	B_MEDIA_MAUI_UNDEFINED_FLAGS	= ~0xf	// NOTE: Always deny these flags
552d4d27facSStephan Aßmus											// in new code.
555d4d27facSStephan Aßmus// NOTE: A field of 0 typically means "anything" or "wildcard".
556d4d27facSStephan Aßmus// NOTE: This structure should not be bigger than 192 bytes!
557d4d27facSStephan Aßmusstruct media_format {
55852a38012Sejakowatz	media_type						type;
55952a38012Sejakowatz	type_code						user_data_type;
56052a38012Sejakowatz	uchar							user_data[48];
56152a38012Sejakowatz	uint32							_reserved_[3];
562d4d27facSStephan Aßmus	uint16							require_flags;	//	media_format_flags
563d4d27facSStephan Aßmus	uint16							deny_flags;		//	media_format_flags
565d4d27facSStephan Aßmusprivate:
566d4d27facSStephan Aßmus	void*							meta_data;
56752a38012Sejakowatz	int32							meta_data_size;
56852a38012Sejakowatz	area_id							meta_data_area;
5690a00d23fSMarcus Overhagen	area_id							__unused_was_use_area;
5700a00d23fSMarcus Overhagen	team_id							__unused_was_team;
571d4d27facSStephan Aßmus	void*							__unused_was_thisPtr;
573d4d27facSStephan Aßmuspublic:
57452a38012Sejakowatz	union {
57552a38012Sejakowatz		media_multi_audio_format	raw_audio;
57652a38012Sejakowatz		media_raw_video_format		raw_video;
57752a38012Sejakowatz		media_multistream_format	multistream;
57852a38012Sejakowatz		media_encoded_audio_format	encoded_audio;
57952a38012Sejakowatz		media_encoded_video_format	encoded_video;
58052a38012Sejakowatz		char						_reserved_[96];	 // pad to 96 bytes
58152a38012Sejakowatz	} u;
582d4d27facSStephan Aßmus
583d4d27facSStephan Aßmus	bool 			IsVideo() const;
584d4d27facSStephan Aßmus
585d4d27facSStephan Aßmus	uint32  		Width() const;
586d4d27facSStephan Aßmus	uint32 			Height() const;
587d4d27facSStephan Aßmus	color_space  	ColorSpace() const;
588d4d27facSStephan Aßmus
589d4d27facSStephan Aßmus	uint32& 		Width();
590d4d27facSStephan Aßmus	uint32& 		Height();
591d4d27facSStephan Aßmus	color_space& 	ColorSpace();
592d4d27facSStephan Aßmus
593d4d27facSStephan Aßmus	bool 			IsAudio() const;
594d4d27facSStephan Aßmus	uint32 			AudioFormat() const;
595d4d27facSStephan Aßmus	uint32& 		AudioFormat();
596d4d27facSStephan Aßmus	uint32 			AudioFrameSize() const;
597d4d27facSStephan Aßmus
598d4d27facSStephan Aßmus	uint32			Encoding() const;
599d4d27facSStephan Aßmus
600d4d27facSStephan Aßmus	bool			Matches(const media_format* other) const;
601d4d27facSStephan Aßmus	void			SpecializeTo(const media_format* other);
602d4d27facSStephan Aßmus
603d4d27facSStephan Aßmus	status_t		SetMetaData(const void* data, size_t size);
604d4d27facSStephan Aßmus	const void*		MetaData() const;
60552a38012Sejakowatz	int32			MetaDataSize() const;
60712ed45b6SMurai Takashi	void			Unflatten(const char *flatBuffer);
60812ed45b6SMurai Takashi	void			Clear();
60912ed45b6SMurai Takashi
61052a38012Sejakowatz					media_format();
611d4d27facSStephan Aßmus					media_format(const media_format& other);
61252a38012Sejakowatz					~media_format();
613d4d27facSStephan Aßmus
614d4d27facSStephan Aßmus	media_format&	operator=(const media_format& other);
615d4d27facSStephan Aßmus};
616d4d27facSStephan Aßmus
617d4d27facSStephan Aßmus
618d4d27facSStephan Aßmusbool operator==(const media_raw_audio_format& a,
619d4d27facSStephan Aßmus	const media_raw_audio_format& b);
620d4d27facSStephan Aßmus
621d4d27facSStephan Aßmusbool operator==(const media_multi_audio_info& a,
622d4d27facSStephan Aßmus	const media_multi_audio_info& b);
623d4d27facSStephan Aßmus
624d4d27facSStephan Aßmusbool operator==(const media_multi_audio_format& a,
625d4d27facSStephan Aßmus	const media_multi_audio_format& b);
626d4d27facSStephan Aßmus
627d4d27facSStephan Aßmusbool operator==(const media_encoded_audio_format& a,
628d4d27facSStephan Aßmus	const media_encoded_audio_format& b);
629d4d27facSStephan Aßmus
630d4d27facSStephan Aßmusbool operator==(const media_video_display_info& a,
631d4d27facSStephan Aßmus	const media_video_display_info& b);
632d4d27facSStephan Aßmus
633d4d27facSStephan Aßmusbool operator==(const media_raw_video_format& a,
634d4d27facSStephan Aßmus	const media_raw_video_format& b);
635d4d27facSStephan Aßmus
636d4d27facSStephan Aßmusbool operator==(const media_encoded_video_format& a,
637d4d27facSStephan Aßmus	const media_encoded_video_format& b);
638d4d27facSStephan Aßmus
639d4d27facSStephan Aßmusbool operator==(const media_multistream_format::vid_info& a,
640d4d27facSStephan Aßmus	const media_multistream_format::vid_info& b);
641d4d27facSStephan Aßmus
642d4d27facSStephan Aßmusbool operator==(const media_multistream_format::avi_info& a,
643d4d27facSStephan Aßmus	const media_multistream_format::avi_info & b);
644d4d27facSStephan Aßmus
645d4d27facSStephan Aßmusbool operator==(const media_multistream_format& a,
646d4d27facSStephan Aßmus	const media_multistream_format& b);
647d4d27facSStephan Aßmus
648d4d27facSStephan Aßmusbool operator==(const media_format& a, const media_format& b);
649d4d27facSStephan Aßmus
650d4d27facSStephan Aßmus
651d4d27facSStephan Aßmusbool format_is_compatible(const media_format & a, const media_format & b);
652d4d27facSStephan Aßmus	// Returns true if a and b are compatible (accounting for wildcards)
653d4d27facSStephan Aßmus	// (a is the format you want to feed to something accepting b
654d4d27facSStephan Aßmus
655f6e4cbb9SAxel Dörflerbool string_for_format(const media_format & f, char * buf, size_t size);
657d4d27facSStephan Aßmus
65852a38012Sejakowatzstruct media_seek_tag {
659d4d27facSStephan Aßmus	char	data[16];
662d4d27facSStephan Aßmus
66352a38012Sejakowatzstruct media_header_time_code {
66452a38012Sejakowatz	int8	type;		//	See TimeCode.h; don't use the "DEFAULT" value
66552a38012Sejakowatz	int8	_reserved;
66652a38012Sejakowatz	int8	hours;
66752a38012Sejakowatz	int8	minutes;
66852a38012Sejakowatz	int8	seconds;
66952a38012Sejakowatz	int8	frames;
670d4d27facSStephan Aßmus	int16	subframes;	//	Set to -1 if not available
673d4d27facSStephan Aßmus
674d4d27facSStephan Aßmus// Broadcast() fills in fields marked with "//+"
675d4d27facSStephan Aßmusstruct media_header {
67652a38012Sejakowatz	media_type		type;			// what kind of data (for union)
677d4d27facSStephan Aßmus	media_buffer_id buffer;			//+ what buffer does this header go with?
67852a38012Sejakowatz	int32			destination;	//+ what 'socket' is this intended for?
67952a38012Sejakowatz	media_node_id	time_source;	// node that encoded start_time
68052a38012Sejakowatz	uint32			_deprecated_;	// used to be change_tag
68152a38012Sejakowatz	uint32			size_used;		// size within buffer that is used
68252a38012Sejakowatz	bigtime_t		start_time;		// performance time
68352a38012Sejakowatz	area_id			owner;			//+ buffer owner info area
68452a38012Sejakowatz	enum {
685d4d27facSStephan Aßmus		B_SEEK_TAG	= 'TRST',		// user data type of the codec seek
68652a38012Sejakowatz									// protocol. size of seek tag is 16 bytes
687d4d27facSStephan Aßmus		B_TIME_CODE	= 'TRTC'		// user data is media_header_time_code
68852a38012Sejakowatz	};
68952a38012Sejakowatz	type_code		user_data_type;
69052a38012Sejakowatz	uchar			user_data[64];	// user_data_type indicates what this is
691b289aaf6SAxel Dörfler	int32			source;
692b289aaf6SAxel Dörfler	port_id			source_port;
69452a38012Sejakowatz	off_t			file_pos;		// where in a file this data came from
69552a38012Sejakowatz	size_t			orig_size;		// and how big it was.  if unused, zero out
69752a38012Sejakowatz	uint32			data_offset;	// offset within buffer (already reflected in Data())
69952a38012Sejakowatz	union {
70052a38012Sejakowatz		media_audio_header			raw_audio;
70152a38012Sejakowatz		media_video_header			raw_video;
70252a38012Sejakowatz		media_multistream_header	multistream;
70352a38012Sejakowatz		media_encoded_audio_header	encoded_audio;
70452a38012Sejakowatz		media_encoded_video_header	encoded_video;
705d4d27facSStephan Aßmus		char						_reserved_[64];	// pad to 64 bytes
706d4d27facSStephan Aßmus	}				u;
71052a38012Sejakowatzstruct media_file_format_id {
71152a38012Sejakowatz	ino_t	node;
71252a38012Sejakowatz	dev_t	device;
71352a38012Sejakowatz	uint32	internal_id;
715d4d27facSStephan Aßmus
716d4d27facSStephan Aßmus
717d4d27facSStephan Aßmusbool operator==(const media_file_format_id& a, const media_file_format_id& b);
718d4d27facSStephan Aßmusbool operator<(const media_file_format_id& a, const media_file_format_id& b);
719d4d27facSStephan Aßmus
72152a38012Sejakowatztypedef enum {
722d4d27facSStephan Aßmus	B_ANY_FORMAT_FAMILY			= 0,
723d4d27facSStephan Aßmus	B_BEOS_FORMAT_FAMILY		= 1,
724d4d27facSStephan Aßmus	B_QUICKTIME_FORMAT_FAMILY	= 2,	// QuickTime is a registered
725d4d27facSStephan Aßmus										// trademark of Apple Computer.
726d4d27facSStephan Aßmus	B_AVI_FORMAT_FAMILY			= 3,
727d4d27facSStephan Aßmus	B_ASF_FORMAT_FAMILY			= 4,
728d4d27facSStephan Aßmus	B_MPEG_FORMAT_FAMILY		= 5,
729d4d27facSStephan Aßmus	B_WAV_FORMAT_FAMILY			= 6,
730d4d27facSStephan Aßmus	B_AIFF_FORMAT_FAMILY		= 7,
731d4d27facSStephan Aßmus	B_AVR_FORMAT_FAMILY			= 8,
732d4d27facSStephan Aßmus
733d4d27facSStephan Aßmus	B_MISC_FORMAT_FAMILY		= 99999,
73452a38012Sejakowatz} media_format_family;
736d4d27facSStephan Aßmus
73752a38012Sejakowatzstruct media_file_format {
738d4d27facSStephan Aßmus	// Possible flags for capabilities bitmask
739d4d27facSStephan Aßmus	enum {
740d4d27facSStephan Aßmus		B_READABLE				= 0x1,
741d4d27facSStephan Aßmus		B_WRITABLE				= 0x2,
742d4d27facSStephan Aßmus		B_PERFECTLY_SEEKABLE	= 0x4,
743d4d27facSStephan Aßmus		B_IMPERFECTLY_SEEKABLE	= 0x8,
744d4d27facSStephan Aßmus		B_KNOWS_RAW_VIDEO		= 0x10,
745d4d27facSStephan Aßmus		B_KNOWS_RAW_AUDIO		= 0x20,
746d4d27facSStephan Aßmus		B_KNOWS_MIDI			= 0x40,
747d4d27facSStephan Aßmus		B_KNOWS_ENCODED_VIDEO	= 0x80,
748d4d27facSStephan Aßmus		B_KNOWS_ENCODED_AUDIO	= 0x100,
749d4d27facSStephan Aßmus		B_KNOWS_OTHER			= 0x1000000, // For example sub-title streams
750d4d27facSStephan Aßmus		B_KNOWS_ANYTHING		= 0x2000000
751d4d27facSStephan Aßmus	};
752d4d27facSStephan Aßmus	uint32					capabilities;	// Bitmask, see flags above
753d4d27facSStephan Aßmus	media_file_format_id	id;				// Opaque id used to construct a
754d4d27facSStephan Aßmus											// BMediaFile
755d4d27facSStephan Aßmus	media_format_family		family;			// One of the family enums
756d4d27facSStephan Aßmus	int32					version;		// 100 for 1.0
757d4d27facSStephan Aßmus
758d4d27facSStephan Aßmus	uint32					_reserved_[25];
759d4d27facSStephan Aßmus
760d4d27facSStephan Aßmus	char					mime_type[64];
761d4d27facSStephan Aßmus	char					pretty_name[64];	// "QuickTime File Format"
762d4d27facSStephan Aßmus	char					short_name[32];		// "quicktime", "avi", "mpeg"
763d4d27facSStephan Aßmus	char					file_extension[8];	// "mov", "avi", "mpg"
764d4d27facSStephan Aßmus
765d4d27facSStephan Aßmus	char					reserved[88];
766d4d27facSStephan Aßmus};
767d4d27facSStephan Aßmus
768d4d27facSStephan Aßmus
769d4d27facSStephan Aßmus// Initialize the cookie to 0 and keep calling this function to iterate
770d4d27facSStephan Aßmus// over all available media file format writers.
771d4d27facSStephan Aßmusstatus_t get_next_file_format(int32* cookie, media_file_format* mfi);
772d4d27facSStephan Aßmus
773d4d27facSStephan Aßmus
774d4d27facSStephan Aßmus// A buffer of this size is guaranteed to be large enough to hold any
775d4d27facSStephan Aßmus// message, which your service thread can read from read_port() and
776d4d27facSStephan Aßmus// passes on to HandleMessage().
77752a38012Sejakowatzconst size_t B_MEDIA_MESSAGE_SIZE = 16384;
780d4d27facSStephan Aßmusextern const char* B_MEDIA_SERVER_SIGNATURE;
781d4d27facSStephan Aßmus
782d4d27facSStephan Aßmusclass media_node;
78352a38012Sejakowatzstruct media_input;
78452a38012Sejakowatzstruct media_output;
78552a38012Sejakowatzstruct live_node_info;
78652a38012Sejakowatzstruct dormant_node_info;
78752a38012Sejakowatzstruct buffer_clone_info;
790d4d27facSStephan Aßmus// Functions which control the shutdown and launching process of the
791d4d27facSStephan Aßmus// media_server and it's friends. You can provide a call back hook which
792d4d27facSStephan Aßmus// will be called during various steps of the process. This callback should
793d4d27facSStephan Aßmus// currently always return TRUE. A 'stage' value of 100 means the process is
7948acd164fSDario Casalinuovo// completely finished. Differently from BeOS the functions automatically
7958acd164fSDario Casalinuovo// send notifications to the Deskbar if not differently specified.
7968acd164fSDario Casalinuovo// It's also provided a new version of launch_media_server allowing
7978acd164fSDario Casalinuovo// to specify a custom callback for notifications.
7988acd164fSDario Casalinuovo
7998acd164fSDario Casalinuovostatus_t launch_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT,
8008acd164fSDario Casalinuovo	bool (*progress)(int stage, const char* message, void* cookie) = NULL,
8018acd164fSDario Casalinuovo	void* cookie = NULL, uint32 flags = 0);
8028acd164fSDario Casalinuovo
803d4d27facSStephan Aßmusstatus_t shutdown_media_server(bigtime_t timeout = B_INFINITE_TIMEOUT,
804d4d27facSStephan Aßmus	bool (*progress)(int stage, const char* message, void* cookie) = NULL,
805d4d27facSStephan Aßmus	void* cookie = NULL);
807d4d27facSStephan Aßmus
808d4d27facSStephan Aßmus// A teeny bit of legacy preserved for BSoundFile from R3.
809d4d27facSStephan Aßmus// These came from the old MediaDefs.h; don't use them
810d4d27facSStephan Aßmus// unless you get them from BSoundFile.
813d4d27facSStephan Aßmus// values for byte_ordering
814d4d27facSStephan Aßmusenum {
815d4d27facSStephan Aßmus	B_BIG_ENDIAN,
816d4d27facSStephan Aßmus	B_LITTLE_ENDIAN
817d4d27facSStephan Aßmus};
818d4d27facSStephan Aßmus
819d4d27facSStephan Aßmus
820d4d27facSStephan Aßmus// values for sample_format
821d4d27facSStephan Aßmusenum {
822d4d27facSStephan Aßmus	B_UNDEFINED_SAMPLES,
823d4d27facSStephan Aßmus	B_LINEAR_SAMPLES,
824d4d27facSStephan Aßmus	B_FLOAT_SAMPLES,
825d4d27facSStephan Aßmus	B_MULAW_SAMPLES
826d4d27facSStephan Aßmus};
827d4d27facSStephan Aßmus
828d4d27facSStephan Aßmus
829d4d27facSStephan Aßmus// #pragma mark - encoders and file writers
83252a38012Sejakowatzstruct media_encode_info {
833d4d27facSStephan Aßmus	uint32		flags;					// B_MEDIA_KEY_FRAME, set before every
834d4d27facSStephan Aßmus										// use
835d4d27facSStephan Aßmus
836d4d27facSStephan Aßmus	int32		used_data_size;			// data size used by other tracks
837d4d27facSStephan Aßmus										// add output size used by this encoder
838d4d27facSStephan Aßmus
839d4d27facSStephan Aßmus	bigtime_t	start_time;				// us from start of file
840d4d27facSStephan Aßmus	bigtime_t	time_to_encode;			// 0 - hurry up, B_INFINITE_TIMEOUT
841d4d27facSStephan Aßmus										// - don't care
84252a38012Sejakowatz	int32		_pad[22];
843d4d27facSStephan Aßmus
844d4d27facSStephan Aßmus	void*		file_format_data;		// file format specific info
84552a38012Sejakowatz	size_t		file_format_data_size;
846d4d27facSStephan Aßmus
847d4d27facSStephan Aßmus	void*		codec_data;				// codec specific info
84852a38012Sejakowatz	size_t		codec_data_size;
849d4d27facSStephan Aßmus
85052a38012Sejakowatz	media_encode_info();
853d4d27facSStephan Aßmus
85452a38012Sejakowatzstruct encode_parameters {
85552a38012Sejakowatz	float		quality;				// 0.0-1.0 , 1.0 is high quality
856d4d27facSStephan Aßmus
85752a38012Sejakowatz	int32		avg_field_size;			// in bytes
85852a38012Sejakowatz	int32		max_field_size;			// in bytes
859d4d27facSStephan Aßmus
86052a38012Sejakowatz	int32		_pad[27];
861d4d27facSStephan Aßmus
862d4d27facSStephan Aßmus	void*		user_data;				// codec specific info
86352a38012Sejakowatz	size_t		user_data_size;
866d4d27facSStephan Aßmus
86752a38012Sejakowatzstruct media_decode_info {
868d4d27facSStephan Aßmus	bigtime_t	time_to_decode;			// 0 - hurry up, B_INFINITE_TIMEOUT
869d4d27facSStephan Aßmus										// - don't care
870d4d27facSStephan Aßmus
87152a38012Sejakowatz	int32		_pad[26];
872d4d27facSStephan Aßmus
873d4d27facSStephan Aßmus	void*		file_format_data;		// file format specific info
87452a38012Sejakowatz	size_t		file_format_data_size;
875d4d27facSStephan Aßmus
876d4d27facSStephan Aßmus	void*		codec_data;				// codec specific info
87752a38012Sejakowatz	size_t		codec_data_size;
878d4d27facSStephan Aßmus
87952a38012Sejakowatz	media_decode_info();
883d4d27facSStephan Aßmus// #pragma mark - inline implementations
884d4d27facSStephan Aßmus
885d4d27facSStephan Aßmus
886d4d27facSStephan Aßmusinline bool
887d4d27facSStephan Aßmusmedia_format::IsVideo() const
888d4d27facSStephan Aßmus{
889d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_VIDEO || type == B_MEDIA_RAW_VIDEO;
890d4d27facSStephan Aßmus}
891d4d27facSStephan Aßmus
892d4d27facSStephan Aßmus
893d4d27facSStephan Aßmusinline uint32
894d4d27facSStephan Aßmusmedia_format::Width() const
895d4d27facSStephan Aßmus{
896d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_VIDEO
897d4d27facSStephan Aßmus		? u.encoded_video.output.display.line_width
898d4d27facSStephan Aßmus		: u.raw_video.display.line_width;
899d4d27facSStephan Aßmus}
900d4d27facSStephan Aßmus
901d4d27facSStephan Aßmus
902d4d27facSStephan Aßmusinline uint32
903d4d27facSStephan Aßmusmedia_format::Height() const
904d4d27facSStephan Aßmus{
905d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_VIDEO
906d4d27facSStephan Aßmus		? u.encoded_video.output.display.line_count
907d4d27facSStephan Aßmus		: u.raw_video.display.line_count;
908d4d27facSStephan Aßmus}
909d4d27facSStephan Aßmus
910d4d27facSStephan Aßmus
911d4d27facSStephan Aßmusinline color_space
912d4d27facSStephan Aßmusmedia_format::ColorSpace() const
913d4d27facSStephan Aßmus{
914d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_VIDEO
915d4d27facSStephan Aßmus		? u.encoded_video.output.display.format
916d4d27facSStephan Aßmus		: u.raw_video.display.format;
917d4d27facSStephan Aßmus}
918d4d27facSStephan Aßmus
919d4d27facSStephan Aßmus
920d4d27facSStephan Aßmusinline uint32&
921d4d27facSStephan Aßmusmedia_format::Width()
922d4d27facSStephan Aßmus{
923d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_VIDEO
924d4d27facSStephan Aßmus		? u.encoded_video.output.display.line_width
925d4d27facSStephan Aßmus		: u.raw_video.display.line_width;
926d4d27facSStephan Aßmus}
927d4d27facSStephan Aßmus
928d4d27facSStephan Aßmus
929d4d27facSStephan Aßmusinline uint32&
930d4d27facSStephan Aßmusmedia_format::Height()
931d4d27facSStephan Aßmus{
932d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_VIDEO
933d4d27facSStephan Aßmus		? u.encoded_video.output.display.line_count
934d4d27facSStephan Aßmus		: u.raw_video.display.line_count;
935d4d27facSStephan Aßmus}
936d4d27facSStephan Aßmus
937d4d27facSStephan Aßmus
938d4d27facSStephan Aßmusinline color_space&
939d4d27facSStephan Aßmusmedia_format::ColorSpace()
940d4d27facSStephan Aßmus{
941d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_VIDEO
942d4d27facSStephan Aßmus		? u.encoded_video.output.display.format
943d4d27facSStephan Aßmus		: u.raw_video.display.format;
944d4d27facSStephan Aßmus}
945d4d27facSStephan Aßmus
946d4d27facSStephan Aßmus
947d4d27facSStephan Aßmusinline bool
948d4d27facSStephan Aßmusmedia_format::IsAudio() const
949d4d27facSStephan Aßmus{
950d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_AUDIO || type == B_MEDIA_RAW_AUDIO;
951d4d27facSStephan Aßmus}
952d4d27facSStephan Aßmus
953d4d27facSStephan Aßmus
954d4d27facSStephan Aßmusinline uint32
955d4d27facSStephan Aßmusmedia_format::AudioFormat() const
956d4d27facSStephan Aßmus{
957d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_AUDIO
958d4d27facSStephan Aßmus		? u.encoded_audio.output.format : u.raw_audio.format;
959d4d27facSStephan Aßmus}
960d4d27facSStephan Aßmus
961d4d27facSStephan Aßmus
962d4d27facSStephan Aßmusinline uint32&
963d4d27facSStephan Aßmusmedia_format::AudioFormat()
964d4d27facSStephan Aßmus{
965d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_AUDIO
966d4d27facSStephan Aßmus		? u.encoded_audio.output.format : u.raw_audio.format;
967d4d27facSStephan Aßmus}
968d4d27facSStephan Aßmus
969d4d27facSStephan Aßmus
970d4d27facSStephan Aßmusinline uint32
971d4d27facSStephan Aßmusmedia_format::AudioFrameSize() const
972d4d27facSStephan Aßmus{
973d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_AUDIO
974d4d27facSStephan Aßmus		? (u.encoded_audio.output.format
975d4d27facSStephan Aßmus			& media_raw_audio_format::B_AUDIO_SIZE_MASK)
976d4d27facSStephan Aßmus			* u.encoded_audio.output.channel_count
977d4d27facSStephan Aßmus		: (u.raw_audio.format & media_raw_audio_format::B_AUDIO_SIZE_MASK)
978d4d27facSStephan Aßmus			* u.raw_audio.channel_count;
979d4d27facSStephan Aßmus}
980d4d27facSStephan Aßmus
981d4d27facSStephan Aßmus
982d4d27facSStephan Aßmusinline uint32
983d4d27facSStephan Aßmusmedia_format::Encoding() const
984d4d27facSStephan Aßmus{
985d4d27facSStephan Aßmus	return type == B_MEDIA_ENCODED_VIDEO