minor syntax
[flac.git] / src / test_libFLAC / decoders.c
1 /* test_libFLAC - Unit tester for libFLAC
2  * Copyright (C) 2002,2003,2004,2005,2006  Josh Coalson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18
19 #if HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include <errno.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #if defined _MSC_VER || defined __MINGW32__
28 #if _MSC_VER <= 1200 /* @@@ [2G limit] */
29 #define fseeko fseek
30 #define ftello ftell
31 #endif
32 #endif
33 #include "decoders.h"
34 #include "FLAC/assert.h"
35 #include "FLAC/stream_decoder.h"
36 #include "share/grabbag.h"
37 #include "test_libs_common/file_utils_flac.h"
38 #include "test_libs_common/metadata_utils.h"
39
40 typedef enum {
41         LAYER_STREAM = 0, /* FLAC__stream_decoder_init_[ogg_]stream() without seeking */
42         LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_[ogg_]stream() with seeking */
43         LAYER_FILE, /* FLAC__stream_decoder_init_[ogg_]FILE() */
44         LAYER_FILENAME /* FLAC__stream_decoder_init_[ogg_]file() */
45 } Layer;
46
47 static const char * const LayerString[] = {
48         "Stream",
49         "Seekable Stream",
50         "FILE*",
51         "Filename"
52 };
53
54 typedef struct {
55         Layer layer;
56         FILE *file;
57         unsigned current_metadata_number;
58         FLAC__bool ignore_errors;
59         FLAC__bool error_occurred;
60 } StreamDecoderClientData;
61
62 static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
63 static FLAC__StreamMetadata *expected_metadata_sequence_[9];
64 static unsigned num_expected_;
65 static off_t flacfilesize_;
66
67 static const char *flacfilename(FLAC__bool is_ogg)
68 {
69         return is_ogg? "metadata.ogg" : "metadata.flac";
70 }
71
72 static FLAC__bool die_(const char *msg)
73 {
74         printf("ERROR: %s\n", msg);
75         return false;
76 }
77
78 static FLAC__bool die_s_(const char *msg, const FLAC__StreamDecoder *decoder)
79 {
80         FLAC__StreamDecoderState state = FLAC__stream_decoder_get_state(decoder);
81
82         if(msg)
83                 printf("FAILED, %s", msg);
84         else
85                 printf("FAILED");
86
87         printf(", state = %u (%s)\n", (unsigned)state, FLAC__StreamDecoderStateString[state]);
88
89         return false;
90 }
91
92 static void init_metadata_blocks_()
93 {
94         mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
95 }
96
97 static void free_metadata_blocks_()
98 {
99         mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
100 }
101
102 static FLAC__bool generate_file_(FLAC__bool is_ogg)
103 {
104         printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":"");
105
106         num_expected_ = 0;
107         expected_metadata_sequence_[num_expected_++] = &padding_;
108         expected_metadata_sequence_[num_expected_++] = &seektable_;
109         expected_metadata_sequence_[num_expected_++] = &application1_;
110         expected_metadata_sequence_[num_expected_++] = &application2_;
111         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
112         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
113         expected_metadata_sequence_[num_expected_++] = &picture_;
114         expected_metadata_sequence_[num_expected_++] = &unknown_;
115         /* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
116
117         if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
118                 return die_("creating the encoded file");
119
120         return true;
121 }
122
123 static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
124 {
125         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
126         const size_t requested_bytes = *bytes;
127
128         (void)decoder;
129
130         if(0 == dcd) {
131                 printf("ERROR: client_data in read callback is NULL\n");
132                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
133         }
134
135         if(dcd->error_occurred)
136                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
137
138         if(feof(dcd->file)) {
139                 *bytes = 0;
140                 return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
141         }
142         else if(requested_bytes > 0) {
143                 *bytes = fread(buffer, 1, requested_bytes, dcd->file);
144                 if(*bytes == 0) {
145                         if(feof(dcd->file))
146                                 return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
147                         else
148                                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
149                 }
150                 else {
151                         return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
152                 }
153         }
154         else
155                 return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
156 }
157
158 static FLAC__StreamDecoderSeekStatus stream_decoder_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
159 {
160         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
161
162         (void)decoder;
163
164         if(0 == dcd) {
165                 printf("ERROR: client_data in seek callback is NULL\n");
166                 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
167         }
168
169         if(dcd->error_occurred)
170                 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
171
172         if(fseeko(dcd->file, (off_t)absolute_byte_offset, SEEK_SET) < 0) {
173                 dcd->error_occurred = true;
174                 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
175         }
176
177         return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
178 }
179
180 static FLAC__StreamDecoderTellStatus stream_decoder_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
181 {
182         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
183         off_t offset;
184
185         (void)decoder;
186
187         if(0 == dcd) {
188                 printf("ERROR: client_data in tell callback is NULL\n");
189                 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
190         }
191
192         if(dcd->error_occurred)
193                 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
194
195         offset = ftello(dcd->file);
196         *absolute_byte_offset = (FLAC__uint64)offset;
197
198         if(offset < 0) {
199                 dcd->error_occurred = true;
200                 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
201         }
202
203         return FLAC__STREAM_DECODER_TELL_STATUS_OK;
204 }
205
206 static FLAC__StreamDecoderLengthStatus stream_decoder_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
207 {
208         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
209
210         (void)decoder;
211
212         if(0 == dcd) {
213                 printf("ERROR: client_data in length callback is NULL\n");
214                 return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
215         }
216
217         if(dcd->error_occurred)
218                 return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
219
220         *stream_length = (FLAC__uint64)flacfilesize_;
221         return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
222 }
223
224 static FLAC__bool stream_decoder_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
225 {
226         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
227
228         (void)decoder;
229
230         if(0 == dcd) {
231                 printf("ERROR: client_data in eof callback is NULL\n");
232                 return true;
233         }
234
235         if(dcd->error_occurred)
236                 return true;
237
238         return feof(dcd->file);
239 }
240
241 static FLAC__StreamDecoderWriteStatus stream_decoder_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
242 {
243         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
244
245         (void)decoder, (void)buffer;
246
247         if(0 == dcd) {
248                 printf("ERROR: client_data in write callback is NULL\n");
249                 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
250         }
251
252         if(dcd->error_occurred)
253                 return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
254
255         if(
256                 (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
257                 (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
258         ) {
259                 printf("content... ");
260                 fflush(stdout);
261         }
262
263         return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
264 }
265
266 static void stream_decoder_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
267 {
268         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
269
270         (void)decoder;
271
272         if(0 == dcd) {
273                 printf("ERROR: client_data in metadata callback is NULL\n");
274                 return;
275         }
276
277         if(dcd->error_occurred)
278                 return;
279
280         printf("%d... ", dcd->current_metadata_number);
281         fflush(stdout);
282
283         if(dcd->current_metadata_number >= num_expected_) {
284                 (void)die_("got more metadata blocks than expected");
285                 dcd->error_occurred = true;
286         }
287         else {
288                 if(!mutils__compare_block(expected_metadata_sequence_[dcd->current_metadata_number], metadata)) {
289                         (void)die_("metadata block mismatch");
290                         dcd->error_occurred = true;
291                 }
292         }
293         dcd->current_metadata_number++;
294 }
295
296 static void stream_decoder_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
297 {
298         StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
299
300         (void)decoder;
301
302         if(0 == dcd) {
303                 printf("ERROR: client_data in error callback is NULL\n");
304                 return;
305         }
306
307         if(!dcd->ignore_errors) {
308                 printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, FLAC__StreamDecoderErrorStatusString[status]);
309                 dcd->error_occurred = true;
310         }
311 }
312
313 static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, StreamDecoderClientData *dcd, FLAC__bool is_ogg)
314 {
315         FLAC__StreamDecoderInitStatus init_status;
316
317         if(!FLAC__stream_decoder_set_md5_checking(decoder, true))
318                 return die_s_("at FLAC__stream_decoder_set_md5_checking(), returned false", decoder);
319
320         /* for FLAC__stream_encoder_init_FILE(), the FLAC__stream_encoder_finish() closes the file so we have to keep re-opening: */
321         if(dcd->layer == LAYER_FILE) {
322                 printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
323                 dcd->file = fopen(flacfilename(is_ogg), "rb");
324                 if(0 == dcd->file) {
325                         printf("ERROR (%s)\n", strerror(errno));
326                         return false;
327                 }
328                 printf("OK\n");
329         }
330
331         switch(dcd->layer) {
332                 case LAYER_STREAM:
333                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
334                         init_status = is_ogg?
335                                 FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
336                                 FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd)
337                         ;
338                         break;
339                 case LAYER_SEEKABLE_STREAM:
340                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
341                         init_status = is_ogg?
342                                 FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
343                                 FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
344                         break;
345                 case LAYER_FILE:
346                         printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":"");
347                         init_status = is_ogg?
348                                 FLAC__stream_decoder_init_ogg_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
349                                 FLAC__stream_decoder_init_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
350                         break;
351                 case LAYER_FILENAME:
352                         printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":"");
353                         init_status = is_ogg?
354                                 FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
355                                 FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
356                         break;
357                 default:
358                         die_("internal error 000");
359                         return false;
360         }
361         if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
362                 return die_s_(0, decoder);
363         printf("OK\n");
364
365         dcd->current_metadata_number = 0;
366
367         if(dcd->layer < LAYER_FILE && fseeko(dcd->file, 0, SEEK_SET) < 0) {
368                 printf("FAILED rewinding input, errno = %d\n", errno);
369                 return false;
370         }
371
372         printf("testing FLAC__stream_decoder_process_until_end_of_stream()... ");
373         if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
374                 return die_s_("returned false", decoder);
375         printf("OK\n");
376
377         printf("testing FLAC__stream_decoder_finish()... ");
378         FLAC__stream_decoder_finish(decoder);
379         printf("OK\n");
380
381         return true;
382 }
383
384 static FLAC__bool test_stream_decoder(Layer layer, FLAC__bool is_ogg)
385 {
386         FLAC__StreamDecoder *decoder;
387         FLAC__StreamDecoderInitStatus init_status;
388         FLAC__StreamDecoderState state;
389         StreamDecoderClientData decoder_client_data;
390         FLAC__bool expect;
391
392         decoder_client_data.layer = layer;
393
394         printf("\n+++ libFLAC unit test: FLAC__StreamDecoder (layer: %s, format: %s)\n\n", LayerString[layer], is_ogg? "Ogg FLAC" : "FLAC");
395
396         printf("testing FLAC__stream_decoder_new()... ");
397         decoder = FLAC__stream_decoder_new();
398         if(0 == decoder) {
399                 printf("FAILED, returned NULL\n");
400                 return false;
401         }
402         printf("OK\n");
403
404         printf("testing FLAC__stream_decoder_delete()... ");
405         FLAC__stream_decoder_delete(decoder);
406         printf("OK\n");
407
408         printf("testing FLAC__stream_decoder_new()... ");
409         decoder = FLAC__stream_decoder_new();
410         if(0 == decoder) {
411                 printf("FAILED, returned NULL\n");
412                 return false;
413         }
414         printf("OK\n");
415
416         switch(layer) {
417                 case LAYER_STREAM:
418                 case LAYER_SEEKABLE_STREAM:
419                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
420                         init_status = is_ogg?
421                                 FLAC__stream_decoder_init_ogg_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0) :
422                                 FLAC__stream_decoder_init_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0);
423                         break;
424                 case LAYER_FILE:
425                         printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":"");
426                         init_status = is_ogg?
427                                 FLAC__stream_decoder_init_ogg_FILE(decoder, stdin, 0, 0, 0, 0) :
428                                 FLAC__stream_decoder_init_FILE(decoder, stdin, 0, 0, 0, 0);
429                         break;
430                 case LAYER_FILENAME:
431                         printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":"");
432                         init_status = is_ogg?
433                                 FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0) :
434                                 FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0);
435                         break;
436                 default:
437                         die_("internal error 003");
438                         return false;
439         }
440         if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS)
441                 return die_s_(0, decoder);
442         printf("OK\n");
443
444         printf("testing FLAC__stream_decoder_delete()... ");
445         FLAC__stream_decoder_delete(decoder);
446         printf("OK\n");
447
448         num_expected_ = 0;
449         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
450
451         printf("testing FLAC__stream_decoder_new()... ");
452         decoder = FLAC__stream_decoder_new();
453         if(0 == decoder) {
454                 printf("FAILED, returned NULL\n");
455                 return false;
456         }
457         printf("OK\n");
458
459         if(is_ogg) {
460                 printf("testing FLAC__stream_decoder_set_ogg_serial_number()... ");
461                 if(!FLAC__stream_decoder_set_ogg_serial_number(decoder, file_utils__ogg_serial_number))
462                         return die_s_("returned false", decoder);
463                 printf("OK\n");
464         }
465
466         printf("testing FLAC__stream_decoder_set_md5_checking()... ");
467         if(!FLAC__stream_decoder_set_md5_checking(decoder, true))
468                 return die_s_("returned false", decoder);
469         printf("OK\n");
470
471         if(layer < LAYER_FILENAME) {
472                 printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
473                 decoder_client_data.file = fopen(flacfilename(is_ogg), "rb");
474                 if(0 == decoder_client_data.file) {
475                         printf("ERROR (%s)\n", strerror(errno));
476                         return false;
477                 }
478                 printf("OK\n");
479         }
480
481         switch(layer) {
482                 case LAYER_STREAM:
483                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
484                         init_status = is_ogg?
485                                 FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) :
486                                 FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data);
487                         break;
488                 case LAYER_SEEKABLE_STREAM:
489                         printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
490                         init_status = is_ogg?
491                                 FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) :
492                                 FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data);
493                         break;
494                 case LAYER_FILE:
495                         printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":"");
496                         init_status = is_ogg?
497                                 FLAC__stream_decoder_init_ogg_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) :
498                                 FLAC__stream_decoder_init_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data);
499                         break;
500                 case LAYER_FILENAME:
501                         printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":"");
502                         init_status = is_ogg?
503                                 FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) :
504                                 FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data);
505                         break;
506                 default:
507                         die_("internal error 009");
508                         return false;
509         }
510         if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
511                 return die_s_(0, decoder);
512         printf("OK\n");
513
514         printf("testing FLAC__stream_decoder_get_state()... ");
515         state = FLAC__stream_decoder_get_state(decoder);
516         printf("returned state = %u (%s)... OK\n", state, FLAC__StreamDecoderStateString[state]);
517
518         decoder_client_data.current_metadata_number = 0;
519         decoder_client_data.ignore_errors = false;
520         decoder_client_data.error_occurred = false;
521
522         printf("testing FLAC__stream_decoder_get_md5_checking()... ");
523         if(!FLAC__stream_decoder_get_md5_checking(decoder)) {
524                 printf("FAILED, returned false, expected true\n");
525                 return false;
526         }
527         printf("OK\n");
528
529         printf("testing FLAC__stream_decoder_process_until_end_of_metadata()... ");
530         if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder))
531                 return die_s_("returned false", decoder);
532         printf("OK\n");
533
534         printf("testing FLAC__stream_decoder_process_single()... ");
535         if(!FLAC__stream_decoder_process_single(decoder))
536                 return die_s_("returned false", decoder);
537         printf("OK\n");
538
539         printf("testing FLAC__stream_decoder_skip_single_frame()... ");
540         if(!FLAC__stream_decoder_skip_single_frame(decoder))
541                 return die_s_("returned false", decoder);
542         printf("OK\n");
543
544         if(layer < LAYER_FILE) {
545                 printf("testing FLAC__stream_decoder_flush()... ");
546                 if(!FLAC__stream_decoder_flush(decoder))
547                         return die_s_("returned false", decoder);
548                 printf("OK\n");
549
550                 decoder_client_data.ignore_errors = true;
551                 printf("testing FLAC__stream_decoder_process_single()... ");
552                 if(!FLAC__stream_decoder_process_single(decoder))
553                         return die_s_("returned false", decoder);
554                 printf("OK\n");
555                 decoder_client_data.ignore_errors = false;
556         }
557
558         expect = (layer != LAYER_STREAM);
559         printf("testing FLAC__stream_decoder_seek_absolute()... ");
560         if(FLAC__stream_decoder_seek_absolute(decoder, 0) != expect)
561                 return die_s_(expect? "returned false" : "returned true", decoder);
562         printf("OK\n");
563
564         printf("testing FLAC__stream_decoder_process_until_end_of_stream()... ");
565         if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
566                 return die_s_("returned false", decoder);
567         printf("OK\n");
568
569         expect = (layer != LAYER_STREAM);
570         printf("testing FLAC__stream_decoder_seek_absolute()... ");
571         if(FLAC__stream_decoder_seek_absolute(decoder, 0) != expect)
572                 return die_s_(expect? "returned false" : "returned true", decoder);
573         printf("OK\n");
574
575         printf("testing FLAC__stream_decoder_get_channels()... ");
576         {
577                 unsigned channels = FLAC__stream_decoder_get_channels(decoder);
578                 if(channels != streaminfo_.data.stream_info.channels) {
579                         printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
580                         return false;
581                 }
582         }
583         printf("OK\n");
584
585         printf("testing FLAC__stream_decoder_get_bits_per_sample()... ");
586         {
587                 unsigned bits_per_sample = FLAC__stream_decoder_get_bits_per_sample(decoder);
588                 if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
589                         printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
590                         return false;
591                 }
592         }
593         printf("OK\n");
594
595         printf("testing FLAC__stream_decoder_get_sample_rate()... ");
596         {
597                 unsigned sample_rate = FLAC__stream_decoder_get_sample_rate(decoder);
598                 if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
599                         printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
600                         return false;
601                 }
602         }
603         printf("OK\n");
604
605         printf("testing FLAC__stream_decoder_get_blocksize()... ");
606         {
607                 unsigned blocksize = FLAC__stream_decoder_get_blocksize(decoder);
608                 /* value could be anything since we're at the last block, so accept any reasonable answer */
609                 printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED");
610                 if(blocksize == 0)
611                         return false;
612         }
613
614         printf("testing FLAC__stream_decoder_get_channel_assignment()... ");
615         {
616                 FLAC__ChannelAssignment ca = FLAC__stream_decoder_get_channel_assignment(decoder);
617                 printf("returned %u (%s)... OK\n", (unsigned)ca, FLAC__ChannelAssignmentString[ca]);
618         }
619
620         if(layer < LAYER_FILE) {
621                 printf("testing FLAC__stream_decoder_reset()... ");
622                 if(!FLAC__stream_decoder_reset(decoder)) {
623                         state = FLAC__stream_decoder_get_state(decoder);
624                         printf("FAILED, returned false, state = %u (%s)\n", state, FLAC__StreamDecoderStateString[state]);
625                         return false;
626                 }
627                 printf("OK\n");
628
629                 if(layer == LAYER_STREAM) {
630                         /* after a reset() we have to rewind the input ourselves */
631                         printf("rewinding input... ");
632                         if(fseeko(decoder_client_data.file, 0, SEEK_SET) < 0) {
633                                 printf("FAILED, errno = %d\n", errno);
634                                 return false;
635                         }
636                         printf("OK\n");
637                 }
638
639                 decoder_client_data.current_metadata_number = 0;
640
641                 printf("testing FLAC__stream_decoder_process_until_end_of_stream()... ");
642                 if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
643                         return die_s_("returned false", decoder);
644                 printf("OK\n");
645         }
646
647         printf("testing FLAC__stream_decoder_finish()... ");
648         (void) FLAC__stream_decoder_finish(decoder);
649         printf("OK\n");
650
651         /*
652          * respond all
653          */
654
655         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
656         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
657                 return die_s_("returned false", decoder);
658         printf("OK\n");
659
660         num_expected_ = 0;
661         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
662                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
663                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
664                 expected_metadata_sequence_[num_expected_++] = &padding_;
665                 expected_metadata_sequence_[num_expected_++] = &seektable_;
666                 expected_metadata_sequence_[num_expected_++] = &application1_;
667                 expected_metadata_sequence_[num_expected_++] = &application2_;
668                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
669                 expected_metadata_sequence_[num_expected_++] = &picture_;
670                 expected_metadata_sequence_[num_expected_++] = &unknown_;
671         }
672         else {
673                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
674                 expected_metadata_sequence_[num_expected_++] = &padding_;
675                 expected_metadata_sequence_[num_expected_++] = &seektable_;
676                 expected_metadata_sequence_[num_expected_++] = &application1_;
677                 expected_metadata_sequence_[num_expected_++] = &application2_;
678                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
679                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
680                 expected_metadata_sequence_[num_expected_++] = &picture_;
681                 expected_metadata_sequence_[num_expected_++] = &unknown_;
682         }
683
684         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
685                 return false;
686
687         /*
688          * ignore all
689          */
690
691         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
692         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
693                 return die_s_("returned false", decoder);
694         printf("OK\n");
695
696         num_expected_ = 0;
697
698         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
699                 return false;
700
701         /*
702          * respond all, ignore VORBIS_COMMENT
703          */
704
705         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
706         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
707                 return die_s_("returned false", decoder);
708         printf("OK\n");
709
710         printf("testing FLAC__stream_decoder_set_metadata_ignore(VORBIS_COMMENT)... ");
711         if(!FLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
712                 return die_s_("returned false", decoder);
713         printf("OK\n");
714
715         num_expected_ = 0;
716         expected_metadata_sequence_[num_expected_++] = &streaminfo_;
717         expected_metadata_sequence_[num_expected_++] = &padding_;
718         expected_metadata_sequence_[num_expected_++] = &seektable_;
719         expected_metadata_sequence_[num_expected_++] = &application1_;
720         expected_metadata_sequence_[num_expected_++] = &application2_;
721         expected_metadata_sequence_[num_expected_++] = &cuesheet_;
722         expected_metadata_sequence_[num_expected_++] = &picture_;
723         expected_metadata_sequence_[num_expected_++] = &unknown_;
724
725         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
726                 return false;
727
728         /*
729          * respond all, ignore APPLICATION
730          */
731
732         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
733         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
734                 return die_s_("returned false", decoder);
735         printf("OK\n");
736
737         printf("testing FLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
738         if(!FLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
739                 return die_s_("returned false", decoder);
740         printf("OK\n");
741
742         num_expected_ = 0;
743         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
744                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
745                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
746                 expected_metadata_sequence_[num_expected_++] = &padding_;
747                 expected_metadata_sequence_[num_expected_++] = &seektable_;
748                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
749                 expected_metadata_sequence_[num_expected_++] = &picture_;
750                 expected_metadata_sequence_[num_expected_++] = &unknown_;
751         }
752         else {
753                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
754                 expected_metadata_sequence_[num_expected_++] = &padding_;
755                 expected_metadata_sequence_[num_expected_++] = &seektable_;
756                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
757                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
758                 expected_metadata_sequence_[num_expected_++] = &picture_;
759                 expected_metadata_sequence_[num_expected_++] = &unknown_;
760         }
761
762         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
763                 return false;
764
765         /*
766          * respond all, ignore APPLICATION id of app#1
767          */
768
769         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
770         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
771                 return die_s_("returned false", decoder);
772         printf("OK\n");
773
774         printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
775         if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
776                 return die_s_("returned false", decoder);
777         printf("OK\n");
778
779         num_expected_ = 0;
780         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
781                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
782                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
783                 expected_metadata_sequence_[num_expected_++] = &padding_;
784                 expected_metadata_sequence_[num_expected_++] = &seektable_;
785                 expected_metadata_sequence_[num_expected_++] = &application2_;
786                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
787                 expected_metadata_sequence_[num_expected_++] = &picture_;
788                 expected_metadata_sequence_[num_expected_++] = &unknown_;
789         }
790         else {
791                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
792                 expected_metadata_sequence_[num_expected_++] = &padding_;
793                 expected_metadata_sequence_[num_expected_++] = &seektable_;
794                 expected_metadata_sequence_[num_expected_++] = &application2_;
795                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
796                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
797                 expected_metadata_sequence_[num_expected_++] = &picture_;
798                 expected_metadata_sequence_[num_expected_++] = &unknown_;
799         }
800
801         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
802                 return false;
803
804         /*
805          * respond all, ignore APPLICATION id of app#1 & app#2
806          */
807
808         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
809         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
810                 return die_s_("returned false", decoder);
811         printf("OK\n");
812
813         printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
814         if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
815                 return die_s_("returned false", decoder);
816         printf("OK\n");
817
818         printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #2)... ");
819         if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id))
820                 return die_s_("returned false", decoder);
821         printf("OK\n");
822
823         num_expected_ = 0;
824         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
825                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
826                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
827                 expected_metadata_sequence_[num_expected_++] = &padding_;
828                 expected_metadata_sequence_[num_expected_++] = &seektable_;
829                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
830                 expected_metadata_sequence_[num_expected_++] = &picture_;
831                 expected_metadata_sequence_[num_expected_++] = &unknown_;
832         }
833         else {
834                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
835                 expected_metadata_sequence_[num_expected_++] = &padding_;
836                 expected_metadata_sequence_[num_expected_++] = &seektable_;
837                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
838                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
839                 expected_metadata_sequence_[num_expected_++] = &picture_;
840                 expected_metadata_sequence_[num_expected_++] = &unknown_;
841         }
842
843         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
844                 return false;
845
846         /*
847          * ignore all, respond VORBIS_COMMENT
848          */
849
850         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
851         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
852                 return die_s_("returned false", decoder);
853         printf("OK\n");
854
855         printf("testing FLAC__stream_decoder_set_metadata_respond(VORBIS_COMMENT)... ");
856         if(!FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
857                 return die_s_("returned false", decoder);
858         printf("OK\n");
859
860         num_expected_ = 0;
861         expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
862
863         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
864                 return false;
865
866         /*
867          * ignore all, respond APPLICATION
868          */
869
870         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
871         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
872                 return die_s_("returned false", decoder);
873         printf("OK\n");
874
875         printf("testing FLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
876         if(!FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
877                 return die_s_("returned false", decoder);
878         printf("OK\n");
879
880         num_expected_ = 0;
881         expected_metadata_sequence_[num_expected_++] = &application1_;
882         expected_metadata_sequence_[num_expected_++] = &application2_;
883
884         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
885                 return false;
886
887         /*
888          * ignore all, respond APPLICATION id of app#1
889          */
890
891         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
892         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
893                 return die_s_("returned false", decoder);
894         printf("OK\n");
895
896         printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
897         if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
898                 return die_s_("returned false", decoder);
899         printf("OK\n");
900
901         num_expected_ = 0;
902         expected_metadata_sequence_[num_expected_++] = &application1_;
903
904         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
905                 return false;
906
907         /*
908          * ignore all, respond APPLICATION id of app#1 & app#2
909          */
910
911         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
912         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
913                 return die_s_("returned false", decoder);
914         printf("OK\n");
915
916         printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
917         if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
918                 return die_s_("returned false", decoder);
919         printf("OK\n");
920
921         printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #2)... ");
922         if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application2_.data.application.id))
923                 return die_s_("returned false", decoder);
924         printf("OK\n");
925
926         num_expected_ = 0;
927         expected_metadata_sequence_[num_expected_++] = &application1_;
928         expected_metadata_sequence_[num_expected_++] = &application2_;
929
930         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
931                 return false;
932
933         /*
934          * respond all, ignore APPLICATION, respond APPLICATION id of app#1
935          */
936
937         printf("testing FLAC__stream_decoder_set_metadata_respond_all()... ");
938         if(!FLAC__stream_decoder_set_metadata_respond_all(decoder))
939                 return die_s_("returned false", decoder);
940         printf("OK\n");
941
942         printf("testing FLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
943         if(!FLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
944                 return die_s_("returned false", decoder);
945         printf("OK\n");
946
947         printf("testing FLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
948         if(!FLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
949                 return die_s_("returned false", decoder);
950         printf("OK\n");
951
952         num_expected_ = 0;
953         if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
954                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
955                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
956                 expected_metadata_sequence_[num_expected_++] = &padding_;
957                 expected_metadata_sequence_[num_expected_++] = &seektable_;
958                 expected_metadata_sequence_[num_expected_++] = &application1_;
959                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
960                 expected_metadata_sequence_[num_expected_++] = &picture_;
961                 expected_metadata_sequence_[num_expected_++] = &unknown_;
962         }
963         else {
964                 expected_metadata_sequence_[num_expected_++] = &streaminfo_;
965                 expected_metadata_sequence_[num_expected_++] = &padding_;
966                 expected_metadata_sequence_[num_expected_++] = &seektable_;
967                 expected_metadata_sequence_[num_expected_++] = &application1_;
968                 expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
969                 expected_metadata_sequence_[num_expected_++] = &cuesheet_;
970                 expected_metadata_sequence_[num_expected_++] = &picture_;
971                 expected_metadata_sequence_[num_expected_++] = &unknown_;
972         }
973
974         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
975                 return false;
976
977         /*
978          * ignore all, respond APPLICATION, ignore APPLICATION id of app#1
979          */
980
981         printf("testing FLAC__stream_decoder_set_metadata_ignore_all()... ");
982         if(!FLAC__stream_decoder_set_metadata_ignore_all(decoder))
983                 return die_s_("returned false", decoder);
984         printf("OK\n");
985
986         printf("testing FLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
987         if(!FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
988                 return die_s_("returned false", decoder);
989         printf("OK\n");
990
991         printf("testing FLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
992         if(!FLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
993                 return die_s_("returned false", decoder);
994         printf("OK\n");
995
996         num_expected_ = 0;
997         expected_metadata_sequence_[num_expected_++] = &application2_;
998
999         if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
1000                 return false;
1001
1002         if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */
1003                 fclose(decoder_client_data.file);
1004
1005         printf("testing FLAC__stream_decoder_delete()... ");
1006         FLAC__stream_decoder_delete(decoder);
1007         printf("OK\n");
1008
1009         printf("\nPASSED!\n");
1010
1011         return true;
1012 }
1013
1014 FLAC__bool test_decoders()
1015 {
1016         FLAC__bool is_ogg = false;
1017
1018         while(1) {
1019                 init_metadata_blocks_();
1020
1021                 if(!generate_file_(is_ogg))
1022                         return false;
1023
1024                 if(!test_stream_decoder(LAYER_STREAM, is_ogg))
1025                         return false;
1026
1027                 if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg))
1028                         return false;
1029
1030                 if(!test_stream_decoder(LAYER_FILE, is_ogg))
1031                         return false;
1032
1033                 if(!test_stream_decoder(LAYER_FILENAME, is_ogg))
1034                         return false;
1035
1036                 (void) grabbag__file_remove_file(flacfilename(is_ogg));
1037
1038                 free_metadata_blocks_();
1039
1040                 if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)
1041                         break;
1042                 is_ogg = true;
1043         }
1044
1045         return true;
1046 }