1 /* libFLAC++ - Free Lossless Audio Codec library
2 * Copyright (C) 2002 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 SeekableStream::SeekableStream():
27 decoder_(::FLAC__seekable_stream_decoder_new())
30 SeekableStream::~SeekableStream()
33 (void) ::FLAC__seekable_stream_decoder_finish(decoder_);
34 ::FLAC__seekable_stream_decoder_delete(decoder_);
38 bool SeekableStream::is_valid() const
43 bool SeekableStream::set_md5_checking(bool value)
45 FLAC__ASSERT(is_valid());
46 return ::FLAC__seekable_stream_decoder_set_md5_checking(decoder_, value);
49 bool SeekableStream::set_metadata_respond(::FLAC__MetaDataType type)
51 FLAC__ASSERT(is_valid());
52 return ::FLAC__seekable_stream_decoder_set_metadata_respond(decoder_, type);
55 bool SeekableStream::set_metadata_respond_application(const FLAC__byte id[4])
57 FLAC__ASSERT(is_valid());
58 return ::FLAC__seekable_stream_decoder_set_metadata_respond_application(decoder_, id);
61 bool SeekableStream::set_metadata_respond_all()
63 FLAC__ASSERT(is_valid());
64 return ::FLAC__seekable_stream_decoder_set_metadata_respond_all(decoder_);
67 bool SeekableStream::set_metadata_ignore(::FLAC__MetaDataType type)
69 FLAC__ASSERT(is_valid());
70 return ::FLAC__seekable_stream_decoder_set_metadata_ignore(decoder_, type);
73 bool SeekableStream::set_metadata_ignore_application(const FLAC__byte id[4])
75 FLAC__ASSERT(is_valid());
76 return ::FLAC__seekable_stream_decoder_set_metadata_ignore_application(decoder_, id);
79 bool SeekableStream::set_metadata_ignore_all()
81 FLAC__ASSERT(is_valid());
82 return ::FLAC__seekable_stream_decoder_set_metadata_ignore_all(decoder_);
85 SeekableStream::State SeekableStream::get_state() const
87 FLAC__ASSERT(is_valid());
88 return State(::FLAC__seekable_stream_decoder_get_state(decoder_));
91 bool SeekableStream::get_md5_checking() const
93 FLAC__ASSERT(is_valid());
94 return ::FLAC__seekable_stream_decoder_get_md5_checking(decoder_);
97 SeekableStream::State SeekableStream::init()
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_));
112 bool SeekableStream::finish()
114 FLAC__ASSERT(is_valid());
115 return ::FLAC__seekable_stream_decoder_finish(decoder_);
118 bool SeekableStream::process_whole_stream()
120 FLAC__ASSERT(is_valid());
121 return ::FLAC__seekable_stream_decoder_process_whole_stream(decoder_);
124 bool SeekableStream::process_metadata()
126 FLAC__ASSERT(is_valid());
127 return ::FLAC__seekable_stream_decoder_process_metadata(decoder_);
130 bool SeekableStream::process_one_frame()
132 FLAC__ASSERT(is_valid());
133 return ::FLAC__seekable_stream_decoder_process_one_frame(decoder_);
136 bool SeekableStream::process_remaining_frames()
138 FLAC__ASSERT(is_valid());
139 return ::FLAC__seekable_stream_decoder_process_remaining_frames(decoder_);
142 bool SeekableStream::seek_absolute(FLAC__uint64 sample)
144 FLAC__ASSERT(is_valid());
145 return ::FLAC__seekable_stream_decoder_seek_absolute(decoder_, sample);
148 FLAC__SeekableStreamDecoderReadStatus SeekableStream::read_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
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);
157 FLAC__SeekableStreamDecoderSeekStatus SeekableStream::seek_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
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);
166 FLAC__SeekableStreamDecoderTellStatus SeekableStream::tell_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
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);
175 FLAC__SeekableStreamDecoderLengthStatus SeekableStream::length_callback_(const ::FLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
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);
184 FLAC__bool SeekableStream::eof_callback_(const ::FLAC__SeekableStreamDecoder *decoder, void *client_data)
187 FLAC__ASSERT(0 != client_data);
188 SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
189 FLAC__ASSERT(0 != instance);
190 return instance->eof_callback();
193 FLAC__StreamDecoderWriteStatus SeekableStream::write_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 *buffer[], void *client_data)
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);
202 void SeekableStream::metadata_callback_(const ::FLAC__SeekableStreamDecoder *decoder, const ::FLAC__StreamMetaData *metadata, void *client_data)
205 FLAC__ASSERT(0 != client_data);
206 SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
207 FLAC__ASSERT(0 != instance);
208 instance->metadata_callback(metadata);
211 void SeekableStream::error_callback_(const ::FLAC__SeekableStreamDecoder *decoder, ::FLAC__StreamDecoderErrorStatus status, void *client_data)
214 FLAC__ASSERT(0 != client_data);
215 SeekableStream *instance = reinterpret_cast<SeekableStream *>(client_data);
216 FLAC__ASSERT(0 != instance);
217 instance->error_callback(status);