/* flac - Command-line FLAC encoder/decoder
- * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007,2008 Josh Coalson
+ * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007,2008,2009 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
# include <config.h>
#endif
-#if defined _WIN32 && !defined __CYGWIN__
-/* where MSVC puts unlink() */
-# include <io.h>
-#else
-# include <unistd.h>
-#endif
-#if defined _MSC_VER || defined __MINGW32__
-#include <sys/types.h> /* for off_t */
-#if _MSC_VER <= 1600 /* @@@ [2G limit] */
-#define fseeko fseek
-#define ftello ftell
-#endif
-#endif
#include <errno.h>
#include <math.h> /* for floor() */
#include <stdio.h> /* for FILE etc. */
#include "FLAC/all.h"
#include "share/grabbag.h"
#include "share/replaygain_synthesis.h"
+#include "share/compat.h"
#include "decode.h"
typedef struct {
FLAC__bool abort_flag;
FLAC__bool aborting_due_to_until; /* true if we intentionally abort decoding prematurely because we hit the --until point */
FLAC__bool aborting_due_to_unparseable; /* true if we abort decoding because we hit an unparseable frame */
+ FLAC__bool error_callback_suppress_messages; /* turn on to prevent repeating messages from the error callback */
FLAC__bool iff_headers_need_fixup;
d->abort_flag = false;
d->aborting_due_to_until = false;
d->aborting_due_to_unparseable = false;
+ d->error_callback_suppress_messages = false;
d->iff_headers_need_fixup = false;
if(flac__utils_fwrite("\000", 1, 1, d->fout) != 1) {
print_error_with_state(
d,
- d->format == FORMAT_WAVE? "ERROR writing pad byte to WAVE data chunk" :
- d->format == FORMAT_WAVE64? "ERROR writing pad bytes to WAVE64 data chunk" :
- d->format == FORMAT_RF64? "ERROR writing pad byte to RF64 data chunk" :
+ d->format == FORMAT_WAVE? "ERROR writing pad byte to WAVE data chunk" :
+ d->format == FORMAT_WAVE64? "ERROR writing pad bytes to WAVE64 data chunk" :
+ d->format == FORMAT_RF64? "ERROR writing pad byte to RF64 data chunk" :
"ERROR writing pad byte to AIFF SSND chunk"
);
return false;
/* +16+8 for data chunk header (GUID and size field) */
iff_size = 16+8 + 16 + 16+8+(is_waveformatextensible?40:16) + 16+8 + foreign_metadata_size + aligned_data_size;
else /* AIFF */
- /* @@@@@@ can ssnd_offset_size be odd and hence screw up our alignment logic? */
- iff_size = 46 + foreign_metadata_size + aligned_data_size + (fm? fm->ssnd_offset_size : 0);
+ iff_size = 46 + foreign_metadata_size + aligned_data_size;
if(format != FORMAT_WAVE64 && format != FORMAT_RF64 && iff_size >= 0xFFFFFFF4) {
flac__utils_printf(stderr, 1, "%s: ERROR: stream is too big to fit in a single %s file\n", decoder_session->inbasefilename, fmt_desc);
decoder_session->fm_offset3 = ftello(f) + aligned_data_size;
}
else {
- FLAC__uint32 ssnd_offset_size = (fm? fm->ssnd_offset_size : 0);
-
if(flac__utils_fwrite("FORM", 1, 4, f) != 4)
return false;
if(flac__utils_fwrite("SSND", 1, 4, f) != 4)
return false;
- if(!write_big_endian_uint32(f, (FLAC__uint32)data_size + 8 + ssnd_offset_size)) /* data size */
+ if(!write_big_endian_uint32(f, (FLAC__uint32)data_size + 8)) /* data size */
return false;
- if(!write_big_endian_uint32(f, ssnd_offset_size))
+ if(!write_big_endian_uint32(f, 0/*offset_size*/))
return false;
if(!write_big_endian_uint32(f, 0/*block_size*/))
return false;
- if(ssnd_offset_size) {
- /* seek forward to {allocate} or {skip over already-written} SSND offset */
- if(fseeko(f, ssnd_offset_size, SEEK_CUR) < 0) {
- flac__utils_printf(stderr, 1, "%s: ERROR: allocating/skipping \"SSND\" offset\n", decoder_session->inbasefilename);
- return false;
- }
- }
-
decoder_session->fm_offset3 = ftello(f) + aligned_data_size;
}
{
DecoderSession *decoder_session = (DecoderSession*)client_data;
(void)decoder;
- flac__utils_printf(stderr, 1, "%s: *** Got error code %d:%s\n", decoder_session->inbasefilename, status, FLAC__StreamDecoderErrorStatusString[status]);
+ if(!decoder_session->error_callback_suppress_messages)
+ flac__utils_printf(stderr, 1, "%s: *** Got error code %d:%s\n", decoder_session->inbasefilename, status, FLAC__StreamDecoderErrorStatusString[status]);
if(!decoder_session->continue_through_decode_errors) {
- decoder_session->abort_flag = true;
- if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
+ /* if we got a sync error while looking for metadata, either it's not a FLAC file (more likely) or the file is corrupted */
+ if(
+ !decoder_session->error_callback_suppress_messages &&
+ status == FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC &&
+ FLAC__stream_decoder_get_state(decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA
+ ) {
+ flac__utils_printf(stderr, 1,
+ "\n"
+ "The input file is either not a FLAC file or is corrupted. If you are\n"
+ "convinced it is a FLAC file, you can rerun the same command and add the\n"
+ "-F parameter to try and recover as much as possible from the file.\n"
+ );
+ decoder_session->error_callback_suppress_messages = true;
+ }
+ else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
decoder_session->aborting_due_to_unparseable = true;
+ decoder_session->abort_flag = true;
}
}
void print_stats(const DecoderSession *decoder_session)
{
+ static int count = 0;
if(flac__utils_verbosity_ >= 2) {
#if defined _MSC_VER || defined __MINGW32__
/* with MSVC you have to spoon feed it the casting */
const double progress = (double)decoder_session->samples_processed / (double)decoder_session->total_samples * 100.0;
#endif
if(decoder_session->total_samples > 0) {
- fprintf(stderr, "\r%s: %s%u%% complete",
+ while (count > 0 && count--)
+ fprintf(stderr, "\b");
+
+ if ((unsigned)floor(progress + 0.5) == 100)
+ return;
+
+ count = fprintf(stderr, "%s: %s%u%% complete",
decoder_session->inbasefilename,
decoder_session->test_only? "testing, " : decoder_session->analysis_mode? "analyzing, " : "",
(unsigned)floor(progress + 0.5)