multifix: change FLAC__stream_encoder_finish() to also return false if there is an error processing the last frame or updating metadata

This commit is contained in:
Josh Coalson
2006-11-16 01:35:13 +00:00
parent ece2f61c16
commit a7dceb9ac1
3 changed files with 25 additions and 15 deletions

View File

@@ -194,7 +194,7 @@
<li><b>Added</b> FLAC__metadata_get_cuesheet()</li> <li><b>Added</b> FLAC__metadata_get_cuesheet()</li>
<li><b>Added</b> FLAC__metadata_get_picture()</li> <li><b>Added</b> FLAC__metadata_get_picture()</li>
<li><b>Added</b> FLAC__metadata_chain_read_ogg() and FLAC__metadata_chain_read_ogg_with_callbacks()</li> <li><b>Added</b> FLAC__metadata_chain_read_ogg() and FLAC__metadata_chain_read_ogg_with_callbacks()</li>
<li><b>Changed</b> FLAC__stream_encoder_finish() now returns a FLAC__bool to signal a verify failure.</li> <li><b>Changed</b> FLAC__stream_encoder_finish() now returns a FLAC__bool to signal a verify failure, or error processing last frame or updating metadata.</li>
<li><b>Changed</b> FLAC__StreamDecoderState: removed state FLAC__STREAM_DECODER_UNPARSEABLE_STREAM</li> <li><b>Changed</b> FLAC__StreamDecoderState: removed state FLAC__STREAM_DECODER_UNPARSEABLE_STREAM</li>
<li><b>Changed</b> FLAC__StreamDecoderErrorStatus: new error code FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM</li> <li><b>Changed</b> FLAC__StreamDecoderErrorStatus: new error code FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM</li>
<li>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.</li> <li>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.</li>
@@ -211,7 +211,7 @@
<li><b>Added</b> FLAC::Metadata::get_picture()</li> <li><b>Added</b> FLAC::Metadata::get_picture()</li>
<li><b>Changed</b> FLAC::Metadata::Chain::read() to accept a flag denoting Ogg FLAC input</li> <li><b>Changed</b> FLAC::Metadata::Chain::read() to accept a flag denoting Ogg FLAC input</li>
<li><b>Changed</b> FLAC::Decoder::Stream::finish() now returns a bool to signal an MD5 failure like FLAC__stream_decoder_finish() does.</li> <li><b>Changed</b> FLAC::Decoder::Stream::finish() now returns a bool to signal an MD5 failure like FLAC__stream_decoder_finish() does.</li>
<li><b>Changed</b> FLAC::Encoder::Stream::finish() now returns a bool to signal a verify failure.</li> <li><b>Changed</b> FLAC::Encoder::Stream::finish() now returns a bool to signal a verify failure, or error processing last frame or updating metadata.</li>
</ul> </ul>
</li> </li>
<li> <li>

View File

@@ -1434,7 +1434,7 @@ FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC
* Alternatively, a dummy seek callback that just * Alternatively, a dummy seek callback that just
* returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
* may also be supplied, all though this is slightly * 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 * \param tell_callback See FLAC__StreamEncoderTellCallback. This
* pointer may be \c NULL if seeking is not * pointer may be \c NULL if seeking is not
* supported. If \a seek_callback is \c NULL then * 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 * Alternatively, a dummy tell callback that just
* returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
* may also be supplied, all though this is slightly * 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 * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
* pointer may be \c NULL if the callback is not * pointer may be \c NULL if the callback is not
* desired. If the client provides a seek callback, * 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 * Alternatively, a dummy seek callback that just
* returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED * returns \c FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
* may also be supplied, all though this is slightly * 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 * \param tell_callback See FLAC__StreamEncoderTellCallback. This
* pointer may be \c NULL if seeking is not * pointer may be \c NULL if seeking is not
* supported. If \a seek_callback is \c NULL then * 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 * Alternatively, a dummy tell callback that just
* returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED * returns \c FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
* may also be supplied, all though this is slightly * 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 * \param metadata_callback See FLAC__StreamEncoderMetadataCallback. This
* pointer may be \c NULL if the callback is not * pointer may be \c NULL if the callback is not
* desired. If the client provides a seek callback, * 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 * one or more write callbacks before returning, and will generate
* a metadata callback. * 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 * In the event of a prematurely-terminated encode, it is not strictly
* necessary to call this immediately before FLAC__stream_encoder_delete() * necessary to call this immediately before FLAC__stream_encoder_delete()
* but it is good practice to match every FLAC__stream_encoder_init_*() * 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 * \assert
* \code encoder != NULL \endcode * \code encoder != NULL \endcode
* \retval FLAC__bool * \retval FLAC__bool
* \c false if verify mode is set (see FLAC__stream_encoder_set_verify()) * \c false if an error occurred processing the last frame; or if verify
* and there was a verify mismatch (in which case the state will be * mode is set (see FLAC__stream_encoder_set_verify()), there was a
* \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR), else \c true. * 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); FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);

View File

@@ -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; FLAC__StreamEncoderState fse_state = FLAC__STREAM_ENCODER_OK;
int ret = 0; int ret = 0;
FLAC__bool verify_error = false;
if(e->encoder) { if(e->encoder) {
fse_state = FLAC__stream_encoder_get_state(e->encoder); fse_state = FLAC__stream_encoder_get_state(e->encoder);
ret = FLAC__stream_encoder_finish(e->encoder)? 0 : 1; 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
;
} }
/* all errors except verify errors should interrupt the stats */
if(e->total_samples_to_encode > 0) { if(ret && !verify_error)
print_error_with_state(e, "ERROR during encoding");
else if(e->total_samples_to_encode > 0) {
print_stats(e); print_stats(e);
flac__utils_printf(stderr, 2, "\n"); flac__utils_printf(stderr, 2, "\n");
} }
if( if(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
) {
print_verify_error(e); print_verify_error(e);
ret = 1; ret = 1;
} }