1 /* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002 Josh Coalson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifndef FLACPP__DECODER_H
21 #define FLACPP__DECODER_H
23 #include "FLAC/file_decoder.h"
24 #include "FLAC/seekable_stream_decoder.h"
25 #include "FLAC/stream_decoder.h"
28 /** \file include/FLAC++/decoder.h
31 * This module contains the classes which implement the various
34 * See the detailed documentation in the
35 * \link flacpp_decoder decoder \endlink module.
38 /** \defgroup flacpp_decoder FLAC++/decoder.h: decoder classes
42 * This module describes the three decoder layers provided by libFLAC++.
44 * The libFLAC++ decoder classes are object wrappers around their
45 * counterparts in libFLAC. All three decoding layers available in
46 * libFLAC are also provided here. The interface is very similar;
47 * make sure to read the \link flac_decoder libFLAC decoder module \endlink.
49 * The only real difference here is that instead of passing in C function
50 * pointers for callbacks, you inherit from the decoder class and provide
51 * implementations for the callbacks in the derived class; because of this
52 * there is no need for a 'client_data' property.
58 // ============================================================
60 // Equivalent: FLAC__StreamDecoder
62 // ============================================================
64 /** \defgroup flacpp_stream_decoder FLAC++/decoder.h: stream decoder class
65 * \ingroup flacpp_decoder
68 * This class wraps the ::FLAC__StreamDecoder.
70 * See the \link flac_stream_decoder libFLAC stream decoder module \endlink.
75 /** This class wraps the ::FLAC__StreamDecoder.
81 inline State(::FLAC__StreamDecoderState state): state_(state) { }
82 inline operator ::FLAC__StreamDecoderState() const { return state_; }
83 inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; }
85 ::FLAC__StreamDecoderState state_;
91 bool is_valid() const;
92 inline operator bool() const { return is_valid(); }
94 bool set_metadata_respond(::FLAC__MetadataType type);
95 bool set_metadata_respond_application(const FLAC__byte id[4]);
96 bool set_metadata_respond_all();
97 bool set_metadata_ignore(::FLAC__MetadataType type);
98 bool set_metadata_ignore_application(const FLAC__byte id[4]);
99 bool set_metadata_ignore_all();
101 State get_state() const;
102 unsigned get_channels() const;
103 ::FLAC__ChannelAssignment get_channel_assignment() const;
104 unsigned get_bits_per_sample() const;
105 unsigned get_sample_rate() const;
106 unsigned get_blocksize() const;
108 /** Initialize the instance; as with the C interface,
109 * init() should be called after construction and 'set'
110 * calls but before any of the 'process' calls.
119 bool process_single();
120 bool process_until_end_of_metadata();
121 bool process_until_end_of_stream();
123 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
124 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
125 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
126 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
128 ::FLAC__StreamDecoder *decoder_;
130 static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
131 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
132 static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
133 static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
135 // Private and undefined so you can't use them:
136 Stream(const Stream &);
137 void operator=(const Stream &);
143 // ============================================================
145 // Equivalent: FLAC__SeekableStreamDecoder
147 // ============================================================
149 /** \defgroup flacpp_seekable_stream_decoder FLAC++/decoder.h: seekable stream decoder class
150 * \ingroup flacpp_decoder
153 * This class wraps the ::FLAC__SeekableStreamDecoder.
155 * See the \link flac_seekable_stream_decoder libFLAC seekable stream decoder module \endlink.
160 /** This class wraps the ::FLAC__SeekableStreamDecoder.
162 class SeekableStream {
166 inline State(::FLAC__SeekableStreamDecoderState state): state_(state) { }
167 inline operator ::FLAC__SeekableStreamDecoderState() const { return state_; }
168 inline const char *as_cstring() const { return ::FLAC__SeekableStreamDecoderStateString[state_]; }
170 ::FLAC__SeekableStreamDecoderState state_;
174 virtual ~SeekableStream();
176 bool is_valid() const;
177 inline operator bool() const { return is_valid(); }
179 bool set_md5_checking(bool value);
180 bool set_metadata_respond(::FLAC__MetadataType type);
181 bool set_metadata_respond_application(const FLAC__byte id[4]);
182 bool set_metadata_respond_all();
183 bool set_metadata_ignore(::FLAC__MetadataType type);
184 bool set_metadata_ignore_application(const FLAC__byte id[4]);
185 bool set_metadata_ignore_all();
187 State get_state() const;
188 Stream::State get_stream_decoder_state() const;
189 bool get_md5_checking() const;
190 unsigned get_channels() const;
191 ::FLAC__ChannelAssignment get_channel_assignment() const;
192 unsigned get_bits_per_sample() const;
193 unsigned get_sample_rate() const;
194 unsigned get_blocksize() const;
203 bool process_single();
204 bool process_until_end_of_metadata();
205 bool process_until_end_of_stream();
207 bool seek_absolute(FLAC__uint64 sample);
209 virtual ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
210 virtual ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
211 virtual ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
212 virtual ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
213 virtual bool eof_callback() = 0;
214 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
215 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
216 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
218 ::FLAC__SeekableStreamDecoder *decoder_;
220 static FLAC__SeekableStreamDecoderReadStatus read_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
221 static FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
222 static FLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
223 static FLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
224 static FLAC__bool eof_callback_(const ::FLAC__SeekableStreamDecoder *decoder, void *client_data);
225 static FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
226 static void metadata_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
227 static void error_callback_(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
229 // Private and undefined so you can't use them:
230 SeekableStream(const SeekableStream &);
231 void operator=(const SeekableStream &);
237 // ============================================================
239 // Equivalent: FLAC__FileDecoder
241 // ============================================================
243 /** \defgroup flacpp_file_decoder FLAC++/decoder.h: file decoder class
244 * \ingroup flacpp_decoder
247 * This class wraps the ::FLAC__FileDecoder.
249 * See the \link flac_file_decoder libFLAC file decoder module \endlink.
254 /** This class wraps the ::FLAC__FileDecoder.
260 inline State(::FLAC__FileDecoderState state): state_(state) { }
261 inline operator ::FLAC__FileDecoderState() const { return state_; }
262 inline const char *as_cstring() const { return ::FLAC__FileDecoderStateString[state_]; }
264 ::FLAC__FileDecoderState state_;
270 bool is_valid() const;
271 inline operator bool() const { return is_valid(); }
273 bool set_md5_checking(bool value);
274 bool set_filename(const char *value); //!< 'value' may not be \c NULL; use "-" for stdin
275 bool set_metadata_respond(::FLAC__MetadataType type);
276 bool set_metadata_respond_application(const FLAC__byte id[4]);
277 bool set_metadata_respond_all();
278 bool set_metadata_ignore(::FLAC__MetadataType type);
279 bool set_metadata_ignore_application(const FLAC__byte id[4]);
280 bool set_metadata_ignore_all();
282 State get_state() const;
283 SeekableStream::State get_seekable_stream_decoder_state() const;
284 Stream::State get_stream_decoder_state() const;
285 bool get_md5_checking() const;
286 unsigned get_channels() const;
287 ::FLAC__ChannelAssignment get_channel_assignment() const;
288 unsigned get_bits_per_sample() const;
289 unsigned get_sample_rate() const;
290 unsigned get_blocksize() const;
296 bool process_single();
297 bool process_until_end_of_metadata();
298 bool process_until_end_of_file();
300 bool seek_absolute(FLAC__uint64 sample);
302 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
303 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
304 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
306 ::FLAC__FileDecoder *decoder_;
308 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
309 static void metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
310 static void error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
312 // Private and undefined so you can't use them:
314 void operator=(const File &);