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

Side by Side Diff: source/libvpx/vp9/decoder/vp9_dboolhuff.c

Issue 111463005: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/decoder/vp9_dboolhuff.h ('k') | source/libvpx/vp9/decoder/vp9_decodeframe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "vpx_ports/mem.h" 11 #include "vpx_ports/mem.h"
12 #include "vpx_mem/vpx_mem.h" 12 #include "vpx_mem/vpx_mem.h"
13 13
14 #include "vp9/decoder/vp9_dboolhuff.h" 14 #include "vp9/decoder/vp9_dboolhuff.h"
15 15
16 // This is meant to be a large, positive constant that can still be efficiently 16 // This is meant to be a large, positive constant that can still be efficiently
17 // loaded as an immediate (on platforms like ARM, for example). 17 // loaded as an immediate (on platforms like ARM, for example).
18 // Even relatively modest values like 100 would work fine. 18 // Even relatively modest values like 100 would work fine.
19 #define LOTS_OF_BITS 0x40000000 19 #define LOTS_OF_BITS 0x40000000
20 20
21
22 int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size) { 21 int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size) {
23 int marker_bit; 22 if (size && !buffer) {
24
25 r->buffer_end = buffer + size;
26 r->buffer = buffer;
27 r->value = 0;
28 r->count = -8;
29 r->range = 255;
30
31 if (size && !buffer)
32 return 1; 23 return 1;
33 24 } else {
34 vp9_reader_fill(r); 25 r->buffer_end = buffer + size;
35 marker_bit = vp9_read_bit(r); 26 r->buffer = buffer;
36 return marker_bit != 0; 27 r->value = 0;
28 r->count = -8;
29 r->range = 255;
30 vp9_reader_fill(r);
31 return vp9_read_bit(r) != 0; // marker bit
32 }
37 } 33 }
38 34
39 void vp9_reader_fill(vp9_reader *r) { 35 void vp9_reader_fill(vp9_reader *r) {
40 const uint8_t *const buffer_end = r->buffer_end; 36 const uint8_t *const buffer_end = r->buffer_end;
41 const uint8_t *buffer = r->buffer; 37 const uint8_t *buffer = r->buffer;
42 VP9_BD_VALUE value = r->value; 38 BD_VALUE value = r->value;
43 int count = r->count; 39 int count = r->count;
44 int shift = BD_VALUE_SIZE - 8 - (count + 8); 40 int shift = BD_VALUE_SIZE - CHAR_BIT - (count + CHAR_BIT);
45 int loop_end = 0; 41 int loop_end = 0;
46 const int bits_left = (int)((buffer_end - buffer)*CHAR_BIT); 42 const int bits_left = (int)((buffer_end - buffer) * CHAR_BIT);
47 const int x = shift + CHAR_BIT - bits_left; 43 const int x = shift + CHAR_BIT - bits_left;
48 44
49 if (x >= 0) { 45 if (x >= 0) {
50 count += LOTS_OF_BITS; 46 count += LOTS_OF_BITS;
51 loop_end = x; 47 loop_end = x;
52 } 48 }
53 49
54 if (x < 0 || bits_left) { 50 if (x < 0 || bits_left) {
55 while (shift >= loop_end) { 51 while (shift >= loop_end) {
56 count += CHAR_BIT; 52 count += CHAR_BIT;
57 value |= (VP9_BD_VALUE)*buffer++ << shift; 53 value |= (BD_VALUE)*buffer++ << shift;
58 shift -= CHAR_BIT; 54 shift -= CHAR_BIT;
59 } 55 }
60 } 56 }
61 57
62 r->buffer = buffer; 58 r->buffer = buffer;
63 r->value = value; 59 r->value = value;
64 r->count = count; 60 r->count = count;
65 } 61 }
66 62
67 const uint8_t *vp9_reader_find_end(vp9_reader *r) { 63 const uint8_t *vp9_reader_find_end(vp9_reader *r) {
(...skipping 15 matching lines...) Expand all
83 // 79 //
84 // When reading a byte from the user's buffer, count is filled with 8 and 80 // When reading a byte from the user's buffer, count is filled with 8 and
85 // one byte is filled into the value buffer. When we reach the end of the 81 // one byte is filled into the value buffer. When we reach the end of the
86 // data, count is additionally filled with LOTS_OF_BITS. So when 82 // data, count is additionally filled with LOTS_OF_BITS. So when
87 // count == LOTS_OF_BITS - 1, the user's data has been exhausted. 83 // count == LOTS_OF_BITS - 1, the user's data has been exhausted.
88 // 84 //
89 // 1 if we have tried to decode bits after the end of stream was encountered. 85 // 1 if we have tried to decode bits after the end of stream was encountered.
90 // 0 No error. 86 // 0 No error.
91 return r->count > BD_VALUE_SIZE && r->count < LOTS_OF_BITS; 87 return r->count > BD_VALUE_SIZE && r->count < LOTS_OF_BITS;
92 } 88 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/decoder/vp9_dboolhuff.h ('k') | source/libvpx/vp9/decoder/vp9_decodeframe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698