lavc/vaapi_encode: Extract set output pkt property function
Signed-off-by: Fei Wang <fei.w.wang@intel.com> Reviewed-by: Neal Gompa <ngompa13@gmail.com>
This commit is contained in:
@@ -650,6 +650,41 @@ fail_at_end:
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int vaapi_encode_set_output_property(AVCodecContext *avctx,
|
||||||
|
VAAPIEncodePicture *pic,
|
||||||
|
AVPacket *pkt)
|
||||||
|
{
|
||||||
|
VAAPIEncodeContext *ctx = avctx->priv_data;
|
||||||
|
|
||||||
|
if (pic->type == PICTURE_TYPE_IDR)
|
||||||
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
||||||
|
|
||||||
|
pkt->pts = pic->pts;
|
||||||
|
pkt->duration = pic->duration;
|
||||||
|
|
||||||
|
// for no-delay encoders this is handled in generic codec
|
||||||
|
if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY &&
|
||||||
|
avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
|
||||||
|
pkt->opaque = pic->opaque;
|
||||||
|
pkt->opaque_ref = pic->opaque_ref;
|
||||||
|
pic->opaque_ref = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx->output_delay == 0) {
|
||||||
|
pkt->dts = pkt->pts;
|
||||||
|
} else if (pic->encode_order < ctx->decode_delay) {
|
||||||
|
if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
|
||||||
|
pkt->dts = INT64_MIN;
|
||||||
|
else
|
||||||
|
pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
|
||||||
|
} else {
|
||||||
|
pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
|
||||||
|
(3 * ctx->output_delay + ctx->async_depth)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int vaapi_encode_output(AVCodecContext *avctx,
|
static int vaapi_encode_output(AVCodecContext *avctx,
|
||||||
VAAPIEncodePicture *pic, AVPacket *pkt)
|
VAAPIEncodePicture *pic, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
@@ -691,12 +726,6 @@ static int vaapi_encode_output(AVCodecContext *avctx,
|
|||||||
ptr += buf->size;
|
ptr += buf->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pic->type == PICTURE_TYPE_IDR)
|
|
||||||
pkt->flags |= AV_PKT_FLAG_KEY;
|
|
||||||
|
|
||||||
pkt->pts = pic->pts;
|
|
||||||
pkt->duration = pic->duration;
|
|
||||||
|
|
||||||
vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer);
|
vas = vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer);
|
||||||
if (vas != VA_STATUS_SUCCESS) {
|
if (vas != VA_STATUS_SUCCESS) {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Failed to unmap output buffers: "
|
av_log(avctx, AV_LOG_ERROR, "Failed to unmap output buffers: "
|
||||||
@@ -705,14 +734,6 @@ static int vaapi_encode_output(AVCodecContext *avctx,
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for no-delay encoders this is handled in generic codec
|
|
||||||
if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY &&
|
|
||||||
avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
|
|
||||||
pkt->opaque = pic->opaque;
|
|
||||||
pkt->opaque_ref = pic->opaque_ref;
|
|
||||||
pic->opaque_ref = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
av_buffer_unref(&pic->output_buffer_ref);
|
av_buffer_unref(&pic->output_buffer_ref);
|
||||||
pic->output_buffer = VA_INVALID_ID;
|
pic->output_buffer = VA_INVALID_ID;
|
||||||
|
|
||||||
@@ -1273,19 +1294,9 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->output_delay == 0) {
|
vaapi_encode_set_output_property(avctx, pic, pkt);
|
||||||
pkt->dts = pkt->pts;
|
av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64", dts %"PRId64", "
|
||||||
} else if (pic->encode_order < ctx->decode_delay) {
|
"size %d bytes.\n", pkt->pts, pkt->dts, pkt->size);
|
||||||
if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
|
|
||||||
pkt->dts = INT64_MIN;
|
|
||||||
else
|
|
||||||
pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
|
|
||||||
} else {
|
|
||||||
pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
|
|
||||||
(3 * ctx->output_delay + ctx->async_depth)];
|
|
||||||
}
|
|
||||||
av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64" dts %"PRId64".\n",
|
|
||||||
pkt->pts, pkt->dts);
|
|
||||||
|
|
||||||
ctx->output_order = pic->encode_order;
|
ctx->output_order = pic->encode_order;
|
||||||
vaapi_encode_clear_old(avctx);
|
vaapi_encode_clear_old(avctx);
|
||||||
|
|||||||
Reference in New Issue
Block a user