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

Side by Side Diff: src/libFLAC/format.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/float.c ('k') | src/libFLAC/ia32/cpu_asm.nasm » ('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 #include <stdio.h> 37 #include <stdio.h>
37 #include <stdlib.h> /* for qsort() */ 38 #include <stdlib.h> /* for qsort() */
38 #include <string.h> /* for memset() */ 39 #include <string.h> /* for memset() */
39 #include "FLAC/assert.h" 40 #include "FLAC/assert.h"
40 #include "FLAC/format.h" 41 #include "FLAC/format.h"
42 #include "share/compat.h"
41 #include "private/format.h" 43 #include "private/format.h"
42 44 #include "private/macros.h"
43 #ifndef FLaC__INLINE
44 #define FLaC__INLINE
45 #endif
46
47 #ifdef min
48 #undef min
49 #endif
50 #define min(a,b) ((a)<(b)?(a):(b))
51
52 /* adjust for compilers that can't understand using LLU suffix for uint64_t lite rals */
53 #ifdef _MSC_VER
54 #define FLAC__U64L(x) x
55 #else
56 #define FLAC__U64L(x) x##LLU
57 #endif
58 45
59 /* VERSION should come from configure */ 46 /* VERSION should come from configure */
60 FLAC_API const char *FLAC__VERSION_STRING = VERSION; 47 FLAC_API const char *FLAC__VERSION_STRING = VERSION;
61 48
62 #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__ 49 FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 201411 25";
63 /* yet one more hack because of MSVC6: */
64 FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
65 #else
66 FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 200709 17";
67 #endif
68 50
69 FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' }; 51 FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
70 FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143; 52 FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
71 FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */ 53 FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
72 54
73 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16 ; /* bits */ 55 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16 ; /* bits */
74 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16 ; /* bits */ 56 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16 ; /* bits */
75 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24 ; /* bits */ 57 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24 ; /* bits */
76 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24 ; /* bits */ 58 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24 ; /* bits */
77 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; / * bits */ 59 FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; / * bits */
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 198
217 FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate) 199 FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
218 { 200 {
219 if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) { 201 if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
220 return false; 202 return false;
221 } 203 }
222 else 204 else
223 return true; 205 return true;
224 } 206 }
225 207
208 FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(unsigned blocksize, unsigne d sample_rate)
209 {
210 if(blocksize > 16384)
211 return false;
212 else if(sample_rate <= 48000 && blocksize > 4608)
213 return false;
214 else
215 return true;
216 }
217
226 FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate) 218 FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
227 { 219 {
228 if( 220 if(
229 !FLAC__format_sample_rate_is_valid(sample_rate) || 221 !FLAC__format_sample_rate_is_valid(sample_rate) ||
230 ( 222 (
231 sample_rate >= (1u << 16) && 223 sample_rate >= (1u << 16) &&
232 !(sample_rate % 1000 == 0 || sample_rate % 10 == 0) 224 !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
233 ) 225 )
234 ) { 226 ) {
235 return false; 227 return false;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 298
307 return j; 299 return j;
308 } 300 }
309 301
310 /* 302 /*
311 * also disallows non-shortest-form encodings, c.f. 303 * also disallows non-shortest-form encodings, c.f.
312 * http://www.unicode.org/versions/corrigendum1.html 304 * http://www.unicode.org/versions/corrigendum1.html
313 * and a more clear explanation at the end of this section: 305 * and a more clear explanation at the end of this section:
314 * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 306 * http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
315 */ 307 */
316 static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8) 308 static unsigned utf8len_(const FLAC__byte *utf8)
317 { 309 {
318 FLAC__ASSERT(0 != utf8); 310 FLAC__ASSERT(0 != utf8);
319 if ((utf8[0] & 0x80) == 0) { 311 if ((utf8[0] & 0x80) == 0) {
320 return 1; 312 return 1;
321 } 313 }
322 else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) { 314 else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
323 if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */ 315 if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
324 return 0; 316 return 0;
325 return 2; 317 return 2;
326 } 318 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 ); 521 );
530 } 522 }
531 523
532 unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned block size) 524 unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned block size)
533 { 525 {
534 unsigned max_rice_partition_order = 0; 526 unsigned max_rice_partition_order = 0;
535 while(!(blocksize & 1)) { 527 while(!(blocksize & 1)) {
536 max_rice_partition_order++; 528 max_rice_partition_order++;
537 blocksize >>= 1; 529 blocksize >>= 1;
538 } 530 }
539 » return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order); 531 » return flac_min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order );
540 } 532 }
541 533
542 unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_an d_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order) 534 unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_an d_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
543 { 535 {
544 unsigned max_rice_partition_order = limit; 536 unsigned max_rice_partition_order = limit;
545 537
546 while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_o rder) <= predictor_order) 538 while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_o rder) <= predictor_order)
547 max_rice_partition_order--; 539 max_rice_partition_order--;
548 540
549 FLAC__ASSERT( 541 FLAC__ASSERT(
(...skipping 24 matching lines...) Expand all
574 FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object ); 566 FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object );
575 } 567 }
576 568
577 FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_s ize(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_part ition_order) 569 FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_s ize(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_part ition_order)
578 { 570 {
579 FLAC__ASSERT(0 != object); 571 FLAC__ASSERT(0 != object);
580 572
581 FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters & & 0 == object->raw_bits)); 573 FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters & & 0 == object->raw_bits));
582 574
583 if(object->capacity_by_order < max_partition_order) { 575 if(object->capacity_by_order < max_partition_order) {
584 » » if(0 == (object->parameters = (unsigned*)realloc(object->paramet ers, sizeof(unsigned)*((size_t)1 << max_partition_order)))) 576 » » if(0 == (object->parameters = realloc(object->parameters, sizeof (unsigned)*(1 << max_partition_order))))
585 return false; 577 return false;
586 » » if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*((size_t)1 << max_partition_order)))) 578 » » if(0 == (object->raw_bits = realloc(object->raw_bits, sizeof(uns igned)*(1 << max_partition_order))))
587 return false; 579 return false;
588 » » memset(object->raw_bits, 0, sizeof(unsigned)*((size_t)1 << max_p artition_order)); 580 » » memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition _order));
589 object->capacity_by_order = max_partition_order; 581 object->capacity_by_order = max_partition_order;
590 } 582 }
591 583
592 return true; 584 return true;
593 } 585 }
OLDNEW
« no previous file with comments | « src/libFLAC/float.c ('k') | src/libFLAC/ia32/cpu_asm.nasm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698