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