merge libOggFLAC into libFLAC and libOggFLAC++ into FLAC++; documentation still needs work

This commit is contained in:
Josh Coalson
2006-10-15 04:24:05 +00:00
parent 03dbb26a27
commit 8da98c897b
120 changed files with 2581 additions and 12227 deletions

View File

@@ -19,15 +19,9 @@ if FLaC__HAS_XMMS
XMMS_DIRS = plugin_common plugin_xmms
endif
if FLaC__HAS_OGG
OGGFLAC_DIRS = libOggFLAC libOggFLAC++
OGGFLAC_TEST_DIRS = test_libOggFLAC test_libOggFLAC++
endif
SUBDIRS = \
libFLAC \
libFLAC++ \
$(OGGFLAC_DIRS) \
share \
flac \
metaflac \
@@ -38,7 +32,6 @@ SUBDIRS = \
test_libs_common \
test_libFLAC \
test_libFLAC++ \
$(OGGFLAC_TEST_DIRS) \
test_seeking \
test_streams

View File

@@ -15,8 +15,8 @@
# restrictive of those mentioned above. See the file COPYING.Xiph in this
# distribution.
.PHONY: all flac libFLAC libFLAC++ libOggFLAC libOggFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_libOggFLAC test_libOggFLAC++ test_seeking test_streams
all: flac libFLAC libFLAC++ libOggFLAC libOggFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_libOggFLAC test_libOggFLAC++ test_seeking test_streams
.PHONY: all flac libFLAC libFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_seeking test_streams
all: flac libFLAC libFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_seeking test_streams
DEFAULT_CONFIG = release
@@ -30,15 +30,13 @@ debug : all
valgrind: all
release : all
flac libFLAC libFLAC++ libOggFLAC libOggFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_libOggFLAC test_libOggFLAC++ test_seeking test_streams:
flac libFLAC libFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_seeking test_streams:
(cd $@ ; $(MAKE) -f Makefile.lite $(CONFIG))
clean:
-(cd flac ; $(MAKE) -f Makefile.lite clean)
-(cd libFLAC ; $(MAKE) -f Makefile.lite clean)
-(cd libFLAC++ ; $(MAKE) -f Makefile.lite clean)
-(cd libOggFLAC ; $(MAKE) -f Makefile.lite clean)
-(cd libOggFLAC++ ; $(MAKE) -f Makefile.lite clean)
-(cd metaflac ; $(MAKE) -f Makefile.lite clean)
-(cd plugin_common ; $(MAKE) -f Makefile.lite clean)
-(cd plugin_xmms ; $(MAKE) -f Makefile.lite clean)
@@ -47,15 +45,11 @@ clean:
-(cd test_libs_common ; $(MAKE) -f Makefile.lite clean)
-(cd test_libFLAC ; $(MAKE) -f Makefile.lite clean)
-(cd test_libFLAC++ ; $(MAKE) -f Makefile.lite clean)
-(cd test_libOggFLAC ; $(MAKE) -f Makefile.lite clean)
-(cd test_libOggFLAC++ ; $(MAKE) -f Makefile.lite clean)
-(cd test_seeking ; $(MAKE) -f Makefile.lite clean)
-(cd test_streams ; $(MAKE) -f Makefile.lite clean)
flac: libFLAC libOggFLAC share
flac: libFLAC share
libFLAC++: libFLAC
libOggFLAC++: libFLAC
libOggFLAC: libFLAC
metaflac: libFLAC share
plugin_common: libFLAC
plugin_xmms: libFLAC plugin_common
@@ -63,7 +57,5 @@ share: libFLAC
test_grabbag: share
test_libFLAC++: libFLAC libFLAC++ test_libs_common
test_libFLAC: libFLAC test_libs_common
test_libOggFLAC++: libFLAC libOggFLAC libOggFLAC++ test_libs_common
test_libOggFLAC: libFLAC libOggFLAC test_libs_common
test_seeking: libFLAC libOggFLAC
test_seeking: libFLAC
test_streams: libFLAC

View File

@@ -19,10 +19,6 @@ bin_PROGRAMS = flac
AM_CFLAGS = @OGG_CFLAGS@
if FLaC__HAS_OGG
NEED_OGGFLAC_LIB = $(top_builddir)/src/libOggFLAC/libOggFLAC.la
endif
EXTRA_DIST = \
Makefile.lite \
flac.dsp
@@ -43,7 +39,6 @@ flac_SOURCES = \
vorbiscomment.h
flac_LDADD = \
$(NEED_OGGFLAC_LIB) \
$(top_builddir)/src/share/grabbag/libgrabbag.la \
$(top_builddir)/src/share/getopt/libgetopt.a \
$(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \

View File

@@ -27,9 +27,9 @@ PROGRAM_NAME = flac
INCLUDES = -I./include -I$(topdir)/include -I$(OGG_INCLUDE_DIR)
ifeq ($(DARWIN_BUILD),yes)
EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libOggFLAC.a $(libdir)/libFLAC.a $(libdir)/libreplaygain_analysis.a $(libdir)/libreplaygain_synthesis.a $(libdir)/libgetopt.a $(libdir)/libutf8.a $(OGG_LIB_DIR)/libogg.a -L$(ICONV_LIB_DIR) -liconv -lm
EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libFLAC.a $(libdir)/libreplaygain_analysis.a $(libdir)/libreplaygain_synthesis.a $(libdir)/libgetopt.a $(libdir)/libutf8.a $(OGG_LIB_DIR)/libogg.a -L$(ICONV_LIB_DIR) -liconv -lm
else
LIBS = -lgrabbag -lOggFLAC -lFLAC -lreplaygain_analysis -lreplaygain_synthesis -lgetopt -lutf8 -L$(OGG_LIB_DIR) -logg -lm
LIBS = -lgrabbag -lFLAC -lreplaygain_analysis -lreplaygain_synthesis -lgetopt -lutf8 -L$(OGG_LIB_DIR) -logg -lm
endif
SRCS_C = \

View File

@@ -42,10 +42,6 @@
#include "share/replaygain_synthesis.h"
#include "decode.h"
#ifdef FLAC__HAS_OGG
#include "OggFLAC/stream_decoder.h"
#endif
typedef struct {
#ifdef FLAC__HAS_OGG
FLAC__bool is_ogg;
@@ -90,12 +86,7 @@ typedef struct {
unsigned sample_rate;
FLAC__uint32 channel_mask;
union {
FLAC__StreamDecoder *flac;
#ifdef FLAC__HAS_OGG
OggFLAC__StreamDecoder *ogg;
#endif
} decoder;
FLAC__StreamDecoder *decoder;
FILE *fout;
} DecoderSession;
@@ -287,10 +278,7 @@ FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__
d->sample_rate = 0;
d->channel_mask = 0;
d->decoder.flac = 0;
#ifdef FLAC__HAS_OGG
d->decoder.ogg = 0;
#endif
d->decoder = 0;
d->fout = 0; /* initialized with an open file later if necessary */
@@ -331,52 +319,36 @@ FLAC__bool DecoderSession_init_decoder(DecoderSession *decoder_session, decode_o
is_big_endian_host_ = (*((FLAC__byte*)(&test)))? false : true;
decoder_session->decoder = FLAC__stream_decoder_new();
if(0 == decoder_session->decoder) {
flac__utils_printf(stderr, 1, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename);
return false;
}
FLAC__stream_decoder_set_md5_checking(decoder_session->decoder, true);
if (0 != decoder_session->cue_specification)
FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder, FLAC__METADATA_TYPE_CUESHEET);
if (decoder_session->replaygain.spec.apply)
FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);
#ifdef FLAC__HAS_OGG
if(decoder_session->is_ogg) {
decoder_session->decoder.ogg = OggFLAC__stream_decoder_new();
if(0 == decoder_session->decoder.ogg) {
flac__utils_printf(stderr, 1, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename);
return false;
}
OggFLAC__stream_decoder_set_md5_checking(decoder_session->decoder.ogg, true);
if(!decode_options.use_first_serial_number)
OggFLAC__stream_decoder_set_serial_number(decoder_session->decoder.ogg, decode_options.serial_number);
if (0 != decoder_session->cue_specification)
OggFLAC__stream_decoder_set_metadata_respond(decoder_session->decoder.ogg, FLAC__METADATA_TYPE_CUESHEET);
if (decoder_session->replaygain.spec.apply)
OggFLAC__stream_decoder_set_metadata_respond(decoder_session->decoder.ogg, FLAC__METADATA_TYPE_VORBIS_COMMENT);
init_status = OggFLAC__stream_decoder_init_file(decoder_session->decoder.ogg, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session);
if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
print_error_with_init_status(decoder_session, "ERROR initializing decoder", init_status);
return false;
}
FLAC__stream_decoder_set_serial_number(decoder_session->decoder, decode_options.serial_number);
init_status = FLAC__stream_decoder_init_ogg_file(decoder_session->decoder, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session);
}
else
#else
(void)decode_options;
#endif
{
decoder_session->decoder.flac = FLAC__stream_decoder_new();
init_status = FLAC__stream_decoder_init_file(decoder_session->decoder, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session);
}
if(0 == decoder_session->decoder.flac) {
flac__utils_printf(stderr, 1, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename);
return false;
}
FLAC__stream_decoder_set_md5_checking(decoder_session->decoder.flac, true);
if (0 != decoder_session->cue_specification)
FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder.flac, FLAC__METADATA_TYPE_CUESHEET);
if (decoder_session->replaygain.spec.apply)
FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder.flac, FLAC__METADATA_TYPE_VORBIS_COMMENT);
init_status = FLAC__stream_decoder_init_file(decoder_session->decoder.flac, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session);
if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
print_error_with_init_status(decoder_session, "ERROR initializing decoder", init_status);
return false;
}
if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
print_error_with_init_status(decoder_session, "ERROR initializing decoder", init_status);
return false;
}
return true;
@@ -384,35 +356,18 @@ FLAC__bool DecoderSession_init_decoder(DecoderSession *decoder_session, decode_o
FLAC__bool DecoderSession_process(DecoderSession *d)
{
#ifdef FLAC__HAS_OGG
if(d->is_ogg) {
if(!OggFLAC__stream_decoder_process_until_end_of_metadata(d->decoder.ogg)) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR while decoding metadata");
return false;
}
if(OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_OK && OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_END_OF_STREAM) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR during metadata decoding");
if(!d->continue_through_decode_errors)
return false;
}
if(!FLAC__stream_decoder_process_until_end_of_metadata(d->decoder)) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR while decoding metadata");
return false;
}
else
#endif
{
if(!FLAC__stream_decoder_process_until_end_of_metadata(d->decoder.flac)) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR while decoding metadata");
if(FLAC__stream_decoder_get_state(d->decoder) > FLAC__STREAM_DECODER_END_OF_STREAM) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR during metadata decoding");
if(!d->continue_through_decode_errors)
return false;
}
if(FLAC__stream_decoder_get_state(d->decoder.flac) > FLAC__STREAM_DECODER_END_OF_STREAM) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR during metadata decoding");
if(!d->continue_through_decode_errors)
return false;
}
}
if(d->abort_flag)
return false;
@@ -457,72 +412,21 @@ FLAC__bool DecoderSession_process(DecoderSession *d)
if(d->skip_specification->value.samples > 0) {
const FLAC__uint64 skip = (FLAC__uint64)d->skip_specification->value.samples;
#ifdef FLAC__HAS_OGG
if(d->is_ogg) {
if(!OggFLAC__stream_decoder_seek_absolute(d->decoder.ogg, skip)) {
print_error_with_state(d, "ERROR seeking while skipping bytes");
return false;
}
if(!OggFLAC__stream_decoder_process_until_end_of_stream(d->decoder.ogg) && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR while decoding frames");
return false;
}
if(OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_OK && OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR during decoding");
return false;
}
}
else
#endif
{
if(!FLAC__stream_decoder_seek_absolute(d->decoder.flac, skip)) {
print_error_with_state(d, "ERROR seeking while skipping bytes");
return false;
}
if(!FLAC__stream_decoder_process_until_end_of_stream(d->decoder.flac) && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR while decoding frames");
return false;
}
if(FLAC__stream_decoder_get_state(d->decoder.flac) > FLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR during decoding");
return false;
}
if(!FLAC__stream_decoder_seek_absolute(d->decoder, skip)) {
print_error_with_state(d, "ERROR seeking while skipping bytes");
return false;
}
}
else {
#ifdef FLAC__HAS_OGG
if(d->is_ogg) {
if(!OggFLAC__stream_decoder_process_until_end_of_stream(d->decoder.ogg) && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR while decoding data");
if(!d->continue_through_decode_errors)
return false;
}
if(OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_OK && OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR during decoding");
return false;
}
}
else
#endif
{
if(!FLAC__stream_decoder_process_until_end_of_stream(d->decoder.flac) && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR while decoding data");
if(!d->continue_through_decode_errors)
return false;
}
if(FLAC__stream_decoder_get_state(d->decoder.flac) > FLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR during decoding");
return false;
}
}
if(!FLAC__stream_decoder_process_until_end_of_stream(d->decoder) && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR while decoding data");
if(!d->continue_through_decode_errors)
return false;
}
if(FLAC__stream_decoder_get_state(d->decoder) > FLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) {
flac__utils_printf(stderr, 2, "\n");
print_error_with_state(d, "ERROR during decoding");
return false;
}
if(!d->analysis_mode && !d->test_only && (d->is_wave_out || d->is_aiff_out) && ((d->total_samples * d->channels * ((d->bps+7)/8)) & 1)) {
@@ -542,22 +446,10 @@ int DecoderSession_finish_ok(DecoderSession *d)
{
FLAC__bool ok = true, md5_failure = false;
#ifdef FLAC__HAS_OGG
if(d->is_ogg) {
if(d->decoder.ogg) {
md5_failure = !OggFLAC__stream_decoder_finish(d->decoder.ogg) && !d->aborting_due_to_until;
print_stats(d);
OggFLAC__stream_decoder_delete(d->decoder.ogg);
}
}
else
#endif
{
if(d->decoder.flac) {
md5_failure = !FLAC__stream_decoder_finish(d->decoder.flac) && !d->aborting_due_to_until;
print_stats(d);
FLAC__stream_decoder_delete(d->decoder.flac);
}
if(d->decoder) {
md5_failure = !FLAC__stream_decoder_finish(d->decoder) && !d->aborting_due_to_until;
print_stats(d);
FLAC__stream_decoder_delete(d->decoder);
}
if(d->analysis_mode)
flac__analyze_finish(d->aopts);
@@ -580,20 +472,9 @@ int DecoderSession_finish_ok(DecoderSession *d)
int DecoderSession_finish_error(DecoderSession *d)
{
#ifdef FLAC__HAS_OGG
if(d->is_ogg) {
if(d->decoder.ogg) {
OggFLAC__stream_decoder_finish(d->decoder.ogg);
OggFLAC__stream_decoder_delete(d->decoder.ogg);
}
}
else
#endif
{
if(d->decoder.flac) {
FLAC__stream_decoder_finish(d->decoder.flac);
FLAC__stream_decoder_delete(d->decoder.flac);
}
if(d->decoder) {
FLAC__stream_decoder_finish(d->decoder);
FLAC__stream_decoder_delete(d->decoder);
}
if(d->analysis_mode)
flac__analyze_finish(d->aopts);
@@ -1218,21 +1099,9 @@ void print_error_with_init_status(const DecoderSession *d, const char *message,
void print_error_with_state(const DecoderSession *d, const char *message)
{
const int ilen = strlen(d->inbasefilename) + 1;
const char *state_string;
flac__utils_printf(stderr, 1, "\n%s: %s\n", d->inbasefilename, message);
#ifdef FLAC__HAS_OGG
if(d->is_ogg) {
state_string = OggFLAC__stream_decoder_get_resolved_state_string(d->decoder.ogg);
}
else
#endif
{
state_string = FLAC__stream_decoder_get_resolved_state_string(d->decoder.flac);
}
flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", state_string);
flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", FLAC__stream_decoder_get_resolved_state_string(d->decoder));
/* print out some more info for some errors: */
if (d->aborting_due_to_unparseable) {

View File

@@ -43,10 +43,6 @@
#include "share/grabbag.h"
#include "encode.h"
#ifdef FLAC__HAS_OGG
#include "OggFLAC/stream_encoder.h"
#endif
#ifdef min
#undef min
#endif
@@ -82,12 +78,7 @@ typedef struct {
unsigned blocksize;
unsigned stats_mask;
union {
FLAC__StreamEncoder *flac;
#ifdef FLAC__HAS_OGG
OggFLAC__StreamEncoder *ogg;
#endif
} encoder;
FLAC__StreamEncoder *encoder;
FILE *fin;
FLAC__StreamMetadata *seek_table_template;
@@ -124,11 +115,6 @@ static FLAC__int32 *input_[FLAC__MAX_CHANNELS];
extern FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
extern FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
extern FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value);
#ifdef FLAC__HAS_OGG
extern FLAC__bool OggFLAC__stream_encoder_disable_constant_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
extern FLAC__bool OggFLAC__stream_encoder_disable_fixed_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
extern FLAC__bool OggFLAC__stream_encoder_disable_verbatim_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value);
#endif
/*
* local routines
@@ -1548,10 +1534,7 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_
e->blocksize = 0;
e->stats_mask = 0;
e->encoder.flac = 0;
#ifdef FLAC__HAS_OGG
e->encoder.ogg = 0;
#endif
e->encoder = 0;
e->fin = infile;
e->seek_table_template = 0;
@@ -1561,19 +1544,8 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_
return false;
}
#ifdef FLAC__HAS_OGG
if(e->use_ogg) {
e->encoder.ogg = OggFLAC__stream_encoder_new();
if(0 == e->encoder.ogg) {
flac__utils_printf(stderr, 1, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
EncoderSession_destroy(e);
return false;
}
}
else
#endif
e->encoder.flac = FLAC__stream_encoder_new();
if(0 == e->encoder.flac) {
e->encoder = FLAC__stream_encoder_new();
if(0 == e->encoder) {
flac__utils_printf(stderr, 1, "%s: ERROR creating the encoder instance\n", e->inbasefilename);
EncoderSession_destroy(e);
return false;
@@ -1587,18 +1559,9 @@ void EncoderSession_destroy(EncoderSession *e)
if(e->fin != stdin)
fclose(e->fin);
#ifdef FLAC__HAS_OGG
if(e->use_ogg) {
if(0 != e->encoder.ogg) {
OggFLAC__stream_encoder_delete(e->encoder.ogg);
e->encoder.ogg = 0;
}
}
else
#endif
if(0 != e->encoder.flac) {
FLAC__stream_encoder_delete(e->encoder.flac);
e->encoder.flac = 0;
if(0 != e->encoder) {
FLAC__stream_encoder_delete(e->encoder);
e->encoder = 0;
}
if(0 != e->seek_table_template) {
@@ -1612,18 +1575,9 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a
FLAC__StreamEncoderState fse_state = FLAC__STREAM_ENCODER_OK;
int ret = 0;
#ifdef FLAC__HAS_OGG
if(e->use_ogg) {
if(e->encoder.ogg) {
fse_state = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(e->encoder.ogg);
OggFLAC__stream_encoder_finish(e->encoder.ogg);
}
}
else
#endif
if(e->encoder.flac) {
fse_state = FLAC__stream_encoder_get_state(e->encoder.flac);
FLAC__stream_encoder_finish(e->encoder.flac);
if(e->encoder) {
fse_state = FLAC__stream_encoder_get_state(e->encoder);
FLAC__stream_encoder_finish(e->encoder);
}
if(e->total_samples_to_encode > 0) {
@@ -1651,28 +1605,12 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a
int EncoderSession_finish_error(EncoderSession *e)
{
FLAC__StreamEncoderState fse_state;
#ifdef FLAC__HAS_OGG
FLAC__ASSERT(e->encoder.ogg || e->encoder.flac);
#else
FLAC__ASSERT(e->encoder.flac);
#endif
FLAC__ASSERT(e->encoder);
if(e->total_samples_to_encode > 0)
flac__utils_printf(stderr, 2, "\n");
#ifdef FLAC__HAS_OGG
if(e->use_ogg) {
fse_state = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(e->encoder.ogg);
}
else
#endif
{
fse_state = FLAC__stream_encoder_get_state(e->encoder.flac);
}
if(fse_state == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
if(FLAC__stream_encoder_get_state(e->encoder) == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
print_verify_error(e);
else if(e->outputfile_opened)
/* only want to delete the file if we opened it; otherwise it could be an existing file and our overwrite failed */
@@ -1956,85 +1894,53 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio
e->blocksize = options.blocksize;
e->stats_mask = (options.do_exhaustive_model_search || options.do_qlp_coeff_prec_search)? 0x0f : 0x3f;
FLAC__stream_encoder_set_verify(e->encoder, options.verify);
FLAC__stream_encoder_set_streamable_subset(e->encoder, !options.lax);
FLAC__stream_encoder_set_do_mid_side_stereo(e->encoder, options.do_mid_side);
FLAC__stream_encoder_set_loose_mid_side_stereo(e->encoder, options.loose_mid_side);
FLAC__stream_encoder_set_channels(e->encoder, channels);
FLAC__stream_encoder_set_bits_per_sample(e->encoder, bps);
FLAC__stream_encoder_set_sample_rate(e->encoder, sample_rate);
FLAC__stream_encoder_set_blocksize(e->encoder, options.blocksize);
FLAC__stream_encoder_set_apodization(e->encoder, options.apodizations);
FLAC__stream_encoder_set_max_lpc_order(e->encoder, options.max_lpc_order);
FLAC__stream_encoder_set_qlp_coeff_precision(e->encoder, options.qlp_coeff_precision);
FLAC__stream_encoder_set_do_qlp_coeff_prec_search(e->encoder, options.do_qlp_coeff_prec_search);
FLAC__stream_encoder_set_do_escape_coding(e->encoder, options.do_escape_coding);
FLAC__stream_encoder_set_do_exhaustive_model_search(e->encoder, options.do_exhaustive_model_search);
FLAC__stream_encoder_set_min_residual_partition_order(e->encoder, options.min_residual_partition_order);
FLAC__stream_encoder_set_max_residual_partition_order(e->encoder, options.max_residual_partition_order);
FLAC__stream_encoder_set_rice_parameter_search_dist(e->encoder, options.rice_parameter_search_dist);
FLAC__stream_encoder_set_total_samples_estimate(e->encoder, e->total_samples_to_encode);
FLAC__stream_encoder_set_metadata(e->encoder, (num_metadata > 0)? metadata : 0, num_metadata);
FLAC__stream_encoder_disable_constant_subframes(e->encoder, options.debug.disable_constant_subframes);
FLAC__stream_encoder_disable_fixed_subframes(e->encoder, options.debug.disable_fixed_subframes);
FLAC__stream_encoder_disable_verbatim_subframes(e->encoder, options.debug.disable_verbatim_subframes);
#ifdef FLAC__HAS_OGG
if(e->use_ogg) {
OggFLAC__stream_encoder_set_serial_number(e->encoder.ogg, options.serial_number);
OggFLAC__stream_encoder_set_verify(e->encoder.ogg, options.verify);
OggFLAC__stream_encoder_set_streamable_subset(e->encoder.ogg, !options.lax);
OggFLAC__stream_encoder_set_do_mid_side_stereo(e->encoder.ogg, options.do_mid_side);
OggFLAC__stream_encoder_set_loose_mid_side_stereo(e->encoder.ogg, options.loose_mid_side);
OggFLAC__stream_encoder_set_channels(e->encoder.ogg, channels);
OggFLAC__stream_encoder_set_bits_per_sample(e->encoder.ogg, bps);
OggFLAC__stream_encoder_set_sample_rate(e->encoder.ogg, sample_rate);
OggFLAC__stream_encoder_set_blocksize(e->encoder.ogg, options.blocksize);
OggFLAC__stream_encoder_set_apodization(e->encoder.ogg, options.apodizations);
OggFLAC__stream_encoder_set_max_lpc_order(e->encoder.ogg, options.max_lpc_order);
OggFLAC__stream_encoder_set_qlp_coeff_precision(e->encoder.ogg, options.qlp_coeff_precision);
OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(e->encoder.ogg, options.do_qlp_coeff_prec_search);
OggFLAC__stream_encoder_set_do_escape_coding(e->encoder.ogg, options.do_escape_coding);
OggFLAC__stream_encoder_set_do_exhaustive_model_search(e->encoder.ogg, options.do_exhaustive_model_search);
OggFLAC__stream_encoder_set_min_residual_partition_order(e->encoder.ogg, options.min_residual_partition_order);
OggFLAC__stream_encoder_set_max_residual_partition_order(e->encoder.ogg, options.max_residual_partition_order);
OggFLAC__stream_encoder_set_rice_parameter_search_dist(e->encoder.ogg, options.rice_parameter_search_dist);
OggFLAC__stream_encoder_set_total_samples_estimate(e->encoder.ogg, e->total_samples_to_encode);
OggFLAC__stream_encoder_set_metadata(e->encoder.ogg, (num_metadata > 0)? metadata : 0, num_metadata);
FLAC__stream_encoder_set_serial_number(e->encoder, options.serial_number);
OggFLAC__stream_encoder_disable_constant_subframes(e->encoder.ogg, options.debug.disable_constant_subframes);
OggFLAC__stream_encoder_disable_fixed_subframes(e->encoder.ogg, options.debug.disable_fixed_subframes);
OggFLAC__stream_encoder_disable_verbatim_subframes(e->encoder.ogg, options.debug.disable_verbatim_subframes);
init_status = OggFLAC__stream_encoder_init_file(e->encoder.ogg, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e);
if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
print_error_with_init_status(e, "ERROR initializing encoder", init_status);
if(OggFLAC__stream_encoder_get_state(e->encoder.ogg) != OggFLAC__STREAM_ENCODER_IO_ERROR)
e->outputfile_opened = true;
if(0 != cuesheet)
FLAC__metadata_object_delete(cuesheet);
return false;
}
else
e->outputfile_opened = true;
init_status = FLAC__stream_encoder_init_ogg_file(e->encoder, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e);
}
else
#endif
{
FLAC__stream_encoder_set_verify(e->encoder.flac, options.verify);
FLAC__stream_encoder_set_streamable_subset(e->encoder.flac, !options.lax);
FLAC__stream_encoder_set_do_mid_side_stereo(e->encoder.flac, options.do_mid_side);
FLAC__stream_encoder_set_loose_mid_side_stereo(e->encoder.flac, options.loose_mid_side);
FLAC__stream_encoder_set_channels(e->encoder.flac, channels);
FLAC__stream_encoder_set_bits_per_sample(e->encoder.flac, bps);
FLAC__stream_encoder_set_sample_rate(e->encoder.flac, sample_rate);
FLAC__stream_encoder_set_blocksize(e->encoder.flac, options.blocksize);
FLAC__stream_encoder_set_apodization(e->encoder.flac, options.apodizations);
FLAC__stream_encoder_set_max_lpc_order(e->encoder.flac, options.max_lpc_order);
FLAC__stream_encoder_set_qlp_coeff_precision(e->encoder.flac, options.qlp_coeff_precision);
FLAC__stream_encoder_set_do_qlp_coeff_prec_search(e->encoder.flac, options.do_qlp_coeff_prec_search);
FLAC__stream_encoder_set_do_escape_coding(e->encoder.flac, options.do_escape_coding);
FLAC__stream_encoder_set_do_exhaustive_model_search(e->encoder.flac, options.do_exhaustive_model_search);
FLAC__stream_encoder_set_min_residual_partition_order(e->encoder.flac, options.min_residual_partition_order);
FLAC__stream_encoder_set_max_residual_partition_order(e->encoder.flac, options.max_residual_partition_order);
FLAC__stream_encoder_set_rice_parameter_search_dist(e->encoder.flac, options.rice_parameter_search_dist);
FLAC__stream_encoder_set_total_samples_estimate(e->encoder.flac, e->total_samples_to_encode);
FLAC__stream_encoder_set_metadata(e->encoder.flac, (num_metadata > 0)? metadata : 0, num_metadata);
FLAC__stream_encoder_disable_constant_subframes(e->encoder.flac, options.debug.disable_constant_subframes);
FLAC__stream_encoder_disable_fixed_subframes(e->encoder.flac, options.debug.disable_fixed_subframes);
FLAC__stream_encoder_disable_verbatim_subframes(e->encoder.flac, options.debug.disable_verbatim_subframes);
init_status = FLAC__stream_encoder_init_file(e->encoder.flac, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e);
if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
print_error_with_init_status(e, "ERROR initializing encoder", init_status);
if(FLAC__stream_encoder_get_state(e->encoder.flac) != FLAC__STREAM_ENCODER_IO_ERROR)
e->outputfile_opened = true;
if(0 != cuesheet)
FLAC__metadata_object_delete(cuesheet);
return false;
}
else
e->outputfile_opened = true;
init_status = FLAC__stream_encoder_init_file(e->encoder, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e);
}
if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
print_error_with_init_status(e, "ERROR initializing encoder", init_status);
if(FLAC__stream_encoder_get_state(e->encoder) != FLAC__STREAM_ENCODER_IO_ERROR)
e->outputfile_opened = true;
if(0 != cuesheet)
FLAC__metadata_object_delete(cuesheet);
return false;
}
else
e->outputfile_opened = true;
if(0 != cuesheet)
FLAC__metadata_object_delete(cuesheet);
@@ -2049,12 +1955,7 @@ FLAC__bool EncoderSession_process(EncoderSession *e, const FLAC__int32 * const b
}
}
#ifdef FLAC__HAS_OGG
if(e->use_ogg)
return OggFLAC__stream_encoder_process(e->encoder.ogg, buffer, samples);
else
#endif
return FLAC__stream_encoder_process(e->encoder.flac, buffer, samples);
return FLAC__stream_encoder_process(e->encoder, buffer, samples);
}
FLAC__bool convert_to_seek_table_template(const char *requested_seek_points, int num_requested_seek_points, FLAC__StreamMetadata *cuesheet, EncoderSession *e)
@@ -2489,33 +2390,18 @@ void print_error_with_init_status(const EncoderSession *e, const char *message,
flac__utils_printf(stderr, 1, "%*s init_status = %s\n", ilen, "", FLAC__StreamEncoderInitStatusString[init_status]);
if(init_status == FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR) {
#ifdef FLAC__HAS_OGG
if(e->use_ogg)
state_string = OggFLAC__stream_encoder_get_resolved_state_string(e->encoder.ogg);
else
#endif
state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder.flac);
state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder);
flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", state_string);
/* print out some more info for some errors: */
if(
0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR])
#ifdef FLAC__HAS_OGG
|| 0 == strcmp(state_string, OggFLAC__StreamEncoderStateString[OggFLAC__STREAM_ENCODER_CLIENT_ERROR])
#endif
) {
if(0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR])) {
flac__utils_printf(stderr, 1,
"\n"
"An error occurred while writing; the most common cause is that the disk is full.\n"
);
}
else if(
0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_IO_ERROR])
#ifdef FLAC__HAS_OGG
|| 0 == strcmp(state_string, OggFLAC__StreamEncoderStateString[OggFLAC__STREAM_ENCODER_IO_ERROR])
#endif
) {
else if(0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_IO_ERROR])) {
flac__utils_printf(stderr, 1,
"\n"
"An error occurred opening the output file; it is likely that the output\n"
@@ -2542,22 +2428,12 @@ void print_error_with_state(const EncoderSession *e, const char *message)
flac__utils_printf(stderr, 1, "\n%s: %s\n", e->inbasefilename, message);
#ifdef FLAC__HAS_OGG
if(e->use_ogg)
state_string = OggFLAC__stream_encoder_get_resolved_state_string(e->encoder.ogg);
else
#endif
state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder.flac);
state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder);
flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", state_string);
/* print out some more info for some errors: */
if(
0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR])
#ifdef FLAC__HAS_OGG
|| 0 == strcmp(state_string, OggFLAC__StreamEncoderStateString[OggFLAC__STREAM_ENCODER_CLIENT_ERROR])
#endif
) {
if(0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR])) {
flac__utils_printf(stderr, 1,
"\n"
"An error occurred while writing; the most common cause is that the disk is full.\n"
@@ -2574,12 +2450,7 @@ void print_verify_error(EncoderSession *e)
FLAC__int32 expected;
FLAC__int32 got;
#ifdef FLAC__HAS_OGG
if(e->use_ogg)
OggFLAC__stream_encoder_get_verify_decoder_error_stats(e->encoder.ogg, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
else
#endif
FLAC__stream_encoder_get_verify_decoder_error_stats(e->encoder.flac, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
FLAC__stream_encoder_get_verify_decoder_error_stats(e->encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
flac__utils_printf(stderr, 1, "%s: ERROR: mismatch in decoded data, verify FAILED!\n", e->inbasefilename);
flac__utils_printf(stderr, 1, " Absolute sample=%u, frame=%u, channel=%u, sample=%u, expected %d, got %d\n", (unsigned)absolute_sample, frame_number, channel, sample, expected, got);

View File

@@ -51,7 +51,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\libOggFLAC_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\replaygain_synthesis_static.lib ..\..\obj\release\lib\getopt_static.lib ..\..\obj\release\lib\utf8_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\replaygain_synthesis_static.lib ..\..\obj\release\lib\getopt_static.lib ..\..\obj\release\lib\utf8_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "flac - Win32 Debug"
@@ -76,7 +76,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\libOggFLAC_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\replaygain_synthesis_static.lib ..\..\obj\debug\lib\getopt_static.lib ..\..\obj\debug\lib\utf8_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\replaygain_synthesis_static.lib ..\..\obj\debug\lib\getopt_static.lib ..\..\obj\debug\lib\utf8_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF

View File

@@ -44,8 +44,6 @@ libFLAC___la_LDFLAGS = -version-info 6:0:0
libFLAC___la_LIBADD = ../libFLAC/libFLAC.la
libFLAC___la_SOURCES = \
file_decoder.cpp \
file_encoder.cpp \
metadata.cpp \
stream_decoder.cpp \
stream_encoder.cpp

View File

@@ -38,8 +38,6 @@ LIB_NAME = libFLAC++
INCLUDES = -I$(topdir)/include
SRCS_CPP = \
file_decoder.cpp \
file_encoder.cpp \
metadata.cpp \
stream_decoder.cpp \
stream_encoder.cpp

View File

@@ -1,81 +0,0 @@
/* libFLAC++ - Free Lossless Audio Codec library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "FLAC++/decoder.h"
#include "FLAC/assert.h"
#ifdef _MSC_VER
// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
#pragma warning ( disable : 4800 )
#endif
namespace FLAC {
namespace Decoder {
File::File():
Stream()
{ }
File::~File()
{
}
::FLAC__StreamDecoderInitStatus File::init(FILE *file)
{
FLAC__ASSERT(0 != decoder_);
return ::FLAC__stream_decoder_init_FILE(decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamDecoderInitStatus File::init(const char *filename)
{
FLAC__ASSERT(0 != decoder_);
return ::FLAC__stream_decoder_init_file(decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamDecoderInitStatus File::init(const std::string &filename)
{
return init(filename.c_str());
}
// This is a dummy to satisfy the pure virtual from Stream; the
// read callback will never be called since we are initializing
// with FLAC__stream_decoder_init_FILE() or
// FLAC__stream_decoder_init_file() and those supply the read
// callback internally.
::FLAC__StreamDecoderReadStatus File::read_callback(FLAC__byte buffer[], unsigned *bytes)
{
(void)buffer, (void)bytes;
FLAC__ASSERT(false);
return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; // double protection
}
}
}

View File

@@ -1,95 +0,0 @@
/* libFLAC++ - Free Lossless Audio Codec library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "FLAC++/encoder.h"
#include "FLAC/assert.h"
#ifdef _MSC_VER
// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
#pragma warning ( disable : 4800 )
#endif
namespace FLAC {
namespace Encoder {
File::File():
Stream()
{ }
File::~File()
{
}
::FLAC__StreamEncoderInitStatus File::init(FILE *file)
{
FLAC__ASSERT(is_valid());
return ::FLAC__stream_encoder_init_FILE(encoder_, file, progress_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus File::init(const char *filename)
{
FLAC__ASSERT(is_valid());
return ::FLAC__stream_encoder_init_file(encoder_, filename, progress_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus File::init(const std::string &filename)
{
return init(filename.c_str());
}
// This is a dummy to satisfy the pure virtual from Stream; the
// read callback will never be called since we are initializing
// with FLAC__stream_decoder_init_FILE() or
// FLAC__stream_decoder_init_file() and those supply the read
// callback internally.
::FLAC__StreamEncoderWriteStatus File::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
{
(void)buffer, (void)bytes, (void)samples, (void)current_frame;
FLAC__ASSERT(false);
return ::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; // double protection
}
void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate)
{
(void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate;
}
void File::progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
{
(void)encoder;
FLAC__ASSERT(0 != client_data);
File *instance = reinterpret_cast<File *>(client_data);
FLAC__ASSERT(0 != instance);
instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate);
}
}
}

View File

@@ -92,14 +92,6 @@ LINK32=link.exe
# PROP Default_Filter "cpp"
# Begin Source File
SOURCE=.\file_decoder.cpp
# End Source File
# Begin Source File
SOURCE=.\file_encoder.cpp
# End Source File
# Begin Source File
SOURCE=.\metadata.cpp
# End Source File
# Begin Source File

View File

@@ -85,14 +85,6 @@ LIB32=link.exe -lib
# PROP Default_Filter "cpp"
# Begin Source File
SOURCE=.\file_decoder.cpp
# End Source File
# Begin Source File
SOURCE=.\file_encoder.cpp
# End Source File
# Begin Source File
SOURCE=.\metadata.cpp
# End Source File
# Begin Source File

View File

@@ -40,6 +40,12 @@
namespace FLAC {
namespace Decoder {
// ------------------------------------------------------------
//
// Stream
//
// ------------------------------------------------------------
Stream::Stream():
decoder_(::FLAC__stream_decoder_new())
{ }
@@ -67,6 +73,12 @@ namespace FLAC {
return 0 != decoder_;
}
bool Stream::set_serial_number(long value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__stream_decoder_set_serial_number(decoder_, value);
}
bool Stream::set_md5_checking(bool value)
{
FLAC__ASSERT(is_valid());
@@ -163,6 +175,12 @@ namespace FLAC {
return ::FLAC__stream_decoder_init_stream(decoder_, read_callback_, seek_callback_, tell_callback_, length_callback_, eof_callback_, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamDecoderInitStatus Stream::init_ogg()
{
FLAC__ASSERT(is_valid());
return ::FLAC__stream_decoder_init_ogg_stream(decoder_, read_callback_, seek_callback_, tell_callback_, length_callback_, eof_callback_, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
void Stream::finish()
{
FLAC__ASSERT(is_valid());
@@ -311,5 +329,65 @@ namespace FLAC {
instance->error_callback(status);
}
// ------------------------------------------------------------
//
// File
//
// ------------------------------------------------------------
File::File():
Stream()
{ }
File::~File()
{
}
::FLAC__StreamDecoderInitStatus File::init(FILE *file)
{
FLAC__ASSERT(0 != decoder_);
return ::FLAC__stream_decoder_init_FILE(decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamDecoderInitStatus File::init(const char *filename)
{
FLAC__ASSERT(0 != decoder_);
return ::FLAC__stream_decoder_init_file(decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamDecoderInitStatus File::init(const std::string &filename)
{
return init(filename.c_str());
}
::FLAC__StreamDecoderInitStatus File::init_ogg(FILE *file)
{
FLAC__ASSERT(0 != decoder_);
return ::FLAC__stream_decoder_init_ogg_FILE(decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamDecoderInitStatus File::init_ogg(const char *filename)
{
FLAC__ASSERT(0 != decoder_);
return ::FLAC__stream_decoder_init_ogg_file(decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamDecoderInitStatus File::init_ogg(const std::string &filename)
{
return init_ogg(filename.c_str());
}
// This is a dummy to satisfy the pure virtual from Stream; the
// read callback will never be called since we are initializing
// with FLAC__stream_decoder_init_FILE() or
// FLAC__stream_decoder_init_file() and those supply the read
// callback internally.
::FLAC__StreamDecoderReadStatus File::read_callback(FLAC__byte buffer[], unsigned *bytes)
{
(void)buffer, (void)bytes;
FLAC__ASSERT(false);
return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; // double protection
}
}
}

View File

@@ -41,6 +41,12 @@
namespace FLAC {
namespace Encoder {
// ------------------------------------------------------------
//
// Stream
//
// ------------------------------------------------------------
Stream::Stream():
encoder_(::FLAC__stream_encoder_new())
{ }
@@ -68,6 +74,12 @@ namespace FLAC {
return 0 != encoder_;
}
bool Stream::set_serial_number(long value)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__stream_encoder_set_serial_number(encoder_, value);
}
bool Stream::set_verify(bool value)
{
FLAC__ASSERT(is_valid());
@@ -333,6 +345,12 @@ namespace FLAC {
return ::FLAC__stream_encoder_init_stream(encoder_, write_callback_, seek_callback_, tell_callback_, metadata_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus Stream::init_ogg()
{
FLAC__ASSERT(is_valid());
return ::FLAC__stream_encoder_init_ogg_stream(encoder_, read_callback_, write_callback_, seek_callback_, tell_callback_, metadata_callback_, /*client_data=*/(void*)this);
}
void Stream::finish()
{
FLAC__ASSERT(is_valid());
@@ -351,6 +369,12 @@ namespace FLAC {
return (bool)::FLAC__stream_encoder_process_interleaved(encoder_, buffer, samples);
}
::FLAC__StreamEncoderReadStatus Stream::read_callback(FLAC__byte buffer[], unsigned *bytes)
{
(void)buffer, (void)bytes;
return ::FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED;
}
::FLAC__StreamEncoderSeekStatus Stream::seek_callback(FLAC__uint64 absolute_byte_offset)
{
(void)absolute_byte_offset;
@@ -368,6 +392,15 @@ namespace FLAC {
(void)metadata;
}
::FLAC__StreamEncoderReadStatus Stream::read_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
(void)encoder;
FLAC__ASSERT(0 != client_data);
Stream *instance = reinterpret_cast<Stream *>(client_data);
FLAC__ASSERT(0 != instance);
return instance->read_callback(buffer, bytes);
}
::FLAC__StreamEncoderWriteStatus Stream::write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
{
(void)encoder;
@@ -404,5 +437,79 @@ namespace FLAC {
instance->metadata_callback(metadata);
}
// ------------------------------------------------------------
//
// File
//
// ------------------------------------------------------------
File::File():
Stream()
{ }
File::~File()
{
}
::FLAC__StreamEncoderInitStatus File::init(FILE *file)
{
FLAC__ASSERT(is_valid());
return ::FLAC__stream_encoder_init_FILE(encoder_, file, progress_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus File::init(const char *filename)
{
FLAC__ASSERT(is_valid());
return ::FLAC__stream_encoder_init_file(encoder_, filename, progress_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus File::init(const std::string &filename)
{
return init(filename.c_str());
}
::FLAC__StreamEncoderInitStatus File::init_ogg(FILE *file)
{
FLAC__ASSERT(is_valid());
return ::FLAC__stream_encoder_init_ogg_FILE(encoder_, file, progress_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus File::init_ogg(const char *filename)
{
FLAC__ASSERT(is_valid());
return ::FLAC__stream_encoder_init_ogg_file(encoder_, filename, progress_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus File::init_ogg(const std::string &filename)
{
return init_ogg(filename.c_str());
}
// This is a dummy to satisfy the pure virtual from Stream; the
// read callback will never be called since we are initializing
// with FLAC__stream_decoder_init_FILE() or
// FLAC__stream_decoder_init_file() and those supply the read
// callback internally.
::FLAC__StreamEncoderWriteStatus File::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
{
(void)buffer, (void)bytes, (void)samples, (void)current_frame;
FLAC__ASSERT(false);
return ::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; // double protection
}
void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate)
{
(void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate;
}
void File::progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
{
(void)encoder;
FLAC__ASSERT(0 != client_data);
File *instance = reinterpret_cast<File *>(client_data);
FLAC__ASSERT(0 != instance);
instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate);
}
}
}

View File

@@ -80,6 +80,13 @@ EXTRA_DIST = \
libFLAC_static.dsp \
libFLAC.m4
if FLaC__HAS_OGG
extra_ogg_sources = \
ogg_decoder_aspect.c \
ogg_encoder_aspect.c \
ogg_helper.c \
ogg_mapping.c
endif
# see 'http://www.gnu.org/software/libtool/manual.html#Libtool-versioning' for numbering convention
libFLAC_la_LDFLAGS = -version-info 8:0:0 -lm $(LOCAL_EXTRA_LDFLAGS)
libFLAC_la_SOURCES = \
@@ -98,4 +105,5 @@ libFLAC_la_SOURCES = \
stream_decoder.c \
stream_encoder.c \
stream_encoder_framing.c \
window.c
window.c \
$(extra_ogg_sources)

View File

@@ -73,6 +73,10 @@ SRCS_C = \
memory.c \
metadata_iterators.c \
metadata_object.c \
ogg_decoder_aspect.c \
ogg_encoder_aspect.c \
ogg_helper.c \
ogg_mapping.c \
stream_decoder.c \
stream_encoder.c \
stream_encoder_framing.c \

View File

@@ -41,5 +41,9 @@ noinst_HEADERS = \
md5.h \
memory.h \
metadata.h \
ogg_decoder_aspect.h \
ogg_encoder_aspect.h \
ogg_helper.h \
ogg_mapping.h \
stream_encoder_framing.h \
window.h

View File

@@ -1,4 +1,4 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
@@ -29,16 +29,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OggFLAC__PRIVATE__OGG_DECODER_ASPECT_H
#define OggFLAC__PRIVATE__OGG_DECODER_ASPECT_H
#ifndef FLAC__PRIVATE__OGG_DECODER_ASPECT_H
#define FLAC__PRIVATE__OGG_DECODER_ASPECT_H
#include <ogg/ogg.h>
#include "FLAC/ordinals.h"
#include "FLAC/stream_decoder.h" /* for FLAC__StreamDecoderReadStatus */
#include "OggFLAC/stream_decoder.h"
typedef struct OggFLAC__OggDecoderAspect {
typedef struct FLAC__OggDecoderAspect {
/* these are storage for values that can be set through the API */
FLAC__bool use_first_serial_number;
long serial_number;
@@ -53,28 +52,28 @@ typedef struct OggFLAC__OggDecoderAspect {
ogg_page working_page;
FLAC__bool have_working_packet; /* only if true will the following vars be valid */
ogg_packet working_packet; /* as we work through the packet we will move working_packet.packet forward and working_packet.bytes down */
} OggFLAC__OggDecoderAspect;
} FLAC__OggDecoderAspect;
void OggFLAC__ogg_decoder_aspect_set_serial_number(OggFLAC__OggDecoderAspect *aspect, long value);
void OggFLAC__ogg_decoder_aspect_set_defaults(OggFLAC__OggDecoderAspect *aspect);
FLAC__bool OggFLAC__ogg_decoder_aspect_init(OggFLAC__OggDecoderAspect *aspect);
void OggFLAC__ogg_decoder_aspect_finish(OggFLAC__OggDecoderAspect *aspect);
void OggFLAC__ogg_decoder_aspect_flush(OggFLAC__OggDecoderAspect *aspect);
void OggFLAC__ogg_decoder_aspect_reset(OggFLAC__OggDecoderAspect *aspect);
void FLAC__ogg_decoder_aspect_set_serial_number(FLAC__OggDecoderAspect *aspect, long value);
void FLAC__ogg_decoder_aspect_set_defaults(FLAC__OggDecoderAspect *aspect);
FLAC__bool FLAC__ogg_decoder_aspect_init(FLAC__OggDecoderAspect *aspect);
void FLAC__ogg_decoder_aspect_finish(FLAC__OggDecoderAspect *aspect);
void FLAC__ogg_decoder_aspect_flush(FLAC__OggDecoderAspect *aspect);
void FLAC__ogg_decoder_aspect_reset(FLAC__OggDecoderAspect *aspect);
typedef enum {
OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_OK = 0,
OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM,
OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC,
OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC,
OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION,
OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT,
OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR,
OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR
} OggFLAC__OggDecoderAspectReadStatus;
FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK = 0,
FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM,
FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC,
FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC,
FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION,
FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT,
FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR,
FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR
} FLAC__OggDecoderAspectReadStatus;
typedef OggFLAC__OggDecoderAspectReadStatus (*OggFLAC__OggDecoderAspectReadCallbackProxy)(const void *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
typedef FLAC__OggDecoderAspectReadStatus (*FLAC__OggDecoderAspectReadCallbackProxy)(const void *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wrapper(OggFLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], unsigned *bytes, OggFLAC__OggDecoderAspectReadCallbackProxy read_callback, const OggFLAC__StreamDecoder *decoder, void *client_data);
FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_read_callback_wrapper(FLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], unsigned *bytes, FLAC__OggDecoderAspectReadCallbackProxy read_callback, const FLAC__StreamDecoder *decoder, void *client_data);
#endif

View File

@@ -1,4 +1,4 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
@@ -29,15 +29,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OggFLAC__PRIVATE__OGG_ENCODER_ASPECT_H
#define OggFLAC__PRIVATE__OGG_ENCODER_ASPECT_H
#ifndef FLAC__PRIVATE__OGG_ENCODER_ASPECT_H
#define FLAC__PRIVATE__OGG_ENCODER_ASPECT_H
#include <ogg/ogg.h>
#include "FLAC/ordinals.h"
#include "FLAC/stream_encoder.h" /* for FLAC__StreamEncoderWriteStatus */
typedef struct OggFLAC__OggEncoderAspect {
typedef struct FLAC__OggEncoderAspect {
/* these are storage for values that can be set through the API */
long serial_number;
unsigned num_metadata;
@@ -48,15 +48,15 @@ typedef struct OggFLAC__OggEncoderAspect {
FLAC__bool seen_magic; /* true if we've seen the fLaC magic in the write callback yet */
FLAC__bool is_first_packet;
FLAC__uint64 samples_written;
} OggFLAC__OggEncoderAspect;
} FLAC__OggEncoderAspect;
void OggFLAC__ogg_encoder_aspect_set_serial_number(OggFLAC__OggEncoderAspect *aspect, long value);
FLAC__bool OggFLAC__ogg_encoder_aspect_set_num_metadata(OggFLAC__OggEncoderAspect *aspect, unsigned value);
void OggFLAC__ogg_encoder_aspect_set_defaults(OggFLAC__OggEncoderAspect *aspect);
FLAC__bool OggFLAC__ogg_encoder_aspect_init(OggFLAC__OggEncoderAspect *aspect);
void OggFLAC__ogg_encoder_aspect_finish(OggFLAC__OggEncoderAspect *aspect);
void FLAC__ogg_encoder_aspect_set_serial_number(FLAC__OggEncoderAspect *aspect, long value);
FLAC__bool FLAC__ogg_encoder_aspect_set_num_metadata(FLAC__OggEncoderAspect *aspect, unsigned value);
void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect);
FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect);
void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect);
typedef FLAC__StreamEncoderWriteStatus (*OggFLAC__OggEncoderAspectWriteCallbackProxy)(const void *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
typedef FLAC__StreamEncoderWriteStatus (*FLAC__OggEncoderAspectWriteCallbackProxy)(const void *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
FLAC__StreamEncoderWriteStatus OggFLAC__ogg_encoder_aspect_write_callback_wrapper(OggFLAC__OggEncoderAspect *aspect, const FLAC__uint64 total_samples_estimate, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, OggFLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data);
FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__uint64 total_samples_estimate, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data);
#endif

View File

@@ -1,4 +1,4 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
@@ -29,15 +29,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OggFLAC__PRIVATE__OGG_HELPER_H
#define OggFLAC__PRIVATE__OGG_HELPER_H
#ifndef FLAC__PRIVATE__OGG_HELPER_H
#define FLAC__PRIVATE__OGG_HELPER_H
#include <ogg/ogg.h>
#include "OggFLAC/stream_encoder.h" /* for OggFLAC__StreamEncoder */
#include "FLAC/stream_encoder.h" /* for FLAC__StreamEncoder */
void simple_ogg_page__init(ogg_page *page);
void simple_ogg_page__clear(ogg_page *page);
FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, OggFLAC__StreamEncoderReadCallback read_callback, void *client_data);
FLAC__bool simple_ogg_page__set_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data);
FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderReadCallback read_callback, void *client_data);
FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data);
#endif

View File

@@ -1,4 +1,4 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
@@ -29,35 +29,35 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OggFLAC__PRIVATE__OGG_MAPPING_H
#define OggFLAC__PRIVATE__OGG_MAPPING_H
#ifndef FLAC__PRIVATE__OGG_MAPPING_H
#define FLAC__PRIVATE__OGG_MAPPING_H
#include "FLAC/ordinals.h"
/** The length of the 'FLAC' magic in bytes. */
#define OggFLAC__MAPPING_PACKET_TYPE_LENGTH (1u)
#define FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH (1u)
extern const unsigned OggFLAC__MAPPING_PACKET_TYPE_LEN; /* = 8 bits */
extern const unsigned FLAC__OGG_MAPPING_PACKET_TYPE_LEN; /* = 8 bits */
extern const FLAC__byte OggFLAC__MAPPING_FIRST_HEADER_PACKET_TYPE; /* = 0x7f */
extern const FLAC__byte FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE; /* = 0x7f */
/** The length of the 'FLAC' magic in bytes. */
#define OggFLAC__MAPPING_MAGIC_LENGTH (4u)
#define FLAC__OGG_MAPPING_MAGIC_LENGTH (4u)
extern const FLAC__byte * const OggFLAC__MAPPING_MAGIC; /* = "FLAC" */
extern const FLAC__byte * const FLAC__OGG_MAPPING_MAGIC; /* = "FLAC" */
extern const unsigned OggFLAC__MAPPING_VERSION_MAJOR_LEN; /* = 8 bits */
extern const unsigned OggFLAC__MAPPING_VERSION_MINOR_LEN; /* = 8 bits */
extern const unsigned FLAC__OGG_MAPPING_VERSION_MAJOR_LEN; /* = 8 bits */
extern const unsigned FLAC__OGG_MAPPING_VERSION_MINOR_LEN; /* = 8 bits */
/** The length of the Ogg FLAC mapping major version number in bytes. */
#define OggFLAC__MAPPING_VERSION_MAJOR_LENGTH (1u)
#define FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH (1u)
/** The length of the Ogg FLAC mapping minor version number in bytes. */
#define OggFLAC__MAPPING_VERSION_MINOR_LENGTH (1u)
#define FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH (1u)
extern const unsigned OggFLAC__MAPPING_NUM_HEADERS_LEN; /* = 16 bits */
extern const unsigned FLAC__OGG_MAPPING_NUM_HEADERS_LEN; /* = 16 bits */
/** The length of the #-of-header-packets number bytes. */
#define OggFLAC__MAPPING_NUM_HEADERS_LENGTH (2u)
#define FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH (2u)
#endif

View File

@@ -33,6 +33,9 @@
#define FLAC__PROTECTED__STREAM_DECODER_H
#include "FLAC/stream_decoder.h"
#ifdef FLAC__HAS_OGG
#include "private/ogg_decoder_aspect.h"
#endif
typedef struct FLAC__StreamDecoderProtected {
FLAC__StreamDecoderState state;
@@ -42,6 +45,9 @@ typedef struct FLAC__StreamDecoderProtected {
unsigned sample_rate; /* in Hz */
unsigned blocksize; /* in samples (per channel) */
FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
#ifdef FLAC__HAS_OGG
FLAC__OggDecoderAspect ogg_decoder_aspect;
#endif
} FLAC__StreamDecoderProtected;
/*

View File

@@ -33,6 +33,9 @@
#define FLAC__PROTECTED__STREAM_ENCODER_H
#include "FLAC/stream_encoder.h"
#ifdef FLAC__HAS_OGG
#include "private/ogg_encoder_aspect.h"
#endif
#ifndef FLAC__INTEGER_ONLY_LIBRARY
@@ -98,6 +101,9 @@ typedef struct FLAC__StreamEncoderProtected {
FLAC__StreamMetadata **metadata;
unsigned num_metadata_blocks;
FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
#ifdef FLAC__HAS_OGG
FLAC__OggEncoderAspect ogg_encoder_aspect;
#endif
} FLAC__StreamEncoderProtected;
#endif

View File

@@ -235,6 +235,22 @@ SOURCE=.\metadata_object.c
# End Source File
# Begin Source File
SOURCE=.\ogg_decoder_aspect.c
# End Source File
# Begin Source File
SOURCE=.\ogg_encoder_aspect.c
# End Source File
# Begin Source File
SOURCE=.\ogg_helper.c
# End Source File
# Begin Source File
SOURCE=.\ogg_mapping.c
# End Source File
# Begin Source File
SOURCE=.\stream_decoder.c
# End Source File
# Begin Source File
@@ -303,6 +319,22 @@ SOURCE=.\include\private\metadata.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_decoder_aspect.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_encoder_aspect.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_helper.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_mapping.h
# End Source File
# Begin Source File
SOURCE=.\include\private\stream_encoder_framing.h
# End Source File
# Begin Source File

View File

@@ -228,6 +228,22 @@ SOURCE=.\metadata_object.c
# End Source File
# Begin Source File
SOURCE=.\ogg_decoder_aspect.c
# End Source File
# Begin Source File
SOURCE=.\ogg_encoder_aspect.c
# End Source File
# Begin Source File
SOURCE=.\ogg_helper.c
# End Source File
# Begin Source File
SOURCE=.\ogg_mapping.c
# End Source File
# Begin Source File
SOURCE=.\stream_decoder.c
# End Source File
# Begin Source File
@@ -296,6 +312,22 @@ SOURCE=.\include\private\metadata.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_decoder_aspect.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_encoder_aspect.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_helper.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_mapping.h
# End Source File
# Begin Source File
SOURCE=.\include\private\stream_encoder_framing.h
# End Source File
# Begin Source File

View File

@@ -1,4 +1,4 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
@@ -49,7 +49,7 @@
*
***********************************************************************/
FLAC__bool OggFLAC__ogg_decoder_aspect_init(OggFLAC__OggDecoderAspect *aspect)
FLAC__bool FLAC__ogg_decoder_aspect_init(FLAC__OggDecoderAspect *aspect)
{
/* we will determine the serial number later if necessary */
if(ogg_stream_init(&aspect->stream_state, aspect->serial_number) != 0)
@@ -69,24 +69,24 @@ FLAC__bool OggFLAC__ogg_decoder_aspect_init(OggFLAC__OggDecoderAspect *aspect)
return true;
}
void OggFLAC__ogg_decoder_aspect_finish(OggFLAC__OggDecoderAspect *aspect)
void FLAC__ogg_decoder_aspect_finish(FLAC__OggDecoderAspect *aspect)
{
(void)ogg_sync_clear(&aspect->sync_state);
(void)ogg_stream_clear(&aspect->stream_state);
}
void OggFLAC__ogg_decoder_aspect_set_serial_number(OggFLAC__OggDecoderAspect *aspect, long value)
void FLAC__ogg_decoder_aspect_set_serial_number(FLAC__OggDecoderAspect *aspect, long value)
{
aspect->use_first_serial_number = false;
aspect->serial_number = value;
}
void OggFLAC__ogg_decoder_aspect_set_defaults(OggFLAC__OggDecoderAspect *aspect)
void FLAC__ogg_decoder_aspect_set_defaults(FLAC__OggDecoderAspect *aspect)
{
aspect->use_first_serial_number = true;
}
void OggFLAC__ogg_decoder_aspect_flush(OggFLAC__OggDecoderAspect *aspect)
void FLAC__ogg_decoder_aspect_flush(FLAC__OggDecoderAspect *aspect)
{
(void)ogg_stream_reset(&aspect->stream_state);
(void)ogg_sync_reset(&aspect->sync_state);
@@ -94,15 +94,15 @@ void OggFLAC__ogg_decoder_aspect_flush(OggFLAC__OggDecoderAspect *aspect)
aspect->have_working_page = false;
}
void OggFLAC__ogg_decoder_aspect_reset(OggFLAC__OggDecoderAspect *aspect)
void FLAC__ogg_decoder_aspect_reset(FLAC__OggDecoderAspect *aspect)
{
OggFLAC__ogg_decoder_aspect_flush(aspect);
FLAC__ogg_decoder_aspect_flush(aspect);
if(aspect->use_first_serial_number)
aspect->need_serial_number = true;
}
OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wrapper(OggFLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], unsigned *bytes, OggFLAC__OggDecoderAspectReadCallbackProxy read_callback, const OggFLAC__StreamDecoder *decoder, void *client_data)
FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_read_callback_wrapper(FLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], unsigned *bytes, FLAC__OggDecoderAspectReadCallbackProxy read_callback, const FLAC__StreamDecoder *decoder, void *client_data)
{
static const unsigned OGG_BYTES_CHUNK = 8192;
const unsigned bytes_requested = *bytes;
@@ -161,25 +161,25 @@ OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wr
if (ret > 0) {
aspect->have_working_packet = true;
/* if it is the first header packet, check for magic and a supported Ogg FLAC mapping version */
if (aspect->working_packet.bytes > 0 && aspect->working_packet.packet[0] == OggFLAC__MAPPING_FIRST_HEADER_PACKET_TYPE) {
if (aspect->working_packet.bytes > 0 && aspect->working_packet.packet[0] == FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE) {
const FLAC__byte *b = aspect->working_packet.packet;
const unsigned header_length =
OggFLAC__MAPPING_PACKET_TYPE_LENGTH +
OggFLAC__MAPPING_MAGIC_LENGTH +
OggFLAC__MAPPING_VERSION_MAJOR_LENGTH +
OggFLAC__MAPPING_VERSION_MINOR_LENGTH +
OggFLAC__MAPPING_NUM_HEADERS_LENGTH;
FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
FLAC__OGG_MAPPING_MAGIC_LENGTH +
FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH;
if (aspect->working_packet.bytes < (long)header_length)
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC;
b += OggFLAC__MAPPING_PACKET_TYPE_LENGTH;
if (memcmp(b, OggFLAC__MAPPING_MAGIC, OggFLAC__MAPPING_MAGIC_LENGTH))
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC;
b += OggFLAC__MAPPING_MAGIC_LENGTH;
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC;
b += FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH;
if (memcmp(b, FLAC__OGG_MAPPING_MAGIC, FLAC__OGG_MAPPING_MAGIC_LENGTH))
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC;
b += FLAC__OGG_MAPPING_MAGIC_LENGTH;
aspect->version_major = (unsigned)(*b);
b += OggFLAC__MAPPING_VERSION_MAJOR_LENGTH;
b += FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH;
aspect->version_minor = (unsigned)(*b);
if (aspect->version_major != 1)
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION;
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION;
aspect->working_packet.packet += header_length;
aspect->working_packet.bytes -= header_length;
}
@@ -189,7 +189,7 @@ OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wr
}
else { /* ret < 0 */
/* lost sync, we'll leave the working page for the next call */
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC;
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC;
}
}
}
@@ -214,19 +214,19 @@ OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wr
char *oggbuf = ogg_sync_buffer(&aspect->sync_state, ogg_bytes_to_read);
if(0 == oggbuf) {
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR;
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR;
}
else {
unsigned ogg_bytes_read = ogg_bytes_to_read;
switch(read_callback(decoder, (FLAC__byte*)oggbuf, &ogg_bytes_read, client_data)) {
case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
break;
case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
aspect->end_of_stream = true;
break;
case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
default:
FLAC__ASSERT(0);
}
@@ -234,20 +234,20 @@ OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wr
if(ogg_sync_wrote(&aspect->sync_state, ogg_bytes_read) < 0) {
/* double protection; this will happen if the read callback returns more bytes than the max requested, which would overflow Ogg's internal buffer */
FLAC__ASSERT(0);
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR;
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR;
}
}
}
else { /* ret < 0 */
/* lost sync, bail out */
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC;
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC;
}
}
}
if (aspect->end_of_stream && *bytes == 0) {
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
}
return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
}

View File

@@ -1,4 +1,4 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
@@ -38,8 +38,8 @@
#include "private/ogg_encoder_aspect.h"
#include "private/ogg_mapping.h"
static const FLAC__byte OggFLAC__MAPPING_VERSION_MAJOR = 1;
static const FLAC__byte OggFLAC__MAPPING_VERSION_MINOR = 0;
static const FLAC__byte FLAC__OGG_MAPPING_VERSION_MAJOR = 1;
static const FLAC__byte FLAC__OGG_MAPPING_VERSION_MINOR = 0;
/***********************************************************************
*
@@ -47,7 +47,7 @@ static const FLAC__byte OggFLAC__MAPPING_VERSION_MINOR = 0;
*
***********************************************************************/
FLAC__bool OggFLAC__ogg_encoder_aspect_init(OggFLAC__OggEncoderAspect *aspect)
FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect)
{
/* we will determine the serial number later if necessary */
if(ogg_stream_init(&aspect->stream_state, aspect->serial_number) != 0)
@@ -60,20 +60,20 @@ FLAC__bool OggFLAC__ogg_encoder_aspect_init(OggFLAC__OggEncoderAspect *aspect)
return true;
}
void OggFLAC__ogg_encoder_aspect_finish(OggFLAC__OggEncoderAspect *aspect)
void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect)
{
(void)ogg_stream_clear(&aspect->stream_state);
/*@@@ what about the page? */
}
void OggFLAC__ogg_encoder_aspect_set_serial_number(OggFLAC__OggEncoderAspect *aspect, long value)
void FLAC__ogg_encoder_aspect_set_serial_number(FLAC__OggEncoderAspect *aspect, long value)
{
aspect->serial_number = value;
}
FLAC__bool OggFLAC__ogg_encoder_aspect_set_num_metadata(OggFLAC__OggEncoderAspect *aspect, unsigned value)
FLAC__bool FLAC__ogg_encoder_aspect_set_num_metadata(FLAC__OggEncoderAspect *aspect, unsigned value)
{
if(value < (1u << OggFLAC__MAPPING_NUM_HEADERS_LEN)) {
if(value < (1u << FLAC__OGG_MAPPING_NUM_HEADERS_LEN)) {
aspect->num_metadata = value;
return true;
}
@@ -81,7 +81,7 @@ FLAC__bool OggFLAC__ogg_encoder_aspect_set_num_metadata(OggFLAC__OggEncoderAspec
return false;
}
void OggFLAC__ogg_encoder_aspect_set_defaults(OggFLAC__OggEncoderAspect *aspect)
void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect)
{
aspect->serial_number = 0;
aspect->num_metadata = 0;
@@ -108,7 +108,7 @@ void OggFLAC__ogg_encoder_aspect_set_defaults(OggFLAC__OggEncoderAspect *aspect)
* separate write callback for the fLaC magic, and then separate write
* callbacks for each metadata block and audio frame.
*/
FLAC__StreamEncoderWriteStatus OggFLAC__ogg_encoder_aspect_write_callback_wrapper(OggFLAC__OggEncoderAspect *aspect, const FLAC__uint64 total_samples_estimate, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, OggFLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data)
FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__uint64 total_samples_estimate, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data)
{
/* WATCHOUT:
* This depends on the behavior of FLAC__StreamEncoder that 'samples'
@@ -123,11 +123,11 @@ FLAC__StreamEncoderWriteStatus OggFLAC__ogg_encoder_aspect_write_callback_wrappe
if(aspect->seen_magic) {
ogg_packet packet;
FLAC__byte synthetic_first_packet_body[
OggFLAC__MAPPING_PACKET_TYPE_LENGTH +
OggFLAC__MAPPING_MAGIC_LENGTH +
OggFLAC__MAPPING_VERSION_MAJOR_LENGTH +
OggFLAC__MAPPING_VERSION_MINOR_LENGTH +
OggFLAC__MAPPING_NUM_HEADERS_LENGTH +
FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
FLAC__OGG_MAPPING_MAGIC_LENGTH +
FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
FLAC__STREAM_SYNC_LENGTH +
FLAC__STREAM_METADATA_HEADER_LENGTH +
FLAC__STREAM_METADATA_STREAMINFO_LENGTH
@@ -147,17 +147,17 @@ FLAC__StreamEncoderWriteStatus OggFLAC__ogg_encoder_aspect_write_callback_wrappe
return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
}
/* add first header packet type */
*b = OggFLAC__MAPPING_FIRST_HEADER_PACKET_TYPE;
b += OggFLAC__MAPPING_PACKET_TYPE_LENGTH;
*b = FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE;
b += FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH;
/* add 'FLAC' mapping magic */
memcpy(b, OggFLAC__MAPPING_MAGIC, OggFLAC__MAPPING_MAGIC_LENGTH);
b += OggFLAC__MAPPING_MAGIC_LENGTH;
memcpy(b, FLAC__OGG_MAPPING_MAGIC, FLAC__OGG_MAPPING_MAGIC_LENGTH);
b += FLAC__OGG_MAPPING_MAGIC_LENGTH;
/* add Ogg FLAC mapping major version number */
memcpy(b, &OggFLAC__MAPPING_VERSION_MAJOR, OggFLAC__MAPPING_VERSION_MAJOR_LENGTH);
b += OggFLAC__MAPPING_VERSION_MAJOR_LENGTH;
memcpy(b, &FLAC__OGG_MAPPING_VERSION_MAJOR, FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH);
b += FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH;
/* add Ogg FLAC mapping minor version number */
memcpy(b, &OggFLAC__MAPPING_VERSION_MINOR, OggFLAC__MAPPING_VERSION_MINOR_LENGTH);
b += OggFLAC__MAPPING_VERSION_MINOR_LENGTH;
memcpy(b, &FLAC__OGG_MAPPING_VERSION_MINOR, FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH);
b += FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH;
/* add number of header packets */
*b = (FLAC__byte)(aspect->num_metadata >> 8);
b++;

View File

@@ -1,4 +1,4 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
@@ -40,32 +40,32 @@
#include "protected/stream_encoder.h"
static FLAC__bool full_read_(OggFLAC__StreamEncoder *encoder, FLAC__byte *buffer, unsigned bytes, OggFLAC__StreamEncoderReadCallback read_callback, void *client_data)
static FLAC__bool full_read_(FLAC__StreamEncoder *encoder, FLAC__byte *buffer, unsigned bytes, FLAC__StreamEncoderReadCallback read_callback, void *client_data)
{
while(bytes > 0) {
unsigned bytes_read = bytes;
switch(read_callback(encoder, buffer, &bytes_read, client_data)) {
case OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE:
case FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE:
bytes -= bytes_read;
buffer += bytes_read;
break;
case OggFLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM:
case FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM:
if(bytes_read == 0) {
encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
return false;
}
bytes -= bytes_read;
buffer += bytes_read;
break;
case OggFLAC__STREAM_ENCODER_READ_STATUS_ABORT:
encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR;
case FLAC__STREAM_ENCODER_READ_STATUS_ABORT:
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
return false;
case OggFLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED:
case FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED:
return false;
default:
/* double protection: */
FLAC__ASSERT(0);
encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
return false;
}
}
@@ -90,7 +90,7 @@ void simple_ogg_page__clear(ogg_page *page)
simple_ogg_page__init(page);
}
FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, OggFLAC__StreamEncoderReadCallback read_callback, void *client_data)
FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderReadCallback read_callback, void *client_data)
{
static const unsigned OGG_HEADER_FIXED_PORTION_LEN = 27;
static const unsigned OGG_MAX_HEADER_LEN = 27/*OGG_HEADER_FIXED_PORTION_LEN*/ + 255;
@@ -107,13 +107,13 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64
return false;
if((seek_status = seek_callback((FLAC__StreamEncoder*)encoder, position, client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
return false;
}
/* allocate space for the page header */
if(0 == (page->header = (unsigned char *)malloc(OGG_MAX_HEADER_LEN))) {
encoder->protected_->state = OggFLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
return false;
}
@@ -131,7 +131,7 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64
memcmp(page->header+6, "\0\0\0\0\0\0\0\0", 8) || /* granulepos is non-zero */
page->header[26] == 0 /* packet is 0-size */
) {
encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
return false;
}
@@ -145,7 +145,7 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64
/* check to see that it specifies a single packet */
for(i = 0; i < (unsigned)page->header[26] - 1; i++) {
if(page->header[i + OGG_HEADER_FIXED_PORTION_LEN] != 255) {
encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
return false;
}
}
@@ -155,7 +155,7 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64
/* allocate space for the page body */
if(0 == (page->body = (unsigned char *)malloc(page->body_len))) {
encoder->protected_->state = OggFLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
return false;
}
@@ -167,14 +167,14 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64
memcpy(crc, page->header+22, 4);
ogg_page_checksum_set(page);
if(memcmp(crc, page->header+22, 4)) {
encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
return false;
}
return true;
}
FLAC__bool simple_ogg_page__set_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data)
FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data)
{
FLAC__StreamEncoderSeekStatus seek_status;
@@ -188,7 +188,7 @@ FLAC__bool simple_ogg_page__set_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64
return false;
if((seek_status = seek_callback((FLAC__StreamEncoder*)encoder, position, client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
return false;
}
@@ -196,7 +196,7 @@ FLAC__bool simple_ogg_page__set_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64
/* re-write the page */
if(write_callback((FLAC__StreamEncoder*)encoder, page->header, page->header_len, 0, 0, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR;
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
return false;
}

View File

@@ -1,4 +1,4 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
/* libFLAC - Free Lossless Audio Codec
* Copyright (C) 2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
@@ -35,13 +35,13 @@
#include "private/ogg_mapping.h"
const unsigned OggFLAC__MAPPING_PACKET_TYPE_LEN = 8; /* bits */
const unsigned FLAC__OGG_MAPPING_PACKET_TYPE_LEN = 8; /* bits */
const FLAC__byte OggFLAC__MAPPING_FIRST_HEADER_PACKET_TYPE = 0x7f;
const FLAC__byte FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE = 0x7f;
const FLAC__byte * const OggFLAC__MAPPING_MAGIC = (const FLAC__byte * const)"FLAC";
const FLAC__byte * const FLAC__OGG_MAPPING_MAGIC = (const FLAC__byte * const)"FLAC";
const unsigned OggFLAC__MAPPING_VERSION_MAJOR_LEN = 8; /* bits */
const unsigned OggFLAC__MAPPING_VERSION_MINOR_LEN = 8; /* bits */
const unsigned FLAC__OGG_MAPPING_VERSION_MAJOR_LEN = 8; /* bits */
const unsigned FLAC__OGG_MAPPING_VERSION_MINOR_LEN = 8; /* bits */
const unsigned OggFLAC__MAPPING_NUM_HEADERS_LEN = 16; /* bits */
const unsigned FLAC__OGG_MAPPING_NUM_HEADERS_LEN = 16; /* bits */

View File

@@ -76,6 +76,17 @@
#define FLAC__U64L(x) x##LLU
#endif
/* technically this should be in an "export.c" but this is convenient enough */
int FLAC_API_SUPPORTS_OGG_FLAC =
#if FLAC__HAS_OGG
1
#else
0
#endif
;
/***********************************************************************
*
* Private static data
@@ -113,9 +124,16 @@ static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned
static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual);
static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
static FLAC__bool read_callback_(FLAC__byte buffer[], unsigned *bytes, void *client_data);
#ifdef FLAC__HAS_OGG
static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes);
static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
#endif
static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
#ifdef FLAC__HAS_OGG
static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
#endif
static FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
static FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
@@ -129,6 +147,9 @@ static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *c
***********************************************************************/
typedef struct FLAC__StreamDecoderPrivate {
#ifdef FLAC__HAS_OGG
FLAC__bool is_ogg;
#endif
FLAC__StreamDecoderReadCallback read_callback;
FLAC__StreamDecoderSeekCallback seek_callback;
FLAC__StreamDecoderTellCallback tell_callback;
@@ -178,6 +199,9 @@ typedef struct FLAC__StreamDecoderPrivate {
FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
FLAC__uint64 target_sample;
unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
#ifdef FLAC__HAS_OGG
FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
#endif
} FLAC__StreamDecoderPrivate;
/***********************************************************************
@@ -192,6 +216,7 @@ FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
"FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
"FLAC__STREAM_DECODER_READ_FRAME",
"FLAC__STREAM_DECODER_END_OF_STREAM",
"FLAC__STREAM_DECODER_OGG_ERROR",
"FLAC__STREAM_DECODER_SEEK_ERROR",
"FLAC__STREAM_DECODER_ABORTED",
"FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
@@ -200,6 +225,7 @@ FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
"FLAC__STREAM_DECODER_INIT_STATUS_OK",
"FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
"FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
"FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
"FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
@@ -340,7 +366,7 @@ FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
*
***********************************************************************/
FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
static FLAC__StreamDecoderInitStatus init_stream_internal_(
FLAC__StreamDecoder *decoder,
FLAC__StreamDecoderReadCallback read_callback,
FLAC__StreamDecoderSeekCallback seek_callback,
@@ -350,7 +376,8 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
FLAC__StreamDecoderWriteCallback write_callback,
FLAC__StreamDecoderMetadataCallback metadata_callback,
FLAC__StreamDecoderErrorCallback error_callback,
void *client_data
void *client_data,
FLAC__bool is_ogg
)
{
FLAC__ASSERT(0 != decoder);
@@ -358,6 +385,11 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
#ifndef FLAC__HAS_OGG
if(is_ogg)
return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
#endif
if(
0 == read_callback ||
0 == write_callback ||
@@ -366,6 +398,12 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
)
return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
#ifdef FLAC__HAS_OGG
decoder->private_->is_ogg = is_ogg;
if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
#endif
/*
* get the CPU info and set the function pointers
*/
@@ -436,13 +474,70 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
return FLAC__STREAM_DECODER_INIT_STATUS_OK;
}
FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
FLAC__StreamDecoder *decoder,
FLAC__StreamDecoderReadCallback read_callback,
FLAC__StreamDecoderSeekCallback seek_callback,
FLAC__StreamDecoderTellCallback tell_callback,
FLAC__StreamDecoderLengthCallback length_callback,
FLAC__StreamDecoderEofCallback eof_callback,
FLAC__StreamDecoderWriteCallback write_callback,
FLAC__StreamDecoderMetadataCallback metadata_callback,
FLAC__StreamDecoderErrorCallback error_callback,
void *client_data
)
{
return init_stream_internal_(
decoder,
read_callback,
seek_callback,
tell_callback,
length_callback,
eof_callback,
write_callback,
metadata_callback,
error_callback,
client_data,
/*is_ogg=*/false
);
}
FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
FLAC__StreamDecoder *decoder,
FLAC__StreamDecoderReadCallback read_callback,
FLAC__StreamDecoderSeekCallback seek_callback,
FLAC__StreamDecoderTellCallback tell_callback,
FLAC__StreamDecoderLengthCallback length_callback,
FLAC__StreamDecoderEofCallback eof_callback,
FLAC__StreamDecoderWriteCallback write_callback,
FLAC__StreamDecoderMetadataCallback metadata_callback,
FLAC__StreamDecoderErrorCallback error_callback,
void *client_data
)
{
return init_stream_internal_(
decoder,
read_callback,
seek_callback,
tell_callback,
length_callback,
eof_callback,
write_callback,
metadata_callback,
error_callback,
client_data,
/*is_ogg=*/true
);
}
static FLAC__StreamDecoderInitStatus init_FILE_internal_(
FLAC__StreamDecoder *decoder,
FILE *file,
FLAC__StreamDecoderWriteCallback write_callback,
FLAC__StreamDecoderMetadataCallback metadata_callback,
FLAC__StreamDecoderErrorCallback error_callback,
void *client_data
void *client_data,
FLAC__bool is_ogg
)
{
FLAC__ASSERT(0 != decoder);
@@ -464,7 +559,7 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
decoder->private_->file = file;
return FLAC__stream_decoder_init_stream(
return init_stream_internal_(
decoder,
file_read_callback_,
decoder->private_->file == stdin? 0: file_seek_callback_,
@@ -474,17 +569,43 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
write_callback,
metadata_callback,
error_callback,
client_data
client_data,
is_ogg
);
}
FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
FLAC__StreamDecoder *decoder,
FILE *file,
FLAC__StreamDecoderWriteCallback write_callback,
FLAC__StreamDecoderMetadataCallback metadata_callback,
FLAC__StreamDecoderErrorCallback error_callback,
void *client_data
)
{
return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
}
FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
FLAC__StreamDecoder *decoder,
FILE *file,
FLAC__StreamDecoderWriteCallback write_callback,
FLAC__StreamDecoderMetadataCallback metadata_callback,
FLAC__StreamDecoderErrorCallback error_callback,
void *client_data
)
{
return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
}
static FLAC__StreamDecoderInitStatus init_file_internal_(
FLAC__StreamDecoder *decoder,
const char *filename,
FLAC__StreamDecoderWriteCallback write_callback,
FLAC__StreamDecoderMetadataCallback metadata_callback,
FLAC__StreamDecoderErrorCallback error_callback,
void *client_data
void *client_data,
FLAC__bool is_ogg
)
{
FILE *file;
@@ -507,7 +628,31 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
if(0 == file)
return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
return FLAC__stream_decoder_init_FILE(decoder, file, write_callback, metadata_callback, error_callback, client_data);
return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
}
FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
FLAC__StreamDecoder *decoder,
const char *filename,
FLAC__StreamDecoderWriteCallback write_callback,
FLAC__StreamDecoderMetadataCallback metadata_callback,
FLAC__StreamDecoderErrorCallback error_callback,
void *client_data
)
{
return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
}
FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
FLAC__StreamDecoder *decoder,
const char *filename,
FLAC__StreamDecoderWriteCallback write_callback,
FLAC__StreamDecoderMetadataCallback metadata_callback,
FLAC__StreamDecoderErrorCallback error_callback,
void *client_data
)
{
return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
}
FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
@@ -552,6 +697,11 @@ FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
decoder->private_->output_capacity = 0;
decoder->private_->output_channels = 0;
#ifdef FLAC__HAS_OGG
if(decoder->private_->is_ogg)
FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
#endif
if(0 != decoder->private_->file) {
if(decoder->private_->file != stdin)
fclose(decoder->private_->file);
@@ -571,6 +721,23 @@ FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
return !md5_failed;
}
FLAC_API FLAC__bool FLAC__stream_decoder_set_serial_number(FLAC__StreamDecoder *decoder, long value)
{
FLAC__ASSERT(0 != decoder);
FLAC__ASSERT(0 != decoder->private_);
FLAC__ASSERT(0 != decoder->protected_);
if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
return false;
#ifdef FLAC__HAS_OGG
/* can't check decoder->private_->is_ogg since that's not set until init time */
FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
return true;
#else
(void)value;
return false;
#endif
}
FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
{
FLAC__ASSERT(0 != decoder);
@@ -764,6 +931,10 @@ FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamD
FLAC__ASSERT(0 != decoder->private_);
FLAC__ASSERT(0 != position);
#ifdef FLAC__HAS_OGG
if(decoder->private_->is_ogg)
return false;
#endif
if(0 == decoder->private_->tell_callback)
return false;
if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
@@ -782,6 +953,11 @@ FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
decoder->private_->samples_decoded = 0;
decoder->private_->do_md5_checking = false;
#ifdef FLAC__HAS_OGG
if(decoder->private_->is_ogg)
FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
#endif
if(!FLAC__bitbuffer_clear(decoder->private_->input)) {
decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
return false;
@@ -804,6 +980,12 @@ FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
return false;
}
#ifdef FLAC__HAS_OGG
/*@@@ could go in !internal_reset_hack block below */
if(decoder->private_->is_ogg)
FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
#endif
/* Rewind if necessary. If FLAC__stream_decoder_init() is calling us,
* (internal_reset_hack) don't try to rewind since we are already at
* the beginning of the stream and don't want to fail if the input is
@@ -1007,6 +1189,7 @@ FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *deco
decoder->private_->is_seeking = false;
return false;
}
/* if we haven't finished processing the metadata yet, do that so we have the STREAMINFO, SEEK_TABLE, and first_frame_offset */
if(
decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
@@ -1025,7 +1208,13 @@ FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *deco
}
{
FLAC__bool ok = seek_to_absolute_sample_(decoder, length, sample);
const FLAC__bool ok =
#ifdef FLAC__HAS_OGG
decoder->private_->is_ogg?
seek_to_absolute_sample_ogg_(decoder, length, sample) :
#endif
seek_to_absolute_sample_(decoder, length, sample)
;
decoder->private_->is_seeking = false;
return ok;
}
@@ -1051,6 +1240,9 @@ unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecod
void set_defaults_(FLAC__StreamDecoder *decoder)
{
#ifdef FLAC__HAS_OGG
decoder->private_->is_ogg = false;
#endif
decoder->private_->read_callback = 0;
decoder->private_->seek_callback = 0;
decoder->private_->tell_callback = 0;
@@ -1066,6 +1258,10 @@ void set_defaults_(FLAC__StreamDecoder *decoder)
decoder->private_->metadata_filter_ids_count = 0;
decoder->protected_->md5_checking = false;
#ifdef FLAC__HAS_OGG
FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
#endif
}
/*
@@ -1483,7 +1679,7 @@ FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_
length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
/* if there is a partial point left, skip over it */
if(length > 0) {
/*@@@ do an error_callback() here? there's an argument for either way */
/*@@@ do a send_error_to_client_() here? there's an argument for either way */
if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, 0, length, read_callback_, decoder))
return false; /* read_callback_ sets the state for us */
}
@@ -2544,7 +2740,8 @@ FLAC__bool read_callback_(FLAC__byte buffer[], unsigned *bytes, void *client_dat
{
FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
if(decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)) {
/* see [1] HACK NOTE below for why we don't call the eof_callback when decoding Ogg FLAC */
if(!decoder->private_->is_ogg && decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)) {
*bytes = 0;
decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
return false;
@@ -2565,13 +2762,20 @@ FLAC__bool read_callback_(FLAC__byte buffer[], unsigned *bytes, void *client_dat
return false;
}
else {
const FLAC__StreamDecoderReadStatus status = decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data);
const FLAC__StreamDecoderReadStatus status =
#ifdef FLAC__HAS_OGG
decoder->private_->is_ogg?
read_callback_ogg_aspect_(decoder, buffer, bytes) :
#endif
decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
;
if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
return false;
}
else if(*bytes == 0) {
if(status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM || (decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data))) {
/* see [1] HACK NOTE below for why we don't call the eof_callback when decoding Ogg FLAC */
if(status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM || (!decoder->private_->is_ogg && decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data))) {
decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
return false;
}
@@ -2587,8 +2791,63 @@ FLAC__bool read_callback_(FLAC__byte buffer[], unsigned *bytes, void *client_dat
decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
return false;
}
/* [1] @@@ HACK NOTE: The end-of-stream checking has to be hacked around
* for Ogg FLAC. This is because the ogg decoder aspect can lose sync
* and at the same time hit the end of the stream. There is no way to
* report an Ogg sync loss through the callbacks (see note in
* read_callback_ogg_aspect_()) so it returns CONTINUE with *bytes==0.
* So to keep the decoder from stopping at this point we gate the call
* to the eof_callback and let the Ogg decoder aspect set the
* end-of-stream state when it is needed.
*/
}
#ifdef FLAC__HAS_OGG
FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes)
{
switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
/* we don't really have a way to handle lost sync via read
* callback so we'll let it pass and let the underlying
* FLAC decoder catch the error
*/
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
default:
FLAC__ASSERT(0);
/* double protection */
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
}
FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
default:
/* double protection: */
FLAC__ASSERT(0);
return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
}
}
#endif
FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
{
if(decoder->private_->is_seeking) {
@@ -2598,6 +2857,9 @@ FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder
FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
#ifdef FLAC__HAS_OGG
decoder->private_->got_a_frame = true;
#endif
decoder->private_->last_frame = *frame; /* save the frame */
if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
unsigned delta = (unsigned)(target_sample - this_frame_sample);
@@ -2882,6 +3144,145 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s
return true;
}
#ifdef FLAC__HAS_OGG
FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
{
FLAC__uint64 left_pos = 0, right_pos = stream_length;
FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
FLAC__uint64 this_frame_sample = 0; /* only initialized to avoid compiler warning */
FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
FLAC__bool did_a_seek;
unsigned iteration = 0;
/* In the first iterations, we will calculate the target byte position
* by the distance from the target sample to left_sample and
* right_sample (let's call it "proportional search"). After that, we
* will switch to binary search.
*/
unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
/* We will switch to a linear search once our current sample is less
* than this number of samples ahead of the target sample
*/
static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
/* If the total number of samples is unknown, use a large value, and
* force binary search immediately.
*/
if(right_sample == 0) {
right_sample = (FLAC__uint64)(-1);
BINARY_SEARCH_AFTER_ITERATION = 0;
}
decoder->private_->target_sample = target_sample;
for( ; ; iteration++) {
if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
pos = (right_pos + left_pos) / 2;
}
else {
#ifndef FLAC__INTEGER_ONLY_LIBRARY
#if defined _MSC_VER || defined __MINGW32__
/* with MSVC you have to spoon feed it the casting */
pos = (FLAC__uint64)((FLAC__double)(FLAC__int64)(target_sample - left_sample) / (FLAC__double)(FLAC__int64)(right_sample - left_sample) * (FLAC__double)(FLAC__int64)(right_pos - left_pos));
#else
pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
#endif
#else
/* a little less accurate: */
if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
else /* @@@ WATCHOUT, ~2TB limit */
pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
#endif
/* @@@ TODO: might want to limit pos to some distance
* before EOF, to make sure we land before the last frame,
* thereby getting a this_frame_sample and so having a better
* estimate. @@@@@@DELETE:this would also mostly (or totally if we could
* be sure to land before the last frame) avoid the
* end-of-stream case we have to check later.
*/
}
/* physical seek */
if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
return false;
}
if(!FLAC__stream_decoder_flush(decoder)) {
/* above call sets the state for us */
return false;
}
did_a_seek = true;
}
else
did_a_seek = false;
decoder->private_->got_a_frame = false;
if(!FLAC__stream_decoder_process_single(decoder)) {
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
return false;
}
if(!decoder->private_->got_a_frame) {
if(did_a_seek) {
/* this can happen if we seek to a point after the last frame; we drop
* to binary search right away in this case to avoid any wasted
* iterations of proportional search.
*/
right_pos = pos;
BINARY_SEARCH_AFTER_ITERATION = 0;
}
else {
/* this can probably only happen if total_samples is unknown and the
* target_sample is past the end of the stream
*/
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
return false;
}
}
/* our write callback will change the state when it gets to the target frame */
else if(!decoder->private_->is_seeking/*@@@@@@ && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM*/) {
break;
}
else {
this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
if (did_a_seek) {
if (this_frame_sample <= target_sample) {
/* The 'equal' case should not happen, since
* FLAC__stream_decoder_process_single()
* should recognize that it has hit the
* target sample and we would exit through
* the 'break' above.
*/
FLAC__ASSERT(this_frame_sample != target_sample);
left_sample = this_frame_sample;
/* sanity check to avoid infinite loop */
if (left_pos == pos) {
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
return false;
}
left_pos = pos;
}
else if(this_frame_sample > target_sample) {
right_sample = this_frame_sample;
/* sanity check to avoid infinite loop */
if (right_pos == pos) {
decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
return false;
}
right_pos = pos;
}
}
}
}
return true;
}
#endif
FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
(void)client_data;

View File

@@ -64,6 +64,9 @@
#include "private/lpc.h"
#include "private/md5.h"
#include "private/memory.h"
#ifdef FLAC__HAS_OGG
#include "private/ogg_helper.h"
#endif
#include "private/stream_encoder_framing.h"
#include "private/window.h"
@@ -105,8 +108,9 @@ static void set_defaults_(FLAC__StreamEncoder *encoder);
static void free_(FLAC__StreamEncoder *encoder);
static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_size);
static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples);
static FLAC__StreamEncoderWriteStatus write_frame_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples);
static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples);
static void update_metadata_(const FLAC__StreamEncoder *encoder);
static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_frame);
static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_frame);
@@ -305,6 +309,7 @@ static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamD
static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
static FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
static FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data);
@@ -374,6 +379,10 @@ typedef struct FLAC__StreamEncoderPrivate {
FLAC__bool disable_constant_subframes;
FLAC__bool disable_fixed_subframes;
FLAC__bool disable_verbatim_subframes;
#if FLAC__HAS_OGG
FLAC__bool is_ogg;
#endif
FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
FLAC__StreamEncoderSeekCallback seek_callback;
FLAC__StreamEncoderTellCallback tell_callback;
FLAC__StreamEncoderWriteCallback write_callback;
@@ -438,6 +447,7 @@ typedef struct FLAC__StreamEncoderPrivate {
FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
"FLAC__STREAM_ENCODER_OK",
"FLAC__STREAM_ENCODER_UNINITIALIZED",
"FLAC__STREAM_ENCODER_OGG_ERROR",
"FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
"FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
"FLAC__STREAM_ENCODER_CLIENT_ERROR",
@@ -449,6 +459,7 @@ FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
"FLAC__STREAM_ENCODER_INIT_STATUS_OK",
"FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
"FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
"FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
@@ -464,6 +475,13 @@ FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
"FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
};
FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
"FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
"FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
"FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
"FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
};
FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
"FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
"FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
@@ -597,7 +615,16 @@ FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
*
***********************************************************************/
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data)
static FLAC__StreamEncoderInitStatus init_stream_internal_(
FLAC__StreamEncoder *encoder,
FLAC__StreamEncoderReadCallback read_callback,
FLAC__StreamEncoderWriteCallback write_callback,
FLAC__StreamEncoderSeekCallback seek_callback,
FLAC__StreamEncoderTellCallback tell_callback,
FLAC__StreamEncoderMetadataCallback metadata_callback,
void *client_data,
FLAC__bool is_ogg
)
{
unsigned i;
FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
@@ -607,6 +634,11 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
#ifndef FLAC__HAS_OGG
if(is_ogg)
return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
#endif
if(0 == write_callback || (seek_callback && 0 == tell_callback))
return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
@@ -725,6 +757,32 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St
if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
#if FLAC__HAS_OGG
/* reorder metadata if necessary to ensure that any VORBIS_COMMENT is the first, according to the mapping spec */
if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
unsigned i;
for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
for( ; i > 0; i--)
encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
encoder->protected_->metadata[0] = vc;
break;
}
}
}
#endif
/* keep track of any SEEKTABLE block */
if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
unsigned i;
for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
break; /* take only the first one */
}
}
}
/* validate metadata */
if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
@@ -894,6 +952,15 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St
/* set state to OK; from here on, errors are fatal and we'll override the state then */
encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
#if FLAC__HAS_OGG
encoder->private_->is_ogg = is_ogg;
if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
}
#endif
encoder->private_->read_callback = read_callback;
encoder->private_->write_callback = write_callback;
encoder->private_->seek_callback = seek_callback;
encoder->private_->tell_callback = tell_callback;
@@ -1016,10 +1083,10 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St
* if not, we will write an empty one (FLAC__add_metadata_block()
* automatically supplies the vendor string).
*
* WATCHOUT: libOggFLAC depends on us to write this block after the
* STREAMINFO since that's what the mapping requires. (In the case
* that metadata_has_vorbis_comment is true it will have already
* insured that the metadata list is properly ordered.)
* WATCHOUT: the Ogg FLAC mapping requires us to write this block after
* the STREAMINFO. (In the case that metadata_has_vorbis_comment is
* true it will have already insured that the metadata list is properly
* ordered.)
*/
if(!metadata_has_vorbis_comment) {
FLAC__StreamMetadata vorbis_comment;
@@ -1075,7 +1142,56 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St
return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
}
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data)
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
FLAC__StreamEncoder *encoder,
FLAC__StreamEncoderWriteCallback write_callback,
FLAC__StreamEncoderSeekCallback seek_callback,
FLAC__StreamEncoderTellCallback tell_callback,
FLAC__StreamEncoderMetadataCallback metadata_callback,
void *client_data
)
{
return init_stream_internal_(
encoder,
/*read_callback=*/0,
write_callback,
seek_callback,
tell_callback,
metadata_callback,
client_data,
/*is_ogg=*/false
);
}
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
FLAC__StreamEncoder *encoder,
FLAC__StreamEncoderReadCallback read_callback,
FLAC__StreamEncoderWriteCallback write_callback,
FLAC__StreamEncoderSeekCallback seek_callback,
FLAC__StreamEncoderTellCallback tell_callback,
FLAC__StreamEncoderMetadataCallback metadata_callback,
void *client_data
)
{
return init_stream_internal_(
encoder,
read_callback,
write_callback,
seek_callback,
tell_callback,
metadata_callback,
client_data,
/*is_ogg=*/true
);
}
static FLAC__StreamEncoderInitStatus init_FILE_internal_(
FLAC__StreamEncoder *encoder,
FILE *file,
FLAC__StreamEncoderProgressCallback progress_callback,
void *client_data,
FLAC__bool is_ogg
)
{
FLAC__StreamEncoderInitStatus init_status;
@@ -1106,7 +1222,16 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__Stre
encoder->private_->samples_written = 0;
encoder->private_->frames_written = 0;
init_status = FLAC__stream_encoder_init_stream(encoder, file_write_callback_, file_seek_callback_, file_tell_callback_, /*metadata_callback=*/0, client_data);
init_status = init_stream_internal_(
encoder,
is_ogg? file_read_callback_ : 0,
file_write_callback_,
file_seek_callback_,
file_tell_callback_,
/*metadata_callback=*/0,
client_data,
is_ogg
);
if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
/* the above function sets the state for us in case of an error */
return init_status;
@@ -1121,8 +1246,34 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__Stre
return init_status;
}
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
FLAC__StreamEncoder *encoder,
FILE *file,
FLAC__StreamEncoderProgressCallback progress_callback,
void *client_data
)
{
return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
}
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
FLAC__StreamEncoder *encoder,
FILE *file,
FLAC__StreamEncoderProgressCallback progress_callback,
void *client_data
)
{
return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
}
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data)
static FLAC__StreamEncoderInitStatus init_file_internal_(
FLAC__StreamEncoder *encoder,
const char *filename,
FLAC__StreamEncoderProgressCallback progress_callback,
void *client_data,
FLAC__bool is_ogg
)
{
FILE *file;
@@ -1143,7 +1294,27 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__Stre
return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
}
return FLAC__stream_encoder_init_FILE(encoder, file, progress_callback, client_data);
return init_FILE_internal_(encoder, file, progress_callback, client_data, is_ogg);
}
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
FLAC__StreamEncoder *encoder,
const char *filename,
FLAC__StreamEncoderProgressCallback progress_callback,
void *client_data
)
{
return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
}
FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
FLAC__StreamEncoder *encoder,
const char *filename,
FLAC__StreamEncoderProgressCallback progress_callback,
void *client_data
)
{
return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
}
FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
@@ -1165,8 +1336,14 @@ FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
if(encoder->private_->seek_callback)
if(encoder->private_->seek_callback) {
#if FLAC__HAS_OGG
if(encoder->private_->is_ogg)
update_ogg_metadata_(encoder);
else
#endif
update_metadata_(encoder);
}
if(encoder->private_->metadata_callback)
encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
}
@@ -1180,15 +1357,39 @@ FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
encoder->private_->file = 0;
}
#if FLAC__HAS_OGG
if(encoder->private_->is_ogg)
FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
#endif
free_(encoder);
set_defaults_(encoder);
encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
}
FLAC_API FLAC__bool FLAC__stream_encoder_set_serial_number(FLAC__StreamEncoder *encoder, long value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
#ifdef FLAC__HAS_OGG
/* can't check encoder->private_->is_ogg since that's not set until init time */
FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
return true;
#else
(void)value;
return false;
#endif
}
FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
#ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
@@ -1200,6 +1401,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder
FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->streamable_subset = value;
@@ -1209,6 +1412,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncod
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->do_mid_side_stereo = value;
@@ -1218,6 +1423,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEnco
FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->loose_mid_side_stereo = value;
@@ -1227,6 +1434,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamE
FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->channels = value;
@@ -1236,6 +1445,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encod
FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->bits_per_sample = value;
@@ -1245,6 +1456,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder
FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->sample_rate = value;
@@ -1254,6 +1467,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *en
FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->blocksize = value;
@@ -1263,6 +1478,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *enco
FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
FLAC__ASSERT(0 != specification);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
@@ -1332,6 +1549,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *en
FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->max_lpc_order = value;
@@ -1341,6 +1560,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *
FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->qlp_coeff_precision = value;
@@ -1350,6 +1571,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEnc
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->do_qlp_coeff_prec_search = value;
@@ -1359,6 +1582,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__Stre
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
#if 0
@@ -1373,6 +1598,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncode
FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->do_exhaustive_model_search = value;
@@ -1382,6 +1609,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__St
FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->min_residual_partition_order = value;
@@ -1391,6 +1620,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__
FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->max_residual_partition_order = value;
@@ -1400,6 +1631,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__
FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
#if 0
@@ -1414,6 +1647,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__St
FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->total_samples_estimate = value;
@@ -1423,19 +1658,16 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__Stream
FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->protected_->metadata = metadata;
encoder->protected_->num_metadata_blocks = num_blocks;
if(0 != metadata && num_blocks > 0) {
unsigned i;
for(i = 0; i < num_blocks; i++) {
if(0 != metadata[i] && metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
encoder->private_->seek_table = &metadata[i]->data.seek_table;
break; /* take only the first one */
}
}
}
#if FLAC__HAS_OGG
if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
return false;
#endif
return true;
}
@@ -1446,6 +1678,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encod
FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->private_->disable_constant_subframes = value;
@@ -1455,6 +1689,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__Stream
FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->private_->disable_fixed_subframes = value;
@@ -1464,6 +1700,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEnc
FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
return false;
encoder->private_->disable_verbatim_subframes = value;
@@ -1473,12 +1711,16 @@ FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__Stream
FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->state;
}
FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->verify)
return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
else
@@ -1487,6 +1729,9 @@ FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(
FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
return FLAC__StreamEncoderStateString[encoder->protected_->state];
else
@@ -1496,6 +1741,8 @@ FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__
FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
if(0 != absolute_sample)
*absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
if(0 != frame_number)
@@ -1513,102 +1760,136 @@ FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__St
FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->verify;
}
FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->streamable_subset;
}
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->do_mid_side_stereo;
}
FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->loose_mid_side_stereo;
}
FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->channels;
}
FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->bits_per_sample;
}
FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->sample_rate;
}
FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->blocksize;
}
FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->max_lpc_order;
}
FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->qlp_coeff_precision;
}
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->do_qlp_coeff_prec_search;
}
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->do_escape_coding;
}
FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->do_exhaustive_model_search;
}
FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->min_residual_partition_order;
}
FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->max_residual_partition_order;
}
FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->rice_parameter_search_dist;
}
FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
{
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
return encoder->protected_->total_samples_estimate;
}
@@ -1619,6 +1900,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, c
const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
j = 0;
@@ -1749,6 +2032,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder
const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
FLAC__ASSERT(0 != encoder);
FLAC__ASSERT(0 != encoder->private_);
FLAC__ASSERT(0 != encoder->protected_);
FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
j = k = 0;
@@ -1915,12 +2200,20 @@ void set_defaults_(FLAC__StreamEncoder *encoder)
encoder->private_->disable_constant_subframes = false;
encoder->private_->disable_fixed_subframes = false;
encoder->private_->disable_verbatim_subframes = false;
#if FLAC__HAS_OGG
encoder->private_->is_ogg = false;
#endif
encoder->private_->read_callback = 0;
encoder->private_->write_callback = 0;
encoder->private_->seek_callback = 0;
encoder->private_->tell_callback = 0;
encoder->private_->metadata_callback = 0;
encoder->private_->progress_callback = 0;
encoder->private_->client_data = 0;
#if FLAC__HAS_OGG
FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
#endif
}
void free_(FLAC__StreamEncoder *encoder)
@@ -2173,7 +2466,7 @@ FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples)
return true;
}
FLAC__StreamEncoderWriteStatus write_frame_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples)
FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples)
{
FLAC__StreamEncoderWriteStatus status;
FLAC__uint64 output_position = 0;
@@ -2229,6 +2522,22 @@ FLAC__StreamEncoderWriteStatus write_frame_(const FLAC__StreamEncoder *encoder,
}
}
#if FLAC__HAS_OGG
if(encoder->private_->is_ogg) {
status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
&encoder->protected_->ogg_encoder_aspect,
FLAC__stream_encoder_get_total_samples_estimate(encoder),
buffer,
bytes,
samples,
encoder->private_->current_frame_number,
(FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
encoder,
encoder->private_->client_data
);
}
else
#endif
status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
@@ -2401,6 +2710,181 @@ void update_metadata_(const FLAC__StreamEncoder *encoder)
}
}
/* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks. */
void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
{
FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
const unsigned min_framesize = metadata->data.stream_info.min_framesize;
const unsigned max_framesize = metadata->data.stream_info.max_framesize;
ogg_page page;
FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
/* All this is based on intimate knowledge of the stream header
* layout, but a change to the header format that would break this
* would also break all streams encoded in the previous format.
*/
/**
** Write STREAMINFO stats
**/
simple_ogg_page__init(&page);
if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
simple_ogg_page__clear(&page);
return; /* state already set */
}
/*
* Write MD5 signature
*/
{
const unsigned md5_offset =
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
) / 8;
if(md5_offset + 16 > (unsigned)page.body_len) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
simple_ogg_page__clear(&page);
return;
}
memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
}
/*
* Write total samples
*/
{
const unsigned total_samples_byte_offset =
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
- 4
) / 8;
if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
simple_ogg_page__clear(&page);
return;
}
b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
b[4] = (FLAC__byte)(samples & 0xFF);
memcpy(page.body + total_samples_byte_offset, b, 5);
}
/*
* Write min/max framesize
*/
{
const unsigned min_framesize_offset =
FLAC__STREAM_METADATA_HEADER_LENGTH +
(
FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
) / 8;
if(min_framesize_offset + 6 > (unsigned)page.body_len) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
simple_ogg_page__clear(&page);
return;
}
b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
b[2] = (FLAC__byte)(min_framesize & 0xFF);
b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
b[5] = (FLAC__byte)(max_framesize & 0xFF);
memcpy(page.body + min_framesize_offset, b, 6);
}
if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
simple_ogg_page__clear(&page);
return; /* state already set */
}
simple_ogg_page__clear(&page);
/*
* Write seektable
*/
if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
unsigned i;
FLAC__byte *p;
FLAC__format_seektable_sort(encoder->private_->seek_table);
FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
simple_ogg_page__init(&page);
if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
simple_ogg_page__clear(&page);
return; /* state already set */
}
if(FLAC__STREAM_METADATA_HEADER_LENGTH + (18*encoder->private_->seek_table->num_points) > (unsigned)page.body_len) {
encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
simple_ogg_page__clear(&page);
return;
}
for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
FLAC__uint64 xx;
unsigned x;
xx = encoder->private_->seek_table->points[i].sample_number;
b[7] = (FLAC__byte)xx; xx >>= 8;
b[6] = (FLAC__byte)xx; xx >>= 8;
b[5] = (FLAC__byte)xx; xx >>= 8;
b[4] = (FLAC__byte)xx; xx >>= 8;
b[3] = (FLAC__byte)xx; xx >>= 8;
b[2] = (FLAC__byte)xx; xx >>= 8;
b[1] = (FLAC__byte)xx; xx >>= 8;
b[0] = (FLAC__byte)xx; xx >>= 8;
xx = encoder->private_->seek_table->points[i].stream_offset;
b[15] = (FLAC__byte)xx; xx >>= 8;
b[14] = (FLAC__byte)xx; xx >>= 8;
b[13] = (FLAC__byte)xx; xx >>= 8;
b[12] = (FLAC__byte)xx; xx >>= 8;
b[11] = (FLAC__byte)xx; xx >>= 8;
b[10] = (FLAC__byte)xx; xx >>= 8;
b[9] = (FLAC__byte)xx; xx >>= 8;
b[8] = (FLAC__byte)xx; xx >>= 8;
x = encoder->private_->seek_table->points[i].frame_samples;
b[17] = (FLAC__byte)x; x >>= 8;
b[16] = (FLAC__byte)x; x >>= 8;
if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
simple_ogg_page__clear(&page);
return;
}
memcpy(p, b, 18);
}
if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
simple_ogg_page__clear(&page);
return; /* state already set */
}
simple_ogg_page__clear(&page);
}
}
FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_frame)
{
FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
@@ -3908,6 +4392,20 @@ void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco
encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
}
FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
(void)client_data;
*bytes = (unsigned)fread(buffer, 1, *bytes, encoder->private_->file);
if (*bytes == 0) {
if (feof(encoder->private_->file))
return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
else if (ferror(encoder->private_->file))
return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
}
return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
}
FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
(void)client_data;
@@ -3952,7 +4450,19 @@ FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *e
(void)client_data, (void)current_frame;
if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
if(0 != encoder->private_->progress_callback && samples > 0) {
FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
#if FLAC__HAS_OGG
/* We would like to be able to use 'samples > 0' in the
* clause here but currently because of the nature of our
* Ogg writing implementation, 'samples' is always 0 (see
* ogg_encoder_aspect.c). The downside is extra progress
* callbacks.
*/
encoder->private_->is_ogg? true :
#endif
samples > 0
);
if(call_it) {
/* NOTE: We have to add +bytes, +samples, and +1 to the stats
* because at this point in the callback chain, the stats
* have not been updated. Only after we return and control

View File

@@ -1,50 +0,0 @@
# libOggFLAC++ - Free Lossless Audio Codec + Ogg library
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of the Xiph.org Foundation nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lib_LTLIBRARIES = libOggFLAC++.la
m4datadir = $(datadir)/aclocal
m4data_DATA = libOggFLAC++.m4
EXTRA_DIST = \
Makefile.lite \
libOggFLAC++_dynamic.dsp \
libOggFLAC++_static.dsp \
libOggFLAC++.m4
# see 'http://www.gnu.org/software/libtool/manual.html#Libtool-versioning' for numbering convention
libOggFLAC___la_LDFLAGS = -version-info 3:0:0
libOggFLAC___la_LIBADD = ../libOggFLAC/libOggFLAC.la
libOggFLAC___la_SOURCES = \
file_decoder.cpp \
file_encoder.cpp \
stream_decoder.cpp \
stream_encoder.cpp

View File

@@ -1,48 +0,0 @@
# libOggFLAC++ - Free Lossless Audio Codec + Ogg library
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of the Xiph.org Foundation nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# GNU makefile
#
topdir = ../..
LIB_NAME = libOggFLAC++
INCLUDES = -I$(topdir)/include
SRCS_CPP = \
file_decoder.cpp \
file_encoder.cpp \
stream_decoder.cpp \
stream_encoder.cpp
include $(topdir)/build/lib.mk
# DO NOT DELETE THIS LINE -- make depend depends on it.

View File

@@ -1,81 +0,0 @@
/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "OggFLAC++/decoder.h"
#include "FLAC/assert.h"
#ifdef _MSC_VER
// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
#pragma warning ( disable : 4800 )
#endif
namespace OggFLAC {
namespace Decoder {
File::File():
Stream()
{ }
File::~File()
{
}
::FLAC__StreamDecoderInitStatus File::init(FILE *file)
{
FLAC__ASSERT(0 != decoder_);
return ::OggFLAC__stream_decoder_init_FILE((OggFLAC__StreamDecoder*)decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamDecoderInitStatus File::init(const char *filename)
{
FLAC__ASSERT(0 != decoder_);
return ::OggFLAC__stream_decoder_init_file((OggFLAC__StreamDecoder*)decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamDecoderInitStatus File::init(const std::string &filename)
{
return init(filename.c_str());
}
// This is a dummy to satisfy the pure virtual from Stream; the
// read callback will never be called since we are initializing
// with FLAC__stream_decoder_init_FILE() or
// FLAC__stream_decoder_init_file() and those supply the read
// callback internally.
::FLAC__StreamDecoderReadStatus File::read_callback(FLAC__byte buffer[], unsigned *bytes)
{
(void)buffer, (void)bytes;
FLAC__ASSERT(false);
return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; // double protection
}
}
}

View File

@@ -1,94 +0,0 @@
/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "OggFLAC++/encoder.h"
#include "FLAC/assert.h"
#ifdef _MSC_VER
// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
#pragma warning ( disable : 4800 )
#endif
namespace OggFLAC {
namespace Encoder {
File::File():
Stream()
{ }
File::~File()
{ }
::FLAC__StreamEncoderInitStatus File::init(FILE *file)
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_init_FILE((OggFLAC__StreamEncoder*)encoder_, file, progress_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus File::init(const char *filename)
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_init_file((OggFLAC__StreamEncoder*)encoder_, filename, progress_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus File::init(const std::string &filename)
{
return init(filename.c_str());
}
// This is a dummy to satisfy the pure virtual from Stream; the
// read callback will never be called since we are initializing
// with OggFLAC__stream_decoder_init_FILE() or
// OggFLAC__stream_decoder_init_file() and those supply the read
// callback internally.
::FLAC__StreamEncoderWriteStatus File::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
{
(void)buffer, (void)bytes, (void)samples, (void)current_frame;
FLAC__ASSERT(false);
return ::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; // double protection
}
void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate)
{
(void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate;
}
void File::progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
{
(void)encoder;
FLAC__ASSERT(0 != client_data);
File *instance = reinterpret_cast<File *>(client_data);
FLAC__ASSERT(0 != instance);
instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate);
}
}
}

View File

@@ -1,107 +0,0 @@
# Configure paths for libOggFLAC++
# "Inspired" by ogg.m4
# Caller must first run AM_PATH_LIBOGGFLAC
dnl AM_PATH_LIBOGGFLACPP([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
dnl Test for libOggFLAC++, and define LIBOGGFLACPP_CFLAGS and LIBOGGFLACPP_LIBS
dnl
AC_DEFUN([AM_PATH_LIBOGGFLACPP],
[dnl
dnl Get the cflags and libraries
dnl
AC_ARG_WITH(libOggFLACPP,[ --with-libOggFLACPP=PFX Prefix where libOggFLAC++ is installed (optional)], libOggFLACPP_prefix="$withval", libOggFLACPP_prefix="")
AC_ARG_WITH(libOggFLACPP-libraries,[ --with-libOggFLACPP-libraries=DIR Directory where libOggFLAC++ library is installed (optional)], libOggFLACPP_libraries="$withval", libOggFLACPP_libraries="")
AC_ARG_WITH(libOggFLACPP-includes,[ --with-libOggFLACPP-includes=DIR Directory where libOggFLAC++ header files are installed (optional)], libOggFLACPP_includes="$withval", libOggFLACPP_includes="")
AC_ARG_ENABLE(libOggFLACPPtest, [ --disable-libOggFLACPPtest Do not try to compile and run a test libOggFLAC++ program],, enable_libOggFLACPPtest=yes)
if test "x$libOggFLACPP_libraries" != "x" ; then
LIBOGGFLACPP_LIBS="-L$libOggFLACPP_libraries"
elif test "x$libOggFLACPP_prefix" != "x" ; then
LIBOGGFLACPP_LIBS="-L$libOggFLACPP_prefix/lib"
elif test "x$prefix" != "xNONE" ; then
LIBOGGFLACPP_LIBS="-L$libdir"
fi
LIBOGGFLACPP_LIBS="$LIBOGGFLACPP_LIBS -lOggFLAC++ $LIBOGGFLAC_LIBS"
if test "x$libOggFLACPP_includes" != "x" ; then
LIBOGGFLACPP_CFLAGS="-I$libOggFLACPP_includes"
elif test "x$libOggFLACPP_prefix" != "x" ; then
LIBOGGFLACPP_CFLAGS="-I$libOggFLACPP_prefix/include"
elif test "$prefix" != "xNONE"; then
LIBOGGFLACPP_CFLAGS="-I$prefix/include"
fi
LIBOGGFLACPP_CFLAGS="$LIBOGGFLACPP_CFLAGS $LIBOGGFLAC_CFLAGS"
AC_MSG_CHECKING(for libOggFLAC++)
no_libOggFLACPP=""
if test "x$enable_libOggFLACPPtest" = "xyes" ; then
ac_save_CFLAGS="$CFLAGS"
ac_save_CXXFLAGS="$CXXFLAGS"
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $LIBOGGFLACPP_CFLAGS"
CXXFLAGS="$CXXFLAGS $LIBOGGFLACPP_CFLAGS"
LIBS="$LIBS $LIBOGGFLACPP_LIBS"
dnl
dnl Now check if the installed libOggFLAC++ is sufficiently new.
dnl
rm -f conf.libOggFLAC++test
AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <OggFLAC++/decoder.h>
int main ()
{
system("touch conf.libOggFLAC++test");
return 0;
}
],, no_libOggFLACPP=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
if test "x$no_libOggFLACPP" = "x" ; then
AC_MSG_RESULT(yes)
ifelse([$1], , :, [$1])
else
AC_MSG_RESULT(no)
if test -f conf.libOggFLAC++test ; then
:
else
echo "*** Could not run libOggFLAC++ test program, checking why..."
CFLAGS="$CFLAGS $LIBOGGFLACPP_CFLAGS"
LIBS="$LIBS $LIBOGGFLACPP_LIBS"
AC_TRY_LINK([
#include <stdio.h>
#include <OggFLAC++/decoder.h>
], [ return 0; ],
[ echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding libOggFLAC++ or finding the wrong"
echo "*** version of libOggFLAC++. If it is not finding libOggFLAC++, you'll need to set your"
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
echo "*** to the installed location Also, make sure you have run ldconfig if that"
echo "*** is required on your system"
echo "***"
echo "*** If you have an old version installed, it is best to remove it, although"
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
[ echo "*** The test program failed to compile or link. See the file config.log for the"
echo "*** exact error that occured. This usually means libOggFLAC++ was incorrectly installed"
echo "*** or that you have moved libOggFLAC++ since it was installed. In the latter case, you"
echo "*** may want to edit the libOggFLAC++-config script: $LIBFLACPP_CONFIG" ])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
LIBOGGFLACPP_CFLAGS=""
LIBOGGFLACPP_LIBS=""
ifelse([$2], , :, [$2])
fi
AC_SUBST(LIBOGGFLACPP_CFLAGS)
AC_SUBST(LIBOGGFLACPP_LIBS)
rm -f conf.libOggFLAC++test
])

View File

@@ -1,139 +0,0 @@
# Microsoft Developer Studio Project File - Name="libOggFLAC++_dynamic" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=libOggFLAC++_dynamic - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "libOggFLAC++_dynamic.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "libOggFLAC++_dynamic.mak" CFG="libOggFLAC++_dynamic - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "libOggFLAC++_dynamic - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "libOggFLAC++_dynamic - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName "libOggFLAC++"
# PROP Scc_LocalPath "..\.."
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "libOggFLAC++_dynamic - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\obj\release\lib"
# PROP Intermediate_Dir "Release_dynamic"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I ".\include" /I "..\..\include" /D "NDEBUG" /D "OggFLACPP_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG" /d "_USRDLL"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
# ADD LINK32 ..\..\obj\release\lib\libFLAC++.lib ..\..\obj\release\lib\libOggFLAC.lib ..\..\obj\release\lib\libFLAC.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:windows /dll /machine:I386 /out:"..\..\obj\release\bin/libOggFLAC++.dll"
!ELSEIF "$(CFG)" == "libOggFLAC++_dynamic - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\obj\debug\lib"
# PROP Intermediate_Dir "Debug_dynamic"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I ".\include" /I "..\..\include" /D "_DEBUG" /D "OggFLACPP_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG" /d "_USRDLL"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\libFLAC++.lib ..\..\obj\debug\lib\libOggFLAC.lib ..\..\obj\debug\lib\libFLAC.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"..\..\obj\debug\bin/libOggFLAC++.dll" /pdbtype:sept
!ENDIF
# Begin Target
# Name "libOggFLAC++_dynamic - Win32 Release"
# Name "libOggFLAC++_dynamic - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp"
# Begin Source File
SOURCE=.\file_decoder.cpp
# End Source File
# Begin Source File
SOURCE=.\file_encoder.cpp
# End Source File
# Begin Source File
SOURCE=.\stream_decoder.cpp
# End Source File
# Begin Source File
SOURCE=.\stream_encoder.cpp
# End Source File
# End Group
# Begin Group "Private Header Files"
# PROP Default_Filter ""
# End Group
# Begin Group "Protected Header Files"
# PROP Default_Filter ""
# End Group
# Begin Group "Public Header Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE="..\..\include\OggFLAC++\all.h"
# End Source File
# Begin Source File
SOURCE="..\..\include\OggFLAC++\decoder.h"
# End Source File
# Begin Source File
SOURCE="..\..\include\OggFLAC++\encoder.h"
# End Source File
# Begin Source File
SOURCE="..\..\include\OggFLAC++\export.h"
# End Source File
# End Group
# End Target
# End Project

View File

@@ -1,132 +0,0 @@
# Microsoft Developer Studio Project File - Name="libOggFLAC++_static" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=libOggFLAC++_static - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "libOggFLAC++_static.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "libOggFLAC++_static.mak" CFG="libOggFLAC++_static - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "libOggFLAC++_static - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "libOggFLAC++_static - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName "libOggFLAC++"
# PROP Scc_LocalPath "..\.."
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "libOggFLAC++_static - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\obj\release\lib"
# PROP Intermediate_Dir "Release_static"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I ".\include" /I "..\..\include" /D "FLAC__NO_DLL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "libOggFLAC++_static - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\obj\debug\lib"
# PROP Intermediate_Dir "Debug_static"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I ".\include" /I "..\..\include" /D "FLAC__NO_DLL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "libOggFLAC++_static - Win32 Release"
# Name "libOggFLAC++_static - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp"
# Begin Source File
SOURCE=.\file_decoder.cpp
# End Source File
# Begin Source File
SOURCE=.\file_encoder.cpp
# End Source File
# Begin Source File
SOURCE=.\stream_decoder.cpp
# End Source File
# Begin Source File
SOURCE=.\stream_encoder.cpp
# End Source File
# End Group
# Begin Group "Private Header Files"
# PROP Default_Filter ""
# End Group
# Begin Group "Protected Header Files"
# PROP Default_Filter ""
# End Group
# Begin Group "Public Header Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE="..\..\include\OggFLAC++\all.h"
# End Source File
# Begin Source File
SOURCE="..\..\include\OggFLAC++\decoder.h"
# End Source File
# Begin Source File
SOURCE="..\..\include\OggFLAC++\encoder.h"
# End Source File
# Begin Source File
SOURCE="..\..\include\OggFLAC++\export.h"
# End Source File
# End Group
# End Target
# End Project

View File

@@ -1,220 +0,0 @@
/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "OggFLAC++/decoder.h"
#include "FLAC/assert.h"
#ifdef _MSC_VER
// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
#pragma warning ( disable : 4800 )
#endif
namespace OggFLAC {
namespace Decoder {
// We can inherit from FLAC::Decoder::Stream because we jam a
// OggFLAC__StreamDecoder pointer into the decoder_ member,
// hence the pointer casting on decoder_ everywhere.
Stream::Stream():
FLAC::Decoder::Stream((FLAC__StreamDecoder*)::OggFLAC__stream_decoder_new())
{ }
Stream::~Stream()
{
if(0 != decoder_) {
::OggFLAC__stream_decoder_finish((OggFLAC__StreamDecoder*)decoder_);
::OggFLAC__stream_decoder_delete((OggFLAC__StreamDecoder*)decoder_);
// this is our signal to FLAC::Decoder::Stream::~Stream()
// that we already deleted the decoder our way, so it
// doesn't need to:
decoder_ = 0;
}
}
bool Stream::set_md5_checking(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_set_md5_checking((OggFLAC__StreamDecoder*)decoder_, value);
}
bool Stream::set_serial_number(long value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_set_serial_number((OggFLAC__StreamDecoder*)decoder_, value);
}
bool Stream::set_metadata_respond(::FLAC__MetadataType type)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_set_metadata_respond((OggFLAC__StreamDecoder*)decoder_, type);
}
bool Stream::set_metadata_respond_application(const FLAC__byte id[4])
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_set_metadata_respond_application((OggFLAC__StreamDecoder*)decoder_, id);
}
bool Stream::set_metadata_respond_all()
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_set_metadata_respond_all((OggFLAC__StreamDecoder*)decoder_);
}
bool Stream::set_metadata_ignore(::FLAC__MetadataType type)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_set_metadata_ignore((OggFLAC__StreamDecoder*)decoder_, type);
}
bool Stream::set_metadata_ignore_application(const FLAC__byte id[4])
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_set_metadata_ignore_application((OggFLAC__StreamDecoder*)decoder_, id);
}
bool Stream::set_metadata_ignore_all()
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_set_metadata_ignore_all((OggFLAC__StreamDecoder*)decoder_);
}
Stream::State Stream::get_state() const
{
FLAC__ASSERT(is_valid());
return State(::OggFLAC__stream_decoder_get_state((const OggFLAC__StreamDecoder*)decoder_));
}
FLAC::Decoder::Stream::State Stream::get_FLAC_stream_decoder_state() const
{
FLAC__ASSERT(is_valid());
return FLAC::Decoder::Stream::State(::OggFLAC__stream_decoder_get_FLAC_stream_decoder_state((const OggFLAC__StreamDecoder*)decoder_));
}
bool Stream::get_md5_checking() const
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_get_md5_checking((const OggFLAC__StreamDecoder*)decoder_);
}
FLAC__uint64 Stream::get_total_samples() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_decoder_get_total_samples((const OggFLAC__StreamDecoder*)decoder_);
}
unsigned Stream::get_channels() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_decoder_get_channels((const OggFLAC__StreamDecoder*)decoder_);
}
::FLAC__ChannelAssignment Stream::get_channel_assignment() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_decoder_get_channel_assignment((const OggFLAC__StreamDecoder*)decoder_);
}
unsigned Stream::get_bits_per_sample() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_decoder_get_bits_per_sample((const OggFLAC__StreamDecoder*)decoder_);
}
unsigned Stream::get_sample_rate() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_decoder_get_sample_rate((const OggFLAC__StreamDecoder*)decoder_);
}
unsigned Stream::get_blocksize() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_decoder_get_blocksize((const OggFLAC__StreamDecoder*)decoder_);
}
::FLAC__StreamDecoderInitStatus Stream::init()
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_decoder_init_stream((OggFLAC__StreamDecoder*)decoder_, read_callback_, seek_callback_, tell_callback_, length_callback_, eof_callback_, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
}
void Stream::finish()
{
FLAC__ASSERT(is_valid());
::OggFLAC__stream_decoder_finish((OggFLAC__StreamDecoder*)decoder_);
}
bool Stream::flush()
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_flush((OggFLAC__StreamDecoder*)decoder_);
}
bool Stream::reset()
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_reset((OggFLAC__StreamDecoder*)decoder_);
}
bool Stream::process_single()
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_process_single((OggFLAC__StreamDecoder*)decoder_);
}
bool Stream::process_until_end_of_metadata()
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_process_until_end_of_metadata((OggFLAC__StreamDecoder*)decoder_);
}
bool Stream::process_until_end_of_stream()
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_process_until_end_of_stream((OggFLAC__StreamDecoder*)decoder_);
}
bool Stream::skip_single_frame()
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_skip_single_frame((OggFLAC__StreamDecoder*)decoder_);
}
bool Stream::seek_absolute(FLAC__uint64 sample)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_seek_absolute((OggFLAC__StreamDecoder*)decoder_, sample);
}
}
}

View File

@@ -1,374 +0,0 @@
/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "OggFLAC++/encoder.h"
#include "FLAC/assert.h"
#ifdef _MSC_VER
// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
#pragma warning ( disable : 4800 )
#endif
namespace OggFLAC {
namespace Encoder {
// We can inherit from FLAC::Encoder::Stream because we jam a
// OggFLAC__StreamEncoder pointer into the encoder_ member,
// hence the pointer casting on encoder_ everywhere.
Stream::Stream():
FLAC::Encoder::Stream((FLAC__StreamEncoder*)::OggFLAC__stream_encoder_new())
{ }
Stream::~Stream()
{
if(0 != encoder_) {
::OggFLAC__stream_encoder_finish((OggFLAC__StreamEncoder*)encoder_);
::OggFLAC__stream_encoder_delete((OggFLAC__StreamEncoder*)encoder_);
// this is our signal to FLAC::Encoder::Stream::~Stream()
// that we already deleted the encoder our way, so it
// doesn't need to:
encoder_ = 0;
}
}
bool Stream::set_serial_number(long value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_serial_number((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_verify(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_verify((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_streamable_subset(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_streamable_subset((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_do_mid_side_stereo(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_do_mid_side_stereo((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_loose_mid_side_stereo(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_loose_mid_side_stereo((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_channels(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_channels((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_bits_per_sample(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_bits_per_sample((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_sample_rate(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_sample_rate((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_blocksize(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_blocksize((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_apodization(const char *specification)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_apodization((OggFLAC__StreamEncoder*)encoder_, specification);
}
bool Stream::set_max_lpc_order(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_max_lpc_order((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_qlp_coeff_precision(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_qlp_coeff_precision((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_do_qlp_coeff_prec_search(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_do_escape_coding(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_do_escape_coding((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_do_exhaustive_model_search(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_do_exhaustive_model_search((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_min_residual_partition_order(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_min_residual_partition_order((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_max_residual_partition_order(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_max_residual_partition_order((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_rice_parameter_search_dist(unsigned value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_rice_parameter_search_dist((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_total_samples_estimate(FLAC__uint64 value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_total_samples_estimate((OggFLAC__StreamEncoder*)encoder_, value);
}
bool Stream::set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_set_metadata((OggFLAC__StreamEncoder*)encoder_, metadata, num_blocks);
}
bool Stream::set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks)
{
FLAC__ASSERT(is_valid());
#if (defined _MSC_VER) || (defined __SUNPRO_CC)
// MSVC++ can't handle:
// ::FLAC__StreamMetadata *m[num_blocks];
// so we do this ugly workaround
::FLAC__StreamMetadata **m = new ::FLAC__StreamMetadata*[num_blocks];
#else
::FLAC__StreamMetadata *m[num_blocks];
#endif
for(unsigned i = 0; i < num_blocks; i++) {
// we can get away with the const_cast since we know the encoder will only correct the is_last flags
m[i] = const_cast< ::FLAC__StreamMetadata*>((const ::FLAC__StreamMetadata*)metadata[i]);
}
#if (defined _MSC_VER) || (defined __SUNPRO_CC)
// complete the hack
const bool ok = (bool)::OggFLAC__stream_encoder_set_metadata((OggFLAC__StreamEncoder*)encoder_, m, num_blocks);
delete [] m;
return ok;
#else
return (bool)::OggFLAC__stream_encoder_set_metadata((OggFLAC__StreamEncoder*)encoder_, m, num_blocks);
#endif
}
Stream::State Stream::get_state() const
{
FLAC__ASSERT(is_valid());
return State(::OggFLAC__stream_encoder_get_state((const OggFLAC__StreamEncoder*)encoder_));
}
FLAC::Encoder::Stream::State Stream::get_FLAC_stream_encoder_state() const
{
FLAC__ASSERT(is_valid());
return FLAC::Encoder::Stream::State(::OggFLAC__stream_encoder_get_FLAC_stream_encoder_state((const OggFLAC__StreamEncoder*)encoder_));
}
FLAC::Decoder::Stream::State Stream::get_verify_decoder_state() const
{
FLAC__ASSERT(is_valid());
return FLAC::Decoder::Stream::State(::OggFLAC__stream_encoder_get_verify_decoder_state((const OggFLAC__StreamEncoder*)encoder_));
}
void Stream::get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
{
FLAC__ASSERT(is_valid());
::OggFLAC__stream_encoder_get_verify_decoder_error_stats((const OggFLAC__StreamEncoder*)encoder_, absolute_sample, frame_number, channel, sample, expected, got);
}
bool Stream::get_verify() const
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_get_verify((const OggFLAC__StreamEncoder*)encoder_);
}
bool Stream::get_streamable_subset() const
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_get_streamable_subset((const OggFLAC__StreamEncoder*)encoder_);
}
bool Stream::get_do_mid_side_stereo() const
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_get_do_mid_side_stereo((const OggFLAC__StreamEncoder*)encoder_);
}
bool Stream::get_loose_mid_side_stereo() const
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_get_loose_mid_side_stereo((const OggFLAC__StreamEncoder*)encoder_);
}
unsigned Stream::get_channels() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_channels((const OggFLAC__StreamEncoder*)encoder_);
}
unsigned Stream::get_bits_per_sample() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_bits_per_sample((const OggFLAC__StreamEncoder*)encoder_);
}
unsigned Stream::get_sample_rate() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_sample_rate((const OggFLAC__StreamEncoder*)encoder_);
}
unsigned Stream::get_blocksize() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_blocksize((const OggFLAC__StreamEncoder*)encoder_);
}
unsigned Stream::get_max_lpc_order() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_max_lpc_order((const OggFLAC__StreamEncoder*)encoder_);
}
unsigned Stream::get_qlp_coeff_precision() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_qlp_coeff_precision((const OggFLAC__StreamEncoder*)encoder_);
}
bool Stream::get_do_qlp_coeff_prec_search() const
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search((const OggFLAC__StreamEncoder*)encoder_);
}
bool Stream::get_do_escape_coding() const
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_get_do_escape_coding((const OggFLAC__StreamEncoder*)encoder_);
}
bool Stream::get_do_exhaustive_model_search() const
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_get_do_exhaustive_model_search((const OggFLAC__StreamEncoder*)encoder_);
}
unsigned Stream::get_min_residual_partition_order() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_min_residual_partition_order((const OggFLAC__StreamEncoder*)encoder_);
}
unsigned Stream::get_max_residual_partition_order() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_max_residual_partition_order((const OggFLAC__StreamEncoder*)encoder_);
}
unsigned Stream::get_rice_parameter_search_dist() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_rice_parameter_search_dist((const OggFLAC__StreamEncoder*)encoder_);
}
FLAC__uint64 Stream::get_total_samples_estimate() const
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_get_total_samples_estimate((const OggFLAC__StreamEncoder*)encoder_);
}
::FLAC__StreamEncoderInitStatus Stream::init()
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_init_stream((OggFLAC__StreamEncoder*)encoder_, read_callback_, write_callback_, seek_callback_, tell_callback_, metadata_callback_, /*client_data=*/(void*)this);
}
void Stream::finish()
{
FLAC__ASSERT(is_valid());
::OggFLAC__stream_encoder_finish((OggFLAC__StreamEncoder*)encoder_);
}
bool Stream::process(const FLAC__int32 * const buffer[], unsigned samples)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_process((OggFLAC__StreamEncoder*)encoder_, buffer, samples);
}
bool Stream::process_interleaved(const FLAC__int32 buffer[], unsigned samples)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_encoder_process_interleaved((OggFLAC__StreamEncoder*)encoder_, buffer, samples);
}
::OggFLAC__StreamEncoderReadStatus Stream::read_callback(FLAC__byte buffer[], unsigned *bytes)
{
(void)buffer, (void)bytes;
return ::OggFLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED;
}
::OggFLAC__StreamEncoderReadStatus Stream::read_callback_(const ::OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
(void)encoder;
FLAC__ASSERT(0 != client_data);
Stream *instance = reinterpret_cast<Stream *>(client_data);
FLAC__ASSERT(0 != instance);
return instance->read_callback(buffer, bytes);
}
}
}

View File

@@ -1,59 +0,0 @@
# libOggFLAC - Free Lossless Audio Codec + Ogg library
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of the Xiph.org Foundation nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lib_LTLIBRARIES = libOggFLAC.la
if DEBUG
DEBUGCFLAGS =
endif
AM_CFLAGS = @OGG_CFLAGS@ $(DEBUGCFLAGS)
SUBDIRS = include .
m4datadir = $(datadir)/aclocal
m4data_DATA = libOggFLAC.m4
EXTRA_DIST = \
Makefile.lite \
libOggFLAC_dynamic.dsp \
libOggFLAC_static.dsp \
libOggFLAC.m4
libOggFLAC_la_LIBADD = @OGG_LIBS@ ../libFLAC/libFLAC.la
# see 'http://www.gnu.org/software/libtool/manual.html#Libtool-versioning' for numbering convention
libOggFLAC_la_LDFLAGS = -version-info 4:0:0
libOggFLAC_la_SOURCES = \
ogg_decoder_aspect.c \
ogg_encoder_aspect.c \
ogg_helper.c \
ogg_mapping.c \
stream_decoder.c \
stream_encoder.c

View File

@@ -1,60 +0,0 @@
# libOggFLAC - Free Lossless Audio Codec + Ogg library
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of the Xiph.org Foundation nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# GNU makefile
#
topdir = ../..
LIB_NAME = libOggFLAC
ifeq ($(DARWIN_BUILD),yes)
DEFINES =
else
ifeq ($(SOLARIS_BUILD),yes)
DEFINES =
else
DEFINES =
endif
endif
INCLUDES = -I./include -I$(topdir)/include -I$(OGG_INCLUDE_DIR)
DEBUG_CFLAGS =
SRCS_C = \
ogg_decoder_aspect.c \
ogg_encoder_aspect.c \
ogg_helper.c \
ogg_mapping.c \
stream_decoder.c \
stream_encoder.c
include $(topdir)/build/lib.mk
# DO NOT DELETE THIS LINE -- make depend depends on it.

View File

@@ -1,31 +0,0 @@
# libOggFLAC - Free Lossless Audio Codec + Ogg library
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of the Xiph.org Foundation nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
SUBDIRS = private protected

View File

@@ -1,36 +0,0 @@
# libOggFLAC - Free Lossless Audio Codec + Ogg library
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of the Xiph.org Foundation nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
noinst_HEADERS = \
all.h \
ogg_decoder_aspect.h \
ogg_encoder_aspect.h \
ogg_helper.h \
ogg_mapping.h

View File

@@ -1,40 +0,0 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OggFLAC__PRIVATE__ALL_H
#define OggFLAC__PRIVATE__ALL_H
#include "ogg_decoder_aspect.h"
#include "ogg_encoder_aspect.h"
#include "ogg_helper.h"
#include "ogg_mapping.h"
#endif

View File

@@ -1,34 +0,0 @@
# libOggFLAC - Free Lossless Audio Codec + Ogg library
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of the Xiph.org Foundation nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
noinst_HEADERS = \
all.h \
stream_decoder.h \
stream_encoder.h

View File

@@ -1,38 +0,0 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OggFLAC__PROTECTED__ALL_H
#define OggFLAC__PROTECTED__ALL_H
#include "stream_decoder.h"
#include "stream_encoder.h"
#endif

View File

@@ -1,43 +0,0 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OggFLAC__PROTECTED__STREAM_DECODER_H
#define OggFLAC__PROTECTED__STREAM_DECODER_H
#include "OggFLAC/stream_decoder.h"
#include "private/ogg_decoder_aspect.h"
typedef struct OggFLAC__StreamDecoderProtected {
OggFLAC__StreamDecoderState state;
OggFLAC__OggDecoderAspect ogg_decoder_aspect;
} OggFLAC__StreamDecoderProtected;
#endif

View File

@@ -1,44 +0,0 @@
/* libOggFLAC - Free Lossless Audio Codec + Ogg library
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef OggFLAC__PROTECTED__STREAM_ENCODER_H
#define OggFLAC__PROTECTED__STREAM_ENCODER_H
#include "OggFLAC/stream_encoder.h"
#include "private/ogg_encoder_aspect.h"
typedef struct OggFLAC__StreamEncoderProtected {
OggFLAC__StreamEncoderState state;
OggFLAC__OggEncoderAspect ogg_encoder_aspect;
FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
} OggFLAC__StreamEncoderProtected;
#endif

View File

@@ -1,104 +0,0 @@
# Configure paths for libOggFLAC
# "Inspired" by ogg.m4
dnl AM_PATH_LIBOGGFLAC([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
dnl Test for libOggFLAC, and define LIBOGGFLAC_CFLAGS and LIBOGGFLAC_LIBS
dnl
AC_DEFUN([AM_PATH_LIBOGGFLAC],
[dnl
dnl Get the cflags and libraries
dnl
AC_ARG_WITH(libOggFLAC,[ --with-libOggFLAC=PFX Prefix where libOggFLAC is installed (optional)], libOggFLAC_prefix="$withval", libOggFLAC_prefix="")
AC_ARG_WITH(libOggFLAC-libraries,[ --with-libOggFLAC-libraries=DIR Directory where libOggFLAC library is installed (optional)], libOggFLAC_libraries="$withval", libOggFLAC_libraries="")
AC_ARG_WITH(libOggFLAC-includes,[ --with-libOggFLAC-includes=DIR Directory where libOggFLAC header files are installed (optional)], libOggFLAC_includes="$withval", libOggFLAC_includes="")
AC_ARG_ENABLE(libOggFLACtest, [ --disable-libOggFLACtest Do not try to compile and run a test libOggFLAC program],, enable_libOggFLACtest=yes)
if test "x$libOggFLAC_libraries" != "x" ; then
LIBOGGFLAC_LIBS="-L$libOggFLAC_libraries"
elif test "x$libOggFLAC_prefix" != "x" ; then
LIBOGGFLAC_LIBS="-L$libOggFLAC_prefix/lib"
elif test "x$prefix" != "xNONE" ; then
LIBOGGFLAC_LIBS="-L$libdir"
fi
LIBOGGFLAC_LIBS="$LIBOGGFLAC_LIBS -lOggFLAC -lFLAC -lm"
if test "x$libOggFLAC_includes" != "x" ; then
LIBOGGFLAC_CFLAGS="-I$libOggFLAC_includes"
elif test "x$libOggFLAC_prefix" != "x" ; then
LIBOGGFLAC_CFLAGS="-I$libOggFLAC_prefix/include"
elif test "$prefix" != "xNONE"; then
LIBOGGFLAC_CFLAGS="-I$prefix/include"
fi
AC_MSG_CHECKING(for libOggFLAC)
no_libOggFLAC=""
if test "x$enable_libOggFLACtest" = "xyes" ; then
ac_save_CFLAGS="$CFLAGS"
ac_save_CXXFLAGS="$CXXFLAGS"
ac_save_LIBS="$LIBS"
CFLAGS="$CFLAGS $LIBOGGFLAC_CFLAGS"
CXXFLAGS="$CXXFLAGS $LIBOGGFLAC_CFLAGS"
LIBS="$LIBS $LIBOGGFLAC_LIBS"
dnl
dnl Now check if the installed libOggFLAC is sufficiently new.
dnl
rm -f conf.libOggFLACtest
AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <OggFLAC/stream_decoder.h>
int main ()
{
system("touch conf.libOggFLACtest");
return 0;
}
],, no_libOggFLAC=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
if test "x$no_libOggFLAC" = "x" ; then
AC_MSG_RESULT(yes)
ifelse([$1], , :, [$1])
else
AC_MSG_RESULT(no)
if test -f conf.libOggFLACtest ; then
:
else
echo "*** Could not run libOggFLAC test program, checking why..."
CFLAGS="$CFLAGS $LIBOGGFLAC_CFLAGS"
LIBS="$LIBS $LIBOGGFLAC_LIBS"
AC_TRY_LINK([
#include <stdio.h>
#include <OggFLAC/stream_decoder.h>
], [ return 0; ],
[ echo "*** The test program compiled, but did not run. This usually means"
echo "*** that the run-time linker is not finding libOggFLAC or finding the wrong"
echo "*** version of libOggFLAC. If it is not finding libOggFLAC, you'll need to set your"
echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
echo "*** to the installed location Also, make sure you have run ldconfig if that"
echo "*** is required on your system"
echo "***"
echo "*** If you have an old version installed, it is best to remove it, although"
echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
[ echo "*** The test program failed to compile or link. See the file config.log for the"
echo "*** exact error that occured. This usually means libOggFLAC was incorrectly installed"
echo "*** or that you have moved libOggFLAC since it was installed. In the latter case, you"
echo "*** may want to edit the libOggFLAC-config script: $LIBOGGFLAC_CONFIG" ])
CFLAGS="$ac_save_CFLAGS"
LIBS="$ac_save_LIBS"
fi
LIBOGGFLAC_CFLAGS=""
LIBOGGFLAC_LIBS=""
ifelse([$2], , :, [$2])
fi
AC_SUBST(LIBOGGFLAC_CFLAGS)
AC_SUBST(LIBOGGFLAC_LIBS)
rm -f conf.libOggFLACtest
])

View File

@@ -1,179 +0,0 @@
# Microsoft Developer Studio Project File - Name="libOggFLAC_dynamic" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=libOggFLAC_dynamic - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "libOggFLAC_dynamic.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "libOggFLAC_dynamic.mak" CFG="libOggFLAC_dynamic - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "libOggFLAC_dynamic - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "libOggFLAC_dynamic - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName "libOggFLAC"
# PROP Scc_LocalPath "..\.."
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "libOggFLAC_dynamic - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\obj\release\lib"
# PROP Intermediate_Dir "Release_dynamic"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I ".\include" /I "..\..\include" /D "NDEBUG" /D "OggFLAC_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG" /d "_USRDLL"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
# ADD LINK32 ..\..\obj\release\lib\libFLAC.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:windows /dll /machine:I386 /out:"..\..\obj\release\bin/libOggFLAC.dll"
!ELSEIF "$(CFG)" == "libOggFLAC_dynamic - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\obj\debug\lib"
# PROP Intermediate_Dir "Debug_dynamic"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I ".\include" /I "..\..\include" /D "_DEBUG" /D "OggFLAC_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG" /d "_USRDLL"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\libFLAC.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"..\..\obj\debug\bin/libOggFLAC.dll" /pdbtype:sept
!ENDIF
# Begin Target
# Name "libOggFLAC_dynamic - Win32 Release"
# Name "libOggFLAC_dynamic - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "c"
# Begin Source File
SOURCE=.\ogg_decoder_aspect.c
# End Source File
# Begin Source File
SOURCE=.\ogg_encoder_aspect.c
# End Source File
# Begin Source File
SOURCE=.\ogg_helper.c
# End Source File
# Begin Source File
SOURCE=.\ogg_mapping.c
# End Source File
# Begin Source File
SOURCE=.\stream_decoder.c
# End Source File
# Begin Source File
SOURCE=.\stream_encoder.c
# End Source File
# End Group
# Begin Group "Private Header Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\include\private\all.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_decoder_aspect.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_encoder_aspect.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_helper.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_mapping.h
# End Source File
# End Group
# Begin Group "Protected Header Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\include\protected\all.h
# End Source File
# Begin Source File
SOURCE=.\include\protected\stream_decoder.h
# End Source File
# Begin Source File
SOURCE=.\include\protected\stream_encoder.h
# End Source File
# End Group
# Begin Group "Public Header Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\include\OggFLAC\all.h
# End Source File
# Begin Source File
SOURCE=..\..\include\OggFLAC\export.h
# End Source File
# Begin Source File
SOURCE=..\..\include\OggFLAC\stream_decoder.h
# End Source File
# Begin Source File
SOURCE=..\..\include\OggFLAC\stream_encoder.h
# End Source File
# End Group
# End Target
# End Project

View File

@@ -1,172 +0,0 @@
# Microsoft Developer Studio Project File - Name="libOggFLAC_static" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=libOggFLAC_static - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "libOggFLAC_static.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "libOggFLAC_static.mak" CFG="libOggFLAC_static - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "libOggFLAC_static - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "libOggFLAC_static - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName "libOggFLAC"
# PROP Scc_LocalPath "..\.."
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "libOggFLAC_static - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\obj\release\lib"
# PROP Intermediate_Dir "Release_static"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I ".\include" /I "..\..\include" /D "FLAC__NO_DLL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /nodefaultlib
!ELSEIF "$(CFG)" == "libOggFLAC_static - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\obj\debug\lib"
# PROP Intermediate_Dir "Debug_static"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I ".\include" /I "..\..\include" /D "FLAC__NO_DLL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /nodefaultlib
!ENDIF
# Begin Target
# Name "libOggFLAC_static - Win32 Release"
# Name "libOggFLAC_static - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "c"
# Begin Source File
SOURCE=.\ogg_decoder_aspect.c
# End Source File
# Begin Source File
SOURCE=.\ogg_encoder_aspect.c
# End Source File
# Begin Source File
SOURCE=.\ogg_helper.c
# End Source File
# Begin Source File
SOURCE=.\ogg_mapping.c
# End Source File
# Begin Source File
SOURCE=.\stream_decoder.c
# End Source File
# Begin Source File
SOURCE=.\stream_encoder.c
# End Source File
# End Group
# Begin Group "Private Header Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\include\private\all.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_decoder_aspect.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_encoder_aspect.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_helper.h
# End Source File
# Begin Source File
SOURCE=.\include\private\ogg_mapping.h
# End Source File
# End Group
# Begin Group "Protected Header Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\include\protected\all.h
# End Source File
# Begin Source File
SOURCE=.\include\protected\stream_decoder.h
# End Source File
# Begin Source File
SOURCE=.\include\protected\stream_encoder.h
# End Source File
# End Group
# Begin Group "Public Header Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\include\OggFLAC\all.h
# End Source File
# Begin Source File
SOURCE=..\..\include\OggFLAC\export.h
# End Source File
# Begin Source File
SOURCE=..\..\include\OggFLAC\stream_decoder.h
# End Source File
# Begin Source File
SOURCE=..\..\include\OggFLAC\stream_encoder.h
# End Source File
# End Group
# End Target
# End Project

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -17,6 +17,8 @@
bin_PROGRAMS = metaflac
AM_CFLAGS = @OGG_CFLAGS@
EXTRA_DIST = \
Makefile.lite \
metaflac.dsp
@@ -44,5 +46,6 @@ metaflac_LDADD = \
$(top_builddir)/src/share/getopt/libgetopt.a \
$(top_builddir)/src/share/utf8/libutf8.la \
$(top_builddir)/src/libFLAC/libFLAC.la \
@OGG_LIBS@ \
@LIBICONV@ \
-lm

View File

@@ -24,12 +24,12 @@ libdir = $(topdir)/obj/$(BUILD)/lib
PROGRAM_NAME = metaflac
INCLUDES = -I./include -I$(topdir)/include
INCLUDES = -I./include -I$(topdir)/include -I$(OGG_INCLUDE_DIR)
ifeq ($(DARWIN_BUILD),yes)
EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libFLAC.a $(libdir)/libreplaygain_analysis.a $(libdir)/libgetopt.a $(libdir)/libutf8.a -L$(ICONV_LIB_DIR) -liconv -lm
EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libFLAC.a $(libdir)/libreplaygain_analysis.a $(libdir)/libgetopt.a $(libdir)/libutf8.a $(OGG_LIB_DIR)/libogg.a -L$(ICONV_LIB_DIR) -liconv -lm
else
LIBS = -lgrabbag -lFLAC -lreplaygain_analysis -lgetopt -lutf8 -lm
LIBS = -lgrabbag -lFLAC -lreplaygain_analysis -lgetopt -lutf8 -L$(OGG_LIB_DIR) -logg -lm
endif
SRCS_C = \

View File

@@ -62,9 +62,13 @@ static const char * const LayerString[] = {
static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
static ::FLAC__StreamMetadata *expected_metadata_sequence_[9];
static unsigned num_expected_;
static const char *flacfilename_ = "metadata.flac";
static off_t flacfilesize_;
static const char *flacfilename(bool is_ogg)
{
return is_ogg? "metadata.ogg" : "metadata.flac";
}
static bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
@@ -95,9 +99,9 @@ static void free_metadata_blocks_()
mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
}
static bool generate_file_()
static bool generate_file_(FLAC__bool is_ogg)
{
printf("\n\ngenerating FLAC file for decoder tests...\n");
printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":"");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &padding_;
@@ -108,8 +112,9 @@ static bool generate_file_()
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
/* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
return die_("creating the encoded file");
return true;
@@ -191,7 +196,7 @@ public:
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
void error_callback(::FLAC__StreamDecoderErrorStatus status);
bool test_respond();
bool test_respond(bool is_ogg);
};
::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
@@ -296,15 +301,18 @@ void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
common_error_callback_(status);
}
bool StreamDecoder::test_respond()
bool StreamDecoder::test_respond(bool is_ogg)
{
::FLAC__StreamDecoderInitStatus init_status;
if(!set_md5_checking(true)) {
printf("FAILED at set_md5_checking(), returned false\n");
return false;
}
printf("testing init()... ");
if(init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
printf("testing init%s()... ", is_ogg? "_ogg":"");
init_status = is_ogg? init_ogg() : init();
if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, this);
printf("OK\n");
@@ -340,7 +348,7 @@ public:
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
void error_callback(::FLAC__StreamDecoderErrorStatus status);
bool test_respond();
bool test_respond(bool is_ogg);
};
::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
@@ -359,8 +367,10 @@ void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
common_error_callback_(status);
}
bool FileDecoder::test_respond()
bool FileDecoder::test_respond(bool is_ogg)
{
::FLAC__StreamDecoderInitStatus init_status;
if(!set_md5_checking(true)) {
printf("FAILED at set_md5_checking(), returned false\n");
return false;
@@ -369,28 +379,28 @@ bool FileDecoder::test_respond()
switch(layer_) {
case LAYER_FILE:
{
printf("opening FLAC file... ");
FILE *file = ::fopen(flacfilename_, "rb");
printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
FILE *file = ::fopen(flacfilename(is_ogg), "rb");
if(0 == file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
printf("testing init()... ");
if(init(file) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, this);
printf("testing init%s()... ", is_ogg? "_ogg":"");
init_status = is_ogg? init_ogg(file) : init(file);
}
break;
case LAYER_FILENAME:
printf("testing init()... ");
if(init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, this);
printf("testing init%s()... ", is_ogg? "_ogg":"");
init_status = is_ogg? init_ogg(flacfilename(is_ogg)) : init(flacfilename(is_ogg));
break;
default:
die_("internal error 001");
return false;
}
if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, this);
printf("OK\n");
current_metadata_number_ = 0;
@@ -419,12 +429,13 @@ static FLAC::Decoder::Stream *new_by_layer(Layer layer)
return new FileDecoder(layer);
}
static bool test_stream_decoder(Layer layer)
static bool test_stream_decoder(Layer layer, bool is_ogg)
{
FLAC::Decoder::Stream *decoder;
::FLAC__StreamDecoderInitStatus init_status;
bool expect;
printf("\n+++ libFLAC++ unit test: FLAC::Decoder::%s (layer: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer]);
printf("\n+++ libFLAC++ unit test: FLAC::Decoder::%s (layer: %s, format: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer], is_ogg? "Ogg FLAC" : "FLAC");
//
// test new -> delete
@@ -466,26 +477,29 @@ static bool test_stream_decoder(Layer layer)
}
printf("OK\n");
printf("testing init()... ");
printf("testing init%s()... ", is_ogg? "_ogg":"");
switch(layer) {
case LAYER_STREAM:
case LAYER_SEEKABLE_STREAM:
dynamic_cast<StreamDecoder*>(decoder)->file_ = stdin;
if(decoder->init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
init_status = is_ogg? decoder->init_ogg() : decoder->init();
break;
case LAYER_FILE:
if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(stdin) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
init_status = is_ogg?
dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(stdin) :
dynamic_cast<FLAC::Decoder::File*>(decoder)->init(stdin);
break;
case LAYER_FILENAME:
if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
init_status = is_ogg?
dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(flacfilename(is_ogg)) :
dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename(is_ogg));
break;
default:
die_("internal error 006");
return false;
}
if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("OK\n");
printf("freeing decoder instance... ");
@@ -513,6 +527,13 @@ static bool test_stream_decoder(Layer layer)
}
printf("OK\n");
if(is_ogg) {
printf("testing set_serial_number()... ");
if(!decoder->set_serial_number(file_utils__ogg_serial_number))
return die_s_("returned false", decoder);
printf("OK\n");
}
if(!decoder->set_md5_checking(true)) {
printf("FAILED at set_md5_checking(), returned false\n");
return false;
@@ -521,42 +542,45 @@ static bool test_stream_decoder(Layer layer)
switch(layer) {
case LAYER_STREAM:
case LAYER_SEEKABLE_STREAM:
printf("opening FLAC file... ");
dynamic_cast<StreamDecoder*>(decoder)->file_ = ::fopen(flacfilename_, "rb");
printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
dynamic_cast<StreamDecoder*>(decoder)->file_ = ::fopen(flacfilename(is_ogg), "rb");
if(0 == dynamic_cast<StreamDecoder*>(decoder)->file_) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
printf("testing init()... ");
if(decoder->init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("testing init%s()... ", is_ogg? "_ogg":"");
init_status = is_ogg? decoder->init_ogg() : decoder->init();
break;
case LAYER_FILE:
{
printf("opening FLAC file... ");
FILE *file = ::fopen(flacfilename_, "rb");
FILE *file = ::fopen(flacfilename(is_ogg), "rb");
if(0 == file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
printf("testing init()... ");
if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(file) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("testing init%s()... ", is_ogg? "_ogg":"");
init_status = is_ogg?
dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(file) :
dynamic_cast<FLAC::Decoder::File*>(decoder)->init(file);
}
break;
case LAYER_FILENAME:
printf("testing init()... ");
if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("testing init%s()... ", is_ogg? "_ogg":"");
init_status = is_ogg?
dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(flacfilename(is_ogg)) :
dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename(is_ogg));
break;
default:
die_("internal error 009");
return false;
}
if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("OK\n");
printf("testing get_state()... ");
@@ -705,17 +729,30 @@ static bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -731,7 +768,7 @@ static bool test_stream_decoder(Layer layer)
num_expected_ = 0;
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -762,7 +799,7 @@ static bool test_stream_decoder(Layer layer)
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -784,15 +821,26 @@ static bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -814,16 +862,28 @@ static bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -852,15 +912,26 @@ static bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -884,7 +955,7 @@ static bool test_stream_decoder(Layer layer)
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -909,7 +980,7 @@ static bool test_stream_decoder(Layer layer)
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -933,7 +1004,7 @@ static bool test_stream_decoder(Layer layer)
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &application1_;
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -965,7 +1036,7 @@ static bool test_stream_decoder(Layer layer)
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -994,16 +1065,28 @@ static bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
/*
@@ -1034,7 +1117,7 @@ static bool test_stream_decoder(Layer layer)
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &application2_;
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond()))
if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg)))
return false;
if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */
@@ -1051,26 +1134,34 @@ static bool test_stream_decoder(Layer layer)
bool test_decoders()
{
init_metadata_blocks_();
FLAC__bool is_ogg = false;
if(!generate_file_())
return false;
while(1) {
init_metadata_blocks_();
if(!test_stream_decoder(LAYER_STREAM))
return false;
if(!generate_file_(is_ogg))
return false;
if(!test_stream_decoder(LAYER_SEEKABLE_STREAM))
return false;
if(!test_stream_decoder(LAYER_STREAM, is_ogg))
return false;
if(!test_stream_decoder(LAYER_FILE))
return false;
if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg))
return false;
if(!test_stream_decoder(LAYER_FILENAME))
return false;
if(!test_stream_decoder(LAYER_FILE, is_ogg))
return false;
(void) grabbag__file_remove_file(flacfilename_);
if(!test_stream_decoder(LAYER_FILENAME, is_ogg))
return false;
free_metadata_blocks_();
(void) grabbag__file_remove_file(flacfilename(is_ogg));
free_metadata_blocks_();
if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)
break;
is_ogg = true;
}
return true;
}

View File

@@ -19,6 +19,7 @@
#include "encoders.h"
#include "FLAC/assert.h"
#include "FLAC++/encoder.h"
#include "share/grabbag.h"
extern "C" {
#include "test_libs_common/file_utils_flac.h"
#include "test_libs_common/metadata_utils.h"
@@ -43,11 +44,15 @@ static const char * const LayerString[] = {
};
static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
static ::FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_ };
static ::FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ };
static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
static const char *flacfilename_ = "metadata.flac";
static FLAC__bool die_(const char *msg)
static const char *flacfilename(bool is_ogg)
{
return is_ogg? "metadata.ogg" : "metadata.flac";
}
static bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
return false;
@@ -89,12 +94,20 @@ public:
~StreamEncoder() { }
// from FLAC::Encoder::Stream
::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame);
::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
};
::FLAC__StreamEncoderReadStatus StreamEncoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
{
(void)buffer, (void)bytes;
return ::FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
}
::FLAC__StreamEncoderWriteStatus StreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
{
(void)buffer, (void)bytes, (void)samples, (void)current_frame;
@@ -145,15 +158,16 @@ static FLAC::Encoder::Stream *new_by_layer(Layer layer)
return new FileEncoder(layer);
}
static bool test_stream_encoder(Layer layer)
static bool test_stream_encoder(Layer layer, bool is_ogg)
{
FLAC::Encoder::Stream *encoder;
::FLAC__StreamEncoderInitStatus init_status;
FILE *file = 0;
FLAC__int32 samples[1024];
FLAC__int32 *samples_array[1] = { samples };
unsigned i;
printf("\n+++ libFLAC++ unit test: FLAC::Encoder::%s (layer: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer]);
printf("\n+++ libFLAC++ unit test: FLAC::Encoder::%s (layer: %s, format: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer], is_ogg? "Ogg FLAC":"FLAC");
printf("allocating encoder instance... ");
encoder = new_by_layer(layer);
@@ -170,6 +184,13 @@ static bool test_stream_encoder(Layer layer)
}
printf("OK\n");
if(is_ogg) {
printf("testing set_serial_number()... ");
if(!encoder->set_serial_number(file_utils__ogg_serial_number))
return die_s_("returned false", encoder);
printf("OK\n");
}
printf("testing set_verify()... ");
if(!encoder->set_verify(true))
return die_s_("returned false", encoder);
@@ -263,32 +284,35 @@ static bool test_stream_encoder(Layer layer)
switch(layer) {
case LAYER_STREAM:
case LAYER_SEEKABLE_STREAM:
printf("testing init()... ");
if(encoder->init() != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
printf("testing init%s()... ", is_ogg? "_ogg":"");
init_status = is_ogg? encoder->init_ogg() : encoder->init();
break;
case LAYER_FILE:
printf("opening file for FLAC output... ");
file = ::fopen(flacfilename_, "w+b");
file = ::fopen(flacfilename(is_ogg), "w+b");
if(0 == file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
printf("testing init()... ");
if(dynamic_cast<FLAC::Encoder::File*>(encoder)->init(file) != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
printf("testing init%s()... ", is_ogg? "_ogg":"");
init_status = is_ogg?
dynamic_cast<FLAC::Encoder::File*>(encoder)->init_ogg(file) :
dynamic_cast<FLAC::Encoder::File*>(encoder)->init(file);
break;
case LAYER_FILENAME:
printf("testing init()... ");
if(dynamic_cast<FLAC::Encoder::File*>(encoder)->init(flacfilename_) != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
printf("testing init%s()... ", is_ogg? "_ogg":"");
init_status = is_ogg?
dynamic_cast<FLAC::Encoder::File*>(encoder)->init_ogg(flacfilename(is_ogg)) :
dynamic_cast<FLAC::Encoder::File*>(encoder)->init(flacfilename(is_ogg));
break;
default:
die_("internal error 001");
return false;
}
if(init_status != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
printf("OK\n");
printf("testing get_state()... ");
@@ -458,21 +482,31 @@ static bool test_stream_encoder(Layer layer)
bool test_encoders()
{
init_metadata_blocks_();
FLAC__bool is_ogg = false;
if(!test_stream_encoder(LAYER_STREAM))
return false;
while(1) {
init_metadata_blocks_();
if(!test_stream_encoder(LAYER_SEEKABLE_STREAM))
return false;
if(!test_stream_encoder(LAYER_STREAM, is_ogg))
return false;
if(!test_stream_encoder(LAYER_FILE))
return false;
if(!test_stream_encoder(LAYER_SEEKABLE_STREAM, is_ogg))
return false;
if(!test_stream_encoder(LAYER_FILENAME))
return false;
if(!test_stream_encoder(LAYER_FILE, is_ogg))
return false;
free_metadata_blocks_();
if(!test_stream_encoder(LAYER_FILENAME, is_ogg))
return false;
(void) grabbag__file_remove_file(flacfilename(is_ogg));
free_metadata_blocks_();
if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)
break;
is_ogg = true;
}
return true;
}

View File

@@ -16,6 +16,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcpy()/memset() */
@@ -589,7 +593,7 @@ static bool generate_file_(FLAC__bool include_extras)
)
return die_("priming our metadata");
if(!file_utils__generate_flacfile(flacfile_, 0, 512 * 1024, &streaminfo, metadata, n))
if(!file_utils__generate_flacfile(/*is_ogg=*/false, flacfile_, 0, 512 * 1024, &streaminfo, metadata, n))
return die_("creating the encoded file");
free(vorbiscomment.data.vorbis_comment.vendor_string.entry);

View File

@@ -38,10 +38,10 @@
#include "test_libs_common/metadata_utils.h"
typedef enum {
LAYER_STREAM = 0, /* FLAC__stream_decoder_init_stream() without seeking */
LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_stream() with seeking */
LAYER_FILE, /* FLAC__stream_decoder_init_FILE() */
LAYER_FILENAME /* FLAC__stream_decoder_init_file() */
LAYER_STREAM = 0, /* FLAC__stream_decoder_init_[ogg_]stream() without seeking */
LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_[ogg_]stream() with seeking */
LAYER_FILE, /* FLAC__stream_decoder_init_[ogg_]FILE() */
LAYER_FILENAME /* FLAC__stream_decoder_init_[ogg_]file() */
} Layer;
static const char * const LayerString[] = {
@@ -62,9 +62,13 @@ typedef struct {
static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
static FLAC__StreamMetadata *expected_metadata_sequence_[9];
static unsigned num_expected_;
static const char *flacfilename_ = "metadata.flac";
static off_t flacfilesize_;
static const char *flacfilename(FLAC__bool is_ogg)
{
return is_ogg? "metadata.ogg" : "metadata.flac";
}
static FLAC__bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
@@ -95,9 +99,9 @@ static void free_metadata_blocks_()
mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
}
static FLAC__bool generate_file_()
static FLAC__bool generate_file_(FLAC__bool is_ogg)
{
printf("\n\ngenerating FLAC file for decoder tests...\n");
printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":"");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &padding_;
@@ -108,8 +112,9 @@ static FLAC__bool generate_file_()
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
/* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
return die_("creating the encoded file");
return true;
@@ -305,7 +310,7 @@ static void stream_decoder_error_callback_(const FLAC__StreamDecoder *decoder, F
}
}
static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, StreamDecoderClientData *dcd)
static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, StreamDecoderClientData *dcd, FLAC__bool is_ogg)
{
FLAC__StreamDecoderInitStatus init_status;
@@ -314,8 +319,8 @@ static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, Str
/* for FLAC__stream_encoder_init_FILE(), the FLAC__stream_encoder_finish() closes the file so we have to keep re-opening: */
if(dcd->layer == LAYER_FILE) {
printf("opening FLAC file... ");
dcd->file = fopen(flacfilename_, "rb");
printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
dcd->file = fopen(flacfilename(is_ogg), "rb");
if(0 == dcd->file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
@@ -323,19 +328,31 @@ static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, Str
printf("OK\n");
}
printf("testing FLAC__stream_decoder_init_stream()... ");
switch(dcd->layer) {
case LAYER_STREAM:
init_status = 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);
printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
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) :
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)
;
break;
case LAYER_SEEKABLE_STREAM:
init_status = 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);
printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
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) :
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);
break;
case LAYER_FILE:
init_status = FLAC__stream_decoder_init_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
FLAC__stream_decoder_init_ogg_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
FLAC__stream_decoder_init_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
break;
case LAYER_FILENAME:
init_status = FLAC__stream_decoder_init_file(decoder, flacfilename_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) :
FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
break;
default:
die_("internal error 000");
@@ -364,16 +381,17 @@ static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, Str
return true;
}
static FLAC__bool test_stream_decoder(Layer layer)
static FLAC__bool test_stream_decoder(Layer layer, FLAC__bool is_ogg)
{
FLAC__StreamDecoder *decoder;
FLAC__StreamDecoderInitStatus init_status;
FLAC__StreamDecoderState state;
StreamDecoderClientData decoder_client_data;
FLAC__bool expect;
decoder_client_data.layer = layer;
printf("\n+++ libFLAC unit test: FLAC__StreamDecoder (layer: %s)\n\n", LayerString[layer]);
printf("\n+++ libFLAC unit test: FLAC__StreamDecoder (layer: %s, format: %s)\n\n", LayerString[layer], is_ogg? "Ogg FLAC" : "FLAC");
printf("testing FLAC__stream_decoder_new()... ");
decoder = FLAC__stream_decoder_new();
@@ -398,24 +416,29 @@ static FLAC__bool test_stream_decoder(Layer layer)
switch(layer) {
case LAYER_STREAM:
case LAYER_SEEKABLE_STREAM:
printf("testing FLAC__stream_decoder_init_stream()... ");
if(FLAC__stream_decoder_init_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS)
return die_s_(0, decoder);
printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
FLAC__stream_decoder_init_ogg_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0) :
FLAC__stream_decoder_init_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0);
break;
case LAYER_FILE:
printf("testing FLAC__stream_decoder_init_FILE()... ");
if(FLAC__stream_decoder_init_FILE(decoder, stdin, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS)
return die_s_(0, decoder);
printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
FLAC__stream_decoder_init_ogg_FILE(decoder, stdin, 0, 0, 0, 0) :
FLAC__stream_decoder_init_FILE(decoder, stdin, 0, 0, 0, 0);
break;
case LAYER_FILENAME:
printf("testing FLAC__stream_decoder_init_file()... ");
if(FLAC__stream_decoder_init_file(decoder, flacfilename_, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS)
return die_s_(0, decoder);
printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0) :
FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0);
break;
default:
die_("internal error 003");
return false;
}
if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS)
return die_s_(0, decoder);
printf("OK\n");
printf("testing FLAC__stream_decoder_delete()... ");
@@ -433,14 +456,21 @@ static FLAC__bool test_stream_decoder(Layer layer)
}
printf("OK\n");
if(is_ogg) {
printf("testing FLAC__stream_decoder_set_serial_number()... ");
if(!FLAC__stream_decoder_set_serial_number(decoder, file_utils__ogg_serial_number))
return die_s_("returned false", decoder);
printf("OK\n");
}
printf("testing FLAC__stream_decoder_set_md5_checking()... ");
if(!FLAC__stream_decoder_set_md5_checking(decoder, true))
return die_s_("returned false", decoder);
printf("OK\n");
if(layer < LAYER_FILENAME) {
printf("opening FLAC file... ");
decoder_client_data.file = fopen(flacfilename_, "rb");
printf("opening %sFLAC file... ", is_ogg? "Ogg ":"");
decoder_client_data.file = fopen(flacfilename(is_ogg), "rb");
if(0 == decoder_client_data.file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
@@ -450,29 +480,35 @@ static FLAC__bool test_stream_decoder(Layer layer)
switch(layer) {
case LAYER_STREAM:
printf("testing FLAC__stream_decoder_init_stream()... ");
if(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) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
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) :
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);
break;
case LAYER_SEEKABLE_STREAM:
printf("testing FLAC__stream_decoder_init_stream()... ");
if(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) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
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) :
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);
break;
case LAYER_FILE:
printf("testing FLAC__stream_decoder_init_FILE()... ");
if(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) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
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) :
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);
break;
case LAYER_FILENAME:
printf("testing FLAC__stream_decoder_init_file()... ");
if(FLAC__stream_decoder_init_file(decoder, flacfilename_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
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) :
FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data);
break;
default:
die_("internal error 009");
return false;
}
if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("OK\n");
printf("testing FLAC__stream_decoder_get_state()... ");
@@ -622,17 +658,30 @@ static FLAC__bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -646,7 +695,7 @@ static FLAC__bool test_stream_decoder(Layer layer)
num_expected_ = 0;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -673,7 +722,7 @@ static FLAC__bool test_stream_decoder(Layer layer)
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -691,15 +740,26 @@ static FLAC__bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -717,16 +777,28 @@ static FLAC__bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -749,15 +821,26 @@ static FLAC__bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -777,7 +860,7 @@ static FLAC__bool test_stream_decoder(Layer layer)
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -798,7 +881,7 @@ static FLAC__bool test_stream_decoder(Layer layer)
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -818,7 +901,7 @@ static FLAC__bool test_stream_decoder(Layer layer)
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &application1_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -844,7 +927,7 @@ static FLAC__bool test_stream_decoder(Layer layer)
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -867,16 +950,28 @@ static FLAC__bool test_stream_decoder(Layer layer)
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
else {
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
}
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
/*
@@ -901,7 +996,7 @@ static FLAC__bool test_stream_decoder(Layer layer)
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &application2_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg))
return false;
if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */
@@ -918,24 +1013,34 @@ static FLAC__bool test_stream_decoder(Layer layer)
FLAC__bool test_decoders()
{
init_metadata_blocks_();
if(!generate_file_())
return false;
FLAC__bool is_ogg = false;
if(!test_stream_decoder(LAYER_STREAM))
return false;
while(1) {
init_metadata_blocks_();
if(!test_stream_decoder(LAYER_SEEKABLE_STREAM))
return false;
if(!generate_file_(is_ogg))
return false;
if(!test_stream_decoder(LAYER_FILE))
return false;
if(!test_stream_decoder(LAYER_STREAM, is_ogg))
return false;
if(!test_stream_decoder(LAYER_FILENAME))
return false;
if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg))
return false;
(void) grabbag__file_remove_file(flacfilename_);
free_metadata_blocks_();
if(!test_stream_decoder(LAYER_FILE, is_ogg))
return false;
if(!test_stream_decoder(LAYER_FILENAME, is_ogg))
return false;
(void) grabbag__file_remove_file(flacfilename(is_ogg));
free_metadata_blocks_();
if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)
break;
is_ogg = true;
}
return true;
}

View File

@@ -32,10 +32,10 @@
#include "test_libs_common/metadata_utils.h"
typedef enum {
LAYER_STREAM = 0, /* FLAC__stream_encoder_init_stream() without seeking */
LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_stream() with seeking */
LAYER_FILE, /* FLAC__stream_encoder_init_FILE() */
LAYER_FILENAME /* FLAC__stream_encoder_init_file() */
LAYER_STREAM = 0, /* FLAC__stream_encoder_init_[ogg_]stream() without seeking */
LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_[ogg_]stream() with seeking */
LAYER_FILE, /* FLAC__stream_encoder_init_[ogg_]FILE() */
LAYER_FILENAME /* FLAC__stream_encoder_init_[ogg_]file() */
} Layer;
static const char * const LayerString[] = {
@@ -46,9 +46,13 @@ static const char * const LayerString[] = {
};
static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_ };
static FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ };
static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
static const char *flacfilename_ = "metadata.flac";
static const char *flacfilename(FLAC__bool is_ogg)
{
return is_ogg? "metadata.ogg" : "metadata.flac";
}
static FLAC__bool die_(const char *msg)
{
@@ -84,6 +88,13 @@ static void free_metadata_blocks_()
mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
}
static FLAC__StreamEncoderReadStatus stream_encoder_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
(void)encoder, (void)buffer, (void)bytes, (void)client_data;
memset(buffer, 0, *bytes); /* init buffer to avoid valgrind errors */
return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
}
static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
{
(void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
@@ -113,9 +124,10 @@ static void stream_encoder_progress_callback_(const FLAC__StreamEncoder *encoder
(void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
}
static FLAC__bool test_stream_encoder(Layer layer)
static FLAC__bool test_stream_encoder(Layer layer, FLAC__bool is_ogg)
{
FLAC__StreamEncoder *encoder;
FLAC__StreamEncoderInitStatus init_status;
FLAC__StreamEncoderState state;
FLAC__StreamDecoderState dstate;
FILE *file = 0;
@@ -125,7 +137,7 @@ static FLAC__bool test_stream_encoder(Layer layer)
samples_array[0] = samples;
printf("\n+++ libFLAC unit test: FLAC__StreamEncoder (layer: %s)\n\n", LayerString[layer]);
printf("\n+++ libFLAC unit test: FLAC__StreamEncoder (layer: %s, format: %s)\n\n", LayerString[layer], is_ogg? "Ogg FLAC":"FLAC");
printf("testing FLAC__stream_encoder_new()... ");
encoder = FLAC__stream_encoder_new();
@@ -135,6 +147,13 @@ static FLAC__bool test_stream_encoder(Layer layer)
}
printf("OK\n");
if(is_ogg) {
printf("testing FLAC__stream_encoder_set_serial_number()... ");
if(!FLAC__stream_encoder_set_serial_number(encoder, file_utils__ogg_serial_number))
return die_s_("returned false", encoder);
printf("OK\n");
}
printf("testing FLAC__stream_encoder_set_verify()... ");
if(!FLAC__stream_encoder_set_verify(encoder, true))
return die_s_("returned false", encoder);
@@ -227,37 +246,43 @@ static FLAC__bool test_stream_encoder(Layer layer)
switch(layer) {
case LAYER_STREAM:
printf("testing FLAC__stream_encoder_init_stream()... ");
if(FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
printf("testing FLAC__stream_encoder_init_%sstream()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
FLAC__stream_encoder_init_ogg_stream(encoder, /*read_callback=*/0, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/0) :
FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/0);
break;
case LAYER_SEEKABLE_STREAM:
printf("testing FLAC__stream_encoder_init_stream()... ");
if(FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
printf("testing FLAC__stream_encoder_init_%sstream()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
FLAC__stream_encoder_init_ogg_stream(encoder, stream_encoder_read_callback_, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/0) :
FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/0);
break;
case LAYER_FILE:
printf("opening file for FLAC output... ");
file = fopen(flacfilename_, "w+b");
file = fopen(flacfilename(is_ogg), "w+b");
if(0 == file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
printf("testing FLAC__stream_encoder_init_FILE()... ");
if(FLAC__stream_encoder_init_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
printf("testing FLAC__stream_encoder_init_%sFILE()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
FLAC__stream_encoder_init_ogg_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0) :
FLAC__stream_encoder_init_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0);
break;
case LAYER_FILENAME:
printf("testing FLAC__stream_encoder_init_file()... ");
if(FLAC__stream_encoder_init_file(encoder, flacfilename_, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
printf("testing FLAC__stream_encoder_init_%sfile()... ", is_ogg? "ogg_":"");
init_status = is_ogg?
FLAC__stream_encoder_init_ogg_file(encoder, flacfilename(is_ogg), stream_encoder_progress_callback_, /*client_data=*/0) :
FLAC__stream_encoder_init_file(encoder, flacfilename(is_ogg), stream_encoder_progress_callback_, /*client_data=*/0);
break;
default:
die_("internal error 001");
return false;
}
if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
printf("OK\n");
printf("testing FLAC__stream_encoder_get_state()... ");
@@ -427,22 +452,31 @@ static FLAC__bool test_stream_encoder(Layer layer)
FLAC__bool test_encoders()
{
init_metadata_blocks_();
FLAC__bool is_ogg = false;
if(!test_stream_encoder(LAYER_STREAM))
return false;
while(1) {
init_metadata_blocks_();
if(!test_stream_encoder(LAYER_SEEKABLE_STREAM))
return false;
if(!test_stream_encoder(LAYER_STREAM, is_ogg))
return false;
if(!test_stream_encoder(LAYER_FILE))
return false;
if(!test_stream_encoder(LAYER_SEEKABLE_STREAM, is_ogg))
return false;
if(!test_stream_encoder(LAYER_FILENAME))
return false;
if(!test_stream_encoder(LAYER_FILE, is_ogg))
return false;
(void) grabbag__file_remove_file(flacfilename_);
free_metadata_blocks_();
if(!test_stream_encoder(LAYER_FILENAME, is_ogg))
return false;
(void) grabbag__file_remove_file(flacfilename(is_ogg));
free_metadata_blocks_();
if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg)
break;
is_ogg = true;
}
return true;
}

View File

@@ -595,7 +595,7 @@ static FLAC__bool generate_file_(FLAC__bool include_extras)
)
return die_("priming our metadata");
if(!file_utils__generate_flacfile(flacfile_, 0, 512 * 1024, &streaminfo, metadata, n))
if(!file_utils__generate_flacfile(/*is_ogg=*/false, flacfile_, 0, 512 * 1024, &streaminfo, metadata, n))
return die_("creating the encoded file");
free(vorbiscomment.data.vorbis_comment.vendor_string.entry);

View File

@@ -1,40 +0,0 @@
# test_libOggFLAC++ - Unit tester for libOggFLAC++
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
EXTRA_DIST = \
Makefile.lite \
test_libOggFLAC++.dsp
AM_CFLAGS = @OGG_CFLAGS@
noinst_PROGRAMS = test_libOggFLAC++
test_libOggFLAC___LDADD = \
$(top_builddir)/src/share/grabbag/libgrabbag.la \
$(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \
$(top_builddir)/src/test_libs_common/libtest_libs_common.la \
$(top_builddir)/src/libOggFLAC++/libOggFLAC++.la \
$(top_builddir)/src/libOggFLAC/libOggFLAC.la \
$(top_builddir)/src/libFLAC++/libFLAC++.la \
$(top_builddir)/src/libFLAC/libFLAC.la \
@OGG_LIBS@ \
-lm
test_libOggFLAC___SOURCES = \
decoders.cpp \
encoders.cpp \
main.cpp \
decoders.h \
encoders.h

View File

@@ -1,44 +0,0 @@
# test_libOggFLAC++ - Unit tester for libOggFLAC++
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# GNU makefile
#
topdir = ../..
libdir = $(topdir)/obj/$(BUILD)/lib
PROGRAM_NAME = test_libOggFLAC++
INCLUDES = -I$(topdir)/include
ifeq ($(DARWIN_BUILD),yes)
EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libreplaygain_analysis.a $(libdir)/libtest_libs_common.a $(libdir)/libOggFLAC++.a $(libdir)/libOggFLAC.a $(libdir)/libFLAC++.a $(libdir)/libFLAC.a $(OGG_LIB_DIR)/libogg.a -lm
else
LIBS = -lgrabbag -lreplaygain_analysis -ltest_libs_common -lOggFLAC++ -lOggFLAC -lFLAC++ -lFLAC -L$(OGG_LIB_DIR) -logg -lm
endif
SRCS_CPP = \
decoders.cpp \
encoders.cpp \
main.cpp
include $(topdir)/build/exe.mk
LINK = $(CCC) $(LINKAGE)
# DO NOT DELETE THIS LINE -- make depend depends on it.

File diff suppressed because it is too large Load Diff

View File

@@ -1,24 +0,0 @@
/* test_libOggFLAC++ - Unit tester for libOggFLAC++
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef OggFLAC__TEST_LIBOGGFLACPP_DECODERS_H
#define OggFLAC__TEST_LIBOGGFLACPP_DECODERS_H
bool test_decoders();
#endif

View File

@@ -1,499 +0,0 @@
/* test_libOggFLAC++ - Unit tester for libOggFLAC++
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "encoders.h"
#include "FLAC/assert.h"
#include "OggFLAC++/encoder.h"
extern "C" {
#include "test_libs_common/file_utils_oggflac.h"
#include "test_libs_common/metadata_utils.h"
}
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef enum {
LAYER_STREAM = 0, /* FLAC__stream_encoder_init_stream() without seeking */
LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_stream() with seeking */
LAYER_FILE, /* FLAC__stream_encoder_init_FILE() */
LAYER_FILENAME /* FLAC__stream_encoder_init_file() */
} Layer;
static const char * const LayerString[] = {
"Stream",
"Seekable Stream",
"FILE*",
"Filename"
};
static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
static ::FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ };
static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
static const char *flacfilename_ = "metadata.ogg";
static FLAC__bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
return false;
}
static bool die_s_(const char *msg, const OggFLAC::Encoder::Stream *encoder)
{
OggFLAC::Encoder::Stream::State state = encoder->get_state();
if(msg)
printf("FAILED, %s", msg);
else
printf("FAILED");
printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamEncoderState)state), state.as_cstring());
if(state == ::OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
FLAC::Encoder::Stream::State state_ = encoder->get_FLAC_stream_encoder_state();
printf(", state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
if(state_ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
printf(" verify decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
}
}
return false;
}
static void init_metadata_blocks_()
{
mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
}
static void free_metadata_blocks_()
{
mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
}
class StreamEncoder : public OggFLAC::Encoder::Stream {
public:
Layer layer_;
StreamEncoder(Layer layer): OggFLAC::Encoder::Stream(), layer_(layer) { }
~StreamEncoder() { }
// from OggFLAC::Encoder::Stream
::OggFLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);
::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame);
::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
void metadata_callback(const ::FLAC__StreamMetadata *metadata);
};
::OggFLAC__StreamEncoderReadStatus StreamEncoder::read_callback(FLAC__byte buffer[], unsigned *bytes)
{
(void)buffer, (void)bytes;
return ::OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
}
::FLAC__StreamEncoderWriteStatus StreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame)
{
(void)buffer, (void)bytes, (void)samples, (void)current_frame;
return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
::FLAC__StreamEncoderSeekStatus StreamEncoder::seek_callback(FLAC__uint64 absolute_byte_offset)
{
(void)absolute_byte_offset;
return layer_==LAYER_STREAM? ::FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED : ::FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
}
::FLAC__StreamEncoderTellStatus StreamEncoder::tell_callback(FLAC__uint64 *absolute_byte_offset)
{
*absolute_byte_offset = 0;
return layer_==LAYER_STREAM? ::FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED : ::FLAC__STREAM_ENCODER_TELL_STATUS_OK;
}
void StreamEncoder::metadata_callback(const ::FLAC__StreamMetadata *metadata)
{
(void)metadata;
}
class FileEncoder : public OggFLAC::Encoder::File {
public:
Layer layer_;
FileEncoder(Layer layer): OggFLAC::Encoder::File(), layer_(layer) { }
~FileEncoder() { }
// from OggFLAC::Encoder::File
void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
};
void FileEncoder::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate)
{
(void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate;
}
static OggFLAC::Encoder::Stream *new_by_layer(Layer layer)
{
if(layer < LAYER_FILE)
return new StreamEncoder(layer);
else
return new FileEncoder(layer);
}
static bool test_stream_encoder(Layer layer)
{
OggFLAC::Encoder::Stream *encoder;
FILE *file = 0;
FLAC__int32 samples[1024];
FLAC__int32 *samples_array[1] = { samples };
unsigned i;
printf("\n+++ libOggFLAC++ unit test: OggFLAC::Encoder::%s (layer: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer]);
printf("allocating encoder instance... ");
encoder = new_by_layer(layer);
if(0 == encoder) {
printf("FAILED, new returned NULL\n");
return false;
}
printf("OK\n");
printf("testing is_valid()... ");
if(!encoder->is_valid()) {
printf("FAILED, returned false\n");
return false;
}
printf("OK\n");
printf("testing set_serial_number()... ");
if(!encoder->set_serial_number(file_utils__serial_number))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_verify()... ");
if(!encoder->set_verify(true))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_streamable_subset()... ");
if(!encoder->set_streamable_subset(true))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_do_mid_side_stereo()... ");
if(!encoder->set_do_mid_side_stereo(false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_loose_mid_side_stereo()... ");
if(!encoder->set_loose_mid_side_stereo(false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_channels()... ");
if(!encoder->set_channels(streaminfo_.data.stream_info.channels))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_bits_per_sample()... ");
if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_sample_rate()... ");
if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_blocksize()... ");
if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_max_lpc_order()... ");
if(!encoder->set_max_lpc_order(0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_qlp_coeff_precision()... ");
if(!encoder->set_qlp_coeff_precision(0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_do_qlp_coeff_prec_search()... ");
if(!encoder->set_do_qlp_coeff_prec_search(false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_do_escape_coding()... ");
if(!encoder->set_do_escape_coding(false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_do_exhaustive_model_search()... ");
if(!encoder->set_do_exhaustive_model_search(false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_min_residual_partition_order()... ");
if(!encoder->set_min_residual_partition_order(0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_max_residual_partition_order()... ");
if(!encoder->set_max_residual_partition_order(0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_rice_parameter_search_dist()... ");
if(!encoder->set_rice_parameter_search_dist(0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_total_samples_estimate()... ");
if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing set_metadata()... ");
if(!encoder->set_metadata(metadata_sequence_, num_metadata_))
return die_s_("returned false", encoder);
printf("OK\n");
switch(layer) {
case LAYER_STREAM:
case LAYER_SEEKABLE_STREAM:
printf("testing init()... ");
if(encoder->init() != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
case LAYER_FILE:
printf("opening file for Ogg FLAC output... ");
file = ::fopen(flacfilename_, "w+b");
if(0 == file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
printf("testing init()... ");
if(dynamic_cast<OggFLAC::Encoder::File*>(encoder)->init(file) != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
case LAYER_FILENAME:
printf("testing init()... ");
if(dynamic_cast<OggFLAC::Encoder::File*>(encoder)->init(flacfilename_) != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
default:
die_("internal error 001");
return false;
}
printf("OK\n");
printf("testing get_state()... ");
OggFLAC::Encoder::Stream::State state = encoder->get_state();
printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamEncoderState)state), state.as_cstring());
printf("testing get_FLAC_stream_encoder_state()... ");
FLAC::Encoder::Stream::State state_ = encoder->get_FLAC_stream_encoder_state();
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring());
printf("testing get_verify_decoder_state()... ");
FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state();
printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring());
{
FLAC__uint64 absolute_sample;
unsigned frame_number;
unsigned channel;
unsigned sample;
FLAC__int32 expected;
FLAC__int32 got;
printf("testing get_verify_decoder_error_stats()... ");
encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got);
printf("OK\n");
}
printf("testing get_verify()... ");
if(encoder->get_verify() != true) {
printf("FAILED, expected true, got false\n");
return false;
}
printf("OK\n");
printf("testing get_streamable_subset()... ");
if(encoder->get_streamable_subset() != true) {
printf("FAILED, expected true, got false\n");
return false;
}
printf("OK\n");
printf("testing get_do_mid_side_stereo()... ");
if(encoder->get_do_mid_side_stereo() != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing get_loose_mid_side_stereo()... ");
if(encoder->get_loose_mid_side_stereo() != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing get_channels()... ");
if(encoder->get_channels() != streaminfo_.data.stream_info.channels) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels());
return false;
}
printf("OK\n");
printf("testing get_bits_per_sample()... ");
if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample());
return false;
}
printf("OK\n");
printf("testing get_sample_rate()... ");
if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate());
return false;
}
printf("OK\n");
printf("testing get_blocksize()... ");
if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize());
return false;
}
printf("OK\n");
printf("testing get_max_lpc_order()... ");
if(encoder->get_max_lpc_order() != 0) {
printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order());
return false;
}
printf("OK\n");
printf("testing get_qlp_coeff_precision()... ");
(void)encoder->get_qlp_coeff_precision();
/* we asked the encoder to auto select this so we accept anything */
printf("OK\n");
printf("testing get_do_qlp_coeff_prec_search()... ");
if(encoder->get_do_qlp_coeff_prec_search() != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing get_do_escape_coding()... ");
if(encoder->get_do_escape_coding() != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing get_do_exhaustive_model_search()... ");
if(encoder->get_do_exhaustive_model_search() != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing get_min_residual_partition_order()... ");
if(encoder->get_min_residual_partition_order() != 0) {
printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order());
return false;
}
printf("OK\n");
printf("testing get_max_residual_partition_order()... ");
if(encoder->get_max_residual_partition_order() != 0) {
printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order());
return false;
}
printf("OK\n");
printf("testing get_rice_parameter_search_dist()... ");
if(encoder->get_rice_parameter_search_dist() != 0) {
printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist());
return false;
}
printf("OK\n");
printf("testing get_total_samples_estimate()... ");
if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) {
printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate());
return false;
}
printf("OK\n");
/* init the dummy sample buffer */
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
samples[i] = i & 7;
printf("testing process()... ");
if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32)))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing process_interleaved()... ");
if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32)))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing finish()... ");
encoder->finish();
printf("OK\n");
printf("freeing encoder instance... ");
delete encoder;
printf("OK\n");
printf("\nPASSED!\n");
return true;
}
bool test_encoders()
{
init_metadata_blocks_();
if(!test_stream_encoder(LAYER_STREAM))
return false;
if(!test_stream_encoder(LAYER_SEEKABLE_STREAM))
return false;
if(!test_stream_encoder(LAYER_FILE))
return false;
if(!test_stream_encoder(LAYER_FILENAME))
return false;
free_metadata_blocks_();
return true;
}

View File

@@ -1,24 +0,0 @@
/* test_libOggFLAC++ - Unit tester for libOggFLAC++
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef OggFLAC__TEST_LIBOGGFLACPP_ENCODERS_H
#define OggFLAC__TEST_LIBOGGFLACPP_ENCODERS_H
bool test_encoders();
#endif

View File

@@ -1,33 +0,0 @@
/* test_libOggFLAC++ - Unit tester for libOggFLAC++
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "decoders.h"
#include "encoders.h"
int main(int argc, char *argv[])
{
(void)argc, (void)argv;
if(!test_encoders())
return 1;
if(!test_decoders())
return 1;
return 0;
}

View File

@@ -1,120 +0,0 @@
# Microsoft Developer Studio Project File - Name="test_libOggFLAC++" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=test_libOggFLAC++ - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "test_libOggFLAC++.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "test_libOggFLAC++.mak" CFG="test_libOggFLAC++ - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "test_libOggFLAC++ - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "test_libOggFLAC++ - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "test_libOggFLAC++ - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\obj\release\bin"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "..\..\include" /D "NDEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\test_libs_common_static.lib ..\..\obj\release\lib\libOggFLAC++_static.lib ..\..\obj\release\lib\libOggFLAC_static.lib ..\..\obj\release\lib\libFLAC++_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "test_libOggFLAC++ - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\obj\debug\bin"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "..\..\include" /D "_DEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\test_libs_common_static.lib ..\..\obj\debug\lib\libOggFLAC++_static.lib ..\..\obj\debug\lib\libOggFLAC_static.lib ..\..\obj\debug\lib\libFLAC++_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "test_libOggFLAC++ - Win32 Release"
# Name "test_libOggFLAC++ - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\decoders.cpp
# End Source File
# Begin Source File
SOURCE=.\encoders.cpp
# End Source File
# Begin Source File
SOURCE=.\main.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\decoders.h
# End Source File
# Begin Source File
SOURCE=.\encoders.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\README
# End Source File
# End Target
# End Project

View File

@@ -1,40 +0,0 @@
# test_libOggFLAC - Unit tester for libOggFLAC
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
EXTRA_DIST = \
Makefile.lite \
test_libOggFLAC.dsp
AM_CFLAGS = @OGG_CFLAGS@
INCLUDES =
noinst_PROGRAMS = test_libOggFLAC
test_libOggFLAC_LDADD = \
$(top_builddir)/src/share/grabbag/libgrabbag.la \
$(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \
$(top_builddir)/src/test_libs_common/libtest_libs_common.la \
$(top_builddir)/src/libOggFLAC/libOggFLAC.la \
$(top_builddir)/src/libFLAC/libFLAC.la \
@OGG_LIBS@ \
-lm
test_libOggFLAC_SOURCES = \
decoders.c \
encoders.c \
main.c \
decoders.h \
encoders.h

View File

@@ -1,42 +0,0 @@
# test_libOggFLAC - Unit tester for libOggFLAC
# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# GNU makefile
#
topdir = ../..
libdir = $(topdir)/obj/$(BUILD)/lib
PROGRAM_NAME = test_libOggFLAC
INCLUDES = -I$(topdir)/include
ifeq ($(DARWIN_BUILD),yes)
EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libreplaygain_analysis.a $(libdir)/libtest_libs_common.a $(libdir)/libOggFLAC.a $(libdir)/libFLAC.a $(OGG_LIB_DIR)/libogg.a -lm
else
LIBS = -lgrabbag -lreplaygain_analysis -ltest_libs_common -lOggFLAC -lFLAC -L$(OGG_LIB_DIR) -logg -lm
endif
SRCS_C = \
decoders.c \
encoders.c \
main.c
include $(topdir)/build/exe.mk
# DO NOT DELETE THIS LINE -- make depend depends on it.

View File

@@ -1,957 +0,0 @@
/* test_libOggFLAC - Unit tester for libOggFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined _MSC_VER || defined __MINGW32__
#if _MSC_VER <= 1200 /* @@@ [2G limit] */
#define fseeko fseek
#define ftello ftell
#endif
#endif
#include "decoders.h"
#include "FLAC/assert.h"
#include "OggFLAC/stream_decoder.h"
#include "share/grabbag.h"
#include "test_libs_common/file_utils_oggflac.h"
#include "test_libs_common/metadata_utils.h"
//@@@@@@ this is almost exactly like test_libFLAC/decoders.c, maybe should consolidate some stuff like client data and callbacks
typedef enum {
LAYER_STREAM = 0, /* FLAC__stream_decoder_init_stream() without seeking */
LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_stream() with seeking */
LAYER_FILE, /* FLAC__stream_decoder_init_FILE() */
LAYER_FILENAME /* FLAC__stream_decoder_init_file() */
} Layer;
static const char * const LayerString[] = {
"Stream",
"Seekable Stream",
"FILE*",
"Filename"
};
typedef struct {
Layer layer;
FILE *file;
unsigned current_metadata_number;
FLAC__bool ignore_errors;
FLAC__bool error_occurred;
} StreamDecoderClientData;
static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
static FLAC__StreamMetadata *expected_metadata_sequence_[9];
static unsigned num_expected_;
static const char *flacfilename_ = "metadata.ogg";
static off_t flacfilesize_;
static FLAC__bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
return false;
}
static FLAC__bool die_s_(const char *msg, const OggFLAC__StreamDecoder *decoder)
{
OggFLAC__StreamDecoderState state = OggFLAC__stream_decoder_get_state(decoder);
if(msg)
printf("FAILED, %s", msg);
else
printf("FAILED");
printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__StreamDecoderStateString[state]);
if(state == OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
FLAC__StreamDecoderState state_ = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder);
printf(" FLAC stream decoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamDecoderStateString[state_]);
}
return false;
}
static void init_metadata_blocks_()
{
mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
}
static void free_metadata_blocks_()
{
mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
}
static FLAC__bool generate_file_()
{
printf("\n\ngenerating Ogg FLAC file for decoder tests...\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
/* WATCHOUT: the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */
if(!file_utils__generate_oggflacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_))
return die_("creating the encoded file");
return true;
}
static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
const unsigned requested_bytes = *bytes;
(void)decoder;
if(0 == dcd) {
printf("ERROR: client_data in read callback is NULL\n");
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
if(dcd->error_occurred)
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
if(feof(dcd->file)) {
*bytes = 0;
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
}
else if(requested_bytes > 0) {
*bytes = fread(buffer, 1, requested_bytes, dcd->file);
if(*bytes == 0) {
if(feof(dcd->file))
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
else
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
else {
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
}
else
return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
}
static FLAC__StreamDecoderSeekStatus stream_decoder_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
(void)decoder;
if(0 == dcd) {
printf("ERROR: client_data in seek callback is NULL\n");
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
}
if(dcd->error_occurred)
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
if(fseeko(dcd->file, (off_t)absolute_byte_offset, SEEK_SET) < 0) {
dcd->error_occurred = true;
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
}
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
}
static FLAC__StreamDecoderTellStatus stream_decoder_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
off_t offset;
(void)decoder;
if(0 == dcd) {
printf("ERROR: client_data in tell callback is NULL\n");
return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
}
if(dcd->error_occurred)
return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
offset = ftello(dcd->file);
*absolute_byte_offset = (FLAC__uint64)offset;
if(offset < 0) {
dcd->error_occurred = true;
return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
}
return FLAC__STREAM_DECODER_TELL_STATUS_OK;
}
static FLAC__StreamDecoderLengthStatus stream_decoder_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
{
StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
(void)decoder;
if(0 == dcd) {
printf("ERROR: client_data in length callback is NULL\n");
return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
}
if(dcd->error_occurred)
return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
*stream_length = (FLAC__uint64)flacfilesize_;
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
}
static FLAC__bool stream_decoder_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
{
StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
(void)decoder;
if(0 == dcd) {
printf("ERROR: client_data in eof callback is NULL\n");
return true;
}
if(dcd->error_occurred)
return true;
return feof(dcd->file);
}
static FLAC__StreamDecoderWriteStatus stream_decoder_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
{
StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
(void)decoder, (void)buffer;
if(0 == dcd) {
printf("ERROR: client_data in write callback is NULL\n");
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
if(dcd->error_occurred)
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
if(
(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) ||
(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0)
) {
printf("content... ");
fflush(stdout);
}
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
static void stream_decoder_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
(void)decoder;
if(0 == dcd) {
printf("ERROR: client_data in metadata callback is NULL\n");
return;
}
if(dcd->error_occurred)
return;
printf("%d... ", dcd->current_metadata_number);
fflush(stdout);
if(dcd->current_metadata_number >= num_expected_) {
(void)die_("got more metadata blocks than expected");
dcd->error_occurred = true;
}
else {
if(!mutils__compare_block(expected_metadata_sequence_[dcd->current_metadata_number], metadata)) {
(void)die_("metadata block mismatch");
dcd->error_occurred = true;
}
}
dcd->current_metadata_number++;
}
static void stream_decoder_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
{
StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data;
(void)decoder;
if(0 == dcd) {
printf("ERROR: client_data in error callback is NULL\n");
return;
}
if(!dcd->ignore_errors) {
printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, FLAC__StreamDecoderErrorStatusString[status]);
dcd->error_occurred = true;
}
}
static FLAC__bool stream_decoder_test_respond_(OggFLAC__StreamDecoder *decoder, StreamDecoderClientData *dcd)
{
FLAC__StreamDecoderInitStatus init_status;
if(!OggFLAC__stream_decoder_set_md5_checking(decoder, true))
return die_s_("at OggFLAC__stream_decoder_set_md5_checking(), returned false", decoder);
/* for OggFLAC__stream_encoder_init_FILE(), the OggFLAC__stream_encoder_finish() closes the file so we have to keep re-opening: */
if(dcd->layer == LAYER_FILE) {
printf("opening Ogg FLAC file... ");
dcd->file = fopen(flacfilename_, "rb");
if(0 == dcd->file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
}
printf("testing OggFLAC__stream_decoder_init_stream()... ");
switch(dcd->layer) {
case LAYER_STREAM:
init_status = OggFLAC__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);
break;
case LAYER_SEEKABLE_STREAM:
init_status = OggFLAC__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);
break;
case LAYER_FILE:
init_status = OggFLAC__stream_decoder_init_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
break;
case LAYER_FILENAME:
init_status = OggFLAC__stream_decoder_init_file(decoder, flacfilename_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd);
break;
default:
die_("internal error 000");
return false;
}
if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
printf("OK\n");
dcd->current_metadata_number = 0;
if(dcd->layer < LAYER_FILE && fseeko(dcd->file, 0, SEEK_SET) < 0) {
printf("FAILED rewinding input, errno = %d\n", errno);
return false;
}
printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_finish()... ");
OggFLAC__stream_decoder_finish(decoder);
printf("OK\n");
return true;
}
static FLAC__bool test_stream_decoder(Layer layer)
{
OggFLAC__StreamDecoder *decoder;
OggFLAC__StreamDecoderState state;
FLAC__StreamDecoderState fstate;
StreamDecoderClientData decoder_client_data;
FLAC__bool expect;
decoder_client_data.layer = layer;
printf("\n+++ libOggFLAC unit test: OggFLAC__StreamDecoder (layer: %s)\n\n", LayerString[layer]);
printf("testing OggFLAC__stream_decoder_new()... ");
decoder = OggFLAC__stream_decoder_new();
if(0 == decoder) {
printf("FAILED, returned NULL\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_decoder_delete()... ");
OggFLAC__stream_decoder_delete(decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_new()... ");
decoder = OggFLAC__stream_decoder_new();
if(0 == decoder) {
printf("FAILED, returned NULL\n");
return false;
}
printf("OK\n");
switch(layer) {
case LAYER_STREAM:
case LAYER_SEEKABLE_STREAM:
printf("testing OggFLAC__stream_decoder_init_stream()... ");
if(OggFLAC__stream_decoder_init_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS)
return die_s_(0, decoder);
break;
case LAYER_FILE:
printf("testing OggFLAC__stream_decoder_init_FILE()... ");
if(OggFLAC__stream_decoder_init_FILE(decoder, stdin, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS)
return die_s_(0, decoder);
break;
case LAYER_FILENAME:
printf("testing OggFLAC__stream_decoder_init_file()... ");
if(OggFLAC__stream_decoder_init_file(decoder, flacfilename_, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS)
return die_s_(0, decoder);
break;
default:
die_("internal error 003");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_decoder_delete()... ");
OggFLAC__stream_decoder_delete(decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
printf("testing OggFLAC__stream_decoder_new()... ");
decoder = OggFLAC__stream_decoder_new();
if(0 == decoder) {
printf("FAILED, returned NULL\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_serial_number()... ");
if(!OggFLAC__stream_decoder_set_serial_number(decoder, file_utils__serial_number))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_md5_checking()... ");
if(!OggFLAC__stream_decoder_set_md5_checking(decoder, true))
return die_s_("returned false", decoder);
printf("OK\n");
if(layer < LAYER_FILENAME) {
printf("opening Ogg FLAC file... ");
decoder_client_data.file = fopen(flacfilename_, "rb");
if(0 == decoder_client_data.file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
}
switch(layer) {
case LAYER_STREAM:
printf("testing OggFLAC__stream_decoder_init_stream()... ");
if(OggFLAC__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) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
break;
case LAYER_SEEKABLE_STREAM:
printf("testing OggFLAC__stream_decoder_init_stream()... ");
if(OggFLAC__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) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
break;
case LAYER_FILE:
printf("testing OggFLAC__stream_decoder_init_FILE()... ");
if(OggFLAC__stream_decoder_init_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
break;
case LAYER_FILENAME:
printf("testing OggFLAC__stream_decoder_init_file()... ");
if(OggFLAC__stream_decoder_init_file(decoder, flacfilename_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_(0, decoder);
break;
default:
die_("internal error 009");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_decoder_get_state()... ");
state = OggFLAC__stream_decoder_get_state(decoder);
printf("returned state = %u (%s)... OK\n", state, OggFLAC__StreamDecoderStateString[state]);
printf("testing OggFLAC__stream_decoder_get_FLAC_stream_decoder_state()... ");
fstate = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder);
printf("returned state = %u (%s)... OK\n", fstate, FLAC__StreamDecoderStateString[fstate]);
decoder_client_data.current_metadata_number = 0;
decoder_client_data.ignore_errors = false;
decoder_client_data.error_occurred = false;
printf("testing OggFLAC__stream_decoder_get_md5_checking()... ");
if(!OggFLAC__stream_decoder_get_md5_checking(decoder)) {
printf("FAILED, returned false, expected true\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_decoder_process_until_end_of_metadata()... ");
if(!OggFLAC__stream_decoder_process_until_end_of_metadata(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_process_single()... ");
if(!OggFLAC__stream_decoder_process_single(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_skip_single_frame()... ");
if(!OggFLAC__stream_decoder_skip_single_frame(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
if(layer < LAYER_FILE) {
printf("testing OggFLAC__stream_decoder_flush()... ");
if(!OggFLAC__stream_decoder_flush(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
decoder_client_data.ignore_errors = true;
printf("testing OggFLAC__stream_decoder_process_single()... ");
if(!OggFLAC__stream_decoder_process_single(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
decoder_client_data.ignore_errors = false;
}
expect = (layer != LAYER_STREAM);
printf("testing OggFLAC__stream_decoder_seek_absolute()... ");
if(OggFLAC__stream_decoder_seek_absolute(decoder, 0) != expect)
return die_s_(expect? "returned false" : "returned true", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
expect = (layer != LAYER_STREAM);
printf("testing OggFLAC__stream_decoder_seek_absolute()... ");
if(OggFLAC__stream_decoder_seek_absolute(decoder, 0) != expect)
return die_s_(expect? "returned false" : "returned true", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_get_channels()... ");
{
unsigned channels = OggFLAC__stream_decoder_get_channels(decoder);
if(channels != streaminfo_.data.stream_info.channels) {
printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels);
return false;
}
}
printf("OK\n");
printf("testing OggFLAC__stream_decoder_get_bits_per_sample()... ");
{
unsigned bits_per_sample = OggFLAC__stream_decoder_get_bits_per_sample(decoder);
if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) {
printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample);
return false;
}
}
printf("OK\n");
printf("testing OggFLAC__stream_decoder_get_sample_rate()... ");
{
unsigned sample_rate = OggFLAC__stream_decoder_get_sample_rate(decoder);
if(sample_rate != streaminfo_.data.stream_info.sample_rate) {
printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate);
return false;
}
}
printf("OK\n");
printf("testing OggFLAC__stream_decoder_get_blocksize()... ");
{
unsigned blocksize = OggFLAC__stream_decoder_get_blocksize(decoder);
/* value could be anything since we're at the last block, so accept any reasonable answer */
printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED");
if(blocksize == 0)
return false;
}
printf("testing OggFLAC__stream_decoder_get_channel_assignment()... ");
{
FLAC__ChannelAssignment ca = OggFLAC__stream_decoder_get_channel_assignment(decoder);
printf("returned %u (%s)... OK\n", (unsigned)ca, FLAC__ChannelAssignmentString[ca]);
}
if(layer < LAYER_FILE) {
printf("testing OggFLAC__stream_decoder_reset()... ");
if(!OggFLAC__stream_decoder_reset(decoder)) {
state = OggFLAC__stream_decoder_get_state(decoder);
printf("FAILED, returned false, state = %u (%s)\n", state, OggFLAC__StreamDecoderStateString[state]);
return false;
}
printf("OK\n");
if(layer == LAYER_STREAM) {
/* after a reset() we have to rewind the input ourselves */
printf("rewinding input... ");
if(fseeko(decoder_client_data.file, 0, SEEK_SET) < 0) {
printf("FAILED, errno = %d\n", errno);
return false;
}
printf("OK\n");
}
decoder_client_data.current_metadata_number = 0;
printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... ");
if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
}
printf("testing OggFLAC__stream_decoder_finish()... ");
(void) OggFLAC__stream_decoder_finish(decoder);
printf("OK\n");
/*
* respond all
*/
printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* ignore all
*/
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* respond all, ignore VORBIS_COMMENT
*/
printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_ignore(VORBIS_COMMENT)... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* respond all, ignore APPLICATION
*/
printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* respond all, ignore APPLICATION id of app#1
*/
printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application2_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* respond all, ignore APPLICATION id of app#1 & app#2
*/
printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #2)... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* ignore all, respond VORBIS_COMMENT
*/
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_respond(VORBIS_COMMENT)... ");
if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* ignore all, respond APPLICATION
*/
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* ignore all, respond APPLICATION id of app#1
*/
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &application1_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* ignore all, respond APPLICATION id of app#1 & app#2
*/
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #2)... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application2_.data.application.id))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &application2_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* respond all, ignore APPLICATION, respond APPLICATION id of app#1
*/
printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... ");
if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &streaminfo_;
expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;
expected_metadata_sequence_[num_expected_++] = &padding_;
expected_metadata_sequence_[num_expected_++] = &seektable_;
expected_metadata_sequence_[num_expected_++] = &application1_;
expected_metadata_sequence_[num_expected_++] = &cuesheet_;
expected_metadata_sequence_[num_expected_++] = &picture_;
expected_metadata_sequence_[num_expected_++] = &unknown_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
/*
* ignore all, respond APPLICATION, ignore APPLICATION id of app#1
*/
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... ");
if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION))
return die_s_("returned false", decoder);
printf("OK\n");
printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... ");
if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id))
return die_s_("returned false", decoder);
printf("OK\n");
num_expected_ = 0;
expected_metadata_sequence_[num_expected_++] = &application2_;
if(!stream_decoder_test_respond_(decoder, &decoder_client_data))
return false;
if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */
fclose(decoder_client_data.file);
printf("testing OggFLAC__stream_decoder_delete()... ");
OggFLAC__stream_decoder_delete(decoder);
printf("OK\n");
printf("\nPASSED!\n");
return true;
}
FLAC__bool test_decoders()
{
init_metadata_blocks_();
if(!generate_file_())
return false;
if(!test_stream_decoder(LAYER_STREAM))
return false;
if(!test_stream_decoder(LAYER_SEEKABLE_STREAM))
return false;
if(!test_stream_decoder(LAYER_FILE))
return false;
if(!test_stream_decoder(LAYER_FILENAME))
return false;
(void) grabbag__file_remove_file(flacfilename_);
free_metadata_blocks_();
return true;
}

View File

@@ -1,26 +0,0 @@
/* test_libOggFLAC - Unit tester for libOggFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef OggFLAC__TEST_LIBOGGFLAC_DECODERS_H
#define OggFLAC__TEST_LIBOGGFLAC_DECODERS_H
#include "FLAC/ordinals.h"
FLAC__bool test_decoders();
#endif

View File

@@ -1,469 +0,0 @@
/* test_libOggFLAC - Unit tester for libOggFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "encoders.h"
#include "FLAC/assert.h"
#include "OggFLAC/stream_encoder.h"
#include "share/grabbag.h"
#include "test_libs_common/file_utils_oggflac.h"
#include "test_libs_common/metadata_utils.h"
typedef enum {
LAYER_STREAM = 0, /* FLAC__stream_encoder_init_stream() without seeking */
LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_stream() with seeking */
LAYER_FILE, /* FLAC__stream_encoder_init_FILE() */
LAYER_FILENAME /* FLAC__stream_encoder_init_file() */
} Layer;
static const char * const LayerString[] = {
"Stream",
"Seekable Stream",
"FILE*",
"Filename"
};
static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_;
static FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ };
static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
static const char *flacfilename_ = "metadata.ogg";
static FLAC__bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
return false;
}
static FLAC__bool die_s_(const char *msg, const OggFLAC__StreamEncoder *encoder)
{
OggFLAC__StreamEncoderState state = OggFLAC__stream_encoder_get_state(encoder);
if(msg)
printf("FAILED, %s", msg);
else
printf("FAILED");
printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__StreamEncoderStateString[state]);
if(state == OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
FLAC__StreamEncoderState state_ = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder);
printf(" FLAC stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
FLAC__StreamDecoderState dstate = OggFLAC__stream_encoder_get_verify_decoder_state(encoder);
printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
}
}
return false;
}
static void init_metadata_blocks_()
{
mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
}
static void free_metadata_blocks_()
{
mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_);
}
static OggFLAC__StreamEncoderReadStatus stream_encoder_read_callback_(const OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
{
(void)encoder, (void)buffer, (void)bytes, (void)client_data;
memset(buffer, 0, *bytes); /* init buffer to avoid valgrind errors */
return OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
}
static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
{
(void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
static FLAC__StreamEncoderSeekStatus stream_encoder_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
{
(void)encoder, (void)absolute_byte_offset, (void)client_data;
return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
}
static FLAC__StreamEncoderTellStatus stream_encoder_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
{
(void)encoder, (void)client_data;
*absolute_byte_offset = 0;
return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
}
static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
(void)encoder, (void)metadata, (void)client_data;
}
static void stream_encoder_progress_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
{
(void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
}
static FLAC__bool test_stream_encoder(Layer layer)
{
OggFLAC__StreamEncoder *encoder;
OggFLAC__StreamEncoderState state;
FLAC__StreamEncoderState fstate;
FLAC__StreamDecoderState dstate;
FILE *file = 0;
FLAC__int32 samples[1024];
FLAC__int32 *samples_array[1];
unsigned i;
samples_array[0] = samples;
printf("\n+++ libOggFLAC unit test: OggFLAC__StreamEncoder (layer: %s)\n\n", LayerString[layer]);
printf("testing OggFLAC__stream_encoder_new()... ");
encoder = OggFLAC__stream_encoder_new();
if(0 == encoder) {
printf("FAILED, returned NULL\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_serial_number()... ");
if(!OggFLAC__stream_encoder_set_serial_number(encoder, file_utils__serial_number))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_verify()... ");
if(!OggFLAC__stream_encoder_set_verify(encoder, true))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_streamable_subset()... ");
if(!OggFLAC__stream_encoder_set_streamable_subset(encoder, true))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_do_mid_side_stereo()... ");
if(!OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_loose_mid_side_stereo()... ");
if(!OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_channels()... ");
if(!OggFLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_bits_per_sample()... ");
if(!OggFLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_sample_rate()... ");
if(!OggFLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_blocksize()... ");
if(!OggFLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_max_lpc_order()... ");
if(!OggFLAC__stream_encoder_set_max_lpc_order(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_qlp_coeff_precision()... ");
if(!OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
if(!OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_do_escape_coding()... ");
if(!OggFLAC__stream_encoder_set_do_escape_coding(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_do_exhaustive_model_search()... ");
if(!OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_min_residual_partition_order()... ");
if(!OggFLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_max_residual_partition_order()... ");
if(!OggFLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_rice_parameter_search_dist()... ");
if(!OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_total_samples_estimate()... ");
if(!OggFLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_set_metadata()... ");
if(!OggFLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
return die_s_("returned false", encoder);
printf("OK\n");
switch(layer) {
case LAYER_STREAM:
printf("testing OggFLAC__stream_encoder_init_stream()... ");
if(OggFLAC__stream_encoder_init_stream(encoder, /*read_callback=*/0, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
case LAYER_SEEKABLE_STREAM:
printf("testing OggFLAC__stream_encoder_init_stream()... ");
if(OggFLAC__stream_encoder_init_stream(encoder, stream_encoder_read_callback_, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
case LAYER_FILE:
printf("opening file for Ogg FLAC output... ");
file = fopen(flacfilename_, "w+b");
if(0 == file) {
printf("ERROR (%s)\n", strerror(errno));
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_init_FILE()... ");
if(OggFLAC__stream_encoder_init_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
case LAYER_FILENAME:
printf("testing OggFLAC__stream_encoder_init_file()... ");
if(OggFLAC__stream_encoder_init_file(encoder, flacfilename_, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK)
return die_s_(0, encoder);
break;
default:
die_("internal error 001");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_state()... ");
state = OggFLAC__stream_encoder_get_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)state, OggFLAC__StreamEncoderStateString[state]);
printf("testing OggFLAC__stream_encoder_get_FLAC_stream_encoder_state()... ");
fstate = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)fstate, FLAC__StreamEncoderStateString[fstate]);
printf("testing OggFLAC__stream_encoder_get_verify_decoder_state()... ");
dstate = OggFLAC__stream_encoder_get_verify_decoder_state(encoder);
printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
{
FLAC__uint64 absolute_sample;
unsigned frame_number;
unsigned channel;
unsigned sample;
FLAC__int32 expected;
FLAC__int32 got;
printf("testing OggFLAC__stream_encoder_get_verify_decoder_error_stats()... ");
OggFLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
printf("OK\n");
}
printf("testing OggFLAC__stream_encoder_get_verify()... ");
if(OggFLAC__stream_encoder_get_verify(encoder) != true) {
printf("FAILED, expected true, got false\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_streamable_subset()... ");
if(OggFLAC__stream_encoder_get_streamable_subset(encoder) != true) {
printf("FAILED, expected true, got false\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_do_mid_side_stereo()... ");
if(OggFLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_loose_mid_side_stereo()... ");
if(OggFLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_channels()... ");
if(OggFLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, OggFLAC__stream_encoder_get_channels(encoder));
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_bits_per_sample()... ");
if(OggFLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, OggFLAC__stream_encoder_get_bits_per_sample(encoder));
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_sample_rate()... ");
if(OggFLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, OggFLAC__stream_encoder_get_sample_rate(encoder));
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_blocksize()... ");
if(OggFLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, OggFLAC__stream_encoder_get_blocksize(encoder));
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_max_lpc_order()... ");
if(OggFLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_max_lpc_order(encoder));
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_qlp_coeff_precision()... ");
(void)OggFLAC__stream_encoder_get_qlp_coeff_precision(encoder);
/* we asked the encoder to auto select this so we accept anything */
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
if(OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_do_escape_coding()... ");
if(OggFLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_do_exhaustive_model_search()... ");
if(OggFLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
printf("FAILED, expected false, got true\n");
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_min_residual_partition_order()... ");
if(OggFLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_min_residual_partition_order(encoder));
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_max_residual_partition_order()... ");
if(OggFLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_max_residual_partition_order(encoder));
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_rice_parameter_search_dist()... ");
if(OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
return false;
}
printf("OK\n");
printf("testing OggFLAC__stream_encoder_get_total_samples_estimate()... ");
if(OggFLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, OggFLAC__stream_encoder_get_total_samples_estimate(encoder));
return false;
}
printf("OK\n");
/* init the dummy sample buffer */
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
samples[i] = i & 7;
printf("testing OggFLAC__stream_encoder_process()... ");
if(!OggFLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_process_interleaved()... ");
if(!OggFLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
return die_s_("returned false", encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_finish()... ");
OggFLAC__stream_encoder_finish(encoder);
printf("OK\n");
printf("testing OggFLAC__stream_encoder_delete()... ");
OggFLAC__stream_encoder_delete(encoder);
printf("OK\n");
printf("\nPASSED!\n");
return true;
}
FLAC__bool test_encoders()
{
init_metadata_blocks_();
if(!test_stream_encoder(LAYER_STREAM))
return false;
if(!test_stream_encoder(LAYER_SEEKABLE_STREAM))
return false;
if(!test_stream_encoder(LAYER_FILE))
return false;
if(!test_stream_encoder(LAYER_FILENAME))
return false;
(void) grabbag__file_remove_file(flacfilename_);
free_metadata_blocks_();
return true;
}

View File

@@ -1,26 +0,0 @@
/* test_libOggFLAC - Unit tester for libOggFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef OggFLAC__TEST_LIBOGGFLAC_ENCODERS_H
#define OggFLAC__TEST_LIBOGGFLAC_ENCODERS_H
#include "FLAC/ordinals.h"
FLAC__bool test_encoders();
#endif

View File

@@ -1,37 +0,0 @@
/* test_libOggFLAC - Unit tester for libOggFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include "decoders.h"
#include "encoders.h"
int main(int argc, char *argv[])
{
(void)argc, (void)argv;
if(!test_encoders())
return 1;
if(!test_decoders())
return 1;
return 0;
}

View File

@@ -1,120 +0,0 @@
# Microsoft Developer Studio Project File - Name="test_libOggFLAC" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=test_libOggFLAC - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "test_libOggFLAC.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "test_libOggFLAC.mak" CFG="test_libOggFLAC - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "test_libOggFLAC - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "test_libOggFLAC - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "test_libOggFLAC - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\obj\release\bin"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\include" /D "NDEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\test_libs_common_static.lib ..\..\obj\release\lib\libOggFLAC_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "test_libOggFLAC - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "..\..\obj\debug\bin"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\include" /D "_DEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\test_libs_common_static.lib ..\..\obj\debug\lib\libOggFLAC_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "test_libOggFLAC - Win32 Release"
# Name "test_libOggFLAC - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\decoders.c
# End Source File
# Begin Source File
SOURCE=.\encoders.c
# End Source File
# Begin Source File
SOURCE=.\main.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\decoders.h
# End Source File
# Begin Source File
SOURCE=.\encoders.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\README
# End Source File
# End Target
# End Project

View File

@@ -15,21 +15,13 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
if FLaC__HAS_OGG
OGGFLAC_SOURCES = \
file_utils_oggflac.c
OGGFLAC_LIBS = \
../libOggFLAC/libOggFLAC.la
endif
INCLUDES = -I$(top_srcdir)/include
noinst_LTLIBRARIES = libtest_libs_common.la
libtest_libs_common_la_SOURCES = \
file_utils_flac.c \
metadata_utils.c \
$(OGGFLAC_SOURCES)
metadata_utils.c
EXTRA_DIST = \
Makefile.lite \

View File

@@ -28,7 +28,6 @@ INCLUDES = -I$(topdir)/include
SRCS_C = \
file_utils_flac.c \
file_utils_oggflac.c \
metadata_utils.c
include $(topdir)/build/lib.mk

View File

@@ -32,6 +32,8 @@
#endif
#define min(a,b) ((a)<(b)?(a):(b))
const long file_utils__ogg_serial_number = 12345;
#ifdef FLAC__VALGRIND_TESTING
static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
@@ -65,10 +67,11 @@ static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const
(void)encoder, (void)metadata, (void)client_data;
}
FLAC__bool file_utils__generate_flacfile(const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata)
FLAC__bool file_utils__generate_flacfile(FLAC__bool is_ogg, const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata)
{
FLAC__int32 samples[1024];
FLAC__StreamEncoder *encoder;
FLAC__StreamEncoderInitStatus init_status;
encoder_client_struct encoder_client_data;
unsigned i, n;
@@ -86,6 +89,7 @@ FLAC__bool file_utils__generate_flacfile(const char *output_filename, off_t *out
return false;
}
FLAC__stream_encoder_set_serial_number(encoder, file_utils__ogg_serial_number);
FLAC__stream_encoder_set_verify(encoder, true);
FLAC__stream_encoder_set_streamable_subset(encoder, true);
FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false);
@@ -105,7 +109,12 @@ FLAC__bool file_utils__generate_flacfile(const char *output_filename, off_t *out
FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo->data.stream_info.total_samples);
FLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata);
if(FLAC__stream_encoder_init_stream(encoder, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
if(is_ogg)
init_status = FLAC__stream_encoder_init_ogg_stream(encoder, /*read_callback=*/0, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data);
else
init_status = FLAC__stream_encoder_init_stream(encoder, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data);
if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
fclose(encoder_client_data.file);
return false;
}

View File

@@ -1,147 +0,0 @@
/* test_libOggFLAC - Unit tester for libOggFLAC
* Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include "FLAC/assert.h"
#include "OggFLAC/stream_encoder.h"
#include "test_libs_common/file_utils_oggflac.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h> /* for stat() */
#ifdef min
#undef min
#endif
#define min(a,b) ((a)<(b)?(a):(b))
const long file_utils__serial_number = 12345;
#ifdef FLAC__VALGRIND_TESTING
static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t ret = fwrite(ptr, size, nmemb, stream);
if(!ferror(stream))
fflush(stream);
return ret;
}
#else
#define local__fwrite fwrite
#endif
typedef struct {
FILE *file;
} encoder_client_struct;
static FLAC__StreamEncoderWriteStatus encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
{
encoder_client_struct *ecd = (encoder_client_struct*)client_data;
(void)encoder, (void)samples, (void)current_frame;
if(local__fwrite(buffer, 1, bytes, ecd->file) != bytes)
return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
else
return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
(void)encoder, (void)metadata, (void)client_data;
}
FLAC__bool file_utils__generate_oggflacfile(const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata)
{
FLAC__int32 samples[1024];
OggFLAC__StreamEncoder *encoder;
encoder_client_struct encoder_client_data;
unsigned i, n;
FLAC__ASSERT(0 != output_filename);
FLAC__ASSERT(0 != streaminfo);
FLAC__ASSERT(streaminfo->type == FLAC__METADATA_TYPE_STREAMINFO);
FLAC__ASSERT((streaminfo->is_last && num_metadata == 0) || (!streaminfo->is_last && num_metadata > 0));
if(0 == (encoder_client_data.file = fopen(output_filename, "wb")))
return false;
encoder = OggFLAC__stream_encoder_new();
if(0 == encoder) {
fclose(encoder_client_data.file);
return false;
}
OggFLAC__stream_encoder_set_serial_number(encoder, file_utils__serial_number);
OggFLAC__stream_encoder_set_verify(encoder, true);
OggFLAC__stream_encoder_set_streamable_subset(encoder, true);
OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder, false);
OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false);
OggFLAC__stream_encoder_set_channels(encoder, streaminfo->data.stream_info.channels);
OggFLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo->data.stream_info.bits_per_sample);
OggFLAC__stream_encoder_set_sample_rate(encoder, streaminfo->data.stream_info.sample_rate);
OggFLAC__stream_encoder_set_blocksize(encoder, streaminfo->data.stream_info.min_blocksize);
OggFLAC__stream_encoder_set_max_lpc_order(encoder, 0);
OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0);
OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false);
OggFLAC__stream_encoder_set_do_escape_coding(encoder, false);
OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false);
OggFLAC__stream_encoder_set_min_residual_partition_order(encoder, 0);
OggFLAC__stream_encoder_set_max_residual_partition_order(encoder, 0);
OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0);
OggFLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo->data.stream_info.total_samples);
OggFLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata);
if(OggFLAC__stream_encoder_init_stream(encoder, /*read_callback=*/0, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
fclose(encoder_client_data.file);
return false;
}
/* init the dummy sample buffer */
for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
samples[i] = i & 7;
while(length > 0) {
n = min(length, sizeof(samples) / sizeof(FLAC__int32));
if(!OggFLAC__stream_encoder_process_interleaved(encoder, samples, n)) {
fclose(encoder_client_data.file);
return false;
}
length -= n;
}
OggFLAC__stream_encoder_finish(encoder);
fclose(encoder_client_data.file);
OggFLAC__stream_encoder_delete(encoder);
if(0 != output_filesize) {
struct stat filestats;
if(stat(output_filename, &filestats) != 0)
return false;
else
*output_filesize = filestats.st_size;
}
return true;
}

View File

@@ -89,10 +89,6 @@ SOURCE=.\file_utils_flac.c
# End Source File
# Begin Source File
SOURCE=.\file_utils_oggflac.c
# End Source File
# Begin Source File
SOURCE=.\metadata_utils.c
# End Source File
# End Group
@@ -105,10 +101,6 @@ SOURCE=..\..\include\test_libs_common\file_utils_flac.h
# End Source File
# Begin Source File
SOURCE=..\..\include\test_libs_common\file_utils_oggflac.h
# End Source File
# Begin Source File
SOURCE=..\..\include\test_libs_common\metadata_utils.h
# End Source File
# End Group

View File

@@ -1,4 +1,4 @@
# test_seeking - Seeking tester for libFLAC and libOggFLAC
# test_seeking - Seeking tester for libFLAC
# Copyright (C) 2004,2005,2006 Josh Coalson
#
# This program is free software; you can redistribute it and/or
@@ -23,13 +23,8 @@ AM_CFLAGS = @OGG_CFLAGS@
INCLUDES =
if FLaC__HAS_OGG
NEED_OGGFLAC_LIB = $(top_builddir)/src/libOggFLAC/libOggFLAC.la
endif
noinst_PROGRAMS = test_seeking
test_seeking_LDADD = \
$(NEED_OGGFLAC_LIB) \
$(top_builddir)/src/libFLAC/libFLAC.la \
@OGG_LIBS@ \
-lm

View File

@@ -1,4 +1,4 @@
# test_seeking - Seeking tester for libFLAC and libOggFLAC
# test_seeking - Seeking tester for libFLAC
# Copyright (C) 2004,2005,2006 Josh Coalson
#
# This program is free software; you can redistribute it and/or
@@ -27,9 +27,9 @@ PROGRAM_NAME = test_seeking
INCLUDES = -I../libFLAC/include -I$(topdir)/include
ifeq ($(DARWIN_BUILD),yes)
EXPLICIT_LIBS = $(libdir)/libOggFLAC.a $(libdir)/libFLAC.a $(OGG_LIB_DIR)/libogg.a -lm
EXPLICIT_LIBS = $(libdir)/libFLAC.a $(OGG_LIB_DIR)/libogg.a -lm
else
LIBS = -lOggFLAC -lFLAC -L$(OGG_LIB_DIR) -logg -lm
LIBS = -lFLAC -L$(OGG_LIB_DIR) -logg -lm
endif
SRCS_C = \

View File

@@ -1,4 +1,4 @@
/* test_seeking - Seeking tester for libFLAC and libOggFLAC
/* test_seeking - Seeking tester for libFLAC
* Copyright (C) 2004,2005,2006 Josh Coalson
*
* This program is free software; you can redistribute it and/or
@@ -32,9 +32,6 @@
#include <sys/stat.h> /* for stat() */
#include "FLAC/assert.h"
#include "FLAC/stream_decoder.h"
#ifdef FLAC__HAS_OGG
#include "OggFLAC/stream_decoder.h"
#endif
typedef struct {
FLAC__bool got_data;
@@ -76,26 +73,6 @@ static FLAC__bool die_s_(const char *msg, const FLAC__StreamDecoder *decoder)
return false;
}
#ifdef FLAC__HAS_OGG
static FLAC__bool die_os_(const char *msg, const OggFLAC__StreamDecoder *decoder)
{
OggFLAC__StreamDecoderState state = OggFLAC__stream_decoder_get_state(decoder);
if(msg)
printf("FAILED, %s", msg);
else
printf("FAILED");
printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__StreamDecoderStateString[state]);
if(state == OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) {
FLAC__StreamDecoderState state_ = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder);
printf(" FLAC stream decoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamDecoderStateString[state_]);
}
return false;
}
#endif
static off_t get_filesize_(const char *srcpath)
{
struct stat srcstat;
@@ -177,7 +154,7 @@ static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco
}
}
static FLAC__bool seek_barrage_native_flac(const char *filename, off_t filesize, unsigned count)
static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t filesize, unsigned count)
{
FLAC__StreamDecoder *decoder;
DecoderClientData decoder_client_data;
@@ -190,27 +167,35 @@ static FLAC__bool seek_barrage_native_flac(const char *filename, off_t filesize,
decoder_client_data.ignore_errors = false;
decoder_client_data.error_occurred = false;
printf("\n+++ seek test: FLAC__StreamDecoder\n\n");
printf("\n+++ seek test: FLAC__StreamDecoder (%s FLAC)\n\n", is_ogg? "Ogg":"native");
decoder = FLAC__stream_decoder_new();
if(0 == decoder)
return die_("FLAC__stream_decoder_new() FAILED, returned NULL\n");
if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_("FLAC__stream_decoder_init_file() FAILED", decoder);
if(is_ogg) {
if(FLAC__stream_decoder_init_ogg_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_("FLAC__stream_decoder_init_file() FAILED", decoder);
}
else {
if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_s_("FLAC__stream_decoder_init_file() FAILED", decoder);
}
if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder))
return die_s_("FLAC__stream_decoder_process_until_end_of_metadata() FAILED", decoder);
if(!is_ogg) { /* not necessary to do this for Ogg because of its seeking method */
/* process until end of stream to make sure we can still seek in that state */
decoder_client_data.quiet = true;
if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
return die_s_("FLAC__stream_decoder_process_until_end_of_stream() FAILED", decoder);
decoder_client_data.quiet = false;
decoder_client_data.quiet = true;
if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
return die_s_("FLAC__stream_decoder_process_until_end_of_stream() FAILED", decoder);
decoder_client_data.quiet = false;
printf("stream decoder state is %s\n", FLAC__stream_decoder_get_resolved_state_string(decoder));
if(FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_END_OF_STREAM)
return die_s_("expected FLAC__STREAM_DECODER_END_OF_STREAM", decoder);
printf("stream decoder state is %s\n", FLAC__stream_decoder_get_resolved_state_string(decoder));
if(FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_END_OF_STREAM)
return die_s_("expected FLAC__STREAM_DECODER_END_OF_STREAM", decoder);
}
printf("file's total_samples is %llu\n", decoder_client_data.total_samples);
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
@@ -222,6 +207,7 @@ static FLAC__bool seek_barrage_native_flac(const char *filename, off_t filesize,
n = (long int)decoder_client_data.total_samples;
/* if we don't have a total samples count, just guess based on the file size */
/* @@@ for is_ogg we should get it from last page's granulepos */
if(n == 0) {
/* 8 would imply no compression, 9 guarantees that we will get some samples off the end of the stream to test that case */
n = 9 * filesize / (decoder_client_data.channels * decoder_client_data.bits_per_sample);
@@ -295,130 +281,6 @@ static FLAC__bool seek_barrage_native_flac(const char *filename, off_t filesize,
return true;
}
#ifdef FLAC__HAS_OGG
static FLAC__bool seek_barrage_ogg_flac(const char *filename, off_t filesize, unsigned count)
{
OggFLAC__StreamDecoder *decoder;
DecoderClientData decoder_client_data;
unsigned i;
long int n;
decoder_client_data.got_data = false;
decoder_client_data.total_samples = 0;
decoder_client_data.quiet = false;
decoder_client_data.ignore_errors = false;
decoder_client_data.error_occurred = false;
printf("\n+++ seek test: OggFLAC__StreamDecoder\n\n");
decoder = OggFLAC__stream_decoder_new();
if(0 == decoder)
return die_("OggFLAC__stream_decoder_new() FAILED, returned NULL\n");
if(OggFLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return die_os_("OggFLAC__stream_decoder_init_file() FAILED", decoder);
if(!OggFLAC__stream_decoder_process_until_end_of_metadata(decoder))
return die_os_("OggFLAC__stream_decoder_process_until_end_of_metadata() FAILED", decoder);
/* process until end of stream to make sure we can still seek in that state */
#if 0
/* not necessary for the Ogg seeking method */
decoder_client_data.quiet = true;
if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder))
return die_os_("OggFLAC__stream_decoder_process_until_end_of_stream() FAILED", decoder);
decoder_client_data.quiet = false;
printf("stream decoder state is %s\n", OggFLAC__stream_decoder_get_resolved_state_string(decoder));
if(OggFLAC__stream_decoder_get_state(decoder) != OggFLAC__STREAM_DECODER_END_OF_STREAM)
return die_os_("expected OggFLAC__STREAM_DECODER_END_OF_STREAM", decoder);
#endif
printf("file's total_samples is %llu\n", decoder_client_data.total_samples);
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
if (decoder_client_data.total_samples > (FLAC__uint64)RAND_MAX) {
printf("ERROR: must be total_samples < %u\n", (unsigned)RAND_MAX);
return false;
}
#endif
n = (long int)decoder_client_data.total_samples;
/* if we don't have a total samples count, just guess based on the file size */
/* @@@ should get it from last page's granulepos */
if(n == 0) {
/* 8 would imply no compression, 9 guarantees that we will get some samples off the end of the stream to test that case */
n = 9 * filesize / (decoder_client_data.channels * decoder_client_data.bits_per_sample);
#if !defined _MSC_VER && !defined __MINGW32__
if(n > RAND_MAX)
n = RAND_MAX;
#endif
}
printf("Begin seek barrage, count=%u\n", count);
for (i = 0; !stop_signal_ && (count == 0 || i < count); i++) {
FLAC__uint64 pos;
/* for the first 10, seek to the first 10 samples */
if (n >= 10 && i < 10) {
pos = i;
}
/* for the second 10, seek to the last 10 samples */
else if (n >= 10 && i < 20) {
pos = n - 1 - (i-10);
}
/* for the third 10, seek past the end and make sure we fail properly as expected */
else if (i < 30) {
pos = n + (i-20);
}
else {
#if !defined _MSC_VER && !defined __MINGW32__
pos = (FLAC__uint64)(random() % n);
#else
/* RAND_MAX is only 32767 in my MSVC */
pos = (FLAC__uint64)((rand()<<15|rand()) % n);
#endif
}
printf("seek(%llu)... ", pos);
fflush(stdout);
if(!OggFLAC__stream_decoder_seek_absolute(decoder, pos)) {
if(pos < (FLAC__uint64)n && decoder_client_data.total_samples != 0)
return die_os_("OggFLAC__stream_decoder_seek_absolute() FAILED", decoder);
else if(decoder_client_data.total_samples == 0)
printf("seek failed, assuming it was past EOF... ");
else
printf("seek past end failed as expected... ");
if(!OggFLAC__stream_decoder_flush(decoder))
return die_os_("OggFLAC__stream_decoder_flush() FAILED", decoder);
}
else {
printf("decode_frame... ");
fflush(stdout);
if(!OggFLAC__stream_decoder_process_single(decoder))
return die_os_("OggFLAC__stream_decoder_process_single() FAILED", decoder);
printf("decode_frame... ");
fflush(stdout);
if(!OggFLAC__stream_decoder_process_single(decoder))
return die_os_("OggFLAC__stream_decoder_process_single() FAILED", decoder);
}
printf("OK\n");
fflush(stdout);
}
if(OggFLAC__stream_decoder_get_state(decoder) != OggFLAC__STREAM_DECODER_UNINITIALIZED) {
if(!OggFLAC__stream_decoder_finish(decoder))
return die_os_("OggFLAC__stream_decoder_finish() FAILED", decoder);
}
printf("\nPASSED!\n");
return true;
}
#endif
int main(int argc, char *argv[])
{
const char *filename;
@@ -466,14 +328,14 @@ int main(int argc, char *argv[])
FLAC__bool ok;
if (strlen(filename) > 4 && 0 == strcmp(filename+strlen(filename)-4, ".ogg")) {
#ifdef FLAC__HAS_OGG
ok = seek_barrage_ogg_flac(filename, filesize, count);
ok = seek_barrage(/*is_ogg=*/true, filename, filesize, count);
#else
fprintf(stderr, "ERROR: Ogg FLAC not supported\n");
ok = false;
#endif
}
else {
ok = seek_barrage_native_flac(filename, filesize, count);
ok = seek_barrage(/*is_ogg=*/false, filename, filesize, count);
}
return ok? 0 : 2;
}

View File

@@ -51,7 +51,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 ..\..\obj\release\lib\libOggFLAC_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "test_seeking - Win32 Debug"
@@ -76,7 +76,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\libOggFLAC_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF