MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / hw_base_encode_pick_next

Function hw_base_encode_pick_next

libavcodec/hw_base_encode.c:206–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206static int hw_base_encode_pick_next(AVCodecContext *avctx,
207 FFHWBaseEncodeContext *ctx,
208 FFHWBaseEncodePicture **pic_out)
209{
210 FFHWBaseEncodePicture *pic = NULL, *prev = NULL, *next, *start;
211 int i, b_counter, closed_gop_end;
212
213 // If there are any B-frames already queued, the next one to encode
214 // is the earliest not-yet-issued frame for which all references are
215 // available.
216 for (pic = ctx->pic_start; pic; pic = pic->next) {
217 if (pic->encode_issued)
218 continue;
219 if (pic->type != FF_HW_PICTURE_TYPE_B)
220 continue;
221 for (i = 0; i < pic->nb_refs[0]; i++) {
222 if (!pic->refs[0][i]->encode_issued)
223 break;
224 }
225 if (i != pic->nb_refs[0])
226 continue;
227
228 for (i = 0; i < pic->nb_refs[1]; i++) {
229 if (!pic->refs[1][i]->encode_issued)
230 break;
231 }
232 if (i == pic->nb_refs[1])
233 break;
234 }
235
236 if (pic) {
237 av_log(avctx, AV_LOG_DEBUG, "Pick B-picture at depth %d to "
238 "encode next.\n", pic->b_depth);
239 *pic_out = pic;
240 return 0;
241 }
242
243 // Find the B-per-Pth available picture to become the next picture
244 // on the top layer.
245 start = NULL;
246 b_counter = 0;
247 closed_gop_end = ctx->closed_gop ||
248 ctx->idr_counter == ctx->gop_per_idr;
249 for (pic = ctx->pic_start; pic; pic = next) {
250 next = pic->next;
251 if (pic->encode_issued) {
252 start = pic;
253 continue;
254 }
255 // If the next available picture is force-IDR, encode it to start
256 // a new GOP immediately.
257 if (pic->force_idr)
258 break;
259 if (b_counter == ctx->b_per_p)
260 break;
261 // If this picture ends a closed GOP or starts a new GOP then it
262 // needs to be in the top layer.
263 if (ctx->gop_counter + b_counter + closed_gop_end >= ctx->gop_size)

Callers 1

Calls 4

av_logFunction · 0.85
hw_base_encode_add_refFunction · 0.85

Tested by

no test coverage detected