1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
#! /bin/sh /usr/share/dpatch/dpatch-run
## 01_flac_input.dpatch by Paul Brossier <piem@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Read flac metadata if no ID3 tags are found
@DPATCH@
--- alsaplayer-0.99.76.orig/input/flac/FlacTag.cpp
+++ alsaplayer-0.99.76/input/flac/FlacTag.cpp
@@ -23,6 +23,7 @@
#include "FlacTag.h"
#include "FlacId3Tag.h"
+#include "FlacMetadataTag.h"
using namespace std;
@@ -34,10 +35,7 @@
bool
FlacTag::hasTag (const std::string & path)
{
- if (FlacId3Tag::hasId3 (path))
- return true;
-
- return false;
+ return FlacId3Tag::hasId3 (path) || FlacMetadataTag::hasMetadata (path);
} // FlacTag::hasTag
@@ -50,6 +48,8 @@
{
if (FlacId3Tag::hasId3 (name))
return new FlacId3Tag (name);
+ else if (FlacMetadataTag::hasMetadata (name))
+ return new FlacMetadataTag (name);
return new FlacTag (name);
}
@@ -67,6 +67,8 @@
{
if (FlacId3Tag::hasId3 (name))
return FlacId3Tag (name);
+ if (FlacMetadataTag::hasMetadata (name))
+ return FlacMetadataTag (name);
return FlacTag (name);
--- alsaplayer-0.99.76.orig/input/flac/FlacMetadataTag.cpp
+++ alsaplayer-0.99.76/input/flac/FlacMetadataTag.cpp
@@ -0,0 +1,154 @@
+//---------------------------------------------------------------------------
+// Provide read-only access to flac stream tags. Supports flac
+// VORBIS_COMMENT metadata blocks via libFLAC.
+//
+// Copyright (c) 2003 by Tim Evans <t.evans@paradise.net.nz>
+//
+// Based on FlacId3v1Tag.cpp by Drew Hess <dhess@bothan.net>.
+//
+// Changes:
+// June 05, 2005 (Hubert Chan <hubert@uhoreg.ca>)
+// - don't use fixed-length buffers
+// - use an array instead of a long if-else chain
+//
+// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+//--------------------------------------------------------------------------
+
+
+#include "FlacMetadataTag.h"
+
+#include <cstring>
+#include "reader.h"
+
+extern "C" {
+#include <FLAC/metadata.h>
+}
+
+
+static bool
+find_vorbis_comment_metadata (const char *filename,
+ FLAC__StreamMetadata **metadata)
+{
+ FLAC__Metadata_SimpleIterator *flac = FLAC__metadata_simple_iterator_new ();
+ if (!flac)
+ return false;
+ if (!FLAC__metadata_simple_iterator_init (flac, filename, true, false)) {
+ FLAC__metadata_simple_iterator_delete (flac);
+ return false;
+ }
+
+ bool status = false;
+ FLAC__MetadataType type;
+ do {
+ type = FLAC__metadata_simple_iterator_get_block_type (flac);
+ if (type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
+ status = true;
+ if (metadata)
+ *metadata = FLAC__metadata_simple_iterator_get_block (flac);
+ break;
+ }
+ }
+ while (FLAC__metadata_simple_iterator_next (flac));
+
+ FLAC__metadata_simple_iterator_delete (flac);
+ return status;
+}
+
+
+// Split the comment into key and value. Key and value are newly allocated
+// strings and should be deleted after they are no longer needed.
+// Returns true if the split was successful; false otherwise.
+static bool
+parse_comment (const FLAC__StreamMetadata_VorbisComment_Entry *comment,
+ char **key, char **value)
+{
+ FLAC__byte *sep;
+ size_t key_len, value_len;
+
+ if ((sep = (FLAC__byte *) memchr(comment->entry, '=', comment->length))
+ == NULL)
+ return false;
+
+ key_len = sep - comment->entry;
+ value_len = comment->length - key_len - 1;
+
+ (*key) = new char[key_len+1];
+ memcpy (*key, comment->entry, key_len);
+ (*key)[key_len] = '\0';
+
+ (*value) = new char[value_len+1];
+ memcpy (*value, sep + 1, value_len);
+ (*value)[value_len] = '\0';
+
+ return true;
+}
+
+
+namespace Flac
+{
+
+const FlacMetadataTag::field_mapping_t FlacMetadataTag::field_mappings[] =
+{
+ { "TITLE", &FlacMetadataTag::_title },
+ { "ARTIST", &FlacMetadataTag::_artist },
+ { "TRACKNUMBER", &FlacMetadataTag::_track },
+ { "ALBUM", &FlacMetadataTag::_album },
+ { "YEAR", &FlacMetadataTag::_year },
+ { "DESCRIPTION", &FlacMetadataTag::_comment },
+ { NULL, NULL }
+};
+
+
+// static
+bool
+FlacMetadataTag::hasMetadata (const std::string & name)
+{
+ return find_vorbis_comment_metadata (name.c_str (), NULL);
+
+} // FlacMetadataTag::hasMetadata
+
+
+FlacMetadataTag::FlacMetadataTag (const std::string & name)
+ : FlacTag (name)
+{
+ FLAC__StreamMetadata *metadata;
+ FLAC__StreamMetadata_VorbisComment_Entry *comment;
+ unsigned int i,j;
+ char *key, *value;
+
+ if (!find_vorbis_comment_metadata (name.c_str (), &metadata))
+ return;
+
+ for (i=0; i<metadata->data.vorbis_comment.num_comments; i++) {
+ comment = &metadata->data.vorbis_comment.comments[i];
+ if (parse_comment(comment, &key, &value)) {
+ // look through the field mappings to see which field we have, and
+ // put it in the appropriate member
+ for (j=0; field_mappings[j].name != NULL; j++) {
+ if (strcmp (field_mappings[j].name, key) == 0)
+ {
+ (this->*(field_mappings[j].value)) = value;
+ }
+ }
+ delete key;
+ delete value;
+ }
+ }
+
+ FLAC__metadata_object_delete (metadata);
+
+} // FlacMetadataTag::FlacMetadataTag
+
+} // namespace Flac
--- alsaplayer-0.99.76.orig/input/flac/FlacMetadataTag.h
+++ alsaplayer-0.99.76/input/flac/FlacMetadataTag.h
@@ -0,0 +1,78 @@
+//---------------------------------------------------------------------------
+// Provide read-only access to flac stream tags. Supports flac
+// VORBIS_COMMENT metadata blocks via libFLAC. Based on FlacId3Tag.h.
+//
+// Copyright (c) 2003 by Tim Evans <t.evans@paradise.net.nz>
+//
+// Based on FlacId3Tag.h by Drew Hess <dhess@bothan.net>.
+//
+// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+//--------------------------------------------------------------------------
+
+
+#ifndef _FLAC_METADATA_TAG_H_
+#define _FLAC_METADATA_TAG_H_
+
+#include "FlacTag.h"
+
+namespace Flac
+{
+
+class FlacMetadataTag : public FlacTag
+{
+
+ // Map metadata names to the variable that they refer to
+ typedef struct
+ {
+ char *name;
+ std::string FlacMetadataTag::* value;
+ }
+ field_mapping_t;
+
+ static const field_mapping_t field_mappings[];
+
+ public:
+
+ FlacMetadataTag (const std::string & name);
+
+ virtual ~FlacMetadataTag ();
+
+ protected:
+
+ //--------------------------------------------------------------
+ // Return true if the flac stream whose name is given has a
+ // metadata tag.
+ //--------------------------------------------------------------
+
+ static bool hasMetadata (const std::string & name);
+
+ friend class FlacTag;
+
+}; // class FlacMeatadataTag
+
+
+//----------------
+// Inline methods.
+//----------------
+
+inline
+FlacMetadataTag::~FlacMetadataTag ()
+{
+}
+
+} // namespace Flac
+
+#endif // _FLAC_METADATA_TAG_H_
+
|