Commit 7d273b4b authored by Josh Coalson's avatar Josh Coalson
Browse files

add support for read-only operations for ogg flac to chain interface

parent d037e887
......@@ -119,6 +119,7 @@
<li>
metaflac:
<ul>
<li>Added support for read-only operations on Ogg FLAC files.</li>
<li>Added a new option <span class="argument"><a href="documentation.html#metaflac_shorthand_set_tag_from_file">--set-tag-from-file</a></span> for setting a tag from file (e.g. for importing a cuesheet as a tag).</li>
<li>Added a new option <span class="argument"><a href="documentation.html#metaflac_shorthand_import_picture_from">--import-picture-from</a></span> for importing pictures.</li>
<li>Added a new option <span class="argument"><a href="documentation.html#metaflac_shorthand_export_picture_to">--export-picture-to</a></span> for exporting pictures.</li>
......@@ -191,6 +192,7 @@
<li><b>Added</b> FLAC__metadata_object_cuesheet_calculate_cddb_id()</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_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__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>
......@@ -206,6 +208,7 @@
<li><b>Added</b> FLAC::Metadata::CueSheet::calculate_cddb_id()</li>
<li><b>Added</b> FLAC::Metadata::get_cuesheet()</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::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>
</ul>
......
......@@ -1095,8 +1095,8 @@ namespace FLAC {
Status status(); ///< See FLAC__metadata_chain_status().
bool read(const char *filename); ///< See FLAC__metadata_chain_read().
bool read(FLAC__IOHandle handle, FLAC__IOCallbacks callbacks); ///< See FLAC__metadata_chain_read_with_callbacks().
bool read(const char *filename, bool is_ogg = false); ///< See FLAC__metadata_chain_read(), FLAC__metadata_chain_read_ogg().
bool read(FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, bool is_ogg = false); ///< See FLAC__metadata_chain_read_with_callbacks(), FLAC__metadata_chain_read_ogg_with_callbacks().
bool check_if_tempfile_needed(bool use_padding); ///< See FLAC__metadata_chain_check_if_tempfile_needed().
......
......@@ -584,12 +584,17 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_S
* all metadata is read into memory, operated on in memory, and then written
* to file, which is more efficient than level 1 when editing multiple blocks.
*
* Currently Ogg FLAC is supported for read only, via
* FLAC__metadata_chain_read_ogg() but a subsequent
* FLAC__metadata_chain_write() will fail.
*
* The general usage of this interface is:
*
* - Create a new chain using FLAC__metadata_chain_new(). A chain is a
* linked list of FLAC metadata blocks.
* - Read all metadata into the the chain from a FLAC file using
* FLAC__metadata_chain_read() and check the status.
* FLAC__metadata_chain_read() or FLAC__metadata_chain_read_ogg() and
* check the status.
* - Optionally, consolidate the padding using
* FLAC__metadata_chain_merge_padding() or
* FLAC__metadata_chain_sort_padding().
......@@ -611,8 +616,8 @@ FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_S
* Even though the FLAC file is not open while the chain is being
* manipulated, you must not alter the file externally during
* this time. The chain assumes the FLAC file will not change
* between the time of FLAC__metadata_chain_read() and
* FLAC__metadata_chain_write().
* between the time of FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg()
* and FLAC__metadata_chain_write().
*
* \note
* Do not modify the is_last, length, or type fields of returned
......@@ -683,11 +688,12 @@ typedef enum {
FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
/**< FLAC__metadata_chain_write() was called on a chain read by
* FLAC__metadata_chain_read_with_callbacks(), or
* FLAC__metadata_chain_write_with_callbacks() or
* FLAC__metadata_chain_write_with_callbacks_and_tempfile() was
* called on a chain read by FLAC__metadata_chain_read(). Matching
* read/write methods must always be used. */
* FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
* or
* FLAC__metadata_chain_write_with_callbacks()/FLAC__metadata_chain_write_with_callbacks_and_tempfile()
* was called on a chain read by
* FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
* Matching read/write methods must always be used. */
FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
/**< FLAC__metadata_chain_write_with_callbacks() was called when the
......@@ -751,6 +757,24 @@ FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_C
*/
FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
/*@@@@ add to unit tests*/
/** Read all metadata from an Ogg FLAC file into the chain.
*
* \note Ogg FLAC metadata data writing is not supported yet and
* FLAC__metadata_chain_write() will fail.
*
* \param chain A pointer to an existing chain.
* \param filename The path to the Ogg FLAC file to read.
* \assert
* \code chain != NULL \endcode
* \code filename != NULL \endcode
* \retval FLAC__bool
* \c true if a valid list of metadata blocks was read from
* \a filename, else \c false. On failure, check the status with
* FLAC__metadata_chain_status().
*/
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
/** Read all metadata from a FLAC stream into the chain via I/O callbacks.
*
* The \a handle need only be open for reading, but must be seekable.
......@@ -773,6 +797,32 @@ FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const
*/
FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
/*@@@@ add to unit tests*/
/** Read all metadata from an Ogg FLAC stream into the chain via I/O callbacks.
*
* The \a handle need only be open for reading, but must be seekable.
* The equivalent minimum stdio fopen() file mode is \c "r" (or \c "rb"
* for Windows).
*
* \note Ogg FLAC metadata data writing is not supported yet and
* FLAC__metadata_chain_write() will fail.
*
* \param chain A pointer to an existing chain.
* \param handle The I/O handle of the Ogg FLAC stream to read. The
* handle will NOT be closed after the metadata is read;
* that is the duty of the caller.
* \param callbacks
* A set of callbacks to use for I/O. The mandatory
* callbacks are \a read, \a seek, and \a tell.
* \assert
* \code chain != NULL \endcode
* \retval FLAC__bool
* \c true if a valid list of metadata blocks was read from
* \a handle, else \c false. On failure, check the status with
* FLAC__metadata_chain_status().
*/
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
/** Checks if writing the given chain would require the use of a
* temporary file, or if it could be written in place.
*
......@@ -833,7 +883,8 @@ FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata
* be preserved even if the FLAC file is written.
*
* For this write function to be used, the chain must have been read with
* FLAC__metadata_chain_read(), not FLAC__metadata_chain_read_with_callbacks().
* FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg(), not
* FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks().
*
* \param chain A pointer to an existing chain.
* \param use_padding See above.
......@@ -856,7 +907,8 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC
* for Windows).
*
* For this write function to be used, the chain must have been read with
* FLAC__metadata_chain_read_with_callbacks(), not FLAC__metadata_chain_read().
* FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
* not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
* Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned
* \c false.
*
......@@ -899,7 +951,8 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Cha
* truncate it on return).
*
* For this write function to be used, the chain must have been read with
* FLAC__metadata_chain_read_with_callbacks(), not FLAC__metadata_chain_read().
* FLAC__metadata_chain_read_with_callbacks()/FLAC__metadata_chain_read_ogg_with_callbacks(),
* not FLAC__metadata_chain_read()/FLAC__metadata_chain_read_ogg().
* Also, FLAC__metadata_chain_check_if_tempfile_needed() must have returned
* \c true.
*
......
......@@ -1402,17 +1402,23 @@ namespace FLAC {
return Status(::FLAC__metadata_chain_status(chain_));
}
bool Chain::read(const char *filename)
bool Chain::read(const char *filename, bool is_ogg)
{
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(is_valid());
return (bool)::FLAC__metadata_chain_read(chain_, filename);
return is_ogg?
(bool)::FLAC__metadata_chain_read_ogg(chain_, filename) :
(bool)::FLAC__metadata_chain_read(chain_, filename)
;
}
bool Chain::read(FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks)
bool Chain::read(FLAC__IOHandle handle, ::FLAC__IOCallbacks callbacks, bool is_ogg)
{
FLAC__ASSERT(is_valid());
return (bool)::FLAC__metadata_chain_read_with_callbacks(chain_, handle, callbacks);
return is_ogg?
(bool)::FLAC__metadata_chain_read_ogg_with_callbacks(chain_, handle, callbacks) :
(bool)::FLAC__metadata_chain_read_with_callbacks(chain_, handle, callbacks)
;
}
bool Chain::check_if_tempfile_needed(bool use_padding)
......
......@@ -839,6 +839,7 @@ typedef struct FLAC__Metadata_Node {
struct FLAC__Metadata_Chain {
char *filename; /* will be NULL if using callbacks */
FLAC__bool is_ogg;
FLAC__Metadata_Node *head;
FLAC__Metadata_Node *tail;
unsigned nodes;
......@@ -850,6 +851,9 @@ struct FLAC__Metadata_Chain {
* or not the whole file has to be rewritten.
*/
off_t initial_length;
/* @@@ hacky, these are currently only needed by ogg reader */
FLAC__IOHandle handle;
FLAC__IOCallback_Read read_cb;
};
struct FLAC__Metadata_Iterator {
......@@ -895,10 +899,12 @@ static void chain_init_(FLAC__Metadata_Chain *chain)
FLAC__ASSERT(0 != chain);
chain->filename = 0;
chain->is_ogg = false;
chain->head = chain->tail = 0;
chain->nodes = 0;
chain->status = FLAC__METADATA_CHAIN_STATUS_OK;
chain->initial_length = 0;
chain->read_cb = 0;
}
static void chain_clear_(FLAC__Metadata_Chain *chain)
......@@ -1188,6 +1194,95 @@ static FLAC__bool chain_read_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle han
return true;
}
FLAC__StreamDecoderReadStatus chain_read_ogg_read_cb_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
{
FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data;
(void)decoder;
if(*bytes > 0 && chain->status == FLAC__METADATA_CHAIN_STATUS_OK) {
*bytes = chain->read_cb(buffer, sizeof(FLAC__byte), *bytes, chain->handle);
if(*bytes == 0)
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
else
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
else
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
static FLAC__StreamDecoderWriteStatus chain_read_ogg_write_cb_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
{
(void)decoder, (void)frame, (void)buffer, (void)client_data;
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
static void chain_read_ogg_metadata_cb_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data;
(void)decoder;
FLAC__Metadata_Node *node = node_new_();
if(0 == node) {
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return;
}
node->data = FLAC__metadata_object_clone(metadata);
if(0 == node->data) {
node_delete_(node);
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return;
}
chain_append_node_(chain, node);
}
static void chain_read_ogg_error_cb_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
{
FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data;
(void)decoder, (void)status;
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */
}
static FLAC__bool chain_read_ogg_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb)
{
FLAC__StreamDecoder *decoder;
FLAC__ASSERT(0 != chain);
/* we assume we're already at the beginning of the file */
chain->handle = handle;
chain->read_cb = read_cb;
if(0 == (decoder = FLAC__stream_decoder_new())) {
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
FLAC__stream_decoder_set_metadata_respond_all(decoder);
if(FLAC__stream_decoder_init_ogg_stream(decoder, chain_read_ogg_read_cb_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, chain_read_ogg_write_cb_, chain_read_ogg_metadata_cb_, chain_read_ogg_error_cb_, chain) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
FLAC__stream_decoder_delete(decoder);
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */
return false;
}
chain->first_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */
if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder))
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */
if(chain->status != FLAC__METADATA_CHAIN_STATUS_OK) {
FLAC__stream_decoder_delete(decoder);
return false;
}
FLAC__stream_decoder_delete(decoder);
chain->last_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */
chain->initial_length = chain_calculate_length_(chain);
return true;
}
static FLAC__bool chain_rewrite_metadata_in_place_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, FLAC__IOCallback_Seek seek_cb)
{
FLAC__Metadata_Node *node;
......@@ -1369,7 +1464,7 @@ FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_C
return status;
}
FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename)
static FLAC__bool chain_read_(FLAC__Metadata_Chain *chain, const char *filename, FLAC__bool is_ogg)
{
FILE *file;
FLAC__bool ret;
......@@ -1384,21 +1479,38 @@ FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const
return false;
}
chain->is_ogg = is_ogg;
if(0 == (file = fopen(filename, "rb"))) {
chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE;
return false;
}
/* chain_read_cb_() sets chain->status for us */
ret = chain_read_cb_(chain, file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, ftell_wrapper_);
/* the function also sets chain->status for us */
ret = is_ogg?
chain_read_ogg_cb_(chain, file, (FLAC__IOCallback_Read)fread) :
chain_read_cb_(chain, file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, ftell_wrapper_)
;
fclose(file);
return ret;
}
FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename)
{
return chain_read_(chain, filename, /*is_ogg=*/false);
}
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename)
{
return chain_read_(chain, filename, /*is_ogg=*/true);
}
static FLAC__bool chain_read_with_callbacks_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__bool is_ogg)
{
FLAC__bool ret;
FLAC__ASSERT(0 != chain);
chain_clear_(chain);
......@@ -1408,16 +1520,31 @@ FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chai
return false;
}
chain->is_ogg = is_ogg;
/* rewind */
if(0 != callbacks.seek(handle, 0, SEEK_SET)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
return false;
}
if(!chain_read_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.tell))
return false; /* chain->status is already set by chain_read_cb_ */
/* the function also sets chain->status for us */
ret = is_ogg?
chain_read_ogg_cb_(chain, handle, callbacks.read) :
chain_read_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.tell)
;
return true;
return ret;
}
FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
{
return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/false);
}
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
{
return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/true);
}
FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding)
......@@ -1462,6 +1589,11 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC
FLAC__ASSERT(0 != chain);
if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
return false;
}
if (0 == chain->filename) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH;
return false;
......@@ -1506,6 +1638,11 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Cha
FLAC__ASSERT(0 != chain);
if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
return false;
}
if (0 != chain->filename) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH;
return false;
......@@ -1538,6 +1675,11 @@ FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC_
FLAC__ASSERT(0 != chain);
if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
return false;
}
if (0 != chain->filename) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH;
return false;
......
......@@ -72,14 +72,17 @@ struct OurMetadata {
unsigned num_blocks;
};
static const char *flacfile_ = "metadata.flac";
/* our copy of the metadata in flacfile_ */
/* our copy of the metadata in flacfilename() */
static OurMetadata our_metadata_;
/* the current block number that corresponds to the position of the iterator we are testing */
static unsigned mc_our_block_number_ = 0;
static const char *flacfilename(bool is_ogg)
{
return is_ogg? "metadata.ogg" : "metadata.flac";
}
static bool die_(const char *msg)
{
printf("ERROR: %s\n", msg);
......@@ -366,10 +369,10 @@ static bool write_chain_(FLAC::Metadata::Chain &chain, bool use_padding, bool pr
return true;
}
static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based)
static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool filename_based, bool is_ogg)
{
if(filename_based)
return chain.read(filename);
return chain.read(filename, is_ogg);
else {
::FLAC__IOCallbacks callbacks;
......@@ -383,7 +386,7 @@ static bool read_chain_(FLAC::Metadata::Chain &chain, const char *filename, bool
FILE *file = fopen(filename, "rb");
if(0 == file)
return false; /*@@@@ chain status still says OK though */
ret = chain.read((::FLAC__IOHandle)file, callbacks);
ret = chain.read((::FLAC__IOHandle)file, callbacks, is_ogg);
fclose(file);
return ret;
}
......@@ -489,13 +492,13 @@ void OurFileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status)
printf("ERROR: got error callback, status = %s (%u)\n", FLAC__StreamDecoderErrorStatusString[status], (unsigned)status);
}
static bool generate_file_(FLAC__bool include_extras)
static bool generate_file_(bool include_extras, bool is_ogg)
{
::FLAC__StreamMetadata streaminfo, vorbiscomment, *cuesheet, picture, padding;
::FLAC__StreamMetadata *metadata[4];
unsigned i = 0, n = 0;
printf("generating FLAC file for test\n");
printf("generating %sFLAC file for test\n", is_ogg? "Ogg " : "");
while(our_metadata_.num_blocks > 0)
delete_from_our_metadata_(0);
......@@ -593,7 +596,7 @@ static bool generate_file_(FLAC__bool include_extras)
)
return die_("priming our metadata");
if(!file_utils__generate_flacfile(/*is_ogg=*/false, flacfile_, 0, 512 * 1024, &streaminfo, metadata, n))
if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), 0, 512 * 1024, &streaminfo, metadata, n))
return die_("creating the encoded file");
free(vorbiscomment.data.vorbis_comment.vendor_string.entry);
......@@ -601,12 +604,11 @@ static bool generate_file_(FLAC__bool include_extras)
return true;
}
static bool test_file_(const char *filename, bool ignore_metadata)
static bool test_file_(bool is_ogg, bool ignore_metadata)
{
const char *filename = flacfilename(is_ogg);
OurFileDecoder decoder(ignore_metadata);
FLAC__ASSERT(0 != filename);
mc_our_block_number_ = 0;
decoder.error_occurred_ = false;
......@@ -618,7 +620,7 @@ static bool test_file_(const char *filename, bool ignore_metadata)
decoder.set_md5_checking(true);
decoder.set_metadata_respond_all();
if(decoder.init(filename) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) {
if((is_ogg? decoder.init_ogg(filename) : decoder.init(filename)) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) {
(void)decoder.finish();
return die_("initializing decoder\n");
}
......@@ -664,15 +666,15 @@ static bool test_level_0_()
printf("\n\n++++++ testing level 0 interface\n");
if(!generate_file_(/*include_extras=*/true))
if(!generate_file_(/*include_extras=*/true, /*is_ogg=*/false))
return false;
if(!test_file_(flacfile_, /*ignore_metadata=*/true))
if(!test_file_(/*is_ogg=*/false, /*ignore_metadata=*/true))
return false;
printf("testing FLAC::Metadata::get_streaminfo()... ");
if(!FLAC::Metadata::get_streaminfo(flacfile_, streaminfo))
if(!FLAC::Metadata::get_streaminfo(flacfilename(/*is_ogg=*/false), streaminfo))
return die_("during FLAC::Metadata::get_streaminfo()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......@@ -694,7 +696,7 @@ static bool test_level_0_()
FLAC::Metadata::VorbisComment *tags = 0;
if(!FLAC::Metadata::get_tags(flacfile_, tags))
if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
return die_("during FLAC::Metadata::get_tags()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......@@ -711,7 +713,7 @@ static bool test_level_0_()
FLAC::Metadata::VorbisComment tags;
if(!FLAC::Metadata::get_tags(flacfile_, tags))
if(!FLAC::Metadata::get_tags(flacfilename(/*is_ogg=*/false), tags))
return die_("during FLAC::Metadata::get_tags()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......@@ -726,7 +728,7 @@ static bool test_level_0_()
FLAC::Metadata::CueSheet *cuesheet = 0;
if(!FLAC::Metadata::get_cuesheet(flacfile_, cuesheet))
if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
return die_("during FLAC::Metadata::get_cuesheet()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......@@ -743,7 +745,7 @@ static bool test_level_0_()
FLAC::Metadata::CueSheet cuesheet;
if(!FLAC::Metadata::get_cuesheet(flacfile_, cuesheet))
if(!FLAC::Metadata::get_cuesheet(flacfilename(/*is_ogg=*/false), cuesheet))
return die_("during FLAC::Metadata::get_cuesheet()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......@@ -758,7 +760,7 @@ static bool test_level_0_()
FLAC::Metadata::Picture *picture = 0;
if(!FLAC::Metadata::get_picture(flacfile_, picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
return die_("during FLAC::Metadata::get_picture()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......@@ -775,7 +777,7 @@ static bool test_level_0_()
FLAC::Metadata::Picture picture;
if(!FLAC::Metadata::get_picture(flacfile_, picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
if(!FLAC::Metadata::get_picture(flacfilename(/*is_ogg=*/false), picture, /*type=*/(::FLAC__StreamMetadata_Picture_Type)(-1), /*mime_type=*/0, /*description=*/0, /*max_width=*/(unsigned)(-1), /*max_height=*/(unsigned)(-1), /*max_depth=*/(unsigned)(-1), /*max_colors=*/(unsigned)(-1)))
return die_("during FLAC::Metadata::get_picture()");
/* check to see if some basic data matches (c.f. generate_file_()) */
......@@ -785,7 +787,7 @@ static bool test_level_0_()
printf("OK\n");
}
if(!remove_file_(flacfile_))
if(!remove_file_(flacfilename(/*is_ogg=*/false)))
return false;
return true;
......@@ -809,13 +811,13 @@ static bool test_level_1_()
{
printf("simple iterator on read-only file\n");