History

vaapi_encode: Support forcing IDR frames via AVFrame.pict_type

(cherry picked from commit a3c3a5eac20a51d402c332cdf5220fff40a7943f)

Mark Thompson committed 9 years ago

Commit c667c091 parent 760f1a72 files · +24 −4Browse files

Unified · Split

2 files
  1. libavcodec/vaapi_encode.c +23 −4
  2. libavcodec/vaapi_encode.h +1 −0
libavcodec/vaapi_encode.c+23−4
@@ -590,6 +590,10 @@ static int vaapi_encode_step(AVCodecContext *avctx, · 589 unmodified lines
590590 } else if (ctx->issue_mode == ISSUE_MODE_MAXIMISE_THROUGHPUT) {
591591 int activity;
592592
593+ // Run through the list of all available pictures repeatedly
594+ // and issue the first one found which has all dependencies
595+ // available (including previously-issued but not necessarily
596+ // completed pictures).
593597 do {
594598 activity = 0;
595599 for (pic = ctx->pic_start; pic; pic = pic->next) {
@@ -605,9 +609,15 @@ static int vaapi_encode_step(AVCodecContext *avctx, · 9 unmodified lines
605609 if (err < 0)
606610 return err;
607611 activity = 1;
612+ // Start again from the beginning of the list,
613+ // because issuing this picture may have satisfied
614+ // forward dependencies of earlier ones.
615+ break;
608616 }
609617 } while(activity);
610618
619+ // If we had a defined target for this step then it will
620+ // always have been issued by now.
611621 if (target) {
612622 av_assert0(target->encode_issued && "broken dependencies?");
613623 }
@@ -639,8 +649,10 @@ static int vaapi_encode_get_next(AVCodecContext *avctx, · 25 unmodified lines
639649 if (!pic)
640650 return AVERROR(ENOMEM);
641651
642− if (ctx->input_order == 0 || ctx->gop_counter >= avctx->gop_size) {
652+ if (ctx->input_order == 0 || ctx->force_idr ||
653+ ctx->gop_counter >= avctx->gop_size) {
643654 pic->type = PICTURE_TYPE_IDR;
655+ ctx->force_idr = 0;
644656 ctx->gop_counter = 1;
645657 ctx->p_counter = 0;
646658 } else if (ctx->p_counter >= ctx->p_per_i) {
@@ -722,7 +734,7 @@ fail: · 75 unmodified lines
722734 return AVERROR(ENOMEM);
723735 }
724736
725−static int vaapi_encode_mangle_end(AVCodecContext *avctx)
737+static int vaapi_encode_truncate_gop(AVCodecContext *avctx)
726738 {
727739 VAAPIEncodeContext *ctx = avctx->priv_data;
728740 VAAPIEncodePicture *pic, *last_pic, *next;
@@ -772,7 +784,7 @@ static int vaapi_encode_mangle_end(AVCodecContext *avctx) · 43 unmodified lines
772784 // mangle anything.
773785 }
774786
775− av_log(avctx, AV_LOG_DEBUG, "Pictures at end of stream:");
787+ av_log(avctx, AV_LOG_DEBUG, "Pictures ending truncated GOP:");
776788 for (pic = ctx->pic_start; pic; pic = pic->next) {
777789 av_log(avctx, AV_LOG_DEBUG, " %s (%"PRId64"/%"PRId64")",
778790 picture_type_name[pic->type],
@@ -826,6 +838,13 @@ int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, · 47 unmodified lines
826838 av_log(avctx, AV_LOG_DEBUG, "Encode frame: %ux%u (%"PRId64").\n",
827839 input_image->width, input_image->height, input_image->pts);
828840
841+ if (input_image->pict_type == AV_PICTURE_TYPE_I) {
842+ err = vaapi_encode_truncate_gop(avctx);
843+ if (err < 0)
844+ goto fail;
845+ ctx->force_idr = 1;
846+ }
847+
829848 err = vaapi_encode_get_next(avctx, &pic);
830849 if (err) {
831850 av_log(avctx, AV_LOG_ERROR, "Input setup failed: %d.\n", err);
@@ -854,7 +873,7 @@ int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, · 22 unmodified lines
854873
855874 } else {
856875 if (!ctx->end_of_stream) {
857− err = vaapi_encode_mangle_end(avctx);
876+ err = vaapi_encode_truncate_gop(avctx);
858877 if (err < 0)
859878 goto fail;
860879 ctx->end_of_stream = 1;
libavcodec/vaapi_encode.h+1−0
@@ -192,6 +192,7 @@ typedef struct VAAPIEncodeContext { · 191 unmodified lines
192192 // Frame type decision.
193193 int p_per_i;
194194 int b_per_p;
195+ int force_idr;
195196 int gop_counter;
196197 int p_counter;
197198 int end_of_stream;

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