Blame include/FLAC++/decoder.h

Packit 8f7830
/* libFLAC++ - Free Lossless Audio Codec library
Packit 8f7830
 * Copyright (C) 2002-2009  Josh Coalson
Packit 8f7830
 * Copyright (C) 2011-2016  Xiph.Org Foundation
Packit 8f7830
 *
Packit 8f7830
 * Redistribution and use in source and binary forms, with or without
Packit 8f7830
 * modification, are permitted provided that the following conditions
Packit 8f7830
 * are met:
Packit 8f7830
 *
Packit 8f7830
 * - Redistributions of source code must retain the above copyright
Packit 8f7830
 * notice, this list of conditions and the following disclaimer.
Packit 8f7830
 *
Packit 8f7830
 * - Redistributions in binary form must reproduce the above copyright
Packit 8f7830
 * notice, this list of conditions and the following disclaimer in the
Packit 8f7830
 * documentation and/or other materials provided with the distribution.
Packit 8f7830
 *
Packit 8f7830
 * - Neither the name of the Xiph.org Foundation nor the names of its
Packit 8f7830
 * contributors may be used to endorse or promote products derived from
Packit 8f7830
 * this software without specific prior written permission.
Packit 8f7830
 *
Packit 8f7830
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 8f7830
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 8f7830
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 8f7830
 * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
Packit 8f7830
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Packit 8f7830
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Packit 8f7830
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit 8f7830
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit 8f7830
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit 8f7830
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Packit 8f7830
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 8f7830
 */
Packit 8f7830
Packit 8f7830
#ifndef FLACPP__DECODER_H
Packit 8f7830
#define FLACPP__DECODER_H
Packit 8f7830
Packit 8f7830
#include "export.h"
Packit 8f7830
Packit 8f7830
#include <string>
Packit 8f7830
#include "FLAC/stream_decoder.h"
Packit 8f7830
Packit 8f7830
Packit 8f7830
/** \file include/FLAC++/decoder.h
Packit 8f7830
 *
Packit 8f7830
 *  \brief
Packit 8f7830
 *  This module contains the classes which implement the various
Packit 8f7830
 *  decoders.
Packit 8f7830
 *
Packit 8f7830
 *  See the detailed documentation in the
Packit 8f7830
 *  \link flacpp_decoder decoder \endlink module.
Packit 8f7830
 */
Packit 8f7830
Packit 8f7830
/** \defgroup flacpp_decoder FLAC++/decoder.h: decoder classes
Packit 8f7830
 *  \ingroup flacpp
Packit 8f7830
 *
Packit 8f7830
 *  \brief
Packit 8f7830
 *  This module describes the decoder layers provided by libFLAC++.
Packit 8f7830
 *
Packit 8f7830
 * The libFLAC++ decoder classes are object wrappers around their
Packit 8f7830
 * counterparts in libFLAC.  All decoding layers available in
Packit 8f7830
 * libFLAC are also provided here.  The interface is very similar;
Packit 8f7830
 * make sure to read the \link flac_decoder libFLAC decoder module \endlink.
Packit 8f7830
 *
Packit 8f7830
 * There are only two significant differences here.  First, instead of
Packit 8f7830
 * passing in C function pointers for callbacks, you inherit from the
Packit 8f7830
 * decoder class and provide implementations for the callbacks in your
Packit 8f7830
 * derived class; because of this there is no need for a 'client_data'
Packit 8f7830
 * property.
Packit 8f7830
 *
Packit 8f7830
 * Second, there are two stream decoder classes.  FLAC::Decoder::Stream
Packit 8f7830
 * is used for the same cases that FLAC__stream_decoder_init_stream() /
Packit 8f7830
 * FLAC__stream_decoder_init_ogg_stream() are used, and FLAC::Decoder::File
Packit 8f7830
 * is used for the same cases that
Packit 8f7830
 * FLAC__stream_decoder_init_FILE() and FLAC__stream_decoder_init_file() /
Packit 8f7830
 * FLAC__stream_decoder_init_ogg_FILE() and FLAC__stream_decoder_init_ogg_file()
Packit 8f7830
 * are used.
Packit 8f7830
 */
Packit 8f7830
Packit 8f7830
namespace FLAC {
Packit 8f7830
	namespace Decoder {
Packit 8f7830
Packit 8f7830
		/** \ingroup flacpp_decoder
Packit 8f7830
		 *  \brief
Packit 8f7830
		 *  This class wraps the ::FLAC__StreamDecoder.  If you are
Packit 8f7830
		 *  decoding from a file, FLAC::Decoder::File may be more
Packit 8f7830
		 *  convenient.
Packit 8f7830
		 *
Packit 8f7830
		 * The usage of this class is similar to FLAC__StreamDecoder,
Packit 8f7830
		 * except instead of providing callbacks to
Packit 8f7830
		 * FLAC__stream_decoder_init*_stream(), you will inherit from this
Packit 8f7830
		 * class and override the virtual callback functions with your
Packit 8f7830
		 * own implementations, then call init() or init_ogg().  The rest
Packit 8f7830
		 * of the calls work the same as in the C layer.
Packit 8f7830
		 *
Packit 8f7830
		 * Only the read, write, and error callbacks are mandatory.  The
Packit 8f7830
		 * others are optional; this class provides default
Packit 8f7830
		 * implementations that do nothing.  In order for seeking to work
Packit 8f7830
		 * you must overide seek_callback(), tell_callback(),
Packit 8f7830
		 * length_callback(), and eof_callback().
Packit 8f7830
		 */
Packit 8f7830
		class FLACPP_API Stream {
Packit 8f7830
		public:
Packit 8f7830
			/** This class is a wrapper around FLAC__StreamDecoderState.
Packit 8f7830
			 */
Packit 8f7830
			class FLACPP_API State {
Packit 8f7830
			public:
Packit 8f7830
				inline State(::FLAC__StreamDecoderState state): state_(state) { }
Packit 8f7830
				inline operator ::FLAC__StreamDecoderState() const { return state_; }
Packit 8f7830
				inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; }
Packit 8f7830
				inline const char *resolved_as_cstring(const Stream &decoder) const { return ::FLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); }
Packit 8f7830
			protected:
Packit 8f7830
				::FLAC__StreamDecoderState state_;
Packit 8f7830
			};
Packit 8f7830
Packit 8f7830
			Stream();
Packit 8f7830
			virtual ~Stream();
Packit 8f7830
Packit 8f7830
			//@{
Packit 8f7830
			/** Call after construction to check the that the object was created
Packit 8f7830
			 *  successfully.  If not, use get_state() to find out why not.
Packit 8f7830
			 */
Packit 8f7830
			virtual bool is_valid() const;
Packit 8f7830
			inline operator bool() const { return is_valid(); } ///< See is_valid()
Packit 8f7830
			//@}
Packit 8f7830
Packit 8f7830
			virtual bool set_ogg_serial_number(long value);                        ///< See FLAC__stream_decoder_set_ogg_serial_number()
Packit 8f7830
			virtual bool set_md5_checking(bool value);                             ///< See FLAC__stream_decoder_set_md5_checking()
Packit 8f7830
			virtual bool set_metadata_respond(::FLAC__MetadataType type);          ///< See FLAC__stream_decoder_set_metadata_respond()
Packit 8f7830
			virtual bool set_metadata_respond_application(const FLAC__byte id[4]); ///< See FLAC__stream_decoder_set_metadata_respond_application()
Packit 8f7830
			virtual bool set_metadata_respond_all();                               ///< See FLAC__stream_decoder_set_metadata_respond_all()
Packit 8f7830
			virtual bool set_metadata_ignore(::FLAC__MetadataType type);           ///< See FLAC__stream_decoder_set_metadata_ignore()
Packit 8f7830
			virtual bool set_metadata_ignore_application(const FLAC__byte id[4]);  ///< See FLAC__stream_decoder_set_metadata_ignore_application()
Packit 8f7830
			virtual bool set_metadata_ignore_all();                                ///< See FLAC__stream_decoder_set_metadata_ignore_all()
Packit 8f7830
Packit 8f7830
			/* get_state() is not virtual since we want subclasses to be able to return their own state */
Packit 8f7830
			State get_state() const;                                          ///< See FLAC__stream_decoder_get_state()
Packit 8f7830
			virtual bool get_md5_checking() const;                            ///< See FLAC__stream_decoder_get_md5_checking()
Packit 8f7830
			virtual FLAC__uint64 get_total_samples() const;                   ///< See FLAC__stream_decoder_get_total_samples()
Packit 8f7830
			virtual unsigned get_channels() const;                            ///< See FLAC__stream_decoder_get_channels()
Packit 8f7830
			virtual ::FLAC__ChannelAssignment get_channel_assignment() const; ///< See FLAC__stream_decoder_get_channel_assignment()
Packit 8f7830
			virtual unsigned get_bits_per_sample() const;                     ///< See FLAC__stream_decoder_get_bits_per_sample()
Packit 8f7830
			virtual unsigned get_sample_rate() const;                         ///< See FLAC__stream_decoder_get_sample_rate()
Packit 8f7830
			virtual unsigned get_blocksize() const;                           ///< See FLAC__stream_decoder_get_blocksize()
Packit 8f7830
			virtual bool get_decode_position(FLAC__uint64 *position) const;   ///< See FLAC__stream_decoder_get_decode_position()
Packit 8f7830
Packit 8f7830
			virtual ::FLAC__StreamDecoderInitStatus init();      ///< Seek FLAC__stream_decoder_init_stream()
Packit 8f7830
			virtual ::FLAC__StreamDecoderInitStatus init_ogg();  ///< Seek FLAC__stream_decoder_init_ogg_stream()
Packit 8f7830
Packit 8f7830
			virtual bool finish(); ///< See FLAC__stream_decoder_finish()
Packit 8f7830
Packit 8f7830
			virtual bool flush(); ///< See FLAC__stream_decoder_flush()
Packit 8f7830
			virtual bool reset(); ///< See FLAC__stream_decoder_reset()
Packit 8f7830
Packit 8f7830
			virtual bool process_single();                ///< See FLAC__stream_decoder_process_single()
Packit 8f7830
			virtual bool process_until_end_of_metadata(); ///< See FLAC__stream_decoder_process_until_end_of_metadata()
Packit 8f7830
			virtual bool process_until_end_of_stream();   ///< See FLAC__stream_decoder_process_until_end_of_stream()
Packit 8f7830
			virtual bool skip_single_frame();             ///< See FLAC__stream_decoder_skip_single_frame()
Packit 8f7830
Packit 8f7830
			virtual bool seek_absolute(FLAC__uint64 sample); ///< See FLAC__stream_decoder_seek_absolute()
Packit 8f7830
		protected:
Packit 8f7830
			/// see FLAC__StreamDecoderReadCallback
Packit 8f7830
			virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) = 0;
Packit 8f7830
Packit 8f7830
			/// see FLAC__StreamDecoderSeekCallback
Packit 8f7830
			virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
Packit 8f7830
Packit 8f7830
			/// see FLAC__StreamDecoderTellCallback
Packit 8f7830
			virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
Packit 8f7830
Packit 8f7830
			/// see FLAC__StreamDecoderLengthCallback
Packit 8f7830
			virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
Packit 8f7830
Packit 8f7830
			/// see FLAC__StreamDecoderEofCallback
Packit 8f7830
			virtual bool eof_callback();
Packit 8f7830
Packit 8f7830
			/// see FLAC__StreamDecoderWriteCallback
Packit 8f7830
			virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
Packit 8f7830
Packit 8f7830
			/// see FLAC__StreamDecoderMetadataCallback
Packit 8f7830
			virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
Packit 8f7830
Packit 8f7830
			/// see FLAC__StreamDecoderErrorCallback
Packit 8f7830
			virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
Packit 8f7830
Packit 8f7830
#if (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
Packit 8f7830
			// lame hack: some compilers can't see a protected decoder_ from nested State::resolved_as_cstring()
Packit 8f7830
			friend State;
Packit 8f7830
#endif
Packit 8f7830
			::FLAC__StreamDecoder *decoder_;
Packit 8f7830
Packit 8f7830
			static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
Packit 8f7830
			static ::FLAC__StreamDecoderSeekStatus seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
Packit 8f7830
			static ::FLAC__StreamDecoderTellStatus tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
Packit 8f7830
			static ::FLAC__StreamDecoderLengthStatus length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
Packit 8f7830
			static FLAC__bool eof_callback_(const ::FLAC__StreamDecoder *decoder, void *client_data);
Packit 8f7830
			static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
Packit 8f7830
			static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
Packit 8f7830
			static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
Packit 8f7830
		private:
Packit 8f7830
			// Private and undefined so you can't use them:
Packit 8f7830
			Stream(const Stream &);
Packit 8f7830
			void operator=(const Stream &);
Packit 8f7830
		};
Packit 8f7830
Packit 8f7830
		/** \ingroup flacpp_decoder
Packit 8f7830
		 *  \brief
Packit 8f7830
		 *  This class wraps the ::FLAC__StreamDecoder.  If you are
Packit 8f7830
		 *  not decoding from a file, you may need to use
Packit 8f7830
		 *  FLAC::Decoder::Stream.
Packit 8f7830
		 *
Packit 8f7830
		 * The usage of this class is similar to FLAC__StreamDecoder,
Packit 8f7830
		 * except instead of providing callbacks to
Packit 8f7830
		 * FLAC__stream_decoder_init*_FILE() or
Packit 8f7830
		 * FLAC__stream_decoder_init*_file(), you will inherit from this
Packit 8f7830
		 * class and override the virtual callback functions with your
Packit 8f7830
		 * own implementations, then call init() or init_off().  The rest
Packit 8f7830
		 * of the calls work the same as in the C layer.
Packit 8f7830
		 *
Packit 8f7830
		 * Only the write, and error callbacks from FLAC::Decoder::Stream
Packit 8f7830
		 * are mandatory.  The others are optional; this class provides
Packit 8f7830
		 * full working implementations for all other callbacks and
Packit 8f7830
		 * supports seeking.
Packit 8f7830
		 */
Packit 8f7830
		class FLACPP_API File: public Stream {
Packit 8f7830
		public:
Packit 8f7830
			File();
Packit 8f7830
			virtual ~File();
Packit 8f7830
Packit 8f7830
			using Stream::init;
Packit 8f7830
			virtual ::FLAC__StreamDecoderInitStatus init(FILE *file);                      ///< See FLAC__stream_decoder_init_FILE()
Packit 8f7830
			virtual ::FLAC__StreamDecoderInitStatus init(const char *filename);            ///< See FLAC__stream_decoder_init_file()
Packit 8f7830
			virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename);     ///< See FLAC__stream_decoder_init_file()
Packit 8f7830
			using Stream::init_ogg;
Packit 8f7830
			virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file);                  ///< See FLAC__stream_decoder_init_ogg_FILE()
Packit 8f7830
			virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename);        ///< See FLAC__stream_decoder_init_ogg_file()
Packit 8f7830
			virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename); ///< See FLAC__stream_decoder_init_ogg_file()
Packit 8f7830
		protected:
Packit 8f7830
			// this is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer
Packit 8f7830
			virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
Packit 8f7830
		private:
Packit 8f7830
			// Private and undefined so you can't use them:
Packit 8f7830
			File(const File &);
Packit 8f7830
			void operator=(const File &);
Packit 8f7830
		};
Packit 8f7830
Packit 8f7830
	}
Packit 8f7830
}
Packit 8f7830
Packit 8f7830
#endif