additions to metadata object api: more vorbiscomment functions, trailing-null on...
[platform/upstream/flac.git] / src / libFLAC++ / file_decoder.cpp
1 /* libFLAC++ - Free Lossless Audio Codec 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 #include "FLAC++/decoder.h"
33 #include "FLAC/assert.h"
34
35 #ifdef _MSC_VER
36 // warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)
37 #pragma warning ( disable : 4800 )
38 #endif
39
40 namespace FLAC {
41         namespace Decoder {
42
43                 File::File():
44                 decoder_(::FLAC__file_decoder_new())
45                 { }
46
47                 File::~File()
48                 {
49                         if(0 != decoder_) {
50                                 (void) ::FLAC__file_decoder_finish(decoder_);
51                                 ::FLAC__file_decoder_delete(decoder_);
52                         }
53                 }
54
55                 bool File::is_valid() const
56                 {
57                         return 0 != decoder_;
58                 }
59
60                 bool File::set_md5_checking(bool value)
61                 {
62                         FLAC__ASSERT(0 != decoder_);
63                         return (bool)::FLAC__file_decoder_set_md5_checking(decoder_, value);
64                 }
65
66                 bool File::set_filename(const char *value)
67                 {
68                         FLAC__ASSERT(0 != decoder_);
69                         return (bool)::FLAC__file_decoder_set_filename(decoder_, value);
70                 }
71
72                 bool File::set_metadata_respond(::FLAC__MetadataType type)
73                 {
74                         FLAC__ASSERT(0 != decoder_);
75                         return (bool)::FLAC__file_decoder_set_metadata_respond(decoder_, type);
76                 }
77
78                 bool File::set_metadata_respond_application(const FLAC__byte id[4])
79                 {
80                         FLAC__ASSERT(0 != decoder_);
81                         return (bool)::FLAC__file_decoder_set_metadata_respond_application(decoder_, id);
82                 }
83
84                 bool File::set_metadata_respond_all()
85                 {
86                         FLAC__ASSERT(0 != decoder_);
87                         return (bool)::FLAC__file_decoder_set_metadata_respond_all(decoder_);
88                 }
89
90                 bool File::set_metadata_ignore(::FLAC__MetadataType type)
91                 {
92                         FLAC__ASSERT(0 != decoder_);
93                         return (bool)::FLAC__file_decoder_set_metadata_ignore(decoder_, type);
94                 }
95
96                 bool File::set_metadata_ignore_application(const FLAC__byte id[4])
97                 {
98                         FLAC__ASSERT(0 != decoder_);
99                         return (bool)::FLAC__file_decoder_set_metadata_ignore_application(decoder_, id);
100                 }
101
102                 bool File::set_metadata_ignore_all()
103                 {
104                         FLAC__ASSERT(0 != decoder_);
105                         return (bool)::FLAC__file_decoder_set_metadata_ignore_all(decoder_);
106                 }
107
108                 File::State File::get_state() const
109                 {
110                         FLAC__ASSERT(0 != decoder_);
111                         return State(::FLAC__file_decoder_get_state(decoder_));
112                 }
113
114                 SeekableStream::State File::get_seekable_stream_decoder_state() const
115                 {
116                         FLAC__ASSERT(0 != decoder_);
117                         return SeekableStream::State(::FLAC__file_decoder_get_seekable_stream_decoder_state(decoder_));
118                 }
119
120                 Stream::State File::get_stream_decoder_state() const
121                 {
122                         FLAC__ASSERT(0 != decoder_);
123                         return Stream::State(::FLAC__file_decoder_get_stream_decoder_state(decoder_));
124                 }
125
126                 bool File::get_md5_checking() const
127                 {
128                         FLAC__ASSERT(0 != decoder_);
129                         return (bool)::FLAC__file_decoder_get_md5_checking(decoder_);
130                 }
131
132                 unsigned File::get_channels() const
133                 {
134                         FLAC__ASSERT(is_valid());
135                         return ::FLAC__file_decoder_get_channels(decoder_);
136                 }
137
138                 ::FLAC__ChannelAssignment File::get_channel_assignment() const
139                 {
140                         FLAC__ASSERT(is_valid());
141                         return ::FLAC__file_decoder_get_channel_assignment(decoder_);
142                 }
143
144                 unsigned File::get_bits_per_sample() const
145                 {
146                         FLAC__ASSERT(is_valid());
147                         return ::FLAC__file_decoder_get_bits_per_sample(decoder_);
148                 }
149
150                 unsigned File::get_sample_rate() const
151                 {
152                         FLAC__ASSERT(is_valid());
153                         return ::FLAC__file_decoder_get_sample_rate(decoder_);
154                 }
155
156                 unsigned File::get_blocksize() const
157                 {
158                         FLAC__ASSERT(is_valid());
159                         return ::FLAC__file_decoder_get_blocksize(decoder_);
160                 }
161
162                 File::State File::init()
163                 {
164                         FLAC__ASSERT(0 != decoder_);
165                         ::FLAC__file_decoder_set_write_callback(decoder_, write_callback_);
166                         ::FLAC__file_decoder_set_metadata_callback(decoder_, metadata_callback_);
167                         ::FLAC__file_decoder_set_error_callback(decoder_, error_callback_);
168                         ::FLAC__file_decoder_set_client_data(decoder_, (void*)this);
169                         return State(::FLAC__file_decoder_init(decoder_));
170                 }
171
172                 bool File::finish()
173                 {
174                         FLAC__ASSERT(0 != decoder_);
175                         return (bool)::FLAC__file_decoder_finish(decoder_);
176                 }
177
178                 bool File::process_single()
179                 {
180                         FLAC__ASSERT(0 != decoder_);
181                         return (bool)::FLAC__file_decoder_process_single(decoder_);
182                 }
183
184                 bool File::process_until_end_of_metadata()
185                 {
186                         FLAC__ASSERT(0 != decoder_);
187                         return (bool)::FLAC__file_decoder_process_until_end_of_metadata(decoder_);
188                 }
189
190                 bool File::process_until_end_of_file()
191                 {
192                         FLAC__ASSERT(0 != decoder_);
193                         return (bool)::FLAC__file_decoder_process_until_end_of_file(decoder_);
194                 }
195
196                 bool File::skip_single_frame()
197                 {
198                         FLAC__ASSERT(is_valid());
199                         return (bool)::FLAC__file_decoder_skip_single_frame(decoder_);
200                 }
201
202                 bool File::seek_absolute(FLAC__uint64 sample)
203                 {
204                         FLAC__ASSERT(0 != decoder_);
205                         return (bool)::FLAC__file_decoder_seek_absolute(decoder_, sample);
206                 }
207
208                 ::FLAC__StreamDecoderWriteStatus File::write_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
209                 {
210                         (void) decoder;
211                         FLAC__ASSERT(0 != client_data);
212                         File *instance = reinterpret_cast<File *>(client_data);
213                         FLAC__ASSERT(0 != instance);
214                         return instance->write_callback(frame, buffer);
215                 }
216
217                 void File::metadata_callback_(const ::FLAC__FileDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data)
218                 {
219                         (void) decoder;
220                         FLAC__ASSERT(0 != client_data);
221                         File *instance = reinterpret_cast<File *>(client_data);
222                         FLAC__ASSERT(0 != instance);
223                         instance->metadata_callback(metadata);
224                 }
225
226                 void File::error_callback_(const ::FLAC__FileDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data)
227                 {
228                         (void) decoder;
229                         FLAC__ASSERT(0 != client_data);
230                         File *instance = reinterpret_cast<File *>(client_data);
231                         FLAC__ASSERT(0 != instance);
232                         instance->error_callback(status);
233                 }
234
235         };
236 };