~ubuntu-branches/ubuntu/lucid/flac/lucid-security

« back to all changes in this revision

Viewing changes to src/libOggFLAC++/stream_encoder.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2007-05-29 22:56:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529225636-ljeff8xxip09qaap
Tags: 1.1.4-1
* New upstream release. closes: #405167, #411311
  - libOggFLAC and libOggFLAC++ have been merged into libFLAC, so
    remove their corresponding packages.
  - Because of the API changes required to effect the above, there has
    been yet another soname bump. libflac7 -> libflac8 and
    libflac++5 -> libflac++6. Emails have been dispatched to the
    maintainers of dependent packages.
* Some notes on patches that were removed:
  - 02_stdin_stdout, 06_manpage_mention_utf8_convert: merged upstream
  - 08_manpage_warnings: Upstream has changed the manpage so it defintely
    can't fit in in 80 cols, so just forget about it. We'll live.
  - 05_eof_warnings_are_errors: Upstream decided to add a -w option to
    flac to treat all warnings as errors. I am going to defer to that
    for now, but if people think it's stupid let me know and I'll port
    the patch forward.
  - 04_stack_smasher: was a backport from 1.1.3, so it's obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* libOggFLAC++ - Free Lossless Audio Codec + Ogg library
2
 
 * Copyright (C) 2002,2003,2004,2005  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 "OggFLAC++/encoder.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 OggFLAC {
41
 
        namespace Encoder {
42
 
 
43
 
                Stream::Stream():
44
 
                encoder_(::OggFLAC__stream_encoder_new())
45
 
                { }
46
 
 
47
 
                Stream::~Stream()
48
 
                {
49
 
                        if(0 != encoder_) {
50
 
                                ::OggFLAC__stream_encoder_finish(encoder_);
51
 
                                ::OggFLAC__stream_encoder_delete(encoder_);
52
 
                        }
53
 
                }
54
 
 
55
 
                bool Stream::is_valid() const
56
 
                {
57
 
                        return 0 != encoder_;
58
 
                }
59
 
 
60
 
                bool Stream::set_serial_number(long value)
61
 
                {
62
 
                        FLAC__ASSERT(is_valid());
63
 
                        return (bool)::OggFLAC__stream_encoder_set_serial_number(encoder_, value);
64
 
                }
65
 
 
66
 
                bool Stream::set_verify(bool value)
67
 
                {
68
 
                        FLAC__ASSERT(is_valid());
69
 
                        return (bool)::OggFLAC__stream_encoder_set_verify(encoder_, value);
70
 
                }
71
 
 
72
 
                bool Stream::set_streamable_subset(bool value)
73
 
                {
74
 
                        FLAC__ASSERT(is_valid());
75
 
                        return (bool)::OggFLAC__stream_encoder_set_streamable_subset(encoder_, value);
76
 
                }
77
 
 
78
 
                bool Stream::set_do_mid_side_stereo(bool value)
79
 
                {
80
 
                        FLAC__ASSERT(is_valid());
81
 
                        return (bool)::OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder_, value);
82
 
                }
83
 
 
84
 
                bool Stream::set_loose_mid_side_stereo(bool value)
85
 
                {
86
 
                        FLAC__ASSERT(is_valid());
87
 
                        return (bool)::OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder_, value);
88
 
                }
89
 
 
90
 
                bool Stream::set_channels(unsigned value)
91
 
                {
92
 
                        FLAC__ASSERT(is_valid());
93
 
                        return (bool)::OggFLAC__stream_encoder_set_channels(encoder_, value);
94
 
                }
95
 
 
96
 
                bool Stream::set_bits_per_sample(unsigned value)
97
 
                {
98
 
                        FLAC__ASSERT(is_valid());
99
 
                        return (bool)::OggFLAC__stream_encoder_set_bits_per_sample(encoder_, value);
100
 
                }
101
 
 
102
 
                bool Stream::set_sample_rate(unsigned value)
103
 
                {
104
 
                        FLAC__ASSERT(is_valid());
105
 
                        return (bool)::OggFLAC__stream_encoder_set_sample_rate(encoder_, value);
106
 
                }
107
 
 
108
 
                bool Stream::set_blocksize(unsigned value)
109
 
                {
110
 
                        FLAC__ASSERT(is_valid());
111
 
                        return (bool)::OggFLAC__stream_encoder_set_blocksize(encoder_, value);
112
 
                }
113
 
 
114
 
                bool Stream::set_max_lpc_order(unsigned value)
115
 
                {
116
 
                        FLAC__ASSERT(is_valid());
117
 
                        return (bool)::OggFLAC__stream_encoder_set_max_lpc_order(encoder_, value);
118
 
                }
119
 
 
120
 
                bool Stream::set_qlp_coeff_precision(unsigned value)
121
 
                {
122
 
                        FLAC__ASSERT(is_valid());
123
 
                        return (bool)::OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder_, value);
124
 
                }
125
 
 
126
 
                bool Stream::set_do_qlp_coeff_prec_search(bool value)
127
 
                {
128
 
                        FLAC__ASSERT(is_valid());
129
 
                        return (bool)::OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder_, value);
130
 
                }
131
 
 
132
 
                bool Stream::set_do_escape_coding(bool value)
133
 
                {
134
 
                        FLAC__ASSERT(is_valid());
135
 
                        return (bool)::OggFLAC__stream_encoder_set_do_escape_coding(encoder_, value);
136
 
                }
137
 
 
138
 
                bool Stream::set_do_exhaustive_model_search(bool value)
139
 
                {
140
 
                        FLAC__ASSERT(is_valid());
141
 
                        return (bool)::OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder_, value);
142
 
                }
143
 
 
144
 
                bool Stream::set_min_residual_partition_order(unsigned value)
145
 
                {
146
 
                        FLAC__ASSERT(is_valid());
147
 
                        return (bool)::OggFLAC__stream_encoder_set_min_residual_partition_order(encoder_, value);
148
 
                }
149
 
 
150
 
                bool Stream::set_max_residual_partition_order(unsigned value)
151
 
                {
152
 
                        FLAC__ASSERT(is_valid());
153
 
                        return (bool)::OggFLAC__stream_encoder_set_max_residual_partition_order(encoder_, value);
154
 
                }
155
 
 
156
 
                bool Stream::set_rice_parameter_search_dist(unsigned value)
157
 
                {
158
 
                        FLAC__ASSERT(is_valid());
159
 
                        return (bool)::OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder_, value);
160
 
                }
161
 
 
162
 
                bool Stream::set_total_samples_estimate(FLAC__uint64 value)
163
 
                {
164
 
                        FLAC__ASSERT(is_valid());
165
 
                        return (bool)::OggFLAC__stream_encoder_set_total_samples_estimate(encoder_, value);
166
 
                }
167
 
 
168
 
                bool Stream::set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks)
169
 
                {
170
 
                        FLAC__ASSERT(is_valid());
171
 
                        return (bool)::OggFLAC__stream_encoder_set_metadata(encoder_, metadata, num_blocks);
172
 
                }
173
 
 
174
 
                Stream::State Stream::get_state() const
175
 
                {
176
 
                        FLAC__ASSERT(is_valid());
177
 
                        return State(::OggFLAC__stream_encoder_get_state(encoder_));
178
 
                }
179
 
 
180
 
                FLAC::Encoder::Stream::State Stream::get_FLAC_stream_encoder_state() const
181
 
                {
182
 
                        FLAC__ASSERT(is_valid());
183
 
                        return FLAC::Encoder::Stream::State(::OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder_));
184
 
                }
185
 
 
186
 
                FLAC::Decoder::Stream::State Stream::get_verify_decoder_state() const
187
 
                {
188
 
                        FLAC__ASSERT(is_valid());
189
 
                        return FLAC::Decoder::Stream::State(::OggFLAC__stream_encoder_get_verify_decoder_state(encoder_));
190
 
                }
191
 
 
192
 
                void Stream::get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
193
 
                {
194
 
                        FLAC__ASSERT(is_valid());
195
 
                        ::OggFLAC__stream_encoder_get_verify_decoder_error_stats(encoder_, absolute_sample, frame_number, channel, sample, expected, got);
196
 
                }
197
 
 
198
 
                bool Stream::get_verify() const
199
 
                {
200
 
                        FLAC__ASSERT(is_valid());
201
 
                        return (bool)::OggFLAC__stream_encoder_get_verify(encoder_);
202
 
                }
203
 
 
204
 
                bool Stream::get_streamable_subset() const
205
 
                {
206
 
                        FLAC__ASSERT(is_valid());
207
 
                        return (bool)::OggFLAC__stream_encoder_get_streamable_subset(encoder_);
208
 
                }
209
 
 
210
 
                bool Stream::get_do_mid_side_stereo() const
211
 
                {
212
 
                        FLAC__ASSERT(is_valid());
213
 
                        return (bool)::OggFLAC__stream_encoder_get_do_mid_side_stereo(encoder_);
214
 
                }
215
 
 
216
 
                bool Stream::get_loose_mid_side_stereo() const
217
 
                {
218
 
                        FLAC__ASSERT(is_valid());
219
 
                        return (bool)::OggFLAC__stream_encoder_get_loose_mid_side_stereo(encoder_);
220
 
                }
221
 
 
222
 
                unsigned Stream::get_channels() const
223
 
                {
224
 
                        FLAC__ASSERT(is_valid());
225
 
                        return ::OggFLAC__stream_encoder_get_channels(encoder_);
226
 
                }
227
 
 
228
 
                unsigned Stream::get_bits_per_sample() const
229
 
                {
230
 
                        FLAC__ASSERT(is_valid());
231
 
                        return ::OggFLAC__stream_encoder_get_bits_per_sample(encoder_);
232
 
                }
233
 
 
234
 
                unsigned Stream::get_sample_rate() const
235
 
                {
236
 
                        FLAC__ASSERT(is_valid());
237
 
                        return ::OggFLAC__stream_encoder_get_sample_rate(encoder_);
238
 
                }
239
 
 
240
 
                unsigned Stream::get_blocksize() const
241
 
                {
242
 
                        FLAC__ASSERT(is_valid());
243
 
                        return ::OggFLAC__stream_encoder_get_blocksize(encoder_);
244
 
                }
245
 
 
246
 
                unsigned Stream::get_max_lpc_order() const
247
 
                {
248
 
                        FLAC__ASSERT(is_valid());
249
 
                        return ::OggFLAC__stream_encoder_get_max_lpc_order(encoder_);
250
 
                }
251
 
 
252
 
                unsigned Stream::get_qlp_coeff_precision() const
253
 
                {
254
 
                        FLAC__ASSERT(is_valid());
255
 
                        return ::OggFLAC__stream_encoder_get_qlp_coeff_precision(encoder_);
256
 
                }
257
 
 
258
 
                bool Stream::get_do_qlp_coeff_prec_search() const
259
 
                {
260
 
                        FLAC__ASSERT(is_valid());
261
 
                        return (bool)::OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder_);
262
 
                }
263
 
 
264
 
                bool Stream::get_do_escape_coding() const
265
 
                {
266
 
                        FLAC__ASSERT(is_valid());
267
 
                        return (bool)::OggFLAC__stream_encoder_get_do_escape_coding(encoder_);
268
 
                }
269
 
 
270
 
                bool Stream::get_do_exhaustive_model_search() const
271
 
                {
272
 
                        FLAC__ASSERT(is_valid());
273
 
                        return (bool)::OggFLAC__stream_encoder_get_do_exhaustive_model_search(encoder_);
274
 
                }
275
 
 
276
 
                unsigned Stream::get_min_residual_partition_order() const
277
 
                {
278
 
                        FLAC__ASSERT(is_valid());
279
 
                        return ::OggFLAC__stream_encoder_get_min_residual_partition_order(encoder_);
280
 
                }
281
 
 
282
 
                unsigned Stream::get_max_residual_partition_order() const
283
 
                {
284
 
                        FLAC__ASSERT(is_valid());
285
 
                        return ::OggFLAC__stream_encoder_get_max_residual_partition_order(encoder_);
286
 
                }
287
 
 
288
 
                unsigned Stream::get_rice_parameter_search_dist() const
289
 
                {
290
 
                        FLAC__ASSERT(is_valid());
291
 
                        return ::OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder_);
292
 
                }
293
 
 
294
 
                FLAC__uint64 Stream::get_total_samples_estimate() const
295
 
                {
296
 
                        FLAC__ASSERT(is_valid());
297
 
                        return ::OggFLAC__stream_encoder_get_total_samples_estimate(encoder_);
298
 
                }
299
 
 
300
 
                Stream::State Stream::init()
301
 
                {
302
 
                        FLAC__ASSERT(is_valid());
303
 
                        ::OggFLAC__stream_encoder_set_write_callback(encoder_, write_callback_);
304
 
                        ::OggFLAC__stream_encoder_set_metadata_callback(encoder_, metadata_callback_);
305
 
                        ::OggFLAC__stream_encoder_set_client_data(encoder_, (void*)this);
306
 
                        return State(::OggFLAC__stream_encoder_init(encoder_));
307
 
                }
308
 
 
309
 
                void Stream::finish()
310
 
                {
311
 
                        FLAC__ASSERT(is_valid());
312
 
                        ::OggFLAC__stream_encoder_finish(encoder_);
313
 
                }
314
 
 
315
 
                bool Stream::process(const FLAC__int32 * const buffer[], unsigned samples)
316
 
                {
317
 
                        FLAC__ASSERT(is_valid());
318
 
                        return (bool)::OggFLAC__stream_encoder_process(encoder_, buffer, samples);
319
 
                }
320
 
 
321
 
                bool Stream::process_interleaved(const FLAC__int32 buffer[], unsigned samples)
322
 
                {
323
 
                        FLAC__ASSERT(is_valid());
324
 
                        return (bool)::OggFLAC__stream_encoder_process_interleaved(encoder_, buffer, samples);
325
 
                }
326
 
 
327
 
                ::FLAC__StreamEncoderWriteStatus Stream::write_callback_(const ::OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
328
 
                {
329
 
                        (void)encoder;
330
 
                        FLAC__ASSERT(0 != client_data);
331
 
                        Stream *instance = reinterpret_cast<Stream *>(client_data);
332
 
                        FLAC__ASSERT(0 != instance);
333
 
                        return instance->write_callback(buffer, bytes, samples, current_frame);
334
 
                }
335
 
 
336
 
                void Stream::metadata_callback_(const ::OggFLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
337
 
                {
338
 
                        (void)encoder;
339
 
                        FLAC__ASSERT(0 != client_data);
340
 
                        Stream *instance = reinterpret_cast<Stream *>(client_data);
341
 
                        FLAC__ASSERT(0 != instance);
342
 
                        instance->metadata_callback(metadata);
343
 
                }
344
 
 
345
 
        }
346
 
}