another big glob of changes/fixes
[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 * const 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 * 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);
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                         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;
155
156                         State init();
157
158                         bool finish();
159
160                         bool flush();
161                         bool reset();
162
163                         bool process_whole_stream();
164                         bool process_metadata();
165                         bool process_one_frame();
166                         bool process_remaining_frames();
167
168                         bool seek_absolute(FLAC__uint64 sample);
169                 protected:
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;
178
179                         ::FLAC__SeekableStreamDecoder *decoder_;
180                 private:
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);
189
190                         // Private and undefined so you can't use them:
191                         SeekableStream(const SeekableStream &);
192                         void operator=(const SeekableStream &);
193                 };
194
195                 // ============================================================
196                 //
197                 //  Equivalent: FLAC__FileDecoder
198                 //
199                 // ============================================================
200
201                 class File {
202                 public:
203                         class State {
204                         public:
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_]; }
208                         protected:
209                                 ::FLAC__FileDecoderState state_;
210                         };
211
212                         File();
213                         virtual ~File();
214
215                         bool is_valid() const;
216                         inline operator bool() const { return is_valid(); }
217
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();
226
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;
234
235                         State init();
236
237                         bool finish();
238
239                         bool process_whole_file();
240                         bool process_metadata();
241                         bool process_one_frame();
242                         bool process_remaining_frames();
243
244                         bool seek_absolute(FLAC__uint64 sample);
245                 protected:
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;
249
250                         ::FLAC__FileDecoder *decoder_;
251                 private:
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);
255
256                         // Private and undefined so you can't use them:
257                         File(const File &);
258                         void operator=(const File &);
259                 };
260
261         };
262 };
263
264 #endif