2005-04-12 02:34:07 -04:00
|
|
|
/*
|
|
|
|
* WMA metatag parsing
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Ron Pedde (ron@pedde.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2005-04-14 02:23:05 -04:00
|
|
|
#include <errno.h>
|
2005-04-12 02:34:07 -04:00
|
|
|
#include <fcntl.h>
|
2006-11-14 00:29:32 -05:00
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#endif
|
2005-04-12 02:34:07 -04:00
|
|
|
#include <stdio.h>
|
2005-04-14 02:23:05 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-05-03 06:08:14 -04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2005-04-14 02:23:05 -04:00
|
|
|
|
2009-05-08 11:46:32 -04:00
|
|
|
#include "logger.h"
|
2009-06-07 12:58:02 -04:00
|
|
|
#include "db.h"
|
2005-04-12 02:34:07 -04:00
|
|
|
|
2009-05-08 11:46:32 -04:00
|
|
|
#define TRUE ((1 == 1))
|
|
|
|
#define FALSE (!TRUE)
|
|
|
|
|
2009-06-07 12:58:02 -04:00
|
|
|
typedef struct media_file_info MP3FILE;
|
|
|
|
|
2005-04-12 02:34:07 -04:00
|
|
|
typedef struct tag_wma_guidlist {
|
|
|
|
char *name;
|
|
|
|
char *guid;
|
|
|
|
char value[16];
|
|
|
|
} WMA_GUID;
|
|
|
|
|
|
|
|
WMA_GUID wma_guidlist[] = {
|
|
|
|
{ "ASF_Index_Object",
|
|
|
|
"D6E229D3-35DA-11D1-9034-00A0C90349BE",
|
|
|
|
"\xD3\x29\xE2\xD6\xDA\x35\xD1\x11\x90\x34\x00\xA0\xC9\x03\x49\xBE" },
|
|
|
|
{ "ASF_Extended_Stream_Properties_Object",
|
|
|
|
"14E6A5CB-C672-4332-8399-A96952065B5A",
|
|
|
|
"\xCB\xA5\xE6\x14\x72\xC6\x32\x43\x83\x99\xA9\x69\x52\x06\x5B\x5A" },
|
|
|
|
{ "ASF_Payload_Ext_Syst_Pixel_Aspect_Ratio",
|
|
|
|
"1B1EE554-F9EA-4BC8-821A-376B74E4C4B8",
|
|
|
|
"\x54\xE5\x1E\x1B\xEA\xF9\xC8\x4B\x82\x1A\x37\x6B\x74\xE4\xC4\xB8" },
|
|
|
|
{ "ASF_Bandwidth_Sharing_Object",
|
|
|
|
"A69609E6-517B-11D2-B6AF-00C04FD908E9",
|
|
|
|
"\xE6\x09\x96\xA6\x7B\x51\xD2\x11\xB6\xAF\x00\xC0\x4F\xD9\x08\xE9" },
|
|
|
|
{ "ASF_Payload_Extension_System_Timecode",
|
|
|
|
"399595EC-8667-4E2D-8FDB-98814CE76C1E",
|
|
|
|
"\xEC\x95\x95\x39\x67\x86\x2D\x4E\x8F\xDB\x98\x81\x4C\xE7\x6C\x1E" },
|
|
|
|
{ "ASF_Marker_Object",
|
|
|
|
"F487CD01-A951-11CF-8EE6-00C00C205365",
|
|
|
|
"\x01\xCD\x87\xF4\x51\xA9\xCF\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65" },
|
|
|
|
{ "ASF_Data_Object",
|
|
|
|
"75B22636-668E-11CF-A6D9-00AA0062CE6C",
|
|
|
|
"\x36\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C" },
|
|
|
|
{ "ASF_Content_Description_Object",
|
|
|
|
"75B22633-668E-11CF-A6D9-00AA0062CE6C",
|
|
|
|
"\x33\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C" },
|
|
|
|
{ "ASF_Reserved_1",
|
|
|
|
"ABD3D211-A9BA-11cf-8EE6-00C00C205365",
|
|
|
|
"\x11\xD2\xD3\xAB\xBA\xA9\xcf\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65" },
|
|
|
|
{ "ASF_Timecode_Index_Object",
|
|
|
|
"3CB73FD0-0C4A-4803-953D-EDF7B6228F0C",
|
|
|
|
"\xD0\x3F\xB7\x3C\x4A\x0C\x03\x48\x95\x3D\xED\xF7\xB6\x22\x8F\x0C" },
|
|
|
|
{ "ASF_Language_List_Object",
|
|
|
|
"7C4346A9-EFE0-4BFC-B229-393EDE415C85",
|
|
|
|
"\xA9\x46\x43\x7C\xE0\xEF\xFC\x4B\xB2\x29\x39\x3E\xDE\x41\x5C\x85" },
|
|
|
|
{ "ASF_No_Error_Correction",
|
|
|
|
"20FB5700-5B55-11CF-A8FD-00805F5C442B",
|
|
|
|
"\x00\x57\xFB\x20\x55\x5B\xCF\x11\xA8\xFD\x00\x80\x5F\x5C\x44\x2B" },
|
|
|
|
{ "ASF_Extended_Content_Description_Object",
|
|
|
|
"D2D0A440-E307-11D2-97F0-00A0C95EA850",
|
|
|
|
"\x40\xA4\xD0\xD2\x07\xE3\xD2\x11\x97\xF0\x00\xA0\xC9\x5E\xA8\x50" },
|
|
|
|
{ "ASF_Media_Object_Index_Parameters_Obj",
|
|
|
|
"6B203BAD-3F11-4E84-ACA8-D7613DE2CFA7",
|
|
|
|
"\xAD\x3B\x20\x6B\x11\x3F\x84\x4E\xAC\xA8\xD7\x61\x3D\xE2\xCF\xA7" },
|
|
|
|
{ "ASF_Codec_List_Object",
|
|
|
|
"86D15240-311D-11D0-A3A4-00A0C90348F6",
|
|
|
|
"\x40\x52\xD1\x86\x1D\x31\xD0\x11\xA3\xA4\x00\xA0\xC9\x03\x48\xF6" },
|
|
|
|
{ "ASF_Stream_Bitrate_Properties_Object",
|
|
|
|
"7BF875CE-468D-11D1-8D82-006097C9A2B2",
|
|
|
|
"\xCE\x75\xF8\x7B\x8D\x46\xD1\x11\x8D\x82\x00\x60\x97\xC9\xA2\xB2" },
|
|
|
|
{ "ASF_Script_Command_Object",
|
|
|
|
"1EFB1A30-0B62-11D0-A39B-00A0C90348F6",
|
|
|
|
"\x30\x1A\xFB\x1E\x62\x0B\xD0\x11\xA3\x9B\x00\xA0\xC9\x03\x48\xF6" },
|
|
|
|
{ "ASF_Degradable_JPEG_Media",
|
|
|
|
"35907DE0-E415-11CF-A917-00805F5C442B",
|
|
|
|
"\xE0\x7D\x90\x35\x15\xE4\xCF\x11\xA9\x17\x00\x80\x5F\x5C\x44\x2B" },
|
|
|
|
{ "ASF_Header_Object",
|
|
|
|
"75B22630-668E-11CF-A6D9-00AA0062CE6C",
|
|
|
|
"\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C" },
|
|
|
|
{ "ASF_Padding_Object",
|
|
|
|
"1806D474-CADF-4509-A4BA-9AABCB96AAE8",
|
|
|
|
"\x74\xD4\x06\x18\xDF\xCA\x09\x45\xA4\xBA\x9A\xAB\xCB\x96\xAA\xE8" },
|
|
|
|
{ "ASF_JFIF_Media",
|
|
|
|
"B61BE100-5B4E-11CF-A8FD-00805F5C442B",
|
|
|
|
"\x00\xE1\x1B\xB6\x4E\x5B\xCF\x11\xA8\xFD\x00\x80\x5F\x5C\x44\x2B" },
|
|
|
|
{ "ASF_Digital_Signature_Object",
|
|
|
|
"2211B3FC-BD23-11D2-B4B7-00A0C955FC6E",
|
|
|
|
"\xFC\xB3\x11\x22\x23\xBD\xD2\x11\xB4\xB7\x00\xA0\xC9\x55\xFC\x6E" },
|
|
|
|
{ "ASF_Metadata_Library_Object",
|
|
|
|
"44231C94-9498-49D1-A141-1D134E457054",
|
|
|
|
"\x94\x1C\x23\x44\x98\x94\xD1\x49\xA1\x41\x1D\x13\x4E\x45\x70\x54" },
|
|
|
|
{ "ASF_Payload_Ext_System_File_Name",
|
|
|
|
"E165EC0E-19ED-45D7-B4A7-25CBD1E28E9B",
|
|
|
|
"\x0E\xEC\x65\xE1\xED\x19\xD7\x45\xB4\xA7\x25\xCB\xD1\xE2\x8E\x9B" },
|
|
|
|
{ "ASF_Stream_Prioritization_Object",
|
|
|
|
"D4FED15B-88D3-454F-81F0-ED5C45999E24",
|
|
|
|
"\x5B\xD1\xFE\xD4\xD3\x88\x4F\x45\x81\xF0\xED\x5C\x45\x99\x9E\x24" },
|
|
|
|
{ "ASF_Bandwidth_Sharing_Exclusive",
|
|
|
|
"AF6060AA-5197-11D2-B6AF-00C04FD908E9",
|
|
|
|
"\xAA\x60\x60\xAF\x97\x51\xD2\x11\xB6\xAF\x00\xC0\x4F\xD9\x08\xE9" },
|
|
|
|
{ "ASF_Group_Mutual_Exclusion_Object",
|
|
|
|
"D1465A40-5A79-4338-B71B-E36B8FD6C249",
|
|
|
|
"\x40\x5A\x46\xD1\x79\x5A\x38\x43\xB7\x1B\xE3\x6B\x8F\xD6\xC2\x49" },
|
|
|
|
{ "ASF_Audio_Spread",
|
|
|
|
"BFC3CD50-618F-11CF-8BB2-00AA00B4E220",
|
|
|
|
"\x50\xCD\xC3\xBF\x8F\x61\xCF\x11\x8B\xB2\x00\xAA\x00\xB4\xE2\x20" },
|
|
|
|
{ "ASF_Advanced_Mutual_Exclusion_Object",
|
|
|
|
"A08649CF-4775-4670-8A16-6E35357566CD",
|
|
|
|
"\xCF\x49\x86\xA0\x75\x47\x70\x46\x8A\x16\x6E\x35\x35\x75\x66\xCD" },
|
|
|
|
{ "ASF_Payload_Ext_Syst_Sample_Duration",
|
|
|
|
"C6BD9450-867F-4907-83A3-C77921B733AD",
|
|
|
|
"\x50\x94\xBD\xC6\x7F\x86\x07\x49\x83\xA3\xC7\x79\x21\xB7\x33\xAD" },
|
|
|
|
{ "ASF_Stream_Properties_Object",
|
|
|
|
"B7DC0791-A9B7-11CF-8EE6-00C00C205365",
|
|
|
|
"\x91\x07\xDC\xB7\xB7\xA9\xCF\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65" },
|
|
|
|
{ "ASF_Metadata_Object",
|
|
|
|
"C5F8CBEA-5BAF-4877-8467-AA8C44FA4CCA",
|
|
|
|
"\xEA\xCB\xF8\xC5\xAF\x5B\x77\x48\x84\x67\xAA\x8C\x44\xFA\x4C\xCA" },
|
|
|
|
{ "ASF_Mutex_Unknown",
|
|
|
|
"D6E22A02-35DA-11D1-9034-00A0C90349BE",
|
|
|
|
"\x02\x2A\xE2\xD6\xDA\x35\xD1\x11\x90\x34\x00\xA0\xC9\x03\x49\xBE" },
|
|
|
|
{ "ASF_Content_Branding_Object",
|
|
|
|
"2211B3FA-BD23-11D2-B4B7-00A0C955FC6E",
|
|
|
|
"\xFA\xB3\x11\x22\x23\xBD\xD2\x11\xB4\xB7\x00\xA0\xC9\x55\xFC\x6E" },
|
|
|
|
{ "ASF_Content_Encryption_Object",
|
|
|
|
"2211B3FB-BD23-11D2-B4B7-00A0C955FC6E",
|
|
|
|
"\xFB\xB3\x11\x22\x23\xBD\xD2\x11\xB4\xB7\x00\xA0\xC9\x55\xFC\x6E" },
|
|
|
|
{ "ASF_Index_Parameters_Object",
|
|
|
|
"D6E229DF-35DA-11D1-9034-00A0C90349BE",
|
|
|
|
"\xDF\x29\xE2\xD6\xDA\x35\xD1\x11\x90\x34\x00\xA0\xC9\x03\x49\xBE" },
|
|
|
|
{ "ASF_Payload_Ext_System_Content_Type",
|
|
|
|
"D590DC20-07BC-436C-9CF7-F3BBFBF1A4DC",
|
|
|
|
"\x20\xDC\x90\xD5\xBC\x07\x6C\x43\x9C\xF7\xF3\xBB\xFB\xF1\xA4\xDC" },
|
|
|
|
{ "ASF_Web_Stream_Media_Subtype",
|
|
|
|
"776257D4-C627-41CB-8F81-7AC7FF1C40CC",
|
|
|
|
"\xD4\x57\x62\x77\x27\xC6\xCB\x41\x8F\x81\x7A\xC7\xFF\x1C\x40\xCC" },
|
|
|
|
{ "ASF_Web_Stream_Format",
|
|
|
|
"DA1E6B13-8359-4050-B398-388E965BF00C",
|
|
|
|
"\x13\x6B\x1E\xDA\x59\x83\x50\x40\xB3\x98\x38\x8E\x96\x5B\xF0\x0C" },
|
|
|
|
{ "ASF_Simple_Index_Object",
|
|
|
|
"33000890-E5B1-11CF-89F4-00A0C90349CB",
|
|
|
|
"\x90\x08\x00\x33\xB1\xE5\xCF\x11\x89\xF4\x00\xA0\xC9\x03\x49\xCB" },
|
|
|
|
{ "ASF_Error_Correction_Object",
|
|
|
|
"75B22635-668E-11CF-A6D9-00AA0062CE6C",
|
|
|
|
"\x35\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C" },
|
|
|
|
{ "ASF_Media_Object_Index_Object",
|
|
|
|
"FEB103F8-12AD-4C64-840F-2A1D2F7AD48C",
|
|
|
|
"\xF8\x03\xB1\xFE\xAD\x12\x64\x4C\x84\x0F\x2A\x1D\x2F\x7A\xD4\x8C" },
|
|
|
|
{ "ASF_Mutex_Language",
|
|
|
|
"D6E22A00-35DA-11D1-9034-00A0C90349BE",
|
|
|
|
"\x00\x2A\xE2\xD6\xDA\x35\xD1\x11\x90\x34\x00\xA0\xC9\x03\x49\xBE" },
|
|
|
|
{ "ASF_File_Transfer_Media",
|
|
|
|
"91BD222C-F21C-497A-8B6D-5AA86BFC0185",
|
|
|
|
"\x2C\x22\xBD\x91\x1C\xF2\x7A\x49\x8B\x6D\x5A\xA8\x6B\xFC\x01\x85" },
|
|
|
|
{ "ASF_Reserved_3",
|
|
|
|
"4B1ACBE3-100B-11D0-A39B-00A0C90348F6",
|
|
|
|
"\xE3\xCB\x1A\x4B\x0B\x10\xD0\x11\xA3\x9B\x00\xA0\xC9\x03\x48\xF6" },
|
|
|
|
{ "ASF_Bitrate_Mutual_Exclusion_Object",
|
|
|
|
"D6E229DC-35DA-11D1-9034-00A0C90349BE",
|
|
|
|
"\xDC\x29\xE2\xD6\xDA\x35\xD1\x11\x90\x34\x00\xA0\xC9\x03\x49\xBE" },
|
|
|
|
{ "ASF_Bandwidth_Sharing_Partial",
|
|
|
|
"AF6060AB-5197-11D2-B6AF-00C04FD908E9",
|
|
|
|
"\xAB\x60\x60\xAF\x97\x51\xD2\x11\xB6\xAF\x00\xC0\x4F\xD9\x08\xE9" },
|
|
|
|
{ "ASF_Command_Media",
|
|
|
|
"59DACFC0-59E6-11D0-A3AC-00A0C90348F6",
|
|
|
|
"\xC0\xCF\xDA\x59\xE6\x59\xD0\x11\xA3\xAC\x00\xA0\xC9\x03\x48\xF6" },
|
|
|
|
{ "ASF_Audio_Media",
|
|
|
|
"F8699E40-5B4D-11CF-A8FD-00805F5C442B",
|
|
|
|
"\x40\x9E\x69\xF8\x4D\x5B\xCF\x11\xA8\xFD\x00\x80\x5F\x5C\x44\x2B" },
|
|
|
|
{ "ASF_Reserved_2",
|
|
|
|
"86D15241-311D-11D0-A3A4-00A0C90348F6",
|
|
|
|
"\x41\x52\xD1\x86\x1D\x31\xD0\x11\xA3\xA4\x00\xA0\xC9\x03\x48\xF6" },
|
|
|
|
{ "ASF_Binary_Media",
|
|
|
|
"3AFB65E2-47EF-40F2-AC2C-70A90D71D343",
|
|
|
|
"\xE2\x65\xFB\x3A\xEF\x47\xF2\x40\xAC\x2C\x70\xA9\x0D\x71\xD3\x43" },
|
|
|
|
{ "ASF_Mutex_Bitrate",
|
|
|
|
"D6E22A01-35DA-11D1-9034-00A0C90349BE",
|
|
|
|
"\x01\x2A\xE2\xD6\xDA\x35\xD1\x11\x90\x34\x00\xA0\xC9\x03\x49\xBE" },
|
|
|
|
{ "ASF_Reserved_4",
|
|
|
|
"4CFEDB20-75F6-11CF-9C0F-00A0C90349CB",
|
|
|
|
"\x20\xDB\xFE\x4C\xF6\x75\xCF\x11\x9C\x0F\x00\xA0\xC9\x03\x49\xCB" },
|
|
|
|
{ "ASF_Alt_Extended_Content_Encryption_Obj",
|
|
|
|
"FF889EF1-ADEE-40DA-9E71-98704BB928CE",
|
|
|
|
"\xF1\x9E\x88\xFF\xEE\xAD\xDA\x40\x9E\x71\x98\x70\x4B\xB9\x28\xCE" },
|
|
|
|
{ "ASF_Timecode_Index_Parameters_Object",
|
|
|
|
"F55E496D-9797-4B5D-8C8B-604DFE9BFB24",
|
|
|
|
"\x6D\x49\x5E\xF5\x97\x97\x5D\x4B\x8C\x8B\x60\x4D\xFE\x9B\xFB\x24" },
|
|
|
|
{ "ASF_Header_Extension_Object",
|
|
|
|
"5FBF03B5-A92E-11CF-8EE3-00C00C205365",
|
|
|
|
"\xB5\x03\xBF\x5F\x2E\xA9\xCF\x11\x8E\xE3\x00\xC0\x0C\x20\x53\x65" },
|
|
|
|
{ "ASF_Video_Media",
|
|
|
|
"BC19EFC0-5B4D-11CF-A8FD-00805F5C442B",
|
|
|
|
"\xC0\xEF\x19\xBC\x4D\x5B\xCF\x11\xA8\xFD\x00\x80\x5F\x5C\x44\x2B" },
|
|
|
|
{ "ASF_Extended_Content_Encryption_Object",
|
|
|
|
"298AE614-2622-4C17-B935-DAE07EE9289C",
|
|
|
|
"\x14\xE6\x8A\x29\x22\x26\x17\x4C\xB9\x35\xDA\xE0\x7E\xE9\x28\x9C" },
|
|
|
|
{ "ASF_File_Properties_Object",
|
|
|
|
"8CABDCA1-A947-11CF-8EE4-00C00C205365",
|
|
|
|
"\xA1\xDC\xAB\x8C\x47\xA9\xCF\x11\x8E\xE4\x00\xC0\x0C\x20\x53\x65" },
|
|
|
|
{ NULL, NULL, "\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0" }
|
|
|
|
};
|
|
|
|
|
2005-04-14 02:23:05 -04:00
|
|
|
#define MAYBEFREE(x) { free((x)); }
|
|
|
|
|
2005-04-12 02:34:07 -04:00
|
|
|
typedef struct tag_wma_header {
|
|
|
|
unsigned char objectid[16];
|
|
|
|
unsigned long long size;
|
|
|
|
unsigned int objects;
|
|
|
|
char reserved1;
|
|
|
|
char reserved2;
|
2009-04-05 07:30:54 -04:00
|
|
|
} __attribute__((packed)) WMA_HEADER;
|
2006-11-14 00:29:32 -05:00
|
|
|
|
2005-04-12 02:34:07 -04:00
|
|
|
typedef struct tag_wma_subheader {
|
|
|
|
unsigned char objectid[16];
|
2005-04-14 02:23:05 -04:00
|
|
|
long long size;
|
2009-04-05 07:30:54 -04:00
|
|
|
} __attribute__((packed)) WMA_SUBHEADER;
|
2006-06-04 04:13:50 -04:00
|
|
|
|
|
|
|
typedef struct tag_wma_stream_properties {
|
|
|
|
unsigned char stream_type[16];
|
|
|
|
unsigned char codec_type[16];
|
|
|
|
char time_offset[8];
|
|
|
|
unsigned int tsdl;
|
|
|
|
unsigned int ecdl;
|
|
|
|
unsigned short int flags;
|
|
|
|
unsigned int reserved;
|
2009-04-05 07:30:54 -04:00
|
|
|
} __attribute__((packed)) WMA_STREAM_PROP;
|
2006-08-28 23:21:19 -04:00
|
|
|
|
|
|
|
typedef struct tag_wma_header_extension {
|
|
|
|
unsigned char reserved_1[16];
|
|
|
|
unsigned short int reserved_2;
|
|
|
|
unsigned int data_size;
|
2009-04-05 07:30:54 -04:00
|
|
|
} __attribute__((packed)) WMA_HEADER_EXT;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Forwards
|
2006-11-14 00:29:32 -05:00
|
|
|
*/
|
2005-05-29 23:41:31 -04:00
|
|
|
WMA_GUID *wma_find_guid(unsigned char *guid);
|
2005-04-14 02:23:05 -04:00
|
|
|
unsigned short int wma_convert_short(unsigned char *src);
|
|
|
|
unsigned int wma_convert_int(unsigned char *src);
|
|
|
|
unsigned long long wma_convert_ll(unsigned char *src);
|
2005-05-29 23:41:31 -04:00
|
|
|
char *wma_utf16toutf8(unsigned char *utf16, int len);
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_parse_content_description(int fd,int size, MP3FILE *pmp3);
|
|
|
|
int wma_parse_extended_content_description(int fd,int size, MP3FILE *pmp3, int extended);
|
|
|
|
int wma_parse_file_properties(int fd,int size, MP3FILE *pmp3);
|
|
|
|
int wma_parse_audio_media(int fd, int size, MP3FILE *pmp3);
|
|
|
|
int wma_parse_stream_properties(int fd, int size, MP3FILE *pmp3);
|
|
|
|
int wma_parse_header_extension(int fd, int size, MP3FILE *pmp3);
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* read an unsigned short int from the fd
|
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_file_read_short(int fd, unsigned short int *psi) {
|
2007-08-01 02:21:53 -04:00
|
|
|
uint32_t len;
|
2009-05-03 06:08:14 -04:00
|
|
|
int ret;
|
2007-09-25 03:50:48 -04:00
|
|
|
|
2007-08-01 02:21:53 -04:00
|
|
|
len = sizeof(unsigned short int);
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, psi, len);
|
|
|
|
if ((ret < 0) || (ret != len)) {
|
2006-02-26 03:46:24 -05:00
|
|
|
return 0;
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*psi = wma_convert_short((unsigned char *)psi);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* read an unsigned int from the fd
|
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_file_read_int(int fd, unsigned int *pi) {
|
2007-08-01 02:21:53 -04:00
|
|
|
uint32_t len;
|
2009-05-03 06:08:14 -04:00
|
|
|
int ret;
|
2007-09-25 03:50:48 -04:00
|
|
|
|
2007-08-01 02:21:53 -04:00
|
|
|
len = sizeof(unsigned int);
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, pi, len);
|
|
|
|
if((ret < 0) || (ret != len)) {
|
2006-02-26 03:46:24 -05:00
|
|
|
return 0;
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*pi = wma_convert_int((unsigned char *)pi);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* read an ll from the fd
|
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_file_read_ll(int fd, unsigned long long *pll) {
|
2007-08-01 02:21:53 -04:00
|
|
|
uint32_t len;
|
2009-05-03 06:08:14 -04:00
|
|
|
int ret;
|
2007-09-25 03:50:48 -04:00
|
|
|
|
2007-08-01 02:21:53 -04:00
|
|
|
len = sizeof(unsigned long long);
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, pll, len);
|
|
|
|
if((ret < 0) || (ret != len)) {
|
2006-02-26 03:46:24 -05:00
|
|
|
return 0;
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*pll = wma_convert_ll((unsigned char *)pll);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* read a utf-16le string as a utf8
|
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_file_read_utf16(int fd, int len, char **utf8) {
|
2005-04-14 02:23:05 -04:00
|
|
|
char *out;
|
|
|
|
unsigned char *utf16;
|
2009-05-03 06:08:14 -04:00
|
|
|
int ret;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
utf16=(unsigned char*)malloc(len);
|
|
|
|
if(!utf16)
|
2006-02-26 03:46:24 -05:00
|
|
|
return 0;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, utf16, len);
|
|
|
|
if((ret < 0) || (ret != len))
|
2006-02-26 03:46:24 -05:00
|
|
|
return 0;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
out = wma_utf16toutf8(utf16,len);
|
|
|
|
*utf8 = out;
|
|
|
|
free(utf16);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_file_read_bytes(int fd,int len, unsigned char **data) {
|
|
|
|
int ret;
|
2007-09-25 03:50:48 -04:00
|
|
|
|
2005-05-29 23:41:31 -04:00
|
|
|
*data = (unsigned char *)malloc(len);
|
2005-04-14 02:23:05 -04:00
|
|
|
if(!*data)
|
2006-02-26 03:46:24 -05:00
|
|
|
return 0;
|
2007-09-25 03:50:48 -04:00
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, *data, len);
|
|
|
|
if((ret < 0) || (ret != len))
|
2006-02-26 03:46:24 -05:00
|
|
|
return 0;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_parse_header_extension(int fd, int size, MP3FILE *pmp3) {
|
2006-08-28 23:21:19 -04:00
|
|
|
WMA_HEADER_EXT he;
|
|
|
|
WMA_SUBHEADER sh;
|
|
|
|
WMA_GUID *pguid;
|
2007-08-01 02:21:53 -04:00
|
|
|
int bytes_left; /* FIXME: uint32_t? */
|
|
|
|
uint64_t current;
|
|
|
|
uint32_t len;
|
2009-05-03 06:08:14 -04:00
|
|
|
int ret;
|
2006-08-28 23:21:19 -04:00
|
|
|
|
2007-08-01 02:21:53 -04:00
|
|
|
len = sizeof(he);
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, &he, len);
|
|
|
|
if((ret < 0) || (ret != len))
|
2006-08-28 23:21:19 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2006-10-15 23:19:10 -04:00
|
|
|
he.data_size = wma_convert_int((unsigned char *)&he.data_size);
|
2006-08-28 23:21:19 -04:00
|
|
|
bytes_left = he.data_size;
|
2009-12-31 16:21:19 -05:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"Found header ext of %d (%d) bytes\n",he.data_size,size);
|
2006-08-28 23:21:19 -04:00
|
|
|
|
|
|
|
while(bytes_left) {
|
|
|
|
/* read in a subheader */
|
2009-05-03 06:08:14 -04:00
|
|
|
current = lseek(fd, 0, SEEK_CUR);
|
2006-08-30 20:37:16 -04:00
|
|
|
|
2007-08-01 02:21:53 -04:00
|
|
|
len = sizeof(sh);
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, &sh, len);
|
|
|
|
if((ret < 0) || (ret != len))
|
2006-08-28 23:21:19 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2006-10-15 23:19:10 -04:00
|
|
|
sh.size = wma_convert_ll((unsigned char *)&sh.size);
|
2006-08-28 23:21:19 -04:00
|
|
|
pguid = wma_find_guid(sh.objectid);
|
|
|
|
if(!pguid) {
|
|
|
|
DPRINTF(E_DBG,L_SCAN," Unknown ext subheader: %02hhx%02hhx"
|
|
|
|
"%02hhx%02hhx-"
|
|
|
|
"%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-"
|
|
|
|
"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx\n",
|
|
|
|
sh.objectid[3],sh.objectid[2],
|
|
|
|
sh.objectid[1],sh.objectid[0],
|
|
|
|
sh.objectid[5],sh.objectid[4],
|
|
|
|
sh.objectid[7],sh.objectid[6],
|
|
|
|
sh.objectid[8],sh.objectid[9],
|
|
|
|
sh.objectid[10],sh.objectid[11],
|
|
|
|
sh.objectid[12],sh.objectid[13],
|
|
|
|
sh.objectid[14],sh.objectid[15]);
|
|
|
|
} else {
|
|
|
|
DPRINTF(E_DBG,L_SCAN," Found ext subheader: %s\n", pguid->name);
|
|
|
|
if(strcmp(pguid->name,"ASF_Metadata_Library_Object")==0) {
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_parse_extended_content_description(fd,size,pmp3,1))
|
2006-08-28 23:21:19 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-15 23:24:52 -04:00
|
|
|
DPRINTF(E_DBG,L_SCAN," Size: %lld\n",sh.size);
|
2006-08-30 20:37:16 -04:00
|
|
|
if(sh.size <= sizeof(sh))
|
|
|
|
return TRUE; /* guess we're done! */
|
2006-08-28 23:21:19 -04:00
|
|
|
|
2006-11-11 18:15:33 -05:00
|
|
|
bytes_left -= (long)sh.size;
|
2009-05-03 06:08:14 -04:00
|
|
|
lseek(fd,current + (uint64_t)sh.size,SEEK_SET);
|
2006-08-28 23:21:19 -04:00
|
|
|
}
|
|
|
|
|
2006-08-30 20:37:16 -04:00
|
|
|
return TRUE;
|
2006-08-28 23:21:19 -04:00
|
|
|
}
|
|
|
|
|
2006-06-04 04:13:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* another try to get stream codec type
|
|
|
|
*
|
|
|
|
* @param fd fd of the file we are reading from -- positioned at start
|
|
|
|
* @param size size of the content description block
|
|
|
|
* @param pmp3 the mp3 struct we are filling with gleaned data
|
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_parse_stream_properties(int fd, int size, MP3FILE *pmp3) {
|
2006-06-04 04:13:50 -04:00
|
|
|
WMA_STREAM_PROP sp;
|
|
|
|
WMA_GUID *pguid;
|
2007-08-01 02:21:53 -04:00
|
|
|
uint32_t len;
|
2009-05-03 06:08:14 -04:00
|
|
|
int ret;
|
2007-09-25 03:50:48 -04:00
|
|
|
|
2007-08-01 02:21:53 -04:00
|
|
|
len = sizeof(sp);
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, &sp, len);
|
|
|
|
if((ret < 0) || (ret != len))
|
2006-06-04 04:13:50 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pguid = wma_find_guid(sp.stream_type);
|
|
|
|
if(!pguid)
|
|
|
|
return TRUE;
|
|
|
|
|
2006-11-14 00:29:32 -05:00
|
|
|
if(strcmp(pguid->name,"ASF_Audio_Media") != 0)
|
2006-06-04 04:13:50 -04:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* it is an audio stream... find codec. The Type-Specific
|
|
|
|
* data should be a WAVEFORMATEX... so we'll leverage
|
|
|
|
* wma_parse_audio_media
|
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
return wma_parse_audio_media(fd,size - sizeof(WMA_STREAM_PROP),pmp3);
|
2006-06-04 04:13:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-11-14 00:29:32 -05:00
|
|
|
* parse the audio media section... This is essentially a
|
2006-06-04 04:13:50 -04:00
|
|
|
* WAVFORMATEX structure. Generally we only care about the
|
|
|
|
* codec type.
|
|
|
|
*
|
|
|
|
* @param fd fd of the file we are reading from -- positioned at start
|
|
|
|
* @param size size of the content description block
|
|
|
|
* @param pmp3 the mp3 struct we are filling with gleaned data
|
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_parse_audio_media(int fd, int size, MP3FILE *pmp3) {
|
2006-06-04 04:13:50 -04:00
|
|
|
unsigned short int codec;
|
|
|
|
|
2006-08-26 00:14:17 -04:00
|
|
|
if(size < 18)
|
2006-06-04 04:13:50 -04:00
|
|
|
return TRUE; /* we'll leave it wma. will work or not! */
|
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_short(fd,&codec)) {
|
2006-06-04 04:13:50 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"WMA Codec Type: %02X\n",codec);
|
|
|
|
|
|
|
|
switch(codec) {
|
2006-06-04 23:37:33 -04:00
|
|
|
case 0x0A:
|
|
|
|
MAYBEFREE(pmp3->codectype);
|
|
|
|
pmp3->codectype = strdup("wmav"); /* voice */
|
|
|
|
break;
|
2006-06-04 04:13:50 -04:00
|
|
|
case 0x162:
|
|
|
|
MAYBEFREE(pmp3->codectype);
|
2006-11-01 23:50:31 -05:00
|
|
|
MAYBEFREE(pmp3->type);
|
|
|
|
pmp3->codectype = strdup("wma"); /* pro */
|
|
|
|
pmp3->type = strdup("wmap");
|
2006-06-04 04:13:50 -04:00
|
|
|
break;
|
|
|
|
case 0x163:
|
|
|
|
MAYBEFREE(pmp3->codectype);
|
|
|
|
pmp3->codectype = strdup("wmal"); /* lossless */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-08-26 00:14:17 -04:00
|
|
|
/* might as well get the sample rate while we are at it */
|
2009-05-03 06:08:14 -04:00
|
|
|
lseek(fd,2,SEEK_CUR);
|
|
|
|
if(!wma_file_read_int(fd,(unsigned int *)&pmp3->samplerate))
|
2006-08-26 00:14:17 -04:00
|
|
|
return FALSE;
|
|
|
|
|
2006-06-04 04:13:50 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-04-14 02:23:05 -04:00
|
|
|
/**
|
|
|
|
* parse the extended content description object. this is an object that
|
|
|
|
* has ad-hoc tags, basically.
|
|
|
|
*
|
2005-06-01 22:26:04 -04:00
|
|
|
* @param fd fd of the file we are reading from -- positioned at start
|
|
|
|
* @param size size of the content description block
|
|
|
|
* @param pmp3 the mp3 struct we are filling with gleaned data
|
2005-04-14 02:23:05 -04:00
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_parse_extended_content_description(int fd,int size, MP3FILE *pmp3, int extended) {
|
2005-04-14 02:23:05 -04:00
|
|
|
unsigned short descriptor_count;
|
|
|
|
int index;
|
|
|
|
unsigned short descriptor_name_len;
|
2005-05-29 23:41:31 -04:00
|
|
|
char *descriptor_name;
|
2005-04-14 02:23:05 -04:00
|
|
|
unsigned short descriptor_value_type;
|
2006-08-28 23:21:19 -04:00
|
|
|
unsigned int descriptor_value_int;
|
2005-04-14 02:23:05 -04:00
|
|
|
unsigned short descriptor_value_len;
|
2006-08-28 23:21:19 -04:00
|
|
|
unsigned short language_list_index;
|
|
|
|
unsigned short stream_number;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
2005-05-29 23:41:31 -04:00
|
|
|
char *descriptor_byte_value=NULL;
|
2005-04-14 02:23:05 -04:00
|
|
|
unsigned int descriptor_int_value; /* bool and dword */
|
|
|
|
unsigned long long descriptor_ll_value;
|
|
|
|
unsigned short int descriptor_short_value;
|
|
|
|
int fail=0;
|
2006-05-02 23:37:31 -04:00
|
|
|
int track, tracknumber;
|
2006-05-30 15:28:25 -04:00
|
|
|
char numbuff[40];
|
2006-06-19 00:45:03 -04:00
|
|
|
char *tmp;
|
2007-07-31 00:34:33 -04:00
|
|
|
unsigned char *ptr;
|
2006-06-19 00:45:03 -04:00
|
|
|
|
2006-05-02 23:37:31 -04:00
|
|
|
|
|
|
|
track = tracknumber = 0;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"Reading extended content description object\n");
|
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_short(fd, &descriptor_count))
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
for(index = 0; index < descriptor_count; index++) {
|
2006-07-29 02:31:30 -04:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"Reading descr %d of %d\n",index,descriptor_count);
|
2006-08-28 23:21:19 -04:00
|
|
|
if(!extended) {
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_short(fd,&descriptor_name_len)) return FALSE;
|
|
|
|
if(!wma_file_read_utf16(fd,descriptor_name_len,&descriptor_name))
|
2006-08-28 23:21:19 -04:00
|
|
|
return FALSE;
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_short(fd,&descriptor_value_type)) {
|
2006-08-28 23:21:19 -04:00
|
|
|
free(descriptor_name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_short(fd,&descriptor_value_len)) {
|
2006-08-28 23:21:19 -04:00
|
|
|
free(descriptor_name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
descriptor_value_int = descriptor_value_len;
|
|
|
|
} else {
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_short(fd,&language_list_index)) return FALSE;
|
|
|
|
if(!wma_file_read_short(fd,&stream_number)) return FALSE;
|
|
|
|
if(!wma_file_read_short(fd,&descriptor_name_len)) return FALSE;
|
|
|
|
if(!wma_file_read_short(fd,&descriptor_value_type)) return FALSE;
|
|
|
|
if(!wma_file_read_int(fd,&descriptor_value_int)) return FALSE;
|
|
|
|
if(!wma_file_read_utf16(fd,descriptor_name_len,&descriptor_name))
|
2006-08-28 23:21:19 -04:00
|
|
|
return FALSE;
|
2006-02-26 03:46:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"Found descriptor: %s\n", descriptor_name);
|
|
|
|
|
|
|
|
/* see what kind it is */
|
|
|
|
switch(descriptor_value_type) {
|
|
|
|
case 0x0000: /* string */
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_utf16(fd,descriptor_value_int,
|
2006-02-26 03:46:24 -05:00
|
|
|
&descriptor_byte_value)) {
|
|
|
|
fail=1;
|
|
|
|
}
|
2006-05-30 15:28:25 -04:00
|
|
|
descriptor_int_value=atoi(descriptor_byte_value);
|
2006-02-26 03:46:24 -05:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"Type: string, value: %s\n",descriptor_byte_value);
|
|
|
|
break;
|
|
|
|
case 0x0001: /* byte array */
|
2006-08-28 23:21:19 -04:00
|
|
|
if(descriptor_value_int > 4096) {
|
2009-05-03 06:08:14 -04:00
|
|
|
lseek(fd,(uint64_t)descriptor_value_int,SEEK_CUR);
|
2006-07-29 02:31:30 -04:00
|
|
|
descriptor_byte_value = NULL;
|
|
|
|
} else {
|
2007-07-31 00:34:33 -04:00
|
|
|
ptr = (unsigned char *)descriptor_byte_value;
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_bytes(fd,descriptor_value_int,
|
2007-07-31 00:34:33 -04:00
|
|
|
&ptr)){
|
2006-07-29 02:31:30 -04:00
|
|
|
fail=1;
|
|
|
|
}
|
2006-02-26 03:46:24 -05:00
|
|
|
}
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"Type: bytes\n");
|
|
|
|
break;
|
|
|
|
case 0x0002: /* bool - dropthru */
|
|
|
|
case 0x0003: /* dword */
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_int(fd,&descriptor_int_value)) fail=1;
|
2006-02-26 03:46:24 -05:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"Type: int, value: %d\n",descriptor_int_value);
|
2006-05-30 15:28:25 -04:00
|
|
|
snprintf(numbuff,sizeof(numbuff)-1,"%d",descriptor_int_value);
|
|
|
|
descriptor_byte_value = strdup(numbuff);
|
2006-02-26 03:46:24 -05:00
|
|
|
break;
|
|
|
|
case 0x0004: /* qword */
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_ll(fd,&descriptor_ll_value)) fail=1;
|
2006-02-26 03:46:24 -05:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"Type: ll, value: %lld\n",descriptor_ll_value);
|
2006-05-30 15:28:25 -04:00
|
|
|
snprintf(numbuff,sizeof(numbuff)-1,"%lld",descriptor_ll_value);
|
|
|
|
descriptor_byte_value = strdup(numbuff);
|
2006-02-26 03:46:24 -05:00
|
|
|
break;
|
|
|
|
case 0x0005: /* word */
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_short(fd,&descriptor_short_value)) fail=1;
|
2006-02-26 03:46:24 -05:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"type: short, value %d\n",descriptor_short_value);
|
2006-05-30 15:28:25 -04:00
|
|
|
snprintf(numbuff,sizeof(numbuff)-1,"%d",descriptor_short_value);
|
|
|
|
descriptor_byte_value = strdup(numbuff);
|
|
|
|
break;
|
2006-08-28 23:21:19 -04:00
|
|
|
case 0x0006: /* guid */
|
2009-05-03 06:08:14 -04:00
|
|
|
lseek(fd,16,SEEK_CUR); /* skip it */
|
2006-08-28 23:21:19 -04:00
|
|
|
if(descriptor_name)
|
|
|
|
free(descriptor_name);
|
|
|
|
descriptor_name = strdup("");
|
|
|
|
descriptor_byte_value = NULL;
|
2006-02-26 03:46:24 -05:00
|
|
|
break;
|
2006-08-28 23:21:19 -04:00
|
|
|
default:
|
|
|
|
DPRINTF(E_LOG,L_SCAN,"Badly formatted wma file\n");
|
|
|
|
if(descriptor_name)
|
|
|
|
free(descriptor_name);
|
|
|
|
if(descriptor_byte_value)
|
|
|
|
free(descriptor_byte_value);
|
|
|
|
return FALSE;
|
2006-02-26 03:46:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(fail) {
|
2006-07-29 02:31:30 -04:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"Read fail on file\n");
|
2006-02-26 03:46:24 -05:00
|
|
|
free(descriptor_name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do stuff with what we found */
|
|
|
|
if(strcasecmp(descriptor_name,"wm/genre")==0) {
|
|
|
|
MAYBEFREE(pmp3->genre);
|
|
|
|
pmp3->genre = descriptor_byte_value;
|
|
|
|
descriptor_byte_value = NULL; /* don't free it! */
|
|
|
|
} else if(strcasecmp(descriptor_name,"wm/albumtitle")==0) {
|
|
|
|
MAYBEFREE(pmp3->album);
|
|
|
|
pmp3->album = descriptor_byte_value;
|
|
|
|
descriptor_byte_value = NULL;
|
|
|
|
} else if(strcasecmp(descriptor_name,"wm/track")==0) {
|
2006-05-30 15:28:25 -04:00
|
|
|
track = descriptor_int_value + 1;
|
2006-05-11 02:50:47 -04:00
|
|
|
} else if(strcasecmp(descriptor_name,"wm/shareduserrating")==0) {
|
|
|
|
/* what a strange rating strategy */
|
2006-05-17 01:53:02 -04:00
|
|
|
pmp3->rating = descriptor_int_value;
|
2006-05-11 02:50:47 -04:00
|
|
|
if(pmp3->rating == 99) {
|
|
|
|
pmp3->rating = 100;
|
|
|
|
} else {
|
|
|
|
if(pmp3->rating) {
|
2006-06-12 22:57:45 -04:00
|
|
|
pmp3->rating = ((pmp3->rating / 25) + 1) * 20;
|
2006-05-11 02:50:47 -04:00
|
|
|
}
|
|
|
|
}
|
2006-02-26 03:46:24 -05:00
|
|
|
} else if(strcasecmp(descriptor_name,"wm/tracknumber")==0) {
|
2006-05-30 15:28:25 -04:00
|
|
|
tracknumber = descriptor_int_value;
|
2006-02-26 03:46:24 -05:00
|
|
|
} else if(strcasecmp(descriptor_name,"wm/year")==0) {
|
|
|
|
pmp3->year = atoi(descriptor_byte_value);
|
|
|
|
} else if(strcasecmp(descriptor_name,"wm/composer")==0) {
|
2006-05-11 02:50:47 -04:00
|
|
|
/* get first one only */
|
|
|
|
if(!pmp3->composer) {
|
|
|
|
pmp3->composer = descriptor_byte_value;
|
|
|
|
descriptor_byte_value = NULL;
|
2006-06-19 00:45:03 -04:00
|
|
|
} else {
|
2006-11-14 00:29:32 -05:00
|
|
|
size = (int)strlen(pmp3->composer) + 1 +
|
2006-07-17 00:49:44 -04:00
|
|
|
(int)strlen(descriptor_byte_value) + 1;
|
2006-06-19 00:45:03 -04:00
|
|
|
tmp = malloc(size);
|
|
|
|
if(!tmp)
|
|
|
|
DPRINTF(E_FATAL,L_SCAN,"malloc: wma_ext_content_descr\n");
|
|
|
|
sprintf(tmp,"%s/%s",pmp3->composer,descriptor_byte_value);
|
|
|
|
free(pmp3->composer);
|
|
|
|
pmp3->composer=tmp;
|
2006-05-11 02:50:47 -04:00
|
|
|
}
|
2006-02-26 03:46:24 -05:00
|
|
|
} else if(strcasecmp(descriptor_name,"wm/albumartist")==0) {
|
2006-05-11 02:50:47 -04:00
|
|
|
/* get first one only */
|
2006-11-03 23:17:24 -05:00
|
|
|
if(!pmp3->album_artist) {
|
|
|
|
pmp3->album_artist = descriptor_byte_value;
|
2006-05-11 02:50:47 -04:00
|
|
|
descriptor_byte_value = NULL;
|
|
|
|
}
|
|
|
|
} else if(strcasecmp(descriptor_name,"author") == 0) {
|
2006-05-11 03:06:00 -04:00
|
|
|
/* get first one only */
|
2006-05-11 02:50:47 -04:00
|
|
|
if(!pmp3->artist) {
|
|
|
|
pmp3->artist = descriptor_byte_value;
|
|
|
|
descriptor_byte_value = NULL;
|
|
|
|
}
|
2006-02-26 03:46:24 -05:00
|
|
|
} else if(strcasecmp(descriptor_name,"wm/contengroupdescription")==0) {
|
|
|
|
MAYBEFREE(pmp3->grouping);
|
|
|
|
pmp3->grouping = descriptor_byte_value;
|
|
|
|
descriptor_byte_value = NULL;
|
|
|
|
} else if(strcasecmp(descriptor_name,"comment")==0) {
|
|
|
|
MAYBEFREE(pmp3->comment);
|
|
|
|
pmp3->comment = descriptor_byte_value;
|
|
|
|
descriptor_byte_value = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cleanup - done with this round */
|
|
|
|
if(descriptor_byte_value) {
|
|
|
|
free(descriptor_byte_value);
|
|
|
|
descriptor_byte_value = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(descriptor_name);
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
2006-05-02 23:37:31 -04:00
|
|
|
|
2006-05-06 18:34:46 -04:00
|
|
|
if(tracknumber) {
|
2006-05-02 23:37:31 -04:00
|
|
|
pmp3->track = tracknumber;
|
2006-05-06 18:34:46 -04:00
|
|
|
} else if(track) {
|
|
|
|
pmp3->track = track;
|
2006-05-02 23:37:31 -04:00
|
|
|
}
|
2006-05-11 02:50:47 -04:00
|
|
|
|
2006-05-11 03:06:00 -04:00
|
|
|
if((!pmp3->artist) && (pmp3->orchestra)) {
|
|
|
|
pmp3->artist = strdup(pmp3->orchestra);
|
2006-05-11 02:50:47 -04:00
|
|
|
}
|
|
|
|
|
2006-05-11 03:06:00 -04:00
|
|
|
if((pmp3->artist) && (!pmp3->orchestra)) {
|
2006-05-24 00:25:21 -04:00
|
|
|
pmp3->orchestra = strdup(pmp3->artist);
|
2006-05-11 02:50:47 -04:00
|
|
|
}
|
|
|
|
|
2005-06-01 22:26:04 -04:00
|
|
|
return TRUE;
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* parse the content description object. this is an object that
|
|
|
|
* contains lengths of title, author, copyright, descr, and rating
|
|
|
|
* then the utf-16le strings for each.
|
|
|
|
*
|
2005-06-01 22:26:04 -04:00
|
|
|
* @param fd fd of the file we are reading from -- positioned at start
|
|
|
|
* @param size size of the content description block
|
|
|
|
* @param pmp3 the mp3 struct we are filling with gleaned data
|
2005-04-14 02:23:05 -04:00
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_parse_content_description(int fd,int size, MP3FILE *pmp3) {
|
2005-04-14 02:23:05 -04:00
|
|
|
unsigned short sizes[5];
|
|
|
|
int index;
|
2005-05-29 23:41:31 -04:00
|
|
|
char *utf8;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
if(size < 10) /* must be at least enough room for the size block */
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
for(index=0; index < 5; index++) {
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_short(fd,&sizes[index]))
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
2005-04-12 02:34:07 -04:00
|
|
|
|
2005-04-14 02:23:05 -04:00
|
|
|
for(index=0;index<5;index++) {
|
2006-02-26 03:46:24 -05:00
|
|
|
if(sizes[index]) {
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_utf16(fd,sizes[index],&utf8))
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"Got item of length %d: %s\n",sizes[index],utf8);
|
2006-11-14 00:29:32 -05:00
|
|
|
|
2006-02-26 03:46:24 -05:00
|
|
|
switch(index) {
|
|
|
|
case 0: /* title */
|
|
|
|
if(pmp3->title)
|
|
|
|
free(pmp3->title);
|
|
|
|
pmp3->title = utf8;
|
|
|
|
break;
|
|
|
|
case 1: /* author */
|
|
|
|
if(pmp3->artist)
|
|
|
|
free(pmp3->artist);
|
|
|
|
pmp3->artist = utf8;
|
|
|
|
break;
|
|
|
|
case 2: /* copyright - dontcare */
|
2006-11-14 00:29:32 -05:00
|
|
|
free(utf8);
|
2006-02-26 03:46:24 -05:00
|
|
|
break;
|
|
|
|
case 3: /* description */
|
|
|
|
if(pmp3->comment)
|
|
|
|
free(pmp3->comment);
|
|
|
|
pmp3->comment = utf8;
|
|
|
|
break;
|
|
|
|
case 4: /* rating - dontcare */
|
|
|
|
free(utf8);
|
|
|
|
break;
|
|
|
|
default: /* can't get here */
|
|
|
|
DPRINTF(E_FATAL,L_SCAN,"This is not my beautiful wife.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
|
|
|
|
2005-06-01 22:26:04 -04:00
|
|
|
return TRUE;
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
|
|
|
|
2005-04-16 16:56:47 -04:00
|
|
|
/**
|
|
|
|
* parse the file properties object. this is an object that
|
|
|
|
* contains playtime and bitrate, primarily.
|
|
|
|
*
|
2005-06-01 22:26:04 -04:00
|
|
|
* @param fd fd of the file we are reading from -- positioned at start
|
|
|
|
* @param size size of the content description block
|
|
|
|
* @param pmp3 the mp3 struct we are filling with gleaned data
|
2005-04-16 16:56:47 -04:00
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
int wma_parse_file_properties(int fd,int size, MP3FILE *pmp3) {
|
2005-05-29 23:41:31 -04:00
|
|
|
unsigned long long play_duration;
|
|
|
|
unsigned long long send_duration;
|
|
|
|
unsigned long long preroll;
|
2006-11-14 00:29:32 -05:00
|
|
|
|
2005-05-29 23:41:31 -04:00
|
|
|
unsigned int max_bitrate;
|
2005-04-16 16:56:47 -04:00
|
|
|
|
|
|
|
/* skip guid (16 bytes), filesize (8), creation time (8),
|
2006-11-14 00:29:32 -05:00
|
|
|
* data packets (8)
|
2005-04-16 16:56:47 -04:00
|
|
|
*/
|
2009-05-03 06:08:14 -04:00
|
|
|
lseek(fd,40,SEEK_CUR);
|
2005-04-16 16:56:47 -04:00
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_ll(fd, &play_duration))
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-16 16:56:47 -04:00
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_ll(fd, &send_duration))
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-17 17:18:59 -04:00
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!wma_file_read_ll(fd, &preroll))
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-17 17:18:59 -04:00
|
|
|
|
2006-03-29 00:08:57 -05:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"play_duration: %lld, "
|
|
|
|
"send_duration: %lld, preroll: %lld\n",
|
|
|
|
play_duration, send_duration, preroll);
|
|
|
|
|
2005-04-17 17:18:59 -04:00
|
|
|
/* I'm not entirely certain what preroll is, but it seems
|
|
|
|
* to make it match up with what windows thinks is the song
|
|
|
|
* length.
|
|
|
|
*/
|
2006-03-29 00:08:57 -05:00
|
|
|
pmp3->song_length = (int)((play_duration / 10000) - preroll);
|
2006-11-14 00:29:32 -05:00
|
|
|
|
2005-04-17 17:18:59 -04:00
|
|
|
/* skip flags(4),
|
2005-04-16 16:56:47 -04:00
|
|
|
* min_packet_size (4), max_packet_size(4)
|
|
|
|
*/
|
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
lseek(fd,12,SEEK_CUR);
|
|
|
|
if(!wma_file_read_int(fd,&max_bitrate))
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-16 16:56:47 -04:00
|
|
|
|
|
|
|
pmp3->bitrate = max_bitrate/1000;
|
|
|
|
|
2005-06-01 22:26:04 -04:00
|
|
|
return TRUE;
|
2005-04-16 16:56:47 -04:00
|
|
|
}
|
|
|
|
|
2005-04-14 02:23:05 -04:00
|
|
|
/**
|
|
|
|
* convert utf16 string to utf8. This is a bit naive, but...
|
|
|
|
* Since utf-8 can't expand past 4 bytes per code point, and
|
|
|
|
* we're converting utf-16, we can't be more than 2n+1 bytes, so
|
2006-11-14 00:29:32 -05:00
|
|
|
* we'll just allocate that much.
|
2005-04-14 02:23:05 -04:00
|
|
|
*
|
|
|
|
* Probably it could be more efficiently calculated, but this will
|
|
|
|
* always work. Besides, these are small strings, and will be freed
|
|
|
|
* after the db insert.
|
|
|
|
*
|
2005-04-16 16:56:47 -04:00
|
|
|
* We assume this is utf-16LE, as it comes from windows
|
2005-04-14 02:23:05 -04:00
|
|
|
*
|
2005-06-01 22:26:04 -04:00
|
|
|
* @param utf16 utf-16 to convert
|
|
|
|
* @param len length of utf-16 string
|
2005-04-14 02:23:05 -04:00
|
|
|
*/
|
2005-05-29 23:41:31 -04:00
|
|
|
char *wma_utf16toutf8(unsigned char *utf16, int len) {
|
2005-04-14 02:23:05 -04:00
|
|
|
char *utf8;
|
2005-05-29 23:41:31 -04:00
|
|
|
unsigned char *src=utf16;
|
2005-04-14 02:23:05 -04:00
|
|
|
char *dst;
|
|
|
|
unsigned int w1, w2;
|
|
|
|
int bytes;
|
|
|
|
|
|
|
|
if(!len)
|
2006-02-26 03:46:24 -05:00
|
|
|
return NULL;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
2005-05-29 23:41:31 -04:00
|
|
|
utf8=(char *)malloc(len*2 + 1);
|
2005-04-14 02:23:05 -04:00
|
|
|
if(!utf8)
|
2006-02-26 03:46:24 -05:00
|
|
|
return NULL;
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
memset(utf8,0x0,len*2 + 1);
|
|
|
|
dst=utf8;
|
|
|
|
|
|
|
|
while((src+2) <= utf16+len) {
|
2006-02-26 03:46:24 -05:00
|
|
|
w1=src[1] << 8 | src[0];
|
|
|
|
src += 2;
|
|
|
|
if((w1 & 0xFC00) == 0xD800) { /* could be surrogate pair */
|
|
|
|
if(src+2 > utf16+len) {
|
2009-05-08 11:52:56 -04:00
|
|
|
DPRINTF(E_INFO,L_SCAN,"Invalid utf-16 in file\n");
|
2006-02-26 03:46:24 -05:00
|
|
|
free(utf8);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
w2 = src[3] << 8 | src[2];
|
|
|
|
if((w2 & 0xFC00) != 0xDC00) {
|
2009-05-08 11:52:56 -04:00
|
|
|
DPRINTF(E_INFO,L_SCAN,"Invalid utf-16 in file\n");
|
2006-02-26 03:46:24 -05:00
|
|
|
free(utf8);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get bottom 10 of each */
|
|
|
|
w1 = w1 & 0x03FF;
|
|
|
|
w1 = w1 << 10;
|
|
|
|
w1 = w1 | (w2 & 0x03FF);
|
|
|
|
|
|
|
|
/* add back the 0x10000 */
|
|
|
|
w1 += 0x10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now encode the original code point in utf-8 */
|
|
|
|
if (w1 < 0x80) {
|
|
|
|
*dst++ = w1;
|
|
|
|
bytes=0;
|
|
|
|
} else if (w1 < 0x800) {
|
|
|
|
*dst++ = 0xC0 | (w1 >> 6);
|
|
|
|
bytes=1;
|
|
|
|
} else if (w1 < 0x10000) {
|
|
|
|
*dst++ = 0xE0 | (w1 >> 12);
|
|
|
|
bytes=2;
|
|
|
|
} else {
|
|
|
|
*dst++ = 0xF0 | (w1 >> 18);
|
|
|
|
bytes=3;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(bytes) {
|
2006-05-03 00:21:28 -04:00
|
|
|
*dst++ = 0x80 | ((w1 >> (6*(bytes-1))) & 0x3f);
|
2006-02-26 03:46:24 -05:00
|
|
|
bytes--;
|
|
|
|
}
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return utf8;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lookup a guid by character
|
|
|
|
*
|
2005-06-01 22:26:04 -04:00
|
|
|
* @param guid 16 byte guid to look up
|
2005-04-14 02:23:05 -04:00
|
|
|
*/
|
2005-05-29 23:41:31 -04:00
|
|
|
WMA_GUID *wma_find_guid(unsigned char *guid) {
|
2005-04-12 02:34:07 -04:00
|
|
|
WMA_GUID *pguid = wma_guidlist;
|
|
|
|
|
|
|
|
while((pguid->name) && (memcmp(guid,pguid->value,16) != 0)) {
|
2006-02-26 03:46:24 -05:00
|
|
|
pguid++;
|
2005-04-12 02:34:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!pguid->name)
|
2006-02-26 03:46:24 -05:00
|
|
|
return NULL;
|
2005-04-12 02:34:07 -04:00
|
|
|
|
|
|
|
return pguid;
|
|
|
|
}
|
|
|
|
|
2005-04-14 02:23:05 -04:00
|
|
|
/**
|
|
|
|
* convert a short int in wrong-endian format to host-endian
|
|
|
|
*
|
2005-06-01 22:26:04 -04:00
|
|
|
* @param src pointer to 16-bit wrong-endian int
|
2005-04-14 02:23:05 -04:00
|
|
|
*/
|
|
|
|
unsigned short wma_convert_short(unsigned char *src) {
|
|
|
|
return src[1] << 8 |
|
2006-02-26 03:46:24 -05:00
|
|
|
src[0];
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* convert an int in wrong-endian format to host-endian
|
|
|
|
*
|
2005-06-01 22:26:04 -04:00
|
|
|
* @param src pointer to 32-bit wrong-endian int
|
2005-04-14 02:23:05 -04:00
|
|
|
*/
|
|
|
|
unsigned int wma_convert_int(unsigned char *src) {
|
|
|
|
return src[3] << 24 |
|
2006-02-26 03:46:24 -05:00
|
|
|
src[2] << 16 |
|
|
|
|
src[1] << 8 |
|
|
|
|
src[0];
|
2005-04-14 02:23:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* convert a long long wrong-endian format to host-endian
|
|
|
|
*
|
2005-06-01 22:26:04 -04:00
|
|
|
* @param src pointer to 64-bit wrong-endian int
|
2005-04-14 02:23:05 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned long long wma_convert_ll(unsigned char *src) {
|
|
|
|
unsigned int tmp_hi, tmp_lo;
|
|
|
|
unsigned long long retval;
|
|
|
|
|
|
|
|
tmp_hi = src[7] << 24 |
|
2006-02-26 03:46:24 -05:00
|
|
|
src[6] << 16 |
|
|
|
|
src[5] << 8 |
|
|
|
|
src[4];
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
tmp_lo = src[3] << 24 |
|
2006-02-26 03:46:24 -05:00
|
|
|
src[2] << 16 |
|
|
|
|
src[1] << 8 |
|
|
|
|
src[0];
|
2005-04-14 02:23:05 -04:00
|
|
|
|
|
|
|
retval = tmp_hi;
|
|
|
|
retval = (retval << 32) | tmp_lo;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get metainfo about a wma file
|
|
|
|
*
|
2005-06-01 22:26:04 -04:00
|
|
|
* @param filename full path to file to scan
|
|
|
|
* @param pmp3 MP3FILE struct to be filled with with metainfo
|
2005-04-14 02:23:05 -04:00
|
|
|
*/
|
2005-04-12 02:34:07 -04:00
|
|
|
int scan_get_wmainfo(char *filename, MP3FILE *pmp3) {
|
|
|
|
WMA_HEADER hdr;
|
|
|
|
WMA_SUBHEADER subhdr;
|
|
|
|
WMA_GUID *pguid;
|
2007-08-01 02:21:53 -04:00
|
|
|
uint64_t offset=0;
|
|
|
|
uint32_t len;
|
2005-04-12 02:34:07 -04:00
|
|
|
int item;
|
2005-06-01 22:26:04 -04:00
|
|
|
int res=TRUE;
|
2006-10-15 19:07:16 -04:00
|
|
|
int encrypted = 0;
|
2009-05-03 06:08:14 -04:00
|
|
|
int fd;
|
2009-04-05 16:42:03 -04:00
|
|
|
int ret;
|
2006-11-14 00:29:32 -05:00
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
2009-05-08 11:52:56 -04:00
|
|
|
DPRINTF(E_INFO,L_SCAN,"Error opening WMA file (%s): %s\n",filename,
|
2009-05-03 06:08:14 -04:00
|
|
|
strerror(errno));
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-12 02:34:07 -04:00
|
|
|
}
|
|
|
|
|
2007-08-01 02:21:53 -04:00
|
|
|
len = sizeof(hdr);
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, &hdr, len);
|
|
|
|
if((ret < 0) || (ret != len)) {
|
2009-05-08 11:52:56 -04:00
|
|
|
DPRINTF(E_INFO,L_SCAN,"Error reading from %s: %s\n",filename,
|
2007-08-01 02:21:53 -04:00
|
|
|
strerror(errno));
|
2009-05-03 06:08:14 -04:00
|
|
|
close(fd);
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-12 02:34:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pguid = wma_find_guid(hdr.objectid);
|
|
|
|
if(!pguid) {
|
2009-05-08 11:52:56 -04:00
|
|
|
DPRINTF(E_INFO,L_SCAN,"Could not find header in %s\n",filename);
|
2009-05-03 06:08:14 -04:00
|
|
|
close(fd);
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
2005-04-12 02:34:07 -04:00
|
|
|
}
|
|
|
|
|
2005-05-29 23:41:31 -04:00
|
|
|
hdr.objects=wma_convert_int((unsigned char *)&hdr.objects);
|
|
|
|
hdr.size=wma_convert_ll((unsigned char *)&hdr.size);
|
2005-04-12 02:34:07 -04:00
|
|
|
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"Found WMA header: %s\n",pguid->name);
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"Header size: %lld\n",hdr.size);
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"Header objects: %d\n",hdr.objects);
|
|
|
|
|
|
|
|
offset = sizeof(hdr); //hdr.size;
|
|
|
|
|
|
|
|
/* Now we just walk through all the headers and see if we
|
|
|
|
* find anything interesting
|
|
|
|
*/
|
2006-11-14 00:29:32 -05:00
|
|
|
|
2006-02-26 03:46:24 -05:00
|
|
|
for(item=0; item < (int) hdr.objects; item++) {
|
2009-05-03 06:08:14 -04:00
|
|
|
if(!lseek(fd,offset,SEEK_SET)) {
|
2009-05-08 11:52:56 -04:00
|
|
|
DPRINTF(E_INFO,L_SCAN,"Error seeking in %s\n",filename);
|
2009-05-03 06:08:14 -04:00
|
|
|
close(fd);
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-08-01 02:21:53 -04:00
|
|
|
len = sizeof(subhdr);
|
2009-05-03 06:08:14 -04:00
|
|
|
ret = read(fd, &subhdr, len);
|
|
|
|
if((ret < 0) || (ret != len)) {
|
2009-05-08 11:52:56 -04:00
|
|
|
DPRINTF(E_INFO,L_SCAN,"Error reading from %s: %s\n",filename,
|
2009-05-03 06:08:14 -04:00
|
|
|
strerror(errno));
|
|
|
|
close(fd);
|
2006-02-26 03:46:24 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
subhdr.size=wma_convert_ll((unsigned char *)&subhdr.size);
|
|
|
|
|
|
|
|
pguid = wma_find_guid(subhdr.objectid);
|
|
|
|
if(pguid) {
|
2009-12-31 16:21:19 -05:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"%ld: Found subheader: %s\n",
|
2006-08-28 23:21:19 -04:00
|
|
|
offset,pguid->name);
|
2006-02-26 03:46:24 -05:00
|
|
|
if(strcmp(pguid->name,"ASF_Content_Description_Object")==0) {
|
2009-05-03 06:08:14 -04:00
|
|
|
res &= wma_parse_content_description(fd,(int)subhdr.size,pmp3);
|
2006-02-26 03:46:24 -05:00
|
|
|
} else if (strcmp(pguid->name,"ASF_Extended_Content_Description_Object")==0) {
|
2009-05-03 06:08:14 -04:00
|
|
|
res &= wma_parse_extended_content_description(fd,(int)subhdr.size,pmp3,0);
|
2006-02-26 03:46:24 -05:00
|
|
|
} else if (strcmp(pguid->name,"ASF_File_Properties_Object")==0) {
|
2009-05-03 06:08:14 -04:00
|
|
|
res &= wma_parse_file_properties(fd,(int)subhdr.size,pmp3);
|
2006-06-04 04:13:50 -04:00
|
|
|
} else if (strcmp(pguid->name,"ASF_Audio_Media")==0) {
|
2009-05-03 06:08:14 -04:00
|
|
|
res &= wma_parse_audio_media(fd,(int)subhdr.size,pmp3);
|
2006-06-04 04:13:50 -04:00
|
|
|
} else if (strcmp(pguid->name,"ASF_Stream_Properties_Object")==0) {
|
2009-05-03 06:08:14 -04:00
|
|
|
res &= wma_parse_stream_properties(fd,(int)subhdr.size,pmp3);
|
2006-08-28 23:21:19 -04:00
|
|
|
} else if(strcmp(pguid->name,"ASF_Header_Extension_Object")==0) {
|
2009-05-03 06:08:14 -04:00
|
|
|
res &= wma_parse_header_extension(fd,(int)subhdr.size,pmp3);
|
2006-10-15 19:07:16 -04:00
|
|
|
} else if(strstr(pguid->name,"Content_Encryption_Object")) {
|
|
|
|
encrypted=1;
|
2006-02-26 03:46:24 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DPRINTF(E_DBG,L_SCAN,"Unknown subheader: %02hhx%02hhx%02hhx%02hhx-"
|
|
|
|
"%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-"
|
|
|
|
"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx\n",
|
|
|
|
subhdr.objectid[3],subhdr.objectid[2],
|
|
|
|
subhdr.objectid[1],subhdr.objectid[0],
|
|
|
|
subhdr.objectid[5],subhdr.objectid[4],
|
|
|
|
subhdr.objectid[7],subhdr.objectid[6],
|
|
|
|
subhdr.objectid[8],subhdr.objectid[9],
|
|
|
|
subhdr.objectid[10],subhdr.objectid[11],
|
|
|
|
subhdr.objectid[12],subhdr.objectid[13],
|
|
|
|
subhdr.objectid[14],subhdr.objectid[15]);
|
|
|
|
|
|
|
|
}
|
2007-08-01 02:21:53 -04:00
|
|
|
offset += (uint64_t) subhdr.size;
|
2005-04-12 02:34:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-01 22:26:04 -04:00
|
|
|
if(!res) {
|
2009-05-08 11:52:56 -04:00
|
|
|
DPRINTF(E_INFO,L_SCAN,"Error reading meta info for file %s\n",
|
2007-08-01 02:21:53 -04:00
|
|
|
filename);
|
2005-04-16 16:56:47 -04:00
|
|
|
} else {
|
2006-02-26 03:46:24 -05:00
|
|
|
DPRINTF(E_DBG,L_SCAN,"Successfully parsed file\n");
|
2005-04-16 16:56:47 -04:00
|
|
|
}
|
|
|
|
|
2009-05-03 06:08:14 -04:00
|
|
|
close(fd);
|
2006-10-15 19:07:16 -04:00
|
|
|
|
|
|
|
if(encrypted) {
|
|
|
|
if(pmp3->codectype)
|
|
|
|
free(pmp3->codectype);
|
|
|
|
|
|
|
|
pmp3->codectype=strdup("wmap");
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:56:47 -04:00
|
|
|
return res;
|
2005-04-12 02:34:07 -04:00
|
|
|
}
|