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

Side by Side Diff: source/libvpx/vp8/decoder/dboolhuff.c

Issue 17009012: libvpx: Pull from upstream (Closed) Base URL: http://src.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 6 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 | « source/libvpx/vp8/decoder/dboolhuff.h ('k') | source/libvpx/vp8/decoder/decodframe.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 /* 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 11
12 #include "dboolhuff.h" 12 #include "dboolhuff.h"
13 13
14 int vp8dx_start_decode(BOOL_DECODER *br, 14 int vp8dx_start_decode(BOOL_DECODER *br,
15 const unsigned char *source, 15 const unsigned char *source,
16 unsigned int source_sz, 16 unsigned int source_sz,
17 const unsigned char *origin, 17 vp8_decrypt_cb *decrypt_cb,
18 const unsigned char *key) 18 void *decrypt_state)
19 { 19 {
20 br->user_buffer_end = source+source_sz; 20 br->user_buffer_end = source+source_sz;
21 br->user_buffer = source; 21 br->user_buffer = source;
22 br->value = 0; 22 br->value = 0;
23 br->count = -8; 23 br->count = -8;
24 br->range = 255; 24 br->range = 255;
25 br->origin = origin; 25 br->decrypt_cb = decrypt_cb;
26 br->key = key; 26 br->decrypt_state = decrypt_state;
27 27
28 if (source_sz && !source) 28 if (source_sz && !source)
29 return 1; 29 return 1;
30 30
31 /* Populate the buffer */ 31 /* Populate the buffer */
32 vp8dx_bool_decoder_fill(br); 32 vp8dx_bool_decoder_fill(br);
33 33
34 return 0; 34 return 0;
35 } 35 }
36 36
37 void vp8dx_bool_decoder_fill(BOOL_DECODER *br) 37 void vp8dx_bool_decoder_fill(BOOL_DECODER *br)
38 { 38 {
39 const unsigned char *bufptr = br->user_buffer; 39 const unsigned char *bufptr = br->user_buffer;
40 const unsigned char *bufend = br->user_buffer_end;
41 VP8_BD_VALUE value = br->value; 40 VP8_BD_VALUE value = br->value;
42 int count = br->count; 41 int count = br->count;
43 int shift = VP8_BD_VALUE_SIZE - 8 - (count + 8); 42 int shift = VP8_BD_VALUE_SIZE - 8 - (count + 8);
44 size_t bits_left = (bufend - bufptr)*CHAR_BIT; 43 size_t bytes_left = br->user_buffer_end - bufptr;
44 size_t bits_left = bytes_left * CHAR_BIT;
45 int x = (int)(shift + CHAR_BIT - bits_left); 45 int x = (int)(shift + CHAR_BIT - bits_left);
46 int loop_end = 0; 46 int loop_end = 0;
47 unsigned char decrypted[sizeof(VP8_BD_VALUE) + 1];
48
49 if (br->decrypt_cb) {
50 int n = bytes_left > sizeof(decrypted) ? sizeof(decrypted) : bytes_left;
51 br->decrypt_cb(br->decrypt_state, bufptr, decrypted, n);
52 bufptr = decrypted;
53 }
47 54
48 if(x >= 0) 55 if(x >= 0)
49 { 56 {
50 count += VP8_LOTS_OF_BITS; 57 count += VP8_LOTS_OF_BITS;
51 loop_end = x; 58 loop_end = x;
52 } 59 }
53 60
54 if (x < 0 || bits_left) 61 if (x < 0 || bits_left)
55 { 62 {
56 while(shift >= loop_end) 63 while(shift >= loop_end)
57 { 64 {
58 count += CHAR_BIT; 65 count += CHAR_BIT;
59 value |= ((VP8_BD_VALUE)decrypt_byte(bufptr, br->origin, 66 value |= (VP8_BD_VALUE)*bufptr << shift;
60 br->key)) << shift;
61 ++bufptr; 67 ++bufptr;
68 ++br->user_buffer;
62 shift -= CHAR_BIT; 69 shift -= CHAR_BIT;
63 } 70 }
64 } 71 }
65 72
66 br->user_buffer = bufptr;
67 br->value = value; 73 br->value = value;
68 br->count = count; 74 br->count = count;
69 } 75 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/decoder/dboolhuff.h ('k') | source/libvpx/vp8/decoder/decodframe.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698