add a samples_written field to the progress callback

This commit is contained in:
Josh Coalson 2002-08-08 22:55:45 +00:00
parent bd08990c8d
commit 2ea0839abb
7 changed files with 17 additions and 14 deletions

View File

@ -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 &);

View File

@ -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);
/***********************************************************************

View File

@ -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<File *>(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);
}
};

View File

@ -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

View File

@ -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;
}

View File

@ -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)
{
}

View File

@ -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()