diff --git a/doc/html/changelog.html b/doc/html/changelog.html
index e899aa4c..53d445ef 100644
--- a/doc/html/changelog.html
+++ b/doc/html/changelog.html
@@ -194,7 +194,7 @@
Added FLAC__metadata_get_cuesheet()
Added FLAC__metadata_get_picture()
Added FLAC__metadata_chain_read_ogg() and FLAC__metadata_chain_read_ogg_with_callbacks()
- Changed FLAC__stream_encoder_finish() now returns a FLAC__bool to signal a verify failure.
+ Changed FLAC__stream_encoder_finish() now returns a FLAC__bool to signal a verify failure, or error processing last frame or updating metadata.
Changed FLAC__StreamDecoderState: removed state FLAC__STREAM_DECODER_UNPARSEABLE_STREAM
Changed FLAC__StreamDecoderErrorStatus: new error code FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
The above two changes mean that when the decoder encounters what it thinks are unparseable frames from a future decoder, instead of returning a fatal error with the FLAC__STREAM_DECODER_UNPARSEABLE_STREAM state, it just calls the error callback with FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM and leaves the behavior up to the application.
@@ -211,7 +211,7 @@
Added FLAC::Metadata::get_picture()
Changed FLAC::Metadata::Chain::read() to accept a flag denoting Ogg FLAC input
Changed FLAC::Decoder::Stream::finish() now returns a bool to signal an MD5 failure like FLAC__stream_decoder_finish() does.
- Changed FLAC::Encoder::Stream::finish() now returns a bool to signal a verify failure.
+ Changed FLAC::Encoder::Stream::finish() now returns a bool to signal a verify failure, or error processing last frame or updating metadata.
diff --git a/include/FLAC/stream_encoder.h b/include/FLAC/stream_encoder.h
index f3c88843..4a8ce340 100644
--- a/include/FLAC/stream_encoder.h
+++ b/include/FLAC/stream_encoder.h
@@ -1434,7 +1434,7 @@ FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC
* Alternatively, a dummy seek callback that just
* returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
* may also be supplied, all though this is slightly
- * less efficient for the decoder.
+ * less efficient for the encoder.
* \param tell_callback See FLAC__StreamEncoderTellCallback. This
* pointer may be \c NULL if seeking is not
* supported. If \a seek_callback is \c NULL then
@@ -1444,7 +1444,7 @@ FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC
* Alternatively, a dummy tell callback that just
* returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
* may also be supplied, all though this is slightly
- * less efficient for the decoder.
+ * less efficient for the encoder.
* \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
* pointer may be \c NULL if the callback is not
* desired. If the client provides a seek callback,
@@ -1502,7 +1502,7 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St
* Alternatively, a dummy seek callback that just
* returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
* may also be supplied, all though this is slightly
- * less efficient for the decoder.
+ * less efficient for the encoder.
* \param tell_callback See FLAC__StreamEncoderTellCallback. This
* pointer may be \c NULL if seeking is not
* supported. If \a seek_callback is \c NULL then
@@ -1512,7 +1512,7 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St
* Alternatively, a dummy tell callback that just
* returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
* may also be supplied, all though this is slightly
- * less efficient for the decoder.
+ * less efficient for the encoder.
* \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
* pointer may be \c NULL if the callback is not
* desired. If the client provides a seek callback,
@@ -1675,6 +1675,10 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__
* one or more write callbacks before returning, and will generate
* a metadata callback.
*
+ * Note that in the course of processing the last frame, errors can
+ * occur, so the caller should be sure to check the return value to
+ * ensure the file was encoded properly.
+ *
* In the event of a prematurely-terminated encode, it is not strictly
* necessary to call this immediately before FLAC__stream_encoder_delete()
* but it is good practice to match every FLAC__stream_encoder_init_*()
@@ -1684,9 +1688,11 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__
* \assert
* \code encoder != NULL \endcode
* \retval FLAC__bool
- * \c false if verify mode is set (see FLAC__stream_encoder_set_verify())
- * and there was a verify mismatch (in which case the state will be
- * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR), else \c true.
+ * \c false if an error occurred processing the last frame; or if verify
+ * mode is set (see FLAC__stream_encoder_set_verify()), there was a
+ * verify mismatch; else \c true. If \c false, caller should check the
+ * state with FLAC__stream_encoder_get_state() for more information
+ * about the error.
*/
FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
diff --git a/src/flac/encode.c b/src/flac/encode.c
index ab6e82a8..d29d7028 100644
--- a/src/flac/encode.c
+++ b/src/flac/encode.c
@@ -1582,21 +1582,25 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a
{
FLAC__StreamEncoderState fse_state = FLAC__STREAM_ENCODER_OK;
int ret = 0;
+ FLAC__bool verify_error = false;
if(e->encoder) {
fse_state = FLAC__stream_encoder_get_state(e->encoder);
ret = FLAC__stream_encoder_finish(e->encoder)? 0 : 1;
+ verify_error =
+ fse_state == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA ||
+ FLAC__stream_encoder_get_state(e->encoder) == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA
+ ;
}
-
- if(e->total_samples_to_encode > 0) {
+ /* all errors except verify errors should interrupt the stats */
+ if(ret && !verify_error)
+ print_error_with_state(e, "ERROR during encoding");
+ else if(e->total_samples_to_encode > 0) {
print_stats(e);
flac__utils_printf(stderr, 2, "\n");
}
- if(
- fse_state == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA ||
- FLAC__stream_encoder_get_state(e->encoder) == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA
- ) {
+ if(verify_error) {
print_verify_error(e);
ret = 1;
}