initial import
[platform/upstream/flac.git] / include / FLAC++ / decoder.h
1 /* libFLAC++ - Free Lossless Audio Codec library
2  * Copyright (C) 2002  Josh Coalson
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifndef FLACPP__DECODER_H
21 #define FLACPP__DECODER_H
22
23 #include "FLAC/file_decoder.h"
24 #include "FLAC/seekable_stream_decoder.h"
25 #include "FLAC/stream_decoder.h"
26
27 // ===============================================================
28 //
29 //  Full documentation for the decoder interfaces can be found
30 //  in the C layer in include/FLAC/*_decoder.h
31 //
32 // ===============================================================
33
34
35 namespace FLAC {
36         namespace Decoder {
37
38                 // ============================================================
39                 //
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.
45                 //
46                 // ============================================================
47
48                 // ============================================================
49                 //
50                 //  Equivalent: FLAC__StreamDecoder
51                 //
52                 // ============================================================
53
54                 class Stream {
55                 public:
56                         class State {
57                         public:
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_]; }
61                         protected:
62                                 ::FLAC__StreamDecoderState state_;
63                         };
64
65                         Stream();
66                         virtual ~Stream();
67
68                         bool is_valid() const;
69                         inline operator bool() const { return is_valid(); }
70
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();
77
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;
84
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.
88                         State init();
89
90                         void finish();
91
92                         bool flush();
93                         bool reset();
94
95                         bool process_whole_stream();
96                         bool process_metadata();
97                         bool process_one_frame();
98                         bool process_remaining_frames();
99                 protected:
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 *buffer[]) = 0;
102                         virtual void metadata_callback(const ::FLAC__StreamMetaData *metadata) = 0;
103                         virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
104
105                         ::FLAC__StreamDecoder *decoder_;
106                 private:
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 *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);
111
112                         // Private and undefined so you can't use them:
113                         Stream(const Stream &);
114                         void operator=(const Stream &);
115                 };
116
117                 // ============================================================
118                 //
119                 //  Equivalent: FLAC__SeekableStreamDecoder
120                 //
121                 // ============================================================
122
123                 class SeekableStream {
124                 public:
125                         class State {
126                         public:
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_]; }
130                         protected:
131                                 ::FLAC__SeekableStreamDecoderState state_;
132                         };
133
134                         SeekableStream();
135                         virtual ~SeekableStream();
136
137                         bool is_valid() const;
138                         inline operator bool() const { return is_valid(); }
139
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();
147
148                         State get_state() const;
149                         bool get_md5_checking() const;
150
151                         State init();
152
153                         bool finish();
154
155                         bool process_whole_stream();
156                         bool process_metadata();
157                         bool process_one_frame();
158                         bool process_remaining_frames();
159
160                         bool seek_absolute(FLAC__uint64 sample);
161                 protected:
162                         virtual ::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes) = 0;
163                         virtual ::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset) = 0;
164                         virtual ::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset) = 0;
165                         virtual ::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length) = 0;
166                         virtual bool eof_callback() = 0;
167                         virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 *buffer[]) = 0;
168                         virtual void metadata_callback(const ::FLAC__StreamMetaData *metadata) = 0;
169                         virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
170
171                         ::FLAC__SeekableStreamDecoder *decoder_;
172                 private:
173                         static FLAC__SeekableStreamDecoderReadStatus read_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
174                         static FLAC__SeekableStreamDecoderSeekStatus seek_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
175                         static FLAC__SeekableStreamDecoderTellStatus tell_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
176                         static FLAC__SeekableStreamDecoderLengthStatus length_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
177                         static FLAC__bool eof_callback_(const ::FLAC__SeekableStreamDecoder *decoder, void *client_data);
178                         static FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 *buffer[], void *client_data);
179                         static void metadata_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetaData *metadata, void *client_data);
180                         static void error_callback_(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
181
182                         // Private and undefined so you can't use them:
183                         SeekableStream(const SeekableStream &);
184                         void operator=(const SeekableStream &);
185                 };
186
187                 // ============================================================
188                 //
189                 //  Equivalent: FLAC__FileDecoder
190                 //
191                 // ============================================================
192
193                 class File {
194                 public:
195                         class State {
196                         public:
197                                 inline State(::FLAC__FileDecoderState state): state_(state) { }
198                                 inline operator ::FLAC__FileDecoderState() const { return state_; }
199                                 inline const char *as_cstring() const { return ::FLAC__FileDecoderStateString[state_]; }
200                         protected:
201                                 ::FLAC__FileDecoderState state_;
202                         };
203
204                         File();
205                         virtual ~File();
206
207                         bool is_valid() const;
208                         inline operator bool() const { return is_valid(); }
209
210                         bool set_md5_checking(bool value);
211                         bool set_filename(const char *value); // 'value' may not be 0; use "-" for stdin
212                         bool set_metadata_respond(::FLAC__MetaDataType type);
213                         bool set_metadata_respond_application(const FLAC__byte id[4]);
214                         bool set_metadata_respond_all();
215                         bool set_metadata_ignore(::FLAC__MetaDataType type);
216                         bool set_metadata_ignore_application(const FLAC__byte id[4]);
217                         bool set_metadata_ignore_all();
218
219                         State get_state() const;
220                         bool get_md5_checking() const;
221
222                         State init();
223
224                         bool finish();
225
226                         bool process_whole_file();
227                         bool process_metadata();
228                         bool process_one_frame();
229                         bool process_remaining_frames();
230
231                         bool seek_absolute(FLAC__uint64 sample);
232                 protected:
233                         virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 *buffer[]) = 0;
234                         virtual void metadata_callback(const ::FLAC__StreamMetaData *metadata) = 0;
235                         virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) = 0;
236
237                         ::FLAC__FileDecoder *decoder_;
238                 private:
239                         static ::FLAC__StreamDecoderWriteStatus write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 *buffer[], void *client_data);
240                         static void metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetaData *metadata, void *client_data);
241                         static void error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data);
242
243                         // Private and undefined so you can't use them:
244                         File(const File &);
245                         void operator=(const File &);
246                 };
247
248         };
249 };
250
251 #endif