From 2ea0839abb392fb8c110048ebaf1456a3daf7b8b Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Thu, 8 Aug 2002 22:55:45 +0000 Subject: [PATCH] add a samples_written field to the progress callback --- include/FLAC++/encoder.h | 4 ++-- include/FLAC/file_encoder.h | 2 +- src/libFLAC++/file_encoder.cc | 8 ++++---- src/libFLAC/file_encoder.c | 5 ++++- src/libOggFLAC/stream_encoder.c | 4 ++-- src/test_libFLAC++/encoders.cc | 4 ++-- src/test_libFLAC/encoders.c | 4 ++-- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/FLAC++/encoder.h b/include/FLAC++/encoder.h index 7458a681..156f33c7 100644 --- a/include/FLAC++/encoder.h +++ b/include/FLAC++/encoder.h @@ -340,11 +340,11 @@ namespace FLAC { bool process(const FLAC__int32 * const buffer[], unsigned samples); bool process_interleaved(const FLAC__int32 buffer[], unsigned samples); protected: - virtual void progress_callback(FLAC__uint64 bytes_written, unsigned frames_written, unsigned total_frames_estimate); + virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate); ::FLAC__FileEncoder *encoder_; private: - static void progress_callback_(const ::FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data); + static void progress_callback_(const ::FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data); // Private and undefined so you can't use them: File(const Stream &); diff --git a/include/FLAC/file_encoder.h b/include/FLAC/file_encoder.h index 49295cf4..8a4a1272 100644 --- a/include/FLAC/file_encoder.h +++ b/include/FLAC/file_encoder.h @@ -151,7 +151,7 @@ typedef struct { } FLAC__FileEncoder; /*@@@ document: */ -typedef void (*FLAC__FileEncoderProgressCallback)(const FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data); +typedef void (*FLAC__FileEncoderProgressCallback)(const FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data); /*********************************************************************** diff --git a/src/libFLAC++/file_encoder.cc b/src/libFLAC++/file_encoder.cc index 1c1c55ef..eaa299c2 100644 --- a/src/libFLAC++/file_encoder.cc +++ b/src/libFLAC++/file_encoder.cc @@ -312,18 +312,18 @@ namespace FLAC { return (bool)::FLAC__file_encoder_process_interleaved(encoder_, buffer, samples); } - void File::progress_callback(FLAC__uint64 bytes_written, unsigned frames_written, unsigned total_frames_estimate) + void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate) { - (void)bytes_written, (void)frames_written, (void)total_frames_estimate; + (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate; } - void File::progress_callback_(const ::FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data) + void File::progress_callback_(const ::FLAC__FileEncoder *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(client_data); FLAC__ASSERT(0 != instance); - instance->progress_callback(bytes_written, frames_written, total_frames_estimate); + instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate); } }; diff --git a/src/libFLAC/file_encoder.c b/src/libFLAC/file_encoder.c index a9ac2faf..abf1c780 100644 --- a/src/libFLAC/file_encoder.c +++ b/src/libFLAC/file_encoder.c @@ -45,6 +45,7 @@ typedef struct FLAC__FileEncoderPrivate { void *client_data; char *filename; FLAC__uint64 bytes_written; + FLAC__uint64 samples_written; unsigned total_frames_estimate; FLAC__SeekableStreamEncoder *seekable_stream_encoder; FILE *file; @@ -156,6 +157,7 @@ FLAC__FileEncoderState FLAC__file_encoder_init(FLAC__FileEncoder *encoder) return encoder->protected_->state = FLAC__FILE_ENCODER_ERROR_OPENING_FILE; encoder->private_->bytes_written = 0; + encoder->private_->samples_written = 0; FLAC__seekable_stream_encoder_set_seek_callback(encoder->private_->seekable_stream_encoder, seek_callback_); FLAC__seekable_stream_encoder_set_write_callback(encoder->private_->seekable_stream_encoder, write_callback_); @@ -663,8 +665,9 @@ FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder if(fwrite(buffer, sizeof(FLAC__byte), bytes, file_encoder->private_->file) == bytes) { file_encoder->private_->bytes_written += bytes; + file_encoder->private_->samples_written += samples; if(0 != file_encoder->private_->progress_callback && samples > 0) - file_encoder->private_->progress_callback(file_encoder, file_encoder->private_->bytes_written, current_frame+1, file_encoder->private_->total_frames_estimate, file_encoder->private_->client_data); + file_encoder->private_->progress_callback(file_encoder, file_encoder->private_->bytes_written, file_encoder->private_->samples_written, current_frame+1, file_encoder->private_->total_frames_estimate, file_encoder->private_->client_data); return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; } else diff --git a/src/libOggFLAC/stream_encoder.c b/src/libOggFLAC/stream_encoder.c index e001ef88..6d38404e 100644 --- a/src/libOggFLAC/stream_encoder.c +++ b/src/libOggFLAC/stream_encoder.c @@ -636,10 +636,10 @@ FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *unused return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; while(ogg_stream_pageout(&encoder->private_->ogg.stream_state, &encoder->private_->ogg.page) != 0) { - if(encoder->private_->write_callback(encoder, encoder->private_->ogg.page.header, encoder->private_->ogg.page.header_len, samples, current_frame, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) + if(encoder->private_->write_callback(encoder, encoder->private_->ogg.page.header, encoder->private_->ogg.page.header_len, 0, current_frame, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - if(encoder->private_->write_callback(encoder, encoder->private_->ogg.page.body, encoder->private_->ogg.page.body_len, samples, current_frame, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) + if(encoder->private_->write_callback(encoder, encoder->private_->ogg.page.body, encoder->private_->ogg.page.body_len, 0, current_frame, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; } diff --git a/src/test_libFLAC++/encoders.cc b/src/test_libFLAC++/encoders.cc index d5826105..964bdf1b 100644 --- a/src/test_libFLAC++/encoders.cc +++ b/src/test_libFLAC++/encoders.cc @@ -778,12 +778,12 @@ public: ~FileEncoder() { } // from FLAC::Encoder::File - void progress_callback(FLAC__uint64 bytes_written, unsigned frames_written, unsigned total_frames_estimate); + void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate); bool die(const char *msg = 0) const; }; -void FileEncoder::progress_callback(FLAC__uint64, unsigned, unsigned) +void FileEncoder::progress_callback(FLAC__uint64, FLAC__uint64, unsigned, unsigned) { } diff --git a/src/test_libFLAC/encoders.c b/src/test_libFLAC/encoders.c index 7f9b75db..1115701f 100644 --- a/src/test_libFLAC/encoders.c +++ b/src/test_libFLAC/encoders.c @@ -796,9 +796,9 @@ static FLAC__bool test_seekable_stream_encoder() return true; } -static void file_encoder_progress_callback_(const FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data) +static void file_encoder_progress_callback_(const FLAC__FileEncoder *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)frames_written, (void)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_file_encoder()