AOMedia AV1 Codec
encode_strategy.h
Go to the documentation of this file.
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
15#ifndef AOM_AV1_ENCODER_ENCODE_STRATEGY_H_
16#define AOM_AV1_ENCODER_ENCODE_STRATEGY_H_
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <stdint.h>
23
24#include "aom/aom_encoder.h"
25
26#include "av1/encoder/encoder.h"
27#include "av1/encoder/firstpass.h"
28
55int av1_encode_strategy(AV1_COMP *const cpi, size_t *const size,
56 uint8_t *const dest, unsigned int *frame_flags,
57 int64_t *const time_stamp, int64_t *const time_end,
58 const aom_rational64_t *const timestamp_ratio,
59 int *const pop_lookahead, int flush);
60
62// Set individual buffer update flags based on frame reference type.
63// force_refresh_all is used when we have a KEY_FRAME or S_FRAME. It forces all
64// refresh_*_frame flags to be set, because we refresh all buffers in this case.
65void av1_configure_buffer_updates(
66 AV1_COMP *const cpi, RefreshFrameFlagsInfo *const refresh_frame_flags,
67 const FRAME_UPDATE_TYPE type, const REFBUF_STATE refbuf_state,
68 int force_refresh_all);
69
70int av1_get_refresh_frame_flags(const AV1_COMP *const cpi,
71 const EncodeFrameParams *const frame_params,
72 FRAME_UPDATE_TYPE frame_update_type,
73 int gf_index,
74#if CONFIG_FRAME_PARALLEL_ENCODE
75 int cur_disp_order,
76 RefFrameMapPair ref_frame_map_pairs[REF_FRAMES],
77#endif // CONFIG_FRAME_PARALLEL_ENCODE
78 const RefBufferStack *const ref_buffer_stack);
79
80int av1_get_refresh_ref_frame_map(int refresh_frame_flags);
81
82void av1_update_ref_frame_map(const AV1_COMP *cpi,
83 FRAME_UPDATE_TYPE frame_update_type,
84 REFBUF_STATE refbuf_state, int ref_map_index,
85 RefBufferStack *ref_buffer_stack);
86
99void av1_get_ref_frames(const RefBufferStack *ref_buffer_stack,
100#if CONFIG_FRAME_PARALLEL_ENCODE
101 RefFrameMapPair ref_frame_map_pairs[REF_FRAMES],
102 int cur_frame_disp,
103#if CONFIG_FRAME_PARALLEL_ENCODE_2
104 const AV1_COMP *cpi, int gf_index,
105 int is_parallel_encode,
106#endif // CONFIG_FRAME_PARALLEL_ENCODE_2
107#endif // CONFIG_FRAME_PARALLEL_ENCODE
108 int remapped_ref_idx[REF_FRAMES]);
109
110int is_forced_keyframe_pending(struct lookahead_ctx *lookahead,
111 const int up_to_index,
112 const COMPRESSOR_STAGE compressor_stage);
113
114static AOM_INLINE int is_frame_droppable(
115 const SVC *const svc,
116 const ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags) {
117 // Droppable frame is only used by external refresh flags. VoD setting won't
118 // trigger its use case.
119 if (svc->set_ref_frame_config)
120 return svc->non_reference_frame;
121 else if (ext_refresh_frame_flags->update_pending)
122 return !(ext_refresh_frame_flags->alt_ref_frame ||
123 ext_refresh_frame_flags->alt2_ref_frame ||
124 ext_refresh_frame_flags->bwd_ref_frame ||
125 ext_refresh_frame_flags->golden_frame ||
126 ext_refresh_frame_flags->last_frame);
127 else
128 return 0;
129}
130
131static AOM_INLINE int get_current_frame_ref_type(const AV1_COMP *const cpi) {
132 // We choose the reference "type" of this frame from the flags which indicate
133 // which reference frames will be refreshed by it. More than one of these
134 // flags may be set, so the order here implies an order of precedence. This is
135 // just used to choose the primary_ref_frame (as the most recent reference
136 // buffer of the same reference-type as the current frame).
137
138 switch (cpi->ppi->gf_group.layer_depth[cpi->gf_frame_index]) {
139 case 0: return 0;
140 case 1: return 1;
141 case MAX_ARF_LAYERS:
142 case MAX_ARF_LAYERS + 1: return 4;
143 default: return 7;
144 }
145}
146
147#if CONFIG_FRAME_PARALLEL_ENCODE
148#if CONFIG_FRAME_PARALLEL_ENCODE_2
149int av1_calc_refresh_idx_for_intnl_arf(
150 AV1_COMP *cpi, RefFrameMapPair ref_frame_map_pairs[REF_FRAMES],
151 int gf_index);
152#endif // CONFIG_FRAME_PARALLEL_ENCODE_2
153#endif // CONFIG_FRAME_PARALLEL_ENCODE
155#ifdef __cplusplus
156} // extern "C"
157#endif
158
159#endif // AOM_AV1_ENCODER_ENCODE_STRATEGY_H_
Describes the encoder algorithm interface to applications.
Declares top-level encoder structures and functions.
int av1_encode_strategy(AV1_COMP *const cpi, size_t *const size, uint8_t *const dest, unsigned int *frame_flags, int64_t *const time_stamp, int64_t *const time_end, const aom_rational64_t *const timestamp_ratio, int *const pop_lookahead, int flush)
Implement high-level encode strategy.
Definition: encode_strategy.c:1447
Top level encoder structure.
Definition: encoder.h:2557
unsigned char gf_frame_index
Definition: encoder.h:2789
AV1_PRIMARY * ppi
Definition: encoder.h:2561
GF_GROUP gf_group
Definition: encoder.h:2384
contains per-frame encoding parameters decided upon by av1_encode_strategy() and passed down to av1_e...
Definition: encoder.h:3200
Frame refresh flags set by the external interface.
Definition: encoder.h:2036
bool golden_frame
Definition: encoder.h:2038
bool bwd_ref_frame
Definition: encoder.h:2039
bool update_pending
Definition: encoder.h:2045
bool last_frame
Definition: encoder.h:2037
bool alt_ref_frame
Definition: encoder.h:2041
bool alt2_ref_frame
Definition: encoder.h:2040
Refresh frame flags for different type of frames.
Definition: encoder.h:1932
The stucture of SVC.
Definition: svc_layercontext.h:92