| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#define ASF_BLOCK_SIZE 8192 |
| 18 |
|
| 19 |
#define IS_VALID_WMA_BASE (1) |
| 20 |
#define IS_VALID_WMA_FULL (1 << 1) |
| 21 |
#define IS_VALID_WMA_PRO (1 << 2) |
| 22 |
#define IS_VALID_WMA_LSL (1 << 3) |
| 23 |
#define IS_VALID_WMA_LSL_MULT5 (1 << 4) |
| 24 |
|
| 25 |
#undef DEFINE_GUID |
| 26 |
|
| 27 |
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ |
| 28 |
GUID name = {l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}} |
| 29 |
|
| 30 |
#define IsEqualGUID(rguid1, rguid2) (!memcmp(rguid1, rguid2, sizeof(GUID))) |
| 31 |
|
| 32 |
#define GETLEN2b(bits) (((bits) == 0x03) ? 4 : bits) |
| 33 |
|
| 34 |
DEFINE_GUID(ASF_Header_Object, 0x75b22630, 0x668e, 0x11cf, |
| 35 |
0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c); |
| 36 |
|
| 37 |
DEFINE_GUID(ASF_Content_Description, 0x75b22633, 0x668e, 0x11cf, |
| 38 |
0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c); |
| 39 |
|
| 40 |
DEFINE_GUID(ASF_File_Properties, 0x8cabdca1, 0xa947, 0x11cf, |
| 41 |
0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65); |
| 42 |
|
| 43 |
DEFINE_GUID(ASF_Stream_Properties, 0xb7dc0791, 0xa9b7, 0x11cf, |
| 44 |
0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65); |
| 45 |
|
| 46 |
DEFINE_GUID(ASF_Header_Extension, 0x5fbf03b5, 0xa92e, 0x11cf, |
| 47 |
0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65); |
| 48 |
|
| 49 |
DEFINE_GUID(ASF_Compatibility, 0x26f18b5d, 0x4584, 0x47ec, |
| 50 |
0x9f, 0x5f, 0x0e, 0x65, 0x1f, 0x04, 0x52, 0xc9); |
| 51 |
|
| 52 |
DEFINE_GUID(ASF_Metadata, 0xc5f8cbea, 0x5baf, 0x4877, |
| 53 |
0x84, 0x67, 0xaa, 0x8c, 0x44, 0xfa, 0x4c, 0xca); |
| 54 |
|
| 55 |
DEFINE_GUID(ASF_Padding, 0x1806d474, 0xcadf, 0x4509, |
| 56 |
0xa4, 0xba, 0x9a, 0xab, 0xcb, 0x96, 0xaa, 0xe8); |
| 57 |
|
| 58 |
DEFINE_GUID(ASF_Extended_Stream_Properties, 0x14E6A5CB, 0xC672, 0x4332, |
| 59 |
0x83, 0x99, 0xA9, 0x69, 0x52, 0x06, 0x5B, 0x5A); |
| 60 |
|
| 61 |
DEFINE_GUID(ASF_Extended_Content_Description, 0xd2d0a440, 0xe307, 0x11d2, |
| 62 |
0x97, 0xf0, 0x00, 0xa0, 0xc9, 0x5e, 0xa8, 0x50); |
| 63 |
|
| 64 |
DEFINE_GUID(ASF_Language_List, 0x7c4346a9, 0xefe0, 0x4bfc, |
| 65 |
0xb2, 0x29, 0x39, 0x3e, 0xde, 0x41, 0x5c, 0x85); |
| 66 |
|
| 67 |
DEFINE_GUID(ASF_Advanced_Mutual_Exclusion, 0xa08649cf, 0x4775, 0x4670, |
| 68 |
0x8a, 0x16, 0x6e, 0x35, 0x35, 0x75, 0x66, 0xcd); |
| 69 |
|
| 70 |
DEFINE_GUID(ASF_Index_Parameters, 0xd6e229df, 0x35da, 0x11d1, |
| 71 |
0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe); |
| 72 |
|
| 73 |
DEFINE_GUID(ASF_Codec_List, 0x86d15240, 0x311d, 0x11d0, |
| 74 |
0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6); |
| 75 |
|
| 76 |
DEFINE_GUID(ASF_Stream_Bitrate_Properties, 0x7bf875ce, 0x468d, 0x11d1, |
| 77 |
0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2); |
| 78 |
|
| 79 |
DEFINE_GUID(ASF_Metadata_Library, 0x44231c94, 0x9498, 0x49d1, |
| 80 |
0xa1, 0x41, 0x1d, 0x13, 0x4e, 0x45, 0x70, 0x54); |
| 81 |
|
| 82 |
DEFINE_GUID(ASF_Content_Encryption, 0x2211b3fb, 0xbd23, 0x11d2, |
| 83 |
0xb4, 0xb7, 0x00, 0xa0, 0xc9, 0x55, 0xfc, 0x6e); |
| 84 |
|
| 85 |
DEFINE_GUID(ASF_Extended_Content_Encryption, 0x298ae614, 0x2622, 0x4c17, |
| 86 |
0xb9, 0x35, 0xda, 0xe0, 0x7e, 0xe9, 0x28, 0x9c); |
| 87 |
|
| 88 |
DEFINE_GUID(ASF_Script_Command, 0x1efb1a30, 0x0b62, 0x11d0, |
| 89 |
0xa3, 0x9b, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6); |
| 90 |
|
| 91 |
DEFINE_GUID(ASF_Digital_Signature, 0x2211b3fc, 0xbd23, 0x11d2, |
| 92 |
0xb4, 0xb7, 0x00, 0xa0, 0xc9, 0x55, 0xfc, 0x6e); |
| 93 |
|
| 94 |
|
| 95 |
DEFINE_GUID(ASF_Index_Placeholder, 0xd9aade20, 0x7c17, 0x4f9c, |
| 96 |
0xbc, 0x28, 0x85, 0x55, 0xdd, 0x98, 0xe2, 0xa2); |
| 97 |
|
| 98 |
DEFINE_GUID(ASF_Error_Correction, 0x75b22635, 0x668e, 0x11cf, |
| 99 |
0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c); |
| 100 |
|
| 101 |
DEFINE_GUID(ASF_Data, 0x75b22636, 0x668e, 0x11cf, |
| 102 |
0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c); |
| 103 |
|
| 104 |
DEFINE_GUID(ASF_Index, 0xd6e229d3, 0x35da, 0x11d1, |
| 105 |
0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe); |
| 106 |
|
| 107 |
DEFINE_GUID(ASF_Simple_Index, 0x33000890, 0xe5b1, 0x11cf, |
| 108 |
0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb); |
| 109 |
|
| 110 |
|
| 111 |
DEFINE_GUID(ASF_Audio_Media, 0xf8699e40, 0x5b4d, 0x11cf, |
| 112 |
0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b); |
| 113 |
|
| 114 |
DEFINE_GUID(ASF_Video_Media, 0xbc19efc0, 0x5b4d, 0x11cf, |
| 115 |
0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b); |
| 116 |
|
| 117 |
DEFINE_GUID(ASF_Command_Media, 0x59dacfc0, 0x59e6, 0x11d0, |
| 118 |
0xa3, 0xac, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6); |
| 119 |
|
| 120 |
DEFINE_GUID(ASF_JFIF_Media, 0xb61be100, 0x5b4e, 0x11cf, |
| 121 |
0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b); |
| 122 |
|
| 123 |
DEFINE_GUID(ASF_Degradable_JPEG_Media, 0x35907de0, 0xe415, 0x11cf, |
| 124 |
0xa9, 0x17, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b); |
| 125 |
|
| 126 |
DEFINE_GUID(ASF_File_Transfer_Media, 0x91bd222c, 0xf21c, 0x497a, |
| 127 |
0x8b, 0x6d, 0x5a, 0xa8, 0x6b, 0xfc, 0x01, 0x85); |
| 128 |
|
| 129 |
DEFINE_GUID(ASF_Binary_Media, 0x3afb65e2, 0x47ef, 0x40f2, |
| 130 |
0xac, 0x2c, 0x70, 0xa9, 0x0d, 0x71, 0xd3, 0x43); |
| 131 |
|
| 132 |
|
| 133 |
DEFINE_GUID(ASF_No_Error_Correction, 0x20fb5700, 0x5b55, 0x11cf, |
| 134 |
0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b); |
| 135 |
|
| 136 |
DEFINE_GUID(ASF_Audio_Spread, 0xbfc3cd50, 0x618f, 0x11cf, |
| 137 |
0x8b, 0xb2, 0x00, 0xaa, 0x00, 0xb4, 0xe2, 0x20); |
| 138 |
|
| 139 |
|
| 140 |
DEFINE_GUID(ASF_Mutex_Language, 0xd6e22a00, 0x35da, 0x11d1, |
| 141 |
0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe); |
| 142 |
|
| 143 |
DEFINE_GUID(ASF_Mutex_Bitrate, 0xd6e22a01, 0x35da, 0x11d1, |
| 144 |
0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe); |
| 145 |
|
| 146 |
DEFINE_GUID(ASF_Mutex_Unknown, 0xd6e22a02, 0x35da, 0x11d1, |
| 147 |
0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe); |
| 148 |
|
| 149 |
typedef struct _asf_object_t { |
| 150 |
GUID ID; |
| 151 |
uint64_t size; |
| 152 |
uint32_t num_objects; |
| 153 |
uint8_t reserved1; |
| 154 |
uint8_t reserved2; |
| 155 |
} _PACKED ASF_Object; |
| 156 |
|
| 157 |
typedef struct asf_index_specs { |
| 158 |
uint16_t stream_number; |
| 159 |
uint16_t index_type; |
| 160 |
uint32_t time_interval; |
| 161 |
uint64_t block_pos; |
| 162 |
uint32_t entry_count; |
| 163 |
uint32_t *offsets; |
| 164 |
} asf_index_specs; |
| 165 |
|
| 166 |
typedef struct asfinfo { |
| 167 |
PerlIO *infile; |
| 168 |
char *file; |
| 169 |
Buffer *buf; |
| 170 |
Buffer *scratch; |
| 171 |
uint64_t file_size; |
| 172 |
uint64_t audio_offset; |
| 173 |
uint64_t audio_size; |
| 174 |
uint32_t object_offset; |
| 175 |
HV *info; |
| 176 |
HV *tags; |
| 177 |
|
| 178 |
uint8_t seeking; |
| 179 |
|
| 180 |
|
| 181 |
uint8_t valid_profiles; |
| 182 |
uint32_t max_bitrate; |
| 183 |
|
| 184 |
uint16_t spec_count; |
| 185 |
struct asf_index_specs *specs; |
| 186 |
} asfinfo; |
| 187 |
|
| 188 |
enum types { |
| 189 |
TYPE_UNICODE, |
| 190 |
TYPE_BYTE, |
| 191 |
TYPE_BOOL, |
| 192 |
TYPE_DWORD, |
| 193 |
TYPE_QWORD, |
| 194 |
TYPE_WORD, |
| 195 |
TYPE_GUID |
| 196 |
}; |
| 197 |
|
| 198 |
int get_asf_metadata(PerlIO *infile, char *file, HV *info, HV *tags); |
| 199 |
asfinfo * _asf_parse(PerlIO *infile, char *file, HV *info, HV *tags, uint8_t seeking); |
| 200 |
void _parse_content_description(asfinfo *asf); |
| 201 |
void _parse_extended_content_description(asfinfo *asf); |
| 202 |
void _parse_file_properties(asfinfo *asf); |
| 203 |
void _parse_stream_properties(asfinfo *asf); |
| 204 |
void _store_stream_info(int stream_number, HV *info, SV *key, SV *value); |
| 205 |
void _store_tag(HV *tags, SV *key, SV *value); |
| 206 |
int _parse_header_extension(asfinfo *asf, uint64_t len); |
| 207 |
void _parse_metadata(asfinfo *asf); |
| 208 |
void _parse_extended_stream_properties(asfinfo *asf, uint64_t len); |
| 209 |
void _parse_language_list(asfinfo *asf); |
| 210 |
void _parse_advanced_mutual_exclusion(asfinfo *asf); |
| 211 |
void _parse_codec_list(asfinfo *asf); |
| 212 |
void _parse_stream_bitrate_properties(asfinfo *asf); |
| 213 |
void _parse_metadata_library(asfinfo *asf); |
| 214 |
void _parse_index_parameters(asfinfo *asf); |
| 215 |
int _parse_index_objects(asfinfo *asf, int index_size); |
| 216 |
void _parse_index(asfinfo *asf, uint64_t size); |
| 217 |
void _parse_content_encryption(asfinfo *asf); |
| 218 |
void _parse_extended_content_encryption(asfinfo *asf); |
| 219 |
void _parse_script_command(asfinfo *asf); |
| 220 |
SV *_parse_picture(asfinfo *asf, uint32_t picture_offset); |
| 221 |
off_t asf_find_frame(PerlIO *infile, char *file, int offset); |
| 222 |
int _timestamp(asfinfo *asf, int offset, int *duration); |