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"
27 // ===============================================================
29 // Full documentation for the decoder interfaces can be found
30 // in the C layer in include/FLAC/*_decoder.h
32 // ===============================================================
38 // ============================================================
40 // The only real difference here is that instead of passing
41 // in C function pointers for callbacks, you inherit from
42 // stream and provide implementations for the callbacks in
43 // the derived class; because of this there is no need for a
44 // 'client_data' property.
46 // ============================================================
48 // ============================================================
50 // Equivalent: FLAC__StreamDecoder
52 // ============================================================
58 inline State(::FLAC__StreamDecoderState state): state_(state) { }
59 inline operator ::FLAC__StreamDecoderState() const { return state_; }
60 inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; }
62 ::FLAC__StreamDecoderState state_;
68 bool is_valid() const;
69 inline operator bool() const { return is_valid(); }
71 bool set_metadata_respond(::FLAC__MetadataType type);
72 bool set_metadata_respond_application(const FLAC__byte id[4]);
73 bool set_metadata_respond_all();
74 bool set_metadata_ignore(::FLAC__MetadataType type);
75 bool set_metadata_ignore_application(const FLAC__byte id[4]);
76 bool set_metadata_ignore_all();
78 State get_state() const;
79 unsigned get_channels() const;
80 ::FLAC__ChannelAssignment get_channel_assignment() const;
81 unsigned get_bits_per_sample() const;
82 unsigned get_sample_rate() const;
83 unsigned get_blocksize() const;
85 // Initialize the instance; as with the C interface,
86 // init() should be called after construction and 'set'
87 // calls but before any of the 'process' calls.
95 bool process_whole_stream();
96 bool process_metadata();
97 bool process_one_frame();
98 bool process_remaining_frames();
100 virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
101 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
102 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
103 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
105 ::FLAC__StreamDecoder *decoder_;
107 static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
108 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
109 static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
110 static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
112 // Private and undefined so you can't use them:
113 Stream(const Stream &);
114 void operator=(const Stream &);
117 // ============================================================
119 // Equivalent: FLAC__SeekableStreamDecoder
121 // ============================================================
123 class SeekableStream {
127 inline State(::FLAC__SeekableStreamDecoderState state): state_(state) { }
128 inline operator ::FLAC__SeekableStreamDecoderState() const { return state_; }
129 inline const char *as_cstring() const { return ::FLAC__SeekableStreamDecoderStateString[state_]; }
131 ::FLAC__SeekableStreamDecoderState state_;
135 virtual ~SeekableStream();
137 bool is_valid() const;
138 inline operator bool() const { return is_valid(); }
140 bool set_md5_checking(bool value);
141 bool set_metadata_respond(::FLAC__MetadataType type);
142 bool set_metadata_respond_application(const FLAC__byte id[4]);
143 bool set_metadata_respond_all();
144 bool set_metadata_ignore(::FLAC__MetadataType type);
145 bool set_metadata_ignore_application(const FLAC__byte id[4]);
146 bool set_metadata_ignore_all();
148 State get_state() const;
149 bool get_md5_checking() const;
150 unsigned get_channels() const;
151 ::FLAC__ChannelAssignment get_channel_assignment() const;
152 unsigned get_bits_per_sample() const;
153 unsigned get_sample_rate() const;
154 unsigned get_blocksize() const;
163 bool process_whole_stream();
164 bool process_metadata();
165 bool process_one_frame();
166 bool process_remaining_frames();
168 bool seek_absolute(FLAC__uint64 sample);
170 virtual ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
171 virtual ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
172 virtual ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
173 virtual ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
174 virtual bool eof_callback() = 0;
175 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
176 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
177 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
179 ::FLAC__SeekableStreamDecoder *decoder_;
181 static FLAC__SeekableStreamDecoderReadStatus read_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
182 static FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
183 static FLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
184 static FLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
185 static FLAC__bool eof_callback_(const ::FLAC__SeekableStreamDecoder *decoder, void *client_data);
186 static FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
187 static void metadata_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
188 static void error_callback_(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
190 // Private and undefined so you can't use them:
191 SeekableStream(const SeekableStream &);
192 void operator=(const SeekableStream &);
195 // ============================================================
197 // Equivalent: FLAC__FileDecoder
199 // ============================================================
205 inline State(::FLAC__FileDecoderState state): state_(state) { }
206 inline operator ::FLAC__FileDecoderState() const { return state_; }
207 inline const char *as_cstring() const { return ::FLAC__FileDecoderStateString[state_]; }
209 ::FLAC__FileDecoderState state_;
215 bool is_valid() const;
216 inline operator bool() const { return is_valid(); }
218 bool set_md5_checking(bool value);
219 bool set_filename(const char *value); // 'value' may not be 0; use "-" for stdin
220 bool set_metadata_respond(::FLAC__MetadataType type);
221 bool set_metadata_respond_application(const FLAC__byte id[4]);
222 bool set_metadata_respond_all();
223 bool set_metadata_ignore(::FLAC__MetadataType type);
224 bool set_metadata_ignore_application(const FLAC__byte id[4]);
225 bool set_metadata_ignore_all();
227 State get_state() const;
228 bool get_md5_checking() const;
229 unsigned get_channels() const;
230 ::FLAC__ChannelAssignment get_channel_assignment() const;
231 unsigned get_bits_per_sample() const;
232 unsigned get_sample_rate() const;
233 unsigned get_blocksize() const;
239 bool process_whole_file();
240 bool process_metadata();
241 bool process_one_frame();
242 bool process_remaining_frames();
244 bool seek_absolute(FLAC__uint64 sample);
246 virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
247 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
248 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
250 ::FLAC__FileDecoder *decoder_;
252 static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
253 static void metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
254 static void error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
256 // Private and undefined so you can't use them:
258 void operator=(const File &);