several ogg-related fixes

This commit is contained in:
Josh Coalson 2001-10-31 23:17:43 +00:00
parent c74cbef7b4
commit 89c899ef52
5 changed files with 54 additions and 40 deletions

View File

@ -21,7 +21,7 @@
PROGRAM_NAME = flac
#@@@OGG
INCLUDES = -I./include -I../../include -I$(HOME)/local/include
INCLUDES = -I./include -I../../include -I$(HOME)/local/include -DFLaC__HAS_OGG
#@@@OGG conditionalize -logg
LIBS = -lFLAC -lm -L$(HOME)/local/lib -logg

View File

@ -93,7 +93,7 @@ static void error_callback(const void *decoder, FLAC__StreamDecoderErrorStatus s
static void print_stats(const stream_info_struct *stream_info);
int flac__decode_wav(const char *infile, const char *outfile, FLAC__bool analysis_mode, analysis_options aopts, wav_decode_options_t options)
int flac__decode_wav(const char *infilename, const char *outfilename, FLAC__bool analysis_mode, analysis_options aopts, wav_decode_options_t options)
{
FLAC__bool md5_failure = false;
stream_info_struct stream_info;
@ -101,7 +101,7 @@ int flac__decode_wav(const char *infile, const char *outfile, FLAC__bool analysi
stream_info.abort_flag = false;
stream_info.analysis_mode = analysis_mode;
stream_info.aopts = aopts;
stream_info.test_only = (outfile == 0);
stream_info.test_only = (outfilename == 0);
stream_info.is_wave_out = true;
stream_info.verbose = options.common.verbose;
stream_info.skip = options.common.skip;
@ -112,18 +112,18 @@ int flac__decode_wav(const char *infile, const char *outfile, FLAC__bool analysi
stream_info.is_ogg = options.common.is_ogg;
#endif
stream_info.decoder.file = 0; /* this zeroes stream_info.decoder.stream also */
stream_info.inbasefilename = flac__file_get_basename(infile);
stream_info.inbasefilename = flac__file_get_basename(infilename);
stream_info.fout = 0; /* initialized with an open file later if necessary */
FLAC__ASSERT(!(stream_info.test_only && stream_info.analysis_mode));
if(!stream_info.test_only) {
if(0 == strcmp(outfile, "-")) {
if(0 == strcmp(outfilename, "-")) {
stream_info.fout = stdout;
}
else {
if(0 == (stream_info.fout = fopen(outfile, "wb"))) {
fprintf(stderr, "%s: ERROR: can't open output file %s\n", stream_info.inbasefilename, outfile);
if(0 == (stream_info.fout = fopen(outfilename, "wb"))) {
fprintf(stderr, "%s: ERROR: can't open output file %s\n", stream_info.inbasefilename, outfilename);
return 1;
}
}
@ -131,11 +131,11 @@ int flac__decode_wav(const char *infile, const char *outfile, FLAC__bool analysi
#ifdef FLaC__HAS_OGG
if(stream_info.is_ogg) {
if (0 == strcmp(infile, "-")) {
if (0 == strcmp(infilename, "-")) {
stream_info.fin = stdin;
} else {
if (0 == (stream_info.fin = fopen(infile, "rb"))) {
fprintf(stderr, "%s: ERROR: can't open input file %s\n", stream_info.inbasefilename, infile);
if (0 == (stream_info.fin = fopen(infilename, "rb"))) {
fprintf(stderr, "%s: ERROR: can't open input file %s\n", stream_info.inbasefilename, infilename);
if(stream_info.fout != stdout)
fclose(stream_info.fout);
return 1;
@ -147,7 +147,7 @@ int flac__decode_wav(const char *infile, const char *outfile, FLAC__bool analysi
if(analysis_mode)
flac__analyze_init(aopts);
if(!init(infile, &stream_info))
if(!init(infilename, &stream_info))
goto wav_abort_;
if(stream_info.skip > 0) {
@ -268,7 +268,7 @@ wav_abort_:
}
if(0 != stream_info.fout && stream_info.fout != stdout) {
fclose(stream_info.fout);
unlink(outfile);
unlink(outfilename);
}
#ifdef FLaC__HAS_OGG
if(stream_info.is_ogg) {
@ -281,7 +281,7 @@ wav_abort_:
return 1;
}
int flac__decode_raw(const char *infile, const char *outfile, FLAC__bool analysis_mode, analysis_options aopts, raw_decode_options_t options)
int flac__decode_raw(const char *infilename, const char *outfilename, FLAC__bool analysis_mode, analysis_options aopts, raw_decode_options_t options)
{
FLAC__bool md5_failure = false;
stream_info_struct stream_info;
@ -289,7 +289,7 @@ int flac__decode_raw(const char *infile, const char *outfile, FLAC__bool analysi
stream_info.abort_flag = false;
stream_info.analysis_mode = analysis_mode;
stream_info.aopts = aopts;
stream_info.test_only = (outfile == 0);
stream_info.test_only = (outfilename == 0);
stream_info.is_wave_out = false;
stream_info.is_big_endian = options.is_big_endian;
stream_info.is_unsigned_samples = options.is_unsigned_samples;
@ -299,21 +299,21 @@ int flac__decode_raw(const char *infile, const char *outfile, FLAC__bool analysi
stream_info.samples_processed = 0;
stream_info.frame_counter = 0;
#ifdef FLaC__HAS_OGG
stream_info.is_ogg = is_ogg;
stream_info.is_ogg = options.common.is_ogg;
#endif
stream_info.decoder.file = 0; /* this zeroes stream_info.decoder.stream also */
stream_info.inbasefilename = flac__file_get_basename(infile);
stream_info.inbasefilename = flac__file_get_basename(infilename);
stream_info.fout = 0; /* initialized with an open file later if necessary */
FLAC__ASSERT(!(stream_info.test_only && stream_info.analysis_mode));
if(!stream_info.test_only) {
if(0 == strcmp(outfile, "-")) {
if(0 == strcmp(outfilename, "-")) {
stream_info.fout = stdout;
}
else {
if(0 == (stream_info.fout = fopen(outfile, "wb"))) {
fprintf(stderr, "%s: ERROR: can't open output file %s\n", stream_info.inbasefilename, outfile);
if(0 == (stream_info.fout = fopen(outfilename, "wb"))) {
fprintf(stderr, "%s: ERROR: can't open output file %s\n", stream_info.inbasefilename, outfilename);
return 1;
}
}
@ -321,11 +321,11 @@ int flac__decode_raw(const char *infile, const char *outfile, FLAC__bool analysi
#ifdef FLaC__HAS_OGG
if(stream_info.is_ogg) {
if (0 == strcmp(infile, "-")) {
if (0 == strcmp(infilename, "-")) {
stream_info.fin = stdin;
} else {
if (0 == (stream_info.fin = fopen(infile, "rb"))) {
fprintf(stderr, "%s: ERROR: can't open input file %s\n", stream_info.inbasefilename, infile);
if (0 == (stream_info.fin = fopen(infilename, "rb"))) {
fprintf(stderr, "%s: ERROR: can't open input file %s\n", stream_info.inbasefilename, infilename);
if(stream_info.fout != stdout)
fclose(stream_info.fout);
return 1;
@ -337,7 +337,7 @@ int flac__decode_raw(const char *infile, const char *outfile, FLAC__bool analysi
if(analysis_mode)
flac__analyze_init(aopts);
if(!init(infile, &stream_info))
if(!init(infilename, &stream_info))
goto raw_abort_;
if(stream_info.skip > 0) {
@ -458,7 +458,7 @@ raw_abort_:
}
if(0 != stream_info.fout && stream_info.fout != stdout) {
fclose(stream_info.fout);
unlink(outfile);
unlink(outfilename);
}
#ifdef FLaC__HAS_OGG
if(stream_info.is_ogg) {
@ -487,7 +487,6 @@ FLAC__bool init(const char *infilename, stream_info_struct *stream_info)
}
FLAC__stream_decoder_set_read_callback(stream_info->decoder.stream, read_callback);
................................................................................
/*
* The three ugly casts here are to 'downcast' the 'void *' argument of
* the callback down to 'FLAC__StreamDecoder *'. In C++ this would be
@ -578,22 +577,22 @@ FLAC__StreamDecoderReadStatus read_callback(const FLAC__StreamDecoder *decoder,
(void)decoder; /* avoid compiler warning */
if (feof(fin))
if(feof(fin))
return FLAC__STREAM_DECODER_READ_END_OF_STREAM;
bytes_read = fread(oggbuf, 1, OGG_READ_BUFFER_SIZE, fin);
if (ferror(fin))
if(ferror(fin))
return FLAC__STREAM_DECODER_READ_ABORT;
if (ogg_sync_wrote(&stream_info->ogg.oy, bytes_read) < 0)
if(ogg_sync_wrote(&stream_info->ogg.oy, bytes_read) < 0)
return FLAC__STREAM_DECODER_READ_ABORT;
while (ogg_sync_pageout(&stream_info->ogg.oy, &og) == 1) {
if (ogg_stream_pagein(&stream_info->ogg.os, &og) == 0) {
while(ogg_sync_pageout(&stream_info->ogg.oy, &og) == 1) {
if(ogg_stream_pagein(&stream_info->ogg.os, &og) == 0) {
ogg_packet op;
while (ogg_stream_packetout(&stream_info->ogg.os, &op) == 1) {
while(ogg_stream_packetout(&stream_info->ogg.os, &op) == 1) {
memcpy(buffer + offset, op.packet, op.bytes);
*bytes += op.bytes;
offset += op.bytes;

View File

@ -41,7 +41,7 @@ typedef struct {
} raw_decode_options_t;
/* outfile == 0 => test only */
int flac__decode_wav(const char *infile, const char *outfile, FLAC__bool analysis_mode, analysis_options aopts, wav_decode_options_t options);
int flac__decode_raw(const char *infile, const char *outfile, FLAC__bool analysis_mode, analysis_options aopts, raw_decode_options_t options);
int flac__decode_wav(const char *infilename, const char *outfilename, FLAC__bool analysis_mode, analysis_options aopts, wav_decode_options_t options);
int flac__decode_raw(const char *infilename, const char *outfilename, FLAC__bool analysis_mode, analysis_options aopts, raw_decode_options_t options);
#endif

View File

@ -449,7 +449,7 @@ int flac__encode_wav(FILE *infile, long infilesize, const char *infilename, cons
FLAC__stream_encoder_finish(encoder_wrapper.encoder);
FLAC__stream_encoder_delete(encoder_wrapper.encoder);
#ifdef FLaC__HAS_OGG
if(use_ogg)
if(encoder_wrapper.use_ogg)
ogg_stream_clear(&encoder_wrapper.ogg.os);
#endif
}
@ -482,7 +482,7 @@ wav_abort_:
FLAC__stream_encoder_finish(encoder_wrapper.encoder);
FLAC__stream_encoder_delete(encoder_wrapper.encoder);
#ifdef FLaC__HAS_OGG
if(use_ogg)
if(encoder_wrapper.use_ogg)
ogg_stream_clear(&encoder_wrapper.ogg.os);
#endif
}
@ -519,7 +519,7 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
encoder_wrapper.seek_table.points = 0;
encoder_wrapper.first_seek_point_to_check = 0;
#ifdef FLaC__HAS_OGG
encoder_wrapper.use_ogg = use_ogg;
encoder_wrapper.use_ogg = options.common.use_ogg;
#endif
if(0 == strcmp(outfilename, "-")) {
@ -624,7 +624,7 @@ int flac__encode_raw(FILE *infile, long infilesize, const char *infilename, cons
FLAC__stream_encoder_finish(encoder_wrapper.encoder);
FLAC__stream_encoder_delete(encoder_wrapper.encoder);
#ifdef FLaC__HAS_OGG
if(use_ogg)
if(encoder_wrapper.use_ogg)
ogg_stream_clear(&encoder_wrapper.ogg.os);
#endif
}
@ -653,7 +653,7 @@ raw_abort_:
FLAC__stream_encoder_finish(encoder_wrapper.encoder);
FLAC__stream_encoder_delete(encoder_wrapper.encoder);
#ifdef FLaC__HAS_OGG
if(use_ogg)
if(encoder_wrapper.use_ogg)
ogg_stream_clear(&encoder_wrapper.ogg.os);
#endif
}

View File

@ -388,7 +388,7 @@ int main(int argc, char *argv[])
"%s -P %u -b %u%s -l %u%s%s%s -q %u -r %u,%u -R %u%s\n",
delete_input?" --delete-input-file":"", sector_align?" --sector-align":"",
#ifdef FLaC__HAS_OGG
ogg?" --ogg":"",
use_ogg?" --ogg":"",
#endif
lax?" --lax":"",
padding, (unsigned)blocksize, loose_mid_side?" -M":do_mid_side?" -m":"", max_lpc_order,
@ -748,6 +748,7 @@ int decode_file(const char *infilename, const char *forced_outfilename)
char outfilename[4096]; /* @@@ bad MAGIC NUMBER */
char *p;
int retval;
FLAC__bool treat_as_ogg = false;
decode_options_t common_options;
if(!test_only && !analyze) {
@ -777,9 +778,23 @@ int decode_file(const char *infilename, const char *forced_outfilename)
if(0 != cmdline_forced_outfilename)
forced_outfilename = cmdline_forced_outfilename;
if(use_ogg)
treat_as_ogg = true;
else if(0 == strcasecmp(infilename+(strlen(infilename)-4), ".ogg"))
treat_as_ogg = true;
else
treat_as_ogg = false;
#ifndef FLaC__HAS_OGG
if(treat_as_ogg) {
fprintf(stderr, "%s: Ogg support has not been built into this copy of flac\n", infilename);
return 1;
}
#endif
common_options.verbose = verbose;
#ifdef FLaC__HAS_OGG
common_options.is_ogg = is_ogg;
common_options.is_ogg = treat_as_ogg;
#endif
common_options.skip = skip;