vfs: check userland buffers before reading them.
[haiku.git] / headers / os / media / MediaFormats.h
blobfcda279c2d84d94607d3ee004db0cca3cbbe1257
1 /*
2 * Copyright 2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
4 */
5 #ifndef _MEDIA_TYPES_H
6 #define _MEDIA_TYPES_H
9 #include <MediaDefs.h>
11 #include <Messenger.h>
12 #include <List.h>
13 #include <Locker.h>
16 struct media_codec_info {
17 char pretty_name[96]; /* eg: "SuperSqueeze Encoder by Foo Inc" */
18 char short_name[32]; /* eg: "SuperSqueeze" */
20 int32 id; /* opaque id passed to
21 BMediaFile::CreateTrack() */
22 int32 sub_id;
24 int32 pad[63];
27 /*! \brief Use this to iterate through the available encoders for a given file
28 format.
29 \param cookie A pointer to a preallocated cookie, which you need
30 to initialize to \c 0 before calling this function
31 the first time.
32 \param fileFormat A pointer to a valid media_file_format structure
33 as can be obtained through get_next_file_format().
34 \param inputFormat This is the type of data given to the encoder.
35 \param _outputFormat This is the type of data the encoder will output.
36 \param _codecInfo Pointer to a preallocated media_codec_info structure,
37 information about the encoder is placed there.
39 \return
40 - \c B_OK: Everything went fine.
41 - \c B_BAD_INDEX: There are no more encoders.
43 status_t get_next_encoder(int32* cookie, const media_file_format* fileFormat,
44 const media_format* inputFormat, media_format* _outputFormat,
45 media_codec_info* _codecInfo);
47 /*! \brief Use this to iterate through the available encoders with
48 restrictions to the input and output media_format while the
49 encoders can specialize wildcards in the media_formats.
51 \param cookie A pointer to a preallocated cookie, which you need
52 to initialize to \c 0 before calling this function
53 the first time.
54 \param fileFormat A pointer to a valid media_file_format structure
55 as can be obtained through get_next_file_format().
56 You can pass \c NULL if you don't care.
57 \param inputFormat This is the type of data given to the encoder,
58 wildcards are accepted.
59 \param outputFormat This is the type of data you want the encoder to
60 output. Wildcards are accepted.
61 \param _codecInfo Pointer to a preallocated media_codec_info structure,
62 information about the encoder is placed there.
63 \param _acceptedInputFormat This is the type of data that the encoder will
64 accept as input. Wildcards in \a inFormat will be
65 specialized here.
66 \param _acceptedOutputFormat This is the type of data that the encoder will
67 output. Wildcards in \a _outFormat will be specialized
68 here.
70 \return
71 - \c B_OK: Everything went fine.
72 - \c B_BAD_INDEX: There are no more encoders.
74 status_t get_next_encoder(int32* cookie, const media_file_format* fileFormat,
75 const media_format* inputFormat, const media_format* outputFormat,
76 media_codec_info* _codecInfo, media_format* _acceptedInputFormat,
77 media_format* _acceptedOutputFormat);
80 /*! \brief Iterate over the all the available encoders without media_format
81 restrictions.
83 \param cookie A pointer to a preallocated cookie, which you need
84 to initialize to \c 0 before calling this function
85 the first time.
86 \param _codecInfo Pointer to a preallocated media_codec_info structure,
87 information about the encoder is placed there.
89 \return
90 - \c B_OK: Everything went fine.
91 - \c B_BAD_INDEX: There are no more encoders.
93 status_t get_next_encoder(int32* cookie, media_codec_info* _codecInfo);
96 enum media_file_accept_format_flags {
97 B_MEDIA_REJECT_WILDCARDS = 0x1
100 bool does_file_accept_format(const media_file_format* fileFormat,
101 media_format* format, uint32 flags = 0);
104 typedef struct {
105 uint8 data[16];
106 } GUID;
109 enum beos_format {
110 B_BEOS_FORMAT_RAW_AUDIO = 'rawa',
111 B_BEOS_FORMAT_RAW_VIDEO = 'rawv'
115 typedef struct {
116 int32 format;
117 } media_beos_description;
120 typedef struct {
121 uint32 codec;
122 uint32 vendor;
123 } media_quicktime_description;
126 typedef struct {
127 uint32 codec;
128 } media_avi_description;
131 typedef struct {
132 uint32 id;
133 } media_avr_description;
136 typedef struct {
137 GUID guid;
138 } media_asf_description;
141 enum mpeg_id {
142 B_MPEG_ANY = 0,
143 B_MPEG_1_AUDIO_LAYER_1 = 0x101,
144 B_MPEG_1_AUDIO_LAYER_2 = 0x102,
145 B_MPEG_1_AUDIO_LAYER_3 = 0x103, /* "MP3" */
146 B_MPEG_1_VIDEO = 0x111,
147 B_MPEG_2_AUDIO_LAYER_1 = 0x201,
148 B_MPEG_2_AUDIO_LAYER_2 = 0x202,
149 B_MPEG_2_AUDIO_LAYER_3 = 0x203,
150 B_MPEG_2_VIDEO = 0x211,
151 B_MPEG_2_5_AUDIO_LAYER_1 = 0x301,
152 B_MPEG_2_5_AUDIO_LAYER_2 = 0x302,
153 B_MPEG_2_5_AUDIO_LAYER_3 = 0x303,
157 typedef struct {
158 uint32 id;
159 } media_mpeg_description;
162 typedef struct {
163 uint32 codec;
164 } media_wav_description;
167 typedef struct {
168 uint32 codec;
169 } media_aiff_description;
172 typedef struct {
173 uint32 file_format;
174 uint32 codec;
175 } media_misc_description;
178 typedef struct _media_format_description {
179 _media_format_description();
180 ~_media_format_description();
181 _media_format_description(
182 const _media_format_description& other);
183 _media_format_description& operator=(
184 const _media_format_description& other);
186 media_format_family family;
187 uint32 _reserved_[3];
188 union {
189 media_beos_description beos;
190 media_quicktime_description quicktime;
191 media_avi_description avi;
192 media_asf_description asf;
193 media_mpeg_description mpeg;
194 media_wav_description wav;
195 media_aiff_description aiff;
196 media_misc_description misc;
197 media_avr_description avr;
198 uint32 _reserved_[12];
199 } u;
200 } media_format_description;
203 class BMediaFormats {
204 public:
205 BMediaFormats();
206 virtual ~BMediaFormats();
208 status_t InitCheck();
210 // Make sure you memset() your descs to 0 before you start filling
211 // them in! Else you may register some bogus value.
212 enum make_format_flags {
213 B_EXCLUSIVE = 0x1, // Fail if this format has already been
214 // registered.
216 B_NO_MERGE = 0x2, // Don't re-number any formats if there are
217 // multiple clashing previous registrations,
218 // but fail instead.
220 B_SET_DEFAULT = 0x4 // Set the first format to be the default for
221 // the format family (when registering more
222 // than one in the same family). Only use in
223 // Encoder add-ons.
226 status_t MakeFormatFor(const media_format_description*
227 descriptions, int32 descriptionCount,
228 media_format* _inOutFormat,
229 uint32 flags = 0, void* _reserved = 0);
231 status_t GetFormatFor(const media_format_description&
232 description, media_format* _outFormat);
234 status_t GetCodeFor(const media_format& format,
235 media_format_family family,
236 media_format_description* _outDescription);
238 status_t RewindFormats();
239 status_t GetNextFormat(media_format* _outFormat,
240 media_format_description* _outDescription);
242 // You need to lock/unlock (only) when using
243 // RewindFormats()/GetNextFormat().
244 bool Lock();
245 void Unlock();
247 // convenience functions
248 static status_t GetBeOSFormatFor(uint32 fourcc,
249 media_format* _outFormat,
250 media_type type = B_MEDIA_UNKNOWN_TYPE);
251 static status_t GetAVIFormatFor(uint32 fourcc,
252 media_format* _outFormat,
253 media_type type = B_MEDIA_UNKNOWN_TYPE);
254 static status_t GetQuicktimeFormatFor(uint32 vendor,
255 uint32 fourcc, media_format* _outFormat,
256 media_type type = B_MEDIA_UNKNOWN_TYPE);
258 // Deprecated:
259 status_t MakeFormatFor(const media_format_description&
260 description, const media_format& inFormat,
261 media_format* _outFormat);
263 private:
264 int32 fIteratorIndex;
266 uint32 _reserved[30];
270 bool operator==(const media_format_description& a,
271 const media_format_description& b);
273 bool operator<(const media_format_description& a,
274 const media_format_description& b);
277 bool operator==(const GUID& a, const GUID& b);
279 bool operator<(const GUID& a, const GUID& b);
282 #endif // _MEDIA_TYPES_H