Coverage Report

Created: 2026-04-12 06:11

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
19.9G
#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
1.75G
#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
18.1G
                                                         int probability) {
56
18.1G
  unsigned int bit = 0;
57
18.1G
  VP8_BD_VALUE value;
58
18.1G
  unsigned int split;
59
18.1G
  VP8_BD_VALUE bigsplit;
60
18.1G
  int count;
61
18.1G
  unsigned int range;
62
63
18.1G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
18.1G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
18.1G
  value = br->value;
68
18.1G
  count = br->count;
69
70
18.1G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
18.1G
  range = split;
73
74
18.1G
  if (value >= bigsplit) {
75
314M
    range = br->range - split;
76
314M
    value = value - bigsplit;
77
314M
    bit = 1;
78
314M
  }
79
80
18.1G
  {
81
18.1G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
18.1G
    range <<= shift;
83
18.1G
    value <<= shift;
84
18.1G
    count -= shift;
85
18.1G
  }
86
18.1G
  br->value = value;
87
18.1G
  br->count = count;
88
18.1G
  br->range = range;
89
90
18.1G
  return bit;
91
18.1G
}
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
188M
                                                         int probability) {
56
188M
  unsigned int bit = 0;
57
188M
  VP8_BD_VALUE value;
58
188M
  unsigned int split;
59
188M
  VP8_BD_VALUE bigsplit;
60
188M
  int count;
61
188M
  unsigned int range;
62
63
188M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
188M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
188M
  value = br->value;
68
188M
  count = br->count;
69
70
188M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
188M
  range = split;
73
74
188M
  if (value >= bigsplit) {
75
7.47M
    range = br->range - split;
76
7.47M
    value = value - bigsplit;
77
7.47M
    bit = 1;
78
7.47M
  }
79
80
188M
  {
81
188M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
188M
    range <<= shift;
83
188M
    value <<= shift;
84
188M
    count -= shift;
85
188M
  }
86
188M
  br->value = value;
87
188M
  br->count = count;
88
188M
  br->range = range;
89
90
188M
  return bit;
91
188M
}
detokenize.c:vp8dx_decode_bool
Line
Count
Source
55
201M
                                                         int probability) {
56
201M
  unsigned int bit = 0;
57
201M
  VP8_BD_VALUE value;
58
201M
  unsigned int split;
59
201M
  VP8_BD_VALUE bigsplit;
60
201M
  int count;
61
201M
  unsigned int range;
62
63
201M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
201M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
201M
  value = br->value;
68
201M
  count = br->count;
69
70
201M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
201M
  range = split;
73
74
201M
  if (value >= bigsplit) {
75
60.6M
    range = br->range - split;
76
60.6M
    value = value - bigsplit;
77
60.6M
    bit = 1;
78
60.6M
  }
79
80
201M
  {
81
201M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
201M
    range <<= shift;
83
201M
    value <<= shift;
84
201M
    count -= shift;
85
201M
  }
86
201M
  br->value = value;
87
201M
  br->count = count;
88
201M
  br->range = range;
89
90
201M
  return bit;
91
201M
}
Unexecuted instantiation: dboolhuff.c:vp8dx_decode_bool
decodemv.c:vp8dx_decode_bool
Line
Count
Source
55
17.7G
                                                         int probability) {
56
17.7G
  unsigned int bit = 0;
57
17.7G
  VP8_BD_VALUE value;
58
17.7G
  unsigned int split;
59
17.7G
  VP8_BD_VALUE bigsplit;
60
17.7G
  int count;
61
17.7G
  unsigned int range;
62
63
17.7G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
17.7G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
17.7G
  value = br->value;
68
17.7G
  count = br->count;
69
70
17.7G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
17.7G
  range = split;
73
74
17.7G
  if (value >= bigsplit) {
75
246M
    range = br->range - split;
76
246M
    value = value - bigsplit;
77
246M
    bit = 1;
78
246M
  }
79
80
17.7G
  {
81
17.7G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
17.7G
    range <<= shift;
83
17.7G
    value <<= shift;
84
17.7G
    count -= shift;
85
17.7G
  }
86
17.7G
  br->value = value;
87
17.7G
  br->count = count;
88
17.7G
  br->range = range;
89
90
17.7G
  return bit;
91
17.7G
}
92
93
2.91M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
2.91M
  int z = 0;
95
2.91M
  int bit;
96
97
20.8M
  for (bit = bits - 1; bit >= 0; bit--) {
98
17.9M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
17.9M
  }
100
101
2.91M
  return z;
102
2.91M
}
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.13M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
2.13M
  int z = 0;
95
2.13M
  int bit;
96
97
13.9M
  for (bit = bits - 1; bit >= 0; bit--) {
98
11.7M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
11.7M
  }
100
101
2.13M
  return z;
102
2.13M
}
Unexecuted instantiation: detokenize.c:vp8_decode_value
Unexecuted instantiation: dboolhuff.c:vp8_decode_value
decodemv.c:vp8_decode_value
Line
Count
Source
93
776k
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
776k
  int z = 0;
95
776k
  int bit;
96
97
6.92M
  for (bit = bits - 1; bit >= 0; bit--) {
98
6.14M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
6.14M
  }
100
101
776k
  return z;
102
776k
}
103
104
1.76G
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
1.76G
  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
1.74G
    return 1;
122
1.74G
  }
123
124
  /* No error. */
125
18.1M
  return 0;
126
1.76G
}
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
7.26M
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
7.26M
  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
27.3k
    return 1;
122
27.3k
  }
123
124
  /* No error. */
125
7.23M
  return 0;
126
7.26M
}
decodeframe.c:vp8dx_bool_error
Line
Count
Source
104
1.75G
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
1.75G
  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
1.74G
    return 1;
122
1.74G
  }
123
124
  /* No error. */
125
10.9M
  return 0;
126
1.75G
}
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_