Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: src/libFLAC/stream_decoder.c

Issue 1961133002: Update FLAC to 1.3.1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/flac.git@master
Patch Set: build config tweaks for Windows Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/libFLAC/metadata_object.c ('k') | src/libFLAC/stream_encoder.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* libFLAC - Free Lossless Audio Codec library 1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson 2 * Copyright (C) 2000-2009 Josh Coalson
3 * Copyright (C) 2011-2014 Xiph.Org Foundation
3 * 4 *
4 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
6 * are met: 7 * are met:
7 * 8 *
8 * - Redistributions of source code must retain the above copyright 9 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
10 * 11 *
11 * - Redistributions in binary form must reproduce the above copyright 12 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
14 * 15 *
15 * - Neither the name of the Xiph.org Foundation nor the names of its 16 * - 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 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission. 18 * this software without specific prior written permission.
18 * 19 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 * 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 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 31 */
31 32
32 #if HAVE_CONFIG_H 33 #ifdef HAVE_CONFIG_H
33 # include <config.h> 34 # include <config.h>
34 #endif 35 #endif
35 36
36 #if defined _MSC_VER || defined __MINGW32__
37 #include <io.h> /* for _setmode() */
38 #include <fcntl.h> /* for _O_BINARY */
39 #endif
40 #if defined __CYGWIN__ || defined __EMX__
41 #include <io.h> /* for setmode(), O_BINARY */
42 #include <fcntl.h> /* for _O_BINARY */
43 #endif
44 #include <stdio.h> 37 #include <stdio.h>
45 #include <stdlib.h> /* for malloc() */ 38 #include <stdlib.h> /* for malloc() */
46 #include <string.h> /* for memset/memcpy() */ 39 #include <string.h> /* for memset/memcpy() */
47 #include <sys/stat.h> /* for stat() */ 40 #include <sys/stat.h> /* for stat() */
48 #include <sys/types.h> /* for off_t */ 41 #include <sys/types.h> /* for off_t */
49 #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ 42 #include "share/compat.h"
50 #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
51 #define fseeko fseek
52 #define ftello ftell
53 #else
54 #define fseeko _fseeki64
55 #define ftello _ftelli64
56 #endif
57 #endif
58 #include "FLAC/assert.h" 43 #include "FLAC/assert.h"
59 #include "share/alloc.h" 44 #include "share/alloc.h"
60 #include "protected/stream_decoder.h" 45 #include "protected/stream_decoder.h"
61 #include "private/bitreader.h" 46 #include "private/bitreader.h"
62 #include "private/bitmath.h" 47 #include "private/bitmath.h"
63 #include "private/cpu.h" 48 #include "private/cpu.h"
64 #include "private/crc.h" 49 #include "private/crc.h"
65 #include "private/fixed.h" 50 #include "private/fixed.h"
66 #include "private/format.h" 51 #include "private/format.h"
67 #include "private/lpc.h" 52 #include "private/lpc.h"
68 #include "private/md5.h" 53 #include "private/md5.h"
69 #include "private/memory.h" 54 #include "private/memory.h"
70 55 #include "private/macros.h"
71 #ifdef max
72 #undef max
73 #endif
74 #define max(a,b) ((a)>(b)?(a):(b))
75
76 /* adjust for compilers that can't understand using LLU suffix for uint64_t lite rals */
77 #ifdef _MSC_VER
78 #define FLAC__U64L(x) x
79 #else
80 #define FLAC__U64L(x) x##LLU
81 #endif
82 56
83 57
84 /* technically this should be in an "export.c" but this is convenient enough */ 58 /* technically this should be in an "export.c" but this is convenient enough */
85 FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC = 59 FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
86 #if FLAC__HAS_OGG 60 #if FLAC__HAS_OGG
87 1 61 1
88 #else 62 #else
89 0 63 0
90 #endif 64 #endif
91 ; 65 ;
92 66
93 67
94 /*********************************************************************** 68 /***********************************************************************
95 * 69 *
96 * Private static data 70 * Private static data
97 * 71 *
98 ***********************************************************************/ 72 ***********************************************************************/
99 73
100 static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' }; 74 static const FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
101 75
102 /*********************************************************************** 76 /***********************************************************************
103 * 77 *
104 * Private class method prototypes 78 * Private class method prototypes
105 * 79 *
106 ***********************************************************************/ 80 ***********************************************************************/
107 81
108 static void set_defaults_(FLAC__StreamDecoder *decoder); 82 static void set_defaults_(FLAC__StreamDecoder *decoder);
109 static FILE *get_binary_stdin_(void); 83 static FILE *get_binary_stdin_(void);
110 static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels); 84 static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
111 static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id) ; 85 static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id) ;
112 static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder); 86 static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
113 static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder); 87 static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
114 static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__ bool is_last, unsigned length); 88 static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__ bool is_last, unsigned length);
115 static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__b ool is_last, unsigned length); 89 static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__b ool is_last, unsigned length);
116 static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLA C__StreamMetadata_VorbisComment *obj); 90 static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLA C__StreamMetadata_VorbisComment *obj, unsigned length);
117 static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__St reamMetadata_CueSheet *obj); 91 static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__St reamMetadata_CueSheet *obj);
118 static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__Str eamMetadata_Picture *obj); 92 static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__Str eamMetadata_Picture *obj);
119 static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder); 93 static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
120 static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder); 94 static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
121 static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_fr ame, FLAC__bool do_full_decode); 95 static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_fr ame, FLAC__bool do_full_decode);
122 static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder); 96 static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
123 static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode); 97 static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
124 static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode); 98 static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
125 static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned ch annel, unsigned bps, const unsigned order, FLAC__bool do_full_decode); 99 static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned ch annel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
126 static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned chan nel, unsigned bps, const unsigned order, FLAC__bool do_full_decode); 100 static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned chan nel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 FLAC__StreamDecoderEofCallback eof_callback; 135 FLAC__StreamDecoderEofCallback eof_callback;
162 FLAC__StreamDecoderWriteCallback write_callback; 136 FLAC__StreamDecoderWriteCallback write_callback;
163 FLAC__StreamDecoderMetadataCallback metadata_callback; 137 FLAC__StreamDecoderMetadataCallback metadata_callback;
164 FLAC__StreamDecoderErrorCallback error_callback; 138 FLAC__StreamDecoderErrorCallback error_callback;
165 /* generic 32-bit datapath: */ 139 /* generic 32-bit datapath: */
166 void (*local_lpc_restore_signal)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FL AC__int32 data[]); 140 void (*local_lpc_restore_signal)(const FLAC__int32 residual[], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantization, FL AC__int32 data[]);
167 /* generic 64-bit datapath: */ 141 /* generic 64-bit datapath: */
168 void (*local_lpc_restore_signal_64bit)(const FLAC__int32 residual[], uns igned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantizati on, FLAC__int32 data[]); 142 void (*local_lpc_restore_signal_64bit)(const FLAC__int32 residual[], uns igned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantizati on, FLAC__int32 data[]);
169 /* for use when the signal is <= 16 bits-per-sample, or <= 15 bits-per-s ample on a side channel (which requires 1 extra bit): */ 143 /* for use when the signal is <= 16 bits-per-sample, or <= 15 bits-per-s ample on a side channel (which requires 1 extra bit): */
170 void (*local_lpc_restore_signal_16bit)(const FLAC__int32 residual[], uns igned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantizati on, FLAC__int32 data[]); 144 void (*local_lpc_restore_signal_16bit)(const FLAC__int32 residual[], uns igned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_quantizati on, FLAC__int32 data[]);
171 /* for use when the signal is <= 16 bits-per-sample, or <= 15 bits-per-s ample on a side channel (which requires 1 extra bit), AND order <= 8: */
172 void (*local_lpc_restore_signal_16bit_order8)(const FLAC__int32 residual [], unsigned data_len, const FLAC__int32 qlp_coeff[], unsigned order, int lp_qua ntization, FLAC__int32 data[]);
173 FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br , int vals[], unsigned nvals, unsigned parameter);
174 void *client_data; 145 void *client_data;
175 FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__strea m_decoder_init_file() called, else NULL */ 146 FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__strea m_decoder_init_file() called, else NULL */
176 FLAC__BitReader *input; 147 FLAC__BitReader *input;
177 FLAC__int32 *output[FLAC__MAX_CHANNELS]; 148 FLAC__int32 *output[FLAC__MAX_CHANNELS];
178 FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the al igned pointers; the real pointers that should be free()'d are residual_unaligned [] below */ 149 FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the al igned pointers; the real pointers that should be free()'d are residual_unaligned [] below */
179 FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_conte nts[FLAC__MAX_CHANNELS]; 150 FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_conte nts[FLAC__MAX_CHANNELS];
180 unsigned output_capacity, output_channels; 151 unsigned output_capacity, output_channels;
181 FLAC__uint32 fixed_block_size, next_fixed_block_size; 152 FLAC__uint32 fixed_block_size, next_fixed_block_size;
182 FLAC__uint64 samples_decoded; 153 FLAC__uint64 samples_decoded;
183 FLAC__bool has_stream_info, has_seek_table; 154 FLAC__bool has_stream_info, has_seek_table;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 * Class constructor/destructor 248 * Class constructor/destructor
278 * 249 *
279 ***********************************************************************/ 250 ***********************************************************************/
280 FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void) 251 FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
281 { 252 {
282 FLAC__StreamDecoder *decoder; 253 FLAC__StreamDecoder *decoder;
283 unsigned i; 254 unsigned i;
284 255
285 FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */ 256 FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
286 257
287 » decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder)); 258 » decoder = calloc(1, sizeof(FLAC__StreamDecoder));
288 if(decoder == 0) { 259 if(decoder == 0) {
289 return 0; 260 return 0;
290 } 261 }
291 262
292 » decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FL AC__StreamDecoderProtected)); 263 » decoder->protected_ = calloc(1, sizeof(FLAC__StreamDecoderProtected));
293 if(decoder->protected_ == 0) { 264 if(decoder->protected_ == 0) {
294 free(decoder); 265 free(decoder);
295 return 0; 266 return 0;
296 } 267 }
297 268
298 » decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__ StreamDecoderPrivate)); 269 » decoder->private_ = calloc(1, sizeof(FLAC__StreamDecoderPrivate));
299 if(decoder->private_ == 0) { 270 if(decoder->private_ == 0) {
300 free(decoder->protected_); 271 free(decoder->protected_);
301 free(decoder); 272 free(decoder);
302 return 0; 273 return 0;
303 } 274 }
304 275
305 decoder->private_->input = FLAC__bitreader_new(); 276 decoder->private_->input = FLAC__bitreader_new();
306 if(decoder->private_->input == 0) { 277 if(decoder->private_->input == 0) {
307 free(decoder->private_); 278 free(decoder->private_);
308 free(decoder->protected_); 279 free(decoder->protected_);
309 free(decoder); 280 free(decoder);
310 return 0; 281 return 0;
311 } 282 }
312 283
313 decoder->private_->metadata_filter_ids_capacity = 16; 284 decoder->private_->metadata_filter_ids_capacity = 16;
314 » if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((F LAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ ids_capacity))) { 285 » if(0 == (decoder->private_->metadata_filter_ids = malloc((FLAC__STREAM_M ETADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity) )) {
315 FLAC__bitreader_delete(decoder->private_->input); 286 FLAC__bitreader_delete(decoder->private_->input);
316 free(decoder->private_); 287 free(decoder->private_);
317 free(decoder->protected_); 288 free(decoder->protected_);
318 free(decoder); 289 free(decoder);
319 return 0; 290 return 0;
320 } 291 }
321 292
322 for(i = 0; i < FLAC__MAX_CHANNELS; i++) { 293 for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
323 decoder->private_->output[i] = 0; 294 decoder->private_->output[i] = 0;
324 decoder->private_->residual_unaligned[i] = decoder->private_->re sidual[i] = 0; 295 decoder->private_->residual_unaligned[i] = decoder->private_->re sidual[i] = 0;
(...skipping 12 matching lines...) Expand all
337 308
338 decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED; 309 decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
339 310
340 return decoder; 311 return decoder;
341 } 312 }
342 313
343 FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder) 314 FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
344 { 315 {
345 unsigned i; 316 unsigned i;
346 317
347 » FLAC__ASSERT(0 != decoder); 318 » if (decoder == NULL)
319 » » return ;
320
348 FLAC__ASSERT(0 != decoder->protected_); 321 FLAC__ASSERT(0 != decoder->protected_);
349 FLAC__ASSERT(0 != decoder->private_); 322 FLAC__ASSERT(0 != decoder->private_);
350 FLAC__ASSERT(0 != decoder->private_->input); 323 FLAC__ASSERT(0 != decoder->private_->input);
351 324
352 (void)FLAC__stream_decoder_finish(decoder); 325 (void)FLAC__stream_decoder_finish(decoder);
353 326
354 if(0 != decoder->private_->metadata_filter_ids) 327 if(0 != decoder->private_->metadata_filter_ids)
355 free(decoder->private_->metadata_filter_ids); 328 free(decoder->private_->metadata_filter_ids);
356 329
357 FLAC__bitreader_delete(decoder->private_->input); 330 FLAC__bitreader_delete(decoder->private_->input);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 0 == read_callback || 371 0 == read_callback ||
399 0 == write_callback || 372 0 == write_callback ||
400 0 == error_callback || 373 0 == error_callback ||
401 (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback)) 374 (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
402 ) 375 )
403 return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS; 376 return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
404 377
405 #if FLAC__HAS_OGG 378 #if FLAC__HAS_OGG
406 decoder->private_->is_ogg = is_ogg; 379 decoder->private_->is_ogg = is_ogg;
407 if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_de coder_aspect)) 380 if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_de coder_aspect))
408 » » return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERR OR; 381 » » return decoder->protected_->initstate = FLAC__STREAM_DECODER_INI T_STATUS_ERROR_OPENING_FILE;
409 #endif 382 #endif
410 383
411 /* 384 /*
412 * get the CPU info and set the function pointers 385 * get the CPU info and set the function pointers
413 */ 386 */
414 FLAC__cpu_info(&decoder->private_->cpuinfo); 387 FLAC__cpu_info(&decoder->private_->cpuinfo);
415 /* first default to the non-asm routines */ 388 /* first default to the non-asm routines */
416 decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal; 389 decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
417 decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_si gnal_wide; 390 decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_si gnal_wide;
418 decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_si gnal; 391 decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_si gnal;
419 decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_res tore_signal;
420 decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitrea der_read_rice_signed_block;
421 /* now override with asm where appropriate */ 392 /* now override with asm where appropriate */
422 #ifndef FLAC__NO_ASM 393 #ifndef FLAC__NO_ASM
423 if(decoder->private_->cpuinfo.use_asm) { 394 if(decoder->private_->cpuinfo.use_asm) {
424 #ifdef FLAC__CPU_IA32 395 #ifdef FLAC__CPU_IA32
425 FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TY PE_IA32); 396 FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TY PE_IA32);
426 #ifdef FLAC__HAS_NASM 397 #ifdef FLAC__HAS_NASM
427 #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */ 398 » » decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_re store_signal_wide_asm_ia32; /* OPT_IA32: was really necessary for GCC < 4.9 */
428 » » if(decoder->private_->cpuinfo.data.ia32.bswap) 399 » » if(decoder->private_->cpuinfo.ia32.mmx) {
429 » » » decoder->private_->local_bitreader_read_rice_signed_bloc k = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
430 #endif
431 » » if(decoder->private_->cpuinfo.data.ia32.mmx) {
432 decoder->private_->local_lpc_restore_signal = FLAC__lpc_ restore_signal_asm_ia32; 400 decoder->private_->local_lpc_restore_signal = FLAC__lpc_ restore_signal_asm_ia32;
433 decoder->private_->local_lpc_restore_signal_16bit = FLAC __lpc_restore_signal_asm_ia32_mmx; 401 decoder->private_->local_lpc_restore_signal_16bit = FLAC __lpc_restore_signal_asm_ia32_mmx;
434 decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
435 } 402 }
436 else { 403 else {
437 decoder->private_->local_lpc_restore_signal = FLAC__lpc_ restore_signal_asm_ia32; 404 decoder->private_->local_lpc_restore_signal = FLAC__lpc_ restore_signal_asm_ia32;
438 decoder->private_->local_lpc_restore_signal_16bit = FLAC __lpc_restore_signal_asm_ia32; 405 decoder->private_->local_lpc_restore_signal_16bit = FLAC __lpc_restore_signal_asm_ia32;
439 decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
440 } 406 }
441 #endif 407 #endif
442 #elif defined FLAC__CPU_PPC 408 #ifdef FLAC__HAS_X86INTRIN
443 » » FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TY PE_PPC); 409 # if defined FLAC__SSE2_SUPPORTED && !defined FLAC__HAS_NASM /* OPT_SSE: not bet ter than MMX asm */
444 » » if(decoder->private_->cpuinfo.data.ppc.altivec) { 410 » » if(decoder->private_->cpuinfo.ia32.sse2) {
445 » » » decoder->private_->local_lpc_restore_signal_16bit = FLAC __lpc_restore_signal_asm_ppc_altivec_16; 411 » » » decoder->private_->local_lpc_restore_signal_16bit = FLAC __lpc_restore_signal_16_intrin_sse2;
446 » » » decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
447 } 412 }
413 # endif
414 # if defined FLAC__SSE4_1_SUPPORTED
415 if(decoder->private_->cpuinfo.ia32.sse41) {
416 decoder->private_->local_lpc_restore_signal_64bit = FLAC __lpc_restore_signal_wide_intrin_sse41;
417 }
418 # endif
419 #endif
420 #elif defined FLAC__CPU_X86_64
421 FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TY PE_X86_64);
422 /* No useful SSE optimizations yet */
448 #endif 423 #endif
449 } 424 }
450 #endif 425 #endif
451 426
452 /* from here on, errors are fatal */ 427 /* from here on, errors are fatal */
453 428
454 » if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cp uinfo, read_callback_, decoder)) { 429 » if(!FLAC__bitreader_init(decoder->private_->input, read_callback_, decod er)) {
455 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR; 430 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR;
456 return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR; 431 return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
457 } 432 }
458 433
459 decoder->private_->read_callback = read_callback; 434 decoder->private_->read_callback = read_callback;
460 decoder->private_->seek_callback = seek_callback; 435 decoder->private_->seek_callback = seek_callback;
461 decoder->private_->tell_callback = tell_callback; 436 decoder->private_->tell_callback = tell_callback;
462 decoder->private_->length_callback = length_callback; 437 decoder->private_->length_callback = length_callback;
463 decoder->private_->eof_callback = eof_callback; 438 decoder->private_->eof_callback = eof_callback;
464 decoder->private_->write_callback = write_callback; 439 decoder->private_->write_callback = write_callback;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 FLAC__StreamDecoderMetadataCallback metadata_callback, 520 FLAC__StreamDecoderMetadataCallback metadata_callback,
546 FLAC__StreamDecoderErrorCallback error_callback, 521 FLAC__StreamDecoderErrorCallback error_callback,
547 void *client_data, 522 void *client_data,
548 FLAC__bool is_ogg 523 FLAC__bool is_ogg
549 ) 524 )
550 { 525 {
551 FLAC__ASSERT(0 != decoder); 526 FLAC__ASSERT(0 != decoder);
552 FLAC__ASSERT(0 != file); 527 FLAC__ASSERT(0 != file);
553 528
554 if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) 529 if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
555 » » return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_ST ATUS_ALREADY_INITIALIZED; 530 » » return decoder->protected_->initstate = FLAC__STREAM_DECODER_INI T_STATUS_ALREADY_INITIALIZED;
556 531
557 if(0 == write_callback || 0 == error_callback) 532 if(0 == write_callback || 0 == error_callback)
558 » » return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_ST ATUS_INVALID_CALLBACKS; 533 » » return decoder->protected_->initstate = FLAC__STREAM_DECODER_INI T_STATUS_INVALID_CALLBACKS;
559 534
560 /* 535 /*
561 * To make sure that our file does not go unclosed after an error, we 536 * To make sure that our file does not go unclosed after an error, we
562 * must assign the FILE pointer before any further error can occur in 537 * must assign the FILE pointer before any further error can occur in
563 * this routine. 538 * this routine.
564 */ 539 */
565 if(file == stdin) 540 if(file == stdin)
566 file = get_binary_stdin_(); /* just to be safe */ 541 file = get_binary_stdin_(); /* just to be safe */
567 542
568 decoder->private_->file = file; 543 decoder->private_->file = file;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 FILE *file; 594 FILE *file;
620 595
621 FLAC__ASSERT(0 != decoder); 596 FLAC__ASSERT(0 != decoder);
622 597
623 /* 598 /*
624 * To make sure that our file does not go unclosed after an error, we 599 * To make sure that our file does not go unclosed after an error, we
625 * have to do the same entrance checks here that are later performed 600 * have to do the same entrance checks here that are later performed
626 * in FLAC__stream_decoder_init_FILE() before the FILE* is assigned. 601 * in FLAC__stream_decoder_init_FILE() before the FILE* is assigned.
627 */ 602 */
628 if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) 603 if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
629 » » return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_ST ATUS_ALREADY_INITIALIZED; 604 » » return decoder->protected_->initstate = FLAC__STREAM_DECODER_INI T_STATUS_ALREADY_INITIALIZED;
630 605
631 if(0 == write_callback || 0 == error_callback) 606 if(0 == write_callback || 0 == error_callback)
632 » » return decoder->protected_->state = FLAC__STREAM_DECODER_INIT_ST ATUS_INVALID_CALLBACKS; 607 » » return decoder->protected_->initstate = FLAC__STREAM_DECODER_INI T_STATUS_INVALID_CALLBACKS;
633 608
634 » file = filename? fopen(filename, "rb") : stdin; 609 » file = filename? flac_fopen(filename, "rb") : stdin;
635 610
636 if(0 == file) 611 if(0 == file)
637 return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE; 612 return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
638 613
639 return init_FILE_internal_(decoder, file, write_callback, metadata_callb ack, error_callback, client_data, is_ogg); 614 return init_FILE_internal_(decoder, file, write_callback, metadata_callb ack, error_callback, client_data, is_ogg);
640 } 615 }
641 616
642 FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file( 617 FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
643 FLAC__StreamDecoder *decoder, 618 FLAC__StreamDecoder *decoder,
644 const char *filename, 619 const char *filename,
(...skipping 23 matching lines...) Expand all
668 FLAC__bool md5_failed = false; 643 FLAC__bool md5_failed = false;
669 unsigned i; 644 unsigned i;
670 645
671 FLAC__ASSERT(0 != decoder); 646 FLAC__ASSERT(0 != decoder);
672 FLAC__ASSERT(0 != decoder->private_); 647 FLAC__ASSERT(0 != decoder->private_);
673 FLAC__ASSERT(0 != decoder->protected_); 648 FLAC__ASSERT(0 != decoder->protected_);
674 649
675 if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED) 650 if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
676 return true; 651 return true;
677 652
678 » /* see the comment in FLAC__seekable_stream_decoder_reset() as to why we 653 » /* see the comment in FLAC__stream_decoder_reset() as to why we
679 * always call FLAC__MD5Final() 654 * always call FLAC__MD5Final()
680 */ 655 */
681 FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->m d5context); 656 FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->m d5context);
682 657
683 if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_tab le.data.seek_table.points) { 658 if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_tab le.data.seek_table.points) {
684 free(decoder->private_->seek_table.data.seek_table.points); 659 free(decoder->private_->seek_table.data.seek_table.points);
685 decoder->private_->seek_table.data.seek_table.points = 0; 660 decoder->private_->seek_table.data.seek_table.points = 0;
686 decoder->private_->has_seek_table = false; 661 decoder->private_->has_seek_table = false;
687 } 662 }
688 FLAC__bitreader_free(decoder->private_->input); 663 FLAC__bitreader_free(decoder->private_->input);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 FLAC__ASSERT(0 != id); 756 FLAC__ASSERT(0 != id);
782 if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) 757 if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
783 return false; 758 return false;
784 759
785 if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION]) 760 if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
786 return true; 761 return true;
787 762
788 FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids); 763 FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
789 764
790 if(decoder->private_->metadata_filter_ids_count == decoder->private_->me tadata_filter_ids_capacity) { 765 if(decoder->private_->metadata_filter_ids_count == decoder->private_->me tadata_filter_ids_capacity) {
791 » » if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)s afe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_-> metadata_filter_ids_capacity, /*times*/2))) { 766 » » if(0 == (decoder->private_->metadata_filter_ids = safe_realloc_m ul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filt er_ids_capacity, /*times*/2))) {
792 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR; 767 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR;
793 return false; 768 return false;
794 } 769 }
795 decoder->private_->metadata_filter_ids_capacity *= 2; 770 decoder->private_->metadata_filter_ids_capacity *= 2;
796 } 771 }
797 772
798 memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metad ata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__ STREAM_METADATA_APPLICATION_ID_LEN/8)); 773 memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metad ata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__ STREAM_METADATA_APPLICATION_ID_LEN/8));
799 decoder->private_->metadata_filter_ids_count++; 774 decoder->private_->metadata_filter_ids_count++;
800 775
801 return true; 776 return true;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 FLAC__ASSERT(0 != id); 815 FLAC__ASSERT(0 != id);
841 if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED) 816 if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
842 return false; 817 return false;
843 818
844 if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION]) 819 if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
845 return true; 820 return true;
846 821
847 FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids); 822 FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
848 823
849 if(decoder->private_->metadata_filter_ids_count == decoder->private_->me tadata_filter_ids_capacity) { 824 if(decoder->private_->metadata_filter_ids_count == decoder->private_->me tadata_filter_ids_capacity) {
850 » » if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)s afe_realloc_mul_2op_(decoder->private_->metadata_filter_ids, decoder->private_-> metadata_filter_ids_capacity, /*times*/2))) { 825 » » if(0 == (decoder->private_->metadata_filter_ids = safe_realloc_m ul_2op_(decoder->private_->metadata_filter_ids, decoder->private_->metadata_filt er_ids_capacity, /*times*/2))) {
851 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR; 826 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR;
852 return false; 827 return false;
853 } 828 }
854 decoder->private_->metadata_filter_ids_capacity *= 2; 829 decoder->private_->metadata_filter_ids_capacity *= 2;
855 } 830 }
856 831
857 memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metad ata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__ STREAM_METADATA_APPLICATION_ID_LEN/8)); 832 memcpy(decoder->private_->metadata_filter_ids + decoder->private_->metad ata_filter_ids_count * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__ STREAM_METADATA_APPLICATION_ID_LEN/8));
858 decoder->private_->metadata_filter_ids_count++; 833 decoder->private_->metadata_filter_ids_count++;
859 834
860 return true; 835 return true;
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 * This will forcibly set stdin to binary mode (for OSes that require it) 1259 * This will forcibly set stdin to binary mode (for OSes that require it)
1285 */ 1260 */
1286 FILE *get_binary_stdin_(void) 1261 FILE *get_binary_stdin_(void)
1287 { 1262 {
1288 /* if something breaks here it is probably due to the presence or 1263 /* if something breaks here it is probably due to the presence or
1289 * absence of an underscore before the identifiers 'setmode', 1264 * absence of an underscore before the identifiers 'setmode',
1290 * 'fileno', and/or 'O_BINARY'; check your system header files. 1265 * 'fileno', and/or 'O_BINARY'; check your system header files.
1291 */ 1266 */
1292 #if defined _MSC_VER || defined __MINGW32__ 1267 #if defined _MSC_VER || defined __MINGW32__
1293 _setmode(_fileno(stdin), _O_BINARY); 1268 _setmode(_fileno(stdin), _O_BINARY);
1294 #elif defined __CYGWIN__ 1269 #elif defined __CYGWIN__
1295 /* almost certainly not needed for any modern Cygwin, but let's be safe. .. */ 1270 /* almost certainly not needed for any modern Cygwin, but let's be safe. .. */
1296 setmode(_fileno(stdin), _O_BINARY); 1271 setmode(_fileno(stdin), _O_BINARY);
1297 #elif defined __EMX__ 1272 #elif defined __EMX__
1298 setmode(fileno(stdin), O_BINARY); 1273 setmode(fileno(stdin), O_BINARY);
1299 #endif 1274 #endif
1300 1275
1301 return stdin; 1276 return stdin;
1302 } 1277 }
1303 1278
1304 FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigne d channels) 1279 FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigne d channels)
(...skipping 17 matching lines...) Expand all
1322 } 1297 }
1323 } 1298 }
1324 1299
1325 for(i = 0; i < channels; i++) { 1300 for(i = 0; i < channels; i++) {
1326 /* WATCHOUT: 1301 /* WATCHOUT:
1327 * FLAC__lpc_restore_signal_asm_ia32_mmx() requires that the 1302 * FLAC__lpc_restore_signal_asm_ia32_mmx() requires that the
1328 * output arrays have a buffer of up to 3 zeroes in front 1303 * output arrays have a buffer of up to 3 zeroes in front
1329 * (at negative indices) for alignment purposes; we use 4 1304 * (at negative indices) for alignment purposes; we use 4
1330 * to keep the data well-aligned. 1305 * to keep the data well-aligned.
1331 */ 1306 */
1332 » » tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /* times (*/size, /*+*/4/*)*/); 1307 » » tmp = safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
1333 if(tmp == 0) { 1308 if(tmp == 0) {
1334 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR; 1309 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR;
1335 return false; 1310 return false;
1336 } 1311 }
1337 memset(tmp, 0, sizeof(FLAC__int32)*4); 1312 memset(tmp, 0, sizeof(FLAC__int32)*4);
1338 decoder->private_->output[i] = tmp + 4; 1313 decoder->private_->output[i] = tmp + 4;
1339 1314
1340 /* WATCHOUT:
1341 * minimum of quadword alignment for PPC vector optimizations is REQUIRED:
1342 */
1343 if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->priva te_->residual_unaligned[i], &decoder->private_->residual[i])) { 1315 if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->priva te_->residual_unaligned[i], &decoder->private_->residual[i])) {
1344 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR; 1316 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR;
1345 return false; 1317 return false;
1346 } 1318 }
1347 } 1319 }
1348 1320
1349 decoder->private_->output_capacity = size; 1321 decoder->private_->output_capacity = size;
1350 decoder->private_->output_channels = channels; 1322 decoder->private_->output_channels = channels;
1351 1323
1352 return true; 1324 return true;
(...skipping 29 matching lines...) Expand all
1382 else { 1354 else {
1383 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, 8)) 1355 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, 8))
1384 return false; /* read_callback_ sets the state f or us */ 1356 return false; /* read_callback_ sets the state f or us */
1385 } 1357 }
1386 if(x == FLAC__STREAM_SYNC_STRING[i]) { 1358 if(x == FLAC__STREAM_SYNC_STRING[i]) {
1387 first = true; 1359 first = true;
1388 i++; 1360 i++;
1389 id = 0; 1361 id = 0;
1390 continue; 1362 continue;
1391 } 1363 }
1364
1365 if(id >= 3)
1366 return false;
1367
1392 if(x == ID3V2_TAG_[id]) { 1368 if(x == ID3V2_TAG_[id]) {
1393 id++; 1369 id++;
1394 i = 0; 1370 i = 0;
1395 if(id == 3) { 1371 if(id == 3) {
1396 if(!skip_id3v2_tag_(decoder)) 1372 if(!skip_id3v2_tag_(decoder))
1397 return false; /* skip_id3v2_tag_ sets th e state for us */ 1373 return false; /* skip_id3v2_tag_ sets th e state for us */
1398 } 1374 }
1399 continue; 1375 continue;
1400 } 1376 }
1401 id = 0; 1377 id = 0;
1402 if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */ 1378 if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
1403 decoder->private_->header_warmup[0] = (FLAC__byte)x; 1379 decoder->private_->header_warmup[0] = (FLAC__byte)x;
1404 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, 8)) 1380 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, 8))
1405 return false; /* read_callback_ sets the state f or us */ 1381 return false; /* read_callback_ sets the state f or us */
1406 1382
1407 /* we have to check if we just read two 0xff's in a row; the second may actually be the beginning of the sync code */ 1383 /* we have to check if we just read two 0xff's in a row; the second may actually be the beginning of the sync code */
1408 /* else we have to check if the second byte is the end o f a sync code */ 1384 /* else we have to check if the second byte is the end o f a sync code */
1409 if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sy nc bits */ 1385 if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sy nc bits */
1410 decoder->private_->lookahead = (FLAC__byte)x; 1386 decoder->private_->lookahead = (FLAC__byte)x;
1411 decoder->private_->cached = true; 1387 decoder->private_->cached = true;
1412 } 1388 }
1413 » » » else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */ 1389 » » » else if(x >> 1 == 0x7c) { /* MAGIC NUMBER for the last 6 sync bits and reserved 7th bit */
1414 decoder->private_->header_warmup[1] = (FLAC__byt e)x; 1390 decoder->private_->header_warmup[1] = (FLAC__byt e)x;
1415 decoder->protected_->state = FLAC__STREAM_DECODE R_READ_FRAME; 1391 decoder->protected_->state = FLAC__STREAM_DECODE R_READ_FRAME;
1416 return true; 1392 return true;
1417 } 1393 }
1418 } 1394 }
1419 i = 0; 1395 i = 0;
1420 if(first) { 1396 if(first) {
1421 send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERRO R_STATUS_LOST_SYNC); 1397 send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERRO R_STATUS_LOST_SYNC);
1422 first = false; 1398 first = false;
1423 } 1399 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 1436
1461 decoder->private_->has_seek_table = true; 1437 decoder->private_->has_seek_table = true;
1462 if(!decoder->private_->is_seeking && decoder->private_->metadata _filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback) 1438 if(!decoder->private_->is_seeking && decoder->private_->metadata _filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
1463 decoder->private_->metadata_callback(decoder, &decoder-> private_->seek_table, decoder->private_->client_data); 1439 decoder->private_->metadata_callback(decoder, &decoder-> private_->seek_table, decoder->private_->client_data);
1464 } 1440 }
1465 else { 1441 else {
1466 FLAC__bool skip_it = !decoder->private_->metadata_filter[type]; 1442 FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
1467 unsigned real_length = length; 1443 unsigned real_length = length;
1468 FLAC__StreamMetadata block; 1444 FLAC__StreamMetadata block;
1469 1445
1446 memset(&block, 0, sizeof(block));
1470 block.is_last = is_last; 1447 block.is_last = is_last;
1471 block.type = (FLAC__MetadataType)type; 1448 block.type = (FLAC__MetadataType)type;
1472 block.length = length; 1449 block.length = length;
1473 1450
1474 if(type == FLAC__METADATA_TYPE_APPLICATION) { 1451 if(type == FLAC__METADATA_TYPE_APPLICATION) {
1475 if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decod er->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATIO N_ID_LEN/8)) 1452 if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decod er->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATIO N_ID_LEN/8))
1476 return false; /* read_callback_ sets the state f or us */ 1453 return false; /* read_callback_ sets the state f or us */
1477 1454
1478 if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LE N/8) { /* underflow check */ 1455 if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LE N/8) { /* underflow check */
1479 decoder->protected_->state = FLAC__STREAM_DECODE R_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/ 1456 decoder->protected_->state = FLAC__STREAM_DECODE R_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
1480 return false; 1457 return false;
1481 } 1458 }
1482 1459
1483 real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/ 8; 1460 real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/ 8;
1484 1461
1485 if(decoder->private_->metadata_filter_ids_count > 0 && h as_id_filtered_(decoder, block.data.application.id)) 1462 if(decoder->private_->metadata_filter_ids_count > 0 && h as_id_filtered_(decoder, block.data.application.id))
1486 skip_it = !skip_it; 1463 skip_it = !skip_it;
1487 } 1464 }
1488 1465
1489 if(skip_it) { 1466 if(skip_it) {
1490 if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decod er->private_->input, real_length)) 1467 if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decod er->private_->input, real_length))
1491 return false; /* read_callback_ sets the state f or us */ 1468 return false; /* read_callback_ sets the state f or us */
1492 } 1469 }
1493 else { 1470 else {
1471 FLAC__bool ok = true;
1494 switch(type) { 1472 switch(type) {
1495 case FLAC__METADATA_TYPE_PADDING: 1473 case FLAC__METADATA_TYPE_PADDING:
1496 /* skip the padding bytes */ 1474 /* skip the padding bytes */
1497 if(!FLAC__bitreader_skip_byte_block_alig ned_no_crc(decoder->private_->input, real_length)) 1475 if(!FLAC__bitreader_skip_byte_block_alig ned_no_crc(decoder->private_->input, real_length))
1498 » » » » » » return false; /* read_callback_ sets the state for us */ 1476 » » » » » » ok = false; /* read_callback_ se ts the state for us */
1499 break; 1477 break;
1500 case FLAC__METADATA_TYPE_APPLICATION: 1478 case FLAC__METADATA_TYPE_APPLICATION:
1501 /* remember, we read the ID already */ 1479 /* remember, we read the ID already */
1502 if(real_length > 0) { 1480 if(real_length > 0) {
1503 » » » » » » if(0 == (block.data.application. data = (FLAC__byte*)malloc(real_length))) { 1481 » » » » » » if(0 == (block.data.application. data = malloc(real_length))) {
1504 decoder->protected_->sta te = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; 1482 decoder->protected_->sta te = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
1505 » » » » » » » return false; 1483 » » » » » » » ok = false;
1506 } 1484 }
1507 » » » » » » if(!FLAC__bitreader_read_byte_bl ock_aligned_no_crc(decoder->private_->input, block.data.application.data, real_l ength)) 1485 » » » » » » else if(!FLAC__bitreader_read_by te_block_aligned_no_crc(decoder->private_->input, block.data.application.data, r eal_length))
1508 » » » » » » » return false; /* read_ca llback_ sets the state for us */ 1486 » » » » » » » ok = false; /* read_call back_ sets the state for us */
1509 } 1487 }
1510 else 1488 else
1511 block.data.application.data = 0; 1489 block.data.application.data = 0;
1512 break; 1490 break;
1513 case FLAC__METADATA_TYPE_VORBIS_COMMENT: 1491 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
1514 » » » » » if(!read_metadata_vorbiscomment_(decoder , &block.data.vorbis_comment)) 1492 » » » » » if(!read_metadata_vorbiscomment_(decoder , &block.data.vorbis_comment, real_length))
1515 » » » » » » return false; 1493 » » » » » » ok = false;
1516 break; 1494 break;
1517 case FLAC__METADATA_TYPE_CUESHEET: 1495 case FLAC__METADATA_TYPE_CUESHEET:
1518 if(!read_metadata_cuesheet_(decoder, &bl ock.data.cue_sheet)) 1496 if(!read_metadata_cuesheet_(decoder, &bl ock.data.cue_sheet))
1519 » » » » » » return false; 1497 » » » » » » ok = false;
1520 break; 1498 break;
1521 case FLAC__METADATA_TYPE_PICTURE: 1499 case FLAC__METADATA_TYPE_PICTURE:
1522 if(!read_metadata_picture_(decoder, &blo ck.data.picture)) 1500 if(!read_metadata_picture_(decoder, &blo ck.data.picture))
1523 » » » » » » return false; 1501 » » » » » » ok = false;
1524 break; 1502 break;
1525 case FLAC__METADATA_TYPE_STREAMINFO: 1503 case FLAC__METADATA_TYPE_STREAMINFO:
1526 case FLAC__METADATA_TYPE_SEEKTABLE: 1504 case FLAC__METADATA_TYPE_SEEKTABLE:
1527 FLAC__ASSERT(0); 1505 FLAC__ASSERT(0);
1528 break; 1506 break;
1529 default: 1507 default:
1530 if(real_length > 0) { 1508 if(real_length > 0) {
1531 » » » » » » if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) { 1509 » » » » » » if(0 == (block.data.unknown.data = malloc(real_length))) {
1532 decoder->protected_->sta te = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR; 1510 decoder->protected_->sta te = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
1533 » » » » » » » return false; 1511 » » » » » » » ok = false;
1534 } 1512 }
1535 » » » » » » if(!FLAC__bitreader_read_byte_bl ock_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_lengt h)) 1513 » » » » » » else if(!FLAC__bitreader_read_by te_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_ length))
1536 » » » » » » » return false; /* read_ca llback_ sets the state for us */ 1514 » » » » » » » ok = false; /* read_call back_ sets the state for us */
1537 } 1515 }
1538 else 1516 else
1539 block.data.unknown.data = 0; 1517 block.data.unknown.data = 0;
1540 break; 1518 break;
1541 } 1519 }
1542 » » » if(!decoder->private_->is_seeking && decoder->private_-> metadata_callback) 1520 » » » if(ok && !decoder->private_->is_seeking && decoder->priv ate_->metadata_callback)
1543 decoder->private_->metadata_callback(decoder, &b lock, decoder->private_->client_data); 1521 decoder->private_->metadata_callback(decoder, &b lock, decoder->private_->client_data);
1544 1522
1545 /* now we have to free any malloc()ed data in the block */ 1523 /* now we have to free any malloc()ed data in the block */
1546 switch(type) { 1524 switch(type) {
1547 case FLAC__METADATA_TYPE_PADDING: 1525 case FLAC__METADATA_TYPE_PADDING:
1548 break; 1526 break;
1549 case FLAC__METADATA_TYPE_APPLICATION: 1527 case FLAC__METADATA_TYPE_APPLICATION:
1550 if(0 != block.data.application.data) 1528 if(0 != block.data.application.data)
1551 free(block.data.application.data ); 1529 free(block.data.application.data );
1552 break; 1530 break;
(...skipping 24 matching lines...) Expand all
1577 free(block.data.picture.data); 1555 free(block.data.picture.data);
1578 break; 1556 break;
1579 case FLAC__METADATA_TYPE_STREAMINFO: 1557 case FLAC__METADATA_TYPE_STREAMINFO:
1580 case FLAC__METADATA_TYPE_SEEKTABLE: 1558 case FLAC__METADATA_TYPE_SEEKTABLE:
1581 FLAC__ASSERT(0); 1559 FLAC__ASSERT(0);
1582 default: 1560 default:
1583 if(0 != block.data.unknown.data) 1561 if(0 != block.data.unknown.data)
1584 free(block.data.unknown.data); 1562 free(block.data.unknown.data);
1585 break; 1563 break;
1586 } 1564 }
1565
1566 if(!ok) /* anything that unsets "ok" should also make su re decoder->protected_->state is updated */
1567 return false;
1587 } 1568 }
1588 } 1569 }
1589 1570
1590 if(is_last) { 1571 if(is_last) {
1591 /* if this fails, it's OK, it's just a hint for the seek routine */ 1572 /* if this fails, it's OK, it's just a hint for the seek routine */
1592 if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder-> private_->first_frame_offset)) 1573 if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder-> private_->first_frame_offset))
1593 decoder->private_->first_frame_offset = 0; 1574 decoder->private_->first_frame_offset = 0;
1594 decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRA ME_SYNC; 1575 decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRA ME_SYNC;
1595 } 1576 }
1596 1577
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 1656
1676 FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_- >input)); 1657 FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_- >input));
1677 1658
1678 decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE; 1659 decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
1679 decoder->private_->seek_table.is_last = is_last; 1660 decoder->private_->seek_table.is_last = is_last;
1680 decoder->private_->seek_table.length = length; 1661 decoder->private_->seek_table.length = length;
1681 1662
1682 decoder->private_->seek_table.data.seek_table.num_points = length / FLAC __STREAM_METADATA_SEEKPOINT_LENGTH; 1663 decoder->private_->seek_table.data.seek_table.num_points = length / FLAC __STREAM_METADATA_SEEKPOINT_LENGTH;
1683 1664
1684 /* use realloc since we may pass through here several times (e.g. after seeking) */ 1665 /* use realloc since we may pass through here several times (e.g. after seeking) */
1685 » if(0 == (decoder->private_->seek_table.data.seek_table.points = (FLAC__S treamMetadata_SeekPoint*)safe_realloc_mul_2op_(decoder->private_->seek_table.dat a.seek_table.points, decoder->private_->seek_table.data.seek_table.num_points, / *times*/sizeof(FLAC__StreamMetadata_SeekPoint)))) { 1666 » if(0 == (decoder->private_->seek_table.data.seek_table.points = safe_rea lloc_mul_2op_(decoder->private_->seek_table.data.seek_table.points, decoder->pri vate_->seek_table.data.seek_table.num_points, /*times*/sizeof(FLAC__StreamMetada ta_SeekPoint)))) {
1686 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR; 1667 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR;
1687 return false; 1668 return false;
1688 } 1669 }
1689 for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) { 1670 for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
1690 if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &x x, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN)) 1671 if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &x x, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
1691 return false; /* read_callback_ sets the state for us */ 1672 return false; /* read_callback_ sets the state for us */
1692 decoder->private_->seek_table.data.seek_table.points[i].sample_n umber = xx; 1673 decoder->private_->seek_table.data.seek_table.points[i].sample_n umber = xx;
1693 1674
1694 if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &x x, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN)) 1675 if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &x x, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
1695 return false; /* read_callback_ sets the state for us */ 1676 return false; /* read_callback_ sets the state for us */
1696 decoder->private_->seek_table.data.seek_table.points[i].stream_o ffset = xx; 1677 decoder->private_->seek_table.data.seek_table.points[i].stream_o ffset = xx;
1697 1678
1698 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x , FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN)) 1679 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x , FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
1699 return false; /* read_callback_ sets the state for us */ 1680 return false; /* read_callback_ sets the state for us */
1700 decoder->private_->seek_table.data.seek_table.points[i].frame_sa mples = x; 1681 decoder->private_->seek_table.data.seek_table.points[i].frame_sa mples = x;
1701 } 1682 }
1702 length -= (decoder->private_->seek_table.data.seek_table.num_points * FL AC__STREAM_METADATA_SEEKPOINT_LENGTH); 1683 length -= (decoder->private_->seek_table.data.seek_table.num_points * FL AC__STREAM_METADATA_SEEKPOINT_LENGTH);
1703 /* if there is a partial point left, skip over it */ 1684 /* if there is a partial point left, skip over it */
1704 if(length > 0) { 1685 if(length > 0) {
1705 /*@@@ do a send_error_to_client_() here? there's an argument fo r either way */ 1686 /*@@@ do a send_error_to_client_() here? there's an argument fo r either way */
1706 if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->priv ate_->input, length)) 1687 if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->priv ate_->input, length))
1707 return false; /* read_callback_ sets the state for us */ 1688 return false; /* read_callback_ sets the state for us */
1708 } 1689 }
1709 1690
1710 return true; 1691 return true;
1711 } 1692 }
1712 1693
1713 FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre amMetadata_VorbisComment *obj) 1694 FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__Stre amMetadata_VorbisComment *obj, unsigned length)
1714 { 1695 {
1715 FLAC__uint32 i; 1696 FLAC__uint32 i;
1716 1697
1717 FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_- >input)); 1698 FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_- >input));
1718 1699
1719 /* read vendor string */ 1700 /* read vendor string */
1720 » FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32 ); 1701 » if (length >= 8) {
1721 » if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length)) 1702 » » length -= 8; /* vendor string length + num comments entries alon e take 8 bytes */
1722 » » return false; /* read_callback_ sets the state for us */ 1703 » » FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_L EN == 32);
1723 » if(obj->vendor_string.length > 0) { 1704 » » if (!FLAC__bitreader_read_uint32_little_endian(decoder->private_ ->input, &obj->vendor_string.length))
1724 » » if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add _2op_(obj->vendor_string.length, /*+*/1))) {
1725 » » » decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR;
1726 » » » return false;
1727 » » }
1728 » » if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->priv ate_->input, obj->vendor_string.entry, obj->vendor_string.length))
1729 return false; /* read_callback_ sets the state for us */ 1705 return false; /* read_callback_ sets the state for us */
1730 » » obj->vendor_string.entry[obj->vendor_string.length] = '\0'; 1706 » » if (obj->vendor_string.length > 0) {
1731 » } 1707 » » » if (length < obj->vendor_string.length) {
1732 » else 1708 » » » » obj->vendor_string.length = 0;
1733 » » obj->vendor_string.entry = 0; 1709 » » » » obj->vendor_string.entry = 0;
1734 1710 » » » » goto skip;
1735 » /* read num comments */
1736 » FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32 );
1737 » if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
1738 » » return false; /* read_callback_ sets the state for us */
1739
1740 » /* read comments */
1741 » if(obj->num_comments > 0) {
1742 » » if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Ent ry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata _VorbisComment_Entry)))) {
1743 » » » decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR;
1744 » » » return false;
1745 » » }
1746 » » for(i = 0; i < obj->num_comments; i++) {
1747 » » » FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_ LENGTH_LEN == 32);
1748 » » » if(!FLAC__bitreader_read_uint32_little_endian(decoder->p rivate_->input, &obj->comments[i].length))
1749 » » » » return false; /* read_callback_ sets the state f or us */
1750 » » » if(obj->comments[i].length > 0) {
1751 » » » » if(0 == (obj->comments[i].entry = (FLAC__byte*)s afe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
1752 » » » » » decoder->protected_->state = FLAC__STREA M_DECODER_MEMORY_ALLOCATION_ERROR;
1753 » » » » » return false;
1754 » » » » }
1755 » » » » if(!FLAC__bitreader_read_byte_block_aligned_no_c rc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
1756 » » » » » return false; /* read_callback_ sets the state for us */
1757 » » » » obj->comments[i].entry[obj->comments[i].length] = '\0';
1758 } 1711 }
1759 else 1712 else
1760 » » » » obj->comments[i].entry = 0; 1713 » » » » length -= obj->vendor_string.length;
1714 » » » if (0 == (obj->vendor_string.entry = safe_malloc_add_2op _(obj->vendor_string.length, /*+*/1))) {
1715 » » » » decoder->protected_->state = FLAC__STREAM_DECODE R_MEMORY_ALLOCATION_ERROR;
1716 » » » » return false;
1717 » » » }
1718 » » » if (!FLAC__bitreader_read_byte_block_aligned_no_crc(deco der->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
1719 » » » » return false; /* read_callback_ sets the state f or us */
1720 » » » obj->vendor_string.entry[obj->vendor_string.length] = '\ 0';
1761 } 1721 }
1722 else
1723 obj->vendor_string.entry = 0;
1724
1725 /* read num comments */
1726 FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_L EN == 32);
1727 if (!FLAC__bitreader_read_uint32_little_endian(decoder->private_ ->input, &obj->num_comments))
1728 return false; /* read_callback_ sets the state for us */
1729
1730 /* read comments */
1731 if (obj->num_comments > 0) {
1732 if (0 == (obj->comments = safe_malloc_mul_2op_p(obj->num _comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
1733 decoder->protected_->state = FLAC__STREAM_DECODE R_MEMORY_ALLOCATION_ERROR;
1734 return false;
1735 }
1736 for (i = 0; i < obj->num_comments; i++) {
1737 FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMEN T_ENTRY_LENGTH_LEN == 32);
1738 if (length < 4) {
1739 obj->num_comments = i;
1740 goto skip;
1741 }
1742 else
1743 length -= 4;
1744 if (!FLAC__bitreader_read_uint32_little_endian(d ecoder->private_->input, &obj->comments[i].length))
1745 return false; /* read_callback_ sets the state for us */
1746 if (obj->comments[i].length > 0) {
1747 if (length < obj->comments[i].length) {
1748 obj->comments[i].length = 0;
1749 obj->comments[i].entry = 0;
1750 obj->num_comments = i;
1751 goto skip;
1752 }
1753 else
1754 length -= obj->comments[i].lengt h;
1755 if (0 == (obj->comments[i].entry = safe_ malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
1756 decoder->protected_->state = FLA C__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
1757 return false;
1758 }
1759 if (!FLAC__bitreader_read_byte_block_ali gned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].l ength))
1760 return false; /* read_callback_ sets the state for us */
1761 obj->comments[i].entry[obj->comments[i]. length] = '\0';
1762 }
1763 else
1764 obj->comments[i].entry = 0;
1765 }
1766 }
1767 else
1768 obj->comments = 0;
1762 } 1769 }
1763 » else { 1770
1764 » » obj->comments = 0; 1771 skip:
1772 » if (length > 0) {
1773 » » /* This will only happen on files with invalid data in comments */
1774 » » if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->priv ate_->input, length))
1775 » » » return false; /* read_callback_ sets the state for us */
1765 } 1776 }
1766 1777
1767 return true; 1778 return true;
1768 } 1779 }
1769 1780
1770 FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMet adata_CueSheet *obj) 1781 FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMet adata_CueSheet *obj)
1771 { 1782 {
1772 FLAC__uint32 i, j, x; 1783 FLAC__uint32 i, j, x;
1773 1784
1774 FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_- >input)); 1785 FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_- >input));
(...skipping 12 matching lines...) Expand all
1787 obj->is_cd = x? true : false; 1798 obj->is_cd = x? true : false;
1788 1799
1789 if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STR EAM_METADATA_CUESHEET_RESERVED_LEN)) 1800 if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STR EAM_METADATA_CUESHEET_RESERVED_LEN))
1790 return false; /* read_callback_ sets the state for us */ 1801 return false; /* read_callback_ sets the state for us */
1791 1802
1792 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__ STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN)) 1803 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__ STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
1793 return false; /* read_callback_ sets the state for us */ 1804 return false; /* read_callback_ sets the state for us */
1794 obj->num_tracks = x; 1805 obj->num_tracks = x;
1795 1806
1796 if(obj->num_tracks > 0) { 1807 if(obj->num_tracks > 0) {
1797 » » if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)saf e_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) { 1808 » » if(0 == (obj->tracks = safe_calloc_(obj->num_tracks, sizeof(FLAC __StreamMetadata_CueSheet_Track)))) {
1798 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR; 1809 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY _ALLOCATION_ERROR;
1799 return false; 1810 return false;
1800 } 1811 }
1801 for(i = 0; i < obj->num_tracks; i++) { 1812 for(i = 0; i < obj->num_tracks; i++) {
1802 FLAC__StreamMetadata_CueSheet_Track *track = &obj->track s[i]; 1813 FLAC__StreamMetadata_CueSheet_Track *track = &obj->track s[i];
1803 if(!FLAC__bitreader_read_raw_uint64(decoder->private_->i nput, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN)) 1814 if(!FLAC__bitreader_read_raw_uint64(decoder->private_->i nput, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
1804 return false; /* read_callback_ sets the state f or us */ 1815 return false; /* read_callback_ sets the state f or us */
1805 1816
1806 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN)) 1817 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
1807 return false; /* read_callback_ sets the state f or us */ 1818 return false; /* read_callback_ sets the state f or us */
(...skipping 12 matching lines...) Expand all
1820 track->pre_emphasis = x; 1831 track->pre_emphasis = x;
1821 1832
1822 if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_-> input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN)) 1833 if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_-> input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
1823 return false; /* read_callback_ sets the state f or us */ 1834 return false; /* read_callback_ sets the state f or us */
1824 1835
1825 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN)) 1836 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
1826 return false; /* read_callback_ sets the state f or us */ 1837 return false; /* read_callback_ sets the state f or us */
1827 track->num_indices = (FLAC__byte)x; 1838 track->num_indices = (FLAC__byte)x;
1828 1839
1829 if(track->num_indices > 0) { 1840 if(track->num_indices > 0) {
1830 » » » » if(0 == (track->indices = (FLAC__StreamMetadata_ CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_Cue Sheet_Index)))) { 1841 » » » » if(0 == (track->indices = safe_calloc_(track->nu m_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
1831 decoder->protected_->state = FLAC__STREA M_DECODER_MEMORY_ALLOCATION_ERROR; 1842 decoder->protected_->state = FLAC__STREA M_DECODER_MEMORY_ALLOCATION_ERROR;
1832 return false; 1843 return false;
1833 } 1844 }
1834 for(j = 0; j < track->num_indices; j++) { 1845 for(j = 0; j < track->num_indices; j++) {
1835 » » » » » FLAC__StreamMetadata_CueSheet_Index *ind ex = &track->indices[j]; 1846 » » » » » FLAC__StreamMetadata_CueSheet_Index *ind x = &track->indices[j];
1836 » » » » » if(!FLAC__bitreader_read_raw_uint64(deco der->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSE T_LEN)) 1847 » » » » » if(!FLAC__bitreader_read_raw_uint64(deco der->private_->input, &indx->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET _LEN))
1837 return false; /* read_callback_ sets the state for us */ 1848 return false; /* read_callback_ sets the state for us */
1838 1849
1839 if(!FLAC__bitreader_read_raw_uint32(deco der->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN)) 1850 if(!FLAC__bitreader_read_raw_uint32(deco der->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
1840 return false; /* read_callback_ sets the state for us */ 1851 return false; /* read_callback_ sets the state for us */
1841 » » » » » index->number = (FLAC__byte)x; 1852 » » » » » indx->number = (FLAC__byte)x;
1842 1853
1843 if(!FLAC__bitreader_skip_bits_no_crc(dec oder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN)) 1854 if(!FLAC__bitreader_skip_bits_no_crc(dec oder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
1844 return false; /* read_callback_ sets the state for us */ 1855 return false; /* read_callback_ sets the state for us */
1845 } 1856 }
1846 } 1857 }
1847 } 1858 }
1848 } 1859 }
1849 1860
1850 return true; 1861 return true;
1851 } 1862 }
1852 1863
1853 FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMeta data_Picture *obj) 1864 FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMeta data_Picture *obj)
1854 { 1865 {
1855 FLAC__uint32 x; 1866 FLAC__uint32 x;
1856 1867
1857 FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_- >input)); 1868 FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_- >input));
1858 1869
1859 /* read type */ 1870 /* read type */
1860 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__ STREAM_METADATA_PICTURE_TYPE_LEN)) 1871 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__ STREAM_METADATA_PICTURE_TYPE_LEN))
1861 return false; /* read_callback_ sets the state for us */ 1872 return false; /* read_callback_ sets the state for us */
1862 obj->type = x; 1873 obj->type = x;
1863 1874
1864 /* read MIME type */ 1875 /* read MIME type */
1865 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__ STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN)) 1876 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__ STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
1866 return false; /* read_callback_ sets the state for us */ 1877 return false; /* read_callback_ sets the state for us */
1867 » if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) { 1878 » if(0 == (obj->mime_type = safe_malloc_add_2op_(x, /*+*/1))) {
1868 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR; 1879 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR;
1869 return false; 1880 return false;
1870 } 1881 }
1871 if(x > 0) { 1882 if(x > 0) {
1872 if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->priv ate_->input, (FLAC__byte*)obj->mime_type, x)) 1883 if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->priv ate_->input, (FLAC__byte*)obj->mime_type, x))
1873 return false; /* read_callback_ sets the state for us */ 1884 return false; /* read_callback_ sets the state for us */
1874 } 1885 }
1875 obj->mime_type[x] = '\0'; 1886 obj->mime_type[x] = '\0';
1876 1887
1877 /* read description */ 1888 /* read description */
1878 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__ STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN)) 1889 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__ STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
1879 return false; /* read_callback_ sets the state for us */ 1890 return false; /* read_callback_ sets the state for us */
1880 » if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1) )) { 1891 » if(0 == (obj->description = safe_malloc_add_2op_(x, /*+*/1))) {
1881 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR; 1892 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR;
1882 return false; 1893 return false;
1883 } 1894 }
1884 if(x > 0) { 1895 if(x > 0) {
1885 if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->priv ate_->input, obj->description, x)) 1896 if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->priv ate_->input, obj->description, x))
1886 return false; /* read_callback_ sets the state for us */ 1897 return false; /* read_callback_ sets the state for us */
1887 } 1898 }
1888 obj->description[x] = '\0'; 1899 obj->description[x] = '\0';
1889 1900
1890 /* read width */ 1901 /* read width */
1891 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->widt h, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN)) 1902 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->widt h, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
1892 return false; /* read_callback_ sets the state for us */ 1903 return false; /* read_callback_ sets the state for us */
1893 1904
1894 /* read height */ 1905 /* read height */
1895 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->heig ht, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN)) 1906 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->heig ht, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
1896 return false; /* read_callback_ sets the state for us */ 1907 return false; /* read_callback_ sets the state for us */
1897 1908
1898 /* read depth */ 1909 /* read depth */
1899 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->dept h, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN)) 1910 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->dept h, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
1900 return false; /* read_callback_ sets the state for us */ 1911 return false; /* read_callback_ sets the state for us */
1901 1912
1902 /* read colors */ 1913 /* read colors */
1903 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colo rs, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN)) 1914 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colo rs, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
1904 return false; /* read_callback_ sets the state for us */ 1915 return false; /* read_callback_ sets the state for us */
1905 1916
1906 /* read data */ 1917 /* read data */
1907 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->dat a_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN)) 1918 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->dat a_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
1908 return false; /* read_callback_ sets the state for us */ 1919 return false; /* read_callback_ sets the state for us */
1909 » if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) { 1920 » if(0 == (obj->data = safe_malloc_(obj->data_length))) {
1910 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR; 1921 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR;
1911 return false; 1922 return false;
1912 } 1923 }
1913 if(obj->data_length > 0) { 1924 if(obj->data_length > 0) {
1914 if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->priv ate_->input, obj->data, obj->data_length)) 1925 if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->priv ate_->input, obj->data, obj->data_length))
1915 return false; /* read_callback_ sets the state for us */ 1926 return false; /* read_callback_ sets the state for us */
1916 } 1927 }
1917 1928
1918 return true; 1929 return true;
1919 } 1930 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 decoder->private_->header_warmup[0] = (FLAC__byte)x; 1984 decoder->private_->header_warmup[0] = (FLAC__byte)x;
1974 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, 8)) 1985 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &x, 8))
1975 return false; /* read_callback_ sets the state f or us */ 1986 return false; /* read_callback_ sets the state f or us */
1976 1987
1977 /* we have to check if we just read two 0xff's in a row; the second may actually be the beginning of the sync code */ 1988 /* we have to check if we just read two 0xff's in a row; the second may actually be the beginning of the sync code */
1978 /* else we have to check if the second byte is the end o f a sync code */ 1989 /* else we have to check if the second byte is the end o f a sync code */
1979 if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sy nc bits */ 1990 if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sy nc bits */
1980 decoder->private_->lookahead = (FLAC__byte)x; 1991 decoder->private_->lookahead = (FLAC__byte)x;
1981 decoder->private_->cached = true; 1992 decoder->private_->cached = true;
1982 } 1993 }
1983 » » » else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */ 1994 » » » else if(x >> 1 == 0x7c) { /* MAGIC NUMBER for the last 6 sync bits and reserved 7th bit */
1984 decoder->private_->header_warmup[1] = (FLAC__byt e)x; 1995 decoder->private_->header_warmup[1] = (FLAC__byt e)x;
1985 decoder->protected_->state = FLAC__STREAM_DECODE R_READ_FRAME; 1996 decoder->protected_->state = FLAC__STREAM_DECODE R_READ_FRAME;
1986 return true; 1997 return true;
1987 } 1998 }
1988 } 1999 }
1989 if(first) { 2000 if(first) {
1990 send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERRO R_STATUS_LOST_SYNC); 2001 send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERRO R_STATUS_LOST_SYNC);
1991 first = false; 2002 first = false;
1992 } 2003 }
1993 } 2004 }
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
2669 FLAC__ASSERT(0); 2680 FLAC__ASSERT(0);
2670 } 2681 }
2671 2682
2672 /* decode the subframe */ 2683 /* decode the subframe */
2673 if(do_full_decode) { 2684 if(do_full_decode) {
2674 memcpy(decoder->private_->output[channel], subframe->warmup, siz eof(FLAC__int32) * order); 2685 memcpy(decoder->private_->output[channel], subframe->warmup, siz eof(FLAC__int32) * order);
2675 /*@@@@@@ technically not pessimistic enough, should be more like 2686 /*@@@@@@ technically not pessimistic enough, should be more like
2676 if( (FLAC__uint64)order * ((((FLAC__uint64)1)<<bps)-1) * ((1<<su bframe->qlp_coeff_precision)-1) < (((FLAC__uint64)-1) << 32) ) 2687 if( (FLAC__uint64)order * ((((FLAC__uint64)1)<<bps)-1) * ((1<<su bframe->qlp_coeff_precision)-1) < (((FLAC__uint64)-1) << 32) )
2677 */ 2688 */
2678 if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(ord er) <= 32) 2689 if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(ord er) <= 32)
2679 » » » if(bps <= 16 && subframe->qlp_coeff_precision <= 16) { 2690 » » » if(bps <= 16 && subframe->qlp_coeff_precision <= 16)
2680 » » » » if(order <= 8) 2691 » » » » decoder->private_->local_lpc_restore_signal_16bi t(decoder->private_->residual[channel], decoder->private_->frame.header.blocksiz e-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->priv ate_->output[channel]+order);
2681 » » » » » decoder->private_->local_lpc_restore_sig nal_16bit_order8(decoder->private_->residual[channel], decoder->private_->frame. header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level , decoder->private_->output[channel]+order);
2682 » » » » else
2683 » » » » » decoder->private_->local_lpc_restore_sig nal_16bit(decoder->private_->residual[channel], decoder->private_->frame.header. blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decod er->private_->output[channel]+order);
2684 » » » }
2685 else 2692 else
2686 decoder->private_->local_lpc_restore_signal(deco der->private_->residual[channel], decoder->private_->frame.header.blocksize-orde r, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_-> output[channel]+order); 2693 decoder->private_->local_lpc_restore_signal(deco der->private_->residual[channel], decoder->private_->frame.header.blocksize-orde r, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_-> output[channel]+order);
2687 else 2694 else
2688 decoder->private_->local_lpc_restore_signal_64bit(decode r->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->ou tput[channel]+order); 2695 decoder->private_->local_lpc_restore_signal_64bit(decode r->private_->residual[channel], decoder->private_->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->private_->ou tput[channel]+order);
2689 } 2696 }
2690 2697
2691 return true; 2698 return true;
2692 } 2699 }
2693 2700
2694 FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channe l, unsigned bps, FLAC__bool do_full_decode) 2701 FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channe l, unsigned bps, FLAC__bool do_full_decode)
(...skipping 27 matching lines...) Expand all
2722 const unsigned partitions = 1u << partition_order; 2729 const unsigned partitions = 1u << partition_order;
2723 const unsigned partition_samples = partition_order > 0? decoder->private _->frame.header.blocksize >> partition_order : decoder->private_->frame.header.b locksize - predictor_order; 2730 const unsigned partition_samples = partition_order > 0? decoder->private _->frame.header.blocksize >> partition_order : decoder->private_->frame.header.b locksize - predictor_order;
2724 const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITION ED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_ LEN; 2731 const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITION ED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_ LEN;
2725 const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITION ED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_ PARAMETER; 2732 const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITION ED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_ PARAMETER;
2726 2733
2727 /* sanity checks */ 2734 /* sanity checks */
2728 if(partition_order == 0) { 2735 if(partition_order == 0) {
2729 if(decoder->private_->frame.header.blocksize < predictor_order) { 2736 if(decoder->private_->frame.header.blocksize < predictor_order) {
2730 send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERRO R_STATUS_LOST_SYNC); 2737 send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERRO R_STATUS_LOST_SYNC);
2731 decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH _FOR_FRAME_SYNC; 2738 decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH _FOR_FRAME_SYNC;
2732 » » » return true; 2739 » » » /* We have received a potentially malicious bit stream. All we can do is error out to avoid a heap overflow. */
2740 » » » return false;
2733 } 2741 }
2734 } 2742 }
2735 else { 2743 else {
2736 if(partition_samples < predictor_order) { 2744 if(partition_samples < predictor_order) {
2737 send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERRO R_STATUS_LOST_SYNC); 2745 send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERRO R_STATUS_LOST_SYNC);
2738 decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH _FOR_FRAME_SYNC; 2746 decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH _FOR_FRAME_SYNC;
2739 » » » return true; 2747 » » » /* We have received a potentially malicious bit stream. All we can do is error out to avoid a heap overflow. */
2748 » » » return false;
2740 } 2749 }
2741 } 2750 }
2742 2751
2743 » if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_ size(partitioned_rice_contents, max(6, partition_order))) { 2752 » if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_ size(partitioned_rice_contents, flac_max(6u, partition_order))) {
2744 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR; 2753 decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCAT ION_ERROR;
2745 return false; 2754 return false;
2746 } 2755 }
2747 2756
2748 sample = 0; 2757 sample = 0;
2749 for(partition = 0; partition < partitions; partition++) { 2758 for(partition = 0; partition < partitions; partition++) {
2750 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &r ice_parameter, plen)) 2759 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &r ice_parameter, plen))
2751 return false; /* read_callback_ sets the state for us */ 2760 return false; /* read_callback_ sets the state for us */
2752 partitioned_rice_contents->parameters[partition] = rice_paramete r; 2761 partitioned_rice_contents->parameters[partition] = rice_paramete r;
2753 if(rice_parameter < pesc) { 2762 if(rice_parameter < pesc) {
2754 partitioned_rice_contents->raw_bits[partition] = 0; 2763 partitioned_rice_contents->raw_bits[partition] = 0;
2755 u = (partition_order == 0 || partition > 0)? partition_s amples : partition_samples - predictor_order; 2764 u = (partition_order == 0 || partition > 0)? partition_s amples : partition_samples - predictor_order;
2756 » » » if(!decoder->private_->local_bitreader_read_rice_signed_ block(decoder->private_->input, residual + sample, u, rice_parameter)) 2765 » » » if(!FLAC__bitreader_read_rice_signed_block(decoder->priv ate_->input, residual + sample, u, rice_parameter))
2757 return false; /* read_callback_ sets the state f or us */ 2766 return false; /* read_callback_ sets the state f or us */
2758 sample += u; 2767 sample += u;
2759 } 2768 }
2760 else { 2769 else {
2761 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN)) 2770 if(!FLAC__bitreader_read_raw_uint32(decoder->private_->i nput, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
2762 return false; /* read_callback_ sets the state f or us */ 2771 return false; /* read_callback_ sets the state f or us */
2763 partitioned_rice_contents->raw_bits[partition] = rice_pa rameter; 2772 partitioned_rice_contents->raw_bits[partition] = rice_pa rameter;
2764 for(u = (partition_order == 0 || partition > 0)? 0 : pre dictor_order; u < partition_samples; u++, sample++) { 2773 for(u = (partition_order == 0 || partition > 0)? 0 : pre dictor_order; u < partition_samples; u++, sample++) {
2765 if(!FLAC__bitreader_read_raw_int32(decoder->priv ate_->input, &i, rice_parameter)) 2774 if(!FLAC__bitreader_read_raw_int32(decoder->priv ate_->input, &i, rice_parameter))
2766 return false; /* read_callback_ sets the state for us */ 2775 return false; /* read_callback_ sets the state for us */
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
3088 upper_bound_sample++; 3097 upper_bound_sample++;
3089 3098
3090 decoder->private_->target_sample = target_sample; 3099 decoder->private_->target_sample = target_sample;
3091 while(1) { 3100 while(1) {
3092 /* check if the bounds are still ok */ 3101 /* check if the bounds are still ok */
3093 if (lower_bound_sample >= upper_bound_sample || lower_bound > up per_bound) { 3102 if (lower_bound_sample >= upper_bound_sample || lower_bound > up per_bound) {
3094 decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_E RROR; 3103 decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_E RROR;
3095 return false; 3104 return false;
3096 } 3105 }
3097 #ifndef FLAC__INTEGER_ONLY_LIBRARY 3106 #ifndef FLAC__INTEGER_ONLY_LIBRARY
3098 #if defined _MSC_VER || defined __MINGW32__
3099 /* with VC++ you have to spoon feed it the casting */
3100 pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(FL AC__int64)(target_sample - lower_bound_sample) / (FLAC__double)(FLAC__int64)(upp er_bound_sample - lower_bound_sample) * (FLAC__double)(FLAC__int64)(upper_bound - lower_bound)) - approx_bytes_per_frame;
3101 #else
3102 pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(ta rget_sample - lower_bound_sample) / (FLAC__double)(upper_bound_sample - lower_bo und_sample) * (FLAC__double)(upper_bound - lower_bound)) - approx_bytes_per_fram e; 3107 pos = (FLAC__int64)lower_bound + (FLAC__int64)((FLAC__double)(ta rget_sample - lower_bound_sample) / (FLAC__double)(upper_bound_sample - lower_bo und_sample) * (FLAC__double)(upper_bound - lower_bound)) - approx_bytes_per_fram e;
3103 #endif
3104 #else 3108 #else
3105 /* a little less accurate: */ 3109 /* a little less accurate: */
3106 if(upper_bound - lower_bound < 0xffffffff) 3110 if(upper_bound - lower_bound < 0xffffffff)
3107 pos = (FLAC__int64)lower_bound + (FLAC__int64)(((target_ sample - lower_bound_sample) * (upper_bound - lower_bound)) / (upper_bound_sampl e - lower_bound_sample)) - approx_bytes_per_frame; 3111 pos = (FLAC__int64)lower_bound + (FLAC__int64)(((target_ sample - lower_bound_sample) * (upper_bound - lower_bound)) / (upper_bound_sampl e - lower_bound_sample)) - approx_bytes_per_frame;
3108 else /* @@@ WATCHOUT, ~2TB limit */ 3112 else /* @@@ WATCHOUT, ~2TB limit */
3109 pos = (FLAC__int64)lower_bound + (FLAC__int64)((((target _sample - lower_bound_sample)>>8) * ((upper_bound - lower_bound)>>8)) / ((upper_ bound_sample - lower_bound_sample)>>16)) - approx_bytes_per_frame; 3113 pos = (FLAC__int64)lower_bound + (FLAC__int64)((((target _sample - lower_bound_sample)>>8) * ((upper_bound - lower_bound)>>8)) / ((upper_ bound_sample - lower_bound_sample)>>16)) - approx_bytes_per_frame;
3110 #endif 3114 #endif
3111 if(pos >= (FLAC__int64)upper_bound) 3115 if(pos >= (FLAC__int64)upper_bound)
3112 pos = (FLAC__int64)upper_bound - 1; 3116 pos = (FLAC__int64)upper_bound - 1;
3113 if(pos < (FLAC__int64)lower_bound) 3117 if(pos < (FLAC__int64)lower_bound)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3145 this_frame_sample = decoder->private_->last_frame.header.number. sample_number; 3149 this_frame_sample = decoder->private_->last_frame.header.number. sample_number;
3146 3150
3147 if (0 == decoder->private_->samples_decoded || (this_frame_sampl e + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !fir st_seek)) { 3151 if (0 == decoder->private_->samples_decoded || (this_frame_sampl e + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !fir st_seek)) {
3148 if (pos == (FLAC__int64)lower_bound) { 3152 if (pos == (FLAC__int64)lower_bound) {
3149 /* can't move back any more than the first frame , something is fatally wrong */ 3153 /* can't move back any more than the first frame , something is fatally wrong */
3150 decoder->protected_->state = FLAC__STREAM_DECODE R_SEEK_ERROR; 3154 decoder->protected_->state = FLAC__STREAM_DECODE R_SEEK_ERROR;
3151 return false; 3155 return false;
3152 } 3156 }
3153 /* our last move backwards wasn't big enough, try again */ 3157 /* our last move backwards wasn't big enough, try again */
3154 approx_bytes_per_frame = approx_bytes_per_frame? approx_ bytes_per_frame * 2 : 16; 3158 approx_bytes_per_frame = approx_bytes_per_frame? approx_ bytes_per_frame * 2 : 16;
3155 » » » continue;» 3159 » » » continue;
3156 } 3160 }
3157 /* allow one seek over upper bound, so we can get a correct uppe r_bound_sample for streams with unknown total_samples */ 3161 /* allow one seek over upper bound, so we can get a correct uppe r_bound_sample for streams with unknown total_samples */
3158 first_seek = false; 3162 first_seek = false;
3159 » » 3163
3160 /* make sure we are not seeking in corrupted stream */ 3164 /* make sure we are not seeking in corrupted stream */
3161 if (this_frame_sample < lower_bound_sample) { 3165 if (this_frame_sample < lower_bound_sample) {
3162 decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_E RROR; 3166 decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_E RROR;
3163 return false; 3167 return false;
3164 } 3168 }
3165 3169
3166 /* we need to narrow the search */ 3170 /* we need to narrow the search */
3167 if(target_sample < this_frame_sample) { 3171 if(target_sample < this_frame_sample) {
3168 upper_bound_sample = this_frame_sample + decoder->privat e_->last_frame.header.blocksize; 3172 upper_bound_sample = this_frame_sample + decoder->privat e_->last_frame.header.blocksize;
3169 /*@@@@@@ what will decode position be if at end of stream? */ 3173 /*@@@@@@ what will decode position be if at end of stream? */
(...skipping 19 matching lines...) Expand all
3189 #if FLAC__HAS_OGG 3193 #if FLAC__HAS_OGG
3190 FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint 64 stream_length, FLAC__uint64 target_sample) 3194 FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint 64 stream_length, FLAC__uint64 target_sample)
3191 { 3195 {
3192 FLAC__uint64 left_pos = 0, right_pos = stream_length; 3196 FLAC__uint64 left_pos = 0, right_pos = stream_length;
3193 FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_to tal_samples(decoder); 3197 FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_to tal_samples(decoder);
3194 FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1; 3198 FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
3195 FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */ 3199 FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
3196 FLAC__bool did_a_seek; 3200 FLAC__bool did_a_seek;
3197 unsigned iteration = 0; 3201 unsigned iteration = 0;
3198 3202
3199 » /* In the first iterations, we will calculate the target byte position 3203 » /* In the first iterations, we will calculate the target byte position
3200 * by the distance from the target sample to left_sample and 3204 * by the distance from the target sample to left_sample and
3201 * right_sample (let's call it "proportional search"). After that, we 3205 * right_sample (let's call it "proportional search"). After that, we
3202 * will switch to binary search. 3206 * will switch to binary search.
3203 */ 3207 */
3204 unsigned BINARY_SEARCH_AFTER_ITERATION = 2; 3208 unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
3205 3209
3206 /* We will switch to a linear search once our current sample is less 3210 /* We will switch to a linear search once our current sample is less
3207 * than this number of samples ahead of the target sample 3211 * than this number of samples ahead of the target sample
3208 */ 3212 */
3209 static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK _SIZE * 2; 3213 static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK _SIZE * 2;
3210 3214
3211 /* If the total number of samples is unknown, use a large value, and 3215 /* If the total number of samples is unknown, use a large value, and
3212 * force binary search immediately. 3216 * force binary search immediately.
3213 */ 3217 */
3214 if(right_sample == 0) { 3218 if(right_sample == 0) {
3215 right_sample = (FLAC__uint64)(-1); 3219 right_sample = (FLAC__uint64)(-1);
3216 BINARY_SEARCH_AFTER_ITERATION = 0; 3220 BINARY_SEARCH_AFTER_ITERATION = 0;
3217 } 3221 }
3218 3222
3219 decoder->private_->target_sample = target_sample; 3223 decoder->private_->target_sample = target_sample;
3220 for( ; ; iteration++) { 3224 for( ; ; iteration++) {
3221 if (iteration == 0 || this_frame_sample > target_sample || targe t_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) { 3225 if (iteration == 0 || this_frame_sample > target_sample || targe t_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
3222 if (iteration >= BINARY_SEARCH_AFTER_ITERATION) { 3226 if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
3223 pos = (right_pos + left_pos) / 2; 3227 pos = (right_pos + left_pos) / 2;
3224 } 3228 }
3225 else { 3229 else {
3226 #ifndef FLAC__INTEGER_ONLY_LIBRARY 3230 #ifndef FLAC__INTEGER_ONLY_LIBRARY
3227 #if defined _MSC_VER || defined __MINGW32__
3228 /* with MSVC you have to spoon feed it the casti ng */
3229 pos = (FLAC__uint64)((FLAC__double)(FLAC__int64) (target_sample - left_sample) / (FLAC__double)(FLAC__int64)(right_sample - left_ sample) * (FLAC__double)(FLAC__int64)(right_pos - left_pos));
3230 #else
3231 pos = (FLAC__uint64)((FLAC__double)(target_sampl e - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(r ight_pos - left_pos)); 3231 pos = (FLAC__uint64)((FLAC__double)(target_sampl e - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(r ight_pos - left_pos));
3232 #endif
3233 #else 3232 #else
3234 /* a little less accurate: */ 3233 /* a little less accurate: */
3235 if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff)) 3234 if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
3236 pos = (FLAC__int64)(((target_sample-left _sample) * (right_pos-left_pos)) / (right_sample-left_sample)); 3235 pos = (FLAC__int64)(((target_sample-left _sample) * (right_pos-left_pos)) / (right_sample-left_sample));
3237 else /* @@@ WATCHOUT, ~2TB limit */ 3236 else /* @@@ WATCHOUT, ~2TB limit */
3238 pos = (FLAC__int64)((((target_sample-lef t_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16)); 3237 pos = (FLAC__int64)((((target_sample-lef t_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
3239 #endif 3238 #endif
3240 /* @@@ TODO: might want to limit pos to some dis tance 3239 /* @@@ TODO: might want to limit pos to some dis tance
3241 * before EOF, to make sure we land before the l ast frame, 3240 * before EOF, to make sure we land before the l ast frame,
3242 * thereby getting a this_frame_sample and so ha ving a better 3241 * thereby getting a this_frame_sample and so ha ving a better
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
3339 else 3338 else
3340 return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */ 3339 return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
3341 } 3340 }
3342 3341
3343 FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *dec oder, FLAC__uint64 absolute_byte_offset, void *client_data) 3342 FLAC__StreamDecoderSeekStatus file_seek_callback_(const FLAC__StreamDecoder *dec oder, FLAC__uint64 absolute_byte_offset, void *client_data)
3344 { 3343 {
3345 (void)client_data; 3344 (void)client_data;
3346 3345
3347 if(decoder->private_->file == stdin) 3346 if(decoder->private_->file == stdin)
3348 return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; 3347 return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
3349 » else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEE K_SET) < 0) 3348 » else if(fseeko(decoder->private_->file, (FLAC__off_t)absolute_byte_offse t, SEEK_SET) < 0)
3350 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; 3349 return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
3351 else 3350 else
3352 return FLAC__STREAM_DECODER_SEEK_STATUS_OK; 3351 return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
3353 } 3352 }
3354 3353
3355 FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *dec oder, FLAC__uint64 *absolute_byte_offset, void *client_data) 3354 FLAC__StreamDecoderTellStatus file_tell_callback_(const FLAC__StreamDecoder *dec oder, FLAC__uint64 *absolute_byte_offset, void *client_data)
3356 { 3355 {
3357 » off_t pos; 3356 » FLAC__off_t pos;
3358 (void)client_data; 3357 (void)client_data;
3359 3358
3360 if(decoder->private_->file == stdin) 3359 if(decoder->private_->file == stdin)
3361 return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; 3360 return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
3362 else if((pos = ftello(decoder->private_->file)) < 0) 3361 else if((pos = ftello(decoder->private_->file)) < 0)
3363 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; 3362 return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
3364 else { 3363 else {
3365 *absolute_byte_offset = (FLAC__uint64)pos; 3364 *absolute_byte_offset = (FLAC__uint64)pos;
3366 return FLAC__STREAM_DECODER_TELL_STATUS_OK; 3365 return FLAC__STREAM_DECODER_TELL_STATUS_OK;
3367 } 3366 }
3368 } 3367 }
3369 3368
3370 FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) 3369 FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
3371 { 3370 {
3372 » struct stat filestats; 3371 » struct flac_stat_s filestats;
3373 (void)client_data; 3372 (void)client_data;
3374 3373
3375 if(decoder->private_->file == stdin) 3374 if(decoder->private_->file == stdin)
3376 return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; 3375 return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
3377 » else if(fstat(fileno(decoder->private_->file), &filestats) != 0) 3376 » else if(flac_fstat(fileno(decoder->private_->file), &filestats) != 0)
3378 return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; 3377 return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
3379 else { 3378 else {
3380 *stream_length = (FLAC__uint64)filestats.st_size; 3379 *stream_length = (FLAC__uint64)filestats.st_size;
3381 return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; 3380 return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
3382 } 3381 }
3383 } 3382 }
3384 3383
3385 FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_d ata) 3384 FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_d ata)
3386 { 3385 {
3387 (void)client_data; 3386 (void)client_data;
3388 3387
3389 return feof(decoder->private_->file)? true : false; 3388 return feof(decoder->private_->file)? true : false;
3390 } 3389 }
OLDNEW
« no previous file with comments | « src/libFLAC/metadata_object.c ('k') | src/libFLAC/stream_encoder.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698