1ee9408a1SStephan Aßmus/*
2ee9408a1SStephan Aßmus * Copyright 2009, Haiku, Inc. All rights reserved.
3ee9408a1SStephan Aßmus * Distributed under the terms of the MIT license.
4ee9408a1SStephan Aßmus */
5ee9408a1SStephan Aßmus#ifndef _MEDIA_TYPES_H
652a38012Sejakowatz#define _MEDIA_TYPES_H
9377e9530SStephan Aßmus#include <MediaDefs.h>
10377e9530SStephan Aßmus
11377e9530SStephan Aßmus#include <Messenger.h>
12377e9530SStephan Aßmus#include <List.h>
13377e9530SStephan Aßmus#include <Locker.h>
1652a38012Sejakowatzstruct media_codec_info {
17ee9408a1SStephan Aßmus	char	pretty_name[96];   /* eg: "SuperSqueeze Encoder by Foo Inc" */
18377e9530SStephan Aßmus	char	short_name[32];    /* eg: "SuperSqueeze" */
192a93bc98SAxel Dörfler
20ee9408a1SStephan Aßmus	int32	id;                /* opaque id passed to
21ee9408a1SStephan Aßmus								  BMediaFile::CreateTrack() */
2252a38012Sejakowatz	int32	sub_id;
232a93bc98SAxel Dörfler
2452a38012Sejakowatz	int32	pad[63];
27ee9408a1SStephan Aßmus/*!	\brief	Use this to iterate through the available encoders for a given file
28ee9408a1SStephan Aßmus			format.
29ee9408a1SStephan Aßmus	\param cookie		A pointer to a preallocated cookie, which you need
30ee9408a1SStephan Aßmus						to initialize to \c 0 before calling this function
31ee9408a1SStephan Aßmus						the first time.
32ee9408a1SStephan Aßmus	\param fileFormat	A pointer to a valid media_file_format structure
33ee9408a1SStephan Aßmus						as can be obtained through get_next_file_format().
34ee9408a1SStephan Aßmus	\param inputFormat	This is the type of data given to the encoder.
35ee9408a1SStephan Aßmus	\param _outputFormat This is the type of data the encoder will output.
36ee9408a1SStephan Aßmus	\param _codecInfo	Pointer to a preallocated media_codec_info structure,
37ee9408a1SStephan Aßmus						information about the encoder is placed there.
38ee9408a1SStephan Aßmus
39ee9408a1SStephan Aßmus	\return
40ee9408a1SStephan Aßmus	- \c B_OK: Everything went fine.
41ee9408a1SStephan Aßmus	- \c B_BAD_INDEX: There are no more encoders.
42ee9408a1SStephan Aßmus */
43ee9408a1SStephan Aßmusstatus_t get_next_encoder(int32* cookie, const media_file_format* fileFormat,
44ee9408a1SStephan Aßmus	const media_format* inputFormat, media_format* _outputFormat,
45ee9408a1SStephan Aßmus	media_codec_info* _codecInfo);
46ee9408a1SStephan Aßmus
47ee9408a1SStephan Aßmus/*!	\brief	Use this to iterate through the available encoders with
48ee9408a1SStephan Aßmus			restrictions to the input and output media_format while the
49ee9408a1SStephan Aßmus			encoders can specialize wildcards in the media_formats.
50ee9408a1SStephan Aßmus
51ee9408a1SStephan Aßmus	\param cookie		A pointer to a preallocated cookie, which you need
52ee9408a1SStephan Aßmus						to initialize to \c 0 before calling this function
53ee9408a1SStephan Aßmus						the first time.
54ee9408a1SStephan Aßmus	\param fileFormat	A pointer to a valid media_file_format structure
55ee9408a1SStephan Aßmus						as can be obtained through get_next_file_format().
56ee9408a1SStephan Aßmus						You can pass \c NULL if you don't care.
57ee9408a1SStephan Aßmus	\param inputFormat	This is the type of data given to the encoder,
58ee9408a1SStephan Aßmus						wildcards are accepted.
59ee9408a1SStephan Aßmus	\param outputFormat	This is the type of data you want the encoder to
60ee9408a1SStephan Aßmus						output. Wildcards are accepted.
61ee9408a1SStephan Aßmus	\param _codecInfo	Pointer to a preallocated media_codec_info structure,
62ee9408a1SStephan Aßmus						information about the encoder is placed there.
63ee9408a1SStephan Aßmus	\param _acceptedInputFormat This is the type of data that the encoder will
64ee9408a1SStephan Aßmus						accept as input. Wildcards in \a inFormat will be
65ee9408a1SStephan Aßmus						specialized here.
66ee9408a1SStephan Aßmus	\param _acceptedOutputFormat This is the type of data that the encoder will
67ee9408a1SStephan Aßmus						output. Wildcards in \a _outFormat will be specialized
68ee9408a1SStephan Aßmus						here.
69ee9408a1SStephan Aßmus
70ee9408a1SStephan Aßmus	\return
71ee9408a1SStephan Aßmus	- \c B_OK: Everything went fine.
72ee9408a1SStephan Aßmus	- \c B_BAD_INDEX: There are no more encoders.
73ee9408a1SStephan Aßmus*/
74ee9408a1SStephan Aßmusstatus_t get_next_encoder(int32* cookie, const media_file_format* fileFormat,
75ee9408a1SStephan Aßmus	const media_format* inputFormat, const media_format* outputFormat,
76ee9408a1SStephan Aßmus	media_codec_info* _codecInfo, media_format* _acceptedInputFormat,
77ee9408a1SStephan Aßmus	media_format* _acceptedOutputFormat);
78ee9408a1SStephan Aßmus
79ee9408a1SStephan Aßmus
80ee9408a1SStephan Aßmus/*!	\brief	Iterate over the all the available encoders without media_format
81ee9408a1SStephan Aßmus			restrictions.
82ee9408a1SStephan Aßmus
83ee9408a1SStephan Aßmus	\param cookie		A pointer to a preallocated cookie, which you need
84ee9408a1SStephan Aßmus						to initialize to \c 0 before calling this function
85ee9408a1SStephan Aßmus						the first time.
86ee9408a1SStephan Aßmus	\param _codecInfo	Pointer to a preallocated media_codec_info structure,
87ee9408a1SStephan Aßmus						information about the encoder is placed there.
88ee9408a1SStephan Aßmus
89ee9408a1SStephan Aßmus	\return
90ee9408a1SStephan Aßmus	- \c B_OK: Everything went fine.
91ee9408a1SStephan Aßmus	- \c B_BAD_INDEX: There are no more encoders.
92ee9408a1SStephan Aßmus*/
93ee9408a1SStephan Aßmusstatus_t get_next_encoder(int32* cookie, media_codec_info* _codecInfo);
942a93bc98SAxel Dörfler
9652a38012Sejakowatzenum media_file_accept_format_flags {
9752a38012Sejakowatz	B_MEDIA_REJECT_WILDCARDS = 0x1
100ee9408a1SStephan Aßmusbool does_file_accept_format(const media_file_format* fileFormat,
101ee9408a1SStephan Aßmus	media_format* format, uint32 flags = 0);
1022a93bc98SAxel Dörfler
10452a38012Sejakowatztypedef struct {
10552a38012Sejakowatz	uint8 data[16];
10652a38012Sejakowatz} GUID;
108ee9408a1SStephan Aßmus
109572e60a4Sbeveloperenum beos_format {
110572e60a4Sbeveloper	B_BEOS_FORMAT_RAW_AUDIO = 'rawa',
111572e60a4Sbeveloper	B_BEOS_FORMAT_RAW_VIDEO = 'rawv'
113ee9408a1SStephan Aßmus
114ee9408a1SStephan Aßmus
11552a38012Sejakowatztypedef struct {
11652a38012Sejakowatz	int32 format;
11752a38012Sejakowatz} media_beos_description;
119ee9408a1SStephan Aßmus
12052a38012Sejakowatztypedef struct {
12152a38012Sejakowatz	uint32 codec;
12252a38012Sejakowatz	uint32 vendor;
12352a38012Sejakowatz} media_quicktime_description;
125ee9408a1SStephan Aßmus
12652a38012Sejakowatztypedef struct {
12752a38012Sejakowatz	uint32 codec;
12852a38012Sejakowatz} media_avi_description;
130ee9408a1SStephan Aßmus
13152a38012Sejakowatztypedef struct {
13252a38012Sejakowatz	uint32 id;
13352a38012Sejakowatz} media_avr_description;
135ee9408a1SStephan Aßmus
13652a38012Sejakowatztypedef struct {
13752a38012Sejakowatz	GUID guid;
13852a38012Sejakowatz} media_asf_description;
140ee9408a1SStephan Aßmus
14152a38012Sejakowatzenum mpeg_id {
14252a38012Sejakowatz	B_MPEG_ANY = 0,
14352a38012Sejakowatz	B_MPEG_1_AUDIO_LAYER_1 = 0x101,
14452a38012Sejakowatz	B_MPEG_1_AUDIO_LAYER_2 = 0x102,
145ee9408a1SStephan Aßmus	B_MPEG_1_AUDIO_LAYER_3 = 0x103,		/* "MP3" */
1465ccadc29Sbeveloper	B_MPEG_1_VIDEO = 0x111,
1475ccadc29Sbeveloper	B_MPEG_2_AUDIO_LAYER_1 = 0x201,
1485ccadc29Sbeveloper	B_MPEG_2_AUDIO_LAYER_2 = 0x202,
1495ccadc29Sbeveloper	B_MPEG_2_AUDIO_LAYER_3 = 0x203,
1505ccadc29Sbeveloper	B_MPEG_2_VIDEO = 0x211,
1515ccadc29Sbeveloper	B_MPEG_2_5_AUDIO_LAYER_1 = 0x301,
1525ccadc29Sbeveloper	B_MPEG_2_5_AUDIO_LAYER_2 = 0x302,
1535ccadc29Sbeveloper	B_MPEG_2_5_AUDIO_LAYER_3 = 0x303,
155ee9408a1SStephan Aßmus
156ee9408a1SStephan Aßmus
15752a38012Sejakowatztypedef struct {
15852a38012Sejakowatz	uint32 id;
15952a38012Sejakowatz} media_mpeg_description;
161ee9408a1SStephan Aßmus
16252a38012Sejakowatztypedef struct {
16352a38012Sejakowatz	uint32 codec;
16452a38012Sejakowatz} media_wav_description;
166ee9408a1SStephan Aßmus
16752a38012Sejakowatztypedef struct {
16852a38012Sejakowatz	uint32 codec;
16952a38012Sejakowatz} media_aiff_description;
171ee9408a1SStephan Aßmus
17252a38012Sejakowatztypedef struct {
17352a38012Sejakowatz	uint32 file_format;
17452a38012Sejakowatz	uint32 codec;
17552a38012Sejakowatz} media_misc_description;
177ee9408a1SStephan Aßmus
17852a38012Sejakowatztypedef struct _media_format_description {
179ee9408a1SStephan Aßmus								_media_format_description();
180ee9408a1SStephan Aßmus								~_media_format_description();
181ee9408a1SStephan Aßmus								_media_format_description(
182ee9408a1SStephan Aßmus									const _media_format_description& other);
183ee9408a1SStephan Aßmus	_media_format_description&	operator=(
184ee9408a1SStephan Aßmus									const _media_format_description& other);
185377e9530SStephan Aßmus
18652a38012Sejakowatz	media_format_family family;
18752a38012Sejakowatz	uint32 _reserved_[3];
18852a38012Sejakowatz	union {
18952a38012Sejakowatz		media_beos_description beos;
19052a38012Sejakowatz		media_quicktime_description quicktime;
19152a38012Sejakowatz		media_avi_description avi;
19252a38012Sejakowatz		media_asf_description asf;
19352a38012Sejakowatz		media_mpeg_description mpeg;
19452a38012Sejakowatz		media_wav_description wav;
19552a38012Sejakowatz		media_aiff_description aiff;
19652a38012Sejakowatz		media_misc_description misc;
19752a38012Sejakowatz		media_avr_description avr;
19852a38012Sejakowatz		uint32 _reserved_[12];
19952a38012Sejakowatz	} u;
20052a38012Sejakowatz} media_format_description;
20352a38012Sejakowatzclass BMediaFormats {
204ee9408a1SStephan Aßmuspublic:
205ee9408a1SStephan Aßmus								BMediaFormats();
206ee9408a1SStephan Aßmus	virtual						~BMediaFormats();
207ee9408a1SStephan Aßmus
208ee9408a1SStephan Aßmus			status_t			InitCheck();
209ee9408a1SStephan Aßmus
210ee9408a1SStephan Aßmus	// Make sure you memset() your descs to 0 before you start filling
211ee9408a1SStephan Aßmus	// them in! Else you may register some bogus value.
212ee9408a1SStephan Aßmus	enum make_format_flags {
213ee9408a1SStephan Aßmus		B_EXCLUSIVE = 0x1,		// Fail if this format has already been
214ee9408a1SStephan Aßmus								// registered.
215ee9408a1SStephan Aßmus
216ee9408a1SStephan Aßmus		B_NO_MERGE = 0x2,		// Don't re-number any formats if there are
217ee9408a1SStephan Aßmus								// multiple clashing previous registrations,
218ee9408a1SStephan Aßmus								// but fail instead.
219ee9408a1SStephan Aßmus
220ee9408a1SStephan Aßmus		B_SET_DEFAULT = 0x4		// Set the first format to be the default for
221ee9408a1SStephan Aßmus								// the format family (when registering more
222ee9408a1SStephan Aßmus								// than one in the same family). Only use in
223ee9408a1SStephan Aßmus								// Encoder add-ons.
224ee9408a1SStephan Aßmus	};
225ee9408a1SStephan Aßmus
226ee9408a1SStephan Aßmus			status_t			MakeFormatFor(const media_format_description*
227ee9408a1SStephan Aßmus									descriptions, int32 descriptionCount,
228ee9408a1SStephan Aßmus									media_format* _inOutFormat,
229ee9408a1SStephan Aßmus									uint32 flags = 0, void* _reserved = 0);
230ee9408a1SStephan Aßmus
231ee9408a1SStephan Aßmus			status_t			GetFormatFor(const media_format_description&
232ee9408a1SStephan Aßmus									description, media_format* _outFormat);
233ee9408a1SStephan Aßmus
234ee9408a1SStephan Aßmus			status_t			GetCodeFor(const media_format& format,
235ee9408a1SStephan Aßmus									media_format_family family,
236ee9408a1SStephan Aßmus									media_format_description* _outDescription);
237ee9408a1SStephan Aßmus
238ee9408a1SStephan Aßmus			status_t			RewindFormats();
239ee9408a1SStephan Aßmus			status_t			GetNextFormat(media_format* _outFormat,
240ee9408a1SStephan Aßmus									media_format_description* _outDescription);
241ee9408a1SStephan Aßmus
242ee9408a1SStephan Aßmus	// You need to lock/unlock (only) when using
243ee9408a1SStephan Aßmus	// RewindFormats()/GetNextFormat().
244ee9408a1SStephan Aßmus			bool				Lock();
245ee9408a1SStephan Aßmus			void				Unlock();
246ee9408a1SStephan Aßmus
247ee9408a1SStephan Aßmus	//	convenience functions
248ee9408a1SStephan Aßmus	static	status_t			GetBeOSFormatFor(uint32 fourcc,
249ee9408a1SStephan Aßmus									media_format* _outFormat,
250ee9408a1SStephan Aßmus									media_type type = B_MEDIA_UNKNOWN_TYPE);
251ee9408a1SStephan Aßmus	static	status_t			GetAVIFormatFor(uint32 fourcc,
252ee9408a1SStephan Aßmus									media_format* _outFormat,
253ee9408a1SStephan Aßmus									media_type type = B_MEDIA_UNKNOWN_TYPE);
254ee9408a1SStephan Aßmus	static	status_t			GetQuicktimeFormatFor(uint32 vendor,
255ee9408a1SStephan Aßmus									uint32 fourcc, media_format* _outFormat,
256ee9408a1SStephan Aßmus									media_type type = B_MEDIA_UNKNOWN_TYPE);
257ee9408a1SStephan Aßmus
258ee9408a1SStephan Aßmus	// Deprecated:
259ee9408a1SStephan Aßmus			status_t			MakeFormatFor(const media_format_description&
260ee9408a1SStephan Aßmus									description, const media_format& inFormat,
261ee9408a1SStephan Aßmus									media_format* _outFormat);
262ee9408a1SStephan Aßmus
263ee9408a1SStephan Aßmusprivate:
264ee9408a1SStephan Aßmus			int32				fIteratorIndex;
265ee9408a1SStephan Aßmus
266ee9408a1SStephan Aßmus			uint32				_reserved[30];
270ee9408a1SStephan Aßmusbool operator==(const media_format_description& a,
271ee9408a1SStephan Aßmus	const media_format_description& b);
272ee9408a1SStephan Aßmus
273ee9408a1SStephan Aßmusbool operator<(const media_format_description& a,
274ee9408a1SStephan Aßmus	const media_format_description& b);
275ee9408a1SStephan Aßmus
276ee9408a1SStephan Aßmus
277ee9408a1SStephan Aßmusbool operator==(const GUID& a, const GUID& b);
278ee9408a1SStephan Aßmus
279ee9408a1SStephan Aßmusbool operator<(const GUID& a, const GUID& b);
280ee9408a1SStephan Aßmus
2812a93bc98SAxel Dörfler
282377e9530SStephan Aßmus#endif	// _MEDIA_TYPES_H