Add 2003 to copyright notice
[platform/upstream/flac.git] / src / libFLAC++ / stream_decoder.cpp
1 /* libFLAC++ - Free Lossless Audio Codec library
2  * Copyright (C) 2002,2003  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                 const char *Stream::State::resolved_as_cstring(const Stream &) const
27                 {
28                         return as_cstring();
29                 }
30
31                 Stream::Stream():
32                 decoder_(::FLAC__stream_decoder_new())
33                 { }
34
35                 Stream::~Stream()
36                 {
37                         if(0 != decoder_) {
38                                 ::FLAC__stream_decoder_finish(decoder_);
39                                 ::FLAC__stream_decoder_delete(decoder_);
40                         }
41                 }
42
43                 bool Stream::is_valid() const
44                 {
45                         return 0 != decoder_;
46                 }
47
48                 bool Stream::set_metadata_respond(::FLAC__MetadataType type)
49                 {
50                         FLAC__ASSERT(is_valid());
51                         return (bool)::FLAC__stream_decoder_set_metadata_respond(decoder_, type);
52                 }
53
54                 bool Stream::set_metadata_respond_application(const FLAC__byte id[4])
55                 {
56                         FLAC__ASSERT(is_valid());
57                         return (bool)::FLAC__stream_decoder_set_metadata_respond_application(decoder_, id);
58                 }
59
60                 bool Stream::set_metadata_respond_all()
61                 {
62                         FLAC__ASSERT(is_valid());
63                         return (bool)::FLAC__stream_decoder_set_metadata_respond_all(decoder_);
64                 }
65
66                 bool Stream::set_metadata_ignore(::FLAC__MetadataType type)
67                 {
68                         FLAC__ASSERT(is_valid());
69                         return (bool)::FLAC__stream_decoder_set_metadata_ignore(decoder_, type);
70                 }
71
72                 bool Stream::set_metadata_ignore_application(const FLAC__byte id[4])
73                 {
74                         FLAC__ASSERT(is_valid());
75                         return (bool)::FLAC__stream_decoder_set_metadata_ignore_application(decoder_, id);
76                 }
77
78                 bool Stream::set_metadata_ignore_all()
79                 {
80                         FLAC__ASSERT(is_valid());
81                         return (bool)::FLAC__stream_decoder_set_metadata_ignore_all(decoder_);
82                 }
83
84                 Stream::State Stream::get_state() const
85                 {
86                         FLAC__ASSERT(is_valid());
87                         return State(::FLAC__stream_decoder_get_state(decoder_));
88                 }
89
90                 unsigned Stream::get_channels() const
91                 {
92                         FLAC__ASSERT(is_valid());
93                         return ::FLAC__stream_decoder_get_channels(decoder_);
94                 }
95
96                 ::FLAC__ChannelAssignment Stream::get_channel_assignment() const
97                 {
98                         FLAC__ASSERT(is_valid());
99                         return ::FLAC__stream_decoder_get_channel_assignment(decoder_);
100                 }
101
102                 unsigned Stream::get_bits_per_sample() const
103                 {
104                         FLAC__ASSERT(is_valid());
105                         return ::FLAC__stream_decoder_get_bits_per_sample(decoder_);
106                 }
107
108                 unsigned Stream::get_sample_rate() const
109                 {
110                         FLAC__ASSERT(is_valid());
111                         return ::FLAC__stream_decoder_get_sample_rate(decoder_);
112                 }
113
114                 unsigned Stream::get_blocksize() const
115                 {
116                         FLAC__ASSERT(is_valid());
117                         return ::FLAC__stream_decoder_get_blocksize(decoder_);
118                 }
119
120                 Stream::State Stream::init()
121                 {
122                         FLAC__ASSERT(is_valid());
123                         ::FLAC__stream_decoder_set_read_callback(decoder_, read_callback_);
124                         ::FLAC__stream_decoder_set_write_callback(decoder_, write_callback_);
125                         ::FLAC__stream_decoder_set_metadata_callback(decoder_, metadata_callback_);
126                         ::FLAC__stream_decoder_set_error_callback(decoder_, error_callback_);
127                         ::FLAC__stream_decoder_set_client_data(decoder_, (void*)this);
128                         return State(::FLAC__stream_decoder_init(decoder_));
129                 }
130
131                 void Stream::finish()
132                 {
133                         FLAC__ASSERT(is_valid());
134                         ::FLAC__stream_decoder_finish(decoder_);
135                 }
136
137                 bool Stream::flush()
138                 {
139                         FLAC__ASSERT(is_valid());
140                         return (bool)::FLAC__stream_decoder_flush(decoder_);
141                 }
142
143                 bool Stream::reset()
144                 {
145                         FLAC__ASSERT(is_valid());
146                         return (bool)::FLAC__stream_decoder_reset(decoder_);
147                 }
148
149                 bool Stream::process_single()
150                 {
151                         FLAC__ASSERT(is_valid());
152                         return (bool)::FLAC__stream_decoder_process_single(decoder_);
153                 }
154
155                 bool Stream::process_until_end_of_metadata()
156                 {
157                         FLAC__ASSERT(is_valid());
158                         return (bool)::FLAC__stream_decoder_process_until_end_of_metadata(decoder_);
159                 }
160
161                 bool Stream::process_until_end_of_stream()
162                 {
163                         FLAC__ASSERT(is_valid());
164                         return (bool)::FLAC__stream_decoder_process_until_end_of_stream(decoder_);
165                 }
166
167                 ::FLAC__StreamDecoderReadStatus Stream::read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
168                 {
169                         (void)decoder;
170                         FLAC__ASSERT(0 != client_data);
171                         Stream *instance = reinterpret_cast<Stream *>(client_data);
172                         FLAC__ASSERT(0 != instance);
173                         return instance->read_callback(buffer, bytes);
174                 }
175
176                 ::FLAC__StreamDecoderWriteStatus Stream::write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
177                 {
178                         (void)decoder;
179                         FLAC__ASSERT(0 != client_data);
180                         Stream *instance = reinterpret_cast<Stream *>(client_data);
181                         FLAC__ASSERT(0 != instance);
182                         return instance->write_callback(frame, buffer);
183                 }
184
185                 void Stream::metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data)
186                 {
187                         (void)decoder;
188                         FLAC__ASSERT(0 != client_data);
189                         Stream *instance = reinterpret_cast<Stream *>(client_data);
190                         FLAC__ASSERT(0 != instance);
191                         instance->metadata_callback(metadata);
192                 }
193
194                 void Stream::error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data)
195                 {
196                         (void)decoder;
197                         FLAC__ASSERT(0 != client_data);
198                         Stream *instance = reinterpret_cast<Stream *>(client_data);
199                         FLAC__ASSERT(0 != instance);
200                         instance->error_callback(status);
201                 }
202
203         };
204 };