/src/aom/av1/encoder/encode_strategy.h
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 | | /*!\file |
13 | | * \brief Declares frame encoding functions. |
14 | | */ |
15 | | #ifndef AOM_AV1_ENCODER_ENCODE_STRATEGY_H_ |
16 | | #define AOM_AV1_ENCODER_ENCODE_STRATEGY_H_ |
17 | | |
18 | | #ifdef __cplusplus |
19 | | extern "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 | | |
29 | | /*!\brief Implement high-level encode strategy |
30 | | * |
31 | | * \ingroup high_level_algo |
32 | | * \callgraph |
33 | | * \callergraph |
34 | | * This function will implement high-level encode strategy, choosing frame type, |
35 | | * frame placement, etc. It populates an EncodeFrameParams struct with the |
36 | | * results of these decisions and then encodes the frame. The caller should use |
37 | | * the output parameters *time_stamp and *time_end only when this function |
38 | | * returns AOM_CODEC_OK. |
39 | | * |
40 | | * \param[in] cpi Top-level encoder structure |
41 | | * \param[in] size Bitstream size |
42 | | * \param[in] dest Bitstream output |
43 | | * \param[in] frame_flags Flags to decide how to encoding the frame |
44 | | * \param[out] time_stamp Time stamp of the frame |
45 | | * \param[out] time_end Time end |
46 | | * \param[in] timestamp_ratio Time base |
47 | | * \param[in] pop_lookahead Decide to pop the source frame from queue |
48 | | * \param[in] flush Decide to encode one frame or the rest of frames |
49 | | * |
50 | | * \return Returns a value to indicate if the encoding is done successfully. |
51 | | * \retval #AOM_CODEC_OK |
52 | | * \retval -1 |
53 | | * \retval #AOM_CODEC_ERROR |
54 | | */ |
55 | | int 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 | | |
61 | | /*!\cond */ |
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. |
65 | | void av1_configure_buffer_updates(AV1_COMP *const cpi, |
66 | | RefreshFrameInfo *const refresh_frame, |
67 | | const FRAME_UPDATE_TYPE type, |
68 | | const REFBUF_STATE refbuf_state, |
69 | | int force_refresh_all); |
70 | | |
71 | | int av1_get_refresh_frame_flags(const AV1_COMP *const cpi, |
72 | | const EncodeFrameParams *const frame_params, |
73 | | FRAME_UPDATE_TYPE frame_update_type, |
74 | | int gf_index, |
75 | | #if CONFIG_FRAME_PARALLEL_ENCODE |
76 | | int cur_disp_order, |
77 | | RefFrameMapPair ref_frame_map_pairs[REF_FRAMES], |
78 | | #endif // CONFIG_FRAME_PARALLEL_ENCODE |
79 | | const RefBufferStack *const ref_buffer_stack); |
80 | | |
81 | | int av1_get_refresh_ref_frame_map(int refresh_frame_flags); |
82 | | |
83 | | void av1_update_ref_frame_map(const AV1_COMP *cpi, |
84 | | FRAME_UPDATE_TYPE frame_update_type, |
85 | | REFBUF_STATE refbuf_state, int ref_map_index, |
86 | | RefBufferStack *ref_buffer_stack); |
87 | | |
88 | | /*!\brief Obtain indices of reference frames from reference frame buffer stacks |
89 | | * |
90 | | * \callgraph |
91 | | * \callergraph |
92 | | * |
93 | | * \param[in] ref_buffer_stack Data structure for reference frame buffer |
94 | | * stacks. |
95 | | * \param[out] remapped_ref_idx An array for storing indices of reference |
96 | | * frames. The index is used to retrieve a |
97 | | * reference frame buffer from ref_frame_map |
98 | | * in AV1Common. |
99 | | */ |
100 | | void av1_get_ref_frames(const RefBufferStack *ref_buffer_stack, |
101 | | #if CONFIG_FRAME_PARALLEL_ENCODE |
102 | | RefFrameMapPair ref_frame_map_pairs[REF_FRAMES], |
103 | | int cur_frame_disp, |
104 | | #if CONFIG_FRAME_PARALLEL_ENCODE_2 |
105 | | const AV1_COMP *cpi, int gf_index, |
106 | | int is_parallel_encode, |
107 | | #endif // CONFIG_FRAME_PARALLEL_ENCODE_2 |
108 | | #endif // CONFIG_FRAME_PARALLEL_ENCODE |
109 | | int remapped_ref_idx[REF_FRAMES]); |
110 | | |
111 | | int is_forced_keyframe_pending(struct lookahead_ctx *lookahead, |
112 | | const int up_to_index, |
113 | | const COMPRESSOR_STAGE compressor_stage); |
114 | | |
115 | | static AOM_INLINE int is_frame_droppable( |
116 | | const SVC *const svc, |
117 | 0 | const ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags) { |
118 | | // Droppable frame is only used by external refresh flags. VoD setting won't |
119 | | // trigger its use case. |
120 | 0 | if (svc->set_ref_frame_config) |
121 | 0 | return svc->non_reference_frame; |
122 | 0 | else if (ext_refresh_frame_flags->update_pending) |
123 | 0 | return !(ext_refresh_frame_flags->alt_ref_frame || |
124 | 0 | ext_refresh_frame_flags->alt2_ref_frame || |
125 | 0 | ext_refresh_frame_flags->bwd_ref_frame || |
126 | 0 | ext_refresh_frame_flags->golden_frame || |
127 | 0 | ext_refresh_frame_flags->last_frame); |
128 | 0 | else |
129 | 0 | return 0; |
130 | 0 | } Unexecuted instantiation: encoder.c:is_frame_droppable Unexecuted instantiation: firstpass.c:is_frame_droppable Unexecuted instantiation: pass2_strategy.c:is_frame_droppable Unexecuted instantiation: ratectrl.c:is_frame_droppable Unexecuted instantiation: tpl_model.c:is_frame_droppable Unexecuted instantiation: encode_strategy.c:is_frame_droppable |
131 | | |
132 | 0 | static AOM_INLINE int get_current_frame_ref_type(const AV1_COMP *const cpi) { |
133 | | // We choose the reference "type" of this frame from the flags which indicate |
134 | | // which reference frames will be refreshed by it. More than one of these |
135 | | // flags may be set, so the order here implies an order of precedence. This is |
136 | | // just used to choose the primary_ref_frame (as the most recent reference |
137 | | // buffer of the same reference-type as the current frame). |
138 | |
|
139 | 0 | switch (cpi->ppi->gf_group.layer_depth[cpi->gf_frame_index]) { |
140 | 0 | case 0: return 0; |
141 | 0 | case 1: return 1; |
142 | 0 | case MAX_ARF_LAYERS: |
143 | 0 | case MAX_ARF_LAYERS + 1: return 4; |
144 | 0 | default: return 7; |
145 | 0 | } |
146 | 0 | } Unexecuted instantiation: encoder.c:get_current_frame_ref_type Unexecuted instantiation: firstpass.c:get_current_frame_ref_type Unexecuted instantiation: pass2_strategy.c:get_current_frame_ref_type Unexecuted instantiation: ratectrl.c:get_current_frame_ref_type Unexecuted instantiation: tpl_model.c:get_current_frame_ref_type Unexecuted instantiation: encode_strategy.c:get_current_frame_ref_type |
147 | | |
148 | | #if CONFIG_FRAME_PARALLEL_ENCODE |
149 | | #if CONFIG_FRAME_PARALLEL_ENCODE_2 |
150 | | int av1_calc_refresh_idx_for_intnl_arf( |
151 | | AV1_COMP *cpi, RefFrameMapPair ref_frame_map_pairs[REF_FRAMES], |
152 | | int gf_index); |
153 | | #endif // CONFIG_FRAME_PARALLEL_ENCODE_2 |
154 | | #endif // CONFIG_FRAME_PARALLEL_ENCODE |
155 | | /*!\endcond */ |
156 | | #ifdef __cplusplus |
157 | | } // extern "C" |
158 | | #endif |
159 | | |
160 | | #endif // AOM_AV1_ENCODER_ENCODE_STRATEGY_H_ |