From 0eea34aad09373896adca6c2e3db575e0f0a8c17 Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Fri, 10 Jan 2003 05:29:17 +0000 Subject: [PATCH] big fix to allow codec and metadata interface to handle unknown metadata block types correctly --- include/FLAC++/metadata.h | 53 +++++++++++++++++++++++++++++++++++++++ include/FLAC/format.h | 11 +++++++- include/FLAC/metadata.h | 4 +++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/include/FLAC++/metadata.h b/include/FLAC++/metadata.h index ae7f0cc3..4cdd7cdf 100644 --- a/include/FLAC++/metadata.h +++ b/include/FLAC++/metadata.h @@ -693,6 +693,59 @@ namespace FLAC { bool is_legal(bool check_cd_da_subset = false, const char **violation = 0) const; }; + /** Opaque metadata block for storing unknown types. + * This should not be used unless you know what you are doing; + * it is currently used only internally to support forward + * compatibility of metadata blocks. + */ + class FLACPP_API Unknown : public Prototype { + public: + Unknown(); + // + //@{ + /** Constructs a copy of the given object. This form + * always performs a deep copy. + */ + inline Unknown(const Unknown &object): Prototype(object) { } + inline Unknown(const ::FLAC__StreamMetadata &object): Prototype(object) { } + inline Unknown(const ::FLAC__StreamMetadata *object): Prototype(object) { } + //@} + + /** Constructs an object with copy control. See + * Prototype(::FLAC__StreamMetadata *object, bool copy). + */ + inline Unknown(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { } + + ~Unknown(); + + //@{ + /** Assign from another object. Always performs a deep copy. */ + inline void operator=(const Unknown &object) { Prototype::operator=(object); } + inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); } + inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); } + //@} + + //@{ + /** Check for equality, performing a deep compare by following pointers. */ + inline bool operator==(const Unknown &object) const { return Prototype::operator==(object); } + inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); } + inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); } + //@} + + //@{ + /** Check for inequality, performing a deep compare by following pointers. */ + inline bool operator!=(const Unknown &object) const { return Prototype::operator!=(object); } + inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); } + inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); } + //@} + + const FLAC__byte *get_data() const; + + //! This form always copies \a data + bool set_data(const FLAC__byte *data, unsigned length); + bool set_data(FLAC__byte *data, unsigned length, bool copy); + }; + /* \} */ diff --git a/include/FLAC/format.h b/include/FLAC/format.h index 10803794..fdc95c18 100644 --- a/include/FLAC/format.h +++ b/include/FLAC/format.h @@ -670,12 +670,20 @@ extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */ +/** Structure that is used when a metadata block of unknown type is loaded. The contents are opaque. + */ +typedef struct { + FLAC__byte *data; +} FLAC__StreamMetadata_Unknown; + + /** FLAC metadata block structure. (c.f. format specification) */ typedef struct { FLAC__MetadataType type; /**< The type of the metadata block; used determine which member of the - * \a data union to dereference. */ + * \a data union to dereference. If type >= FLAC__METADATA_TYPE_UNDEFINED + * then \a data.unknown must be used. */ FLAC__bool is_last; /**< \c true if this metadata block is the last, else \a false */ @@ -690,6 +698,7 @@ typedef struct { FLAC__StreamMetadata_SeekTable seek_table; FLAC__StreamMetadata_VorbisComment vorbis_comment; FLAC__StreamMetadata_CueSheet cue_sheet; + FLAC__StreamMetadata_Unknown unknown; } data; /**< Polymorphic block data; use the \a type value to determine which * to use. */ diff --git a/include/FLAC/metadata.h b/include/FLAC/metadata.h index 9165962b..5afbfeb7 100644 --- a/include/FLAC/metadata.h +++ b/include/FLAC/metadata.h @@ -907,6 +907,10 @@ FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_It * with the exception of FLAC__METADATA_TYPE_VORBIS_COMMENT, which will have * the vendor string set (but zero comments). * + * Do not pass in a value greater than or equal to + * \a FLAC__METADATA_TYPE_UNDEFINED unless you really know what you're + * doing. + * * \param type Type of object to create * \retval FLAC__StreamMetadata* * \c NULL if there was an error allocating memory, else the new instance.