Coverage Report

Created: 2025-11-16 07:20

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
14.1G
#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.61G
#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
12.5G
                                                         int probability) {
56
12.5G
  unsigned int bit = 0;
57
12.5G
  VP8_BD_VALUE value;
58
12.5G
  unsigned int split;
59
12.5G
  VP8_BD_VALUE bigsplit;
60
12.5G
  int count;
61
12.5G
  unsigned int range;
62
63
12.5G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
12.5G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
12.5G
  value = br->value;
68
12.5G
  count = br->count;
69
70
12.5G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
12.5G
  range = split;
73
74
12.5G
  if (value >= bigsplit) {
75
263M
    range = br->range - split;
76
263M
    value = value - bigsplit;
77
263M
    bit = 1;
78
263M
  }
79
80
12.5G
  {
81
12.5G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
12.5G
    range <<= shift;
83
12.5G
    value <<= shift;
84
12.5G
    count -= shift;
85
12.5G
  }
86
12.5G
  br->value = value;
87
12.5G
  br->count = count;
88
12.5G
  br->range = range;
89
90
12.5G
  return bit;
91
12.5G
}
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
75.2M
                                                         int probability) {
56
75.2M
  unsigned int bit = 0;
57
75.2M
  VP8_BD_VALUE value;
58
75.2M
  unsigned int split;
59
75.2M
  VP8_BD_VALUE bigsplit;
60
75.2M
  int count;
61
75.2M
  unsigned int range;
62
63
75.2M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
75.2M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
75.2M
  value = br->value;
68
75.2M
  count = br->count;
69
70
75.2M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
75.2M
  range = split;
73
74
75.2M
  if (value >= bigsplit) {
75
6.09M
    range = br->range - split;
76
6.09M
    value = value - bigsplit;
77
6.09M
    bit = 1;
78
6.09M
  }
79
80
75.2M
  {
81
75.2M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
75.2M
    range <<= shift;
83
75.2M
    value <<= shift;
84
75.2M
    count -= shift;
85
75.2M
  }
86
75.2M
  br->value = value;
87
75.2M
  br->count = count;
88
75.2M
  br->range = range;
89
90
75.2M
  return bit;
91
75.2M
}
detokenize.c:vp8dx_decode_bool
Line
Count
Source
55
230M
                                                         int probability) {
56
230M
  unsigned int bit = 0;
57
230M
  VP8_BD_VALUE value;
58
230M
  unsigned int split;
59
230M
  VP8_BD_VALUE bigsplit;
60
230M
  int count;
61
230M
  unsigned int range;
62
63
230M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
230M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
230M
  value = br->value;
68
230M
  count = br->count;
69
70
230M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
230M
  range = split;
73
74
230M
  if (value >= bigsplit) {
75
70.8M
    range = br->range - split;
76
70.8M
    value = value - bigsplit;
77
70.8M
    bit = 1;
78
70.8M
  }
79
80
230M
  {
81
230M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
230M
    range <<= shift;
83
230M
    value <<= shift;
84
230M
    count -= shift;
85
230M
  }
86
230M
  br->value = value;
87
230M
  br->count = count;
88
230M
  br->range = range;
89
90
230M
  return bit;
91
230M
}
Unexecuted instantiation: dboolhuff.c:vp8dx_decode_bool
decodemv.c:vp8dx_decode_bool
Line
Count
Source
55
12.2G
                                                         int probability) {
56
12.2G
  unsigned int bit = 0;
57
12.2G
  VP8_BD_VALUE value;
58
12.2G
  unsigned int split;
59
12.2G
  VP8_BD_VALUE bigsplit;
60
12.2G
  int count;
61
12.2G
  unsigned int range;
62
63
12.2G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
12.2G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
12.2G
  value = br->value;
68
12.2G
  count = br->count;
69
70
12.2G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
12.2G
  range = split;
73
74
12.2G
  if (value >= bigsplit) {
75
186M
    range = br->range - split;
76
186M
    value = value - bigsplit;
77
186M
    bit = 1;
78
186M
  }
79
80
12.2G
  {
81
12.2G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
12.2G
    range <<= shift;
83
12.2G
    value <<= shift;
84
12.2G
    count -= shift;
85
12.2G
  }
86
12.2G
  br->value = value;
87
12.2G
  br->count = count;
88
12.2G
  br->range = range;
89
90
12.2G
  return bit;
91
12.2G
}
92
93
1.73M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
1.73M
  int z = 0;
95
1.73M
  int bit;
96
97
13.2M
  for (bit = bits - 1; bit >= 0; bit--) {
98
11.4M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
11.4M
  }
100
101
1.73M
  return z;
102
1.73M
}
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
1.31M
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
1.31M
  int z = 0;
95
1.31M
  int bit;
96
97
9.47M
  for (bit = bits - 1; bit >= 0; bit--) {
98
8.16M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
8.16M
  }
100
101
1.31M
  return z;
102
1.31M
}
Unexecuted instantiation: detokenize.c:vp8_decode_value
Unexecuted instantiation: dboolhuff.c:vp8_decode_value
decodemv.c:vp8_decode_value
Line
Count
Source
93
422k
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
422k
  int z = 0;
95
422k
  int bit;
96
97
3.75M
  for (bit = bits - 1; bit >= 0; bit--) {
98
3.33M
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
3.33M
  }
100
101
422k
  return z;
102
422k
}
103
104
1.62G
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.62G
  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.60G
    return 1;
122
1.60G
  }
123
124
  /* No error. */
125
17.6M
  return 0;
126
1.62G
}
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
1.62G
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.62G
  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.60G
    return 1;
122
1.60G
  }
123
124
  /* No error. */
125
17.6M
  return 0;
126
1.62G
}
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_