annotate src/flac/libflac/metadata_object.c @ 906:16e51fb5908e trunk

[svn] - aosd: beta4, ghosd source was rewritten to support argb visual (x composite extension) as an option, this allows to have real transparency in the OSD
author giacomo
date Sat, 31 Mar 2007 17:44:23 -0700
parents 454ad11020ec
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
715
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1 /* libFLAC - Free Lossless Audio Codec library
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
2 * Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Josh Coalson
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
3 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
4 * Redistribution and use in source and binary forms, with or without
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
5 * modification, are permitted provided that the following conditions
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
6 * are met:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
7 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
8 * - Redistributions of source code must retain the above copyright
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
10 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
11 * - Redistributions in binary form must reproduce the above copyright
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
12 * notice, this list of conditions and the following disclaimer in the
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
13 * documentation and/or other materials provided with the distribution.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
14 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
15 * - Neither the name of the Xiph.org Foundation nor the names of its
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
16 * contributors may be used to endorse or promote products derived from
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
17 * this software without specific prior written permission.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
18 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
30 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
31
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
32 #if HAVE_CONFIG_H
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
33 # include <config.h>
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
34 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
35
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
36 #include <stdlib.h>
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
37 #include <string.h>
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
38
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
39 #include "private/metadata.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
40
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
41 #include "FLAC/assert.h"
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
42
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
43
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
44 /****************************************************************************
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
45 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
46 * Local routines
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
47 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
48 ***************************************************************************/
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
49
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
50 /* copy bytes:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
51 * from = NULL && bytes = 0
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
52 * to <- NULL
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
53 * from != NULL && bytes > 0
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
54 * to <- copy of from
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
55 * else ASSERT
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
56 * malloc error leaved 'to' unchanged
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
57 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
58 static FLAC__bool copy_bytes_(FLAC__byte **to, const FLAC__byte *from, unsigned bytes)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
59 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
60 FLAC__ASSERT(0 != to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
61 if(bytes > 0 && 0 != from) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
62 FLAC__byte *x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
63 if(0 == (x = (FLAC__byte*)malloc(bytes)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
64 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
65 memcpy(x, from, bytes);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
66 *to = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
67 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
68 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
69 FLAC__ASSERT(0 == from);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
70 FLAC__ASSERT(bytes == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
71 *to = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
72 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
73 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
74 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
75
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
76 #if 0 /* UNUSED */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
77 /* like copy_bytes_(), but free()s the original '*to' if the copy succeeds and the original '*to' is non-NULL */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
78 static FLAC__bool free_copy_bytes_(FLAC__byte **to, const FLAC__byte *from, unsigned bytes)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
79 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
80 FLAC__byte *copy;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
81 FLAC__ASSERT(0 != to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
82 if(copy_bytes_(&copy, from, bytes)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
83 if(*to)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
84 free(*to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
85 *to = copy;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
86 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
87 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
88 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
89 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
90 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
91 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
92
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
93 /* reallocate entry to 1 byte larger and add a terminating NUL */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
94 /* realloc() failure leaves entry unchanged */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
95 static FLAC__bool ensure_null_terminated_(FLAC__byte **entry, unsigned length)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
96 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
97 FLAC__byte *x = (FLAC__byte*)realloc(*entry, length+1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
98 if(0 != x) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
99 x[length] = '\0';
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
100 *entry = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
101 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
102 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
103 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
104 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
105 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
106
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
107 /* copies the NUL-terminated C-string 'from' to '*to', leaving '*to'
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
108 * unchanged if malloc fails, free()ing the original '*to' if it
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
109 * succeeds and the original '*to' was not NULL
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
110 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
111 static FLAC__bool copy_cstring_(char **to, const char *from)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
112 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
113 char *copy = strdup(from);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
114 FLAC__ASSERT(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
115 if(copy) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
116 if(*to)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
117 free(*to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
118 *to = copy;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
119 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
120 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
121 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
122 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
123 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
124
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
125 static FLAC__bool copy_vcentry_(FLAC__StreamMetadata_VorbisComment_Entry *to, const FLAC__StreamMetadata_VorbisComment_Entry *from)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
126 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
127 to->length = from->length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
128 if(0 == from->entry) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
129 FLAC__ASSERT(from->length == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
130 to->entry = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
131 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
132 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
133 FLAC__byte *x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
134 FLAC__ASSERT(from->length > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
135 if(0 == (x = (FLAC__byte*)malloc(from->length+1)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
136 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
137 memcpy(x, from->entry, from->length);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
138 x[from->length] = '\0';
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
139 to->entry = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
140 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
141 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
142 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
143
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
144 static FLAC__bool copy_track_(FLAC__StreamMetadata_CueSheet_Track *to, const FLAC__StreamMetadata_CueSheet_Track *from)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
145 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
146 memcpy(to, from, sizeof(FLAC__StreamMetadata_CueSheet_Track));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
147 if(0 == from->indices) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
148 FLAC__ASSERT(from->num_indices == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
149 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
150 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
151 FLAC__StreamMetadata_CueSheet_Index *x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
152 FLAC__ASSERT(from->num_indices > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
153 if(0 == (x = (FLAC__StreamMetadata_CueSheet_Index*)malloc(from->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index))))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
154 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
155 memcpy(x, from->indices, from->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
156 to->indices = x;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
157 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
158 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
159 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
160
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
161 static void seektable_calculate_length_(FLAC__StreamMetadata *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
162 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
163 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
164 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
165
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
166 object->length = object->data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
167 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
168
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
169 static FLAC__StreamMetadata_SeekPoint *seekpoint_array_new_(unsigned num_points)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
170 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
171 FLAC__StreamMetadata_SeekPoint *object_array;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
172
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
173 FLAC__ASSERT(num_points > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
174
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
175 object_array = (FLAC__StreamMetadata_SeekPoint*)malloc(num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
176
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
177 if(0 != object_array) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
178 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
179 for(i = 0; i < num_points; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
180 object_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
181 object_array[i].stream_offset = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
182 object_array[i].frame_samples = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
183 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
184 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
185
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
186 return object_array;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
187 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
188
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
189 static void vorbiscomment_calculate_length_(FLAC__StreamMetadata *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
190 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
191 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
192
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
193 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
194
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
195 object->length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
196 object->length += object->data.vorbis_comment.vendor_string.length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
197 object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
198 for(i = 0; i < object->data.vorbis_comment.num_comments; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
199 object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
200 object->length += object->data.vorbis_comment.comments[i].length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
201 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
202 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
203
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
204 static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_new_(unsigned num_comments)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
205 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
206 FLAC__ASSERT(num_comments > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
207
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
208 return (FLAC__StreamMetadata_VorbisComment_Entry*)calloc(num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
209 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
210
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
211 static void vorbiscomment_entry_array_delete_(FLAC__StreamMetadata_VorbisComment_Entry *object_array, unsigned num_comments)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
212 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
213 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
214
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
215 FLAC__ASSERT(0 != object_array && num_comments > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
216
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
217 for(i = 0; i < num_comments; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
218 if(0 != object_array[i].entry)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
219 free(object_array[i].entry);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
220
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
221 if(0 != object_array)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
222 free(object_array);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
223 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
224
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
225 static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_copy_(const FLAC__StreamMetadata_VorbisComment_Entry *object_array, unsigned num_comments)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
226 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
227 FLAC__StreamMetadata_VorbisComment_Entry *return_array;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
228
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
229 FLAC__ASSERT(0 != object_array);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
230 FLAC__ASSERT(num_comments > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
231
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
232 return_array = vorbiscomment_entry_array_new_(num_comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
233
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
234 if(0 != return_array) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
235 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
236
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
237 for(i = 0; i < num_comments; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
238 if(!copy_vcentry_(return_array+i, object_array+i)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
239 vorbiscomment_entry_array_delete_(return_array, num_comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
240 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
241 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
242 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
243 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
244
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
245 return return_array;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
246 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
247
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
248 static FLAC__bool vorbiscomment_set_entry_(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry *dest, const FLAC__StreamMetadata_VorbisComment_Entry *src, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
249 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
250 FLAC__byte *save;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
251
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
252 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
253 FLAC__ASSERT(0 != dest);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
254 FLAC__ASSERT(0 != src);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
255 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
256 FLAC__ASSERT((0 != src->entry && src->length > 0) || (0 == src->entry && src->length == 0));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
257
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
258 save = dest->entry;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
259
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
260 if(0 != src->entry && src->length > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
261 if(copy) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
262 /* do the copy first so that if we fail we leave the dest object untouched */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
263 if(!copy_vcentry_(dest, src))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
264 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
265 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
266 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
267 /* we have to make sure that the string we're taking over is null-terminated */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
268
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
269 /*
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
270 * Stripping the const from src->entry is OK since we're taking
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
271 * ownership of the pointer. This is a hack around a deficiency
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
272 * in the API where the same function is used for 'copy' and
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
273 * 'own', but the source entry is a const pointer. If we were
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
274 * precise, the 'own' flavor would be a separate function with a
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
275 * non-const source pointer. But it's not, so we hack away.
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
276 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
277 if(!ensure_null_terminated_((FLAC__byte**)(&src->entry), src->length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
278 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
279 *dest = *src;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
280 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
281 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
282 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
283 /* the src is null */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
284 *dest = *src;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
285 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
286
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
287 if(0 != save)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
288 free(save);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
289
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
290 vorbiscomment_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
291 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
292 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
293
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
294 static int vorbiscomment_find_entry_from_(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name, unsigned field_name_length)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
295 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
296 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
297
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
298 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
299 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
300 FLAC__ASSERT(0 != field_name);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
301
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
302 for(i = offset; i < object->data.vorbis_comment.num_comments; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
303 if(FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
304 return (int)i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
305 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
306
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
307 return -1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
308 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
309
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
310 static void cuesheet_calculate_length_(FLAC__StreamMetadata *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
311 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
312 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
313
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
314 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
315
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
316 object->length = (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
317 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
318 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
319 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
320 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
321 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
322 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
323
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
324 object->length += object->data.cue_sheet.num_tracks * (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
325 FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
326 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
327 FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
328 FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
329 FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
330 FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
331 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
332 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
333
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
334 for(i = 0; i < object->data.cue_sheet.num_tracks; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
335 object->length += object->data.cue_sheet.tracks[i].num_indices * (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
336 FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
337 FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
338 FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
339 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
340 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
341 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
342
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
343 static FLAC__StreamMetadata_CueSheet_Index *cuesheet_track_index_array_new_(unsigned num_indices)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
344 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
345 FLAC__ASSERT(num_indices > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
346
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
347 return (FLAC__StreamMetadata_CueSheet_Index*)calloc(num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
348 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
349
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
350 static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_new_(unsigned num_tracks)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
351 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
352 FLAC__ASSERT(num_tracks > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
353
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
354 return (FLAC__StreamMetadata_CueSheet_Track*)calloc(num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
355 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
356
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
357 static void cuesheet_track_array_delete_(FLAC__StreamMetadata_CueSheet_Track *object_array, unsigned num_tracks)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
358 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
359 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
360
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
361 FLAC__ASSERT(0 != object_array && num_tracks > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
362
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
363 for(i = 0; i < num_tracks; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
364 if(0 != object_array[i].indices) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
365 FLAC__ASSERT(object_array[i].num_indices > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
366 free(object_array[i].indices);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
367 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
368 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
369
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
370 if(0 != object_array)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
371 free(object_array);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
372 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
373
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
374 static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_copy_(const FLAC__StreamMetadata_CueSheet_Track *object_array, unsigned num_tracks)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
375 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
376 FLAC__StreamMetadata_CueSheet_Track *return_array;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
377
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
378 FLAC__ASSERT(0 != object_array);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
379 FLAC__ASSERT(num_tracks > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
380
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
381 return_array = cuesheet_track_array_new_(num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
382
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
383 if(0 != return_array) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
384 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
385
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
386 for(i = 0; i < num_tracks; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
387 if(!copy_track_(return_array+i, object_array+i)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
388 cuesheet_track_array_delete_(return_array, num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
389 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
390 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
391 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
392 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
393
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
394 return return_array;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
395 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
396
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
397 static FLAC__bool cuesheet_set_track_(FLAC__StreamMetadata *object, FLAC__StreamMetadata_CueSheet_Track *dest, const FLAC__StreamMetadata_CueSheet_Track *src, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
398 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
399 FLAC__StreamMetadata_CueSheet_Index *save;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
400
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
401 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
402 FLAC__ASSERT(0 != dest);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
403 FLAC__ASSERT(0 != src);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
404 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
405 FLAC__ASSERT((0 != src->indices && src->num_indices > 0) || (0 == src->indices && src->num_indices == 0));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
406
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
407 save = dest->indices;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
408
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
409 /* do the copy first so that if we fail we leave the object untouched */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
410 if(copy) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
411 if(!copy_track_(dest, src))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
412 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
413 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
414 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
415 *dest = *src;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
416 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
417
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
418 if(0 != save)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
419 free(save);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
420
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
421 cuesheet_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
422 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
423 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
424
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
425
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
426 /****************************************************************************
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
427 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
428 * Metadata object routines
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
429 *
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
430 ***************************************************************************/
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
431
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
432 FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
433 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
434 FLAC__StreamMetadata *object;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
435
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
436 if(type > FLAC__MAX_METADATA_TYPE_CODE)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
437 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
438
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
439 object = (FLAC__StreamMetadata*)calloc(1, sizeof(FLAC__StreamMetadata));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
440 if(0 != object) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
441 object->is_last = false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
442 object->type = type;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
443 switch(type) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
444 case FLAC__METADATA_TYPE_STREAMINFO:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
445 object->length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
446 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
447 case FLAC__METADATA_TYPE_PADDING:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
448 /* calloc() took care of this for us:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
449 object->length = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
450 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
451 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
452 case FLAC__METADATA_TYPE_APPLICATION:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
453 object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
454 /* calloc() took care of this for us:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
455 object->data.application.data = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
456 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
457 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
458 case FLAC__METADATA_TYPE_SEEKTABLE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
459 /* calloc() took care of this for us:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
460 object->length = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
461 object->data.seek_table.num_points = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
462 object->data.seek_table.points = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
463 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
464 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
465 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
466 object->data.vorbis_comment.vendor_string.length = (unsigned)strlen(FLAC__VENDOR_STRING);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
467 if(!copy_bytes_(&object->data.vorbis_comment.vendor_string.entry, (const FLAC__byte*)FLAC__VENDOR_STRING, object->data.vorbis_comment.vendor_string.length+1)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
468 free(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
469 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
470 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
471 vorbiscomment_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
472 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
473 case FLAC__METADATA_TYPE_CUESHEET:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
474 cuesheet_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
475 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
476 case FLAC__METADATA_TYPE_PICTURE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
477 object->length = (
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
478 FLAC__STREAM_METADATA_PICTURE_TYPE_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
479 FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN + /* empty mime_type string */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
480 FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN + /* empty description string */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
481 FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
482 FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
483 FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
484 FLAC__STREAM_METADATA_PICTURE_COLORS_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
485 FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN +
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
486 0 /* no data */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
487 ) / 8;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
488 object->data.picture.type = FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
489 object->data.picture.mime_type = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
490 object->data.picture.description = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
491 /* calloc() took care of this for us:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
492 object->data.picture.width = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
493 object->data.picture.height = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
494 object->data.picture.depth = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
495 object->data.picture.colors = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
496 object->data.picture.data_length = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
497 object->data.picture.data = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
498 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
499 /* now initialize mime_type and description with empty strings to make things easier on the client */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
500 if(!copy_cstring_(&object->data.picture.mime_type, "")) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
501 free(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
502 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
503 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
504 if(!copy_cstring_((char**)(&object->data.picture.description), "")) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
505 if(object->data.picture.mime_type)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
506 free(object->data.picture.mime_type);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
507 free(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
508 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
509 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
510 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
511 default:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
512 /* calloc() took care of this for us:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
513 object->length = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
514 object->data.unknown.data = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
515 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
516 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
517 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
518 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
519
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
520 return object;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
521 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
522
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
523 FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
524 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
525 FLAC__StreamMetadata *to;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
526
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
527 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
528
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
529 if(0 != (to = FLAC__metadata_object_new(object->type))) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
530 to->is_last = object->is_last;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
531 to->type = object->type;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
532 to->length = object->length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
533 switch(to->type) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
534 case FLAC__METADATA_TYPE_STREAMINFO:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
535 memcpy(&to->data.stream_info, &object->data.stream_info, sizeof(FLAC__StreamMetadata_StreamInfo));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
536 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
537 case FLAC__METADATA_TYPE_PADDING:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
538 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
539 case FLAC__METADATA_TYPE_APPLICATION:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
540 memcpy(&to->data.application.id, &object->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
541 if(!copy_bytes_(&to->data.application.data, object->data.application.data, object->length - FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
542 FLAC__metadata_object_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
543 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
544 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
545 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
546 case FLAC__METADATA_TYPE_SEEKTABLE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
547 to->data.seek_table.num_points = object->data.seek_table.num_points;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
548 if(!copy_bytes_((FLAC__byte**)&to->data.seek_table.points, (FLAC__byte*)object->data.seek_table.points, object->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint))) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
549 FLAC__metadata_object_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
550 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
551 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
552 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
553 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
554 if(0 != to->data.vorbis_comment.vendor_string.entry) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
555 free(to->data.vorbis_comment.vendor_string.entry);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
556 to->data.vorbis_comment.vendor_string.entry = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
557 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
558 if(!copy_vcentry_(&to->data.vorbis_comment.vendor_string, &object->data.vorbis_comment.vendor_string)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
559 FLAC__metadata_object_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
560 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
561 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
562 if(object->data.vorbis_comment.num_comments == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
563 FLAC__ASSERT(0 == object->data.vorbis_comment.comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
564 to->data.vorbis_comment.comments = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
565 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
566 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
567 FLAC__ASSERT(0 != object->data.vorbis_comment.comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
568 to->data.vorbis_comment.comments = vorbiscomment_entry_array_copy_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
569 if(0 == to->data.vorbis_comment.comments) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
570 FLAC__metadata_object_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
571 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
572 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
573 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
574 to->data.vorbis_comment.num_comments = object->data.vorbis_comment.num_comments;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
575 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
576 case FLAC__METADATA_TYPE_CUESHEET:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
577 memcpy(&to->data.cue_sheet, &object->data.cue_sheet, sizeof(FLAC__StreamMetadata_CueSheet));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
578 if(object->data.cue_sheet.num_tracks == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
579 FLAC__ASSERT(0 == object->data.cue_sheet.tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
580 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
581 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
582 FLAC__ASSERT(0 != object->data.cue_sheet.tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
583 to->data.cue_sheet.tracks = cuesheet_track_array_copy_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
584 if(0 == to->data.cue_sheet.tracks) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
585 FLAC__metadata_object_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
586 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
587 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
588 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
589 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
590 case FLAC__METADATA_TYPE_PICTURE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
591 to->data.picture.type = object->data.picture.type;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
592 if(!copy_cstring_(&to->data.picture.mime_type, object->data.picture.mime_type)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
593 FLAC__metadata_object_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
594 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
595 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
596 if(!copy_cstring_((char**)(&to->data.picture.description), (const char*)object->data.picture.description)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
597 FLAC__metadata_object_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
598 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
599 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
600 to->data.picture.width = object->data.picture.width;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
601 to->data.picture.height = object->data.picture.height;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
602 to->data.picture.depth = object->data.picture.depth;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
603 to->data.picture.colors = object->data.picture.colors;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
604 to->data.picture.data_length = object->data.picture.data_length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
605 if(!copy_bytes_((&to->data.picture.data), object->data.picture.data, object->data.picture.data_length)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
606 FLAC__metadata_object_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
607 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
608 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
609 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
610 default:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
611 if(!copy_bytes_(&to->data.unknown.data, object->data.unknown.data, object->length)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
612 FLAC__metadata_object_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
613 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
614 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
615 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
616 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
617 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
618
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
619 return to;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
620 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
621
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
622 void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
623 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
624 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
625
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
626 switch(object->type) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
627 case FLAC__METADATA_TYPE_STREAMINFO:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
628 case FLAC__METADATA_TYPE_PADDING:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
629 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
630 case FLAC__METADATA_TYPE_APPLICATION:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
631 if(0 != object->data.application.data) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
632 free(object->data.application.data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
633 object->data.application.data = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
634 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
635 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
636 case FLAC__METADATA_TYPE_SEEKTABLE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
637 if(0 != object->data.seek_table.points) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
638 free(object->data.seek_table.points);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
639 object->data.seek_table.points = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
640 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
641 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
642 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
643 if(0 != object->data.vorbis_comment.vendor_string.entry) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
644 free(object->data.vorbis_comment.vendor_string.entry);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
645 object->data.vorbis_comment.vendor_string.entry = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
646 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
647 if(0 != object->data.vorbis_comment.comments) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
648 FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
649 vorbiscomment_entry_array_delete_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
650 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
651 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
652 case FLAC__METADATA_TYPE_CUESHEET:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
653 if(0 != object->data.cue_sheet.tracks) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
654 FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
655 cuesheet_track_array_delete_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
656 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
657 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
658 case FLAC__METADATA_TYPE_PICTURE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
659 if(0 != object->data.picture.mime_type) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
660 free(object->data.picture.mime_type);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
661 object->data.picture.mime_type = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
662 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
663 if(0 != object->data.picture.description) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
664 free(object->data.picture.description);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
665 object->data.picture.description = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
666 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
667 if(0 != object->data.picture.data) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
668 free(object->data.picture.data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
669 object->data.picture.data = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
670 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
671 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
672 default:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
673 if(0 != object->data.unknown.data) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
674 free(object->data.unknown.data);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
675 object->data.unknown.data = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
676 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
677 break;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
678 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
679 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
680
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
681 FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
682 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
683 FLAC__metadata_object_delete_data(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
684 free(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
685 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
686
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
687 static FLAC__bool compare_block_data_streaminfo_(const FLAC__StreamMetadata_StreamInfo *block1, const FLAC__StreamMetadata_StreamInfo *block2)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
688 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
689 if(block1->min_blocksize != block2->min_blocksize)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
690 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
691 if(block1->max_blocksize != block2->max_blocksize)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
692 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
693 if(block1->min_framesize != block2->min_framesize)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
694 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
695 if(block1->max_framesize != block2->max_framesize)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
696 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
697 if(block1->sample_rate != block2->sample_rate)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
698 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
699 if(block1->channels != block2->channels)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
700 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
701 if(block1->bits_per_sample != block2->bits_per_sample)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
702 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
703 if(block1->total_samples != block2->total_samples)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
704 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
705 if(0 != memcmp(block1->md5sum, block2->md5sum, 16))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
706 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
707 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
708 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
709
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
710 static FLAC__bool compare_block_data_application_(const FLAC__StreamMetadata_Application *block1, const FLAC__StreamMetadata_Application *block2, unsigned block_length)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
711 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
712 FLAC__ASSERT(0 != block1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
713 FLAC__ASSERT(0 != block2);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
714 FLAC__ASSERT(block_length >= sizeof(block1->id));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
715
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
716 if(0 != memcmp(block1->id, block2->id, sizeof(block1->id)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
717 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
718 if(0 != block1->data && 0 != block2->data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
719 return 0 == memcmp(block1->data, block2->data, block_length - sizeof(block1->id));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
720 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
721 return block1->data == block2->data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
722 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
723
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
724 static FLAC__bool compare_block_data_seektable_(const FLAC__StreamMetadata_SeekTable *block1, const FLAC__StreamMetadata_SeekTable *block2)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
725 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
726 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
727
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
728 FLAC__ASSERT(0 != block1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
729 FLAC__ASSERT(0 != block2);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
730
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
731 if(block1->num_points != block2->num_points)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
732 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
733
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
734 if(0 != block1->points && 0 != block2->points) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
735 for(i = 0; i < block1->num_points; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
736 if(block1->points[i].sample_number != block2->points[i].sample_number)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
737 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
738 if(block1->points[i].stream_offset != block2->points[i].stream_offset)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
739 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
740 if(block1->points[i].frame_samples != block2->points[i].frame_samples)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
741 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
742 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
743 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
744 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
745 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
746 return block1->points == block2->points;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
747 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
748
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
749 static FLAC__bool compare_block_data_vorbiscomment_(const FLAC__StreamMetadata_VorbisComment *block1, const FLAC__StreamMetadata_VorbisComment *block2)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
750 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
751 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
752
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
753 if(block1->vendor_string.length != block2->vendor_string.length)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
754 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
755
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
756 if(0 != block1->vendor_string.entry && 0 != block2->vendor_string.entry) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
757 if(0 != memcmp(block1->vendor_string.entry, block2->vendor_string.entry, block1->vendor_string.length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
758 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
759 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
760 else if(block1->vendor_string.entry != block2->vendor_string.entry)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
761 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
762
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
763 if(block1->num_comments != block2->num_comments)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
764 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
765
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
766 for(i = 0; i < block1->num_comments; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
767 if(0 != block1->comments[i].entry && 0 != block2->comments[i].entry) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
768 if(0 != memcmp(block1->comments[i].entry, block2->comments[i].entry, block1->comments[i].length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
769 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
770 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
771 else if(block1->comments[i].entry != block2->comments[i].entry)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
772 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
773 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
774 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
775 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
776
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
777 static FLAC__bool compare_block_data_cuesheet_(const FLAC__StreamMetadata_CueSheet *block1, const FLAC__StreamMetadata_CueSheet *block2)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
778 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
779 unsigned i, j;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
780
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
781 if(0 != strcmp(block1->media_catalog_number, block2->media_catalog_number))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
782 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
783
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
784 if(block1->lead_in != block2->lead_in)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
785 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
786
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
787 if(block1->is_cd != block2->is_cd)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
788 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
789
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
790 if(block1->num_tracks != block2->num_tracks)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
791 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
792
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
793 if(0 != block1->tracks && 0 != block2->tracks) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
794 FLAC__ASSERT(block1->num_tracks > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
795 for(i = 0; i < block1->num_tracks; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
796 if(block1->tracks[i].offset != block2->tracks[i].offset)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
797 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
798 if(block1->tracks[i].number != block2->tracks[i].number)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
799 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
800 if(0 != memcmp(block1->tracks[i].isrc, block2->tracks[i].isrc, sizeof(block1->tracks[i].isrc)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
801 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
802 if(block1->tracks[i].type != block2->tracks[i].type)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
803 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
804 if(block1->tracks[i].pre_emphasis != block2->tracks[i].pre_emphasis)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
805 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
806 if(block1->tracks[i].num_indices != block2->tracks[i].num_indices)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
807 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
808 if(0 != block1->tracks[i].indices && 0 != block2->tracks[i].indices) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
809 FLAC__ASSERT(block1->tracks[i].num_indices > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
810 for(j = 0; j < block1->tracks[i].num_indices; j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
811 if(block1->tracks[i].indices[j].offset != block2->tracks[i].indices[j].offset)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
812 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
813 if(block1->tracks[i].indices[j].number != block2->tracks[i].indices[j].number)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
814 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
815 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
816 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
817 else if(block1->tracks[i].indices != block2->tracks[i].indices)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
818 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
819 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
820 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
821 else if(block1->tracks != block2->tracks)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
822 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
823 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
824 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
825
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
826 static FLAC__bool compare_block_data_picture_(const FLAC__StreamMetadata_Picture *block1, const FLAC__StreamMetadata_Picture *block2)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
827 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
828 if(block1->type != block2->type)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
829 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
830 if(block1->mime_type != block2->mime_type && (0 == block1->mime_type || 0 == block2->mime_type || strcmp(block1->mime_type, block2->mime_type)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
831 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
832 if(block1->description != block2->description && (0 == block1->description || 0 == block2->description || strcmp((const char *)block1->description, (const char *)block2->description)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
833 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
834 if(block1->width != block2->width)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
835 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
836 if(block1->height != block2->height)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
837 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
838 if(block1->depth != block2->depth)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
839 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
840 if(block1->colors != block2->colors)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
841 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
842 if(block1->data_length != block2->data_length)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
843 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
844 if(block1->data != block2->data && (0 == block1->data || 0 == block2->data || memcmp(block1->data, block2->data, block1->data_length)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
845 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
846 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
847 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
848
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
849 static FLAC__bool compare_block_data_unknown_(const FLAC__StreamMetadata_Unknown *block1, const FLAC__StreamMetadata_Unknown *block2, unsigned block_length)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
850 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
851 FLAC__ASSERT(0 != block1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
852 FLAC__ASSERT(0 != block2);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
853
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
854 if(0 != block1->data && 0 != block2->data)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
855 return 0 == memcmp(block1->data, block2->data, block_length);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
856 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
857 return block1->data == block2->data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
858 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
859
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
860 FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
861 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
862 FLAC__ASSERT(0 != block1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
863 FLAC__ASSERT(0 != block2);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
864
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
865 if(block1->type != block2->type) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
866 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
867 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
868 if(block1->is_last != block2->is_last) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
869 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
870 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
871 if(block1->length != block2->length) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
872 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
873 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
874 switch(block1->type) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
875 case FLAC__METADATA_TYPE_STREAMINFO:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
876 return compare_block_data_streaminfo_(&block1->data.stream_info, &block2->data.stream_info);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
877 case FLAC__METADATA_TYPE_PADDING:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
878 return true; /* we don't compare the padding guts */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
879 case FLAC__METADATA_TYPE_APPLICATION:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
880 return compare_block_data_application_(&block1->data.application, &block2->data.application, block1->length);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
881 case FLAC__METADATA_TYPE_SEEKTABLE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
882 return compare_block_data_seektable_(&block1->data.seek_table, &block2->data.seek_table);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
883 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
884 return compare_block_data_vorbiscomment_(&block1->data.vorbis_comment, &block2->data.vorbis_comment);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
885 case FLAC__METADATA_TYPE_CUESHEET:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
886 return compare_block_data_cuesheet_(&block1->data.cue_sheet, &block2->data.cue_sheet);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
887 case FLAC__METADATA_TYPE_PICTURE:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
888 return compare_block_data_picture_(&block1->data.picture, &block2->data.picture);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
889 default:
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
890 return compare_block_data_unknown_(&block1->data.unknown, &block2->data.unknown, block1->length);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
891 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
892 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
893
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
894 FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
895 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
896 FLAC__byte *save;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
897
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
898 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
899 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_APPLICATION);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
900 FLAC__ASSERT((0 != data && length > 0) || (0 == data && length == 0 && copy == false));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
901
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
902 save = object->data.application.data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
903
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
904 /* do the copy first so that if we fail we leave the object untouched */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
905 if(copy) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
906 if(!copy_bytes_(&object->data.application.data, data, length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
907 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
908 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
909 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
910 object->data.application.data = data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
911 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
912
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
913 if(0 != save)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
914 free(save);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
915
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
916 object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 + length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
917 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
918 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
919
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
920 FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
921 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
922 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
923 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
924
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
925 if(0 == object->data.seek_table.points) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
926 FLAC__ASSERT(object->data.seek_table.num_points == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
927 if(0 == new_num_points)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
928 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
929 else if(0 == (object->data.seek_table.points = seekpoint_array_new_(new_num_points)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
930 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
931 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
932 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
933 const unsigned old_size = object->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
934 const unsigned new_size = new_num_points * sizeof(FLAC__StreamMetadata_SeekPoint);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
935
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
936 FLAC__ASSERT(object->data.seek_table.num_points > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
937
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
938 if(new_size == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
939 free(object->data.seek_table.points);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
940 object->data.seek_table.points = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
941 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
942 else if(0 == (object->data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*)realloc(object->data.seek_table.points, new_size)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
943 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
944
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
945 /* if growing, set new elements to placeholders */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
946 if(new_size > old_size) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
947 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
948 for(i = object->data.seek_table.num_points; i < new_num_points; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
949 object->data.seek_table.points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
950 object->data.seek_table.points[i].stream_offset = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
951 object->data.seek_table.points[i].frame_samples = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
952 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
953 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
954 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
955
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
956 object->data.seek_table.num_points = new_num_points;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
957
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
958 seektable_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
959 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
960 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
961
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
962 FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
963 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
964 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
965 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
966 FLAC__ASSERT(point_num < object->data.seek_table.num_points);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
967
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
968 object->data.seek_table.points[point_num] = point;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
969 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
970
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
971 FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
972 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
973 int i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
974
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
975 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
976 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
977 FLAC__ASSERT(point_num <= object->data.seek_table.num_points);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
978
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
979 if(!FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points+1))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
980 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
981
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
982 /* move all points >= point_num forward one space */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
983 for(i = (int)object->data.seek_table.num_points-1; i > (int)point_num; i--)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
984 object->data.seek_table.points[i] = object->data.seek_table.points[i-1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
985
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
986 FLAC__metadata_object_seektable_set_point(object, point_num, point);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
987 seektable_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
988 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
989 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
990
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
991 FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
992 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
993 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
994
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
995 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
996 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
997 FLAC__ASSERT(point_num < object->data.seek_table.num_points);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
998
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
999 /* move all points > point_num backward one space */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1000 for(i = point_num; i < object->data.seek_table.num_points-1; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1001 object->data.seek_table.points[i] = object->data.seek_table.points[i+1];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1002
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1003 return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points-1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1004 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1005
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1006 FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1007 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1008 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1009 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1010
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1011 return FLAC__format_seektable_is_legal(&object->data.seek_table);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1012 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1013
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1014 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1015 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1016 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1017 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1018
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1019 if(num > 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1020 /* WATCHOUT: we rely on the fact that growing the array adds PLACEHOLDERS at the end */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1021 return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points + num);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1022 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1023 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1024 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1025
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1026 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1027 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1028 FLAC__StreamMetadata_SeekTable *seek_table;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1029
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1030 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1031 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1032
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1033 seek_table = &object->data.seek_table;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1034
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1035 if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + 1))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1036 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1037
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1038 seek_table->points[seek_table->num_points - 1].sample_number = sample_number;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1039 seek_table->points[seek_table->num_points - 1].stream_offset = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1040 seek_table->points[seek_table->num_points - 1].frame_samples = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1041
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1042 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1043 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1044
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1045 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1046 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1047 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1048 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1049 FLAC__ASSERT(0 != sample_numbers || num == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1050
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1051 if(num > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1052 FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1053 unsigned i, j;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1054
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1055 i = seek_table->num_points;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1056
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1057 if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1058 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1059
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1060 for(j = 0; j < num; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1061 seek_table->points[i].sample_number = sample_numbers[j];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1062 seek_table->points[i].stream_offset = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1063 seek_table->points[i].frame_samples = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1064 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1065 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1066
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1067 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1068 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1069
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1070 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1071 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1072 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1073 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1074 FLAC__ASSERT(total_samples > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1075
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1076 if(num > 0 && total_samples > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1077 FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1078 unsigned i, j;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1079
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1080 i = seek_table->num_points;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1081
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1082 if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1083 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1084
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1085 for(j = 0; j < num; i++, j++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1086 seek_table->points[i].sample_number = total_samples * (FLAC__uint64)j / (FLAC__uint64)num;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1087 seek_table->points[i].stream_offset = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1088 seek_table->points[i].frame_samples = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1089 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1090 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1091
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1092 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1093 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1094
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1095 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1096 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1097 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1098 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1099 FLAC__ASSERT(samples > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1100 FLAC__ASSERT(total_samples > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1101
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1102 if(samples > 0 && total_samples > 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1103 FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1104 unsigned i, j;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1105 FLAC__uint64 num, sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1106
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1107 num = 1 + total_samples / samples; /* 1+ for the first sample at 0 */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1108 /* now account for the fact that we don't place a seekpoint at "total_samples" since samples are number from 0: */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1109 if(total_samples % samples == 0)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1110 num--;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1111
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1112 i = seek_table->num_points;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1113
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1114 if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + (unsigned)num))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1115 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1116
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1117 sample = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1118 for(j = 0; j < num; i++, j++, sample += samples) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1119 seek_table->points[i].sample_number = sample;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1120 seek_table->points[i].stream_offset = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1121 seek_table->points[i].frame_samples = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1122 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1123 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1124
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1125 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1126 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1127
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1128 FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1129 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1130 unsigned unique;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1131
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1132 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1133 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1134
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1135 unique = FLAC__format_seektable_sort(&object->data.seek_table);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1136
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1137 return !compact || FLAC__metadata_object_seektable_resize_points(object, unique);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1138 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1139
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1140 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1141 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1142 if(!FLAC__format_vorbiscomment_entry_value_is_legal(entry.entry, entry.length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1143 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1144 return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.vendor_string, &entry, copy);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1145 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1146
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1147 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1148 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1149 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1150 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1151
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1152 if(0 == object->data.vorbis_comment.comments) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1153 FLAC__ASSERT(object->data.vorbis_comment.num_comments == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1154 if(0 == new_num_comments)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1155 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1156 else if(0 == (object->data.vorbis_comment.comments = vorbiscomment_entry_array_new_(new_num_comments)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1157 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1158 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1159 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1160 const unsigned old_size = object->data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1161 const unsigned new_size = new_num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1162
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1163 FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1164
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1165 /* if shrinking, free the truncated entries */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1166 if(new_num_comments < object->data.vorbis_comment.num_comments) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1167 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1168 for(i = new_num_comments; i < object->data.vorbis_comment.num_comments; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1169 if(0 != object->data.vorbis_comment.comments[i].entry)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1170 free(object->data.vorbis_comment.comments[i].entry);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1171 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1172
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1173 if(new_size == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1174 free(object->data.vorbis_comment.comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1175 object->data.vorbis_comment.comments = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1176 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1177 else if(0 == (object->data.vorbis_comment.comments = (FLAC__StreamMetadata_VorbisComment_Entry*)realloc(object->data.vorbis_comment.comments, new_size)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1178 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1179
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1180 /* if growing, zero all the length/pointers of new elements */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1181 if(new_size > old_size)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1182 memset(object->data.vorbis_comment.comments + object->data.vorbis_comment.num_comments, 0, new_size - old_size);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1183 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1184
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1185 object->data.vorbis_comment.num_comments = new_num_comments;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1186
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1187 vorbiscomment_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1188 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1189 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1190
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1191 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1192 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1193 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1194 FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1195
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1196 if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1197 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1198 return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.comments[comment_num], &entry, copy);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1199 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1200
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1201 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1202 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1203 FLAC__StreamMetadata_VorbisComment *vc;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1204
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1205 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1206 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1207 FLAC__ASSERT(comment_num <= object->data.vorbis_comment.num_comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1208
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1209 if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1210 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1211
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1212 vc = &object->data.vorbis_comment;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1213
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1214 if(!FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments+1))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1215 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1216
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1217 /* move all comments >= comment_num forward one space */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1218 memmove(&vc->comments[comment_num+1], &vc->comments[comment_num], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-1-comment_num));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1219 vc->comments[comment_num].length = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1220 vc->comments[comment_num].entry = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1221
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1222 return FLAC__metadata_object_vorbiscomment_set_comment(object, comment_num, entry, copy);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1223 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1224
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1225 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1226 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1227 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1228 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1229 return FLAC__metadata_object_vorbiscomment_insert_comment(object, object->data.vorbis_comment.num_comments, entry, copy);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1230 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1231
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1232 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1233 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1234 FLAC__ASSERT(0 != entry.entry && entry.length > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1235
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1236 if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1237 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1238
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1239 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1240 int i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1241 unsigned field_name_length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1242 const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1243
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1244 FLAC__ASSERT(0 != eq);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1245
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1246 if(0 == eq)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1247 return false; /* double protection */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1248
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1249 field_name_length = eq-entry.entry;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1250
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1251 if((i = vorbiscomment_find_entry_from_(object, 0, (const char *)entry.entry, field_name_length)) >= 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1252 unsigned index = (unsigned)i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1253 if(!FLAC__metadata_object_vorbiscomment_set_comment(object, index, entry, copy))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1254 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1255 if(all && (index+1 < object->data.vorbis_comment.num_comments)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1256 for(i = vorbiscomment_find_entry_from_(object, index+1, (const char *)entry.entry, field_name_length); i >= 0; ) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1257 if(!FLAC__metadata_object_vorbiscomment_delete_comment(object, (unsigned)i))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1258 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1259 if((unsigned)i < object->data.vorbis_comment.num_comments)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1260 i = vorbiscomment_find_entry_from_(object, (unsigned)i, (const char *)entry.entry, field_name_length);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1261 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1262 i = -1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1263 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1264 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1265 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1266 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1267 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1268 return FLAC__metadata_object_vorbiscomment_append_comment(object, entry, copy);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1269 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1270 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1271
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1272 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1273 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1274 FLAC__StreamMetadata_VorbisComment *vc;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1275
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1276 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1277 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1278 FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1279
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1280 vc = &object->data.vorbis_comment;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1281
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1282 /* free the comment at comment_num */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1283 if(0 != vc->comments[comment_num].entry)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1284 free(vc->comments[comment_num].entry);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1285
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1286 /* move all comments > comment_num backward one space */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1287 memmove(&vc->comments[comment_num], &vc->comments[comment_num+1], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-comment_num-1));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1288 vc->comments[vc->num_comments-1].length = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1289 vc->comments[vc->num_comments-1].entry = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1290
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1291 return FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments-1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1292 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1293
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1294 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair(FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, const char *field_value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1295 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1296 FLAC__ASSERT(0 != entry);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1297 FLAC__ASSERT(0 != field_name);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1298 FLAC__ASSERT(0 != field_value);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1299
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1300 if(!FLAC__format_vorbiscomment_entry_name_is_legal(field_name))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1301 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1302 if(!FLAC__format_vorbiscomment_entry_value_is_legal((const FLAC__byte *)field_value, (unsigned)(-1)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1303 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1304
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1305 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1306 const size_t nn = strlen(field_name);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1307 const size_t nv = strlen(field_value);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1308 entry->length = nn + 1 /*=*/ + nv;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1309 if(0 == (entry->entry = (FLAC__byte*)malloc(entry->length+1)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1310 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1311 memcpy(entry->entry, field_name, nn);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1312 entry->entry[nn] = '=';
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1313 memcpy(entry->entry+nn+1, field_value, nv);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1314 entry->entry[entry->length] = '\0';
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1315 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1316
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1317 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1318 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1319
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1320 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(const FLAC__StreamMetadata_VorbisComment_Entry entry, char **field_name, char **field_value)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1321 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1322 FLAC__ASSERT(0 != entry.entry && entry.length > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1323 FLAC__ASSERT(0 != field_name);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1324 FLAC__ASSERT(0 != field_value);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1325
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1326 if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1327 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1328
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1329 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1330 const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1331 const size_t nn = eq-entry.entry;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1332 const size_t nv = entry.length-nn-1; /* -1 for the '=' */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1333 FLAC__ASSERT(0 != eq);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1334 if(0 == eq)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1335 return false; /* double protection */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1336 if(0 == (*field_name = (char*)malloc(nn+1)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1337 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1338 if(0 == (*field_value = (char*)malloc(nv+1))) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1339 free(*field_name);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1340 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1341 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1342 memcpy(*field_name, entry.entry, nn);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1343 memcpy(*field_value, entry.entry+nn+1, nv);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1344 (*field_name)[nn] = '\0';
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1345 (*field_value)[nv] = '\0';
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1346 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1347
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1348 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1349 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1350
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1351 FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1352 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1353 FLAC__ASSERT(0 != entry.entry && entry.length > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1354 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1355 const FLAC__byte *eq = (FLAC__byte*)memchr(entry.entry, '=', entry.length);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1356 #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ || defined __EMX__
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1357 #define FLAC__STRNCASECMP strnicmp
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1358 #else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1359 #define FLAC__STRNCASECMP strncasecmp
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1360 #endif
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1361 return (0 != eq && (unsigned)(eq-entry.entry) == field_name_length && 0 == FLAC__STRNCASECMP(field_name, (const char *)entry.entry, field_name_length));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1362 #undef FLAC__STRNCASECMP
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1363 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1364 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1365
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1366 FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1367 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1368 FLAC__ASSERT(0 != field_name);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1369
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1370 return vorbiscomment_find_entry_from_(object, offset, field_name, strlen(field_name));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1371 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1372
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1373 FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1374 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1375 const unsigned field_name_length = strlen(field_name);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1376 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1377
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1378 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1379 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1380
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1381 for(i = 0; i < object->data.vorbis_comment.num_comments; i++) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1382 if(FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1383 if(!FLAC__metadata_object_vorbiscomment_delete_comment(object, i))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1384 return -1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1385 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1386 return 1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1387 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1388 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1389
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1390 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1391 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1392
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1393 FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1394 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1395 FLAC__bool ok = true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1396 unsigned matching = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1397 const unsigned field_name_length = strlen(field_name);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1398 int i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1399
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1400 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1401 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1402
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1403 /* must delete from end to start otherwise it will interfere with our iteration */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1404 for(i = (int)object->data.vorbis_comment.num_comments - 1; ok && i >= 0; i--) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1405 if(FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments[i], field_name, field_name_length)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1406 matching++;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1407 ok &= FLAC__metadata_object_vorbiscomment_delete_comment(object, (unsigned)i);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1408 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1409 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1410
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1411 return ok? (int)matching : -1;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1412 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1413
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1414 FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1415 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1416 return (FLAC__StreamMetadata_CueSheet_Track*)calloc(1, sizeof(FLAC__StreamMetadata_CueSheet_Track));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1417 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1418
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1419 FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1420 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1421 FLAC__StreamMetadata_CueSheet_Track *to;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1422
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1423 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1424
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1425 if(0 != (to = FLAC__metadata_object_cuesheet_track_new())) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1426 if(!copy_track_(to, object)) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1427 FLAC__metadata_object_cuesheet_track_delete(to);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1428 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1429 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1430 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1431
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1432 return to;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1433 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1434
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1435 void FLAC__metadata_object_cuesheet_track_delete_data(FLAC__StreamMetadata_CueSheet_Track *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1436 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1437 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1438
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1439 if(0 != object->indices) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1440 FLAC__ASSERT(object->num_indices > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1441 free(object->indices);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1442 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1443 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1444
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1445 FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1446 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1447 FLAC__metadata_object_cuesheet_track_delete_data(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1448 free(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1449 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1450
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1451 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1452 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1453 FLAC__StreamMetadata_CueSheet_Track *track;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1454 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1455 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1456 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1457
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1458 track = &object->data.cue_sheet.tracks[track_num];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1459
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1460 if(0 == track->indices) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1461 FLAC__ASSERT(track->num_indices == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1462 if(0 == new_num_indices)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1463 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1464 else if(0 == (track->indices = cuesheet_track_index_array_new_(new_num_indices)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1465 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1466 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1467 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1468 const unsigned old_size = track->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1469 const unsigned new_size = new_num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1470
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1471 FLAC__ASSERT(track->num_indices > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1472
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1473 if(new_size == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1474 free(track->indices);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1475 track->indices = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1476 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1477 else if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)realloc(track->indices, new_size)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1478 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1479
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1480 /* if growing, zero all the lengths/pointers of new elements */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1481 if(new_size > old_size)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1482 memset(track->indices + track->num_indices, 0, new_size - old_size);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1483 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1484
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1485 track->num_indices = new_num_indices;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1486
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1487 cuesheet_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1488 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1489 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1490
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1491 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num, FLAC__StreamMetadata_CueSheet_Index index)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1492 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1493 FLAC__StreamMetadata_CueSheet_Track *track;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1494
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1495 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1496 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1497 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1498 FLAC__ASSERT(index_num <= object->data.cue_sheet.tracks[track_num].num_indices);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1499
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1500 track = &object->data.cue_sheet.tracks[track_num];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1501
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1502 if(!FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices+1))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1503 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1504
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1505 /* move all indices >= index_num forward one space */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1506 memmove(&track->indices[index_num+1], &track->indices[index_num], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-1-index_num));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1507
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1508 track->indices[index_num] = index;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1509 cuesheet_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1510 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1511 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1512
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1513 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1514 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1515 FLAC__StreamMetadata_CueSheet_Index index;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1516 memset(&index, 0, sizeof(index));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1517 return FLAC__metadata_object_cuesheet_track_insert_index(object, track_num, index_num, index);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1518 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1519
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1520 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1521 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1522 FLAC__StreamMetadata_CueSheet_Track *track;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1523
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1524 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1525 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1526 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1527 FLAC__ASSERT(index_num < object->data.cue_sheet.tracks[track_num].num_indices);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1528
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1529 track = &object->data.cue_sheet.tracks[track_num];
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1530
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1531 /* move all indices > index_num backward one space */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1532 memmove(&track->indices[index_num], &track->indices[index_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-index_num-1));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1533
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1534 FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices-1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1535 cuesheet_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1536 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1537 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1538
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1539 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1540 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1541 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1542 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1543
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1544 if(0 == object->data.cue_sheet.tracks) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1545 FLAC__ASSERT(object->data.cue_sheet.num_tracks == 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1546 if(0 == new_num_tracks)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1547 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1548 else if(0 == (object->data.cue_sheet.tracks = cuesheet_track_array_new_(new_num_tracks)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1549 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1550 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1551 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1552 const unsigned old_size = object->data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1553 const unsigned new_size = new_num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1554
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1555 FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1556
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1557 /* if shrinking, free the truncated entries */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1558 if(new_num_tracks < object->data.cue_sheet.num_tracks) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1559 unsigned i;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1560 for(i = new_num_tracks; i < object->data.cue_sheet.num_tracks; i++)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1561 if(0 != object->data.cue_sheet.tracks[i].indices)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1562 free(object->data.cue_sheet.tracks[i].indices);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1563 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1564
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1565 if(new_size == 0) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1566 free(object->data.cue_sheet.tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1567 object->data.cue_sheet.tracks = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1568 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1569 else if(0 == (object->data.cue_sheet.tracks = (FLAC__StreamMetadata_CueSheet_Track*)realloc(object->data.cue_sheet.tracks, new_size)))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1570 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1571
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1572 /* if growing, zero all the lengths/pointers of new elements */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1573 if(new_size > old_size)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1574 memset(object->data.cue_sheet.tracks + object->data.cue_sheet.num_tracks, 0, new_size - old_size);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1575 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1576
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1577 object->data.cue_sheet.num_tracks = new_num_tracks;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1578
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1579 cuesheet_calculate_length_(object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1580 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1581 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1582
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1583 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1584 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1585 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1586 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1587
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1588 return cuesheet_set_track_(object, object->data.cue_sheet.tracks + track_num, track, copy);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1589 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1590
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1591 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1592 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1593 FLAC__StreamMetadata_CueSheet *cs;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1594
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1595 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1596 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1597 FLAC__ASSERT(track_num <= object->data.cue_sheet.num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1598
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1599 cs = &object->data.cue_sheet;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1600
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1601 if(!FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks+1))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1602 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1603
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1604 /* move all tracks >= track_num forward one space */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1605 memmove(&cs->tracks[track_num+1], &cs->tracks[track_num], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(cs->num_tracks-1-track_num));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1606 cs->tracks[track_num].num_indices = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1607 cs->tracks[track_num].indices = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1608
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1609 return FLAC__metadata_object_cuesheet_set_track(object, track_num, track, copy);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1610 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1611
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1612 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1613 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1614 FLAC__StreamMetadata_CueSheet_Track track;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1615 memset(&track, 0, sizeof(track));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1616 return FLAC__metadata_object_cuesheet_insert_track(object, track_num, &track, /*copy=*/false);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1617 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1618
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1619 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1620 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1621 FLAC__StreamMetadata_CueSheet *cs;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1622
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1623 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1624 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1625 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1626
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1627 cs = &object->data.cue_sheet;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1628
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1629 /* free the track at track_num */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1630 if(0 != cs->tracks[track_num].indices)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1631 free(cs->tracks[track_num].indices);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1632
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1633 /* move all tracks > track_num backward one space */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1634 memmove(&cs->tracks[track_num], &cs->tracks[track_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(cs->num_tracks-track_num-1));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1635 cs->tracks[cs->num_tracks-1].num_indices = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1636 cs->tracks[cs->num_tracks-1].indices = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1637
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1638 return FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks-1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1639 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1640
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1641 FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1642 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1643 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1644 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1645
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1646 return FLAC__format_cuesheet_is_legal(&object->data.cue_sheet, check_cd_da_subset, violation);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1647 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1648
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1649 static FLAC__uint64 get_index_01_offset_(const FLAC__StreamMetadata_CueSheet *cs, unsigned track)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1650 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1651 if (track >= (cs->num_tracks-1) || cs->tracks[track].num_indices < 1)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1652 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1653 else if (cs->tracks[track].indices[0].number == 1)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1654 return cs->tracks[track].indices[0].offset + cs->tracks[track].offset + cs->lead_in;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1655 else if (cs->tracks[track].num_indices < 2)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1656 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1657 else if (cs->tracks[track].indices[1].number == 1)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1658 return cs->tracks[track].indices[1].offset + cs->tracks[track].offset + cs->lead_in;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1659 else
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1660 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1661 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1662
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1663 static FLAC__uint32 cddb_add_digits_(FLAC__uint32 x)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1664 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1665 FLAC__uint32 n = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1666 while (x) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1667 n += (x%10);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1668 x /= 10;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1669 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1670 return n;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1671 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1672
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1673 FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1674 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1675 const FLAC__StreamMetadata_CueSheet *cs;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1676
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1677 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1678 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1679
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1680 cs = &object->data.cue_sheet;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1681
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1682 if (cs->num_tracks < 2) /* need at least one real track and the lead-out track */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1683 return 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1684
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1685 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1686 FLAC__uint32 i, length, sum = 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1687 for (i = 0; i < (cs->num_tracks-1); i++) /* -1 to avoid counting the lead-out */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1688 sum += cddb_add_digits_((FLAC__uint32)(get_index_01_offset_(cs, i) / 44100));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1689 length = (FLAC__uint32)((cs->tracks[cs->num_tracks-1].offset+cs->lead_in) / 44100) - (FLAC__uint32)(get_index_01_offset_(cs, 0) / 44100);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1690
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1691 return (sum % 0xFF) << 24 | length << 8 | (FLAC__uint32)(cs->num_tracks-1);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1692 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1693 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1694
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1695 FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1696 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1697 char *old;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1698 size_t old_length, new_length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1699
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1700 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1701 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1702 FLAC__ASSERT(0 != mime_type);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1703
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1704 old = object->data.picture.mime_type;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1705 old_length = old? strlen(old) : 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1706 new_length = strlen(mime_type);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1707
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1708 /* do the copy first so that if we fail we leave the object untouched */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1709 if(copy) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1710 if(!copy_bytes_((FLAC__byte**)(&object->data.picture.mime_type), (FLAC__byte*)mime_type, new_length+1))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1711 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1712 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1713 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1714 object->data.picture.mime_type = mime_type;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1715 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1716
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1717 if(0 != old)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1718 free(old);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1719
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1720 object->length -= old_length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1721 object->length += new_length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1722 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1723 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1724
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1725 FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1726 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1727 FLAC__byte *old;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1728 size_t old_length, new_length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1729
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1730 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1731 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1732 FLAC__ASSERT(0 != description);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1733
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1734 old = object->data.picture.description;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1735 old_length = old? strlen((const char *)old) : 0;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1736 new_length = strlen((const char *)description);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1737
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1738 /* do the copy first so that if we fail we leave the object untouched */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1739 if(copy) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1740 if(!copy_bytes_(&object->data.picture.description, description, new_length+1))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1741 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1742 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1743 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1744 object->data.picture.description = description;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1745 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1746
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1747 if(0 != old)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1748 free(old);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1749
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1750 object->length -= old_length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1751 object->length += new_length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1752 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1753 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1754
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1755 FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1756 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1757 FLAC__byte *old;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1758
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1759 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1760 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1761 FLAC__ASSERT((0 != data && length > 0) || (0 == data && length == 0 && copy == false));
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1762
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1763 old = object->data.picture.data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1764
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1765 /* do the copy first so that if we fail we leave the object untouched */
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1766 if(copy) {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1767 if(!copy_bytes_(&object->data.picture.data, data, length))
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1768 return false;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1769 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1770 else {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1771 object->data.picture.data = data;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1772 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1773
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1774 if(0 != old)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1775 free(old);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1776
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1777 object->length -= object->data.picture.data_length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1778 object->data.picture.data_length = length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1779 object->length += length;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1780 return true;
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1781 }
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1782
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1783 FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation)
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1784 {
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1785 FLAC__ASSERT(0 != object);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1786 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_PICTURE);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1787
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1788 return FLAC__format_picture_is_legal(&object->data.picture, violation);
a9b178bc4ae4 [svn] Import flac. Please test.
js
parents:
diff changeset
1789 }