1 /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2 * Copyright (C) 2002,2003,2004 Josh Coalson
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * - Neither the name of the Xiph.org Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef OggFLACPP__DECODER_H
33 #define OggFLACPP__DECODER_H
37 #include "OggFLAC/file_decoder.h"
38 #include "OggFLAC/seekable_stream_decoder.h"
39 #include "OggFLAC/stream_decoder.h"
40 // we only need this for the state abstraction really...
41 #include "FLAC++/decoder.h"
44 /** \file include/OggFLAC++/decoder.h
47 * This module contains the classes which implement the various
50 * See the detailed documentation in the
51 * \link oggflacpp_decoder decoder \endlink module.
54 /** \defgroup oggflacpp_decoder OggFLAC++/decoder.h: decoder classes
58 * This module describes the three decoder layers provided by libOggFLAC++.
60 * The libOggFLAC++ decoder classes are object wrappers around their
61 * counterparts in libOggFLAC. All three decoding layers available in
62 * libOggFLAC are also provided here. The interface is very similar;
63 * make sure to read the \link oggflac_decoder libOggFLAC decoder module \endlink.
65 * The only real difference here is that instead of passing in C function
66 * pointers for callbacks, you inherit from the decoder class and provide
67 * implementations for the callbacks in the derived class; because of this
68 * there is no need for a 'client_data' property.
74 // ============================================================
76 // Equivalent: OggFLAC__StreamDecoder
78 // ============================================================
80 /** \defgroup oggflacpp_stream_decoder OggFLAC++/decoder.h: stream decoder class
81 * \ingroup oggflacpp_decoder
84 * This class wraps the ::OggFLAC__StreamDecoder.
86 * See the \link oggflac_stream_decoder libOggFLAC stream decoder module \endlink.
91 /** This class wraps the ::OggFLAC__StreamDecoder.
93 class OggFLACPP_API Stream {
95 class OggFLACPP_API State {
97 inline State(::OggFLAC__StreamDecoderState state): state_(state) { }
98 inline operator ::OggFLAC__StreamDecoderState() const { return state_; }
99 inline const char *as_cstring() const { return ::OggFLAC__StreamDecoderStateString[state_]; }
100 inline const char *resolved_as_cstring(const Stream &decoder) const { return ::OggFLAC__stream_decoder_get_resolved_state_string(decoder.decoder_); }
102 ::OggFLAC__StreamDecoderState state_;
108 bool is_valid() const;
109 inline operator bool() const { return is_valid(); }
111 bool set_serial_number(long value);
112 bool set_metadata_respond(::FLAC__MetadataType type);
113 bool set_metadata_respond_application(const FLAC__byte id[4]);
114 bool set_metadata_respond_all();
115 bool set_metadata_ignore(::FLAC__MetadataType type);
116 bool set_metadata_ignore_application(const FLAC__byte id[4]);
117 bool set_metadata_ignore_all();
119 State get_state() const;
120 FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
121 unsigned get_channels() const;
122 ::FLAC__ChannelAssignment get_channel_assignment() const;
123 unsigned get_bits_per_sample() const;
124 unsigned get_sample_rate() const;
125 unsigned get_blocksize() const;
127 /** Initialize the instance; as with the C interface,
128 * init() should be called after construction and 'set'
129 * calls but before any of the 'process' calls.
138 bool process_single();
139 bool process_until_end_of_metadata();
140 bool process_until_end_of_stream();
142 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
143 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
144 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
145 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
148 //@@@@@@ lame hack: some MSVC versions can't see a protected decoder_ from nested State::resolved_as_cstring(); fix properly later
151 ::OggFLAC__StreamDecoder *decoder_;
153 static ::FLAC__StreamDecoderReadStatus read_callback_(const ::OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
154 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::OggFLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
155 static void metadata_callback_(const ::OggFLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
156 static void error_callback_(const ::OggFLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
158 // Private and undefined so you can't use them:
159 Stream(const Stream &);
160 void operator=(const Stream &);
165 // ============================================================
167 // Equivalent: OggFLAC__SeekableStreamDecoder
169 // ============================================================
171 /** \defgroup oggflacpp_seekable_stream_decoder OggFLAC++/decoder.h: seekable stream decoder class
172 * \ingroup oggflacpp_decoder
175 * This class wraps the ::OggFLAC__SeekableStreamDecoder.
177 * See the \link oggflac_seekable_stream_decoder libOggFLAC seekable stream decoder module \endlink.
182 /** This class wraps the ::OggFLAC__SeekableStreamDecoder.
184 class OggFLACPP_API SeekableStream {
186 class OggFLACPP_API State {
188 inline State(::OggFLAC__SeekableStreamDecoderState state): state_(state) { }
189 inline operator ::OggFLAC__SeekableStreamDecoderState() const { return state_; }
190 inline const char *as_cstring() const { return ::OggFLAC__SeekableStreamDecoderStateString[state_]; }
191 inline const char *resolved_as_cstring(const SeekableStream &decoder) const { return ::OggFLAC__seekable_stream_decoder_get_resolved_state_string(decoder.decoder_); }
193 ::OggFLAC__SeekableStreamDecoderState state_;
197 virtual ~SeekableStream();
199 bool is_valid() const;
200 inline operator bool() const { return is_valid(); }
202 bool set_serial_number(long value);
203 bool set_md5_checking(bool value);
204 bool set_metadata_respond(::FLAC__MetadataType type);
205 bool set_metadata_respond_application(const FLAC__byte id[4]);
206 bool set_metadata_respond_all();
207 bool set_metadata_ignore(::FLAC__MetadataType type);
208 bool set_metadata_ignore_application(const FLAC__byte id[4]);
209 bool set_metadata_ignore_all();
211 State get_state() const;
212 FLAC::Decoder::SeekableStream::State get_FLAC_seekable_stream_decoder_state() const;
213 FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
214 bool get_md5_checking() const;
215 unsigned get_channels() const;
216 ::FLAC__ChannelAssignment get_channel_assignment() const;
217 unsigned get_bits_per_sample() const;
218 unsigned get_sample_rate() const;
219 unsigned get_blocksize() const;
228 bool process_single();
229 bool process_until_end_of_metadata();
230 bool process_until_end_of_stream();
232 bool seek_absolute(FLAC__uint64 sample);
234 virtual ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
235 virtual ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
236 virtual ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
237 virtual ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
238 virtual bool eof_callback() = 0;
239 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
240 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
241 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
244 //@@@@@@ lame hack: some MSVC versions can't see a protected decoder_ from nested State::resolved_as_cstring(); fix properly later
247 ::OggFLAC__SeekableStreamDecoder *decoder_;
249 static ::FLAC__SeekableStreamDecoderReadStatus read_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
250 static ::FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
251 static ::FLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
252 static ::FLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
253 static FLAC__bool eof_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, void *client_data);
254 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
255 static void metadata_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
256 static void error_callback_(const ::OggFLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
258 // Private and undefined so you can't use them:
259 SeekableStream(const SeekableStream &);
260 void operator=(const SeekableStream &);
265 // ============================================================
267 // Equivalent: OggFLAC__FileDecoder
269 // ============================================================
271 /** \defgroup oggflacpp_file_decoder OggFLAC++/decoder.h: file decoder class
272 * \ingroup oggflacpp_decoder
275 * This class wraps the ::OggFLAC__FileDecoder.
277 * See the \link oggflac_file_decoder libOggFLAC file decoder module \endlink.
282 /** This class wraps the ::OggFLAC__FileDecoder.
284 class OggFLACPP_API File {
286 class OggFLACPP_API State {
288 inline State(::OggFLAC__FileDecoderState state): state_(state) { }
289 inline operator ::OggFLAC__FileDecoderState() const { return state_; }
290 inline const char *as_cstring() const { return ::OggFLAC__FileDecoderStateString[state_]; }
291 inline const char *resolved_as_cstring(const File &decoder) const { return ::OggFLAC__file_decoder_get_resolved_state_string(decoder.decoder_); }
293 ::OggFLAC__FileDecoderState state_;
299 bool is_valid() const;
300 inline operator bool() const { return is_valid(); }
302 bool set_serial_number(long value);
303 bool set_md5_checking(bool value);
304 bool set_filename(const char *value); //!< 'value' may not be \c NULL; use "-" for stdin
305 bool set_metadata_respond(::FLAC__MetadataType type);
306 bool set_metadata_respond_application(const FLAC__byte id[4]);
307 bool set_metadata_respond_all();
308 bool set_metadata_ignore(::FLAC__MetadataType type);
309 bool set_metadata_ignore_application(const FLAC__byte id[4]);
310 bool set_metadata_ignore_all();
312 State get_state() const;
313 OggFLAC::Decoder::SeekableStream::State get_seekable_stream_decoder_state() const;
314 FLAC::Decoder::SeekableStream::State get_FLAC_seekable_stream_decoder_state() const;
315 FLAC::Decoder::Stream::State get_FLAC_stream_decoder_state() const;
316 bool get_md5_checking() const;
317 unsigned get_channels() const;
318 ::FLAC__ChannelAssignment get_channel_assignment() const;
319 unsigned get_bits_per_sample() const;
320 unsigned get_sample_rate() const;
321 unsigned get_blocksize() const;
327 bool process_single();
328 bool process_until_end_of_metadata();
329 bool process_until_end_of_file();
331 bool seek_absolute(FLAC__uint64 sample);
333 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
334 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
335 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
338 //@@@@@@ lame hack: some MSVC versions can't see a protected decoder_ from nested State::resolved_as_cstring(); fix properly later
341 ::OggFLAC__FileDecoder *decoder_;
343 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::OggFLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
344 static void metadata_callback_(const ::OggFLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
345 static void error_callback_(const ::OggFLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
347 // Private and undefined so you can't use them:
349 void operator=(const File &);