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_]; }
84 const char *resolved_as_cstring(const Stream &) const;
86 ::FLAC__StreamDecoderState state_;
92 bool is_valid() const;
93 inline operator bool() const { return is_valid(); }
95 bool set_metadata_respond(::FLAC__MetadataType type);
96 bool set_metadata_respond_application(const FLAC__byte id[4]);
97 bool set_metadata_respond_all();
98 bool set_metadata_ignore(::FLAC__MetadataType type);
99 bool set_metadata_ignore_application(const FLAC__byte id[4]);
100 bool set_metadata_ignore_all();
102 State get_state() const;
103 unsigned get_channels() const;
104 ::FLAC__ChannelAssignment get_channel_assignment() const;
105 unsigned get_bits_per_sample() const;
106 unsigned get_sample_rate() const;
107 unsigned get_blocksize() const;
109 /** Initialize the instance; as with the C interface,
110 * init() should be called after construction and 'set'
111 * calls but before any of the 'process' calls.
120 bool process_single();
121 bool process_until_end_of_metadata();
122 bool process_until_end_of_stream();
124 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
125 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
126 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
127 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
129 ::FLAC__StreamDecoder *decoder_;
131 static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
132 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
133 static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
134 static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
136 // Private and undefined so you can't use them:
137 Stream(const Stream &);
138 void operator=(const Stream &);
144 // ============================================================
146 // Equivalent: FLAC__SeekableStreamDecoder
148 // ============================================================
150 /** \defgroup flacpp_seekable_stream_decoder FLAC++/decoder.h: seekable stream decoder class
151 * \ingroup flacpp_decoder
154 * This class wraps the ::FLAC__SeekableStreamDecoder.
156 * See the \link flac_seekable_stream_decoder libFLAC seekable stream decoder module \endlink.
161 /** This class wraps the ::FLAC__SeekableStreamDecoder.
163 class SeekableStream {
167 inline State(::FLAC__SeekableStreamDecoderState state): state_(state) { }
168 inline operator ::FLAC__SeekableStreamDecoderState() const { return state_; }
169 inline const char *as_cstring() const { return ::FLAC__SeekableStreamDecoderStateString[state_]; }
170 const char *resolved_as_cstring(const SeekableStream &) const;
172 ::FLAC__SeekableStreamDecoderState state_;
176 virtual ~SeekableStream();
178 bool is_valid() const;
179 inline operator bool() const { return is_valid(); }
181 bool set_md5_checking(bool value);
182 bool set_metadata_respond(::FLAC__MetadataType type);
183 bool set_metadata_respond_application(const FLAC__byte id[4]);
184 bool set_metadata_respond_all();
185 bool set_metadata_ignore(::FLAC__MetadataType type);
186 bool set_metadata_ignore_application(const FLAC__byte id[4]);
187 bool set_metadata_ignore_all();
189 State get_state() const;
190 Stream::State get_stream_decoder_state() const;
191 bool get_md5_checking() const;
192 unsigned get_channels() const;
193 ::FLAC__ChannelAssignment get_channel_assignment() const;
194 unsigned get_bits_per_sample() const;
195 unsigned get_sample_rate() const;
196 unsigned get_blocksize() const;
205 bool process_single();
206 bool process_until_end_of_metadata();
207 bool process_until_end_of_stream();
209 bool seek_absolute(FLAC__uint64 sample);
211 virtual ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
212 virtual ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
213 virtual ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
214 virtual ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
215 virtual bool eof_callback() = 0;
216 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
217 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
218 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
220 ::FLAC__SeekableStreamDecoder *decoder_;
222 static ::FLAC__SeekableStreamDecoderReadStatus read_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
223 static ::FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
224 static ::FLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
225 static ::FLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
226 static FLAC__bool eof_callback_(const ::FLAC__SeekableStreamDecoder *decoder, void *client_data);
227 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
228 static void metadata_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
229 static void error_callback_(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
231 // Private and undefined so you can't use them:
232 SeekableStream(const SeekableStream &);
233 void operator=(const SeekableStream &);
239 // ============================================================
241 // Equivalent: FLAC__FileDecoder
243 // ============================================================
245 /** \defgroup flacpp_file_decoder FLAC++/decoder.h: file decoder class
246 * \ingroup flacpp_decoder
249 * This class wraps the ::FLAC__FileDecoder.
251 * See the \link flac_file_decoder libFLAC file decoder module \endlink.
256 /** This class wraps the ::FLAC__FileDecoder.
262 inline State(::FLAC__FileDecoderState state): state_(state) { }
263 inline operator ::FLAC__FileDecoderState() const { return state_; }
264 inline const char *as_cstring() const { return ::FLAC__FileDecoderStateString[state_]; }
265 const char *resolved_as_cstring(const File &) const;
267 ::FLAC__FileDecoderState state_;
273 bool is_valid() const;
274 inline operator bool() const { return is_valid(); }
276 bool set_md5_checking(bool value);
277 bool set_filename(const char *value); //!< 'value' may not be \c NULL; use "-" for stdin
278 bool set_metadata_respond(::FLAC__MetadataType type);
279 bool set_metadata_respond_application(const FLAC__byte id[4]);
280 bool set_metadata_respond_all();
281 bool set_metadata_ignore(::FLAC__MetadataType type);
282 bool set_metadata_ignore_application(const FLAC__byte id[4]);
283 bool set_metadata_ignore_all();
285 State get_state() const;
286 SeekableStream::State get_seekable_stream_decoder_state() const;
287 Stream::State get_stream_decoder_state() const;
288 bool get_md5_checking() const;
289 unsigned get_channels() const;
290 ::FLAC__ChannelAssignment get_channel_assignment() const;
291 unsigned get_bits_per_sample() const;
292 unsigned get_sample_rate() const;
293 unsigned get_blocksize() const;
299 bool process_single();
300 bool process_until_end_of_metadata();
301 bool process_until_end_of_file();
303 bool seek_absolute(FLAC__uint64 sample);
305 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
306 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
307 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
309 ::FLAC__FileDecoder *decoder_;
311 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
312 static void metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
313 static void error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
315 // Private and undefined so you can't use them:
317 void operator=(const File &);