Coverage Report

Created: 2025-11-16 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/common/pred_common.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3
 *
4
 * This source code is subject to the terms of the BSD 2 Clause License and
5
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6
 * was not distributed with this source code in the LICENSE file, you can
7
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8
 * Media Patent License 1.0 was not distributed with this source code in the
9
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
 */
11
12
#include "av1/common/common.h"
13
#include "av1/common/pred_common.h"
14
#include "av1/common/reconinter.h"
15
#include "av1/common/reconintra.h"
16
#include "av1/common/seg_common.h"
17
18
// Returns a context number for the given MB prediction signal
19
static InterpFilter get_ref_filter_type(const MB_MODE_INFO *ref_mbmi,
20
                                        const MACROBLOCKD *xd, int dir,
21
5.59M
                                        MV_REFERENCE_FRAME ref_frame) {
22
5.59M
  (void)xd;
23
24
5.59M
  return ((ref_mbmi->ref_frame[0] == ref_frame ||
25
1.61M
           ref_mbmi->ref_frame[1] == ref_frame)
26
5.59M
              ? av1_extract_interp_filter(ref_mbmi->interp_filters, dir & 0x01)
27
5.59M
              : SWITCHABLE_FILTERS);
28
5.59M
}
29
30
2.87M
int av1_get_pred_context_switchable_interp(const MACROBLOCKD *xd, int dir) {
31
2.87M
  const MB_MODE_INFO *const mbmi = xd->mi[0];
32
2.87M
  const int ctx_offset =
33
2.87M
      (mbmi->ref_frame[1] > INTRA_FRAME) * INTER_FILTER_COMP_OFFSET;
34
2.87M
  assert(dir == 0 || dir == 1);
35
2.87M
  const MV_REFERENCE_FRAME ref_frame = mbmi->ref_frame[0];
36
  // Note:
37
  // The mode info data structure has a one element border above and to the
38
  // left of the entries corresponding to real macroblocks.
39
  // The prediction flags in these dummy entries are initialized to 0.
40
2.87M
  int filter_type_ctx = ctx_offset + (dir & 0x01) * INTER_FILTER_DIR_OFFSET;
41
2.87M
  int left_type = SWITCHABLE_FILTERS;
42
2.87M
  int above_type = SWITCHABLE_FILTERS;
43
44
2.87M
  if (xd->left_available)
45
2.80M
    left_type = get_ref_filter_type(xd->mi[-1], xd, dir, ref_frame);
46
47
2.87M
  if (xd->up_available)
48
2.79M
    above_type =
49
2.79M
        get_ref_filter_type(xd->mi[-xd->mi_stride], xd, dir, ref_frame);
50
51
2.87M
  if (left_type == above_type) {
52
1.83M
    filter_type_ctx += left_type;
53
1.83M
  } else if (left_type == SWITCHABLE_FILTERS) {
54
488k
    assert(above_type != SWITCHABLE_FILTERS);
55
488k
    filter_type_ctx += above_type;
56
543k
  } else if (above_type == SWITCHABLE_FILTERS) {
57
492k
    assert(left_type != SWITCHABLE_FILTERS);
58
492k
    filter_type_ctx += left_type;
59
492k
  } else {
60
50.9k
    filter_type_ctx += SWITCHABLE_FILTERS;
61
50.9k
  }
62
63
2.87M
  return filter_type_ctx;
64
2.87M
}
65
66
262k
static void palette_add_to_cache(uint16_t *cache, int *n, uint16_t val) {
67
  // Do not add an already existing value
68
262k
  if (*n > 0 && val == cache[*n - 1]) return;
69
70
228k
  cache[(*n)++] = val;
71
228k
}
72
73
int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
74
81.2k
                          uint16_t *cache) {
75
81.2k
  const int row = -xd->mb_to_top_edge >> 3;
76
  // Do not refer to above SB row when on SB boundary.
77
81.2k
  const MB_MODE_INFO *const above_mi =
78
81.2k
      (row % (1 << MIN_SB_SIZE_LOG2)) ? xd->above_mbmi : NULL;
79
81.2k
  const MB_MODE_INFO *const left_mi = xd->left_mbmi;
80
81.2k
  int above_n = 0, left_n = 0;
81
81.2k
  if (above_mi) above_n = above_mi->palette_mode_info.palette_size[plane != 0];
82
81.2k
  if (left_mi) left_n = left_mi->palette_mode_info.palette_size[plane != 0];
83
81.2k
  if (above_n == 0 && left_n == 0) return 0;
84
45.5k
  int above_idx = plane * PALETTE_MAX_SIZE;
85
45.5k
  int left_idx = plane * PALETTE_MAX_SIZE;
86
45.5k
  int n = 0;
87
45.5k
  const uint16_t *above_colors =
88
45.5k
      above_mi ? above_mi->palette_mode_info.palette_colors : NULL;
89
45.5k
  const uint16_t *left_colors =
90
45.5k
      left_mi ? left_mi->palette_mode_info.palette_colors : NULL;
91
  // Merge the sorted lists of base colors from above and left to get
92
  // combined sorted color cache.
93
140k
  while (above_n > 0 && left_n > 0) {
94
95.3k
    uint16_t v_above = above_colors[above_idx];
95
95.3k
    uint16_t v_left = left_colors[left_idx];
96
95.3k
    if (v_left < v_above) {
97
37.7k
      palette_add_to_cache(cache, &n, v_left);
98
37.7k
      ++left_idx, --left_n;
99
57.6k
    } else {
100
57.6k
      palette_add_to_cache(cache, &n, v_above);
101
57.6k
      ++above_idx, --above_n;
102
57.6k
      if (v_left == v_above) ++left_idx, --left_n;
103
57.6k
    }
104
95.3k
  }
105
119k
  while (above_n-- > 0) {
106
73.4k
    uint16_t val = above_colors[above_idx++];
107
73.4k
    palette_add_to_cache(cache, &n, val);
108
73.4k
  }
109
139k
  while (left_n-- > 0) {
110
93.5k
    uint16_t val = left_colors[left_idx++];
111
93.5k
    palette_add_to_cache(cache, &n, val);
112
93.5k
  }
113
45.5k
  assert(n <= 2 * PALETTE_MAX_SIZE);
114
45.8k
  return n;
115
45.5k
}
116
117
// The mode info data structure has a one element border above and to the
118
// left of the entries corresponding to real macroblocks.
119
// The prediction flags in these dummy entries are initialized to 0.
120
// 0 - inter/inter, inter/--, --/inter, --/--
121
// 1 - intra/inter, inter/intra
122
// 2 - intra/--, --/intra
123
// 3 - intra/intra
124
5.15M
int av1_get_intra_inter_context(const MACROBLOCKD *xd) {
125
5.15M
  const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
126
5.15M
  const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
127
5.15M
  const int has_above = xd->up_available;
128
5.15M
  const int has_left = xd->left_available;
129
130
5.15M
  if (has_above && has_left) {  // both edges available
131
4.96M
    const int above_intra = !is_inter_block(above_mbmi);
132
4.96M
    const int left_intra = !is_inter_block(left_mbmi);
133
4.96M
    return left_intra && above_intra ? 3 : left_intra || above_intra;
134
4.96M
  } else if (has_above || has_left) {  // one edge available
135
169k
    return 2 * !is_inter_block(has_above ? above_mbmi : left_mbmi);
136
169k
  } else {
137
26.7k
    return 0;
138
26.7k
  }
139
5.15M
}
140
141
#define CHECK_BACKWARD_REFS(ref_frame) \
142
1.07M
  (((ref_frame) >= BWDREF_FRAME) && ((ref_frame) <= ALTREF_FRAME))
143
854k
#define IS_BACKWARD_REF_FRAME(ref_frame) CHECK_BACKWARD_REFS(ref_frame)
144
145
713k
int av1_get_reference_mode_context(const MACROBLOCKD *xd) {
146
713k
  int ctx;
147
713k
  const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
148
713k
  const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
149
713k
  const int has_above = xd->up_available;
150
713k
  const int has_left = xd->left_available;
151
152
  // Note:
153
  // The mode info data structure has a one element border above and to the
154
  // left of the entries corresponding to real macroblocks.
155
  // The prediction flags in these dummy entries are initialized to 0.
156
713k
  if (has_above && has_left) {  // both edges available
157
625k
    if (!has_second_ref(above_mbmi) && !has_second_ref(left_mbmi))
158
      // neither edge uses comp pred (0/1)
159
245k
      ctx = IS_BACKWARD_REF_FRAME(above_mbmi->ref_frame[0]) ^
160
245k
            IS_BACKWARD_REF_FRAME(left_mbmi->ref_frame[0]);
161
379k
    else if (!has_second_ref(above_mbmi))
162
      // one of two edges uses comp pred (2/3)
163
108k
      ctx = 2 + (IS_BACKWARD_REF_FRAME(above_mbmi->ref_frame[0]) ||
164
79.1k
                 !is_inter_block(above_mbmi));
165
271k
    else if (!has_second_ref(left_mbmi))
166
      // one of two edges uses comp pred (2/3)
167
109k
      ctx = 2 + (IS_BACKWARD_REF_FRAME(left_mbmi->ref_frame[0]) ||
168
80.1k
                 !is_inter_block(left_mbmi));
169
161k
    else  // both edges use comp pred (4)
170
161k
      ctx = 4;
171
625k
  } else if (has_above || has_left) {  // one edge available
172
76.8k
    const MB_MODE_INFO *edge_mbmi = has_above ? above_mbmi : left_mbmi;
173
174
76.8k
    if (!has_second_ref(edge_mbmi))
175
      // edge does not use comp pred (0/1)
176
40.7k
      ctx = IS_BACKWARD_REF_FRAME(edge_mbmi->ref_frame[0]);
177
36.0k
    else
178
      // edge uses comp pred (3)
179
36.0k
      ctx = 3;
180
76.8k
  } else {  // no edges available (1)
181
10.6k
    ctx = 1;
182
10.6k
  }
183
713k
  assert(ctx >= 0 && ctx < COMP_INTER_CONTEXTS);
184
713k
  return ctx;
185
713k
}
186
187
378k
int av1_get_comp_reference_type_context(const MACROBLOCKD *xd) {
188
378k
  int pred_context;
189
378k
  const MB_MODE_INFO *const above_mbmi = xd->above_mbmi;
190
378k
  const MB_MODE_INFO *const left_mbmi = xd->left_mbmi;
191
378k
  const int above_in_image = xd->up_available;
192
378k
  const int left_in_image = xd->left_available;
193
194
378k
  if (above_in_image && left_in_image) {  // both edges available
195
335k
    const int above_intra = !is_inter_block(above_mbmi);
196
335k
    const int left_intra = !is_inter_block(left_mbmi);
197
198
335k
    if (above_intra && left_intra) {  // intra/intra
199
5.02k
      pred_context = 2;
200
330k
    } else if (above_intra || left_intra) {  // intra/inter
201
54.9k
      const MB_MODE_INFO *inter_mbmi = above_intra ? left_mbmi : above_mbmi;
202
203
54.9k
      if (!has_second_ref(inter_mbmi))  // single pred
204
18.5k
        pred_context = 2;
205
36.4k
      else  // comp pred
206
36.4k
        pred_context = 1 + 2 * has_uni_comp_refs(inter_mbmi);
207
275k
    } else {  // inter/inter
208
275k
      const int a_sg = !has_second_ref(above_mbmi);
209
275k
      const int l_sg = !has_second_ref(left_mbmi);
210
275k
      const MV_REFERENCE_FRAME frfa = above_mbmi->ref_frame[0];
211
275k
      const MV_REFERENCE_FRAME frfl = left_mbmi->ref_frame[0];
212
213
275k
      if (a_sg && l_sg) {  // single/single
214
35.1k
        pred_context = 1 + 2 * (!(IS_BACKWARD_REF_FRAME(frfa) ^
215
35.1k
                                  IS_BACKWARD_REF_FRAME(frfl)));
216
240k
      } else if (l_sg || a_sg) {  // single/comp
217
101k
        const int uni_rfc =
218
101k
            a_sg ? has_uni_comp_refs(left_mbmi) : has_uni_comp_refs(above_mbmi);
219
220
101k
        if (!uni_rfc)  // comp bidir
221
84.7k
          pred_context = 1;
222
16.3k
        else  // comp unidir
223
16.3k
          pred_context = 3 + (!(IS_BACKWARD_REF_FRAME(frfa) ^
224
16.3k
                                IS_BACKWARD_REF_FRAME(frfl)));
225
139k
      } else {  // comp/comp
226
139k
        const int a_uni_rfc = has_uni_comp_refs(above_mbmi);
227
139k
        const int l_uni_rfc = has_uni_comp_refs(left_mbmi);
228
229
139k
        if (!a_uni_rfc && !l_uni_rfc)  // bidir/bidir
230
110k
          pred_context = 0;
231
29.1k
        else if (!a_uni_rfc || !l_uni_rfc)  // unidir/bidir
232
19.2k
          pred_context = 2;
233
9.93k
        else  // unidir/unidir
234
9.93k
          pred_context =
235
9.93k
              3 + (!((frfa == BWDREF_FRAME) ^ (frfl == BWDREF_FRAME)));
236
139k
      }
237
275k
    }
238
335k
  } else if (above_in_image || left_in_image) {  // one edge available
239
35.0k
    const MB_MODE_INFO *edge_mbmi = above_in_image ? above_mbmi : left_mbmi;
240
241
35.0k
    if (!is_inter_block(edge_mbmi)) {  // intra
242
754
      pred_context = 2;
243
34.2k
    } else {                           // inter
244
34.2k
      if (!has_second_ref(edge_mbmi))  // single pred
245
7.31k
        pred_context = 2;
246
26.9k
      else  // comp pred
247
26.9k
        pred_context = 4 * has_uni_comp_refs(edge_mbmi);
248
34.2k
    }
249
35.0k
  } else {  // no edges available
250
7.67k
    pred_context = 2;
251
7.67k
  }
252
253
378k
  assert(pred_context >= 0 && pred_context < COMP_REF_TYPE_CONTEXTS);
254
378k
  return pred_context;
255
378k
}
256
257
// Returns a context number for the given MB prediction signal
258
//
259
// Signal the uni-directional compound reference frame pair as either
260
// (BWDREF, ALTREF), or (LAST, LAST2) / (LAST, LAST3) / (LAST, GOLDEN),
261
// conditioning on the pair is known as uni-directional.
262
//
263
// 3 contexts: Voting is used to compare the count of forward references with
264
//             that of backward references from the spatial neighbors.
265
56.5k
int av1_get_pred_context_uni_comp_ref_p(const MACROBLOCKD *xd) {
266
56.5k
  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
267
268
  // Count of forward references (L, L2, L3, or G)
269
56.5k
  const int frf_count = ref_counts[LAST_FRAME] + ref_counts[LAST2_FRAME] +
270
56.5k
                        ref_counts[LAST3_FRAME] + ref_counts[GOLDEN_FRAME];
271
  // Count of backward references (B or A)
272
56.5k
  const int brf_count = ref_counts[BWDREF_FRAME] + ref_counts[ALTREF2_FRAME] +
273
56.5k
                        ref_counts[ALTREF_FRAME];
274
275
56.5k
  const int pred_context =
276
56.5k
      (frf_count == brf_count) ? 1 : ((frf_count < brf_count) ? 0 : 2);
277
278
56.5k
  assert(pred_context >= 0 && pred_context < UNI_COMP_REF_CONTEXTS);
279
56.5k
  return pred_context;
280
56.5k
}
281
282
// Returns a context number for the given MB prediction signal
283
//
284
// Signal the uni-directional compound reference frame pair as
285
// either (LAST, LAST2), or (LAST, LAST3) / (LAST, GOLDEN),
286
// conditioning on the pair is known as one of the above three.
287
//
288
// 3 contexts: Voting is used to compare the count of LAST2_FRAME with the
289
//             total count of LAST3/GOLDEN from the spatial neighbors.
290
40.6k
int av1_get_pred_context_uni_comp_ref_p1(const MACROBLOCKD *xd) {
291
40.6k
  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
292
293
  // Count of LAST2
294
40.6k
  const int last2_count = ref_counts[LAST2_FRAME];
295
  // Count of LAST3 or GOLDEN
296
40.6k
  const int last3_or_gld_count =
297
40.6k
      ref_counts[LAST3_FRAME] + ref_counts[GOLDEN_FRAME];
298
299
40.6k
  const int pred_context = (last2_count == last3_or_gld_count)
300
40.6k
                               ? 1
301
40.6k
                               : ((last2_count < last3_or_gld_count) ? 0 : 2);
302
303
40.6k
  assert(pred_context >= 0 && pred_context < UNI_COMP_REF_CONTEXTS);
304
40.6k
  return pred_context;
305
40.6k
}
306
307
// Returns a context number for the given MB prediction signal
308
//
309
// Signal the uni-directional compound reference frame pair as
310
// either (LAST, LAST3) or (LAST, GOLDEN),
311
// conditioning on the pair is known as one of the above two.
312
//
313
// 3 contexts: Voting is used to compare the count of LAST3_FRAME with the
314
//             total count of GOLDEN_FRAME from the spatial neighbors.
315
26.3k
int av1_get_pred_context_uni_comp_ref_p2(const MACROBLOCKD *xd) {
316
26.3k
  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
317
318
  // Count of LAST3
319
26.3k
  const int last3_count = ref_counts[LAST3_FRAME];
320
  // Count of GOLDEN
321
26.3k
  const int gld_count = ref_counts[GOLDEN_FRAME];
322
323
26.3k
  const int pred_context =
324
26.3k
      (last3_count == gld_count) ? 1 : ((last3_count < gld_count) ? 0 : 2);
325
326
26.3k
  assert(pred_context >= 0 && pred_context < UNI_COMP_REF_CONTEXTS);
327
26.3k
  return pred_context;
328
26.3k
}
329
330
// == Common context functions for both comp and single ref ==
331
//
332
// Obtain contexts to signal a reference frame to be either LAST/LAST2 or
333
// LAST3/GOLDEN.
334
2.88M
static int get_pred_context_ll2_or_l3gld(const MACROBLOCKD *xd) {
335
2.88M
  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
336
337
  // Count of LAST + LAST2
338
2.88M
  const int last_last2_count = ref_counts[LAST_FRAME] + ref_counts[LAST2_FRAME];
339
  // Count of LAST3 + GOLDEN
340
2.88M
  const int last3_gld_count =
341
2.88M
      ref_counts[LAST3_FRAME] + ref_counts[GOLDEN_FRAME];
342
343
2.88M
  const int pred_context = (last_last2_count == last3_gld_count)
344
2.88M
                               ? 1
345
2.88M
                               : ((last_last2_count < last3_gld_count) ? 0 : 2);
346
347
2.88M
  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
348
2.88M
  return pred_context;
349
2.88M
}
350
351
// Obtain contexts to signal a reference frame to be either LAST or LAST2.
352
2.49M
static int get_pred_context_last_or_last2(const MACROBLOCKD *xd) {
353
2.49M
  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
354
355
  // Count of LAST
356
2.49M
  const int last_count = ref_counts[LAST_FRAME];
357
  // Count of LAST2
358
2.49M
  const int last2_count = ref_counts[LAST2_FRAME];
359
360
2.49M
  const int pred_context =
361
2.49M
      (last_count == last2_count) ? 1 : ((last_count < last2_count) ? 0 : 2);
362
363
2.49M
  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
364
2.49M
  return pred_context;
365
2.49M
}
366
367
// Obtain contexts to signal a reference frame to be either LAST3 or GOLDEN.
368
393k
static int get_pred_context_last3_or_gld(const MACROBLOCKD *xd) {
369
393k
  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
370
371
  // Count of LAST3
372
393k
  const int last3_count = ref_counts[LAST3_FRAME];
373
  // Count of GOLDEN
374
393k
  const int gld_count = ref_counts[GOLDEN_FRAME];
375
376
393k
  const int pred_context =
377
393k
      (last3_count == gld_count) ? 1 : ((last3_count < gld_count) ? 0 : 2);
378
379
393k
  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
380
394k
  return pred_context;
381
393k
}
382
383
// Obtain contexts to signal a reference frame be either BWDREF/ALTREF2, or
384
// ALTREF.
385
831k
static int get_pred_context_brfarf2_or_arf(const MACROBLOCKD *xd) {
386
831k
  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
387
388
  // Counts of BWDREF, ALTREF2, or ALTREF frames (B, A2, or A)
389
831k
  const int brfarf2_count =
390
831k
      ref_counts[BWDREF_FRAME] + ref_counts[ALTREF2_FRAME];
391
831k
  const int arf_count = ref_counts[ALTREF_FRAME];
392
393
831k
  const int pred_context =
394
831k
      (brfarf2_count == arf_count) ? 1 : ((brfarf2_count < arf_count) ? 0 : 2);
395
396
831k
  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
397
831k
  return pred_context;
398
831k
}
399
400
// Obtain contexts to signal a reference frame be either BWDREF or ALTREF2.
401
379k
static int get_pred_context_brf_or_arf2(const MACROBLOCKD *xd) {
402
379k
  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
403
404
  // Count of BWDREF frames (B)
405
379k
  const int brf_count = ref_counts[BWDREF_FRAME];
406
  // Count of ALTREF2 frames (A2)
407
379k
  const int arf2_count = ref_counts[ALTREF2_FRAME];
408
409
379k
  const int pred_context =
410
379k
      (brf_count == arf2_count) ? 1 : ((brf_count < arf2_count) ? 0 : 2);
411
412
379k
  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
413
379k
  return pred_context;
414
379k
}
415
416
// == Context functions for comp ref ==
417
//
418
// Returns a context number for the given MB prediction signal
419
// Signal the first reference frame for a compound mode be either
420
// GOLDEN/LAST3, or LAST/LAST2.
421
321k
int av1_get_pred_context_comp_ref_p(const MACROBLOCKD *xd) {
422
321k
  return get_pred_context_ll2_or_l3gld(xd);
423
321k
}
424
425
// Returns a context number for the given MB prediction signal
426
// Signal the first reference frame for a compound mode be LAST,
427
// conditioning on that it is known either LAST/LAST2.
428
216k
int av1_get_pred_context_comp_ref_p1(const MACROBLOCKD *xd) {
429
216k
  return get_pred_context_last_or_last2(xd);
430
216k
}
431
432
// Returns a context number for the given MB prediction signal
433
// Signal the first reference frame for a compound mode be GOLDEN,
434
// conditioning on that it is known either GOLDEN or LAST3.
435
104k
int av1_get_pred_context_comp_ref_p2(const MACROBLOCKD *xd) {
436
104k
  return get_pred_context_last3_or_gld(xd);
437
104k
}
438
439
// Signal the 2nd reference frame for a compound mode be either
440
// ALTREF, or ALTREF2/BWDREF.
441
321k
int av1_get_pred_context_comp_bwdref_p(const MACROBLOCKD *xd) {
442
321k
  return get_pred_context_brfarf2_or_arf(xd);
443
321k
}
444
445
// Signal the 2nd reference frame for a compound mode be either
446
// ALTREF2 or BWDREF.
447
146k
int av1_get_pred_context_comp_bwdref_p1(const MACROBLOCKD *xd) {
448
146k
  return get_pred_context_brf_or_arf2(xd);
449
146k
}
450
451
// == Context functions for single ref ==
452
//
453
// For the bit to signal whether the single reference is a forward reference
454
// frame or a backward reference frame.
455
3.07M
int av1_get_pred_context_single_ref_p1(const MACROBLOCKD *xd) {
456
3.07M
  const uint8_t *const ref_counts = &xd->neighbors_ref_counts[0];
457
458
  // Count of forward reference frames
459
3.07M
  const int fwd_count = ref_counts[LAST_FRAME] + ref_counts[LAST2_FRAME] +
460
3.07M
                        ref_counts[LAST3_FRAME] + ref_counts[GOLDEN_FRAME];
461
  // Count of backward reference frames
462
3.07M
  const int bwd_count = ref_counts[BWDREF_FRAME] + ref_counts[ALTREF2_FRAME] +
463
3.07M
                        ref_counts[ALTREF_FRAME];
464
465
3.07M
  const int pred_context =
466
3.07M
      (fwd_count == bwd_count) ? 1 : ((fwd_count < bwd_count) ? 0 : 2);
467
468
3.07M
  assert(pred_context >= 0 && pred_context < REF_CONTEXTS);
469
3.07M
  return pred_context;
470
3.07M
}
471
472
// For the bit to signal whether the single reference is ALTREF_FRAME or
473
// non-ALTREF backward reference frame, knowing that it shall be either of
474
// these 2 choices.
475
511k
int av1_get_pred_context_single_ref_p2(const MACROBLOCKD *xd) {
476
511k
  return get_pred_context_brfarf2_or_arf(xd);
477
511k
}
478
479
// For the bit to signal whether the single reference is LAST3/GOLDEN or
480
// LAST2/LAST, knowing that it shall be either of these 2 choices.
481
2.56M
int av1_get_pred_context_single_ref_p3(const MACROBLOCKD *xd) {
482
2.56M
  return get_pred_context_ll2_or_l3gld(xd);
483
2.56M
}
484
485
// For the bit to signal whether the single reference is LAST2_FRAME or
486
// LAST_FRAME, knowing that it shall be either of these 2 choices.
487
2.27M
int av1_get_pred_context_single_ref_p4(const MACROBLOCKD *xd) {
488
2.27M
  return get_pred_context_last_or_last2(xd);
489
2.27M
}
490
491
// For the bit to signal whether the single reference is GOLDEN_FRAME or
492
// LAST3_FRAME, knowing that it shall be either of these 2 choices.
493
289k
int av1_get_pred_context_single_ref_p5(const MACROBLOCKD *xd) {
494
289k
  return get_pred_context_last3_or_gld(xd);
495
289k
}
496
497
// For the bit to signal whether the single reference is ALTREF2_FRAME or
498
// BWDREF_FRAME, knowing that it shall be either of these 2 choices.
499
233k
int av1_get_pred_context_single_ref_p6(const MACROBLOCKD *xd) {
500
233k
  return get_pred_context_brf_or_arf2(xd);
501
233k
}