Coverage Report

Created: 2025-06-22 08:04

/src/aom/av1/encoder/gop_structure.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2019, 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 <stdint.h>
13
14
#include "av1/common/blockd.h"
15
#include "config/aom_config.h"
16
#include "config/aom_scale_rtcd.h"
17
18
#include "aom/aom_codec.h"
19
#include "aom/aom_encoder.h"
20
21
#include "av1/common/av1_common_int.h"
22
23
#include "av1/encoder/encoder.h"
24
#include "av1/encoder/firstpass.h"
25
#include "av1/encoder/gop_structure.h"
26
#include "av1/encoder/pass2_strategy.h"
27
28
// This function sets gf_group->frame_parallel_level for LF_UPDATE frames based
29
// on the value of parallel_frame_count.
30
static void set_frame_parallel_level(int *frame_parallel_level,
31
                                     int *parallel_frame_count,
32
0
                                     int max_parallel_frames) {
33
0
  assert(*parallel_frame_count > 0);
34
  // parallel_frame_count > 1 indicates subsequent frame(s) in the current
35
  // parallel encode set.
36
0
  *frame_parallel_level = 1 + (*parallel_frame_count > 1);
37
  // Update the count of no. of parallel frames.
38
0
  (*parallel_frame_count)++;
39
0
  if (*parallel_frame_count > max_parallel_frames) *parallel_frame_count = 1;
40
0
}
41
42
// This function sets gf_group->src_offset based on frame_parallel_level.
43
// Outputs are gf_group->src_offset and first_frame_index
44
static void set_src_offset(GF_GROUP *const gf_group, int *first_frame_index,
45
0
                           int cur_frame_idx, int frame_ind) {
46
0
  if (gf_group->frame_parallel_level[frame_ind] > 0) {
47
0
    if (gf_group->frame_parallel_level[frame_ind] == 1) {
48
0
      *first_frame_index = cur_frame_idx;
49
0
    }
50
51
    // Obtain the offset of the frame at frame_ind in the lookahead queue by
52
    // subtracting the display order hints of the current frame from the display
53
    // order hint of the first frame in parallel encoding set (at
54
    // first_frame_index).
55
0
    gf_group->src_offset[frame_ind] =
56
0
        (cur_frame_idx + gf_group->arf_src_offset[frame_ind]) -
57
0
        *first_frame_index;
58
0
  }
59
0
}
60
61
// Sets the GF_GROUP params for LF_UPDATE frames.
62
static inline void set_params_for_leaf_frames(
63
    const TWO_PASS *twopass, const TWO_PASS_FRAME *twopass_frame,
64
    const PRIMARY_RATE_CONTROL *p_rc, FRAME_INFO *frame_info,
65
    GF_GROUP *const gf_group, int *cur_frame_idx, int *frame_ind,
66
    int *parallel_frame_count, int max_parallel_frames,
67
    int do_frame_parallel_encode, int *first_frame_index, int *cur_disp_index,
68
0
    int layer_depth, int start, int end) {
69
0
  gf_group->update_type[*frame_ind] = LF_UPDATE;
70
0
  gf_group->arf_src_offset[*frame_ind] = 0;
71
0
  gf_group->cur_frame_idx[*frame_ind] = *cur_frame_idx;
72
0
  gf_group->layer_depth[*frame_ind] = MAX_ARF_LAYERS;
73
0
  gf_group->frame_type[*frame_ind] = INTER_FRAME;
74
0
  gf_group->refbuf_state[*frame_ind] = REFBUF_UPDATE;
75
0
  gf_group->max_layer_depth = AOMMAX(gf_group->max_layer_depth, layer_depth);
76
0
  gf_group->display_idx[*frame_ind] = (*cur_disp_index);
77
0
  gf_group->arf_boost[*frame_ind] =
78
0
      av1_calc_arf_boost(twopass, twopass_frame, p_rc, frame_info, start,
79
0
                         end - start, 0, NULL, NULL, 0);
80
0
  ++(*cur_disp_index);
81
82
  // Set the level of parallelism for the LF_UPDATE frame.
83
0
  if (do_frame_parallel_encode) {
84
0
    set_frame_parallel_level(&gf_group->frame_parallel_level[*frame_ind],
85
0
                             parallel_frame_count, max_parallel_frames);
86
    // Set LF_UPDATE frames as non-reference frames.
87
0
    gf_group->is_frame_non_ref[*frame_ind] = true;
88
0
  }
89
0
  set_src_offset(gf_group, first_frame_index, *cur_frame_idx, *frame_ind);
90
91
0
  ++(*frame_ind);
92
0
  ++(*cur_frame_idx);
93
0
}
94
95
// Sets the GF_GROUP params for INTNL_OVERLAY_UPDATE frames.
96
static inline void set_params_for_intnl_overlay_frames(
97
    GF_GROUP *const gf_group, int *cur_frame_idx, int *frame_ind,
98
0
    int *first_frame_index, int *cur_disp_index, int layer_depth) {
99
0
  gf_group->update_type[*frame_ind] = INTNL_OVERLAY_UPDATE;
100
0
  gf_group->arf_src_offset[*frame_ind] = 0;
101
0
  gf_group->cur_frame_idx[*frame_ind] = *cur_frame_idx;
102
0
  gf_group->layer_depth[*frame_ind] = layer_depth;
103
0
  gf_group->frame_type[*frame_ind] = INTER_FRAME;
104
0
  gf_group->refbuf_state[*frame_ind] = REFBUF_UPDATE;
105
0
  gf_group->display_idx[*frame_ind] = (*cur_disp_index);
106
0
  ++(*cur_disp_index);
107
108
0
  set_src_offset(gf_group, first_frame_index, *cur_frame_idx, *frame_ind);
109
0
  ++(*frame_ind);
110
0
  ++(*cur_frame_idx);
111
0
}
112
113
// Sets the GF_GROUP params for INTNL_ARF_UPDATE frames.
114
static inline void set_params_for_internal_arfs(
115
    const TWO_PASS *twopass, const TWO_PASS_FRAME *twopass_frame,
116
    const PRIMARY_RATE_CONTROL *p_rc, FRAME_INFO *frame_info,
117
    GF_GROUP *const gf_group, int *cur_frame_idx, int *frame_ind,
118
    int *parallel_frame_count, int max_parallel_frames,
119
    int do_frame_parallel_encode, int *first_frame_index, int depth_thr,
120
    int *cur_disp_idx, int layer_depth, int arf_src_offset, int offset,
121
0
    int f_frames, int b_frames) {
122
0
  gf_group->update_type[*frame_ind] = INTNL_ARF_UPDATE;
123
0
  gf_group->arf_src_offset[*frame_ind] = arf_src_offset;
124
0
  gf_group->cur_frame_idx[*frame_ind] = *cur_frame_idx;
125
0
  gf_group->layer_depth[*frame_ind] = layer_depth;
126
0
  gf_group->frame_type[*frame_ind] = INTER_FRAME;
127
0
  gf_group->refbuf_state[*frame_ind] = REFBUF_UPDATE;
128
0
  gf_group->display_idx[*frame_ind] =
129
0
      (*cur_disp_idx) + gf_group->arf_src_offset[*frame_ind];
130
0
  gf_group->arf_boost[*frame_ind] =
131
0
      av1_calc_arf_boost(twopass, twopass_frame, p_rc, frame_info, offset,
132
0
                         f_frames, b_frames, NULL, NULL, 0);
133
134
0
  if (do_frame_parallel_encode) {
135
0
    if (depth_thr != INT_MAX) {
136
0
      assert(depth_thr == 3 || depth_thr == 4);
137
0
      assert(IMPLIES(depth_thr == 3, layer_depth == 4));
138
0
      assert(IMPLIES(depth_thr == 4, layer_depth == 5));
139
      // Set frame_parallel_level of the first frame in the given layer to 1.
140
0
      if (gf_group->layer_depth[(*frame_ind) - 1] != layer_depth) {
141
0
        gf_group->frame_parallel_level[*frame_ind] = 1;
142
0
      } else {
143
        // Set frame_parallel_level of the consecutive frame in the same given
144
        // layer to 2.
145
0
        assert(gf_group->frame_parallel_level[(*frame_ind) - 1] == 1);
146
0
        gf_group->frame_parallel_level[*frame_ind] = 2;
147
        // Store the display order hints of the past 2 INTNL_ARF_UPDATE
148
        // frames which would not have been displayed at the time of the encode
149
        // of current frame.
150
0
        gf_group->skip_frame_refresh[*frame_ind][0] =
151
0
            gf_group->display_idx[(*frame_ind) - 1];
152
0
        gf_group->skip_frame_refresh[*frame_ind][1] =
153
0
            gf_group->display_idx[(*frame_ind) - 2];
154
        // Set the display_idx of frame_parallel_level 1 frame in
155
        // gf_group->skip_frame_as_ref.
156
0
        gf_group->skip_frame_as_ref[*frame_ind] =
157
0
            gf_group->display_idx[(*frame_ind) - 1];
158
0
      }
159
0
    }
160
    // If max_parallel_frames is not exceeded and if the frame will not be
161
    // temporally filtered, encode the next internal ARF frame in parallel.
162
0
    if (*parallel_frame_count > 1 &&
163
0
        *parallel_frame_count <= max_parallel_frames) {
164
0
      if (gf_group->arf_src_offset[*frame_ind] < TF_LOOKAHEAD_IDX_THR)
165
0
        gf_group->frame_parallel_level[*frame_ind] = 2;
166
0
      *parallel_frame_count = 1;
167
0
    }
168
0
  }
169
0
  set_src_offset(gf_group, first_frame_index, *cur_frame_idx, *frame_ind);
170
0
  ++(*frame_ind);
171
0
}
172
173
// Set parameters for frames between 'start' and 'end' (excluding both).
174
static void set_multi_layer_params_for_fp(
175
    const TWO_PASS *twopass, const TWO_PASS_FRAME *twopass_frame,
176
    GF_GROUP *const gf_group, const PRIMARY_RATE_CONTROL *p_rc,
177
    RATE_CONTROL *rc, FRAME_INFO *frame_info, int start, int end,
178
    int *cur_frame_idx, int *frame_ind, int *parallel_frame_count,
179
    int max_parallel_frames, int do_frame_parallel_encode,
180
0
    int *first_frame_index, int depth_thr, int *cur_disp_idx, int layer_depth) {
181
0
  const int num_frames_to_process = end - start;
182
183
  // Either we are at the last level of the pyramid, or we don't have enough
184
  // frames between 'l' and 'r' to create one more level.
185
0
  if (layer_depth > gf_group->max_layer_depth_allowed ||
186
0
      num_frames_to_process < 3) {
187
    // Leaf nodes.
188
0
    while (start < end) {
189
0
      set_params_for_leaf_frames(twopass, twopass_frame, p_rc, frame_info,
190
0
                                 gf_group, cur_frame_idx, frame_ind,
191
0
                                 parallel_frame_count, max_parallel_frames,
192
0
                                 do_frame_parallel_encode, first_frame_index,
193
0
                                 cur_disp_idx, layer_depth, start, end);
194
0
      ++start;
195
0
    }
196
0
  } else {
197
0
    const int m = (start + end - 1) / 2;
198
199
    // Internal ARF.
200
0
    int arf_src_offset = m - start;
201
0
    set_params_for_internal_arfs(
202
0
        twopass, twopass_frame, p_rc, frame_info, gf_group, cur_frame_idx,
203
0
        frame_ind, parallel_frame_count, max_parallel_frames,
204
0
        do_frame_parallel_encode, first_frame_index, INT_MAX, cur_disp_idx,
205
0
        layer_depth, arf_src_offset, m, end - m, m - start);
206
207
    // If encode reordering is enabled, configure the multi-layers accordingly
208
    // and return. For e.g., the encode order for gf-interval 16 after
209
    // reordering would be 0-> 16-> 8-> 4-> 2-> 6-> 1-> 3-> 5-> 7-> 12-> 10->
210
    // 14-> 9-> 11-> 13-> 15.
211
0
    if (layer_depth >= depth_thr) {
212
0
      int m1 = (m + start - 1) / 2;
213
0
      int m2 = (m + 1 + end) / 2;
214
0
      int arf_src_offsets[2] = { m1 - start, m2 - start };
215
      // Parameters to compute arf_boost.
216
0
      int offset[2] = { m1, m2 };
217
0
      int f_frames[2] = { m - m1, end - m2 };
218
0
      int b_frames[2] = { m1 - start, m2 - (m + 1) };
219
220
      // Set GF_GROUP params for INTNL_ARF_UPDATE frames which are reordered.
221
0
      for (int i = 0; i < 2; i++) {
222
0
        set_params_for_internal_arfs(
223
0
            twopass, twopass_frame, p_rc, frame_info, gf_group, cur_frame_idx,
224
0
            frame_ind, parallel_frame_count, max_parallel_frames,
225
0
            do_frame_parallel_encode, first_frame_index, depth_thr,
226
0
            cur_disp_idx, layer_depth + 1, arf_src_offsets[i], offset[i],
227
0
            f_frames[i], b_frames[i]);
228
0
      }
229
230
      // Initialize the start and end indices to configure LF_UPDATE frames.
231
0
      int start_idx[4] = { start, m1 + 1, m + 1, end - 1 };
232
0
      int end_idx[4] = { m1, m, m2, end };
233
0
      int layer_depth_for_intnl_overlay[4] = { layer_depth + 1, layer_depth,
234
0
                                               layer_depth + 1, INVALID_IDX };
235
236
      // Set GF_GROUP params for the rest of LF_UPDATE and INTNL_OVERLAY_UPDATE
237
      // frames after reordering.
238
0
      for (int i = 0; i < 4; i++) {
239
0
        set_multi_layer_params_for_fp(
240
0
            twopass, twopass_frame, gf_group, p_rc, rc, frame_info,
241
0
            start_idx[i], end_idx[i], cur_frame_idx, frame_ind,
242
0
            parallel_frame_count, max_parallel_frames, do_frame_parallel_encode,
243
0
            first_frame_index, depth_thr, cur_disp_idx, layer_depth + 2);
244
0
        if (layer_depth_for_intnl_overlay[i] != INVALID_IDX)
245
0
          set_params_for_intnl_overlay_frames(
246
0
              gf_group, cur_frame_idx, frame_ind, first_frame_index,
247
0
              cur_disp_idx, layer_depth_for_intnl_overlay[i]);
248
0
      }
249
0
      return;
250
0
    }
251
252
    // Frames displayed before this internal ARF.
253
0
    set_multi_layer_params_for_fp(
254
0
        twopass, twopass_frame, gf_group, p_rc, rc, frame_info, start, m,
255
0
        cur_frame_idx, frame_ind, parallel_frame_count, max_parallel_frames,
256
0
        do_frame_parallel_encode, first_frame_index, depth_thr, cur_disp_idx,
257
0
        layer_depth + 1);
258
259
    // Overlay for internal ARF.
260
0
    set_params_for_intnl_overlay_frames(gf_group, cur_frame_idx, frame_ind,
261
0
                                        first_frame_index, cur_disp_idx,
262
0
                                        layer_depth);
263
264
    // Frames displayed after this internal ARF.
265
0
    set_multi_layer_params_for_fp(
266
0
        twopass, twopass_frame, gf_group, p_rc, rc, frame_info, m + 1, end,
267
0
        cur_frame_idx, frame_ind, parallel_frame_count, max_parallel_frames,
268
0
        do_frame_parallel_encode, first_frame_index, depth_thr, cur_disp_idx,
269
0
        layer_depth + 1);
270
0
  }
271
0
}
272
273
// Structure for bookkeeping start, end and display indices to configure
274
// INTNL_ARF_UPDATE frames.
275
typedef struct {
276
  int start;
277
  int end;
278
  int display_index;
279
} FRAME_REORDER_INFO;
280
281
// Updates the stats required to configure the GF_GROUP.
282
static inline void fill_arf_frame_stats(FRAME_REORDER_INFO *arf_frame_stats,
283
                                        int arf_frame_index, int display_idx,
284
0
                                        int start, int end) {
285
0
  arf_frame_stats[arf_frame_index].start = start;
286
0
  arf_frame_stats[arf_frame_index].end = end;
287
0
  arf_frame_stats[arf_frame_index].display_index = display_idx;
288
0
}
289
290
// Sets GF_GROUP params for INTNL_ARF_UPDATE frames. Also populates
291
// doh_gf_index_map and arf_frame_stats.
292
static inline void set_params_for_internal_arfs_in_gf14(
293
    GF_GROUP *const gf_group, FRAME_REORDER_INFO *arf_frame_stats,
294
    int *cur_frame_idx, int *cur_disp_idx, int *frame_ind,
295
    int *count_arf_frames, int *doh_gf_index_map, int start, int end,
296
0
    int layer_depth, int layer_with_parallel_encodes) {
297
0
  int index = (start + end - 1) / 2;
298
0
  gf_group->update_type[*frame_ind] = INTNL_ARF_UPDATE;
299
0
  gf_group->arf_src_offset[*frame_ind] = index - 1;
300
0
  gf_group->cur_frame_idx[*frame_ind] = *cur_frame_idx;
301
0
  gf_group->layer_depth[*frame_ind] = layer_depth;
302
0
  gf_group->frame_type[*frame_ind] = INTER_FRAME;
303
0
  gf_group->refbuf_state[*frame_ind] = REFBUF_UPDATE;
304
0
  gf_group->display_idx[*frame_ind] =
305
0
      (*cur_disp_idx) + gf_group->arf_src_offset[*frame_ind];
306
307
  // Update the display index of the current frame with its gf index.
308
0
  doh_gf_index_map[index] = *frame_ind;
309
0
  if (layer_with_parallel_encodes) {
310
0
    assert(layer_depth == 4);
311
    // Set frame_parallel_level of the first frame in the given layer depth
312
    // to 1.
313
0
    if (gf_group->layer_depth[(*frame_ind) - 1] != layer_depth) {
314
0
      gf_group->frame_parallel_level[*frame_ind] = 1;
315
0
    } else {
316
      // Set frame_parallel_level of the consecutive frame in the same given
317
      // layer depth to 2.
318
0
      assert(gf_group->frame_parallel_level[(*frame_ind) - 1] == 1);
319
0
      gf_group->frame_parallel_level[*frame_ind] = 2;
320
      // Set the display_idx of frame_parallel_level 1 frame in
321
      // gf_group->skip_frame_as_ref.
322
0
      gf_group->skip_frame_as_ref[*frame_ind] =
323
0
          gf_group->display_idx[(*frame_ind) - 1];
324
0
    }
325
0
  }
326
0
  ++(*frame_ind);
327
328
  // Update arf_frame_stats.
329
0
  fill_arf_frame_stats(arf_frame_stats, *count_arf_frames, index, start, end);
330
0
  ++(*count_arf_frames);
331
0
}
332
333
// Sets GF_GROUP params for all INTNL_ARF_UPDATE frames in the given layer
334
// dpeth.
335
static inline void set_params_for_cur_layer_frames(
336
    GF_GROUP *const gf_group, FRAME_REORDER_INFO *arf_frame_stats,
337
    int *cur_frame_idx, int *cur_disp_idx, int *frame_ind,
338
    int *count_arf_frames, int *doh_gf_index_map, int num_dir, int node_start,
339
0
    int node_end, int layer_depth) {
340
0
  assert(num_dir < 3);
341
0
  int start, end;
342
  // Iterate through the nodes in the previous layer depth.
343
0
  for (int i = node_start; i < node_end; i++) {
344
    // For each node, check if a frame can be coded as INTNL_ARF_UPDATE frame on
345
    // either direction.
346
0
    for (int dir = 0; dir < num_dir; dir++) {
347
      // Checks for a frame to the left of current node.
348
0
      if (dir == 0) {
349
0
        start = arf_frame_stats[i].start;
350
0
        end = arf_frame_stats[i].display_index;
351
0
      } else {
352
        // Checks for a frame to the right of current node.
353
0
        start = arf_frame_stats[i].display_index + 1;
354
0
        end = arf_frame_stats[i].end;
355
0
      }
356
0
      const int num_frames_to_process = end - start;
357
      // Checks if a frame can be coded as INTNL_ARF_UPDATE frame. If
358
      // num_frames_to_process is less than 3, then there are not enough frames
359
      // between 'start' and 'end' to create another level.
360
0
      if (num_frames_to_process >= 3) {
361
        // Flag to indicate the lower layer depths for which parallel encoding
362
        // is enabled. Currently enabled for layer 4 frames.
363
0
        int layer_with_parallel_encodes = layer_depth == 4;
364
0
        set_params_for_internal_arfs_in_gf14(
365
0
            gf_group, arf_frame_stats, cur_frame_idx, cur_disp_idx, frame_ind,
366
0
            count_arf_frames, doh_gf_index_map, start, end, layer_depth,
367
0
            layer_with_parallel_encodes);
368
0
      }
369
0
    }
370
0
  }
371
0
}
372
373
// Configures multi-layers of the GF_GROUP when consecutive encode of frames in
374
// the same layer depth is enbaled.
375
static inline void set_multi_layer_params_for_gf14(
376
    const TWO_PASS *twopass, const TWO_PASS_FRAME *twopass_frame,
377
    const PRIMARY_RATE_CONTROL *p_rc, FRAME_INFO *frame_info,
378
    GF_GROUP *const gf_group, FRAME_REORDER_INFO *arf_frame_stats,
379
    int *cur_frame_idx, int *frame_ind, int *count_arf_frames,
380
    int *doh_gf_index_map, int *parallel_frame_count, int *first_frame_index,
381
    int *cur_disp_index, int gf_interval, int layer_depth,
382
0
    int max_parallel_frames) {
383
0
  assert(layer_depth == 2);
384
0
  assert(gf_group->max_layer_depth_allowed >= 4);
385
0
  int layer, node_start, node_end = 0;
386
  // Maximum layer depth excluding LF_UPDATE frames is 4 since applicable only
387
  // for gf-interval 14.
388
0
  const int max_layer_depth = 4;
389
  // Iterate through each layer depth starting from 2 till 'max_layer_depth'.
390
0
  for (layer = layer_depth; layer <= max_layer_depth; layer++) {
391
    // 'node_start' and 'node_end' indicate the number of nodes from the
392
    // previous layer depth to be considered. It also corresponds to the indices
393
    // of arf_frame_stats.
394
0
    node_start = node_end;
395
0
    node_end = (*count_arf_frames);
396
    // 'num_dir' indicates the number of directions to traverse w.r.t. a given
397
    // node in order to choose an INTNL_ARF_UPDATE frame. Layer depth 2 would
398
    // have only one frame and hence needs to traverse only in the left
399
    // direction w.r.t the node in the previous layer.
400
0
    int num_dir = layer == 2 ? 1 : 2;
401
0
    set_params_for_cur_layer_frames(gf_group, arf_frame_stats, cur_frame_idx,
402
0
                                    cur_disp_index, frame_ind, count_arf_frames,
403
0
                                    doh_gf_index_map, num_dir, node_start,
404
0
                                    node_end, layer);
405
0
  }
406
407
0
  for (int i = 1; i < gf_interval; i++) {
408
    // Since doh_gf_index_map is already populated for all INTNL_ARF_UPDATE
409
    // frames in the GF_GROUP, any frame with INVALID_IDX would correspond to an
410
    // LF_UPDATE frame.
411
0
    if (doh_gf_index_map[i] == INVALID_IDX) {
412
      // LF_UPDATE frames.
413
      // TODO(Remya): Correct start and end parameters passed to
414
      // set_params_for_leaf_frames() once encode reordering for gf-interval 14
415
      // is enbaled for parallel encode of lower layer frames.
416
0
      set_params_for_leaf_frames(
417
0
          twopass, twopass_frame, p_rc, frame_info, gf_group, cur_frame_idx,
418
0
          frame_ind, parallel_frame_count, max_parallel_frames, 1,
419
0
          first_frame_index, cur_disp_index, layer, 0, 0);
420
0
    } else {
421
      // In order to obtain the layer depths of INTNL_OVERLAY_UPDATE frames, get
422
      // the gf index of corresponding INTNL_ARF_UPDATE frames.
423
0
      int intnl_arf_index = doh_gf_index_map[i];
424
0
      int ld = gf_group->layer_depth[intnl_arf_index];
425
0
      set_params_for_intnl_overlay_frames(gf_group, cur_frame_idx, frame_ind,
426
0
                                          first_frame_index, cur_disp_index,
427
0
                                          ld);
428
0
    }
429
0
  }
430
0
}
431
432
// Set parameters for frames between 'start' and 'end' (excluding both).
433
static void set_multi_layer_params(
434
    const TWO_PASS *twopass, const TWO_PASS_FRAME *twopass_frame,
435
    GF_GROUP *const gf_group, const PRIMARY_RATE_CONTROL *p_rc,
436
    RATE_CONTROL *rc, FRAME_INFO *frame_info, int start, int end,
437
    int *cur_frame_idx, int *frame_ind, int *parallel_frame_count,
438
    int max_parallel_frames, int do_frame_parallel_encode,
439
0
    int *first_frame_index, int *cur_disp_idx, int layer_depth) {
440
0
  const int num_frames_to_process = end - start;
441
442
  // Either we are at the last level of the pyramid, or we don't have enough
443
  // frames between 'l' and 'r' to create one more level.
444
0
  if (layer_depth > gf_group->max_layer_depth_allowed ||
445
0
      num_frames_to_process < 3) {
446
    // Leaf nodes.
447
0
    while (start < end) {
448
0
      gf_group->update_type[*frame_ind] = LF_UPDATE;
449
0
      gf_group->arf_src_offset[*frame_ind] = 0;
450
0
      gf_group->cur_frame_idx[*frame_ind] = *cur_frame_idx;
451
0
      gf_group->display_idx[*frame_ind] = *cur_disp_idx;
452
0
      gf_group->layer_depth[*frame_ind] = MAX_ARF_LAYERS;
453
0
      gf_group->arf_boost[*frame_ind] =
454
0
          av1_calc_arf_boost(twopass, twopass_frame, p_rc, frame_info, start,
455
0
                             end - start, 0, NULL, NULL, 0);
456
0
      gf_group->frame_type[*frame_ind] = INTER_FRAME;
457
0
      gf_group->refbuf_state[*frame_ind] = REFBUF_UPDATE;
458
0
      gf_group->max_layer_depth =
459
0
          AOMMAX(gf_group->max_layer_depth, layer_depth);
460
      // Set the level of parallelism for the LF_UPDATE frame.
461
0
      if (do_frame_parallel_encode) {
462
0
        set_frame_parallel_level(&gf_group->frame_parallel_level[*frame_ind],
463
0
                                 parallel_frame_count, max_parallel_frames);
464
        // Set LF_UPDATE frames as non-reference frames.
465
0
        gf_group->is_frame_non_ref[*frame_ind] = true;
466
0
      }
467
0
      set_src_offset(gf_group, first_frame_index, *cur_frame_idx, *frame_ind);
468
0
      ++(*frame_ind);
469
0
      ++(*cur_frame_idx);
470
0
      ++(*cur_disp_idx);
471
0
      ++start;
472
0
    }
473
0
  } else {
474
0
    const int m = (start + end - 1) / 2;
475
476
    // Internal ARF.
477
0
    gf_group->update_type[*frame_ind] = INTNL_ARF_UPDATE;
478
0
    gf_group->arf_src_offset[*frame_ind] = m - start;
479
0
    gf_group->cur_frame_idx[*frame_ind] = *cur_frame_idx;
480
0
    gf_group->display_idx[*frame_ind] =
481
0
        *cur_disp_idx + gf_group->arf_src_offset[*frame_ind];
482
0
    gf_group->layer_depth[*frame_ind] = layer_depth;
483
0
    gf_group->frame_type[*frame_ind] = INTER_FRAME;
484
0
    gf_group->refbuf_state[*frame_ind] = REFBUF_UPDATE;
485
486
0
    if (do_frame_parallel_encode) {
487
      // If max_parallel_frames is not exceeded and if the frame will not be
488
      // temporally filtered, encode the next internal ARF frame in parallel.
489
0
      if (*parallel_frame_count > 1 &&
490
0
          *parallel_frame_count <= max_parallel_frames) {
491
0
        if (gf_group->arf_src_offset[*frame_ind] < TF_LOOKAHEAD_IDX_THR)
492
0
          gf_group->frame_parallel_level[*frame_ind] = 2;
493
0
        *parallel_frame_count = 1;
494
0
      }
495
0
    }
496
0
    set_src_offset(gf_group, first_frame_index, *cur_frame_idx, *frame_ind);
497
498
    // Get the boost factor for intermediate ARF frames.
499
0
    gf_group->arf_boost[*frame_ind] =
500
0
        av1_calc_arf_boost(twopass, twopass_frame, p_rc, frame_info, m, end - m,
501
0
                           m - start, NULL, NULL, 0);
502
0
    ++(*frame_ind);
503
504
    // Frames displayed before this internal ARF.
505
0
    set_multi_layer_params(twopass, twopass_frame, gf_group, p_rc, rc,
506
0
                           frame_info, start, m, cur_frame_idx, frame_ind,
507
0
                           parallel_frame_count, max_parallel_frames,
508
0
                           do_frame_parallel_encode, first_frame_index,
509
0
                           cur_disp_idx, layer_depth + 1);
510
511
    // Overlay for internal ARF.
512
0
    gf_group->update_type[*frame_ind] = INTNL_OVERLAY_UPDATE;
513
0
    gf_group->arf_src_offset[*frame_ind] = 0;
514
0
    gf_group->cur_frame_idx[*frame_ind] = *cur_frame_idx;
515
0
    gf_group->display_idx[*frame_ind] = *cur_disp_idx;
516
0
    gf_group->arf_boost[*frame_ind] = 0;
517
0
    gf_group->layer_depth[*frame_ind] = layer_depth;
518
0
    gf_group->frame_type[*frame_ind] = INTER_FRAME;
519
0
    gf_group->refbuf_state[*frame_ind] = REFBUF_UPDATE;
520
521
0
    set_src_offset(gf_group, first_frame_index, *cur_frame_idx, *frame_ind);
522
0
    ++(*frame_ind);
523
0
    ++(*cur_frame_idx);
524
0
    ++(*cur_disp_idx);
525
526
    // Frames displayed after this internal ARF.
527
0
    set_multi_layer_params(twopass, twopass_frame, gf_group, p_rc, rc,
528
0
                           frame_info, m + 1, end, cur_frame_idx, frame_ind,
529
0
                           parallel_frame_count, max_parallel_frames,
530
0
                           do_frame_parallel_encode, first_frame_index,
531
0
                           cur_disp_idx, layer_depth + 1);
532
0
  }
533
0
}
534
535
static int construct_multi_layer_gf_structure(
536
    AV1_COMP *cpi, TWO_PASS *twopass, GF_GROUP *const gf_group,
537
    RATE_CONTROL *rc, FRAME_INFO *const frame_info, int baseline_gf_interval,
538
0
    FRAME_UPDATE_TYPE first_frame_update_type) {
539
0
  PRIMARY_RATE_CONTROL *const p_rc = &cpi->ppi->p_rc;
540
  // TODO(angiebird): Why do we need "-1" here?
541
0
  const int gf_interval = baseline_gf_interval - 1;
542
0
  int frame_index = 0;
543
0
  int cur_frame_index = 0;
544
545
  // Set the display order hint for the first frame in the GF_GROUP.
546
0
  int cur_disp_index = (first_frame_update_type == KF_UPDATE)
547
0
                           ? 0
548
0
                           : cpi->common.current_frame.frame_number;
549
550
  // Initialize gf_group->frame_parallel_level, gf_group->is_frame_non_ref,
551
  // gf_group->src_offset and gf_group->is_frame_dropped with 0.
552
0
  memset(gf_group->frame_parallel_level, 0,
553
0
         sizeof(gf_group->frame_parallel_level));
554
0
  memset(gf_group->is_frame_non_ref, 0, sizeof(gf_group->is_frame_non_ref));
555
0
  memset(gf_group->src_offset, 0, sizeof(gf_group->src_offset));
556
0
  memset(gf_group->is_frame_dropped, 0, sizeof(gf_group->is_frame_dropped));
557
  // Initialize gf_group->skip_frame_refresh and gf_group->skip_frame_as_ref
558
  // with INVALID_IDX.
559
0
  memset(gf_group->skip_frame_refresh, INVALID_IDX,
560
0
         sizeof(gf_group->skip_frame_refresh));
561
0
  memset(gf_group->skip_frame_as_ref, INVALID_IDX,
562
0
         sizeof(gf_group->skip_frame_as_ref));
563
564
0
  int kf_decomp = cpi->oxcf.kf_cfg.enable_keyframe_filtering > 1;
565
  // This is a patch that fixes https://crbug.com/aomedia/3163
566
  // enable_keyframe_filtering > 1 will introduce an extra overlay frame at
567
  // key frame location. However when
568
  // baseline_gf_interval == MAX_STATIC_GF_GROUP_LENGTH, we can't
569
  // afford to have an extra overlay frame. Otherwise, the gf_group->size will
570
  // become MAX_STATIC_GF_GROUP_LENGTH + 1, which causes memory error.
571
  // A cheap solution is to turn of kf_decomp here.
572
  // TODO(angiebird): Find a systematic way to solve this issue.
573
0
  if (baseline_gf_interval == MAX_STATIC_GF_GROUP_LENGTH) {
574
0
    kf_decomp = 0;
575
0
  }
576
0
  if (first_frame_update_type == KF_UPDATE) {
577
0
    gf_group->update_type[frame_index] = kf_decomp ? ARF_UPDATE : KF_UPDATE;
578
0
    gf_group->arf_src_offset[frame_index] = 0;
579
0
    gf_group->cur_frame_idx[frame_index] = cur_frame_index;
580
0
    gf_group->layer_depth[frame_index] = 0;
581
0
    gf_group->frame_type[frame_index] = KEY_FRAME;
582
0
    gf_group->refbuf_state[frame_index] = REFBUF_RESET;
583
0
    gf_group->max_layer_depth = 0;
584
0
    gf_group->display_idx[frame_index] = cur_disp_index;
585
0
    if (!kf_decomp) cur_disp_index++;
586
0
    ++frame_index;
587
588
0
    if (kf_decomp) {
589
0
      gf_group->update_type[frame_index] = OVERLAY_UPDATE;
590
0
      gf_group->arf_src_offset[frame_index] = 0;
591
0
      gf_group->cur_frame_idx[frame_index] = cur_frame_index;
592
0
      gf_group->layer_depth[frame_index] = 0;
593
0
      gf_group->frame_type[frame_index] = INTER_FRAME;
594
0
      gf_group->refbuf_state[frame_index] = REFBUF_UPDATE;
595
0
      gf_group->max_layer_depth = 0;
596
0
      gf_group->display_idx[frame_index] = cur_disp_index;
597
0
      cur_disp_index++;
598
0
      ++frame_index;
599
0
    }
600
0
    cur_frame_index++;
601
0
  }
602
603
0
  if (first_frame_update_type == GF_UPDATE) {
604
0
    gf_group->update_type[frame_index] = GF_UPDATE;
605
0
    gf_group->arf_src_offset[frame_index] = 0;
606
0
    gf_group->cur_frame_idx[frame_index] = cur_frame_index;
607
0
    gf_group->layer_depth[frame_index] = 0;
608
0
    gf_group->frame_type[frame_index] = INTER_FRAME;
609
0
    gf_group->refbuf_state[frame_index] = REFBUF_UPDATE;
610
0
    gf_group->max_layer_depth = 0;
611
0
    gf_group->display_idx[frame_index] = cur_disp_index;
612
0
    cur_disp_index++;
613
0
    ++frame_index;
614
0
    ++cur_frame_index;
615
0
  }
616
617
  // ALTREF.
618
0
  const int use_altref = gf_group->max_layer_depth_allowed > 0;
619
0
  int is_fwd_kf = rc->frames_to_fwd_kf == gf_interval;
620
621
0
  if (use_altref) {
622
0
    gf_group->update_type[frame_index] = ARF_UPDATE;
623
0
    gf_group->arf_src_offset[frame_index] = gf_interval - cur_frame_index;
624
0
    gf_group->cur_frame_idx[frame_index] = cur_frame_index;
625
0
    gf_group->layer_depth[frame_index] = 1;
626
0
    gf_group->arf_boost[frame_index] = cpi->ppi->p_rc.gfu_boost;
627
0
    gf_group->frame_type[frame_index] = is_fwd_kf ? KEY_FRAME : INTER_FRAME;
628
0
    gf_group->refbuf_state[frame_index] = REFBUF_UPDATE;
629
0
    gf_group->max_layer_depth = 1;
630
0
    gf_group->arf_index = frame_index;
631
0
    gf_group->display_idx[frame_index] =
632
0
        cur_disp_index + gf_group->arf_src_offset[frame_index];
633
0
    ++frame_index;
634
0
  } else {
635
0
    gf_group->arf_index = -1;
636
0
  }
637
638
  // Flag to indicate if multi-layer configuration is complete.
639
0
  int is_multi_layer_configured = 0;
640
641
  // Running count of no. of frames that is part of a given parallel
642
  // encode set in a gf_group. Value of 1 indicates no parallel encode.
643
0
  int parallel_frame_count = 1;
644
  // Enable parallel encode of frames if gf_group has a multi-layer pyramid
645
  // structure with minimum 4 layers.
646
0
  int do_frame_parallel_encode = (cpi->ppi->num_fp_contexts > 1 && use_altref &&
647
0
                                  gf_group->max_layer_depth_allowed >= 4);
648
649
0
  int first_frame_index = cur_frame_index;
650
0
  if (do_frame_parallel_encode) {
651
    // construct_multi_layer_gf_structure() takes the input parameter
652
    // 'gf_interval' as p_rc->baseline_gf_interval - 1 . Below code computes the
653
    // actual GF_GROUP length by compensating for this offset.
654
0
    int actual_gf_length = ((first_frame_update_type == KF_UPDATE) ||
655
0
                            (first_frame_update_type == GF_UPDATE))
656
0
                               ? gf_interval
657
0
                               : gf_interval + 1;
658
659
    // In order to facilitate parallel encoding of frames in lower layer depths,
660
    // encode reordering is done. Currently encode reordering is enabled only
661
    // for gf-intervals 16 and 32. NOTE: Since the buffer holding the
662
    // reference frames is of size 8 (ref_frame_map[REF_FRAMES]), there is a
663
    // limitation on the number of hidden frames possible at any given point and
664
    // hence the reordering is enabled only for gf-intervals 16 and 32.
665
    // Disabling encode reordering for gf-interval 14 since some cross-frame
666
    // dependencies related to temporal filtering for FPMT is currently not
667
    // handled.
668
0
    int disable_gf14_reorder = 1;
669
0
    if (actual_gf_length == 14 && !disable_gf14_reorder) {
670
      // This array holds the gf index of INTNL_ARF_UPDATE frames in the slot
671
      // corresponding to their display order hint. This is used while
672
      // configuring the LF_UPDATE frames and INTNL_OVERLAY_UPDATE frames.
673
0
      int doh_gf_index_map[FIXED_GF_INTERVAL];
674
      // Initialize doh_gf_index_map with INVALID_IDX.
675
0
      memset(&doh_gf_index_map[0], INVALID_IDX,
676
0
             (sizeof(doh_gf_index_map[0]) * FIXED_GF_INTERVAL));
677
678
0
      FRAME_REORDER_INFO arf_frame_stats[REF_FRAMES - 1];
679
      // Store the stats corresponding to layer 1 frame.
680
0
      fill_arf_frame_stats(arf_frame_stats, 0, actual_gf_length, 1,
681
0
                           actual_gf_length);
682
0
      int count_arf_frames = 1;
683
684
      // Sets multi-layer params for gf-interval 14 to consecutively encode
685
      // frames in the same layer depth, i.e., encode order would be 0-> 14->
686
      // 7-> 3-> 10-> 5-> 12-> 1-> 2-> 4-> 6-> 8-> 9-> 11-> 13.
687
      // TODO(Remya): Set GF_GROUP param 'arf_boost' for all frames.
688
0
      set_multi_layer_params_for_gf14(
689
0
          twopass, &cpi->twopass_frame, p_rc, frame_info, gf_group,
690
0
          arf_frame_stats, &cur_frame_index, &frame_index, &count_arf_frames,
691
0
          doh_gf_index_map, &parallel_frame_count, &first_frame_index,
692
0
          &cur_disp_index, actual_gf_length, use_altref + 1,
693
0
          cpi->ppi->num_fp_contexts);
694
695
      // Set gf_group->skip_frame_refresh.
696
0
      for (int i = 0; i < actual_gf_length; i++) {
697
0
        int count = 0;
698
0
        if (gf_group->update_type[i] == INTNL_ARF_UPDATE) {
699
0
          for (int j = 0; j < i; j++) {
700
            // Store the display order hint of the frames which would not
701
            // have been displayed at the encode call of frame 'i'.
702
0
            if ((gf_group->display_idx[j] < gf_group->display_idx[i]) &&
703
0
                gf_group->update_type[j] == INTNL_ARF_UPDATE) {
704
0
              gf_group->skip_frame_refresh[i][count++] =
705
0
                  gf_group->display_idx[j];
706
0
            }
707
0
          }
708
0
        }
709
0
      }
710
0
    } else {
711
      // Set layer depth threshold for reordering as per the gf length.
712
0
      int depth_thr = (actual_gf_length == 16)   ? 3
713
0
                      : (actual_gf_length == 32) ? 4
714
0
                                                 : INT_MAX;
715
716
0
      set_multi_layer_params_for_fp(
717
0
          twopass, &cpi->twopass_frame, gf_group, p_rc, rc, frame_info,
718
0
          cur_frame_index, gf_interval, &cur_frame_index, &frame_index,
719
0
          &parallel_frame_count, cpi->ppi->num_fp_contexts,
720
0
          do_frame_parallel_encode, &first_frame_index, depth_thr,
721
0
          &cur_disp_index, use_altref + 1);
722
0
    }
723
0
    is_multi_layer_configured = 1;
724
0
  }
725
726
  // Rest of the frames.
727
0
  if (!is_multi_layer_configured)
728
0
    set_multi_layer_params(twopass, &cpi->twopass_frame, gf_group, p_rc, rc,
729
0
                           frame_info, cur_frame_index, gf_interval,
730
0
                           &cur_frame_index, &frame_index,
731
0
                           &parallel_frame_count, cpi->ppi->num_fp_contexts,
732
0
                           do_frame_parallel_encode, &first_frame_index,
733
0
                           &cur_disp_index, use_altref + 1);
734
735
0
  if (use_altref) {
736
0
    gf_group->update_type[frame_index] = OVERLAY_UPDATE;
737
0
    gf_group->arf_src_offset[frame_index] = 0;
738
0
    gf_group->cur_frame_idx[frame_index] = cur_frame_index;
739
0
    gf_group->layer_depth[frame_index] = MAX_ARF_LAYERS;
740
0
    gf_group->arf_boost[frame_index] = NORMAL_BOOST;
741
0
    gf_group->frame_type[frame_index] = INTER_FRAME;
742
0
    gf_group->refbuf_state[frame_index] =
743
0
        is_fwd_kf ? REFBUF_RESET : REFBUF_UPDATE;
744
0
    gf_group->display_idx[frame_index] = cur_disp_index;
745
0
    ++frame_index;
746
0
  } else {
747
0
    for (; cur_frame_index <= gf_interval; ++cur_frame_index) {
748
0
      gf_group->update_type[frame_index] = LF_UPDATE;
749
0
      gf_group->arf_src_offset[frame_index] = 0;
750
0
      gf_group->cur_frame_idx[frame_index] = cur_frame_index;
751
0
      gf_group->layer_depth[frame_index] = MAX_ARF_LAYERS;
752
0
      gf_group->arf_boost[frame_index] = NORMAL_BOOST;
753
0
      gf_group->frame_type[frame_index] = INTER_FRAME;
754
0
      gf_group->refbuf_state[frame_index] = REFBUF_UPDATE;
755
0
      gf_group->max_layer_depth = AOMMAX(gf_group->max_layer_depth, 2);
756
0
      set_src_offset(gf_group, &first_frame_index, cur_frame_index,
757
0
                     frame_index);
758
0
      gf_group->display_idx[frame_index] = cur_disp_index;
759
0
      cur_disp_index++;
760
0
      ++frame_index;
761
0
    }
762
0
  }
763
0
  if (do_frame_parallel_encode) {
764
    // Iterate through the gf_group and reset frame_parallel_level to 0 in case
765
    // a frame is marked as frame_parallel_level 1 with no subsequent
766
    // frame_parallel_level 2 frame(s).
767
0
    int level1_frame_idx = INT_MAX;
768
0
    int level2_frame_count = 0;
769
0
    for (int frame_idx = 0; frame_idx < frame_index; frame_idx++) {
770
0
      if (gf_group->frame_parallel_level[frame_idx] == 1) {
771
        // Set frame_parallel_level to 0 if only one frame is present in a
772
        // parallel encode set.
773
0
        if (level1_frame_idx != INT_MAX && !level2_frame_count)
774
0
          gf_group->frame_parallel_level[level1_frame_idx] = 0;
775
        // Book-keep frame_idx of frame_parallel_level 1 frame and reset the
776
        // count of frame_parallel_level 2 frames in the corresponding parallel
777
        // encode set.
778
0
        level1_frame_idx = frame_idx;
779
0
        level2_frame_count = 0;
780
0
      }
781
0
      if (gf_group->frame_parallel_level[frame_idx] == 2) level2_frame_count++;
782
0
    }
783
    // If frame_parallel_level is set to 1 for the last LF_UPDATE
784
    // frame in the gf_group, reset it to zero since there are no subsequent
785
    // frames in the gf_group.
786
0
    if (gf_group->frame_parallel_level[frame_index - 2] == 1) {
787
0
      assert(gf_group->update_type[frame_index - 2] == LF_UPDATE);
788
0
      gf_group->frame_parallel_level[frame_index - 2] = 0;
789
0
    }
790
0
  }
791
792
0
  for (int gf_idx = frame_index; gf_idx < MAX_STATIC_GF_GROUP_LENGTH;
793
0
       ++gf_idx) {
794
0
    gf_group->update_type[gf_idx] = LF_UPDATE;
795
0
    gf_group->arf_src_offset[gf_idx] = 0;
796
0
    gf_group->cur_frame_idx[gf_idx] = gf_idx;
797
0
    gf_group->layer_depth[gf_idx] = MAX_ARF_LAYERS;
798
0
    gf_group->arf_boost[gf_idx] = NORMAL_BOOST;
799
0
    gf_group->frame_type[gf_idx] = INTER_FRAME;
800
0
    gf_group->refbuf_state[gf_idx] = REFBUF_UPDATE;
801
0
    gf_group->max_layer_depth = AOMMAX(gf_group->max_layer_depth, 2);
802
0
  }
803
804
0
  return frame_index;
805
0
}
806
807
0
static void set_ld_layer_depth(GF_GROUP *gf_group, int gop_length) {
808
0
  int log_gop_length = 0;
809
0
  while ((1 << log_gop_length) < gop_length) {
810
0
    ++log_gop_length;
811
0
  }
812
813
0
  for (int gf_index = 0; gf_index < gf_group->size; ++gf_index) {
814
0
    int count = 0;
815
    // Find the trailing zeros
816
0
    for (; count < MAX_ARF_LAYERS; ++count) {
817
0
      if ((gf_index >> count) & 0x01) break;
818
0
    }
819
0
    gf_group->layer_depth[gf_index] = AOMMAX(log_gop_length - count, 0);
820
0
  }
821
0
  gf_group->max_layer_depth = AOMMIN(log_gop_length, MAX_ARF_LAYERS);
822
0
}
823
824
0
void av1_gop_setup_structure(AV1_COMP *cpi) {
825
0
  RATE_CONTROL *const rc = &cpi->rc;
826
0
  PRIMARY_RATE_CONTROL *const p_rc = &cpi->ppi->p_rc;
827
0
  GF_GROUP *const gf_group = &cpi->ppi->gf_group;
828
0
  TWO_PASS *const twopass = &cpi->ppi->twopass;
829
0
  FRAME_INFO *const frame_info = &cpi->frame_info;
830
0
  const int key_frame = rc->frames_since_key == 0;
831
0
  FRAME_UPDATE_TYPE first_frame_update_type = ARF_UPDATE;
832
833
0
  if (key_frame) {
834
0
    first_frame_update_type = KF_UPDATE;
835
0
    if (cpi->oxcf.kf_max_pyr_height != -1) {
836
0
      gf_group->max_layer_depth_allowed = AOMMIN(
837
0
          cpi->oxcf.kf_max_pyr_height, gf_group->max_layer_depth_allowed);
838
0
    }
839
0
  } else if (!cpi->ppi->gf_state.arf_gf_boost_lst) {
840
0
    first_frame_update_type = GF_UPDATE;
841
0
  }
842
843
0
  gf_group->size = construct_multi_layer_gf_structure(
844
0
      cpi, twopass, gf_group, rc, frame_info, p_rc->baseline_gf_interval,
845
0
      first_frame_update_type);
846
847
0
  if (gf_group->max_layer_depth_allowed == 0)
848
0
    set_ld_layer_depth(gf_group, p_rc->baseline_gf_interval);
849
0
}
850
851
int av1_gop_check_forward_keyframe(const GF_GROUP *gf_group,
852
0
                                   int gf_frame_index) {
853
0
  return gf_group->frame_type[gf_frame_index] == KEY_FRAME &&
854
0
         gf_group->refbuf_state[gf_frame_index] == REFBUF_UPDATE;
855
0
}
856
857
0
int av1_gop_is_second_arf(const GF_GROUP *gf_group, int gf_frame_index) {
858
0
  const int arf_src_offset = gf_group->arf_src_offset[gf_frame_index];
859
  // TODO(angiebird): when gf_group->size == 32, it's possble to
860
  // have "two" second arf. Check if this is acceptable.
861
0
  if (gf_group->update_type[gf_frame_index] == INTNL_ARF_UPDATE &&
862
0
      arf_src_offset >= TF_LOOKAHEAD_IDX_THR) {
863
0
    return 1;
864
0
  }
865
0
  return 0;
866
0
}