Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

encoder.h

Go to the documentation of this file.
00001 /* libFLAC++ - Free Lossless Audio Codec library
00002  * Copyright (C) 2002,2003,2004,2005,2006,2007  Josh Coalson
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * - Redistributions of source code must retain the above copyright
00009  * notice, this list of conditions and the following disclaimer.
00010  *
00011  * - Redistributions in binary form must reproduce the above copyright
00012  * notice, this list of conditions and the following disclaimer in the
00013  * documentation and/or other materials provided with the distribution.
00014  *
00015  * - Neither the name of the Xiph.org Foundation nor the names of its
00016  * contributors may be used to endorse or promote products derived from
00017  * this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022  * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
00023  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00024  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00025  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00026  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00027  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00028  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #ifndef FLACPP__ENCODER_H
00033 #define FLACPP__ENCODER_H
00034 
00035 #include "export.h"
00036 
00037 #include "FLAC/stream_encoder.h"
00038 #include "decoder.h"
00039 #include "metadata.h"
00040 
00041 
00078 namespace FLAC {
00079     namespace Encoder {
00080 
00101         class FLACPP_API Stream {
00102         public:
00105             class FLACPP_API State {
00106             public:
00107                 inline State(::FLAC__StreamEncoderState state): state_(state) { }
00108                 inline operator ::FLAC__StreamEncoderState() const { return state_; }
00109                 inline const char *as_cstring() const { return ::FLAC__StreamEncoderStateString[state_]; }
00110                 inline const char *resolved_as_cstring(const Stream &encoder) const { return ::FLAC__stream_encoder_get_resolved_state_string(encoder.encoder_); }
00111             protected:
00112 				::FLAC__StreamEncoderState state_;
00113             };
00114 
00115             Stream();
00116             virtual ~Stream();
00117 
00119 
00123             virtual bool is_valid() const;
00124             inline operator bool() const { return is_valid(); } 
00125 
00126 
00127             virtual bool set_ogg_serial_number(long value);                 
00128             virtual bool set_verify(bool value);                            
00129             virtual bool set_streamable_subset(bool value);                 
00130             virtual bool set_channels(unsigned value);                      
00131             virtual bool set_bits_per_sample(unsigned value);               
00132             virtual bool set_sample_rate(unsigned value);                   
00133             virtual bool set_compression_level(unsigned value);             
00134             virtual bool set_blocksize(unsigned value);                     
00135             virtual bool set_do_mid_side_stereo(bool value);                
00136             virtual bool set_loose_mid_side_stereo(bool value);             
00137             virtual bool set_apodization(const char *specification);        
00138             virtual bool set_max_lpc_order(unsigned value);                 
00139             virtual bool set_qlp_coeff_precision(unsigned value);           
00140             virtual bool set_do_qlp_coeff_prec_search(bool value);          
00141             virtual bool set_do_escape_coding(bool value);                  
00142             virtual bool set_do_exhaustive_model_search(bool value);        
00143             virtual bool set_min_residual_partition_order(unsigned value);  
00144             virtual bool set_max_residual_partition_order(unsigned value);  
00145             virtual bool set_rice_parameter_search_dist(unsigned value);    
00146             virtual bool set_total_samples_estimate(FLAC__uint64 value);    
00147             virtual bool set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks);    
00148             virtual bool set_metadata(FLAC::Metadata::Prototype **metadata, unsigned num_blocks); 
00149 
00150             /* get_state() is not virtual since we want subclasses to be able to return their own state */
00151             State get_state() const;                                   
00152             virtual Decoder::Stream::State get_verify_decoder_state() const; 
00153             virtual void get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got); 
00154             virtual bool     get_verify() const;                       
00155             virtual bool     get_streamable_subset() const;            
00156             virtual bool     get_do_mid_side_stereo() const;           
00157             virtual bool     get_loose_mid_side_stereo() const;        
00158             virtual unsigned get_channels() const;                     
00159             virtual unsigned get_bits_per_sample() const;              
00160             virtual unsigned get_sample_rate() const;                  
00161             virtual unsigned get_blocksize() const;                    
00162             virtual unsigned get_max_lpc_order() const;                
00163             virtual unsigned get_qlp_coeff_precision() const;          
00164             virtual bool     get_do_qlp_coeff_prec_search() const;     
00165             virtual bool     get_do_escape_coding() const;             
00166             virtual bool     get_do_exhaustive_model_search() const;   
00167             virtual unsigned get_min_residual_partition_order() const; 
00168             virtual unsigned get_max_residual_partition_order() const; 
00169             virtual unsigned get_rice_parameter_search_dist() const;   
00170             virtual FLAC__uint64 get_total_samples_estimate() const;   
00171 
00172             virtual ::FLAC__StreamEncoderInitStatus init();            
00173             virtual ::FLAC__StreamEncoderInitStatus init_ogg();        
00174 
00175             virtual bool finish(); 
00176 
00177             virtual bool process(const FLAC__int32 * const buffer[], unsigned samples);     
00178             virtual bool process_interleaved(const FLAC__int32 buffer[], unsigned samples); 
00179         protected:
00181             virtual ::FLAC__StreamEncoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
00182 
00184             virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame) = 0;
00185 
00187             virtual ::FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
00188 
00190             virtual ::FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
00191 
00193             virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata);
00194 
00195 #if (defined _MSC_VER) || (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC)
00196             // lame hack: some MSVC/GCC versions can't see a protected encoder_ from nested State::resolved_as_cstring()
00197             friend State;
00198 #endif
00199             ::FLAC__StreamEncoder *encoder_;
00200 
00201             static ::FLAC__StreamEncoderReadStatus read_callback_(const ::FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
00202             static ::FLAC__StreamEncoderWriteStatus write_callback_(const ::FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
00203             static ::FLAC__StreamEncoderSeekStatus seek_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
00204             static ::FLAC__StreamEncoderTellStatus tell_callback_(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
00205             static void metadata_callback_(const ::FLAC__StreamEncoder *encoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
00206         private:
00207             // Private and undefined so you can't use them:
00208             Stream(const Stream &);
00209             void operator=(const Stream &);
00210         };
00211 
00232         class FLACPP_API File: public Stream {
00233         public:
00234             File();
00235             virtual ~File();
00236 
00237             virtual ::FLAC__StreamEncoderInitStatus init(FILE *file);                      
00238             virtual ::FLAC__StreamEncoderInitStatus init(const char *filename);            
00239             virtual ::FLAC__StreamEncoderInitStatus init(const std::string &filename);     
00240             virtual ::FLAC__StreamEncoderInitStatus init_ogg(FILE *file);                  
00241             virtual ::FLAC__StreamEncoderInitStatus init_ogg(const char *filename);        
00242             virtual ::FLAC__StreamEncoderInitStatus init_ogg(const std::string &filename); 
00243         protected:
00245             virtual void progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate);
00246 
00248             virtual ::FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame);
00249         private:
00250             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);
00251 
00252             // Private and undefined so you can't use them:
00253             File(const Stream &);
00254             void operator=(const Stream &);
00255         };
00256 
00257     }
00258 }
00259 
00260 #endif