Coverage Report

Created: 2026-09-14 08:00

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
1.93G
#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
153M
#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
1.74G
                                                         int probability) {
56
1.74G
  unsigned int bit = 0;
57
1.74G
  VP8_BD_VALUE value;
58
1.74G
  unsigned int split;
59
1.74G
  VP8_BD_VALUE bigsplit;
60
1.74G
  int count;
61
1.74G
  unsigned int range;
62
63
1.74G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
1.74G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
1.74G
  value = br->value;
68
1.74G
  count = br->count;
69
70
1.74G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
1.74G
  range = split;
73
74
1.74G
  if (value >= bigsplit) {
75
109M
    range = br->range - split;
76
109M
    value = value - bigsplit;
77
109M
    bit = 1;
78
109M
  }
79
80
1.74G
  {
81
1.74G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
1.74G
    range <<= shift;
83
1.74G
    value <<= shift;
84
1.74G
    count -= shift;
85
1.74G
  }
86
1.74G
  br->value = value;
87
1.74G
  br->count = count;
88
1.74G
  br->range = range;
89
90
1.74G
  return bit;
91
1.74G
}
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
210M
                                                         int probability) {
56
210M
  unsigned int bit = 0;
57
210M
  VP8_BD_VALUE value;
58
210M
  unsigned int split;
59
210M
  VP8_BD_VALUE bigsplit;
60
210M
  int count;
61
210M
  unsigned int range;
62
63
210M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
210M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
210M
  value = br->value;
68
210M
  count = br->count;
69
70
210M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
210M
  range = split;
73
74
210M
  if (value >= bigsplit) {
75
16.7M
    range = br->range - split;
76
16.7M
    value = value - bigsplit;
77
16.7M
    bit = 1;
78
16.7M
  }
79
80
210M
  {
81
210M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
210M
    range <<= shift;
83
210M
    value <<= shift;
84
210M
    count -= shift;
85
210M
  }
86
210M
  br->value = value;
87
210M
  br->count = count;
88
210M
  br->range = range;
89
90
210M
  return bit;
91
210M
}
detokenize.c:vp8dx_decode_bool
Line
Count
Source
55
145M
                                                         int probability) {
56
145M
  unsigned int bit = 0;
57
145M
  VP8_BD_VALUE value;
58
145M
  unsigned int split;
59
145M
  VP8_BD_VALUE bigsplit;
60
145M
  int count;
61
145M
  unsigned int range;
62
63
145M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
145M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
145M
  value = br->value;
68
145M
  count = br->count;
69
70
145M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
145M
  range = split;
73
74
145M
  if (value >= bigsplit) {
75
40.7M
    range = br->range - split;
76
40.7M
    value = value - bigsplit;
77
40.7M
    bit = 1;
78
40.7M
  }
79
80
145M
  {
81
145M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
145M
    range <<= shift;
83
145M
    value <<= shift;
84
145M
    count -= shift;
85
145M
  }
86
145M
  br->value = value;
87
145M
  br->count = count;
88
145M
  br->range = range;
89
90
145M
  return bit;
91
145M
}
Unexecuted instantiation: dboolhuff.c:vp8dx_decode_bool
decodemv.c:vp8dx_decode_bool
Line
Count
Source
55
1.39G
                                                         int probability) {
56
1.39G
  unsigned int bit = 0;
57
1.39G
  VP8_BD_VALUE value;
58
1.39G
  unsigned int split;
59
1.39G
  VP8_BD_VALUE bigsplit;
60
1.39G
  int count;
61
1.39G
  unsigned int range;
62
63
1.39G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
1.39G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
1.39G
  value = br->value;
68
1.39G
  count = br->count;
69
70
1.39G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
1.39G
  range = split;
73
74
1.39G
  if (value >= bigsplit) {
75
52.4M
    range = br->range - split;
76
52.4M
    value = value - bigsplit;
77
52.4M
    bit = 1;
78
52.4M
  }
79
80
1.39G
  {
81
1.39G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
1.39G
    range <<= shift;
83
1.39G
    value <<= shift;
84
1.39G
    count -= shift;
85
1.39G
  }
86
1.39G
  br->value = value;
87
1.39G
  br->count = count;
88
1.39G
  br->range = range;
89
90
1.39G
  return bit;
91
1.39G
}
92
93
4.89M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
4.89M
  int z = 0;
95
4.89M
  int bit;
96
97
37.2M
  for (bit = bits - 1; bit >= 0; bit--) {
98
32.3M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
32.3M
  }
100
101
4.89M
  return z;
102
4.89M
}
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
3.71M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
3.71M
  int z = 0;
95
3.71M
  int bit;
96
97
26.7M
  for (bit = bits - 1; bit >= 0; bit--) {
98
23.0M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
23.0M
  }
100
101
3.71M
  return z;
102
3.71M
}
Unexecuted instantiation: detokenize.c:vp8_decode_value
Unexecuted instantiation: dboolhuff.c:vp8_decode_value
decodemv.c:vp8_decode_value
Line
Count
Source
93
1.17M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
1.17M
  int z = 0;
95
1.17M
  int bit;
96
97
10.4M
  for (bit = bits - 1; bit >= 0; bit--) {
98
9.25M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
9.25M
  }
100
101
1.17M
  return z;
102
1.17M
}
103
104
160M
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
160M
  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
153M
    return 1;
122
153M
  }
123
124
  /* No error. */
125
7.25M
  return 0;
126
160M
}
Unexecuted instantiation: vp8_dx_iface.c:vp8dx_bool_error
Unexecuted instantiation: onyxd_if.c:vp8dx_bool_error
Unexecuted instantiation: threading.c:vp8dx_bool_error
decodeframe.c:vp8dx_bool_error
Line
Count
Source
104
160M
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
160M
  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
153M
    return 1;
122
153M
  }
123
124
  /* No error. */
125
7.25M
  return 0;
126
160M
}
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_