inline *::State::resolved_as_cstring()
[platform/upstream/flac.git] / include / FLAC++ / decoder.h
1 /* libFLAC++ - Free Lossless Audio Codec library
2  * Copyright (C) 2002,2003  Josh Coalson
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
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.
14  *
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.
18  *
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.
30  */
31
32 #ifndef FLACPP__DECODER_H
33 #define FLACPP__DECODER_H
34
35 #include "export.h"
36
37 #include "FLAC/file_decoder.h"
38 #include "FLAC/seekable_stream_decoder.h"
39 #include "FLAC/stream_decoder.h"
40
41
42 /** \file include/FLAC++/decoder.h
43  *
44  *  \brief
45  *  This module contains the classes which implement the various
46  *  decoders.
47  *
48  *  See the detailed documentation in the
49  *  \link flacpp_decoder decoder \endlink module.
50  */
51
52 /** \defgroup flacpp_decoder FLAC++/decoder.h: decoder classes
53  *  \ingroup flacpp
54  *
55  *  \brief
56  *  This module describes the three decoder layers provided by libFLAC++.
57  *
58  * The libFLAC++ decoder classes are object wrappers around their
59  * counterparts in libFLAC.  All three decoding layers available in
60  * libFLAC are also provided here.  The interface is very similar;
61  * make sure to read the \link flac_decoder libFLAC decoder module \endlink.
62  *
63  * The only real difference here is that instead of passing in C function
64  * pointers for callbacks, you inherit from the decoder class and provide
65  * implementations for the callbacks in the derived class; because of this
66  * there is no need for a 'client_data' property.
67  */
68
69 namespace FLAC {
70         namespace Decoder {
71
72                 // ============================================================
73                 //
74                 //  Equivalent: FLAC__StreamDecoder
75                 //
76                 // ============================================================
77
78                 /** \defgroup flacpp_stream_decoder FLAC++/decoder.h: stream decoder class
79                  *  \ingroup flacpp_decoder
80                  *
81                  *  \brief
82                  *  This class wraps the ::FLAC__StreamDecoder.
83                  *
84                  * See the \link flac_stream_decoder libFLAC stream decoder module \endlink.
85                  *
86                  * \{
87                  */
88
89                 /** This class wraps the ::FLAC__StreamDecoder.
90                  */
91                 class FLACPP_API Stream {
92                 public:
93                         class FLACPP_API State {
94                         public:
95                                 inline State(::FLAC__StreamDecoderState state): state_(state) { }
96                                 inline operator ::FLAC__StreamDecoderState() const { return state_; }
97                                 inline const char *as_cstring() const { return ::FLAC__StreamDecoderStateString[state_]; }
98                         protected:
99                                 ::FLAC__StreamDecoderState state_;
100                         };
101
102                         Stream();
103                         virtual ~Stream();
104
105                         bool is_valid() const;
106                         inline operator bool() const { return is_valid(); }
107
108                         bool set_metadata_respond(::FLAC__MetadataType type);
109                         bool set_metadata_respond_application(const FLAC__byte id[4]);
110                         bool set_metadata_respond_all();
111                         bool set_metadata_ignore(::FLAC__MetadataType type);
112                         bool set_metadata_ignore_application(const FLAC__byte id[4]);
113                         bool set_metadata_ignore_all();
114
115                         State get_state() const;
116                         unsigned get_channels() const;
117                         ::FLAC__ChannelAssignment get_channel_assignment() const;
118                         unsigned get_bits_per_sample() const;
119                         unsigned get_sample_rate() const;
120                         unsigned get_blocksize() const;
121
122                         /** Initialize the instance; as with the C interface,
123                          *  init() should be called after construction and 'set'
124                          *  calls but before any of the 'process' calls.
125                          */
126                         State init();
127
128                         void finish();
129
130                         bool flush();
131                         bool reset();
132
133                         bool process_single();
134                         bool process_until_end_of_metadata();
135                         bool process_until_end_of_stream();
136                 protected:
137                         virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
138                         virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
139                         virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
140                         virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
141
142                         ::FLAC__StreamDecoder *decoder_;
143                 private:
144                         static ::FLAC__StreamDecoderReadStatus read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
145                         static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
146                         static void metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
147                         static void error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
148
149                         // Private and undefined so you can't use them:
150                         Stream(const Stream &);
151                         void operator=(const Stream &);
152                 };
153
154                 /* \} */
155
156
157                 // ============================================================
158                 //
159                 //  Equivalent: FLAC__SeekableStreamDecoder
160                 //
161                 // ============================================================
162
163                 /** \defgroup flacpp_seekable_stream_decoder FLAC++/decoder.h: seekable stream decoder class
164                  *  \ingroup flacpp_decoder
165                  *
166                  *  \brief
167                  *  This class wraps the ::FLAC__SeekableStreamDecoder.
168                  *
169                  * See the \link flac_seekable_stream_decoder libFLAC seekable stream decoder module \endlink.
170                  *
171                  * \{
172                  */
173
174                 /** This class wraps the ::FLAC__SeekableStreamDecoder.
175                  */
176                 class FLACPP_API SeekableStream {
177                 public:
178                         class FLACPP_API State {
179                         public:
180                                 inline State(::FLAC__SeekableStreamDecoderState state): state_(state) { }
181                                 inline operator ::FLAC__SeekableStreamDecoderState() const { return state_; }
182                                 inline const char *as_cstring() const { return ::FLAC__SeekableStreamDecoderStateString[state_]; }
183                                 inline const char *resolved_as_cstring(const SeekableStream &decoder) const { return ::FLAC__seekable_stream_decoder_get_resolved_state_string(decoder.decoder_); }
184                         protected:
185                                 ::FLAC__SeekableStreamDecoderState state_;
186                         };
187
188                         SeekableStream();
189                         virtual ~SeekableStream();
190
191                         bool is_valid() const;
192                         inline operator bool() const { return is_valid(); }
193
194                         bool set_md5_checking(bool value);
195                         bool set_metadata_respond(::FLAC__MetadataType type);
196                         bool set_metadata_respond_application(const FLAC__byte id[4]);
197                         bool set_metadata_respond_all();
198                         bool set_metadata_ignore(::FLAC__MetadataType type);
199                         bool set_metadata_ignore_application(const FLAC__byte id[4]);
200                         bool set_metadata_ignore_all();
201
202                         State get_state() const;
203                         Stream::State get_stream_decoder_state() const;
204                         bool get_md5_checking() const;
205                         unsigned get_channels() const;
206                         ::FLAC__ChannelAssignment get_channel_assignment() const;
207                         unsigned get_bits_per_sample() const;
208                         unsigned get_sample_rate() const;
209                         unsigned get_blocksize() const;
210
211                         State init();
212
213                         bool finish();
214
215                         bool flush();
216                         bool reset();
217
218                         bool process_single();
219                         bool process_until_end_of_metadata();
220                         bool process_until_end_of_stream();
221
222                         bool seek_absolute(FLAC__uint64 sample);
223                 protected:
224                         virtual ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
225                         virtual ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
226                         virtual ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
227                         virtual ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
228                         virtual bool eof_callback() = 0;
229                         virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
230                         virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
231                         virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
232
233                         ::FLAC__SeekableStreamDecoder *decoder_;
234                 private:
235                         static ::FLAC__SeekableStreamDecoderReadStatus read_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
236                         static ::FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
237                         static ::FLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
238                         static ::FLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
239                         static FLAC__bool eof_callback_(const ::FLAC__SeekableStreamDecoder *decoder, void *client_data);
240                         static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
241                         static void metadata_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
242                         static void error_callback_(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
243
244                         // Private and undefined so you can't use them:
245                         SeekableStream(const SeekableStream &);
246                         void operator=(const SeekableStream &);
247                 };
248
249                 /* \} */
250
251
252                 // ============================================================
253                 //
254                 //  Equivalent: FLAC__FileDecoder
255                 //
256                 // ============================================================
257
258                 /** \defgroup flacpp_file_decoder FLAC++/decoder.h: file decoder class
259                  *  \ingroup flacpp_decoder
260                  *
261                  *  \brief
262                  *  This class wraps the ::FLAC__FileDecoder.
263                  *
264                  * See the \link flac_file_decoder libFLAC file decoder module \endlink.
265                  *
266                  * \{
267                  */
268
269                 /** This class wraps the ::FLAC__FileDecoder.
270                  */
271                 class FLACPP_API File {
272                 public:
273                         class FLACPP_API State {
274                         public:
275                                 inline State(::FLAC__FileDecoderState state): state_(state) { }
276                                 inline operator ::FLAC__FileDecoderState() const { return state_; }
277                                 inline const char *as_cstring() const { return ::FLAC__FileDecoderStateString[state_]; }
278                                 inline const char *resolved_as_cstring(const File &decoder) const { return ::FLAC__file_decoder_get_resolved_state_string(decoder.decoder_); }
279                         protected:
280                                 ::FLAC__FileDecoderState state_;
281                         };
282
283                         File();
284                         virtual ~File();
285
286                         bool is_valid() const;
287                         inline operator bool() const { return is_valid(); }
288
289                         bool set_md5_checking(bool value);
290                         bool set_filename(const char *value); //!< 'value' may not be \c NULL; use "-" for stdin
291                         bool set_metadata_respond(::FLAC__MetadataType type);
292                         bool set_metadata_respond_application(const FLAC__byte id[4]);
293                         bool set_metadata_respond_all();
294                         bool set_metadata_ignore(::FLAC__MetadataType type);
295                         bool set_metadata_ignore_application(const FLAC__byte id[4]);
296                         bool set_metadata_ignore_all();
297
298                         State get_state() const;
299                         SeekableStream::State get_seekable_stream_decoder_state() const;
300                         Stream::State get_stream_decoder_state() const;
301                         bool get_md5_checking() const;
302                         unsigned get_channels() const;
303                         ::FLAC__ChannelAssignment get_channel_assignment() const;
304                         unsigned get_bits_per_sample() const;
305                         unsigned get_sample_rate() const;
306                         unsigned get_blocksize() const;
307
308                         State init();
309
310                         bool finish();
311
312                         bool process_single();
313                         bool process_until_end_of_metadata();
314                         bool process_until_end_of_file();
315
316                         bool seek_absolute(FLAC__uint64 sample);
317                 protected:
318                         virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]) = 0;
319                         virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) = 0;
320                         virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
321
322                         ::FLAC__FileDecoder *decoder_;
323                 private:
324                         static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
325                         static void metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data);
326                         static void error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
327
328                         // Private and undefined so you can't use them:
329                         File(const File &);
330                         void operator=(const File &);
331                 };
332
333                 /* \} */
334
335         };
336 };
337
338 #endif