fixes based on MSVC compile
[flac.git] / src / libFLAC++ / seekable_stream_decoder.cc
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 #include "FLAC++/decoder.h"
21 #include "FLAC/assert.h"
22
23 namespace FLAC {
24         namespace Decoder {
25
26                 SeekableStream::SeekableStream():
27                 decoder_(::FLAC__seekable_stream_decoder_new())
28                 { }
29
30                 SeekableStream::~SeekableStream()
31                 {
32                         if(0 != decoder_) {
33                                 (void) ::FLAC__seekable_stream_decoder_finish(decoder_);
34                                 ::FLAC__seekable_stream_decoder_delete(decoder_);
35                         }
36                 }
37
38                 bool SeekableStream::is_valid() const
39                 {
40                         return 0 != decoder_;
41                 }
42
43                 bool SeekableStream::set_md5_checking(bool value)
44                 {
45                         FLAC__ASSERT(is_valid());
46                         return (bool)::FLAC__seekable_stream_decoder_set_md5_checking(decoder_, value);
47                 }
48
49                 bool SeekableStream::set_metadata_respond(::FLAC__MetaDataType type)
50                 {
51                         FLAC__ASSERT(is_valid());
52                         return (bool)::FLAC__seekable_stream_decoder_set_metadata_respond(decoder_, type);
53                 }
54
55                 bool SeekableStream::set_metadata_respond_application(const FLAC__byte id[4])
56                 {
57                         FLAC__ASSERT(is_valid());
58                         return (bool)::FLAC__seekable_stream_decoder_set_metadata_respond_application(decoder_, id);
59                 }
60
61                 bool SeekableStream::set_metadata_respond_all()
62                 {
63                         FLAC__ASSERT(is_valid());
64                         return (bool)::FLAC__seekable_stream_decoder_set_metadata_respond_all(decoder_);
65                 }
66
67                 bool SeekableStream::set_metadata_ignore(::FLAC__MetaDataType type)
68                 {
69                         FLAC__ASSERT(is_valid());
70                         return (bool)::FLAC__seekable_stream_decoder_set_metadata_ignore(decoder_, type);
71                 }
72
73                 bool SeekableStream::set_metadata_ignore_application(const FLAC__byte id[4])
74                 {
75                         FLAC__ASSERT(is_valid());
76                         return (bool)::FLAC__seekable_stream_decoder_set_metadata_ignore_application(decoder_, id);
77                 }
78
79                 bool SeekableStream::set_metadata_ignore_all()
80                 {
81                         FLAC__ASSERT(is_valid());
82                         return (bool)::FLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder_);
83                 }
84
85                 SeekableStream::State SeekableStream::get_state() const
86                 {
87                         FLAC__ASSERT(is_valid());
88                         return State(::FLAC__seekable_stream_decoder_get_state(decoder_));
89                 }
90
91                 bool SeekableStream::get_md5_checking() const
92                 {
93                         FLAC__ASSERT(is_valid());
94                         return (bool)::FLAC__seekable_stream_decoder_get_md5_checking(decoder_);
95                 }
96
97                 SeekableStream::State SeekableStream::init()
98                 {
99                         FLAC__ASSERT(is_valid());
100                         ::FLAC__seekable_stream_decoder_set_read_callback(decoder_, read_callback_);
101                         ::FLAC__seekable_stream_decoder_set_seek_callback(decoder_, seek_callback_);
102                         ::FLAC__seekable_stream_decoder_set_tell_callback(decoder_, tell_callback_);
103                         ::FLAC__seekable_stream_decoder_set_length_callback(decoder_, length_callback_);
104                         ::FLAC__seekable_stream_decoder_set_eof_callback(decoder_, eof_callback_);
105                         ::FLAC__seekable_stream_decoder_set_write_callback(decoder_, write_callback_);
106                         ::FLAC__seekable_stream_decoder_set_metadata_callback(decoder_, metadata_callback_);
107                         ::FLAC__seekable_stream_decoder_set_error_callback(decoder_, error_callback_);
108                         ::FLAC__seekable_stream_decoder_set_client_data(decoder_, (void*)this);
109                         return State(::FLAC__seekable_stream_decoder_init(decoder_));
110                 }
111
112                 bool SeekableStream::finish()
113                 {
114                         FLAC__ASSERT(is_valid());
115                         return (bool)::FLAC__seekable_stream_decoder_finish(decoder_);
116                 }
117
118                 bool SeekableStream::process_whole_stream()
119                 {
120                         FLAC__ASSERT(is_valid());
121                         return (bool)::FLAC__seekable_stream_decoder_process_whole_stream(decoder_);
122                 }
123
124                 bool SeekableStream::process_metadata()
125                 {
126                         FLAC__ASSERT(is_valid());
127                         return (bool)::FLAC__seekable_stream_decoder_process_metadata(decoder_);
128                 }
129
130                 bool SeekableStream::process_one_frame()
131                 {
132                         FLAC__ASSERT(is_valid());
133                         return (bool)::FLAC__seekable_stream_decoder_process_one_frame(decoder_);
134                 }
135
136                 bool SeekableStream::process_remaining_frames()
137                 {
138                         FLAC__ASSERT(is_valid());
139                         return (bool)::FLAC__seekable_stream_decoder_process_remaining_frames(decoder_);
140                 }
141
142                 bool SeekableStream::seek_absolute(FLAC__uint64 sample)
143                 {
144                         FLAC__ASSERT(is_valid());
145                         return (bool)::FLAC__seekable_stream_decoder_seek_absolute(decoder_, sample);
146                 }
147
148                 FLAC__SeekableStreamDecoderReadStatus SeekableStream::read_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
149                 {
150                         (void) decoder;
151                         FLAC__ASSERT(0 != client_data);
152                         SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
153                         FLAC__ASSERT(0 != instance);
154                         return instance->read_callback(buffer, bytes);
155                 }
156
157                 FLAC__SeekableStreamDecoderSeekStatus SeekableStream::seek_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
158                 {
159                         (void) decoder;
160                         FLAC__ASSERT(0 != client_data);
161                         SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
162                         FLAC__ASSERT(0 != instance);
163                         return instance->seek_callback(absolute_byte_offset);
164                 }
165
166                 FLAC__SeekableStreamDecoderTellStatus SeekableStream::tell_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
167                 {
168                         (void) decoder;
169                         FLAC__ASSERT(0 != client_data);
170                         SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
171                         FLAC__ASSERT(0 != instance);
172                         return instance->tell_callback(absolute_byte_offset);
173                 }
174
175                 FLAC__SeekableStreamDecoderLengthStatus SeekableStream::length_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
176                 {
177                         (void) decoder;
178                         FLAC__ASSERT(0 != client_data);
179                         SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
180                         FLAC__ASSERT(0 != instance);
181                         return instance->length_callback(stream_length);
182                 }
183
184                 FLAC__bool SeekableStream::eof_callback_(const ::FLAC__SeekableStreamDecoder *decoder, void *client_data)
185                 {
186                         (void) decoder;
187                         FLAC__ASSERT(0 != client_data);
188                         SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
189                         FLAC__ASSERT(0 != instance);
190                         return instance->eof_callback();
191                 }
192
193                 FLAC__StreamDecoderWriteStatus SeekableStream::write_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 *buffer[], void *client_data)
194                 {
195                         (void) decoder;
196                         FLAC__ASSERT(0 != client_data);
197                         SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
198                         FLAC__ASSERT(0 != instance);
199                         return instance->write_callback(frame, buffer);
200                 }
201
202                 void SeekableStream::metadata_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetaData *metadata, void *client_data)
203                 {
204                         (void) decoder;
205                         FLAC__ASSERT(0 != client_data);
206                         SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
207                         FLAC__ASSERT(0 != instance);
208                         instance->metadata_callback(metadata);
209                 }
210
211                 void SeekableStream::error_callback_(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data)
212                 {
213                         (void) decoder;
214                         FLAC__ASSERT(0 != client_data);
215                         SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
216                         FLAC__ASSERT(0 != instance);
217                         instance->error_callback(status);
218                 }
219
220         };
221 };