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 <stdlib.h>
|
|
|
|
#include <ctype.h>
|
2010-05-06 21:04:40 +00:00
|
|
|
#include "string-extra.h"
|
2011-10-30 16:05:04 +00:00
|
|
|
#include "platform.h"
|
2007-06-16 18:19:51 +00:00
|
|
|
#include "debug.h"
|
|
|
|
#include "logf.h"
|
2008-04-28 10:22:05 +00:00
|
|
|
#include "metadata.h"
|
2005-09-22 16:58:03 +00:00
|
|
|
|
2011-06-24 05:25:21 +00:00
|
|
|
#include "metadata_parsers.h"
|
2008-10-15 06:38:51 +00:00
|
|
|
|
2007-06-16 18:19:51 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-06-14 23:12:34 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* For trailing tag stripping and base audio data types */
|
2007-11-28 04:58:16 +00:00
|
|
|
#include "buffering.h"
|
|
|
|
|
2007-06-16 18:19:51 +00:00
|
|
|
#include "metadata/metadata_common.h"
|
2005-06-27 00:12:40 +00:00
|
|
|
|
2010-11-26 18:02:50 +00:00
|
|
|
static bool get_shn_metadata(int fd, struct mp3entry *id3)
|
|
|
|
{
|
|
|
|
/* TODO: read the id3v2 header if it exists */
|
|
|
|
id3->vbr = true;
|
|
|
|
id3->filesize = filesize(fd);
|
|
|
|
return skip_id3v2(fd, id3);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool get_other_asap_metadata(int fd, struct mp3entry *id3)
|
|
|
|
{
|
|
|
|
id3->bitrate = 706;
|
|
|
|
id3->frequency = 44100;
|
|
|
|
id3->vbr = false;
|
|
|
|
id3->filesize = filesize(fd);
|
|
|
|
id3->genre_string = id3_get_num_genre(36);
|
|
|
|
return true;
|
|
|
|
}
|
2006-10-25 16:57:53 +00:00
|
|
|
#endif /* CONFIG_CODEC == SWCODEC */
|
2010-12-11 04:30:54 +00:00
|
|
|
bool write_metadata_log = false;
|
2006-10-25 16:57:53 +00:00
|
|
|
|
2008-10-15 06:38:51 +00:00
|
|
|
const struct afmt_entry audio_formats[AFMT_NUM_CODECS] =
|
|
|
|
{
|
|
|
|
/* Unknown file format */
|
2011-08-14 11:18:03 +00:00
|
|
|
[0 ... AFMT_NUM_CODECS-1] =
|
2011-08-14 11:23:01 +00:00
|
|
|
AFMT_ENTRY("???", NULL, NULL, NULL, "\0" ),
|
2008-10-15 06:38:51 +00:00
|
|
|
|
|
|
|
/* MPEG Audio layer 2 */
|
|
|
|
[AFMT_MPA_L2] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("MP2", "mpa", NULL, get_mp3_metadata, "mpa\0mp2\0"),
|
2011-06-19 22:34:40 +00:00
|
|
|
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
|
|
|
/* MPEG Audio layer 3 on HWCODEC: .talk clips, no encoder */
|
|
|
|
[AFMT_MPA_L3] =
|
|
|
|
AFMT_ENTRY("MP3", "mpa", NULL, get_mp3_metadata, "mp3\0talk\0"),
|
|
|
|
|
|
|
|
#else /* CONFIG_CODEC == SWCODEC */
|
|
|
|
/* MPEG Audio layer 3 on SWCODEC */
|
2008-10-15 06:38:51 +00:00
|
|
|
[AFMT_MPA_L3] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("MP3", "mpa", "mp3_enc", get_mp3_metadata, "mp3\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
|
2011-06-19 22:34:40 +00:00
|
|
|
/* MPEG Audio layer 1 */
|
|
|
|
[AFMT_MPA_L1] =
|
|
|
|
AFMT_ENTRY("MP1", "mpa", NULL, get_mp3_metadata, "mp1\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* Audio Interchange File Format */
|
|
|
|
[AFMT_AIFF] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("AIFF", "aiff", "aiff_enc", get_aiff_metadata, "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-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("WAV", "wav", "wav_enc", get_wave_metadata, "wav\0at3\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* Ogg Vorbis */
|
|
|
|
[AFMT_OGG_VORBIS] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("Ogg", "vorbis", NULL, get_ogg_metadata, "ogg\0oga\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* FLAC */
|
|
|
|
[AFMT_FLAC] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("FLAC", "flac", NULL, get_flac_metadata, "flac\0"),
|
2011-02-03 08:28:23 +00:00
|
|
|
/* Musepack SV7 */
|
|
|
|
[AFMT_MPC_SV7] =
|
|
|
|
AFMT_ENTRY("MPCv7", "mpc", NULL, get_musepack_metadata,"mpc\0"),
|
2010-11-26 18:02:50 +00:00
|
|
|
/* A/52 (aka AC3) audio */
|
2008-10-15 06:38:51 +00:00
|
|
|
[AFMT_A52] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("AC3", "a52", NULL, get_a52_metadata, "a52\0ac3\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* WavPack */
|
|
|
|
[AFMT_WAVPACK] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("WV","wavpack","wavpack_enc",get_wavpack_metadata,"wv\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* Apple Lossless Audio Codec */
|
2009-07-27 12:13:22 +00:00
|
|
|
[AFMT_MP4_ALAC] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("ALAC", "alac", NULL, get_mp4_metadata, "m4a\0m4b\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* Advanced Audio Coding in M4A container */
|
2009-07-27 12:13:22 +00:00
|
|
|
[AFMT_MP4_AAC] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("AAC", "aac", NULL, get_mp4_metadata, "mp4\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* Shorten */
|
|
|
|
[AFMT_SHN] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("SHN","shorten", NULL, get_shn_metadata, "shn\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* SID File Format */
|
|
|
|
[AFMT_SID] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("SID", "sid", NULL, get_sid_metadata, "sid\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* ADX File Format */
|
|
|
|
[AFMT_ADX] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("ADX", "adx", NULL, get_adx_metadata, "adx\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* NESM (NES Sound Format) */
|
|
|
|
[AFMT_NSF] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("NSF", "nsf", NULL, get_nsf_metadata, "nsf\0nsfe\0"),
|
|
|
|
/* Speex File Format */
|
2008-10-15 06:38:51 +00:00
|
|
|
[AFMT_SPEEX] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("Speex", "speex",NULL, get_ogg_metadata, "spx\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* SPC700 Save State */
|
|
|
|
[AFMT_SPC] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("SPC", "spc", NULL, get_spc_metadata, "spc\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* APE (Monkey's Audio) */
|
|
|
|
[AFMT_APE] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("APE", "ape", NULL, get_monkeys_metadata,"ape\0mac\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* WMA (WMAV1/V2 in ASF) */
|
|
|
|
[AFMT_WMA] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("WMA", "wma", NULL, get_asf_metadata,"wma\0wmv\0asf\0"),
|
2010-05-09 21:42:09 +00:00
|
|
|
/* WMA Professional in ASF */
|
|
|
|
[AFMT_WMAPRO] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("WMAPro","wmapro",NULL, NULL, "wma\0wmv\0asf\0"),
|
2008-10-15 06:38:51 +00:00
|
|
|
/* Amiga MOD File */
|
|
|
|
[AFMT_MOD] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("MOD", "mod", NULL, get_mod_metadata, "mod\0"),
|
2010-02-04 17:31:10 +00:00
|
|
|
/* Atari SAP File */
|
2008-10-15 06:38:51 +00:00
|
|
|
[AFMT_SAP] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("SAP", "asap", NULL, get_asap_metadata, "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] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("Cook", "cook", NULL, get_rm_metadata,"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] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("RAAC", "raac", NULL, NULL, "rm\0ra\0rmvb\0"),
|
2009-08-04 13:54:06 +00:00
|
|
|
/* AC3 in RM/RA */
|
|
|
|
[AFMT_RM_AC3] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("AC3", "a52_rm", NULL, NULL, "rm\0ra\0rmvb\0"),
|
2009-08-14 17:36:57 +00:00
|
|
|
/* ATRAC3 in RM/RA */
|
|
|
|
[AFMT_RM_ATRAC3] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("ATRAC3","atrac3_rm",NULL, NULL, "rm\0ra\0rmvb\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari CMC File */
|
|
|
|
[AFMT_CMC] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("CMC", "asap", NULL, get_other_asap_metadata,"cmc\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari CM3 File */
|
|
|
|
[AFMT_CM3] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("CM3", "asap", NULL, get_other_asap_metadata,"cm3\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari CMR File */
|
|
|
|
[AFMT_CMR] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("CMR", "asap", NULL, get_other_asap_metadata,"cmr\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari CMS File */
|
|
|
|
[AFMT_CMS] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("CMS", "asap", NULL, get_other_asap_metadata,"cms\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari DMC File */
|
|
|
|
[AFMT_DMC] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("DMC", "asap", NULL, get_other_asap_metadata,"dmc\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari DLT File */
|
|
|
|
[AFMT_DLT] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("DLT", "asap", NULL, get_other_asap_metadata,"dlt\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari MPT File */
|
|
|
|
[AFMT_MPT] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("MPT", "asap", NULL, get_other_asap_metadata,"mpt\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari MPD File */
|
|
|
|
[AFMT_MPD] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("MPD", "asap", NULL, get_other_asap_metadata,"mpd\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari RMT File */
|
2010-11-26 18:02:50 +00:00
|
|
|
[AFMT_RMT] =
|
|
|
|
AFMT_ENTRY("RMT", "asap", NULL, get_other_asap_metadata,"rmt\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari TMC File */
|
|
|
|
[AFMT_TMC] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("TMC", "asap", NULL, get_other_asap_metadata,"tmc\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari TM8 File */
|
|
|
|
[AFMT_TM8] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("TM8", "asap", NULL, get_other_asap_metadata,"tm8\0"),
|
2010-02-06 12:49:03 +00:00
|
|
|
/* Atari TM2 File */
|
|
|
|
[AFMT_TM2] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("TM2", "asap", NULL, get_other_asap_metadata,"tm2\0"),
|
2010-02-12 03:21:37 +00:00
|
|
|
/* Atrac3 in Sony OMA Container */
|
|
|
|
[AFMT_OMA_ATRAC3] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("ATRAC3","atrac3_oma",NULL, get_oma_metadata, "oma\0aa3\0"),
|
2010-02-24 11:46:29 +00:00
|
|
|
/* SMAF (Synthetic music Mobile Application Format) */
|
|
|
|
[AFMT_SMAF] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("SMAF", "smaf", NULL, get_smaf_metadata, "mmf\0"),
|
2010-02-28 07:22:20 +00:00
|
|
|
/* Sun Audio file */
|
|
|
|
[AFMT_AU] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("AU", "au", NULL, get_au_metadata, "au\0snd\0"),
|
2010-02-28 08:13:30 +00:00
|
|
|
/* VOX (Dialogic telephony file formats) */
|
|
|
|
[AFMT_VOX] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("VOX", "vox", NULL, get_vox_metadata, "vox\0"),
|
2010-02-28 08:48:07 +00:00
|
|
|
/* Wave64 */
|
|
|
|
[AFMT_WAVE64] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("WAVE64","wav64",NULL, get_wave64_metadata,"w64\0"),
|
2010-05-13 12:40:09 +00:00
|
|
|
/* True Audio */
|
2010-11-26 18:02:50 +00:00
|
|
|
[AFMT_TTA] =
|
|
|
|
AFMT_ENTRY("TTA", "tta", NULL, get_tta_metadata, "tta\0"),
|
2010-08-07 17:55:02 +00:00
|
|
|
/* WMA Voice in ASF */
|
|
|
|
[AFMT_WMAVOICE] =
|
2010-11-26 18:02:50 +00:00
|
|
|
AFMT_ENTRY("WMAVoice","wmavoice",NULL, NULL, "wma\0wmv\0"),
|
2011-02-03 11:43:45 +00:00
|
|
|
/* Musepack SV8 */
|
|
|
|
[AFMT_MPC_SV8] =
|
|
|
|
AFMT_ENTRY("MPCv8", "mpc", NULL, get_musepack_metadata,"mpc\0"),
|
|
|
|
/* Advanced Audio Coding High Efficiency in M4A container */
|
|
|
|
[AFMT_MP4_AAC_HE] =
|
|
|
|
AFMT_ENTRY("AAC-HE","aac", NULL, get_mp4_metadata, "mp4\0"),
|
2011-08-07 20:01:04 +00:00
|
|
|
/* AY (ZX Spectrum, Amstrad CPC Sound Format) */
|
|
|
|
[AFMT_AY] =
|
|
|
|
AFMT_ENTRY("AY", "ay", NULL, get_ay_metadata, "ay\0"),
|
|
|
|
/* GBS (Game Boy Sound Format) */
|
|
|
|
[AFMT_GBS] =
|
|
|
|
AFMT_ENTRY("GBS", "gbs", NULL, get_gbs_metadata, "gbs\0"),
|
|
|
|
/* HES (Hudson Entertainment System Sound Format) */
|
|
|
|
[AFMT_HES] =
|
|
|
|
AFMT_ENTRY("HES", "hes", NULL, get_hes_metadata, "hes\0"),
|
|
|
|
/* SGC (Sega Master System, Game Gear, Coleco Vision Sound Format) */
|
|
|
|
[AFMT_SGC] =
|
|
|
|
AFMT_ENTRY("SGC", "sgc", NULL, get_sgc_metadata, "sgc\0"),
|
|
|
|
/* VGM (Video Game Music Format) */
|
|
|
|
[AFMT_VGM] =
|
|
|
|
AFMT_ENTRY("VGM", "vgm", NULL, get_vgm_metadata, "vgm\0vgz\0"),
|
|
|
|
/* KSS (MSX computer KSS Music File) */
|
|
|
|
[AFMT_KSS] =
|
|
|
|
AFMT_ENTRY("KSS", "kss", NULL, get_kss_metadata, "kss\0"),
|
2012-07-26 12:38:32 +00:00
|
|
|
/* Opus */
|
|
|
|
[AFMT_OPUS] =
|
|
|
|
AFMT_ENTRY("Opus", "opus", NULL, get_ogg_metadata, "opus\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,
|
|
|
|
};
|
|
|
|
|
2011-12-14 21:45:25 +00:00
|
|
|
#if 0 /* Currently unused, left for reference and future use */
|
2008-10-15 06:38:51 +00:00
|
|
|
/* 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,
|
|
|
|
};
|
2011-12-14 21:45:25 +00:00
|
|
|
#endif
|
2008-10-15 06:38:51 +00:00
|
|
|
#endif /* CONFIG_CODEC == SWCODEC && defined (HAVE_RECORDING) */
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
/* Get the canonical AFMT type */
|
|
|
|
int get_audio_base_codec_type(int type)
|
|
|
|
{
|
|
|
|
int base_type = type;
|
|
|
|
switch (type) {
|
|
|
|
case AFMT_MPA_L1:
|
|
|
|
case AFMT_MPA_L2:
|
|
|
|
case AFMT_MPA_L3:
|
|
|
|
base_type = AFMT_MPA_L3;
|
|
|
|
break;
|
|
|
|
case AFMT_MPC_SV7:
|
|
|
|
case AFMT_MPC_SV8:
|
|
|
|
base_type = AFMT_MPC_SV7;
|
|
|
|
break;
|
|
|
|
case AFMT_MP4_AAC:
|
|
|
|
case AFMT_MP4_AAC_HE:
|
|
|
|
base_type = AFMT_MP4_AAC;
|
|
|
|
break;
|
|
|
|
case AFMT_SAP:
|
|
|
|
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:
|
|
|
|
base_type = AFMT_SAP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the basic audio type */
|
2011-08-12 05:27:13 +00:00
|
|
|
bool rbcodec_format_is_atomic(int afmt)
|
2011-04-27 03:08:23 +00:00
|
|
|
{
|
|
|
|
if ((unsigned)afmt >= AFMT_NUM_CODECS)
|
2011-08-12 05:27:13 +00:00
|
|
|
return false;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
switch (get_audio_base_codec_type(afmt))
|
|
|
|
{
|
|
|
|
case AFMT_NSF:
|
|
|
|
case AFMT_SPC:
|
|
|
|
case AFMT_SID:
|
|
|
|
case AFMT_MOD:
|
|
|
|
case AFMT_SAP:
|
2011-08-07 20:01:04 +00:00
|
|
|
case AFMT_AY:
|
|
|
|
case AFMT_GBS:
|
|
|
|
case AFMT_HES:
|
|
|
|
case AFMT_SGC:
|
|
|
|
case AFMT_VGM:
|
|
|
|
case AFMT_KSS:
|
2011-04-27 03:08:23 +00:00
|
|
|
/* Type must be allocated and loaded in its entirety onto
|
|
|
|
the buffer */
|
2011-08-12 05:27:13 +00:00
|
|
|
return true;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* Assume type may be loaded and discarded incrementally */
|
2011-08-12 05:27:13 +00:00
|
|
|
return false;
|
2011-04-27 03:08:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the format allowed to buffer starting at some offset other than 0
|
|
|
|
or first frame only for resume purposes? */
|
|
|
|
bool format_buffers_with_offset(int afmt)
|
|
|
|
{
|
|
|
|
switch (afmt)
|
|
|
|
{
|
|
|
|
case AFMT_MPA_L1:
|
|
|
|
case AFMT_MPA_L2:
|
|
|
|
case AFMT_MPA_L3:
|
|
|
|
case AFMT_WAVPACK:
|
|
|
|
/* Format may be loaded at the first needed frame */
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
/* Format must be loaded from the beginning of the file
|
|
|
|
(does not imply 'atomic', while 'atomic' implies 'no offset') */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_CODEC == SWCODEC */
|
|
|
|
|
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;
|
|
|
|
|
2011-02-27 19:14:48 +00:00
|
|
|
result = !get_metadata(entry, fd, 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
|
|
|
{
|
2010-11-26 18:02:50 +00:00
|
|
|
const struct afmt_entry *entry;
|
2010-12-11 04:30:54 +00:00
|
|
|
int logfd = 0;
|
|
|
|
DEBUGF("Read metadata for %s\n", trackname);
|
|
|
|
if (write_metadata_log)
|
|
|
|
{
|
|
|
|
logfd = open("/metadata.log", O_WRONLY | O_APPEND | O_CREAT, 0666);
|
|
|
|
if (logfd >= 0)
|
|
|
|
{
|
|
|
|
write(logfd, trackname, strlen(trackname));
|
|
|
|
write(logfd, "\n", 1);
|
|
|
|
close(logfd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-05 16:02:35 +00:00
|
|
|
/* Clear the mp3entry to avoid having bogus pointers appear */
|
2011-04-27 03:08:23 +00:00
|
|
|
wipe_mp3entry(id3);
|
2007-10-05 16:02:35 +00:00
|
|
|
|
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
|
|
|
|
2011-12-16 10:09:41 +00:00
|
|
|
/* default values for embedded cuesheets */
|
2011-12-22 18:56:11 +00:00
|
|
|
id3->has_embedded_cuesheet = false;
|
|
|
|
id3->embedded_cuesheet.pos = 0;
|
2011-12-16 10:09:41 +00:00
|
|
|
|
2010-11-26 18:02:50 +00:00
|
|
|
entry = &audio_formats[id3->codectype];
|
|
|
|
|
2005-12-01 20:39:19 +00:00
|
|
|
/* Load codec specific track tag information and confirm the codec type. */
|
2010-11-26 18:02:50 +00:00
|
|
|
if (!entry->parse_func)
|
2005-09-22 16:58:03 +00:00
|
|
|
{
|
2010-11-26 18:02:50 +00:00
|
|
|
DEBUGF("nothing to parse for %s (format %s)", trackname, entry->label);
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-28 07:22:20 +00:00
|
|
|
|
2010-11-26 18:02:50 +00:00
|
|
|
if (!entry->parse_func(fd, id3))
|
|
|
|
{
|
|
|
|
DEBUGF("parsing %s failed (format: %s)", trackname, entry->label);
|
2005-12-01 20:39:19 +00:00
|
|
|
return false;
|
2005-07-28 20:21:54 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 18:15:59 +00:00
|
|
|
lseek(fd, 0, SEEK_SET);
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(id3->path, trackname, sizeof(id3->path));
|
2010-11-26 18:02:50 +00:00
|
|
|
/* We have successfully read the metadata from the file */
|
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
|
|
|
|
2011-02-24 20:03:14 +00:00
|
|
|
#define MOVE_ENTRY(x) if (x) x += offset;
|
|
|
|
|
2008-10-15 06:38:51 +00:00
|
|
|
void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig)
|
|
|
|
{
|
|
|
|
long offset;
|
|
|
|
if (orig > dest)
|
2011-02-24 20:03:14 +00:00
|
|
|
offset = -((size_t)orig - (size_t)dest);
|
2008-10-15 06:38:51 +00:00
|
|
|
else
|
2011-02-24 20:03:14 +00:00
|
|
|
offset = ((size_t)dest - (size_t)orig);
|
|
|
|
|
|
|
|
MOVE_ENTRY(entry->title)
|
|
|
|
MOVE_ENTRY(entry->artist)
|
|
|
|
MOVE_ENTRY(entry->album)
|
|
|
|
|
|
|
|
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;
|
2011-02-24 20:03:14 +00:00
|
|
|
|
|
|
|
MOVE_ENTRY(entry->track_string)
|
|
|
|
MOVE_ENTRY(entry->disc_string)
|
|
|
|
MOVE_ENTRY(entry->year_string)
|
|
|
|
MOVE_ENTRY(entry->composer)
|
|
|
|
MOVE_ENTRY(entry->comment)
|
|
|
|
MOVE_ENTRY(entry->albumartist)
|
|
|
|
MOVE_ENTRY(entry->grouping)
|
|
|
|
MOVE_ENTRY(entry->mb_track_id)
|
2008-10-15 06:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig)
|
|
|
|
{
|
|
|
|
memcpy(dest, orig, sizeof(struct mp3entry));
|
|
|
|
adjust_mp3entry(dest, dest, orig);
|
|
|
|
}
|
2011-02-08 20:31:35 +00:00
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
/* A shortcut to simplify the common task of clearing the struct */
|
|
|
|
void wipe_mp3entry(struct mp3entry *id3)
|
|
|
|
{
|
|
|
|
memset(id3, 0, sizeof (struct mp3entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
/* Glean what is possible from the filename alone - does not parse metadata */
|
|
|
|
void fill_metadata_from_path(struct mp3entry *id3, const char *trackname)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
/* Clear the mp3entry to avoid having bogus pointers appear */
|
|
|
|
wipe_mp3entry(id3);
|
|
|
|
|
|
|
|
/* Find the filename portion of the path */
|
|
|
|
p = strrchr(trackname, '/');
|
|
|
|
strlcpy(id3->id3v2buf, p ? ++p : id3->path, ID3V2_BUF_SIZE);
|
|
|
|
|
|
|
|
/* Get the format from the extension and trim it off */
|
|
|
|
p = strrchr(id3->id3v2buf, '.');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
/* Might be wrong for container formats - should we bother? */
|
|
|
|
id3->codectype = probe_file_format(p);
|
|
|
|
|
|
|
|
if (id3->codectype != AFMT_UNKNOWN)
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the filename as the title */
|
|
|
|
id3->title = id3->id3v2buf;
|
|
|
|
|
|
|
|
/* Copy the path info */
|
|
|
|
strlcpy(id3->path, trackname, sizeof (id3->path));
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_CODEC == SWCODEC */
|