annotate Plugins/Input/aac/mp4ff/mp4meta.c @ 1637:5261e37b4d55 trunk

[svn] - fully working CoreAudio plugin, based on the OSS plugin and an incomplete xmms coreaudio plugin (fink)
author nenolod
date Thu, 07 Sep 2006 11:32:59 -0700
parents 705d4c089fce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1020
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
1 /*
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
4 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
8 ** (at your option) any later version.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
9 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
13 ** GNU General Public License for more details.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
14 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
17 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1020
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
18 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
20 ** forbidden.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
21 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
24 **
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
25 ** $Id: mp4meta.c,v 1.13 2004/01/11 15:52:18 menno Exp $
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
26 **/
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
27
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
28 #ifdef USE_TAGGING
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
29
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
30 #include <stdlib.h>
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
31 #include <stdio.h>
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
32 #include <string.h>
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
33 #include "mp4ffint.h"
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
34
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
35 int32_t mp4ff_tag_add_field(mp4ff_metadata_t *tags, const char *item, const char *value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
36 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
37 void *backup = (void *)tags->tags;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
38
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
39 if (!item || (item && !*item) || !value) return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
40
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
41 tags->tags = (mp4ff_tag_t*)realloc(tags->tags, (tags->count+1) * sizeof(mp4ff_tag_t));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
42 if (!tags->tags)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
43 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
44 if (backup) free(backup);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
45 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
46 } else {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
47 tags->tags[tags->count].item = strdup(item);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
48 tags->tags[tags->count].value = strdup(value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
49
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
50 if (!tags->tags[tags->count].item || !tags->tags[tags->count].value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
51 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
52 if (!tags->tags[tags->count].item) free (tags->tags[tags->count].item);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
53 if (!tags->tags[tags->count].value) free (tags->tags[tags->count].value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
54 tags->tags[tags->count].item = NULL;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
55 tags->tags[tags->count].value = NULL;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
56 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
57 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
58
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
59 tags->count++;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
60 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
61 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
62 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
63
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
64 int32_t mp4ff_tag_set_field(mp4ff_metadata_t *tags, const char *item, const char *value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
65 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
66 unsigned int i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
67
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
68 if (!item || (item && !*item) || !value) return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
69
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
70 for (i = 0; i < tags->count; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
71 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
72 if (!stricmp(tags->tags[i].item, item))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
73 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
74 free(tags->tags[i].value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
75 tags->tags[i].value = strdup(value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
76 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
77 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
78 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
79
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
80 return mp4ff_tag_add_field(tags, item, value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
81 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
82
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
83 int32_t mp4ff_tag_delete(mp4ff_metadata_t *tags)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
84 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
85 uint32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
86
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
87 for (i = 0; i < tags->count; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
88 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
89 if (tags->tags[i].item) free(tags->tags[i].item);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
90 if (tags->tags[i].value) free(tags->tags[i].value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
91 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
92
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
93 if (tags->tags) free(tags->tags);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
94
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
95 tags->tags = NULL;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
96 tags->count = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
97
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
98 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
99 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
100
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
101 const char* ID3v1GenreList[] = {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
102 "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
103 "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
104 "Other", "Pop", "R&B", "Rap", "Reggae", "Rock",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
105 "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
106 "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
107 "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
108 "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
109 "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
110 "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
111 "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
112 "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
113 "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
114 "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
115 "Rock & Roll", "Hard Rock", "Folk", "Folk/Rock", "National Folk", "Swing",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
116 "Fast-Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
117 "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
118 "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
119 "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
120 "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
121 "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
122 "Punk Rock", "Drum Solo", "A capella", "Euro-House", "Dance Hall",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
123 "Goa", "Drum & Bass", "Club House", "Hardcore", "Terror",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
124 "Indie", "BritPop", "NegerPunk", "Polsk Punk", "Beat",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
125 "Christian Gangsta", "Heavy Metal", "Black Metal", "Crossover", "Contemporary C",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
126 "Christian Rock", "Merengue", "Salsa", "Thrash Metal", "Anime", "JPop",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
127 "SynthPop",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
128 };
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
129
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
130 uint32_t mp4ff_meta_genre_to_index(const char * genrestr)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
131 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
132 unsigned n;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
133 for(n=0;n<sizeof(ID3v1GenreList)/sizeof(ID3v1GenreList[0]);n++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
134 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
135 if (!stricmp(genrestr,ID3v1GenreList[n])) return n+1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
136 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
137 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
138 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
139
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
140 const char * mp4ff_meta_index_to_genre(uint32_t idx)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
141 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
142 if (idx>0 && idx<=sizeof(ID3v1GenreList)/sizeof(ID3v1GenreList[0]))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
143 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
144 return ID3v1GenreList[idx-1];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
145 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
146 else
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
147 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
148 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
149 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
150 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
151
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
152
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
153 int32_t TrackToString(char** str, const uint16_t track, const uint16_t totalTracks)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
154 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
155 char temp[32];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
156 sprintf(temp, "%.5u of %.5u", track, totalTracks);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
157 *str = strdup(temp);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
158 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
159 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
160
1129
c59fe7000c95 [svn] Fully respect pointer signedness in libmp4ff.
chainsaw
parents: 1020
diff changeset
161 int32_t mp4ff_set_metadata_name(mp4ff_t *f, const uint8_t atom_type, unsigned char **name)
1020
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
162 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
163 char *tag_names[] = {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
164 "unknown", "title", "artist", "writer", "album",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
165 "date", "tool", "comment", "genre", "track",
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
166 "disc", "compilation", "genre", "tempo", "cover"
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
167 };
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
168 uint8_t tag_idx = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
169
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
170 switch (atom_type)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
171 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
172 case ATOM_TITLE: tag_idx = 1; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
173 case ATOM_ARTIST: tag_idx = 2; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
174 case ATOM_WRITER: tag_idx = 3; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
175 case ATOM_ALBUM: tag_idx = 4; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
176 case ATOM_DATE: tag_idx = 5; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
177 case ATOM_TOOL: tag_idx = 6; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
178 case ATOM_COMMENT: tag_idx = 7; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
179 case ATOM_GENRE1: tag_idx = 8; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
180 case ATOM_TRACK: tag_idx = 9; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
181 case ATOM_DISC: tag_idx = 10; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
182 case ATOM_COMPILATION: tag_idx = 11; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
183 case ATOM_GENRE2: tag_idx = 12; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
184 case ATOM_TEMPO: tag_idx = 13; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
185 case ATOM_COVER: tag_idx = 14; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
186 default: tag_idx = 0; break;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
187 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
188
1129
c59fe7000c95 [svn] Fully respect pointer signedness in libmp4ff.
chainsaw
parents: 1020
diff changeset
189 *name = (unsigned char*)strdup(tag_names[tag_idx]);
1020
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
190
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
191 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
192 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
193
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
194 int32_t mp4ff_parse_tag(mp4ff_t *f, const uint8_t parent_atom_type, const int32_t size)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
195 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
196 uint8_t atom_type;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
197 uint8_t header_size = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
198 uint64_t subsize, sumsize = 0;
1129
c59fe7000c95 [svn] Fully respect pointer signedness in libmp4ff.
chainsaw
parents: 1020
diff changeset
199 unsigned char * name = NULL;
c59fe7000c95 [svn] Fully respect pointer signedness in libmp4ff.
chainsaw
parents: 1020
diff changeset
200 unsigned char * data = NULL;
c59fe7000c95 [svn] Fully respect pointer signedness in libmp4ff.
chainsaw
parents: 1020
diff changeset
201 uint32_t done = 0;
1020
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
202
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
203 while (sumsize < size)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
204 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
205 uint64_t destpos;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
206 subsize = mp4ff_atom_read_header(f, &atom_type, &header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
207 destpos = mp4ff_position(f)+subsize-header_size;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
208 if (!done)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
209 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
210 if (atom_type == ATOM_DATA)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
211 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
212 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
213 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
214 mp4ff_read_int32(f); /* reserved */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
215
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
216 /* some need special attention */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
217 if (parent_atom_type == ATOM_GENRE2 || parent_atom_type == ATOM_TEMPO)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
218 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
219 if (subsize - header_size >= 8 + 2)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
220 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
221 uint16_t val = mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
222
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
223 if (parent_atom_type == ATOM_TEMPO)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
224 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
225 char temp[16];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
226 sprintf(temp, "%.5u BPM", val);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
227 mp4ff_tag_add_field(&(f->tags), "tempo", temp);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
228 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
229 else
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
230 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
231 const char * temp = mp4ff_meta_index_to_genre(val);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
232 if (temp)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
233 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
234 mp4ff_tag_add_field(&(f->tags), "genre", temp);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
235 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
236 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
237 done = 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
238 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
239 } else if (parent_atom_type == ATOM_TRACK || parent_atom_type == ATOM_DISC) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
240 if (!done && subsize - header_size >= 8 + 8)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
241 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
242 uint16_t index,total;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
243 char temp[32];
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
244 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
245 index = mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
246 total = mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
247 mp4ff_read_int16(f);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
248
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
249 sprintf(temp,"%d",index);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
250 mp4ff_tag_add_field(&(f->tags), parent_atom_type == ATOM_TRACK ? "track" : "disc", temp);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
251 if (total>0)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
252 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
253 sprintf(temp,"%d",total);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
254 mp4ff_tag_add_field(&(f->tags), parent_atom_type == ATOM_TRACK ? "totaltracks" : "totaldiscs", temp);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
255 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
256 done = 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
257 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
258 } else
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
259 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
260 if (data) {free(data);data = NULL;}
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
261 data = mp4ff_read_string(f,(uint32_t)(subsize-(header_size+8)));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
262 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
263 } else if (atom_type == ATOM_NAME) {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
264 if (!done)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
265 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
266 mp4ff_read_char(f); /* version */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
267 mp4ff_read_int24(f); /* flags */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
268 if (name) free(name);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
269 name = mp4ff_read_string(f,(uint32_t)(subsize-(header_size+4)));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
270 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
271 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
272 mp4ff_set_position(f, destpos);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
273 sumsize += subsize;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
274 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
275 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
276
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
277 if (data)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
278 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
279 if (!done)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
280 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
281 if (name == NULL) mp4ff_set_metadata_name(f, parent_atom_type, &name);
1129
c59fe7000c95 [svn] Fully respect pointer signedness in libmp4ff.
chainsaw
parents: 1020
diff changeset
282 if (name) mp4ff_tag_add_field(&(f->tags), (char*)name, (char*)data);
1020
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
283 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
284
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
285 free(data);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
286 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
287 if (name) free(name);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
288 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
289 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
290
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
291 int32_t mp4ff_parse_metadata(mp4ff_t *f, const int32_t size)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
292 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
293 uint64_t subsize, sumsize = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
294 uint8_t atom_type;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
295 uint8_t header_size = 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
296
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
297 while (sumsize < size)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
298 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
299 subsize = mp4ff_atom_read_header(f, &atom_type, &header_size);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
300 mp4ff_parse_tag(f, atom_type, (uint32_t)(subsize-header_size));
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
301 sumsize += subsize;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
302 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
303
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
304 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
305 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
306
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
307 /* find a metadata item by name */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
308 /* returns 0 if item found, 1 if no such item */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
309 int32_t mp4ff_meta_find_by_name(const mp4ff_t *f, const char *item, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
310 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
311 uint32_t i;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
312
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
313 for (i = 0; i < f->tags.count; i++)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
314 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
315 if (!stricmp(f->tags.tags[i].item, item))
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
316 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
317 *value = strdup(f->tags.tags[i].value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
318 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
319 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
320 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
321
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
322 *value = NULL;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
323
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
324 /* not found */
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
325 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
326 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
327
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
328 int32_t mp4ff_meta_get_num_items(const mp4ff_t *f)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
329 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
330 return f->tags.count;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
331 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
332
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
333 int32_t mp4ff_meta_get_by_index(const mp4ff_t *f, uint32_t index,
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
334 char **item, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
335 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
336 if (index >= f->tags.count)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
337 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
338 *item = NULL;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
339 *value = NULL;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
340 return 0;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
341 } else {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
342 *item = strdup(f->tags.tags[index].item);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
343 *value = strdup(f->tags.tags[index].value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
344 return 1;
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
345 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
346 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
347
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
348 int32_t mp4ff_meta_get_title(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
349 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
350 return mp4ff_meta_find_by_name(f, "title", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
351 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
352
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
353 int32_t mp4ff_meta_get_artist(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
354 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
355 return mp4ff_meta_find_by_name(f, "artist", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
356 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
357
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
358 int32_t mp4ff_meta_get_writer(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
359 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
360 return mp4ff_meta_find_by_name(f, "writer", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
361 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
362
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
363 int32_t mp4ff_meta_get_album(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
364 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
365 return mp4ff_meta_find_by_name(f, "album", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
366 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
367
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
368 int32_t mp4ff_meta_get_date(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
369 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
370 return mp4ff_meta_find_by_name(f, "date", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
371 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
372
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
373 int32_t mp4ff_meta_get_tool(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
374 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
375 return mp4ff_meta_find_by_name(f, "tool", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
376 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
377
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
378 int32_t mp4ff_meta_get_comment(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
379 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
380 return mp4ff_meta_find_by_name(f, "comment", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
381 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
382
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
383 int32_t mp4ff_meta_get_genre(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
384 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
385 return mp4ff_meta_find_by_name(f, "genre", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
386 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
387
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
388 int32_t mp4ff_meta_get_track(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
389 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
390 return mp4ff_meta_find_by_name(f, "track", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
391 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
392
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
393 int32_t mp4ff_meta_get_disc(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
394 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
395 return mp4ff_meta_find_by_name(f, "disc", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
396 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
397
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
398 int32_t mp4ff_meta_get_compilation(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
399 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
400 return mp4ff_meta_find_by_name(f, "compilation", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
401 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
402
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
403 int32_t mp4ff_meta_get_tempo(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
404 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
405 return mp4ff_meta_find_by_name(f, "tempo", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
406 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
407
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
408 int32_t mp4ff_meta_get_coverart(const mp4ff_t *f, char **value)
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
409 {
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
410 return mp4ff_meta_find_by_name(f, "cover", value);
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
411 }
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
412
d70514b3b436 [svn] - stuff
nenolod
parents:
diff changeset
413 #endif