aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-07-28 20:25:45 +0200
committerMax Kellermann <max@duempel.org>2013-07-28 20:25:45 +0200
commitdd5ba062cc03d0de7fa2b46f16817f8c7c2b112e (patch)
tree3bf0273d15ce6a4a2b62ba344e80bbb4a3617e40 /src
parentba161ec572b98d3bcf9f735ff122133319fe896a (diff)
downloadmpd-dd5ba062cc03d0de7fa2b46f16817f8c7c2b112e.tar.gz
mpd-dd5ba062cc03d0de7fa2b46f16817f8c7c2b112e.tar.xz
mpd-dd5ba062cc03d0de7fa2b46f16817f8c7c2b112e.zip
tag_id3: convert to C++
Diffstat (limited to 'src')
-rw-r--r--src/SongUpdate.cxx2
-rw-r--r--src/TagId3.cxx (renamed from src/tag_id3.c)121
-rw-r--r--src/TagId3.hxx (renamed from src/tag_id3.h)6
-rw-r--r--src/decoder/DsdLib.cxx5
-rw-r--r--src/decoder/MadDecoderPlugin.cxx6
-rw-r--r--src/playlist/EmbeddedCuePlaylistPlugin.cxx2
6 files changed, 68 insertions, 74 deletions
diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx
index 6752386be..cfe4741c9 100644
--- a/src/SongUpdate.cxx
+++ b/src/SongUpdate.cxx
@@ -28,10 +28,10 @@
#include "input_stream.h"
#include "DecoderPlugin.hxx"
#include "DecoderList.hxx"
+#include "TagId3.hxx"
extern "C" {
#include "tag_ape.h"
-#include "tag_id3.h"
#include "tag_handler.h"
}
diff --git a/src/tag_id3.c b/src/TagId3.cxx
index 5744e0e62..d6bef2fa9 100644
--- a/src/tag_id3.c
+++ b/src/TagId3.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,12 +18,16 @@
*/
#include "config.h"
-#include "tag_id3.h"
+#include "TagId3.hxx"
#include "tag_handler.h"
#include "tag_table.h"
#include "tag.h"
+
+extern "C" {
#include "riff.h"
#include "aiff.h"
+}
+
#include "conf.h"
#include "io_error.h"
@@ -70,12 +74,12 @@ tag_id3_getstring(const struct id3_frame *frame, unsigned i)
const id3_ucs4_t *ucs4;
field = id3_frame_field(frame, i);
- if (field == NULL)
- return NULL;
+ if (field == nullptr)
+ return nullptr;
ucs4 = id3_field_getstring(field);
- if (ucs4 == NULL)
- return NULL;
+ if (ucs4 == nullptr)
+ return nullptr;
return id3_ucs4_utf8duplicate(ucs4);
}
@@ -91,27 +95,28 @@ import_id3_string(bool is_id3v1, const id3_ucs4_t *ucs4)
/* use encoding field here? */
if (is_id3v1 &&
- (encoding = config_get_string(CONF_ID3V1_ENCODING, NULL)) != NULL) {
+ (encoding = config_get_string(CONF_ID3V1_ENCODING, nullptr)) != nullptr) {
isostr = id3_ucs4_latin1duplicate(ucs4);
if (G_UNLIKELY(!isostr)) {
- return NULL;
+ return nullptr;
}
utf8 = (id3_utf8_t *)
g_convert_with_fallback((const char*)isostr, -1,
"utf-8", encoding,
- NULL, NULL, NULL, NULL);
- if (utf8 == NULL) {
+ nullptr, nullptr,
+ nullptr, nullptr);
+ if (utf8 == nullptr) {
g_debug("Unable to convert %s string to UTF-8: '%s'",
encoding, isostr);
g_free(isostr);
- return NULL;
+ return nullptr;
}
g_free(isostr);
} else {
utf8 = id3_ucs4_utf8duplicate(ucs4);
if (G_UNLIKELY(!utf8)) {
- return NULL;
+ return nullptr;
}
}
@@ -144,27 +149,27 @@ tag_id3_import_text_frame(struct id3_tag *tag, const struct id3_frame *frame,
/* check the encoding field */
field = id3_frame_field(frame, 0);
- if (field == NULL || field->type != ID3_FIELD_TYPE_TEXTENCODING)
+ if (field == nullptr || field->type != ID3_FIELD_TYPE_TEXTENCODING)
return;
/* process the value(s) */
field = id3_frame_field(frame, 1);
- if (field == NULL || field->type != ID3_FIELD_TYPE_STRINGLIST)
+ if (field == nullptr || field->type != ID3_FIELD_TYPE_STRINGLIST)
return;
/* Get the number of strings available */
nstrings = id3_field_getnstrings(field);
for (i = 0; i < nstrings; i++) {
ucs4 = id3_field_getstrings(field, i);
- if (ucs4 == NULL)
+ if (ucs4 == nullptr)
continue;
if (type == TAG_GENRE)
ucs4 = id3_genre_name(ucs4);
utf8 = import_id3_string(tag_is_id3v1(tag), ucs4);
- if (utf8 == NULL)
+ if (utf8 == nullptr)
continue;
tag_handler_invoke_tag(handler, handler_ctx,
@@ -183,7 +188,7 @@ tag_id3_import_text(struct id3_tag *tag, const char *id, enum tag_type type,
{
const struct id3_frame *frame;
for (unsigned i = 0;
- (frame = id3_tag_findframe(tag, id, i)) != NULL; ++i)
+ (frame = id3_tag_findframe(tag, id, i)) != nullptr; ++i)
tag_id3_import_text_frame(tag, frame, type,
handler, handler_ctx);
}
@@ -212,15 +217,15 @@ tag_id3_import_comment_frame(struct id3_tag *tag,
/* for now I only read the 4th field, with the fullstring */
field = id3_frame_field(frame, 3);
- if (field == NULL)
+ if (field == nullptr)
return;
ucs4 = id3_field_getfullstring(field);
- if (ucs4 == NULL)
+ if (ucs4 == nullptr)
return;
utf8 = import_id3_string(tag_is_id3v1(tag), ucs4);
- if (utf8 == NULL)
+ if (utf8 == nullptr)
return;
tag_handler_invoke_tag(handler, handler_ctx, type, (const char *)utf8);
@@ -237,7 +242,7 @@ tag_id3_import_comment(struct id3_tag *tag, const char *id, enum tag_type type,
{
const struct id3_frame *frame;
for (unsigned i = 0;
- (frame = id3_tag_findframe(tag, id, i)) != NULL; ++i)
+ (frame = id3_tag_findframe(tag, id, i)) != nullptr; ++i)
tag_id3_import_comment_frame(tag, frame, type,
handler, handler_ctx);
}
@@ -256,7 +261,7 @@ tag_id3_parse_txxx_name(const char *name)
{ "MusicBrainz Album Artist Id",
TAG_MUSICBRAINZ_ALBUMARTISTID },
{ "MusicBrainz Track Id", TAG_MUSICBRAINZ_TRACKID },
- { NULL, TAG_NUM_OF_ITEM_TYPES }
+ { nullptr, TAG_NUM_OF_ITEM_TYPES }
};
return tag_table_lookup(txxx_tags, name);
@@ -276,15 +281,15 @@ tag_id3_import_musicbrainz(struct id3_tag *id3_tag,
enum tag_type type;
frame = id3_tag_findframe(id3_tag, "TXXX", i);
- if (frame == NULL)
+ if (frame == nullptr)
break;
name = tag_id3_getstring(frame, 1);
- if (name == NULL)
+ if (name == nullptr)
continue;
value = tag_id3_getstring(frame, 2);
- if (value == NULL)
+ if (value == nullptr)
continue;
tag_handler_invoke_pair(handler, handler_ctx,
@@ -317,24 +322,24 @@ tag_id3_import_ufid(struct id3_tag *id3_tag,
id3_length_t length;
frame = id3_tag_findframe(id3_tag, "UFID", i);
- if (frame == NULL)
+ if (frame == nullptr)
break;
field = id3_frame_field(frame, 0);
- if (field == NULL)
+ if (field == nullptr)
continue;
name = id3_field_getlatin1(field);
- if (name == NULL ||
+ if (name == nullptr ||
strcmp((const char *)name, "http://musicbrainz.org") != 0)
continue;
field = id3_frame_field(frame, 1);
- if (field == NULL)
+ if (field == nullptr)
continue;
value = id3_field_getbinarydata(field, &length);
- if (value == NULL || length == 0)
+ if (value == nullptr || length == 0)
continue;
char *p = g_strndup((const char *)value, length);
@@ -388,7 +393,7 @@ struct tag *tag_id3_import(struct id3_tag * tag)
if (tag_is_empty(ret)) {
tag_free(ret);
- ret = NULL;
+ ret = nullptr;
}
return ret;
@@ -417,28 +422,29 @@ tag_id3_read(FILE *stream, long offset, int whence)
{
struct id3_tag *tag;
id3_byte_t query_buffer[ID3_TAG_QUERYSIZE];
- id3_byte_t *tag_buffer;
int tag_size;
int query_buffer_size;
- int tag_buffer_size;
/* It's ok if we get less than we asked for */
query_buffer_size = fill_buffer(query_buffer, ID3_TAG_QUERYSIZE,
stream, offset, whence);
- if (query_buffer_size <= 0) return NULL;
+ if (query_buffer_size <= 0)
+ return nullptr;
/* Look for a tag header */
tag_size = id3_tag_query(query_buffer, query_buffer_size);
- if (tag_size <= 0) return NULL;
+ if (tag_size <= 0) return nullptr;
/* Found a tag. Allocate a buffer and read it in. */
- tag_buffer = g_malloc(tag_size);
- if (!tag_buffer) return NULL;
+ id3_byte_t *tag_buffer = (id3_byte_t *)g_malloc(tag_size);
+ if (!tag_buffer)
+ return nullptr;
- tag_buffer_size = fill_buffer(tag_buffer, tag_size, stream, offset, whence);
+ int tag_buffer_size = fill_buffer(tag_buffer, tag_size,
+ stream, offset, whence);
if (tag_buffer_size < tag_size) {
g_free(tag_buffer);
- return NULL;
+ return nullptr;
}
tag = id3_tag_parse(tag_buffer, tag_buffer_size);
@@ -458,11 +464,11 @@ tag_id3_find_from_beginning(FILE *stream)
tag = tag_id3_read(stream, 0, SEEK_SET);
if (!tag) {
- return NULL;
+ return nullptr;
} else if (tag_is_id3v1(tag)) {
/* id3v1 tags don't belong here */
id3_tag_delete(tag);
- return NULL;
+ return nullptr;
}
/* We have an id3v2 tag, so let's look for SEEK frames */
@@ -514,30 +520,25 @@ tag_id3_find_from_end(FILE *stream)
static struct id3_tag *
tag_id3_riff_aiff_load(FILE *file)
{
- size_t size;
- void *buffer;
- size_t ret;
- struct id3_tag *tag;
-
- size = riff_seek_id3(file);
+ size_t size = riff_seek_id3(file);
if (size == 0)
size = aiff_seek_id3(file);
if (size == 0)
- return NULL;
+ return nullptr;
if (size > 4 * 1024 * 1024)
/* too large, don't allocate so much memory */
- return NULL;
+ return nullptr;
- buffer = g_malloc(size);
- ret = fread(buffer, size, 1, file);
+ id3_byte_t *buffer = (id3_byte_t *)g_malloc(size);
+ size_t ret = fread(buffer, size, 1, file);
if (ret != 1) {
g_warning("Failed to read RIFF chunk");
g_free(buffer);
- return NULL;
+ return nullptr;
}
- tag = id3_tag_parse(buffer, size);
+ struct id3_tag *tag = id3_tag_parse(buffer, size);
g_free(buffer);
return tag;
}
@@ -546,17 +547,17 @@ struct id3_tag *
tag_id3_load(const char *path_fs, GError **error_r)
{
FILE *file = fopen(path_fs, "rb");
- if (file == NULL) {
+ if (file == nullptr) {
g_set_error(error_r, errno_quark(), errno,
"Failed to open file %s: %s",
path_fs, g_strerror(errno));
- return NULL;
+ return nullptr;
}
struct id3_tag *tag = tag_id3_find_from_beginning(file);
- if (tag == NULL) {
+ if (tag == nullptr) {
tag = tag_id3_riff_aiff_load(file);
- if (tag == NULL)
+ if (tag == nullptr)
tag = tag_id3_find_from_end(file);
}
@@ -568,10 +569,10 @@ bool
tag_id3_scan(const char *path_fs,
const struct tag_handler *handler, void *handler_ctx)
{
- GError *error = NULL;
+ GError *error = nullptr;
struct id3_tag *tag = tag_id3_load(path_fs, &error);
- if (tag == NULL) {
- if (error != NULL) {
+ if (tag == nullptr) {
+ if (error != nullptr) {
g_warning("%s", error->message);
g_error_free(error);
}
diff --git a/src/tag_id3.h b/src/TagId3.hxx
index 1907c13fc..271fc081f 100644
--- a/src/tag_id3.h
+++ b/src/TagId3.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef MPD_TAG_ID3_H
-#define MPD_TAG_ID3_H
+#ifndef MPD_TAG_ID3_HXX
+#define MPD_TAG_ID3_HXX
#include "check.h"
#include "gcc.h"
diff --git a/src/decoder/DsdLib.cxx b/src/decoder/DsdLib.cxx
index 40a553d91..5337612a9 100644
--- a/src/decoder/DsdLib.cxx
+++ b/src/decoder/DsdLib.cxx
@@ -28,10 +28,7 @@
#include "DecoderAPI.hxx"
#include "util/bit_reverse.h"
#include "tag_handler.h"
-
-extern "C" {
-#include "tag_id3.h"
-}
+#include "TagId3.hxx"
#include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx
index bbfd2f412..f8dd03701 100644
--- a/src/decoder/MadDecoderPlugin.cxx
+++ b/src/decoder/MadDecoderPlugin.cxx
@@ -21,11 +21,7 @@
#include "MadDecoderPlugin.hxx"
#include "DecoderAPI.hxx"
#include "conf.h"
-
-extern "C" {
-#include "tag_id3.h"
-}
-
+#include "TagId3.hxx"
#include "TagRva2.hxx"
#include "tag_handler.h"
#include "audio_check.h"
diff --git a/src/playlist/EmbeddedCuePlaylistPlugin.cxx b/src/playlist/EmbeddedCuePlaylistPlugin.cxx
index b88e4ae8c..8f8d87153 100644
--- a/src/playlist/EmbeddedCuePlaylistPlugin.cxx
+++ b/src/playlist/EmbeddedCuePlaylistPlugin.cxx
@@ -28,13 +28,13 @@
#include "PlaylistPlugin.hxx"
#include "tag.h"
#include "tag_handler.h"
+#include "TagId3.hxx"
#include "Song.hxx"
#include "TagFile.hxx"
#include "cue/CueParser.hxx"
extern "C" {
#include "tag_ape.h"
-#include "tag_id3.h"
}
#include <glib.h>