1
/* test_libOggFLAC++ - Unit tester for libOggFLAC++
2
* Copyright (C) 2002,2003,2004,2005 Josh Coalson
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.
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.
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.
21
#include "file_utils.h"
22
#include "metadata_utils.h"
24
#include "FLAC/assert.h"
25
#include "OggFLAC++/encoder.h"
30
static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
31
static ::FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &unknown_ };
32
static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
33
static const char *oggflacfilename_ = "metadata.ogg";
35
static void init_metadata_blocks_()
37
mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
40
static void free_metadata_blocks_()
42
mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
45
class StreamEncoder : public OggFLAC::Encoder::Stream {
47
StreamEncoder(): OggFLAC::Encoder::Stream() { }
50
// from OggFLAC::Encoder::Stream
51
::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame);
52
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
54
bool die(const char *msg = 0) const;
57
::FLAC__StreamEncoderWriteStatus StreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
59
(void)buffer, (void)bytes, (void)samples, (void)current_frame;
61
return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
64
void StreamEncoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
69
bool StreamEncoder::die(const char *msg) const
71
State state = get_state();
74
printf("FAILED, %s", msg);
78
printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamEncoderState)state), state.as_cstring());
79
if(state == ::OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
80
FLAC::Encoder::Stream::State state_ = get_FLAC_stream_encoder_state();
81
printf(" FLAC stream encoder state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
82
if(state_ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
83
FLAC::Decoder::Stream::State dstate = get_verify_decoder_state();
84
printf(" verify decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
91
static bool test_stream_encoder()
93
StreamEncoder *encoder;
94
FLAC__int32 samples[1024];
95
FLAC__int32 *samples_array[1] = { samples };
98
printf("\n+++ libOggFLAC++ unit test: OggFLAC::Encoder::Stream\n\n");
100
printf("allocating encoder instance... ");
101
encoder = new StreamEncoder();
103
printf("FAILED, new returned NULL\n");
108
printf("testing is_valid()... ");
109
if(!encoder->is_valid()) {
110
printf("FAILED, returned false\n");
115
printf("testing set_serial_number()... ");
116
if(!encoder->set_serial_number(file_utils__serial_number))
117
return encoder->die("returned false");
120
printf("testing set_verify()... ");
121
if(!encoder->set_verify(true))
122
return encoder->die("returned false");
125
printf("testing set_streamable_subset()... ");
126
if(!encoder->set_streamable_subset(true))
127
return encoder->die("returned false");
130
printf("testing set_do_mid_side_stereo()... ");
131
if(!encoder->set_do_mid_side_stereo(false))
132
return encoder->die("returned false");
135
printf("testing set_loose_mid_side_stereo()... ");
136
if(!encoder->set_loose_mid_side_stereo(false))
137
return encoder->die("returned false");
140
printf("testing set_channels()... ");
141
if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
142
return encoder->die("returned false");
145
printf("testing set_bits_per_sample()... ");
146
if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
147
return encoder->die("returned false");
150
printf("testing set_sample_rate()... ");
151
if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
152
return encoder->die("returned false");
155
printf("testing set_blocksize()... ");
156
if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
157
return encoder->die("returned false");
160
printf("testing set_max_lpc_order()... ");
161
if(!encoder->set_max_lpc_order(0))
162
return encoder->die("returned false");
165
printf("testing set_qlp_coeff_precision()... ");
166
if(!encoder->set_qlp_coeff_precision(0))
167
return encoder->die("returned false");
170
printf("testing set_do_qlp_coeff_prec_search()... ");
171
if(!encoder->set_do_qlp_coeff_prec_search(false))
172
return encoder->die("returned false");
175
printf("testing set_do_escape_coding()... ");
176
if(!encoder->set_do_escape_coding(false))
177
return encoder->die("returned false");
180
printf("testing set_do_exhaustive_model_search()... ");
181
if(!encoder->set_do_exhaustive_model_search(false))
182
return encoder->die("returned false");
185
printf("testing set_min_residual_partition_order()... ");
186
if(!encoder->set_min_residual_partition_order(0))
187
return encoder->die("returned false");
190
printf("testing set_max_residual_partition_order()... ");
191
if(!encoder->set_max_residual_partition_order(0))
192
return encoder->die("returned false");
195
printf("testing set_rice_parameter_search_dist()... ");
196
if(!encoder->set_rice_parameter_search_dist(0))
197
return encoder->die("returned false");
200
printf("testing set_total_samples_estimate()... ");
201
if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
202
return encoder->die("returned false");
205
printf("testing set_metadata()... ");
206
if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
207
return encoder->die("returned false");
210
printf("testing init()... ");
211
if(encoder->init() != ::OggFLAC__STREAM_ENCODER_OK)
212
return encoder->die();
215
printf("testing get_state()... ");
216
OggFLAC::Encoder::Stream::State state = encoder->get_state();
217
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamEncoderState)state), state.as_cstring());
219
printf("testing get_FLAC_stream_encoder_state()... ");
220
FLAC::Encoder::Stream::State state_ = encoder->get_FLAC_stream_encoder_state();
221
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
223
printf("testing get_verify_decoder_state()... ");
224
FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
225
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
228
FLAC__uint64 absolute_sample;
229
unsigned frame_number;
232
FLAC__int32 expected;
235
printf("testing get_verify_decoder_error_stats()... ");
236
encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got);
240
printf("testing get_verify()... ");
241
if(encoder->get_verify() != true) {
242
printf("FAILED, expected true, got false\n");
247
printf("testing get_streamable_subset()... ");
248
if(encoder->get_streamable_subset() != true) {
249
printf("FAILED, expected true, got false\n");
254
printf("testing get_do_mid_side_stereo()... ");
255
if(encoder->get_do_mid_side_stereo() != false) {
256
printf("FAILED, expected false, got true\n");
261
printf("testing get_loose_mid_side_stereo()... ");
262
if(encoder->get_loose_mid_side_stereo() != false) {
263
printf("FAILED, expected false, got true\n");
268
printf("testing get_channels()... ");
269
if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
270
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
275
printf("testing get_bits_per_sample()... ");
276
if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
277
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
282
printf("testing get_sample_rate()... ");
283
if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
284
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
289
printf("testing get_blocksize()... ");
290
if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
291
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
296
printf("testing get_max_lpc_order()... ");
297
if(encoder->get_max_lpc_order() != 0) {
298
printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
303
printf("testing get_qlp_coeff_precision()... ");
304
(void)encoder->get_qlp_coeff_precision();
305
/* we asked the encoder to auto select this so we accept anything */
308
printf("testing get_do_qlp_coeff_prec_search()... ");
309
if(encoder->get_do_qlp_coeff_prec_search() != false) {
310
printf("FAILED, expected false, got true\n");
315
printf("testing get_do_escape_coding()... ");
316
if(encoder->get_do_escape_coding() != false) {
317
printf("FAILED, expected false, got true\n");
322
printf("testing get_do_exhaustive_model_search()... ");
323
if(encoder->get_do_exhaustive_model_search() != false) {
324
printf("FAILED, expected false, got true\n");
329
printf("testing get_min_residual_partition_order()... ");
330
if(encoder->get_min_residual_partition_order() != 0) {
331
printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
336
printf("testing get_max_residual_partition_order()... ");
337
if(encoder->get_max_residual_partition_order() != 0) {
338
printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
343
printf("testing get_rice_parameter_search_dist()... ");
344
if(encoder->get_rice_parameter_search_dist() != 0) {
345
printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
350
printf("testing get_total_samples_estimate()... ");
351
if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) {
352
printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
357
/* init the dummy sample buffer */
358
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
361
printf("testing process()... ");
362
if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
363
return encoder->die("returned false");
366
printf("testing process_interleaved()... ");
367
if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
368
return encoder->die("returned false");
371
printf("testing finish()... ");
375
printf("freeing encoder instance... ");
379
printf("\nPASSED!\n");
384
class SeekableStreamEncoder : public OggFLAC::Encoder::SeekableStream {
386
SeekableStreamEncoder(): OggFLAC::Encoder::SeekableStream() { }
387
~SeekableStreamEncoder() { }
389
// from OggFLAC::Encoder::SeekableStream
390
::OggFLAC__SeekableStreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
391
::FLAC__SeekableStreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
392
::FLAC__SeekableStreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
393
::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame);
395
bool die(const char *msg = 0) const;
398
::OggFLAC__SeekableStreamEncoderReadStatus SeekableStreamEncoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
400
(void)buffer, (void)bytes;
401
::memset(buffer, 0, *bytes); /* init buffer to avoid valgrind errors */
402
return ::OggFLAC__SEEKABLE_STREAM_ENCODER_READ_STATUS_CONTINUE;
405
::FLAC__SeekableStreamEncoderSeekStatus SeekableStreamEncoder::seek_callback(FLAC__uint64 absolute_byte_offset)
407
(void)absolute_byte_offset;
409
return ::FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
412
::FLAC__SeekableStreamEncoderTellStatus SeekableStreamEncoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
414
(void)absolute_byte_offset;
416
return ::FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK;
419
::FLAC__StreamEncoderWriteStatus SeekableStreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
421
(void)buffer, (void)bytes, (void)samples, (void)current_frame;
423
return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
426
bool SeekableStreamEncoder::die(const char *msg) const
428
State state = get_state();
431
printf("FAILED, %s", msg);
435
printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamEncoderState)state), state.as_cstring());
436
if(state == ::OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
437
FLAC::Encoder::Stream::State state_ = get_FLAC_stream_encoder_state();
438
printf(" FLAC stream encoder state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
439
if(state_ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
440
FLAC::Decoder::Stream::State dstate = get_verify_decoder_state();
441
printf(" verify decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
448
static bool test_seekable_stream_encoder()
450
SeekableStreamEncoder *encoder;
451
FLAC__int32 samples[1024];
452
FLAC__int32 *samples_array[1] = { samples };
455
printf("\n+++ libOggFLAC++ unit test: OggFLAC::Encoder::SeekableStream\n\n");
457
printf("allocating encoder instance... ");
458
encoder = new SeekableStreamEncoder();
460
printf("FAILED, new returned NULL\n");
465
printf("testing is_valid()... ");
466
if(!encoder->is_valid()) {
467
printf("FAILED, returned false\n");
472
printf("testing set_serial_number()... ");
473
if(!encoder->set_serial_number(file_utils__serial_number))
474
return encoder->die("returned false");
477
printf("testing set_verify()... ");
478
if(!encoder->set_verify(true))
479
return encoder->die("returned false");
482
printf("testing set_streamable_subset()... ");
483
if(!encoder->set_streamable_subset(true))
484
return encoder->die("returned false");
487
printf("testing set_do_mid_side_stereo()... ");
488
if(!encoder->set_do_mid_side_stereo(false))
489
return encoder->die("returned false");
492
printf("testing set_loose_mid_side_stereo()... ");
493
if(!encoder->set_loose_mid_side_stereo(false))
494
return encoder->die("returned false");
497
printf("testing set_channels()... ");
498
if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
499
return encoder->die("returned false");
502
printf("testing set_bits_per_sample()... ");
503
if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
504
return encoder->die("returned false");
507
printf("testing set_sample_rate()... ");
508
if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
509
return encoder->die("returned false");
512
printf("testing set_blocksize()... ");
513
if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
514
return encoder->die("returned false");
517
printf("testing set_max_lpc_order()... ");
518
if(!encoder->set_max_lpc_order(0))
519
return encoder->die("returned false");
522
printf("testing set_qlp_coeff_precision()... ");
523
if(!encoder->set_qlp_coeff_precision(0))
524
return encoder->die("returned false");
527
printf("testing set_do_qlp_coeff_prec_search()... ");
528
if(!encoder->set_do_qlp_coeff_prec_search(false))
529
return encoder->die("returned false");
532
printf("testing set_do_escape_coding()... ");
533
if(!encoder->set_do_escape_coding(false))
534
return encoder->die("returned false");
537
printf("testing set_do_exhaustive_model_search()... ");
538
if(!encoder->set_do_exhaustive_model_search(false))
539
return encoder->die("returned false");
542
printf("testing set_min_residual_partition_order()... ");
543
if(!encoder->set_min_residual_partition_order(0))
544
return encoder->die("returned false");
547
printf("testing set_max_residual_partition_order()... ");
548
if(!encoder->set_max_residual_partition_order(0))
549
return encoder->die("returned false");
552
printf("testing set_rice_parameter_search_dist()... ");
553
if(!encoder->set_rice_parameter_search_dist(0))
554
return encoder->die("returned false");
557
printf("testing set_total_samples_estimate()... ");
558
if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
559
return encoder->die("returned false");
562
printf("testing set_metadata()... ");
563
if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
564
return encoder->die("returned false");
567
printf("testing init()... ");
568
if(encoder->init() != ::OggFLAC__SEEKABLE_STREAM_ENCODER_OK)
569
return encoder->die();
572
printf("testing get_state()... ");
573
OggFLAC::Encoder::SeekableStream::State state = encoder->get_state();
574
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__SeekableStreamEncoderState)state), state.as_cstring());
576
printf("testing get_FLAC_stream_encoder_state()... ");
577
FLAC::Encoder::Stream::State state_ = encoder->get_FLAC_stream_encoder_state();
578
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
580
printf("testing get_verify_decoder_state()... ");
581
FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
582
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
585
FLAC__uint64 absolute_sample;
586
unsigned frame_number;
589
FLAC__int32 expected;
592
printf("testing get_verify_decoder_error_stats()... ");
593
encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got);
597
printf("testing get_verify()... ");
598
if(encoder->get_verify() != true) {
599
printf("FAILED, expected true, got false\n");
604
printf("testing get_streamable_subset()... ");
605
if(encoder->get_streamable_subset() != true) {
606
printf("FAILED, expected true, got false\n");
611
printf("testing get_do_mid_side_stereo()... ");
612
if(encoder->get_do_mid_side_stereo() != false) {
613
printf("FAILED, expected false, got true\n");
618
printf("testing get_loose_mid_side_stereo()... ");
619
if(encoder->get_loose_mid_side_stereo() != false) {
620
printf("FAILED, expected false, got true\n");
625
printf("testing get_channels()... ");
626
if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
627
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
632
printf("testing get_bits_per_sample()... ");
633
if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
634
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
639
printf("testing get_sample_rate()... ");
640
if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
641
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
646
printf("testing get_blocksize()... ");
647
if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
648
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
653
printf("testing get_max_lpc_order()... ");
654
if(encoder->get_max_lpc_order() != 0) {
655
printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
660
printf("testing get_qlp_coeff_precision()... ");
661
(void)encoder->get_qlp_coeff_precision();
662
/* we asked the encoder to auto select this so we accept anything */
665
printf("testing get_do_qlp_coeff_prec_search()... ");
666
if(encoder->get_do_qlp_coeff_prec_search() != false) {
667
printf("FAILED, expected false, got true\n");
672
printf("testing get_do_escape_coding()... ");
673
if(encoder->get_do_escape_coding() != false) {
674
printf("FAILED, expected false, got true\n");
679
printf("testing get_do_exhaustive_model_search()... ");
680
if(encoder->get_do_exhaustive_model_search() != false) {
681
printf("FAILED, expected false, got true\n");
686
printf("testing get_min_residual_partition_order()... ");
687
if(encoder->get_min_residual_partition_order() != 0) {
688
printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
693
printf("testing get_max_residual_partition_order()... ");
694
if(encoder->get_max_residual_partition_order() != 0) {
695
printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
700
printf("testing get_rice_parameter_search_dist()... ");
701
if(encoder->get_rice_parameter_search_dist() != 0) {
702
printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
707
printf("testing get_total_samples_estimate()... ");
708
if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) {
709
printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
714
/* init the dummy sample buffer */
715
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
718
printf("testing process()... ");
719
if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
720
return encoder->die("returned false");
723
printf("testing process_interleaved()... ");
724
if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
725
return encoder->die("returned false");
728
printf("testing finish()... ");
732
printf("freeing encoder instance... ");
736
printf("\nPASSED!\n");
741
class FileEncoder : public OggFLAC::Encoder::File {
743
FileEncoder(): OggFLAC::Encoder::File() { }
746
// from OggFLAC::Encoder::File
747
void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
749
bool die(const char *msg = 0) const;
752
void FileEncoder::progress_callback(FLAC__uint64, FLAC__uint64, unsigned, unsigned)
756
bool FileEncoder::die(const char *msg) const
758
State state = get_state();
761
printf("FAILED, %s", msg);
765
printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__FileEncoderState)state), state.as_cstring());
766
if(state == ::OggFLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
767
OggFLAC::Encoder::SeekableStream::State state_ = get_seekable_stream_encoder_state();
768
printf(" seekable stream encoder state = %u (%s)\n", (unsigned)((::OggFLAC__SeekableStreamEncoderState)state_), state_.as_cstring());
769
if(state_ == ::OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
770
FLAC::Encoder::Stream::State state__ = get_FLAC_stream_encoder_state();
771
printf(" FLAC stream encoder state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state__), state__.as_cstring());
772
if(state__ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
773
FLAC::Decoder::Stream::State dstate = get_verify_decoder_state();
774
printf(" verify decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
782
static bool test_file_encoder()
784
FileEncoder *encoder;
785
FLAC__int32 samples[1024];
786
FLAC__int32 *samples_array[1] = { samples };
789
printf("\n+++ libOggFLAC++ unit test: OggFLAC::Encoder::File\n\n");
791
printf("allocating encoder instance... ");
792
encoder = new FileEncoder();
794
printf("FAILED, new returned NULL\n");
799
printf("testing is_valid()... ");
800
if(!encoder->is_valid()) {
801
printf("FAILED, returned false\n");
806
printf("testing set_serial_number()... ");
807
if(!encoder->set_serial_number(file_utils__serial_number))
808
return encoder->die("returned false");
811
printf("testing set_verify()... ");
812
if(!encoder->set_verify(true))
813
return encoder->die("returned false");
816
printf("testing set_streamable_subset()... ");
817
if(!encoder->set_streamable_subset(true))
818
return encoder->die("returned false");
821
printf("testing set_do_mid_side_stereo()... ");
822
if(!encoder->set_do_mid_side_stereo(false))
823
return encoder->die("returned false");
826
printf("testing set_loose_mid_side_stereo()... ");
827
if(!encoder->set_loose_mid_side_stereo(false))
828
return encoder->die("returned false");
831
printf("testing set_channels()... ");
832
if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
833
return encoder->die("returned false");
836
printf("testing set_bits_per_sample()... ");
837
if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
838
return encoder->die("returned false");
841
printf("testing set_sample_rate()... ");
842
if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
843
return encoder->die("returned false");
846
printf("testing set_blocksize()... ");
847
if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
848
return encoder->die("returned false");
851
printf("testing set_max_lpc_order()... ");
852
if(!encoder->set_max_lpc_order(0))
853
return encoder->die("returned false");
856
printf("testing set_qlp_coeff_precision()... ");
857
if(!encoder->set_qlp_coeff_precision(0))
858
return encoder->die("returned false");
861
printf("testing set_do_qlp_coeff_prec_search()... ");
862
if(!encoder->set_do_qlp_coeff_prec_search(false))
863
return encoder->die("returned false");
866
printf("testing set_do_escape_coding()... ");
867
if(!encoder->set_do_escape_coding(false))
868
return encoder->die("returned false");
871
printf("testing set_do_exhaustive_model_search()... ");
872
if(!encoder->set_do_exhaustive_model_search(false))
873
return encoder->die("returned false");
876
printf("testing set_min_residual_partition_order()... ");
877
if(!encoder->set_min_residual_partition_order(0))
878
return encoder->die("returned false");
881
printf("testing set_max_residual_partition_order()... ");
882
if(!encoder->set_max_residual_partition_order(0))
883
return encoder->die("returned false");
886
printf("testing set_rice_parameter_search_dist()... ");
887
if(!encoder->set_rice_parameter_search_dist(0))
888
return encoder->die("returned false");
891
printf("testing set_total_samples_estimate()... ");
892
if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
893
return encoder->die("returned false");
896
printf("testing set_metadata()... ");
897
if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
898
return encoder->die("returned false");
901
printf("testing set_filename()... ");
902
if(!encoder->set_filename(oggflacfilename_))
903
return encoder->die("returned false");
906
printf("testing init()... ");
907
if(encoder->init() != ::OggFLAC__FILE_ENCODER_OK)
908
return encoder->die();
911
printf("testing get_state()... ");
912
OggFLAC::Encoder::File::State state = encoder->get_state();
913
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__FileEncoderState)state), state.as_cstring());
915
printf("testing get_seekable_stream_encoder_state()... ");
916
OggFLAC::Encoder::SeekableStream::State state_ = encoder->get_seekable_stream_encoder_state();
917
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__SeekableStreamEncoderState)state_), state_.as_cstring());
919
printf("testing get_FLAC_stream_encoder_state()... ");
920
FLAC::Encoder::Stream::State state__ = encoder->get_FLAC_stream_encoder_state();
921
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state__), state__.as_cstring());
923
printf("testing get_verify_decoder_state()... ");
924
FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
925
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
928
FLAC__uint64 absolute_sample;
929
unsigned frame_number;
932
FLAC__int32 expected;
935
printf("testing get_verify_decoder_error_stats()... ");
936
encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got);
940
printf("testing get_verify()... ");
941
if(encoder->get_verify() != true) {
942
printf("FAILED, expected true, got false\n");
947
printf("testing get_streamable_subset()... ");
948
if(encoder->get_streamable_subset() != true) {
949
printf("FAILED, expected true, got false\n");
954
printf("testing get_do_mid_side_stereo()... ");
955
if(encoder->get_do_mid_side_stereo() != false) {
956
printf("FAILED, expected false, got true\n");
961
printf("testing get_loose_mid_side_stereo()... ");
962
if(encoder->get_loose_mid_side_stereo() != false) {
963
printf("FAILED, expected false, got true\n");
968
printf("testing get_channels()... ");
969
if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
970
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
975
printf("testing get_bits_per_sample()... ");
976
if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
977
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
982
printf("testing get_sample_rate()... ");
983
if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
984
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
989
printf("testing get_blocksize()... ");
990
if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
991
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
996
printf("testing get_max_lpc_order()... ");
997
if(encoder->get_max_lpc_order() != 0) {
998
printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
1003
printf("testing get_qlp_coeff_precision()... ");
1004
(void)encoder->get_qlp_coeff_precision();
1005
/* we asked the encoder to auto select this so we accept anything */
1008
printf("testing get_do_qlp_coeff_prec_search()... ");
1009
if(encoder->get_do_qlp_coeff_prec_search() != false) {
1010
printf("FAILED, expected false, got true\n");
1015
printf("testing get_do_escape_coding()... ");
1016
if(encoder->get_do_escape_coding() != false) {
1017
printf("FAILED, expected false, got true\n");
1022
printf("testing get_do_exhaustive_model_search()... ");
1023
if(encoder->get_do_exhaustive_model_search() != false) {
1024
printf("FAILED, expected false, got true\n");
1029
printf("testing get_min_residual_partition_order()... ");
1030
if(encoder->get_min_residual_partition_order() != 0) {
1031
printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
1036
printf("testing get_max_residual_partition_order()... ");
1037
if(encoder->get_max_residual_partition_order() != 0) {
1038
printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
1043
printf("testing get_rice_parameter_search_dist()... ");
1044
if(encoder->get_rice_parameter_search_dist() != 0) {
1045
printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
1050
printf("testing get_total_samples_estimate()... ");
1051
if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) {
1052
printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
1057
/* init the dummy sample buffer */
1058
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
1061
printf("testing process()... ");
1062
if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
1063
return encoder->die("returned false");
1066
printf("testing process_interleaved()... ");
1067
if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
1068
return encoder->die("returned false");
1071
printf("testing finish()... ");
1075
printf("freeing encoder instance... ");
1079
printf("\nPASSED!\n");
1084
bool test_encoders()
1086
init_metadata_blocks_();
1088
if(!test_stream_encoder())
1091
if(!test_seekable_stream_encoder())
1094
if(!test_file_encoder())
1097
free_metadata_blocks_();