Commit 68acb04a authored by Josh Coalson's avatar Josh Coalson

change libOggFLAC++ API to make OggFLAC::Decoder::Stream and...

change libOggFLAC++ API to make OggFLAC::Decoder::Stream and OggFLAC::Encoder::Stream inherit from their FLAC counterparts
parent edf672ed
......@@ -124,26 +124,27 @@ namespace FLAC {
*
* \{
*/
bool is_valid() const;
virtual bool is_valid() const;
inline operator bool() const { return is_valid(); }
/* \} */
bool set_md5_checking(bool value); ///< See FLAC__stream_decoder_set_md5_checking()
bool set_metadata_respond(::FLAC__MetadataType type); ///< See FLAC__stream_decoder_set_metadata_respond()
bool set_metadata_respond_application(const FLAC__byte id[4]); ///< See FLAC__stream_decoder_set_metadata_respond_application()
bool set_metadata_respond_all(); ///< See FLAC__stream_decoder_set_metadata_respond_all()
bool set_metadata_ignore(::FLAC__MetadataType type); ///< See FLAC__stream_decoder_set_metadata_ignore()
bool set_metadata_ignore_application(const FLAC__byte id[4]); ///< See FLAC__stream_decoder_set_metadata_ignore_application()
bool set_metadata_ignore_all(); ///< See FLAC__stream_decoder_set_metadata_ignore_all()
State get_state() const; ///< See FLAC__stream_decoder_get_state()
bool get_md5_checking() const; ///< See FLAC__stream_decoder_get_md5_checking()
FLAC__uint64 get_total_samples() const; ///< See FLAC__stream_decoder_get_total_samples()
unsigned get_channels() const; ///< See FLAC__stream_decoder_get_channels()
::FLAC__ChannelAssignment get_channel_assignment() const; ///< See FLAC__stream_decoder_get_channel_assignment()
unsigned get_bits_per_sample() const; ///< See FLAC__stream_decoder_get_bits_per_sample()
unsigned get_sample_rate() const; ///< See FLAC__stream_decoder_get_sample_rate()
unsigned get_blocksize() const; ///< See FLAC__stream_decoder_get_blocksize()
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()
virtual bool set_metadata_respond_all(); ///< See FLAC__stream_decoder_set_metadata_respond_all()
virtual bool set_metadata_ignore(::FLAC__MetadataType type); ///< See FLAC__stream_decoder_set_metadata_ignore()
virtual bool set_metadata_ignore_application(const FLAC__byte id[4]); ///< See FLAC__stream_decoder_set_metadata_ignore_application()
virtual bool set_metadata_ignore_all(); ///< See FLAC__stream_decoder_set_metadata_ignore_all()
/* get_state() is not virtual since we want subclasses to be able to return their own state */
State get_state() const; ///< See FLAC__stream_decoder_get_state()
virtual bool get_md5_checking() const; ///< See FLAC__stream_decoder_get_md5_checking()
virtual FLAC__uint64 get_total_samples() const; ///< See FLAC__stream_decoder_get_total_samples()
virtual unsigned get_channels() const; ///< See FLAC__stream_decoder_get_channels()
virtual ::FLAC__ChannelAssignment get_channel_assignment() const; ///< See FLAC__stream_decoder_get_channel_assignment()
virtual unsigned get_bits_per_sample() const; ///< See FLAC__stream_decoder_get_bits_per_sample()
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'
......@@ -151,19 +152,19 @@ namespace FLAC {
*
* See FLAC__stream_decoder_init_stream().
*/
::FLAC__StreamDecoderInitStatus init();
virtual ::FLAC__StreamDecoderInitStatus init();
void finish(); ///< See FLAC__stream_decoder_finish()
virtual void finish(); ///< See FLAC__stream_decoder_finish()
bool flush(); ///< See FLAC__stream_decoder_flush()
bool reset(); ///< See FLAC__stream_decoder_reset()
virtual bool flush(); ///< See FLAC__stream_decoder_flush()
virtual bool reset(); ///< See FLAC__stream_decoder_reset()
bool process_single(); ///< See FLAC__stream_decoder_process_single()
bool process_until_end_of_metadata(); ///< See FLAC__stream_decoder_process_until_end_of_metadata()
bool process_until_end_of_stream(); ///< See FLAC__stream_decoder_process_until_end_of_stream()
bool skip_single_frame(); ///< See FLAC__stream_decoder_skip_single_frame()
virtual bool process_single(); ///< See FLAC__stream_decoder_process_single()
virtual bool process_until_end_of_metadata(); ///< See FLAC__stream_decoder_process_until_end_of_metadata()
virtual bool process_until_end_of_stream(); ///< See FLAC__stream_decoder_process_until_end_of_stream()
virtual bool skip_single_frame(); ///< See FLAC__stream_decoder_skip_single_frame()
bool seek_absolute(FLAC__uint64 sample); ///< See FLAC__stream_decoder_seek_absolute()
virtual bool seek_absolute(FLAC__uint64 sample); ///< See FLAC__stream_decoder_seek_absolute()
protected:
/// see FLAC__StreamDecoderReadCallback
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
......@@ -193,6 +194,9 @@ namespace FLAC {
// lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring()
friend State;
#endif
// hackery solely for the use of libOggFLAC++
Stream(::FLAC__StreamDecoder *);
::FLAC__StreamDecoder *decoder_;
static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
......
......@@ -126,51 +126,52 @@ namespace FLAC {
*
* \{
*/
bool is_valid() const;
virtual bool is_valid() const;
inline operator bool() const { return is_valid(); }
/* \} */
bool set_verify(bool value); ///< See FLAC__stream_encoder_set_verify()
bool set_streamable_subset(bool value); ///< See FLAC__stream_encoder_set_streamable_subset()
bool set_do_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_do_mid_side_stereo()
bool set_loose_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_loose_mid_side_stereo()
bool set_channels(unsigned value); ///< See FLAC__stream_encoder_set_channels()
bool set_bits_per_sample(unsigned value); ///< See FLAC__stream_encoder_set_bits_per_sample()
bool set_sample_rate(unsigned value); ///< See FLAC__stream_encoder_set_sample_rate()
bool set_blocksize(unsigned value); ///< See FLAC__stream_encoder_set_blocksize()
bool set_apodization(const char *specification); ///< See FLAC__stream_encoder_set_apodization()
bool set_max_lpc_order(unsigned value); ///< See FLAC__stream_encoder_set_max_lpc_order()
bool set_qlp_coeff_precision(unsigned value); ///< See FLAC__stream_encoder_set_qlp_coeff_precision()
bool set_do_qlp_coeff_prec_search(bool value); ///< See FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
bool set_do_escape_coding(bool value); ///< See FLAC__stream_encoder_set_do_escape_coding()
bool set_do_exhaustive_model_search(bool value); ///< See FLAC__stream_encoder_set_do_exhaustive_model_search()
bool set_min_residual_partition_order(unsigned value); ///< See FLAC__stream_encoder_set_min_residual_partition_order()
bool set_max_residual_partition_order(unsigned value); ///< See FLAC__stream_encoder_set_max_residual_partition_order()
bool set_rice_parameter_search_dist(unsigned value); ///< See FLAC__stream_encoder_set_rice_parameter_search_dist()
bool set_total_samples_estimate(FLAC__uint64 value); ///< See FLAC__stream_encoder_set_total_samples_estimate()
bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks); ///< See FLAC__stream_encoder_set_metadata()
bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks); ///< See FLAC__stream_encoder_set_metadata()
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()
virtual bool set_loose_mid_side_stereo(bool value); ///< See FLAC__stream_encoder_set_loose_mid_side_stereo()
virtual bool set_channels(unsigned value); ///< See FLAC__stream_encoder_set_channels()
virtual bool set_bits_per_sample(unsigned value); ///< See FLAC__stream_encoder_set_bits_per_sample()
virtual bool set_sample_rate(unsigned value); ///< See FLAC__stream_encoder_set_sample_rate()
virtual bool set_blocksize(unsigned value); ///< See FLAC__stream_encoder_set_blocksize()
virtual bool set_apodization(const char *specification); ///< See FLAC__stream_encoder_set_apodization()
virtual bool set_max_lpc_order(unsigned value); ///< See FLAC__stream_encoder_set_max_lpc_order()
virtual bool set_qlp_coeff_precision(unsigned value); ///< See FLAC__stream_encoder_set_qlp_coeff_precision()
virtual bool set_do_qlp_coeff_prec_search(bool value); ///< See FLAC__stream_encoder_set_do_qlp_coeff_prec_search()
virtual bool set_do_escape_coding(bool value); ///< See FLAC__stream_encoder_set_do_escape_coding()
virtual bool set_do_exhaustive_model_search(bool value); ///< See FLAC__stream_encoder_set_do_exhaustive_model_search()
virtual bool set_min_residual_partition_order(unsigned value); ///< See FLAC__stream_encoder_set_min_residual_partition_order()
virtual bool set_max_residual_partition_order(unsigned value); ///< See FLAC__stream_encoder_set_max_residual_partition_order()
virtual bool set_rice_parameter_search_dist(unsigned value); ///< See FLAC__stream_encoder_set_rice_parameter_search_dist()
virtual bool set_total_samples_estimate(FLAC__uint64 value); ///< See FLAC__stream_encoder_set_total_samples_estimate()
virtual bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks); ///< See FLAC__stream_encoder_set_metadata()
virtual bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks); ///< See FLAC__stream_encoder_set_metadata()
State get_state() const; ///< See FLAC__stream_encoder_get_state()
Decoder::Stream::State get_verify_decoder_state() const; ///< See FLAC__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 FLAC__stream_encoder_get_verify_decoder_error_stats()
bool get_verify() const; ///< See FLAC__stream_encoder_get_verify()
bool get_streamable_subset() const; ///< See FLAC__stream_encoder_get_streamable_subset()
bool get_do_mid_side_stereo() const; ///< See FLAC__stream_encoder_get_do_mid_side_stereo()
bool get_loose_mid_side_stereo() const; ///< See FLAC__stream_encoder_get_loose_mid_side_stereo()
unsigned get_channels() const; ///< See FLAC__stream_encoder_get_channels()
unsigned get_bits_per_sample() const; ///< See FLAC__stream_encoder_get_bits_per_sample()
unsigned get_sample_rate() const; ///< See FLAC__stream_encoder_get_sample_rate()
unsigned get_blocksize() const; ///< See FLAC__stream_encoder_get_blocksize()
unsigned get_max_lpc_order() const; ///< See FLAC__stream_encoder_get_max_lpc_order()
unsigned get_qlp_coeff_precision() const; ///< See FLAC__stream_encoder_get_qlp_coeff_precision()
bool get_do_qlp_coeff_prec_search() const; ///< See FLAC__stream_encoder_get_do_qlp_coeff_prec_search()
bool get_do_escape_coding() const; ///< See FLAC__stream_encoder_get_do_escape_coding()
bool get_do_exhaustive_model_search() const; ///< See FLAC__stream_encoder_get_do_exhaustive_model_search()
unsigned get_min_residual_partition_order() const; ///< See FLAC__stream_encoder_get_min_residual_partition_order()
unsigned get_max_residual_partition_order() const; ///< See FLAC__stream_encoder_get_max_residual_partition_order()
unsigned get_rice_parameter_search_dist() const; ///< See FLAC__stream_encoder_get_rice_parameter_search_dist()
FLAC__uint64 get_total_samples_estimate() const; ///< See FLAC__stream_encoder_get_total_samples_estimate()
/* get_state() is not virtual since we want subclasses to be able to return their own state */
State get_state() const; ///< See FLAC__stream_encoder_get_state()
virtual Decoder::Stream::State get_verify_decoder_state() const; ///< See FLAC__stream_encoder_get_verify_decoder_state()
virtual void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got); ///< See FLAC__stream_encoder_get_verify_decoder_error_stats()
virtual bool get_verify() const; ///< See FLAC__stream_encoder_get_verify()
virtual bool get_streamable_subset() const; ///< See FLAC__stream_encoder_get_streamable_subset()
virtual bool get_do_mid_side_stereo() const; ///< See FLAC__stream_encoder_get_do_mid_side_stereo()
virtual bool get_loose_mid_side_stereo() const; ///< See FLAC__stream_encoder_get_loose_mid_side_stereo()
virtual unsigned get_channels() const; ///< See FLAC__stream_encoder_get_channels()
virtual unsigned get_bits_per_sample() const; ///< See FLAC__stream_encoder_get_bits_per_sample()
virtual unsigned get_sample_rate() const; ///< See FLAC__stream_encoder_get_sample_rate()
virtual unsigned get_blocksize() const; ///< See FLAC__stream_encoder_get_blocksize()
virtual unsigned get_max_lpc_order() const; ///< See FLAC__stream_encoder_get_max_lpc_order()
virtual unsigned get_qlp_coeff_precision() const; ///< See FLAC__stream_encoder_get_qlp_coeff_precision()
virtual bool get_do_qlp_coeff_prec_search() const; ///< See FLAC__stream_encoder_get_do_qlp_coeff_prec_search()
virtual bool get_do_escape_coding() const; ///< See FLAC__stream_encoder_get_do_escape_coding()
virtual bool get_do_exhaustive_model_search() const; ///< See FLAC__stream_encoder_get_do_exhaustive_model_search()
virtual unsigned get_min_residual_partition_order() const; ///< See FLAC__stream_encoder_get_min_residual_partition_order()
virtual unsigned get_max_residual_partition_order() const; ///< See FLAC__stream_encoder_get_max_residual_partition_order()
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'
......@@ -178,12 +179,12 @@ namespace FLAC {
*
* See FLAC__stream_encoder_init_stream().
*/
::FLAC__StreamEncoderInitStatus init();
virtual ::FLAC__StreamEncoderInitStatus init();
void finish(); ///< See FLAC__stream_encoder_finish()
virtual void finish(); ///< See FLAC__stream_encoder_finish()
bool process(const FLAC__int32 * const buffer[], unsigned samples); ///< See FLAC__stream_encoder_process()
bool process_interleaved(const FLAC__int32 buffer[], unsigned samples); ///< See FLAC__stream_encoder_process_interleaved()
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__StreamEncoderWriteCallback
virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame) = 0;
......@@ -201,6 +202,9 @@ namespace FLAC {
// lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
friend State;
#endif
// hackery solely for the use of libOggFLAC++
Stream(::FLAC__StreamEncoder *);
::FLAC__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);
......
......@@ -278,6 +278,11 @@
* two new convenience functions that may be useful:
* FLAC__metadata_object_cuesheet_calculate_cddb_id() and
* FLAC__metadata_get_cuesheet().
*
* In libOggFLAC++, OggFLAC::Decoder::Stream now inherits from
* FLAC::Decoder::Stream and OggFLAC::Encoder::Stream now inherits from
* FLAC::Encoder::Stream, which means both OggFLAC and FLAC can be
* supported by using common code for everything after initialization.
*/
/** \defgroup flac FLAC C API
......
......@@ -71,6 +71,37 @@
* 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 {
......@@ -105,14 +136,14 @@ namespace OggFLAC {
* you must overide seek_callback(), tell_callback(),
* length_callback(), and eof_callback().
*/
class OggFLACPP_API Stream {
class OggFLACPP_API Stream: public FLAC::Decoder::Stream {
public:
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(decoder.decoder_); }
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_;
};
......@@ -120,15 +151,6 @@ namespace OggFLAC {
Stream();
virtual ~Stream();
/** Call after construction to check the that the object was created
* successfully. If not, use get_state() to find out why not.
*
* \{
*/
bool is_valid() const;
inline operator bool() const { return is_valid(); }
/* \} */
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()
......@@ -168,44 +190,10 @@ namespace OggFLAC {
bool seek_absolute(FLAC__uint64 sample); ///< See OggFLAC__stream_decoder_seek_absolute()
protected:
/// see FLAC__StreamDecoderReadCallback
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
/// see FLAC__StreamDecoderSeekCallback
virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
/// see FLAC__StreamDecoderTellCallback
virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
/// see FLAC__StreamDecoderLengthCallback
virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);
/// see FLAC__StreamDecoderEofCallback
virtual bool eof_callback();
/// see FLAC__StreamDecoderWriteCallback
virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
/// see FLAC__StreamDecoderMetadataCallback
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
/// see FLAC__StreamDecoderErrorCallback
virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
#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
::OggFLAC__StreamDecoder *decoder_;
static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
static ::FLAC__StreamDecoderSeekStatus seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
static ::FLAC__StreamDecoderTellStatus tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static ::FLAC__StreamDecoderLengthStatus length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
static FLAC__bool eof_callback_(const ::FLAC__StreamDecoder *decoder, 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);
private:
// Private and undefined so you can't use them:
Stream(const Stream &);
......
......@@ -73,6 +73,37 @@
* 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 {
......@@ -108,14 +139,14 @@ namespace OggFLAC {
* tell_callback(); see OggFLAC__stream_encoder_init_stream() as to
* why.
*/
class OggFLACPP_API Stream {
class OggFLACPP_API Stream: public FLAC::Encoder::Stream {
public:
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(encoder.encoder_); }
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_;
};
......@@ -123,15 +154,6 @@ namespace OggFLAC {
Stream();
virtual ~Stream();
/** Call after construction to check the that the object was created
* successfully. If not, use get_state() to find out why not.
*
* \{
*/
bool is_valid() const;
inline operator bool() const { return is_valid(); }
/* \} */
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()
......@@ -192,29 +214,11 @@ namespace OggFLAC {
/// See OggFLAC__StreamEncoderReadCallback
virtual ::OggFLAC__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;
/// See FLAC__StreamEncoderSeekCallback
virtual ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
/// See FLAC__StreamEncoderTellCallback
virtual ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
/// See FLAC__StreamEncoderTellCallback
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
#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
::OggFLAC__StreamEncoder *encoder_;
static ::OggFLAC__StreamEncoderReadStatus read_callback_(const ::OggFLAC__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);
static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
private:
// Private and undefined so you can't use them:
Stream(const Stream &);
......
......@@ -44,8 +44,18 @@ namespace FLAC {
decoder_(::FLAC__stream_decoder_new())
{ }
Stream::Stream(::FLAC__StreamDecoder *decoder):
decoder_(decoder)
{ }
Stream::~Stream()
{
// WATCHOUT: must check for NULL not only because
// ::FLAC__stream_encoder_new() might have failed in
// the constructor, but also because
// OggFLAC::Encoder::Stream deletes the encoder_ before
// we get to it here to make the C inheritance magic
// work.
if(0 != decoder_) {
::FLAC__stream_decoder_finish(decoder_);
::FLAC__stream_decoder_delete(decoder_);
......
......@@ -45,8 +45,18 @@ namespace FLAC {
encoder_(::FLAC__stream_encoder_new())
{ }
Stream::Stream(::FLAC__StreamEncoder *encoder):
encoder_(encoder)
{ }
Stream::~Stream()
{
// WATCHOUT: must check for NULL not only because
// ::FLAC__stream_encoder_new() might have failed in
// the constructor, but also because
// OggFLAC::Encoder::Stream deletes the encoder_ before
// we get to it here to make the C inheritance magic
// work.
if(0 != encoder_) {
::FLAC__stream_encoder_finish(encoder_);
::FLAC__stream_encoder_delete(encoder_);
......
......@@ -51,13 +51,13 @@ namespace OggFLAC {
::FLAC__StreamDecoderInitStatus File::init(FILE *file)
{
FLAC__ASSERT(0 != decoder_);
return ::OggFLAC__stream_decoder_init_FILE(decoder_, file, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
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(decoder_, filename, write_callback_, metadata_callback_, error_callback_, /*client_data=*/(void*)this);
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)
......
......@@ -45,19 +45,18 @@ namespace OggFLAC {
{ }
File::~File()
{
}
{ }
::FLAC__StreamEncoderInitStatus File::init(FILE *file)
{
FLAC__ASSERT(is_valid());
return ::OggFLAC__stream_encoder_init_FILE(encoder_, file, progress_callback_, /*client_data=*/(void*)this);
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(encoder_, filename, progress_callback_, /*client_data=*/(void*)this);
return ::OggFLAC__stream_encoder_init_file((OggFLAC__StreamEncoder*)encoder_, filename, progress_callback_, /*client_data=*/(void*)this);
}
::FLAC__StreamEncoderInitStatus File::init(const std::string &filename)
......
......@@ -40,277 +40,180 @@
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():
decoder_(::OggFLAC__stream_decoder_new())
FLAC::Decoder::Stream((FLAC__StreamDecoder*)::OggFLAC__stream_decoder_new())
{ }
Stream::~Stream()
{
if(0 != decoder_) {
::OggFLAC__stream_decoder_finish(decoder_);
::OggFLAC__stream_decoder_delete(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::is_valid() const
{
return 0 != decoder_;
}
bool Stream::set_md5_checking(bool value)
{
FLAC__ASSERT(is_valid());
return (bool)::OggFLAC__stream_decoder_set_md5_checking(decoder_, value);
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(decoder_, value);
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(decoder_, type);
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(decoder_, id);
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(decoder_);
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(decoder_, type);
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(decoder_, id);
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(decoder_);
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(decoder_));
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(decoder_));
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(decoder_);