1 /* MediaFormats.h */ 2 /* Copyright 1998 Be Incorporated. All rights reserved. */ 3 4 #if !defined(_MEDIA_TYPES_H) 5 #define _MEDIA_TYPES_H 6 7 #if defined(__cplusplus) 8 #include <MediaDefs.h> 9 10 #include <Messenger.h> 11 #include <List.h> 12 #include <Locker.h> 13 #endif 14 15 16 struct media_codec_info { 17 char pretty_name[96]; // eg: "SuperSqueeze Encoder by Foo Inc" 18 char short_name[32]; // eg: "supersqueeze" 19 20 int32 id; // opaque id passed to BMediaFile::CreateTrack 21 int32 sub_id; 22 23 int32 pad[63]; 24 }; 25 26 // 27 // Use this to iterate through the available encoders for a file format. 28 // 29 status_t get_next_encoder(int32 *cookie, 30 const media_file_format *mfi, // this comes from get_next_file_format() 31 const media_format *input_format, // this is the type of data given to the encoder 32 media_format *output_format, // this is the type of data encoder will output 33 media_codec_info *ei); // information about the encoder 34 35 status_t get_next_encoder( 36 int32 *cookie, 37 const media_file_format *mfi, // this comes from get_next_file_format() 38 // pass NULL if you don't care 39 const media_format *input_format, // this is the type of data given to the 40 // encoder, wildcards are accepted 41 const media_format *output_format, // this is the type of data encoder 42 // you want the encoder to output. 43 // Wildcards are accepted 44 media_codec_info *ei, // information about the encoder 45 media_format *accepted_input_format,// this is the type of data that the 46 // encoder will accept as input. 47 // Wildcards in input_format will be 48 // specialized here. 49 media_format *accepted_output_format// this is the type of data that the 50 // encoder will output. 51 // Wildcards in output_format will be 52 // specialized here. 53 ); 54 55 56 status_t get_next_encoder(int32 *cookie, media_codec_info *ei); 57 58 enum media_file_accept_format_flags { 59 B_MEDIA_REJECT_WILDCARDS = 0x1 60 }; 61 62 bool does_file_accept_format(const media_file_format *mfi, 63 media_format *format, uint32 flags = 0); 64 65 typedef struct { 66 uint8 data[16]; 67 } GUID; 68 69 typedef struct { 70 int32 format; 71 } media_beos_description; 72 73 typedef struct { 74 uint32 codec; 75 uint32 vendor; 76 } media_quicktime_description; 77 78 typedef struct { 79 uint32 codec; 80 } media_avi_description; 81 82 typedef struct { 83 uint32 id; 84 } media_avr_description; 85 86 typedef struct { 87 GUID guid; 88 } media_asf_description; 89 90 enum mpeg_id { 91 B_MPEG_ANY = 0, 92 B_MPEG_1_AUDIO_LAYER_1 = 0x101, 93 B_MPEG_1_AUDIO_LAYER_2 = 0x102, 94 B_MPEG_1_AUDIO_LAYER_3 = 0x103, // "MP3" 95 B_MPEG_1_VIDEO = 0x111 96 }; 97 typedef struct { 98 uint32 id; 99 } media_mpeg_description; 100 101 typedef struct { 102 uint32 codec; 103 } media_wav_description; 104 105 typedef struct { 106 uint32 codec; 107 } media_aiff_description; 108 109 typedef struct { 110 uint32 file_format; 111 uint32 codec; 112 } media_misc_description; 113 114 typedef struct _media_format_description { 115 #if defined(__cplusplus) 116 _media_format_description(); 117 ~_media_format_description(); 118 _media_format_description(const _media_format_description & other); 119 _media_format_description & operator=(const _media_format_description & other); 120 #endif 121 media_format_family family; 122 uint32 _reserved_[3]; 123 union { 124 media_beos_description beos; 125 media_quicktime_description quicktime; 126 media_avi_description avi; 127 media_asf_description asf; 128 media_mpeg_description mpeg; 129 media_wav_description wav; 130 media_aiff_description aiff; 131 media_misc_description misc; 132 media_avr_description avr; 133 uint32 _reserved_[12]; 134 } u; 135 } media_format_description; 136 137 138 #if defined(__cplusplus) 139 140 namespace BPrivate { 141 class addon_list; 142 void dec_load_hook(void *arg, image_id imgid); 143 void extractor_load_hook(void *arg, image_id imgid); 144 class Extractor; 145 } 146 147 class BMediaFormats { 148 public: 149 BMediaFormats(); 150 virtual ~BMediaFormats(); 151 152 status_t InitCheck(); 153 154 // Make sure you memset() your descs to 0 before you start filling 155 // them in! Else you may register some bogus value. 156 enum make_format_flags { 157 B_EXCLUSIVE = 0x1, // Fail if this format has already been registered 158 B_NO_MERGE = 0x2, // Don't re-number any formats if there are multiple 159 // clashing previous registrations, but fail instead 160 B_SET_DEFAULT = 0x4 // Set the first format to be the default for the 161 // format family (when registering more than one in 162 // the same family). Only use in Encoder add-ons. 163 }; 164 status_t MakeFormatFor( 165 const media_format_description * descs, 166 int32 desc_count, 167 media_format * io_format, 168 uint32 flags = 0, 169 void * _reserved = 0); 170 status_t GetFormatFor( 171 const media_format_description & desc, 172 media_format * out_format); 173 174 // convenience functions 175 static status_t GetBeOSFormatFor( 176 uint32 fourcc, media_format * out_format, 177 media_type type = B_MEDIA_UNKNOWN_TYPE); 178 static status_t GetAVIFormatFor( 179 uint32 fourcc, media_format * out_format, 180 media_type type = B_MEDIA_UNKNOWN_TYPE); 181 static status_t GetQuicktimeFormatFor( 182 uint32 vendor, uint32 fourcc, media_format * out_format, 183 media_type type = B_MEDIA_UNKNOWN_TYPE); 184 185 status_t GetCodeFor( 186 const media_format & format, 187 media_format_family family, 188 media_format_description * out_description); 189 190 status_t RewindFormats(); 191 status_t GetNextFormat( 192 media_format * out_format, 193 media_format_description * out_description); 194 // You need to lock/unlock (only) when using RewindFormats()/GetNextFormat() 195 bool Lock(); 196 void Unlock(); 197 198 /* --- begin deprecated API --- */ 199 status_t MakeFormatFor( 200 const media_format_description & desc, 201 const media_format & in_format, 202 media_format * out_format); 203 private: 204 friend class BPrivate::addon_list; 205 friend void BPrivate::dec_load_hook(void *arg, image_id imgid); 206 friend void BPrivate::extractor_load_hook(void * arg, image_id imgid); 207 friend class BMediaDecoder; 208 friend class BMediaTrack; 209 friend class BPrivate::Extractor; 210 211 char _reserved_messenger[24]; // sizeof(BMessenger) 24 212 char _reserved_list[28]; // sizeof(BList) 28 213 char _reserved_locker[32]; // sizeof(BLocker) 36 214 int32 m_lock_count; 215 static int32 s_cleared; 216 static BMessenger s_server; 217 static BList s_formats; 218 static BLocker s_lock; 219 int32 m_index; 220 221 void clear_formats(); 222 static void ex_clear_formats_imp(); 223 static void clear_formats_imp(); 224 status_t get_formats(); 225 static status_t get_formats_imp(); 226 static BMessenger & get_server(); 227 228 static status_t bind_addon( 229 const char * addon, 230 const media_format * formats, 231 int32 count); 232 static bool is_bound( 233 const char * addon, 234 const media_format * formats, 235 int32 count); 236 static status_t find_addons( 237 const media_format * format, 238 BPrivate::addon_list & addons); 239 }; 240 241 _IMPEXP_MEDIA bool operator==(const media_format_description & a, const media_format_description & b); 242 _IMPEXP_MEDIA bool operator<(const media_format_description & a, const media_format_description & b); 243 244 _IMPEXP_MEDIA bool operator==(const GUID & a, const GUID & b); 245 _IMPEXP_MEDIA bool operator<(const GUID & a, const GUID & b); 246 #endif 247 248 #endif /* _MEDIA_TYPES_H */ 249 250