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__DECODER_H 00034 #define FLACPP__DECODER_H 00035 00036 #include "export.h" 00037 00038 #include <string> 00039 #include "FLAC/stream_decoder.h" 00040 00041 00078 namespace FLAC { 00079 namespace Decoder { 00080 00100 class FLACPP_API Stream { 00101 public: 00104 class FLACPP_API State { 00105 public: 00106 inline State(::FLAC__StreamDecoderState state): state_(state) { } 00107 inline operator ::FLAC__StreamDecoderState() const { return state_; } 00108 inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; } 00109 inline const char *resolved_as_cstring(const Stream &decoder) const { return ::FLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); } 00110 protected: 00111 ::FLAC__StreamDecoderState state_; 00112 }; 00113 00114 Stream(); 00115 virtual ~Stream(); 00116 00118 00121 virtual bool is_valid() const; 00122 inline operator bool() const { return is_valid(); } 00123 00124 00125 virtual bool set_ogg_serial_number(long value); 00126 virtual bool set_md5_checking(bool value); 00127 virtual bool set_metadata_respond(::FLAC__MetadataType type); 00128 virtual bool set_metadata_respond_application(const FLAC__byte id[4]); 00129 virtual bool set_metadata_respond_all(); 00130 virtual bool set_metadata_ignore(::FLAC__MetadataType type); 00131 virtual bool set_metadata_ignore_application(const FLAC__byte id[4]); 00132 virtual bool set_metadata_ignore_all(); 00133 00134 /* get_state() is not virtual since we want subclasses to be able to return their own state */ 00135 State get_state() const; 00136 virtual bool get_md5_checking() const; 00137 virtual FLAC__uint64 get_total_samples() const; 00138 virtual unsigned get_channels() const; 00139 virtual ::FLAC__ChannelAssignment get_channel_assignment() const; 00140 virtual unsigned get_bits_per_sample() const; 00141 virtual unsigned get_sample_rate() const; 00142 virtual unsigned get_blocksize() const; 00143 virtual bool get_decode_position(FLAC__uint64 *position) const; 00144 00145 virtual ::FLAC__StreamDecoderInitStatus init(); 00146 virtual ::FLAC__StreamDecoderInitStatus init_ogg(); 00147 00148 virtual bool finish(); 00149 00150 virtual bool flush(); 00151 virtual bool reset(); 00152 00153 virtual bool process_single(); 00154 virtual bool process_until_end_of_metadata(); 00155 virtual bool process_until_end_of_stream(); 00156 virtual bool skip_single_frame(); 00157 00158 virtual bool seek_absolute(FLAC__uint64 sample); 00159 protected: 00161 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) = 0; 00162 00164 virtual ::FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset); 00165 00167 virtual ::FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset); 00168 00170 virtual ::FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length); 00171 00173 virtual bool eof_callback(); 00174 00176 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0; 00177 00179 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata); 00180 00182 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0; 00183 00184 #if (defined _MSC_VER) || (defined __BORLANDC__) || (defined __GNUG__ && (__GNUG__ < 2 || (__GNUG__ == 2 && __GNUC_MINOR__ < 96))) || (defined __SUNPRO_CC) 00185 // lame hack: some MSVC/GCC versions can't see a protected decoder_ from nested State::resolved_as_cstring() 00186 friend State; 00187 #endif 00188 ::FLAC__StreamDecoder *decoder_; 00189 00190 static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); 00191 static ::FLAC__StreamDecoderSeekStatus seek_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); 00192 static ::FLAC__StreamDecoderTellStatus tell_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); 00193 static ::FLAC__StreamDecoderLengthStatus length_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); 00194 static FLAC__bool eof_callback_(const ::FLAC__StreamDecoder *decoder, void *client_data); 00195 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); 00196 static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data); 00197 static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data); 00198 private: 00199 // Private and undefined so you can't use them: 00200 Stream(const Stream &); 00201 void operator=(const Stream &); 00202 }; 00203 00223 class FLACPP_API File: public Stream { 00224 public: 00225 File(); 00226 virtual ~File(); 00227 00228 virtual ::FLAC__StreamDecoderInitStatus init(FILE *file); 00229 virtual ::FLAC__StreamDecoderInitStatus init(const char *filename); 00230 virtual ::FLAC__StreamDecoderInitStatus init(const std::string &filename); 00231 virtual ::FLAC__StreamDecoderInitStatus init_ogg(FILE *file); 00232 virtual ::FLAC__StreamDecoderInitStatus init_ogg(const char *filename); 00233 virtual ::FLAC__StreamDecoderInitStatus init_ogg(const std::string &filename); 00234 protected: 00235 // this is a dummy implementation to satisfy the pure virtual in Stream that is actually supplied internally by the C layer 00236 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes); 00237 private: 00238 // Private and undefined so you can't use them: 00239 File(const File &); 00240 void operator=(const File &); 00241 }; 00242 00243 } 00244 } 00245 00246 #endif