1
/* libFLAC++ - Free Lossless Audio Codec library
2
* Copyright (C) 2002,2003 Josh Coalson
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.
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.
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.
20
#include "FLAC++/decoder.h"
21
#include "FLAC/assert.h"
26
const char *Stream::State::resolved_as_cstring(const Stream &) const
32
decoder_(::FLAC__stream_decoder_new())
38
::FLAC__stream_decoder_finish(decoder_);
39
::FLAC__stream_decoder_delete(decoder_);
43
bool Stream::is_valid() const
48
bool Stream::set_metadata_respond(::FLAC__MetadataType type)
50
FLAC__ASSERT(is_valid());
51
return (bool)::FLAC__stream_decoder_set_metadata_respond(decoder_, type);
54
bool Stream::set_metadata_respond_application(const FLAC__byte id[4])
56
FLAC__ASSERT(is_valid());
57
return (bool)::FLAC__stream_decoder_set_metadata_respond_application(decoder_, id);
60
bool Stream::set_metadata_respond_all()
62
FLAC__ASSERT(is_valid());
63
return (bool)::FLAC__stream_decoder_set_metadata_respond_all(decoder_);
66
bool Stream::set_metadata_ignore(::FLAC__MetadataType type)
68
FLAC__ASSERT(is_valid());
69
return (bool)::FLAC__stream_decoder_set_metadata_ignore(decoder_, type);
72
bool Stream::set_metadata_ignore_application(const FLAC__byte id[4])
74
FLAC__ASSERT(is_valid());
75
return (bool)::FLAC__stream_decoder_set_metadata_ignore_application(decoder_, id);
78
bool Stream::set_metadata_ignore_all()
80
FLAC__ASSERT(is_valid());
81
return (bool)::FLAC__stream_decoder_set_metadata_ignore_all(decoder_);
84
Stream::State Stream::get_state() const
86
FLAC__ASSERT(is_valid());
87
return State(::FLAC__stream_decoder_get_state(decoder_));
90
unsigned Stream::get_channels() const
92
FLAC__ASSERT(is_valid());
93
return ::FLAC__stream_decoder_get_channels(decoder_);
96
::FLAC__ChannelAssignment Stream::get_channel_assignment() const
98
FLAC__ASSERT(is_valid());
99
return ::FLAC__stream_decoder_get_channel_assignment(decoder_);
102
unsigned Stream::get_bits_per_sample() const
104
FLAC__ASSERT(is_valid());
105
return ::FLAC__stream_decoder_get_bits_per_sample(decoder_);
108
unsigned Stream::get_sample_rate() const
110
FLAC__ASSERT(is_valid());
111
return ::FLAC__stream_decoder_get_sample_rate(decoder_);
114
unsigned Stream::get_blocksize() const
116
FLAC__ASSERT(is_valid());
117
return ::FLAC__stream_decoder_get_blocksize(decoder_);
120
Stream::State Stream::init()
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_));
131
void Stream::finish()
133
FLAC__ASSERT(is_valid());
134
::FLAC__stream_decoder_finish(decoder_);
139
FLAC__ASSERT(is_valid());
140
return (bool)::FLAC__stream_decoder_flush(decoder_);
145
FLAC__ASSERT(is_valid());
146
return (bool)::FLAC__stream_decoder_reset(decoder_);
149
bool Stream::process_single()
151
FLAC__ASSERT(is_valid());
152
return (bool)::FLAC__stream_decoder_process_single(decoder_);
155
bool Stream::process_until_end_of_metadata()
157
FLAC__ASSERT(is_valid());
158
return (bool)::FLAC__stream_decoder_process_until_end_of_metadata(decoder_);
161
bool Stream::process_until_end_of_stream()
163
FLAC__ASSERT(is_valid());
164
return (bool)::FLAC__stream_decoder_process_until_end_of_stream(decoder_);
167
::FLAC__StreamDecoderReadStatus Stream::read_callback_(const ::FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
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);
176
::FLAC__StreamDecoderWriteStatus Stream::write_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
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);
185
void Stream::metadata_callback_(const ::FLAC__StreamDecoder *decoder, const ::FLAC__StreamMetadata *metadata, void *client_data)
188
FLAC__ASSERT(0 != client_data);
189
Stream *instance = reinterpret_cast<Stream *>(client_data);
190
FLAC__ASSERT(0 != instance);
191
instance->metadata_callback(metadata);
194
void Stream::error_callback_(const ::FLAC__StreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data)
197
FLAC__ASSERT(0 != client_data);
198
Stream *instance = reinterpret_cast<Stream *>(client_data);
199
FLAC__ASSERT(0 != instance);
200
instance->error_callback(status);