History

avcodec/mpegvideo_dec: Factor allocating dummy frames out

This will allow to reuse it to allocate dummy frames for the second field (which can be a P-field even if the first field was an intra field).

Andreas Rheinhardt committed 2 years ago

Commit 99543c91 parent a30c95e2 files · +56 −33Browse files

Unified · Split

2 files
  1. libavcodec/mpegvideo_dec.c +52 −33
  2. libavcodec/mpegvideodec.h +4 −0
libavcodec/mpegvideo_dec.c+52−33
@@ -281,14 +281,21 @@ fail: · 280 unmodified lines
281 return ret;281 return ret;
282}282}
283 283
284static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp)284static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp, Picture *wpic)
285{285{
286 Picture *pic;286 Picture *pic;
287 int ret = alloc_picture(s, picp, 1);287 int ret = alloc_picture(s, &pic, 1);
288 if (ret < 0)288 if (ret < 0)
289 return ret;289 return ret;
290 290
291 pic = *picp;291 ff_mpeg_unref_picture(wpic);
292 ret = ff_mpeg_ref_picture(wpic, pic);
293 if (ret < 0) {
294 ff_mpeg_unref_picture(pic);
295 return ret;
296 }
297
298 *picp = pic;
292 299
293 ff_thread_report_progress(&pic->tf, INT_MAX, 0);300 ff_thread_report_progress(&pic->tf, INT_MAX, 0);
294 ff_thread_report_progress(&pic->tf, INT_MAX, 1);301 ff_thread_report_progress(&pic->tf, INT_MAX, 1);
@@ -314,6 +321,45 @@ static void color_frame(AVFrame *frame, int luma) · 19 unmodified lines
314 }321 }
315}322}
316 323
324int ff_mpv_alloc_dummy_frames(MpegEncContext *s)
325{
326 AVCodecContext *avctx = s->avctx;
327 int ret;
328
329 if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
330 (s->pict_type != AV_PICTURE_TYPE_I)) {
331 if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0])
332 av_log(avctx, AV_LOG_DEBUG,
333 "allocating dummy last picture for B frame\n");
334 else if (s->codec_id != AV_CODEC_ID_H261 /* H.261 has no keyframes */ &&
335 (s->picture_structure == PICT_FRAME || s->first_field))
336 av_log(avctx, AV_LOG_ERROR,
337 "warning: first frame is no keyframe\n");
338
339 /* Allocate a dummy frame */
340 ret = alloc_dummy_frame(s, &s->last_picture_ptr, &s->last_picture);
341 if (ret < 0)
342 return ret;
343
344 if (!avctx->hwaccel) {
345 int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80;
346 color_frame(s->last_picture_ptr->f, luma_val);
347 }
348 }
349 if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
350 s->pict_type == AV_PICTURE_TYPE_B) {
351 /* Allocate a dummy frame */
352 ret = alloc_dummy_frame(s, &s->next_picture_ptr, &s->next_picture);
353 if (ret < 0)
354 return ret;
355 }
356
357 av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
358 s->last_picture_ptr->f->buf[0]));
359
360 return 0;
361}
362
317/**363/**
318 * generic function called after decoding364 * generic function called after decoding
319 * the header and before a frame is decoded.365 * the header and before a frame is decoded.
@@ -382,34 +428,6 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) · 62 unmodified lines
382 s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL,428 s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL,
383 s->pict_type, s->droppable);429 s->pict_type, s->droppable);
384 430
385 if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
386 (s->pict_type != AV_PICTURE_TYPE_I)) {
387 if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0])
388 av_log(avctx, AV_LOG_DEBUG,
389 "allocating dummy last picture for B frame\n");
390 else if (s->codec_id != AV_CODEC_ID_H261)
391 av_log(avctx, AV_LOG_ERROR,
392 "warning: first frame is no keyframe\n");
393
394 /* Allocate a dummy frame */
395 ret = alloc_dummy_frame(s, &s->last_picture_ptr);
396 if (ret < 0)
397 return ret;
398
399 if (!avctx->hwaccel) {
400 int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80;
401 color_frame(s->last_picture_ptr->f, luma_val);
402 }
403
404 }
405 if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
406 s->pict_type == AV_PICTURE_TYPE_B) {
407 /* Allocate a dummy frame */
408 ret = alloc_dummy_frame(s, &s->next_picture_ptr);
409 if (ret < 0)
410 return ret;
411 }
412
413 if (s->last_picture_ptr) {431 if (s->last_picture_ptr) {
414 if (s->last_picture_ptr->f->buf[0] &&432 if (s->last_picture_ptr->f->buf[0] &&
415 (ret = ff_mpeg_ref_picture(&s->last_picture,433 (ret = ff_mpeg_ref_picture(&s->last_picture,
@@ -423,8 +441,9 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) · 7 unmodified lines
423 return ret;441 return ret;
424 }442 }
425 443
426 av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&444 ret = ff_mpv_alloc_dummy_frames(s);
427 s->last_picture_ptr->f->buf[0]));445 if (ret < 0)
446 return ret;
428 447
429 /* set dequantizer, we can't do it during init as448 /* set dequantizer, we can't do it during init as
430 * it might change for MPEG-4 and we can't do it in the header449 * it might change for MPEG-4 and we can't do it in the header
libavcodec/mpegvideodec.h+4−0
@@ -50,6 +50,10 @@ void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx); · 49 unmodified lines
50int ff_mpv_common_frame_size_change(MpegEncContext *s);50int ff_mpv_common_frame_size_change(MpegEncContext *s);
51 51
52int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx);52int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx);
53/**
54 * Ensure that the dummy frames are allocated according to pict_type if necessary.
55 */
56int ff_mpv_alloc_dummy_frames(MpegEncContext *s);
53void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]);57void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]);
54void ff_mpv_report_decode_progress(MpegEncContext *s);58void ff_mpv_report_decode_progress(MpegEncContext *s);
55void ff_mpv_frame_end(MpegEncContext *s);59void ff_mpv_frame_end(MpegEncContext *s);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t