Coverage Report

Created: 2026-05-16 07:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/contrib/contrib-build/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
6.95G
#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
583M
#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.35G
                                                         int probability) {
56
6.35G
  unsigned int bit = 0;
57
6.35G
  VP8_BD_VALUE value;
58
6.35G
  unsigned int split;
59
6.35G
  VP8_BD_VALUE bigsplit;
60
6.35G
  int count;
61
6.35G
  unsigned int range;
62
63
6.35G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
6.35G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
6.35G
  value = br->value;
68
6.35G
  count = br->count;
69
70
6.35G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
6.35G
  range = split;
73
74
6.35G
  if (value >= bigsplit) {
75
89.7M
    range = br->range - split;
76
89.7M
    value = value - bigsplit;
77
89.7M
    bit = 1;
78
89.7M
  }
79
80
6.35G
  {
81
6.35G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
6.35G
    range <<= shift;
83
6.35G
    value <<= shift;
84
6.35G
    count -= shift;
85
6.35G
  }
86
6.35G
  br->value = value;
87
6.35G
  br->count = count;
88
6.35G
  br->range = range;
89
90
6.35G
  return bit;
91
6.35G
}
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
4.32M
                                                         int probability) {
56
4.32M
  unsigned int bit = 0;
57
4.32M
  VP8_BD_VALUE value;
58
4.32M
  unsigned int split;
59
4.32M
  VP8_BD_VALUE bigsplit;
60
4.32M
  int count;
61
4.32M
  unsigned int range;
62
63
4.32M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
4.32M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
4.32M
  value = br->value;
68
4.32M
  count = br->count;
69
70
4.32M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
4.32M
  range = split;
73
74
4.32M
  if (value >= bigsplit) {
75
383k
    range = br->range - split;
76
383k
    value = value - bigsplit;
77
383k
    bit = 1;
78
383k
  }
79
80
4.32M
  {
81
4.32M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
4.32M
    range <<= shift;
83
4.32M
    value <<= shift;
84
4.32M
    count -= shift;
85
4.32M
  }
86
4.32M
  br->value = value;
87
4.32M
  br->count = count;
88
4.32M
  br->range = range;
89
90
4.32M
  return bit;
91
4.32M
}
detokenize.c:vp8dx_decode_bool
Line
Count
Source
55
95.4M
                                                         int probability) {
56
95.4M
  unsigned int bit = 0;
57
95.4M
  VP8_BD_VALUE value;
58
95.4M
  unsigned int split;
59
95.4M
  VP8_BD_VALUE bigsplit;
60
95.4M
  int count;
61
95.4M
  unsigned int range;
62
63
95.4M
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
95.4M
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
95.4M
  value = br->value;
68
95.4M
  count = br->count;
69
70
95.4M
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
95.4M
  range = split;
73
74
95.4M
  if (value >= bigsplit) {
75
24.0M
    range = br->range - split;
76
24.0M
    value = value - bigsplit;
77
24.0M
    bit = 1;
78
24.0M
  }
79
80
95.4M
  {
81
95.4M
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
95.4M
    range <<= shift;
83
95.4M
    value <<= shift;
84
95.4M
    count -= shift;
85
95.4M
  }
86
95.4M
  br->value = value;
87
95.4M
  br->count = count;
88
95.4M
  br->range = range;
89
90
95.4M
  return bit;
91
95.4M
}
Unexecuted instantiation: dboolhuff.c:vp8dx_decode_bool
decodemv.c:vp8dx_decode_bool
Line
Count
Source
55
6.25G
                                                         int probability) {
56
6.25G
  unsigned int bit = 0;
57
6.25G
  VP8_BD_VALUE value;
58
6.25G
  unsigned int split;
59
6.25G
  VP8_BD_VALUE bigsplit;
60
6.25G
  int count;
61
6.25G
  unsigned int range;
62
63
6.25G
  split = 1 + (((br->range - 1) * probability) >> 8);
64
65
6.25G
  if (br->count < 0) vp8dx_bool_decoder_fill(br);
66
67
6.25G
  value = br->value;
68
6.25G
  count = br->count;
69
70
6.25G
  bigsplit = (VP8_BD_VALUE)split << (VP8_BD_VALUE_SIZE - 8);
71
72
6.25G
  range = split;
73
74
6.25G
  if (value >= bigsplit) {
75
65.3M
    range = br->range - split;
76
65.3M
    value = value - bigsplit;
77
65.3M
    bit = 1;
78
65.3M
  }
79
80
6.25G
  {
81
6.25G
    const unsigned char shift = vp8_norm[(unsigned char)range];
82
6.25G
    range <<= shift;
83
6.25G
    value <<= shift;
84
6.25G
    count -= shift;
85
6.25G
  }
86
6.25G
  br->value = value;
87
6.25G
  br->count = count;
88
6.25G
  br->range = range;
89
90
6.25G
  return bit;
91
6.25G
}
92
93
70.4k
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
70.4k
  int z = 0;
95
70.4k
  int bit;
96
97
536k
  for (bit = bits - 1; bit >= 0; bit--) {
98
465k
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
465k
  }
100
101
70.4k
  return z;
102
70.4k
}
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
68.9k
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
68.9k
  int z = 0;
95
68.9k
  int bit;
96
97
522k
  for (bit = bits - 1; bit >= 0; bit--) {
98
453k
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
453k
  }
100
101
68.9k
  return z;
102
68.9k
}
Unexecuted instantiation: detokenize.c:vp8_decode_value
Unexecuted instantiation: dboolhuff.c:vp8_decode_value
decodemv.c:vp8_decode_value
Line
Count
Source
93
1.49k
static INLINE int vp8_decode_value(BOOL_DECODER *br, int bits) {
94
1.49k
  int z = 0;
95
1.49k
  int bit;
96
97
13.4k
  for (bit = bits - 1; bit >= 0; bit--) {
98
11.9k
    z |= (vp8dx_decode_bool(br, 0x80) << bit);
99
11.9k
  }
100
101
1.49k
  return z;
102
1.49k
}
103
104
592M
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
592M
  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
582M
    return 1;
122
582M
  }
123
124
  /* No error. */
125
9.44M
  return 0;
126
592M
}
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
3.12M
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
3.12M
  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.55k
    return 1;
122
1.55k
  }
123
124
  /* No error. */
125
3.12M
  return 0;
126
3.12M
}
decodeframe.c:vp8dx_bool_error
Line
Count
Source
104
588M
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
588M
  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
582M
    return 1;
122
582M
  }
123
124
  /* No error. */
125
6.31M
  return 0;
126
588M
}
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_