Dave Chapman | 3ad485b | 2005-06-14 22:27:57 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 Dave Chapman |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Dave Chapman | 3ad485b | 2005-06-14 22:27:57 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | #include <stdio.h> |
Dave Chapman | 3ad485b | 2005-06-14 22:27:57 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
| 23 | #include <ctype.h> |
Thomas Martitz | 50a6ca3 | 2010-05-06 21:04:40 +0000 | [diff] [blame] | 24 | #include "string-extra.h" |
Dave Chapman | 3ad485b | 2005-06-14 22:27:57 +0000 | [diff] [blame] | 25 | |
Marcoen Hirschberg | 2175d1e | 2007-06-16 18:19:51 +0000 | [diff] [blame] | 26 | #include "debug.h" |
| 27 | #include "logf.h" |
Michael Hohmuth | 7141ff4 | 2011-02-08 20:31:35 +0000 | [diff] [blame] | 28 | #include "settings.h" |
Nicolas Pennequin | 9f4bd87 | 2007-02-14 14:40:24 +0000 | [diff] [blame] | 29 | #include "cuesheet.h" |
Bertrik Sikken | a5d3029 | 2008-04-28 10:22:05 +0000 | [diff] [blame] | 30 | #include "metadata.h" |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 31 | |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 32 | #include "metadata/metadata_parsers.h" |
| 33 | |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 34 | #if CONFIG_CODEC == SWCODEC |
Marcoen Hirschberg | 2175d1e | 2007-06-16 18:19:51 +0000 | [diff] [blame] | 35 | |
Michael Sevakis | c537d59 | 2011-04-27 03:08:23 +0000 | [diff] [blame] | 36 | /* For trailing tag stripping and base audio data types */ |
Brandon Low | 3386dd7 | 2007-11-28 04:58:16 +0000 | [diff] [blame] | 37 | #include "buffering.h" |
| 38 | |
Marcoen Hirschberg | 2175d1e | 2007-06-16 18:19:51 +0000 | [diff] [blame] | 39 | #include "metadata/metadata_common.h" |
Marcoen Hirschberg | 2175d1e | 2007-06-16 18:19:51 +0000 | [diff] [blame] | 40 | |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 41 | static bool get_shn_metadata(int fd, struct mp3entry *id3) |
| 42 | { |
| 43 | /* TODO: read the id3v2 header if it exists */ |
| 44 | id3->vbr = true; |
| 45 | id3->filesize = filesize(fd); |
| 46 | return skip_id3v2(fd, id3); |
| 47 | } |
| 48 | |
| 49 | static bool get_other_asap_metadata(int fd, struct mp3entry *id3) |
| 50 | { |
| 51 | id3->bitrate = 706; |
| 52 | id3->frequency = 44100; |
| 53 | id3->vbr = false; |
| 54 | id3->filesize = filesize(fd); |
| 55 | id3->genre_string = id3_get_num_genre(36); |
| 56 | return true; |
| 57 | } |
Miika Pekkarinen | 58ebf47 | 2006-10-25 16:57:53 +0000 | [diff] [blame] | 58 | #endif /* CONFIG_CODEC == SWCODEC */ |
Michael Giacomelli | 9788043 | 2010-12-11 04:30:54 +0000 | [diff] [blame] | 59 | bool write_metadata_log = false; |
Miika Pekkarinen | 58ebf47 | 2006-10-25 16:57:53 +0000 | [diff] [blame] | 60 | |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 61 | const struct afmt_entry audio_formats[AFMT_NUM_CODECS] = |
| 62 | { |
| 63 | /* Unknown file format */ |
| 64 | [AFMT_UNKNOWN] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 65 | AFMT_ENTRY("???", NULL, NULL, NULL, NULL ), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 66 | |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 67 | /* MPEG Audio layer 2 */ |
| 68 | [AFMT_MPA_L2] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 69 | AFMT_ENTRY("MP2", "mpa", NULL, get_mp3_metadata, "mpa\0mp2\0"), |
Jens Arnold | c56cca2 | 2011-06-19 22:34:40 +0000 | [diff] [blame^] | 70 | |
| 71 | #if CONFIG_CODEC != SWCODEC |
| 72 | /* MPEG Audio layer 3 on HWCODEC: .talk clips, no encoder */ |
| 73 | [AFMT_MPA_L3] = |
| 74 | AFMT_ENTRY("MP3", "mpa", NULL, get_mp3_metadata, "mp3\0talk\0"), |
| 75 | |
| 76 | #else /* CONFIG_CODEC == SWCODEC */ |
| 77 | /* MPEG Audio layer 3 on SWCODEC */ |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 78 | [AFMT_MPA_L3] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 79 | AFMT_ENTRY("MP3", "mpa", "mp3_enc", get_mp3_metadata, "mp3\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 80 | |
Jens Arnold | c56cca2 | 2011-06-19 22:34:40 +0000 | [diff] [blame^] | 81 | /* MPEG Audio layer 1 */ |
| 82 | [AFMT_MPA_L1] = |
| 83 | AFMT_ENTRY("MP1", "mpa", NULL, get_mp3_metadata, "mp1\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 84 | /* Audio Interchange File Format */ |
| 85 | [AFMT_AIFF] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 86 | AFMT_ENTRY("AIFF", "aiff", "aiff_enc", get_aiff_metadata, "aiff\0aif\0"), |
Mohamed Tarek | 82f0589 | 2010-02-16 03:34:39 +0000 | [diff] [blame] | 87 | /* Uncompressed PCM in a WAV file OR ATRAC3 stream in WAV file (.at3) */ |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 88 | [AFMT_PCM_WAV] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 89 | AFMT_ENTRY("WAV", "wav", "wav_enc", get_wave_metadata, "wav\0at3\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 90 | /* Ogg Vorbis */ |
| 91 | [AFMT_OGG_VORBIS] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 92 | AFMT_ENTRY("Ogg", "vorbis", NULL, get_ogg_metadata, "ogg\0oga\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 93 | /* FLAC */ |
| 94 | [AFMT_FLAC] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 95 | AFMT_ENTRY("FLAC", "flac", NULL, get_flac_metadata, "flac\0"), |
Andree Buschmann | 7345ac1 | 2011-02-03 08:28:23 +0000 | [diff] [blame] | 96 | /* Musepack SV7 */ |
| 97 | [AFMT_MPC_SV7] = |
| 98 | AFMT_ENTRY("MPCv7", "mpc", NULL, get_musepack_metadata,"mpc\0"), |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 99 | /* A/52 (aka AC3) audio */ |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 100 | [AFMT_A52] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 101 | AFMT_ENTRY("AC3", "a52", NULL, get_a52_metadata, "a52\0ac3\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 102 | /* WavPack */ |
| 103 | [AFMT_WAVPACK] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 104 | AFMT_ENTRY("WV","wavpack","wavpack_enc",get_wavpack_metadata,"wv\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 105 | /* Apple Lossless Audio Codec */ |
Mohamed Tarek | 5f5d105 | 2009-07-27 12:13:22 +0000 | [diff] [blame] | 106 | [AFMT_MP4_ALAC] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 107 | AFMT_ENTRY("ALAC", "alac", NULL, get_mp4_metadata, "m4a\0m4b\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 108 | /* Advanced Audio Coding in M4A container */ |
Mohamed Tarek | 5f5d105 | 2009-07-27 12:13:22 +0000 | [diff] [blame] | 109 | [AFMT_MP4_AAC] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 110 | AFMT_ENTRY("AAC", "aac", NULL, get_mp4_metadata, "mp4\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 111 | /* Shorten */ |
| 112 | [AFMT_SHN] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 113 | AFMT_ENTRY("SHN","shorten", NULL, get_shn_metadata, "shn\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 114 | /* SID File Format */ |
| 115 | [AFMT_SID] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 116 | AFMT_ENTRY("SID", "sid", NULL, get_sid_metadata, "sid\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 117 | /* ADX File Format */ |
| 118 | [AFMT_ADX] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 119 | AFMT_ENTRY("ADX", "adx", NULL, get_adx_metadata, "adx\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 120 | /* NESM (NES Sound Format) */ |
| 121 | [AFMT_NSF] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 122 | AFMT_ENTRY("NSF", "nsf", NULL, get_nsf_metadata, "nsf\0nsfe\0"), |
| 123 | /* Speex File Format */ |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 124 | [AFMT_SPEEX] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 125 | AFMT_ENTRY("Speex", "speex",NULL, get_ogg_metadata, "spx\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 126 | /* SPC700 Save State */ |
| 127 | [AFMT_SPC] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 128 | AFMT_ENTRY("SPC", "spc", NULL, get_spc_metadata, "spc\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 129 | /* APE (Monkey's Audio) */ |
| 130 | [AFMT_APE] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 131 | AFMT_ENTRY("APE", "ape", NULL, get_monkeys_metadata,"ape\0mac\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 132 | /* WMA (WMAV1/V2 in ASF) */ |
| 133 | [AFMT_WMA] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 134 | AFMT_ENTRY("WMA", "wma", NULL, get_asf_metadata,"wma\0wmv\0asf\0"), |
Mohamed Tarek | cd4d80a | 2010-05-09 21:42:09 +0000 | [diff] [blame] | 135 | /* WMA Professional in ASF */ |
| 136 | [AFMT_WMAPRO] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 137 | AFMT_ENTRY("WMAPro","wmapro",NULL, NULL, "wma\0wmv\0asf\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 138 | /* Amiga MOD File */ |
| 139 | [AFMT_MOD] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 140 | AFMT_ENTRY("MOD", "mod", NULL, get_mod_metadata, "mod\0"), |
Dominik Wenger | 35472fe | 2010-02-04 17:31:10 +0000 | [diff] [blame] | 141 | /* Atari SAP File */ |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 142 | [AFMT_SAP] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 143 | AFMT_ENTRY("SAP", "asap", NULL, get_asap_metadata, "sap\0"), |
Mohamed Tarek | e184ef1 | 2009-07-06 22:40:45 +0000 | [diff] [blame] | 144 | /* Cook in RM/RA */ |
Mohamed Tarek | 5f5d105 | 2009-07-27 12:13:22 +0000 | [diff] [blame] | 145 | [AFMT_RM_COOK] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 146 | AFMT_ENTRY("Cook", "cook", NULL, get_rm_metadata,"rm\0ra\0rmvb\0"), |
Mohamed Tarek | b8cccb5 | 2009-07-25 15:47:13 +0000 | [diff] [blame] | 147 | /* AAC in RM/RA */ |
Mohamed Tarek | 5f5d105 | 2009-07-27 12:13:22 +0000 | [diff] [blame] | 148 | [AFMT_RM_AAC] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 149 | AFMT_ENTRY("RAAC", "raac", NULL, NULL, "rm\0ra\0rmvb\0"), |
Mohamed Tarek | 26cee86 | 2009-08-04 13:54:06 +0000 | [diff] [blame] | 150 | /* AC3 in RM/RA */ |
| 151 | [AFMT_RM_AC3] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 152 | AFMT_ENTRY("AC3", "a52_rm", NULL, NULL, "rm\0ra\0rmvb\0"), |
Mohamed Tarek | 685628c | 2009-08-14 17:36:57 +0000 | [diff] [blame] | 153 | /* ATRAC3 in RM/RA */ |
| 154 | [AFMT_RM_ATRAC3] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 155 | AFMT_ENTRY("ATRAC3","atrac3_rm",NULL, NULL, "rm\0ra\0rmvb\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 156 | /* Atari CMC File */ |
| 157 | [AFMT_CMC] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 158 | AFMT_ENTRY("CMC", "asap", NULL, get_other_asap_metadata,"cmc\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 159 | /* Atari CM3 File */ |
| 160 | [AFMT_CM3] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 161 | AFMT_ENTRY("CM3", "asap", NULL, get_other_asap_metadata,"cm3\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 162 | /* Atari CMR File */ |
| 163 | [AFMT_CMR] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 164 | AFMT_ENTRY("CMR", "asap", NULL, get_other_asap_metadata,"cmr\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 165 | /* Atari CMS File */ |
| 166 | [AFMT_CMS] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 167 | AFMT_ENTRY("CMS", "asap", NULL, get_other_asap_metadata,"cms\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 168 | /* Atari DMC File */ |
| 169 | [AFMT_DMC] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 170 | AFMT_ENTRY("DMC", "asap", NULL, get_other_asap_metadata,"dmc\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 171 | /* Atari DLT File */ |
| 172 | [AFMT_DLT] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 173 | AFMT_ENTRY("DLT", "asap", NULL, get_other_asap_metadata,"dlt\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 174 | /* Atari MPT File */ |
| 175 | [AFMT_MPT] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 176 | AFMT_ENTRY("MPT", "asap", NULL, get_other_asap_metadata,"mpt\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 177 | /* Atari MPD File */ |
| 178 | [AFMT_MPD] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 179 | AFMT_ENTRY("MPD", "asap", NULL, get_other_asap_metadata,"mpd\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 180 | /* Atari RMT File */ |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 181 | [AFMT_RMT] = |
| 182 | AFMT_ENTRY("RMT", "asap", NULL, get_other_asap_metadata,"rmt\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 183 | /* Atari TMC File */ |
| 184 | [AFMT_TMC] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 185 | AFMT_ENTRY("TMC", "asap", NULL, get_other_asap_metadata,"tmc\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 186 | /* Atari TM8 File */ |
| 187 | [AFMT_TM8] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 188 | AFMT_ENTRY("TM8", "asap", NULL, get_other_asap_metadata,"tm8\0"), |
Dominik Wenger | e96d139 | 2010-02-06 12:49:03 +0000 | [diff] [blame] | 189 | /* Atari TM2 File */ |
| 190 | [AFMT_TM2] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 191 | AFMT_ENTRY("TM2", "asap", NULL, get_other_asap_metadata,"tm2\0"), |
Mohamed Tarek | 23ac6ff | 2010-02-12 03:21:37 +0000 | [diff] [blame] | 192 | /* Atrac3 in Sony OMA Container */ |
| 193 | [AFMT_OMA_ATRAC3] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 194 | AFMT_ENTRY("ATRAC3","atrac3_oma",NULL, get_oma_metadata, "oma\0aa3\0"), |
Yoshihisa Uchida | 45e009a | 2010-02-24 11:46:29 +0000 | [diff] [blame] | 195 | /* SMAF (Synthetic music Mobile Application Format) */ |
| 196 | [AFMT_SMAF] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 197 | AFMT_ENTRY("SMAF", "smaf", NULL, get_smaf_metadata, "mmf\0"), |
Yoshihisa Uchida | 4e3c807 | 2010-02-28 07:22:20 +0000 | [diff] [blame] | 198 | /* Sun Audio file */ |
| 199 | [AFMT_AU] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 200 | AFMT_ENTRY("AU", "au", NULL, get_au_metadata, "au\0snd\0"), |
Yoshihisa Uchida | 8c5eaa3 | 2010-02-28 08:13:30 +0000 | [diff] [blame] | 201 | /* VOX (Dialogic telephony file formats) */ |
| 202 | [AFMT_VOX] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 203 | AFMT_ENTRY("VOX", "vox", NULL, get_vox_metadata, "vox\0"), |
Yoshihisa Uchida | 561cb2c | 2010-02-28 08:48:07 +0000 | [diff] [blame] | 204 | /* Wave64 */ |
| 205 | [AFMT_WAVE64] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 206 | AFMT_ENTRY("WAVE64","wav64",NULL, get_wave64_metadata,"w64\0"), |
Yoshihisa Uchida | 0f5c6d4 | 2010-05-13 12:40:09 +0000 | [diff] [blame] | 207 | /* True Audio */ |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 208 | [AFMT_TTA] = |
| 209 | AFMT_ENTRY("TTA", "tta", NULL, get_tta_metadata, "tta\0"), |
Mohamed Tarek | 4ff2cf4 | 2010-08-07 17:55:02 +0000 | [diff] [blame] | 210 | /* WMA Voice in ASF */ |
| 211 | [AFMT_WMAVOICE] = |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 212 | AFMT_ENTRY("WMAVoice","wmavoice",NULL, NULL, "wma\0wmv\0"), |
Andree Buschmann | 5a2421a | 2011-02-03 11:43:45 +0000 | [diff] [blame] | 213 | /* Musepack SV8 */ |
| 214 | [AFMT_MPC_SV8] = |
| 215 | AFMT_ENTRY("MPCv8", "mpc", NULL, get_musepack_metadata,"mpc\0"), |
| 216 | /* Advanced Audio Coding High Efficiency in M4A container */ |
| 217 | [AFMT_MP4_AAC_HE] = |
| 218 | AFMT_ENTRY("AAC-HE","aac", NULL, get_mp4_metadata, "mp4\0"), |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 219 | #endif |
| 220 | }; |
| 221 | |
| 222 | #if CONFIG_CODEC == SWCODEC && defined (HAVE_RECORDING) |
| 223 | /* get REC_FORMAT_* corresponding AFMT_* */ |
| 224 | const int rec_format_afmt[REC_NUM_FORMATS] = |
| 225 | { |
| 226 | /* give AFMT_UNKNOWN by default */ |
| 227 | [0 ... REC_NUM_FORMATS-1] = AFMT_UNKNOWN, |
| 228 | /* add new entries below this line */ |
| 229 | [REC_FORMAT_AIFF] = AFMT_AIFF, |
| 230 | [REC_FORMAT_MPA_L3] = AFMT_MPA_L3, |
| 231 | [REC_FORMAT_WAVPACK] = AFMT_WAVPACK, |
| 232 | [REC_FORMAT_PCM_WAV] = AFMT_PCM_WAV, |
| 233 | }; |
| 234 | |
| 235 | /* get AFMT_* corresponding REC_FORMAT_* */ |
| 236 | const int afmt_rec_format[AFMT_NUM_CODECS] = |
| 237 | { |
| 238 | /* give -1 by default */ |
| 239 | [0 ... AFMT_NUM_CODECS-1] = -1, |
| 240 | /* add new entries below this line */ |
| 241 | [AFMT_AIFF] = REC_FORMAT_AIFF, |
| 242 | [AFMT_MPA_L3] = REC_FORMAT_MPA_L3, |
| 243 | [AFMT_WAVPACK] = REC_FORMAT_WAVPACK, |
| 244 | [AFMT_PCM_WAV] = REC_FORMAT_PCM_WAV, |
| 245 | }; |
| 246 | #endif /* CONFIG_CODEC == SWCODEC && defined (HAVE_RECORDING) */ |
| 247 | |
Michael Sevakis | c537d59 | 2011-04-27 03:08:23 +0000 | [diff] [blame] | 248 | #if CONFIG_CODEC == SWCODEC |
| 249 | /* Get the canonical AFMT type */ |
| 250 | int get_audio_base_codec_type(int type) |
| 251 | { |
| 252 | int base_type = type; |
| 253 | switch (type) { |
| 254 | case AFMT_MPA_L1: |
| 255 | case AFMT_MPA_L2: |
| 256 | case AFMT_MPA_L3: |
| 257 | base_type = AFMT_MPA_L3; |
| 258 | break; |
| 259 | case AFMT_MPC_SV7: |
| 260 | case AFMT_MPC_SV8: |
| 261 | base_type = AFMT_MPC_SV7; |
| 262 | break; |
| 263 | case AFMT_MP4_AAC: |
| 264 | case AFMT_MP4_AAC_HE: |
| 265 | base_type = AFMT_MP4_AAC; |
| 266 | break; |
| 267 | case AFMT_SAP: |
| 268 | case AFMT_CMC: |
| 269 | case AFMT_CM3: |
| 270 | case AFMT_CMR: |
| 271 | case AFMT_CMS: |
| 272 | case AFMT_DMC: |
| 273 | case AFMT_DLT: |
| 274 | case AFMT_MPT: |
| 275 | case AFMT_MPD: |
| 276 | case AFMT_RMT: |
| 277 | case AFMT_TMC: |
| 278 | case AFMT_TM8: |
| 279 | case AFMT_TM2: |
| 280 | base_type = AFMT_SAP; |
| 281 | break; |
| 282 | default: |
| 283 | break; |
| 284 | } |
| 285 | |
| 286 | return base_type; |
| 287 | } |
| 288 | |
| 289 | /* Get the basic audio type */ |
| 290 | enum data_type get_audio_base_data_type(int afmt) |
| 291 | { |
| 292 | if ((unsigned)afmt >= AFMT_NUM_CODECS) |
| 293 | return TYPE_UNKNOWN; |
| 294 | |
| 295 | switch (get_audio_base_codec_type(afmt)) |
| 296 | { |
| 297 | case AFMT_NSF: |
| 298 | case AFMT_SPC: |
| 299 | case AFMT_SID: |
| 300 | case AFMT_MOD: |
| 301 | case AFMT_SAP: |
| 302 | /* Type must be allocated and loaded in its entirety onto |
| 303 | the buffer */ |
| 304 | return TYPE_ATOMIC_AUDIO; |
| 305 | |
| 306 | default: |
| 307 | /* Assume type may be loaded and discarded incrementally */ |
| 308 | return TYPE_PACKET_AUDIO; |
| 309 | |
| 310 | case AFMT_UNKNOWN: |
| 311 | /* Have no idea at all */ |
| 312 | return TYPE_UNKNOWN; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /* Is the format allowed to buffer starting at some offset other than 0 |
| 317 | or first frame only for resume purposes? */ |
| 318 | bool format_buffers_with_offset(int afmt) |
| 319 | { |
| 320 | switch (afmt) |
| 321 | { |
| 322 | case AFMT_MPA_L1: |
| 323 | case AFMT_MPA_L2: |
| 324 | case AFMT_MPA_L3: |
| 325 | case AFMT_WAVPACK: |
| 326 | /* Format may be loaded at the first needed frame */ |
| 327 | return true; |
| 328 | default: |
| 329 | /* Format must be loaded from the beginning of the file |
| 330 | (does not imply 'atomic', while 'atomic' implies 'no offset') */ |
| 331 | return false; |
| 332 | } |
| 333 | } |
| 334 | #endif /* CONFIG_CODEC == SWCODEC */ |
| 335 | |
Dave Chapman | fbd8e5d | 2006-02-01 16:42:02 +0000 | [diff] [blame] | 336 | |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 337 | /* Simple file type probing by looking at the filename extension. */ |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 338 | unsigned int probe_file_format(const char *filename) |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 339 | { |
| 340 | char *suffix; |
| 341 | unsigned int i; |
| 342 | |
| 343 | suffix = strrchr(filename, '.'); |
| 344 | |
| 345 | if (suffix == NULL) |
| 346 | { |
| 347 | return AFMT_UNKNOWN; |
| 348 | } |
| 349 | |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 350 | /* skip '.' */ |
| 351 | suffix++; |
| 352 | |
| 353 | for (i = 1; i < AFMT_NUM_CODECS; i++) |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 354 | { |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 355 | /* search extension list for type */ |
| 356 | const char *ext = audio_formats[i].ext_list; |
| 357 | |
| 358 | do |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 359 | { |
Magnus Holmgren | 1e7b7bc | 2006-12-29 14:59:10 +0000 | [diff] [blame] | 360 | if (strcasecmp(suffix, ext) == 0) |
| 361 | { |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 362 | return i; |
| 363 | } |
| 364 | |
| 365 | ext += strlen(ext) + 1; |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 366 | } |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 367 | while (*ext != '\0'); |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | return AFMT_UNKNOWN; |
| 371 | } |
| 372 | |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 373 | /* Note, that this returns false for successful, true for error! */ |
| 374 | bool mp3info(struct mp3entry *entry, const char *filename) |
| 375 | { |
| 376 | int fd; |
| 377 | bool result; |
| 378 | |
| 379 | fd = open(filename, O_RDONLY); |
| 380 | if (fd < 0) |
| 381 | return true; |
| 382 | |
Thomas Martitz | ade4c16 | 2011-02-27 19:14:48 +0000 | [diff] [blame] | 383 | result = !get_metadata(entry, fd, filename); |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 384 | |
| 385 | close(fd); |
| 386 | |
| 387 | return result; |
| 388 | } |
| 389 | |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 390 | /* Get metadata for track - return false if parsing showed problems with the |
| 391 | * file that would prevent playback. |
| 392 | */ |
Thom Johansen | 294ec1d | 2007-09-19 10:40:55 +0000 | [diff] [blame] | 393 | bool get_metadata(struct mp3entry* id3, int fd, const char* trackname) |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 394 | { |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 395 | const struct afmt_entry *entry; |
Michael Giacomelli | 9788043 | 2010-12-11 04:30:54 +0000 | [diff] [blame] | 396 | int logfd = 0; |
| 397 | DEBUGF("Read metadata for %s\n", trackname); |
| 398 | if (write_metadata_log) |
| 399 | { |
| 400 | logfd = open("/metadata.log", O_WRONLY | O_APPEND | O_CREAT, 0666); |
| 401 | if (logfd >= 0) |
| 402 | { |
| 403 | write(logfd, trackname, strlen(trackname)); |
| 404 | write(logfd, "\n", 1); |
| 405 | close(logfd); |
| 406 | } |
| 407 | } |
| 408 | |
Nicolas Pennequin | e49247e | 2007-10-05 16:02:35 +0000 | [diff] [blame] | 409 | /* Clear the mp3entry to avoid having bogus pointers appear */ |
Michael Sevakis | c537d59 | 2011-04-27 03:08:23 +0000 | [diff] [blame] | 410 | wipe_mp3entry(id3); |
Nicolas Pennequin | e49247e | 2007-10-05 16:02:35 +0000 | [diff] [blame] | 411 | |
Dave Chapman | 15ca091 | 2005-12-01 20:39:19 +0000 | [diff] [blame] | 412 | /* Take our best guess at the codec type based on file extension */ |
Nicolas Pennequin | 6a92e47 | 2007-08-14 11:56:13 +0000 | [diff] [blame] | 413 | id3->codectype = probe_file_format(trackname); |
Dave Chapman | 15ca091 | 2005-12-01 20:39:19 +0000 | [diff] [blame] | 414 | |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 415 | entry = &audio_formats[id3->codectype]; |
| 416 | |
Dave Chapman | 15ca091 | 2005-12-01 20:39:19 +0000 | [diff] [blame] | 417 | /* Load codec specific track tag information and confirm the codec type. */ |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 418 | if (!entry->parse_func) |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 419 | { |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 420 | DEBUGF("nothing to parse for %s (format %s)", trackname, entry->label); |
Dave Chapman | 15ca091 | 2005-12-01 20:39:19 +0000 | [diff] [blame] | 421 | return false; |
Magnus Holmgren | ccdae5d | 2005-09-22 16:58:03 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 424 | if (!entry->parse_func(fd, id3)) |
| 425 | { |
| 426 | DEBUGF("parsing %s failed (format: %s)", trackname, entry->label); |
| 427 | return false; |
| 428 | } |
Ryan Jackson | 9e35640 | 2005-07-28 20:21:54 +0000 | [diff] [blame] | 429 | |
Thomas Martitz | ec9bb4c | 2010-11-26 18:15:59 +0000 | [diff] [blame] | 430 | lseek(fd, 0, SEEK_SET); |
Thomas Martitz | 9393e4c | 2010-11-26 18:02:50 +0000 | [diff] [blame] | 431 | strlcpy(id3->path, trackname, sizeof(id3->path)); |
| 432 | /* We have successfully read the metadata from the file */ |
Linus Nielsen Feltzing | eaf8b2d | 2005-07-05 08:43:36 +0000 | [diff] [blame] | 433 | return true; |
| 434 | } |
Miika Pekkarinen | 7c4e0c8 | 2006-03-26 11:33:42 +0000 | [diff] [blame] | 435 | |
Björn Stenberg | ee46a3d | 2008-12-15 23:42:19 +0000 | [diff] [blame] | 436 | #ifndef __PCTOOL__ |
Brandon Low | c1b7184 | 2007-11-28 05:13:05 +0000 | [diff] [blame] | 437 | #if CONFIG_CODEC == SWCODEC |
Brandon Low | 3386dd7 | 2007-11-28 04:58:16 +0000 | [diff] [blame] | 438 | void strip_tags(int handle_id) |
| 439 | { |
Brandon Low | 3386dd7 | 2007-11-28 04:58:16 +0000 | [diff] [blame] | 440 | static const unsigned char tag[] = "TAG"; |
| 441 | static const unsigned char apetag[] = "APETAGEX"; |
| 442 | size_t len, version; |
Brandon Low | df40425 | 2007-11-30 18:48:07 +0000 | [diff] [blame] | 443 | void *tail; |
Brandon Low | 3386dd7 | 2007-11-28 04:58:16 +0000 | [diff] [blame] | 444 | |
Brandon Low | df40425 | 2007-11-30 18:48:07 +0000 | [diff] [blame] | 445 | if (bufgettail(handle_id, 128, &tail) != 128) |
Brandon Low | 3386dd7 | 2007-11-28 04:58:16 +0000 | [diff] [blame] | 446 | return; |
| 447 | |
Brandon Low | 3e7f02e | 2007-11-28 16:39:55 +0000 | [diff] [blame] | 448 | if (memcmp(tail, tag, 3) == 0) |
| 449 | { |
| 450 | /* Skip id3v1 tag */ |
| 451 | logf("Cutting off ID3v1 tag"); |
| 452 | bufcuttail(handle_id, 128); |
| 453 | } |
Brandon Low | 3386dd7 | 2007-11-28 04:58:16 +0000 | [diff] [blame] | 454 | |
Brandon Low | 3e7f02e | 2007-11-28 16:39:55 +0000 | [diff] [blame] | 455 | /* Get a new tail, as the old one may have been cut */ |
Brandon Low | df40425 | 2007-11-30 18:48:07 +0000 | [diff] [blame] | 456 | if (bufgettail(handle_id, 32, &tail) != 32) |
Brandon Low | 3386dd7 | 2007-11-28 04:58:16 +0000 | [diff] [blame] | 457 | return; |
| 458 | |
Brandon Low | 3e7f02e | 2007-11-28 16:39:55 +0000 | [diff] [blame] | 459 | /* Check for APE tag (look for the APE tag footer) */ |
| 460 | if (memcmp(tail, apetag, 8) != 0) |
| 461 | return; |
Brandon Low | 3386dd7 | 2007-11-28 04:58:16 +0000 | [diff] [blame] | 462 | |
| 463 | /* Read the version and length from the footer */ |
Brandon Low | df40425 | 2007-11-30 18:48:07 +0000 | [diff] [blame] | 464 | version = get_long_le(&((unsigned char *)tail)[8]); |
| 465 | len = get_long_le(&((unsigned char *)tail)[12]); |
Brandon Low | 3386dd7 | 2007-11-28 04:58:16 +0000 | [diff] [blame] | 466 | if (version == 2000) |
| 467 | len += 32; /* APEv2 has a 32 byte header */ |
| 468 | |
| 469 | /* Skip APE tag */ |
| 470 | logf("Cutting off APE tag (%ldB)", len); |
| 471 | bufcuttail(handle_id, len); |
| 472 | } |
Brandon Low | c1b7184 | 2007-11-28 05:13:05 +0000 | [diff] [blame] | 473 | #endif /* CONFIG_CODEC == SWCODEC */ |
Björn Stenberg | ee46a3d | 2008-12-15 23:42:19 +0000 | [diff] [blame] | 474 | #endif /* ! __PCTOOL__ */ |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 475 | |
Andree Buschmann | 9c2e7fd | 2011-02-24 20:03:14 +0000 | [diff] [blame] | 476 | #define MOVE_ENTRY(x) if (x) x += offset; |
| 477 | |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 478 | void adjust_mp3entry(struct mp3entry *entry, void *dest, const void *orig) |
| 479 | { |
| 480 | long offset; |
| 481 | if (orig > dest) |
Andree Buschmann | 9c2e7fd | 2011-02-24 20:03:14 +0000 | [diff] [blame] | 482 | offset = -((size_t)orig - (size_t)dest); |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 483 | else |
Andree Buschmann | 9c2e7fd | 2011-02-24 20:03:14 +0000 | [diff] [blame] | 484 | offset = ((size_t)dest - (size_t)orig); |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 485 | |
Andree Buschmann | 9c2e7fd | 2011-02-24 20:03:14 +0000 | [diff] [blame] | 486 | MOVE_ENTRY(entry->title) |
| 487 | MOVE_ENTRY(entry->artist) |
| 488 | MOVE_ENTRY(entry->album) |
| 489 | |
| 490 | if (entry->genre_string > (char*)orig && |
| 491 | entry->genre_string < (char*)orig + sizeof(struct mp3entry)) |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 492 | /* Don't adjust that if it points to an entry of the "genres" array */ |
| 493 | entry->genre_string += offset; |
Andree Buschmann | 9c2e7fd | 2011-02-24 20:03:14 +0000 | [diff] [blame] | 494 | |
| 495 | MOVE_ENTRY(entry->track_string) |
| 496 | MOVE_ENTRY(entry->disc_string) |
| 497 | MOVE_ENTRY(entry->year_string) |
| 498 | MOVE_ENTRY(entry->composer) |
| 499 | MOVE_ENTRY(entry->comment) |
| 500 | MOVE_ENTRY(entry->albumartist) |
| 501 | MOVE_ENTRY(entry->grouping) |
| 502 | MOVE_ENTRY(entry->mb_track_id) |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | void copy_mp3entry(struct mp3entry *dest, const struct mp3entry *orig) |
| 506 | { |
| 507 | memcpy(dest, orig, sizeof(struct mp3entry)); |
| 508 | adjust_mp3entry(dest, dest, orig); |
| 509 | } |
Michael Hohmuth | 7141ff4 | 2011-02-08 20:31:35 +0000 | [diff] [blame] | 510 | |
Michael Sevakis | c537d59 | 2011-04-27 03:08:23 +0000 | [diff] [blame] | 511 | /* A shortcut to simplify the common task of clearing the struct */ |
| 512 | void wipe_mp3entry(struct mp3entry *id3) |
| 513 | { |
| 514 | memset(id3, 0, sizeof (struct mp3entry)); |
| 515 | } |
| 516 | |
| 517 | #if CONFIG_CODEC == SWCODEC |
| 518 | /* Glean what is possible from the filename alone - does not parse metadata */ |
| 519 | void fill_metadata_from_path(struct mp3entry *id3, const char *trackname) |
| 520 | { |
| 521 | char *p; |
| 522 | |
| 523 | /* Clear the mp3entry to avoid having bogus pointers appear */ |
| 524 | wipe_mp3entry(id3); |
| 525 | |
| 526 | /* Find the filename portion of the path */ |
| 527 | p = strrchr(trackname, '/'); |
| 528 | strlcpy(id3->id3v2buf, p ? ++p : id3->path, ID3V2_BUF_SIZE); |
| 529 | |
| 530 | /* Get the format from the extension and trim it off */ |
| 531 | p = strrchr(id3->id3v2buf, '.'); |
| 532 | if (p) |
| 533 | { |
| 534 | /* Might be wrong for container formats - should we bother? */ |
| 535 | id3->codectype = probe_file_format(p); |
| 536 | |
| 537 | if (id3->codectype != AFMT_UNKNOWN) |
| 538 | *p = '\0'; |
| 539 | } |
| 540 | |
| 541 | /* Set the filename as the title */ |
| 542 | id3->title = id3->id3v2buf; |
| 543 | |
| 544 | /* Copy the path info */ |
| 545 | strlcpy(id3->path, trackname, sizeof (id3->path)); |
| 546 | } |
| 547 | #endif /* CONFIG_CODEC == SWCODEC */ |
| 548 | |
Michael Hohmuth | 5afd066 | 2011-02-08 20:50:25 +0000 | [diff] [blame] | 549 | #ifndef __PCTOOL__ |
Michael Hohmuth | 7141ff4 | 2011-02-08 20:31:35 +0000 | [diff] [blame] | 550 | #ifdef HAVE_TAGCACHE |
| 551 | #if CONFIG_CODEC == SWCODEC |
| 552 | |
| 553 | enum { AUTORESUMABLE_UNKNOWN = 0, AUTORESUMABLE_TRUE, AUTORESUMABLE_FALSE }; |
| 554 | |
| 555 | bool autoresumable(struct mp3entry *id3) |
| 556 | { |
Michael Hohmuth | a530376 | 2011-02-11 00:20:03 +0000 | [diff] [blame] | 557 | char *endp, *path; |
| 558 | size_t len; |
| 559 | bool is_resumable; |
| 560 | |
Michael Hohmuth | 7141ff4 | 2011-02-08 20:31:35 +0000 | [diff] [blame] | 561 | if (id3->autoresumable) /* result cached? */ |
| 562 | return id3->autoresumable == AUTORESUMABLE_TRUE; |
| 563 | |
Michael Hohmuth | 7141ff4 | 2011-02-08 20:31:35 +0000 | [diff] [blame] | 564 | is_resumable = false; |
| 565 | |
Michael Hohmuth | a530376 | 2011-02-11 00:20:03 +0000 | [diff] [blame] | 566 | if (id3->path) |
| 567 | { |
| 568 | for (path = global_settings.autoresume_paths; |
| 569 | *path; /* search terms left? */ |
| 570 | path++) |
| 571 | { |
| 572 | if (*path == ':') /* Skip empty search patterns */ |
| 573 | continue; |
| 574 | |
| 575 | /* FIXME: As soon as strcspn or strchrnul are made available in |
| 576 | the core, the following can be made more efficient. */ |
| 577 | endp = strchr(path, ':'); |
| 578 | if (endp) |
| 579 | len = endp - path; |
| 580 | else |
| 581 | len = strlen(path); |
| 582 | |
| 583 | /* Note: At this point, len is always > 0 */ |
| 584 | |
| 585 | if (strncasecmp(id3->path, path, len) == 0) |
| 586 | { |
| 587 | /* Full directory-name matches only. Trailing '/' in |
| 588 | search path OK. */ |
| 589 | if (id3->path[len] == '/' || id3->path[len - 1] == '/') |
| 590 | { |
| 591 | is_resumable = true; |
| 592 | break; |
| 593 | } |
| 594 | } |
| 595 | path += len - 1; |
| 596 | } |
| 597 | } |
| 598 | |
Michael Hohmuth | 7141ff4 | 2011-02-08 20:31:35 +0000 | [diff] [blame] | 599 | /* cache result */ |
| 600 | id3->autoresumable = |
| 601 | is_resumable ? AUTORESUMABLE_TRUE : AUTORESUMABLE_FALSE; |
| 602 | |
Michael Hohmuth | a530376 | 2011-02-11 00:20:03 +0000 | [diff] [blame] | 603 | logf("autoresumable: %s is%s resumable", |
| 604 | id3->path, is_resumable ? "" : " not"); |
| 605 | |
Michael Hohmuth | 7141ff4 | 2011-02-08 20:31:35 +0000 | [diff] [blame] | 606 | return is_resumable; |
| 607 | } |
| 608 | |
| 609 | #endif /* SWCODEC */ |
| 610 | #endif /* HAVE_TAGCACHE */ |
Michael Hohmuth | 5afd066 | 2011-02-08 20:50:25 +0000 | [diff] [blame] | 611 | #endif /* __PCTOOL__ */ |