fix _new / _init / _finish / _delete sequence to be more correct, ala C++
This commit is contained in:
parent
8400e43eae
commit
f567b91c0f
@ -62,9 +62,6 @@ typedef struct FLAC__FileDecoderPrivate {
|
||||
FILE *file;
|
||||
char *filename; /* == NULL if stdin */
|
||||
FLAC__SeekableStreamDecoder *seekable_stream_decoder;
|
||||
struct {
|
||||
FLAC__bool md5_checking;
|
||||
} init_values_for_superclass;
|
||||
} FLAC__FileDecoderPrivate;
|
||||
|
||||
/***********************************************************************
|
||||
@ -115,6 +112,15 @@ FLAC__FileDecoder *FLAC__file_decoder_new()
|
||||
return 0;
|
||||
}
|
||||
|
||||
decoder->private_->seekable_stream_decoder = FLAC__seekable_stream_decoder_new();
|
||||
|
||||
if(0 == decoder->private_->seekable_stream_decoder) {
|
||||
free(decoder->private_);
|
||||
free(decoder->protected_);
|
||||
free(decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
decoder->protected_->state = FLAC__FILE_DECODER_UNINITIALIZED;
|
||||
|
||||
decoder->private_->filename = 0;
|
||||
@ -122,7 +128,6 @@ FLAC__FileDecoder *FLAC__file_decoder_new()
|
||||
decoder->private_->metadata_callback = 0;
|
||||
decoder->private_->error_callback = 0;
|
||||
decoder->private_->client_data = 0;
|
||||
decoder->private_->init_values_for_superclass.md5_checking = false;
|
||||
|
||||
return decoder;
|
||||
}
|
||||
@ -133,6 +138,12 @@ void FLAC__file_decoder_delete(FLAC__FileDecoder *decoder)
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
|
||||
if(decoder->private_->filename != 0)
|
||||
free(decoder->private_->filename);
|
||||
|
||||
if(decoder->private_->seekable_stream_decoder != 0)
|
||||
FLAC__seekable_stream_decoder_delete(decoder->private_->seekable_stream_decoder);
|
||||
|
||||
free(decoder->private_);
|
||||
free(decoder->protected_);
|
||||
free(decoder);
|
||||
@ -157,7 +168,6 @@ FLAC__FileDecoderState FLAC__file_decoder_init(FLAC__FileDecoder *decoder)
|
||||
return decoder->protected_->state = FLAC__FILE_DECODER_INVALID_CALLBACK;
|
||||
|
||||
decoder->private_->file = 0;
|
||||
decoder->private_->seekable_stream_decoder = 0;
|
||||
|
||||
if(0 == decoder->private_->filename)
|
||||
decoder->private_->file = get_binary_stdin_();
|
||||
@ -167,11 +177,6 @@ FLAC__FileDecoderState FLAC__file_decoder_init(FLAC__FileDecoder *decoder)
|
||||
if(decoder->private_->file == 0)
|
||||
return decoder->protected_->state = FLAC__FILE_DECODER_ERROR_OPENING_FILE;
|
||||
|
||||
decoder->private_->seekable_stream_decoder = FLAC__seekable_stream_decoder_new();
|
||||
|
||||
if(0 == decoder->private_->seekable_stream_decoder)
|
||||
return decoder->protected_->state = FLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR;
|
||||
|
||||
FLAC__seekable_stream_decoder_set_read_callback(decoder->private_->seekable_stream_decoder, read_callback_);
|
||||
FLAC__seekable_stream_decoder_set_seek_callback(decoder->private_->seekable_stream_decoder, seek_callback_);
|
||||
FLAC__seekable_stream_decoder_set_tell_callback(decoder->private_->seekable_stream_decoder, tell_callback_);
|
||||
@ -182,14 +187,6 @@ FLAC__FileDecoderState FLAC__file_decoder_init(FLAC__FileDecoder *decoder)
|
||||
FLAC__seekable_stream_decoder_set_error_callback(decoder->private_->seekable_stream_decoder, error_callback_);
|
||||
FLAC__seekable_stream_decoder_set_client_data(decoder->private_->seekable_stream_decoder, decoder);
|
||||
|
||||
/*
|
||||
* Unfortunately, because of the "_new() ... _set_() ... _init()" order of
|
||||
* decoder initialization, settings that are 'inherited' from the superclass
|
||||
* have to be passed up this way, because the superclass has not even been
|
||||
* created yet when the value is set in the subclass.
|
||||
*/
|
||||
(void)FLAC__seekable_stream_decoder_set_md5_checking(decoder->private_->seekable_stream_decoder, decoder->private_->init_values_for_superclass.md5_checking);
|
||||
|
||||
if(FLAC__seekable_stream_decoder_init(decoder->private_->seekable_stream_decoder) != FLAC__SEEKABLE_STREAM_DECODER_OK)
|
||||
return decoder->protected_->state = FLAC__FILE_DECODER_STREAM_DECODER_ERROR; /*@@@ change this to FLAC__FILE_DECODER_SEEKABLE_STREAM_ERROR in next minor-revision */
|
||||
|
||||
@ -198,23 +195,24 @@ FLAC__FileDecoderState FLAC__file_decoder_init(FLAC__FileDecoder *decoder)
|
||||
|
||||
FLAC__bool FLAC__file_decoder_finish(FLAC__FileDecoder *decoder)
|
||||
{
|
||||
FLAC__bool ok = true;
|
||||
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
|
||||
if(decoder->protected_->state == FLAC__FILE_DECODER_UNINITIALIZED)
|
||||
return true;
|
||||
|
||||
FLAC__ASSERT(decoder->private_->seekable_stream_decoder != 0);
|
||||
|
||||
if(decoder->private_->file != 0 && decoder->private_->file != stdin)
|
||||
fclose(decoder->private_->file);
|
||||
if(0 != decoder->private_->filename) {
|
||||
|
||||
if(decoder->private_->filename != 0) {
|
||||
free(decoder->private_->filename);
|
||||
decoder->private_->filename = 0;
|
||||
}
|
||||
if(decoder->private_->seekable_stream_decoder != 0) {
|
||||
ok = FLAC__seekable_stream_decoder_finish(decoder->private_->seekable_stream_decoder);
|
||||
FLAC__seekable_stream_decoder_delete(decoder->private_->seekable_stream_decoder);
|
||||
}
|
||||
|
||||
decoder->protected_->state = FLAC__FILE_DECODER_UNINITIALIZED;
|
||||
return ok;
|
||||
|
||||
return FLAC__seekable_stream_decoder_finish(decoder->private_->seekable_stream_decoder);
|
||||
}
|
||||
|
||||
FLAC__bool FLAC__file_decoder_set_md5_checking(const FLAC__FileDecoder *decoder, FLAC__bool value)
|
||||
@ -222,10 +220,10 @@ FLAC__bool FLAC__file_decoder_set_md5_checking(const FLAC__FileDecoder *decoder,
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->seekable_stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
decoder->private_->init_values_for_superclass.md5_checking = value;
|
||||
return true;
|
||||
return FLAC__seekable_stream_decoder_set_md5_checking(decoder->private_->seekable_stream_decoder, value);
|
||||
}
|
||||
|
||||
FLAC__bool FLAC__file_decoder_set_filename(const FLAC__FileDecoder *decoder, const char *value)
|
||||
@ -299,6 +297,7 @@ FLAC__bool FLAC__file_decoder_set_metadata_respond(const FLAC__FileDecoder *deco
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->seekable_stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__seekable_stream_decoder_set_metadata_respond(decoder->private_->seekable_stream_decoder, type);
|
||||
@ -309,6 +308,7 @@ FLAC__bool FLAC__file_decoder_set_metadata_respond_application(const FLAC__FileD
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->seekable_stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__seekable_stream_decoder_set_metadata_respond_application(decoder->private_->seekable_stream_decoder, id);
|
||||
@ -319,6 +319,7 @@ FLAC__bool FLAC__file_decoder_set_metadata_respond_all(const FLAC__FileDecoder *
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->seekable_stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__seekable_stream_decoder_set_metadata_respond_all(decoder->private_->seekable_stream_decoder);
|
||||
@ -329,6 +330,7 @@ FLAC__bool FLAC__file_decoder_set_metadata_ignore(const FLAC__FileDecoder *decod
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->seekable_stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__seekable_stream_decoder_set_metadata_ignore(decoder->private_->seekable_stream_decoder, type);
|
||||
@ -339,6 +341,7 @@ FLAC__bool FLAC__file_decoder_set_metadata_ignore_application(const FLAC__FileDe
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->seekable_stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__seekable_stream_decoder_set_metadata_ignore_application(decoder->private_->seekable_stream_decoder, id);
|
||||
@ -349,6 +352,7 @@ FLAC__bool FLAC__file_decoder_set_metadata_ignore_all(const FLAC__FileDecoder *d
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->seekable_stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__FILE_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder->private_->seekable_stream_decoder);
|
||||
|
@ -131,6 +131,15 @@ FLAC__SeekableStreamDecoder *FLAC__seekable_stream_decoder_new()
|
||||
return 0;
|
||||
}
|
||||
|
||||
decoder->private_->stream_decoder = FLAC__stream_decoder_new();
|
||||
|
||||
if(0 == decoder->private_->stream_decoder) {
|
||||
free(decoder->private_);
|
||||
free(decoder->protected_);
|
||||
free(decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
decoder->protected_->state = FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED;
|
||||
|
||||
decoder->private_->read_callback = 0;
|
||||
@ -152,6 +161,9 @@ void FLAC__seekable_stream_decoder_delete(FLAC__SeekableStreamDecoder *decoder)
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
|
||||
if(decoder->private_->stream_decoder != 0)
|
||||
FLAC__stream_decoder_delete(decoder->private_->stream_decoder);
|
||||
|
||||
free(decoder->private_);
|
||||
free(decoder->protected_);
|
||||
free(decoder);
|
||||
@ -178,7 +190,6 @@ FLAC__SeekableStreamDecoderState FLAC__seekable_stream_decoder_init(FLAC__Seekab
|
||||
if(0 == decoder->private_->write_callback || 0 == decoder->private_->metadata_callback || 0 == decoder->private_->error_callback)
|
||||
return decoder->protected_->state = FLAC__SEEKABLE_STREAM_DECODER_INVALID_CALLBACK;
|
||||
|
||||
decoder->private_->stream_decoder = 0;
|
||||
decoder->private_->seek_table = 0;
|
||||
|
||||
/* We initialize the MD5Context even though we may never use it. This is
|
||||
@ -189,11 +200,6 @@ FLAC__SeekableStreamDecoderState FLAC__seekable_stream_decoder_init(FLAC__Seekab
|
||||
*/
|
||||
MD5Init(&decoder->private_->md5context);
|
||||
|
||||
decoder->private_->stream_decoder = FLAC__stream_decoder_new();
|
||||
|
||||
if(0 == decoder->private_->stream_decoder)
|
||||
return decoder->protected_->state = FLAC__SEEKABLE_STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
|
||||
|
||||
FLAC__stream_decoder_set_read_callback(decoder->private_->stream_decoder, read_callback_);
|
||||
FLAC__stream_decoder_set_write_callback(decoder->private_->stream_decoder, write_callback_);
|
||||
FLAC__stream_decoder_set_metadata_callback(decoder->private_->stream_decoder, metadata_callback_);
|
||||
@ -211,21 +217,28 @@ FLAC__bool FLAC__seekable_stream_decoder_finish(FLAC__SeekableStreamDecoder *dec
|
||||
FLAC__bool md5_failed = false;
|
||||
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
|
||||
if(decoder->protected_->state == FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED)
|
||||
return true;
|
||||
|
||||
FLAC__ASSERT(decoder->private_->stream_decoder != 0);
|
||||
|
||||
/* see the comment in FLAC__seekable_stream_decoder_init() as to why we
|
||||
* always call MD5Final()
|
||||
*/
|
||||
MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
|
||||
if(decoder->private_->stream_decoder != 0) {
|
||||
FLAC__stream_decoder_finish(decoder->private_->stream_decoder);
|
||||
FLAC__stream_decoder_delete(decoder->private_->stream_decoder);
|
||||
}
|
||||
|
||||
FLAC__stream_decoder_finish(decoder->private_->stream_decoder);
|
||||
|
||||
if(decoder->protected_->md5_checking) {
|
||||
if(memcmp(decoder->private_->stored_md5sum, decoder->private_->computed_md5sum, 16))
|
||||
md5_failed = true;
|
||||
}
|
||||
|
||||
decoder->protected_->state = FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED;
|
||||
|
||||
return !md5_failed;
|
||||
}
|
||||
|
||||
@ -343,6 +356,7 @@ FLAC__bool FLAC__seekable_stream_decoder_set_metadata_respond(const FLAC__Seekab
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__stream_decoder_set_metadata_respond(decoder->private_->stream_decoder, type);
|
||||
@ -353,6 +367,7 @@ FLAC__bool FLAC__seekable_stream_decoder_set_metadata_respond_application(const
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__stream_decoder_set_metadata_respond_application(decoder->private_->stream_decoder, id);
|
||||
@ -363,6 +378,7 @@ FLAC__bool FLAC__seekable_stream_decoder_set_metadata_respond_all(const FLAC__Se
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__stream_decoder_set_metadata_respond_all(decoder->private_->stream_decoder);
|
||||
@ -373,6 +389,7 @@ FLAC__bool FLAC__seekable_stream_decoder_set_metadata_ignore(const FLAC__Seekabl
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__stream_decoder_set_metadata_ignore(decoder->private_->stream_decoder, type);
|
||||
@ -383,6 +400,7 @@ FLAC__bool FLAC__seekable_stream_decoder_set_metadata_ignore_application(const F
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__stream_decoder_set_metadata_ignore_application(decoder->private_->stream_decoder, id);
|
||||
@ -393,6 +411,7 @@ FLAC__bool FLAC__seekable_stream_decoder_set_metadata_ignore_all(const FLAC__See
|
||||
FLAC__ASSERT(decoder != 0);
|
||||
FLAC__ASSERT(decoder->private_ != 0);
|
||||
FLAC__ASSERT(decoder->protected_ != 0);
|
||||
FLAC__ASSERT(decoder->private_->stream_decoder != 0);
|
||||
if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED)
|
||||
return false;
|
||||
return FLAC__stream_decoder_set_metadata_ignore_all(decoder->private_->stream_decoder);
|
||||
|
Loading…
Reference in New Issue
Block a user