2002-05-29 05:49:50 +00:00
/* libFLAC++ - Free Lossless Audio Codec library
2013-05-25 17:11:19 +10:00
* Copyright ( C ) 2002 - 2009 Josh Coalson
2016-12-05 06:35:39 +11:00
* Copyright ( C ) 2011 - 2016 Xiph . Org Foundation
2002-05-29 05:49:50 +00:00
*
2003-01-31 23:34:56 +00:00
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
2002-05-29 05:49:50 +00:00
*
2003-01-31 23:34:56 +00:00
* - Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
2002-05-29 05:49:50 +00:00
*
2003-01-31 23:34:56 +00:00
* - 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 .
2002-05-29 05:49:50 +00:00
*/
# ifndef FLACPP__ENCODER_H
# define FLACPP__ENCODER_H
2002-10-16 22:18:32 +00:00
# include "export.h"
2002-05-29 05:49:50 +00:00
# include "FLAC/stream_encoder.h"
2002-08-03 21:56:15 +00:00
# include "decoder.h"
2004-07-22 01:04:22 +00:00
# include "metadata.h"
2002-05-29 05:49:50 +00:00
2002-07-27 04:59:54 +00:00
/** \file include/FLAC++/encoder.h
*
* \ brief
* This module contains the classes which implement the various
* encoders .
*
* See the detailed documentation in the
* \ link flacpp_encoder encoder \ endlink module .
*/
/** \defgroup flacpp_encoder FLAC++/encoder.h: encoder classes
* \ ingroup flacpp
*
* \ brief
2006-09-13 01:42:27 +00:00
* This module describes the encoder layers provided by libFLAC + + .
2002-08-21 03:40:11 +00:00
*
* The libFLAC + + encoder classes are object wrappers around their
2006-10-15 04:24:05 +00:00
* counterparts in libFLAC . All encoding layers available in
2002-08-21 03:40:11 +00:00
* libFLAC are also provided here . The interface is very similar ;
* make sure to read the \ link flac_encoder libFLAC encoder module \ endlink .
2002-07-27 04:59:54 +00:00
*
2006-09-13 01:42:27 +00:00
* 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 . FLAC : : Encoder : : Stream
2006-10-15 07:50:44 +00:00
* is used for the same cases that FLAC__stream_encoder_init_stream ( ) /
2006-11-20 05:30:25 +00:00
* FLAC__stream_encoder_init_ogg_stream ( ) are used , and FLAC : : Encoder : : File
2006-10-15 07:50:44 +00:00
* is used for the same cases that
* FLAC__stream_encoder_init_FILE ( ) and FLAC__stream_encoder_init_file ( ) /
* FLAC__stream_encoder_init_ogg_FILE ( ) and FLAC__stream_encoder_init_ogg_file ( )
2006-09-13 01:42:27 +00:00
* are used .
2002-07-27 04:59:54 +00:00
*/
2002-05-29 05:49:50 +00:00
namespace FLAC {
namespace Encoder {
2006-10-15 07:50:44 +00:00
/** \ingroup flacpp_encoder
2002-07-27 04:59:54 +00:00
* \ brief
2006-10-15 07:50:44 +00:00
* This class wraps the : : FLAC__StreamEncoder . If you are
2006-09-13 01:42:27 +00:00
* encoding to a file , FLAC : : Encoder : : File may be more
* convenient .
*
* The usage of this class is similar to FLAC__StreamEncoder ,
* except instead of providing callbacks to
2006-10-15 07:50:44 +00:00
* FLAC__stream_encoder_init * _stream ( ) , you will inherit from this
2006-09-13 01:42:27 +00:00
* class and override the virtual callback functions with your
2006-10-15 07:50:44 +00:00
* own implementations , then call init ( ) or init_ogg ( ) . The rest of
2006-09-13 01:42:27 +00:00
* 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
2018-05-22 10:17:53 -04:00
* be written properly , you must override seek_callback ( ) and
2006-09-13 01:42:27 +00:00
* tell_callback ( ) ; see FLAC__stream_encoder_init_stream ( ) as to
* why .
2002-07-27 04:59:54 +00:00
*/
2002-10-16 22:18:32 +00:00
class FLACPP_API Stream {
2002-05-29 05:49:50 +00:00
public :
2006-10-07 05:43:01 +00:00
/** This class is a wrapper around FLAC__StreamEncoderState.
*/
2002-10-16 22:18:32 +00:00
class FLACPP_API State {
2002-05-29 05:49:50 +00:00
public :
inline State ( : : FLAC__StreamEncoderState state ) : state_ ( state ) { }
inline operator : : FLAC__StreamEncoderState ( ) const { return state_ ; }
inline const char * as_cstring ( ) const { return : : FLAC__StreamEncoderStateString [ state_ ] ; }
2003-09-24 04:17:26 +00:00
inline const char * resolved_as_cstring ( const Stream & encoder ) const { return : : FLAC__stream_encoder_get_resolved_state_string ( encoder . encoder_ ) ; }
2002-05-29 05:49:50 +00:00
protected :
: : FLAC__StreamEncoderState state_ ;
} ;
Stream ( ) ;
virtual ~ Stream ( ) ;
2006-10-07 05:43:01 +00:00
//@{
2017-03-21 05:39:26 +11:00
/** Call after construction to check that the object was created
2006-09-13 01:42:27 +00:00
* successfully . If not , use get_state ( ) to find out why not .
*
*/
2006-09-15 15:40:57 +00:00
virtual bool is_valid ( ) const ;
2006-10-15 07:50:44 +00:00
inline operator bool ( ) const { return is_valid ( ) ; } ///< See is_valid()
2006-10-07 05:43:01 +00:00
//@}
2006-09-13 01:42:27 +00:00
2006-10-15 06:04:55 +00:00
virtual bool set_ogg_serial_number ( long value ) ; ///< See FLAC__stream_encoder_set_ogg_serial_number()
2006-09-15 15:40:57 +00:00
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()
2017-01-15 06:47:51 +11:00
virtual bool set_channels ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_channels()
virtual bool set_bits_per_sample ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_bits_per_sample()
virtual bool set_sample_rate ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_sample_rate()
virtual bool set_compression_level ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_compression_level()
virtual bool set_blocksize ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_blocksize()
2006-11-03 16:08:52 +00:00
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()
2006-09-15 15:40:57 +00:00
virtual bool set_apodization ( const char * specification ) ; ///< See FLAC__stream_encoder_set_apodization()
2017-01-15 06:47:51 +11:00
virtual bool set_max_lpc_order ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_max_lpc_order()
virtual bool set_qlp_coeff_precision ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_qlp_coeff_precision()
2006-09-15 15:40:57 +00:00
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()
2017-01-15 06:47:51 +11:00
virtual bool set_min_residual_partition_order ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_min_residual_partition_order()
virtual bool set_max_residual_partition_order ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_max_residual_partition_order()
virtual bool set_rice_parameter_search_dist ( uint32_t value ) ; ///< See FLAC__stream_encoder_set_rice_parameter_search_dist()
2006-09-15 15:40:57 +00:00
virtual bool set_total_samples_estimate ( FLAC__uint64 value ) ; ///< See FLAC__stream_encoder_set_total_samples_estimate()
2017-01-15 06:47:51 +11:00
virtual bool set_metadata ( : : FLAC__StreamMetadata * * metadata , uint32_t num_blocks ) ; ///< See FLAC__stream_encoder_set_metadata()
virtual bool set_metadata ( FLAC : : Metadata : : Prototype * * metadata , uint32_t num_blocks ) ; ///< See FLAC__stream_encoder_set_metadata()
2006-09-15 15:40:57 +00:00
/* 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()
2017-01-15 06:47:51 +11:00
virtual void get_verify_decoder_error_stats ( FLAC__uint64 * absolute_sample , uint32_t * frame_number , uint32_t * channel , uint32_t * sample , FLAC__int32 * expected , FLAC__int32 * got ) ; ///< See FLAC__stream_encoder_get_verify_decoder_error_stats()
2006-09-15 15:40:57 +00:00
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()
2017-01-15 06:47:51 +11:00
virtual uint32_t get_channels ( ) const ; ///< See FLAC__stream_encoder_get_channels()
virtual uint32_t get_bits_per_sample ( ) const ; ///< See FLAC__stream_encoder_get_bits_per_sample()
virtual uint32_t get_sample_rate ( ) const ; ///< See FLAC__stream_encoder_get_sample_rate()
virtual uint32_t get_blocksize ( ) const ; ///< See FLAC__stream_encoder_get_blocksize()
virtual uint32_t get_max_lpc_order ( ) const ; ///< See FLAC__stream_encoder_get_max_lpc_order()
virtual uint32_t get_qlp_coeff_precision ( ) const ; ///< See FLAC__stream_encoder_get_qlp_coeff_precision()
2006-09-15 15:40:57 +00:00
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()
2017-01-15 06:47:51 +11:00
virtual uint32_t get_min_residual_partition_order ( ) const ; ///< See FLAC__stream_encoder_get_min_residual_partition_order()
virtual uint32_t get_max_residual_partition_order ( ) const ; ///< See FLAC__stream_encoder_get_max_residual_partition_order()
virtual uint32_t get_rice_parameter_search_dist ( ) const ; ///< See FLAC__stream_encoder_get_rice_parameter_search_dist()
2006-09-15 15:40:57 +00:00
virtual FLAC__uint64 get_total_samples_estimate ( ) const ; ///< See FLAC__stream_encoder_get_total_samples_estimate()
2006-09-13 01:42:27 +00:00
2006-10-15 04:24:05 +00:00
virtual : : FLAC__StreamEncoderInitStatus init ( ) ; ///< See FLAC__stream_encoder_init_stream()
virtual : : FLAC__StreamEncoderInitStatus init_ogg ( ) ; ///< See FLAC__stream_encoder_init_ogg_stream()
2006-09-13 01:42:27 +00:00
2006-11-09 06:58:26 +00:00
virtual bool finish ( ) ; ///< See FLAC__stream_encoder_finish()
2006-09-13 01:42:27 +00:00
2017-01-15 06:47:51 +11:00
virtual bool process ( const FLAC__int32 * const buffer [ ] , uint32_t samples ) ; ///< See FLAC__stream_encoder_process()
virtual bool process_interleaved ( const FLAC__int32 buffer [ ] , uint32_t samples ) ; ///< See FLAC__stream_encoder_process_interleaved()
2006-09-13 01:42:27 +00:00
protected :
2006-10-15 04:24:05 +00:00
/// See FLAC__StreamEncoderReadCallback
2006-10-15 08:32:56 +00:00
virtual : : FLAC__StreamEncoderReadStatus read_callback ( FLAC__byte buffer [ ] , size_t * bytes ) ;
2006-10-15 04:24:05 +00:00
2006-09-13 01:42:27 +00:00
/// See FLAC__StreamEncoderWriteCallback
2017-01-15 06:47:51 +11:00
virtual : : FLAC__StreamEncoderWriteStatus write_callback ( const FLAC__byte buffer [ ] , size_t bytes , uint32_t samples , uint32_t current_frame ) = 0 ;
2002-05-29 05:49:50 +00:00
2006-09-13 01:42:27 +00:00
/// See FLAC__StreamEncoderSeekCallback
virtual : : FLAC__StreamEncoderSeekStatus seek_callback ( FLAC__uint64 absolute_byte_offset ) ;
2002-05-29 05:49:50 +00:00
2006-09-13 01:42:27 +00:00
/// See FLAC__StreamEncoderTellCallback
virtual : : FLAC__StreamEncoderTellStatus tell_callback ( FLAC__uint64 * absolute_byte_offset ) ;
2002-05-29 05:49:50 +00:00
2007-09-13 00:37:50 +00:00
/// See FLAC__StreamEncoderMetadataCallback
2006-09-13 01:42:27 +00:00
virtual void metadata_callback ( const : : FLAC__StreamMetadata * metadata ) ;
2002-05-29 05:49:50 +00:00
2015-12-10 06:12:08 +11:00
# if (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
// lame hack: some compilers can't see a protected encoder_ from nested State::resolved_as_cstring()
2004-07-30 00:02:33 +00:00
friend State ;
2003-12-18 20:06:52 +00:00
# endif
2002-05-29 05:49:50 +00:00
: : FLAC__StreamEncoder * encoder_ ;
2006-09-13 01:42:27 +00:00
2006-10-15 08:32:56 +00:00
static : : FLAC__StreamEncoderReadStatus read_callback_ ( const : : FLAC__StreamEncoder * encoder , FLAC__byte buffer [ ] , size_t * bytes , void * client_data ) ;
2017-01-15 06:47:51 +11:00
static : : FLAC__StreamEncoderWriteStatus write_callback_ ( const : : FLAC__StreamEncoder * encoder , const FLAC__byte buffer [ ] , size_t bytes , uint32_t samples , uint32_t current_frame , void * client_data ) ;
2006-09-13 01:42:27 +00:00
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 ) ;
2002-06-08 04:53:42 +00:00
static void metadata_callback_ ( const : : FLAC__StreamEncoder * encoder , const : : FLAC__StreamMetadata * metadata , void * client_data ) ;
2006-09-13 01:42:27 +00:00
private :
2002-05-29 05:49:50 +00:00
// Private and undefined so you can't use them:
Stream ( const Stream & ) ;
void operator = ( const Stream & ) ;
} ;
2006-10-15 07:50:44 +00:00
/** \ingroup flacpp_encoder
2002-08-02 06:26:37 +00:00
* \ brief
2006-10-15 07:50:44 +00:00
* This class wraps the : : FLAC__StreamEncoder . If you are
2006-09-13 01:42:27 +00:00
* not encoding to a file , you may need to use
* FLAC : : Encoder : : Stream .
2002-08-02 06:26:37 +00:00
*
2006-09-13 01:42:27 +00:00
* The usage of this class is similar to FLAC__StreamEncoder ,
* except instead of providing callbacks to
2006-10-15 07:50:44 +00:00
* FLAC__stream_encoder_init * _FILE ( ) or
* FLAC__stream_encoder_init * _file ( ) , you will inherit from this
2006-09-13 01:42:27 +00:00
* class and override the virtual callback functions with your
2006-10-15 07:50:44 +00:00
* own implementations , then call init ( ) or init_ogg ( ) . The rest
* of the calls work the same as in the C layer .
2002-08-15 19:19:46 +00:00
*
2006-09-13 01:42:27 +00:00
* There are no mandatory callbacks ; all the callbacks from
* FLAC : : 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 .
2002-08-02 06:26:37 +00:00
*/
2006-09-13 01:42:27 +00:00
class FLACPP_API File : public Stream {
2002-08-02 06:26:37 +00:00
public :
2006-10-07 05:43:01 +00:00
File ( ) ;
virtual ~ File ( ) ;
2015-12-24 18:49:26 +01:00
using Stream : : init ;
2006-10-15 04:24:05 +00:00
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()
2015-12-24 18:49:26 +01:00
using Stream : : init_ogg ;
2006-10-15 04:24:05 +00:00
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()
2002-08-02 06:26:37 +00:00
protected :
2006-09-13 01:42:27 +00:00
/// See FLAC__StreamEncoderProgressCallback
2017-01-15 06:47:51 +11:00
virtual void progress_callback ( FLAC__uint64 bytes_written , FLAC__uint64 samples_written , uint32_t frames_written , uint32_t total_frames_estimate ) ;
2002-08-02 06:26:37 +00:00
2006-09-13 01:42:27 +00:00
/// This is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer
2017-01-15 06:47:51 +11:00
virtual : : FLAC__StreamEncoderWriteStatus write_callback ( const FLAC__byte buffer [ ] , size_t bytes , uint32_t samples , uint32_t current_frame ) ;
2002-08-02 06:26:37 +00:00
private :
2017-01-15 06:47:51 +11:00
static void progress_callback_ ( const : : FLAC__StreamEncoder * encoder , FLAC__uint64 bytes_written , FLAC__uint64 samples_written , uint32_t frames_written , uint32_t total_frames_estimate , void * client_data ) ;
2002-08-02 06:26:37 +00:00
// Private and undefined so you can't use them:
File ( const Stream & ) ;
void operator = ( const Stream & ) ;
} ;
2005-01-25 02:27:20 +00:00
}
}
2002-05-29 05:49:50 +00:00
# endif