blob: 589357b6775df0404a410fecbc027a5dedd2efa5 [file] [log] [blame]
Josh Coalson90ced912002-05-30 05:23:38 +00001/* libFLAC - Free Lossless Audio Codec library
Josh Coalson95643902004-01-17 04:14:43 +00002 * Copyright (C) 2001,2002,2003,2004 Josh Coalson
Josh Coalson90ced912002-05-30 05:23:38 +00003 *
Josh Coalsonafd81072003-01-31 23:34:56 +00004 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
Josh Coalson90ced912002-05-30 05:23:38 +00007 *
Josh Coalsonafd81072003-01-31 23:34:56 +00008 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
Josh Coalson90ced912002-05-30 05:23:38 +000010 *
Josh Coalsonafd81072003-01-31 23:34:56 +000011 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of the Xiph.org Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Josh Coalson90ced912002-05-30 05:23:38 +000030 */
31
32#include <stdlib.h>
33#include <string.h>
34
35#include "private/metadata.h"
36
37#include "FLAC/assert.h"
38
39
40/****************************************************************************
41 *
42 * Local routines
43 *
44 ***************************************************************************/
45
46static FLAC__bool copy_bytes_(FLAC__byte **to, const FLAC__byte *from, unsigned bytes)
47{
48 if(bytes > 0 && 0 != from) {
49 FLAC__byte *x;
Josh Coalson5e3fcb22002-11-06 07:11:26 +000050 if(0 == (x = (FLAC__byte*)malloc(bytes)))
Josh Coalson90ced912002-05-30 05:23:38 +000051 return false;
52 memcpy(x, from, bytes);
53 *to = x;
54 }
55 else {
56 FLAC__ASSERT(0 == from);
57 FLAC__ASSERT(bytes == 0);
58 *to = 0;
59 }
60 return true;
61}
62
Josh Coalsoncc682512002-06-08 04:53:42 +000063static FLAC__bool copy_vcentry_(FLAC__StreamMetadata_VorbisComment_Entry *to, const FLAC__StreamMetadata_VorbisComment_Entry *from)
Josh Coalson90ced912002-05-30 05:23:38 +000064{
65 to->length = from->length;
66 if(0 == from->entry) {
67 FLAC__ASSERT(from->length == 0);
68 to->entry = 0;
69 }
70 else {
71 FLAC__byte *x;
72 FLAC__ASSERT(from->length > 0);
Josh Coalson5e3fcb22002-11-06 07:11:26 +000073 if(0 == (x = (FLAC__byte*)malloc(from->length)))
Josh Coalson90ced912002-05-30 05:23:38 +000074 return false;
75 memcpy(x, from->entry, from->length);
76 to->entry = x;
77 }
78 return true;
79}
80
Josh Coalson8e9c4512002-11-14 05:00:24 +000081static FLAC__bool copy_track_(FLAC__StreamMetadata_CueSheet_Track *to, const FLAC__StreamMetadata_CueSheet_Track *from)
82{
83 memcpy(to, from, sizeof(FLAC__StreamMetadata_CueSheet_Track));
84 if(0 == from->indices) {
85 FLAC__ASSERT(from->num_indices == 0);
86 }
87 else {
88 FLAC__StreamMetadata_CueSheet_Index *x;
89 FLAC__ASSERT(from->num_indices > 0);
90 if(0 == (x = (FLAC__StreamMetadata_CueSheet_Index*)malloc(from->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index))))
91 return false;
92 memcpy(x, from->indices, from->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index));
93 to->indices = x;
94 }
95 return true;
96}
97
Josh Coalsoncc682512002-06-08 04:53:42 +000098static void seektable_calculate_length_(FLAC__StreamMetadata *object)
Josh Coalson90ced912002-05-30 05:23:38 +000099{
100 FLAC__ASSERT(0 != object);
101 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
102
103 object->length = object->data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
104}
105
Josh Coalsoncc682512002-06-08 04:53:42 +0000106static FLAC__StreamMetadata_SeekPoint *seekpoint_array_new_(unsigned num_points)
Josh Coalson90ced912002-05-30 05:23:38 +0000107{
Josh Coalsoncc682512002-06-08 04:53:42 +0000108 FLAC__StreamMetadata_SeekPoint *object_array;
Josh Coalson90ced912002-05-30 05:23:38 +0000109
110 FLAC__ASSERT(num_points > 0);
111
Josh Coalson5e3fcb22002-11-06 07:11:26 +0000112 object_array = (FLAC__StreamMetadata_SeekPoint*)malloc(num_points * sizeof(FLAC__StreamMetadata_SeekPoint));
Josh Coalson90ced912002-05-30 05:23:38 +0000113
114 if(0 != object_array) {
115 unsigned i;
116 for(i = 0; i < num_points; i++) {
117 object_array[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
118 object_array[i].stream_offset = 0;
119 object_array[i].frame_samples = 0;
120 }
121 }
122
123 return object_array;
124}
125
Josh Coalsoncc682512002-06-08 04:53:42 +0000126static void vorbiscomment_calculate_length_(FLAC__StreamMetadata *object)
Josh Coalson90ced912002-05-30 05:23:38 +0000127{
128 unsigned i;
129
130 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
131
132 object->length = (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN) / 8;
133 object->length += object->data.vorbis_comment.vendor_string.length;
134 object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8;
135 for(i = 0; i < object->data.vorbis_comment.num_comments; i++) {
136 object->length += (FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8);
137 object->length += object->data.vorbis_comment.comments[i].length;
138 }
139}
140
Josh Coalsoncc682512002-06-08 04:53:42 +0000141static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_new_(unsigned num_comments)
Josh Coalson90ced912002-05-30 05:23:38 +0000142{
Josh Coalson90ced912002-05-30 05:23:38 +0000143 FLAC__ASSERT(num_comments > 0);
144
Josh Coalson5e3fcb22002-11-06 07:11:26 +0000145 return (FLAC__StreamMetadata_VorbisComment_Entry*)calloc(num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry));
Josh Coalson90ced912002-05-30 05:23:38 +0000146}
147
Josh Coalsoncc682512002-06-08 04:53:42 +0000148static void vorbiscomment_entry_array_delete_(FLAC__StreamMetadata_VorbisComment_Entry *object_array, unsigned num_comments)
Josh Coalson90ced912002-05-30 05:23:38 +0000149{
150 unsigned i;
151
152 FLAC__ASSERT(0 != object_array && num_comments > 0);
153
154 for(i = 0; i < num_comments; i++)
155 if(0 != object_array[i].entry)
156 free(object_array[i].entry);
157
158 if(0 != object_array)
159 free(object_array);
160}
161
Josh Coalsoncc682512002-06-08 04:53:42 +0000162static FLAC__StreamMetadata_VorbisComment_Entry *vorbiscomment_entry_array_copy_(const FLAC__StreamMetadata_VorbisComment_Entry *object_array, unsigned num_comments)
Josh Coalson90ced912002-05-30 05:23:38 +0000163{
Josh Coalsoncc682512002-06-08 04:53:42 +0000164 FLAC__StreamMetadata_VorbisComment_Entry *return_array;
Josh Coalson90ced912002-05-30 05:23:38 +0000165
166 FLAC__ASSERT(0 != object_array);
167 FLAC__ASSERT(num_comments > 0);
168
169 return_array = vorbiscomment_entry_array_new_(num_comments);
170
171 if(0 != return_array) {
172 unsigned i;
173
Josh Coalson90ced912002-05-30 05:23:38 +0000174 for(i = 0; i < num_comments; i++) {
175 if(!copy_vcentry_(return_array+i, object_array+i)) {
176 vorbiscomment_entry_array_delete_(return_array, num_comments);
177 return 0;
178 }
179 }
180 }
181
182 return return_array;
183}
184
Josh Coalsoncc682512002-06-08 04:53:42 +0000185static FLAC__bool vorbiscomment_set_entry_(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry *dest, const FLAC__StreamMetadata_VorbisComment_Entry *src, FLAC__bool copy)
Josh Coalson90ced912002-05-30 05:23:38 +0000186{
187 FLAC__byte *save;
188
189 FLAC__ASSERT(0 != object);
190 FLAC__ASSERT(0 != dest);
191 FLAC__ASSERT(0 != src);
192 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
Josh Coalson748459c2004-09-08 00:49:30 +0000193 FLAC__ASSERT((0 != src->entry && src->length > 0) || (0 == src->entry && src->length == 0));
Josh Coalson90ced912002-05-30 05:23:38 +0000194
Josh Coalson6b8e5302002-05-31 06:23:09 +0000195 save = dest->entry;
Josh Coalson90ced912002-05-30 05:23:38 +0000196
197 /* do the copy first so that if we fail we leave the object untouched */
Josh Coalson748459c2004-09-08 00:49:30 +0000198 if(copy && (0 != src->entry && src->length > 0)) {
Josh Coalson90ced912002-05-30 05:23:38 +0000199 if(!copy_vcentry_(dest, src))
200 return false;
201 }
202 else {
Josh Coalson748459c2004-09-08 00:49:30 +0000203 /* either we're not copying or the src is null */
Josh Coalson90ced912002-05-30 05:23:38 +0000204 *dest = *src;
205 }
206
207 if(0 != save)
208 free(save);
209
210 vorbiscomment_calculate_length_(object);
211 return true;
212}
213
Josh Coalson8e9c4512002-11-14 05:00:24 +0000214static void cuesheet_calculate_length_(FLAC__StreamMetadata *object)
215{
216 unsigned i;
217
218 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
219
220 object->length = (
221 FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN +
222 FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN +
Josh Coalson8f0c71b2002-12-05 06:37:46 +0000223 FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN +
Josh Coalsondf7240a2002-11-16 06:32:30 +0000224 FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN +
Josh Coalson8e9c4512002-11-14 05:00:24 +0000225 FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN
226 ) / 8;
227
228 object->length += object->data.cue_sheet.num_tracks * (
229 FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN +
230 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN +
231 FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN +
232 FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN +
233 FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN +
234 FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN +
235 FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN
236 ) / 8;
237
238 for(i = 0; i < object->data.cue_sheet.num_tracks; i++) {
239 object->length += object->data.cue_sheet.tracks[i].num_indices * (
240 FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN +
241 FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN +
242 FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN
243 ) / 8;
244 }
245}
246
247static FLAC__StreamMetadata_CueSheet_Index *cuesheet_track_index_array_new_(unsigned num_indices)
248{
249 FLAC__ASSERT(num_indices > 0);
250
251 return (FLAC__StreamMetadata_CueSheet_Index*)calloc(num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index));
252}
253
254static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_new_(unsigned num_tracks)
255{
256 FLAC__ASSERT(num_tracks > 0);
257
258 return (FLAC__StreamMetadata_CueSheet_Track*)calloc(num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track));
259}
260
261static void cuesheet_track_array_delete_(FLAC__StreamMetadata_CueSheet_Track *object_array, unsigned num_tracks)
262{
263 unsigned i;
264
265 FLAC__ASSERT(0 != object_array && num_tracks > 0);
266
267 for(i = 0; i < num_tracks; i++) {
268 if(0 != object_array[i].indices) {
269 FLAC__ASSERT(object_array[i].num_indices > 0);
270 free(object_array[i].indices);
271 }
272 }
273
274 if(0 != object_array)
275 free(object_array);
276}
277
278static FLAC__StreamMetadata_CueSheet_Track *cuesheet_track_array_copy_(const FLAC__StreamMetadata_CueSheet_Track *object_array, unsigned num_tracks)
279{
280 FLAC__StreamMetadata_CueSheet_Track *return_array;
281
282 FLAC__ASSERT(0 != object_array);
283 FLAC__ASSERT(num_tracks > 0);
284
285 return_array = cuesheet_track_array_new_(num_tracks);
286
287 if(0 != return_array) {
288 unsigned i;
289
290 for(i = 0; i < num_tracks; i++) {
291 if(!copy_track_(return_array+i, object_array+i)) {
292 cuesheet_track_array_delete_(return_array, num_tracks);
293 return 0;
294 }
295 }
296 }
297
298 return return_array;
299}
300
301static FLAC__bool cuesheet_set_track_(FLAC__StreamMetadata *object, FLAC__StreamMetadata_CueSheet_Track *dest, const FLAC__StreamMetadata_CueSheet_Track *src, FLAC__bool copy)
302{
303 FLAC__StreamMetadata_CueSheet_Index *save;
304
305 FLAC__ASSERT(0 != object);
306 FLAC__ASSERT(0 != dest);
307 FLAC__ASSERT(0 != src);
308 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
309 FLAC__ASSERT((0 != src->indices && src->num_indices > 0) || (0 == src->indices && src->num_indices == 0));
Josh Coalson8e9c4512002-11-14 05:00:24 +0000310
311 save = dest->indices;
312
313 /* do the copy first so that if we fail we leave the object untouched */
314 if(copy) {
315 if(!copy_track_(dest, src))
316 return false;
317 }
318 else {
319 *dest = *src;
320 }
321
322 if(0 != save)
323 free(save);
324
325 cuesheet_calculate_length_(object);
326 return true;
327}
328
Josh Coalson90ced912002-05-30 05:23:38 +0000329
330/****************************************************************************
331 *
332 * Metadata object routines
333 *
334 ***************************************************************************/
335
Josh Coalson6afed9f2002-10-16 22:29:47 +0000336FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type)
Josh Coalson90ced912002-05-30 05:23:38 +0000337{
Josh Coalson1cb23412004-07-22 01:32:00 +0000338 FLAC__StreamMetadata *object;
339
340 if(type > FLAC__MAX_METADATA_TYPE_CODE)
341 return 0;
342
343 object = (FLAC__StreamMetadata*)calloc(1, sizeof(FLAC__StreamMetadata));
Josh Coalson90ced912002-05-30 05:23:38 +0000344 if(0 != object) {
Josh Coalson90ced912002-05-30 05:23:38 +0000345 object->is_last = false;
346 object->type = type;
347 switch(type) {
348 case FLAC__METADATA_TYPE_STREAMINFO:
349 object->length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
350 break;
351 case FLAC__METADATA_TYPE_PADDING:
Josh Coalsond0609472003-01-10 05:37:13 +0000352 /* calloc() took care of this for us:
353 object->length = 0;
354 */
Josh Coalson90ced912002-05-30 05:23:38 +0000355 break;
356 case FLAC__METADATA_TYPE_APPLICATION:
357 object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
Josh Coalsond0609472003-01-10 05:37:13 +0000358 /* calloc() took care of this for us:
359 object->data.application.data = 0;
360 */
Josh Coalson90ced912002-05-30 05:23:38 +0000361 break;
362 case FLAC__METADATA_TYPE_SEEKTABLE:
Josh Coalsond0609472003-01-10 05:37:13 +0000363 /* calloc() took care of this for us:
364 object->length = 0;
365 object->data.seek_table.num_points = 0;
366 object->data.seek_table.points = 0;
367 */
Josh Coalson90ced912002-05-30 05:23:38 +0000368 break;
369 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
Josh Coalson45bb9882002-10-26 04:34:16 +0000370 {
371 object->data.vorbis_comment.vendor_string.length = (unsigned)strlen(FLAC__VENDOR_STRING);
372 if(!copy_bytes_(&object->data.vorbis_comment.vendor_string.entry, (const FLAC__byte*)FLAC__VENDOR_STRING, object->data.vorbis_comment.vendor_string.length)) {
373 free(object);
374 return 0;
375 }
Josh Coalson8e9c4512002-11-14 05:00:24 +0000376 vorbiscomment_calculate_length_(object);
Josh Coalson45bb9882002-10-26 04:34:16 +0000377 }
Josh Coalson90ced912002-05-30 05:23:38 +0000378 break;
Josh Coalson8e9c4512002-11-14 05:00:24 +0000379 case FLAC__METADATA_TYPE_CUESHEET:
380 cuesheet_calculate_length_(object);
381 break;
Josh Coalson90ced912002-05-30 05:23:38 +0000382 default:
Josh Coalsond0609472003-01-10 05:37:13 +0000383 /* calloc() took care of this for us:
384 object->length = 0;
385 object->data.unknown.data = 0;
386 */
387 break;
Josh Coalson90ced912002-05-30 05:23:38 +0000388 }
389 }
390
391 return object;
392}
393
Josh Coalson6afed9f2002-10-16 22:29:47 +0000394FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object)
Josh Coalson90ced912002-05-30 05:23:38 +0000395{
Josh Coalsoncc682512002-06-08 04:53:42 +0000396 FLAC__StreamMetadata *to;
Josh Coalson90ced912002-05-30 05:23:38 +0000397
398 FLAC__ASSERT(0 != object);
399
400 if(0 != (to = FLAC__metadata_object_new(object->type))) {
401 to->is_last = object->is_last;
402 to->type = object->type;
403 to->length = object->length;
404 switch(to->type) {
405 case FLAC__METADATA_TYPE_STREAMINFO:
Josh Coalsoncc682512002-06-08 04:53:42 +0000406 memcpy(&to->data.stream_info, &object->data.stream_info, sizeof(FLAC__StreamMetadata_StreamInfo));
Josh Coalson90ced912002-05-30 05:23:38 +0000407 break;
408 case FLAC__METADATA_TYPE_PADDING:
409 break;
410 case FLAC__METADATA_TYPE_APPLICATION:
411 memcpy(&to->data.application.id, &object->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8);
412 if(!copy_bytes_(&to->data.application.data, object->data.application.data, object->length - FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)) {
413 FLAC__metadata_object_delete(to);
414 return 0;
415 }
416 break;
417 case FLAC__METADATA_TYPE_SEEKTABLE:
418 to->data.seek_table.num_points = object->data.seek_table.num_points;
Josh Coalsoncc682512002-06-08 04:53:42 +0000419 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))) {
Josh Coalson90ced912002-05-30 05:23:38 +0000420 FLAC__metadata_object_delete(to);
421 return 0;
422 }
423 break;
424 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
Josh Coalson4fa90592002-12-04 07:01:37 +0000425 if(0 != to->data.vorbis_comment.vendor_string.entry) {
Josh Coalson45bb9882002-10-26 04:34:16 +0000426 free(to->data.vorbis_comment.vendor_string.entry);
Josh Coalson4fa90592002-12-04 07:01:37 +0000427 to->data.vorbis_comment.vendor_string.entry = 0;
428 }
Josh Coalson90ced912002-05-30 05:23:38 +0000429 if(!copy_vcentry_(&to->data.vorbis_comment.vendor_string, &object->data.vorbis_comment.vendor_string)) {
430 FLAC__metadata_object_delete(to);
431 return 0;
432 }
433 if(object->data.vorbis_comment.num_comments == 0) {
434 FLAC__ASSERT(0 == object->data.vorbis_comment.comments);
435 to->data.vorbis_comment.comments = 0;
436 }
437 else {
438 FLAC__ASSERT(0 != object->data.vorbis_comment.comments);
439 to->data.vorbis_comment.comments = vorbiscomment_entry_array_copy_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments);
440 if(0 == to->data.vorbis_comment.comments) {
441 FLAC__metadata_object_delete(to);
442 return 0;
443 }
444 }
445 to->data.vorbis_comment.num_comments = object->data.vorbis_comment.num_comments;
446 break;
Josh Coalson8e9c4512002-11-14 05:00:24 +0000447 case FLAC__METADATA_TYPE_CUESHEET:
448 memcpy(&to->data.cue_sheet, &object->data.cue_sheet, sizeof(FLAC__StreamMetadata_CueSheet));
449 if(object->data.cue_sheet.num_tracks == 0) {
450 FLAC__ASSERT(0 == object->data.cue_sheet.tracks);
451 }
452 else {
453 FLAC__ASSERT(0 != object->data.cue_sheet.tracks);
454 to->data.cue_sheet.tracks = cuesheet_track_array_copy_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks);
455 if(0 == to->data.cue_sheet.tracks) {
456 FLAC__metadata_object_delete(to);
457 return 0;
458 }
459 }
460 break;
Josh Coalson90ced912002-05-30 05:23:38 +0000461 default:
Josh Coalsond0609472003-01-10 05:37:13 +0000462 if(!copy_bytes_(&to->data.unknown.data, object->data.unknown.data, object->length)) {
463 FLAC__metadata_object_delete(to);
464 return 0;
465 }
466 break;
Josh Coalson90ced912002-05-30 05:23:38 +0000467 }
468 }
469
470 return to;
471}
472
Josh Coalsoncc682512002-06-08 04:53:42 +0000473void FLAC__metadata_object_delete_data(FLAC__StreamMetadata *object)
Josh Coalson90ced912002-05-30 05:23:38 +0000474{
475 FLAC__ASSERT(0 != object);
476
477 switch(object->type) {
478 case FLAC__METADATA_TYPE_STREAMINFO:
479 case FLAC__METADATA_TYPE_PADDING:
480 break;
481 case FLAC__METADATA_TYPE_APPLICATION:
Josh Coalson4fa90592002-12-04 07:01:37 +0000482 if(0 != object->data.application.data) {
Josh Coalson90ced912002-05-30 05:23:38 +0000483 free(object->data.application.data);
Josh Coalson4fa90592002-12-04 07:01:37 +0000484 object->data.application.data = 0;
485 }
Josh Coalson90ced912002-05-30 05:23:38 +0000486 break;
487 case FLAC__METADATA_TYPE_SEEKTABLE:
Josh Coalson4fa90592002-12-04 07:01:37 +0000488 if(0 != object->data.seek_table.points) {
Josh Coalson90ced912002-05-30 05:23:38 +0000489 free(object->data.seek_table.points);
Josh Coalson4fa90592002-12-04 07:01:37 +0000490 object->data.seek_table.points = 0;
491 }
Josh Coalson90ced912002-05-30 05:23:38 +0000492 break;
493 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
Josh Coalson4fa90592002-12-04 07:01:37 +0000494 if(0 != object->data.vorbis_comment.vendor_string.entry) {
Josh Coalson90ced912002-05-30 05:23:38 +0000495 free(object->data.vorbis_comment.vendor_string.entry);
Josh Coalson4fa90592002-12-04 07:01:37 +0000496 object->data.vorbis_comment.vendor_string.entry = 0;
497 }
Josh Coalson90ced912002-05-30 05:23:38 +0000498 if(0 != object->data.vorbis_comment.comments) {
499 FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0);
500 vorbiscomment_entry_array_delete_(object->data.vorbis_comment.comments, object->data.vorbis_comment.num_comments);
501 }
502 break;
Josh Coalson8e9c4512002-11-14 05:00:24 +0000503 case FLAC__METADATA_TYPE_CUESHEET:
504 if(0 != object->data.cue_sheet.tracks) {
505 FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0);
506 cuesheet_track_array_delete_(object->data.cue_sheet.tracks, object->data.cue_sheet.num_tracks);
507 }
508 break;
Josh Coalson90ced912002-05-30 05:23:38 +0000509 default:
Josh Coalsond0609472003-01-10 05:37:13 +0000510 if(0 != object->data.unknown.data) {
511 free(object->data.unknown.data);
512 object->data.unknown.data = 0;
513 }
514 break;
Josh Coalson90ced912002-05-30 05:23:38 +0000515 }
516}
517
Josh Coalson6afed9f2002-10-16 22:29:47 +0000518FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object)
Josh Coalson90ced912002-05-30 05:23:38 +0000519{
520 FLAC__metadata_object_delete_data(object);
521 free(object);
522}
523
Josh Coalsoncc682512002-06-08 04:53:42 +0000524static FLAC__bool compare_block_data_streaminfo_(const FLAC__StreamMetadata_StreamInfo *block1, const FLAC__StreamMetadata_StreamInfo *block2)
Josh Coalson57ba6f42002-06-07 05:27:37 +0000525{
526 if(block1->min_blocksize != block2->min_blocksize)
527 return false;
528 if(block1->max_blocksize != block2->max_blocksize)
529 return false;
530 if(block1->min_framesize != block2->min_framesize)
531 return false;
532 if(block1->max_framesize != block2->max_framesize)
533 return false;
534 if(block1->sample_rate != block2->sample_rate)
535 return false;
536 if(block1->channels != block2->channels)
537 return false;
538 if(block1->bits_per_sample != block2->bits_per_sample)
539 return false;
540 if(block1->total_samples != block2->total_samples)
541 return false;
542 if(0 != memcmp(block1->md5sum, block2->md5sum, 16))
543 return false;
544 return true;
545}
546
Josh Coalsoncc682512002-06-08 04:53:42 +0000547static FLAC__bool compare_block_data_application_(const FLAC__StreamMetadata_Application *block1, const FLAC__StreamMetadata_Application *block2, unsigned block_length)
Josh Coalson57ba6f42002-06-07 05:27:37 +0000548{
549 FLAC__ASSERT(0 != block1);
550 FLAC__ASSERT(0 != block2);
551 FLAC__ASSERT(block_length >= sizeof(block1->id));
552
553 if(0 != memcmp(block1->id, block2->id, sizeof(block1->id)))
554 return false;
555 if(0 != block1->data && 0 != block2->data)
556 return 0 == memcmp(block1->data, block2->data, block_length - sizeof(block1->id));
557 else
558 return block1->data == block2->data;
559}
560
Josh Coalsoncc682512002-06-08 04:53:42 +0000561static FLAC__bool compare_block_data_seektable_(const FLAC__StreamMetadata_SeekTable *block1, const FLAC__StreamMetadata_SeekTable *block2)
Josh Coalson57ba6f42002-06-07 05:27:37 +0000562{
563 unsigned i;
564
565 FLAC__ASSERT(0 != block1);
566 FLAC__ASSERT(0 != block2);
567
568 if(block1->num_points != block2->num_points)
569 return false;
570
571 if(0 != block1->points && 0 != block2->points) {
572 for(i = 0; i < block1->num_points; i++) {
573 if(block1->points[i].sample_number != block2->points[i].sample_number)
574 return false;
575 if(block1->points[i].stream_offset != block2->points[i].stream_offset)
576 return false;
577 if(block1->points[i].frame_samples != block2->points[i].frame_samples)
578 return false;
579 }
580 return true;
581 }
582 else
583 return block1->points == block2->points;
584}
585
Josh Coalsoncc682512002-06-08 04:53:42 +0000586static FLAC__bool compare_block_data_vorbiscomment_(const FLAC__StreamMetadata_VorbisComment *block1, const FLAC__StreamMetadata_VorbisComment *block2)
Josh Coalson57ba6f42002-06-07 05:27:37 +0000587{
588 unsigned i;
589
590 if(block1->vendor_string.length != block2->vendor_string.length)
591 return false;
592
593 if(0 != block1->vendor_string.entry && 0 != block2->vendor_string.entry) {
594 if(0 != memcmp(block1->vendor_string.entry, block2->vendor_string.entry, block1->vendor_string.length))
595 return false;
596 }
597 else if(block1->vendor_string.entry != block2->vendor_string.entry)
598 return false;
599
600 if(block1->num_comments != block2->num_comments)
601 return false;
602
603 for(i = 0; i < block1->num_comments; i++) {
604 if(0 != block1->comments[i].entry && 0 != block2->comments[i].entry) {
605 if(0 != memcmp(block1->comments[i].entry, block2->comments[i].entry, block1->comments[i].length))
606 return false;
607 }
608 else if(block1->comments[i].entry != block2->comments[i].entry)
609 return false;
610 }
611 return true;
612}
613
Josh Coalson8e9c4512002-11-14 05:00:24 +0000614static FLAC__bool compare_block_data_cuesheet_(const FLAC__StreamMetadata_CueSheet *block1, const FLAC__StreamMetadata_CueSheet *block2)
615{
616 unsigned i, j;
617
618 if(0 != strcmp(block1->media_catalog_number, block2->media_catalog_number))
619 return false;
620
621 if(block1->lead_in != block2->lead_in)
622 return false;
623
Josh Coalson8f0c71b2002-12-05 06:37:46 +0000624 if(block1->is_cd != block2->is_cd)
625 return false;
626
Josh Coalson8e9c4512002-11-14 05:00:24 +0000627 if(block1->num_tracks != block2->num_tracks)
628 return false;
629
630 if(0 != block1->tracks && 0 != block2->tracks) {
631 FLAC__ASSERT(block1->num_tracks > 0);
632 for(i = 0; i < block1->num_tracks; i++) {
633 if(block1->tracks[i].offset != block2->tracks[i].offset)
634 return false;
635 if(block1->tracks[i].number != block2->tracks[i].number)
636 return false;
637 if(0 != memcmp(block1->tracks[i].isrc, block2->tracks[i].isrc, sizeof(block1->tracks[i].isrc)))
638 return false;
639 if(block1->tracks[i].type != block2->tracks[i].type)
640 return false;
641 if(block1->tracks[i].pre_emphasis != block2->tracks[i].pre_emphasis)
642 return false;
643 if(block1->tracks[i].num_indices != block2->tracks[i].num_indices)
644 return false;
645 if(0 != block1->tracks[i].indices && 0 != block2->tracks[i].indices) {
646 FLAC__ASSERT(block1->tracks[i].num_indices > 0);
647 for(j = 0; j < block1->tracks[i].num_indices; j++) {
648 if(block1->tracks[i].indices[j].offset != block2->tracks[i].indices[j].offset)
649 return false;
650 if(block1->tracks[i].indices[j].number != block2->tracks[i].indices[j].number)
651 return false;
652 }
653 }
654 else if(block1->tracks[i].indices != block2->tracks[i].indices)
655 return false;
656 }
657 }
658 else if(block1->tracks != block2->tracks)
659 return false;
660 return true;
661}
662
Josh Coalsond0609472003-01-10 05:37:13 +0000663static FLAC__bool compare_block_data_unknown_(const FLAC__StreamMetadata_Unknown *block1, const FLAC__StreamMetadata_Unknown *block2, unsigned block_length)
664{
665 FLAC__ASSERT(0 != block1);
666 FLAC__ASSERT(0 != block2);
667
668 if(0 != block1->data && 0 != block2->data)
669 return 0 == memcmp(block1->data, block2->data, block_length);
670 else
671 return block1->data == block2->data;
672}
673
Josh Coalson6afed9f2002-10-16 22:29:47 +0000674FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2)
Josh Coalson57ba6f42002-06-07 05:27:37 +0000675{
Josh Coalsond8ab3462002-07-11 05:54:05 +0000676 FLAC__ASSERT(0 != block1);
677 FLAC__ASSERT(0 != block2);
678
Josh Coalson57ba6f42002-06-07 05:27:37 +0000679 if(block1->type != block2->type) {
680 return false;
Josh Coalson5a5de732002-08-01 06:37:11 +0000681 }
Josh Coalson57ba6f42002-06-07 05:27:37 +0000682 if(block1->is_last != block2->is_last) {
683 return false;
Josh Coalson5a5de732002-08-01 06:37:11 +0000684 }
Josh Coalson57ba6f42002-06-07 05:27:37 +0000685 if(block1->length != block2->length) {
686 return false;
Josh Coalson5a5de732002-08-01 06:37:11 +0000687 }
Josh Coalson57ba6f42002-06-07 05:27:37 +0000688 switch(block1->type) {
689 case FLAC__METADATA_TYPE_STREAMINFO:
690 return compare_block_data_streaminfo_(&block1->data.stream_info, &block2->data.stream_info);
691 case FLAC__METADATA_TYPE_PADDING:
692 return true; /* we don't compare the padding guts */
693 case FLAC__METADATA_TYPE_APPLICATION:
694 return compare_block_data_application_(&block1->data.application, &block2->data.application, block1->length);
695 case FLAC__METADATA_TYPE_SEEKTABLE:
696 return compare_block_data_seektable_(&block1->data.seek_table, &block2->data.seek_table);
697 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
698 return compare_block_data_vorbiscomment_(&block1->data.vorbis_comment, &block2->data.vorbis_comment);
Josh Coalson8e9c4512002-11-14 05:00:24 +0000699 case FLAC__METADATA_TYPE_CUESHEET:
700 return compare_block_data_cuesheet_(&block1->data.cue_sheet, &block2->data.cue_sheet);
Josh Coalson57ba6f42002-06-07 05:27:37 +0000701 default:
Josh Coalsond0609472003-01-10 05:37:13 +0000702 return compare_block_data_unknown_(&block1->data.unknown, &block2->data.unknown, block1->length);
Josh Coalson57ba6f42002-06-07 05:27:37 +0000703 }
704}
705
Josh Coalson6afed9f2002-10-16 22:29:47 +0000706FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy)
Josh Coalson90ced912002-05-30 05:23:38 +0000707{
708 FLAC__byte *save;
709
Josh Coalsond8ab3462002-07-11 05:54:05 +0000710 FLAC__ASSERT(0 != object);
Josh Coalson90ced912002-05-30 05:23:38 +0000711 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_APPLICATION);
712 FLAC__ASSERT((0 != data && length > 0) || (0 == data && length == 0 && copy == false));
713
714 save = object->data.application.data;
715
716 /* do the copy first so that if we fail we leave the object untouched */
717 if(copy) {
718 if(!copy_bytes_(&object->data.application.data, data, length))
719 return false;
720 }
721 else {
722 object->data.application.data = data;
723 }
724
725 if(0 != save)
726 free(save);
727
728 object->length = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8 + length;
729 return true;
730}
731
Josh Coalson6afed9f2002-10-16 22:29:47 +0000732FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points)
Josh Coalson90ced912002-05-30 05:23:38 +0000733{
734 FLAC__ASSERT(0 != object);
735 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
736
737 if(0 == object->data.seek_table.points) {
738 FLAC__ASSERT(object->data.seek_table.num_points == 0);
739 if(0 == new_num_points)
740 return true;
741 else if(0 == (object->data.seek_table.points = seekpoint_array_new_(new_num_points)))
742 return false;
743 }
744 else {
Josh Coalsoncc682512002-06-08 04:53:42 +0000745 const unsigned old_size = object->data.seek_table.num_points * sizeof(FLAC__StreamMetadata_SeekPoint);
746 const unsigned new_size = new_num_points * sizeof(FLAC__StreamMetadata_SeekPoint);
Josh Coalson90ced912002-05-30 05:23:38 +0000747
748 FLAC__ASSERT(object->data.seek_table.num_points > 0);
749
750 if(new_size == 0) {
751 free(object->data.seek_table.points);
752 object->data.seek_table.points = 0;
753 }
Josh Coalson5e3fcb22002-11-06 07:11:26 +0000754 else if(0 == (object->data.seek_table.points = (FLAC__StreamMetadata_SeekPoint*)realloc(object->data.seek_table.points, new_size)))
Josh Coalson90ced912002-05-30 05:23:38 +0000755 return false;
756
757 /* if growing, set new elements to placeholders */
758 if(new_size > old_size) {
759 unsigned i;
760 for(i = object->data.seek_table.num_points; i < new_num_points; i++) {
761 object->data.seek_table.points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
762 object->data.seek_table.points[i].stream_offset = 0;
763 object->data.seek_table.points[i].frame_samples = 0;
764 }
765 }
766 }
767
768 object->data.seek_table.num_points = new_num_points;
769
770 seektable_calculate_length_(object);
771 return true;
772}
773
Josh Coalson6afed9f2002-10-16 22:29:47 +0000774FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point)
Josh Coalson90ced912002-05-30 05:23:38 +0000775{
776 FLAC__ASSERT(0 != object);
777 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
Josh Coalson8e9c4512002-11-14 05:00:24 +0000778 FLAC__ASSERT(point_num < object->data.seek_table.num_points);
Josh Coalson90ced912002-05-30 05:23:38 +0000779
780 object->data.seek_table.points[point_num] = point;
781}
782
Josh Coalson6afed9f2002-10-16 22:29:47 +0000783FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point)
Josh Coalson90ced912002-05-30 05:23:38 +0000784{
785 int i;
786
787 FLAC__ASSERT(0 != object);
Josh Coalson6b8e5302002-05-31 06:23:09 +0000788 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
Josh Coalson8e9c4512002-11-14 05:00:24 +0000789 FLAC__ASSERT(point_num <= object->data.seek_table.num_points);
Josh Coalson90ced912002-05-30 05:23:38 +0000790
791 if(!FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points+1))
792 return false;
793
794 /* move all points >= point_num forward one space */
795 for(i = (int)object->data.seek_table.num_points-1; i > (int)point_num; i--)
796 object->data.seek_table.points[i] = object->data.seek_table.points[i-1];
797
798 FLAC__metadata_object_seektable_set_point(object, point_num, point);
799 seektable_calculate_length_(object);
800 return true;
801}
802
Josh Coalson6afed9f2002-10-16 22:29:47 +0000803FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num)
Josh Coalson90ced912002-05-30 05:23:38 +0000804{
805 unsigned i;
806
807 FLAC__ASSERT(0 != object);
808 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
Josh Coalson8e9c4512002-11-14 05:00:24 +0000809 FLAC__ASSERT(point_num < object->data.seek_table.num_points);
Josh Coalson90ced912002-05-30 05:23:38 +0000810
811 /* move all points > point_num backward one space */
812 for(i = point_num; i < object->data.seek_table.num_points-1; i++)
813 object->data.seek_table.points[i] = object->data.seek_table.points[i+1];
814
815 return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points-1);
816}
817
Josh Coalson6afed9f2002-10-16 22:29:47 +0000818FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object)
Josh Coalson28e08d82002-06-05 05:56:41 +0000819{
Josh Coalson28e08d82002-06-05 05:56:41 +0000820 FLAC__ASSERT(0 != object);
821 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
822
Josh Coalson0833f342002-07-15 05:31:55 +0000823 return FLAC__format_seektable_is_legal(&object->data.seek_table);
Josh Coalson28e08d82002-06-05 05:56:41 +0000824}
825
Josh Coalson6afed9f2002-10-16 22:29:47 +0000826FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num)
Josh Coalson5a5de732002-08-01 06:37:11 +0000827{
828 FLAC__ASSERT(0 != object);
829 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
830
831 if(num > 0)
832 /* WATCHOUT: we rely on the fact that growing the array adds PLACEHOLDERS at the end */
833 return FLAC__metadata_object_seektable_resize_points(object, object->data.seek_table.num_points + num);
834 else
835 return true;
836}
837
Josh Coalson6afed9f2002-10-16 22:29:47 +0000838FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number)
Josh Coalson5a5de732002-08-01 06:37:11 +0000839{
840 FLAC__StreamMetadata_SeekTable *seek_table;
841
842 FLAC__ASSERT(0 != object);
843 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
844
845 seek_table = &object->data.seek_table;
846
847 if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + 1))
848 return false;
849
850 seek_table->points[seek_table->num_points - 1].sample_number = sample_number;
851 seek_table->points[seek_table->num_points - 1].stream_offset = 0;
852 seek_table->points[seek_table->num_points - 1].frame_samples = 0;
853
854 return true;
855}
856
Josh Coalson6afed9f2002-10-16 22:29:47 +0000857FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num)
Josh Coalson5a5de732002-08-01 06:37:11 +0000858{
859 FLAC__ASSERT(0 != object);
860 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
861 FLAC__ASSERT(0 != sample_numbers || num == 0);
862
863 if(num > 0) {
864 FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table;
865 unsigned i, j;
866
867 i = seek_table->num_points;
868
869 if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num))
870 return false;
871
872 for(j = 0; j < num; i++, j++) {
873 seek_table->points[i].sample_number = sample_numbers[j];
874 seek_table->points[i].stream_offset = 0;
875 seek_table->points[i].frame_samples = 0;
876 }
877 }
878
879 return true;
880}
881
Josh Coalson6afed9f2002-10-16 22:29:47 +0000882FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples)
Josh Coalson5a5de732002-08-01 06:37:11 +0000883{
884 FLAC__ASSERT(0 != object);
885 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
886 FLAC__ASSERT(total_samples > 0);
887
888 if(num > 0) {
889 FLAC__StreamMetadata_SeekTable *seek_table = &object->data.seek_table;
890 unsigned i, j;
891
892 i = seek_table->num_points;
893
894 if(!FLAC__metadata_object_seektable_resize_points(object, seek_table->num_points + num))
895 return false;
896
897 for(j = 0; j < num; i++, j++) {
898 seek_table->points[i].sample_number = total_samples * (FLAC__uint64)j / (FLAC__uint64)num;
899 seek_table->points[i].stream_offset = 0;
900 seek_table->points[i].frame_samples = 0;
901 }
902 }
903
904 return true;
905}
906
Josh Coalson6afed9f2002-10-16 22:29:47 +0000907FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact)
Josh Coalson5a5de732002-08-01 06:37:11 +0000908{
909 unsigned unique;
910
911 FLAC__ASSERT(0 != object);
912 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_SEEKTABLE);
913
914 unique = FLAC__format_seektable_sort(&object->data.seek_table);
915
916 return !compact || FLAC__metadata_object_seektable_resize_points(object, unique);
917}
918
Josh Coalson6afed9f2002-10-16 22:29:47 +0000919FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
Josh Coalson90ced912002-05-30 05:23:38 +0000920{
Josh Coalson6b8e5302002-05-31 06:23:09 +0000921 return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.vendor_string, &entry, copy);
Josh Coalson90ced912002-05-30 05:23:38 +0000922}
923
Josh Coalson6afed9f2002-10-16 22:29:47 +0000924FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments)
Josh Coalson90ced912002-05-30 05:23:38 +0000925{
926 FLAC__ASSERT(0 != object);
927 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
928
929 if(0 == object->data.vorbis_comment.comments) {
930 FLAC__ASSERT(object->data.vorbis_comment.num_comments == 0);
931 if(0 == new_num_comments)
932 return true;
933 else if(0 == (object->data.vorbis_comment.comments = vorbiscomment_entry_array_new_(new_num_comments)))
934 return false;
935 }
936 else {
Josh Coalsoncc682512002-06-08 04:53:42 +0000937 const unsigned old_size = object->data.vorbis_comment.num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry);
938 const unsigned new_size = new_num_comments * sizeof(FLAC__StreamMetadata_VorbisComment_Entry);
Josh Coalson90ced912002-05-30 05:23:38 +0000939
940 FLAC__ASSERT(object->data.vorbis_comment.num_comments > 0);
941
942 /* if shrinking, free the truncated entries */
943 if(new_num_comments < object->data.vorbis_comment.num_comments) {
944 unsigned i;
945 for(i = new_num_comments; i < object->data.vorbis_comment.num_comments; i++)
946 if(0 != object->data.vorbis_comment.comments[i].entry)
947 free(object->data.vorbis_comment.comments[i].entry);
948 }
949
950 if(new_size == 0) {
951 free(object->data.vorbis_comment.comments);
952 object->data.vorbis_comment.comments = 0;
953 }
Josh Coalson5e3fcb22002-11-06 07:11:26 +0000954 else if(0 == (object->data.vorbis_comment.comments = (FLAC__StreamMetadata_VorbisComment_Entry*)realloc(object->data.vorbis_comment.comments, new_size)))
Josh Coalson90ced912002-05-30 05:23:38 +0000955 return false;
956
957 /* if growing, zero all the length/pointers of new elements */
958 if(new_size > old_size)
959 memset(object->data.vorbis_comment.comments + object->data.vorbis_comment.num_comments, 0, new_size - old_size);
960 }
961
962 object->data.vorbis_comment.num_comments = new_num_comments;
963
964 vorbiscomment_calculate_length_(object);
965 return true;
966}
967
Josh Coalson6afed9f2002-10-16 22:29:47 +0000968FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
Josh Coalson90ced912002-05-30 05:23:38 +0000969{
Josh Coalsonfb993862003-01-15 03:18:07 +0000970 FLAC__ASSERT(0 != object);
971 FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments);
972
Josh Coalson6b8e5302002-05-31 06:23:09 +0000973 return vorbiscomment_set_entry_(object, &object->data.vorbis_comment.comments[comment_num], &entry, copy);
Josh Coalson90ced912002-05-30 05:23:38 +0000974}
975
Josh Coalson6afed9f2002-10-16 22:29:47 +0000976FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy)
Josh Coalson90ced912002-05-30 05:23:38 +0000977{
Josh Coalsoncc682512002-06-08 04:53:42 +0000978 FLAC__StreamMetadata_VorbisComment *vc;
Josh Coalson90ced912002-05-30 05:23:38 +0000979
980 FLAC__ASSERT(0 != object);
Josh Coalson90ced912002-05-30 05:23:38 +0000981 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
Josh Coalson8e9c4512002-11-14 05:00:24 +0000982 FLAC__ASSERT(comment_num <= object->data.vorbis_comment.num_comments);
Josh Coalson90ced912002-05-30 05:23:38 +0000983
Josh Coalson6b8e5302002-05-31 06:23:09 +0000984 vc = &object->data.vorbis_comment;
985
986 if(!FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments+1))
Josh Coalson90ced912002-05-30 05:23:38 +0000987 return false;
988
989 /* move all comments >= comment_num forward one space */
Josh Coalsoncc682512002-06-08 04:53:42 +0000990 memmove(&vc->comments[comment_num+1], &vc->comments[comment_num], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-1-comment_num));
Josh Coalson6b8e5302002-05-31 06:23:09 +0000991 vc->comments[comment_num].length = 0;
992 vc->comments[comment_num].entry = 0;
Josh Coalson90ced912002-05-30 05:23:38 +0000993
994 return FLAC__metadata_object_vorbiscomment_set_comment(object, comment_num, entry, copy);
995}
996
Josh Coalson6afed9f2002-10-16 22:29:47 +0000997FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num)
Josh Coalson90ced912002-05-30 05:23:38 +0000998{
Josh Coalsoncc682512002-06-08 04:53:42 +0000999 FLAC__StreamMetadata_VorbisComment *vc;
Josh Coalson90ced912002-05-30 05:23:38 +00001000
1001 FLAC__ASSERT(0 != object);
1002 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
Josh Coalson8e9c4512002-11-14 05:00:24 +00001003 FLAC__ASSERT(comment_num < object->data.vorbis_comment.num_comments);
Josh Coalson90ced912002-05-30 05:23:38 +00001004
Josh Coalson6b8e5302002-05-31 06:23:09 +00001005 vc = &object->data.vorbis_comment;
1006
Josh Coalson90ced912002-05-30 05:23:38 +00001007 /* free the comment at comment_num */
Josh Coalson6b8e5302002-05-31 06:23:09 +00001008 if(0 != vc->comments[comment_num].entry)
1009 free(vc->comments[comment_num].entry);
Josh Coalson90ced912002-05-30 05:23:38 +00001010
1011 /* move all comments > comment_num backward one space */
Josh Coalsoncc682512002-06-08 04:53:42 +00001012 memmove(&vc->comments[comment_num], &vc->comments[comment_num+1], sizeof(FLAC__StreamMetadata_VorbisComment_Entry)*(vc->num_comments-comment_num-1));
Josh Coalson6b8e5302002-05-31 06:23:09 +00001013 vc->comments[vc->num_comments-1].length = 0;
1014 vc->comments[vc->num_comments-1].entry = 0;
Josh Coalson90ced912002-05-30 05:23:38 +00001015
Josh Coalson6b8e5302002-05-31 06:23:09 +00001016 return FLAC__metadata_object_vorbiscomment_resize_comments(object, vc->num_comments-1);
Josh Coalson90ced912002-05-30 05:23:38 +00001017}
Josh Coalson45bb9882002-10-26 04:34:16 +00001018
1019FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry *entry, const char *field_name, unsigned field_name_length)
1020{
Josh Coalson5e3fcb22002-11-06 07:11:26 +00001021 const FLAC__byte *eq = (FLAC__byte*)memchr(entry->entry, '=', entry->length);
Josh Coalson45bb9882002-10-26 04:34:16 +00001022#if defined _MSC_VER || defined __MINGW32__
1023#define FLAC__STRNCASECMP strnicmp
1024#else
1025#define FLAC__STRNCASECMP strncasecmp
1026#endif
Josh Coalson5e3fcb22002-11-06 07:11:26 +00001027 return (0 != eq && (unsigned)(eq-entry->entry) == field_name_length && 0 == FLAC__STRNCASECMP(field_name, (const char *)entry->entry, field_name_length));
Josh Coalson45bb9882002-10-26 04:34:16 +00001028#undef FLAC__STRNCASECMP
1029}
1030
Josh Coalsonb667e702002-11-05 07:24:33 +00001031FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name)
Josh Coalson45bb9882002-10-26 04:34:16 +00001032{
1033 const unsigned field_name_length = strlen(field_name);
1034 unsigned i;
1035
1036 FLAC__ASSERT(0 != object);
1037 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
1038
1039 for(i = offset; i < object->data.vorbis_comment.num_comments; i++) {
1040 if(FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments + i, field_name, field_name_length))
1041 return (int)i;
1042 }
1043
1044 return -1;
1045}
1046
1047FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name)
1048{
1049 const unsigned field_name_length = strlen(field_name);
1050 unsigned i;
1051
1052 FLAC__ASSERT(0 != object);
1053 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
1054
1055 for(i = 0; i < object->data.vorbis_comment.num_comments; i++) {
1056 if(FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments + i, field_name, field_name_length)) {
1057 if(!FLAC__metadata_object_vorbiscomment_delete_comment(object, i))
1058 return -1;
1059 else
1060 return 1;
1061 }
1062 }
1063
1064 return 0;
1065}
1066
1067FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name)
1068{
1069 FLAC__bool ok = true;
1070 unsigned matching = 0;
1071 const unsigned field_name_length = strlen(field_name);
1072 int i;
1073
1074 FLAC__ASSERT(0 != object);
1075 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
1076
1077 /* must delete from end to start otherwise it will interfere with our iteration */
1078 for(i = (int)object->data.vorbis_comment.num_comments - 1; ok && i >= 0; i--) {
1079 if(FLAC__metadata_object_vorbiscomment_entry_matches(object->data.vorbis_comment.comments + i, field_name, field_name_length)) {
1080 matching++;
1081 ok &= FLAC__metadata_object_vorbiscomment_delete_comment(object, (unsigned)i);
1082 }
1083 }
1084
1085 return ok? (int)matching : -1;
1086}
Josh Coalson8e9c4512002-11-14 05:00:24 +00001087
Josh Coalsondf7240a2002-11-16 06:32:30 +00001088FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new()
1089{
1090 return (FLAC__StreamMetadata_CueSheet_Track*)calloc(1, sizeof(FLAC__StreamMetadata_CueSheet_Track));
1091}
1092
1093FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object)
1094{
1095 FLAC__StreamMetadata_CueSheet_Track *to;
1096
1097 FLAC__ASSERT(0 != object);
1098
1099 if(0 != (to = FLAC__metadata_object_cuesheet_track_new())) {
1100 if(!copy_track_(to, object)) {
1101 FLAC__metadata_object_cuesheet_track_delete(to);
1102 return 0;
1103 }
1104 }
1105
1106 return to;
1107}
1108
1109void FLAC__metadata_object_cuesheet_track_delete_data(FLAC__StreamMetadata_CueSheet_Track *object)
1110{
1111 FLAC__ASSERT(0 != object);
1112
1113 if(0 != object->indices) {
1114 FLAC__ASSERT(object->num_indices > 0);
1115 free(object->indices);
1116 }
1117}
1118
1119FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object)
1120{
1121 FLAC__metadata_object_cuesheet_track_delete_data(object);
1122 free(object);
1123}
1124
Josh Coalson8e9c4512002-11-14 05:00:24 +00001125FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices)
1126{
1127 FLAC__StreamMetadata_CueSheet_Track *track;
1128 FLAC__ASSERT(0 != object);
1129 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
1130 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
1131
1132 track = &object->data.cue_sheet.tracks[track_num];
1133
1134 if(0 == track->indices) {
1135 FLAC__ASSERT(track->num_indices == 0);
1136 if(0 == new_num_indices)
1137 return true;
1138 else if(0 == (track->indices = cuesheet_track_index_array_new_(new_num_indices)))
1139 return false;
1140 }
1141 else {
1142 const unsigned old_size = track->num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index);
1143 const unsigned new_size = new_num_indices * sizeof(FLAC__StreamMetadata_CueSheet_Index);
1144
1145 FLAC__ASSERT(track->num_indices > 0);
1146
1147 if(new_size == 0) {
1148 free(track->indices);
1149 track->indices = 0;
1150 }
1151 else if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)realloc(track->indices, new_size)))
1152 return false;
1153
1154 /* if growing, zero all the lengths/pointers of new elements */
1155 if(new_size > old_size)
1156 memset(track->indices + track->num_indices, 0, new_size - old_size);
1157 }
1158
1159 track->num_indices = new_num_indices;
1160
1161 cuesheet_calculate_length_(object);
1162 return true;
1163}
1164
1165FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num, FLAC__StreamMetadata_CueSheet_Index index)
1166{
1167 FLAC__StreamMetadata_CueSheet_Track *track;
1168
1169 FLAC__ASSERT(0 != object);
1170 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
1171 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
1172 FLAC__ASSERT(index_num <= object->data.cue_sheet.tracks[track_num].num_indices);
1173
1174 track = &object->data.cue_sheet.tracks[track_num];
1175
1176 if(!FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices+1))
1177 return false;
1178
1179 /* move all indices >= index_num forward one space */
1180 memmove(&track->indices[index_num+1], &track->indices[index_num], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-1-index_num));
1181
1182 track->indices[index_num] = index;
1183 cuesheet_calculate_length_(object);
1184 return true;
1185}
1186
Josh Coalson3b026e82002-11-21 06:41:01 +00001187FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num)
1188{
1189 FLAC__StreamMetadata_CueSheet_Index index;
1190 memset(&index, 0, sizeof(index));
Josh Coalsonbfc8e312002-11-21 09:00:25 +00001191 return FLAC__metadata_object_cuesheet_track_insert_index(object, track_num, index_num, index);
Josh Coalson3b026e82002-11-21 06:41:01 +00001192}
1193
Josh Coalson8e9c4512002-11-14 05:00:24 +00001194FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num)
1195{
1196 FLAC__StreamMetadata_CueSheet_Track *track;
1197
1198 FLAC__ASSERT(0 != object);
1199 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
1200 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
1201 FLAC__ASSERT(index_num < object->data.cue_sheet.tracks[track_num].num_indices);
1202
1203 track = &object->data.cue_sheet.tracks[track_num];
1204
1205 /* move all indices > index_num backward one space */
Josh Coalson4fa90592002-12-04 07:01:37 +00001206 memmove(&track->indices[index_num], &track->indices[index_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Index)*(track->num_indices-index_num-1));
Josh Coalson8e9c4512002-11-14 05:00:24 +00001207
1208 FLAC__metadata_object_cuesheet_track_resize_indices(object, track_num, track->num_indices-1);
1209 cuesheet_calculate_length_(object);
1210 return true;
1211}
1212
1213FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks)
1214{
1215 FLAC__ASSERT(0 != object);
1216 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
1217
1218 if(0 == object->data.cue_sheet.tracks) {
1219 FLAC__ASSERT(object->data.cue_sheet.num_tracks == 0);
1220 if(0 == new_num_tracks)
1221 return true;
1222 else if(0 == (object->data.cue_sheet.tracks = cuesheet_track_array_new_(new_num_tracks)))
1223 return false;
1224 }
1225 else {
1226 const unsigned old_size = object->data.cue_sheet.num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track);
1227 const unsigned new_size = new_num_tracks * sizeof(FLAC__StreamMetadata_CueSheet_Track);
1228
1229 FLAC__ASSERT(object->data.cue_sheet.num_tracks > 0);
1230
1231 /* if shrinking, free the truncated entries */
1232 if(new_num_tracks < object->data.cue_sheet.num_tracks) {
1233 unsigned i;
1234 for(i = new_num_tracks; i < object->data.cue_sheet.num_tracks; i++)
1235 if(0 != object->data.cue_sheet.tracks[i].indices)
1236 free(object->data.cue_sheet.tracks[i].indices);
1237 }
1238
1239 if(new_size == 0) {
1240 free(object->data.cue_sheet.tracks);
1241 object->data.cue_sheet.tracks = 0;
1242 }
1243 else if(0 == (object->data.cue_sheet.tracks = (FLAC__StreamMetadata_CueSheet_Track*)realloc(object->data.cue_sheet.tracks, new_size)))
1244 return false;
1245
1246 /* if growing, zero all the lengths/pointers of new elements */
1247 if(new_size > old_size)
1248 memset(object->data.cue_sheet.tracks + object->data.cue_sheet.num_tracks, 0, new_size - old_size);
1249 }
1250
1251 object->data.cue_sheet.num_tracks = new_num_tracks;
1252
1253 cuesheet_calculate_length_(object);
1254 return true;
1255}
1256
Josh Coalsondf7240a2002-11-16 06:32:30 +00001257FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy)
Josh Coalson8e9c4512002-11-14 05:00:24 +00001258{
Josh Coalsonfb993862003-01-15 03:18:07 +00001259 FLAC__ASSERT(0 != object);
1260 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
1261
Josh Coalsondf7240a2002-11-16 06:32:30 +00001262 return cuesheet_set_track_(object, object->data.cue_sheet.tracks + track_num, track, copy);
Josh Coalson8e9c4512002-11-14 05:00:24 +00001263}
1264
Josh Coalsondf7240a2002-11-16 06:32:30 +00001265FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy)
Josh Coalson8e9c4512002-11-14 05:00:24 +00001266{
1267 FLAC__StreamMetadata_CueSheet *cs;
1268
1269 FLAC__ASSERT(0 != object);
1270 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
1271 FLAC__ASSERT(track_num <= object->data.cue_sheet.num_tracks);
1272
1273 cs = &object->data.cue_sheet;
1274
1275 if(!FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks+1))
1276 return false;
1277
1278 /* move all tracks >= track_num forward one space */
1279 memmove(&cs->tracks[track_num+1], &cs->tracks[track_num], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(cs->num_tracks-1-track_num));
1280 cs->tracks[track_num].num_indices = 0;
1281 cs->tracks[track_num].indices = 0;
1282
1283 return FLAC__metadata_object_cuesheet_set_track(object, track_num, track, copy);
1284}
1285
Josh Coalson3b026e82002-11-21 06:41:01 +00001286FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num)
1287{
1288 FLAC__StreamMetadata_CueSheet_Track track;
1289 memset(&track, 0, sizeof(track));
1290 return FLAC__metadata_object_cuesheet_insert_track(object, track_num, &track, /*copy=*/false);
1291}
1292
Josh Coalson8e9c4512002-11-14 05:00:24 +00001293FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num)
1294{
1295 FLAC__StreamMetadata_CueSheet *cs;
1296
1297 FLAC__ASSERT(0 != object);
1298 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
1299 FLAC__ASSERT(track_num < object->data.cue_sheet.num_tracks);
1300
1301 cs = &object->data.cue_sheet;
1302
1303 /* free the track at track_num */
1304 if(0 != cs->tracks[track_num].indices)
1305 free(cs->tracks[track_num].indices);
1306
1307 /* move all tracks > track_num backward one space */
1308 memmove(&cs->tracks[track_num], &cs->tracks[track_num+1], sizeof(FLAC__StreamMetadata_CueSheet_Track)*(cs->num_tracks-track_num-1));
1309 cs->tracks[cs->num_tracks-1].num_indices = 0;
1310 cs->tracks[cs->num_tracks-1].indices = 0;
1311
1312 return FLAC__metadata_object_cuesheet_resize_tracks(object, cs->num_tracks-1);
1313}
1314
1315FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation)
1316{
1317 FLAC__ASSERT(0 != object);
1318 FLAC__ASSERT(object->type == FLAC__METADATA_TYPE_CUESHEET);
1319
1320 return FLAC__format_cuesheet_is_legal(&object->data.cue_sheet, check_cd_da_subset, violation);
1321}