1//========================================================================= 2// FILENAME : tagutils-asf.h 3// DESCRIPTION : ASF (wma/wmv) metadata reader 4//========================================================================= 5// Copyright (c) 2008- NETGEAR, Inc. All Rights Reserved. 6//========================================================================= 7 8/* 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24 25#define __PACKED__ __attribute__((packed)) 26 27#include <endian.h> 28 29typedef struct _GUID { 30 __u32 l; 31 __u16 w[2]; 32 __u8 b[8]; 33} __PACKED__ GUID; 34 35#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 36 GUID name = { l, { w1, w2 }, { b1, b2, b3, b4, b5, b6, b7, b8 } } 37#define IsEqualGUID(rguid1, rguid2) (!memcmp(rguid1, rguid2, sizeof(GUID))) 38 39#if __BYTE_ORDER == __LITTLE_ENDIAN 40#define SWAP32(l) (l) 41#define SWAP16(w) (w) 42#else 43#define SWAP32(l) ( (((l) >> 24) & 0x000000ff) | (((l) >> 8) & 0x0000ff00) | (((l) << 8) & 0x00ff0000) | (((l) << 24) & 0xff000000) ) 44#define SWAP16(w) ( (((w) >> 8) & 0x00ff) | (((w) << 8) & 0xff00) ) 45#endif 46 47DEFINE_GUID(ASF_StreamHeader, SWAP32(0xb7dc0791), SWAP16(0xa9b7), SWAP16(0x11cf), 48 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65); 49 50DEFINE_GUID(ASF_VideoStream, SWAP32(0xbc19efc0), SWAP16(0x5b4d), SWAP16(0x11cf), 51 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b); 52 53DEFINE_GUID(ASF_AudioStream, SWAP32(0xf8699e40), SWAP16(0x5b4d), SWAP16(0x11cf), 54 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b); 55 56DEFINE_GUID(ASF_HeaderObject, SWAP32(0x75b22630), SWAP16(0x668e), SWAP16(0x11cf), 57 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c); 58 59DEFINE_GUID(ASF_FileProperties, SWAP32(0x8cabdca1), SWAP16(0xa947), SWAP16(0x11cf), 60 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65); 61 62DEFINE_GUID(ASF_ContentDescription, SWAP32(0x75b22633), SWAP16(0x668e), SWAP16(0x11cf), 63 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c); 64 65DEFINE_GUID(ASF_ExtendedContentDescription, SWAP32(0xd2d0a440), SWAP16(0xe307), SWAP16(0x11d2), 66 0x97, 0xf0, 0x00, 0xa0, 0xc9, 0x5e, 0xa8, 0x50); 67 68DEFINE_GUID(ASF_ClientGuid, SWAP32(0x8d262e32), SWAP16(0xfc28), SWAP16(0x11d7), 69 0xa9, 0xea, 0x00, 0x04, 0x5a, 0x6b, 0x76, 0xc2); 70 71DEFINE_GUID(ASF_HeaderExtension, SWAP32(0x5fbf03b5), SWAP16(0xa92e), SWAP16(0x11cf), 72 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65); 73 74DEFINE_GUID(ASF_CodecList, SWAP32(0x86d15240), SWAP16(0x311d), SWAP16(0x11d0), 75 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6); 76 77DEFINE_GUID(ASF_DataObject, SWAP32(0x75b22636), SWAP16(0x668e), SWAP16(0x11cf), 78 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c); 79 80DEFINE_GUID(ASF_PaddingObject, SWAP32(0x1806d474), SWAP16(0xcadf), SWAP16(0x4509), 81 0xa4, 0xba, 0x9a, 0xab, 0xcb, 0x96, 0xaa, 0xe8); 82 83DEFINE_GUID(ASF_SimpleIndexObject, SWAP32(0x33000890), SWAP16(0xe5b1), SWAP16(0x11cf), 84 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb); 85 86DEFINE_GUID(ASF_NoErrorCorrection, SWAP32(0x20fb5700), SWAP16(0x5b55), SWAP16(0x11cf), 87 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b); 88 89DEFINE_GUID(ASF_AudioSpread, SWAP32(0xbfc3cd50), SWAP16(0x618f), SWAP16(0x11cf), 90 0x8b, 0xb2, 0x00, 0xaa, 0x00, 0xb4, 0xe2, 0x20); 91 92DEFINE_GUID(ASF_Reserved1, SWAP32(0xabd3d211), SWAP16(0xa9ba), SWAP16(0x11cf), 93 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65); 94 95DEFINE_GUID(ASF_Reserved2, SWAP32(0x86d15241), SWAP16(0x311d), SWAP16(0x11d0), 96 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6); 97 98DEFINE_GUID(ASF_ContentEncryptionObject, SWAP32(0x2211B3FB), SWAP16(0xBD23), SWAP16(0x11D2), 99 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E); 100 101DEFINE_GUID(ASF_ExtendedContentEncryptionObject, SWAP32(0x298AE614), SWAP16(0x2622), SWAP16(0x4C17), 102 0xB9, 0x35, 0xDA, 0xE0, 0x7E, 0xE9, 0x28, 0x9C); 103 104DEFINE_GUID(ASF_ExtendedStreamPropertiesObject, SWAP32(0x14E6A5CB), SWAP16(0xC672), SWAP16(0x4332), 105 0x83, 0x99, 0xA9, 0x69, 0x52, 0x06, 0x5B, 0x5A); 106 107DEFINE_GUID(ASF_MediaTypeAudio, SWAP32(0x31178C9D), SWAP16(0x03E1), SWAP16(0x4528), 108 0xB5, 0x82, 0x3D, 0xF9, 0xDB, 0x22, 0xF5, 0x03); 109 110DEFINE_GUID(ASF_FormatTypeWave, SWAP32(0xC4C4C4D1), SWAP16(0x0049), SWAP16(0x4E2B), 111 0x98, 0xFB, 0x95, 0x37, 0xF6, 0xCE, 0x51, 0x6D); 112 113DEFINE_GUID(ASF_StreamBufferStream, SWAP32(0x3AFB65E2), SWAP16(0x47EF), SWAP16(0x40F2), 114 0xAC, 0x2C, 0x70, 0xA9, 0x0D, 0x71, 0xD3, 0x43); 115 116typedef struct _BITMAPINFOHEADER { 117 __u32 biSize; 118 __s32 biWidth; 119 __s32 biHeight; 120 __u16 biPlanes; 121 __u16 biBitCount; 122 __u32 biCompression; 123 __u32 biSizeImage; 124 __s32 biXPelsPerMeter; 125 __s32 biYPelsPerMeter; 126 __u32 biClrUsed; 127 __u32 biClrImportant; 128} __PACKED__ BITMAPINFOHEADER; 129 130typedef struct _WAVEFORMATEX { 131 __u16 wFormatTag; 132 __u16 nChannels; 133 __u32 nSamplesPerSec; 134 __u32 nAvgBytesPerSec; 135 __u16 nBlockAlign; 136 __u16 wBitsPerSample; 137 __u16 cbSize; 138} __PACKED__ WAVEFORMATEX; 139 140typedef struct _asf_stream_object_t { 141 GUID ID; 142 __u64 Size; 143 GUID StreamType; 144 GUID ErrorCorrectionType; 145 __u64 TimeOffset; 146 __u32 TypeSpecificSize; 147 __u32 ErrorCorrectionSize; 148 __u16 StreamNumber; 149 __u32 Reserved; 150} __PACKED__ asf_stream_object_t; 151 152typedef struct _asf_media_stream_t { 153 asf_stream_object_t Hdr; 154 GUID MajorType; 155 GUID SubType; 156 __u32 FixedSizeSamples; 157 __u32 TemporalCompression; 158 __u32 SampleSize; 159 GUID FormatType; 160 __u32 FormatSize; 161} __PACKED__ asf_media_stream_t; 162 163typedef struct _avi_audio_format_t { 164 __u16 wFormatTag; 165 __u16 nChannels; 166 __u32 nSamplesPerSec; 167 __u32 nAvgBytesPerSec; 168 __u16 nBlockAlign; 169 __u16 wBitsPerSample; 170 __u16 cbSize; 171} __PACKED__ avi_audio_format_t; 172 173typedef struct _asf_extended_stream_object_t { 174 GUID ID; 175 __u64 Size; 176 __u64 StartTime; 177 __u64 EndTime; 178 __u32 DataBitrate; 179 __u32 BufferSize; 180 __u32 InitialBufferFullness; 181 __u32 AltDataBitrate; 182 __u32 AltBufferSize; 183 __u32 AltInitialBufferFullness; 184 __u32 MaximumObjectSize; 185 __u32 Flags; 186 __u16 StreamNumber; 187 __u16 LanguageIDIndex; 188 __u64 AvgTimePerFrame; 189 __u16 StreamNameCount; 190 __u16 PayloadExtensionSystemCount; 191} __PACKED__ asf_extended_stream_object_t; 192 193typedef struct _asf_stream_name_t { 194 __u16 ID; 195 __u16 Length; 196} __PACKED__ asf_stream_name_t; 197 198typedef struct _asf_payload_extension_t { 199 GUID ID; 200 __u16 Size; 201 __u32 InfoLength; 202} __PACKED__ asf_payload_extension_t; 203 204 205 206typedef struct _asf_object_t { 207 GUID ID; 208 __u64 Size; 209} __PACKED__ asf_object_t; 210 211typedef struct _asf_codec_entry_t { 212 __u16 Type; 213 __u16 NameLen; 214 __u32 Name; 215 __u16 DescLen; 216 __u32 Desc; 217 __u16 InfoLen; 218 __u32 Info; 219} __PACKED__ asf_codec_entry_t; 220 221typedef struct _asf_codec_list_t { 222 GUID ID; 223 __u64 Size; 224 GUID Reserved; 225 __u64 NumEntries; 226 asf_codec_entry_t Entries[2]; 227 asf_codec_entry_t VideoCodec; 228} __PACKED__ asf_codec_list_t; 229 230typedef struct _asf_content_description_t { 231 GUID ID; 232 __u64 Size; 233 __u16 TitleLength; 234 __u16 AuthorLength; 235 __u16 CopyrightLength; 236 __u16 DescriptionLength; 237 __u16 RatingLength; 238 __u32 Title; 239 __u32 Author; 240 __u32 Copyright; 241 __u32 Description; 242 __u32 Rating; 243} __PACKED__ asf_content_description_t; 244 245typedef struct _asf_file_properties_t { 246 GUID ID; 247 __u64 Size; 248 GUID FileID; 249 __u64 FileSize; 250 __u64 CreationTime; 251 __u64 TotalPackets; 252 __u64 PlayDuration; 253 __u64 SendDuration; 254 __u64 Preroll; 255 __u32 Flags; 256 __u32 MinPacketSize; 257 __u32 MaxPacketSize; 258 __u32 MaxBitrate; 259} __PACKED__ asf_file_properties_t; 260 261typedef struct _asf_header_extension_t { 262 GUID ID; 263 __u64 Size; 264 GUID Reserved1; 265 __u16 Reserved2; 266 __u32 DataSize; 267} __PACKED__ asf_header_extension_t; 268 269typedef struct _asf_video_stream_t { 270 asf_stream_object_t Hdr; 271 __u32 Width; 272 __u32 Height; 273 __u8 ReservedFlags; 274 __u16 FormatSize; 275 BITMAPINFOHEADER bmi; 276 __u8 ebih[1]; 277} __PACKED__ asf_video_stream_t; 278 279typedef struct _asf_audio_stream_t { 280 asf_stream_object_t Hdr; 281 WAVEFORMATEX wfx; 282} __PACKED__ asf_audio_stream_t; 283 284typedef struct _asf_payload_t { 285 __u8 StreamNumber; 286 __u8 MediaObjectNumber; 287 __u32 MediaObjectOffset; 288 __u8 ReplicatedDataLength; 289 __u32 ReplicatedData[2]; 290 __u32 PayloadLength; 291} __PACKED__ asf_payload_t; 292 293typedef struct _asf_packet_t { 294 __u8 TypeFlags; 295 __u8 ECFlags; 296 __u8 ECType; 297 __u8 ECCycle; 298 __u8 PropertyFlags; 299 __u32 PacketLength; 300 __u32 Sequence; 301 __u32 PaddingLength; 302 __u32 SendTime; 303 __u16 Duration; 304 __u8 PayloadFlags; 305 asf_payload_t Payload; 306} __PACKED__ asf_packet_t; 307 308typedef struct _asf_data_object_t { 309 GUID ID; 310 __u64 Size; 311 GUID FileID; 312 __u64 TotalPackets; 313 unsigned short Reserved; 314} __PACKED__ asf_data_object_t; 315 316typedef struct _asf_padding_object_t { 317 GUID ID; 318 __u64 Size; 319} __PACKED__ asf_padding_object_t; 320 321typedef struct _asf_simple_index_object_t { 322 GUID ID; 323 __u64 Size; 324 GUID FileID; 325 __u32 IndexEntryTimeInterval; 326 __u32 MaximumPacketCount; 327 __u32 IndexEntriesCount; 328} __PACKED__ asf_simple_index_object_t; 329 330typedef struct _asf_header_object_t { 331 GUID ID; 332 __u64 Size; 333 __u32 NumObjects; 334 __u16 Reserved; 335 asf_header_extension_t HeaderExtension; 336 asf_content_description_t ContentDescription; 337 asf_file_properties_t FileProperties; 338 asf_video_stream_t * VideoStream; 339 asf_audio_stream_t * AudioStream; 340 asf_codec_list_t CodecList; 341 asf_padding_object_t PaddingObject; 342} __PACKED__ asf_header_object_t; 343 344 345#define ASF_VT_UNICODE (0) 346#define ASF_VT_BYTEARRAY (1) 347#define ASF_VT_BOOL (2) 348#define ASF_VT_DWORD (3) 349#define ASF_VT_QWORD (4) 350#define ASF_VT_WORD (5) 351 352static int _get_asffileinfo(char *file, struct song_metadata *psong); 353