Introduce Rockbox Utility to the manual as automated installation option. Only rather...
[Rockbox.git] / apps / metadata / vorbis.c
bloba93d271ad03bdce7a391ec3eb78f61fbbfa0f541
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Dave Chapman
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
22 #include <ctype.h>
23 #include <inttypes.h>
25 #include "system.h"
26 #include "id3.h"
27 #include "metadata_common.h"
28 #include "metadata_parsers.h"
29 #include "structec.h"
30 #include "logf.h"
32 /* Read the items in a Vorbis comment packet. Returns true the items were
33 * fully read, false otherwise.
35 bool read_vorbis_tags(int fd, struct mp3entry *id3,
36 long tag_remaining)
38 char *buf = id3->id3v2buf;
39 int32_t comment_count;
40 int32_t len;
41 int buf_remaining = sizeof(id3->id3v2buf) + sizeof(id3->id3v1buf);
42 int i;
44 if (ecread(fd, &len, 1, "l", IS_BIG_ENDIAN) < (long) sizeof(len))
46 return false;
49 if ((lseek(fd, len, SEEK_CUR) < 0)
50 || (ecread(fd, &comment_count, 1, "l", IS_BIG_ENDIAN)
51 < (long) sizeof(comment_count)))
53 return false;
56 tag_remaining -= len + sizeof(len) + sizeof(comment_count);
58 if (tag_remaining <= 0)
60 return true;
63 for (i = 0; i < comment_count; i++)
65 char name[TAG_NAME_LENGTH];
66 char value[TAG_VALUE_LENGTH];
67 int32_t read_len;
69 if (tag_remaining < 4)
71 break;
74 if (ecread(fd, &len, 1, "l", IS_BIG_ENDIAN) < (long) sizeof(len))
76 return false;
79 tag_remaining -= 4;
81 /* Quit if we've passed the end of the page */
82 if (tag_remaining < len)
84 break;
87 tag_remaining -= len;
88 read_len = read_string(fd, name, sizeof(name), '=', len);
90 if (read_len < 0)
92 return false;
95 len -= read_len;
97 if (read_string(fd, value, sizeof(value), -1, len) < 0)
99 return false;
102 len = parse_tag(name, value, id3, buf, buf_remaining,
103 TAGTYPE_VORBIS);
104 buf += len;
105 buf_remaining -= len;
108 /* Skip to the end of the block */
109 if (tag_remaining)
111 if (lseek(fd, tag_remaining, SEEK_CUR) < 0)
113 return false;
117 return true;