Coverage Report

Created: 2025-11-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vp8/encoder/boolhuff.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
/****************************************************************************
12
 *
13
 *   Module Title :     boolhuff.h
14
 *
15
 *   Description  :     Bool Coder header file.
16
 *
17
 ****************************************************************************/
18
#ifndef VPX_VP8_ENCODER_BOOLHUFF_H_
19
#define VPX_VP8_ENCODER_BOOLHUFF_H_
20
21
#include "vpx_ports/mem.h"
22
#include "vpx/internal/vpx_codec_internal.h"
23
24
#ifdef __cplusplus
25
extern "C" {
26
#endif
27
28
typedef struct {
29
  unsigned int lowvalue;
30
  unsigned int range;
31
  int count;
32
  unsigned int pos;
33
  unsigned char *buffer;
34
  unsigned char *buffer_end;
35
  struct vpx_internal_error_info *error;
36
} BOOL_CODER;
37
38
void vp8_start_encode(BOOL_CODER *bc, unsigned char *source,
39
                      unsigned char *source_end);
40
41
void vp8_encode_value(BOOL_CODER *bc, int data, int bits);
42
void vp8_stop_encode(BOOL_CODER *bc);
43
extern const unsigned int vp8_prob_cost[256];
44
45
DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
46
47
static int validate_buffer(const unsigned char *start, size_t len,
48
                           const unsigned char *end,
49
250M
                           struct vpx_internal_error_info *error) {
50
250M
  if (start + len > start && start + len < end) {
51
250M
    return 1;
52
250M
  } else {
53
3
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
3
                       "Truncated packet or corrupt partition ");
55
3
  }
56
57
3
  return 0;
58
250M
}
Unexecuted instantiation: vp8_cx_iface.c:validate_buffer
Unexecuted instantiation: ethreading.c:validate_buffer
Unexecuted instantiation: onyx_if.c:validate_buffer
Unexecuted instantiation: pickinter.c:validate_buffer
Unexecuted instantiation: picklpf.c:validate_buffer
Unexecuted instantiation: vp8_quantize.c:validate_buffer
Unexecuted instantiation: ratectrl.c:validate_buffer
Unexecuted instantiation: rdopt.c:validate_buffer
Unexecuted instantiation: segmentation.c:validate_buffer
Unexecuted instantiation: vp8_skin_detection.c:validate_buffer
Unexecuted instantiation: tokenize.c:validate_buffer
Unexecuted instantiation: treewriter.c:validate_buffer
Unexecuted instantiation: temporal_filter.c:validate_buffer
bitstream.c:validate_buffer
Line
Count
Source
49
246M
                           struct vpx_internal_error_info *error) {
50
246M
  if (start + len > start && start + len < end) {
51
246M
    return 1;
52
246M
  } else {
53
2
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
2
                       "Truncated packet or corrupt partition ");
55
2
  }
56
57
2
  return 0;
58
246M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
3.03M
                           struct vpx_internal_error_info *error) {
50
3.03M
  if (start + len > start && start + len < end) {
51
3.03M
    return 1;
52
3.03M
  } else {
53
1
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
1
                       "Truncated packet or corrupt partition ");
55
1
  }
56
57
1
  return 0;
58
3.03M
}
Unexecuted instantiation: encodeframe.c:validate_buffer
Unexecuted instantiation: encodeintra.c:validate_buffer
Unexecuted instantiation: encodemb.c:validate_buffer
encodemv.c:validate_buffer
Line
Count
Source
49
816k
                           struct vpx_internal_error_info *error) {
50
816k
  if (start + len > start && start + len < end) {
51
816k
    return 1;
52
816k
  } else {
53
0
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
0
                       "Truncated packet or corrupt partition ");
55
0
  }
56
57
0
  return 0;
58
816k
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
59
176M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
176M
  unsigned int split;
61
176M
  int count = bc->count;
62
176M
  unsigned int range = bc->range;
63
176M
  unsigned int lowvalue = bc->lowvalue;
64
176M
  int shift;
65
66
176M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
176M
  range = split;
69
70
176M
  if (bit) {
71
41.5M
    lowvalue += split;
72
41.5M
    range = bc->range - split;
73
41.5M
  }
74
75
176M
  shift = vp8_norm[range];
76
77
176M
  range <<= shift;
78
176M
  count += shift;
79
80
176M
  if (count >= 0) {
81
11.0M
    int offset = shift - count;
82
83
11.0M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
867
      int x = bc->pos - 1;
85
86
3.79k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.92k
        bc->buffer[x] = (unsigned char)0;
88
2.92k
        x--;
89
2.92k
      }
90
91
867
      bc->buffer[x] += 1;
92
867
    }
93
94
11.0M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
11.0M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
11.0M
    shift = count;
98
11.0M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
11.0M
    count -= 8;
100
11.0M
  }
101
102
176M
  lowvalue <<= shift;
103
176M
  bc->count = count;
104
176M
  bc->lowvalue = lowvalue;
105
176M
  bc->range = range;
106
176M
}
Unexecuted instantiation: vp8_cx_iface.c:vp8_encode_bool
Unexecuted instantiation: ethreading.c:vp8_encode_bool
Unexecuted instantiation: onyx_if.c:vp8_encode_bool
Unexecuted instantiation: pickinter.c:vp8_encode_bool
Unexecuted instantiation: picklpf.c:vp8_encode_bool
Unexecuted instantiation: vp8_quantize.c:vp8_encode_bool
Unexecuted instantiation: ratectrl.c:vp8_encode_bool
Unexecuted instantiation: rdopt.c:vp8_encode_bool
Unexecuted instantiation: segmentation.c:vp8_encode_bool
Unexecuted instantiation: vp8_skin_detection.c:vp8_encode_bool
Unexecuted instantiation: tokenize.c:vp8_encode_bool
Unexecuted instantiation: treewriter.c:vp8_encode_bool
Unexecuted instantiation: temporal_filter.c:vp8_encode_bool
bitstream.c:vp8_encode_bool
Line
Count
Source
59
139M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
139M
  unsigned int split;
61
139M
  int count = bc->count;
62
139M
  unsigned int range = bc->range;
63
139M
  unsigned int lowvalue = bc->lowvalue;
64
139M
  int shift;
65
66
139M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
139M
  range = split;
69
70
139M
  if (bit) {
71
29.8M
    lowvalue += split;
72
29.8M
    range = bc->range - split;
73
29.8M
  }
74
75
139M
  shift = vp8_norm[range];
76
77
139M
  range <<= shift;
78
139M
  count += shift;
79
80
139M
  if (count >= 0) {
81
7.15M
    int offset = shift - count;
82
83
7.15M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
793
      int x = bc->pos - 1;
85
86
3.52k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.72k
        bc->buffer[x] = (unsigned char)0;
88
2.72k
        x--;
89
2.72k
      }
90
91
793
      bc->buffer[x] += 1;
92
793
    }
93
94
7.15M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
7.15M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
7.15M
    shift = count;
98
7.15M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
7.15M
    count -= 8;
100
7.15M
  }
101
102
139M
  lowvalue <<= shift;
103
139M
  bc->count = count;
104
139M
  bc->lowvalue = lowvalue;
105
139M
  bc->range = range;
106
139M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
26.1M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
26.1M
  unsigned int split;
61
26.1M
  int count = bc->count;
62
26.1M
  unsigned int range = bc->range;
63
26.1M
  unsigned int lowvalue = bc->lowvalue;
64
26.1M
  int shift;
65
66
26.1M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
26.1M
  range = split;
69
70
26.1M
  if (bit) {
71
8.72M
    lowvalue += split;
72
8.72M
    range = bc->range - split;
73
8.72M
  }
74
75
26.1M
  shift = vp8_norm[range];
76
77
26.1M
  range <<= shift;
78
26.1M
  count += shift;
79
80
26.1M
  if (count >= 0) {
81
3.03M
    int offset = shift - count;
82
83
3.03M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
13
      int x = bc->pos - 1;
85
86
36
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
23
        bc->buffer[x] = (unsigned char)0;
88
23
        x--;
89
23
      }
90
91
13
      bc->buffer[x] += 1;
92
13
    }
93
94
3.03M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
3.03M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
3.03M
    shift = count;
98
3.03M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
3.03M
    count -= 8;
100
3.03M
  }
101
102
26.1M
  lowvalue <<= shift;
103
26.1M
  bc->count = count;
104
26.1M
  bc->lowvalue = lowvalue;
105
26.1M
  bc->range = range;
106
26.1M
}
Unexecuted instantiation: encodeframe.c:vp8_encode_bool
Unexecuted instantiation: encodeintra.c:vp8_encode_bool
Unexecuted instantiation: encodemb.c:vp8_encode_bool
encodemv.c:vp8_encode_bool
Line
Count
Source
59
11.4M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
11.4M
  unsigned int split;
61
11.4M
  int count = bc->count;
62
11.4M
  unsigned int range = bc->range;
63
11.4M
  unsigned int lowvalue = bc->lowvalue;
64
11.4M
  int shift;
65
66
11.4M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
11.4M
  range = split;
69
70
11.4M
  if (bit) {
71
2.95M
    lowvalue += split;
72
2.95M
    range = bc->range - split;
73
2.95M
  }
74
75
11.4M
  shift = vp8_norm[range];
76
77
11.4M
  range <<= shift;
78
11.4M
  count += shift;
79
80
11.4M
  if (count >= 0) {
81
816k
    int offset = shift - count;
82
83
816k
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
61
      int x = bc->pos - 1;
85
86
234
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
173
        bc->buffer[x] = (unsigned char)0;
88
173
        x--;
89
173
      }
90
91
61
      bc->buffer[x] += 1;
92
61
    }
93
94
816k
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
816k
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
816k
    shift = count;
98
816k
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
816k
    count -= 8;
100
816k
  }
101
102
11.4M
  lowvalue <<= shift;
103
11.4M
  bc->count = count;
104
11.4M
  bc->lowvalue = lowvalue;
105
11.4M
  bc->range = range;
106
11.4M
}
Unexecuted instantiation: firstpass.c:vp8_encode_bool
Unexecuted instantiation: mcomp.c:vp8_encode_bool
Unexecuted instantiation: modecosts.c:vp8_encode_bool
107
108
#ifdef __cplusplus
109
}  // extern "C"
110
#endif
111
112
#endif  // VPX_VP8_ENCODER_BOOLHUFF_H_