diff options
120 files changed, 2580 insertions, 12226 deletions
@@ -69,18 +69,6 @@ Package=<4> Project_Dep_Name libFLAC++_static
End Project Dependency
Begin Project Dependency
- Project_Dep_Name libOggFLAC_dynamic
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name libOggFLAC_static
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name libOggFLAC++_dynamic
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name libOggFLAC++_static
- End Project Dependency
- Begin Project Dependency
Project_Dep_Name test_libs_common_static
End Project Dependency
Begin Project Dependency
@@ -102,12 +90,6 @@ Package=<4> Project_Dep_Name test_libFLAC++
End Project Dependency
Begin Project Dependency
- Project_Dep_Name test_libOggFLAC
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name test_libOggFLAC++
- End Project Dependency
- Begin Project Dependency
Project_Dep_Name test_seeking
End Project Dependency
Begin Project Dependency
@@ -159,12 +141,6 @@ Package=<4> Project_Dep_Name libFLAC++_static
End Project Dependency
Begin Project Dependency
- Project_Dep_Name libOggFLAC_static
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name libOggFLAC++_static
- End Project Dependency
- Begin Project Dependency
Project_Dep_Name test_libs_common_static
End Project Dependency
Begin Project Dependency
@@ -186,12 +162,6 @@ Package=<4> Project_Dep_Name test_libFLAC++
End Project Dependency
Begin Project Dependency
- Project_Dep_Name test_libOggFLAC
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name test_libOggFLAC++
- End Project Dependency
- Begin Project Dependency
Project_Dep_Name test_seeking
End Project Dependency
Begin Project Dependency
@@ -225,9 +195,6 @@ Package=<4> Project_Dep_Name libFLAC_static
End Project Dependency
Begin Project Dependency
- Project_Dep_Name libOggFLAC_static
- End Project Dependency
- Begin Project Dependency
Project_Dep_Name utf8_static
End Project Dependency
}}}
@@ -384,72 +351,6 @@ Package=<4> ###############################################################################
-Project: "libOggFLAC_dynamic"=.\src\libOggFLAC\libOggFLAC_dynamic.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name libFLAC_dynamic
- End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "libOggFLAC_static"=.\src\libOggFLAC\libOggFLAC_static.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name libFLAC_static
- End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "libOggFLAC++_dynamic"=".\src\libOggFLAC++\libOggFLAC++_dynamic.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name libOggFLAC_dynamic
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name libFLAC++_dynamic
- End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "libOggFLAC++_static"=".\src\libOggFLAC++\libOggFLAC++_static.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name libOggFLAC_static
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name libFLAC++_static
- End Project Dependency
-}}}
-
-###############################################################################
-
Project: "metaflac"=.\src\metaflac\metaflac.dsp - Package Owner=<4>
Package=<5>
@@ -536,9 +437,6 @@ Package=<4> Begin Project Dependency
Project_Dep_Name libFLAC_static
End Project Dependency
- Begin Project Dependency
- Project_Dep_Name libOggFLAC_static
- End Project Dependency
}}}
###############################################################################
@@ -579,42 +477,6 @@ Package=<4> ###############################################################################
-Project: "test_libOggFLAC"=.\src\test_libOggFLAC\test_libOggFLAC.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name libOggFLAC_static
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name test_libs_common_static
- End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "test_libOggFLAC++"=".\src\test_libOggFLAC++\test_libOggFLAC++.dsp" - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name libOggFLAC++_static
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name test_libs_common_static
- End Project Dependency
-}}}
-
-###############################################################################
-
Project: "test_seeking"=.\src\test_seeking\test_seeking.dsp - Package Owner=<4>
Package=<5>
diff --git a/Makefile.lite b/Makefile.lite index 2245bed3..5911c4a4 100644 --- a/Makefile.lite +++ b/Makefile.lite @@ -30,7 +30,7 @@ topdir = . -.PHONY: all doc src libFLAC libFLAC++ libOggFLAC libOggFLAC++ share plugin_common plugin_xmms flac metaflac test_grabbag test_libFLAC test_libFLAC++ test_libOggFLAC test_libOggFLAC++ test_seeking test_streams +.PHONY: all doc src libFLAC libFLAC++ share plugin_common plugin_xmms flac metaflac test_grabbag test_libFLAC test_libFLAC++ test_seeking test_streams all: doc src DEFAULT_CONFIG = release @@ -57,16 +57,10 @@ libFLAC: libFLAC++: libFLAC (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) -libOggFLAC: libFLAC - (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) - -libOggFLAC++: libFLAC - (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) - share: libFLAC (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) -flac: libFLAC libOggFLAC share +flac: libFLAC share (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) metaflac: libFLAC share @@ -78,7 +72,7 @@ plugin_common: libFLAC plugin_xmms: libFLAC plugin_common (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) -test_seeking: libFLAC libOggFLAC +test_seeking: libFLAC (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) test_streams: libFLAC @@ -93,12 +87,6 @@ test_libFLAC: libFLAC test_libFLAC++: libFLAC libFLAC++ (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) -test_libOggFLAC: libFLAC libOggFLAC - (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) - -test_libOggFLAC++: libFLAC libOggFLAC libOggFLAC++ - (cd src/$@ ; $(MAKE) -f Makefile.lite $(CONFIG)) - test: debug (cd test ; $(MAKE) -f Makefile.lite debug) @@ -22,17 +22,15 @@ codec developed by Josh Coalson. FLAC is comprised of * `libFLAC', a library which implements reference encoders and - decoders, and a metadata interface + decoders for native FLAC and Ogg FLAC, and a metadata interface * `libFLAC++', a C++ object wrapper library around libFLAC - * `libOggFLAC' and `libOggFLAC++', which provide encoders and - decoders for FLAC streams in an Ogg container * `flac', a command-line program for encoding and decoding files * `metaflac', a command-line program for viewing and editing FLAC metadata * player plugins for XMMS and Winamp * user and API documentation -The libraries (libFLAC, libFLAC++, libOggFLAC, and libOggFLAC++) are +The libraries (libFLAC, libFLAC++) are licensed under Xiph.org's BSD-like license (see COPYING.Xiph). All other programs and plugins are licensed under the GNU General Public License (see COPYING.GPL). The documentation is licensed under the GNU Free diff --git a/configure.in b/configure.in index 2a7d2d88..b1f04ac7 100644 --- a/configure.in +++ b/configure.in @@ -289,11 +289,6 @@ AC_CONFIG_FILES([ \ src/libFLAC/include/private/Makefile \ src/libFLAC/include/protected/Makefile \ src/libFLAC++/Makefile \ - src/libOggFLAC/Makefile \ - src/libOggFLAC/include/Makefile \ - src/libOggFLAC/include/private/Makefile \ - src/libOggFLAC/include/protected/Makefile \ - src/libOggFLAC++/Makefile \ src/flac/Makefile \ src/metaflac/Makefile \ src/monkeys_audio_utilities/Makefile \ @@ -318,15 +313,11 @@ AC_CONFIG_FILES([ \ src/test_libs_common/Makefile \ src/test_libFLAC/Makefile \ src/test_libFLAC++/Makefile \ - src/test_libOggFLAC/Makefile \ - src/test_libOggFLAC++/Makefile \ src/test_seeking/Makefile \ src/test_streams/Makefile \ include/Makefile \ include/FLAC/Makefile \ include/FLAC++/Makefile \ - include/OggFLAC/Makefile \ - include/OggFLAC++/Makefile \ include/share/Makefile \ include/share/grabbag/Makefile \ include/test_libs_common/Makefile \ diff --git a/doc/html/changelog.html b/doc/html/changelog.html index 459c06c1..3aedd127 100644 --- a/doc/html/changelog.html +++ b/doc/html/changelog.html @@ -72,7 +72,7 @@ <li><span class="commandname">flac</span> now supports FLAC as input to the encoder (i.e. can re-encode FLAC to FLAC) and preserve all the metadata like tags, etc.</li> <li>New <a href="format.html#def_PICTURE"><span class="code">PICTURE</span></a> metadata block for storing things like cover art, new <span class="argument"><a href="documentation.html#flac_options_picture">--picture</a></span> option to <span class="commandname">flac</span> and <span class="argument"><a href="documentation.html#metaflac_shorthand_import_picture">--import-picture</a></span> option to <span class="commandname">metaflac</span> for importing pictures, and metadata API <a href="api/group__flac__metadata__level0.html#ga3">additions</a> for searching for suitable pictures based on type, size and color constraints.</li> <li>Support for new <tt>REPLAYGAIN_REFERENCE_LOUDNESS</tt> tag.</li> - <li>In the developer libraries, the interface has been simplfied by merging the three decoding layers into a single class; ditto for the encoders.</li> + <li>In the developer libraries, the interface has been simplfied by merging the three decoding layers into a single class; ditto for the encoders. Also, libOggFLAC has been merged into libFLAC and libOggFLAC++ has been merged into libFLAC++ so there is a single API supporting both native FLAC and Ogg FLAC.</li> </ul> </li> <li> @@ -154,6 +154,8 @@ <li> libraries: <ul> + <li>Merged libOggFLAC into libFLAC; both formats are now supporte through the same API.</li> + <li>Merged libOggFLAC++ into libFLAC++; both formats are now supporte through the same API.</li> <li>libFLAC: Improved compression with no impact on FLAC format or decoding time by adding a windowing stage before LPC analysis.</li> <li>libFLAC: Fixed a bug in cuesheet parsing where it would return an error if the last line of the cuesheet did not end with a newline.</li> <li>libFLAC: Fixed UTF-8 decoder to disallow non-shortest-form and surrogate sequences (see <a href="http://www.unicode.org/versions/corrigendum1.html">here</a>).</li> @@ -166,6 +168,8 @@ <li> all libraries; <ul> + <li>Merged libOggFLAC into libFLAC; both formats are now supporte through the same API.</li> + <li>Merged libOggFLAC++ into libFLAC++; both formats are now supporte through the same API.</li> <li>Merged seekable stream decoder and file decoder into the stream decoder.</li> <li>Merged seekable stream encoder and file encoder into the stream encoder.</li> <li>Added #defines for the API version number to make porting easier; see <tt>include/lib*FLAC*/export.h</tt>.</li> @@ -196,19 +200,13 @@ <li> libOggFLAC: <ul> - <li><b>Added</b> OggFLAC__stream_encoder_set_apodization()</li> - <li><b>Added</b> OggFLAC__metadata_object_cuesheet_calculate_cddb_id()</li> - <li><b>Added</b> OggFLAC__metadata_get_cuesheet()</li> - <li><b>Added</b> OggFLAC__metadata_get_picture()</li> + <li>Merged into libFLAC.</li> </ul> </li> <li> libOggFLAC++: <ul> - <li><b>Added</b> OggFLAC::Encoder::Stream::set_apodization()</li> - <li><b>Added</b> OggFLAC::Metadata::CueSheet::calculate_cddb_id()</li> - <li><b>Added</b> OggFLAC::Metadata::get_cuesheet()</li> - <li><b>Added</b> OggFLAC::Metadata::get_picture()</li> + <li>Merged into libFLAC++.</li> </ul> </li> </ul> diff --git a/include/FLAC++/decoder.h b/include/FLAC++/decoder.h index cecdd2b6..49fa0feb 100644 --- a/include/FLAC++/decoder.h +++ b/include/FLAC++/decoder.h @@ -129,6 +129,7 @@ namespace FLAC { inline operator bool() const { return is_valid(); } //@} + virtual bool set_serial_number(long value); ///< See FLAC__stream_decoder_set_serial_number() virtual bool set_md5_checking(bool value); ///< See FLAC__stream_decoder_set_md5_checking() virtual bool set_metadata_respond(::FLAC__MetadataType type); ///< See FLAC__stream_decoder_set_metadata_respond() virtual bool set_metadata_respond_application(const FLAC__byte id[4]); ///< See FLAC__stream_decoder_set_metadata_respond_application() @@ -147,13 +148,8 @@ namespace FLAC { virtual unsigned get_sample_rate() const; ///< See FLAC__stream_decoder_get_sample_rate() virtual unsigned get_blocksize() const; ///< See FLAC__stream_decoder_get_blocksize() - /** Initialize the instance; as with the C interface, - * init() should be called after construction and 'set' - * calls but before any of the 'process' calls. - * - * See FLAC__stream_decoder_init_stream(). - */ - virtual ::FLAC__StreamDecoderInitStatus init(); + virtual ::FLAC__StreamDecoderInitStatus init(); ///< Seek FLAC__stream_decoder_init_stream() + virtual ::FLAC__StreamDecoderInitStatus init_ogg(); ///< Seek FLAC__stream_decoder_init_ogg_stream() virtual void finish(); ///< See FLAC__stream_decoder_finish() @@ -250,18 +246,12 @@ namespace FLAC { File(); virtual ~File(); - //@{ - /** Initialize the instance; as with the C interface, - * init() should be called after construction and 'set' - * calls but before any of the 'process' calls. - * - * See FLAC__stream_decoder_init_FILE() and - * FLAC__stream_decoder_init_file(). - */ - ::FLAC__StreamDecoderInitStatus init(FILE *file); - ::FLAC__StreamDecoderInitStatus init(const char *filename); - ::FLAC__StreamDecoderInitStatus init(const std::string &filename); - //@} + virtual ::FLAC__StreamDecoderInitStatus init(FILE *file); ///< See FLAC__stream_decoder_init_FILE() + virtual ::FLAC__StreamDecoderInitStatus init(const char *filename); ///< See FLAC__stream_decoder_init_file() + virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename); ///< See FLAC__stream_decoder_init_file() + virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file); ///< See FLAC__stream_decoder_init_ogg_FILE() + virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename); ///< See FLAC__stream_decoder_init_ogg_file() + virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename); ///< See FLAC__stream_decoder_init_ogg_file() protected: // this is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes); diff --git a/include/FLAC++/encoder.h b/include/FLAC++/encoder.h index 3db9bc1e..327cd6a3 100644 --- a/include/FLAC++/encoder.h +++ b/include/FLAC++/encoder.h @@ -56,7 +56,7 @@ * This module describes the encoder layers provided by libFLAC++. * * The libFLAC++ encoder classes are object wrappers around their - * counterparts in libFLAC. All decoding layers available in + * counterparts in libFLAC. All encoding layers available in * libFLAC are also provided here. The interface is very similar; * make sure to read the \link flac_encoder libFLAC encoder module \endlink. * @@ -132,6 +132,7 @@ namespace FLAC { inline operator bool() const { return is_valid(); } //@} + virtual bool set_serial_number(long value); ///< See FLAC__stream_encoder_set_serial_number() virtual bool set_verify(bool value); ///< See FLAC__stream_encoder_set_verify() virtual bool set_streamable_subset(bool value); ///< See FLAC__stream_encoder_set_streamable_subset() virtual bool set_do_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_do_mid_side_stereo() @@ -175,19 +176,17 @@ namespace FLAC { virtual unsigned get_rice_parameter_search_dist() const; ///< See FLAC__stream_encoder_get_rice_parameter_search_dist() virtual FLAC__uint64 get_total_samples_estimate() const; ///< See FLAC__stream_encoder_get_total_samples_estimate() - /** Initialize the instance; as with the C interface, - * init() should be called after construction and 'set' - * calls but before any of the 'process' calls. - * - * See FLAC__stream_encoder_init_stream(). - */ - virtual ::FLAC__StreamEncoderInitStatus init(); + virtual ::FLAC__StreamEncoderInitStatus init(); ///< See FLAC__stream_encoder_init_stream() + virtual ::FLAC__StreamEncoderInitStatus init_ogg(); ///< See FLAC__stream_encoder_init_ogg_stream() virtual void finish(); ///< See FLAC__stream_encoder_finish() virtual bool process(const FLAC__int32 * const buffer[], unsigned samples); ///< See FLAC__stream_encoder_process() virtual bool process_interleaved(const FLAC__int32 buffer[], unsigned samples); ///< See FLAC__stream_encoder_process_interleaved() protected: + /// See FLAC__StreamEncoderReadCallback + virtual ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes); + /// See FLAC__StreamEncoderWriteCallback virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0; @@ -209,6 +208,7 @@ namespace FLAC { ::FLAC__StreamEncoder *encoder_; + static ::FLAC__StreamEncoderReadStatus read_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); static ::FLAC__StreamEncoderSeekStatus seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); static ::FLAC__StreamEncoderTellStatus tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); @@ -256,18 +256,12 @@ namespace FLAC { File(); virtual ~File(); - //@{ - /* Initialize the instance; as with the C interface, - * init() should be called after construction and 'set' - * calls but before any of the 'process' calls. - * - * See FLAC__stream_encoder_init_FILE() and - * FLAC__stream_encoder_init_file(). - */ - ::FLAC__StreamEncoderInitStatus init(FILE *file); - ::FLAC__StreamEncoderInitStatus init(const char *filename); - ::FLAC__StreamEncoderInitStatus init(const std::string &filename); - //@} + virtual ::FLAC__StreamEncoderInitStatus init(FILE *file); ///< See FLAC__stream_encoder_init_FILE() + virtual ::FLAC__StreamEncoderInitStatus init(const char *filename); ///< See FLAC__stream_encoder_init_file() + virtual ::FLAC__StreamEncoderInitStatus init(const std::string &filename); ///< See FLAC__stream_encoder_init_file() + virtual ::FLAC__StreamEncoderInitStatus init_ogg(FILE *file); ///< See FLAC__stream_encoder_init_ogg_FILE() + virtual ::FLAC__StreamEncoderInitStatus init_ogg(const char *filename); ///< See FLAC__stream_encoder_init_ogg_file() + virtual ::FLAC__StreamEncoderInitStatus init_ogg(const std::string &filename); ///< See FLAC__stream_encoder_init_ogg_file() protected: /// See FLAC__StreamEncoderProgressCallback virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate); @@ -282,8 +276,6 @@ namespace FLAC { void operator=(const Stream &); }; - /* \} */ - } } diff --git a/include/FLAC/export.h b/include/FLAC/export.h index 5696bcc0..febed1a2 100644 --- a/include/FLAC/export.h +++ b/include/FLAC/export.h @@ -52,4 +52,7 @@ #define FLAC_API_VERSION_REVISION 0 #define FLAC_API_VERSION_AGE 0 +/** \c 1 if the library has been compiled with support for Ogg FLAC, else \c 0. */ +extern int FLAC_API_SUPPORTS_OGG_FLAC; + #endif diff --git a/include/FLAC/stream_decoder.h b/include/FLAC/stream_decoder.h index ce2b927d..06ba1b2d 100644 --- a/include/FLAC/stream_decoder.h +++ b/include/FLAC/stream_decoder.h @@ -208,6 +208,9 @@ typedef enum { FLAC__STREAM_DECODER_END_OF_STREAM, /**< The decoder has reached the end of the stream. */ + FLAC__STREAM_DECODER_OGG_ERROR, + /**< An error occurred in the underlying Ogg layer. */ + FLAC__STREAM_DECODER_SEEK_ERROR, /**< An error occurred while seeking. The decoder must be flushed * with FLAC__stream_decoder_flush() or reset with @@ -245,6 +248,11 @@ typedef enum { FLAC__STREAM_DECODER_INIT_STATUS_OK = 0, /**< Initialization was successful. */ + FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER, + /**< The library was not compiled with support for the given container + * format. + */ + FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS, /**< A required callback was not supplied. */ @@ -659,6 +667,21 @@ FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder); * ***********************************************************************/ +/** Set the serial number for the Ogg stream. + * The default behavior is to use the serial number of the first Ogg + * page. Setting a serial number here will explicitly specify which + * stream is to be decoded. + * + * \default \c use serial number of first page + * \param decoder A decoder instance to set. + * \param serial_number See above. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC_API FLAC__bool FLAC__stream_decoder_set_serial_number(FLAC__StreamDecoder *decoder, long serial_number); + /** Set the "MD5 signature checking" flag. If \c true, the decoder will * compute the MD5 signature of the unencoded audio data while decoding * and compare it to the signature from the STREAMINFO block, if it @@ -875,24 +898,28 @@ FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder * * there may still be undecoded bytes in the decoder's read FIFO. * The returned position is correct even after a seek. * + * \warning This function currently only works for native FLAC, + * not Ogg FLAC streams. + * * \param decoder A decoder instance to query. * \param position Address at which to return the desired position. * \assert * \code decoder != NULL \endcode * \code position != NULL \endcode * \retval FLAC__bool - * \c true if successful, \c false if there was an error from - * the 'tell' callback or it returned + * \c true if successful, \c false if the stream is not native FLAC, + * or there was an error from the 'tell' callback or it returned * \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED. */ FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position); -/** Initialize the decoder instance. +/** Initialize the decoder instance to decode native FLAC streams. * - * This flavor of initialization sets up the decoder to decode from a stream. - * I/O is performed via callbacks to the client. For decoding from a plain file - * via filename or open FILE*, FLAC__stream_decoder_init_file() and - * FLAC__stream_decoder_init_FILE() provide a simpler interface. + * This flavor of initialization sets up the decoder to decode from a + * native FLAC stream. I/O is performed via callbacks to the client. + * For decoding from a plain file via filename or open FILE*, + * FLAC__stream_decoder_init_file() and FLAC__stream_decoder_init_FILE() + * provide a simpler interface. * * This function should be called after FLAC__stream_decoder_new() and * FLAC__stream_decoder_set_*() but before any of the @@ -963,10 +990,91 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( void *client_data ); -/** Initialize the decoder instance. +/** Initialize the decoder instance to decode Ogg FLAC streams. * - * This flavor of initialization sets up the decoder to decode from a plain - * file. For non-stdio streams, you must use + * This flavor of initialization sets up the decoder to decode from a + * FLAC stream in an Ogg container. I/O is performed via callbacks to the + * client. For decoding from a plain file via filename or open FILE*, + * FLAC__stream_decoder_init_ogg_file() and FLAC__stream_decoder_init_ogg_FILE() + * provide a simpler interface. + * + * This function should be called after FLAC__stream_decoder_new() and + * FLAC__stream_decoder_set_*() but before any of the + * FLAC__stream_decoder_process_*() functions. Will set and return the + * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA + * if initialization succeeded. + * + * \note Support for Ogg FLAC in the library is optional. If this + * library has been built without support for Ogg FLAC, this function + * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER. + * + * \param decoder An uninitialized decoder instance. + * \param read_callback See FLAC__StreamDecoderReadCallback. This + * pointer must not be \c NULL. + * \param seek_callback See FLAC__StreamDecoderSeekCallback. This + * pointer may be \c NULL if seeking is not + * supported. If \a seek_callback is not \c NULL then a + * \a tell_callback, \a length_callback, and \a eof_callback must also be supplied. + * Alternatively, a dummy seek callback that just + * returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED + * may also be supplied, all though this is slightly + * less efficient for the decoder. + * \param tell_callback See FLAC__StreamDecoderTellCallback. This + * pointer may be \c NULL if not supported by the client. If + * \a seek_callback is not \c NULL then a + * \a tell_callback must also be supplied. + * Alternatively, a dummy tell callback that just + * returns \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED + * may also be supplied, all though this is slightly + * less efficient for the decoder. + * \param length_callback See FLAC__StreamDecoderLengthCallback. This + * pointer may be \c NULL if not supported by the client. If + * \a seek_callback is not \c NULL then a + * \a length_callback must also be supplied. + * Alternatively, a dummy length callback that just + * returns \c FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED + * may also be supplied, all though this is slightly + * less efficient for the decoder. + * \param eof_callback See FLAC__StreamDecoderEofCallback. This + * pointer may be \c NULL if not supported by the client. If + * \a seek_callback is not \c NULL then a + * \a eof_callback must also be supplied. + * Alternatively, a dummy length callback that just + * returns \c false + * may also be supplied, all though this is slightly + * less efficient for the decoder. + * \param write_callback See FLAC__StreamDecoderWriteCallback. This + * pointer must not be \c NULL. + * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This + * pointer may be \c NULL if the callback is not + * desired. + * \param error_callback See FLAC__StreamDecoderErrorCallback. This + * pointer must not be \c NULL. + * \param client_data This value will be supplied to callbacks in their + * \a client_data argument. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__StreamDecoderInitStatus + * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; + * see FLAC__StreamDecoderInitStatus for the meanings of other return values. + */ +FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream( + FLAC__StreamDecoder *decoder, + FLAC__StreamDecoderReadCallback read_callback, + FLAC__StreamDecoderSeekCallback seek_callback, + FLAC__StreamDecoderTellCallback tell_callback, + FLAC__StreamDecoderLengthCallback length_callback, + FLAC__StreamDecoderEofCallback eof_callback, + FLAC__StreamDecoderWriteCallback write_callback, + FLAC__StreamDecoderMetadataCallback metadata_callback, + FLAC__StreamDecoderErrorCallback error_callback, + void *client_data +); + +/** Initialize the decoder instance to decode native FLAC files. + * + * This flavor of initialization sets up the decoder to decode from a + * plain native FLAC file. For non-stdio streams, you must use * FLAC__stream_decoder_init_stream() and provide callbacks for the I/O. * * This function should be called after FLAC__stream_decoder_new() and @@ -1009,11 +1117,61 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE( void *client_data ); -/** Initialize the decoder instance. +/** Initialize the decoder instance to decode Ogg FLAC files. + * + * This flavor of initialization sets up the decoder to decode from a + * plain Ogg FLAC file. For non-stdio streams, you must use + * FLAC__stream_decoder_init_ogg_stream() and provide callbacks for the I/O. + * + * This function should be called after FLAC__stream_decoder_new() and + * FLAC__stream_decoder_set_*() but before any of the + * FLAC__stream_decoder_process_*() functions. Will set and return the + * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA + * if initialization succeeded. + * + * \note Support for Ogg FLAC in the library is optional. If this + * library has been built without support for Ogg FLAC, this function + * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER. + * + * \param decoder An uninitialized decoder instance. + * \param file An open FLAC file. The file should have been + * opened with mode \c "rb" and rewound. The file + * becomes owned by the decoder and should not be + * manipulated by the client while decoding. + * Unless \a file is \c stdin, it will be closed + * when FLAC__stream_decoder_finish() is called. + * Note however that seeking will not work when + * decoding from \c stdout since it is not seekable. + * \param write_callback See FLAC__StreamDecoderWriteCallback. This + * pointer must not be \c NULL. + * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This + * pointer may be \c NULL if the callback is not + * desired. + * \param error_callback See FLAC__StreamDecoderErrorCallback. This + * pointer must not be \c NULL. + * \param client_data This value will be supplied to callbacks in their + * \a client_data argument. + * \assert + * \code decoder != NULL \endcode + * \code file != NULL \endcode + * \retval FLAC__StreamDecoderInitStatus + * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; + * see FLAC__StreamDecoderInitStatus for the meanings of other return values. + */ +FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE( + FLAC__StreamDecoder *decoder, + FILE *file, + FLAC__StreamDecoderWriteCallback write_callback, + FLAC__StreamDecoderMetadataCallback metadata_callback, + FLAC__StreamDecoderErrorCallback error_callback, + void *client_data +); + +/** Initialize the decoder instance to decode native FLAC files. * * This flavor of initialization sets up the decoder to decode from a plain - * file. If POSIX fopen() semantics are not sufficient, (for example, with - * Unicode filenames on Windows), you must use + * native FLAC file. If POSIX fopen() semantics are not sufficient, (for + * example, with Unicode filenames on Windows), you must use * FLAC__stream_decoder_init_FILE(), or FLAC__stream_decoder_init_stream() * and provide callbacks for the I/O. * @@ -1051,6 +1209,52 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file( void *client_data ); +/** Initialize the decoder instance to decode Ogg FLAC files. + * + * This flavor of initialization sets up the decoder to decode from a plain + * Ogg FLAC file. If POSIX fopen() semantics are not sufficient, (for + * example, with Unicode filenames on Windows), you must use + * FLAC__stream_decoder_init_ogg_FILE(), or FLAC__stream_decoder_init_ogg_stream() + * and provide callbacks for the I/O. + * + * This function should be called after FLAC__stream_decoder_new() and + * FLAC__stream_decoder_set_*() but before any of the + * FLAC__stream_decoder_process_*() functions. Will set and return the + * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA + * if initialization succeeded. + * + * \note Support for Ogg FLAC in the library is optional. If this + * library has been built without support for Ogg FLAC, this function + * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER. + * + * \param decoder An uninitialized decoder instance. + * \param filename The name of the file to decode from. The file will + * be opened with fopen(). Use \c NULL to decode from + * \c stdin. Note that \c stdin is not seekable. + * \param write_callback See FLAC__StreamDecoderWriteCallback. This + * pointer must not be \c NULL. + * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This + * pointer may be \c NULL if the callback is not + * desired. + * \param error_callback See FLAC__StreamDecoderErrorCallback. This + * pointer must not be \c NULL. + * \param client_data This value will be supplied to callbacks in their + * \a client_data argument. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__StreamDecoderInitStatus + * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; + * see FLAC__StreamDecoderInitStatus for the meanings of other return values. + */ +FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file( + FLAC__StreamDecoder *decoder, + const char *filename, + FLAC__StreamDecoderWriteCallback write_callback, + FLAC__StreamDecoderMetadataCallback metadata_callback, + FLAC__StreamDecoderErrorCallback error_callback, + void *client_data +); + /** Finish the decoding process. * Flushes the decoding buffer, releases resources, resets the decoder * settings to their defaults, and returns the decoder state to diff --git a/include/FLAC/stream_encoder.h b/include/FLAC/stream_encoder.h index 97704797..85a2b46d 100644 --- a/include/FLAC/stream_encoder.h +++ b/include/FLAC/stream_encoder.h @@ -219,6 +219,9 @@ typedef enum { * can be processed. */ + FLAC__STREAM_ENCODER_OGG_ERROR, + /**< An error occurred in the underlying Ogg layer. */ + FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR, /**< An error occurred in the underlying verify stream decoder; * check FLAC__stream_encoder_get_verify_decoder_state(). @@ -254,6 +257,7 @@ typedef enum { */ extern FLAC_API const char * const FLAC__StreamEncoderStateString[]; + /** Possible return values for the FLAC__stream_encoder_init_*() functions. */ typedef enum { @@ -264,6 +268,11 @@ typedef enum { FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR, /**< General failure to set up encoder; call FLAC__stream_encoder_get_state() for cause. */ + FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER, + /**< The library was not compiled with support for the given container + * format. + */ + FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS, /**< A required callback was not supplied. */ @@ -324,6 +333,33 @@ typedef enum { */ extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[]; + +/** Return values for the FLAC__StreamEncoder read callback. + */ +typedef enum { + + FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE, + /**< The read was OK and decoding can continue. */ + + FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM, + /**< The read was attempted at the end of the stream. */ + + FLAC__STREAM_ENCODER_READ_STATUS_ABORT, + /**< An unrecoverable error occurred. */ + + FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED + /**< Client does not support reading back from the output. */ + +} FLAC__StreamEncoderReadStatus; + +/** Maps a FLAC__StreamEncoderReadStatus to a C string. + * + * Using a FLAC__StreamEncoderReadStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[]; + + /** Return values for the FLAC__StreamEncoder write callback. */ typedef enum { @@ -343,6 +379,7 @@ typedef enum { */ extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[]; + /** Return values for the FLAC__StreamEncoder seek callback. */ typedef enum { @@ -406,6 +443,38 @@ typedef struct { struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */ } FLAC__StreamEncoder; +/** Signature for the read callback. + * + * A function pointer matching this signature must be passed to + * FLAC__stream_encoder_init_ogg_stream() if seeking is supported. + * The supplied function will be called when the encoder needs to read back + * encoded data. This happens during the metadata callback, when the encoder + * has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered + * while encoding. The address of the buffer to be filled is supplied, along + * with the number of bytes the buffer can hold. The callback may choose to + * supply less data and modify the byte count but must be careful not to + * overflow the buffer. The callback then returns a status code chosen from + * FLAC__StreamEncoderReadStatus. + * + * \note In general, FLAC__StreamEncoder functions which change the + * state should not be called on the \a encoder while in the callback. + * + * \param encoder The encoder instance calling the callback. + * \param buffer A pointer to a location for the callee to store + * data to be encoded. + * \param bytes A pointer to the size of the buffer. On entry + * to the callback, it contains the maximum number + * of bytes that may be stored in \a buffer. The + * callee must set it to the actual number of bytes + * stored (0 in case of error or end-of-stream) before + * returning. + * \param client_data The callee's client data set through + * FLAC__stream_encoder_set_client_data(). + * \retval FLAC__StreamEncoderReadStatus + * The callee's return status. + */ +typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); + /** Signature for the write callback. * * A function pointer matching this signature must be passed to @@ -421,6 +490,13 @@ typedef struct { * number that is being written; otherwise it indicates that the write * callback is being called to write metadata. * + * \note + * Unlike when writing to native FLAC, when writing to Ogg FLAC the + * write callback will be called twice when writing each audio + * frame; once for the page header, and once for the page body. + * When writing the page header, the \a samples argument to the + * write callback will be \c 0. + * * \note In general, FLAC__StreamEncoder functions which change the * state should not be called on the \a encoder while in the callback. * @@ -558,6 +634,25 @@ FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder); * ***********************************************************************/ +/** Set the serial number for the FLAC stream to use in the Ogg container. + * + * \note + * This does not need to be set for native FLAC encoding. + * + * \note + * It is recommended to set a serial number explicitly as the default of '0' + * may collide with other streams. + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param serial_number See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC_API FLAC__bool FLAC__stream_encoder_set_serial_number(FLAC__StreamEncoder *encoder, long serial_number); + /** Set the "verify" flag. If \c true, the encoder will verify it's own * encoded output by feeding it through an internal decoder and comparing * the original signal against the decoded signal. If a mismatch occurs, @@ -919,6 +1014,19 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__Stream * block is present in the \a metadata array, libFLAC will write an * empty one, containing only the vendor string. * + * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be + * the second metadata block of the stream. The encoder already supplies + * the STREAMINFO block automatically. If \a metadata does not contain a + * VORBIS_COMMENT block, the encoder will supply that too. Otherwise, if + * \a metadata does contain a VORBIS_COMMENT block and it is not the + * first, this function will reorder \a metadata by moving the + * VORBIS_COMMENT block to the front; the relative ordering of the other + * blocks will remain as they were. + * + * \note The Ogg FLAC mapping limits the number of metadata blocks per + * stream to \c 65535. If \a num_blocks exceeds this the function will + * return \c false. + * * \default \c NULL, 0 * \param encoder An encoder instance to set. * \param metadata See above. @@ -927,6 +1035,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__Stream * \code encoder != NULL \endcode * \retval FLAC__bool * \c false if the encoder is already initialized, else \c true. + * \c false if the encoder is already initialized, or if + * \a num_blocks > 65535 if encoding to Ogg FLAC, else \c true. */ FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks); @@ -1157,12 +1267,13 @@ FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC */ FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder); -/** Initialize the encoder instance. +/** Initialize the encoder instance to encode native FLAC streams. * - * This flavor of initialization sets up the encoder to encode to a stream. - * I/O is performed via callbacks to the client. For encoding to a plain file - * via filename or open \c FILE*, FLAC__stream_encoder_init_file() and - * FLAC__stream_encoder_init_FILE() provide a simpler interface. + * This flavor of initialization sets up the encoder to encode to a + * native FLAC stream. I/O is performed via callbacks to the client. + * For encoding to a plain file via filename or open \c FILE*, + * FLAC__stream_encoder_init_file() and FLAC__stream_encoder_init_FILE() + * provide a simpler interface. * * This function should be called after FLAC__stream_encoder_new() and * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() @@ -1219,20 +1330,84 @@ FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC */ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data); -/** Initialize the encoder instance. +/** Initialize the encoder instance to encode Ogg FLAC streams. * - * This flavor of initialization sets up the encoder to encode to a plain - * file. For non-stdio streams, you must use - * FLAC__stream_encoder_init_stream() and provide callbacks for the I/O. + * This flavor of initialization sets up the encoder to encode to a FLAC + * stream in an Ogg container. I/O is performed via callbacks to the + * client. For encoding to a plain file via filename or open \c FILE*, + * FLAC__stream_encoder_init_ogg_file() and FLAC__stream_encoder_init_ogg_FILE() + * provide a simpler interface. * * This function should be called after FLAC__stream_encoder_new() and * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() * or FLAC__stream_encoder_process_interleaved(). * initialization succeeded. * - * The call to FLAC__stream_encoder_init_stream() currently will also immediately - * call the write callback several times, once with the \c fLaC signature, - * and once for each encoded metadata block. + * The call to FLAC__stream_encoder_init_ogg_stream() currently will + * also immediately call the write callback several times, once with + * the \c fLaC signature, and once for each encoded metadata block.@@@@@@ + * + * \param encoder An uninitialized encoder instance. + * \param read_callback See FLAC__StreamEncoderReadCallback. This + * pointer must not be \c NULL if \a seek_callback + * is non-NULL since they are both needed to be + * able to write data back to the Ogg FLAC stream + * in the post-encode phase. + * \param write_callback See FLAC__StreamEncoderWriteCallback. This + * pointer must not be \c NULL. + * \param seek_callback See FLAC__StreamEncoderSeekCallback. This + * pointer may be \c NULL if seeking is not + * supported. The encoder uses seeking to go back + * and write some some stream statistics to the + * STREAMINFO block; this is recommended but not + * necessary to create a valid FLAC stream. If + * \a seek_callback is not \c NULL then a + * \a tell_callback must also be supplied. + * 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. + * \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 + * this argument will be ignored. If + * \a seek_callback is not \c NULL then a + * \a tell_callback must also be supplied. + * 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. + * \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, + * this function is not necessary as the encoder + * will automatically seek back and update the + * STREAMINFO block. It may also be \c NULL if the + * client does not support seeking, since it will + * have no way of going back to update the + * STREAMINFO. However the client can still supply + * a callback if it would like to know the details + * from the STREAMINFO. + * \param client_data This value will be supplied to callbacks in their + * \a client_data argument. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__StreamEncoderInitStatus + * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; + * see FLAC__StreamEncoderInitStatus for the meanings of other return values. + */ +FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data); + +/** Initialize the encoder instance to encode native FLAC files. + * + * This flavor of initialization sets up the encoder to encode to a + * plain native FLAC file. For non-stdio streams, you must use + * FLAC__stream_encoder_init_stream() and provide callbacks for the I/O. + * + * This function should be called after FLAC__stream_encoder_new() and + * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() + * or FLAC__stream_encoder_process_interleaved(). + * initialization succeeded. * * \param encoder An uninitialized encoder instance. * \param file An open file. The file should have been opened @@ -1258,12 +1433,47 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St */ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); -/** Initialize the encoder instance. +/** Initialize the encoder instance to encode Ogg FLAC files. + * + * This flavor of initialization sets up the encoder to encode to a + * plain Ogg FLAC file. For non-stdio streams, you must use + * FLAC__stream_encoder_init_ogg_stream() and provide callbacks for the I/O. + * + * This function should be called after FLAC__stream_encoder_new() and + * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() + * or FLAC__stream_encoder_process_interleaved(). + * initialization succeeded. + * + * \param encoder An uninitialized encoder instance. + * \param file An open file. The file should have been opened + * with mode \c "w+b" and rewound. The file + * becomes owned by the encoder and should not be + * manipulated by the client while encoding. + * Unless \a file is \c stdout, it will be closed + * when FLAC__stream_encoder_finish() is called. + * Note however that a proper SEEKTABLE cannot be + * created when encoding to \c stdout since it is + * not seekable. + * \param progress_callback See FLAC__StreamEncoderProgressCallback. This + * pointer may be \c NULL if the callback is not + * desired. + * \param client_data This value will be supplied to callbacks in their + * \a client_data argument. + * \assert + * \code encoder != NULL \endcode + * \code file != NULL \endcode + * \retval FLAC__StreamEncoderInitStatus + * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; + * see FLAC__StreamEncoderInitStatus for the meanings of other return values. + */ +FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); + +/** Initialize the encoder instance to encode native FLAC files. * * This flavor of initialization sets up the encoder to encode to a plain - * file. If POSIX fopen() semantics are not sufficient (for example, + * FLAC file. If POSIX fopen() semantics are not sufficient (for example, * with Unicode filenames on Windows), you must use - * FLAC__stream_encodeR_init_FILE(), or FLAC__stream_encoder_init_stream() + * FLAC__stream_encoder_init_FILE(), or FLAC__stream_encoder_init_stream() * and provide callbacks for the I/O. * * This function should be called after FLAC__stream_encoder_new() and @@ -1271,10 +1481,6 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__Stre * or FLAC__stream_encoder_process_interleaved(). * initialization succeeded. * - * The call to FLAC__stream_encoder_init_stream() currently will also immediately - * call the write callback several times, once with the \c fLaC signature, - * and once for each encoded metadata block. - * * \param encoder An uninitialized encoder instance. * \param filename The name of the file to encode to. The file will * be opened with fopen(). Use \c NULL to encode to @@ -1294,6 +1500,38 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__Stre */ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); +/** Initialize the encoder instance to encode Ogg FLAC files. + * + * This flavor of initialization sets up the encoder to encode to a plain + * Ogg FLAC file. If POSIX fopen() semantics are not sufficient (for example, + * with Unicode filenames on Windows), you must use + * FLAC__stream_encoder_init_ogg_FILE(), or FLAC__stream_encoder_init_ogg_stream() + * and provide callbacks for the I/O. + * + * This function should be called after FLAC__stream_encoder_new() and + * FLAC__stream_encoder_set_*() but before FLAC__stream_encoder_process() + * or FLAC__stream_encoder_process_interleaved(). + * initialization succeeded. + * + * \param encoder An uninitialized encoder instance. + * \param filename The name of the file to encode to. The file will + * be opened with fopen(). Use \c NULL to encode to + * \c stdout. Note however that a proper SEEKTABLE + * cannot be created when encoding to \c stdout since + * it is not seekable. + * \param progress_callback See FLAC__StreamEncoderProgressCallback. This + * pointer may be \c NULL if the callback is not + * desired. + * \param client_data This value will be supplied to callbacks in their + * \a client_data argument. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__StreamEncoderInitStatus + * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; + * see FLAC__StreamEncoderInitStatus for the meanings of other return values. + */ +FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); + /** Finish the encoding process. * Flushes the encoding buffer, releases resources, resets the encoder * settings to their defaults, and returns the encoder state to diff --git a/include/Makefile.am b/include/Makefile.am index 31b7e5fe..aeddca55 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -15,8 +15,4 @@ # restrictive of those mentioned above. See the file COPYING.Xiph in this # distribution. -if FLaC__HAS_OGG -OGGFLAC_DIRS = OggFLAC OggFLAC++ -endif - -SUBDIRS = FLAC FLAC++ $(OGGFLAC_DIRS) share test_libs_common +SUBDIRS = FLAC FLAC++ share test_libs_common diff --git a/include/OggFLAC++/Makefile.am b/include/OggFLAC++/Makefile.am deleted file mode 100644 index 39cfd091..00000000 --- a/include/OggFLAC++/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -# libOggFLAC++ - Free Lossless Audio Codec + Ogg library -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# - Neither the name of the Xiph.org Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -oggflaccppincludedir = $(includedir)/OggFLAC++ - -oggflaccppinclude_HEADERS = \ - all.h \ - decoder.h \ - encoder.h \ - export.h diff --git a/include/OggFLAC++/all.h b/include/OggFLAC++/all.h deleted file mode 100644 index d1101d26..00000000 --- a/include/OggFLAC++/all.h +++ /dev/null @@ -1,47 +0,0 @@ -/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLACPP__ALL_H -#define OggFLACPP__ALL_H - -#include "export.h" - -#include "encoder.h" -#include "decoder.h" - -/** \defgroup oggflacpp OggFLAC C++ API - * - * The OggFLAC C++ API is the interface to libOggFLAC++, a set of classes - * that encapsulate the encoders and decoders in libOggFLAC. - * - */ - -#endif diff --git a/include/OggFLAC++/decoder.h b/include/OggFLAC++/decoder.h deleted file mode 100644 index e882e297..00000000 --- a/include/OggFLAC++/decoder.h +++ /dev/null @@ -1,267 +0,0 @@ -/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLACPP__DECODER_H -#define OggFLACPP__DECODER_H - -#include "export.h" - -#include "OggFLAC/stream_decoder.h" -// we only need this for the state abstraction really... -#include "FLAC++/decoder.h" - - -/** \file include/OggFLAC++/decoder.h - * - * \brief - * This module contains the classes which implement the various - * decoders. - * - * See the detailed documentation in the - * \link oggflacpp_decoder decoder \endlink module. - */ - -/** \defgroup oggflacpp_decoder OggFLAC++/decoder.h: decoder classes - * \ingroup oggflacpp - * - * \brief - * This module describes the decoder layers provided by libOggFLAC++. - * - * The libOggFLAC++ decoder classes are object wrappers around their - * counterparts in libOggFLAC. All decoding layers available in - * libOggFLAC are also provided here. The interface is very similar; - * make sure to read the \link oggflac_decoder libOggFLAC decoder module \endlink. - * - * There are only two significant differences here. First, instead of - * passing in C function pointers for callbacks, you inherit from the - * decoder class and provide implementations for the callbacks in your - * derived class; because of this there is no need for a 'client_data' - * property. - * - * Second, there are two stream decoder classes. OggFLAC::Decoder::Stream - * is used for the same cases that OggFLAC__stream_decoder_init_stream() is - * used, and OggFLAC::Decoder::File is used for the same cases that - * OggFLAC__stream_decoder_init_FILE() and OggFLAC__stream_decoder_init_file() - * are used. - * - * Note that OggFLAC::Decoder::Stream inherits from FLAC::Decoder::Stream so - * it is possible to support both FLAC and Ogg FLAC decoding with only a - * little specialized code (just up to initialization). For example, - * \code - * class MyFLACDecoder: public FLAC::Decoder::Stream - * { - * // implement callbacks - * }; - * FLAC::Decoder::Stream *flac = new MyFLACDecoder(); - * if(*flac) { - * flac->set_...(); - * // continue set_ calls() - * if(flac->init() == ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - * my_process_stream(flac); - * } - * - * ... - * - * class MyOggFLACDecoder: public OggFLAC::Decoder::Stream - * { - * // implement callbacks - * }; - * FLAC::Decoder::Stream *oggflac = new MyOggFLACDecoder(); - * if(*oggflac) { - * oggflac->set_serial_number(); - * // continue set_ calls() - * if(oggflac->init() == ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - * my_process_stream(oggflac); - * } - * \endcode - */ - -namespace OggFLAC { - namespace Decoder { - - /** \defgroup oggflacpp_stream_decoder OggFLAC++/decoder.h: stream decoder class - * \ingroup oggflacpp_decoder - * - * \brief - * This class wraps the ::OggFLAC__StreamDecoder. - * - * See the \link oggflac_stream_decoder libOggFLAC stream decoder module \endlink - * for basic usage. - * - * \{ - */ - - /** This class wraps the ::OggFLAC__StreamDecoder. If you are - * decoding from a file, OggFLAC::Decoder::File may be more - * convenient. - * - * The usage of this class is similar to OggFLAC__StreamDecoder, - * except instead of providing callbacks to - * OggFLAC__stream_decoder_init_stream(), you will inherit from this - * class and override the virtual callback functions with your - * own implementations, then call Stream::init(). The rest of - * the calls work the same as in the C layer. - * - * Only the read, write, and error callbacks are mandatory. The - * others are optional; this class provides default - * implementations that do nothing. In order for seeking to work - * you must overide seek_callback(), tell_callback(), - * length_callback(), and eof_callback(). - */ - class OggFLACPP_API Stream: public FLAC::Decoder::Stream { - public: - /** This class is a wrapper around OggFLAC__StreamDecoderState. - */ - class OggFLACPP_API State { - public: - inline State(::OggFLAC__StreamDecoderState state): state_(state) { } - inline operator ::OggFLAC__StreamDecoderState() const { return state_; } - inline const char *as_cstring() const { return ::OggFLAC__StreamDecoderStateString[state_]; } - inline const char *resolved_as_cstring(const Stream &decoder) const { return ::OggFLAC__stream_decoder_get_resolved_state_string((const OggFLAC__StreamDecoder*)decoder.decoder_); } - protected: - ::OggFLAC__StreamDecoderState state_; - }; - - Stream(); - virtual ~Stream(); - - bool set_serial_number(long value); ///< See OggFLAC__stream_decoder_set_serial_number() - bool set_md5_checking(bool value); ///< See OggFLAC__stream_decoder_set_md5_checking() - bool set_metadata_respond(::FLAC__MetadataType type); ///< See OggFLAC__stream_decoder_set_metadata_respond() - bool set_metadata_respond_application(const FLAC__byte id[4]); ///< See OggFLAC__stream_decoder_set_metadata_respond_application() - bool set_metadata_respond_all(); ///< See OggFLAC__stream_decoder_set_metadata_respond_all() - bool set_metadata_ignore(::FLAC__MetadataType type); ///< See OggFLAC__stream_decoder_set_metadata_ignore() - bool set_metadata_ignore_application(const FLAC__byte id[4]); ///< See OggFLAC__stream_decoder_set_metadata_ignore_application() - bool set_metadata_ignore_all(); ///< See OggFLAC__stream_decoder_set_metadata_ignore_all() - - State get_state() const; ///< See OggFLAC__stream_decoder_get_state() - FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const; ///< See OggFLAC__stream_decoder_get_FLAC_stream_decoder_state() - bool get_md5_checking() const; ///< See OggFLAC__stream_decoder_get_md5_checking() - FLAC__uint64 get_total_samples() const; ///< See OggFLAC__stream_decoder_get_total_samples() - unsigned get_channels() const; ///< See OggFLAC__stream_decoder_get_channels() - ::FLAC__ChannelAssignment get_channel_assignment() const; ///< See OggFLAC__stream_decoder_get_channel_assignment() - unsigned get_bits_per_sample() const; ///< See OggFLAC__stream_decoder_get_bits_per_sample() - unsigned get_sample_rate() const; ///< See OggFLAC__stream_decoder_get_sample_rate() - unsigned get_blocksize() const; ///< See OggFLAC__stream_decoder_get_blocksize() - - /** Initialize the instance; as with the C interface, - * init() should be called after construction and 'set' - * calls but before any of the 'process' calls. - * - * See OggFLAC__stream_decoder_init_stream(). - */ - ::FLAC__StreamDecoderInitStatus init(); - - void finish(); ///< See OggFLAC__stream_decoder_finish() - - bool flush(); ///< See OggFLAC__stream_decoder_flush() - bool reset(); ///< See OggFLAC__stream_decoder_reset() - - bool process_single(); ///< See OggFLAC__stream_decoder_process_single() - bool process_until_end_of_metadata(); ///< See OggFLAC__stream_decoder_process_until_end_of_metadata() - bool process_until_end_of_stream(); ///< See OggFLAC__stream_decoder_process_until_end_of_stream() - bool skip_single_frame(); ///< See OggFLAC__stream_decoder_skip_single_frame() - - bool seek_absolute(FLAC__uint64 sample); ///< See OggFLAC__stream_decoder_seek_absolute() - protected: -#if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC) - // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring() - friend State; -#endif - private: - // Private and undefined so you can't use them: - Stream(const Stream &); - void operator=(const Stream &); - }; - - /* \} */ - - /** \defgroup oggflacpp_file_decoder OggFLAC++/decoder.h: file decoder class - * \ingroup oggflacpp_decoder - * - * \brief - * This class wraps the ::OggFLAC__FileDecoder. - * - * See the \link oggflac_stream_decoder libOggFLAC stream decoder module \endlink - * for basic usage. - * - * \{ - */ - - /** This class wraps the ::OggFLAC__StreamDecoder. If you are - * not decoding from a file, you may need to use - * OggFLAC::Decoder::Stream. - * - * The usage of this class is similar to OggFLAC__StreamDecoder, - * except instead of providing callbacks to - * OggFLAC__stream_decoder_init_FILE() or - * OggFLAC__stream_decoder_init_file(), you will inherit from this - * class and override the virtual callback functions with your - * own implementations, then call File::init(). The rest of - * the calls work the same as in the C layer. - * - * Only the write, and error callbacks from OggFLAC::Decoder::Stream - * are mandatory. The others are optional; this class provides - * full working implementations for all other callbacks and - * supports seeking. - */ - class OggFLACPP_API File: public Stream { - public: - File(); - virtual ~File(); - - //@{ - /** Initialize the instance; as with the C interface, - * init() should be called after construction and 'set' - * calls but before any of the 'process' calls. - * - * See OggFLAC__stream_decoder_init_FILE() and - * OggFLAC__stream_decoder_init_file(). - */ - ::FLAC__StreamDecoderInitStatus init(FILE *file); - ::FLAC__StreamDecoderInitStatus init(const char *filename); - ::FLAC__StreamDecoderInitStatus init(const std::string &filename); - //@} - protected: - // this is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer - virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes); - private: - // Private and undefined so you can't use them: - File(const File &); - void operator=(const File &); - }; - - /* \} */ - - } -} - -#endif diff --git a/include/OggFLAC++/encoder.h b/include/OggFLAC++/encoder.h deleted file mode 100644 index ca48bafd..00000000 --- a/include/OggFLAC++/encoder.h +++ /dev/null @@ -1,298 +0,0 @@ -/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLACPP__ENCODER_H -#define OggFLACPP__ENCODER_H - -#include "export.h" - -#include "OggFLAC/stream_encoder.h" -#include "decoder.h" -// we only need these for the state abstractions really... -#include "FLAC++/decoder.h" -#include "FLAC++/encoder.h" - - -/** \file include/OggFLAC++/encoder.h - * - * \brief - * This module contains the classes which implement the various - * encoders. - * - * See the detailed documentation in the - * \link oggflacpp_encoder encoder \endlink module. - */ - -/** \defgroup oggflacpp_encoder OggFLAC++/encoder.h: encoder classes - * \ingroup oggflacpp - * - * \brief - * This module describes the encoder layers provided by libOggFLAC++. - * - * The libOggFLAC++ encoder classes are object wrappers around their - * counterparts in libOggFLAC. All decoding layers available in - * libOggFLAC are also provided here. The interface is very similar; - * make sure to read the \link oggflac_encoder libOggFLAC encoder module \endlink. - * - * There are only two significant differences here. First, instead of - * passing in C function pointers for callbacks, you inherit from the - * encoder class and provide implementations for the callbacks in your - * derived class; because of this there is no need for a 'client_data' - * property. - * - * Second, there are two stream encoder classes. OggFLAC::Encoder::Stream - * is used for the same cases that OggFLAC__stream_encoder_init_stream() is - * used, and OggFLAC::Encoder::File is used for the same cases that - * OggFLAC__stream_encoder_init_FILE() and OggFLAC__stream_encoder_init_file() - * are used. - * - * Note that OggFLAC::Encoder::Stream inherits from FLAC::Encoder::Stream so - * it is possible to support both FLAC and Ogg FLAC encoding with only a - * little specialized code (just up to initialization). For example, - * \code - * class MyFLACEncoder: public FLAC::Encoder::Stream - * { - * // implement callbacks - * }; - * FLAC::Encoder::Stream *flac = new MyFLACEncoder(); - * if(*flac) { - * flac->set_...(); - * // continue set_ calls() - * if(flac->init() == ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) - * my_process_stream(flac); - * } - * - * ... - * - * class MyOggFLACEncoder: public OggFLAC::Encoder::Stream - * { - * // implement callbacks - * }; - * FLAC::Encoder::Stream *oggflac = new MyOggFLACEncoder(); - * if(*oggflac) { - * oggflac->set_serial_number(); - * // continue set_ calls() - * if(oggflac->init() == ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) - * my_process_stream(oggflac); - * } - * \endcode - */ - -namespace OggFLAC { - namespace Encoder { - - /** \defgroup oggflacpp_stream_encoder OggFLAC++/encoder.h: stream encoder class - * \ingroup oggflacpp_encoder - * - * \brief - * This class wraps the ::OggFLAC__StreamEncoder. - * - * See the \link oggflac_stream_encoder libOggFLAC stream encoder module \endlink - * for basic usage. - * - * \{ - */ - - /** This class wraps the ::OggFLAC__StreamEncoder. If you are - * encoding to a file, OggFLAC::Encoder::File may be more - * convenient. - * - * The usage of this class is similar to OggFLAC__StreamEncoder, - * except instead of providing callbacks to - * OggFLAC__stream_encoder_init_stream(), you will inherit from this - * class and override the virtual callback functions with your - * own implementations, then call Stream::init(). The rest of - * the calls work the same as in the C layer. - * - * Only the write callback is mandatory. The others are - * optional; this class provides default implementations that do - * nothing. In order for some STREAMINFO and SEEKTABLE data to - * be written properly, you must overide read_callback(), seek_callback() and - * tell_callback(); see OggFLAC__stream_encoder_init_stream() as to - * why. - */ - class OggFLACPP_API Stream: public FLAC::Encoder::Stream { - public: - /** This class is a wrapper around OggFLAC__StreamEncoderState. - */ - class OggFLACPP_API State { - public: - inline State(::OggFLAC__StreamEncoderState state): state_(state) { } - inline operator ::OggFLAC__StreamEncoderState() const { return state_; } - inline const char *as_cstring() const { return ::OggFLAC__StreamEncoderStateString[state_]; } - inline const char *resolved_as_cstring(const Stream &encoder) const { return ::OggFLAC__stream_encoder_get_resolved_state_string((const OggFLAC__StreamEncoder*)encoder.encoder_); } - protected: - ::OggFLAC__StreamEncoderState state_; - }; - - Stream(); - virtual ~Stream(); - - bool set_serial_number(long value); ///< See OggFLAC__stream_encoder_set_serial_number() - bool set_verify(bool value); ///< See OggFLAC__stream_encoder_set_verify() - bool set_streamable_subset(bool value); ///< See OggFLAC__stream_encoder_set_streamable_subset() - bool set_do_mid_side_stereo(bool value); ///< See OggFLAC__stream_encoder_set_do_mid_side_stereo() - bool set_loose_mid_side_stereo(bool value); ///< See OggFLAC__stream_encoder_set_loose_mid_side_stereo() - bool set_channels(unsigned value); ///< See OggFLAC__stream_encoder_set_channels() - bool set_bits_per_sample(unsigned value); ///< See OggFLAC__stream_encoder_set_bits_per_sample() - bool set_sample_rate(unsigned value); ///< See OggFLAC__stream_encoder_set_sample_rate() - bool set_blocksize(unsigned value); ///< See OggFLAC__stream_encoder_set_blocksize() - bool set_apodization(const char *specification); ///< See OggFLAC__stream_encoder_set_apodization() - bool set_max_lpc_order(unsigned value); ///< See OggFLAC__stream_encoder_set_max_lpc_order() - bool set_qlp_coeff_precision(unsigned value); ///< See OggFLAC__stream_encoder_set_qlp_coeff_precision() - bool set_do_qlp_coeff_prec_search(bool value); ///< See OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search() - bool set_do_escape_coding(bool value); ///< See OggFLAC__stream_encoder_set_do_escape_coding() - bool set_do_exhaustive_model_search(bool value); ///< See OggFLAC__stream_encoder_set_do_exhaustive_model_search() - bool set_min_residual_partition_order(unsigned value); ///< See OggFLAC__stream_encoder_set_min_residual_partition_order() - bool set_max_residual_partition_order(unsigned value); ///< See OggFLAC__stream_encoder_set_max_residual_partition_order() - bool set_rice_parameter_search_dist(unsigned value); ///< See OggFLAC__stream_encoder_set_rice_parameter_search_dist() - bool set_total_samples_estimate(FLAC__uint64 value); ///< See OggFLAC__stream_encoder_set_total_samples_estimate() - bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks); ///< See OggFLAC__stream_encoder_set_metadata() - bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks); ///< See OggFLAC__stream_encoder_set_metadata() - - State get_state() const; ///< See OggFLAC__stream_encoder_get_state() - FLAC::Encoder::Stream::State get_FLAC_stream_encoder_state() const; ///< See OggFLAC__stream_encoder_get_FLAC_stream_encoder_state() - FLAC::Decoder::Stream::State get_verify_decoder_state() const; ///< See OggFLAC__stream_encoder_get_verify_decoder_state() - void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got); ///< See OggFLAC__stream_encoder_get_verify_decoder_error_stats() - bool get_verify() const; ///< See OggFLAC__stream_encoder_get_verify() - bool get_streamable_subset() const; ///< See OggFLAC__stream_encoder_get_streamable_subset() - bool get_do_mid_side_stereo() const; ///< See OggFLAC__stream_encoder_get_do_mid_side_stereo() - bool get_loose_mid_side_stereo() const; ///< See OggFLAC__stream_encoder_get_loose_mid_side_stereo() - unsigned get_channels() const; ///< See OggFLAC__stream_encoder_get_channels() - unsigned get_bits_per_sample() const; ///< See OggFLAC__stream_encoder_get_bits_per_sample() - unsigned get_sample_rate() const; ///< See OggFLAC__stream_encoder_get_sample_rate() - unsigned get_blocksize() const; ///< See OggFLAC__stream_encoder_get_blocksize() - unsigned get_max_lpc_order() const; ///< See OggFLAC__stream_encoder_get_max_lpc_order() - unsigned get_qlp_coeff_precision() const; ///< See OggFLAC__stream_encoder_get_qlp_coeff_precision() - bool get_do_qlp_coeff_prec_search() const; ///< See OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search() - bool get_do_escape_coding() const; ///< See OggFLAC__stream_encoder_get_do_escape_coding() - bool get_do_exhaustive_model_search() const; ///< See OggFLAC__stream_encoder_get_do_exhaustive_model_search() - unsigned get_min_residual_partition_order() const; ///< See OggFLAC__stream_encoder_get_min_residual_partition_order() - unsigned get_max_residual_partition_order() const; ///< See OggFLAC__stream_encoder_get_max_residual_partition_order() - unsigned get_rice_parameter_search_dist() const; ///< See OggFLAC__stream_encoder_get_rice_parameter_search_dist() - FLAC__uint64 get_total_samples_estimate() const; ///< See OggFLAC__stream_encoder_get_total_samples_estimate() - - /** Initialize the instance; as with the C interface, - * init() should be called after construction and 'set' - * calls but before any of the 'process' calls. - * - * See OggFLAC__stream_encoder_init_stream(). - */ - ::FLAC__StreamEncoderInitStatus init(); - - void finish(); ///< See OggFLAC__stream_encoder_finish() - - bool process(const FLAC__int32 * const buffer[], unsigned samples); ///< See OggFLAC__stream_encoder_process() - bool process_interleaved(const FLAC__int32 buffer[], unsigned samples); ///< See OggFLAC__stream_encoder_process_interleaved() - protected: - /// See OggFLAC__StreamEncoderReadCallback - virtual ::OggFLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes); - -#if (defined _MSC_VER) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC) - // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring() - friend State; -#endif - static ::OggFLAC__StreamEncoderReadStatus read_callback_(const ::OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); - private: - // Private and undefined so you can't use them: - Stream(const Stream &); - void operator=(const Stream &); - }; - - /* \} */ - - /** \defgroup oggflacpp_file_encoder OggFLAC++/encoder.h: file encoder class - * \ingroup oggflacpp_encoder - * - * \brief - * This class wraps the ::OggFLAC__FileEncoder. - * - * See the \link oggflac_stream_encoder libOggFLAC stream encoder module \endlink - * for basic usage. - * - * \{ - */ - - /** This class wraps the ::OggFLAC__StreamEncoder. If you are - * not encoding to a file, you may need to use - * OggFLAC::Encoder::Stream. - * - * The usage of this class is similar to OggFLAC__StreamEncoder, - * except instead of providing callbacks to - * OggFLAC__stream_encoder_init_FILE() or - * OggFLAC__stream_encoder_init_file(), you will inherit from this - * class and override the virtual callback functions with your - * own implementations, then call File::init(). The rest of - * the calls work the same as in the C layer. - * - * There are no mandatory callbacks; all the callbacks from - * OggFLAC::Encoder::Stream are implemented here fully and support - * full post-encode STREAMINFO and SEEKTABLE updating. There is - * only an optional progress callback which you may override to - * get periodic reports on the progress of the encode. - */ - class OggFLACPP_API File: public Stream { - public: - File(); - virtual ~File(); - - //@{ - /** Initialize the instance; as with the C interface, - * init() should be called after construction and 'set' - * calls but before any of the 'process' calls. - * - * See OggFLAC__stream_encoder_init_FILE() and - * OggFLAC__stream_encoder_init_file(). - */ - ::FLAC__StreamEncoderInitStatus init(FILE *file); - ::FLAC__StreamEncoderInitStatus init(const char *filename); - ::FLAC__StreamEncoderInitStatus init(const std::string &filename); - //@} - protected: - /// See FLAC__StreamEncoderProgressCallback - virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate); - - /// This is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer - virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame); - private: - static void progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data); - - // Private and undefined so you can't use them: - File(const Stream &); - void operator=(const Stream &); - }; - - /* \} */ - - } -} - -#endif diff --git a/include/OggFLAC++/export.h b/include/OggFLAC++/export.h deleted file mode 100644 index 0e293f99..00000000 --- a/include/OggFLAC++/export.h +++ /dev/null @@ -1,55 +0,0 @@ -/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLACPP__EXPORT_H -#define OggFLACPP__EXPORT_H - -#if defined(FLAC__NO_DLL) || !defined(_MSC_VER) -#define OggFLACPP_API - -#else - -#ifdef OggFLACPP_API_EXPORTS -#define OggFLACPP_API _declspec(dllexport) -#else -#define OggFLACPP_API _declspec(dllimport) - -#endif -#endif - -/* These #defines will mirror the libtool-based library version number, see - * http://www.gnu.org/software/libtool/manual.html#Libtool-versioning - */ -#define OggFLACPP_API_VERSION_CURRENT 3 -#define OggFLACPP_API_VERSION_REVISION 0 -#define OggFLACPP_API_VERSION_AGE 0 - -#endif diff --git a/include/OggFLAC/Makefile.am b/include/OggFLAC/Makefile.am deleted file mode 100644 index 5c8e4df4..00000000 --- a/include/OggFLAC/Makefile.am +++ /dev/null @@ -1,40 +0,0 @@ -# libOggFLAC - Free Lossless Audio Codec + Ogg library -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# - Neither the name of the Xiph.org Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -oggflaccincludedir = $(includedir)/OggFLAC - -# NOTE: file_decoder.h and seekable_stream_decoder.h are NOT ready -# for distribution yet. - -oggflaccinclude_HEADERS = \ - all.h \ - export.h \ - stream_decoder.h \ - stream_encoder.h diff --git a/include/OggFLAC/all.h b/include/OggFLAC/all.h deleted file mode 100644 index d4080edb..00000000 --- a/include/OggFLAC/all.h +++ /dev/null @@ -1,51 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLAC__ALL_H -#define OggFLAC__ALL_H - -/* NOTE: file_decoder.h and seekable_stream_decoder.h are NOT ready - * for distribution yet. - */ - -#include "export.h" - -#include "stream_decoder.h" -#include "stream_encoder.h" - -/** \defgroup oggflac OggFLAC C API - * - * The OggFLAC C API is the interface to libOggFLAC, a set of encoders - * and decoders that wrap around the libFLAC API to provide encoding - * to and decoding from FLAC streams in an Ogg transport. - */ - -#endif diff --git a/include/OggFLAC/export.h b/include/OggFLAC/export.h deleted file mode 100644 index 075f77f1..00000000 --- a/include/OggFLAC/export.h +++ /dev/null @@ -1,55 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLAC__EXPORT_H -#define OggFLAC__EXPORT_H - -#if defined(FLAC__NO_DLL) || !defined(_MSC_VER) -#define OggFLAC_API - -#else - -#ifdef OggFLAC_API_EXPORTS -#define OggFLAC_API _declspec(dllexport) -#else -#define OggFLAC_API _declspec(dllimport) - -#endif -#endif - -/* These #defines will mirror the libtool-based library version number, see - * http://www.gnu.org/software/libtool/manual.html#Libtool-versioning - */ -#define OggFLAC_API_VERSION_CURRENT 4 -#define OggFLAC_API_VERSION_REVISION 0 -#define OggFLAC_API_VERSION_AGE 0 - -#endif diff --git a/include/OggFLAC/stream_decoder.h b/include/OggFLAC/stream_decoder.h deleted file mode 100644 index 7d016804..00000000 --- a/include/OggFLAC/stream_decoder.h +++ /dev/null @@ -1,689 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLAC__STREAM_DECODER_H -#define OggFLAC__STREAM_DECODER_H - -#include <stdio.h> /* for FILE */ -#include "export.h" -#include "FLAC/stream_decoder.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -/** \file include/OggFLAC/stream_decoder.h - * - * \brief - * This module contains the functions which implement the stream - * decoder. - * - * See the detailed documentation in the - * \link oggflac_stream_decoder stream decoder \endlink module. - */ - -/** \defgroup oggflac_decoder OggFLAC/ *_decoder.h: decoder interfaces - * \ingroup oggflac - * - * \brief - * This module describes the decoder layers provided by libOggFLAC. - * - * libOggFLAC currently provides the same layers of access as - * libFLAC; the interfaces are nearly identical, with th addition of a - * method for specifying the Ogg serial number. See the - * \link flac_decoder FLAC decoder module \endlink for full documentation. - */ - -/** \defgroup oggflac_stream_decoder OggFLAC/stream_decoder.h: stream decoder interface - * \ingroup oggflac_decoder - * - * \brief - * This module contains the functions which implement the stream - * decoder. - * - * The interface here is nearly identical to FLAC's stream decoder, - * including the callbacks, with the addition of - * OggFLAC__stream_decoder_set_serial_number(). See the - * \link flac_stream_decoder FLAC stream decoder module \endlink - * for full documentation. - * - * \{ - */ - - -/** State values for an OggFLAC__StreamDecoder - * - * The decoder's state can be obtained by calling OggFLAC__stream_decoder_get_state(). - */ -typedef enum { - - OggFLAC__STREAM_DECODER_OK = 0, - /**< The decoder is in the normal OK state. */ - - OggFLAC__STREAM_DECODER_END_OF_STREAM, - /**< The decoder has reached the end of the stream. */ - - OggFLAC__STREAM_DECODER_OGG_ERROR, - /**< An error occurred in the underlying Ogg layer. */ - - OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR, - /**< An error occurred in the underlying FLAC stream decoder; - * check OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(). - */ - - OggFLAC__STREAM_DECODER_SEEK_ERROR, - /**< An error occurred while seeking or the seek or tell - * callback returned an error. The decoder must be flushed with - * OggFLAC__stream_decoder_flush() or reset with - * OggFLAC__stream_decoder_reset() before decoding can continue. - */ - - OggFLAC__STREAM_DECODER_READ_ERROR, - /**< The read callback returned an error. */ - - OggFLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR, - /**< An error occurred allocating memory. The decoder is in an invalid - * state and can no longer be used. - */ - - OggFLAC__STREAM_DECODER_UNINITIALIZED - /**< The decoder is in the uninitialized state; one of the - * OggFLAC__stream_decoder_init_*() functions must be called before samples - * can be processed. - */ - -} OggFLAC__StreamDecoderState; - -/** Maps an OggFLAC__StreamDecoderState to a C string. - * - * Using an OggFLAC__StreamDecoderState as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern OggFLAC_API const char * const OggFLAC__StreamDecoderStateString[]; - - -/*********************************************************************** - * - * class OggFLAC__StreamDecoder - * - ***********************************************************************/ - -struct OggFLAC__StreamDecoderProtected; -struct OggFLAC__StreamDecoderPrivate; -/** The opaque structure definition for the stream decoder type. - * See the \link oggflac_stream_decoder stream decoder module \endlink - * for a detailed description. - */ -typedef struct { - FLAC__StreamDecoder super_; - struct OggFLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */ - struct OggFLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */ -} OggFLAC__StreamDecoder; - - -/*********************************************************************** - * - * Class constructor/destructor - * - ***********************************************************************/ - -/** Create a new stream decoder instance. The instance is created with - * default settings; see the individual OggFLAC__stream_decoder_set_*() - * functions for each setting's default. - * - * \retval OggFLAC__StreamDecoder* - * \c NULL if there was an error allocating memory, else the new instance. - */ -OggFLAC_API OggFLAC__StreamDecoder *OggFLAC__stream_decoder_new(); - -/** Free a decoder instance. Deletes the object pointed to by \a decoder. - * - * \param decoder A pointer to an existing decoder. - * \assert - * \code decoder != NULL \endcode - */ -OggFLAC_API void OggFLAC__stream_decoder_delete(OggFLAC__StreamDecoder *decoder); - - -/*********************************************************************** - * - * Public class method prototypes - * - ***********************************************************************/ - -/** Set the serial number for the Ogg stream. - * The default behavior is to use the serial number of the first Ogg - * page. Setting a serial number here will explicitly specify which - * stream is to be decoded. - * - * \default \c use serial number of first page - * \param decoder A decoder instance to set. - * \param serial_number See above. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_serial_number(OggFLAC__StreamDecoder *decoder, long serial_number); - -/** Set the "MD5 signature checking" flag. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_md5_checking() - * - * \default \c false - * \param decoder A decoder instance to set. - * \param value Flag value (see above). - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_md5_checking(OggFLAC__StreamDecoder *decoder, FLAC__bool value); - -/** Direct the decoder to pass on all metadata blocks of type \a type. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_respond() - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \param type See above. - * \assert - * \code decoder != NULL \endcode - * \a type is valid - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_respond(OggFLAC__StreamDecoder *decoder, FLAC__MetadataType type); - -/** Direct the decoder to pass on all APPLICATION metadata blocks of the - * given \a id. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_respond_application() - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \param id See above. - * \assert - * \code decoder != NULL \endcode - * \code id != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_respond_application(OggFLAC__StreamDecoder *decoder, const FLAC__byte id[4]); - -/** Direct the decoder to pass on all metadata blocks of any type. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_respond_all() - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_respond_all(OggFLAC__StreamDecoder *decoder); - -/** Direct the decoder to filter out all metadata blocks of type \a type. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_ignore() - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \param type See above. - * \assert - * \code decoder != NULL \endcode - * \a type is valid - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore(OggFLAC__StreamDecoder *decoder, FLAC__MetadataType type); - -/** Direct the decoder to filter out all APPLICATION metadata blocks of - * the given \a id. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_ignore_application() - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \param id See above. - * \assert - * \code decoder != NULL \endcode - * \code id != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore_application(OggFLAC__StreamDecoder *decoder, const FLAC__byte id[4]); - -/** Direct the decoder to filter out all metadata blocks of any type. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_ignore_all() - * - * \default By default, only the \c STREAMINFO block is returned via the - * metadata callback. - * \param decoder A decoder instance to set. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if the decoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore_all(OggFLAC__StreamDecoder *decoder); - -/** Get the current decoder state. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval OggFLAC__StreamDecoderState - * The current decoder state. - */ -OggFLAC_API OggFLAC__StreamDecoderState OggFLAC__stream_decoder_get_state(const OggFLAC__StreamDecoder *decoder); - -/** Get the state of the underlying FLAC stream decoder. - * Useful when the stream decoder state is - * \c OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__StreamDecoderState - * The FLAC stream decoder state. - */ -OggFLAC_API FLAC__StreamDecoderState OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(const OggFLAC__StreamDecoder *decoder); - -/** Get the current decoder state as a C string. - * This version automatically resolves - * \c OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR - * by getting the FLAC stream decoder's state. - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval const char * - * The decoder state as a C string. Do not modify the contents. - */ -OggFLAC_API const char *OggFLAC__stream_decoder_get_resolved_state_string(const OggFLAC__StreamDecoder *decoder); - -/** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_md5_checking() - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * See above. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_get_md5_checking(const OggFLAC__StreamDecoder *decoder); - -/** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_total_samples() - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval unsigned - * See above. - */ -OggFLAC_API FLAC__uint64 OggFLAC__stream_decoder_get_total_samples(const OggFLAC__StreamDecoder *decoder); - -/** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_channels() - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval unsigned - * See above. - */ -OggFLAC_API unsigned OggFLAC__stream_decoder_get_channels(const OggFLAC__StreamDecoder *decoder); - -/** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_channel_assignment() - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval OggFLAC__ChannelAssignment - * See above. - */ -OggFLAC_API FLAC__ChannelAssignment OggFLAC__stream_decoder_get_channel_assignment(const OggFLAC__StreamDecoder *decoder); - -/** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_bits_per_sample() - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval unsigned - * See above. - */ -OggFLAC_API unsigned OggFLAC__stream_decoder_get_bits_per_sample(const OggFLAC__StreamDecoder *decoder); - -/** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_sample_rate() - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval unsigned - * See above. - */ -OggFLAC_API unsigned OggFLAC__stream_decoder_get_sample_rate(const OggFLAC__StreamDecoder *decoder); - -/** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_blocksize() - * - * \param decoder A decoder instance to query. - * \assert - * \code decoder != NULL \endcode - * \retval unsigned - * See above. - */ -OggFLAC_API unsigned OggFLAC__stream_decoder_get_blocksize(const OggFLAC__StreamDecoder *decoder); - -/** Initialize the decoder instance. - * - * This flavor of initialization sets up the decoder to decode from a stream. - * I/O is performed via callbacks to the client. For decoding from a plain file - * via filename or open FILE*, OggFLAC__stream_decoder_init_file() and - * OggFLAC__stream_decoder_init_FILE() provide a simpler interface. - * - * This function should be called after OggFLAC__stream_decoder_new() and - * OggFLAC__stream_decoder_set_*() but before any of the - * OggFLAC__stream_decoder_process_*() functions. Will set and return the - * decoder state, which will be OggFLAC__STREAM_DECODER_OK - * if initialization succeeded. - * - * \param decoder An uninitialized decoder instance. - * \param read_callback See FLAC__StreamDecoderReadCallback. This - * pointer must not be \c NULL. - * \param seek_callback See FLAC__StreamDecoderSeekCallback. This - * pointer may be \c NULL if seeking is not - * supported. If \a seek_callback is not \c NULL then a - * \a tell_callback, \a length_callback, and \a eof_callback must also be supplied. - * Alternatively, a dummy seek callback that just - * returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param tell_callback See FLAC__StreamDecoderTellCallback. This - * pointer may be \c NULL if not supported by the client. If - * \a seek_callback is not \c NULL then a - * \a tell_callback must also be supplied. - * Alternatively, a dummy tell callback that just - * returns \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param length_callback See FLAC__StreamDecoderLengthCallback. This - * pointer may be \c NULL if not supported by the client. If - * \a seek_callback is not \c NULL then a - * \a length_callback must also be supplied. - * Alternatively, a dummy length callback that just - * returns \c FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param eof_callback See FLAC__StreamDecoderEofCallback. This - * pointer may be \c NULL if not supported by the client. If - * \a seek_callback is not \c NULL then a - * \a eof_callback must also be supplied. - * Alternatively, a dummy length callback that just - * returns \c false - * may also be supplied, all though this is slightly - * less efficient for the decoder. - * \param write_callback See FLAC__StreamDecoderWriteCallback. This - * pointer must not be \c NULL. - * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param error_callback See FLAC__StreamDecoderErrorCallback. This - * pointer must not be \c NULL. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__StreamDecoderInitStatus - * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamDecoderInitStatus for the meanings of other return values. - */ -OggFLAC_API FLAC__StreamDecoderInitStatus OggFLAC__stream_decoder_init_stream( - OggFLAC__StreamDecoder *decoder, - FLAC__StreamDecoderReadCallback read_callback, - FLAC__StreamDecoderSeekCallback seek_callback, - FLAC__StreamDecoderTellCallback tell_callback, - FLAC__StreamDecoderLengthCallback length_callback, - FLAC__StreamDecoderEofCallback eof_callback, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -); - -/** Initialize the decoder instance. - * - * This flavor of initialization sets up the decoder to decode from a plain - * file. For non-stdio streams, you must use - * OggFLAC__stream_decoder_init_stream() and provide callbacks for the I/O. - * - * This function should be called after OggFLAC__stream_decoder_new() and - * OggFLAC__stream_decoder_set_*() but before any of the - * OggFLAC__stream_decoder_process_*() functions. Will set and return the - * decoder state, which will be OggFLAC__STREAM_DECODER_OK - * if initialization succeeded. - * - * \param decoder An uninitialized decoder instance. - * \param file An open Ogg FLAC file. The file should have been - * opened with mode \c "rb" and rewound. The file - * becomes owned by the decoder and should not be - * manipulated by the client while decoding. - * Unless \a file is \c stdin, it will be closed - * when OggFLAC__stream_decoder_finish() is called. - * Note however that seeking will not work when - * decoding from \c stdout since it is not seekable. - * \param write_callback See FLAC__StreamDecoderWriteCallback. This - * pointer must not be \c NULL. - * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param error_callback See FLAC__StreamDecoderErrorCallback. This - * pointer must not be \c NULL. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code decoder != NULL \endcode - * \code file != NULL \endcode - * \retval FLAC__StreamDecoderInitStatus - * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamDecoderInitStatus for the meanings of other return values. - */ -OggFLAC_API FLAC__StreamDecoderInitStatus OggFLAC__stream_decoder_init_FILE( - OggFLAC__StreamDecoder *decoder, - FILE *file, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -); - -/** Initialize the decoder instance. - * - * This flavor of initialization sets up the decoder to decode from a plain - * file. If POSIX fopen() semantics are not sufficient, (for example, with - * Unicode filenames on Windows), you must use - * OggFLAC__stream_decoder_init_FILE(), or OggFLAC__stream_decoder_init_stream() - * and provide callbacks for the I/O. - * - * This function should be called after OggFLAC__stream_decoder_new() and - * OggFLAC__stream_decoder_set_*() but before any of the - * OggFLAC__stream_decoder_process_*() functions. Will set and return the - * decoder state, which will be OggFLAC__STREAM_DECODER_OK - * if initialization succeeded. - * - * \param decoder An uninitialized decoder instance. - * \param filename The name of the file to decode from. The file will - * be opened with fopen(). Use \c NULL to decode from - * \c stdin. Note that \c stdin is not seekable. - * \param write_callback See FLAC__StreamDecoderWriteCallback. This - * pointer must not be \c NULL. - * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param error_callback See FLAC__StreamDecoderErrorCallback. This - * pointer must not be \c NULL. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__StreamDecoderInitStatus - * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamDecoderInitStatus for the meanings of other return values. - */ -OggFLAC_API FLAC__StreamDecoderInitStatus OggFLAC__stream_decoder_init_file( - OggFLAC__StreamDecoder *decoder, - const char *filename, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -); - -/** Finish the decoding process. - * Flushes the decoding buffer, releases resources, resets the decoder - * settings to their defaults, and returns the decoder state to - * OggFLAC__STREAM_DECODER_UNINITIALIZED. - * - * In the event of a prematurely-terminated decode, it is not strictly - * necessary to call this immediately before OggFLAC__stream_decoder_delete() - * but it is good practice to match every OggFLAC__stream_decoder_init() - * with an OggFLAC__stream_decoder_finish(). - * - * \param decoder An uninitialized decoder instance. - * \assert - * \code decoder != NULL \endcode - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_finish(OggFLAC__StreamDecoder *decoder); - -/** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_flush() - * - * \param decoder A decoder instance. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c true if successful, else \c false if a memory allocation - * error occurs. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_flush(OggFLAC__StreamDecoder *decoder); - -/** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_reset() - * - * \param decoder A decoder instance. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c true if successful, else \c false if a memory allocation - * or seek error occurs. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_reset(OggFLAC__StreamDecoder *decoder); - -/** Decode one metadata block or audio frame. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_process_single() - * - * \param decoder An initialized decoder instance in the state - * \c OggFLAC__STREAM_DECODER_OK. - * \assert - * \code decoder != NULL \endcode - * \code OggFLAC__stream_decoder_get_state(decoder) == OggFLAC__STREAM_DECODER_OK \endcode - * \retval FLAC__bool - * \c false if any fatal read, write, or memory allocation error - * occurred (meaning decoding must stop), else \c true; for more - * information about the decoder, check the decoder state with - * OggFLAC__stream_decoder_get_state(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_single(OggFLAC__StreamDecoder *decoder); - -/** Decode until the end of the metadata. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_process_until_end_of_metadata() - * - * \param decoder An initialized decoder instance in the state - * \c OggFLAC__STREAM_DECODER_OK. - * \assert - * \code decoder != NULL \endcode - * \code OggFLAC__stream_decoder_get_state(decoder) == OggFLAC__STREAM_DECODER_OK \endcode - * \retval FLAC__bool - * \c false if any fatal read, write, or memory allocation error - * occurred (meaning decoding must stop), else \c true; for more - * information about the decoder, check the decoder state with - * OggFLAC__stream_decoder_get_state(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_until_end_of_metadata(OggFLAC__StreamDecoder *decoder); - -/** Decode until the end of the stream. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_process_until_end_of_stream() - * - * \param decoder An initialized decoder instance in the state - * \c OggFLAC__STREAM_DECODER_OK. - * \assert - * \code decoder != NULL \endcode - * \code OggFLAC__stream_decoder_get_state(decoder) == OggFLAC__STREAM_DECODER_OK \endcode - * \retval FLAC__bool - * \c false if any fatal read, write, or memory allocation error - * occurred (meaning decoding must stop), else \c true; for more - * information about the decoder, check the decoder state with - * OggFLAC__stream_decoder_get_state(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_until_end_of_stream(OggFLAC__StreamDecoder *decoder); - -/** Skip one audio frame. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_skip_single_frame() - * - * \param decoder An initialized decoder instance not in a metadata - * state. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c false if any fatal read, write, or memory allocation error - * occurred (meaning decoding must stop), or if the underlying FLAC - * stream decoder is in the FLAC__STREAM_DECODER_SEARCH_FOR_METADATA or - * FLAC__STREAM_DECODER_READ_METADATA state, else \c true; for more - * information about the decoder, check the decoder state with - * OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_skip_single_frame(OggFLAC__StreamDecoder *decoder); - -/** Flush the input and seek to an absolute sample. - * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_seek_absolute(). - * - * \param decoder A decoder instance. - * \param sample The target sample number to seek to. - * \assert - * \code decoder != NULL \endcode - * \retval FLAC__bool - * \c true if successful, else \c false. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_seek_absolute(OggFLAC__StreamDecoder *decoder, FLAC__uint64 sample); - -/* \} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/OggFLAC/stream_encoder.h b/include/OggFLAC/stream_encoder.h deleted file mode 100644 index e971b385..00000000 --- a/include/OggFLAC/stream_encoder.h +++ /dev/null @@ -1,959 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLAC__STREAM_ENCODER_H -#define OggFLAC__STREAM_ENCODER_H - -#include "export.h" - -#include "FLAC/stream_encoder.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -/** \file include/OggFLAC/stream_encoder.h - * - * \brief - * This module contains the functions which implement the stream - * encoder. - * - * See the detailed documentation in the - * \link oggflac_stream_encoder stream encoder \endlink module. - */ - -/** \defgroup oggflac_encoder OggFLAC/ *_encoder.h: encoder interfaces - * \ingroup oggflac - * - * \brief - * This module describes the encoder layers provided by libOggFLAC. - * - * libOggFLAC currently provides the same layers of access as libFLAC; - * the interfaces are nearly identical, with the addition of a method for - * specifying the Ogg serial number. See the \link flac_encoder FLAC - * encoder module \endlink for full documentation. - */ - -/** \defgroup oggflac_stream_encoder OggFLAC/stream_encoder.h: stream encoder interface - * \ingroup oggflac_encoder - * - * \brief - * This module contains the functions which implement the stream - * encoder. The Ogg stream encoder is derived - * from the FLAC stream encoder. - * - * The interface here is nearly identical to FLAC's stream encoder, - * including the callbacks, with the addition of - * OggFLAC__stream_encoder_set_serial_number(). See the - * \link flac_stream_encoder FLAC stream encoder module \endlink - * for full documentation. - * - * \{ - */ - - -/** State values for an OggFLAC__StreamEncoder - * - * The encoder's state can be obtained by calling OggFLAC__stream_encoder_get_state(). - */ -typedef enum { - - OggFLAC__STREAM_ENCODER_OK = 0, - /**< The encoder is in the normal OK state and samples can be processed. */ - - OggFLAC__STREAM_ENCODER_UNINITIALIZED, - /**< The encoder is in the uninitialized state; one of the - * OggFLAC__stream_encoder_init_*() functions must be called before samples - * can be processed. - */ - - OggFLAC__STREAM_ENCODER_OGG_ERROR, - /**< An error occurred in the underlying Ogg layer. */ - - OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR, - /**< An error occurred in the underlying FLAC stream encoder; - * check OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(). - */ - - OggFLAC__STREAM_ENCODER_CLIENT_ERROR, - /**< One of the callbacks returned a fatal error. */ - - OggFLAC__STREAM_ENCODER_IO_ERROR, - /**< An I/O error occurred while opening/reading/writing a file. - * Check \c errno. - */ - - OggFLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR - /**< Memory allocation failed. */ - -} OggFLAC__StreamEncoderState; - -/** Maps an OggFLAC__StreamEncoderState to a C string. - * - * Using an OggFLAC__StreamEncoderState as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern OggFLAC_API const char * const OggFLAC__StreamEncoderStateString[]; - - -/** Return values for the OggFLAC__StreamEncoder read callback. - */ -typedef enum { - - OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE, - /**< The read was OK and decoding can continue. */ - - OggFLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM, - /**< The read was attempted at the end of the stream. */ - - OggFLAC__STREAM_ENCODER_READ_STATUS_ABORT, - /**< An unrecoverable error occurred. */ - - OggFLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED - /**< Client does not support reading back from the output. */ - -} OggFLAC__StreamEncoderReadStatus; - -/** Maps a OggFLAC__StreamEncoderReadStatus to a C string. - * - * Using a OggFLAC__StreamEncoderReadStatus as the index to this array - * will give the string equivalent. The contents should not be modified. - */ -extern OggFLAC_API const char * const OggFLAC__StreamEncoderReadStatusString[]; - - -/*********************************************************************** - * - * class OggFLAC__StreamEncoder - * - ***********************************************************************/ - -struct OggFLAC__StreamEncoderProtected; -struct OggFLAC__StreamEncoderPrivate; -/** The opaque structure definition for the stream encoder type. - * See the \link oggflac_stream_encoder stream encoder module \endlink - * for a detailed description. - */ -typedef struct { - FLAC__StreamEncoder super_; - struct OggFLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */ - struct OggFLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */ -} OggFLAC__StreamEncoder; - -/** Signature for the read callback. - * - * A function pointer matching this signature must be passed to - * OggFLAC__stream_encoder_init_stream() if seeking is supported. - * The supplied function will be called when the encoder needs to read back - * encoded data. This happens during the metadata callback, when the encoder - * has to read, modify, and rewrite the metadata (e.g. seekpoints) gathered - * while encoding. The address of the buffer to be filled is supplied, along - * with the number of bytes the buffer can hold. The callback may choose to - * supply less data and modify the byte count but must be careful not to - * overflow the buffer. The callback then returns a status code chosen from - * OggFLAC__StreamEncoderReadStatus. - * - * \note In general, FLAC__StreamEncoder functions which change the - * state should not be called on the \a encoder while in the callback. - * - * \param encoder The encoder instance calling the callback. - * \param buffer A pointer to a location for the callee to store - * data to be encoded. - * \param bytes A pointer to the size of the buffer. On entry - * to the callback, it contains the maximum number - * of bytes that may be stored in \a buffer. The - * callee must set it to the actual number of bytes - * stored (0 in case of error or end-of-stream) before - * returning. - * \param client_data The callee's client data set through - * OggFLAC__stream_encoder_set_client_data(). - * \retval OggFLAC__StreamEncoderReadStatus - * The callee's return status. - */ -typedef OggFLAC__StreamEncoderReadStatus (*OggFLAC__StreamEncoderReadCallback)(const OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); - - -/*********************************************************************** - * - * Class constructor/destructor - * - ***********************************************************************/ - -/** Create a new stream encoder instance. The instance is created with - * default settings; see the individual OggFLAC__stream_encoder_set_*() - * functions for each setting's default. - * - * \retval OggFLAC__StreamEncoder* - * \c NULL if there was an error allocating memory, else the new instance. - */ -OggFLAC_API OggFLAC__StreamEncoder *OggFLAC__stream_encoder_new(); - -/** Free an encoder instance. Deletes the object pointed to by \a encoder. - * - * \param encoder A pointer to an existing encoder. - * \assert - * \code encoder != NULL \endcode - */ -OggFLAC_API void OggFLAC__stream_encoder_delete(OggFLAC__StreamEncoder *encoder); - - -/*********************************************************************** - * - * Public class method prototypes - * - ***********************************************************************/ - -/** Set the serial number for the FLAC stream. - * - * \note - * It is recommended to set a serial number explicitly as the default of '0' - * may collide with other streams. - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param serial_number See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_serial_number(OggFLAC__StreamEncoder *encoder, long serial_number); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_verify() - * - * \default \c false - * \param encoder An encoder instance to set. - * \param value Flag value (see above). - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_verify(OggFLAC__StreamEncoder *encoder, FLAC__bool value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_streamable_subset() - * - * \default \c true - * \param encoder An encoder instance to set. - * \param value Flag value (see above). - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_streamable_subset(OggFLAC__StreamEncoder *encoder, FLAC__bool value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_mid_side_stereo() - * - * \default \c false - * \param encoder An encoder instance to set. - * \param value Flag value (see above). - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_loose_mid_side_stereo() - * - * \default \c false - * \param encoder An encoder instance to set. - * \param value Flag value (see above). - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_loose_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_channels() - * - * \default \c 2 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_channels(OggFLAC__StreamEncoder *encoder, unsigned value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_bits_per_sample() - * - * \default \c 16 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_bits_per_sample(OggFLAC__StreamEncoder *encoder, unsigned value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_sample_rate() - * - * \default \c 44100 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_sample_rate(OggFLAC__StreamEncoder *encoder, unsigned value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_blocksize() - * - * \default \c 1152 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_blocksize(OggFLAC__StreamEncoder *encoder, unsigned value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_apodization() - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param specification See above. - * \assert - * \code encoder != NULL \endcode - * \code specification != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_apodization(OggFLAC__StreamEncoder *encoder, const char *specification); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_lpc_order() - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_max_lpc_order(OggFLAC__StreamEncoder *encoder, unsigned value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_precision() - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_qlp_coeff_precision(OggFLAC__StreamEncoder *encoder, unsigned value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_qlp_coeff_prec_search() - * - * \default \c false - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_escape_coding() - * - * \default \c false - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_escape_coding(OggFLAC__StreamEncoder *encoder, FLAC__bool value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_do_exhaustive_model_search() - * - * \default \c false - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_exhaustive_model_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_min_residual_partition_order() - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_min_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_max_residual_partition_order() - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_max_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_rice_parameter_search_dist() - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_rice_parameter_search_dist(OggFLAC__StreamEncoder *encoder, unsigned value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_total_samples_estimate() - * - * \default \c 0 - * \param encoder An encoder instance to set. - * \param value See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_total_samples_estimate(OggFLAC__StreamEncoder *encoder, FLAC__uint64 value); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_set_metadata() - * - * \note The Ogg FLAC mapping requires that the VORBIS_COMMENT block be - * the second metadata block of the stream. The encoder already supplies - * the STREAMINFO block automatically. If \a metadata does not contain a - * VORBIS_COMMENT block, the encoder will supply that too. Otherwise, if - * \a metadata does contain a VORBIS_COMMENT block and it is not the - * first, this function will reorder \a metadata by moving the - * VORBIS_COMMENT block to the front; the relative ordering of the other - * blocks will remain as they were. - * - * \note The Ogg FLAC mapping limits the number of metadata blocks per - * stream to \c 65535. If \a num_blocks exceeds this the function will - * return \c false. - * - * \default \c NULL, 0 - * \param encoder An encoder instance to set. - * \param metadata See above. - * \param num_blocks See above. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * \c false if the encoder is already initialized, or if - * \a num_blocks > 65535, else \c true. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_metadata(OggFLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks); - -/** Get the current encoder state. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval OggFLAC__StreamEncoderState - * The current encoder state. - */ -OggFLAC_API OggFLAC__StreamEncoderState OggFLAC__stream_encoder_get_state(const OggFLAC__StreamEncoder *encoder); - -/** Get the state of the underlying FLAC stream encoder. - * Useful when the stream encoder state is - * \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamEncoderState - * The FLAC stream encoder state. - */ -OggFLAC_API FLAC__StreamEncoderState OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(const OggFLAC__StreamEncoder *encoder); - -/** Get the state of the underlying FLAC stream encoder's verify decoder. - * Useful when the stream encoder state is - * \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR and the - * FLAC encoder state is \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamDecoderState - * The FLAC verify decoder state. - */ -OggFLAC_API FLAC__StreamDecoderState OggFLAC__stream_encoder_get_verify_decoder_state(const OggFLAC__StreamEncoder *encoder); - -/** Get the current encoder state as a C string. - * This version automatically resolves - * \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR by getting the - * FLAC stream encoder's state. - * - * \param encoder A encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval const char * - * The encoder state as a C string. Do not modify the contents. - */ -OggFLAC_API const char *OggFLAC__stream_encoder_get_resolved_state_string(const OggFLAC__StreamEncoder *encoder); - -/** Get relevant values about the nature of a verify decoder error. - * Inherited from FLAC__stream_encoder_get_verify_decoder_error_stats(). - * Useful when the stream encoder state is - * \c OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR and the - * FLAC stream encoder state is - * \c FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. - * - * \param encoder An encoder instance to query. - * \param absolute_sample The absolute sample number of the mismatch. - * \param frame_number The number of the frame in which the mismatch occurred. - * \param channel The channel in which the mismatch occurred. - * \param sample The number of the sample (relative to the frame) in - * which the mismatch occurred. - * \param expected The expected value for the sample in question. - * \param got The actual value returned by the decoder. - * \assert - * \code encoder != NULL \endcode - * \code absolute_sample != NULL \endcode - * \code frame_number != NULL \endcode - * \code channel != NULL \endcode - * \code sample != NULL \endcode - * \code expected != NULL \endcode - */ -OggFLAC_API void OggFLAC__stream_encoder_get_verify_decoder_error_stats(const OggFLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_verify() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See OggFLAC__stream_encoder_set_verify(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_verify(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_streamable_subset() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See OggFLAC__stream_encoder_set_streamable_subset(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_streamable_subset(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_mid_side_stereo() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See OggFLAC__stream_encoder_get_do_mid_side_stereo(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_mid_side_stereo(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_loose_mid_side_stereo() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See OggFLAC__stream_encoder_set_loose_mid_side_stereo(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_loose_mid_side_stereo(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_channels() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval unsigned - * See OggFLAC__stream_encoder_set_channels(). - */ -OggFLAC_API unsigned OggFLAC__stream_encoder_get_channels(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_bits_per_sample() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval unsigned - * See OggFLAC__stream_encoder_set_bits_per_sample(). - */ -OggFLAC_API unsigned OggFLAC__stream_encoder_get_bits_per_sample(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_sample_rate() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval unsigned - * See OggFLAC__stream_encoder_set_sample_rate(). - */ -OggFLAC_API unsigned OggFLAC__stream_encoder_get_sample_rate(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_blocksize() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval unsigned - * See OggFLAC__stream_encoder_set_blocksize(). - */ -OggFLAC_API unsigned OggFLAC__stream_encoder_get_blocksize(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_max_lpc_order() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval unsigned - * See OggFLAC__stream_encoder_set_max_lpc_order(). - */ -OggFLAC_API unsigned OggFLAC__stream_encoder_get_max_lpc_order(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_qlp_coeff_precision() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval unsigned - * See OggFLAC__stream_encoder_set_qlp_coeff_precision(). - */ -OggFLAC_API unsigned OggFLAC__stream_encoder_get_qlp_coeff_precision(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_qlp_coeff_prec_search() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_escape_coding() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See OggFLAC__stream_encoder_set_do_escape_coding(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_escape_coding(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_do_exhaustive_model_search() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__bool - * See OggFLAC__stream_encoder_set_do_exhaustive_model_search(). - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_exhaustive_model_search(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_min_residual_partition_order() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval unsigned - * See OggFLAC__stream_encoder_set_min_residual_partition_order(). - */ -OggFLAC_API unsigned OggFLAC__stream_encoder_get_min_residual_partition_order(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_man_residual_partition_order() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval unsigned - * See OggFLAC__stream_encoder_set_max_residual_partition_order(). - */ -OggFLAC_API unsigned OggFLAC__stream_encoder_get_max_residual_partition_order(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_rice_parameter_search_dist() - * - * \param encoder An encoder instance to query. - * \assert - * \code encoder != NULL \endcode - * \retval unsigned - * See OggFLAC__stream_encoder_set_rice_parameter_search_dist(). - */ -OggFLAC_API unsigned OggFLAC__stream_encoder_get_rice_parameter_search_dist(const OggFLAC__StreamEncoder *encoder); - -/** This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_get_total_samples_estimate() - * - * \param encoder An encoder instance to set. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__uint64 - * See OggFLAC__stream_encoder_get_total_samples_estimate(). - */ -OggFLAC_API FLAC__uint64 OggFLAC__stream_encoder_get_total_samples_estimate(const OggFLAC__StreamEncoder *encoder); - -/** Initialize the encoder instance. - * - * This flavor of initialization sets up the encoder to encode to a stream. - * I/O is performed via callbacks to the client. For encoding to a plain file - * via filename or open \c FILE*, OggFLAC__stream_encoder_init_file() and - * OggFLAC__stream_encoder_init_FILE() provide a simpler interface. - * - * This function should be called after OggFLAC__stream_encoder_new() and - * OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process() - * or OggFLAC__stream_encoder_process_interleaved(). - * initialization succeeded. - * - * The call to OggFLAC__stream_encoder_init_stream() currently will also immediately - * call the write callback several times, once with the \c fLaC signature, - * and once for each encoded metadata block. - * - * \note - * Unlike the FLAC stream encoder write callback, the Ogg stream - * encoder write callback will be called twice when writing each audio - * frame; once for the page header, and once for the page body. - * When writing the page header, the \a samples argument to the - * write callback will be \c 0. - * - * \param encoder An uninitialized encoder instance. - * \param read_callback See OggFLAC__StreamEncoderReadCallback. This - * pointer must not be \c NULL if \a seek_callback - * is non-NULL since they are both needed to be - * able to write data back to the Ogg FLAC stream - * in the post-encode phase. - * \param write_callback See FLAC__StreamEncoderWriteCallback. This - * pointer must not be \c NULL. - * \param seek_callback See FLAC__StreamEncoderSeekCallback. This - * pointer may be \c NULL if seeking is not - * supported. The encoder uses seeking to go back - * and write some some stream statistics to the - * STREAMINFO block; this is recommended but not - * necessary to create a valid FLAC stream. If - * \a seek_callback is not \c NULL then a - * \a tell_callback must also be supplied. - * 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. - * \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 - * this argument will be ignored. If - * \a seek_callback is not \c NULL then a - * \a tell_callback must also be supplied. - * 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. - * \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, - * this function is not necessary as the encoder - * will automatically seek back and update the - * STREAMINFO block. It may also be \c NULL if the - * client does not support seeking, since it will - * have no way of going back to update the - * STREAMINFO. However the client can still supply - * a callback if it would like to know the details - * from the STREAMINFO. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamEncoderInitStatus - * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamEncoderInitStatus for the meanings of other return values. - */ -OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_stream(OggFLAC__StreamEncoder *encoder, OggFLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data); - -/** Initialize the encoder instance. - * - * This flavor of initialization sets up the encoder to encode to a plain - * file. For non-stdio streams, you must use - * OggFLAC__stream_encoder_init_stream() and provide callbacks for the I/O. - * - * This function should be called after OggFLAC__stream_encoder_new() and - * OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process() - * or OggFLAC__stream_encoder_process_interleaved(). - * initialization succeeded. - * - * The call to OggFLAC__stream_encoder_init_stream() currently will also immediately - * call the write callback several times, once with the \c fLaC signature, - * and once for each encoded metadata block. - * - * \note - * Unlike the FLAC stream encoder write callback, the Ogg stream - * encoder write callback will be called twice when writing each audio - * frame; once for the page header, and once for the page body. - * When writing the page header, the \a samples argument to the - * write callback will be \c 0. - * - * \param encoder An uninitialized encoder instance. - * \param file An open file. The file should have been opened - * with mode \c "w+b" and rewound. The file - * becomes owned by the encoder and should not be - * manipulated by the client while encoding. - * Unless \a file is \c stdout, it will be closed - * when OggFLAC__stream_encoder_finish() is called. - * Note however that a proper SEEKTABLE cannot be - * created when encoding to \c stdout since it is - * not seekable. - * \param progress_callback See FLAC__StreamEncoderProgressCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code encoder != NULL \endcode - * \code file != NULL \endcode - * \retval FLAC__StreamEncoderInitStatus - * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamEncoderInitStatus for the meanings of other return values. - */ -OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_FILE(OggFLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); - -/** Initialize the encoder instance. - * - * This flavor of initialization sets up the encoder to encode to a plain - * file. If POSIX fopen() semantics are not sufficient (for example, - * with Unicode filenames on Windows), you must use - * OggFLAC__stream_encodeR_init_FILE(), or OggFLAC__stream_encoder_init_stream() - * and provide callbacks for the I/O. - * - * This function should be called after OggFLAC__stream_encoder_new() and - * OggFLAC__stream_encoder_set_*() but before OggFLAC__stream_encoder_process() - * or OggFLAC__stream_encoder_process_interleaved(). - * initialization succeeded. - * - * The call to OggFLAC__stream_encoder_init_stream() currently will also immediately - * call the write callback several times, once with the \c fLaC signature, - * and once for each encoded metadata block. - * - * \note - * Unlike the FLAC stream encoder write callback, the Ogg stream - * encoder write callback will be called twice when writing each audio - * frame; once for the page header, and once for the page body. - * When writing the page header, the \a samples argument to the - * write callback will be \c 0. - * - * \param encoder An uninitialized encoder instance. - * \param filename The name of the file to encode to. The file will - * be opened with fopen(). Use \c NULL to encode to - * \c stdout. Note however that a proper SEEKTABLE - * cannot be created when encoding to \c stdout since - * it is not seekable. - * \param progress_callback See FLAC__StreamEncoderProgressCallback. This - * pointer may be \c NULL if the callback is not - * desired. - * \param client_data This value will be supplied to callbacks in their - * \a client_data argument. - * \assert - * \code encoder != NULL \endcode - * \retval FLAC__StreamEncoderInitStatus - * \c FLAC__STREAM_ENCODER_INIT_STATUS_OK if initialization was successful; - * see FLAC__StreamEncoderInitStatus for the meanings of other return values. - */ -OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_file(OggFLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data); - -/** Finish the encoding process. - * Flushes the encoding buffer, releases resources, resets the encoder - * settings to their defaults, and returns the encoder state to - * OggFLAC__STREAM_ENCODER_UNINITIALIZED. Note that this can generate - * one or more write callbacks before returning. - * - * In the event of a prematurely-terminated encode, it is not strictly - * necessary to call this immediately before OggFLAC__stream_encoder_delete() - * but it is good practice to match every OggFLAC__stream_encoder_init() - * with an OggFLAC__stream_encoder_finish(). - * - * \param encoder An uninitialized encoder instance. - * \assert - * \code encoder != NULL \endcode - */ -OggFLAC_API void OggFLAC__stream_encoder_finish(OggFLAC__StreamEncoder *encoder); - -/** Submit data for encoding. - * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process(). - * - * \param encoder An initialized encoder instance in the OK state. - * \param buffer An array of pointers to each channel's signal. - * \param samples The number of samples in one channel. - * \assert - * \code encoder != NULL \endcode - * \code OggFLAC__stream_encoder_get_state(encoder) == OggFLAC__STREAM_ENCODER_OK \endcode - * \retval FLAC__bool - * \c true if successful, else \c false; in this case, check the - * encoder state with OggFLAC__stream_encoder_get_state() to see what - * went wrong. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_process(OggFLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples); - -/** Submit data for encoding. - * This is inherited from FLAC__StreamEncoder; see FLAC__stream_encoder_process_interleaved(). - * - * \param encoder An initialized encoder instance in the OK state. - * \param buffer An array of channel-interleaved data (see above). - * \param samples The number of samples in one channel, the same as for - * OggFLAC__stream_encoder_process(). For example, if - * encoding two channels, \c 1000 \a samples corresponds - * to a \a buffer of 2000 values. - * \assert - * \code encoder != NULL \endcode - * \code OggFLAC__stream_encoder_get_state(encoder) == OggFLAC__STREAM_ENCODER_OK \endcode - * \retval FLAC__bool - * \c true if successful, else \c false; in this case, check the - * encoder state with OggFLAC__stream_encoder_get_state() to see what - * went wrong. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_process_interleaved(OggFLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples); - -/* \} */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/test_libs_common/Makefile.am b/include/test_libs_common/Makefile.am index 8060b67f..a0342dc1 100644 --- a/include/test_libs_common/Makefile.am +++ b/include/test_libs_common/Makefile.am @@ -2,12 +2,6 @@ AUTOMAKE_OPTIONS = foreign -if FLaC__HAS_OGG -OGGFLAC_DIST = \ - file_utils_oggflac.h -endif - EXTRA_DIST = \ file_utils_flac.h \ - metadata_utils.h \ - $(OGGFLAC_DIST) + metadata_utils.h diff --git a/include/test_libs_common/file_utils_flac.h b/include/test_libs_common/file_utils_flac.h index 4b69568d..c04c5eb5 100644 --- a/include/test_libs_common/file_utils_flac.h +++ b/include/test_libs_common/file_utils_flac.h @@ -27,6 +27,8 @@ #include "FLAC/format.h" #include <sys/types.h> /* for off_t */ -FLAC__bool file_utils__generate_flacfile(const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata); +extern const long file_utils__ogg_serial_number; + +FLAC__bool file_utils__generate_flacfile(FLAC__bool is_ogg, const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata); #endif diff --git a/include/test_libs_common/file_utils_oggflac.h b/include/test_libs_common/file_utils_oggflac.h deleted file mode 100644 index d59127fb..00000000 --- a/include/test_libs_common/file_utils_oggflac.h +++ /dev/null @@ -1,34 +0,0 @@ -/* test_libOggFLAC - Unit tester for libOggFLAC - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef OggFLAC__TEST_LIBOGGFLAC_FILE_UTILS_H -#define OggFLAC__TEST_LIBOGGFLAC_FILE_UTILS_H - -/* needed because of off_t */ -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include "FLAC/format.h" -#include <sys/types.h> /* for off_t */ - -extern const long file_utils__serial_number; - -FLAC__bool file_utils__generate_oggflacfile(const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata); - -#endif diff --git a/src/Makefile.am b/src/Makefile.am index 2d97fe25..9de7d7de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,15 +19,9 @@ if FLaC__HAS_XMMS XMMS_DIRS = plugin_common plugin_xmms endif -if FLaC__HAS_OGG -OGGFLAC_DIRS = libOggFLAC libOggFLAC++ -OGGFLAC_TEST_DIRS = test_libOggFLAC test_libOggFLAC++ -endif - SUBDIRS = \ libFLAC \ libFLAC++ \ - $(OGGFLAC_DIRS) \ share \ flac \ metaflac \ @@ -38,7 +32,6 @@ SUBDIRS = \ test_libs_common \ test_libFLAC \ test_libFLAC++ \ - $(OGGFLAC_TEST_DIRS) \ test_seeking \ test_streams diff --git a/src/Makefile.lite b/src/Makefile.lite index f2c2bd27..3fc51104 100644 --- a/src/Makefile.lite +++ b/src/Makefile.lite @@ -15,8 +15,8 @@ # restrictive of those mentioned above. See the file COPYING.Xiph in this # distribution. -.PHONY: all flac libFLAC libFLAC++ libOggFLAC libOggFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_libOggFLAC test_libOggFLAC++ test_seeking test_streams -all: flac libFLAC libFLAC++ libOggFLAC libOggFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_libOggFLAC test_libOggFLAC++ test_seeking test_streams +.PHONY: all flac libFLAC libFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_seeking test_streams +all: flac libFLAC libFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_seeking test_streams DEFAULT_CONFIG = release @@ -30,15 +30,13 @@ debug : all valgrind: all release : all -flac libFLAC libFLAC++ libOggFLAC libOggFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_libOggFLAC test_libOggFLAC++ test_seeking test_streams: +flac libFLAC libFLAC++ metaflac plugin_common plugin_xmms share test_grabbag test_libs_common test_libFLAC test_libFLAC++ test_seeking test_streams: (cd $@ ; $(MAKE) -f Makefile.lite $(CONFIG)) clean: -(cd flac ; $(MAKE) -f Makefile.lite clean) -(cd libFLAC ; $(MAKE) -f Makefile.lite clean) -(cd libFLAC++ ; $(MAKE) -f Makefile.lite clean) - -(cd libOggFLAC ; $(MAKE) -f Makefile.lite clean) - -(cd libOggFLAC++ ; $(MAKE) -f Makefile.lite clean) -(cd metaflac ; $(MAKE) -f Makefile.lite clean) -(cd plugin_common ; $(MAKE) -f Makefile.lite clean) -(cd plugin_xmms ; $(MAKE) -f Makefile.lite clean) @@ -47,15 +45,11 @@ clean: -(cd test_libs_common ; $(MAKE) -f Makefile.lite clean) -(cd test_libFLAC ; $(MAKE) -f Makefile.lite clean) -(cd test_libFLAC++ ; $(MAKE) -f Makefile.lite clean) - -(cd test_libOggFLAC ; $(MAKE) -f Makefile.lite clean) - -(cd test_libOggFLAC++ ; $(MAKE) -f Makefile.lite clean) -(cd test_seeking ; $(MAKE) -f Makefile.lite clean) -(cd test_streams ; $(MAKE) -f Makefile.lite clean) -flac: libFLAC libOggFLAC share +flac: libFLAC share libFLAC++: libFLAC -libOggFLAC++: libFLAC -libOggFLAC: libFLAC metaflac: libFLAC share plugin_common: libFLAC plugin_xmms: libFLAC plugin_common @@ -63,7 +57,5 @@ share: libFLAC test_grabbag: share test_libFLAC++: libFLAC libFLAC++ test_libs_common test_libFLAC: libFLAC test_libs_common -test_libOggFLAC++: libFLAC libOggFLAC libOggFLAC++ test_libs_common -test_libOggFLAC: libFLAC libOggFLAC test_libs_common -test_seeking: libFLAC libOggFLAC +test_seeking: libFLAC test_streams: libFLAC diff --git a/src/flac/Makefile.am b/src/flac/Makefile.am index 8aed4eed..2eedfa6a 100644 --- a/src/flac/Makefile.am +++ b/src/flac/Makefile.am @@ -19,10 +19,6 @@ bin_PROGRAMS = flac AM_CFLAGS = @OGG_CFLAGS@ -if FLaC__HAS_OGG -NEED_OGGFLAC_LIB = $(top_builddir)/src/libOggFLAC/libOggFLAC.la -endif - EXTRA_DIST = \ Makefile.lite \ flac.dsp @@ -43,7 +39,6 @@ flac_SOURCES = \ vorbiscomment.h flac_LDADD = \ - $(NEED_OGGFLAC_LIB) \ $(top_builddir)/src/share/grabbag/libgrabbag.la \ $(top_builddir)/src/share/getopt/libgetopt.a \ $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ diff --git a/src/flac/Makefile.lite b/src/flac/Makefile.lite index 807c6ba3..cb63a403 100644 --- a/src/flac/Makefile.lite +++ b/src/flac/Makefile.lite @@ -27,9 +27,9 @@ PROGRAM_NAME = flac INCLUDES = -I./include -I$(topdir)/include -I$(OGG_INCLUDE_DIR) ifeq ($(DARWIN_BUILD),yes) -EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libOggFLAC.a $(libdir)/libFLAC.a $(libdir)/libreplaygain_analysis.a $(libdir)/libreplaygain_synthesis.a $(libdir)/libgetopt.a $(libdir)/libutf8.a $(OGG_LIB_DIR)/libogg.a -L$(ICONV_LIB_DIR) -liconv -lm +EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libFLAC.a $(libdir)/libreplaygain_analysis.a $(libdir)/libreplaygain_synthesis.a $(libdir)/libgetopt.a $(libdir)/libutf8.a $(OGG_LIB_DIR)/libogg.a -L$(ICONV_LIB_DIR) -liconv -lm else -LIBS = -lgrabbag -lOggFLAC -lFLAC -lreplaygain_analysis -lreplaygain_synthesis -lgetopt -lutf8 -L$(OGG_LIB_DIR) -logg -lm +LIBS = -lgrabbag -lFLAC -lreplaygain_analysis -lreplaygain_synthesis -lgetopt -lutf8 -L$(OGG_LIB_DIR) -logg -lm endif SRCS_C = \ diff --git a/src/flac/decode.c b/src/flac/decode.c index fec97d69..157e0606 100644 --- a/src/flac/decode.c +++ b/src/flac/decode.c @@ -42,10 +42,6 @@ #include "share/replaygain_synthesis.h" #include "decode.h" -#ifdef FLAC__HAS_OGG -#include "OggFLAC/stream_decoder.h" -#endif - typedef struct { #ifdef FLAC__HAS_OGG FLAC__bool is_ogg; @@ -90,12 +86,7 @@ typedef struct { unsigned sample_rate; FLAC__uint32 channel_mask; - union { - FLAC__StreamDecoder *flac; -#ifdef FLAC__HAS_OGG - OggFLAC__StreamDecoder *ogg; -#endif - } decoder; + FLAC__StreamDecoder *decoder; FILE *fout; } DecoderSession; @@ -287,10 +278,7 @@ FLAC__bool DecoderSession_construct(DecoderSession *d, FLAC__bool is_ogg, FLAC__ d->sample_rate = 0; d->channel_mask = 0; - d->decoder.flac = 0; -#ifdef FLAC__HAS_OGG - d->decoder.ogg = 0; -#endif + d->decoder = 0; d->fout = 0; /* initialized with an open file later if necessary */ @@ -331,52 +319,36 @@ FLAC__bool DecoderSession_init_decoder(DecoderSession *decoder_session, decode_o is_big_endian_host_ = (*((FLAC__byte*)(&test)))? false : true; -#ifdef FLAC__HAS_OGG - if(decoder_session->is_ogg) { - decoder_session->decoder.ogg = OggFLAC__stream_decoder_new(); + decoder_session->decoder = FLAC__stream_decoder_new(); - if(0 == decoder_session->decoder.ogg) { - flac__utils_printf(stderr, 1, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename); - return false; - } + if(0 == decoder_session->decoder) { + flac__utils_printf(stderr, 1, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename); + return false; + } + + FLAC__stream_decoder_set_md5_checking(decoder_session->decoder, true); + if (0 != decoder_session->cue_specification) + FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder, FLAC__METADATA_TYPE_CUESHEET); + if (decoder_session->replaygain.spec.apply) + FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); - OggFLAC__stream_decoder_set_md5_checking(decoder_session->decoder.ogg, true); +#ifdef FLAC__HAS_OGG + if(decoder_session->is_ogg) { if(!decode_options.use_first_serial_number) - OggFLAC__stream_decoder_set_serial_number(decoder_session->decoder.ogg, decode_options.serial_number); - if (0 != decoder_session->cue_specification) - OggFLAC__stream_decoder_set_metadata_respond(decoder_session->decoder.ogg, FLAC__METADATA_TYPE_CUESHEET); - if (decoder_session->replaygain.spec.apply) - OggFLAC__stream_decoder_set_metadata_respond(decoder_session->decoder.ogg, FLAC__METADATA_TYPE_VORBIS_COMMENT); - - init_status = OggFLAC__stream_decoder_init_file(decoder_session->decoder.ogg, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session); - if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - print_error_with_init_status(decoder_session, "ERROR initializing decoder", init_status); - return false; - } + FLAC__stream_decoder_set_serial_number(decoder_session->decoder, decode_options.serial_number); + init_status = FLAC__stream_decoder_init_ogg_file(decoder_session->decoder, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session); } else #else (void)decode_options; #endif { - decoder_session->decoder.flac = FLAC__stream_decoder_new(); - - if(0 == decoder_session->decoder.flac) { - flac__utils_printf(stderr, 1, "%s: ERROR creating the decoder instance\n", decoder_session->inbasefilename); - return false; - } - - FLAC__stream_decoder_set_md5_checking(decoder_session->decoder.flac, true); - if (0 != decoder_session->cue_specification) - FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder.flac, FLAC__METADATA_TYPE_CUESHEET); - if (decoder_session->replaygain.spec.apply) - FLAC__stream_decoder_set_metadata_respond(decoder_session->decoder.flac, FLAC__METADATA_TYPE_VORBIS_COMMENT); + init_status = FLAC__stream_decoder_init_file(decoder_session->decoder, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session); + } - init_status = FLAC__stream_decoder_init_file(decoder_session->decoder.flac, strcmp(infilename, "-")? infilename : 0, write_callback, metadata_callback, error_callback, /*client_data=*/decoder_session); - if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { - print_error_with_init_status(decoder_session, "ERROR initializing decoder", init_status); - return false; - } + if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { + print_error_with_init_status(decoder_session, "ERROR initializing decoder", init_status); + return false; } return true; @@ -384,35 +356,18 @@ FLAC__bool DecoderSession_init_decoder(DecoderSession *decoder_session, decode_o FLAC__bool DecoderSession_process(DecoderSession *d) { -#ifdef FLAC__HAS_OGG - if(d->is_ogg) { - if(!OggFLAC__stream_decoder_process_until_end_of_metadata(d->decoder.ogg)) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR while decoding metadata"); - return false; - } - if(OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_OK && OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_END_OF_STREAM) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR during metadata decoding"); - if(!d->continue_through_decode_errors) - return false; - } + if(!FLAC__stream_decoder_process_until_end_of_metadata(d->decoder)) { + flac__utils_printf(stderr, 2, "\n"); + print_error_with_state(d, "ERROR while decoding metadata"); + return false; } - else -#endif - { - if(!FLAC__stream_decoder_process_until_end_of_metadata(d->decoder.flac)) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR while decoding metadata"); + if(FLAC__stream_decoder_get_state(d->decoder) > FLAC__STREAM_DECODER_END_OF_STREAM) { + flac__utils_printf(stderr, 2, "\n"); + print_error_with_state(d, "ERROR during metadata decoding"); + if(!d->continue_through_decode_errors) return false; - } - if(FLAC__stream_decoder_get_state(d->decoder.flac) > FLAC__STREAM_DECODER_END_OF_STREAM) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR during metadata decoding"); - if(!d->continue_through_decode_errors) - return false; - } } + if(d->abort_flag) return false; @@ -457,72 +412,21 @@ FLAC__bool DecoderSession_process(DecoderSession *d) if(d->skip_specification->value.samples > 0) { const FLAC__uint64 skip = (FLAC__uint64)d->skip_specification->value.samples; -#ifdef FLAC__HAS_OGG - if(d->is_ogg) { - if(!OggFLAC__stream_decoder_seek_absolute(d->decoder.ogg, skip)) { - print_error_with_state(d, "ERROR seeking while skipping bytes"); - return false; - } - if(!OggFLAC__stream_decoder_process_until_end_of_stream(d->decoder.ogg) && !d->aborting_due_to_until) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR while decoding frames"); - return false; - } - if(OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_OK && OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR during decoding"); - return false; - } - } - else -#endif - { - if(!FLAC__stream_decoder_seek_absolute(d->decoder.flac, skip)) { - print_error_with_state(d, "ERROR seeking while skipping bytes"); - return false; - } - if(!FLAC__stream_decoder_process_until_end_of_stream(d->decoder.flac) && !d->aborting_due_to_until) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR while decoding frames"); - return false; - } - if(FLAC__stream_decoder_get_state(d->decoder.flac) > FLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR during decoding"); - return false; - } + if(!FLAC__stream_decoder_seek_absolute(d->decoder, skip)) { + print_error_with_state(d, "ERROR seeking while skipping bytes"); + return false; } } - else { -#ifdef FLAC__HAS_OGG - if(d->is_ogg) { - if(!OggFLAC__stream_decoder_process_until_end_of_stream(d->decoder.ogg) && !d->aborting_due_to_until) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR while decoding data"); - if(!d->continue_through_decode_errors) - return false; - } - if(OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_OK && OggFLAC__stream_decoder_get_state(d->decoder.ogg) != OggFLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR during decoding"); - return false; - } - } - else -#endif - { - if(!FLAC__stream_decoder_process_until_end_of_stream(d->decoder.flac) && !d->aborting_due_to_until) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR while decoding data"); - if(!d->continue_through_decode_errors) - return false; - } - if(FLAC__stream_decoder_get_state(d->decoder.flac) > FLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) { - flac__utils_printf(stderr, 2, "\n"); - print_error_with_state(d, "ERROR during decoding"); - return false; - } - } + if(!FLAC__stream_decoder_process_until_end_of_stream(d->decoder) && !d->aborting_due_to_until) { + flac__utils_printf(stderr, 2, "\n"); + print_error_with_state(d, "ERROR while decoding data"); + if(!d->continue_through_decode_errors) + return false; + } + if(FLAC__stream_decoder_get_state(d->decoder) > FLAC__STREAM_DECODER_END_OF_STREAM && !d->aborting_due_to_until) { + flac__utils_printf(stderr, 2, "\n"); + print_error_with_state(d, "ERROR during decoding"); + return false; } if(!d->analysis_mode && !d->test_only && (d->is_wave_out || d->is_aiff_out) && ((d->total_samples * d->channels * ((d->bps+7)/8)) & 1)) { @@ -542,22 +446,10 @@ int DecoderSession_finish_ok(DecoderSession *d) { FLAC__bool ok = true, md5_failure = false; -#ifdef FLAC__HAS_OGG - if(d->is_ogg) { - if(d->decoder.ogg) { - md5_failure = !OggFLAC__stream_decoder_finish(d->decoder.ogg) && !d->aborting_due_to_until; - print_stats(d); - OggFLAC__stream_decoder_delete(d->decoder.ogg); - } - } - else -#endif - { - if(d->decoder.flac) { - md5_failure = !FLAC__stream_decoder_finish(d->decoder.flac) && !d->aborting_due_to_until; - print_stats(d); - FLAC__stream_decoder_delete(d->decoder.flac); - } + if(d->decoder) { + md5_failure = !FLAC__stream_decoder_finish(d->decoder) && !d->aborting_due_to_until; + print_stats(d); + FLAC__stream_decoder_delete(d->decoder); } if(d->analysis_mode) flac__analyze_finish(d->aopts); @@ -580,20 +472,9 @@ int DecoderSession_finish_ok(DecoderSession *d) int DecoderSession_finish_error(DecoderSession *d) { -#ifdef FLAC__HAS_OGG - if(d->is_ogg) { - if(d->decoder.ogg) { - OggFLAC__stream_decoder_finish(d->decoder.ogg); - OggFLAC__stream_decoder_delete(d->decoder.ogg); - } - } - else -#endif - { - if(d->decoder.flac) { - FLAC__stream_decoder_finish(d->decoder.flac); - FLAC__stream_decoder_delete(d->decoder.flac); - } + if(d->decoder) { + FLAC__stream_decoder_finish(d->decoder); + FLAC__stream_decoder_delete(d->decoder); } if(d->analysis_mode) flac__analyze_finish(d->aopts); @@ -1218,21 +1099,9 @@ void print_error_with_init_status(const DecoderSession *d, const char *message, void print_error_with_state(const DecoderSession *d, const char *message) { const int ilen = strlen(d->inbasefilename) + 1; - const char *state_string; flac__utils_printf(stderr, 1, "\n%s: %s\n", d->inbasefilename, message); - -#ifdef FLAC__HAS_OGG - if(d->is_ogg) { - state_string = OggFLAC__stream_decoder_get_resolved_state_string(d->decoder.ogg); - } - else -#endif - { - state_string = FLAC__stream_decoder_get_resolved_state_string(d->decoder.flac); - } - - flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", state_string); + flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", FLAC__stream_decoder_get_resolved_state_string(d->decoder)); /* print out some more info for some errors: */ if (d->aborting_due_to_unparseable) { diff --git a/src/flac/encode.c b/src/flac/encode.c index c85e2fad..fa414f14 100644 --- a/src/flac/encode.c +++ b/src/flac/encode.c @@ -43,10 +43,6 @@ #include "share/grabbag.h" #include "encode.h" -#ifdef FLAC__HAS_OGG -#include "OggFLAC/stream_encoder.h" -#endif - #ifdef min #undef min #endif @@ -82,12 +78,7 @@ typedef struct { unsigned blocksize; unsigned stats_mask; - union { - FLAC__StreamEncoder *flac; -#ifdef FLAC__HAS_OGG - OggFLAC__StreamEncoder *ogg; -#endif - } encoder; + FLAC__StreamEncoder *encoder; FILE *fin; FLAC__StreamMetadata *seek_table_template; @@ -124,11 +115,6 @@ static FLAC__int32 *input_[FLAC__MAX_CHANNELS]; extern FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); extern FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); extern FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); -#ifdef FLAC__HAS_OGG -extern FLAC__bool OggFLAC__stream_encoder_disable_constant_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value); -extern FLAC__bool OggFLAC__stream_encoder_disable_fixed_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value); -extern FLAC__bool OggFLAC__stream_encoder_disable_verbatim_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value); -#endif /* * local routines @@ -1548,10 +1534,7 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_ e->blocksize = 0; e->stats_mask = 0; - e->encoder.flac = 0; -#ifdef FLAC__HAS_OGG - e->encoder.ogg = 0; -#endif + e->encoder = 0; e->fin = infile; e->seek_table_template = 0; @@ -1561,19 +1544,8 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_ return false; } -#ifdef FLAC__HAS_OGG - if(e->use_ogg) { - e->encoder.ogg = OggFLAC__stream_encoder_new(); - if(0 == e->encoder.ogg) { - flac__utils_printf(stderr, 1, "%s: ERROR creating the encoder instance\n", e->inbasefilename); - EncoderSession_destroy(e); - return false; - } - } - else -#endif - e->encoder.flac = FLAC__stream_encoder_new(); - if(0 == e->encoder.flac) { + e->encoder = FLAC__stream_encoder_new(); + if(0 == e->encoder) { flac__utils_printf(stderr, 1, "%s: ERROR creating the encoder instance\n", e->inbasefilename); EncoderSession_destroy(e); return false; @@ -1587,18 +1559,9 @@ void EncoderSession_destroy(EncoderSession *e) if(e->fin != stdin) fclose(e->fin); -#ifdef FLAC__HAS_OGG - if(e->use_ogg) { - if(0 != e->encoder.ogg) { - OggFLAC__stream_encoder_delete(e->encoder.ogg); - e->encoder.ogg = 0; - } - } - else -#endif - if(0 != e->encoder.flac) { - FLAC__stream_encoder_delete(e->encoder.flac); - e->encoder.flac = 0; + if(0 != e->encoder) { + FLAC__stream_encoder_delete(e->encoder); + e->encoder = 0; } if(0 != e->seek_table_template) { @@ -1612,18 +1575,9 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a FLAC__StreamEncoderState fse_state = FLAC__STREAM_ENCODER_OK; int ret = 0; -#ifdef FLAC__HAS_OGG - if(e->use_ogg) { - if(e->encoder.ogg) { - fse_state = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(e->encoder.ogg); - OggFLAC__stream_encoder_finish(e->encoder.ogg); - } - } - else -#endif - if(e->encoder.flac) { - fse_state = FLAC__stream_encoder_get_state(e->encoder.flac); - FLAC__stream_encoder_finish(e->encoder.flac); + if(e->encoder) { + fse_state = FLAC__stream_encoder_get_state(e->encoder); + FLAC__stream_encoder_finish(e->encoder); } if(e->total_samples_to_encode > 0) { @@ -1651,28 +1605,12 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a int EncoderSession_finish_error(EncoderSession *e) { - FLAC__StreamEncoderState fse_state; - -#ifdef FLAC__HAS_OGG - FLAC__ASSERT(e->encoder.ogg || e->encoder.flac); -#else - FLAC__ASSERT(e->encoder.flac); -#endif + FLAC__ASSERT(e->encoder); if(e->total_samples_to_encode > 0) flac__utils_printf(stderr, 2, "\n"); -#ifdef FLAC__HAS_OGG - if(e->use_ogg) { - fse_state = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(e->encoder.ogg); - } - else -#endif - { - fse_state = FLAC__stream_encoder_get_state(e->encoder.flac); - } - - if(fse_state == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) + if(FLAC__stream_encoder_get_state(e->encoder) == FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) print_verify_error(e); else if(e->outputfile_opened) /* only want to delete the file if we opened it; otherwise it could be an existing file and our overwrite failed */ @@ -1956,84 +1894,52 @@ FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t optio e->blocksize = options.blocksize; e->stats_mask = (options.do_exhaustive_model_search || options.do_qlp_coeff_prec_search)? 0x0f : 0x3f; + FLAC__stream_encoder_set_verify(e->encoder, options.verify); + FLAC__stream_encoder_set_streamable_subset(e->encoder, !options.lax); + FLAC__stream_encoder_set_do_mid_side_stereo(e->encoder, options.do_mid_side); + FLAC__stream_encoder_set_loose_mid_side_stereo(e->encoder, options.loose_mid_side); + FLAC__stream_encoder_set_channels(e->encoder, channels); + FLAC__stream_encoder_set_bits_per_sample(e->encoder, bps); + FLAC__stream_encoder_set_sample_rate(e->encoder, sample_rate); + FLAC__stream_encoder_set_blocksize(e->encoder, options.blocksize); + FLAC__stream_encoder_set_apodization(e->encoder, options.apodizations); + FLAC__stream_encoder_set_max_lpc_order(e->encoder, options.max_lpc_order); + FLAC__stream_encoder_set_qlp_coeff_precision(e->encoder, options.qlp_coeff_precision); + FLAC__stream_encoder_set_do_qlp_coeff_prec_search(e->encoder, options.do_qlp_coeff_prec_search); + FLAC__stream_encoder_set_do_escape_coding(e->encoder, options.do_escape_coding); + FLAC__stream_encoder_set_do_exhaustive_model_search(e->encoder, options.do_exhaustive_model_search); + FLAC__stream_encoder_set_min_residual_partition_order(e->encoder, options.min_residual_partition_order); + FLAC__stream_encoder_set_max_residual_partition_order(e->encoder, options.max_residual_partition_order); + FLAC__stream_encoder_set_rice_parameter_search_dist(e->encoder, options.rice_parameter_search_dist); + FLAC__stream_encoder_set_total_samples_estimate(e->encoder, e->total_samples_to_encode); + FLAC__stream_encoder_set_metadata(e->encoder, (num_metadata > 0)? metadata : 0, num_metadata); + + FLAC__stream_encoder_disable_constant_subframes(e->encoder, options.debug.disable_constant_subframes); + FLAC__stream_encoder_disable_fixed_subframes(e->encoder, options.debug.disable_fixed_subframes); + FLAC__stream_encoder_disable_verbatim_subframes(e->encoder, options.debug.disable_verbatim_subframes); + #ifdef FLAC__HAS_OGG if(e->use_ogg) { - OggFLAC__stream_encoder_set_serial_number(e->encoder.ogg, options.serial_number); - OggFLAC__stream_encoder_set_verify(e->encoder.ogg, options.verify); - OggFLAC__stream_encoder_set_streamable_subset(e->encoder.ogg, !options.lax); - OggFLAC__stream_encoder_set_do_mid_side_stereo(e->encoder.ogg, options.do_mid_side); - OggFLAC__stream_encoder_set_loose_mid_side_stereo(e->encoder.ogg, options.loose_mid_side); - OggFLAC__stream_encoder_set_channels(e->encoder.ogg, channels); - OggFLAC__stream_encoder_set_bits_per_sample(e->encoder.ogg, bps); - OggFLAC__stream_encoder_set_sample_rate(e->encoder.ogg, sample_rate); - OggFLAC__stream_encoder_set_blocksize(e->encoder.ogg, options.blocksize); - OggFLAC__stream_encoder_set_apodization(e->encoder.ogg, options.apodizations); - OggFLAC__stream_encoder_set_max_lpc_order(e->encoder.ogg, options.max_lpc_order); - OggFLAC__stream_encoder_set_qlp_coeff_precision(e->encoder.ogg, options.qlp_coeff_precision); - OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(e->encoder.ogg, options.do_qlp_coeff_prec_search); - OggFLAC__stream_encoder_set_do_escape_coding(e->encoder.ogg, options.do_escape_coding); - OggFLAC__stream_encoder_set_do_exhaustive_model_search(e->encoder.ogg, options.do_exhaustive_model_search); - OggFLAC__stream_encoder_set_min_residual_partition_order(e->encoder.ogg, options.min_residual_partition_order); - OggFLAC__stream_encoder_set_max_residual_partition_order(e->encoder.ogg, options.max_residual_partition_order); - OggFLAC__stream_encoder_set_rice_parameter_search_dist(e->encoder.ogg, options.rice_parameter_search_dist); - OggFLAC__stream_encoder_set_total_samples_estimate(e->encoder.ogg, e->total_samples_to_encode); - OggFLAC__stream_encoder_set_metadata(e->encoder.ogg, (num_metadata > 0)? metadata : 0, num_metadata); - - OggFLAC__stream_encoder_disable_constant_subframes(e->encoder.ogg, options.debug.disable_constant_subframes); - OggFLAC__stream_encoder_disable_fixed_subframes(e->encoder.ogg, options.debug.disable_fixed_subframes); - OggFLAC__stream_encoder_disable_verbatim_subframes(e->encoder.ogg, options.debug.disable_verbatim_subframes); - - init_status = OggFLAC__stream_encoder_init_file(e->encoder.ogg, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e); - if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { - print_error_with_init_status(e, "ERROR initializing encoder", init_status); - if(OggFLAC__stream_encoder_get_state(e->encoder.ogg) != OggFLAC__STREAM_ENCODER_IO_ERROR) - e->outputfile_opened = true; - if(0 != cuesheet) - FLAC__metadata_object_delete(cuesheet); - return false; - } - else - e->outputfile_opened = true; + FLAC__stream_encoder_set_serial_number(e->encoder, options.serial_number); + + init_status = FLAC__stream_encoder_init_ogg_file(e->encoder, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e); } else #endif { - FLAC__stream_encoder_set_verify(e->encoder.flac, options.verify); - FLAC__stream_encoder_set_streamable_subset(e->encoder.flac, !options.lax); - FLAC__stream_encoder_set_do_mid_side_stereo(e->encoder.flac, options.do_mid_side); - FLAC__stream_encoder_set_loose_mid_side_stereo(e->encoder.flac, options.loose_mid_side); - FLAC__stream_encoder_set_channels(e->encoder.flac, channels); - FLAC__stream_encoder_set_bits_per_sample(e->encoder.flac, bps); - FLAC__stream_encoder_set_sample_rate(e->encoder.flac, sample_rate); - FLAC__stream_encoder_set_blocksize(e->encoder.flac, options.blocksize); - FLAC__stream_encoder_set_apodization(e->encoder.flac, options.apodizations); - FLAC__stream_encoder_set_max_lpc_order(e->encoder.flac, options.max_lpc_order); - FLAC__stream_encoder_set_qlp_coeff_precision(e->encoder.flac, options.qlp_coeff_precision); - FLAC__stream_encoder_set_do_qlp_coeff_prec_search(e->encoder.flac, options.do_qlp_coeff_prec_search); - FLAC__stream_encoder_set_do_escape_coding(e->encoder.flac, options.do_escape_coding); - FLAC__stream_encoder_set_do_exhaustive_model_search(e->encoder.flac, options.do_exhaustive_model_search); - FLAC__stream_encoder_set_min_residual_partition_order(e->encoder.flac, options.min_residual_partition_order); - FLAC__stream_encoder_set_max_residual_partition_order(e->encoder.flac, options.max_residual_partition_order); - FLAC__stream_encoder_set_rice_parameter_search_dist(e->encoder.flac, options.rice_parameter_search_dist); - FLAC__stream_encoder_set_total_samples_estimate(e->encoder.flac, e->total_samples_to_encode); - FLAC__stream_encoder_set_metadata(e->encoder.flac, (num_metadata > 0)? metadata : 0, num_metadata); - - FLAC__stream_encoder_disable_constant_subframes(e->encoder.flac, options.debug.disable_constant_subframes); - FLAC__stream_encoder_disable_fixed_subframes(e->encoder.flac, options.debug.disable_fixed_subframes); - FLAC__stream_encoder_disable_verbatim_subframes(e->encoder.flac, options.debug.disable_verbatim_subframes); - - init_status = FLAC__stream_encoder_init_file(e->encoder.flac, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e); - if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { - print_error_with_init_status(e, "ERROR initializing encoder", init_status); - if(FLAC__stream_encoder_get_state(e->encoder.flac) != FLAC__STREAM_ENCODER_IO_ERROR) - e->outputfile_opened = true; - if(0 != cuesheet) - FLAC__metadata_object_delete(cuesheet); - return false; - } - else + init_status = FLAC__stream_encoder_init_file(e->encoder, e->is_stdout? 0 : e->outfilename, encoder_progress_callback, /*client_data=*/e); + } + + if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { + print_error_with_init_status(e, "ERROR initializing encoder", init_status); + if(FLAC__stream_encoder_get_state(e->encoder) != FLAC__STREAM_ENCODER_IO_ERROR) e->outputfile_opened = true; + if(0 != cuesheet) + FLAC__metadata_object_delete(cuesheet); + return false; } + else + e->outputfile_opened = true; if(0 != cuesheet) FLAC__metadata_object_delete(cuesheet); @@ -2049,12 +1955,7 @@ FLAC__bool EncoderSession_process(EncoderSession *e, const FLAC__int32 * const b } } -#ifdef FLAC__HAS_OGG - if(e->use_ogg) - return OggFLAC__stream_encoder_process(e->encoder.ogg, buffer, samples); - else -#endif - return FLAC__stream_encoder_process(e->encoder.flac, buffer, samples); + return FLAC__stream_encoder_process(e->encoder, buffer, samples); } FLAC__bool convert_to_seek_table_template(const char *requested_seek_points, int num_requested_seek_points, FLAC__StreamMetadata *cuesheet, EncoderSession *e) @@ -2489,33 +2390,18 @@ void print_error_with_init_status(const EncoderSession *e, const char *message, flac__utils_printf(stderr, 1, "%*s init_status = %s\n", ilen, "", FLAC__StreamEncoderInitStatusString[init_status]); if(init_status == FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR) { -#ifdef FLAC__HAS_OGG - if(e->use_ogg) - state_string = OggFLAC__stream_encoder_get_resolved_state_string(e->encoder.ogg); - else -#endif - state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder.flac); + state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder); flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", state_string); /* print out some more info for some errors: */ - if( - 0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR]) -#ifdef FLAC__HAS_OGG - || 0 == strcmp(state_string, OggFLAC__StreamEncoderStateString[OggFLAC__STREAM_ENCODER_CLIENT_ERROR]) -#endif - ) { + if(0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR])) { flac__utils_printf(stderr, 1, "\n" "An error occurred while writing; the most common cause is that the disk is full.\n" ); } - else if( - 0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_IO_ERROR]) -#ifdef FLAC__HAS_OGG - || 0 == strcmp(state_string, OggFLAC__StreamEncoderStateString[OggFLAC__STREAM_ENCODER_IO_ERROR]) -#endif - ) { + else if(0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_IO_ERROR])) { flac__utils_printf(stderr, 1, "\n" "An error occurred opening the output file; it is likely that the output\n" @@ -2542,22 +2428,12 @@ void print_error_with_state(const EncoderSession *e, const char *message) flac__utils_printf(stderr, 1, "\n%s: %s\n", e->inbasefilename, message); -#ifdef FLAC__HAS_OGG - if(e->use_ogg) - state_string = OggFLAC__stream_encoder_get_resolved_state_string(e->encoder.ogg); - else -#endif - state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder.flac); + state_string = FLAC__stream_encoder_get_resolved_state_string(e->encoder); flac__utils_printf(stderr, 1, "%*s state = %s\n", ilen, "", state_string); /* print out some more info for some errors: */ - if( - 0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR]) -#ifdef FLAC__HAS_OGG - || 0 == strcmp(state_string, OggFLAC__StreamEncoderStateString[OggFLAC__STREAM_ENCODER_CLIENT_ERROR]) -#endif - ) { + if(0 == strcmp(state_string, FLAC__StreamEncoderStateString[FLAC__STREAM_ENCODER_CLIENT_ERROR])) { flac__utils_printf(stderr, 1, "\n" "An error occurred while writing; the most common cause is that the disk is full.\n" @@ -2574,12 +2450,7 @@ void print_verify_error(EncoderSession *e) FLAC__int32 expected; FLAC__int32 got; -#ifdef FLAC__HAS_OGG - if(e->use_ogg) - OggFLAC__stream_encoder_get_verify_decoder_error_stats(e->encoder.ogg, &absolute_sample, &frame_number, &channel, &sample, &expected, &got); - else -#endif - FLAC__stream_encoder_get_verify_decoder_error_stats(e->encoder.flac, &absolute_sample, &frame_number, &channel, &sample, &expected, &got); + FLAC__stream_encoder_get_verify_decoder_error_stats(e->encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got); flac__utils_printf(stderr, 1, "%s: ERROR: mismatch in decoded data, verify FAILED!\n", e->inbasefilename); flac__utils_printf(stderr, 1, " Absolute sample=%u, frame=%u, channel=%u, sample=%u, expected %d, got %d\n", (unsigned)absolute_sample, frame_number, channel, sample, expected, got); diff --git a/src/flac/flac.dsp b/src/flac/flac.dsp index 6a3aa09f..f91a4d0c 100644 --- a/src/flac/flac.dsp +++ b/src/flac/flac.dsp @@ -51,7 +51,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\libOggFLAC_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\replaygain_synthesis_static.lib ..\..\obj\release\lib\getopt_static.lib ..\..\obj\release\lib\utf8_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\replaygain_synthesis_static.lib ..\..\obj\release\lib\getopt_static.lib ..\..\obj\release\lib\utf8_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "flac - Win32 Debug"
@@ -76,7 +76,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\libOggFLAC_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\replaygain_synthesis_static.lib ..\..\obj\debug\lib\getopt_static.lib ..\..\obj\debug\lib\utf8_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\replaygain_synthesis_static.lib ..\..\obj\debug\lib\getopt_static.lib ..\..\obj\debug\lib\utf8_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
diff --git a/src/libFLAC++/Makefile.am b/src/libFLAC++/Makefile.am index c02e87b9..c37dd300 100644 --- a/src/libFLAC++/Makefile.am +++ b/src/libFLAC++/Makefile.am @@ -44,8 +44,6 @@ libFLAC___la_LDFLAGS = -version-info 6:0:0 libFLAC___la_LIBADD = ../libFLAC/libFLAC.la libFLAC___la_SOURCES = \ - file_decoder.cpp \ - file_encoder.cpp \ metadata.cpp \ stream_decoder.cpp \ stream_encoder.cpp diff --git a/src/libFLAC++/Makefile.lite b/src/libFLAC++/Makefile.lite index 73f7ce2e..8bdb59cf 100644 --- a/src/libFLAC++/Makefile.lite +++ b/src/libFLAC++/Makefile.lite @@ -38,8 +38,6 @@ LIB_NAME = libFLAC++ INCLUDES = -I$(topdir)/include SRCS_CPP = \ - file_decoder.cpp \ - file_encoder.cpp \ metadata.cpp \ stream_decoder.cpp \ stream_encoder.cpp diff --git a/src/libFLAC++/file_decoder.cpp b/src/libFLAC++/file_decoder.cpp deleted file mode 100644 index 82814284..00000000 --- a/src/libFLAC++/file_decoder.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "FLAC++/decoder.h" -#include "FLAC/assert.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -namespace FLAC { - namespace Decoder { - - File::File(): - Stream() - { } - - File::~File() - { - } - - ::FLAC__StreamDecoderInitStatus File::init(FILE *file) - { - FLAC__ASSERT(0 != decoder_); - return ::FLAC__stream_decoder_init_FILE(decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamDecoderInitStatus File::init(const char *filename) - { - FLAC__ASSERT(0 != decoder_); - return ::FLAC__stream_decoder_init_file(decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamDecoderInitStatus File::init(const std::string &filename) - { - return init(filename.c_str()); - } - - // This is a dummy to satisfy the pure virtual from Stream; the - // read callback will never be called since we are initializing - // with FLAC__stream_decoder_init_FILE() or - // FLAC__stream_decoder_init_file() and those supply the read - // callback internally. - ::FLAC__StreamDecoderReadStatus File::read_callback(FLAC__byte buffer[], unsigned *bytes) - { - (void)buffer, (void)bytes; - FLAC__ASSERT(false); - return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; // double protection - } - - } -} diff --git a/src/libFLAC++/file_encoder.cpp b/src/libFLAC++/file_encoder.cpp deleted file mode 100644 index 89a4164a..00000000 --- a/src/libFLAC++/file_encoder.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* libFLAC++ - Free Lossless Audio Codec library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "FLAC++/encoder.h" -#include "FLAC/assert.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -namespace FLAC { - namespace Encoder { - - File::File(): - Stream() - { } - - File::~File() - { - } - - ::FLAC__StreamEncoderInitStatus File::init(FILE *file) - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_init_FILE(encoder_, file, progress_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamEncoderInitStatus File::init(const char *filename) - { - FLAC__ASSERT(is_valid()); - return ::FLAC__stream_encoder_init_file(encoder_, filename, progress_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamEncoderInitStatus File::init(const std::string &filename) - { - return init(filename.c_str()); - } - - // This is a dummy to satisfy the pure virtual from Stream; the - // read callback will never be called since we are initializing - // with FLAC__stream_decoder_init_FILE() or - // FLAC__stream_decoder_init_file() and those supply the read - // callback internally. - ::FLAC__StreamEncoderWriteStatus File::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) - { - (void)buffer, (void)bytes, (void)samples, (void)current_frame; - FLAC__ASSERT(false); - return ::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; // double protection - } - - void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate) - { - (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate; - } - - void File::progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data) - { - (void)encoder; - FLAC__ASSERT(0 != client_data); - File *instance = reinterpret_cast<File *>(client_data); - FLAC__ASSERT(0 != instance); - instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate); - } - - } -} diff --git a/src/libFLAC++/libFLAC++_dynamic.dsp b/src/libFLAC++/libFLAC++_dynamic.dsp index ce76786d..46607f70 100644 --- a/src/libFLAC++/libFLAC++_dynamic.dsp +++ b/src/libFLAC++/libFLAC++_dynamic.dsp @@ -92,14 +92,6 @@ LINK32=link.exe # PROP Default_Filter "cpp"
# Begin Source File
-SOURCE=.\file_decoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\file_encoder.cpp
-# End Source File
-# Begin Source File
-
SOURCE=.\metadata.cpp
# End Source File
# Begin Source File
diff --git a/src/libFLAC++/libFLAC++_static.dsp b/src/libFLAC++/libFLAC++_static.dsp index 21468725..b47cda04 100644 --- a/src/libFLAC++/libFLAC++_static.dsp +++ b/src/libFLAC++/libFLAC++_static.dsp @@ -85,14 +85,6 @@ LIB32=link.exe -lib # PROP Default_Filter "cpp"
# Begin Source File
-SOURCE=.\file_decoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\file_encoder.cpp
-# End Source File
-# Begin Source File
-
SOURCE=.\metadata.cpp
# End Source File
# Begin Source File
diff --git a/src/libFLAC++/stream_decoder.cpp b/src/libFLAC++/stream_decoder.cpp index da9efe82..d20a8a0a 100644 --- a/src/libFLAC++/stream_decoder.cpp +++ b/src/libFLAC++/stream_decoder.cpp @@ -40,6 +40,12 @@ namespace FLAC { namespace Decoder { + // ------------------------------------------------------------ + // + // Stream + // + // ------------------------------------------------------------ + Stream::Stream(): decoder_(::FLAC__stream_decoder_new()) { } @@ -67,6 +73,12 @@ namespace FLAC { return 0 != decoder_; } + bool Stream::set_serial_number(long value) + { + FLAC__ASSERT(is_valid()); + return (bool)::FLAC__stream_decoder_set_serial_number(decoder_, value); + } + bool Stream::set_md5_checking(bool value) { FLAC__ASSERT(is_valid()); @@ -163,6 +175,12 @@ namespace FLAC { return ::FLAC__stream_decoder_init_stream(decoder_, read_callback_, seek_callback_, tell_callback_, length_callback_, eof_callback_, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); } + ::FLAC__StreamDecoderInitStatus Stream::init_ogg() + { + FLAC__ASSERT(is_valid()); + return ::FLAC__stream_decoder_init_ogg_stream(decoder_, read_callback_, seek_callback_, tell_callback_, length_callback_, eof_callback_, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); + } + void Stream::finish() { FLAC__ASSERT(is_valid()); @@ -311,5 +329,65 @@ namespace FLAC { instance->error_callback(status); } + // ------------------------------------------------------------ + // + // File + // + // ------------------------------------------------------------ + + File::File(): + Stream() + { } + + File::~File() + { + } + + ::FLAC__StreamDecoderInitStatus File::init(FILE *file) + { + FLAC__ASSERT(0 != decoder_); + return ::FLAC__stream_decoder_init_FILE(decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); + } + + ::FLAC__StreamDecoderInitStatus File::init(const char *filename) + { + FLAC__ASSERT(0 != decoder_); + return ::FLAC__stream_decoder_init_file(decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); + } + + ::FLAC__StreamDecoderInitStatus File::init(const std::string &filename) + { + return init(filename.c_str()); + } + + ::FLAC__StreamDecoderInitStatus File::init_ogg(FILE *file) + { + FLAC__ASSERT(0 != decoder_); + return ::FLAC__stream_decoder_init_ogg_FILE(decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); + } + + ::FLAC__StreamDecoderInitStatus File::init_ogg(const char *filename) + { + FLAC__ASSERT(0 != decoder_); + return ::FLAC__stream_decoder_init_ogg_file(decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); + } + + ::FLAC__StreamDecoderInitStatus File::init_ogg(const std::string &filename) + { + return init_ogg(filename.c_str()); + } + + // This is a dummy to satisfy the pure virtual from Stream; the + // read callback will never be called since we are initializing + // with FLAC__stream_decoder_init_FILE() or + // FLAC__stream_decoder_init_file() and those supply the read + // callback internally. + ::FLAC__StreamDecoderReadStatus File::read_callback(FLAC__byte buffer[], unsigned *bytes) + { + (void)buffer, (void)bytes; + FLAC__ASSERT(false); + return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; // double protection + } + } } diff --git a/src/libFLAC++/stream_encoder.cpp b/src/libFLAC++/stream_encoder.cpp index a33a6f39..c0aca1ba 100644 --- a/src/libFLAC++/stream_encoder.cpp +++ b/src/libFLAC++/stream_encoder.cpp @@ -41,6 +41,12 @@ namespace FLAC { namespace Encoder { + // ------------------------------------------------------------ + // + // Stream + // + // ------------------------------------------------------------ + Stream::Stream(): encoder_(::FLAC__stream_encoder_new()) { } @@ -68,6 +74,12 @@ namespace FLAC { return 0 != encoder_; } + bool Stream::set_serial_number(long value) + { + FLAC__ASSERT(is_valid()); + return (bool)::FLAC__stream_encoder_set_serial_number(encoder_, value); + } + bool Stream::set_verify(bool value) { FLAC__ASSERT(is_valid()); @@ -333,6 +345,12 @@ namespace FLAC { return ::FLAC__stream_encoder_init_stream(encoder_, write_callback_, seek_callback_, tell_callback_, metadata_callback_, /*client_data=*/(void*)this); } + ::FLAC__StreamEncoderInitStatus Stream::init_ogg() + { + FLAC__ASSERT(is_valid()); + return ::FLAC__stream_encoder_init_ogg_stream(encoder_, read_callback_, write_callback_, seek_callback_, tell_callback_, metadata_callback_, /*client_data=*/(void*)this); + } + void Stream::finish() { FLAC__ASSERT(is_valid()); @@ -351,6 +369,12 @@ namespace FLAC { return (bool)::FLAC__stream_encoder_process_interleaved(encoder_, buffer, samples); } + ::FLAC__StreamEncoderReadStatus Stream::read_callback(FLAC__byte buffer[], unsigned *bytes) + { + (void)buffer, (void)bytes; + return ::FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED; + } + ::FLAC__StreamEncoderSeekStatus Stream::seek_callback(FLAC__uint64 absolute_byte_offset) { (void)absolute_byte_offset; @@ -368,6 +392,15 @@ namespace FLAC { (void)metadata; } + ::FLAC__StreamEncoderReadStatus Stream::read_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) + { + (void)encoder; + FLAC__ASSERT(0 != client_data); + Stream *instance = reinterpret_cast<Stream *>(client_data); + FLAC__ASSERT(0 != instance); + return instance->read_callback(buffer, bytes); + } + ::FLAC__StreamEncoderWriteStatus Stream::write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) { (void)encoder; @@ -404,5 +437,79 @@ namespace FLAC { instance->metadata_callback(metadata); } + // ------------------------------------------------------------ + // + // File + // + // ------------------------------------------------------------ + + File::File(): + Stream() + { } + + File::~File() + { + } + + ::FLAC__StreamEncoderInitStatus File::init(FILE *file) + { + FLAC__ASSERT(is_valid()); + return ::FLAC__stream_encoder_init_FILE(encoder_, file, progress_callback_, /*client_data=*/(void*)this); + } + + ::FLAC__StreamEncoderInitStatus File::init(const char *filename) + { + FLAC__ASSERT(is_valid()); + return ::FLAC__stream_encoder_init_file(encoder_, filename, progress_callback_, /*client_data=*/(void*)this); + } + + ::FLAC__StreamEncoderInitStatus File::init(const std::string &filename) + { + return init(filename.c_str()); + } + + ::FLAC__StreamEncoderInitStatus File::init_ogg(FILE *file) + { + FLAC__ASSERT(is_valid()); + return ::FLAC__stream_encoder_init_ogg_FILE(encoder_, file, progress_callback_, /*client_data=*/(void*)this); + } + + ::FLAC__StreamEncoderInitStatus File::init_ogg(const char *filename) + { + FLAC__ASSERT(is_valid()); + return ::FLAC__stream_encoder_init_ogg_file(encoder_, filename, progress_callback_, /*client_data=*/(void*)this); + } + + ::FLAC__StreamEncoderInitStatus File::init_ogg(const std::string &filename) + { + return init_ogg(filename.c_str()); + } + + // This is a dummy to satisfy the pure virtual from Stream; the + // read callback will never be called since we are initializing + // with FLAC__stream_decoder_init_FILE() or + // FLAC__stream_decoder_init_file() and those supply the read + // callback internally. + ::FLAC__StreamEncoderWriteStatus File::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) + { + (void)buffer, (void)bytes, (void)samples, (void)current_frame; + FLAC__ASSERT(false); + return ::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; // double protection + } + + void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate) + { + (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate; + } + + void File::progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data) + { + (void)encoder; + FLAC__ASSERT(0 != client_data); + File *instance = reinterpret_cast<File *>(client_data); + FLAC__ASSERT(0 != instance); + instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate); + } + } } diff --git a/src/libFLAC/Makefile.am b/src/libFLAC/Makefile.am index c84f0a16..1b137469 100644 --- a/src/libFLAC/Makefile.am +++ b/src/libFLAC/Makefile.am @@ -80,6 +80,13 @@ EXTRA_DIST = \ libFLAC_static.dsp \ libFLAC.m4 +if FLaC__HAS_OGG +extra_ogg_sources = \ + ogg_decoder_aspect.c \ + ogg_encoder_aspect.c \ + ogg_helper.c \ + ogg_mapping.c +endif # see 'http://www.gnu.org/software/libtool/manual.html#Libtool-versioning' for numbering convention libFLAC_la_LDFLAGS = -version-info 8:0:0 -lm $(LOCAL_EXTRA_LDFLAGS) libFLAC_la_SOURCES = \ @@ -98,4 +105,5 @@ libFLAC_la_SOURCES = \ stream_decoder.c \ stream_encoder.c \ stream_encoder_framing.c \ - window.c + window.c \ + $(extra_ogg_sources) diff --git a/src/libFLAC/Makefile.lite b/src/libFLAC/Makefile.lite index aac6f11c..5b94ab3e 100644 --- a/src/libFLAC/Makefile.lite +++ b/src/libFLAC/Makefile.lite @@ -73,6 +73,10 @@ SRCS_C = \ memory.c \ metadata_iterators.c \ metadata_object.c \ + ogg_decoder_aspect.c \ + ogg_encoder_aspect.c \ + ogg_helper.c \ + ogg_mapping.c \ stream_decoder.c \ stream_encoder.c \ stream_encoder_framing.c \ diff --git a/src/libFLAC/include/private/Makefile.am b/src/libFLAC/include/private/Makefile.am index 9541a7d0..023cc508 100644 --- a/src/libFLAC/include/private/Makefile.am +++ b/src/libFLAC/include/private/Makefile.am @@ -41,5 +41,9 @@ noinst_HEADERS = \ md5.h \ memory.h \ metadata.h \ + ogg_decoder_aspect.h \ + ogg_encoder_aspect.h \ + ogg_helper.h \ + ogg_mapping.h \ stream_encoder_framing.h \ window.h diff --git a/src/libOggFLAC/include/private/ogg_decoder_aspect.h b/src/libFLAC/include/private/ogg_decoder_aspect.h index ba5c3d22..bf2967d3 100644 --- a/src/libOggFLAC/include/private/ogg_decoder_aspect.h +++ b/src/libFLAC/include/private/ogg_decoder_aspect.h @@ -1,4 +1,4 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library +/* libFLAC - Free Lossless Audio Codec * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson * * Redistribution and use in source and binary forms, with or without @@ -29,16 +29,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OggFLAC__PRIVATE__OGG_DECODER_ASPECT_H -#define OggFLAC__PRIVATE__OGG_DECODER_ASPECT_H +#ifndef FLAC__PRIVATE__OGG_DECODER_ASPECT_H +#define FLAC__PRIVATE__OGG_DECODER_ASPECT_H #include <ogg/ogg.h> #include "FLAC/ordinals.h" #include "FLAC/stream_decoder.h" /* for FLAC__StreamDecoderReadStatus */ -#include "OggFLAC/stream_decoder.h" -typedef struct OggFLAC__OggDecoderAspect { +typedef struct FLAC__OggDecoderAspect { /* these are storage for values that can be set through the API */ FLAC__bool use_first_serial_number; long serial_number; @@ -53,28 +52,28 @@ typedef struct OggFLAC__OggDecoderAspect { ogg_page working_page; FLAC__bool have_working_packet; /* only if true will the following vars be valid */ ogg_packet working_packet; /* as we work through the packet we will move working_packet.packet forward and working_packet.bytes down */ -} OggFLAC__OggDecoderAspect; +} FLAC__OggDecoderAspect; -void OggFLAC__ogg_decoder_aspect_set_serial_number(OggFLAC__OggDecoderAspect *aspect, long value); -void OggFLAC__ogg_decoder_aspect_set_defaults(OggFLAC__OggDecoderAspect *aspect); -FLAC__bool OggFLAC__ogg_decoder_aspect_init(OggFLAC__OggDecoderAspect *aspect); -void OggFLAC__ogg_decoder_aspect_finish(OggFLAC__OggDecoderAspect *aspect); -void OggFLAC__ogg_decoder_aspect_flush(OggFLAC__OggDecoderAspect *aspect); -void OggFLAC__ogg_decoder_aspect_reset(OggFLAC__OggDecoderAspect *aspect); +void FLAC__ogg_decoder_aspect_set_serial_number(FLAC__OggDecoderAspect *aspect, long value); +void FLAC__ogg_decoder_aspect_set_defaults(FLAC__OggDecoderAspect *aspect); +FLAC__bool FLAC__ogg_decoder_aspect_init(FLAC__OggDecoderAspect *aspect); +void FLAC__ogg_decoder_aspect_finish(FLAC__OggDecoderAspect *aspect); +void FLAC__ogg_decoder_aspect_flush(FLAC__OggDecoderAspect *aspect); +void FLAC__ogg_decoder_aspect_reset(FLAC__OggDecoderAspect *aspect); typedef enum { - OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_OK = 0, - OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM, - OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC, - OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC, - OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION, - OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT, - OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR, - OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR -} OggFLAC__OggDecoderAspectReadStatus; + FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK = 0, + FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM, + FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC, + FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC, + FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION, + FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT, + FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR, + FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR +} FLAC__OggDecoderAspectReadStatus; -typedef OggFLAC__OggDecoderAspectReadStatus (*OggFLAC__OggDecoderAspectReadCallbackProxy)(const void *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); +typedef FLAC__OggDecoderAspectReadStatus (*FLAC__OggDecoderAspectReadCallbackProxy)(const void *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); -OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wrapper(OggFLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], unsigned *bytes, OggFLAC__OggDecoderAspectReadCallbackProxy read_callback, const OggFLAC__StreamDecoder *decoder, void *client_data); +FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_read_callback_wrapper(FLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], unsigned *bytes, FLAC__OggDecoderAspectReadCallbackProxy read_callback, const FLAC__StreamDecoder *decoder, void *client_data); #endif diff --git a/src/libOggFLAC/include/private/ogg_encoder_aspect.h b/src/libFLAC/include/private/ogg_encoder_aspect.h index 11bd10bf..06d5ed94 100644 --- a/src/libOggFLAC/include/private/ogg_encoder_aspect.h +++ b/src/libFLAC/include/private/ogg_encoder_aspect.h @@ -1,4 +1,4 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library +/* libFLAC - Free Lossless Audio Codec * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson * * Redistribution and use in source and binary forms, with or without @@ -29,15 +29,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OggFLAC__PRIVATE__OGG_ENCODER_ASPECT_H -#define OggFLAC__PRIVATE__OGG_ENCODER_ASPECT_H +#ifndef FLAC__PRIVATE__OGG_ENCODER_ASPECT_H +#define FLAC__PRIVATE__OGG_ENCODER_ASPECT_H #include <ogg/ogg.h> #include "FLAC/ordinals.h" #include "FLAC/stream_encoder.h" /* for FLAC__StreamEncoderWriteStatus */ -typedef struct OggFLAC__OggEncoderAspect { +typedef struct FLAC__OggEncoderAspect { /* these are storage for values that can be set through the API */ long serial_number; unsigned num_metadata; @@ -48,15 +48,15 @@ typedef struct OggFLAC__OggEncoderAspect { FLAC__bool seen_magic; /* true if we've seen the fLaC magic in the write callback yet */ FLAC__bool is_first_packet; FLAC__uint64 samples_written; -} OggFLAC__OggEncoderAspect; +} FLAC__OggEncoderAspect; -void OggFLAC__ogg_encoder_aspect_set_serial_number(OggFLAC__OggEncoderAspect *aspect, long value); -FLAC__bool OggFLAC__ogg_encoder_aspect_set_num_metadata(OggFLAC__OggEncoderAspect *aspect, unsigned value); -void OggFLAC__ogg_encoder_aspect_set_defaults(OggFLAC__OggEncoderAspect *aspect); -FLAC__bool OggFLAC__ogg_encoder_aspect_init(OggFLAC__OggEncoderAspect *aspect); -void OggFLAC__ogg_encoder_aspect_finish(OggFLAC__OggEncoderAspect *aspect); +void FLAC__ogg_encoder_aspect_set_serial_number(FLAC__OggEncoderAspect *aspect, long value); +FLAC__bool FLAC__ogg_encoder_aspect_set_num_metadata(FLAC__OggEncoderAspect *aspect, unsigned value); +void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect); +FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect); +void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect); -typedef FLAC__StreamEncoderWriteStatus (*OggFLAC__OggEncoderAspectWriteCallbackProxy)(const void *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); +typedef FLAC__StreamEncoderWriteStatus (*FLAC__OggEncoderAspectWriteCallbackProxy)(const void *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); -FLAC__StreamEncoderWriteStatus OggFLAC__ogg_encoder_aspect_write_callback_wrapper(OggFLAC__OggEncoderAspect *aspect, const FLAC__uint64 total_samples_estimate, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, OggFLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data); +FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__uint64 total_samples_estimate, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data); #endif diff --git a/src/libOggFLAC/include/private/ogg_helper.h b/src/libFLAC/include/private/ogg_helper.h index 5a0cfafd..98a14296 100644 --- a/src/libOggFLAC/include/private/ogg_helper.h +++ b/src/libFLAC/include/private/ogg_helper.h @@ -1,4 +1,4 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library +/* libFLAC - Free Lossless Audio Codec * Copyright (C) 2004,2005,2006 Josh Coalson * * Redistribution and use in source and binary forms, with or without @@ -29,15 +29,15 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OggFLAC__PRIVATE__OGG_HELPER_H -#define OggFLAC__PRIVATE__OGG_HELPER_H +#ifndef FLAC__PRIVATE__OGG_HELPER_H +#define FLAC__PRIVATE__OGG_HELPER_H #include <ogg/ogg.h> -#include "OggFLAC/stream_encoder.h" /* for OggFLAC__StreamEncoder */ +#include "FLAC/stream_encoder.h" /* for FLAC__StreamEncoder */ void simple_ogg_page__init(ogg_page *page); void simple_ogg_page__clear(ogg_page *page); -FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, OggFLAC__StreamEncoderReadCallback read_callback, void *client_data); -FLAC__bool simple_ogg_page__set_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data); +FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderReadCallback read_callback, void *client_data); +FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data); #endif diff --git a/src/libOggFLAC/include/private/ogg_mapping.h b/src/libFLAC/include/private/ogg_mapping.h index b0cf210c..dbc86e18 100644 --- a/src/libOggFLAC/include/private/ogg_mapping.h +++ b/src/libFLAC/include/private/ogg_mapping.h @@ -1,4 +1,4 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library +/* libFLAC - Free Lossless Audio Codec * Copyright (C) 2004,2005,2006 Josh Coalson * * Redistribution and use in source and binary forms, with or without @@ -29,35 +29,35 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef OggFLAC__PRIVATE__OGG_MAPPING_H -#define OggFLAC__PRIVATE__OGG_MAPPING_H +#ifndef FLAC__PRIVATE__OGG_MAPPING_H +#define FLAC__PRIVATE__OGG_MAPPING_H #include "FLAC/ordinals.h" /** The length of the 'FLAC' magic in bytes. */ -#define OggFLAC__MAPPING_PACKET_TYPE_LENGTH (1u) +#define FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH (1u) -extern const unsigned OggFLAC__MAPPING_PACKET_TYPE_LEN; /* = 8 bits */ +extern const unsigned FLAC__OGG_MAPPING_PACKET_TYPE_LEN; /* = 8 bits */ -extern const FLAC__byte OggFLAC__MAPPING_FIRST_HEADER_PACKET_TYPE; /* = 0x7f */ +extern const FLAC__byte FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE; /* = 0x7f */ /** The length of the 'FLAC' magic in bytes. */ -#define OggFLAC__MAPPING_MAGIC_LENGTH (4u) +#define FLAC__OGG_MAPPING_MAGIC_LENGTH (4u) -extern const FLAC__byte * const OggFLAC__MAPPING_MAGIC; /* = "FLAC" */ +extern const FLAC__byte * const FLAC__OGG_MAPPING_MAGIC; /* = "FLAC" */ -extern const unsigned OggFLAC__MAPPING_VERSION_MAJOR_LEN; /* = 8 bits */ -extern const unsigned OggFLAC__MAPPING_VERSION_MINOR_LEN; /* = 8 bits */ +extern const unsigned FLAC__OGG_MAPPING_VERSION_MAJOR_LEN; /* = 8 bits */ +extern const unsigned FLAC__OGG_MAPPING_VERSION_MINOR_LEN; /* = 8 bits */ /** The length of the Ogg FLAC mapping major version number in bytes. */ -#define OggFLAC__MAPPING_VERSION_MAJOR_LENGTH (1u) +#define FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH (1u) /** The length of the Ogg FLAC mapping minor version number in bytes. */ -#define OggFLAC__MAPPING_VERSION_MINOR_LENGTH (1u) +#define FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH (1u) -extern const unsigned OggFLAC__MAPPING_NUM_HEADERS_LEN; /* = 16 bits */ +extern const unsigned FLAC__OGG_MAPPING_NUM_HEADERS_LEN; /* = 16 bits */ /** The length of the #-of-header-packets number bytes. */ -#define OggFLAC__MAPPING_NUM_HEADERS_LENGTH (2u) +#define FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH (2u) #endif diff --git a/src/libFLAC/include/protected/stream_decoder.h b/src/libFLAC/include/protected/stream_decoder.h index d4c55598..e1a9f1a9 100644 --- a/src/libFLAC/include/protected/stream_decoder.h +++ b/src/libFLAC/include/protected/stream_decoder.h @@ -33,6 +33,9 @@ #define FLAC__PROTECTED__STREAM_DECODER_H #include "FLAC/stream_decoder.h" +#ifdef FLAC__HAS_OGG +#include "private/ogg_decoder_aspect.h" +#endif typedef struct FLAC__StreamDecoderProtected { FLAC__StreamDecoderState state; @@ -42,6 +45,9 @@ typedef struct FLAC__StreamDecoderProtected { unsigned sample_rate; /* in Hz */ unsigned blocksize; /* in samples (per channel) */ FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */ +#ifdef FLAC__HAS_OGG + FLAC__OggDecoderAspect ogg_decoder_aspect; +#endif } FLAC__StreamDecoderProtected; /* diff --git a/src/libFLAC/include/protected/stream_encoder.h b/src/libFLAC/include/protected/stream_encoder.h index 5233b20d..683a81e1 100644 --- a/src/libFLAC/include/protected/stream_encoder.h +++ b/src/libFLAC/include/protected/stream_encoder.h @@ -33,6 +33,9 @@ #define FLAC__PROTECTED__STREAM_ENCODER_H #include "FLAC/stream_encoder.h" +#ifdef FLAC__HAS_OGG +#include "private/ogg_encoder_aspect.h" +#endif #ifndef FLAC__INTEGER_ONLY_LIBRARY @@ -98,6 +101,9 @@ typedef struct FLAC__StreamEncoderProtected { FLAC__StreamMetadata **metadata; unsigned num_metadata_blocks; FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset; +#ifdef FLAC__HAS_OGG + FLAC__OggEncoderAspect ogg_encoder_aspect; +#endif } FLAC__StreamEncoderProtected; #endif diff --git a/src/libFLAC/libFLAC_dynamic.dsp b/src/libFLAC/libFLAC_dynamic.dsp index 961592a1..0a0f8428 100644 --- a/src/libFLAC/libFLAC_dynamic.dsp +++ b/src/libFLAC/libFLAC_dynamic.dsp @@ -235,6 +235,22 @@ SOURCE=.\metadata_object.c # End Source File
# Begin Source File
+SOURCE=.\ogg_decoder_aspect.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg_encoder_aspect.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg_helper.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg_mapping.c
+# End Source File
+# Begin Source File
+
SOURCE=.\stream_decoder.c
# End Source File
# Begin Source File
@@ -303,6 +319,22 @@ SOURCE=.\include\private\metadata.h # End Source File
# Begin Source File
+SOURCE=.\include\private\ogg_decoder_aspect.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\private\ogg_encoder_aspect.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\private\ogg_helper.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\private\ogg_mapping.h
+# End Source File
+# Begin Source File
+
SOURCE=.\include\private\stream_encoder_framing.h
# End Source File
# Begin Source File
diff --git a/src/libFLAC/libFLAC_static.dsp b/src/libFLAC/libFLAC_static.dsp index 170c1799..7a188b8b 100644 --- a/src/libFLAC/libFLAC_static.dsp +++ b/src/libFLAC/libFLAC_static.dsp @@ -228,6 +228,22 @@ SOURCE=.\metadata_object.c # End Source File
# Begin Source File
+SOURCE=.\ogg_decoder_aspect.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg_encoder_aspect.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg_helper.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\ogg_mapping.c
+# End Source File
+# Begin Source File
+
SOURCE=.\stream_decoder.c
# End Source File
# Begin Source File
@@ -296,6 +312,22 @@ SOURCE=.\include\private\metadata.h # End Source File
# Begin Source File
+SOURCE=.\include\private\ogg_decoder_aspect.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\private\ogg_encoder_aspect.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\private\ogg_helper.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\private\ogg_mapping.h
+# End Source File
+# Begin Source File
+
SOURCE=.\include\private\stream_encoder_framing.h
# End Source File
# Begin Source File
diff --git a/src/libOggFLAC/ogg_decoder_aspect.c b/src/libFLAC/ogg_decoder_aspect.c index a85dd723..45ff60e5 100644 --- a/src/libOggFLAC/ogg_decoder_aspect.c +++ b/src/libFLAC/ogg_decoder_aspect.c @@ -1,4 +1,4 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library +/* libFLAC - Free Lossless Audio Codec * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson * * Redistribution and use in source and binary forms, with or without @@ -49,7 +49,7 @@ * ***********************************************************************/ -FLAC__bool OggFLAC__ogg_decoder_aspect_init(OggFLAC__OggDecoderAspect *aspect) +FLAC__bool FLAC__ogg_decoder_aspect_init(FLAC__OggDecoderAspect *aspect) { /* we will determine the serial number later if necessary */ if(ogg_stream_init(&aspect->stream_state, aspect->serial_number) != 0) @@ -69,24 +69,24 @@ FLAC__bool OggFLAC__ogg_decoder_aspect_init(OggFLAC__OggDecoderAspect *aspect) return true; } -void OggFLAC__ogg_decoder_aspect_finish(OggFLAC__OggDecoderAspect *aspect) +void FLAC__ogg_decoder_aspect_finish(FLAC__OggDecoderAspect *aspect) { (void)ogg_sync_clear(&aspect->sync_state); (void)ogg_stream_clear(&aspect->stream_state); } -void OggFLAC__ogg_decoder_aspect_set_serial_number(OggFLAC__OggDecoderAspect *aspect, long value) +void FLAC__ogg_decoder_aspect_set_serial_number(FLAC__OggDecoderAspect *aspect, long value) { aspect->use_first_serial_number = false; aspect->serial_number = value; } -void OggFLAC__ogg_decoder_aspect_set_defaults(OggFLAC__OggDecoderAspect *aspect) +void FLAC__ogg_decoder_aspect_set_defaults(FLAC__OggDecoderAspect *aspect) { aspect->use_first_serial_number = true; } -void OggFLAC__ogg_decoder_aspect_flush(OggFLAC__OggDecoderAspect *aspect) +void FLAC__ogg_decoder_aspect_flush(FLAC__OggDecoderAspect *aspect) { (void)ogg_stream_reset(&aspect->stream_state); (void)ogg_sync_reset(&aspect->sync_state); @@ -94,15 +94,15 @@ void OggFLAC__ogg_decoder_aspect_flush(OggFLAC__OggDecoderAspect *aspect) aspect->have_working_page = false; } -void OggFLAC__ogg_decoder_aspect_reset(OggFLAC__OggDecoderAspect *aspect) +void FLAC__ogg_decoder_aspect_reset(FLAC__OggDecoderAspect *aspect) { - OggFLAC__ogg_decoder_aspect_flush(aspect); + FLAC__ogg_decoder_aspect_flush(aspect); if(aspect->use_first_serial_number) aspect->need_serial_number = true; } -OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wrapper(OggFLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], unsigned *bytes, OggFLAC__OggDecoderAspectReadCallbackProxy read_callback, const OggFLAC__StreamDecoder *decoder, void *client_data) +FLAC__OggDecoderAspectReadStatus FLAC__ogg_decoder_aspect_read_callback_wrapper(FLAC__OggDecoderAspect *aspect, FLAC__byte buffer[], unsigned *bytes, FLAC__OggDecoderAspectReadCallbackProxy read_callback, const FLAC__StreamDecoder *decoder, void *client_data) { static const unsigned OGG_BYTES_CHUNK = 8192; const unsigned bytes_requested = *bytes; @@ -161,25 +161,25 @@ OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wr if (ret > 0) { aspect->have_working_packet = true; /* if it is the first header packet, check for magic and a supported Ogg FLAC mapping version */ - if (aspect->working_packet.bytes > 0 && aspect->working_packet.packet[0] == OggFLAC__MAPPING_FIRST_HEADER_PACKET_TYPE) { + if (aspect->working_packet.bytes > 0 && aspect->working_packet.packet[0] == FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE) { const FLAC__byte *b = aspect->working_packet.packet; const unsigned header_length = - OggFLAC__MAPPING_PACKET_TYPE_LENGTH + - OggFLAC__MAPPING_MAGIC_LENGTH + - OggFLAC__MAPPING_VERSION_MAJOR_LENGTH + - OggFLAC__MAPPING_VERSION_MINOR_LENGTH + - OggFLAC__MAPPING_NUM_HEADERS_LENGTH; + FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH + + FLAC__OGG_MAPPING_MAGIC_LENGTH + + FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH + + FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH + + FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH; if (aspect->working_packet.bytes < (long)header_length) - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC; - b += OggFLAC__MAPPING_PACKET_TYPE_LENGTH; - if (memcmp(b, OggFLAC__MAPPING_MAGIC, OggFLAC__MAPPING_MAGIC_LENGTH)) - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC; - b += OggFLAC__MAPPING_MAGIC_LENGTH; + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC; + b += FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH; + if (memcmp(b, FLAC__OGG_MAPPING_MAGIC, FLAC__OGG_MAPPING_MAGIC_LENGTH)) + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC; + b += FLAC__OGG_MAPPING_MAGIC_LENGTH; aspect->version_major = (unsigned)(*b); - b += OggFLAC__MAPPING_VERSION_MAJOR_LENGTH; + b += FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH; aspect->version_minor = (unsigned)(*b); if (aspect->version_major != 1) - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION; + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION; aspect->working_packet.packet += header_length; aspect->working_packet.bytes -= header_length; } @@ -189,7 +189,7 @@ OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wr } else { /* ret < 0 */ /* lost sync, we'll leave the working page for the next call */ - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC; + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC; } } } @@ -214,19 +214,19 @@ OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wr char *oggbuf = ogg_sync_buffer(&aspect->sync_state, ogg_bytes_to_read); if(0 == oggbuf) { - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR; + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR; } else { unsigned ogg_bytes_read = ogg_bytes_to_read; switch(read_callback(decoder, (FLAC__byte*)oggbuf, &ogg_bytes_read, client_data)) { - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_OK: + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK: break; - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM: + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM: aspect->end_of_stream = true; break; - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT: - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT: + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; default: FLAC__ASSERT(0); } @@ -234,20 +234,20 @@ OggFLAC__OggDecoderAspectReadStatus OggFLAC__ogg_decoder_aspect_read_callback_wr if(ogg_sync_wrote(&aspect->sync_state, ogg_bytes_read) < 0) { /* double protection; this will happen if the read callback returns more bytes than the max requested, which would overflow Ogg's internal buffer */ FLAC__ASSERT(0); - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR; + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR; } } } else { /* ret < 0 */ /* lost sync, bail out */ - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC; + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC; } } } if (aspect->end_of_stream && *bytes == 0) { - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM; + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM; } - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_OK; + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK; } diff --git a/src/libOggFLAC/ogg_encoder_aspect.c b/src/libFLAC/ogg_encoder_aspect.c index 9f7b25ae..c6eb2850 100644 --- a/src/libOggFLAC/ogg_encoder_aspect.c +++ b/src/libFLAC/ogg_encoder_aspect.c @@ -1,4 +1,4 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library +/* libFLAC - Free Lossless Audio Codec * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson * * Redistribution and use in source and binary forms, with or without @@ -38,8 +38,8 @@ #include "private/ogg_encoder_aspect.h" #include "private/ogg_mapping.h" -static const FLAC__byte OggFLAC__MAPPING_VERSION_MAJOR = 1; -static const FLAC__byte OggFLAC__MAPPING_VERSION_MINOR = 0; +static const FLAC__byte FLAC__OGG_MAPPING_VERSION_MAJOR = 1; +static const FLAC__byte FLAC__OGG_MAPPING_VERSION_MINOR = 0; /*********************************************************************** * @@ -47,7 +47,7 @@ static const FLAC__byte OggFLAC__MAPPING_VERSION_MINOR = 0; * ***********************************************************************/ -FLAC__bool OggFLAC__ogg_encoder_aspect_init(OggFLAC__OggEncoderAspect *aspect) +FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect) { /* we will determine the serial number later if necessary */ if(ogg_stream_init(&aspect->stream_state, aspect->serial_number) != 0) @@ -60,20 +60,20 @@ FLAC__bool OggFLAC__ogg_encoder_aspect_init(OggFLAC__OggEncoderAspect *aspect) return true; } -void OggFLAC__ogg_encoder_aspect_finish(OggFLAC__OggEncoderAspect *aspect) +void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect) { (void)ogg_stream_clear(&aspect->stream_state); /*@@@ what about the page? */ } -void OggFLAC__ogg_encoder_aspect_set_serial_number(OggFLAC__OggEncoderAspect *aspect, long value) +void FLAC__ogg_encoder_aspect_set_serial_number(FLAC__OggEncoderAspect *aspect, long value) { aspect->serial_number = value; } -FLAC__bool OggFLAC__ogg_encoder_aspect_set_num_metadata(OggFLAC__OggEncoderAspect *aspect, unsigned value) +FLAC__bool FLAC__ogg_encoder_aspect_set_num_metadata(FLAC__OggEncoderAspect *aspect, unsigned value) { - if(value < (1u << OggFLAC__MAPPING_NUM_HEADERS_LEN)) { + if(value < (1u << FLAC__OGG_MAPPING_NUM_HEADERS_LEN)) { aspect->num_metadata = value; return true; } @@ -81,7 +81,7 @@ FLAC__bool OggFLAC__ogg_encoder_aspect_set_num_metadata(OggFLAC__OggEncoderAspec return false; } -void OggFLAC__ogg_encoder_aspect_set_defaults(OggFLAC__OggEncoderAspect *aspect) +void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect) { aspect->serial_number = 0; aspect->num_metadata = 0; @@ -108,7 +108,7 @@ void OggFLAC__ogg_encoder_aspect_set_defaults(OggFLAC__OggEncoderAspect *aspect) * separate write callback for the fLaC magic, and then separate write * callbacks for each metadata block and audio frame. */ -FLAC__StreamEncoderWriteStatus OggFLAC__ogg_encoder_aspect_write_callback_wrapper(OggFLAC__OggEncoderAspect *aspect, const FLAC__uint64 total_samples_estimate, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, OggFLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data) +FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__uint64 total_samples_estimate, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data) { /* WATCHOUT: * This depends on the behavior of FLAC__StreamEncoder that 'samples' @@ -123,11 +123,11 @@ FLAC__StreamEncoderWriteStatus OggFLAC__ogg_encoder_aspect_write_callback_wrappe if(aspect->seen_magic) { ogg_packet packet; FLAC__byte synthetic_first_packet_body[ - OggFLAC__MAPPING_PACKET_TYPE_LENGTH + - OggFLAC__MAPPING_MAGIC_LENGTH + - OggFLAC__MAPPING_VERSION_MAJOR_LENGTH + - OggFLAC__MAPPING_VERSION_MINOR_LENGTH + - OggFLAC__MAPPING_NUM_HEADERS_LENGTH + + FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH + + FLAC__OGG_MAPPING_MAGIC_LENGTH + + FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH + + FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH + + FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH + FLAC__STREAM_SYNC_LENGTH + FLAC__STREAM_METADATA_HEADER_LENGTH + FLAC__STREAM_METADATA_STREAMINFO_LENGTH @@ -147,17 +147,17 @@ FLAC__StreamEncoderWriteStatus OggFLAC__ogg_encoder_aspect_write_callback_wrappe return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; } /* add first header packet type */ - *b = OggFLAC__MAPPING_FIRST_HEADER_PACKET_TYPE; - b += OggFLAC__MAPPING_PACKET_TYPE_LENGTH; + *b = FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE; + b += FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH; /* add 'FLAC' mapping magic */ - memcpy(b, OggFLAC__MAPPING_MAGIC, OggFLAC__MAPPING_MAGIC_LENGTH); - b += OggFLAC__MAPPING_MAGIC_LENGTH; + memcpy(b, FLAC__OGG_MAPPING_MAGIC, FLAC__OGG_MAPPING_MAGIC_LENGTH); + b += FLAC__OGG_MAPPING_MAGIC_LENGTH; /* add Ogg FLAC mapping major version number */ - memcpy(b, &OggFLAC__MAPPING_VERSION_MAJOR, OggFLAC__MAPPING_VERSION_MAJOR_LENGTH); - b += OggFLAC__MAPPING_VERSION_MAJOR_LENGTH; + memcpy(b, &FLAC__OGG_MAPPING_VERSION_MAJOR, FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH); + b += FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH; /* add Ogg FLAC mapping minor version number */ - memcpy(b, &OggFLAC__MAPPING_VERSION_MINOR, OggFLAC__MAPPING_VERSION_MINOR_LENGTH); - b += OggFLAC__MAPPING_VERSION_MINOR_LENGTH; + memcpy(b, &FLAC__OGG_MAPPING_VERSION_MINOR, FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH); + b += FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH; /* add number of header packets */ *b = (FLAC__byte)(aspect->num_metadata >> 8); b++; diff --git a/src/libOggFLAC/ogg_helper.c b/src/libFLAC/ogg_helper.c index ca985553..edac05dd 100644 --- a/src/libOggFLAC/ogg_helper.c +++ b/src/libFLAC/ogg_helper.c @@ -1,4 +1,4 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library +/* libFLAC - Free Lossless Audio Codec * Copyright (C) 2004,2005,2006 Josh Coalson * * Redistribution and use in source and binary forms, with or without @@ -40,32 +40,32 @@ #include "protected/stream_encoder.h" -static FLAC__bool full_read_(OggFLAC__StreamEncoder *encoder, FLAC__byte *buffer, unsigned bytes, OggFLAC__StreamEncoderReadCallback read_callback, void *client_data) +static FLAC__bool full_read_(FLAC__StreamEncoder *encoder, FLAC__byte *buffer, unsigned bytes, FLAC__StreamEncoderReadCallback read_callback, void *client_data) { while(bytes > 0) { unsigned bytes_read = bytes; switch(read_callback(encoder, buffer, &bytes_read, client_data)) { - case OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE: + case FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE: bytes -= bytes_read; buffer += bytes_read; break; - case OggFLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM: + case FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM: if(bytes_read == 0) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; return false; } bytes -= bytes_read; buffer += bytes_read; break; - case OggFLAC__STREAM_ENCODER_READ_STATUS_ABORT: - encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR; + case FLAC__STREAM_ENCODER_READ_STATUS_ABORT: + encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; return false; - case OggFLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED: + case FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED: return false; default: /* double protection: */ FLAC__ASSERT(0); - encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; return false; } } @@ -90,7 +90,7 @@ void simple_ogg_page__clear(ogg_page *page) simple_ogg_page__init(page); } -FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, OggFLAC__StreamEncoderReadCallback read_callback, void *client_data) +FLAC__bool simple_ogg_page__get_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderReadCallback read_callback, void *client_data) { static const unsigned OGG_HEADER_FIXED_PORTION_LEN = 27; static const unsigned OGG_MAX_HEADER_LEN = 27/*OGG_HEADER_FIXED_PORTION_LEN*/ + 255; @@ -107,13 +107,13 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 return false; if((seek_status = seek_callback((FLAC__StreamEncoder*)encoder, position, client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; return false; } /* allocate space for the page header */ if(0 == (page->header = (unsigned char *)malloc(OGG_MAX_HEADER_LEN))) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -131,7 +131,7 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 memcmp(page->header+6, "\0\0\0\0\0\0\0\0", 8) || /* granulepos is non-zero */ page->header[26] == 0 /* packet is 0-size */ ) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; return false; } @@ -145,7 +145,7 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 /* check to see that it specifies a single packet */ for(i = 0; i < (unsigned)page->header[26] - 1; i++) { if(page->header[i + OGG_HEADER_FIXED_PORTION_LEN] != 255) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; return false; } } @@ -155,7 +155,7 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 /* allocate space for the page body */ if(0 == (page->body = (unsigned char *)malloc(page->body_len))) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR; return false; } @@ -167,14 +167,14 @@ FLAC__bool simple_ogg_page__get_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 memcpy(crc, page->header+22, 4); ogg_page_checksum_set(page); if(memcmp(crc, page->header+22, 4)) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; return false; } return true; } -FLAC__bool simple_ogg_page__set_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data) +FLAC__bool simple_ogg_page__set_at(FLAC__StreamEncoder *encoder, FLAC__uint64 position, ogg_page *page, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderWriteCallback write_callback, void *client_data) { FLAC__StreamEncoderSeekStatus seek_status; @@ -188,7 +188,7 @@ FLAC__bool simple_ogg_page__set_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 return false; if((seek_status = seek_callback((FLAC__StreamEncoder*)encoder, position, client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) { if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR) - encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; return false; } @@ -196,7 +196,7 @@ FLAC__bool simple_ogg_page__set_at(OggFLAC__StreamEncoder *encoder, FLAC__uint64 /* re-write the page */ if(write_callback((FLAC__StreamEncoder*)encoder, page->header, page->header_len, 0, 0, client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR; + encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; return false; } diff --git a/src/libOggFLAC/ogg_mapping.c b/src/libFLAC/ogg_mapping.c index bfd27ad0..0a9cd0e1 100644 --- a/src/libOggFLAC/ogg_mapping.c +++ b/src/libFLAC/ogg_mapping.c @@ -1,4 +1,4 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library +/* libFLAC - Free Lossless Audio Codec * Copyright (C) 2004,2005,2006 Josh Coalson * * Redistribution and use in source and binary forms, with or without @@ -35,13 +35,13 @@ #include "private/ogg_mapping.h" -const unsigned OggFLAC__MAPPING_PACKET_TYPE_LEN = 8; /* bits */ +const unsigned FLAC__OGG_MAPPING_PACKET_TYPE_LEN = 8; /* bits */ -const FLAC__byte OggFLAC__MAPPING_FIRST_HEADER_PACKET_TYPE = 0x7f; +const FLAC__byte FLAC__OGG_MAPPING_FIRST_HEADER_PACKET_TYPE = 0x7f; -const FLAC__byte * const OggFLAC__MAPPING_MAGIC = (const FLAC__byte * const)"FLAC"; +const FLAC__byte * const FLAC__OGG_MAPPING_MAGIC = (const FLAC__byte * const)"FLAC"; -const unsigned OggFLAC__MAPPING_VERSION_MAJOR_LEN = 8; /* bits */ -const unsigned OggFLAC__MAPPING_VERSION_MINOR_LEN = 8; /* bits */ +const unsigned FLAC__OGG_MAPPING_VERSION_MAJOR_LEN = 8; /* bits */ +const unsigned FLAC__OGG_MAPPING_VERSION_MINOR_LEN = 8; /* bits */ -const unsigned OggFLAC__MAPPING_NUM_HEADERS_LEN = 16; /* bits */ +const unsigned FLAC__OGG_MAPPING_NUM_HEADERS_LEN = 16; /* bits */ diff --git a/src/libFLAC/stream_decoder.c b/src/libFLAC/stream_decoder.c index 40c09aa6..be71f095 100644 --- a/src/libFLAC/stream_decoder.c +++ b/src/libFLAC/stream_decoder.c @@ -76,6 +76,17 @@ #define FLAC__U64L(x) x##LLU #endif + +/* technically this should be in an "export.c" but this is convenient enough */ +int FLAC_API_SUPPORTS_OGG_FLAC = +#if FLAC__HAS_OGG + 1 +#else + 0 +#endif +; + + /*********************************************************************** * * Private static data @@ -113,9 +124,16 @@ static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned static FLAC__bool read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents, FLAC__int32 *residual); static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder); static FLAC__bool read_callback_(FLAC__byte buffer[], unsigned *bytes, void *client_data); +#ifdef FLAC__HAS_OGG +static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes); +static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); +#endif static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]); static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status); static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample); +#ifdef FLAC__HAS_OGG +static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample); +#endif static FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); static FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); static FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); @@ -129,6 +147,9 @@ static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *c ***********************************************************************/ typedef struct FLAC__StreamDecoderPrivate { +#ifdef FLAC__HAS_OGG + FLAC__bool is_ogg; +#endif FLAC__StreamDecoderReadCallback read_callback; FLAC__StreamDecoderSeekCallback seek_callback; FLAC__StreamDecoderTellCallback tell_callback; @@ -178,6 +199,9 @@ typedef struct FLAC__StreamDecoderPrivate { FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */ FLAC__uint64 target_sample; unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */ +#ifdef FLAC__HAS_OGG + FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */ +#endif } FLAC__StreamDecoderPrivate; /*********************************************************************** @@ -192,6 +216,7 @@ FLAC_API const char * const FLAC__StreamDecoderStateString[] = { "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC", "FLAC__STREAM_DECODER_READ_FRAME", "FLAC__STREAM_DECODER_END_OF_STREAM", + "FLAC__STREAM_DECODER_OGG_ERROR", "FLAC__STREAM_DECODER_SEEK_ERROR", "FLAC__STREAM_DECODER_ABORTED", "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR", @@ -200,6 +225,7 @@ FLAC_API const char * const FLAC__StreamDecoderStateString[] = { FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = { "FLAC__STREAM_DECODER_INIT_STATUS_OK", + "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER", "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS", "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR", "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE", @@ -340,7 +366,7 @@ FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder) * ***********************************************************************/ -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( +static FLAC__StreamDecoderInitStatus init_stream_internal_( FLAC__StreamDecoder *decoder, FLAC__StreamDecoderReadCallback read_callback, FLAC__StreamDecoderSeekCallback seek_callback, @@ -350,7 +376,8 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( FLAC__StreamDecoderWriteCallback write_callback, FLAC__StreamDecoderMetadataCallback metadata_callback, FLAC__StreamDecoderErrorCallback error_callback, - void *client_data + void *client_data, + FLAC__bool is_ogg ) { FLAC__ASSERT(0 != decoder); @@ -358,6 +385,11 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED; +#ifndef FLAC__HAS_OGG + if(is_ogg) + return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER; +#endif + if( 0 == read_callback || 0 == write_callback || @@ -366,6 +398,12 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( ) return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS; +#ifdef FLAC__HAS_OGG + decoder->private_->is_ogg = is_ogg; + if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect)) + return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR; +#endif + /* * get the CPU info and set the function pointers */ @@ -436,15 +474,72 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( return FLAC__STREAM_DECODER_INIT_STATUS_OK; } -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE( +FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( FLAC__StreamDecoder *decoder, - FILE *file, + FLAC__StreamDecoderReadCallback read_callback, + FLAC__StreamDecoderSeekCallback seek_callback, + FLAC__StreamDecoderTellCallback tell_callback, + FLAC__StreamDecoderLengthCallback length_callback, + FLAC__StreamDecoderEofCallback eof_callback, FLAC__StreamDecoderWriteCallback write_callback, FLAC__StreamDecoderMetadataCallback metadata_callback, FLAC__StreamDecoderErrorCallback error_callback, void *client_data ) { + return init_stream_internal_( + decoder, + read_callback, + seek_callback, + tell_callback, + length_callback, + eof_callback, + write_callback, + metadata_callback, + error_callback, + client_data, + /*is_ogg=*/false + ); +} + +FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream( + FLAC__StreamDecoder *decoder, + FLAC__StreamDecoderReadCallback read_callback, + FLAC__StreamDecoderSeekCallback seek_callback, + FLAC__StreamDecoderTellCallback tell_callback, + FLAC__StreamDecoderLengthCallback length_callback, + FLAC__StreamDecoderEofCallback eof_callback, + FLAC__StreamDecoderWriteCallback write_callback, + FLAC__StreamDecoderMetadataCallback metadata_callback, + FLAC__StreamDecoderErrorCallback error_callback, + void *client_data +) +{ + return init_stream_internal_( + decoder, + read_callback, + seek_callback, + tell_callback, + length_callback, + eof_callback, + write_callback, + metadata_callback, + error_callback, + client_data, + /*is_ogg=*/true + ); +} + +static FLAC__StreamDecoderInitStatus init_FILE_internal_( + FLAC__StreamDecoder *decoder, + FILE *file, + FLAC__StreamDecoderWriteCallback write_callback, + FLAC__StreamDecoderMetadataCallback metadata_callback, + FLAC__StreamDecoderErrorCallback error_callback, + void *client_data, + FLAC__bool is_ogg +) +{ FLAC__ASSERT(0 != decoder); FLAC__ASSERT(0 != file); @@ -464,7 +559,7 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE( decoder->private_->file = file; - return FLAC__stream_decoder_init_stream( + return init_stream_internal_( decoder, file_read_callback_, decoder->private_->file == stdin? 0: file_seek_callback_, @@ -474,19 +569,45 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE( write_callback, metadata_callback, error_callback, - client_data + client_data, + is_ogg ); } -FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file( +FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE( FLAC__StreamDecoder *decoder, - const char *filename, + FILE *file, + FLAC__StreamDecoderWriteCallback write_callback, + FLAC__StreamDecoderMetadataCallback metadata_callback, + FLAC__StreamDecoderErrorCallback error_callback, + void *client_data +) +{ + return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false); +} + +FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE( + FLAC__StreamDecoder *decoder, + FILE *file, FLAC__StreamDecoderWriteCallback write_callback, FLAC__StreamDecoderMetadataCallback metadata_callback, FLAC__StreamDecoderErrorCallback error_callback, void *client_data ) { + return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true); +} + +static FLAC__StreamDecoderInitStatus init_file_internal_( + FLAC__StreamDecoder *decoder, + const char *filename, + FLAC__StreamDecoderWriteCallback write_callback, + FLAC__StreamDecoderMetadataCallback metadata_callback, + FLAC__StreamDecoderErrorCallback error_callback, + void *client_data, + FLAC__bool is_ogg +) +{ FILE *file; FLAC__ASSERT(0 != decoder); @@ -507,7 +628,31 @@ FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file( if(0 == file) return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE; - return FLAC__stream_decoder_init_FILE(decoder, file, write_callback, metadata_callback, error_callback, client_data); + return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg); +} + +FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file( + FLAC__StreamDecoder *decoder, + const char *filename, + FLAC__StreamDecoderWriteCallback write_callback, + FLAC__StreamDecoderMetadataCallback metadata_callback, + FLAC__StreamDecoderErrorCallback error_callback, + void *client_data +) +{ + return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false); +} + +FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file( + FLAC__StreamDecoder *decoder, + const char *filename, + FLAC__StreamDecoderWriteCallback write_callback, + FLAC__StreamDecoderMetadataCallback metadata_callback, + FLAC__StreamDecoderErrorCallback error_callback, + void *client_data +) +{ + return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true); } FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder) @@ -552,6 +697,11 @@ FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder) decoder->private_->output_capacity = 0; decoder->private_->output_channels = 0; +#ifdef FLAC__HAS_OGG + if(decoder->private_->is_ogg) + FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect); +#endif + if(0 != decoder->private_->file) { if(decoder->private_->file != stdin) fclose(decoder->private_->file); @@ -571,6 +721,23 @@ FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder) return !md5_failed; } +FLAC_API FLAC__bool FLAC__stream_decoder_set_serial_number(FLAC__StreamDecoder *decoder, long value) +{ + FLAC__ASSERT(0 != decoder); + FLAC__ASSERT(0 != decoder->private_); + FLAC__ASSERT(0 != decoder->protected_); + if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) + return false; +#ifdef FLAC__HAS_OGG + /* can't check decoder->private_->is_ogg since that's not set until init time */ + FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value); + return true; +#else + (void)value; + return false; +#endif +} + FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value) { FLAC__ASSERT(0 != decoder); @@ -764,6 +931,10 @@ FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamD FLAC__ASSERT(0 != decoder->private_); FLAC__ASSERT(0 != position); +#ifdef FLAC__HAS_OGG + if(decoder->private_->is_ogg) + return false; +#endif if(0 == decoder->private_->tell_callback) return false; if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK) @@ -782,6 +953,11 @@ FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder) decoder->private_->samples_decoded = 0; decoder->private_->do_md5_checking = false; +#ifdef FLAC__HAS_OGG + if(decoder->private_->is_ogg) + FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect); +#endif + if(!FLAC__bitbuffer_clear(decoder->private_->input)) { decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; return false; @@ -804,6 +980,12 @@ FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder) return false; } +#ifdef FLAC__HAS_OGG + /*@@@ could go in !internal_reset_hack block below */ + if(decoder->private_->is_ogg) + FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect); +#endif + /* Rewind if necessary. If FLAC__stream_decoder_init() is calling us, * (internal_reset_hack) don't try to rewind since we are already at * the beginning of the stream and don't want to fail if the input is @@ -1007,6 +1189,7 @@ FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *deco decoder->private_->is_seeking = false; return false; } + /* if we haven't finished processing the metadata yet, do that so we have the STREAMINFO, SEEK_TABLE, and first_frame_offset */ if( decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA || @@ -1025,7 +1208,13 @@ FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *deco } { - FLAC__bool ok = seek_to_absolute_sample_(decoder, length, sample); + const FLAC__bool ok = +#ifdef FLAC__HAS_OGG + decoder->private_->is_ogg? + seek_to_absolute_sample_ogg_(decoder, length, sample) : +#endif + seek_to_absolute_sample_(decoder, length, sample) + ; decoder->private_->is_seeking = false; return ok; } @@ -1051,6 +1240,9 @@ unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecod void set_defaults_(FLAC__StreamDecoder *decoder) { +#ifdef FLAC__HAS_OGG + decoder->private_->is_ogg = false; +#endif decoder->private_->read_callback = 0; decoder->private_->seek_callback = 0; decoder->private_->tell_callback = 0; @@ -1066,6 +1258,10 @@ void set_defaults_(FLAC__StreamDecoder *decoder) decoder->private_->metadata_filter_ids_count = 0; decoder->protected_->md5_checking = false; + +#ifdef FLAC__HAS_OGG + FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect); +#endif } /* @@ -1483,7 +1679,7 @@ FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_ length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH); /* if there is a partial point left, skip over it */ if(length > 0) { - /*@@@ do an error_callback() here? there's an argument for either way */ + /*@@@ do a send_error_to_client_() here? there's an argument for either way */ if(!FLAC__bitbuffer_read_byte_block_aligned_no_crc(decoder->private_->input, 0, length, read_callback_, decoder)) return false; /* read_callback_ sets the state for us */ } @@ -2544,7 +2740,8 @@ FLAC__bool read_callback_(FLAC__byte buffer[], unsigned *bytes, void *client_dat { FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data; - if(decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)) { + /* see [1] HACK NOTE below for why we don't call the eof_callback when decoding Ogg FLAC */ + if(!decoder->private_->is_ogg && decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)) { *bytes = 0; decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM; return false; @@ -2565,13 +2762,20 @@ FLAC__bool read_callback_(FLAC__byte buffer[], unsigned *bytes, void *client_dat return false; } else { - const FLAC__StreamDecoderReadStatus status = decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data); + const FLAC__StreamDecoderReadStatus status = +#ifdef FLAC__HAS_OGG + decoder->private_->is_ogg? + read_callback_ogg_aspect_(decoder, buffer, bytes) : +#endif + decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data) + ; if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) { decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED; return false; } else if(*bytes == 0) { - if(status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM || (decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data))) { + /* see [1] HACK NOTE below for why we don't call the eof_callback when decoding Ogg FLAC */ + if(status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM || (!decoder->private_->is_ogg && decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data))) { decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM; return false; } @@ -2587,8 +2791,63 @@ FLAC__bool read_callback_(FLAC__byte buffer[], unsigned *bytes, void *client_dat decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED; return false; } + /* [1] @@@ HACK NOTE: The end-of-stream checking has to be hacked around + * for Ogg FLAC. This is because the ogg decoder aspect can lose sync + * and at the same time hit the end of the stream. There is no way to + * report an Ogg sync loss through the callbacks (see note in + * read_callback_ogg_aspect_()) so it returns CONTINUE with *bytes==0. + * So to keep the decoder from stopping at this point we gate the call + * to the eof_callback and let the Ogg decoder aspect set the + * end-of-stream state when it is needed. + */ } +#ifdef FLAC__HAS_OGG +FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes) +{ + switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) { + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK: + return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; + /* we don't really have a way to handle lost sync via read + * callback so we'll let it pass and let the underlying + * FLAC decoder catch the error + */ + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC: + return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM: + return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC: + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION: + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT: + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR: + case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR: + return FLAC__STREAM_DECODER_READ_STATUS_ABORT; + default: + FLAC__ASSERT(0); + /* double protection */ + return FLAC__STREAM_DECODER_READ_STATUS_ABORT; + } +} + +FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) +{ + FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder; + + switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) { + case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE: + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK; + case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM: + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM; + case FLAC__STREAM_DECODER_READ_STATUS_ABORT: + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; + default: + /* double protection: */ + FLAC__ASSERT(0); + return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; + } +} +#endif + FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]) { if(decoder->private_->is_seeking) { @@ -2598,6 +2857,9 @@ FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); +#ifdef FLAC__HAS_OGG + decoder->private_->got_a_frame = true; +#endif decoder->private_->last_frame = *frame; /* save the frame */ if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */ unsigned delta = (unsigned)(target_sample - this_frame_sample); @@ -2882,6 +3144,145 @@ FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 s return true; } +#ifdef FLAC__HAS_OGG +FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample) +{ + FLAC__uint64 left_pos = 0, right_pos = stream_length; + FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder); + FLAC__uint64 this_frame_sample = 0; /* only initialized to avoid compiler warning */ + FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */ + FLAC__bool did_a_seek; + unsigned iteration = 0; + + /* In the first iterations, we will calculate the target byte position + * by the distance from the target sample to left_sample and + * right_sample (let's call it "proportional search"). After that, we + * will switch to binary search. + */ + unsigned BINARY_SEARCH_AFTER_ITERATION = 2; + + /* We will switch to a linear search once our current sample is less + * than this number of samples ahead of the target sample + */ + static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2; + + /* If the total number of samples is unknown, use a large value, and + * force binary search immediately. + */ + if(right_sample == 0) { + right_sample = (FLAC__uint64)(-1); + BINARY_SEARCH_AFTER_ITERATION = 0; + } + + decoder->private_->target_sample = target_sample; + for( ; ; iteration++) { + if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) { + if (iteration >= BINARY_SEARCH_AFTER_ITERATION) { + pos = (right_pos + left_pos) / 2; + } + else { +#ifndef FLAC__INTEGER_ONLY_LIBRARY +#if defined _MSC_VER || defined __MINGW32__ + /* with MSVC you have to spoon feed it the casting */ + pos = (FLAC__uint64)((FLAC__double)(FLAC__int64)(target_sample - left_sample) / (FLAC__double)(FLAC__int64)(right_sample - left_sample) * (FLAC__double)(FLAC__int64)(right_pos - left_pos)); +#else + pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos)); +#endif +#else + /* a little less accurate: */ + if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff)) + pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample)); + else /* @@@ WATCHOUT, ~2TB limit */ + pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16)); +#endif + /* @@@ TODO: might want to limit pos to some distance + * before EOF, to make sure we land before the last frame, + * thereby getting a this_frame_sample and so having a better + * estimate. @@@@@@DELETE:this would also mostly (or totally if we could + * be sure to land before the last frame) avoid the + * end-of-stream case we have to check later. + */ + } + + /* physical seek */ + if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) { + decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; + return false; + } + if(!FLAC__stream_decoder_flush(decoder)) { + /* above call sets the state for us */ + return false; + } + did_a_seek = true; + } + else + did_a_seek = false; + + decoder->private_->got_a_frame = false; + if(!FLAC__stream_decoder_process_single(decoder)) { + decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; + return false; + } + if(!decoder->private_->got_a_frame) { + if(did_a_seek) { + /* this can happen if we seek to a point after the last frame; we drop + * to binary search right away in this case to avoid any wasted + * iterations of proportional search. + */ + right_pos = pos; + BINARY_SEARCH_AFTER_ITERATION = 0; + } + else { + /* this can probably only happen if total_samples is unknown and the + * target_sample is past the end of the stream + */ + decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; + return false; + } + } + /* our write callback will change the state when it gets to the target frame */ + else if(!decoder->private_->is_seeking/*@@@@@@ && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM*/) { + break; + } + else { + this_frame_sample = decoder->private_->last_frame.header.number.sample_number; + FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); + + if (did_a_seek) { + if (this_frame_sample <= target_sample) { + /* The 'equal' case should not happen, since + * FLAC__stream_decoder_process_single() + * should recognize that it has hit the + * target sample and we would exit through + * the 'break' above. + */ + FLAC__ASSERT(this_frame_sample != target_sample); + + left_sample = this_frame_sample; + /* sanity check to avoid infinite loop */ + if (left_pos == pos) { + decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; + return false; + } + left_pos = pos; + } + else if(this_frame_sample > target_sample) { + right_sample = this_frame_sample; + /* sanity check to avoid infinite loop */ + if (right_pos == pos) { + decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR; + return false; + } + right_pos = pos; + } + } + } + } + + return true; +} +#endif + FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) { (void)client_data; diff --git a/src/libFLAC/stream_encoder.c b/src/libFLAC/stream_encoder.c index 66eb992c..cf95d440 100644 --- a/src/libFLAC/stream_encoder.c +++ b/src/libFLAC/stream_encoder.c @@ -64,6 +64,9 @@ #include "private/lpc.h" #include "private/md5.h" #include "private/memory.h" +#ifdef FLAC__HAS_OGG +#include "private/ogg_helper.h" +#endif #include "private/stream_encoder_framing.h" #include "private/window.h" @@ -105,8 +108,9 @@ static void set_defaults_(FLAC__StreamEncoder *encoder); static void free_(FLAC__StreamEncoder *encoder); static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_size); static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples); -static FLAC__StreamEncoderWriteStatus write_frame_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples); +static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples); static void update_metadata_(const FLAC__StreamEncoder *encoder); +static void update_ogg_metadata_(FLAC__StreamEncoder *encoder); static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_frame); static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_frame); @@ -305,6 +309,7 @@ static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamD static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); +static FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); static FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); static FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); @@ -374,6 +379,10 @@ typedef struct FLAC__StreamEncoderPrivate { FLAC__bool disable_constant_subframes; FLAC__bool disable_fixed_subframes; FLAC__bool disable_verbatim_subframes; +#if FLAC__HAS_OGG + FLAC__bool is_ogg; +#endif + FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */ FLAC__StreamEncoderSeekCallback seek_callback; FLAC__StreamEncoderTellCallback tell_callback; FLAC__StreamEncoderWriteCallback write_callback; @@ -438,6 +447,7 @@ typedef struct FLAC__StreamEncoderPrivate { FLAC_API const char * const FLAC__StreamEncoderStateString[] = { "FLAC__STREAM_ENCODER_OK", "FLAC__STREAM_ENCODER_UNINITIALIZED", + "FLAC__STREAM_ENCODER_OGG_ERROR", "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR", "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA", "FLAC__STREAM_ENCODER_CLIENT_ERROR", @@ -449,6 +459,7 @@ FLAC_API const char * const FLAC__StreamEncoderStateString[] = { FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = { "FLAC__STREAM_ENCODER_INIT_STATUS_OK", "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR", + "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER", "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS", "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS", "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE", @@ -464,6 +475,13 @@ FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = { "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED" }; +FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = { + "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE", + "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM", + "FLAC__STREAM_ENCODER_READ_STATUS_ABORT", + "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED" +}; + FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = { "FLAC__STREAM_ENCODER_WRITE_STATUS_OK", "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR" @@ -597,7 +615,16 @@ FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder) * ***********************************************************************/ -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__StreamEncoder *encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data) +static FLAC__StreamEncoderInitStatus init_stream_internal_( + FLAC__StreamEncoder *encoder, + FLAC__StreamEncoderReadCallback read_callback, + FLAC__StreamEncoderWriteCallback write_callback, + FLAC__StreamEncoderSeekCallback seek_callback, + FLAC__StreamEncoderTellCallback tell_callback, + FLAC__StreamEncoderMetadataCallback metadata_callback, + void *client_data, + FLAC__bool is_ogg +) { unsigned i; FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2; @@ -607,6 +634,11 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; +#ifndef FLAC__HAS_OGG + if(is_ogg) + return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER; +#endif + if(0 == write_callback || (seek_callback && 0 == tell_callback)) return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS; @@ -725,6 +757,32 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order) encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order; +#if FLAC__HAS_OGG + /* reorder metadata if necessary to ensure that any VORBIS_COMMENT is the first, according to the mapping spec */ + if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) { + unsigned i; + for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) { + if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { + FLAC__StreamMetadata *vc = encoder->protected_->metadata[i]; + for( ; i > 0; i--) + encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1]; + encoder->protected_->metadata[0] = vc; + break; + } + } + } +#endif + /* keep track of any SEEKTABLE block */ + if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) { + unsigned i; + for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) { + if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) { + encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table; + break; /* take only the first one */ + } + } + } + /* validate metadata */ if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; @@ -894,6 +952,15 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St /* set state to OK; from here on, errors are fatal and we'll override the state then */ encoder->protected_->state = FLAC__STREAM_ENCODER_OK; +#if FLAC__HAS_OGG + encoder->private_->is_ogg = is_ogg; + if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) { + encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; + return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; + } +#endif + + encoder->private_->read_callback = read_callback; encoder->private_->write_callback = write_callback; encoder->private_->seek_callback = seek_callback; encoder->private_->tell_callback = tell_callback; @@ -1016,10 +1083,10 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St * if not, we will write an empty one (FLAC__add_metadata_block() * automatically supplies the vendor string). * - * WATCHOUT: libOggFLAC depends on us to write this block after the - * STREAMINFO since that's what the mapping requires. (In the case - * that metadata_has_vorbis_comment is true it will have already - * insured that the metadata list is properly ordered.) + * WATCHOUT: the Ogg FLAC mapping requires us to write this block after + * the STREAMINFO. (In the case that metadata_has_vorbis_comment is + * true it will have already insured that the metadata list is properly + * ordered.) */ if(!metadata_has_vorbis_comment) { FLAC__StreamMetadata vorbis_comment; @@ -1075,7 +1142,56 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(FLAC__St return FLAC__STREAM_ENCODER_INIT_STATUS_OK; } -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data) +FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream( + FLAC__StreamEncoder *encoder, + FLAC__StreamEncoderWriteCallback write_callback, + FLAC__StreamEncoderSeekCallback seek_callback, + FLAC__StreamEncoderTellCallback tell_callback, + FLAC__StreamEncoderMetadataCallback metadata_callback, + void *client_data +) +{ + return init_stream_internal_( + encoder, + /*read_callback=*/0, + write_callback, + seek_callback, + tell_callback, + metadata_callback, + client_data, + /*is_ogg=*/false + ); +} + +FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream( + FLAC__StreamEncoder *encoder, + FLAC__StreamEncoderReadCallback read_callback, + FLAC__StreamEncoderWriteCallback write_callback, + FLAC__StreamEncoderSeekCallback seek_callback, + FLAC__StreamEncoderTellCallback tell_callback, + FLAC__StreamEncoderMetadataCallback metadata_callback, + void *client_data +) +{ + return init_stream_internal_( + encoder, + read_callback, + write_callback, + seek_callback, + tell_callback, + metadata_callback, + client_data, + /*is_ogg=*/true + ); +} + +static FLAC__StreamEncoderInitStatus init_FILE_internal_( + FLAC__StreamEncoder *encoder, + FILE *file, + FLAC__StreamEncoderProgressCallback progress_callback, + void *client_data, + FLAC__bool is_ogg +) { FLAC__StreamEncoderInitStatus init_status; @@ -1106,7 +1222,16 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__Stre encoder->private_->samples_written = 0; encoder->private_->frames_written = 0; - init_status = FLAC__stream_encoder_init_stream(encoder, file_write_callback_, file_seek_callback_, file_tell_callback_, /*metadata_callback=*/0, client_data); + init_status = init_stream_internal_( + encoder, + is_ogg? file_read_callback_ : 0, + file_write_callback_, + file_seek_callback_, + file_tell_callback_, + /*metadata_callback=*/0, + client_data, + is_ogg + ); if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { /* the above function sets the state for us in case of an error */ return init_status; @@ -1121,8 +1246,34 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__Stre return init_status; } + +FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE( + FLAC__StreamEncoder *encoder, + FILE *file, + FLAC__StreamEncoderProgressCallback progress_callback, + void *client_data +) +{ + return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/false); +} + +FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE( + FLAC__StreamEncoder *encoder, + FILE *file, + FLAC__StreamEncoderProgressCallback progress_callback, + void *client_data +) +{ + return init_FILE_internal_(encoder, file, progress_callback, client_data, /*is_ogg=*/true); +} -FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data) +static FLAC__StreamEncoderInitStatus init_file_internal_( + FLAC__StreamEncoder *encoder, + const char *filename, + FLAC__StreamEncoderProgressCallback progress_callback, + void *client_data, + FLAC__bool is_ogg +) { FILE *file; @@ -1143,7 +1294,27 @@ FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__Stre return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; } - return FLAC__stream_encoder_init_FILE(encoder, file, progress_callback, client_data); + return init_FILE_internal_(encoder, file, progress_callback, client_data, is_ogg); +} + +FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file( + FLAC__StreamEncoder *encoder, + const char *filename, + FLAC__StreamEncoderProgressCallback progress_callback, + void *client_data +) +{ + return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/false); +} + +FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file( + FLAC__StreamEncoder *encoder, + const char *filename, + FLAC__StreamEncoderProgressCallback progress_callback, + void *client_data +) +{ + return init_file_internal_(encoder, filename, progress_callback, client_data, /*is_ogg=*/true); } FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder) @@ -1165,8 +1336,14 @@ FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder) FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context); if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) { - if(encoder->private_->seek_callback) + if(encoder->private_->seek_callback) { +#if FLAC__HAS_OGG + if(encoder->private_->is_ogg) + update_ogg_metadata_(encoder); + else +#endif update_metadata_(encoder); + } if(encoder->private_->metadata_callback) encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data); } @@ -1180,15 +1357,39 @@ FLAC_API void FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder) encoder->private_->file = 0; } +#if FLAC__HAS_OGG + if(encoder->private_->is_ogg) + FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect); +#endif + free_(encoder); set_defaults_(encoder); encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED; } +FLAC_API FLAC__bool FLAC__stream_encoder_set_serial_number(FLAC__StreamEncoder *encoder, long value) +{ + FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); + if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) + return false; +#ifdef FLAC__HAS_OGG + /* can't check encoder->private_->is_ogg since that's not set until init time */ + FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value); + return true; +#else + (void)value; + return false; +#endif +} + FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING @@ -1200,6 +1401,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->streamable_subset = value; @@ -1209,6 +1412,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncod FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->do_mid_side_stereo = value; @@ -1218,6 +1423,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEnco FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->loose_mid_side_stereo = value; @@ -1227,6 +1434,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamE FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->channels = value; @@ -1236,6 +1445,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encod FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->bits_per_sample = value; @@ -1245,6 +1456,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->sample_rate = value; @@ -1254,6 +1467,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *en FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->blocksize = value; @@ -1263,6 +1478,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *enco FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); FLAC__ASSERT(0 != specification); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; @@ -1332,6 +1549,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *en FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->max_lpc_order = value; @@ -1341,6 +1560,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder * FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->qlp_coeff_precision = value; @@ -1350,6 +1571,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEnc FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->do_qlp_coeff_prec_search = value; @@ -1359,6 +1582,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__Stre FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; #if 0 @@ -1373,6 +1598,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncode FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->do_exhaustive_model_search = value; @@ -1382,6 +1609,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__St FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->min_residual_partition_order = value; @@ -1391,6 +1620,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__ FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->max_residual_partition_order = value; @@ -1400,6 +1631,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__ FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; #if 0 @@ -1414,6 +1647,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__St FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->total_samples_estimate = value; @@ -1423,19 +1658,16 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__Stream FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->protected_->metadata = metadata; encoder->protected_->num_metadata_blocks = num_blocks; - if(0 != metadata && num_blocks > 0) { - unsigned i; - for(i = 0; i < num_blocks; i++) { - if(0 != metadata[i] && metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) { - encoder->private_->seek_table = &metadata[i]->data.seek_table; - break; /* take only the first one */ - } - } - } +#if FLAC__HAS_OGG + if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks)) + return false; +#endif return true; } @@ -1446,6 +1678,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encod FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->private_->disable_constant_subframes = value; @@ -1455,6 +1689,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__Stream FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->private_->disable_fixed_subframes = value; @@ -1464,6 +1700,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEnc FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED) return false; encoder->private_->disable_verbatim_subframes = value; @@ -1473,12 +1711,16 @@ FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__Stream FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->state; } FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->verify) return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder); else @@ -1487,6 +1729,9 @@ FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state( FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder) { + FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) return FLAC__StreamEncoderStateString[encoder->protected_->state]; else @@ -1496,6 +1741,8 @@ FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__ FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); if(0 != absolute_sample) *absolute_sample = encoder->private_->verify.error_stats.absolute_sample; if(0 != frame_number) @@ -1513,102 +1760,136 @@ FLAC_API void FLAC__stream_encoder_get_verify_decoder_error_stats(const FLAC__St FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->verify; } FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->streamable_subset; } FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->do_mid_side_stereo; } FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->loose_mid_side_stereo; } FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->channels; } FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->bits_per_sample; } FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->sample_rate; } FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->blocksize; } FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->max_lpc_order; } FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->qlp_coeff_precision; } FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->do_qlp_coeff_prec_search; } FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->do_escape_coding; } FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->do_exhaustive_model_search; } FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->min_residual_partition_order; } FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->max_residual_partition_order; } FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->rice_parameter_search_dist; } FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder) { FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); return encoder->protected_->total_samples_estimate; } @@ -1619,6 +1900,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, c const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize; FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK); j = 0; @@ -1749,6 +2032,8 @@ FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize; FLAC__ASSERT(0 != encoder); + FLAC__ASSERT(0 != encoder->private_); + FLAC__ASSERT(0 != encoder->protected_); FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK); j = k = 0; @@ -1915,12 +2200,20 @@ void set_defaults_(FLAC__StreamEncoder *encoder) encoder->private_->disable_constant_subframes = false; encoder->private_->disable_fixed_subframes = false; encoder->private_->disable_verbatim_subframes = false; +#if FLAC__HAS_OGG + encoder->private_->is_ogg = false; +#endif + encoder->private_->read_callback = 0; encoder->private_->write_callback = 0; encoder->private_->seek_callback = 0; encoder->private_->tell_callback = 0; encoder->private_->metadata_callback = 0; encoder->private_->progress_callback = 0; encoder->private_->client_data = 0; + +#if FLAC__HAS_OGG + FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect); +#endif } void free_(FLAC__StreamEncoder *encoder) @@ -2173,7 +2466,7 @@ FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples) return true; } -FLAC__StreamEncoderWriteStatus write_frame_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples) +FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples) { FLAC__StreamEncoderWriteStatus status; FLAC__uint64 output_position = 0; @@ -2229,6 +2522,22 @@ FLAC__StreamEncoderWriteStatus write_frame_(const FLAC__StreamEncoder *encoder, } } +#if FLAC__HAS_OGG + if(encoder->private_->is_ogg) { + status = FLAC__ogg_encoder_aspect_write_callback_wrapper( + &encoder->protected_->ogg_encoder_aspect, + FLAC__stream_encoder_get_total_samples_estimate(encoder), + buffer, + bytes, + samples, + encoder->private_->current_frame_number, + (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback, + encoder, + encoder->private_->client_data + ); + } + else +#endif status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data); if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { @@ -2401,6 +2710,181 @@ void update_metadata_(const FLAC__StreamEncoder *encoder) } } +/* Gets called when the encoding process has finished so that we can update the STREAMINFO and SEEKTABLE blocks. */ +void update_ogg_metadata_(FLAC__StreamEncoder *encoder) +{ + FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)]; + const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo; + const FLAC__uint64 samples = metadata->data.stream_info.total_samples; + const unsigned min_framesize = metadata->data.stream_info.min_framesize; + const unsigned max_framesize = metadata->data.stream_info.max_framesize; + ogg_page page; + + FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO); + + /* All this is based on intimate knowledge of the stream header + * layout, but a change to the header format that would break this + * would also break all streams encoded in the previous format. + */ + + /** + ** Write STREAMINFO stats + **/ + simple_ogg_page__init(&page); + if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) { + simple_ogg_page__clear(&page); + return; /* state already set */ + } + + /* + * Write MD5 signature + */ + { + const unsigned md5_offset = + FLAC__STREAM_METADATA_HEADER_LENGTH + + ( + FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + + FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN + ) / 8; + + if(md5_offset + 16 > (unsigned)page.body_len) { + encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; + simple_ogg_page__clear(&page); + return; + } + memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16); + } + + /* + * Write total samples + */ + { + const unsigned total_samples_byte_offset = + FLAC__STREAM_METADATA_HEADER_LENGTH + + ( + FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + + FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN + - 4 + ) / 8; + + if(total_samples_byte_offset + 5 > (unsigned)page.body_len) { + encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; + simple_ogg_page__clear(&page); + return; + } + b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0; + b[0] |= (FLAC__byte)((samples >> 32) & 0x0F); + b[1] = (FLAC__byte)((samples >> 24) & 0xFF); + b[2] = (FLAC__byte)((samples >> 16) & 0xFF); + b[3] = (FLAC__byte)((samples >> 8) & 0xFF); + b[4] = (FLAC__byte)(samples & 0xFF); + memcpy(page.body + total_samples_byte_offset, b, 5); + } + + /* + * Write min/max framesize + */ + { + const unsigned min_framesize_offset = + FLAC__STREAM_METADATA_HEADER_LENGTH + + ( + FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + + FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + ) / 8; + + if(min_framesize_offset + 6 > (unsigned)page.body_len) { + encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; + simple_ogg_page__clear(&page); + return; + } + b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF); + b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF); + b[2] = (FLAC__byte)(min_framesize & 0xFF); + b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF); + b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF); + b[5] = (FLAC__byte)(max_framesize & 0xFF); + memcpy(page.body + min_framesize_offset, b, 6); + } + if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) { + simple_ogg_page__clear(&page); + return; /* state already set */ + } + simple_ogg_page__clear(&page); + + /* + * Write seektable + */ + if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) { + unsigned i; + FLAC__byte *p; + + FLAC__format_seektable_sort(encoder->private_->seek_table); + + FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table)); + + simple_ogg_page__init(&page); + if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) { + simple_ogg_page__clear(&page); + return; /* state already set */ + } + + if(FLAC__STREAM_METADATA_HEADER_LENGTH + (18*encoder->private_->seek_table->num_points) > (unsigned)page.body_len) { + encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR; + simple_ogg_page__clear(&page); + return; + } + + for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) { + FLAC__uint64 xx; + unsigned x; + xx = encoder->private_->seek_table->points[i].sample_number; + b[7] = (FLAC__byte)xx; xx >>= 8; + b[6] = (FLAC__byte)xx; xx >>= 8; + b[5] = (FLAC__byte)xx; xx >>= 8; + b[4] = (FLAC__byte)xx; xx >>= 8; + b[3] = (FLAC__byte)xx; xx >>= 8; + b[2] = (FLAC__byte)xx; xx >>= 8; + b[1] = (FLAC__byte)xx; xx >>= 8; + b[0] = (FLAC__byte)xx; xx >>= 8; + xx = encoder->private_->seek_table->points[i].stream_offset; + b[15] = (FLAC__byte)xx; xx >>= 8; + b[14] = (FLAC__byte)xx; xx >>= 8; + b[13] = (FLAC__byte)xx; xx >>= 8; + b[12] = (FLAC__byte)xx; xx >>= 8; + b[11] = (FLAC__byte)xx; xx >>= 8; + b[10] = (FLAC__byte)xx; xx >>= 8; + b[9] = (FLAC__byte)xx; xx >>= 8; + b[8] = (FLAC__byte)xx; xx >>= 8; + x = encoder->private_->seek_table->points[i].frame_samples; + b[17] = (FLAC__byte)x; x >>= 8; + b[16] = (FLAC__byte)x; x >>= 8; + if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { + encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR; + simple_ogg_page__clear(&page); + return; + } + memcpy(p, b, 18); + } + + if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) { + simple_ogg_page__clear(&page); + return; /* state already set */ + } + simple_ogg_page__clear(&page); + } +} + FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_frame) { FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK); @@ -3908,6 +4392,20 @@ void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR; } +FLAC__StreamEncoderReadStatus file_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) +{ + (void)client_data; + + *bytes = (unsigned)fread(buffer, 1, *bytes, encoder->private_->file); + if (*bytes == 0) { + if (feof(encoder->private_->file)) + return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM; + else if (ferror(encoder->private_->file)) + return FLAC__STREAM_ENCODER_READ_STATUS_ABORT; + } + return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; +} + FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) { (void)client_data; @@ -3952,7 +4450,19 @@ FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *e (void)client_data, (void)current_frame; if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) { - if(0 != encoder->private_->progress_callback && samples > 0) { + FLAC__bool call_it = 0 != encoder->private_->progress_callback && ( +#if FLAC__HAS_OGG + /* We would like to be able to use 'samples > 0' in the + * clause here but currently because of the nature of our + * Ogg writing implementation, 'samples' is always 0 (see + * ogg_encoder_aspect.c). The downside is extra progress + * callbacks. + */ + encoder->private_->is_ogg? true : +#endif + samples > 0 + ); + if(call_it) { /* NOTE: We have to add +bytes, +samples, and +1 to the stats * because at this point in the callback chain, the stats * have not been updated. Only after we return and control diff --git a/src/libOggFLAC++/Makefile.am b/src/libOggFLAC++/Makefile.am deleted file mode 100644 index 9ce8ce7b..00000000 --- a/src/libOggFLAC++/Makefile.am +++ /dev/null @@ -1,50 +0,0 @@ -# libOggFLAC++ - Free Lossless Audio Codec + Ogg library -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# - Neither the name of the Xiph.org Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -lib_LTLIBRARIES = libOggFLAC++.la - -m4datadir = $(datadir)/aclocal -m4data_DATA = libOggFLAC++.m4 - -EXTRA_DIST = \ - Makefile.lite \ - libOggFLAC++_dynamic.dsp \ - libOggFLAC++_static.dsp \ - libOggFLAC++.m4 - -# see 'http://www.gnu.org/software/libtool/manual.html#Libtool-versioning' for numbering convention -libOggFLAC___la_LDFLAGS = -version-info 3:0:0 -libOggFLAC___la_LIBADD = ../libOggFLAC/libOggFLAC.la - -libOggFLAC___la_SOURCES = \ - file_decoder.cpp \ - file_encoder.cpp \ - stream_decoder.cpp \ - stream_encoder.cpp diff --git a/src/libOggFLAC++/Makefile.lite b/src/libOggFLAC++/Makefile.lite deleted file mode 100644 index e5dd81d7..00000000 --- a/src/libOggFLAC++/Makefile.lite +++ /dev/null @@ -1,48 +0,0 @@ -# libOggFLAC++ - Free Lossless Audio Codec + Ogg library -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# - Neither the name of the Xiph.org Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# -# GNU makefile -# - -topdir = ../.. - -LIB_NAME = libOggFLAC++ -INCLUDES = -I$(topdir)/include - -SRCS_CPP = \ - file_decoder.cpp \ - file_encoder.cpp \ - stream_decoder.cpp \ - stream_encoder.cpp - -include $(topdir)/build/lib.mk - -# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/src/libOggFLAC++/file_decoder.cpp b/src/libOggFLAC++/file_decoder.cpp deleted file mode 100644 index 201ed337..00000000 --- a/src/libOggFLAC++/file_decoder.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "OggFLAC++/decoder.h" -#include "FLAC/assert.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -namespace OggFLAC { - namespace Decoder { - - File::File(): - Stream() - { } - - File::~File() - { - } - - ::FLAC__StreamDecoderInitStatus File::init(FILE *file) - { - FLAC__ASSERT(0 != decoder_); - return ::OggFLAC__stream_decoder_init_FILE((OggFLAC__StreamDecoder*)decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamDecoderInitStatus File::init(const char *filename) - { - FLAC__ASSERT(0 != decoder_); - return ::OggFLAC__stream_decoder_init_file((OggFLAC__StreamDecoder*)decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamDecoderInitStatus File::init(const std::string &filename) - { - return init(filename.c_str()); - } - - // This is a dummy to satisfy the pure virtual from Stream; the - // read callback will never be called since we are initializing - // with FLAC__stream_decoder_init_FILE() or - // FLAC__stream_decoder_init_file() and those supply the read - // callback internally. - ::FLAC__StreamDecoderReadStatus File::read_callback(FLAC__byte buffer[], unsigned *bytes) - { - (void)buffer, (void)bytes; - FLAC__ASSERT(false); - return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; // double protection - } - - } -} diff --git a/src/libOggFLAC++/file_encoder.cpp b/src/libOggFLAC++/file_encoder.cpp deleted file mode 100644 index e89718cd..00000000 --- a/src/libOggFLAC++/file_encoder.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "OggFLAC++/encoder.h" -#include "FLAC/assert.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -namespace OggFLAC { - namespace Encoder { - - File::File(): - Stream() - { } - - File::~File() - { } - - ::FLAC__StreamEncoderInitStatus File::init(FILE *file) - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_init_FILE((OggFLAC__StreamEncoder*)encoder_, file, progress_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamEncoderInitStatus File::init(const char *filename) - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_init_file((OggFLAC__StreamEncoder*)encoder_, filename, progress_callback_, /*client_data=*/(void*)this); - } - - ::FLAC__StreamEncoderInitStatus File::init(const std::string &filename) - { - return init(filename.c_str()); - } - - // This is a dummy to satisfy the pure virtual from Stream; the - // read callback will never be called since we are initializing - // with OggFLAC__stream_decoder_init_FILE() or - // OggFLAC__stream_decoder_init_file() and those supply the read - // callback internally. - ::FLAC__StreamEncoderWriteStatus File::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) - { - (void)buffer, (void)bytes, (void)samples, (void)current_frame; - FLAC__ASSERT(false); - return ::FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; // double protection - } - - void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate) - { - (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate; - } - - void File::progress_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data) - { - (void)encoder; - FLAC__ASSERT(0 != client_data); - File *instance = reinterpret_cast<File *>(client_data); - FLAC__ASSERT(0 != instance); - instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate); - } - - } -} diff --git a/src/libOggFLAC++/libOggFLAC++.m4 b/src/libOggFLAC++/libOggFLAC++.m4 deleted file mode 100644 index b10e7ac2..00000000 --- a/src/libOggFLAC++/libOggFLAC++.m4 +++ /dev/null @@ -1,107 +0,0 @@ -# Configure paths for libOggFLAC++ -# "Inspired" by ogg.m4 -# Caller must first run AM_PATH_LIBOGGFLAC - -dnl AM_PATH_LIBOGGFLACPP([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libOggFLAC++, and define LIBOGGFLACPP_CFLAGS and LIBOGGFLACPP_LIBS -dnl -AC_DEFUN([AM_PATH_LIBOGGFLACPP], -[dnl -dnl Get the cflags and libraries -dnl -AC_ARG_WITH(libOggFLACPP,[ --with-libOggFLACPP=PFX Prefix where libOggFLAC++ is installed (optional)], libOggFLACPP_prefix="$withval", libOggFLACPP_prefix="") -AC_ARG_WITH(libOggFLACPP-libraries,[ --with-libOggFLACPP-libraries=DIR Directory where libOggFLAC++ library is installed (optional)], libOggFLACPP_libraries="$withval", libOggFLACPP_libraries="") -AC_ARG_WITH(libOggFLACPP-includes,[ --with-libOggFLACPP-includes=DIR Directory where libOggFLAC++ header files are installed (optional)], libOggFLACPP_includes="$withval", libOggFLACPP_includes="") -AC_ARG_ENABLE(libOggFLACPPtest, [ --disable-libOggFLACPPtest Do not try to compile and run a test libOggFLAC++ program],, enable_libOggFLACPPtest=yes) - - if test "x$libOggFLACPP_libraries" != "x" ; then - LIBOGGFLACPP_LIBS="-L$libOggFLACPP_libraries" - elif test "x$libOggFLACPP_prefix" != "x" ; then - LIBOGGFLACPP_LIBS="-L$libOggFLACPP_prefix/lib" - elif test "x$prefix" != "xNONE" ; then - LIBOGGFLACPP_LIBS="-L$libdir" - fi - - LIBOGGFLACPP_LIBS="$LIBOGGFLACPP_LIBS -lOggFLAC++ $LIBOGGFLAC_LIBS" - - if test "x$libOggFLACPP_includes" != "x" ; then - LIBOGGFLACPP_CFLAGS="-I$libOggFLACPP_includes" - elif test "x$libOggFLACPP_prefix" != "x" ; then - LIBOGGFLACPP_CFLAGS="-I$libOggFLACPP_prefix/include" - elif test "$prefix" != "xNONE"; then - LIBOGGFLACPP_CFLAGS="-I$prefix/include" - fi - - LIBOGGFLACPP_CFLAGS="$LIBOGGFLACPP_CFLAGS $LIBOGGFLAC_CFLAGS" - - AC_MSG_CHECKING(for libOggFLAC++) - no_libOggFLACPP="" - - - if test "x$enable_libOggFLACPPtest" = "xyes" ; then - ac_save_CFLAGS="$CFLAGS" - ac_save_CXXFLAGS="$CXXFLAGS" - ac_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $LIBOGGFLACPP_CFLAGS" - CXXFLAGS="$CXXFLAGS $LIBOGGFLACPP_CFLAGS" - LIBS="$LIBS $LIBOGGFLACPP_LIBS" -dnl -dnl Now check if the installed libOggFLAC++ is sufficiently new. -dnl - rm -f conf.libOggFLAC++test - AC_TRY_RUN([ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <OggFLAC++/decoder.h> - -int main () -{ - system("touch conf.libOggFLAC++test"); - return 0; -} - -],, no_libOggFLACPP=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - - if test "x$no_libOggFLACPP" = "x" ; then - AC_MSG_RESULT(yes) - ifelse([$1], , :, [$1]) - else - AC_MSG_RESULT(no) - if test -f conf.libOggFLAC++test ; then - : - else - echo "*** Could not run libOggFLAC++ test program, checking why..." - CFLAGS="$CFLAGS $LIBOGGFLACPP_CFLAGS" - LIBS="$LIBS $LIBOGGFLACPP_LIBS" - AC_TRY_LINK([ -#include <stdio.h> -#include <OggFLAC++/decoder.h> -], [ return 0; ], - [ echo "*** The test program compiled, but did not run. This usually means" - echo "*** that the run-time linker is not finding libOggFLAC++ or finding the wrong" - echo "*** version of libOggFLAC++. If it is not finding libOggFLAC++, you'll need to set your" - echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" - echo "*** to the installed location Also, make sure you have run ldconfig if that" - echo "*** is required on your system" - echo "***" - echo "*** If you have an old version installed, it is best to remove it, although" - echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], - [ echo "*** The test program failed to compile or link. See the file config.log for the" - echo "*** exact error that occured. This usually means libOggFLAC++ was incorrectly installed" - echo "*** or that you have moved libOggFLAC++ since it was installed. In the latter case, you" - echo "*** may want to edit the libOggFLAC++-config script: $LIBFLACPP_CONFIG" ]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - LIBOGGFLACPP_CFLAGS="" - LIBOGGFLACPP_LIBS="" - ifelse([$2], , :, [$2]) - fi - AC_SUBST(LIBOGGFLACPP_CFLAGS) - AC_SUBST(LIBOGGFLACPP_LIBS) - rm -f conf.libOggFLAC++test -]) diff --git a/src/libOggFLAC++/libOggFLAC++_dynamic.dsp b/src/libOggFLAC++/libOggFLAC++_dynamic.dsp deleted file mode 100644 index ef52d262..00000000 --- a/src/libOggFLAC++/libOggFLAC++_dynamic.dsp +++ /dev/null @@ -1,139 +0,0 @@ -# Microsoft Developer Studio Project File - Name="libOggFLAC++_dynamic" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=libOggFLAC++_dynamic - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "libOggFLAC++_dynamic.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "libOggFLAC++_dynamic.mak" CFG="libOggFLAC++_dynamic - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "libOggFLAC++_dynamic - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "libOggFLAC++_dynamic - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName "libOggFLAC++"
-# PROP Scc_LocalPath "..\.."
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "libOggFLAC++_dynamic - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\obj\release\lib"
-# PROP Intermediate_Dir "Release_dynamic"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I ".\include" /I "..\..\include" /D "NDEBUG" /D "OggFLACPP_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG" /d "_USRDLL"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
-# ADD LINK32 ..\..\obj\release\lib\libFLAC++.lib ..\..\obj\release\lib\libOggFLAC.lib ..\..\obj\release\lib\libFLAC.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:windows /dll /machine:I386 /out:"..\..\obj\release\bin/libOggFLAC++.dll"
-
-!ELSEIF "$(CFG)" == "libOggFLAC++_dynamic - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\obj\debug\lib"
-# PROP Intermediate_Dir "Debug_dynamic"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I ".\include" /I "..\..\include" /D "_DEBUG" /D "OggFLACPP_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG" /d "_USRDLL"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 ..\..\obj\debug\lib\libFLAC++.lib ..\..\obj\debug\lib\libOggFLAC.lib ..\..\obj\debug\lib\libFLAC.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"..\..\obj\debug\bin/libOggFLAC++.dll" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "libOggFLAC++_dynamic - Win32 Release"
-# Name "libOggFLAC++_dynamic - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp"
-# Begin Source File
-
-SOURCE=.\file_decoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\file_encoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\stream_decoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\stream_encoder.cpp
-# End Source File
-# End Group
-# Begin Group "Private Header Files"
-
-# PROP Default_Filter ""
-# End Group
-# Begin Group "Protected Header Files"
-
-# PROP Default_Filter ""
-# End Group
-# Begin Group "Public Header Files"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE="..\..\include\OggFLAC++\all.h"
-# End Source File
-# Begin Source File
-
-SOURCE="..\..\include\OggFLAC++\decoder.h"
-# End Source File
-# Begin Source File
-
-SOURCE="..\..\include\OggFLAC++\encoder.h"
-# End Source File
-# Begin Source File
-
-SOURCE="..\..\include\OggFLAC++\export.h"
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/src/libOggFLAC++/libOggFLAC++_static.dsp b/src/libOggFLAC++/libOggFLAC++_static.dsp deleted file mode 100644 index 573a97d9..00000000 --- a/src/libOggFLAC++/libOggFLAC++_static.dsp +++ /dev/null @@ -1,132 +0,0 @@ -# Microsoft Developer Studio Project File - Name="libOggFLAC++_static" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Static Library" 0x0104
-
-CFG=libOggFLAC++_static - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "libOggFLAC++_static.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "libOggFLAC++_static.mak" CFG="libOggFLAC++_static - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "libOggFLAC++_static - Win32 Release" (based on "Win32 (x86) Static Library")
-!MESSAGE "libOggFLAC++_static - Win32 Debug" (based on "Win32 (x86) Static Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName "libOggFLAC++"
-# PROP Scc_LocalPath "..\.."
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "libOggFLAC++_static - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\obj\release\lib"
-# PROP Intermediate_Dir "Release_static"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I ".\include" /I "..\..\include" /D "FLAC__NO_DLL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "libOggFLAC++_static - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\obj\debug\lib"
-# PROP Intermediate_Dir "Debug_static"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I ".\include" /I "..\..\include" /D "FLAC__NO_DLL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ENDIF
-
-# Begin Target
-
-# Name "libOggFLAC++_static - Win32 Release"
-# Name "libOggFLAC++_static - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp"
-# Begin Source File
-
-SOURCE=.\file_decoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\file_encoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\stream_decoder.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\stream_encoder.cpp
-# End Source File
-# End Group
-# Begin Group "Private Header Files"
-
-# PROP Default_Filter ""
-# End Group
-# Begin Group "Protected Header Files"
-
-# PROP Default_Filter ""
-# End Group
-# Begin Group "Public Header Files"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE="..\..\include\OggFLAC++\all.h"
-# End Source File
-# Begin Source File
-
-SOURCE="..\..\include\OggFLAC++\decoder.h"
-# End Source File
-# Begin Source File
-
-SOURCE="..\..\include\OggFLAC++\encoder.h"
-# End Source File
-# Begin Source File
-
-SOURCE="..\..\include\OggFLAC++\export.h"
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/src/libOggFLAC++/stream_decoder.cpp b/src/libOggFLAC++/stream_decoder.cpp deleted file mode 100644 index 7aaf9314..00000000 --- a/src/libOggFLAC++/stream_decoder.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "OggFLAC++/decoder.h" -#include "FLAC/assert.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -namespace OggFLAC { - namespace Decoder { - - // We can inherit from FLAC::Decoder::Stream because we jam a - // OggFLAC__StreamDecoder pointer into the decoder_ member, - // hence the pointer casting on decoder_ everywhere. - - Stream::Stream(): - FLAC::Decoder::Stream((FLAC__StreamDecoder*)::OggFLAC__stream_decoder_new()) - { } - - Stream::~Stream() - { - if(0 != decoder_) { - ::OggFLAC__stream_decoder_finish((OggFLAC__StreamDecoder*)decoder_); - ::OggFLAC__stream_decoder_delete((OggFLAC__StreamDecoder*)decoder_); - // this is our signal to FLAC::Decoder::Stream::~Stream() - // that we already deleted the decoder our way, so it - // doesn't need to: - decoder_ = 0; - } - } - - bool Stream::set_md5_checking(bool value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_set_md5_checking((OggFLAC__StreamDecoder*)decoder_, value); - } - - bool Stream::set_serial_number(long value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_set_serial_number((OggFLAC__StreamDecoder*)decoder_, value); - } - - bool Stream::set_metadata_respond(::FLAC__MetadataType type) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_set_metadata_respond((OggFLAC__StreamDecoder*)decoder_, type); - } - - bool Stream::set_metadata_respond_application(const FLAC__byte id[4]) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_set_metadata_respond_application((OggFLAC__StreamDecoder*)decoder_, id); - } - - bool Stream::set_metadata_respond_all() - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_set_metadata_respond_all((OggFLAC__StreamDecoder*)decoder_); - } - - bool Stream::set_metadata_ignore(::FLAC__MetadataType type) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_set_metadata_ignore((OggFLAC__StreamDecoder*)decoder_, type); - } - - bool Stream::set_metadata_ignore_application(const FLAC__byte id[4]) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_set_metadata_ignore_application((OggFLAC__StreamDecoder*)decoder_, id); - } - - bool Stream::set_metadata_ignore_all() - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_set_metadata_ignore_all((OggFLAC__StreamDecoder*)decoder_); - } - - Stream::State Stream::get_state() const - { - FLAC__ASSERT(is_valid()); - return State(::OggFLAC__stream_decoder_get_state((const OggFLAC__StreamDecoder*)decoder_)); - } - - FLAC::Decoder::Stream::State Stream::get_FLAC_stream_decoder_state() const - { - FLAC__ASSERT(is_valid()); - return FLAC::Decoder::Stream::State(::OggFLAC__stream_decoder_get_FLAC_stream_decoder_state((const OggFLAC__StreamDecoder*)decoder_)); - } - - bool Stream::get_md5_checking() const - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_get_md5_checking((const OggFLAC__StreamDecoder*)decoder_); - } - - FLAC__uint64 Stream::get_total_samples() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_decoder_get_total_samples((const OggFLAC__StreamDecoder*)decoder_); - } - - unsigned Stream::get_channels() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_decoder_get_channels((const OggFLAC__StreamDecoder*)decoder_); - } - - ::FLAC__ChannelAssignment Stream::get_channel_assignment() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_decoder_get_channel_assignment((const OggFLAC__StreamDecoder*)decoder_); - } - - unsigned Stream::get_bits_per_sample() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_decoder_get_bits_per_sample((const OggFLAC__StreamDecoder*)decoder_); - } - - unsigned Stream::get_sample_rate() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_decoder_get_sample_rate((const OggFLAC__StreamDecoder*)decoder_); - } - - unsigned Stream::get_blocksize() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_decoder_get_blocksize((const OggFLAC__StreamDecoder*)decoder_); - } - - ::FLAC__StreamDecoderInitStatus Stream::init() - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_decoder_init_stream((OggFLAC__StreamDecoder*)decoder_, read_callback_, seek_callback_, tell_callback_, length_callback_, eof_callback_, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this); - } - - void Stream::finish() - { - FLAC__ASSERT(is_valid()); - ::OggFLAC__stream_decoder_finish((OggFLAC__StreamDecoder*)decoder_); - } - - bool Stream::flush() - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_flush((OggFLAC__StreamDecoder*)decoder_); - } - - bool Stream::reset() - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_reset((OggFLAC__StreamDecoder*)decoder_); - } - - bool Stream::process_single() - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_process_single((OggFLAC__StreamDecoder*)decoder_); - } - - bool Stream::process_until_end_of_metadata() - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_process_until_end_of_metadata((OggFLAC__StreamDecoder*)decoder_); - } - - bool Stream::process_until_end_of_stream() - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_process_until_end_of_stream((OggFLAC__StreamDecoder*)decoder_); - } - - bool Stream::skip_single_frame() - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_skip_single_frame((OggFLAC__StreamDecoder*)decoder_); - } - - bool Stream::seek_absolute(FLAC__uint64 sample) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_decoder_seek_absolute((OggFLAC__StreamDecoder*)decoder_, sample); - } - - } -} diff --git a/src/libOggFLAC++/stream_encoder.cpp b/src/libOggFLAC++/stream_encoder.cpp deleted file mode 100644 index 43726137..00000000 --- a/src/libOggFLAC++/stream_encoder.cpp +++ /dev/null @@ -1,374 +0,0 @@ -/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "OggFLAC++/encoder.h" -#include "FLAC/assert.h" - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -namespace OggFLAC { - namespace Encoder { - - // We can inherit from FLAC::Encoder::Stream because we jam a - // OggFLAC__StreamEncoder pointer into the encoder_ member, - // hence the pointer casting on encoder_ everywhere. - - Stream::Stream(): - FLAC::Encoder::Stream((FLAC__StreamEncoder*)::OggFLAC__stream_encoder_new()) - { } - - Stream::~Stream() - { - if(0 != encoder_) { - ::OggFLAC__stream_encoder_finish((OggFLAC__StreamEncoder*)encoder_); - ::OggFLAC__stream_encoder_delete((OggFLAC__StreamEncoder*)encoder_); - // this is our signal to FLAC::Encoder::Stream::~Stream() - // that we already deleted the encoder our way, so it - // doesn't need to: - encoder_ = 0; - } - } - - bool Stream::set_serial_number(long value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_serial_number((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_verify(bool value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_verify((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_streamable_subset(bool value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_streamable_subset((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_do_mid_side_stereo(bool value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_do_mid_side_stereo((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_loose_mid_side_stereo(bool value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_loose_mid_side_stereo((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_channels(unsigned value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_channels((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_bits_per_sample(unsigned value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_bits_per_sample((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_sample_rate(unsigned value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_sample_rate((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_blocksize(unsigned value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_blocksize((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_apodization(const char *specification) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_apodization((OggFLAC__StreamEncoder*)encoder_, specification); - } - - bool Stream::set_max_lpc_order(unsigned value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_max_lpc_order((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_qlp_coeff_precision(unsigned value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_qlp_coeff_precision((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_do_qlp_coeff_prec_search(bool value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_do_escape_coding(bool value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_do_escape_coding((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_do_exhaustive_model_search(bool value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_do_exhaustive_model_search((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_min_residual_partition_order(unsigned value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_min_residual_partition_order((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_max_residual_partition_order(unsigned value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_max_residual_partition_order((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_rice_parameter_search_dist(unsigned value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_rice_parameter_search_dist((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_total_samples_estimate(FLAC__uint64 value) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_total_samples_estimate((OggFLAC__StreamEncoder*)encoder_, value); - } - - bool Stream::set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_set_metadata((OggFLAC__StreamEncoder*)encoder_, metadata, num_blocks); - } - - bool Stream::set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks) - { - FLAC__ASSERT(is_valid()); -#if (defined _MSC_VER) || (defined __SUNPRO_CC) - // MSVC++ can't handle: - // ::FLAC__StreamMetadata *m[num_blocks]; - // so we do this ugly workaround - ::FLAC__StreamMetadata **m = new ::FLAC__StreamMetadata*[num_blocks]; -#else - ::FLAC__StreamMetadata *m[num_blocks]; -#endif - for(unsigned i = 0; i < num_blocks; i++) { - // we can get away with the const_cast since we know the encoder will only correct the is_last flags - m[i] = const_cast< ::FLAC__StreamMetadata*>((const ::FLAC__StreamMetadata*)metadata[i]); - } -#if (defined _MSC_VER) || (defined __SUNPRO_CC) - // complete the hack - const bool ok = (bool)::OggFLAC__stream_encoder_set_metadata((OggFLAC__StreamEncoder*)encoder_, m, num_blocks); - delete [] m; - return ok; -#else - return (bool)::OggFLAC__stream_encoder_set_metadata((OggFLAC__StreamEncoder*)encoder_, m, num_blocks); -#endif - } - - Stream::State Stream::get_state() const - { - FLAC__ASSERT(is_valid()); - return State(::OggFLAC__stream_encoder_get_state((const OggFLAC__StreamEncoder*)encoder_)); - } - - FLAC::Encoder::Stream::State Stream::get_FLAC_stream_encoder_state() const - { - FLAC__ASSERT(is_valid()); - return FLAC::Encoder::Stream::State(::OggFLAC__stream_encoder_get_FLAC_stream_encoder_state((const OggFLAC__StreamEncoder*)encoder_)); - } - - FLAC::Decoder::Stream::State Stream::get_verify_decoder_state() const - { - FLAC__ASSERT(is_valid()); - return FLAC::Decoder::Stream::State(::OggFLAC__stream_encoder_get_verify_decoder_state((const OggFLAC__StreamEncoder*)encoder_)); - } - - void Stream::get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got) - { - FLAC__ASSERT(is_valid()); - ::OggFLAC__stream_encoder_get_verify_decoder_error_stats((const OggFLAC__StreamEncoder*)encoder_, absolute_sample, frame_number, channel, sample, expected, got); - } - - bool Stream::get_verify() const - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_get_verify((const OggFLAC__StreamEncoder*)encoder_); - } - - bool Stream::get_streamable_subset() const - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_get_streamable_subset((const OggFLAC__StreamEncoder*)encoder_); - } - - bool Stream::get_do_mid_side_stereo() const - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_get_do_mid_side_stereo((const OggFLAC__StreamEncoder*)encoder_); - } - - bool Stream::get_loose_mid_side_stereo() const - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_get_loose_mid_side_stereo((const OggFLAC__StreamEncoder*)encoder_); - } - - unsigned Stream::get_channels() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_channels((const OggFLAC__StreamEncoder*)encoder_); - } - - unsigned Stream::get_bits_per_sample() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_bits_per_sample((const OggFLAC__StreamEncoder*)encoder_); - } - - unsigned Stream::get_sample_rate() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_sample_rate((const OggFLAC__StreamEncoder*)encoder_); - } - - unsigned Stream::get_blocksize() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_blocksize((const OggFLAC__StreamEncoder*)encoder_); - } - - unsigned Stream::get_max_lpc_order() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_max_lpc_order((const OggFLAC__StreamEncoder*)encoder_); - } - - unsigned Stream::get_qlp_coeff_precision() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_qlp_coeff_precision((const OggFLAC__StreamEncoder*)encoder_); - } - - bool Stream::get_do_qlp_coeff_prec_search() const - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search((const OggFLAC__StreamEncoder*)encoder_); - } - - bool Stream::get_do_escape_coding() const - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_get_do_escape_coding((const OggFLAC__StreamEncoder*)encoder_); - } - - bool Stream::get_do_exhaustive_model_search() const - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_get_do_exhaustive_model_search((const OggFLAC__StreamEncoder*)encoder_); - } - - unsigned Stream::get_min_residual_partition_order() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_min_residual_partition_order((const OggFLAC__StreamEncoder*)encoder_); - } - - unsigned Stream::get_max_residual_partition_order() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_max_residual_partition_order((const OggFLAC__StreamEncoder*)encoder_); - } - - unsigned Stream::get_rice_parameter_search_dist() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_rice_parameter_search_dist((const OggFLAC__StreamEncoder*)encoder_); - } - - FLAC__uint64 Stream::get_total_samples_estimate() const - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_get_total_samples_estimate((const OggFLAC__StreamEncoder*)encoder_); - } - - ::FLAC__StreamEncoderInitStatus Stream::init() - { - FLAC__ASSERT(is_valid()); - return ::OggFLAC__stream_encoder_init_stream((OggFLAC__StreamEncoder*)encoder_, read_callback_, write_callback_, seek_callback_, tell_callback_, metadata_callback_, /*client_data=*/(void*)this); - } - - void Stream::finish() - { - FLAC__ASSERT(is_valid()); - ::OggFLAC__stream_encoder_finish((OggFLAC__StreamEncoder*)encoder_); - } - - bool Stream::process(const FLAC__int32 * const buffer[], unsigned samples) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_process((OggFLAC__StreamEncoder*)encoder_, buffer, samples); - } - - bool Stream::process_interleaved(const FLAC__int32 buffer[], unsigned samples) - { - FLAC__ASSERT(is_valid()); - return (bool)::OggFLAC__stream_encoder_process_interleaved((OggFLAC__StreamEncoder*)encoder_, buffer, samples); - } - - ::OggFLAC__StreamEncoderReadStatus Stream::read_callback(FLAC__byte buffer[], unsigned *bytes) - { - (void)buffer, (void)bytes; - return ::OggFLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED; - } - - ::OggFLAC__StreamEncoderReadStatus Stream::read_callback_(const ::OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) - { - (void)encoder; - FLAC__ASSERT(0 != client_data); - Stream *instance = reinterpret_cast<Stream *>(client_data); - FLAC__ASSERT(0 != instance); - return instance->read_callback(buffer, bytes); - } - - } -} diff --git a/src/libOggFLAC/Makefile.am b/src/libOggFLAC/Makefile.am deleted file mode 100644 index 4519dbd5..00000000 --- a/src/libOggFLAC/Makefile.am +++ /dev/null @@ -1,59 +0,0 @@ -# libOggFLAC - Free Lossless Audio Codec + Ogg library -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# - Neither the name of the Xiph.org Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -lib_LTLIBRARIES = libOggFLAC.la -if DEBUG -DEBUGCFLAGS = -endif - -AM_CFLAGS = @OGG_CFLAGS@ $(DEBUGCFLAGS) - -SUBDIRS = include . - -m4datadir = $(datadir)/aclocal -m4data_DATA = libOggFLAC.m4 - -EXTRA_DIST = \ - Makefile.lite \ - libOggFLAC_dynamic.dsp \ - libOggFLAC_static.dsp \ - libOggFLAC.m4 - -libOggFLAC_la_LIBADD = @OGG_LIBS@ ../libFLAC/libFLAC.la -# see 'http://www.gnu.org/software/libtool/manual.html#Libtool-versioning' for numbering convention -libOggFLAC_la_LDFLAGS = -version-info 4:0:0 - -libOggFLAC_la_SOURCES = \ - ogg_decoder_aspect.c \ - ogg_encoder_aspect.c \ - ogg_helper.c \ - ogg_mapping.c \ - stream_decoder.c \ - stream_encoder.c diff --git a/src/libOggFLAC/Makefile.lite b/src/libOggFLAC/Makefile.lite deleted file mode 100644 index 1f10aed3..00000000 --- a/src/libOggFLAC/Makefile.lite +++ /dev/null @@ -1,60 +0,0 @@ -# libOggFLAC - Free Lossless Audio Codec + Ogg library -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# - Neither the name of the Xiph.org Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -# -# GNU makefile -# - -topdir = ../.. - -LIB_NAME = libOggFLAC -ifeq ($(DARWIN_BUILD),yes) -DEFINES = -else -ifeq ($(SOLARIS_BUILD),yes) -DEFINES = -else -DEFINES = -endif -endif -INCLUDES = -I./include -I$(topdir)/include -I$(OGG_INCLUDE_DIR) -DEBUG_CFLAGS = - -SRCS_C = \ - ogg_decoder_aspect.c \ - ogg_encoder_aspect.c \ - ogg_helper.c \ - ogg_mapping.c \ - stream_decoder.c \ - stream_encoder.c - -include $(topdir)/build/lib.mk - -# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/src/libOggFLAC/include/Makefile.am b/src/libOggFLAC/include/Makefile.am deleted file mode 100644 index 4947c692..00000000 --- a/src/libOggFLAC/include/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -# libOggFLAC - Free Lossless Audio Codec + Ogg library -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# - Neither the name of the Xiph.org Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -SUBDIRS = private protected diff --git a/src/libOggFLAC/include/private/Makefile.am b/src/libOggFLAC/include/private/Makefile.am deleted file mode 100644 index a47fbb40..00000000 --- a/src/libOggFLAC/include/private/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -# libOggFLAC - Free Lossless Audio Codec + Ogg library -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# - Neither the name of the Xiph.org Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -noinst_HEADERS = \ - all.h \ - ogg_decoder_aspect.h \ - ogg_encoder_aspect.h \ - ogg_helper.h \ - ogg_mapping.h diff --git a/src/libOggFLAC/include/private/all.h b/src/libOggFLAC/include/private/all.h deleted file mode 100644 index 54cd93b1..00000000 --- a/src/libOggFLAC/include/private/all.h +++ /dev/null @@ -1,40 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLAC__PRIVATE__ALL_H -#define OggFLAC__PRIVATE__ALL_H - -#include "ogg_decoder_aspect.h" -#include "ogg_encoder_aspect.h" -#include "ogg_helper.h" -#include "ogg_mapping.h" - -#endif diff --git a/src/libOggFLAC/include/protected/Makefile.am b/src/libOggFLAC/include/protected/Makefile.am deleted file mode 100644 index fd7b6f91..00000000 --- a/src/libOggFLAC/include/protected/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -# libOggFLAC - Free Lossless Audio Codec + Ogg library -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# - Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# - Neither the name of the Xiph.org Foundation nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -noinst_HEADERS = \ - all.h \ - stream_decoder.h \ - stream_encoder.h diff --git a/src/libOggFLAC/include/protected/all.h b/src/libOggFLAC/include/protected/all.h deleted file mode 100644 index 35940791..00000000 --- a/src/libOggFLAC/include/protected/all.h +++ /dev/null @@ -1,38 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLAC__PROTECTED__ALL_H -#define OggFLAC__PROTECTED__ALL_H - -#include "stream_decoder.h" -#include "stream_encoder.h" - -#endif diff --git a/src/libOggFLAC/include/protected/stream_decoder.h b/src/libOggFLAC/include/protected/stream_decoder.h deleted file mode 100644 index c291cdbf..00000000 --- a/src/libOggFLAC/include/protected/stream_decoder.h +++ /dev/null @@ -1,43 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLAC__PROTECTED__STREAM_DECODER_H -#define OggFLAC__PROTECTED__STREAM_DECODER_H - -#include "OggFLAC/stream_decoder.h" -#include "private/ogg_decoder_aspect.h" - -typedef struct OggFLAC__StreamDecoderProtected { - OggFLAC__StreamDecoderState state; - OggFLAC__OggDecoderAspect ogg_decoder_aspect; -} OggFLAC__StreamDecoderProtected; - -#endif diff --git a/src/libOggFLAC/include/protected/stream_encoder.h b/src/libOggFLAC/include/protected/stream_encoder.h deleted file mode 100644 index a47a4674..00000000 --- a/src/libOggFLAC/include/protected/stream_encoder.h +++ /dev/null @@ -1,44 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OggFLAC__PROTECTED__STREAM_ENCODER_H -#define OggFLAC__PROTECTED__STREAM_ENCODER_H - -#include "OggFLAC/stream_encoder.h" -#include "private/ogg_encoder_aspect.h" - -typedef struct OggFLAC__StreamEncoderProtected { - OggFLAC__StreamEncoderState state; - OggFLAC__OggEncoderAspect ogg_encoder_aspect; - FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset; -} OggFLAC__StreamEncoderProtected; - -#endif diff --git a/src/libOggFLAC/libOggFLAC.m4 b/src/libOggFLAC/libOggFLAC.m4 deleted file mode 100644 index a04623f6..00000000 --- a/src/libOggFLAC/libOggFLAC.m4 +++ /dev/null @@ -1,104 +0,0 @@ -# Configure paths for libOggFLAC -# "Inspired" by ogg.m4 - -dnl AM_PATH_LIBOGGFLAC([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for libOggFLAC, and define LIBOGGFLAC_CFLAGS and LIBOGGFLAC_LIBS -dnl -AC_DEFUN([AM_PATH_LIBOGGFLAC], -[dnl -dnl Get the cflags and libraries -dnl -AC_ARG_WITH(libOggFLAC,[ --with-libOggFLAC=PFX Prefix where libOggFLAC is installed (optional)], libOggFLAC_prefix="$withval", libOggFLAC_prefix="") -AC_ARG_WITH(libOggFLAC-libraries,[ --with-libOggFLAC-libraries=DIR Directory where libOggFLAC library is installed (optional)], libOggFLAC_libraries="$withval", libOggFLAC_libraries="") -AC_ARG_WITH(libOggFLAC-includes,[ --with-libOggFLAC-includes=DIR Directory where libOggFLAC header files are installed (optional)], libOggFLAC_includes="$withval", libOggFLAC_includes="") -AC_ARG_ENABLE(libOggFLACtest, [ --disable-libOggFLACtest Do not try to compile and run a test libOggFLAC program],, enable_libOggFLACtest=yes) - - if test "x$libOggFLAC_libraries" != "x" ; then - LIBOGGFLAC_LIBS="-L$libOggFLAC_libraries" - elif test "x$libOggFLAC_prefix" != "x" ; then - LIBOGGFLAC_LIBS="-L$libOggFLAC_prefix/lib" - elif test "x$prefix" != "xNONE" ; then - LIBOGGFLAC_LIBS="-L$libdir" - fi - - LIBOGGFLAC_LIBS="$LIBOGGFLAC_LIBS -lOggFLAC -lFLAC -lm" - - if test "x$libOggFLAC_includes" != "x" ; then - LIBOGGFLAC_CFLAGS="-I$libOggFLAC_includes" - elif test "x$libOggFLAC_prefix" != "x" ; then - LIBOGGFLAC_CFLAGS="-I$libOggFLAC_prefix/include" - elif test "$prefix" != "xNONE"; then - LIBOGGFLAC_CFLAGS="-I$prefix/include" - fi - - AC_MSG_CHECKING(for libOggFLAC) - no_libOggFLAC="" - - - if test "x$enable_libOggFLACtest" = "xyes" ; then - ac_save_CFLAGS="$CFLAGS" - ac_save_CXXFLAGS="$CXXFLAGS" - ac_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $LIBOGGFLAC_CFLAGS" - CXXFLAGS="$CXXFLAGS $LIBOGGFLAC_CFLAGS" - LIBS="$LIBS $LIBOGGFLAC_LIBS" -dnl -dnl Now check if the installed libOggFLAC is sufficiently new. -dnl - rm -f conf.libOggFLACtest - AC_TRY_RUN([ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <OggFLAC/stream_decoder.h> - -int main () -{ - system("touch conf.libOggFLACtest"); - return 0; -} - -],, no_libOggFLAC=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - - if test "x$no_libOggFLAC" = "x" ; then - AC_MSG_RESULT(yes) - ifelse([$1], , :, [$1]) - else - AC_MSG_RESULT(no) - if test -f conf.libOggFLACtest ; then - : - else - echo "*** Could not run libOggFLAC test program, checking why..." - CFLAGS="$CFLAGS $LIBOGGFLAC_CFLAGS" - LIBS="$LIBS $LIBOGGFLAC_LIBS" - AC_TRY_LINK([ -#include <stdio.h> -#include <OggFLAC/stream_decoder.h> -], [ return 0; ], - [ echo "*** The test program compiled, but did not run. This usually means" - echo "*** that the run-time linker is not finding libOggFLAC or finding the wrong" - echo "*** version of libOggFLAC. If it is not finding libOggFLAC, you'll need to set your" - echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" - echo "*** to the installed location Also, make sure you have run ldconfig if that" - echo "*** is required on your system" - echo "***" - echo "*** If you have an old version installed, it is best to remove it, although" - echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], - [ echo "*** The test program failed to compile or link. See the file config.log for the" - echo "*** exact error that occured. This usually means libOggFLAC was incorrectly installed" - echo "*** or that you have moved libOggFLAC since it was installed. In the latter case, you" - echo "*** may want to edit the libOggFLAC-config script: $LIBOGGFLAC_CONFIG" ]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - LIBOGGFLAC_CFLAGS="" - LIBOGGFLAC_LIBS="" - ifelse([$2], , :, [$2]) - fi - AC_SUBST(LIBOGGFLAC_CFLAGS) - AC_SUBST(LIBOGGFLAC_LIBS) - rm -f conf.libOggFLACtest -]) diff --git a/src/libOggFLAC/libOggFLAC_dynamic.dsp b/src/libOggFLAC/libOggFLAC_dynamic.dsp deleted file mode 100644 index 0f630d63..00000000 --- a/src/libOggFLAC/libOggFLAC_dynamic.dsp +++ /dev/null @@ -1,179 +0,0 @@ -# Microsoft Developer Studio Project File - Name="libOggFLAC_dynamic" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=libOggFLAC_dynamic - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "libOggFLAC_dynamic.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "libOggFLAC_dynamic.mak" CFG="libOggFLAC_dynamic - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "libOggFLAC_dynamic - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "libOggFLAC_dynamic - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName "libOggFLAC"
-# PROP Scc_LocalPath "..\.."
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "libOggFLAC_dynamic - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\obj\release\lib"
-# PROP Intermediate_Dir "Release_dynamic"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I ".\include" /I "..\..\include" /D "NDEBUG" /D "OggFLAC_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG" /d "_USRDLL"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
-# ADD LINK32 ..\..\obj\release\lib\libFLAC.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:windows /dll /machine:I386 /out:"..\..\obj\release\bin/libOggFLAC.dll"
-
-!ELSEIF "$(CFG)" == "libOggFLAC_dynamic - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\obj\debug\lib"
-# PROP Intermediate_Dir "Debug_dynamic"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I ".\include" /I "..\..\include" /D "_DEBUG" /D "OggFLAC_API_EXPORTS" /D "_WINDOWS" /D "_WINDLL" /D "WIN32" /D "_USRDLL" /FR /FD /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win32
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG" /d "_USRDLL"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 ..\..\obj\debug\lib\libFLAC.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:windows /dll /debug /machine:I386 /out:"..\..\obj\debug\bin/libOggFLAC.dll" /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "libOggFLAC_dynamic - Win32 Release"
-# Name "libOggFLAC_dynamic - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "c"
-# Begin Source File
-
-SOURCE=.\ogg_decoder_aspect.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ogg_encoder_aspect.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ogg_helper.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ogg_mapping.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stream_decoder.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stream_encoder.c
-# End Source File
-# End Group
-# Begin Group "Private Header Files"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=.\include\private\all.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\private\ogg_decoder_aspect.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\private\ogg_encoder_aspect.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\private\ogg_helper.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\private\ogg_mapping.h
-# End Source File
-# End Group
-# Begin Group "Protected Header Files"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=.\include\protected\all.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\protected\stream_decoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\protected\stream_encoder.h
-# End Source File
-# End Group
-# Begin Group "Public Header Files"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\include\OggFLAC\all.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\include\OggFLAC\export.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\include\OggFLAC\stream_decoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\include\OggFLAC\stream_encoder.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/src/libOggFLAC/libOggFLAC_static.dsp b/src/libOggFLAC/libOggFLAC_static.dsp deleted file mode 100644 index 466512af..00000000 --- a/src/libOggFLAC/libOggFLAC_static.dsp +++ /dev/null @@ -1,172 +0,0 @@ -# Microsoft Developer Studio Project File - Name="libOggFLAC_static" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Static Library" 0x0104
-
-CFG=libOggFLAC_static - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "libOggFLAC_static.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "libOggFLAC_static.mak" CFG="libOggFLAC_static - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "libOggFLAC_static - Win32 Release" (based on "Win32 (x86) Static Library")
-!MESSAGE "libOggFLAC_static - Win32 Debug" (based on "Win32 (x86) Static Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName "libOggFLAC"
-# PROP Scc_LocalPath "..\.."
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "libOggFLAC_static - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\obj\release\lib"
-# PROP Intermediate_Dir "Release_static"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I ".\include" /I "..\..\include" /D "FLAC__NO_DLL" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /nodefaultlib
-
-!ELSEIF "$(CFG)" == "libOggFLAC_static - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\obj\debug\lib"
-# PROP Intermediate_Dir "Debug_static"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I ".\include" /I "..\..\include" /D "FLAC__NO_DLL" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo /nodefaultlib
-
-!ENDIF
-
-# Begin Target
-
-# Name "libOggFLAC_static - Win32 Release"
-# Name "libOggFLAC_static - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "c"
-# Begin Source File
-
-SOURCE=.\ogg_decoder_aspect.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ogg_encoder_aspect.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ogg_helper.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\ogg_mapping.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stream_decoder.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\stream_encoder.c
-# End Source File
-# End Group
-# Begin Group "Private Header Files"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=.\include\private\all.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\private\ogg_decoder_aspect.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\private\ogg_encoder_aspect.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\private\ogg_helper.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\private\ogg_mapping.h
-# End Source File
-# End Group
-# Begin Group "Protected Header Files"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=.\include\protected\all.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\protected\stream_decoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\include\protected\stream_encoder.h
-# End Source File
-# End Group
-# Begin Group "Public Header Files"
-
-# PROP Default_Filter ""
-# Begin Source File
-
-SOURCE=..\..\include\OggFLAC\all.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\include\OggFLAC\export.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\include\OggFLAC\stream_decoder.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\include\OggFLAC\stream_encoder.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/src/libOggFLAC/stream_decoder.c b/src/libOggFLAC/stream_decoder.c deleted file mode 100644 index 20f9ec8c..00000000 --- a/src/libOggFLAC/stream_decoder.c +++ /dev/null @@ -1,1064 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#if defined _MSC_VER || defined __MINGW32__ -#include <io.h> /* for _setmode() */ -#include <fcntl.h> /* for _O_BINARY */ -#endif -#if defined __CYGWIN__ || defined __EMX__ -#include <io.h> /* for setmode(), O_BINARY */ -#include <fcntl.h> /* for _O_BINARY */ -#endif -#include <stdio.h> -#include <stdlib.h> /* for calloc() */ -#include <sys/stat.h> /* for stat() */ -#include <sys/types.h> /* for off_t */ -#if defined _MSC_VER || defined __MINGW32__ -#if _MSC_VER <= 1200 /* @@@ [2G limit] */ -#define fseeko fseek -#define ftello ftell -#endif -#endif -#include "FLAC/assert.h" -#include "protected/stream_decoder.h" -#include "../libFLAC/include/private/float.h" /* @@@ ugly hack, but how else to do? we need to reuse the float formats but don't want to expose it */ - -/*********************************************************************** - * - * Private class method prototypes - * - ***********************************************************************/ - -static void set_defaults_(OggFLAC__StreamDecoder *decoder); -static FILE *get_binary_stdin_(); -static FLAC__StreamDecoderReadStatus read_callback2_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); -static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); -static OggFLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); -static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); -static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); -static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); -static FLAC__bool seek_to_absolute_sample_(OggFLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample); -static FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); -static FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); -static FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); -static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); -static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data); - - -/*********************************************************************** - * - * Private class data - * - ***********************************************************************/ - -typedef struct OggFLAC__StreamDecoderPrivate { - FLAC__StreamDecoderReadCallback read_callback; - FLAC__StreamDecoderSeekCallback seek_callback; - FLAC__StreamDecoderTellCallback tell_callback; - FLAC__StreamDecoderLengthCallback length_callback; - FLAC__StreamDecoderEofCallback eof_callback; - FLAC__StreamDecoderWriteCallback write_callback; - FLAC__StreamDecoderMetadataCallback metadata_callback; - FLAC__StreamDecoderErrorCallback error_callback; - void *client_data; - FILE *file; /* only used if OggFLAC__stream_decoder_init_file()/OggFLAC__stream_decoder_init_file() called, else NULL */ - /* the rest of these are only used for seeking: */ - FLAC__bool is_seeking; - FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */ - FLAC__uint64 target_sample; - FLAC__bool got_a_frame; /* hack needed in seek routine to check when process_single() actually writes a frame */ -} OggFLAC__StreamDecoderPrivate; - -/*********************************************************************** - * - * Public static class data - * - ***********************************************************************/ - -OggFLAC_API const char * const OggFLAC__StreamDecoderStateString[] = { - "OggFLAC__STREAM_DECODER_OK", - "OggFLAC__STREAM_DECODER_END_OF_STREAM", - "OggFLAC__STREAM_DECODER_OGG_ERROR", - "OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR", - "OggFLAC__STREAM_DECODER_SEEK_ERROR", - "OggFLAC__STREAM_DECODER_READ_ERROR", - "OggFLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR", - "OggFLAC__STREAM_DECODER_UNINITIALIZED" -}; - - -/*********************************************************************** - * - * Class constructor/destructor - * - ***********************************************************************/ -OggFLAC_API OggFLAC__StreamDecoder *OggFLAC__stream_decoder_new() -{ - OggFLAC__StreamDecoder *decoder; - FLAC__StreamDecoder *parent; - - FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */ - - decoder = (OggFLAC__StreamDecoder*)calloc(1, sizeof(OggFLAC__StreamDecoder)); - if(decoder == 0) { - return 0; - } - - decoder->protected_ = (OggFLAC__StreamDecoderProtected*)calloc(1, sizeof(OggFLAC__StreamDecoderProtected)); - if(decoder->protected_ == 0) { - free(decoder); - return 0; - } - - decoder->private_ = (OggFLAC__StreamDecoderPrivate*)calloc(1, sizeof(OggFLAC__StreamDecoderPrivate)); - if(decoder->private_ == 0) { - free(decoder->protected_); - free(decoder); - return 0; - } - - parent = FLAC__stream_decoder_new(); - if(0 == parent) { - free(decoder->private_); - free(decoder->protected_); - free(decoder); - return 0; - } - decoder->super_ = *parent; - - decoder->private_->file = 0; - - set_defaults_(decoder); - - decoder->protected_->state = OggFLAC__STREAM_DECODER_UNINITIALIZED; - - return decoder; -} - -OggFLAC_API void OggFLAC__stream_decoder_delete(OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - FLAC__ASSERT(0 != decoder->private_); - - OggFLAC__stream_decoder_finish(decoder); - - free(decoder->private_); - free(decoder->protected_); - /* don't free(decoder) because FLAC__stream_decoder_delete() will do it */ - - /* call superclass destructor last */ - FLAC__stream_decoder_delete((FLAC__StreamDecoder*)decoder); -} - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -OggFLAC_API FLAC__StreamDecoderInitStatus OggFLAC__stream_decoder_init_stream( - OggFLAC__StreamDecoder *decoder, - FLAC__StreamDecoderReadCallback read_callback, - FLAC__StreamDecoderSeekCallback seek_callback, - FLAC__StreamDecoderTellCallback tell_callback, - FLAC__StreamDecoderLengthCallback length_callback, - FLAC__StreamDecoderEofCallback eof_callback, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -) -{ - FLAC__ASSERT(0 != decoder); - - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED; - - if( - 0 == read_callback || - 0 == write_callback || - 0 == error_callback || - (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback)) - ) - return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS; - - if(!OggFLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect)) - return decoder->protected_->state = OggFLAC__STREAM_DECODER_OGG_ERROR; - - /* from here on, errors are fatal */ - - decoder->private_->read_callback = read_callback; - decoder->private_->seek_callback = seek_callback; - decoder->private_->tell_callback = tell_callback; - decoder->private_->length_callback = length_callback; - decoder->private_->eof_callback = eof_callback; - decoder->private_->write_callback = write_callback; - decoder->private_->metadata_callback = metadata_callback; - decoder->private_->error_callback = error_callback; - decoder->private_->client_data = client_data; - - decoder->private_->is_seeking = false; - - if(FLAC__stream_decoder_init_stream((FLAC__StreamDecoder*)decoder, read_callback_ogg_aspect_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, write_callback_, metadata_callback_, error_callback_, /*client_data=*/decoder) != FLAC__STREAM_DECODER_INIT_STATUS_OK) \ - return decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR; - - decoder->protected_->state = OggFLAC__STREAM_DECODER_OK; - return FLAC__STREAM_DECODER_INIT_STATUS_OK; -} - -OggFLAC_API FLAC__StreamDecoderInitStatus OggFLAC__stream_decoder_init_FILE( - OggFLAC__StreamDecoder *decoder, - FILE *file, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != file); - - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED; - - if(0 == write_callback || 0 == error_callback) - return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS; - - /* - * To make sure that our file does not go unclosed after an error, we - * must assign the FILE pointer before any further error can occur in - * this routine. - */ - if(file == stdin) - file = get_binary_stdin_(); /* just to be safe */ - - decoder->private_->file = file; - - return OggFLAC__stream_decoder_init_stream( - decoder, - file_read_callback_, - decoder->private_->file == stdin? 0: file_seek_callback_, - decoder->private_->file == stdin? 0: file_tell_callback_, - decoder->private_->file == stdin? 0: file_length_callback_, - file_eof_callback_, - write_callback, - metadata_callback, - error_callback, - client_data - ); -} - -OggFLAC_API FLAC__StreamDecoderInitStatus OggFLAC__stream_decoder_init_file( - OggFLAC__StreamDecoder *decoder, - const char *filename, - FLAC__StreamDecoderWriteCallback write_callback, - FLAC__StreamDecoderMetadataCallback metadata_callback, - FLAC__StreamDecoderErrorCallback error_callback, - void *client_data -) -{ - FILE *file; - - FLAC__ASSERT(0 != decoder); - - /* - * To make sure that our file does not go unclosed after an error, we - * have to do the same entrance checks here that are later performed - * in OggFLAC__stream_decoder_init_FILE() before the FILE* is assigned. - */ - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED; - - if(0 == write_callback || 0 == error_callback) - return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS; - - file = filename? fopen(filename, "rb") : stdin; - - if(0 == file) - return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE; - - return OggFLAC__stream_decoder_init_FILE(decoder, file, write_callback, metadata_callback, error_callback, client_data); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_finish(OggFLAC__StreamDecoder *decoder) -{ - FLAC__bool md5_ok; - - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - - if(decoder->protected_->state == OggFLAC__STREAM_DECODER_UNINITIALIZED) - return true; - - md5_ok = FLAC__stream_decoder_finish((FLAC__StreamDecoder*)decoder); - - OggFLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect); - - if(0 != decoder->private_->file) { - if(decoder->private_->file != stdin) - fclose(decoder->private_->file); - decoder->private_->file = 0; - } - - decoder->private_->is_seeking = false; - - set_defaults_(decoder); - - decoder->protected_->state = OggFLAC__STREAM_DECODER_UNINITIALIZED; - - return md5_ok; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_md5_checking(OggFLAC__StreamDecoder *decoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return false; - return FLAC__stream_decoder_set_md5_checking((FLAC__StreamDecoder*)decoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_serial_number(OggFLAC__StreamDecoder *decoder, long value) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return false; - OggFLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value); - return true; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_respond(OggFLAC__StreamDecoder *decoder, FLAC__MetadataType type) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return false; - return FLAC__stream_decoder_set_metadata_respond((FLAC__StreamDecoder*)decoder, type); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_respond_application(OggFLAC__StreamDecoder *decoder, const FLAC__byte id[4]) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return false; - return FLAC__stream_decoder_set_metadata_respond_application((FLAC__StreamDecoder*)decoder, id); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_respond_all(OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return false; - return FLAC__stream_decoder_set_metadata_respond_all((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore(OggFLAC__StreamDecoder *decoder, FLAC__MetadataType type) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return false; - return FLAC__stream_decoder_set_metadata_ignore((FLAC__StreamDecoder*)decoder, type); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore_application(OggFLAC__StreamDecoder *decoder, const FLAC__byte id[4]) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return false; - return FLAC__stream_decoder_set_metadata_ignore_application((FLAC__StreamDecoder*)decoder, id); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore_all(OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_UNINITIALIZED) - return false; - return FLAC__stream_decoder_set_metadata_ignore_all((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API OggFLAC__StreamDecoderState OggFLAC__stream_decoder_get_state(const OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->protected_); - return decoder->protected_->state; -} - -OggFLAC_API FLAC__StreamDecoderState OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(const OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - return FLAC__stream_decoder_get_state((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API const char *OggFLAC__stream_decoder_get_resolved_state_string(const OggFLAC__StreamDecoder *decoder) -{ - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) - return OggFLAC__StreamDecoderStateString[decoder->protected_->state]; - else - return FLAC__stream_decoder_get_resolved_state_string((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_get_md5_checking(const OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - return FLAC__stream_decoder_get_md5_checking((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API FLAC__uint64 OggFLAC__stream_decoder_get_total_samples(const OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - return FLAC__stream_decoder_get_total_samples((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API unsigned OggFLAC__stream_decoder_get_channels(const OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - return FLAC__stream_decoder_get_channels((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API FLAC__ChannelAssignment OggFLAC__stream_decoder_get_channel_assignment(const OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - return FLAC__stream_decoder_get_channel_assignment((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API unsigned OggFLAC__stream_decoder_get_bits_per_sample(const OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - return FLAC__stream_decoder_get_bits_per_sample((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API unsigned OggFLAC__stream_decoder_get_sample_rate(const OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - return FLAC__stream_decoder_get_sample_rate((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API unsigned OggFLAC__stream_decoder_get_blocksize(const OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - return FLAC__stream_decoder_get_blocksize((FLAC__StreamDecoder*)decoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_flush(OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - - OggFLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect); - - if(!FLAC__stream_decoder_flush((FLAC__StreamDecoder*)decoder)) { - decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR; - return false; - } - - decoder->protected_->state = OggFLAC__STREAM_DECODER_OK; - - return true; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_reset(OggFLAC__StreamDecoder *decoder) -{ - FLAC__ASSERT(0 != decoder); - FLAC__ASSERT(0 != decoder->private_); - FLAC__ASSERT(0 != decoder->protected_); - - if(!OggFLAC__stream_decoder_flush(decoder)) { - decoder->protected_->state = OggFLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return false; - } - - OggFLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect); - - if(!FLAC__stream_decoder_reset((FLAC__StreamDecoder*)decoder)) { - decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR; - return false; - } - - decoder->protected_->state = OggFLAC__STREAM_DECODER_OK; - - return true; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_single(OggFLAC__StreamDecoder *decoder) -{ - FLAC__bool ret; - FLAC__ASSERT(0 != decoder); - - if(FLAC__stream_decoder_get_state((FLAC__StreamDecoder*)decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) - decoder->protected_->state = OggFLAC__STREAM_DECODER_END_OF_STREAM; - - if(decoder->protected_->state == OggFLAC__STREAM_DECODER_END_OF_STREAM) - return true; - - FLAC__ASSERT(decoder->protected_->state == OggFLAC__STREAM_DECODER_OK); - - ret = FLAC__stream_decoder_process_single((FLAC__StreamDecoder*)decoder); - if(!ret) - decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR; - - return ret; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_until_end_of_metadata(OggFLAC__StreamDecoder *decoder) -{ - FLAC__bool ret; - FLAC__ASSERT(0 != decoder); - - if(FLAC__stream_decoder_get_state((FLAC__StreamDecoder*)decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) - decoder->protected_->state = OggFLAC__STREAM_DECODER_END_OF_STREAM; - - if(decoder->protected_->state == OggFLAC__STREAM_DECODER_END_OF_STREAM) - return true; - - FLAC__ASSERT(decoder->protected_->state == OggFLAC__STREAM_DECODER_OK); - - ret = FLAC__stream_decoder_process_until_end_of_metadata((FLAC__StreamDecoder*)decoder); - if(!ret) - decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR; - - return ret; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_until_end_of_stream(OggFLAC__StreamDecoder *decoder) -{ - FLAC__bool ret; - FLAC__ASSERT(0 != decoder); - - if(FLAC__stream_decoder_get_state((FLAC__StreamDecoder*)decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) - decoder->protected_->state = OggFLAC__STREAM_DECODER_END_OF_STREAM; - - if(decoder->protected_->state == OggFLAC__STREAM_DECODER_END_OF_STREAM) - return true; - - FLAC__ASSERT(decoder->protected_->state == OggFLAC__STREAM_DECODER_OK); - - ret = FLAC__stream_decoder_process_until_end_of_stream((FLAC__StreamDecoder*)decoder); - if(!ret) - decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR; - - return ret; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_skip_single_frame(OggFLAC__StreamDecoder *decoder) -{ - FLAC__bool ret; - FLAC__ASSERT(0 != decoder); - - if(FLAC__stream_decoder_get_state((FLAC__StreamDecoder*)decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) - decoder->protected_->state = OggFLAC__STREAM_DECODER_END_OF_STREAM; - - if(decoder->protected_->state == OggFLAC__STREAM_DECODER_END_OF_STREAM) - return true; - - FLAC__ASSERT(decoder->protected_->state == OggFLAC__STREAM_DECODER_OK); - - ret = FLAC__stream_decoder_skip_single_frame((FLAC__StreamDecoder*)decoder); - if(!ret) - decoder->protected_->state = OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR; - - return ret; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_decoder_seek_absolute(OggFLAC__StreamDecoder *decoder, FLAC__uint64 sample) -{ - FLAC__uint64 length; - - FLAC__ASSERT(0 != decoder); - - if(decoder->protected_->state != OggFLAC__STREAM_DECODER_OK && decoder->protected_->state != OggFLAC__STREAM_DECODER_END_OF_STREAM) - return false; - - if(0 == decoder->private_->seek_callback) - return false; - - FLAC__ASSERT(decoder->private_->seek_callback); - FLAC__ASSERT(decoder->private_->tell_callback); - FLAC__ASSERT(decoder->private_->length_callback); - FLAC__ASSERT(decoder->private_->eof_callback); - - if(OggFLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= OggFLAC__stream_decoder_get_total_samples(decoder)) - return false; - - decoder->private_->is_seeking = true; - - /* get the file length (currently our algorithm needs to know the length so it's also an error to get FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED) */ - if(decoder->private_->length_callback((FLAC__StreamDecoder*)decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) { - decoder->private_->is_seeking = false; - return false; - } - - /* if we haven't finished processing the metadata yet, do that so we have the STREAMINFO */ - if( - FLAC__stream_decoder_get_state((FLAC__StreamDecoder*)decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA || - FLAC__stream_decoder_get_state((FLAC__StreamDecoder*)decoder) == FLAC__STREAM_DECODER_READ_METADATA - ) { - if(!OggFLAC__stream_decoder_process_until_end_of_metadata(decoder)) { - /* above call sets the state for us */ - decoder->private_->is_seeking = false; - return false; - } - /* check this again in case we didn't know total_samples the first time */ - if(OggFLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= OggFLAC__stream_decoder_get_total_samples(decoder)) { - decoder->private_->is_seeking = false; - return false; - } - } - - { - FLAC__bool ok = seek_to_absolute_sample_(decoder, length, sample); - decoder->private_->is_seeking = false; - return ok; - } -} - - -/*********************************************************************** - * - * Private class methods - * - ***********************************************************************/ - -void set_defaults_(OggFLAC__StreamDecoder *decoder) -{ - decoder->private_->read_callback = 0; - decoder->private_->seek_callback = 0; - decoder->private_->tell_callback = 0; - decoder->private_->length_callback = 0; - decoder->private_->eof_callback = 0; - decoder->private_->write_callback = 0; - decoder->private_->metadata_callback = 0; - decoder->private_->error_callback = 0; - decoder->private_->client_data = 0; - OggFLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect); -} - -/* - * This will forcibly set stdin to binary mode (for OSes that require it) - */ -FILE *get_binary_stdin_() -{ - /* if something breaks here it is probably due to the presence or - * absence of an underscore before the identifiers 'setmode', - * 'fileno', and/or 'O_BINARY'; check your system header files. - */ -#if defined _MSC_VER || defined __MINGW32__ - _setmode(_fileno(stdin), _O_BINARY); -#elif defined __CYGWIN__ || defined __EMX__ - /* almost certainly not needed for any modern Cygwin, but let's be safe... */ - setmode(_fileno(stdin), _O_BINARY); -#endif - - return stdin; -} - -FLAC__StreamDecoderReadStatus read_callback2_(const FLAC__StreamDecoder *super, FLAC__byte buffer[], unsigned *bytes, void *client_data) -{ - const OggFLAC__StreamDecoder *decoder = (const OggFLAC__StreamDecoder *)super; - (void)client_data; - if(decoder->private_->eof_callback && decoder->private_->eof_callback((FLAC__StreamDecoder*)decoder, decoder->private_->client_data)) { - *bytes = 0; -#if 0 - /*@@@@@@ we used to do this: */ - stream_decoder->protected_->state = OggFLAC__STREAM_DECODER_END_OF_STREAM; - /* but it causes a problem because the Ogg decoding layer reads as much as it can to get pages, so the state will get to end-of-stream before the bitbuffer does */ -#endif - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - } - else if(*bytes > 0) { - const FLAC__StreamDecoderReadStatus status = decoder->private_->read_callback(super, buffer, bytes, decoder->private_->client_data); - if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) { - decoder->protected_->state = OggFLAC__STREAM_DECODER_READ_ERROR; - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } - else if(*bytes == 0) { - if(status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM || (decoder->private_->eof_callback && decoder->private_->eof_callback((FLAC__StreamDecoder*)decoder, decoder->private_->client_data))) { -#if 0 - /*@@@@@@ we used to do this: */ - stream_decoder->protected_->state = OggFLAC__STREAM_DECODER_END_OF_STREAM; - /* but it causes a problem because the Ogg decoding layer reads as much as it can to get pages, so the state will get to end-of-stream before the bitbuffer does */ -#endif - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - } - else - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - else - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */ -} - -FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *super, FLAC__byte buffer[], unsigned *bytes, void *client_data) -{ - const OggFLAC__StreamDecoder *decoder = (const OggFLAC__StreamDecoder *)super; - (void)client_data; - - switch(OggFLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) { - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_OK: - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - /* we don't really have a way to handle lost sync via read - * callback so we'll let it pass and let the underlying - * FLAC decoder catch the error - */ - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC: - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM: - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC: - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION: - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT: - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR: - decoder->protected_->state = OggFLAC__STREAM_DECODER_READ_ERROR; - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - case OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR: - decoder->protected_->state = OggFLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - default: - FLAC__ASSERT(0); - /* double protection */ - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } -} - -OggFLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) -{ - OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder*)void_decoder; - - switch(read_callback2_((FLAC__StreamDecoder*)decoder, buffer, bytes, client_data)) { - case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE: - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_OK; - case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM: - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM; - case FLAC__STREAM_DECODER_READ_STATUS_ABORT: - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; - default: - /* double protection: */ - FLAC__ASSERT(0); - return OggFLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT; - } -} - -FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *super, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder *)super; - (void)client_data; - - if(decoder->private_->is_seeking) { - FLAC__uint64 this_frame_sample = frame->header.number.sample_number; - FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize; - FLAC__uint64 target_sample = decoder->private_->target_sample; - - FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - - decoder->private_->got_a_frame = true; - decoder->private_->last_frame = *frame; /* save the frame */ - if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */ - unsigned delta = (unsigned)(target_sample - this_frame_sample); - /* kick out of seek mode */ - decoder->private_->is_seeking = false; - /* shift out the samples before target_sample */ - if(delta > 0) { - unsigned channel; - const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS]; - for(channel = 0; channel < frame->header.channels; channel++) - newbuffer[channel] = buffer[channel] + delta; - decoder->private_->last_frame.header.blocksize -= delta; - decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta; - /* write the relevant samples */ - return decoder->private_->write_callback((FLAC__StreamDecoder*)decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data); - } - else { - /* write the relevant samples */ - return decoder->private_->write_callback((FLAC__StreamDecoder*)decoder, frame, buffer, decoder->private_->client_data); - } - } - else { - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; - } - } - else - return decoder->private_->write_callback((FLAC__StreamDecoder*)decoder, frame, buffer, decoder->private_->client_data); -} - -void metadata_callback_(const FLAC__StreamDecoder *super, const FLAC__StreamMetadata *metadata, void *client_data) -{ - OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder *)super; - (void)client_data; - - if(!decoder->private_->is_seeking) - decoder->private_->metadata_callback((FLAC__StreamDecoder*)decoder, metadata, decoder->private_->client_data); -} - -void error_callback_(const FLAC__StreamDecoder *super, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder *)super; - (void)client_data; - - if(!decoder->private_->is_seeking) - decoder->private_->error_callback((FLAC__StreamDecoder*)decoder, status, decoder->private_->client_data); -} - -FLAC__bool seek_to_absolute_sample_(OggFLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample) -{ - FLAC__uint64 left_pos = 0, right_pos = stream_length; - FLAC__uint64 left_sample = 0, right_sample = OggFLAC__stream_decoder_get_total_samples(decoder); - FLAC__uint64 this_frame_sample = 0; /* only initialized to avoid compiler warning */ - FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */ - FLAC__bool did_a_seek; - unsigned iteration = 0; - - /* In the first iterations, we will calculate the target byte position - * by the distance from the target sample to left_sample and - * right_sample (let's call it "proportional search"). After that, we - * will switch to binary search. - */ - unsigned BINARY_SEARCH_AFTER_ITERATION = 2; - - /* We will switch to a linear search once our current sample is less - * than this number of samples ahead of the target sample - */ - static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2; - - /* If the total number of samples is unknown, use a large value, and - * force binary search immediately. - */ - if(right_sample == 0) { - right_sample = (FLAC__uint64)(-1); - BINARY_SEARCH_AFTER_ITERATION = 0; - } - - decoder->private_->target_sample = target_sample; - for( ; ; iteration++) { - if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) { - if (iteration >= BINARY_SEARCH_AFTER_ITERATION) { - pos = (right_pos + left_pos) / 2; - } - else { -#ifndef FLAC__INTEGER_ONLY_LIBRARY -#if defined _MSC_VER || defined __MINGW32__ - /* with MSVC you have to spoon feed it the casting */ - pos = (FLAC__uint64)((FLAC__double)(FLAC__int64)(target_sample - left_sample) / (FLAC__double)(FLAC__int64)(right_sample - left_sample) * (FLAC__double)(FLAC__int64)(right_pos - left_pos)); -#else - pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos)); -#endif -#else - /* a little less accurate: */ - if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff)) - pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample)); - else /* @@@ WATCHOUT, ~2TB limit */ - pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16)); -#endif - /* @@@ TODO: might want to limit pos to some distance - * before EOF, to make sure we land before the last frame, - * thereby getting a this_frame_sample and so having a better - * estimate. @@@@@@DELETE:this would also mostly (or totally if we could - * be sure to land before the last frame) avoid the - * end-of-stream case we have to check later. - */ - } - - /* physical seek */ - if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) { - decoder->protected_->state = OggFLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - if(!OggFLAC__stream_decoder_flush(decoder)) { - /* above call sets the state for us */ - return false; - } - did_a_seek = true; - } - else - did_a_seek = false; - - decoder->private_->got_a_frame = false; - if(!OggFLAC__stream_decoder_process_single(decoder)) { - decoder->protected_->state = OggFLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - if(!decoder->private_->got_a_frame) { - if(did_a_seek) { - /* this can happen if we seek to a point after the last frame; we drop - * to binary search right away in this case to avoid any wasted - * iterations of proportional search. - */ - right_pos = pos; - BINARY_SEARCH_AFTER_ITERATION = 0; - } - else { - /* this can probably only happen if total_samples is unknown and the - * target_sample is past the end of the stream - */ - decoder->protected_->state = OggFLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - } - /* our write callback will change the state when it gets to the target frame */ - else if(!decoder->private_->is_seeking/*@@@@@@ && decoder->protected_->state != OggFLAC__STREAM_DECODER_END_OF_STREAM*/) { - break; - } - else { - this_frame_sample = decoder->private_->last_frame.header.number.sample_number; - FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER); - - if (did_a_seek) { - if (this_frame_sample <= target_sample) { - /* The 'equal' case should not happen, since - * OggFLAC__stream_decoder_process_single() - * should recognize that it has hit the - * target sample and we would exit through - * the 'break' above. - */ - FLAC__ASSERT(this_frame_sample != target_sample); - - left_sample = this_frame_sample; - /* sanity check to avoid infinite loop */ - if (left_pos == pos) { - decoder->protected_->state = OggFLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - left_pos = pos; - } - else if(this_frame_sample > target_sample) { - right_sample = this_frame_sample; - /* sanity check to avoid infinite loop */ - if (right_pos == pos) { - decoder->protected_->state = OggFLAC__STREAM_DECODER_SEEK_ERROR; - return false; - } - right_pos = pos; - } - } - } - } - - return true; -} - -FLAC__StreamDecoderReadStatus file_read_callback_(const FLAC__StreamDecoder *super, FLAC__byte buffer[], unsigned *bytes, void *client_data) -{ - OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder *)super; - (void)client_data; - - if(*bytes > 0) { - *bytes = (unsigned)fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file); - if(ferror(decoder->private_->file)) - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - else 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; /* abort to avoid a deadlock */ -} - -FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *super, FLAC__uint64 absolute_byte_offset, void *client_data) -{ - OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder *)super; - (void)client_data; - - if(decoder->private_->file == stdin) - return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; - else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0) - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - else - return FLAC__STREAM_DECODER_SEEK_STATUS_OK; -} - -FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *super, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder *)super; - off_t pos; - (void)client_data; - - if(decoder->private_->file == stdin) - return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; - else if((pos = ftello(decoder->private_->file)) < 0) - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - else { - *absolute_byte_offset = (FLAC__uint64)pos; - return FLAC__STREAM_DECODER_TELL_STATUS_OK; - } -} - -FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *super, FLAC__uint64 *stream_length, void *client_data) -{ - OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder *)super; - struct stat filestats; - (void)client_data; - - if(decoder->private_->file == stdin) - return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; - else if(fstat(fileno(decoder->private_->file), &filestats) != 0) - return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - else { - *stream_length = (FLAC__uint64)filestats.st_size; - return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; - } -} - -FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *super, void *client_data) -{ - OggFLAC__StreamDecoder *decoder = (OggFLAC__StreamDecoder *)super; - (void)client_data; - - return feof(decoder->private_->file)? true : false; -} diff --git a/src/libOggFLAC/stream_encoder.c b/src/libOggFLAC/stream_encoder.c deleted file mode 100644 index 3e4bbb65..00000000 --- a/src/libOggFLAC/stream_encoder.c +++ /dev/null @@ -1,1199 +0,0 @@ -/* libOggFLAC - Free Lossless Audio Codec + Ogg library - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * - Neither the name of the Xiph.org Foundation nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#if defined _MSC_VER || defined __MINGW32__ -#include <io.h> /* for _setmode() */ -#include <fcntl.h> /* for _O_BINARY */ -#endif -#if defined __CYGWIN__ || defined __EMX__ -#include <io.h> /* for setmode(), O_BINARY */ -#include <fcntl.h> /* for _O_BINARY */ -#endif -#include <stdio.h> -#include <stdlib.h> /* for calloc() */ -#include <string.h> /* for memcpy() */ -#include <sys/types.h> /* for off_t */ -#if defined _MSC_VER || defined __MINGW32__ -#if _MSC_VER <= 1200 /* @@@ [2G limit] */ -#define fseeko fseek -#define ftello ftell -#endif -#endif -#include "FLAC/assert.h" -#include "OggFLAC/stream_encoder.h" -#include "protected/stream_encoder.h" -#include "private/ogg_helper.h" - -#ifdef max -#undef max -#endif -#define max(a,b) ((a)>(b)?(a):(b)) - -/*********************************************************************** - * - * Private class method prototypes - * - ***********************************************************************/ - -/* unpublished debug routines */ -extern FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); -extern FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); -extern FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value); - -static void set_defaults_(OggFLAC__StreamEncoder *encoder); -static FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); -static void metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data); -static OggFLAC__StreamEncoderReadStatus file_read_callback_(const OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); -static FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); -static FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data); -static FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); -static FILE *get_binary_stdout_(); - - -/*********************************************************************** - * - * Private class data - * - ***********************************************************************/ - -typedef struct OggFLAC__StreamEncoderPrivate { - OggFLAC__StreamEncoderReadCallback read_callback; - FLAC__StreamEncoderWriteCallback write_callback; - FLAC__StreamEncoderSeekCallback seek_callback; - FLAC__StreamEncoderTellCallback tell_callback; - FLAC__StreamEncoderMetadataCallback metadata_callback; - FLAC__StreamEncoderProgressCallback progress_callback; - void *client_data; - FLAC__StreamMetadata_SeekTable *seek_table; - /* internal vars (all the above are class settings) */ - unsigned first_seekpoint_to_check; - FILE *file; /* only used when encoding to a file */ - FLAC__uint64 bytes_written; - FLAC__uint64 samples_written; - unsigned frames_written; - unsigned total_frames_estimate; -} OggFLAC__StreamEncoderPrivate; - - -/*********************************************************************** - * - * Public static class data - * - ***********************************************************************/ - -OggFLAC_API const char * const OggFLAC__StreamEncoderStateString[] = { - "OggFLAC__STREAM_ENCODER_OK", - "OggFLAC__STREAM_ENCODER_UNINITIALIZED", - "OggFLAC__STREAM_ENCODER_OGG_ERROR", - "OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR", - "OggFLAC__STREAM_ENCODER_CLIENT_ERROR", - "OggFLAC__STREAM_ENCODER_IO_ERROR", - "OggFLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR" -}; - -OggFLAC_API const char * const OggFLAC__treamEncoderReadStatusString[] = { - "OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE", - "OggFLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM", - "OggFLAC__STREAM_ENCODER_READ_STATUS_ABORT", - "OggFLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED" -}; - - -/*********************************************************************** - * - * Class constructor/destructor - * - */ -OggFLAC_API OggFLAC__StreamEncoder *OggFLAC__stream_encoder_new() -{ - OggFLAC__StreamEncoder *encoder; - FLAC__StreamEncoder *parent; - - FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */ - - encoder = (OggFLAC__StreamEncoder*)calloc(1, sizeof(OggFLAC__StreamEncoder)); - if(encoder == 0) { - return 0; - } - - encoder->protected_ = (OggFLAC__StreamEncoderProtected*)calloc(1, sizeof(OggFLAC__StreamEncoderProtected)); - if(encoder->protected_ == 0) { - free(encoder); - return 0; - } - - encoder->private_ = (OggFLAC__StreamEncoderPrivate*)calloc(1, sizeof(OggFLAC__StreamEncoderPrivate)); - if(encoder->private_ == 0) { - free(encoder->protected_); - free(encoder); - return 0; - } - - parent = FLAC__stream_encoder_new(); - if(0 == parent) { - free(encoder->private_); - free(encoder->protected_); - free(encoder); - return 0; - } - encoder->super_ = *parent; - - encoder->private_->file = 0; - - set_defaults_(encoder); - - encoder->protected_->state = OggFLAC__STREAM_ENCODER_UNINITIALIZED; - - return encoder; -} - -OggFLAC_API void OggFLAC__stream_encoder_delete(OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->protected_); - FLAC__ASSERT(0 != encoder->private_); - - (void)OggFLAC__stream_encoder_finish(encoder); - - free(encoder->private_); - free(encoder->protected_); - /* don't free(encoder) because FLAC__stream_encoder_delete() will do it */ - - /* call superclass destructor last */ - FLAC__stream_encoder_delete((FLAC__StreamEncoder*)encoder); -} - - -/*********************************************************************** - * - * Public class methods - * - ***********************************************************************/ - -OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_stream(OggFLAC__StreamEncoder *encoder, OggFLAC__StreamEncoderReadCallback read_callback, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, void *client_data) -{ - FLAC__ASSERT(0 != encoder); - - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; - - if(0 == write_callback || (seek_callback && (0 == read_callback || 0 == tell_callback))) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS; - - /* check seek table before FLAC__stream_encoder_init_stream() does, just to avoid messing up the encoder state for a trivial error */ - if(0 != encoder->private_->seek_table && !FLAC__format_seektable_is_legal(encoder->private_->seek_table)) - return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA; - - /* set state to OK; from here on, errors are fatal and we'll override the state then */ - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OK; - - if(!OggFLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - encoder->private_->read_callback = read_callback; - encoder->private_->write_callback = write_callback; - encoder->private_->seek_callback = seek_callback; - encoder->private_->tell_callback = tell_callback; - encoder->private_->metadata_callback = metadata_callback; - encoder->private_->client_data = client_data; - - /* - * These must be done before we init the stream encoder because that - * calls the write_callback, which uses these values. - */ - encoder->private_->first_seekpoint_to_check = 0; - encoder->private_->samples_written = 0; - encoder->protected_->streaminfo_offset = 0; - encoder->protected_->seektable_offset = 0; - encoder->protected_->audio_offset = 0; - - /* we do our own special metadata updating inside Ogg here, so we don't pass in our seek/tell callbacks */ - if(FLAC__stream_encoder_init_stream((FLAC__StreamEncoder*)encoder, write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, metadata_callback_, /*client_data=*/encoder) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - /* - * Initializing the stream encoder writes all the metadata, so we - * save the stream offset now. - */ - if(encoder->private_->tell_callback && encoder->private_->tell_callback((FLAC__StreamEncoder*)encoder, &encoder->protected_->audio_offset, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) { /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get the offset; no error */ - encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - return FLAC__STREAM_ENCODER_INIT_STATUS_OK; -} - -OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_FILE(OggFLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data) -{ - FLAC__StreamEncoderInitStatus init_status; - - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != file); - - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; - - /* double protection */ - if(file == 0) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_IO_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - /* - * To make sure that our file does not go unclosed after an error, we - * must assign the FILE pointer before any further error can occur in - * this routine. - */ - if(file == stdout) - file = get_binary_stdout_(); /* just to be safe */ - - encoder->private_->file = file; - - encoder->private_->progress_callback = progress_callback; - encoder->private_->bytes_written = 0; - encoder->private_->samples_written = 0; - encoder->private_->frames_written = 0; - - init_status = OggFLAC__stream_encoder_init_stream(encoder, file_read_callback_, file_write_callback_, file_seek_callback_, file_tell_callback_, /*metadata_callback=*/0, client_data); - if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { - /* the above function sets the state for us in case of an error */ - return init_status; - } - - { - unsigned blocksize = OggFLAC__stream_encoder_get_blocksize(encoder); - - FLAC__ASSERT(blocksize != 0); - encoder->private_->total_frames_estimate = (unsigned)((OggFLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize); - } - - return init_status; -} - -OggFLAC_API FLAC__StreamEncoderInitStatus OggFLAC__stream_encoder_init_file(OggFLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data) -{ - FILE *file; - - FLAC__ASSERT(0 != encoder); - - /* - * To make sure that our file does not go unclosed after an error, we - * have to do the same entrance checks here that are later performed - * in FLAC__stream_encoder_init_FILE() before the FILE* is assigned. - */ - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED; - - file = filename? fopen(filename, "w+b") : stdout; - - if(file == 0) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_IO_ERROR; - return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR; - } - - return OggFLAC__stream_encoder_init_FILE(encoder, file, progress_callback, client_data); -} - -OggFLAC_API void OggFLAC__stream_encoder_finish(OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - - if(encoder->protected_->state == OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return; - - FLAC__stream_encoder_finish((FLAC__StreamEncoder*)encoder); - - OggFLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect); - - if(0 != encoder->private_->file) { - if(encoder->private_->file != stdout) - fclose(encoder->private_->file); - encoder->private_->file = 0; - } - - set_defaults_(encoder); - - encoder->protected_->state = OggFLAC__STREAM_ENCODER_UNINITIALIZED; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_serial_number(OggFLAC__StreamEncoder *encoder, long value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - OggFLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value); - return true; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_verify(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_verify((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_streamable_subset(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_streamable_subset((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_do_mid_side_stereo((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_loose_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_loose_mid_side_stereo((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_channels(OggFLAC__StreamEncoder *encoder, unsigned value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_channels((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_bits_per_sample(OggFLAC__StreamEncoder *encoder, unsigned value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_bits_per_sample((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_sample_rate(OggFLAC__StreamEncoder *encoder, unsigned value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_sample_rate((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_blocksize(OggFLAC__StreamEncoder *encoder, unsigned value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_blocksize((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_apodization(OggFLAC__StreamEncoder *encoder, const char *specification) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_apodization((FLAC__StreamEncoder*)encoder, specification); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_max_lpc_order(OggFLAC__StreamEncoder *encoder, unsigned value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_max_lpc_order((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_qlp_coeff_precision(OggFLAC__StreamEncoder *encoder, unsigned value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_qlp_coeff_precision((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_do_qlp_coeff_prec_search((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_escape_coding(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_do_escape_coding((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_do_exhaustive_model_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_do_exhaustive_model_search((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_min_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_min_residual_partition_order((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_max_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_max_residual_partition_order((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_rice_parameter_search_dist(OggFLAC__StreamEncoder *encoder, unsigned value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_rice_parameter_search_dist((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_total_samples_estimate(OggFLAC__StreamEncoder *encoder, FLAC__uint64 value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_set_total_samples_estimate((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_set_metadata(OggFLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - /* reorder metadata if necessary to ensure that any VORBIS_COMMENT is the first, according to the mapping spec */ - if(0 != metadata && num_blocks > 1) { - unsigned i; - for(i = 1; i < num_blocks; i++) { - if(0 != metadata[i] && metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { - FLAC__StreamMetadata *vc = metadata[i]; - for( ; i > 0; i--) - metadata[i] = metadata[i-1]; - metadata[0] = vc; - break; - } - } - } - if(0 != metadata && num_blocks > 0) { - unsigned i; - for(i = 0; i < num_blocks; i++) { - /* keep track of any SEEKTABLE block */ - if(0 != metadata[i] && metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) { - encoder->private_->seek_table = &metadata[i]->data.seek_table; - break; /* take only the first one */ - } - } - } - if(!OggFLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks)) - return false; - return FLAC__stream_encoder_set_metadata((FLAC__StreamEncoder*)encoder, metadata, num_blocks); -} - -/* - * These three functions are not static, but not publically exposed in - * include/OggFLAC/ either. They are used by the test suite. - */ -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_disable_constant_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_disable_constant_subframes((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_disable_fixed_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_disable_fixed_subframes((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_disable_verbatim_subframes(OggFLAC__StreamEncoder *encoder, FLAC__bool value) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_UNINITIALIZED) - return false; - return FLAC__stream_encoder_disable_verbatim_subframes((FLAC__StreamEncoder*)encoder, value); -} - -OggFLAC_API OggFLAC__StreamEncoderState OggFLAC__stream_encoder_get_state(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return encoder->protected_->state; -} - -OggFLAC_API FLAC__StreamEncoderState OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_state((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API FLAC__StreamDecoderState OggFLAC__stream_encoder_get_verify_decoder_state(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_verify_decoder_state((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API const char *OggFLAC__stream_encoder_get_resolved_state_string(const OggFLAC__StreamEncoder *encoder) -{ - if(encoder->protected_->state != OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) - return OggFLAC__StreamEncoderStateString[encoder->protected_->state]; - else - return FLAC__stream_encoder_get_resolved_state_string((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API void OggFLAC__stream_encoder_get_verify_decoder_error_stats(const OggFLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__stream_encoder_get_verify_decoder_error_stats((FLAC__StreamEncoder*)encoder, absolute_sample, frame_number, channel, sample, expected, got); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_verify(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_verify((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_streamable_subset(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_streamable_subset((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_mid_side_stereo(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_do_mid_side_stereo((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_loose_mid_side_stereo(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_loose_mid_side_stereo((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API unsigned OggFLAC__stream_encoder_get_channels(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_channels((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API unsigned OggFLAC__stream_encoder_get_bits_per_sample(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_bits_per_sample((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API unsigned OggFLAC__stream_encoder_get_sample_rate(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_sample_rate((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API unsigned OggFLAC__stream_encoder_get_blocksize(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_blocksize((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API unsigned OggFLAC__stream_encoder_get_max_lpc_order(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_max_lpc_order((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API unsigned OggFLAC__stream_encoder_get_qlp_coeff_precision(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_qlp_coeff_precision((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_do_qlp_coeff_prec_search((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_escape_coding(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_do_escape_coding((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_get_do_exhaustive_model_search(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_do_exhaustive_model_search((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API unsigned OggFLAC__stream_encoder_get_min_residual_partition_order(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_min_residual_partition_order((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API unsigned OggFLAC__stream_encoder_get_max_residual_partition_order(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_max_residual_partition_order((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API unsigned OggFLAC__stream_encoder_get_rice_parameter_search_dist(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_rice_parameter_search_dist((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API FLAC__uint64 OggFLAC__stream_encoder_get_total_samples_estimate(const OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - return FLAC__stream_encoder_get_total_samples_estimate((FLAC__StreamEncoder*)encoder); -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_process(OggFLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(!FLAC__stream_encoder_process((FLAC__StreamEncoder*)encoder, buffer, samples)) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR; - return false; - } - else - return true; -} - -OggFLAC_API FLAC__bool OggFLAC__stream_encoder_process_interleaved(OggFLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - if(!FLAC__stream_encoder_process_interleaved((FLAC__StreamEncoder*)encoder, buffer, samples)) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR; - return false; - } - else - return true; -} - -/*********************************************************************** - * - * Private class methods - * - ***********************************************************************/ - -void set_defaults_(OggFLAC__StreamEncoder *encoder) -{ - FLAC__ASSERT(0 != encoder); - FLAC__ASSERT(0 != encoder->private_); - FLAC__ASSERT(0 != encoder->protected_); - - encoder->private_->read_callback = 0; - encoder->private_->write_callback = 0; - encoder->private_->seek_callback = 0; - encoder->private_->tell_callback = 0; - encoder->private_->metadata_callback = 0; - encoder->private_->progress_callback = 0; - encoder->private_->client_data = 0; - - encoder->private_->seek_table = 0; - - OggFLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect); -} - -FLAC__StreamEncoderWriteStatus write_callback_(const FLAC__StreamEncoder *super, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) -{ - OggFLAC__StreamEncoder *encoder = (OggFLAC__StreamEncoder*)super; - FLAC__StreamEncoderWriteStatus status; - FLAC__uint64 output_position; - - (void)client_data; /* silence compiler warning about unused parameter */ - - /* FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED just means we didn't get the offset; no error */ - if(encoder->private_->tell_callback && encoder->private_->tell_callback((FLAC__StreamEncoder*)encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR; - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - } - - /* - * Watch for the STREAMINFO block and first SEEKTABLE block to go by and store their offsets. - */ - if(samples == 0) { - FLAC__MetadataType type = (buffer[0] & 0x7f); - if(type == FLAC__METADATA_TYPE_STREAMINFO) - encoder->protected_->streaminfo_offset = output_position; - else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0) - encoder->protected_->seektable_offset = output_position; - } - - /* - * Mark the current seek point if hit (if audio_offset == 0 that - * means we're still writing metadata and haven't hit the first - * frame yet) - */ - if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) { - const unsigned blocksize = FLAC__stream_encoder_get_blocksize((FLAC__StreamEncoder*)encoder); - const FLAC__uint64 frame_first_sample = encoder->private_->samples_written; - const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1; - FLAC__uint64 test_sample; - unsigned i; - for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) { - test_sample = encoder->private_->seek_table->points[i].sample_number; - if(test_sample > frame_last_sample) { - break; - } - else if(test_sample >= frame_first_sample) { - encoder->private_->seek_table->points[i].sample_number = frame_first_sample; - encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset; - encoder->private_->seek_table->points[i].frame_samples = blocksize; - encoder->private_->first_seekpoint_to_check++; - /* DO NOT: "break;" and here's why: - * The seektable template may contain more than one target - * sample for any given frame; we will keep looping, generating - * duplicate seekpoints for them, and we'll clean it up later, - * just before writing the seektable back to the metadata. - */ - } - else { - encoder->private_->first_seekpoint_to_check++; - } - } - } - - status = OggFLAC__ogg_encoder_aspect_write_callback_wrapper(&encoder->protected_->ogg_encoder_aspect, FLAC__stream_encoder_get_total_samples_estimate((FLAC__StreamEncoder*)encoder), buffer, bytes, samples, current_frame, (OggFLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback, encoder, encoder->private_->client_data); - - if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) - encoder->private_->samples_written += samples; - else - encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR; - - return status; -} - -void metadata_callback_(const FLAC__StreamEncoder *super, const FLAC__StreamMetadata *metadata, void *client_data) -{ - OggFLAC__StreamEncoder *encoder = (OggFLAC__StreamEncoder*)super; - FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)]; - const FLAC__uint64 samples = metadata->data.stream_info.total_samples; - const unsigned min_framesize = metadata->data.stream_info.min_framesize; - const unsigned max_framesize = metadata->data.stream_info.max_framesize; - ogg_page page; - - FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO); - - /* We get called by the stream encoder when the encoding process - * has finished so that we can update the STREAMINFO and SEEKTABLE - * blocks. - */ - - (void)client_data; /* silence compiler warning about unused parameter */ - - /* All this is based on intimate knowledge of the stream header - * layout, but a change to the header format that would break this - * would also break all streams encoded in the previous format. - */ - - /** - ** Write STREAMINFO stats - **/ - simple_ogg_page__init(&page); - if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) { - simple_ogg_page__clear(&page); - return; /* state already set */ - } - - /* - * Write MD5 signature - */ - { - const unsigned md5_offset = - FLAC__STREAM_METADATA_HEADER_LENGTH + - ( - FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + - FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN - ) / 8; - - if(md5_offset + 16 > (unsigned)page.body_len) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR; - simple_ogg_page__clear(&page); - return; - } - memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16); - } - - /* - * Write total samples - */ - { - const unsigned total_samples_byte_offset = - FLAC__STREAM_METADATA_HEADER_LENGTH + - ( - FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN + - FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN - - 4 - ) / 8; - - if(total_samples_byte_offset + 5 > (unsigned)page.body_len) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR; - simple_ogg_page__clear(&page); - return; - } - b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0; - b[0] |= (FLAC__byte)((samples >> 32) & 0x0F); - b[1] = (FLAC__byte)((samples >> 24) & 0xFF); - b[2] = (FLAC__byte)((samples >> 16) & 0xFF); - b[3] = (FLAC__byte)((samples >> 8) & 0xFF); - b[4] = (FLAC__byte)(samples & 0xFF); - memcpy(page.body + total_samples_byte_offset, b, 5); - } - - /* - * Write min/max framesize - */ - { - const unsigned min_framesize_offset = - FLAC__STREAM_METADATA_HEADER_LENGTH + - ( - FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN + - FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN - ) / 8; - - if(min_framesize_offset + 6 > (unsigned)page.body_len) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR; - simple_ogg_page__clear(&page); - return; - } - b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF); - b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF); - b[2] = (FLAC__byte)(min_framesize & 0xFF); - b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF); - b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF); - b[5] = (FLAC__byte)(max_framesize & 0xFF); - memcpy(page.body + min_framesize_offset, b, 6); - } - if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) { - simple_ogg_page__clear(&page); - return; /* state already set */ - } - simple_ogg_page__clear(&page); - - /* - * Write seektable - */ - if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) { - unsigned i; - FLAC__byte *p; - - FLAC__format_seektable_sort(encoder->private_->seek_table); - - FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table)); - - simple_ogg_page__init(&page); - if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) { - simple_ogg_page__clear(&page); - return; /* state already set */ - } - - if(FLAC__STREAM_METADATA_HEADER_LENGTH + (18*encoder->private_->seek_table->num_points) > (unsigned)page.body_len) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_OGG_ERROR; - simple_ogg_page__clear(&page); - return; - } - - for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) { - FLAC__uint64 xx; - unsigned x; - xx = encoder->private_->seek_table->points[i].sample_number; - b[7] = (FLAC__byte)xx; xx >>= 8; - b[6] = (FLAC__byte)xx; xx >>= 8; - b[5] = (FLAC__byte)xx; xx >>= 8; - b[4] = (FLAC__byte)xx; xx >>= 8; - b[3] = (FLAC__byte)xx; xx >>= 8; - b[2] = (FLAC__byte)xx; xx >>= 8; - b[1] = (FLAC__byte)xx; xx >>= 8; - b[0] = (FLAC__byte)xx; xx >>= 8; - xx = encoder->private_->seek_table->points[i].stream_offset; - b[15] = (FLAC__byte)xx; xx >>= 8; - b[14] = (FLAC__byte)xx; xx >>= 8; - b[13] = (FLAC__byte)xx; xx >>= 8; - b[12] = (FLAC__byte)xx; xx >>= 8; - b[11] = (FLAC__byte)xx; xx >>= 8; - b[10] = (FLAC__byte)xx; xx >>= 8; - b[9] = (FLAC__byte)xx; xx >>= 8; - b[8] = (FLAC__byte)xx; xx >>= 8; - x = encoder->private_->seek_table->points[i].frame_samples; - b[17] = (FLAC__byte)x; x >>= 8; - b[16] = (FLAC__byte)x; x >>= 8; - if(encoder->private_->write_callback((FLAC__StreamEncoder*)encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) { - encoder->protected_->state = OggFLAC__STREAM_ENCODER_CLIENT_ERROR; - simple_ogg_page__clear(&page); - return; - } - memcpy(p, b, 18); - } - - if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) { - simple_ogg_page__clear(&page); - return; /* state already set */ - } - simple_ogg_page__clear(&page); - } - - if(encoder->private_->metadata_callback) - encoder->private_->metadata_callback((FLAC__StreamEncoder*)encoder, metadata, client_data); -} - -OggFLAC__StreamEncoderReadStatus file_read_callback_(const OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) -{ - (void)client_data; - - *bytes = (unsigned)fread(buffer, 1, *bytes, encoder->private_->file); - if (*bytes == 0) { - if (feof(encoder->private_->file)) - return OggFLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM; - else if (ferror(encoder->private_->file)) - return OggFLAC__STREAM_ENCODER_READ_STATUS_ABORT; - } - return OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; -} - -FLAC__StreamEncoderSeekStatus file_seek_callback_(const FLAC__StreamEncoder *super, FLAC__uint64 absolute_byte_offset, void *client_data) -{ - OggFLAC__StreamEncoder *encoder = (OggFLAC__StreamEncoder*)super; - - (void)client_data; - - if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0) - return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR; - else - return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; -} - -FLAC__StreamEncoderTellStatus file_tell_callback_(const FLAC__StreamEncoder *super, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - OggFLAC__StreamEncoder *encoder = (OggFLAC__StreamEncoder*)super; - off_t offset; - - (void)client_data; - - offset = ftello(encoder->private_->file); - - if(offset < 0) { - return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; - } - else { - *absolute_byte_offset = (FLAC__uint64)offset; - return FLAC__STREAM_ENCODER_TELL_STATUS_OK; - } -} - -#ifdef FLAC__VALGRIND_TESTING -static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#else -#define local__fwrite fwrite -#endif - -FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *super, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) -{ - OggFLAC__StreamEncoder *encoder = (OggFLAC__StreamEncoder*)super; - - (void)client_data; - - if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) { - encoder->private_->bytes_written += bytes; - encoder->private_->samples_written += samples; - /* we keep a high watermark on the number of frames written because - * when the encoder goes back to write metadata, 'current_frame' - * will drop back to 0. - */ - encoder->private_->frames_written = max(encoder->private_->frames_written, current_frame+1); - /* We would like to add an '&& samples > 0' to the if - * clause here but currently because of the nature of our Ogg - * writing implementation, 'samples' is always 0 (see - * ogg_encoder_aspect.c). The downside is extra progress - * callbacks. - */ - if(0 != encoder->private_->progress_callback /* && samples > 0 */) - encoder->private_->progress_callback((FLAC__StreamEncoder*)encoder, encoder->private_->bytes_written, encoder->private_->samples_written, encoder->private_->frames_written, encoder->private_->total_frames_estimate, encoder->private_->client_data); - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; - } - else - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; -} - -/* - * This will forcibly set stdout to binary mode (for OSes that require it) - */ -FILE *get_binary_stdout_() -{ - /* if something breaks here it is probably due to the presence or - * absence of an underscore before the identifiers 'setmode', - * 'fileno', and/or 'O_BINARY'; check your system header files. - */ -#if defined _MSC_VER || defined __MINGW32__ - _setmode(_fileno(stdout), _O_BINARY); -#elif defined __CYGWIN__ - /* almost certainly not needed for any modern Cygwin, but let's be safe... */ - setmode(_fileno(stdout), _O_BINARY); -#elif defined __EMX__ - setmode(fileno(stdout), O_BINARY); -#endif - - return stdout; -} diff --git a/src/metaflac/Makefile.am b/src/metaflac/Makefile.am index 2dc68162..1a61e712 100644 --- a/src/metaflac/Makefile.am +++ b/src/metaflac/Makefile.am @@ -17,6 +17,8 @@ bin_PROGRAMS = metaflac +AM_CFLAGS = @OGG_CFLAGS@ + EXTRA_DIST = \ Makefile.lite \ metaflac.dsp @@ -44,5 +46,6 @@ metaflac_LDADD = \ $(top_builddir)/src/share/getopt/libgetopt.a \ $(top_builddir)/src/share/utf8/libutf8.la \ $(top_builddir)/src/libFLAC/libFLAC.la \ + @OGG_LIBS@ \ @LIBICONV@ \ -lm diff --git a/src/metaflac/Makefile.lite b/src/metaflac/Makefile.lite index d7328332..abfb2f23 100644 --- a/src/metaflac/Makefile.lite +++ b/src/metaflac/Makefile.lite @@ -24,12 +24,12 @@ libdir = $(topdir)/obj/$(BUILD)/lib PROGRAM_NAME = metaflac -INCLUDES = -I./include -I$(topdir)/include +INCLUDES = -I./include -I$(topdir)/include -I$(OGG_INCLUDE_DIR) ifeq ($(DARWIN_BUILD),yes) -EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libFLAC.a $(libdir)/libreplaygain_analysis.a $(libdir)/libgetopt.a $(libdir)/libutf8.a -L$(ICONV_LIB_DIR) -liconv -lm +EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libFLAC.a $(libdir)/libreplaygain_analysis.a $(libdir)/libgetopt.a $(libdir)/libutf8.a $(OGG_LIB_DIR)/libogg.a -L$(ICONV_LIB_DIR) -liconv -lm else -LIBS = -lgrabbag -lFLAC -lreplaygain_analysis -lgetopt -lutf8 -lm +LIBS = -lgrabbag -lFLAC -lreplaygain_analysis -lgetopt -lutf8 -L$(OGG_LIB_DIR) -logg -lm endif SRCS_C = \ diff --git a/src/test_libFLAC++/decoders.cpp b/src/test_libFLAC++/decoders.cpp index f9d2b528..2030de98 100644 --- a/src/test_libFLAC++/decoders.cpp +++ b/src/test_libFLAC++/decoders.cpp @@ -62,9 +62,13 @@ static const char * const LayerString[] = { static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; static ::FLAC__StreamMetadata *expected_metadata_sequence_[9]; static unsigned num_expected_; -static const char *flacfilename_ = "metadata.flac"; static off_t flacfilesize_; +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); @@ -95,9 +99,9 @@ static void free_metadata_blocks_() mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); } -static bool generate_file_() +static bool generate_file_(FLAC__bool is_ogg) { - printf("\n\ngenerating FLAC file for decoder tests...\n"); + printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":""); num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &padding_; @@ -108,8 +112,9 @@ static bool generate_file_() expected_metadata_sequence_[num_expected_++] = &cuesheet_; expected_metadata_sequence_[num_expected_++] = &picture_; expected_metadata_sequence_[num_expected_++] = &unknown_; + /* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */ - if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_)) + if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_)) return die_("creating the encoded file"); return true; @@ -191,7 +196,7 @@ public: void metadata_callback(const ::FLAC__StreamMetadata *metadata); void error_callback(::FLAC__StreamDecoderErrorStatus status); - bool test_respond(); + bool test_respond(bool is_ogg); }; ::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes) @@ -296,15 +301,18 @@ void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status) common_error_callback_(status); } -bool StreamDecoder::test_respond() +bool StreamDecoder::test_respond(bool is_ogg) { + ::FLAC__StreamDecoderInitStatus init_status; + if(!set_md5_checking(true)) { printf("FAILED at set_md5_checking(), returned false\n"); return false; } - printf("testing init()... "); - if(init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) + printf("testing init%s()... ", is_ogg? "_ogg":""); + init_status = is_ogg? init_ogg() : init(); + if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) return die_s_(0, this); printf("OK\n"); @@ -340,7 +348,7 @@ public: void metadata_callback(const ::FLAC__StreamMetadata *metadata); void error_callback(::FLAC__StreamDecoderErrorStatus status); - bool test_respond(); + bool test_respond(bool is_ogg); }; ::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) @@ -359,8 +367,10 @@ void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status) common_error_callback_(status); } -bool FileDecoder::test_respond() +bool FileDecoder::test_respond(bool is_ogg) { + ::FLAC__StreamDecoderInitStatus init_status; + if(!set_md5_checking(true)) { printf("FAILED at set_md5_checking(), returned false\n"); return false; @@ -369,28 +379,28 @@ bool FileDecoder::test_respond() switch(layer_) { case LAYER_FILE: { - printf("opening FLAC file... "); - FILE *file = ::fopen(flacfilename_, "rb"); + printf("opening %sFLAC file... ", is_ogg? "Ogg ":""); + FILE *file = ::fopen(flacfilename(is_ogg), "rb"); if(0 == file) { printf("ERROR (%s)\n", strerror(errno)); return false; } printf("OK\n"); - printf("testing init()... "); - if(init(file) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, this); + printf("testing init%s()... ", is_ogg? "_ogg":""); + init_status = is_ogg? init_ogg(file) : init(file); } break; case LAYER_FILENAME: - printf("testing init()... "); - if(init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, this); + printf("testing init%s()... ", is_ogg? "_ogg":""); + init_status = is_ogg? init_ogg(flacfilename(is_ogg)) : init(flacfilename(is_ogg)); break; default: die_("internal error 001"); return false; } + if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) + return die_s_(0, this); printf("OK\n"); current_metadata_number_ = 0; @@ -419,12 +429,13 @@ static FLAC::Decoder::Stream *new_by_layer(Layer layer) return new FileDecoder(layer); } -static bool test_stream_decoder(Layer layer) +static bool test_stream_decoder(Layer layer, bool is_ogg) { FLAC::Decoder::Stream *decoder; + ::FLAC__StreamDecoderInitStatus init_status; bool expect; - printf("\n+++ libFLAC++ unit test: FLAC::Decoder::%s (layer: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer]); + printf("\n+++ libFLAC++ unit test: FLAC::Decoder::%s (layer: %s, format: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer], is_ogg? "Ogg FLAC" : "FLAC"); // // test new -> delete @@ -466,26 +477,29 @@ static bool test_stream_decoder(Layer layer) } printf("OK\n"); - printf("testing init()... "); + printf("testing init%s()... ", is_ogg? "_ogg":""); switch(layer) { case LAYER_STREAM: case LAYER_SEEKABLE_STREAM: dynamic_cast<StreamDecoder*>(decoder)->file_ = stdin; - if(decoder->init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + init_status = is_ogg? decoder->init_ogg() : decoder->init(); break; case LAYER_FILE: - if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(stdin) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + init_status = is_ogg? + dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(stdin) : + dynamic_cast<FLAC::Decoder::File*>(decoder)->init(stdin); break; case LAYER_FILENAME: - if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + init_status = is_ogg? + dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(flacfilename(is_ogg)) : + dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename(is_ogg)); break; default: die_("internal error 006"); return false; } + if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) + return die_s_(0, decoder); printf("OK\n"); printf("freeing decoder instance... "); @@ -513,6 +527,13 @@ static bool test_stream_decoder(Layer layer) } printf("OK\n"); + if(is_ogg) { + printf("testing set_serial_number()... "); + if(!decoder->set_serial_number(file_utils__ogg_serial_number)) + return die_s_("returned false", decoder); + printf("OK\n"); + } + if(!decoder->set_md5_checking(true)) { printf("FAILED at set_md5_checking(), returned false\n"); return false; @@ -521,42 +542,45 @@ static bool test_stream_decoder(Layer layer) switch(layer) { case LAYER_STREAM: case LAYER_SEEKABLE_STREAM: - printf("opening FLAC file... "); - dynamic_cast<StreamDecoder*>(decoder)->file_ = ::fopen(flacfilename_, "rb"); + printf("opening %sFLAC file... ", is_ogg? "Ogg ":""); + dynamic_cast<StreamDecoder*>(decoder)->file_ = ::fopen(flacfilename(is_ogg), "rb"); if(0 == dynamic_cast<StreamDecoder*>(decoder)->file_) { printf("ERROR (%s)\n", strerror(errno)); return false; } printf("OK\n"); - printf("testing init()... "); - if(decoder->init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + printf("testing init%s()... ", is_ogg? "_ogg":""); + init_status = is_ogg? decoder->init_ogg() : decoder->init(); break; case LAYER_FILE: { printf("opening FLAC file... "); - FILE *file = ::fopen(flacfilename_, "rb"); + FILE *file = ::fopen(flacfilename(is_ogg), "rb"); if(0 == file) { printf("ERROR (%s)\n", strerror(errno)); return false; } printf("OK\n"); - printf("testing init()... "); - if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(file) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + printf("testing init%s()... ", is_ogg? "_ogg":""); + init_status = is_ogg? + dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(file) : + dynamic_cast<FLAC::Decoder::File*>(decoder)->init(file); } break; case LAYER_FILENAME: - printf("testing init()... "); - if(dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + printf("testing init%s()... ", is_ogg? "_ogg":""); + init_status = is_ogg? + dynamic_cast<FLAC::Decoder::File*>(decoder)->init_ogg(flacfilename(is_ogg)) : + dynamic_cast<FLAC::Decoder::File*>(decoder)->init(flacfilename(is_ogg)); break; default: die_("internal error 009"); return false; } + if(init_status != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) + return die_s_(0, decoder); printf("OK\n"); printf("testing get_state()... "); @@ -705,17 +729,30 @@ static bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application1_; + expected_metadata_sequence_[num_expected_++] = &application2_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application1_; + expected_metadata_sequence_[num_expected_++] = &application2_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -731,7 +768,7 @@ static bool test_stream_decoder(Layer layer) num_expected_ = 0; - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -762,7 +799,7 @@ static bool test_stream_decoder(Layer layer) expected_metadata_sequence_[num_expected_++] = &picture_; expected_metadata_sequence_[num_expected_++] = &unknown_; - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -784,15 +821,26 @@ static bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -814,16 +862,28 @@ static bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application2_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application2_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -852,15 +912,26 @@ static bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -884,7 +955,7 @@ static bool test_stream_decoder(Layer layer) num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -909,7 +980,7 @@ static bool test_stream_decoder(Layer layer) expected_metadata_sequence_[num_expected_++] = &application1_; expected_metadata_sequence_[num_expected_++] = &application2_; - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -933,7 +1004,7 @@ static bool test_stream_decoder(Layer layer) num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &application1_; - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -965,7 +1036,7 @@ static bool test_stream_decoder(Layer layer) expected_metadata_sequence_[num_expected_++] = &application1_; expected_metadata_sequence_[num_expected_++] = &application2_; - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -994,16 +1065,28 @@ static bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application1_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application1_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; /* @@ -1034,7 +1117,7 @@ static bool test_stream_decoder(Layer layer) num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &application2_; - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) + if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond(is_ogg) : dynamic_cast<FileDecoder*>(decoder)->test_respond(is_ogg))) return false; if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */ @@ -1051,26 +1134,34 @@ static bool test_stream_decoder(Layer layer) bool test_decoders() { - init_metadata_blocks_(); + FLAC__bool is_ogg = false; - if(!generate_file_()) - return false; + while(1) { + init_metadata_blocks_(); - if(!test_stream_decoder(LAYER_STREAM)) - return false; + if(!generate_file_(is_ogg)) + return false; - if(!test_stream_decoder(LAYER_SEEKABLE_STREAM)) - return false; + if(!test_stream_decoder(LAYER_STREAM, is_ogg)) + return false; - if(!test_stream_decoder(LAYER_FILE)) - return false; + if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg)) + return false; - if(!test_stream_decoder(LAYER_FILENAME)) - return false; + if(!test_stream_decoder(LAYER_FILE, is_ogg)) + return false; - (void) grabbag__file_remove_file(flacfilename_); + if(!test_stream_decoder(LAYER_FILENAME, is_ogg)) + return false; - free_metadata_blocks_(); + (void) grabbag__file_remove_file(flacfilename(is_ogg)); + + free_metadata_blocks_(); + + if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg) + break; + is_ogg = true; + } return true; } diff --git a/src/test_libFLAC++/encoders.cpp b/src/test_libFLAC++/encoders.cpp index 94124b9f..1eaabdd2 100644 --- a/src/test_libFLAC++/encoders.cpp +++ b/src/test_libFLAC++/encoders.cpp @@ -19,6 +19,7 @@ #include "encoders.h" #include "FLAC/assert.h" #include "FLAC++/encoder.h" +#include "share/grabbag.h" extern "C" { #include "test_libs_common/file_utils_flac.h" #include "test_libs_common/metadata_utils.h" @@ -43,11 +44,15 @@ static const char * const LayerString[] = { }; static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static ::FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_ }; +static ::FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ }; static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]); -static const char *flacfilename_ = "metadata.flac"; -static FLAC__bool die_(const char *msg) +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); return false; @@ -89,12 +94,20 @@ public: ~StreamEncoder() { } // from FLAC::Encoder::Stream + ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes); ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame); ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset); ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset); void metadata_callback(const ::FLAC__StreamMetadata *metadata); }; +::FLAC__StreamEncoderReadStatus StreamEncoder::read_callback(FLAC__byte buffer[], unsigned *bytes) +{ + (void)buffer, (void)bytes; + + return ::FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; +} + ::FLAC__StreamEncoderWriteStatus StreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) { (void)buffer, (void)bytes, (void)samples, (void)current_frame; @@ -145,15 +158,16 @@ static FLAC::Encoder::Stream *new_by_layer(Layer layer) return new FileEncoder(layer); } -static bool test_stream_encoder(Layer layer) +static bool test_stream_encoder(Layer layer, bool is_ogg) { FLAC::Encoder::Stream *encoder; + ::FLAC__StreamEncoderInitStatus init_status; FILE *file = 0; FLAC__int32 samples[1024]; FLAC__int32 *samples_array[1] = { samples }; unsigned i; - printf("\n+++ libFLAC++ unit test: FLAC::Encoder::%s (layer: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer]); + printf("\n+++ libFLAC++ unit test: FLAC::Encoder::%s (layer: %s, format: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer], is_ogg? "Ogg FLAC":"FLAC"); printf("allocating encoder instance... "); encoder = new_by_layer(layer); @@ -170,6 +184,13 @@ static bool test_stream_encoder(Layer layer) } printf("OK\n"); + if(is_ogg) { + printf("testing set_serial_number()... "); + if(!encoder->set_serial_number(file_utils__ogg_serial_number)) + return die_s_("returned false", encoder); + printf("OK\n"); + } + printf("testing set_verify()... "); if(!encoder->set_verify(true)) return die_s_("returned false", encoder); @@ -263,32 +284,35 @@ static bool test_stream_encoder(Layer layer) switch(layer) { case LAYER_STREAM: case LAYER_SEEKABLE_STREAM: - printf("testing init()... "); - if(encoder->init() != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); + printf("testing init%s()... ", is_ogg? "_ogg":""); + init_status = is_ogg? encoder->init_ogg() : encoder->init(); break; case LAYER_FILE: printf("opening file for FLAC output... "); - file = ::fopen(flacfilename_, "w+b"); + file = ::fopen(flacfilename(is_ogg), "w+b"); if(0 == file) { printf("ERROR (%s)\n", strerror(errno)); return false; } printf("OK\n"); - printf("testing init()... "); - if(dynamic_cast<FLAC::Encoder::File*>(encoder)->init(file) != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); + printf("testing init%s()... ", is_ogg? "_ogg":""); + init_status = is_ogg? + dynamic_cast<FLAC::Encoder::File*>(encoder)->init_ogg(file) : + dynamic_cast<FLAC::Encoder::File*>(encoder)->init(file); break; case LAYER_FILENAME: - printf("testing init()... "); - if(dynamic_cast<FLAC::Encoder::File*>(encoder)->init(flacfilename_) != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); + printf("testing init%s()... ", is_ogg? "_ogg":""); + init_status = is_ogg? + dynamic_cast<FLAC::Encoder::File*>(encoder)->init_ogg(flacfilename(is_ogg)) : + dynamic_cast<FLAC::Encoder::File*>(encoder)->init(flacfilename(is_ogg)); break; default: die_("internal error 001"); return false; } + if(init_status != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) + return die_s_(0, encoder); printf("OK\n"); printf("testing get_state()... "); @@ -458,21 +482,31 @@ static bool test_stream_encoder(Layer layer) bool test_encoders() { - init_metadata_blocks_(); + FLAC__bool is_ogg = false; - if(!test_stream_encoder(LAYER_STREAM)) - return false; + while(1) { + init_metadata_blocks_(); - if(!test_stream_encoder(LAYER_SEEKABLE_STREAM)) - return false; + if(!test_stream_encoder(LAYER_STREAM, is_ogg)) + return false; - if(!test_stream_encoder(LAYER_FILE)) - return false; + if(!test_stream_encoder(LAYER_SEEKABLE_STREAM, is_ogg)) + return false; - if(!test_stream_encoder(LAYER_FILENAME)) - return false; + if(!test_stream_encoder(LAYER_FILE, is_ogg)) + return false; - free_metadata_blocks_(); + if(!test_stream_encoder(LAYER_FILENAME, is_ogg)) + return false; + + (void) grabbag__file_remove_file(flacfilename(is_ogg)); + + free_metadata_blocks_(); + + if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg) + break; + is_ogg = true; + } return true; } diff --git a/src/test_libFLAC++/metadata_manip.cpp b/src/test_libFLAC++/metadata_manip.cpp index d31b28fb..93b642b3 100644 --- a/src/test_libFLAC++/metadata_manip.cpp +++ b/src/test_libFLAC++/metadata_manip.cpp @@ -16,6 +16,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#if HAVE_CONFIG_H +# include <config.h> +#endif + #include <stdio.h> #include <stdlib.h> /* for malloc() */ #include <string.h> /* for memcpy()/memset() */ @@ -589,7 +593,7 @@ static bool generate_file_(FLAC__bool include_extras) ) return die_("priming our metadata"); - if(!file_utils__generate_flacfile(flacfile_, 0, 512 * 1024, &streaminfo, metadata, n)) + if(!file_utils__generate_flacfile(/*is_ogg=*/false, flacfile_, 0, 512 * 1024, &streaminfo, metadata, n)) return die_("creating the encoded file"); free(vorbiscomment.data.vorbis_comment.vendor_string.entry); diff --git a/src/test_libFLAC/decoders.c b/src/test_libFLAC/decoders.c index 5c9eeda7..7aa46ed0 100644 --- a/src/test_libFLAC/decoders.c +++ b/src/test_libFLAC/decoders.c @@ -38,10 +38,10 @@ #include "test_libs_common/metadata_utils.h" typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_decoder_init_stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_stream() with seeking */ - LAYER_FILE, /* FLAC__stream_decoder_init_FILE() */ - LAYER_FILENAME /* FLAC__stream_decoder_init_file() */ + LAYER_STREAM = 0, /* FLAC__stream_decoder_init_[ogg_]stream() without seeking */ + LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_[ogg_]stream() with seeking */ + LAYER_FILE, /* FLAC__stream_decoder_init_[ogg_]FILE() */ + LAYER_FILENAME /* FLAC__stream_decoder_init_[ogg_]file() */ } Layer; static const char * const LayerString[] = { @@ -62,9 +62,13 @@ typedef struct { static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; static FLAC__StreamMetadata *expected_metadata_sequence_[9]; static unsigned num_expected_; -static const char *flacfilename_ = "metadata.flac"; static off_t flacfilesize_; +static const char *flacfilename(FLAC__bool is_ogg) +{ + return is_ogg? "metadata.ogg" : "metadata.flac"; +} + static FLAC__bool die_(const char *msg) { printf("ERROR: %s\n", msg); @@ -95,9 +99,9 @@ static void free_metadata_blocks_() mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); } -static FLAC__bool generate_file_() +static FLAC__bool generate_file_(FLAC__bool is_ogg) { - printf("\n\ngenerating FLAC file for decoder tests...\n"); + printf("\n\ngenerating %sFLAC file for decoder tests...\n", is_ogg? "Ogg ":""); num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &padding_; @@ -108,8 +112,9 @@ static FLAC__bool generate_file_() expected_metadata_sequence_[num_expected_++] = &cuesheet_; expected_metadata_sequence_[num_expected_++] = &picture_; expected_metadata_sequence_[num_expected_++] = &unknown_; + /* WATCHOUT: for Ogg FLAC the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */ - if(!file_utils__generate_flacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_)) + if(!file_utils__generate_flacfile(is_ogg, flacfilename(is_ogg), &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_)) return die_("creating the encoded file"); return true; @@ -305,7 +310,7 @@ static void stream_decoder_error_callback_(const FLAC__StreamDecoder *decoder, F } } -static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, StreamDecoderClientData *dcd) +static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, StreamDecoderClientData *dcd, FLAC__bool is_ogg) { FLAC__StreamDecoderInitStatus init_status; @@ -314,8 +319,8 @@ static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, Str /* for FLAC__stream_encoder_init_FILE(), the FLAC__stream_encoder_finish() closes the file so we have to keep re-opening: */ if(dcd->layer == LAYER_FILE) { - printf("opening FLAC file... "); - dcd->file = fopen(flacfilename_, "rb"); + printf("opening %sFLAC file... ", is_ogg? "Ogg ":""); + dcd->file = fopen(flacfilename(is_ogg), "rb"); if(0 == dcd->file) { printf("ERROR (%s)\n", strerror(errno)); return false; @@ -323,19 +328,31 @@ static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, Str printf("OK\n"); } - printf("testing FLAC__stream_decoder_init_stream()... "); switch(dcd->layer) { case LAYER_STREAM: - init_status = FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); + printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) : + FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) + ; break; case LAYER_SEEKABLE_STREAM: - init_status = FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); + printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) : + FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); break; case LAYER_FILE: - init_status = FLAC__stream_decoder_init_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); + printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) : + FLAC__stream_decoder_init_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); break; case LAYER_FILENAME: - init_status = FLAC__stream_decoder_init_file(decoder, flacfilename_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); + printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd) : + FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); break; default: die_("internal error 000"); @@ -364,16 +381,17 @@ static FLAC__bool stream_decoder_test_respond_(FLAC__StreamDecoder *decoder, Str return true; } -static FLAC__bool test_stream_decoder(Layer layer) +static FLAC__bool test_stream_decoder(Layer layer, FLAC__bool is_ogg) { FLAC__StreamDecoder *decoder; + FLAC__StreamDecoderInitStatus init_status; FLAC__StreamDecoderState state; StreamDecoderClientData decoder_client_data; FLAC__bool expect; decoder_client_data.layer = layer; - printf("\n+++ libFLAC unit test: FLAC__StreamDecoder (layer: %s)\n\n", LayerString[layer]); + printf("\n+++ libFLAC unit test: FLAC__StreamDecoder (layer: %s, format: %s)\n\n", LayerString[layer], is_ogg? "Ogg FLAC" : "FLAC"); printf("testing FLAC__stream_decoder_new()... "); decoder = FLAC__stream_decoder_new(); @@ -398,24 +416,29 @@ static FLAC__bool test_stream_decoder(Layer layer) switch(layer) { case LAYER_STREAM: case LAYER_SEEKABLE_STREAM: - printf("testing FLAC__stream_decoder_init_stream()... "); - if(FLAC__stream_decoder_init_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS) - return die_s_(0, decoder); + printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0) : + FLAC__stream_decoder_init_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0); break; case LAYER_FILE: - printf("testing FLAC__stream_decoder_init_FILE()... "); - if(FLAC__stream_decoder_init_FILE(decoder, stdin, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS) - return die_s_(0, decoder); + printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_FILE(decoder, stdin, 0, 0, 0, 0) : + FLAC__stream_decoder_init_FILE(decoder, stdin, 0, 0, 0, 0); break; case LAYER_FILENAME: - printf("testing FLAC__stream_decoder_init_file()... "); - if(FLAC__stream_decoder_init_file(decoder, flacfilename_, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS) - return die_s_(0, decoder); + printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0) : + FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), 0, 0, 0, 0); break; default: die_("internal error 003"); return false; } + if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS) + return die_s_(0, decoder); printf("OK\n"); printf("testing FLAC__stream_decoder_delete()... "); @@ -433,14 +456,21 @@ static FLAC__bool test_stream_decoder(Layer layer) } printf("OK\n"); + if(is_ogg) { + printf("testing FLAC__stream_decoder_set_serial_number()... "); + if(!FLAC__stream_decoder_set_serial_number(decoder, file_utils__ogg_serial_number)) + return die_s_("returned false", decoder); + printf("OK\n"); + } + printf("testing FLAC__stream_decoder_set_md5_checking()... "); if(!FLAC__stream_decoder_set_md5_checking(decoder, true)) return die_s_("returned false", decoder); printf("OK\n"); if(layer < LAYER_FILENAME) { - printf("opening FLAC file... "); - decoder_client_data.file = fopen(flacfilename_, "rb"); + printf("opening %sFLAC file... ", is_ogg? "Ogg ":""); + decoder_client_data.file = fopen(flacfilename(is_ogg), "rb"); if(0 == decoder_client_data.file) { printf("ERROR (%s)\n", strerror(errno)); return false; @@ -450,29 +480,35 @@ static FLAC__bool test_stream_decoder(Layer layer) switch(layer) { case LAYER_STREAM: - printf("testing FLAC__stream_decoder_init_stream()... "); - if(FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) : + FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data); break; case LAYER_SEEKABLE_STREAM: - printf("testing FLAC__stream_decoder_init_stream()... "); - if(FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + printf("testing FLAC__stream_decoder_init_%sstream()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) : + FLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data); break; case LAYER_FILE: - printf("testing FLAC__stream_decoder_init_FILE()... "); - if(FLAC__stream_decoder_init_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + printf("testing FLAC__stream_decoder_init_%sFILE()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) : + FLAC__stream_decoder_init_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data); break; case LAYER_FILENAME: - printf("testing FLAC__stream_decoder_init_file()... "); - if(FLAC__stream_decoder_init_file(decoder, flacfilename_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); + printf("testing FLAC__stream_decoder_init_%sfile()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_decoder_init_ogg_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) : + FLAC__stream_decoder_init_file(decoder, flacfilename(is_ogg), stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data); break; default: die_("internal error 009"); return false; } + if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) + return die_s_(0, decoder); printf("OK\n"); printf("testing FLAC__stream_decoder_get_state()... "); @@ -622,17 +658,30 @@ static FLAC__bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application1_; + expected_metadata_sequence_[num_expected_++] = &application2_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application1_; + expected_metadata_sequence_[num_expected_++] = &application2_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -646,7 +695,7 @@ static FLAC__bool test_stream_decoder(Layer layer) num_expected_ = 0; - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -673,7 +722,7 @@ static FLAC__bool test_stream_decoder(Layer layer) expected_metadata_sequence_[num_expected_++] = &picture_; expected_metadata_sequence_[num_expected_++] = &unknown_; - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -691,15 +740,26 @@ static FLAC__bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -717,16 +777,28 @@ static FLAC__bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application2_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application2_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -749,15 +821,26 @@ static FLAC__bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -777,7 +860,7 @@ static FLAC__bool test_stream_decoder(Layer layer) num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -798,7 +881,7 @@ static FLAC__bool test_stream_decoder(Layer layer) expected_metadata_sequence_[num_expected_++] = &application1_; expected_metadata_sequence_[num_expected_++] = &application2_; - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -818,7 +901,7 @@ static FLAC__bool test_stream_decoder(Layer layer) num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &application1_; - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -844,7 +927,7 @@ static FLAC__bool test_stream_decoder(Layer layer) expected_metadata_sequence_[num_expected_++] = &application1_; expected_metadata_sequence_[num_expected_++] = &application2_; - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -867,16 +950,28 @@ static FLAC__bool test_stream_decoder(Layer layer) printf("OK\n"); num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; + if(is_ogg) { /* encoder moves vorbis comment after streaminfo according to ogg mapping */ + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application1_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } + else { + expected_metadata_sequence_[num_expected_++] = &streaminfo_; + expected_metadata_sequence_[num_expected_++] = &padding_; + expected_metadata_sequence_[num_expected_++] = &seektable_; + expected_metadata_sequence_[num_expected_++] = &application1_; + expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; + expected_metadata_sequence_[num_expected_++] = &cuesheet_; + expected_metadata_sequence_[num_expected_++] = &picture_; + expected_metadata_sequence_[num_expected_++] = &unknown_; + } - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; /* @@ -901,7 +996,7 @@ static FLAC__bool test_stream_decoder(Layer layer) num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &application2_; - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) + if(!stream_decoder_test_respond_(decoder, &decoder_client_data, is_ogg)) return false; if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */ @@ -918,24 +1013,34 @@ static FLAC__bool test_stream_decoder(Layer layer) FLAC__bool test_decoders() { - init_metadata_blocks_(); - if(!generate_file_()) - return false; + FLAC__bool is_ogg = false; - if(!test_stream_decoder(LAYER_STREAM)) - return false; + while(1) { + init_metadata_blocks_(); - if(!test_stream_decoder(LAYER_SEEKABLE_STREAM)) - return false; + if(!generate_file_(is_ogg)) + return false; - if(!test_stream_decoder(LAYER_FILE)) - return false; + if(!test_stream_decoder(LAYER_STREAM, is_ogg)) + return false; - if(!test_stream_decoder(LAYER_FILENAME)) - return false; + if(!test_stream_decoder(LAYER_SEEKABLE_STREAM, is_ogg)) + return false; + + if(!test_stream_decoder(LAYER_FILE, is_ogg)) + return false; + + if(!test_stream_decoder(LAYER_FILENAME, is_ogg)) + return false; + + (void) grabbag__file_remove_file(flacfilename(is_ogg)); + + free_metadata_blocks_(); - (void) grabbag__file_remove_file(flacfilename_); - free_metadata_blocks_(); + if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg) + break; + is_ogg = true; + } return true; } diff --git a/src/test_libFLAC/encoders.c b/src/test_libFLAC/encoders.c index f3e97881..33ef4166 100644 --- a/src/test_libFLAC/encoders.c +++ b/src/test_libFLAC/encoders.c @@ -32,10 +32,10 @@ #include "test_libs_common/metadata_utils.h" typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_encoder_init_stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_stream() with seeking */ - LAYER_FILE, /* FLAC__stream_encoder_init_FILE() */ - LAYER_FILENAME /* FLAC__stream_encoder_init_file() */ + LAYER_STREAM = 0, /* FLAC__stream_encoder_init_[ogg_]stream() without seeking */ + LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_[ogg_]stream() with seeking */ + LAYER_FILE, /* FLAC__stream_encoder_init_[ogg_]FILE() */ + LAYER_FILENAME /* FLAC__stream_encoder_init_[ogg_]file() */ } Layer; static const char * const LayerString[] = { @@ -46,9 +46,13 @@ static const char * const LayerString[] = { }; static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static FLAC__StreamMetadata *metadata_sequence_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_ }; +static FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ }; static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]); -static const char *flacfilename_ = "metadata.flac"; + +static const char *flacfilename(FLAC__bool is_ogg) +{ + return is_ogg? "metadata.ogg" : "metadata.flac"; +} static FLAC__bool die_(const char *msg) { @@ -84,6 +88,13 @@ static void free_metadata_blocks_() mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); } +static FLAC__StreamEncoderReadStatus stream_encoder_read_callback_(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) +{ + (void)encoder, (void)buffer, (void)bytes, (void)client_data; + memset(buffer, 0, *bytes); /* init buffer to avoid valgrind errors */ + return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; +} + static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) { (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data; @@ -113,9 +124,10 @@ static void stream_encoder_progress_callback_(const FLAC__StreamEncoder *encoder (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data; } -static FLAC__bool test_stream_encoder(Layer layer) +static FLAC__bool test_stream_encoder(Layer layer, FLAC__bool is_ogg) { FLAC__StreamEncoder *encoder; + FLAC__StreamEncoderInitStatus init_status; FLAC__StreamEncoderState state; FLAC__StreamDecoderState dstate; FILE *file = 0; @@ -125,7 +137,7 @@ static FLAC__bool test_stream_encoder(Layer layer) samples_array[0] = samples; - printf("\n+++ libFLAC unit test: FLAC__StreamEncoder (layer: %s)\n\n", LayerString[layer]); + printf("\n+++ libFLAC unit test: FLAC__StreamEncoder (layer: %s, format: %s)\n\n", LayerString[layer], is_ogg? "Ogg FLAC":"FLAC"); printf("testing FLAC__stream_encoder_new()... "); encoder = FLAC__stream_encoder_new(); @@ -135,6 +147,13 @@ static FLAC__bool test_stream_encoder(Layer layer) } printf("OK\n"); + if(is_ogg) { + printf("testing FLAC__stream_encoder_set_serial_number()... "); + if(!FLAC__stream_encoder_set_serial_number(encoder, file_utils__ogg_serial_number)) + return die_s_("returned false", encoder); + printf("OK\n"); + } + printf("testing FLAC__stream_encoder_set_verify()... "); if(!FLAC__stream_encoder_set_verify(encoder, true)) return die_s_("returned false", encoder); @@ -227,37 +246,43 @@ static FLAC__bool test_stream_encoder(Layer layer) switch(layer) { case LAYER_STREAM: - printf("testing FLAC__stream_encoder_init_stream()... "); - if(FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); + printf("testing FLAC__stream_encoder_init_%sstream()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_encoder_init_ogg_stream(encoder, /*read_callback=*/0, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/0) : + FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/0); break; case LAYER_SEEKABLE_STREAM: - printf("testing FLAC__stream_encoder_init_stream()... "); - if(FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); + printf("testing FLAC__stream_encoder_init_%sstream()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_encoder_init_ogg_stream(encoder, stream_encoder_read_callback_, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/0) : + FLAC__stream_encoder_init_stream(encoder, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/0); break; case LAYER_FILE: printf("opening file for FLAC output... "); - file = fopen(flacfilename_, "w+b"); + file = fopen(flacfilename(is_ogg), "w+b"); if(0 == file) { printf("ERROR (%s)\n", strerror(errno)); return false; } printf("OK\n"); - printf("testing FLAC__stream_encoder_init_FILE()... "); - if(FLAC__stream_encoder_init_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); + printf("testing FLAC__stream_encoder_init_%sFILE()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_encoder_init_ogg_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0) : + FLAC__stream_encoder_init_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0); break; case LAYER_FILENAME: - printf("testing FLAC__stream_encoder_init_file()... "); - if(FLAC__stream_encoder_init_file(encoder, flacfilename_, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); + printf("testing FLAC__stream_encoder_init_%sfile()... ", is_ogg? "ogg_":""); + init_status = is_ogg? + FLAC__stream_encoder_init_ogg_file(encoder, flacfilename(is_ogg), stream_encoder_progress_callback_, /*client_data=*/0) : + FLAC__stream_encoder_init_file(encoder, flacfilename(is_ogg), stream_encoder_progress_callback_, /*client_data=*/0); break; default: die_("internal error 001"); return false; } + if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) + return die_s_(0, encoder); printf("OK\n"); printf("testing FLAC__stream_encoder_get_state()... "); @@ -427,22 +452,31 @@ static FLAC__bool test_stream_encoder(Layer layer) FLAC__bool test_encoders() { - init_metadata_blocks_(); + FLAC__bool is_ogg = false; - if(!test_stream_encoder(LAYER_STREAM)) - return false; + while(1) { + init_metadata_blocks_(); - if(!test_stream_encoder(LAYER_SEEKABLE_STREAM)) - return false; + if(!test_stream_encoder(LAYER_STREAM, is_ogg)) + return false; - if(!test_stream_encoder(LAYER_FILE)) - return false; + if(!test_stream_encoder(LAYER_SEEKABLE_STREAM, is_ogg)) + return false; - if(!test_stream_encoder(LAYER_FILENAME)) - return false; + if(!test_stream_encoder(LAYER_FILE, is_ogg)) + return false; - (void) grabbag__file_remove_file(flacfilename_); - free_metadata_blocks_(); + if(!test_stream_encoder(LAYER_FILENAME, is_ogg)) + return false; + + (void) grabbag__file_remove_file(flacfilename(is_ogg)); + + free_metadata_blocks_(); + + if(!FLAC_API_SUPPORTS_OGG_FLAC || is_ogg) + break; + is_ogg = true; + } return true; } diff --git a/src/test_libFLAC/metadata_manip.c b/src/test_libFLAC/metadata_manip.c index 58df54ce..ea21e50c 100644 --- a/src/test_libFLAC/metadata_manip.c +++ b/src/test_libFLAC/metadata_manip.c @@ -595,7 +595,7 @@ static FLAC__bool generate_file_(FLAC__bool include_extras) ) return die_("priming our metadata"); - if(!file_utils__generate_flacfile(flacfile_, 0, 512 * 1024, &streaminfo, metadata, n)) + if(!file_utils__generate_flacfile(/*is_ogg=*/false, flacfile_, 0, 512 * 1024, &streaminfo, metadata, n)) return die_("creating the encoded file"); free(vorbiscomment.data.vorbis_comment.vendor_string.entry); diff --git a/src/test_libOggFLAC++/Makefile.am b/src/test_libOggFLAC++/Makefile.am deleted file mode 100644 index 199178eb..00000000 --- a/src/test_libOggFLAC++/Makefile.am +++ /dev/null @@ -1,40 +0,0 @@ -# test_libOggFLAC++ - Unit tester for libOggFLAC++ -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -EXTRA_DIST = \ - Makefile.lite \ - test_libOggFLAC++.dsp - -AM_CFLAGS = @OGG_CFLAGS@ - -noinst_PROGRAMS = test_libOggFLAC++ -test_libOggFLAC___LDADD = \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/test_libs_common/libtest_libs_common.la \ - $(top_builddir)/src/libOggFLAC++/libOggFLAC++.la \ - $(top_builddir)/src/libOggFLAC/libOggFLAC.la \ - $(top_builddir)/src/libFLAC++/libFLAC++.la \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - @OGG_LIBS@ \ - -lm -test_libOggFLAC___SOURCES = \ - decoders.cpp \ - encoders.cpp \ - main.cpp \ - decoders.h \ - encoders.h diff --git a/src/test_libOggFLAC++/Makefile.lite b/src/test_libOggFLAC++/Makefile.lite deleted file mode 100644 index a2fe5691..00000000 --- a/src/test_libOggFLAC++/Makefile.lite +++ /dev/null @@ -1,44 +0,0 @@ -# test_libOggFLAC++ - Unit tester for libOggFLAC++ -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -# -# GNU makefile -# - -topdir = ../.. -libdir = $(topdir)/obj/$(BUILD)/lib - -PROGRAM_NAME = test_libOggFLAC++ - -INCLUDES = -I$(topdir)/include - -ifeq ($(DARWIN_BUILD),yes) -EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libreplaygain_analysis.a $(libdir)/libtest_libs_common.a $(libdir)/libOggFLAC++.a $(libdir)/libOggFLAC.a $(libdir)/libFLAC++.a $(libdir)/libFLAC.a $(OGG_LIB_DIR)/libogg.a -lm -else -LIBS = -lgrabbag -lreplaygain_analysis -ltest_libs_common -lOggFLAC++ -lOggFLAC -lFLAC++ -lFLAC -L$(OGG_LIB_DIR) -logg -lm -endif - -SRCS_CPP = \ - decoders.cpp \ - encoders.cpp \ - main.cpp - -include $(topdir)/build/exe.mk - -LINK = $(CCC) $(LINKAGE) - -# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/src/test_libOggFLAC++/decoders.cpp b/src/test_libOggFLAC++/decoders.cpp deleted file mode 100644 index 002150bb..00000000 --- a/src/test_libOggFLAC++/decoders.cpp +++ /dev/null @@ -1,1089 +0,0 @@ -/* test_libOggFLAC++ - Unit tester for libOggFLAC++ - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#if defined _MSC_VER || defined __MINGW32__ -#if _MSC_VER <= 1200 /* @@@ [2G limit] */ -#define fseeko fseek -#define ftello ftell -#endif -#endif -#include "decoders.h" -#include "FLAC/assert.h" -#include "FLAC/metadata.h" // for ::FLAC__metadata_object_is_equal() -#include "OggFLAC++/decoder.h" -#include "share/grabbag.h" -extern "C" { -#include "test_libs_common/file_utils_oggflac.h" -#include "test_libs_common/metadata_utils.h" -} - -#ifdef _MSC_VER -// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning) -#pragma warning ( disable : 4800 ) -#endif - -typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_decoder_init_stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_stream() with seeking */ - LAYER_FILE, /* FLAC__stream_decoder_init_FILE() */ - LAYER_FILENAME /* FLAC__stream_decoder_init_file() */ -} Layer; - -static const char * const LayerString[] = { - "Stream", - "Seekable Stream", - "FILE*", - "Filename" -}; - -static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static ::FLAC__StreamMetadata *expected_metadata_sequence_[9]; -static unsigned num_expected_; -static const char *flacfilename_ = "metadata.ogg"; -static off_t flacfilesize_; - -static bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static FLAC__bool die_s_(const char *msg, const OggFLAC::Decoder::Stream *decoder) -{ - OggFLAC::Decoder::Stream::State state = decoder->get_state(); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring()); - if(state == ::OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) { - FLAC::Decoder::Stream::State state_ = decoder->get_FLAC_stream_decoder_state(); - printf(" FLAC stream decoder state = %u (%s)\n", (unsigned)((::FLAC::Decoder::Stream::State)state_), state_.as_cstring()); - } - - return false; -} - -static void init_metadata_blocks_() -{ - mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static void free_metadata_blocks_() -{ - mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static bool generate_file_() -{ - printf("\n\ngenerating Ogg FLAC file for decoder tests...\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - /* WATCHOUT: the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */ - - if(!file_utils__generate_oggflacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_)) - return die_("creating the encoded file"); - - return true; -} - - -class DecoderCommon { -public: - Layer layer_; - unsigned current_metadata_number_; - bool ignore_errors_; - bool error_occurred_; - - DecoderCommon(Layer layer): layer_(layer), current_metadata_number_(0), ignore_errors_(false), error_occurred_(false) { } - ::FLAC__StreamDecoderWriteStatus common_write_callback_(const ::FLAC__Frame *frame); - void common_metadata_callback_(const ::FLAC__StreamMetadata *metadata); - void common_error_callback_(::FLAC__StreamDecoderErrorStatus status); -}; - -::FLAC__StreamDecoderWriteStatus DecoderCommon::common_write_callback_(const ::FLAC__Frame *frame) -{ - if(error_occurred_) - return ::FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - - if( - (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) || - (frame->header.number_type == ::FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0) - ) { - printf("content... "); - fflush(stdout); - } - - return ::FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -void DecoderCommon::common_metadata_callback_(const ::FLAC__StreamMetadata *metadata) -{ - if(error_occurred_) - return; - - printf("%d... ", current_metadata_number_); - fflush(stdout); - - if(current_metadata_number_ >= num_expected_) { - (void)die_("got more metadata blocks than expected"); - error_occurred_ = true; - } - else { - if(!::FLAC__metadata_object_is_equal(expected_metadata_sequence_[current_metadata_number_], metadata)) { - (void)die_("metadata block mismatch"); - error_occurred_ = true; - } - } - current_metadata_number_++; -} - -void DecoderCommon::common_error_callback_(::FLAC__StreamDecoderErrorStatus status) -{ - if(!ignore_errors_) { - printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, ::FLAC__StreamDecoderErrorStatusString[status]); - error_occurred_ = true; - } -} - -class StreamDecoder : public OggFLAC::Decoder::Stream, public DecoderCommon { -public: - FILE *file_; - - StreamDecoder(Layer layer): OggFLAC::Decoder::Stream(), DecoderCommon(layer), file_(0) { } - ~StreamDecoder() { } - - // from OggFLAC::Decoder::Stream - ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes); - ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset); - ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset); - ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length); - bool eof_callback(); - ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]); - void metadata_callback(const ::FLAC__StreamMetadata *metadata); - void error_callback(::FLAC__StreamDecoderErrorStatus status); - - bool test_respond(); -}; - -::FLAC__StreamDecoderReadStatus StreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes) -{ - const unsigned requested_bytes = *bytes; - - if(error_occurred_) - return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; - - if(feof(file_)) { - *bytes = 0; - return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - } - else if(requested_bytes > 0) { - *bytes = ::fread(buffer, 1, requested_bytes, file_); - if(*bytes == 0) { - if(feof(file_)) - return ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - else - return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - else { - return ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - } - else - return ::FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */ -} - -::FLAC__StreamDecoderSeekStatus StreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset) -{ - if(layer_ == LAYER_STREAM) - return ::FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; - - if(error_occurred_) - return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - - if(fseeko(file_, (off_t)absolute_byte_offset, SEEK_SET) < 0) { - error_occurred_ = true; - return ::FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - } - - return ::FLAC__STREAM_DECODER_SEEK_STATUS_OK; -} - -::FLAC__StreamDecoderTellStatus StreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset) -{ - if(layer_ == LAYER_STREAM) - return ::FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; - - if(error_occurred_) - return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - - off_t offset = ftello(file_); - *absolute_byte_offset = (FLAC__uint64)offset; - - if(offset < 0) { - error_occurred_ = true; - return ::FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - } - - return ::FLAC__STREAM_DECODER_TELL_STATUS_OK; -} - -::FLAC__StreamDecoderLengthStatus StreamDecoder::length_callback(FLAC__uint64 *stream_length) -{ - if(layer_ == LAYER_STREAM) - return ::FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; - - if(error_occurred_) - return ::FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - - *stream_length = (FLAC__uint64)flacfilesize_; - return ::FLAC__STREAM_DECODER_LENGTH_STATUS_OK; -} - -bool StreamDecoder::eof_callback() -{ - if(layer_ == LAYER_STREAM) - return false; - - if(error_occurred_) - return true; - - return (bool)feof(file_); -} - -::FLAC__StreamDecoderWriteStatus StreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) -{ - (void)buffer; - - return common_write_callback_(frame); -} - -void StreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata) -{ - common_metadata_callback_(metadata); -} - -void StreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status) -{ - common_error_callback_(status); -} - -bool StreamDecoder::test_respond() -{ - if(!set_md5_checking(true)) { - printf("FAILED at set_md5_checking(), returned false\n"); - return false; - } - - printf("testing init()... "); - if(init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, this); - printf("OK\n"); - - current_metadata_number_ = 0; - - if(fseeko(file_, 0, SEEK_SET) < 0) { - printf("FAILED rewinding input, errno = %d\n", errno); - return false; - } - - printf("testing process_until_end_of_stream()... "); - if(!process_until_end_of_stream()) { - State state = get_state(); - printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring()); - return false; - } - printf("OK\n"); - - printf("testing finish()... "); - finish(); - printf("OK\n"); - - return true; -} - -class FileDecoder : public OggFLAC::Decoder::File, public DecoderCommon { -public: - FileDecoder(Layer layer): OggFLAC::Decoder::File(), DecoderCommon(layer) { } - ~FileDecoder() { } - - // from OggFLAC::Decoder::Stream - ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]); - void metadata_callback(const ::FLAC__StreamMetadata *metadata); - void error_callback(::FLAC__StreamDecoderErrorStatus status); - - bool test_respond(); -}; - -::FLAC__StreamDecoderWriteStatus FileDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) -{ - (void)buffer; - return common_write_callback_(frame); -} - -void FileDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata) -{ - common_metadata_callback_(metadata); -} - -void FileDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status) -{ - common_error_callback_(status); -} - -bool FileDecoder::test_respond() -{ - if(!set_md5_checking(true)) { - printf("FAILED at set_md5_checking(), returned false\n"); - return false; - } - - switch(layer_) { - case LAYER_FILE: - { - printf("opening Ogg FLAC file... "); - FILE *file = ::fopen(flacfilename_, "rb"); - if(0 == file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - - printf("testing init()... "); - if(init(file) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, this); - } - break; - case LAYER_FILENAME: - printf("testing init()... "); - if(init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, this); - break; - default: - die_("internal error 001"); - return false; - } - printf("OK\n"); - - current_metadata_number_ = 0; - - printf("testing process_until_end_of_stream()... "); - if(!process_until_end_of_stream()) { - State state = get_state(); - printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring()); - return false; - } - printf("OK\n"); - - printf("testing finish()... "); - finish(); - printf("OK\n"); - - return true; -} - -static OggFLAC::Decoder::Stream *new_by_layer(Layer layer) -{ - if(layer < LAYER_FILE) - return new StreamDecoder(layer); - else - return new FileDecoder(layer); -} - -static bool test_stream_decoder(Layer layer) -{ - OggFLAC::Decoder::Stream *decoder; - bool expect; - - printf("\n+++ libOggFLAC++ unit test: OggFLAC::Decoder::%s (layer: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer]); - - // - // test new -> delete - // - printf("allocating decoder instance... "); - decoder = new_by_layer(layer); - if(0 == decoder) { - printf("FAILED, new returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing is_valid()... "); - if(!decoder->is_valid()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("freeing decoder instance... "); - delete decoder; - printf("OK\n"); - - // - // test new -> init -> delete - // - printf("allocating decoder instance... "); - decoder = new_by_layer(layer); - if(0 == decoder) { - printf("FAILED, new returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing is_valid()... "); - if(!decoder->is_valid()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing init()... "); - switch(layer) { - case LAYER_STREAM: - case LAYER_SEEKABLE_STREAM: - dynamic_cast<StreamDecoder*>(decoder)->file_ = stdin; - if(decoder->init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - break; - case LAYER_FILE: - if(dynamic_cast<OggFLAC::Decoder::File*>(decoder)->init(stdin) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - break; - case LAYER_FILENAME: - if(dynamic_cast<OggFLAC::Decoder::File*>(decoder)->init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - break; - default: - die_("internal error 006"); - return false; - } - printf("OK\n"); - - printf("freeing decoder instance... "); - delete decoder; - printf("OK\n"); - - // - // test normal usage - // - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - - printf("allocating decoder instance... "); - decoder = new_by_layer(layer); - if(0 == decoder) { - printf("FAILED, new returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing is_valid()... "); - if(!decoder->is_valid()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_serial_number()... "); - if(!decoder->set_serial_number(file_utils__serial_number)) - return die_s_("returned false", decoder); - printf("OK\n"); - - if(!decoder->set_md5_checking(true)) { - printf("FAILED at set_md5_checking(), returned false\n"); - return false; - } - - switch(layer) { - case LAYER_STREAM: - case LAYER_SEEKABLE_STREAM: - printf("opening Ogg FLAC file... "); - dynamic_cast<StreamDecoder*>(decoder)->file_ = ::fopen(flacfilename_, "rb"); - if(0 == dynamic_cast<StreamDecoder*>(decoder)->file_) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - - printf("testing init()... "); - if(decoder->init() != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - break; - case LAYER_FILE: - { - printf("opening Ogg FLAC file... "); - FILE *file = ::fopen(flacfilename_, "rb"); - if(0 == file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - - printf("testing init()... "); - if(dynamic_cast<OggFLAC::Decoder::File*>(decoder)->init(file) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - } - break; - case LAYER_FILENAME: - printf("testing init()... "); - if(dynamic_cast<OggFLAC::Decoder::File*>(decoder)->init(flacfilename_) != ::FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - break; - default: - die_("internal error 009"); - return false; - } - printf("OK\n"); - - printf("testing get_state()... "); - OggFLAC::Decoder::Stream::State state = decoder->get_state(); - printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamDecoderState)state), state.as_cstring()); - - printf("testing get_FLAC_stream_decoder_state()... "); - FLAC::Decoder::Stream::State state_ = decoder->get_FLAC_stream_decoder_state(); - printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring()); - - dynamic_cast<DecoderCommon*>(decoder)->current_metadata_number_ = 0; - dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = false; - dynamic_cast<DecoderCommon*>(decoder)->error_occurred_ = false; - - printf("testing get_md5_checking()... "); - if(!decoder->get_md5_checking()) { - printf("FAILED, returned false, expected true\n"); - return false; - } - printf("OK\n"); - - printf("testing process_until_end_of_metadata()... "); - if(!decoder->process_until_end_of_metadata()) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing process_single()... "); - if(!decoder->process_single()) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing skip_single_frame()... "); - if(!decoder->skip_single_frame()) - return die_s_("returned false", decoder); - printf("OK\n"); - - if(layer < LAYER_FILE) { - printf("testing flush()... "); - if(!decoder->flush()) - return die_s_("returned false", decoder); - printf("OK\n"); - - dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = true; - printf("testing process_single()... "); - if(!decoder->process_single()) - return die_s_("returned false", decoder); - printf("OK\n"); - dynamic_cast<DecoderCommon*>(decoder)->ignore_errors_ = false; - } - - expect = (layer != LAYER_STREAM); - printf("testing seek_absolute()... "); - if(decoder->seek_absolute(0) != expect) - return die_s_(expect? "returned false" : "returned true", decoder); - printf("OK\n"); - - printf("testing process_until_end_of_stream()... "); - if(!decoder->process_until_end_of_stream()) - return die_s_("returned false", decoder); - printf("OK\n"); - - expect = (layer != LAYER_STREAM); - printf("testing seek_absolute()... "); - if(decoder->seek_absolute(0) != expect) - return die_s_(expect? "returned false" : "returned true", decoder); - printf("OK\n"); - - printf("testing get_channels()... "); - { - unsigned channels = decoder->get_channels(); - if(channels != streaminfo_.data.stream_info.channels) { - printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels); - return false; - } - } - printf("OK\n"); - - printf("testing get_bits_per_sample()... "); - { - unsigned bits_per_sample = decoder->get_bits_per_sample(); - if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) { - printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample); - return false; - } - } - printf("OK\n"); - - printf("testing get_sample_rate()... "); - { - unsigned sample_rate = decoder->get_sample_rate(); - if(sample_rate != streaminfo_.data.stream_info.sample_rate) { - printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate); - return false; - } - } - printf("OK\n"); - - printf("testing get_blocksize()... "); - { - unsigned blocksize = decoder->get_blocksize(); - /* value could be anything since we're at the last block, so accept any answer */ - printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED"); - if(blocksize == 0) - return false; - } - - printf("testing get_channel_assignment()... "); - { - ::FLAC__ChannelAssignment ca = decoder->get_channel_assignment(); - printf("returned %u (%s)... OK\n", (unsigned)ca, ::FLAC__ChannelAssignmentString[ca]); - } - - if(layer < LAYER_FILE) { - printf("testing reset()... "); - if(!decoder->reset()) - return die_s_("returned false", decoder); - printf("OK\n"); - - if(layer == LAYER_STREAM) { - /* after a reset() we have to rewind the input ourselves */ - printf("rewinding input... "); - if(fseeko(dynamic_cast<StreamDecoder*>(decoder)->file_, 0, SEEK_SET) < 0) { - printf("FAILED, errno = %d\n", errno); - return false; - } - printf("OK\n"); - } - - dynamic_cast<DecoderCommon*>(decoder)->current_metadata_number_ = 0; - - printf("testing process_until_end_of_stream()... "); - if(!decoder->process_until_end_of_stream()) - return die_s_("returned false", decoder); - printf("OK\n"); - } - - printf("testing finish()... "); - decoder->finish(); - printf("OK\n"); - - /* - * respond all - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * ignore all - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * respond all, ignore VORBIS_COMMENT - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore(VORBIS_COMMENT)... "); - if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * respond all, ignore APPLICATION - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore(APPLICATION)... "); - if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * respond all, ignore APPLICATION id of app#1 - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore_application(of app block #1)... "); - if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * respond all, ignore APPLICATION id of app#1 & app#2 - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore_application(of app block #1)... "); - if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore_application(of app block #2)... "); - if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * ignore all, respond VORBIS_COMMENT - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond(VORBIS_COMMENT)... "); - if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * ignore all, respond APPLICATION - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond(APPLICATION)... "); - if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * ignore all, respond APPLICATION id of app#1 - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond_application(of app block #1)... "); - if(!decoder->set_metadata_respond_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * ignore all, respond APPLICATION id of app#1 & app#2 - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond_application(of app block #1)... "); - if(!decoder->set_metadata_respond_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond_application(of app block #2)... "); - if(!decoder->set_metadata_respond_application(application2_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * respond all, ignore APPLICATION, respond APPLICATION id of app#1 - */ - - printf("testing set_metadata_respond_all()... "); - if(!decoder->set_metadata_respond_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore(APPLICATION)... "); - if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond_application(of app block #1)... "); - if(!decoder->set_metadata_respond_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - /* - * ignore all, respond APPLICATION, ignore APPLICATION id of app#1 - */ - - printf("testing set_metadata_ignore_all()... "); - if(!decoder->set_metadata_ignore_all()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_respond(APPLICATION)... "); - if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_metadata_ignore_application(of app block #1)... "); - if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!(layer < LAYER_FILE? dynamic_cast<StreamDecoder*>(decoder)->test_respond() : dynamic_cast<FileDecoder*>(decoder)->test_respond())) - return false; - - if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */ - ::fclose(dynamic_cast<StreamDecoder*>(decoder)->file_); - - printf("freeing decoder instance... "); - delete decoder; - printf("OK\n"); - - printf("\nPASSED!\n"); - - return true; -} - -bool test_decoders() -{ - init_metadata_blocks_(); - - if(!generate_file_()) - return false; - - if(!test_stream_decoder(LAYER_STREAM)) - return false; - - if(!test_stream_decoder(LAYER_SEEKABLE_STREAM)) - return false; - - if(!test_stream_decoder(LAYER_FILE)) - return false; - - if(!test_stream_decoder(LAYER_FILENAME)) - return false; - - (void) grabbag__file_remove_file(flacfilename_); - - free_metadata_blocks_(); - - return true; -} diff --git a/src/test_libOggFLAC++/decoders.h b/src/test_libOggFLAC++/decoders.h deleted file mode 100644 index e5be4683..00000000 --- a/src/test_libOggFLAC++/decoders.h +++ /dev/null @@ -1,24 +0,0 @@ -/* test_libOggFLAC++ - Unit tester for libOggFLAC++ - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef OggFLAC__TEST_LIBOGGFLACPP_DECODERS_H -#define OggFLAC__TEST_LIBOGGFLACPP_DECODERS_H - -bool test_decoders(); - -#endif diff --git a/src/test_libOggFLAC++/encoders.cpp b/src/test_libOggFLAC++/encoders.cpp deleted file mode 100644 index ce91c8ec..00000000 --- a/src/test_libOggFLAC++/encoders.cpp +++ /dev/null @@ -1,499 +0,0 @@ -/* test_libOggFLAC++ - Unit tester for libOggFLAC++ - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "encoders.h" -#include "FLAC/assert.h" -#include "OggFLAC++/encoder.h" -extern "C" { -#include "test_libs_common/file_utils_oggflac.h" -#include "test_libs_common/metadata_utils.h" -} -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_encoder_init_stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_stream() with seeking */ - LAYER_FILE, /* FLAC__stream_encoder_init_FILE() */ - LAYER_FILENAME /* FLAC__stream_encoder_init_file() */ -} Layer; - -static const char * const LayerString[] = { - "Stream", - "Seekable Stream", - "FILE*", - "Filename" -}; - -static ::FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static ::FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ }; -static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]); -static const char *flacfilename_ = "metadata.ogg"; - -static FLAC__bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static bool die_s_(const char *msg, const OggFLAC::Encoder::Stream *encoder) -{ - OggFLAC::Encoder::Stream::State state = encoder->get_state(); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (unsigned)((::OggFLAC__StreamEncoderState)state), state.as_cstring()); - if(state == ::OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) { - FLAC::Encoder::Stream::State state_ = encoder->get_FLAC_stream_encoder_state(); - printf(", state = %u (%s)\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring()); - if(state_ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) { - FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state(); - printf(" verify decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring()); - } - } - - return false; -} - -static void init_metadata_blocks_() -{ - mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static void free_metadata_blocks_() -{ - mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -class StreamEncoder : public OggFLAC::Encoder::Stream { -public: - Layer layer_; - - StreamEncoder(Layer layer): OggFLAC::Encoder::Stream(), layer_(layer) { } - ~StreamEncoder() { } - - // from OggFLAC::Encoder::Stream - ::OggFLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes); - ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame); - ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset); - ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset); - void metadata_callback(const ::FLAC__StreamMetadata *metadata); -}; - -::OggFLAC__StreamEncoderReadStatus StreamEncoder::read_callback(FLAC__byte buffer[], unsigned *bytes) -{ - (void)buffer, (void)bytes; - - return ::OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; -} - -::FLAC__StreamEncoderWriteStatus StreamEncoder::write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) -{ - (void)buffer, (void)bytes, (void)samples, (void)current_frame; - - return ::FLAC__STREAM_ENCODER_WRITE_STATUS_OK; -} - -::FLAC__StreamEncoderSeekStatus StreamEncoder::seek_callback(FLAC__uint64 absolute_byte_offset) -{ - (void)absolute_byte_offset; - - return layer_==LAYER_STREAM? ::FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED : ::FLAC__STREAM_ENCODER_SEEK_STATUS_OK; -} - -::FLAC__StreamEncoderTellStatus StreamEncoder::tell_callback(FLAC__uint64 *absolute_byte_offset) -{ - *absolute_byte_offset = 0; - - return layer_==LAYER_STREAM? ::FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED : ::FLAC__STREAM_ENCODER_TELL_STATUS_OK; -} - -void StreamEncoder::metadata_callback(const ::FLAC__StreamMetadata *metadata) -{ - (void)metadata; -} - -class FileEncoder : public OggFLAC::Encoder::File { -public: - Layer layer_; - - FileEncoder(Layer layer): OggFLAC::Encoder::File(), layer_(layer) { } - ~FileEncoder() { } - - // from OggFLAC::Encoder::File - void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate); -}; - -void FileEncoder::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate) -{ - (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate; -} - -static OggFLAC::Encoder::Stream *new_by_layer(Layer layer) -{ - if(layer < LAYER_FILE) - return new StreamEncoder(layer); - else - return new FileEncoder(layer); -} - -static bool test_stream_encoder(Layer layer) -{ - OggFLAC::Encoder::Stream *encoder; - FILE *file = 0; - FLAC__int32 samples[1024]; - FLAC__int32 *samples_array[1] = { samples }; - unsigned i; - - printf("\n+++ libOggFLAC++ unit test: OggFLAC::Encoder::%s (layer: %s)\n\n", layer<LAYER_FILE? "Stream":"File", LayerString[layer]); - - printf("allocating encoder instance... "); - encoder = new_by_layer(layer); - if(0 == encoder) { - printf("FAILED, new returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing is_valid()... "); - if(!encoder->is_valid()) { - printf("FAILED, returned false\n"); - return false; - } - printf("OK\n"); - - printf("testing set_serial_number()... "); - if(!encoder->set_serial_number(file_utils__serial_number)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_verify()... "); - if(!encoder->set_verify(true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_streamable_subset()... "); - if(!encoder->set_streamable_subset(true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_do_mid_side_stereo()... "); - if(!encoder->set_do_mid_side_stereo(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_loose_mid_side_stereo()... "); - if(!encoder->set_loose_mid_side_stereo(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_channels()... "); - if(!encoder->set_channels(streaminfo_.data.stream_info.channels)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_bits_per_sample()... "); - if(!encoder->set_bits_per_sample(streaminfo_.data.stream_info.bits_per_sample)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_sample_rate()... "); - if(!encoder->set_sample_rate(streaminfo_.data.stream_info.sample_rate)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_blocksize()... "); - if(!encoder->set_blocksize(streaminfo_.data.stream_info.min_blocksize)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_max_lpc_order()... "); - if(!encoder->set_max_lpc_order(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_qlp_coeff_precision()... "); - if(!encoder->set_qlp_coeff_precision(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_do_qlp_coeff_prec_search()... "); - if(!encoder->set_do_qlp_coeff_prec_search(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_do_escape_coding()... "); - if(!encoder->set_do_escape_coding(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_do_exhaustive_model_search()... "); - if(!encoder->set_do_exhaustive_model_search(false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_min_residual_partition_order()... "); - if(!encoder->set_min_residual_partition_order(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_max_residual_partition_order()... "); - if(!encoder->set_max_residual_partition_order(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_rice_parameter_search_dist()... "); - if(!encoder->set_rice_parameter_search_dist(0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_total_samples_estimate()... "); - if(!encoder->set_total_samples_estimate(streaminfo_.data.stream_info.total_samples)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing set_metadata()... "); - if(!encoder->set_metadata(metadata_sequence_, num_metadata_)) - return die_s_("returned false", encoder); - printf("OK\n"); - - switch(layer) { - case LAYER_STREAM: - case LAYER_SEEKABLE_STREAM: - printf("testing init()... "); - if(encoder->init() != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); - break; - case LAYER_FILE: - printf("opening file for Ogg FLAC output... "); - file = ::fopen(flacfilename_, "w+b"); - if(0 == file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - - printf("testing init()... "); - if(dynamic_cast<OggFLAC::Encoder::File*>(encoder)->init(file) != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); - break; - case LAYER_FILENAME: - printf("testing init()... "); - if(dynamic_cast<OggFLAC::Encoder::File*>(encoder)->init(flacfilename_) != ::FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); - break; - default: - die_("internal error 001"); - return false; - } - printf("OK\n"); - - printf("testing get_state()... "); - OggFLAC::Encoder::Stream::State state = encoder->get_state(); - printf("returned state = %u (%s)... OK\n", (unsigned)((::OggFLAC__StreamEncoderState)state), state.as_cstring()); - - printf("testing get_FLAC_stream_encoder_state()... "); - FLAC::Encoder::Stream::State state_ = encoder->get_FLAC_stream_encoder_state(); - printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamEncoderState)state_), state_.as_cstring()); - - printf("testing get_verify_decoder_state()... "); - FLAC::Decoder::Stream::State dstate = encoder->get_verify_decoder_state(); - printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)dstate), dstate.as_cstring()); - - { - FLAC__uint64 absolute_sample; - unsigned frame_number; - unsigned channel; - unsigned sample; - FLAC__int32 expected; - FLAC__int32 got; - - printf("testing get_verify_decoder_error_stats()... "); - encoder->get_verify_decoder_error_stats(&absolute_sample, &frame_number, &channel, &sample, &expected, &got); - printf("OK\n"); - } - - printf("testing get_verify()... "); - if(encoder->get_verify() != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - printf("OK\n"); - - printf("testing get_streamable_subset()... "); - if(encoder->get_streamable_subset() != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - printf("OK\n"); - - printf("testing get_do_mid_side_stereo()... "); - if(encoder->get_do_mid_side_stereo() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_loose_mid_side_stereo()... "); - if(encoder->get_loose_mid_side_stereo() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_channels()... "); - if(encoder->get_channels() != streaminfo_.data.stream_info.channels) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, encoder->get_channels()); - return false; - } - printf("OK\n"); - - printf("testing get_bits_per_sample()... "); - if(encoder->get_bits_per_sample() != streaminfo_.data.stream_info.bits_per_sample) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, encoder->get_bits_per_sample()); - return false; - } - printf("OK\n"); - - printf("testing get_sample_rate()... "); - if(encoder->get_sample_rate() != streaminfo_.data.stream_info.sample_rate) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, encoder->get_sample_rate()); - return false; - } - printf("OK\n"); - - printf("testing get_blocksize()... "); - if(encoder->get_blocksize() != streaminfo_.data.stream_info.min_blocksize) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, encoder->get_blocksize()); - return false; - } - printf("OK\n"); - - printf("testing get_max_lpc_order()... "); - if(encoder->get_max_lpc_order() != 0) { - printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_lpc_order()); - return false; - } - printf("OK\n"); - - printf("testing get_qlp_coeff_precision()... "); - (void)encoder->get_qlp_coeff_precision(); - /* we asked the encoder to auto select this so we accept anything */ - printf("OK\n"); - - printf("testing get_do_qlp_coeff_prec_search()... "); - if(encoder->get_do_qlp_coeff_prec_search() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_do_escape_coding()... "); - if(encoder->get_do_escape_coding() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_do_exhaustive_model_search()... "); - if(encoder->get_do_exhaustive_model_search() != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing get_min_residual_partition_order()... "); - if(encoder->get_min_residual_partition_order() != 0) { - printf("FAILED, expected %u, got %u\n", 0, encoder->get_min_residual_partition_order()); - return false; - } - printf("OK\n"); - - printf("testing get_max_residual_partition_order()... "); - if(encoder->get_max_residual_partition_order() != 0) { - printf("FAILED, expected %u, got %u\n", 0, encoder->get_max_residual_partition_order()); - return false; - } - printf("OK\n"); - - printf("testing get_rice_parameter_search_dist()... "); - if(encoder->get_rice_parameter_search_dist() != 0) { - printf("FAILED, expected %u, got %u\n", 0, encoder->get_rice_parameter_search_dist()); - return false; - } - printf("OK\n"); - - printf("testing get_total_samples_estimate()... "); - if(encoder->get_total_samples_estimate() != streaminfo_.data.stream_info.total_samples) { - printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, encoder->get_total_samples_estimate()); - return false; - } - printf("OK\n"); - - /* init the dummy sample buffer */ - for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++) - samples[i] = i & 7; - - printf("testing process()... "); - if(!encoder->process(samples_array, sizeof(samples) / sizeof(FLAC__int32))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing process_interleaved()... "); - if(!encoder->process_interleaved(samples, sizeof(samples) / sizeof(FLAC__int32))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing finish()... "); - encoder->finish(); - printf("OK\n"); - - printf("freeing encoder instance... "); - delete encoder; - printf("OK\n"); - - printf("\nPASSED!\n"); - - return true; -} - -bool test_encoders() -{ - init_metadata_blocks_(); - - if(!test_stream_encoder(LAYER_STREAM)) - return false; - - if(!test_stream_encoder(LAYER_SEEKABLE_STREAM)) - return false; - - if(!test_stream_encoder(LAYER_FILE)) - return false; - - if(!test_stream_encoder(LAYER_FILENAME)) - return false; - - free_metadata_blocks_(); - - return true; -} diff --git a/src/test_libOggFLAC++/encoders.h b/src/test_libOggFLAC++/encoders.h deleted file mode 100644 index dd7e94b0..00000000 --- a/src/test_libOggFLAC++/encoders.h +++ /dev/null @@ -1,24 +0,0 @@ -/* test_libOggFLAC++ - Unit tester for libOggFLAC++ - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef OggFLAC__TEST_LIBOGGFLACPP_ENCODERS_H -#define OggFLAC__TEST_LIBOGGFLACPP_ENCODERS_H - -bool test_encoders(); - -#endif diff --git a/src/test_libOggFLAC++/main.cpp b/src/test_libOggFLAC++/main.cpp deleted file mode 100644 index dbdfed98..00000000 --- a/src/test_libOggFLAC++/main.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* test_libOggFLAC++ - Unit tester for libOggFLAC++ - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "decoders.h" -#include "encoders.h" - -int main(int argc, char *argv[]) -{ - (void)argc, (void)argv; - - if(!test_encoders()) - return 1; - - if(!test_decoders()) - return 1; - - return 0; -} diff --git a/src/test_libOggFLAC++/test_libOggFLAC++.dsp b/src/test_libOggFLAC++/test_libOggFLAC++.dsp deleted file mode 100644 index 63c458aa..00000000 --- a/src/test_libOggFLAC++/test_libOggFLAC++.dsp +++ /dev/null @@ -1,120 +0,0 @@ -# Microsoft Developer Studio Project File - Name="test_libOggFLAC++" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=test_libOggFLAC++ - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "test_libOggFLAC++.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "test_libOggFLAC++.mak" CFG="test_libOggFLAC++ - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "test_libOggFLAC++ - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "test_libOggFLAC++ - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "test_libOggFLAC++ - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\obj\release\bin"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
-# ADD CPP /nologo /MD /W3 /GR /GX /O2 /I "..\..\include" /D "NDEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c
-# SUBTRACT CPP /YX /Yc /Yu
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\test_libs_common_static.lib ..\..\obj\release\lib\libOggFLAC++_static.lib ..\..\obj\release\lib\libOggFLAC_static.lib ..\..\obj\release\lib\libFLAC++_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "test_libOggFLAC++ - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\obj\debug\bin"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GR /GX /ZI /Od /I "..\..\include" /D "_DEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
-# SUBTRACT CPP /YX /Yc /Yu
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\test_libs_common_static.lib ..\..\obj\debug\lib\libOggFLAC++_static.lib ..\..\obj\debug\lib\libOggFLAC_static.lib ..\..\obj\debug\lib\libFLAC++_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "test_libOggFLAC++ - Win32 Release"
-# Name "test_libOggFLAC++ - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\decoders.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\encoders.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\main.cpp
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\decoders.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\encoders.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\README
-# End Source File
-# End Target
-# End Project
diff --git a/src/test_libOggFLAC/Makefile.am b/src/test_libOggFLAC/Makefile.am deleted file mode 100644 index 52bd1315..00000000 --- a/src/test_libOggFLAC/Makefile.am +++ /dev/null @@ -1,40 +0,0 @@ -# test_libOggFLAC - Unit tester for libOggFLAC -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -EXTRA_DIST = \ - Makefile.lite \ - test_libOggFLAC.dsp - -AM_CFLAGS = @OGG_CFLAGS@ - -INCLUDES = - -noinst_PROGRAMS = test_libOggFLAC -test_libOggFLAC_LDADD = \ - $(top_builddir)/src/share/grabbag/libgrabbag.la \ - $(top_builddir)/src/share/replaygain_analysis/libreplaygain_analysis.la \ - $(top_builddir)/src/test_libs_common/libtest_libs_common.la \ - $(top_builddir)/src/libOggFLAC/libOggFLAC.la \ - $(top_builddir)/src/libFLAC/libFLAC.la \ - @OGG_LIBS@ \ - -lm -test_libOggFLAC_SOURCES = \ - decoders.c \ - encoders.c \ - main.c \ - decoders.h \ - encoders.h diff --git a/src/test_libOggFLAC/Makefile.lite b/src/test_libOggFLAC/Makefile.lite deleted file mode 100644 index edc462f4..00000000 --- a/src/test_libOggFLAC/Makefile.lite +++ /dev/null @@ -1,42 +0,0 @@ -# test_libOggFLAC - Unit tester for libOggFLAC -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -# -# GNU makefile -# - -topdir = ../.. -libdir = $(topdir)/obj/$(BUILD)/lib - -PROGRAM_NAME = test_libOggFLAC - -INCLUDES = -I$(topdir)/include - -ifeq ($(DARWIN_BUILD),yes) -EXPLICIT_LIBS = $(libdir)/libgrabbag.a $(libdir)/libreplaygain_analysis.a $(libdir)/libtest_libs_common.a $(libdir)/libOggFLAC.a $(libdir)/libFLAC.a $(OGG_LIB_DIR)/libogg.a -lm -else -LIBS = -lgrabbag -lreplaygain_analysis -ltest_libs_common -lOggFLAC -lFLAC -L$(OGG_LIB_DIR) -logg -lm -endif - -SRCS_C = \ - decoders.c \ - encoders.c \ - main.c - -include $(topdir)/build/exe.mk - -# DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/src/test_libOggFLAC/decoders.c b/src/test_libOggFLAC/decoders.c deleted file mode 100644 index 05b0eb96..00000000 --- a/src/test_libOggFLAC/decoders.c +++ /dev/null @@ -1,957 +0,0 @@ -/* test_libOggFLAC - Unit tester for libOggFLAC - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#if defined _MSC_VER || defined __MINGW32__ -#if _MSC_VER <= 1200 /* @@@ [2G limit] */ -#define fseeko fseek -#define ftello ftell -#endif -#endif -#include "decoders.h" -#include "FLAC/assert.h" -#include "OggFLAC/stream_decoder.h" -#include "share/grabbag.h" -#include "test_libs_common/file_utils_oggflac.h" -#include "test_libs_common/metadata_utils.h" - -//@@@@@@ this is almost exactly like test_libFLAC/decoders.c, maybe should consolidate some stuff like client data and callbacks -typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_decoder_init_stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_decoder_init_stream() with seeking */ - LAYER_FILE, /* FLAC__stream_decoder_init_FILE() */ - LAYER_FILENAME /* FLAC__stream_decoder_init_file() */ -} Layer; - -static const char * const LayerString[] = { - "Stream", - "Seekable Stream", - "FILE*", - "Filename" -}; - -typedef struct { - Layer layer; - FILE *file; - unsigned current_metadata_number; - FLAC__bool ignore_errors; - FLAC__bool error_occurred; -} StreamDecoderClientData; - -static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static FLAC__StreamMetadata *expected_metadata_sequence_[9]; -static unsigned num_expected_; -static const char *flacfilename_ = "metadata.ogg"; -static off_t flacfilesize_; - -static FLAC__bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static FLAC__bool die_s_(const char *msg, const OggFLAC__StreamDecoder *decoder) -{ - OggFLAC__StreamDecoderState state = OggFLAC__stream_decoder_get_state(decoder); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__StreamDecoderStateString[state]); - if(state == OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) { - FLAC__StreamDecoderState state_ = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder); - printf(" FLAC stream decoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamDecoderStateString[state_]); - } - - return false; -} - -static void init_metadata_blocks_() -{ - mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static void free_metadata_blocks_() -{ - mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static FLAC__bool generate_file_() -{ - printf("\n\ngenerating Ogg FLAC file for decoder tests...\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - /* WATCHOUT: the encoder should move the VORBIS_COMMENT block to the front, right after STREAMINFO */ - - if(!file_utils__generate_oggflacfile(flacfilename_, &flacfilesize_, 512 * 1024, &streaminfo_, expected_metadata_sequence_, num_expected_)) - return die_("creating the encoded file"); - - return true; -} - -static FLAC__StreamDecoderReadStatus stream_decoder_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - const unsigned requested_bytes = *bytes; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in read callback is NULL\n"); - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - - if(feof(dcd->file)) { - *bytes = 0; - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - } - else if(requested_bytes > 0) { - *bytes = fread(buffer, 1, requested_bytes, dcd->file); - if(*bytes == 0) { - if(feof(dcd->file)) - return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; - else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; - } - else { - return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; - } - } - else - return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */ -} - -static FLAC__StreamDecoderSeekStatus stream_decoder_seek_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in seek callback is NULL\n"); - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - - if(fseeko(dcd->file, (off_t)absolute_byte_offset, SEEK_SET) < 0) { - dcd->error_occurred = true; - return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; - } - - return FLAC__STREAM_DECODER_SEEK_STATUS_OK; -} - -static FLAC__StreamDecoderTellStatus stream_decoder_tell_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - off_t offset; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in tell callback is NULL\n"); - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - - offset = ftello(dcd->file); - *absolute_byte_offset = (FLAC__uint64)offset; - - if(offset < 0) { - dcd->error_occurred = true; - return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; - } - - return FLAC__STREAM_DECODER_TELL_STATUS_OK; -} - -static FLAC__StreamDecoderLengthStatus stream_decoder_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in length callback is NULL\n"); - return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; - - *stream_length = (FLAC__uint64)flacfilesize_; - return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; -} - -static FLAC__bool stream_decoder_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in eof callback is NULL\n"); - return true; - } - - if(dcd->error_occurred) - return true; - - return feof(dcd->file); -} - -static FLAC__StreamDecoderWriteStatus stream_decoder_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder, (void)buffer; - - if(0 == dcd) { - printf("ERROR: client_data in write callback is NULL\n"); - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - } - - if(dcd->error_occurred) - return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; - - if( - (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER && frame->header.number.frame_number == 0) || - (frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER && frame->header.number.sample_number == 0) - ) { - printf("content... "); - fflush(stdout); - } - - return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; -} - -static void stream_decoder_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in metadata callback is NULL\n"); - return; - } - - if(dcd->error_occurred) - return; - - printf("%d... ", dcd->current_metadata_number); - fflush(stdout); - - if(dcd->current_metadata_number >= num_expected_) { - (void)die_("got more metadata blocks than expected"); - dcd->error_occurred = true; - } - else { - if(!mutils__compare_block(expected_metadata_sequence_[dcd->current_metadata_number], metadata)) { - (void)die_("metadata block mismatch"); - dcd->error_occurred = true; - } - } - dcd->current_metadata_number++; -} - -static void stream_decoder_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) -{ - StreamDecoderClientData *dcd = (StreamDecoderClientData*)client_data; - - (void)decoder; - - if(0 == dcd) { - printf("ERROR: client_data in error callback is NULL\n"); - return; - } - - if(!dcd->ignore_errors) { - printf("ERROR: got error callback: err = %u (%s)\n", (unsigned)status, FLAC__StreamDecoderErrorStatusString[status]); - dcd->error_occurred = true; - } -} - -static FLAC__bool stream_decoder_test_respond_(OggFLAC__StreamDecoder *decoder, StreamDecoderClientData *dcd) -{ - FLAC__StreamDecoderInitStatus init_status; - - if(!OggFLAC__stream_decoder_set_md5_checking(decoder, true)) - return die_s_("at OggFLAC__stream_decoder_set_md5_checking(), returned false", decoder); - - /* for OggFLAC__stream_encoder_init_FILE(), the OggFLAC__stream_encoder_finish() closes the file so we have to keep re-opening: */ - if(dcd->layer == LAYER_FILE) { - printf("opening Ogg FLAC file... "); - dcd->file = fopen(flacfilename_, "rb"); - if(0 == dcd->file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - } - - printf("testing OggFLAC__stream_decoder_init_stream()... "); - switch(dcd->layer) { - case LAYER_STREAM: - init_status = OggFLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); - break; - case LAYER_SEEKABLE_STREAM: - init_status = OggFLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); - break; - case LAYER_FILE: - init_status = OggFLAC__stream_decoder_init_FILE(decoder, dcd->file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); - break; - case LAYER_FILENAME: - init_status = OggFLAC__stream_decoder_init_file(decoder, flacfilename_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, dcd); - break; - default: - die_("internal error 000"); - return false; - } - if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - printf("OK\n"); - - dcd->current_metadata_number = 0; - - if(dcd->layer < LAYER_FILE && fseeko(dcd->file, 0, SEEK_SET) < 0) { - printf("FAILED rewinding input, errno = %d\n", errno); - return false; - } - - printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... "); - if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_finish()... "); - OggFLAC__stream_decoder_finish(decoder); - printf("OK\n"); - - return true; -} - -static FLAC__bool test_stream_decoder(Layer layer) -{ - OggFLAC__StreamDecoder *decoder; - OggFLAC__StreamDecoderState state; - FLAC__StreamDecoderState fstate; - StreamDecoderClientData decoder_client_data; - FLAC__bool expect; - - decoder_client_data.layer = layer; - - printf("\n+++ libOggFLAC unit test: OggFLAC__StreamDecoder (layer: %s)\n\n", LayerString[layer]); - - printf("testing OggFLAC__stream_decoder_new()... "); - decoder = OggFLAC__stream_decoder_new(); - if(0 == decoder) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_delete()... "); - OggFLAC__stream_decoder_delete(decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_new()... "); - decoder = OggFLAC__stream_decoder_new(); - if(0 == decoder) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - switch(layer) { - case LAYER_STREAM: - case LAYER_SEEKABLE_STREAM: - printf("testing OggFLAC__stream_decoder_init_stream()... "); - if(OggFLAC__stream_decoder_init_stream(decoder, 0, 0, 0, 0, 0, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS) - return die_s_(0, decoder); - break; - case LAYER_FILE: - printf("testing OggFLAC__stream_decoder_init_FILE()... "); - if(OggFLAC__stream_decoder_init_FILE(decoder, stdin, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS) - return die_s_(0, decoder); - break; - case LAYER_FILENAME: - printf("testing OggFLAC__stream_decoder_init_file()... "); - if(OggFLAC__stream_decoder_init_file(decoder, flacfilename_, 0, 0, 0, 0) != FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS) - return die_s_(0, decoder); - break; - default: - die_("internal error 003"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_delete()... "); - OggFLAC__stream_decoder_delete(decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - - printf("testing OggFLAC__stream_decoder_new()... "); - decoder = OggFLAC__stream_decoder_new(); - if(0 == decoder) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_serial_number()... "); - if(!OggFLAC__stream_decoder_set_serial_number(decoder, file_utils__serial_number)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_md5_checking()... "); - if(!OggFLAC__stream_decoder_set_md5_checking(decoder, true)) - return die_s_("returned false", decoder); - printf("OK\n"); - - if(layer < LAYER_FILENAME) { - printf("opening Ogg FLAC file... "); - decoder_client_data.file = fopen(flacfilename_, "rb"); - if(0 == decoder_client_data.file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - } - - switch(layer) { - case LAYER_STREAM: - printf("testing OggFLAC__stream_decoder_init_stream()... "); - if(OggFLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - break; - case LAYER_SEEKABLE_STREAM: - printf("testing OggFLAC__stream_decoder_init_stream()... "); - if(OggFLAC__stream_decoder_init_stream(decoder, stream_decoder_read_callback_, stream_decoder_seek_callback_, stream_decoder_tell_callback_, stream_decoder_length_callback_, stream_decoder_eof_callback_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - break; - case LAYER_FILE: - printf("testing OggFLAC__stream_decoder_init_FILE()... "); - if(OggFLAC__stream_decoder_init_FILE(decoder, decoder_client_data.file, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - break; - case LAYER_FILENAME: - printf("testing OggFLAC__stream_decoder_init_file()... "); - if(OggFLAC__stream_decoder_init_file(decoder, flacfilename_, stream_decoder_write_callback_, stream_decoder_metadata_callback_, stream_decoder_error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_(0, decoder); - break; - default: - die_("internal error 009"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_get_state()... "); - state = OggFLAC__stream_decoder_get_state(decoder); - printf("returned state = %u (%s)... OK\n", state, OggFLAC__StreamDecoderStateString[state]); - - printf("testing OggFLAC__stream_decoder_get_FLAC_stream_decoder_state()... "); - fstate = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder); - printf("returned state = %u (%s)... OK\n", fstate, FLAC__StreamDecoderStateString[fstate]); - - decoder_client_data.current_metadata_number = 0; - decoder_client_data.ignore_errors = false; - decoder_client_data.error_occurred = false; - - printf("testing OggFLAC__stream_decoder_get_md5_checking()... "); - if(!OggFLAC__stream_decoder_get_md5_checking(decoder)) { - printf("FAILED, returned false, expected true\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_process_until_end_of_metadata()... "); - if(!OggFLAC__stream_decoder_process_until_end_of_metadata(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_process_single()... "); - if(!OggFLAC__stream_decoder_process_single(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_skip_single_frame()... "); - if(!OggFLAC__stream_decoder_skip_single_frame(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - if(layer < LAYER_FILE) { - printf("testing OggFLAC__stream_decoder_flush()... "); - if(!OggFLAC__stream_decoder_flush(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - decoder_client_data.ignore_errors = true; - printf("testing OggFLAC__stream_decoder_process_single()... "); - if(!OggFLAC__stream_decoder_process_single(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - decoder_client_data.ignore_errors = false; - } - - expect = (layer != LAYER_STREAM); - printf("testing OggFLAC__stream_decoder_seek_absolute()... "); - if(OggFLAC__stream_decoder_seek_absolute(decoder, 0) != expect) - return die_s_(expect? "returned false" : "returned true", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... "); - if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - expect = (layer != LAYER_STREAM); - printf("testing OggFLAC__stream_decoder_seek_absolute()... "); - if(OggFLAC__stream_decoder_seek_absolute(decoder, 0) != expect) - return die_s_(expect? "returned false" : "returned true", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_get_channels()... "); - { - unsigned channels = OggFLAC__stream_decoder_get_channels(decoder); - if(channels != streaminfo_.data.stream_info.channels) { - printf("FAILED, returned %u, expected %u\n", channels, streaminfo_.data.stream_info.channels); - return false; - } - } - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_get_bits_per_sample()... "); - { - unsigned bits_per_sample = OggFLAC__stream_decoder_get_bits_per_sample(decoder); - if(bits_per_sample != streaminfo_.data.stream_info.bits_per_sample) { - printf("FAILED, returned %u, expected %u\n", bits_per_sample, streaminfo_.data.stream_info.bits_per_sample); - return false; - } - } - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_get_sample_rate()... "); - { - unsigned sample_rate = OggFLAC__stream_decoder_get_sample_rate(decoder); - if(sample_rate != streaminfo_.data.stream_info.sample_rate) { - printf("FAILED, returned %u, expected %u\n", sample_rate, streaminfo_.data.stream_info.sample_rate); - return false; - } - } - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_get_blocksize()... "); - { - unsigned blocksize = OggFLAC__stream_decoder_get_blocksize(decoder); - /* value could be anything since we're at the last block, so accept any reasonable answer */ - printf("returned %u... %s\n", blocksize, blocksize>0? "OK" : "FAILED"); - if(blocksize == 0) - return false; - } - - printf("testing OggFLAC__stream_decoder_get_channel_assignment()... "); - { - FLAC__ChannelAssignment ca = OggFLAC__stream_decoder_get_channel_assignment(decoder); - printf("returned %u (%s)... OK\n", (unsigned)ca, FLAC__ChannelAssignmentString[ca]); - } - - if(layer < LAYER_FILE) { - printf("testing OggFLAC__stream_decoder_reset()... "); - if(!OggFLAC__stream_decoder_reset(decoder)) { - state = OggFLAC__stream_decoder_get_state(decoder); - printf("FAILED, returned false, state = %u (%s)\n", state, OggFLAC__StreamDecoderStateString[state]); - return false; - } - printf("OK\n"); - - if(layer == LAYER_STREAM) { - /* after a reset() we have to rewind the input ourselves */ - printf("rewinding input... "); - if(fseeko(decoder_client_data.file, 0, SEEK_SET) < 0) { - printf("FAILED, errno = %d\n", errno); - return false; - } - printf("OK\n"); - } - - decoder_client_data.current_metadata_number = 0; - - printf("testing OggFLAC__stream_decoder_process_until_end_of_stream()... "); - if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - } - - printf("testing OggFLAC__stream_decoder_finish()... "); - (void) OggFLAC__stream_decoder_finish(decoder); - printf("OK\n"); - - /* - * respond all - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * ignore all - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * respond all, ignore VORBIS_COMMENT - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore(VORBIS_COMMENT)... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * respond all, ignore APPLICATION - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * respond all, ignore APPLICATION id of app#1 - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application2_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * respond all, ignore APPLICATION id of app#1 & app#2 - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #2)... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application2_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * ignore all, respond VORBIS_COMMENT - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_respond(VORBIS_COMMENT)... "); - if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * ignore all, respond APPLICATION - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... "); - if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * ignore all, respond APPLICATION id of app#1 - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * ignore all, respond APPLICATION id of app#1 & app#2 - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #2)... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application2_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * respond all, ignore APPLICATION, respond APPLICATION id of app#1 - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore(APPLICATION)... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore(decoder, FLAC__METADATA_TYPE_APPLICATION)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_respond_application(of app block #1)... "); - if(!OggFLAC__stream_decoder_set_metadata_respond_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &streaminfo_; - expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; - expected_metadata_sequence_[num_expected_++] = &padding_; - expected_metadata_sequence_[num_expected_++] = &seektable_; - expected_metadata_sequence_[num_expected_++] = &application1_; - expected_metadata_sequence_[num_expected_++] = &cuesheet_; - expected_metadata_sequence_[num_expected_++] = &picture_; - expected_metadata_sequence_[num_expected_++] = &unknown_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - /* - * ignore all, respond APPLICATION, ignore APPLICATION id of app#1 - */ - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_all()... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_all(decoder)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_respond(APPLICATION)... "); - if(!OggFLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_APPLICATION)) - return die_s_("returned false", decoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_decoder_set_metadata_ignore_application(of app block #1)... "); - if(!OggFLAC__stream_decoder_set_metadata_ignore_application(decoder, application1_.data.application.id)) - return die_s_("returned false", decoder); - printf("OK\n"); - - num_expected_ = 0; - expected_metadata_sequence_[num_expected_++] = &application2_; - - if(!stream_decoder_test_respond_(decoder, &decoder_client_data)) - return false; - - if(layer < LAYER_FILE) /* for LAYER_FILE, FLAC__stream_decoder_finish() closes the file */ - fclose(decoder_client_data.file); - - printf("testing OggFLAC__stream_decoder_delete()... "); - OggFLAC__stream_decoder_delete(decoder); - printf("OK\n"); - - printf("\nPASSED!\n"); - - return true; -} - -FLAC__bool test_decoders() -{ - init_metadata_blocks_(); - if(!generate_file_()) - return false; - - if(!test_stream_decoder(LAYER_STREAM)) - return false; - - if(!test_stream_decoder(LAYER_SEEKABLE_STREAM)) - return false; - - if(!test_stream_decoder(LAYER_FILE)) - return false; - - if(!test_stream_decoder(LAYER_FILENAME)) - return false; - - (void) grabbag__file_remove_file(flacfilename_); - free_metadata_blocks_(); - - return true; -} diff --git a/src/test_libOggFLAC/decoders.h b/src/test_libOggFLAC/decoders.h deleted file mode 100644 index 73ce380e..00000000 --- a/src/test_libOggFLAC/decoders.h +++ /dev/null @@ -1,26 +0,0 @@ -/* test_libOggFLAC - Unit tester for libOggFLAC - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef OggFLAC__TEST_LIBOGGFLAC_DECODERS_H -#define OggFLAC__TEST_LIBOGGFLAC_DECODERS_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_decoders(); - -#endif diff --git a/src/test_libOggFLAC/encoders.c b/src/test_libOggFLAC/encoders.c deleted file mode 100644 index d7701a5d..00000000 --- a/src/test_libOggFLAC/encoders.c +++ /dev/null @@ -1,469 +0,0 @@ -/* test_libOggFLAC - Unit tester for libOggFLAC - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "encoders.h" -#include "FLAC/assert.h" -#include "OggFLAC/stream_encoder.h" -#include "share/grabbag.h" -#include "test_libs_common/file_utils_oggflac.h" -#include "test_libs_common/metadata_utils.h" - -typedef enum { - LAYER_STREAM = 0, /* FLAC__stream_encoder_init_stream() without seeking */ - LAYER_SEEKABLE_STREAM, /* FLAC__stream_encoder_init_stream() with seeking */ - LAYER_FILE, /* FLAC__stream_encoder_init_FILE() */ - LAYER_FILENAME /* FLAC__stream_encoder_init_file() */ -} Layer; - -static const char * const LayerString[] = { - "Stream", - "Seekable Stream", - "FILE*", - "Filename" -}; - -static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, picture_, unknown_; -static FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &picture_, &unknown_ }; -static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]); -static const char *flacfilename_ = "metadata.ogg"; - -static FLAC__bool die_(const char *msg) -{ - printf("ERROR: %s\n", msg); - return false; -} - -static FLAC__bool die_s_(const char *msg, const OggFLAC__StreamEncoder *encoder) -{ - OggFLAC__StreamEncoderState state = OggFLAC__stream_encoder_get_state(encoder); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__StreamEncoderStateString[state]); - if(state == OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) { - FLAC__StreamEncoderState state_ = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder); - printf(" FLAC stream encoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]); - if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) { - FLAC__StreamDecoderState dstate = OggFLAC__stream_encoder_get_verify_decoder_state(encoder); - printf(" verify decoder state = %u (%s)\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]); - } - } - - return false; -} - -static void init_metadata_blocks_() -{ - mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static void free_metadata_blocks_() -{ - mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &picture_, &unknown_); -} - -static OggFLAC__StreamEncoderReadStatus stream_encoder_read_callback_(const OggFLAC__StreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data) -{ - (void)encoder, (void)buffer, (void)bytes, (void)client_data; - memset(buffer, 0, *bytes); /* init buffer to avoid valgrind errors */ - return OggFLAC__STREAM_ENCODER_READ_STATUS_CONTINUE; -} - -static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) -{ - (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data; - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; -} - -static FLAC__StreamEncoderSeekStatus stream_encoder_seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data) -{ - (void)encoder, (void)absolute_byte_offset, (void)client_data; - return FLAC__STREAM_ENCODER_SEEK_STATUS_OK; -} - -static FLAC__StreamEncoderTellStatus stream_encoder_tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data) -{ - (void)encoder, (void)client_data; - *absolute_byte_offset = 0; - return FLAC__STREAM_ENCODER_TELL_STATUS_OK; -} - -static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - (void)encoder, (void)metadata, (void)client_data; -} - -static void stream_encoder_progress_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data) -{ - (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data; -} - -static FLAC__bool test_stream_encoder(Layer layer) -{ - OggFLAC__StreamEncoder *encoder; - OggFLAC__StreamEncoderState state; - FLAC__StreamEncoderState fstate; - FLAC__StreamDecoderState dstate; - FILE *file = 0; - FLAC__int32 samples[1024]; - FLAC__int32 *samples_array[1]; - unsigned i; - - samples_array[0] = samples; - - printf("\n+++ libOggFLAC unit test: OggFLAC__StreamEncoder (layer: %s)\n\n", LayerString[layer]); - - printf("testing OggFLAC__stream_encoder_new()... "); - encoder = OggFLAC__stream_encoder_new(); - if(0 == encoder) { - printf("FAILED, returned NULL\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_serial_number()... "); - if(!OggFLAC__stream_encoder_set_serial_number(encoder, file_utils__serial_number)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_verify()... "); - if(!OggFLAC__stream_encoder_set_verify(encoder, true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_streamable_subset()... "); - if(!OggFLAC__stream_encoder_set_streamable_subset(encoder, true)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_do_mid_side_stereo()... "); - if(!OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_loose_mid_side_stereo()... "); - if(!OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_channels()... "); - if(!OggFLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_bits_per_sample()... "); - if(!OggFLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_sample_rate()... "); - if(!OggFLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_blocksize()... "); - if(!OggFLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_max_lpc_order()... "); - if(!OggFLAC__stream_encoder_set_max_lpc_order(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_qlp_coeff_precision()... "); - if(!OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search()... "); - if(!OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_do_escape_coding()... "); - if(!OggFLAC__stream_encoder_set_do_escape_coding(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_do_exhaustive_model_search()... "); - if(!OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_min_residual_partition_order()... "); - if(!OggFLAC__stream_encoder_set_min_residual_partition_order(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_max_residual_partition_order()... "); - if(!OggFLAC__stream_encoder_set_max_residual_partition_order(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_rice_parameter_search_dist()... "); - if(!OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_total_samples_estimate()... "); - if(!OggFLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples)) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_set_metadata()... "); - if(!OggFLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_)) - return die_s_("returned false", encoder); - printf("OK\n"); - - switch(layer) { - case LAYER_STREAM: - printf("testing OggFLAC__stream_encoder_init_stream()... "); - if(OggFLAC__stream_encoder_init_stream(encoder, /*read_callback=*/0, stream_encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, stream_encoder_metadata_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); - break; - case LAYER_SEEKABLE_STREAM: - printf("testing OggFLAC__stream_encoder_init_stream()... "); - if(OggFLAC__stream_encoder_init_stream(encoder, stream_encoder_read_callback_, stream_encoder_write_callback_, stream_encoder_seek_callback_, stream_encoder_tell_callback_, /*metadata_callback=*/0, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); - break; - case LAYER_FILE: - printf("opening file for Ogg FLAC output... "); - file = fopen(flacfilename_, "w+b"); - if(0 == file) { - printf("ERROR (%s)\n", strerror(errno)); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_init_FILE()... "); - if(OggFLAC__stream_encoder_init_FILE(encoder, file, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); - break; - case LAYER_FILENAME: - printf("testing OggFLAC__stream_encoder_init_file()... "); - if(OggFLAC__stream_encoder_init_file(encoder, flacfilename_, stream_encoder_progress_callback_, /*client_data=*/0) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) - return die_s_(0, encoder); - break; - default: - die_("internal error 001"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_state()... "); - state = OggFLAC__stream_encoder_get_state(encoder); - printf("returned state = %u (%s)... OK\n", (unsigned)state, OggFLAC__StreamEncoderStateString[state]); - - printf("testing OggFLAC__stream_encoder_get_FLAC_stream_encoder_state()... "); - fstate = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder); - printf("returned state = %u (%s)... OK\n", (unsigned)fstate, FLAC__StreamEncoderStateString[fstate]); - - printf("testing OggFLAC__stream_encoder_get_verify_decoder_state()... "); - dstate = OggFLAC__stream_encoder_get_verify_decoder_state(encoder); - printf("returned state = %u (%s)... OK\n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]); - - { - FLAC__uint64 absolute_sample; - unsigned frame_number; - unsigned channel; - unsigned sample; - FLAC__int32 expected; - FLAC__int32 got; - - printf("testing OggFLAC__stream_encoder_get_verify_decoder_error_stats()... "); - OggFLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got); - printf("OK\n"); - } - - printf("testing OggFLAC__stream_encoder_get_verify()... "); - if(OggFLAC__stream_encoder_get_verify(encoder) != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_streamable_subset()... "); - if(OggFLAC__stream_encoder_get_streamable_subset(encoder) != true) { - printf("FAILED, expected true, got false\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_do_mid_side_stereo()... "); - if(OggFLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_loose_mid_side_stereo()... "); - if(OggFLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_channels()... "); - if(OggFLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.channels, OggFLAC__stream_encoder_get_channels(encoder)); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_bits_per_sample()... "); - if(OggFLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.bits_per_sample, OggFLAC__stream_encoder_get_bits_per_sample(encoder)); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_sample_rate()... "); - if(OggFLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.sample_rate, OggFLAC__stream_encoder_get_sample_rate(encoder)); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_blocksize()... "); - if(OggFLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) { - printf("FAILED, expected %u, got %u\n", streaminfo_.data.stream_info.min_blocksize, OggFLAC__stream_encoder_get_blocksize(encoder)); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_max_lpc_order()... "); - if(OggFLAC__stream_encoder_get_max_lpc_order(encoder) != 0) { - printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_max_lpc_order(encoder)); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_qlp_coeff_precision()... "); - (void)OggFLAC__stream_encoder_get_qlp_coeff_precision(encoder); - /* we asked the encoder to auto select this so we accept anything */ - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search()... "); - if(OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_do_escape_coding()... "); - if(OggFLAC__stream_encoder_get_do_escape_coding(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_do_exhaustive_model_search()... "); - if(OggFLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) { - printf("FAILED, expected false, got true\n"); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_min_residual_partition_order()... "); - if(OggFLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) { - printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_min_residual_partition_order(encoder)); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_max_residual_partition_order()... "); - if(OggFLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) { - printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_max_residual_partition_order(encoder)); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_rice_parameter_search_dist()... "); - if(OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) { - printf("FAILED, expected %u, got %u\n", 0, OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder)); - return false; - } - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_get_total_samples_estimate()... "); - if(OggFLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) { - printf("FAILED, expected %llu, got %llu\n", streaminfo_.data.stream_info.total_samples, OggFLAC__stream_encoder_get_total_samples_estimate(encoder)); - return false; - } - printf("OK\n"); - - /* init the dummy sample buffer */ - for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++) - samples[i] = i & 7; - - printf("testing OggFLAC__stream_encoder_process()... "); - if(!OggFLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_process_interleaved()... "); - if(!OggFLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32))) - return die_s_("returned false", encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_finish()... "); - OggFLAC__stream_encoder_finish(encoder); - printf("OK\n"); - - printf("testing OggFLAC__stream_encoder_delete()... "); - OggFLAC__stream_encoder_delete(encoder); - printf("OK\n"); - - printf("\nPASSED!\n"); - - return true; -} - -FLAC__bool test_encoders() -{ - init_metadata_blocks_(); - - if(!test_stream_encoder(LAYER_STREAM)) - return false; - - if(!test_stream_encoder(LAYER_SEEKABLE_STREAM)) - return false; - - if(!test_stream_encoder(LAYER_FILE)) - return false; - - if(!test_stream_encoder(LAYER_FILENAME)) - return false; - - (void) grabbag__file_remove_file(flacfilename_); - free_metadata_blocks_(); - - return true; -} diff --git a/src/test_libOggFLAC/encoders.h b/src/test_libOggFLAC/encoders.h deleted file mode 100644 index b2abebd1..00000000 --- a/src/test_libOggFLAC/encoders.h +++ /dev/null @@ -1,26 +0,0 @@ -/* test_libOggFLAC - Unit tester for libOggFLAC - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef OggFLAC__TEST_LIBOGGFLAC_ENCODERS_H -#define OggFLAC__TEST_LIBOGGFLAC_ENCODERS_H - -#include "FLAC/ordinals.h" - -FLAC__bool test_encoders(); - -#endif diff --git a/src/test_libOggFLAC/main.c b/src/test_libOggFLAC/main.c deleted file mode 100644 index a8a65113..00000000 --- a/src/test_libOggFLAC/main.c +++ /dev/null @@ -1,37 +0,0 @@ -/* test_libOggFLAC - Unit tester for libOggFLAC - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include "decoders.h" -#include "encoders.h" - -int main(int argc, char *argv[]) -{ - (void)argc, (void)argv; - - if(!test_encoders()) - return 1; - - if(!test_decoders()) - return 1; - - return 0; -} diff --git a/src/test_libOggFLAC/test_libOggFLAC.dsp b/src/test_libOggFLAC/test_libOggFLAC.dsp deleted file mode 100644 index 55f7d7b5..00000000 --- a/src/test_libOggFLAC/test_libOggFLAC.dsp +++ /dev/null @@ -1,120 +0,0 @@ -# Microsoft Developer Studio Project File - Name="test_libOggFLAC" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=test_libOggFLAC - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "test_libOggFLAC.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "test_libOggFLAC.mak" CFG="test_libOggFLAC - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "test_libOggFLAC - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "test_libOggFLAC - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "test_libOggFLAC - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "..\..\obj\release\bin"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\include" /D "NDEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /c
-# SUBTRACT CPP /YX /Yc /Yu
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ..\..\obj\release\lib\grabbag_static.lib ..\..\obj\release\lib\replaygain_analysis_static.lib ..\..\obj\release\lib\test_libs_common_static.lib ..\..\obj\release\lib\libOggFLAC_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
-
-!ELSEIF "$(CFG)" == "test_libOggFLAC - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "..\..\obj\debug\bin"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\include" /D "_DEBUG" /D "FLAC__NO_DLL" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c
-# SUBTRACT CPP /YX /Yc /Yu
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 ..\..\obj\debug\lib\grabbag_static.lib ..\..\obj\debug\lib\replaygain_analysis_static.lib ..\..\obj\debug\lib\test_libs_common_static.lib ..\..\obj\debug\lib\libOggFLAC_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-
-!ENDIF
-
-# Begin Target
-
-# Name "test_libOggFLAC - Win32 Release"
-# Name "test_libOggFLAC - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\decoders.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\encoders.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\main.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\decoders.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\encoders.h
-# End Source File
-# End Group
-# Begin Source File
-
-SOURCE=.\README
-# End Source File
-# End Target
-# End Project
diff --git a/src/test_libs_common/Makefile.am b/src/test_libs_common/Makefile.am index 21473298..105649ba 100644 --- a/src/test_libs_common/Makefile.am +++ b/src/test_libs_common/Makefile.am @@ -15,21 +15,13 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -if FLaC__HAS_OGG -OGGFLAC_SOURCES = \ - file_utils_oggflac.c -OGGFLAC_LIBS = \ - ../libOggFLAC/libOggFLAC.la -endif - INCLUDES = -I$(top_srcdir)/include noinst_LTLIBRARIES = libtest_libs_common.la libtest_libs_common_la_SOURCES = \ file_utils_flac.c \ - metadata_utils.c \ - $(OGGFLAC_SOURCES) + metadata_utils.c EXTRA_DIST = \ Makefile.lite \ diff --git a/src/test_libs_common/Makefile.lite b/src/test_libs_common/Makefile.lite index 7b6074b5..12365f9e 100644 --- a/src/test_libs_common/Makefile.lite +++ b/src/test_libs_common/Makefile.lite @@ -28,7 +28,6 @@ INCLUDES = -I$(topdir)/include SRCS_C = \ file_utils_flac.c \ - file_utils_oggflac.c \ metadata_utils.c include $(topdir)/build/lib.mk diff --git a/src/test_libs_common/file_utils_flac.c b/src/test_libs_common/file_utils_flac.c index 6dbf3aa9..bf73cb72 100644 --- a/src/test_libs_common/file_utils_flac.c +++ b/src/test_libs_common/file_utils_flac.c @@ -32,6 +32,8 @@ #endif #define min(a,b) ((a)<(b)?(a):(b)) +const long file_utils__ogg_serial_number = 12345; + #ifdef FLAC__VALGRIND_TESTING static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { @@ -65,10 +67,11 @@ static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const (void)encoder, (void)metadata, (void)client_data; } -FLAC__bool file_utils__generate_flacfile(const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata) +FLAC__bool file_utils__generate_flacfile(FLAC__bool is_ogg, const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata) { FLAC__int32 samples[1024]; FLAC__StreamEncoder *encoder; + FLAC__StreamEncoderInitStatus init_status; encoder_client_struct encoder_client_data; unsigned i, n; @@ -86,6 +89,7 @@ FLAC__bool file_utils__generate_flacfile(const char *output_filename, off_t *out return false; } + FLAC__stream_encoder_set_serial_number(encoder, file_utils__ogg_serial_number); FLAC__stream_encoder_set_verify(encoder, true); FLAC__stream_encoder_set_streamable_subset(encoder, true); FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false); @@ -105,7 +109,12 @@ FLAC__bool file_utils__generate_flacfile(const char *output_filename, off_t *out FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo->data.stream_info.total_samples); FLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata); - if(FLAC__stream_encoder_init_stream(encoder, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { + if(is_ogg) + init_status = FLAC__stream_encoder_init_ogg_stream(encoder, /*read_callback=*/0, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data); + else + init_status = FLAC__stream_encoder_init_stream(encoder, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data); + + if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { fclose(encoder_client_data.file); return false; } diff --git a/src/test_libs_common/file_utils_oggflac.c b/src/test_libs_common/file_utils_oggflac.c deleted file mode 100644 index 09cb34c2..00000000 --- a/src/test_libs_common/file_utils_oggflac.c +++ /dev/null @@ -1,147 +0,0 @@ -/* test_libOggFLAC - Unit tester for libOggFLAC - * Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#if HAVE_CONFIG_H -# include <config.h> -#endif - -#include "FLAC/assert.h" -#include "OggFLAC/stream_encoder.h" -#include "test_libs_common/file_utils_oggflac.h" -#include <stdio.h> -#include <stdlib.h> -#include <sys/stat.h> /* for stat() */ - -#ifdef min -#undef min -#endif -#define min(a,b) ((a)<(b)?(a):(b)) - -const long file_utils__serial_number = 12345; - -#ifdef FLAC__VALGRIND_TESTING -static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) -{ - size_t ret = fwrite(ptr, size, nmemb, stream); - if(!ferror(stream)) - fflush(stream); - return ret; -} -#else -#define local__fwrite fwrite -#endif - -typedef struct { - FILE *file; -} encoder_client_struct; - -static FLAC__StreamEncoderWriteStatus encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data) -{ - encoder_client_struct *ecd = (encoder_client_struct*)client_data; - - (void)encoder, (void)samples, (void)current_frame; - - if(local__fwrite(buffer, 1, bytes, ecd->file) != bytes) - return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; - else - return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; -} - -static void encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data) -{ - (void)encoder, (void)metadata, (void)client_data; -} - -FLAC__bool file_utils__generate_oggflacfile(const char *output_filename, off_t *output_filesize, unsigned length, const FLAC__StreamMetadata *streaminfo, FLAC__StreamMetadata **metadata, unsigned num_metadata) -{ - FLAC__int32 samples[1024]; - OggFLAC__StreamEncoder *encoder; - encoder_client_struct encoder_client_data; - unsigned i, n; - - FLAC__ASSERT(0 != output_filename); - FLAC__ASSERT(0 != streaminfo); - FLAC__ASSERT(streaminfo->type == FLAC__METADATA_TYPE_STREAMINFO); - FLAC__ASSERT((streaminfo->is_last && num_metadata == 0) || (!streaminfo->is_last && num_metadata > 0)); - - if(0 == (encoder_client_data.file = fopen(output_filename, "wb"))) - return false; - - encoder = OggFLAC__stream_encoder_new(); - if(0 == encoder) { - fclose(encoder_client_data.file); - return false; - } - - OggFLAC__stream_encoder_set_serial_number(encoder, file_utils__serial_number); - OggFLAC__stream_encoder_set_verify(encoder, true); - OggFLAC__stream_encoder_set_streamable_subset(encoder, true); - OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder, false); - OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false); - OggFLAC__stream_encoder_set_channels(encoder, streaminfo->data.stream_info.channels); - OggFLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo->data.stream_info.bits_per_sample); - OggFLAC__stream_encoder_set_sample_rate(encoder, streaminfo->data.stream_info.sample_rate); - OggFLAC__stream_encoder_set_blocksize(encoder, streaminfo->data.stream_info.min_blocksize); - OggFLAC__stream_encoder_set_max_lpc_order(encoder, 0); - OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0); - OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false); - OggFLAC__stream_encoder_set_do_escape_coding(encoder, false); - OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false); - OggFLAC__stream_encoder_set_min_residual_partition_order(encoder, 0); - OggFLAC__stream_encoder_set_max_residual_partition_order(encoder, 0); - OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0); - OggFLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo->data.stream_info.total_samples); - OggFLAC__stream_encoder_set_metadata(encoder, metadata, num_metadata); - - if(OggFLAC__stream_encoder_init_stream(encoder, /*read_callback=*/0, encoder_write_callback_, /*seek_callback=*/0, /*tell_callback=*/0, encoder_metadata_callback_, &encoder_client_data) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { - fclose(encoder_client_data.file); - return false; - } - - /* init the dummy sample buffer */ - for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++) - samples[i] = i & 7; - - while(length > 0) { - n = min(length, sizeof(samples) / sizeof(FLAC__int32)); - - if(!OggFLAC__stream_encoder_process_interleaved(encoder, samples, n)) { - fclose(encoder_client_data.file); - return false; - } - - length -= n; - } - - OggFLAC__stream_encoder_finish(encoder); - - fclose(encoder_client_data.file); - - OggFLAC__stream_encoder_delete(encoder); - - if(0 != output_filesize) { - struct stat filestats; - - if(stat(output_filename, &filestats) != 0) - return false; - else - *output_filesize = filestats.st_size; - } - - return true; -} diff --git a/src/test_libs_common/test_libs_common_static.dsp b/src/test_libs_common/test_libs_common_static.dsp index dd33c18f..292e8300 100644 --- a/src/test_libs_common/test_libs_common_static.dsp +++ b/src/test_libs_common/test_libs_common_static.dsp @@ -89,10 +89,6 @@ SOURCE=.\file_utils_flac.c # End Source File
# Begin Source File
-SOURCE=.\file_utils_oggflac.c
-# End Source File
-# Begin Source File
-
SOURCE=.\metadata_utils.c
# End Source File
# End Group
@@ -105,10 +101,6 @@ SOURCE=..\..\include\test_libs_common\file_utils_flac.h # End Source File
# Begin Source File
-SOURCE=..\..\include\test_libs_common\file_utils_oggflac.h
-# End Source File
-# Begin Source File
-
SOURCE=..\..\include\test_libs_common\metadata_utils.h
# End Source File
# End Group
diff --git a/src/test_seeking/Makefile.am b/src/test_seeking/Makefile.am index eeff6d86..63ba2a84 100644 --- a/src/test_seeking/Makefile.am +++ b/src/test_seeking/Makefile.am @@ -1,4 +1,4 @@ -# test_seeking - Seeking tester for libFLAC and libOggFLAC +# test_seeking - Seeking tester for libFLAC # Copyright (C) 2004,2005,2006 Josh Coalson # # This program is free software; you can redistribute it and/or @@ -23,13 +23,8 @@ AM_CFLAGS = @OGG_CFLAGS@ INCLUDES = -if FLaC__HAS_OGG -NEED_OGGFLAC_LIB = $(top_builddir)/src/libOggFLAC/libOggFLAC.la -endif - noinst_PROGRAMS = test_seeking test_seeking_LDADD = \ - $(NEED_OGGFLAC_LIB) \ $(top_builddir)/src/libFLAC/libFLAC.la \ @OGG_LIBS@ \ -lm diff --git a/src/test_seeking/Makefile.lite b/src/test_seeking/Makefile.lite index 1e7faafe..6f056af1 100644 --- a/src/test_seeking/Makefile.lite +++ b/src/test_seeking/Makefile.lite @@ -1,4 +1,4 @@ -# test_seeking - Seeking tester for libFLAC and libOggFLAC +# test_seeking - Seeking tester for libFLAC # Copyright (C) 2004,2005,2006 Josh Coalson # # This program is free software; you can redistribute it and/or @@ -27,9 +27,9 @@ PROGRAM_NAME = test_seeking INCLUDES = -I../libFLAC/include -I$(topdir)/include ifeq ($(DARWIN_BUILD),yes) -EXPLICIT_LIBS = $(libdir)/libOggFLAC.a $(libdir)/libFLAC.a $(OGG_LIB_DIR)/libogg.a -lm +EXPLICIT_LIBS = $(libdir)/libFLAC.a $(OGG_LIB_DIR)/libogg.a -lm else -LIBS = -lOggFLAC -lFLAC -L$(OGG_LIB_DIR) -logg -lm +LIBS = -lFLAC -L$(OGG_LIB_DIR) -logg -lm endif SRCS_C = \ diff --git a/src/test_seeking/main.c b/src/test_seeking/main.c index e581b609..a71972b4 100644 --- a/src/test_seeking/main.c +++ b/src/test_seeking/main.c @@ -1,4 +1,4 @@ -/* test_seeking - Seeking tester for libFLAC and libOggFLAC +/* test_seeking - Seeking tester for libFLAC * Copyright (C) 2004,2005,2006 Josh Coalson * * This program is free software; you can redistribute it and/or @@ -32,9 +32,6 @@ #include <sys/stat.h> /* for stat() */ #include "FLAC/assert.h" #include "FLAC/stream_decoder.h" -#ifdef FLAC__HAS_OGG -#include "OggFLAC/stream_decoder.h" -#endif typedef struct { FLAC__bool got_data; @@ -76,26 +73,6 @@ static FLAC__bool die_s_(const char *msg, const FLAC__StreamDecoder *decoder) return false; } -#ifdef FLAC__HAS_OGG -static FLAC__bool die_os_(const char *msg, const OggFLAC__StreamDecoder *decoder) -{ - OggFLAC__StreamDecoderState state = OggFLAC__stream_decoder_get_state(decoder); - - if(msg) - printf("FAILED, %s", msg); - else - printf("FAILED"); - - printf(", state = %u (%s)\n", (unsigned)state, OggFLAC__StreamDecoderStateString[state]); - if(state == OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR) { - FLAC__StreamDecoderState state_ = OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(decoder); - printf(" FLAC stream decoder state = %u (%s)\n", (unsigned)state_, FLAC__StreamDecoderStateString[state_]); - } - - return false; -} -#endif - static off_t get_filesize_(const char *srcpath) { struct stat srcstat; @@ -177,7 +154,7 @@ static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco } } -static FLAC__bool seek_barrage_native_flac(const char *filename, off_t filesize, unsigned count) +static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t filesize, unsigned count) { FLAC__StreamDecoder *decoder; DecoderClientData decoder_client_data; @@ -190,27 +167,35 @@ static FLAC__bool seek_barrage_native_flac(const char *filename, off_t filesize, decoder_client_data.ignore_errors = false; decoder_client_data.error_occurred = false; - printf("\n+++ seek test: FLAC__StreamDecoder\n\n"); + printf("\n+++ seek test: FLAC__StreamDecoder (%s FLAC)\n\n", is_ogg? "Ogg":"native"); decoder = FLAC__stream_decoder_new(); if(0 == decoder) return die_("FLAC__stream_decoder_new() FAILED, returned NULL\n"); - if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_s_("FLAC__stream_decoder_init_file() FAILED", decoder); + if(is_ogg) { + if(FLAC__stream_decoder_init_ogg_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) + return die_s_("FLAC__stream_decoder_init_file() FAILED", decoder); + } + else { + if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) + return die_s_("FLAC__stream_decoder_init_file() FAILED", decoder); + } if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) return die_s_("FLAC__stream_decoder_process_until_end_of_metadata() FAILED", decoder); + if(!is_ogg) { /* not necessary to do this for Ogg because of its seeking method */ /* process until end of stream to make sure we can still seek in that state */ - decoder_client_data.quiet = true; - if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_s_("FLAC__stream_decoder_process_until_end_of_stream() FAILED", decoder); - decoder_client_data.quiet = false; - - printf("stream decoder state is %s\n", FLAC__stream_decoder_get_resolved_state_string(decoder)); - if(FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_END_OF_STREAM) - return die_s_("expected FLAC__STREAM_DECODER_END_OF_STREAM", decoder); + decoder_client_data.quiet = true; + if(!FLAC__stream_decoder_process_until_end_of_stream(decoder)) + return die_s_("FLAC__stream_decoder_process_until_end_of_stream() FAILED", decoder); + decoder_client_data.quiet = false; + + printf("stream decoder state is %s\n", FLAC__stream_decoder_get_resolved_state_string(decoder)); + if(FLAC__stream_decoder_get_state(decoder) != FLAC__STREAM_DECODER_END_OF_STREAM) + return die_s_("expected FLAC__STREAM_DECODER_END_OF_STREAM", decoder); + } printf("file's total_samples is %llu\n", decoder_client_data.total_samples); #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__ @@ -222,6 +207,7 @@ static FLAC__bool seek_barrage_native_flac(const char *filename, off_t filesize, n = (long int)decoder_client_data.total_samples; /* if we don't have a total samples count, just guess based on the file size */ + /* @@@ for is_ogg we should get it from last page's granulepos */ if(n == 0) { /* 8 would imply no compression, 9 guarantees that we will get some samples off the end of the stream to test that case */ n = 9 * filesize / (decoder_client_data.channels * decoder_client_data.bits_per_sample); @@ -295,130 +281,6 @@ static FLAC__bool seek_barrage_native_flac(const char *filename, off_t filesize, return true; } -#ifdef FLAC__HAS_OGG -static FLAC__bool seek_barrage_ogg_flac(const char *filename, off_t filesize, unsigned count) -{ - OggFLAC__StreamDecoder *decoder; - DecoderClientData decoder_client_data; - unsigned i; - long int n; - - decoder_client_data.got_data = false; - decoder_client_data.total_samples = 0; - decoder_client_data.quiet = false; - decoder_client_data.ignore_errors = false; - decoder_client_data.error_occurred = false; - - printf("\n+++ seek test: OggFLAC__StreamDecoder\n\n"); - - decoder = OggFLAC__stream_decoder_new(); - if(0 == decoder) - return die_("OggFLAC__stream_decoder_new() FAILED, returned NULL\n"); - - if(OggFLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &decoder_client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) - return die_os_("OggFLAC__stream_decoder_init_file() FAILED", decoder); - - if(!OggFLAC__stream_decoder_process_until_end_of_metadata(decoder)) - return die_os_("OggFLAC__stream_decoder_process_until_end_of_metadata() FAILED", decoder); - - /* process until end of stream to make sure we can still seek in that state */ -#if 0 - /* not necessary for the Ogg seeking method */ - decoder_client_data.quiet = true; - if(!OggFLAC__stream_decoder_process_until_end_of_stream(decoder)) - return die_os_("OggFLAC__stream_decoder_process_until_end_of_stream() FAILED", decoder); - decoder_client_data.quiet = false; - - printf("stream decoder state is %s\n", OggFLAC__stream_decoder_get_resolved_state_string(decoder)); - if(OggFLAC__stream_decoder_get_state(decoder) != OggFLAC__STREAM_DECODER_END_OF_STREAM) - return die_os_("expected OggFLAC__STREAM_DECODER_END_OF_STREAM", decoder); -#endif - - printf("file's total_samples is %llu\n", decoder_client_data.total_samples); -#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__ - if (decoder_client_data.total_samples > (FLAC__uint64)RAND_MAX) { - printf("ERROR: must be total_samples < %u\n", (unsigned)RAND_MAX); - return false; - } -#endif - n = (long int)decoder_client_data.total_samples; - - /* if we don't have a total samples count, just guess based on the file size */ - /* @@@ should get it from last page's granulepos */ - if(n == 0) { - /* 8 would imply no compression, 9 guarantees that we will get some samples off the end of the stream to test that case */ - n = 9 * filesize / (decoder_client_data.channels * decoder_client_data.bits_per_sample); -#if !defined _MSC_VER && !defined __MINGW32__ - if(n > RAND_MAX) - n = RAND_MAX; -#endif - } - - printf("Begin seek barrage, count=%u\n", count); - - for (i = 0; !stop_signal_ && (count == 0 || i < count); i++) { - FLAC__uint64 pos; - - /* for the first 10, seek to the first 10 samples */ - if (n >= 10 && i < 10) { - pos = i; - } - /* for the second 10, seek to the last 10 samples */ - else if (n >= 10 && i < 20) { - pos = n - 1 - (i-10); - } - /* for the third 10, seek past the end and make sure we fail properly as expected */ - else if (i < 30) { - pos = n + (i-20); - } - else { -#if !defined _MSC_VER && !defined __MINGW32__ - pos = (FLAC__uint64)(random() % n); -#else - /* RAND_MAX is only 32767 in my MSVC */ - pos = (FLAC__uint64)((rand()<<15|rand()) % n); -#endif - } - - printf("seek(%llu)... ", pos); - fflush(stdout); - if(!OggFLAC__stream_decoder_seek_absolute(decoder, pos)) { - if(pos < (FLAC__uint64)n && decoder_client_data.total_samples != 0) - return die_os_("OggFLAC__stream_decoder_seek_absolute() FAILED", decoder); - else if(decoder_client_data.total_samples == 0) - printf("seek failed, assuming it was past EOF... "); - else - printf("seek past end failed as expected... "); - if(!OggFLAC__stream_decoder_flush(decoder)) - return die_os_("OggFLAC__stream_decoder_flush() FAILED", decoder); - } - else { - printf("decode_frame... "); - fflush(stdout); - if(!OggFLAC__stream_decoder_process_single(decoder)) - return die_os_("OggFLAC__stream_decoder_process_single() FAILED", decoder); - - printf("decode_frame... "); - fflush(stdout); - if(!OggFLAC__stream_decoder_process_single(decoder)) - return die_os_("OggFLAC__stream_decoder_process_single() FAILED", decoder); - } - - printf("OK\n"); - fflush(stdout); - } - - if(OggFLAC__stream_decoder_get_state(decoder) != OggFLAC__STREAM_DECODER_UNINITIALIZED) { - if(!OggFLAC__stream_decoder_finish(decoder)) - return die_os_("OggFLAC__stream_decoder_finish() FAILED", decoder); - } - - printf("\nPASSED!\n"); - - return true; -} -#endif - int main(int argc, char *argv[]) { const char *filename; @@ -466,14 +328,14 @@ int main(int argc, char *argv[]) FLAC__bool ok; if (strlen(filename) > 4 && 0 == strcmp(filename+strlen(filename)-4, ".ogg")) { #ifdef FLAC__HAS_OGG - ok = seek_barrage_ogg_flac(filename, filesize, count); + ok = seek_barrage(/*is_ogg=*/true, filename, filesize, count); #else fprintf(stderr, "ERROR: Ogg FLAC not supported\n"); ok = false; #endif } else { - ok = seek_barrage_native_flac(filename, filesize, count); + ok = seek_barrage(/*is_ogg=*/false, filename, filesize, count); } return ok? 0 : 2; } diff --git a/src/test_seeking/test_seeking.dsp b/src/test_seeking/test_seeking.dsp index 7f98dc34..2c7c4714 100644 --- a/src/test_seeking/test_seeking.dsp +++ b/src/test_seeking/test_seeking.dsp @@ -51,7 +51,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 ..\..\obj\release\lib\libOggFLAC_static.lib ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 ..\..\obj\release\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "test_seeking - Win32 Debug"
@@ -76,7 +76,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 ..\..\obj\debug\lib\libOggFLAC_static.lib ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 ..\..\obj\debug\lib\libFLAC_static.lib ..\..\obj\release\lib\ogg_static.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
diff --git a/test/Makefile.am b/test/Makefile.am index 8b681398..bf9bbebd 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -19,19 +19,12 @@ TESTS_ENVIRONMENT = FLAC__TEST_LEVEL=@FLAC__TEST_LEVEL@ FLAC__TEST_WITH_VALRGIND SUBDIRS = cuesheets flac-to-flac-metadata-test-files metaflac-test-files pictures -if FLaC__HAS_OGG -OGG_TESTS = \ - ./test_libOggFLAC.sh \ - ./test_libOggFLAC++.sh -endif - TESTS = \ ./test_libFLAC.sh \ ./test_libFLAC++.sh \ - $(OGG_TESTS) \ + ./test_grabbag.sh \ ./test_flac.sh \ ./test_metaflac.sh \ - ./test_grabbag.sh \ ./test_seeking.sh \ ./test_streams.sh @@ -42,8 +35,6 @@ EXTRA_DIST = \ metaflac.flac.ok \ test_libFLAC.sh \ test_libFLAC++.sh \ - test_libOggFLAC.sh \ - test_libOggFLAC++.sh \ test_flac.sh \ test_metaflac.sh \ test_grabbag.sh \ diff --git a/test/Makefile.lite b/test/Makefile.lite index 17eb7ef2..65a565fd 100644 --- a/test/Makefile.lite +++ b/test/Makefile.lite @@ -28,11 +28,9 @@ CONFIG = $(DEFAULT_CONFIG) all: clean $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_libFLAC.sh $(CONFIG) $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_libFLAC++.sh $(CONFIG) - $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_libOggFLAC.sh $(CONFIG) - $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_libOggFLAC++.sh $(CONFIG) + $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_grabbag.sh $(CONFIG) $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_flac.sh $(CONFIG) $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_metaflac.sh $(CONFIG) - $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_grabbag.sh $(CONFIG) $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_seeking.sh $(CONFIG) $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_streams.sh $(CONFIG) $(FLAC__TEST_LEVEL) $(FLAC__TEST_WITH_VALGRIND) ./test_bins.sh $(CONFIG) diff --git a/test/test_bins.sh b/test/test_bins.sh index 2ed02585..452ecbcb 100755 --- a/test/test_bins.sh +++ b/test/test_bins.sh @@ -30,7 +30,6 @@ else fi LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../src/libOggFLAC/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=../src/share/grabbag/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=../src/share/getopt/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH diff --git a/test/test_flac.sh b/test/test_flac.sh index 98098b42..94f6852a 100755 --- a/test/test_flac.sh +++ b/test/test_flac.sh @@ -39,7 +39,6 @@ else fi LD_LIBRARY_PATH=`pwd`/../src/libFLAC/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=`pwd`/../src/libOggFLAC/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=`pwd`/../src/share/grabbag/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=`pwd`/../src/share/getopt/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH diff --git a/test/test_libOggFLAC++.sh b/test/test_libOggFLAC++.sh deleted file mode 100755 index a3d8041c..00000000 --- a/test/test_libOggFLAC++.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# This file is part the FLAC project. FLAC is comprised of several -# components distributed under difference licenses. The codec libraries -# are distributed under Xiph.Org's BSD-like license (see the file -# COPYING.Xiph in this distribution). All other programs, libraries, and -# plugins are distributed under the GPL (see COPYING.GPL). The documentation -# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the -# FLAC distribution contains at the top the terms under which it may be -# distributed. -# -# Since this particular file is relevant to all components of FLAC, -# it may be distributed under the Xiph.Org license, which is the least -# restrictive of those mentioned above. See the file COPYING.Xiph in this -# distribution. - -die () -{ - echo $* 1>&2 - exit 1 -} - -if [ x = x"$1" ] ; then - BUILD=debug -else - BUILD="$1" -fi - -LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../src/libOggFLAC/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../src/libOggFLAC++/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../src/share/grabbag/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../obj/$BUILD/lib:$LD_LIBRARY_PATH -export LD_LIBRARY_PATH -PATH=../src/test_libOggFLAC++:$PATH -PATH=../obj/$BUILD/bin:$PATH - -run_test_libOggFLACpp () -{ - if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then - valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 test_libOggFLAC++ $* 4>>test_libOggFLAC++.valgrind.log - else - test_libOggFLAC++ $* - fi -} - -run_test_libOggFLACpp || die "ERROR during test_libOggFLAC++" diff --git a/test/test_libOggFLAC.sh b/test/test_libOggFLAC.sh deleted file mode 100755 index c81fa872..00000000 --- a/test/test_libOggFLAC.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh - -# FLAC - Free Lossless Audio Codec -# Copyright (C) 2002,2003,2004,2005,2006 Josh Coalson -# -# This file is part the FLAC project. FLAC is comprised of several -# components distributed under difference licenses. The codec libraries -# are distributed under Xiph.Org's BSD-like license (see the file -# COPYING.Xiph in this distribution). All other programs, libraries, and -# plugins are distributed under the GPL (see COPYING.GPL). The documentation -# is distributed under the Gnu FDL (see COPYING.FDL). Each file in the -# FLAC distribution contains at the top the terms under which it may be -# distributed. -# -# Since this particular file is relevant to all components of FLAC, -# it may be distributed under the Xiph.Org license, which is the least -# restrictive of those mentioned above. See the file COPYING.Xiph in this -# distribution. - -die () -{ - echo $* 1>&2 - exit 1 -} - -if [ x = x"$1" ] ; then - BUILD=debug -else - BUILD="$1" -fi - -LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../src/libOggFLAC/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../src/share/grabbag/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../obj/$BUILD/lib:$LD_LIBRARY_PATH -export LD_LIBRARY_PATH -PATH=../src/test_libOggFLAC:$PATH -PATH=../obj/$BUILD/bin:$PATH - -run_test_libOggFLAC () -{ - if [ x"$FLAC__TEST_WITH_VALGRIND" = xyes ] ; then - valgrind --leak-check=yes --show-reachable=yes --num-callers=100 --logfile-fd=4 test_libOggFLAC $* 4>>test_libOggFLAC.valgrind.log - else - test_libOggFLAC $* - fi -} - -run_test_libOggFLAC || die "ERROR during test_libOggFLAC" diff --git a/test/test_metaflac.sh b/test/test_metaflac.sh index 838ef6b5..592846ff 100755 --- a/test/test_metaflac.sh +++ b/test/test_metaflac.sh @@ -39,7 +39,6 @@ else fi LD_LIBRARY_PATH=`pwd`/../src/libFLAC/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=`pwd`/../src/libOggFLAC/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=`pwd`/../src/share/grabbag/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=`pwd`/../src/share/getopt/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=`pwd`/../src/share/replaygain_analysis/.libs:$LD_LIBRARY_PATH diff --git a/test/test_seeking.sh b/test/test_seeking.sh index 2bef4686..0c8bd4ac 100755 --- a/test/test_seeking.sh +++ b/test/test_seeking.sh @@ -30,7 +30,6 @@ else fi LD_LIBRARY_PATH=../src/libFLAC/.libs:$LD_LIBRARY_PATH -LD_LIBRARY_PATH=../src/libOggFLAC/.libs:$LD_LIBRARY_PATH LD_LIBRARY_PATH=../obj/$BUILD/lib:$LD_LIBRARY_PATH export LD_LIBRARY_PATH PATH=../src/flac:$PATH |