mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
fix up reporting of the current frame to the write callback; also fixes a problem with progress callbacks in the ogg flac file encoder
This commit is contained in:
@@ -35,6 +35,11 @@
|
||||
#include "FLAC/assert.h"
|
||||
#include "protected/file_encoder.h"
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
#define max(x,y) ((x)>(y)?(x):(y))
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* Private class method prototypes
|
||||
@@ -63,6 +68,7 @@ typedef struct FLAC__FileEncoderPrivate {
|
||||
char *filename;
|
||||
FLAC__uint64 bytes_written;
|
||||
FLAC__uint64 samples_written;
|
||||
FLAC__uint64 frames_written;
|
||||
unsigned total_frames_estimate;
|
||||
FLAC__SeekableStreamEncoder *seekable_stream_encoder;
|
||||
FILE *file;
|
||||
@@ -172,6 +178,7 @@ FLAC_API FLAC__FileEncoderState FLAC__file_encoder_init(FLAC__FileEncoder *encod
|
||||
|
||||
encoder->private_->bytes_written = 0;
|
||||
encoder->private_->samples_written = 0;
|
||||
encoder->private_->frames_written = 0;
|
||||
|
||||
FLAC__seekable_stream_encoder_set_seek_callback(encoder->private_->seekable_stream_encoder, seek_callback_);
|
||||
FLAC__seekable_stream_encoder_set_tell_callback(encoder->private_->seekable_stream_encoder, tell_callback_);
|
||||
@@ -755,8 +762,13 @@ FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__SeekableStreamEncoder
|
||||
if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, file_encoder->private_->file) == bytes) {
|
||||
file_encoder->private_->bytes_written += bytes;
|
||||
file_encoder->private_->samples_written += samples;
|
||||
/* we keep a high watermark on the number of frames written because
|
||||
* when the encoder goes back to write metadata, 'current_frame'
|
||||
* will drop back to 0.
|
||||
*/
|
||||
file_encoder->private_->frames_written = max(file_encoder->private_->frames_written, current_frame+1);
|
||||
if(0 != file_encoder->private_->progress_callback && samples > 0)
|
||||
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);
|
||||
file_encoder->private_->progress_callback(file_encoder, file_encoder->private_->bytes_written, file_encoder->private_->samples_written, file_encoder->private_->frames_written, file_encoder->private_->total_frames_estimate, file_encoder->private_->client_data);
|
||||
return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user