2005-06-14 22:27:57 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Dave Chapman
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2005-06-14 22:27:57 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
2005-09-22 16:58:03 +00:00
|
|
|
#include <inttypes.h>
|
2005-06-14 22:27:57 +00:00
|
|
|
|
2007-06-16 18:19:51 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "logf.h"
|
2007-02-14 14:40:24 +00:00
|
|
|
#include "cuesheet.h"
|
2008-04-28 10:22:05 +00:00
|
|
|
#include "metadata.h"
|
2005-09-22 16:58:03 +00:00
|
|
|
|
2008-10-15 06:38:51 +00:00
|
|
|
#include "metadata/metadata_parsers.h"
|
|
|
|
|
2007-06-16 18:19:51 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-06-14 23:12:34 +00:00
|
|
|
|
2007-11-28 04:58:16 +00:00
|
|
|
/* For trailing tag stripping */
|
|
|
|
#include "buffering.h"
|
|
|
|
|
2007-06-16 18:19:51 +00:00
|
|
|
#include "metadata/metadata_common.h"
|
2005-06-27 00:12:40 +00:00
|
|
|
|
2006-10-25 16:57:53 +00:00
|
|
|
#endif /* CONFIG_CODEC == SWCODEC */
|
|
|
|
|
2008-10-15 06:38:51 +00:00
|
|
|
const struct afmt_entry audio_formats[AFMT_NUM_CODECS] =
|
|
|
|
{
|
|
|
|
/* Unknown file format */
|
|
|
|
[AFMT_UNKNOWN] =
|
|
|
|
AFMT_ENTRY("???", NULL, NULL, NULL ),
|
|
|
|
|
|
|
|
/* MPEG Audio layer 1 */
|
|
|
|
[AFMT_MPA_L1] =
|
|
|
|
AFMT_ENTRY("MP1", "mpa", NULL, "mp1\0" ),
|
|
|
|
/* MPEG Audio layer 2 */
|
|
|
|
[AFMT_MPA_L2] =
|
|
|
|
AFMT_ENTRY("MP2", "mpa", NULL, "mpa\0mp2\0" ),
|
|
|
|
/* MPEG Audio layer 3 */
|
|
|
|
[AFMT_MPA_L3] =
|
|
|
|
AFMT_ENTRY("MP3", "mpa", "mp3_enc", "mp3\0" ),
|
|
|
|
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
/* Audio Interchange File Format */
|
|
|
|
[AFMT_AIFF] =
|
|
|
|
AFMT_ENTRY("AIFF", "aiff", "aiff_enc", "aiff\0aif\0"),
|
2010-02-16 03:34:39 +00:00
|
|
|
/* Uncompressed PCM in a WAV file OR ATRAC3 stream in WAV file (.at3) */
|
2008-10-15 06:38:51 +00:00
|
|
|
[AFMT_PCM_WAV] =
|
2010-02-16 03:34:39 +00:00
|
|
|
AFMT_ENTRY("WAV", "wav", "wav_enc", "wav\0at3\0" ),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* Ogg Vorbis */
|
|
|
|
[AFMT_OGG_VORBIS] =
|
2008-10-30 01:17:26 +00:00
|
|
|
AFMT_ENTRY("Ogg", "vorbis", NULL, "ogg\0oga\0" ),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* FLAC */
|
|
|
|
[AFMT_FLAC] =
|
|
|
|
AFMT_ENTRY("FLAC", "flac", NULL, "flac\0" ),
|
|
|
|
/* Musepack */
|
|
|
|
[AFMT_MPC] =
|
|
|
|
AFMT_ENTRY("MPC", "mpc", NULL, "mpc\0" ),
|
|
|
|
/* A/52 (aka AC3) audio */
|
|
|
|
[AFMT_A52] =
|
|
|
|
AFMT_ENTRY("AC3", "a52", NULL, "a52\0ac3\0" ),
|
|
|
|
/* WavPack */
|
|
|
|
[AFMT_WAVPACK] =
|
|
|
|
AFMT_ENTRY("WV", "wavpack", "wavpack_enc", "wv\0" ),
|
|
|
|
/* Apple Lossless Audio Codec */
|
2009-07-27 12:13:22 +00:00
|
|
|
[AFMT_MP4_ALAC] =
|
2008-10-15 06:38:51 +00:00
|
|
|
AFMT_ENTRY("ALAC", "alac", NULL, "m4a\0m4b\0" ),
|
|
|
|
/* Advanced Audio Coding in M4A container */
|
2009-07-27 12:13:22 +00:00
|
|
|
[AFMT_MP4_AAC] =
|
2008-10-15 06:38:51 +00:00
|
|
|
AFMT_ENTRY("AAC", "aac", NULL, "mp4\0" ),
|
|
|
|
/* Shorten */
|
|
|
|
[AFMT_SHN] =
|
|
|
|
AFMT_ENTRY("SHN", "shorten", NULL, "shn\0" ),
|
|
|
|
/* SID File Format */
|
|
|
|
[AFMT_SID] =
|
|
|
|
AFMT_ENTRY("SID", "sid", NULL, "sid\0" ),
|
|
|
|
/* ADX File Format */
|
|
|
|
[AFMT_ADX] =
|
|
|
|
AFMT_ENTRY("ADX", "adx", NULL, "adx\0" ),
|
|
|
|
/* NESM (NES Sound Format) */
|
|
|
|
[AFMT_NSF] =
|
|
|
|
AFMT_ENTRY("NSF", "nsf", NULL, "nsf\0nsfe\0" ),
|
|
|
|
/* Speex File Format */
|
|
|
|
[AFMT_SPEEX] =
|
|
|
|
AFMT_ENTRY("Speex","speex", NULL, "spx\0" ),
|
|
|
|
/* SPC700 Save State */
|
|
|
|
[AFMT_SPC] =
|
|
|
|
AFMT_ENTRY("SPC", "spc", NULL, "spc\0" ),
|
|
|
|
/* APE (Monkey's Audio) */
|
|
|
|
[AFMT_APE] =
|
|
|
|
AFMT_ENTRY("APE", "ape", NULL, "ape\0mac\0" ),
|
|
|
|
/* WMA (WMAV1/V2 in ASF) */
|
|
|
|
[AFMT_WMA] =
|
|
|
|
AFMT_ENTRY("WMA", "wma", NULL, "wma\0wmv\0asf\0" ),
|
|
|
|
/* Amiga MOD File */
|
|
|
|
[AFMT_MOD] =
|
|
|
|
AFMT_ENTRY("MOD", "mod", NULL, "mod\0" ),
|
2010-02-04 17:31:10 +00:00
|
|
|
/* Atari SAP File */
|
2008-10-15 06:38:51 +00:00
|
|
|
[AFMT_SAP] =
|
|
|
|
AFMT_ENTRY("SAP", "asap", NULL, "sap\0" ),
|
2009-07-06 22:40:45 +00:00
|
|
|
/* Cook in RM/RA */
|
2009-07-27 12:13:22 +00:00
|
|
|
[AFMT_RM_COOK] =
|
2009-07-27 11:36:26 +00:00
|
|
|
AFMT_ENTRY("Cook", "cook", NULL, "rm\0ra\0rmvb\0" ),
|
2009-07-25 15:47:13 +00:00
|
|
|
/* AAC in RM/RA */
|
2009-07-27 12:13:22 +00:00
|
|
|
[AFMT_RM_AAC] =
|
2009-07-27 11:36:26 +00:00
|
|
|
AFMT_ENTRY("RAAC", "raac", NULL, "rm\0ra\0rmvb\0" ),
|
2009-08-04 13:54:06 +00:00
|
|
|
/* AC3 in RM/RA */
|
|
|
|
[AFMT_RM_AC3] =
|
2009-08-04 15:05:56 +00:00
|
|
|
AFMT_ENTRY("AC3", "a52_rm", NULL, "rm\0ra\0rmvb\0" ),
|
2009-08-14 17:36:57 +00:00
|
|
|
/* ATRAC3 in RM/RA */
|
|
|
|
[AFMT_RM_ATRAC3] =
|
|
|
|
AFMT_ENTRY("ATRAC3","atrac3_rm", NULL, "rm\0ra\0rmvb\0" ),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari CMC File */
|
|
|
|
[AFMT_CMC] =
|
|
|
|
AFMT_ENTRY("CMC", "asap", NULL, "cmc\0" ),
|
|
|
|
/* Atari CM3 File */
|
|
|
|
[AFMT_CM3] =
|
|
|
|
AFMT_ENTRY("CM3", "asap", NULL, "cm3\0" ),
|
|
|
|
/* Atari CMR File */
|
|
|
|
[AFMT_CMR] =
|
|
|
|
AFMT_ENTRY("CMR", "asap", NULL, "cmr\0" ),
|
|
|
|
/* Atari CMS File */
|
|
|
|
[AFMT_CMS] =
|
|
|
|
AFMT_ENTRY("CMS", "asap", NULL, "cms\0" ),
|
|
|
|
/* Atari DMC File */
|
|
|
|
[AFMT_DMC] =
|
|
|
|
AFMT_ENTRY("DMC", "asap", NULL, "dmc\0" ),
|
|
|
|
/* Atari DLT File */
|
|
|
|
[AFMT_DLT] =
|
|
|
|
AFMT_ENTRY("DLT", "asap", NULL, "dlt\0" ),
|
|
|
|
/* Atari MPT File */
|
|
|
|
[AFMT_MPT] =
|
|
|
|
AFMT_ENTRY("MPT", "asap", NULL, "mpt\0" ),
|
|
|
|
/* Atari MPD File */
|
|
|
|
[AFMT_MPD] =
|
|
|
|
AFMT_ENTRY("MPD", "asap", NULL, "mpd\0" ),
|
|
|
|
/* Atari RMT File */
|
|
|
|
[AFMT_RMT] =
|
|
|
|
AFMT_ENTRY("RMT", "asap", NULL, "rmt\0" ),
|
|
|
|
/* Atari TMC File */
|
|
|
|
[AFMT_TMC] =
|
|
|
|
AFMT_ENTRY("TMC", "asap", NULL, "tmc\0" ),
|
|
|
|
/* Atari TM8 File */
|
|
|
|
[AFMT_TM8] =
|
|
|
|
AFMT_ENTRY("TM8", "asap", NULL, "tm8\0" ),
|
|
|
|
/* Atari TM2 File */
|
|
|
|
[AFMT_TM2] =
|
|
|
|
AFMT_ENTRY("TM2", "asap", NULL, "tm2\0" ),
|
2010-02-12 03:21:37 +00:00
|
|
|
/* Atrac3 in Sony OMA Container */
|
|
|
|
[AFMT_OMA_ATRAC3] =
|
|
|
|
AFMT_ENTRY("ATRAC3", "atrac3_oma", NULL, "oma\0aa3\0" ),
|
2008-10-15 06:38:51 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#if CONFIG_CODEC == SWCODEC && defined (HAVE_RECORDING)
|
|
|
|
/* get REC_FORMAT_* corresponding AFMT_* */
|
|
|
|
const int rec_format_afmt[REC_NUM_FORMATS] =
|
|
|
|
{
|
|
|
|
/* give AFMT_UNKNOWN by default */
|
|
|
|
[0 ... REC_NUM_FORMATS-1] = AFMT_UNKNOWN,
|
|
|
|
/* add new entries below this line */
|
|
|
|
[REC_FORMAT_AIFF] = AFMT_AIFF,
|
|
|
|
[REC_FORMAT_MPA_L3] = AFMT_MPA_L3,
|
|
|
|
[REC_FORMAT_WAVPACK] = AFMT_WAVPACK,
|
|
|
|
[REC_FORMAT_PCM_WAV] = AFMT_PCM_WAV,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* get AFMT_* corresponding REC_FORMAT_* */
|
|
|
|
const int afmt_rec_format[AFMT_NUM_CODECS] =
|
|
|
|
{
|
|
|
|
/* give -1 by default */
|
|
|
|
[0 ... AFMT_NUM_CODECS-1] = -1,
|
|
|
|
/* add new entries below this line */
|
|
|
|
[AFMT_AIFF] = REC_FORMAT_AIFF,
|
|
|
|
[AFMT_MPA_L3] = REC_FORMAT_MPA_L3,
|
|
|
|
[AFMT_WAVPACK] = REC_FORMAT_WAVPACK,
|
|
|
|
[AFMT_PCM_WAV] = REC_FORMAT_PCM_WAV,
|
|
|
|
};
|
|
|
|
#endif /* CONFIG_CODEC == SWCODEC && defined (HAVE_RECORDING) */
|
|
|
|
|
2006-02-01 16:42:02 +00:00
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
/* Simple file type probing by looking at the filename extension. */
|
2006-03-26 11:33:42 +00:00
|
|
|
unsigned int probe_file_format(const char *filename)
|
2005-06-19 20:27:46 +00:00
|
|
|
{
|
2005-09-22 16:58:03 +00:00
|
|
|
char *suffix;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
suffix = strrchr(filename, '.');
|
2005-06-19 20:27:46 +00:00
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
if (suffix == NULL)
|
|
|
|
{
|
|
|
|
return AFMT_UNKNOWN;
|
2005-06-19 20:27:46 +00:00
|
|
|
}
|
2005-09-22 16:58:03 +00:00
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
/* skip '.' */
|
|
|
|
suffix++;
|
|
|
|
|
|
|
|
for (i = 1; i < AFMT_NUM_CODECS; i++)
|
|
|
|
{
|
|
|
|
/* search extension list for type */
|
|
|
|
const char *ext = audio_formats[i].ext_list;
|
2005-06-19 20:27:46 +00:00
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
do
|
2005-09-22 16:58:03 +00:00
|
|
|
{
|
2006-12-29 14:59:10 +00:00
|
|
|
if (strcasecmp(suffix, ext) == 0)
|
|
|
|
{
|
2006-11-06 18:07:30 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
ext += strlen(ext) + 1;
|
2005-09-22 16:58:03 +00:00
|
|
|
}
|
2006-11-06 18:07:30 +00:00
|
|
|
while (*ext != '\0');
|
2005-09-22 16:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return AFMT_UNKNOWN;
|
2005-06-19 20:27:46 +00:00
|
|
|
}
|
|
|
|
|
2008-10-15 06:38:51 +00:00
|
|
|
/* Note, that this returns false for successful, true for error! */
|
|
|
|
bool mp3info(struct mp3entry *entry, const char *filename)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return true;
|
|
|
|
|
2008-10-21 19:28:40 +00:00
|
|
|
result = !get_mp3_metadata(fd, entry, filename);
|
2008-10-15 06:38:51 +00:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
/* Get metadata for track - return false if parsing showed problems with the
|
|
|
|
* file that would prevent playback.
|
2005-06-19 20:27:46 +00:00
|
|
|
*/
|
2007-09-19 10:40:55 +00:00
|
|
|
bool get_metadata(struct mp3entry* id3, int fd, const char* trackname)
|
2005-06-19 20:27:46 +00:00
|
|
|
{
|
2007-10-05 16:02:35 +00:00
|
|
|
/* Clear the mp3entry to avoid having bogus pointers appear */
|
|
|
|
memset(id3, 0, sizeof(struct mp3entry));
|
|
|
|
|
2005-12-01 20:39:19 +00:00
|
|
|
/* Take our best guess at the codec type based on file extension */
|
2007-08-14 11:56:13 +00:00
|
|
|
id3->codectype = probe_file_format(trackname);
|
2005-12-01 20:39:19 +00:00
|
|
|
|
|
|
|
/* Load codec specific track tag information and confirm the codec type. */
|
2007-08-14 11:56:13 +00:00
|
|
|
switch (id3->codectype)
|
2005-09-22 16:58:03 +00:00
|
|
|
{
|
|
|
|
case AFMT_MPA_L1:
|
|
|
|
case AFMT_MPA_L2:
|
|
|
|
case AFMT_MPA_L3:
|
2007-09-19 10:40:55 +00:00
|
|
|
if (!get_mp3_metadata(fd, id3, trackname))
|
2005-09-22 16:58:03 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2005-06-19 20:27:46 +00:00
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
break;
|
2005-06-19 20:27:46 +00:00
|
|
|
|
2006-03-26 11:33:42 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-09-22 16:58:03 +00:00
|
|
|
case AFMT_FLAC:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_flac_metadata(fd, id3))
|
2005-09-22 16:58:03 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2005-06-19 20:27:46 +00:00
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
break;
|
|
|
|
|
2007-07-03 09:25:36 +00:00
|
|
|
case AFMT_WMA:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_asf_metadata(fd, id3))
|
2007-07-03 09:25:36 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-06-05 16:58:29 +00:00
|
|
|
case AFMT_APE:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_monkeys_metadata(fd, id3))
|
2007-06-05 16:58:29 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-14 11:56:13 +00:00
|
|
|
read_ape_tags(fd, id3);
|
2007-06-05 16:58:29 +00:00
|
|
|
break;
|
|
|
|
|
2005-10-10 18:18:24 +00:00
|
|
|
case AFMT_MPC:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_musepack_metadata(fd, id3))
|
2005-11-04 21:34:03 +00:00
|
|
|
return false;
|
2007-08-14 11:56:13 +00:00
|
|
|
read_ape_tags(fd, id3);
|
2005-10-10 18:18:24 +00:00
|
|
|
break;
|
2007-02-09 10:06:53 +00:00
|
|
|
|
2008-07-26 20:11:58 +00:00
|
|
|
case AFMT_OGG_VORBIS:
|
2007-02-09 10:06:53 +00:00
|
|
|
case AFMT_SPEEX:
|
2008-07-26 20:11:58 +00:00
|
|
|
if (!get_ogg_metadata(fd, id3))/*detects and handles Ogg/Speex files*/
|
2005-09-22 16:58:03 +00:00
|
|
|
{
|
|
|
|
return false;
|
2005-06-19 20:27:46 +00:00
|
|
|
}
|
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
break;
|
2005-06-19 20:27:46 +00:00
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
case AFMT_PCM_WAV:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_wave_metadata(fd, id3))
|
2005-09-22 16:58:03 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2005-07-05 08:43:36 +00:00
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AFMT_WAVPACK:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_wavpack_metadata(fd, id3))
|
2007-12-04 20:48:40 +00:00
|
|
|
{
|
2005-07-05 08:43:36 +00:00
|
|
|
return false;
|
2007-12-04 20:48:40 +00:00
|
|
|
}
|
2005-07-05 08:43:36 +00:00
|
|
|
|
2007-08-14 11:56:13 +00:00
|
|
|
read_ape_tags(fd, id3); /* use any apetag info we find */
|
2005-09-22 16:58:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AFMT_A52:
|
2007-12-04 20:48:40 +00:00
|
|
|
if (!get_a52_metadata(fd, id3))
|
2005-09-22 16:58:03 +00:00
|
|
|
{
|
|
|
|
return false;
|
2005-07-05 08:43:36 +00:00
|
|
|
}
|
2005-07-28 18:43:33 +00:00
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
break;
|
|
|
|
|
2009-07-27 12:13:22 +00:00
|
|
|
case AFMT_MP4_ALAC:
|
|
|
|
case AFMT_MP4_AAC:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_mp4_metadata(fd, id3))
|
2005-09-22 21:55:37 +00:00
|
|
|
{
|
2005-12-01 20:39:19 +00:00
|
|
|
return false;
|
2005-09-22 21:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2008-05-21 11:19:58 +00:00
|
|
|
case AFMT_MOD:
|
|
|
|
if (!get_mod_metadata(fd, id3))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2005-11-13 11:04:02 +00:00
|
|
|
case AFMT_SHN:
|
2007-08-14 11:56:13 +00:00
|
|
|
id3->vbr = true;
|
|
|
|
id3->filesize = filesize(fd);
|
|
|
|
if (!skip_id3v2(fd, id3))
|
2005-11-13 11:04:02 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* TODO: read the id3v2 header if it exists */
|
|
|
|
break;
|
2006-07-18 18:33:12 +00:00
|
|
|
|
|
|
|
case AFMT_SID:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_sid_metadata(fd, id3))
|
2006-07-18 18:33:12 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2007-12-04 20:48:40 +00:00
|
|
|
|
2007-02-14 03:34:55 +00:00
|
|
|
case AFMT_SPC:
|
2007-12-04 20:48:40 +00:00
|
|
|
if (!get_spc_metadata(fd, id3))
|
2007-03-03 06:08:28 +00:00
|
|
|
{
|
|
|
|
DEBUGF("get_spc_metadata error\n");
|
2007-12-04 20:48:40 +00:00
|
|
|
return false;
|
2007-03-03 06:08:28 +00:00
|
|
|
}
|
2007-08-14 11:56:13 +00:00
|
|
|
id3->filesize = filesize(fd);
|
|
|
|
id3->genre_string = id3_get_num_genre(36);
|
2007-02-14 03:49:09 +00:00
|
|
|
break;
|
2007-12-04 20:48:40 +00:00
|
|
|
|
2006-09-25 16:13:05 +00:00
|
|
|
case AFMT_ADX:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_adx_metadata(fd, id3))
|
2006-09-25 16:13:05 +00:00
|
|
|
{
|
|
|
|
DEBUGF("get_adx_metadata error\n");
|
|
|
|
return false;
|
|
|
|
}
|
2007-03-03 06:08:28 +00:00
|
|
|
|
2006-09-25 16:13:05 +00:00
|
|
|
break;
|
2007-12-04 20:48:40 +00:00
|
|
|
|
2007-01-25 18:06:17 +00:00
|
|
|
case AFMT_NSF:
|
2009-08-30 02:53:15 +00:00
|
|
|
if (!get_nsf_metadata(fd, id3))
|
2007-01-25 18:06:17 +00:00
|
|
|
{
|
2009-08-30 02:53:15 +00:00
|
|
|
DEBUGF("get_nsf_metadata error\n");
|
2007-01-25 18:06:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-03-03 06:08:28 +00:00
|
|
|
break;
|
2005-11-13 11:04:02 +00:00
|
|
|
|
2006-02-01 16:42:02 +00:00
|
|
|
case AFMT_AIFF:
|
2007-08-14 11:56:13 +00:00
|
|
|
if (!get_aiff_metadata(fd, id3))
|
2006-02-01 16:42:02 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2008-07-26 15:16:10 +00:00
|
|
|
|
|
|
|
case AFMT_SAP:
|
|
|
|
if (!get_asap_metadata(fd, id3))
|
|
|
|
{
|
|
|
|
DEBUGF("get_sap_metadata error\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
id3->filesize = filesize(fd);
|
|
|
|
id3->genre_string = id3_get_num_genre(36);
|
|
|
|
break;
|
2010-02-06 12:49:03 +00:00
|
|
|
|
|
|
|
case AFMT_CMC:
|
|
|
|
case AFMT_CM3:
|
|
|
|
case AFMT_CMR:
|
|
|
|
case AFMT_CMS:
|
|
|
|
case AFMT_DMC:
|
|
|
|
case AFMT_DLT:
|
|
|
|
case AFMT_MPT:
|
|
|
|
case AFMT_MPD:
|
|
|
|
case AFMT_RMT:
|
|
|
|
case AFMT_TMC:
|
|
|
|
case AFMT_TM8:
|
|
|
|
case AFMT_TM2:
|
|
|
|
id3->bitrate = 706;
|
|
|
|
id3->frequency = 44100;
|
|
|
|
id3->vbr = false;
|
|
|
|
id3->filesize = filesize(fd);
|
|
|
|
id3->genre_string = id3_get_num_genre(36);
|
|
|
|
break;
|
2009-07-27 12:13:22 +00:00
|
|
|
case AFMT_RM_COOK:
|
2009-07-06 22:40:45 +00:00
|
|
|
if (!get_rm_metadata(fd, id3))
|
|
|
|
{
|
|
|
|
DEBUGF("get_rm_metadata error\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2010-02-12 03:21:37 +00:00
|
|
|
case AFMT_OMA_ATRAC3:
|
|
|
|
if (!get_oma_metadata(fd, id3))
|
|
|
|
{
|
|
|
|
DEBUGF("get_oma_metadata error\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2008-07-26 15:16:10 +00:00
|
|
|
|
2006-10-25 16:57:53 +00:00
|
|
|
#endif /* CONFIG_CODEC == SWCODEC */
|
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
default:
|
2005-12-01 20:39:19 +00:00
|
|
|
/* If we don't know how to read the metadata, assume we can't play
|
|
|
|
the file */
|
|
|
|
return false;
|
2005-09-22 16:58:03 +00:00
|
|
|
break;
|
2005-07-28 20:21:54 +00:00
|
|
|
}
|
|
|
|
|
2005-12-01 20:39:19 +00:00
|
|
|
/* We have successfully read the metadata from the file */
|
2007-03-04 16:47:33 +00:00
|
|
|
|
2005-09-22 16:58:03 +00:00
|
|
|
lseek(fd, 0, SEEK_SET);
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(id3->path, trackname, sizeof(id3->path));
|
2005-09-22 16:58:03 +00:00
|
|
|
|
2005-07-05 08:43:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
2006-03-26 11:33:42 +00:00
|
|
|
|
2008-12-15 23:42:19 +00:00
|
|
|
#ifndef __PCTOOL__
|
2007-11-28 05:13:05 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2007-11-28 04:58:16 +00:00
|
|
|
void strip_tags(int handle_id)
|
|
|
|
{
|
|
|
|
static const unsigned char tag[] = "TAG";
|
|
|
|
static const unsigned char apetag[] = "APETAGEX";
|
|
|
|
size_t len, version;
|
2007-11-30 18:48:07 +00:00
|
|
|
void *tail;
|
2007-11-28 04:58:16 +00:00
|
|
|
|
2007-11-30 18:48:07 +00:00
|
|
|
if (bufgettail(handle_id, 128, &tail) != 128)
|
2007-11-28 04:58:16 +00:00
|
|
|
return;
|
|
|
|
|
2007-11-28 16:39:55 +00:00
|
|
|
if (memcmp(tail, tag, 3) == 0)
|
|
|
|
{
|
|
|
|
/* Skip id3v1 tag */
|
|
|
|
logf("Cutting off ID3v1 tag");
|
|
|
|
bufcuttail(handle_id, 128);
|
|
|
|
}
|
2007-11-28 04:58:16 +00:00
|
|
|
|
2007-11-28 16:39:55 +00:00
|
|
|
/* Get a new tail, as the old one may have been cut */
|
2007-11-30 18:48:07 +00:00
|
|
|
if (bufgettail(handle_id, 32, &tail) != 32)
|
2007-11-28 04:58:16 +00:00
|
|
|
return;
|
|
|
|
|
2007-11-28 16:39:55 +00:00
|
|
|
/* Check for APE tag (look for the APE tag footer) */
|
|
|
|
if (memcmp(tail, apetag, 8) != 0)
|
|
|
|
return;
|
2007-11-28 04:58:16 +00:00
|
|
|
|
|
|
|
/* Read the version and length from the footer */
|
2007-11-30 18:48:07 +00:00
|
|
|
version = get_long_le(&((unsigned char *)tail)[8]);
|
|
|
|
len = get_long_le(&((unsigned char *)tail)[12]);
|
2007-11-28 04:58:16 +00:00
|
|
|
if (version == 2000)
|
|
|
|
len += 32; /* APEv2 has a 32 byte header */
|
|
|
|
|
|
|
|
/* Skip APE tag */
|
|
|
|
logf("Cutting off APE tag (%ldB)", len);
|
|
|
|
bufcuttail(handle_id, len);
|
|
|
|
}
|
2007-11-28 05:13:05 +00:00
|
|
|
#endif /* CONFIG_CODEC == SWCODEC */
|
2008-12-15 23:42:19 +00:00
|
|
|
#endif /* ! __PCTOOL__ */
|
2008-10-15 06:38:51 +00:00
|
|
|
|
|
|
|
void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig)
|
|
|
|
{
|
|
|
|
long offset;
|
|
|
|
if (orig > dest)
|
|
|
|
offset = - ((size_t)orig - (size_t)dest);
|
|
|
|
else
|
|
|
|
offset = (size_t)dest - (size_t)orig;
|
|
|
|
|
|
|
|
if (entry->title)
|
|
|
|
entry->title += offset;
|
|
|
|
if (entry->artist)
|
|
|
|
entry->artist += offset;
|
|
|
|
if (entry->album)
|
|
|
|
entry->album += offset;
|
2009-08-01 19:52:54 +00:00
|
|
|
if (entry->genre_string > (char*)orig
|
|
|
|
&& entry->genre_string < (char*)orig + sizeof(struct mp3entry))
|
2008-10-15 06:38:51 +00:00
|
|
|
/* Don't adjust that if it points to an entry of the "genres" array */
|
|
|
|
entry->genre_string += offset;
|
|
|
|
if (entry->track_string)
|
|
|
|
entry->track_string += offset;
|
|
|
|
if (entry->disc_string)
|
|
|
|
entry->disc_string += offset;
|
|
|
|
if (entry->year_string)
|
|
|
|
entry->year_string += offset;
|
|
|
|
if (entry->composer)
|
|
|
|
entry->composer += offset;
|
|
|
|
if (entry->comment)
|
|
|
|
entry->comment += offset;
|
|
|
|
if (entry->albumartist)
|
|
|
|
entry->albumartist += offset;
|
|
|
|
if (entry->grouping)
|
|
|
|
entry->grouping += offset;
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
if (entry->track_gain_string)
|
|
|
|
entry->track_gain_string += offset;
|
|
|
|
if (entry->album_gain_string)
|
|
|
|
entry->album_gain_string += offset;
|
|
|
|
#endif
|
|
|
|
if (entry->mb_track_id)
|
|
|
|
entry->mb_track_id += offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig)
|
|
|
|
{
|
|
|
|
memcpy(dest, orig, sizeof(struct mp3entry));
|
|
|
|
adjust_mp3entry(dest, dest, orig);
|
|
|
|
}
|