1 //=========================================================================
2 // FILENAME : tagutils-asf.h
3 // DESCRIPTION : ASF (wma/wmv) metadata reader
4 //=========================================================================
5 // Copyright (c) 2008- NETGEAR, Inc. All Rights Reserved.
6 //=========================================================================
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.
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.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #define __PACKED__ __attribute__((packed))
26 #ifdef HAVE_MACHINE_ENDIAN_H
27 #include <machine/endian.h>
32 typedef struct _GUID
{
38 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
39 GUID name = { l, { w1, w2 }, { b1, b2, b3, b4, b5, b6, b7, b8 } }
40 #define IsEqualGUID(rguid1, rguid2) (!memcmp(rguid1, rguid2, sizeof(GUID)))
42 #if __BYTE_ORDER == __LITTLE_ENDIAN
46 #define SWAP32(l) ( (((l) >> 24) & 0x000000ff) | (((l) >> 8) & 0x0000ff00) | (((l) << 8) & 0x00ff0000) | (((l) << 24) & 0xff000000) )
47 #define SWAP16(w) ( (((w) >> 8) & 0x00ff) | (((w) << 8) & 0xff00) )
50 DEFINE_GUID(ASF_StreamHeader
, SWAP32(0xb7dc0791), SWAP16(0xa9b7), SWAP16(0x11cf),
51 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65);
53 DEFINE_GUID(ASF_VideoStream
, SWAP32(0xbc19efc0), SWAP16(0x5b4d), SWAP16(0x11cf),
54 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b);
56 DEFINE_GUID(ASF_AudioStream
, SWAP32(0xf8699e40), SWAP16(0x5b4d), SWAP16(0x11cf),
57 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b);
59 DEFINE_GUID(ASF_HeaderObject
, SWAP32(0x75b22630), SWAP16(0x668e), SWAP16(0x11cf),
60 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c);
62 DEFINE_GUID(ASF_FileProperties
, SWAP32(0x8cabdca1), SWAP16(0xa947), SWAP16(0x11cf),
63 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65);
65 DEFINE_GUID(ASF_ContentDescription
, SWAP32(0x75b22633), SWAP16(0x668e), SWAP16(0x11cf),
66 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c);
68 DEFINE_GUID(ASF_ExtendedContentDescription
, SWAP32(0xd2d0a440), SWAP16(0xe307), SWAP16(0x11d2),
69 0x97, 0xf0, 0x00, 0xa0, 0xc9, 0x5e, 0xa8, 0x50);
71 DEFINE_GUID(ASF_ClientGuid
, SWAP32(0x8d262e32), SWAP16(0xfc28), SWAP16(0x11d7),
72 0xa9, 0xea, 0x00, 0x04, 0x5a, 0x6b, 0x76, 0xc2);
74 DEFINE_GUID(ASF_HeaderExtension
, SWAP32(0x5fbf03b5), SWAP16(0xa92e), SWAP16(0x11cf),
75 0x8e, 0xe3, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65);
77 DEFINE_GUID(ASF_CodecList
, SWAP32(0x86d15240), SWAP16(0x311d), SWAP16(0x11d0),
78 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6);
80 DEFINE_GUID(ASF_DataObject
, SWAP32(0x75b22636), SWAP16(0x668e), SWAP16(0x11cf),
81 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c);
83 DEFINE_GUID(ASF_PaddingObject
, SWAP32(0x1806d474), SWAP16(0xcadf), SWAP16(0x4509),
84 0xa4, 0xba, 0x9a, 0xab, 0xcb, 0x96, 0xaa, 0xe8);
86 DEFINE_GUID(ASF_SimpleIndexObject
, SWAP32(0x33000890), SWAP16(0xe5b1), SWAP16(0x11cf),
87 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb);
89 DEFINE_GUID(ASF_NoErrorCorrection
, SWAP32(0x20fb5700), SWAP16(0x5b55), SWAP16(0x11cf),
90 0xa8, 0xfd, 0x00, 0x80, 0x5f, 0x5c, 0x44, 0x2b);
92 DEFINE_GUID(ASF_AudioSpread
, SWAP32(0xbfc3cd50), SWAP16(0x618f), SWAP16(0x11cf),
93 0x8b, 0xb2, 0x00, 0xaa, 0x00, 0xb4, 0xe2, 0x20);
95 DEFINE_GUID(ASF_Reserved1
, SWAP32(0xabd3d211), SWAP16(0xa9ba), SWAP16(0x11cf),
96 0x8e, 0xe6, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65);
98 DEFINE_GUID(ASF_Reserved2
, SWAP32(0x86d15241), SWAP16(0x311d), SWAP16(0x11d0),
99 0xa3, 0xa4, 0x00, 0xa0, 0xc9, 0x03, 0x48, 0xf6);
101 DEFINE_GUID(ASF_ContentEncryptionObject
, SWAP32(0x2211B3FB), SWAP16(0xBD23), SWAP16(0x11D2),
102 0xB4, 0xB7, 0x00, 0xA0, 0xC9, 0x55, 0xFC, 0x6E);
104 DEFINE_GUID(ASF_ExtendedContentEncryptionObject
, SWAP32(0x298AE614), SWAP16(0x2622), SWAP16(0x4C17),
105 0xB9, 0x35, 0xDA, 0xE0, 0x7E, 0xE9, 0x28, 0x9C);
107 DEFINE_GUID(ASF_ExtendedStreamPropertiesObject
, SWAP32(0x14E6A5CB), SWAP16(0xC672), SWAP16(0x4332),
108 0x83, 0x99, 0xA9, 0x69, 0x52, 0x06, 0x5B, 0x5A);
110 DEFINE_GUID(ASF_MediaTypeAudio
, SWAP32(0x31178C9D), SWAP16(0x03E1), SWAP16(0x4528),
111 0xB5, 0x82, 0x3D, 0xF9, 0xDB, 0x22, 0xF5, 0x03);
113 DEFINE_GUID(ASF_FormatTypeWave
, SWAP32(0xC4C4C4D1), SWAP16(0x0049), SWAP16(0x4E2B),
114 0x98, 0xFB, 0x95, 0x37, 0xF6, 0xCE, 0x51, 0x6D);
116 DEFINE_GUID(ASF_StreamBufferStream
, SWAP32(0x3AFB65E2), SWAP16(0x47EF), SWAP16(0x40F2),
117 0xAC, 0x2C, 0x70, 0xA9, 0x0D, 0x71, 0xD3, 0x43);
119 typedef struct _BITMAPINFOHEADER
{
125 uint32_t biCompression
;
126 uint32_t biSizeImage
;
127 int32_t biXPelsPerMeter
;
128 int32_t biYPelsPerMeter
;
130 uint32_t biClrImportant
;
131 } __PACKED__ BITMAPINFOHEADER
;
133 typedef struct _WAVEFORMATEX
{
136 uint32_t nSamplesPerSec
;
137 uint32_t nAvgBytesPerSec
;
138 uint16_t nBlockAlign
;
139 uint16_t wBitsPerSample
;
141 } __PACKED__ WAVEFORMATEX
;
143 typedef struct _asf_stream_object_t
{
147 GUID ErrorCorrectionType
;
149 uint32_t TypeSpecificSize
;
150 uint32_t ErrorCorrectionSize
;
151 uint16_t StreamNumber
;
153 } __PACKED__ asf_stream_object_t
;
155 typedef struct _asf_media_stream_t
{
156 asf_stream_object_t Hdr
;
159 uint32_t FixedSizeSamples
;
160 uint32_t TemporalCompression
;
164 } __PACKED__ asf_media_stream_t
;
166 typedef struct _avi_audio_format_t
{
169 uint32_t nSamplesPerSec
;
170 uint32_t nAvgBytesPerSec
;
171 uint16_t nBlockAlign
;
172 uint16_t wBitsPerSample
;
174 } __PACKED__ avi_audio_format_t
;
176 typedef struct _asf_extended_stream_object_t
{
181 uint32_t DataBitrate
;
183 uint32_t InitialBufferFullness
;
184 uint32_t AltDataBitrate
;
185 uint32_t AltBufferSize
;
186 uint32_t AltInitialBufferFullness
;
187 uint32_t MaximumObjectSize
;
189 uint16_t StreamNumber
;
190 uint16_t LanguageIDIndex
;
191 uint64_t AvgTimePerFrame
;
192 uint16_t StreamNameCount
;
193 uint16_t PayloadExtensionSystemCount
;
194 } __PACKED__ asf_extended_stream_object_t
;
196 typedef struct _asf_stream_name_t
{
199 } __PACKED__ asf_stream_name_t
;
201 typedef struct _asf_payload_extension_t
{
205 } __PACKED__ asf_payload_extension_t
;
209 typedef struct _asf_object_t
{
212 } __PACKED__ asf_object_t
;
214 typedef struct _asf_codec_entry_t
{
222 } __PACKED__ asf_codec_entry_t
;
224 typedef struct _asf_codec_list_t
{
229 asf_codec_entry_t Entries
[2];
230 asf_codec_entry_t VideoCodec
;
231 } __PACKED__ asf_codec_list_t
;
233 typedef struct _asf_content_description_t
{
236 uint16_t TitleLength
;
237 uint16_t AuthorLength
;
238 uint16_t CopyrightLength
;
239 uint16_t DescriptionLength
;
240 uint16_t RatingLength
;
244 uint32_t Description
;
246 } __PACKED__ asf_content_description_t
;
248 typedef struct _asf_file_properties_t
{
253 uint64_t CreationTime
;
254 uint64_t TotalPackets
;
255 uint64_t PlayDuration
;
256 uint64_t SendDuration
;
259 uint32_t MinPacketSize
;
260 uint32_t MaxPacketSize
;
262 } __PACKED__ asf_file_properties_t
;
264 typedef struct _asf_header_extension_t
{
270 } __PACKED__ asf_header_extension_t
;
272 typedef struct _asf_video_stream_t
{
273 asf_stream_object_t Hdr
;
276 uint8_t ReservedFlags
;
278 BITMAPINFOHEADER bmi
;
280 } __PACKED__ asf_video_stream_t
;
282 typedef struct _asf_audio_stream_t
{
283 asf_stream_object_t Hdr
;
285 } __PACKED__ asf_audio_stream_t
;
287 typedef struct _asf_payload_t
{
288 uint8_t StreamNumber
;
289 uint8_t MediaObjectNumber
;
290 uint32_t MediaObjectOffset
;
291 uint8_t ReplicatedDataLength
;
292 uint32_t ReplicatedData
[2];
293 uint32_t PayloadLength
;
294 } __PACKED__ asf_payload_t
;
296 typedef struct _asf_packet_t
{
301 uint8_t PropertyFlags
;
302 uint32_t PacketLength
;
304 uint32_t PaddingLength
;
307 uint8_t PayloadFlags
;
308 asf_payload_t Payload
;
309 } __PACKED__ asf_packet_t
;
311 typedef struct _asf_data_object_t
{
315 uint64_t TotalPackets
;
316 unsigned short Reserved
;
317 } __PACKED__ asf_data_object_t
;
319 typedef struct _asf_padding_object_t
{
322 } __PACKED__ asf_padding_object_t
;
324 typedef struct _asf_simple_index_object_t
{
328 uint32_t IndexEntryTimeInterval
;
329 uint32_t MaximumPacketCount
;
330 uint32_t IndexEntriesCount
;
331 } __PACKED__ asf_simple_index_object_t
;
333 typedef struct _asf_header_object_t
{
338 asf_header_extension_t HeaderExtension
;
339 asf_content_description_t ContentDescription
;
340 asf_file_properties_t FileProperties
;
341 asf_video_stream_t
* VideoStream
;
342 asf_audio_stream_t
* AudioStream
;
343 asf_codec_list_t CodecList
;
344 asf_padding_object_t PaddingObject
;
345 } __PACKED__ asf_header_object_t
;
348 #define ASF_VT_UNICODE (0)
349 #define ASF_VT_BYTEARRAY (1)
350 #define ASF_VT_BOOL (2)
351 #define ASF_VT_DWORD (3)
352 #define ASF_VT_QWORD (4)
353 #define ASF_VT_WORD (5)
355 static int _get_asffileinfo(char *file
, struct song_metadata
*psong
);