remove -E,--escape-coding
[platform/upstream/flac.git] / src / libFLAC++ / file_encoder.cc
1 /* libFLAC++ - Free Lossless Audio Codec library
2  * Copyright (C) 2002  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++/encoder.h"
21 #include "FLAC/assert.h"
22
23 namespace FLAC {
24         namespace Encoder {
25
26                 const char *File::State::resolved_as_cstring(const File &encoder) const
27                 {
28                         if(state_ == ::FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
29                                 FLAC::Encoder::SeekableStream::State state__ = encoder.get_seekable_stream_encoder_state();
30                                 if(state__ == ::FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
31                                         FLAC::Encoder::Stream::State state___ = encoder.get_stream_encoder_state();
32                                         if(state___ == ::FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
33                                                 return encoder.get_verify_decoder_state().as_cstring();
34                                         else
35                                                 return state___.as_cstring();
36                                 }
37                                 else
38                                         return state__.as_cstring();
39                         }
40                         else
41                                 return as_cstring();
42                 }
43
44                 File::File():
45                 encoder_(::FLAC__file_encoder_new())
46                 { }
47
48                 File::~File()
49                 {
50                         if(0 != encoder_) {
51                                 ::FLAC__file_encoder_finish(encoder_);
52                                 ::FLAC__file_encoder_delete(encoder_);
53                         }
54                 }
55
56                 bool File::is_valid() const
57                 {
58                         return 0 != encoder_;
59                 }
60
61                 bool File::set_verify(bool value)
62                 {
63                         FLAC__ASSERT(is_valid());
64                         return (bool)::FLAC__file_encoder_set_verify(encoder_, value);
65                 }
66
67                 bool File::set_streamable_subset(bool value)
68                 {
69                         FLAC__ASSERT(is_valid());
70                         return (bool)::FLAC__file_encoder_set_streamable_subset(encoder_, value);
71                 }
72
73                 bool File::set_do_mid_side_stereo(bool value)
74                 {
75                         FLAC__ASSERT(is_valid());
76                         return (bool)::FLAC__file_encoder_set_do_mid_side_stereo(encoder_, value);
77                 }
78
79                 bool File::set_loose_mid_side_stereo(bool value)
80                 {
81                         FLAC__ASSERT(is_valid());
82                         return (bool)::FLAC__file_encoder_set_loose_mid_side_stereo(encoder_, value);
83                 }
84
85                 bool File::set_channels(unsigned value)
86                 {
87                         FLAC__ASSERT(is_valid());
88                         return (bool)::FLAC__file_encoder_set_channels(encoder_, value);
89                 }
90
91                 bool File::set_bits_per_sample(unsigned value)
92                 {
93                         FLAC__ASSERT(is_valid());
94                         return (bool)::FLAC__file_encoder_set_bits_per_sample(encoder_, value);
95                 }
96
97                 bool File::set_sample_rate(unsigned value)
98                 {
99                         FLAC__ASSERT(is_valid());
100                         return (bool)::FLAC__file_encoder_set_sample_rate(encoder_, value);
101                 }
102
103                 bool File::set_blocksize(unsigned value)
104                 {
105                         FLAC__ASSERT(is_valid());
106                         return (bool)::FLAC__file_encoder_set_blocksize(encoder_, value);
107                 }
108
109                 bool File::set_max_lpc_order(unsigned value)
110                 {
111                         FLAC__ASSERT(is_valid());
112                         return (bool)::FLAC__file_encoder_set_max_lpc_order(encoder_, value);
113                 }
114
115                 bool File::set_qlp_coeff_precision(unsigned value)
116                 {
117                         FLAC__ASSERT(is_valid());
118                         return (bool)::FLAC__file_encoder_set_qlp_coeff_precision(encoder_, value);
119                 }
120
121                 bool File::set_do_qlp_coeff_prec_search(bool value)
122                 {
123                         FLAC__ASSERT(is_valid());
124                         return (bool)::FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder_, value);
125                 }
126
127                 bool File::set_do_escape_coding(bool value)
128                 {
129                         FLAC__ASSERT(is_valid());
130                         return (bool)::FLAC__file_encoder_set_do_escape_coding(encoder_, value);
131                 }
132
133                 bool File::set_do_exhaustive_model_search(bool value)
134                 {
135                         FLAC__ASSERT(is_valid());
136                         return (bool)::FLAC__file_encoder_set_do_exhaustive_model_search(encoder_, value);
137                 }
138
139                 bool File::set_min_residual_partition_order(unsigned value)
140                 {
141                         FLAC__ASSERT(is_valid());
142                         return (bool)::FLAC__file_encoder_set_min_residual_partition_order(encoder_, value);
143                 }
144
145                 bool File::set_max_residual_partition_order(unsigned value)
146                 {
147                         FLAC__ASSERT(is_valid());
148                         return (bool)::FLAC__file_encoder_set_max_residual_partition_order(encoder_, value);
149                 }
150
151                 bool File::set_rice_parameter_search_dist(unsigned value)
152                 {
153                         FLAC__ASSERT(is_valid());
154                         return (bool)::FLAC__file_encoder_set_rice_parameter_search_dist(encoder_, value);
155                 }
156
157                 bool File::set_total_samples_estimate(FLAC__uint64 value)
158                 {
159                         FLAC__ASSERT(is_valid());
160                         return (bool)::FLAC__file_encoder_set_total_samples_estimate(encoder_, value);
161                 }
162
163                 bool File::set_metadata(::FLAC__StreamMetadata **metadata, unsigned num_blocks)
164                 {
165                         FLAC__ASSERT(is_valid());
166                         return (bool)::FLAC__file_encoder_set_metadata(encoder_, metadata, num_blocks);
167                 }
168
169                 bool File::set_filename(const char *value)
170                 {
171                         FLAC__ASSERT(is_valid());
172                         return (bool)::FLAC__file_encoder_set_filename(encoder_, value);
173                 }
174
175                 File::State File::get_state() const
176                 {
177                         FLAC__ASSERT(is_valid());
178                         return State(::FLAC__file_encoder_get_state(encoder_));
179                 }
180
181                 SeekableStream::State File::get_seekable_stream_encoder_state() const
182                 {
183                         FLAC__ASSERT(is_valid());
184                         return SeekableStream::State(::FLAC__file_encoder_get_seekable_stream_encoder_state(encoder_));
185                 }
186
187                 Stream::State File::get_stream_encoder_state() const
188                 {
189                         FLAC__ASSERT(is_valid());
190                         return Stream::State(::FLAC__file_encoder_get_stream_encoder_state(encoder_));
191                 }
192
193                 Decoder::Stream::State File::get_verify_decoder_state() const
194                 {
195                         FLAC__ASSERT(is_valid());
196                         return Decoder::Stream::State(::FLAC__file_encoder_get_verify_decoder_state(encoder_));
197                 }
198
199                 void File::get_verify_decoder_error_stats(FLAC__uint64 *absolute_sample, unsigned *frame_number, unsigned *channel, unsigned *sample, FLAC__int32 *expected, FLAC__int32 *got)
200                 {
201                         FLAC__ASSERT(is_valid());
202                         ::FLAC__file_encoder_get_verify_decoder_error_stats(encoder_, absolute_sample, frame_number, channel, sample, expected, got);
203                 }
204
205                 bool File::get_verify() const
206                 {
207                         FLAC__ASSERT(is_valid());
208                         return (bool)::FLAC__file_encoder_get_verify(encoder_);
209                 }
210
211                 bool File::get_streamable_subset() const
212                 {
213                         FLAC__ASSERT(is_valid());
214                         return (bool)::FLAC__file_encoder_get_streamable_subset(encoder_);
215                 }
216
217                 bool File::get_do_mid_side_stereo() const
218                 {
219                         FLAC__ASSERT(is_valid());
220                         return (bool)::FLAC__file_encoder_get_do_mid_side_stereo(encoder_);
221                 }
222
223                 bool File::get_loose_mid_side_stereo() const
224                 {
225                         FLAC__ASSERT(is_valid());
226                         return (bool)::FLAC__file_encoder_get_loose_mid_side_stereo(encoder_);
227                 }
228
229                 unsigned File::get_channels() const
230                 {
231                         FLAC__ASSERT(is_valid());
232                         return ::FLAC__file_encoder_get_channels(encoder_);
233                 }
234
235                 unsigned File::get_bits_per_sample() const
236                 {
237                         FLAC__ASSERT(is_valid());
238                         return ::FLAC__file_encoder_get_bits_per_sample(encoder_);
239                 }
240
241                 unsigned File::get_sample_rate() const
242                 {
243                         FLAC__ASSERT(is_valid());
244                         return ::FLAC__file_encoder_get_sample_rate(encoder_);
245                 }
246
247                 unsigned File::get_blocksize() const
248                 {
249                         FLAC__ASSERT(is_valid());
250                         return ::FLAC__file_encoder_get_blocksize(encoder_);
251                 }
252
253                 unsigned File::get_max_lpc_order() const
254                 {
255                         FLAC__ASSERT(is_valid());
256                         return ::FLAC__file_encoder_get_max_lpc_order(encoder_);
257                 }
258
259                 unsigned File::get_qlp_coeff_precision() const
260                 {
261                         FLAC__ASSERT(is_valid());
262                         return ::FLAC__file_encoder_get_qlp_coeff_precision(encoder_);
263                 }
264
265                 bool File::get_do_qlp_coeff_prec_search() const
266                 {
267                         FLAC__ASSERT(is_valid());
268                         return (bool)::FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder_);
269                 }
270
271                 bool File::get_do_escape_coding() const
272                 {
273                         FLAC__ASSERT(is_valid());
274                         return (bool)::FLAC__file_encoder_get_do_escape_coding(encoder_);
275                 }
276
277                 bool File::get_do_exhaustive_model_search() const
278                 {
279                         FLAC__ASSERT(is_valid());
280                         return (bool)::FLAC__file_encoder_get_do_exhaustive_model_search(encoder_);
281                 }
282
283                 unsigned File::get_min_residual_partition_order() const
284                 {
285                         FLAC__ASSERT(is_valid());
286                         return ::FLAC__file_encoder_get_min_residual_partition_order(encoder_);
287                 }
288
289                 unsigned File::get_max_residual_partition_order() const
290                 {
291                         FLAC__ASSERT(is_valid());
292                         return ::FLAC__file_encoder_get_max_residual_partition_order(encoder_);
293                 }
294
295                 unsigned File::get_rice_parameter_search_dist() const
296                 {
297                         FLAC__ASSERT(is_valid());
298                         return ::FLAC__file_encoder_get_rice_parameter_search_dist(encoder_);
299                 }
300
301                 FLAC__uint64 File::get_total_samples_estimate() const
302                 {
303                         FLAC__ASSERT(is_valid());
304                         return ::FLAC__file_encoder_get_total_samples_estimate(encoder_);
305                 }
306
307                 File::State File::init()
308                 {
309                         FLAC__ASSERT(is_valid());
310                         ::FLAC__file_encoder_set_progress_callback(encoder_, progress_callback_);
311                         ::FLAC__file_encoder_set_client_data(encoder_, (void*)this);
312                         return State(::FLAC__file_encoder_init(encoder_));
313                 }
314
315                 void File::finish()
316                 {
317                         FLAC__ASSERT(is_valid());
318                         ::FLAC__file_encoder_finish(encoder_);
319                 }
320
321                 bool File::process(const FLAC__int32 * const buffer[], unsigned samples)
322                 {
323                         FLAC__ASSERT(is_valid());
324                         return (bool)::FLAC__file_encoder_process(encoder_, buffer, samples);
325                 }
326
327                 bool File::process_interleaved(const FLAC__int32 buffer[], unsigned samples)
328                 {
329                         FLAC__ASSERT(is_valid());
330                         return (bool)::FLAC__file_encoder_process_interleaved(encoder_, buffer, samples);
331                 }
332
333                 void File::progress_callback(FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate)
334                 {
335                         (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate;
336                 }
337
338                 void File::progress_callback_(const ::FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
339                 {
340                         (void)encoder;
341                         FLAC__ASSERT(0 != client_data);
342                         File *instance = reinterpret_cast<File *>(client_data);
343                         FLAC__ASSERT(0 != instance);
344                         instance->progress_callback(bytes_written, samples_written, frames_written, total_frames_estimate);
345                 }
346
347         };
348 };