[tracker/tracker-0.6] Code cleanups for MP3 extractor
- From: Martyn James Russell <mr src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-0.6] Code cleanups for MP3 extractor
- Date: Wed, 24 Jun 2009 11:59:40 +0000 (UTC)
commit bf121e529c9029cf9ec2fd0b6e9b97b62f1102c6
Author: Martyn Russell <martyn imendio com>
Date: Wed Jun 24 10:09:11 2009 +0100
Code cleanups for MP3 extractor
src/tracker-extract/tracker-extract-mp3.c | 454 ++++++++++++++++-------------
1 files changed, 253 insertions(+), 201 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index 08fe0f1..ca3a095 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -51,14 +51,16 @@
#include "tracker-extract-albumart.h"
#include "tracker-escape.h"
-/* We mmap the beginning of the file and read separately the last 128 bytes
- for id3v1 tags. While these are probably cornercases the rationale is that
- we don't want to fault a whole page for the last 128 bytes and on the other
- we don't want to mmap the whole file with unlimited size (might need to create
- private copy in some special cases, finding continuous space etc). We now take
- 5 first MB of the file and assume that this is enough. In theory there is no
- maximum size as someone could embed 50 gigabytes of albumart there.
-*/
+/* We mmap the beginning of the file and read separately the last 128
+ * bytes for id3v1 tags. While these are probably cornercases the
+ * rationale is that we don't want to fault a whole page for the last
+ * 128 bytes and on the other we don't want to mmap the whole file
+ * with unlimited size (might need to create private copy in some
+ * special cases, finding continuous space etc). We now take 5 first
+ * MB of the file and assume that this is enough. In theory there is
+ * no maximum size as someone could embed 50 gigabytes of albumart
+ * there.
+ */
#define MAX_FILE_READ 1024 * 1024 * 5
#define MAX_MP3_SCAN_DEEP 16768
@@ -71,7 +73,7 @@
typedef struct {
const gchar *text;
const gchar *type;
-} Matches;
+} tag_matches;
typedef struct {
gchar *title;
@@ -82,7 +84,7 @@ typedef struct {
gchar *trackno;
gchar *genre;
gchar *encoding;
-} id3tag;
+} tag_info;
typedef struct {
size_t size;
@@ -271,7 +273,7 @@ static const guint freq_mask = 0xC0000;
static const guint ch_mask = 0xC0000000;
static const guint pad_mask = 0x20000;
-static guint bitrate_table[16][6] = {
+static const guint bitrate_table[16][6] = {
{ 0, 0, 0, 0, 0, 0 },
{ 32, 32, 32, 32, 8, 8 },
{ 64, 48, 40, 48, 16, 16 },
@@ -290,13 +292,15 @@ static guint bitrate_table[16][6] = {
{ -1, -1, -1, -1, -1, -1 }
};
-static gint freq_table[4][3] = {
- {44100, 22050, 11025},
- {48000, 24000, 12000},
- {32000, 16000, 8000}
+static const gint freq_table[4][3] = {
+ { 44100, 22050, 11025 },
+ { 48000, 24000, 12000 },
+ { 32000, 16000, 8000 }
};
-static gint spf_table[6] = { 48, 144, 144, 48, 144, 72 };
+static const gint spf_table[6] = {
+ 48, 144, 144, 48, 144, 72
+};
static TrackerExtractData extract_data[] = {
{ "audio/mpeg", extract_mp3 },
@@ -307,15 +311,15 @@ static TrackerExtractData extract_data[] = {
static char *
read_id3v1_buffer (int fd, goffset size)
{
- char *buffer;
+ gchar *buffer;
guint bytes_read;
guint rc;
- if (size<128) {
+ if (size < 128) {
return NULL;
}
- if (lseek (fd, size-ID3V1_SIZE, SEEK_SET) < 0) {
+ if (lseek (fd, size - ID3V1_SIZE, SEEK_SET) < 0) {
return NULL;
}
@@ -336,11 +340,11 @@ read_id3v1_buffer (int fd, goffset size)
g_free (buffer);
return NULL;
}
- }
- else if (rc == 0)
+ } else if (rc == 0) {
break;
- else
+ } else {
bytes_read += rc;
+ }
}
return buffer;
@@ -348,20 +352,21 @@ read_id3v1_buffer (int fd, goffset size)
/* Convert from UCS-2 to UTF-8 checking the BOM.*/
static gchar *
-ucs2_to_utf8 (const gchar *data, guint len)
+ucs2_to_utf8 (const gchar *data,
+ guint len)
{
- gchar *encoding = NULL;
- guint16 c;
- gboolean be;
- gchar *utf8 = NULL;
+ gchar *encoding = NULL;
+ guint16 c;
+ gboolean be;
+ gchar *utf8 = NULL;
memcpy (&c, data, 2);
switch (c) {
case 0xfeff:
case 0xfffe:
- be = (G_BYTE_ORDER == G_BIG_ENDIAN);
- be = (c == 0xfeff) ? be : !be;
+ be = G_BYTE_ORDER == G_BIG_ENDIAN;
+ be = c == 0xfeff ? be : !be;
encoding = be ? "UCS-2BE" : "UCS-2LE";
data += 2;
len -= 2;
@@ -385,11 +390,13 @@ get_genre_number (const char *str, guint *genre)
GMatchInfo *info = NULL;
gchar *result = NULL;
- if (!regex1)
+ if (!regex1) {
regex1 = g_regex_new ("\\(([0-9]+)\\)", 0, 0, NULL);
+ }
- if (!regex2)
+ if (!regex2) {
regex2 = g_regex_new ("([0-9]+)\\z", 0, 0, NULL);
+ }
if (g_regex_match (regex1, str, 0, &info)) {
result = g_match_info_fetch (info, 1);
@@ -434,9 +441,9 @@ un_unsync (const unsigned char *source,
unsigned char **destination,
size_t *dest_size)
{
- size_t offset = 0;
- gchar *dest;
- size_t new_size;
+ gchar *dest;
+ size_t offset = 0;
+ size_t new_size;
*destination = g_malloc0 (size);
dest = *destination;
@@ -445,11 +452,12 @@ un_unsync (const unsigned char *source,
while (offset < size) {
*dest = source[offset];
- if ((source[offset] == 0xFF) &&
- (source[offset + 1] == 0x00)) {
+ if (source[offset] == 0xFF &&
+ source[offset + 1] == 0x00) {
offset++;
new_size--;
}
+
dest++;
offset++;
}
@@ -457,7 +465,6 @@ un_unsync (const unsigned char *source,
*dest_size = new_size;
}
-
static char*
get_encoding (const char *data,
gssize size,
@@ -550,7 +557,7 @@ t_convert (const gchar *str,
static gboolean
get_id3 (const gchar *data,
size_t size,
- id3tag *id3)
+ tag_info *id3)
{
#ifdef HAVE_ENCA
GString *s;
@@ -656,7 +663,7 @@ mp3_parse_header (const gchar *data,
gint ch = 0;
guint frame_size;
guint frames = 0;
- size_t pos = 0;
+ size_t pos;
pos = seek_pos;
@@ -788,7 +795,7 @@ mp3_parse_header (const gchar *data,
break;
}
- if ((!vbr_flag) && (frames > VBR_THRESHOLD)) {
+ if (!vbr_flag && frames > VBR_THRESHOLD) {
break;
}
@@ -802,8 +809,8 @@ mp3_parse_header (const gchar *data,
avg_bps /= frames;
- if (filedata->duration==0) {
- if ((!vbr_flag && frames > VBR_THRESHOLD) || (frames > MAX_FRAMES_SCAN)) {
+ if (filedata->duration ==0 ) {
+ if ((!vbr_flag && frames > VBR_THRESHOLD) || frames > MAX_FRAMES_SCAN) {
/* If not all frames scanned */
length = (filedata->size - filedata->id3v2_size) / (avg_bps ? avg_bps : bitrate ? bitrate : 0xFFFFFFFF) / 125;
} else{
@@ -862,39 +869,39 @@ mp3_parse (const gchar *data,
static void
get_id3v24_tags (const gchar *data,
size_t size,
- id3tag *info,
+ tag_info *info,
GHashTable *metadata,
file_data *filedata)
{
guint pos = 0;
- Matches tmap[] = {
- {"TCOP", "File:Copyright"},
- {"TDRC", "Audio:ReleaseDate"},
- {"TCON", "Audio:Genre"},
- {"TIT1", "Audio:Genre"},
+ tag_matches tmap[] = {
+ { "TCOP", "File:Copyright" },
+ { "TDRC", "Audio:ReleaseDate" },
+ { "TCON", "Audio:Genre" },
+ { "TIT1", "Audio:Genre" },
#ifdef ENABLE_DETAILED_METADATA
- {"TENC", "DC:Publishers"},
+ { "TENC", "DC:Publishers" },
#endif /* ENABLE_DETAILED_METADATA */
- {"TEXT", "Audio:Lyrics"},
- {"TPE1", "Audio:Artist"},
- {"TPE2", "Audio:Artist"},
- {"TPE3", "Audio:Performer"},
+ { "TEXT", "Audio:Lyrics" },
+ { "TPE1", "Audio:Artist" },
+ { "TPE2", "Audio:Artist" },
+ { "TPE3", "Audio:Performer" },
/* {"TOPE", "Audio:Artist"}, We dont' want the original artist for now */
#ifdef ENABLE_DETAILED_METADATA
- {"TPUB", "DC:Publishers"},
+ { "TPUB", "DC:Publishers" },
#endif /* ENABLE_DETAILED_METADATA */
- {"TOAL", "Audio:Album"},
- {"TALB", "Audio:Album"},
- {"TLAN", "File:Language"},
- {"TIT2", "Audio:Title"},
+ { "TOAL", "Audio:Album" },
+ { "TALB", "Audio:Album" },
+ { "TLAN", "File:Language" },
+ { "TIT2", "Audio:Title" },
#ifdef ENABLE_DETAILED_METADATA
- {"TIT3", "Audio:Comment"},
+ { "TIT3", "Audio:Comment" },
#endif /* ENABLE_DETAILED_METADATA */
- {"TDRL", "Audio:ReleaseDate"},
- {"TRCK", "Audio:TrackNo"},
- {"PCNT", "Audio:PlayCount"},
- {"TLEN", "Audio:Duration"},
- {NULL, 0},
+ { "TDRL", "Audio:ReleaseDate" },
+ { "TRCK", "Audio:TrackNo" },
+ { "PCNT", "Audio:PlayCount" },
+ { "TLEN", "Audio:Duration" },
+ { NULL, 0 },
};
while (pos < size) {
@@ -911,9 +918,9 @@ get_id3v24_tags (const gchar *data,
((data[pos+6] & 0x7F) << 7) |
((data[pos+7] & 0x7F) << 0));
- if ((pos + 10 + csize > size) ||
- (csize > size) ||
- (csize == 0)) {
+ if (pos + 10 + csize > size ||
+ csize > size ||
+ csize == 0) {
break;
}
@@ -989,6 +996,7 @@ get_id3v24_tags (const gchar *data,
parts = g_strsplit (word, "/", 2);
g_free (word);
+
word = g_strdup (parts[0]);
g_strfreev (parts);
} else if (strcmp (tmap[i].text, "TCON") == 0) {
@@ -1007,8 +1015,9 @@ get_id3v24_tags (const gchar *data,
duration = atoi (word);
g_free (word);
- word = g_strdup_printf ("%d", duration/1000);
- filedata->duration = duration/1000;
+
+ word = g_strdup_printf ("%d", duration / 1000);
+ filedata->duration = duration / 1000;
}
g_hash_table_insert (metadata,
@@ -1033,11 +1042,18 @@ get_id3v24_tags (const gchar *data,
guint offset;
gint text_desc_len;
- text_encode = data[pos + 10]; /* $xx */
- text_language = &data[pos + 11]; /* $xx xx xx */
- text_desc = &data[pos + 14]; /* <text string according to encoding> $00 (00) */
+ /* $xx */
+ text_encode = data[pos + 10];
+
+ /* $xx xx xx */
+ text_language = &data[pos + 11];
+
+ /* <text string according to encoding> $00 (00) */
+ text_desc = &data[pos + 14];
text_desc_len = strlen (text_desc);
- text = &data[pos + 14 + text_desc_len + 1]; /* <full text string according to encoding> */
+
+ /* <full text string according to encoding> */
+ text = &data[pos + 14 + text_desc_len + 1];
offset = 4 + text_desc_len + 1;
@@ -1124,36 +1140,36 @@ get_id3v24_tags (const gchar *data,
static void
get_id3v23_tags (const gchar *data,
size_t size,
- id3tag *info,
+ tag_info *info,
GHashTable *metadata,
file_data *filedata)
{
- guint pos = 0;
- Matches tmap[] = {
- {"TCOP", "File:Copyright"},
- {"TDAT", "Audio:ReleaseDate"},
- {"TCON", "Audio:Genre"},
- {"TIT1", "Audio:Genre"},
+ guint pos = 0;
+ tag_matches tmap[] = {
+ { "TCOP", "File:Copyright" },
+ { "TDAT", "Audio:ReleaseDate" },
+ { "TCON", "Audio:Genre" },
+ { "TIT1", "Audio:Genre" },
#ifdef ENABLE_DETAILED_METADATA
- {"TENC", "DC:Publishers"},
+ { "TENC", "DC:Publishers" },
#endif /* ENABLE_DETAILED_METADATA */
- {"TEXT", "Audio:Lyrics"},
- {"TPE1", "Audio:Artist"},
- {"TPE2", "Audio:Artist"},
- {"TPE3", "Audio:Performer"},
+ { "TEXT", "Audio:Lyrics" },
+ { "TPE1", "Audio:Artist" },
+ { "TPE2", "Audio:Artist" },
+ { "TPE3", "Audio:Performer" },
/* {"TOPE", "Audio:Artist"}, We don't want the original artist for now */
#ifdef ENABLE_DETAILED_METADATA
- {"TPUB", "DC:Publishers"},
+ { "TPUB", "DC:Publishers" },
#endif /* ENABLE_DETAILED_METADATA */
- {"TOAL", "Audio:Album"},
- {"TALB", "Audio:Album"},
- {"TLAN", "File:Language"},
- {"TIT2", "Audio:Title"},
- {"TYER", "Audio:ReleaseDate"},
- {"TRCK", "Audio:TrackNo"},
- {"PCNT", "Audio:PlayCount"},
- {"TLEN", "Audio:Duration"},
- {NULL, 0},
+ { "TOAL", "Audio:Album" },
+ { "TALB", "Audio:Album" },
+ { "TLAN", "File:Language" },
+ { "TIT2", "Audio:Title" },
+ { "TYER", "Audio:ReleaseDate" },
+ { "TRCK", "Audio:TrackNo" },
+ { "PCNT", "Audio:PlayCount" },
+ { "TLEN", "Audio:Duration" },
+ { NULL, 0 },
};
while (pos < size) {
@@ -1283,11 +1299,18 @@ get_id3v23_tags (const gchar *data,
guint offset;
gint text_desc_len;
- text_encode = data[pos + 10]; /* $xx */
- text_language = &data[pos + 11]; /* $xx xx xx */
- text_desc = &data[pos + 14]; /* <text string according to encoding> $00 (00) */
+ /* $xx */
+ text_encode = data[pos + 10];
+
+ /* $xx xx xx */
+ text_language = &data[pos + 11];
+
+ /* <text string according to encoding> $00 (00) */
+ text_desc = &data[pos + 14];
text_desc_len = strlen (text_desc);
- text = &data[pos + 14 + text_desc_len + 1]; /* <full text string according to encoding> */
+
+ /* <full text string according to encoding> */
+ text = &data[pos + 14 + text_desc_len + 1];
offset = 4 + text_desc_len + 1;
@@ -1364,42 +1387,42 @@ get_id3v23_tags (const gchar *data,
static void
get_id3v20_tags (const gchar *data,
size_t size,
- id3tag *info,
+ tag_info *info,
GHashTable *metadata,
file_data *filedata)
{
- guint pos = 0;
- Matches tmap[] = {
- {"TAL", "Audio:Album"},
- {"TT1", "Audio:Artist"},
- {"TT2", "Audio:Title"},
- {"TT3", "Audio:Title"},
+ guint pos = 0;
+ tag_matches tmap[] = {
+ { "TAL", "Audio:Album" },
+ { "TT1", "Audio:Artist" },
+ { "TT2", "Audio:Title" },
+ { "TT3", "Audio:Title" },
#ifdef ENABLE_DETAILED_METADATA
- {"TXT", "Audio:Comment"},
- {"TPB", "DC:Publishers"},
+ { "TXT", "Audio:Comment" },
+ { "TPB", "DC:Publishers" },
#endif /* ENABLE_DETAILED_METADATA */
- {"WAF", "DC:Location"},
- {"WAR", "DC:Location"},
- {"WAS", "DC:Location"},
- {"WAF", "DC:Location"},
- {"WCM", "File:License"},
- {"TYE", "Audio:ReleaseDate"},
- {"TLA", "File:Lanuguage"},
- {"TP1", "Audio:Artist"},
- {"TP2", "Audio:Artist"},
- {"TP3", "Audio:Performer"},
- {"TEN", "Audio:Performer"},
- {"TCO", "Audio:Genre"},
- {"TCR", "File:Copyright"},
- {"SLT", "Audio:Lyrics"},
- {"TOA", "Audio:Artist"},
- {"TOT", "Audio:Album"},
- {"TOL", "Audio:Artist"},
+ { "WAF", "DC:Location" },
+ { "WAR", "DC:Location" },
+ { "WAS", "DC:Location" },
+ { "WAF", "DC:Location" },
+ { "WCM", "File:License" },
+ { "TYE", "Audio:ReleaseDate" },
+ { "TLA", "File:Lanuguage" },
+ { "TP1", "Audio:Artist" },
+ { "TP2", "Audio:Artist" },
+ { "TP3", "Audio:Performer" },
+ { "TEN", "Audio:Performer" },
+ { "TCO", "Audio:Genre" },
+ { "TCR", "File:Copyright" },
+ { "SLT", "Audio:Lyrics" },
+ { "TOA", "Audio:Artist" },
+ { "TOT", "Audio:Album" },
+ { "TOL", "Audio:Artist" },
#ifdef ENABLE_DETAILED_METADATA
- {"COM", "Audio:Comment"},
+ { "COM", "Audio:Comment" },
#endif /* ENABLE_DETAILED_METADATA */
- {"TLE", "Audio:Duration"},
- { NULL, 0},
+ { "TLE", "Audio:Duration" },
+ { NULL, 0 },
};
while (pos < size) {
@@ -1422,8 +1445,8 @@ get_id3v20_tags (const gchar *data,
i = 0;
while (tmap[i].text != NULL) {
- if (strncmp(tmap[i].text, (const char*) &data[pos], 3) == 0) {
- gchar * word;
+ if (strncmp (tmap[i].text, (const char*) &data[pos], 3) == 0) {
+ gchar *word;
/* This byte describes the encoding
* try to convert strings to UTF-8 if
@@ -1473,6 +1496,7 @@ get_id3v20_tags (const gchar *data,
if (strcmp (tmap[i].text, "TCO") == 0) {
gint genre;
+
if (get_genre_number (word, &genre)) {
g_free (word);
word = g_strdup (get_genre_name (genre));
@@ -1506,16 +1530,17 @@ get_id3v20_tags (const gchar *data,
/* Check for embedded images */
if (strncmp (&data[pos], "PIC", 3) == 0) {
- gchar pic_type;
- const gchar *desc;
- guint offset;
- const gchar *mime;
+ gchar pic_type;
+ const gchar *desc;
+ const gchar *mime;
mime = &data[pos + 6 + 3 + 1];
pic_type = data[pos + 6 + 3 + 1 + 3];
desc = &data[pos + 6 + 3 + 1 + 3 + 1];
if (pic_type == 3 || (pic_type == 0 && filedata->albumartsize == 0)) {
+ guint offset;
+
offset = pos + 6 + 3 + 1 + 3 + 1 + strlen (desc) + 1;
filedata->albumartmime = g_strdup (mime);
@@ -1532,19 +1557,19 @@ get_id3v20_tags (const gchar *data,
static void
parse_id3v24 (const gchar *data,
size_t size,
- id3tag *info,
+ tag_info *info,
GHashTable *metadata,
file_data *filedata,
size_t *offset_delta)
{
- gint unsync;
- gint extendedHdr;
- gint experimental;
- gint footer;
- guint tsize;
- guint pos;
- guint ehdrSize;
- guint padding;
+ gint unsync;
+ gint extendedHdr;
+ gint experimental;
+ gint footer;
+ guint tsize;
+ guint pos;
+ guint ehdrSize;
+ guint padding;
if ((size < 16) ||
(data[0] != 0x49) ||
@@ -1564,7 +1589,7 @@ parse_id3v24 (const gchar *data,
((data[8] & 0x7F) << 7) |
((data[9] & 0x7F) << 0));
- if ((tsize + 10 > size) || (experimental)) {
+ if (tsize + 10 > size || experimental) {
return;
}
@@ -1580,10 +1605,10 @@ parse_id3v24 (const gchar *data,
}
if (unsync) {
- size_t unsync_size;
- gchar *body;
+ size_t unsync_size;
+ gchar *body;
- un_unsync (&data[pos], tsize, (unsigned char **)&body, &unsync_size);
+ un_unsync (&data[pos], tsize, (unsigned char **) &body, &unsync_size);
get_id3v24_tags (body, unsync_size, info, metadata, filedata);
g_free (body);
} else {
@@ -1596,25 +1621,25 @@ parse_id3v24 (const gchar *data,
static void
parse_id3v23 (const gchar *data,
size_t size,
- id3tag *info,
+ tag_info *info,
GHashTable *metadata,
file_data *filedata,
size_t *offset_delta)
{
- gint unsync;
- gint extendedHdr;
- gint experimental;
- guint tsize;
- guint pos;
- guint ehdrSize;
- guint padding;
-
- if ((size < 16) ||
- (data[0] != 0x49) ||
- (data[1] != 0x44) ||
- (data[2] != 0x33) ||
- (data[3] != 0x03) ||
- (data[4] != 0x00)) {
+ gint unsync;
+ gint extendedHdr;
+ gint experimental;
+ guint tsize;
+ guint pos;
+ guint ehdrSize;
+ guint padding;
+
+ if (size < 16 ||
+ data[0] != 0x49 ||
+ data[1] != 0x44 ||
+ data[2] != 0x33 ||
+ data[3] != 0x03 ||
+ data[4] != 0x00) {
return;
}
@@ -1626,7 +1651,7 @@ parse_id3v23 (const gchar *data,
((data[8] & 0x7F) << 7) |
((data[9] & 0x7F) << 0));
- if ((tsize + 10 > size) || (experimental)) {
+ if (tsize + 10 > size || experimental) {
return;
}
@@ -1646,18 +1671,18 @@ parse_id3v23 (const gchar *data,
pos += 4 + ehdrSize;
- if (padding < tsize)
+ if (padding < tsize) {
tsize -= padding;
- else {
+ } else {
return;
}
}
if (unsync) {
- size_t unsync_size;
- gchar *body;
+ size_t unsync_size;
+ gchar *body;
- un_unsync (&data[pos], tsize, (unsigned char **)&body, &unsync_size);
+ un_unsync (&data[pos], tsize, (unsigned char **) &body, &unsync_size);
get_id3v23_tags (body, unsync_size, info, metadata, filedata);
g_free (body);
} else {
@@ -1670,21 +1695,21 @@ parse_id3v23 (const gchar *data,
static void
parse_id3v20 (const gchar *data,
size_t size,
- id3tag *info,
+ tag_info *info,
GHashTable *metadata,
file_data *filedata,
size_t *offset_delta)
{
- gint unsync;
- guint tsize;
- guint pos;
-
- if ((size < 16) ||
- (data[0] != 0x49) ||
- (data[1] != 0x44) ||
- (data[2] != 0x33) ||
- (data[3] != 0x02) ||
- (data[4] != 0x00)) {
+ gint unsync;
+ guint tsize;
+ guint pos;
+
+ if (size < 16 ||
+ data[0] != 0x49 ||
+ data[1] != 0x44 ||
+ data[2] != 0x33 ||
+ data[3] != 0x02 ||
+ data[4] != 0x00) {
return;
}
@@ -1694,16 +1719,17 @@ parse_id3v20 (const gchar *data,
((data[8] & 0x7F) << 07) |
((data[9] & 0x7F) << 00));
- if (tsize + 10 > size) {
+ if (tsize + 10 > size) {
return;
}
+
pos = 10;
if (unsync) {
size_t unsync_size;
gchar *body;
- un_unsync (&data[pos], tsize, (unsigned char **)&body, &unsync_size);
+ un_unsync (&data[pos], tsize, (unsigned char **) &body, &unsync_size);
get_id3v20_tags (body, unsync_size, info, metadata, filedata);
g_free (body);
} else {
@@ -1716,18 +1742,33 @@ parse_id3v20 (const gchar *data,
static goffset
parse_id3v2 (const gchar *data,
size_t size,
- id3tag *info,
+ tag_info *info,
GHashTable *metadata,
file_data *filedata)
{
gboolean done = FALSE;
- size_t offset = 0;
+ size_t offset = 0;
do {
size_t offset_delta = 0;
- parse_id3v24 (data+offset, size-offset, info, metadata, filedata, &offset_delta);
- parse_id3v23 (data+offset, size-offset, info, metadata, filedata, &offset_delta);
- parse_id3v20 (data+offset, size-offset, info, metadata, filedata, &offset_delta);
+
+ parse_id3v24 (data + offset,
+ size - offset,
+ info,
+ metadata,
+ filedata,
+ &offset_delta);
+ parse_id3v23 (data + offset,
+ size - offset,
+ info,
+ metadata,
+ filedata,
+ &offset_delta);
+ parse_id3v20 (data + offset,
+ size - offset,
+ info, metadata,
+ filedata,
+ &offset_delta);
if (offset_delta == 0) {
done = TRUE;
@@ -1745,14 +1786,14 @@ static void
extract_mp3 (const gchar *filename,
GHashTable *metadata)
{
- int fd;
- void *buffer;
- void *id3v1_buffer;
- goffset size;
- goffset buffer_size;
- id3tag info;
- goffset audio_offset;
- file_data filedata;
+ int fd;
+ void *buffer;
+ void *id3v1_buffer;
+ goffset size;
+ goffset buffer_size;
+ tag_info info;
+ goffset audio_offset;
+ file_data filedata;
info.title = NULL;
info.artist = NULL;
@@ -1813,7 +1854,7 @@ extract_mp3 (const gchar *filename,
close (fd);
- if (buffer == NULL || buffer == (void*) - 1) {
+ if (buffer == NULL || buffer == (void*) -1) {
return;
}
@@ -1868,10 +1909,18 @@ extract_mp3 (const gchar *filename,
}
/* Get other embedded tags */
- audio_offset = parse_id3v2 (buffer, buffer_size, &info, metadata, &filedata);
+ audio_offset = parse_id3v2 (buffer,
+ buffer_size,
+ &info,
+ metadata,
+ &filedata);
/* Get mp3 stream info */
- mp3_parse (buffer, buffer_size, audio_offset, metadata, &filedata);
+ mp3_parse (buffer,
+ buffer_size,
+ audio_offset,
+ metadata,
+ &filedata);
g_free (info.title);
g_free (info.year);
@@ -1902,10 +1951,14 @@ extract_mp3 (const gchar *filename,
/* Check that we have the minimum data. FIXME We should not need to do this */
if (!g_hash_table_lookup (metadata, "Audio:Title")) {
- gchar *basename = g_filename_display_basename (filename);
- gchar **parts = g_strsplit (basename, ".", -1);
- gchar *title = g_strdup (parts[0]);
+ gchar *basename;
+ gchar **parts;
+ gchar *title;
+ basename = g_filename_display_basename (filename);
+ parts = g_strsplit (basename, ".", -1);
+ title = g_strdup (parts[0]);
+
g_strfreev (parts);
g_free (basename);
@@ -1921,7 +1974,6 @@ extract_mp3 (const gchar *filename,
#ifndef G_OS_WIN32
munmap (buffer, buffer_size);
#endif
-
}
TrackerExtractData *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]