Coverage Report

Created: 2026-09-01 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vp8/decoder/dboolhuff.h
Line
Count
Source
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
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
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#ifndef VPX_VP8_DECODER_DBOOLHUFF_H_
12
#define VPX_VP8_DECODER_DBOOLHUFF_H_
13
14
#include <stddef.h>
15
#include <limits.h>
16
17
#include "./vpx_config.h"
18
#include "vpx_ports/compiler_attributes.h"
19
#include "vpx_ports/mem.h"
20
#include "vpx/vp8dx.h"
21
#include "vpx/vpx_integer.h"
22
23
#ifdef __cplusplus
24
extern "C" {
25
#endif
26
27
typedef size_t VP8_BD_VALUE;
28
29
4.74G
#define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE) * CHAR_BIT)
30
31
/*This is meant to be a large, positive constant that can still be efficiently
32
   loaded as an immediate (on platforms like ARM, for example).
33
  Even relatively modest values like 100 would work fine.*/
34
329M
#define VP8_LOTS_OF_BITS (0x40000000)
35
36
typedef struct {
37
  const unsigned char *user_buffer_end;
38
  const unsigned char *user_buffer;
39
  VP8_BD_VALUE value;
40
  int count;
41
  unsigned int range;
42
  vpx_decrypt_cb decrypt_cb;
43
  void *decrypt_state;
44
} BOOL_DECODER;
45
46
DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
47
48
int vp8dx_start_decode(BOOL_DECODER *br, const unsigned char *source,
49
                       unsigned int source_sz, vpx_decrypt_cb decrypt_cb,
50
                       void *decrypt_state);
51
52
void vp8dx_bool_decoder_fill(BOOL_DECODER *br);
53
54
static VPX_NO_UNSIGNED_SHIFT_CHECK int vp8dx_decode_bool(BOOL_DECODER *br,
55
4.38G
                                                         int probability) {
56
4.38G
  unsigned int bit = 0;
57
4.38G
  VP8_BD_VALUE value;
58
4.38G
  unsigned int split;
59
4.38G
  VP8_BD_VALUE bigsplit;
60
4.38G
  int count;
61
4.38G
  unsigned int range;
62
63
4.38G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
4.38G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
4.38G
  value = br->value;
68
4.38G
  count = br->count;
69
70
4.38G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
4.38G
  range = split;
73
74
4.38G
  if (value >= bigsplit) {
75
119M
    range = br->range - split;
76
119M
    value = value - bigsplit;
77
119M
    bit = 1;
78
119M
  }
79
80
4.38G
  {
81
4.38G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
4.38G
    range <<= shift;
83
4.38G
    value <<= shift;
84
4.38G
    count -= shift;
85
4.38G
  }
86
4.38G
  br->value = value;
87
4.38G
  br->count = count;
88
4.38G
  br->range = range;
89
90
4.38G
  return bit;
91
4.38G
}
Unexecuted instantiation: vp8_dx_iface.c:vp8dx_decode_bool
Unexecuted instantiation: onyxd_if.c:vp8dx_decode_bool
Unexecuted instantiation: threading.c:vp8dx_decode_bool
decodeframe.c:vp8dx_decode_bool
Line
Count
Source
55
223M
                                                         int probability) {
56
223M
  unsigned int bit = 0;
57
223M
  VP8_BD_VALUE value;
58
223M
  unsigned int split;
59
223M
  VP8_BD_VALUE bigsplit;
60
223M
  int count;
61
223M
  unsigned int range;
62
63
223M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
223M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
223M
  value = br->value;
68
223M
  count = br->count;
69
70
223M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
223M
  range = split;
73
74
223M
  if (value >= bigsplit) {
75
9.67M
    range = br->range - split;
76
9.67M
    value = value - bigsplit;
77
9.67M
    bit = 1;
78
9.67M
  }
79
80
223M
  {
81
223M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
223M
    range <<= shift;
83
223M
    value <<= shift;
84
223M
    count -= shift;
85
223M
  }
86
223M
  br->value = value;
87
223M
  br->count = count;
88
223M
  br->range = range;
89
90
223M
  return bit;
91
223M
}
detokenize.c:vp8dx_decode_bool
Line
Count
Source
55
160M
                                                         int probability) {
56
160M
  unsigned int bit = 0;
57
160M
  VP8_BD_VALUE value;
58
160M
  unsigned int split;
59
160M
  VP8_BD_VALUE bigsplit;
60
160M
  int count;
61
160M
  unsigned int range;
62
63
160M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
160M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
160M
  value = br->value;
68
160M
  count = br->count;
69
70
160M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
160M
  range = split;
73
74
160M
  if (value >= bigsplit) {
75
40.4M
    range = br->range - split;
76
40.4M
    value = value - bigsplit;
77
40.4M
    bit = 1;
78
40.4M
  }
79
80
160M
  {
81
160M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
160M
    range <<= shift;
83
160M
    value <<= shift;
84
160M
    count -= shift;
85
160M
  }
86
160M
  br->value = value;
87
160M
  br->count = count;
88
160M
  br->range = range;
89
90
160M
  return bit;
91
160M
}
Unexecuted instantiation: dboolhuff.c:vp8dx_decode_bool
decodemv.c:vp8dx_decode_bool
Line
Count
Source
55
4.00G
                                                         int probability) {
56
4.00G
  unsigned int bit = 0;
57
4.00G
  VP8_BD_VALUE value;
58
4.00G
  unsigned int split;
59
4.00G
  VP8_BD_VALUE bigsplit;
60
4.00G
  int count;
61
4.00G
  unsigned int range;
62
63
4.00G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
4.00G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
4.00G
  value = br->value;
68
4.00G
  count = br->count;
69
70
4.00G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
4.00G
  range = split;
73
74
4.00G
  if (value >= bigsplit) {
75
69.1M
    range = br->range - split;
76
69.1M
    value = value - bigsplit;
77
69.1M
    bit = 1;
78
69.1M
  }
79
80
4.00G
  {
81
4.00G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
4.00G
    range <<= shift;
83
4.00G
    value <<= shift;
84
4.00G
    count -= shift;
85
4.00G
  }
86
4.00G
  br->value = value;
87
4.00G
  br->count = count;
88
4.00G
  br->range = range;
89
90
4.00G
  return bit;
91
4.00G
}
92
93
3.58M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
3.58M
  int z = 0;
95
3.58M
  int bit;
96
97
25.9M
  for (bit = bits - 1; bit >= 0; bit--) {
98
22.3M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
22.3M
  }
100
101
3.58M
  return z;
102
3.58M
}
Unexecuted instantiation: vp8_dx_iface.c:vp8_decode_value
Unexecuted instantiation: onyxd_if.c:vp8_decode_value
Unexecuted instantiation: threading.c:vp8_decode_value
decodeframe.c:vp8_decode_value
Line
Count
Source
93
2.58M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
2.58M
  int z = 0;
95
2.58M
  int bit;
96
97
16.9M
  for (bit = bits - 1; bit >= 0; bit--) {
98
14.4M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
14.4M
  }
100
101
2.58M
  return z;
102
2.58M
}
Unexecuted instantiation: detokenize.c:vp8_decode_value
Unexecuted instantiation: dboolhuff.c:vp8_decode_value
decodemv.c:vp8_decode_value
Line
Count
Source
93
1.00M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
1.00M
  int z = 0;
95
1.00M
  int bit;
96
97
8.96M
  for (bit = bits - 1; bit >= 0; bit--) {
98
7.96M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
7.96M
  }
100
101
1.00M
  return z;
102
1.00M
}
103
104
339M
static INLINE int vp8dx_bool_error(BOOL_DECODER *br) {
105
  /* Check if we have reached the end of the buffer.
106
   *
107
   * Variable 'count' stores the number of bits in the 'value' buffer, minus
108
   * 8. The top byte is part of the algorithm, and the remainder is buffered
109
   * to be shifted into it. So if count == 8, the top 16 bits of 'value' are
110
   * occupied, 8 for the algorithm and 8 in the buffer.
111
   *
112
   * When reading a byte from the user's buffer, count is filled with 8 and
113
   * one byte is filled into the value buffer. When we reach the end of the
114
   * data, count is additionally filled with VP8_LOTS_OF_BITS. So when
115
   * count == VP8_LOTS_OF_BITS - 1, the user's data has been exhausted.
116
   */
117
339M
  if ((br->count > VP8_BD_VALUE_SIZE) && (br->count < VP8_LOTS_OF_BITS)) {
118
    /* We have tried to decode bits after the end of
119
     * stream was encountered.
120
     */
121
326M
    return 1;
122
326M
  }
123
124
  /* No error. */
125
12.9M
  return 0;
126
339M
}
Unexecuted instantiation: vp8_dx_iface.c:vp8dx_bool_error
Unexecuted instantiation: onyxd_if.c:vp8dx_bool_error
threading.c:vp8dx_bool_error
Line
Count
Source
104
2.09M
static INLINE int vp8dx_bool_error(BOOL_DECODER *br) {
105
  /* Check if we have reached the end of the buffer.
106
   *
107
   * Variable 'count' stores the number of bits in the 'value' buffer, minus
108
   * 8. The top byte is part of the algorithm, and the remainder is buffered
109
   * to be shifted into it. So if count == 8, the top 16 bits of 'value' are
110
   * occupied, 8 for the algorithm and 8 in the buffer.
111
   *
112
   * When reading a byte from the user's buffer, count is filled with 8 and
113
   * one byte is filled into the value buffer. When we reach the end of the
114
   * data, count is additionally filled with VP8_LOTS_OF_BITS. So when
115
   * count == VP8_LOTS_OF_BITS - 1, the user's data has been exhausted.
116
   */
117
2.09M
  if ((br->count > VP8_BD_VALUE_SIZE) && (br->count < VP8_LOTS_OF_BITS)) {
118
    /* We have tried to decode bits after the end of
119
     * stream was encountered.
120
     */
121
35.6k
    return 1;
122
35.6k
  }
123
124
  /* No error. */
125
2.05M
  return 0;
126
2.09M
}
decodeframe.c:vp8dx_bool_error
Line
Count
Source
104
337M
static INLINE int vp8dx_bool_error(BOOL_DECODER *br) {
105
  /* Check if we have reached the end of the buffer.
106
   *
107
   * Variable 'count' stores the number of bits in the 'value' buffer, minus
108
   * 8. The top byte is part of the algorithm, and the remainder is buffered
109
   * to be shifted into it. So if count == 8, the top 16 bits of 'value' are
110
   * occupied, 8 for the algorithm and 8 in the buffer.
111
   *
112
   * When reading a byte from the user's buffer, count is filled with 8 and
113
   * one byte is filled into the value buffer. When we reach the end of the
114
   * data, count is additionally filled with VP8_LOTS_OF_BITS. So when
115
   * count == VP8_LOTS_OF_BITS - 1, the user's data has been exhausted.
116
   */
117
337M
  if ((br->count > VP8_BD_VALUE_SIZE) && (br->count < VP8_LOTS_OF_BITS)) {
118
    /* We have tried to decode bits after the end of
119
     * stream was encountered.
120
     */
121
326M
    return 1;
122
326M
  }
123
124
  /* No error. */
125
10.9M
  return 0;
126
337M
}
Unexecuted instantiation: detokenize.c:vp8dx_bool_error
Unexecuted instantiation: dboolhuff.c:vp8dx_bool_error
Unexecuted instantiation: decodemv.c:vp8dx_bool_error
127
128
#ifdef __cplusplus
129
}  // extern "C"
130
#endif
131
132
#endif  // VPX_VP8_DECODER_DBOOLHUFF_H_