update copyright to 2004
[platform/upstream/flac.git] / include / OggFLAC++ / decoder.h
1 /* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2  * Copyright (C) 2002,2003,2004  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 OggFLACPP__DECODER_H
33 #define OggFLACPP__DECODER_H
34
35 #include "export.h"
36
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"
42
43
44 /** \file include/OggFLAC++/decoder.h
45  *
46  *  \brief
47  *  This module contains the classes which implement the various
48  *  decoders.
49  *
50  *  See the detailed documentation in the
51  *  \link oggflacpp_decoder decoder \endlink module.
52  */
53
54 /** \defgroup oggflacpp_decoder OggFLAC++/decoder.h: decoder classes
55  *  \ingroup oggflacpp
56  *
57  *  \brief
58  *  This module describes the three decoder layers provided by libOggFLAC++.
59  *
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.
64  *
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.
69  */
70
71 namespace OggFLAC {
72         namespace Decoder {
73
74                 // ============================================================
75                 //
76                 //  Equivalent: OggFLAC__StreamDecoder
77                 //
78                 // ============================================================
79
80                 /** \defgroup oggflacpp_stream_decoder OggFLAC++/decoder.h: stream decoder class
81                  *  \ingroup oggflacpp_decoder
82                  *
83                  *  \brief
84                  *  This class wraps the ::OggFLAC__StreamDecoder.
85                  *
86                  * See the \link oggflac_stream_decoder libOggFLAC stream decoder module \endlink.
87                  *
88                  * \{
89                  */
90
91                 /** This class wraps the ::OggFLAC__StreamDecoder.
92                  */
93                 class OggFLACPP_API Stream {
94                 public:
95                         class OggFLACPP_API State {
96                         public:
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_); }
101                         protected:
102                                 ::OggFLAC__StreamDecoderState state_;
103                         };
104
105                         Stream();
106                         virtual ~Stream();
107
108                         bool is_valid() const;
109                         inline operator bool() const { return is_valid(); }
110
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();
118
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;
126
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.
130                          */
131                         State init();
132
133                         void finish();
134
135                         bool flush();
136                         bool reset();
137
138                         bool process_single();
139                         bool process_until_end_of_metadata();
140                         bool process_until_end_of_stream();
141                 protected:
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;
146
147 #ifdef _MSC_VER
148                 //@@@@@@ lame hack: some MSVC versions can't see a protected decoder_ from nested State::resolved_as_cstring(); fix properly later
149                 public:
150 #endif
151                         ::OggFLAC__StreamDecoder *decoder_;
152                 private:
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);
157
158                         // Private and undefined so you can't use them:
159                         Stream(const Stream &);
160                         void operator=(const Stream &);
161                 };
162
163                 /* \} */
164
165                 // ============================================================
166                 //
167                 //  Equivalent: OggFLAC__SeekableStreamDecoder
168                 //
169                 // ============================================================
170
171                 /** \defgroup oggflacpp_seekable_stream_decoder OggFLAC++/decoder.h: seekable stream decoder class
172                  *  \ingroup oggflacpp_decoder
173                  *
174                  *  \brief
175                  *  This class wraps the ::OggFLAC__SeekableStreamDecoder.
176                  *
177                  * See the \link oggflac_seekable_stream_decoder libOggFLAC seekable stream decoder module \endlink.
178                  *
179                  * \{
180                  */
181
182                 /** This class wraps the ::OggFLAC__SeekableStreamDecoder.
183                  */
184                 class OggFLACPP_API SeekableStream {
185                 public:
186                         class OggFLACPP_API State {
187                         public:
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_); }
192                         protected:
193                                 ::OggFLAC__SeekableStreamDecoderState state_;
194                         };
195
196                         SeekableStream();
197                         virtual ~SeekableStream();
198
199                         bool is_valid() const;
200                         inline operator bool() const { return is_valid(); }
201
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();
210
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;
220
221                         State init();
222
223                         bool finish();
224
225                         bool flush();
226                         bool reset();
227
228                         bool process_single();
229                         bool process_until_end_of_metadata();
230                         bool process_until_end_of_stream();
231
232                         bool seek_absolute(FLAC__uint64 sample);
233                 protected:
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;
242
243 #ifdef _MSC_VER
244                 //@@@@@@ lame hack: some MSVC versions can't see a protected decoder_ from nested State::resolved_as_cstring(); fix properly later
245                 public:
246 #endif
247                         ::OggFLAC__SeekableStreamDecoder *decoder_;
248                 private:
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);
257
258                         // Private and undefined so you can't use them:
259                         SeekableStream(const SeekableStream &);
260                         void operator=(const SeekableStream &);
261                 };
262
263                 /* \} */
264
265                 // ============================================================
266                 //
267                 //  Equivalent: OggFLAC__FileDecoder
268                 //
269                 // ============================================================
270
271                 /** \defgroup oggflacpp_file_decoder OggFLAC++/decoder.h: file decoder class
272                  *  \ingroup oggflacpp_decoder
273                  *
274                  *  \brief
275                  *  This class wraps the ::OggFLAC__FileDecoder.
276                  *
277                  * See the \link oggflac_file_decoder libOggFLAC file decoder module \endlink.
278                  *
279                  * \{
280                  */
281
282                 /** This class wraps the ::OggFLAC__FileDecoder.
283                  */
284                 class OggFLACPP_API File {
285                 public:
286                         class OggFLACPP_API State {
287                         public:
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_); }
292                         protected:
293                                 ::OggFLAC__FileDecoderState state_;
294                         };
295
296                         File();
297                         virtual ~File();
298
299                         bool is_valid() const;
300                         inline operator bool() const { return is_valid(); }
301
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();
311
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;
322
323                         State init();
324
325                         bool finish();
326
327                         bool process_single();
328                         bool process_until_end_of_metadata();
329                         bool process_until_end_of_file();
330
331                         bool seek_absolute(FLAC__uint64 sample);
332                 protected:
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;
336
337 #ifdef _MSC_VER
338                 //@@@@@@ lame hack: some MSVC versions can't see a protected decoder_ from nested State::resolved_as_cstring(); fix properly later
339                 public:
340 #endif
341                         ::OggFLAC__FileDecoder *decoder_;
342                 private:
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);
346
347                         // Private and undefined so you can't use them:
348                         File(const File &);
349                         void operator=(const File &);
350                 };
351
352                 /* \} */
353
354         };
355 };
356
357 #endif