Coverage Report

Created: 2026-02-14 06:59

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
7.37G
#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
764M
#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
6.59G
                                                         int probability) {
56
6.59G
  unsigned int bit = 0;
57
6.59G
  VP8_BD_VALUE value;
58
6.59G
  unsigned int split;
59
6.59G
  VP8_BD_VALUE bigsplit;
60
6.59G
  int count;
61
6.59G
  unsigned int range;
62
63
6.59G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
6.59G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
6.59G
  value = br->value;
68
6.59G
  count = br->count;
69
70
6.59G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
6.59G
  range = split;
73
74
6.59G
  if (value >= bigsplit) {
75
84.4M
    range = br->range - split;
76
84.4M
    value = value - bigsplit;
77
84.4M
    bit = 1;
78
84.4M
  }
79
80
6.59G
  {
81
6.59G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
6.59G
    range <<= shift;
83
6.59G
    value <<= shift;
84
6.59G
    count -= shift;
85
6.59G
  }
86
6.59G
  br->value = value;
87
6.59G
  br->count = count;
88
6.59G
  br->range = range;
89
90
6.59G
  return bit;
91
6.59G
}
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
9.27M
                                                         int probability) {
56
9.27M
  unsigned int bit = 0;
57
9.27M
  VP8_BD_VALUE value;
58
9.27M
  unsigned int split;
59
9.27M
  VP8_BD_VALUE bigsplit;
60
9.27M
  int count;
61
9.27M
  unsigned int range;
62
63
9.27M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
9.27M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
9.27M
  value = br->value;
68
9.27M
  count = br->count;
69
70
9.27M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
9.27M
  range = split;
73
74
9.27M
  if (value >= bigsplit) {
75
836k
    range = br->range - split;
76
836k
    value = value - bigsplit;
77
836k
    bit = 1;
78
836k
  }
79
80
9.27M
  {
81
9.27M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
9.27M
    range <<= shift;
83
9.27M
    value <<= shift;
84
9.27M
    count -= shift;
85
9.27M
  }
86
9.27M
  br->value = value;
87
9.27M
  br->count = count;
88
9.27M
  br->range = range;
89
90
9.27M
  return bit;
91
9.27M
}
detokenize.c:vp8dx_decode_bool
Line
Count
Source
55
73.7M
                                                         int probability) {
56
73.7M
  unsigned int bit = 0;
57
73.7M
  VP8_BD_VALUE value;
58
73.7M
  unsigned int split;
59
73.7M
  VP8_BD_VALUE bigsplit;
60
73.7M
  int count;
61
73.7M
  unsigned int range;
62
63
73.7M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
73.7M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
73.7M
  value = br->value;
68
73.7M
  count = br->count;
69
70
73.7M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
73.7M
  range = split;
73
74
73.7M
  if (value >= bigsplit) {
75
24.2M
    range = br->range - split;
76
24.2M
    value = value - bigsplit;
77
24.2M
    bit = 1;
78
24.2M
  }
79
80
73.7M
  {
81
73.7M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
73.7M
    range <<= shift;
83
73.7M
    value <<= shift;
84
73.7M
    count -= shift;
85
73.7M
  }
86
73.7M
  br->value = value;
87
73.7M
  br->count = count;
88
73.7M
  br->range = range;
89
90
73.7M
  return bit;
91
73.7M
}
Unexecuted instantiation: dboolhuff.c:vp8dx_decode_bool
decodemv.c:vp8dx_decode_bool
Line
Count
Source
55
6.51G
                                                         int probability) {
56
6.51G
  unsigned int bit = 0;
57
6.51G
  VP8_BD_VALUE value;
58
6.51G
  unsigned int split;
59
6.51G
  VP8_BD_VALUE bigsplit;
60
6.51G
  int count;
61
6.51G
  unsigned int range;
62
63
6.51G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
6.51G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
6.51G
  value = br->value;
68
6.51G
  count = br->count;
69
70
6.51G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
6.51G
  range = split;
73
74
6.51G
  if (value >= bigsplit) {
75
59.2M
    range = br->range - split;
76
59.2M
    value = value - bigsplit;
77
59.2M
    bit = 1;
78
59.2M
  }
79
80
6.51G
  {
81
6.51G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
6.51G
    range <<= shift;
83
6.51G
    value <<= shift;
84
6.51G
    count -= shift;
85
6.51G
  }
86
6.51G
  br->value = value;
87
6.51G
  br->count = count;
88
6.51G
  br->range = range;
89
90
6.51G
  return bit;
91
6.51G
}
92
93
198k
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
198k
  int z = 0;
95
198k
  int bit;
96
97
1.54M
  for (bit = bits - 1; bit >= 0; bit--) {
98
1.35M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
1.35M
  }
100
101
198k
  return z;
102
198k
}
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
165k
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
165k
  int z = 0;
95
165k
  int bit;
96
97
1.25M
  for (bit = bits - 1; bit >= 0; bit--) {
98
1.08M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
1.08M
  }
100
101
165k
  return z;
102
165k
}
Unexecuted instantiation: detokenize.c:vp8_decode_value
Unexecuted instantiation: dboolhuff.c:vp8_decode_value
decodemv.c:vp8_decode_value
Line
Count
Source
93
33.5k
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
33.5k
  int z = 0;
95
33.5k
  int bit;
96
97
298k
  for (bit = bits - 1; bit >= 0; bit--) {
98
264k
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
264k
  }
100
101
33.5k
  return z;
102
33.5k
}
103
104
768M
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
768M
  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
762M
    return 1;
122
762M
  }
123
124
  /* No error. */
125
5.67M
  return 0;
126
768M
}
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
768M
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
768M
  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
762M
    return 1;
122
762M
  }
123
124
  /* No error. */
125
5.67M
  return 0;
126
768M
}
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_