Commit 281b68b0 authored by Mark Thompson's avatar Mark Thompson

vaapi_h264: Add support for AUD NAL units

Adds a new private option to enable them (off by default).

(cherry picked from commit 820a4483)
parent 2e29ca2a
...@@ -53,6 +53,7 @@ typedef struct VAAPIEncodeH264Context { ...@@ -53,6 +53,7 @@ typedef struct VAAPIEncodeH264Context {
int fixed_qp_p; int fixed_qp_p;
int fixed_qp_b; int fixed_qp_b;
H264RawAUD aud;
H264RawSPS sps; H264RawSPS sps;
H264RawPPS pps; H264RawPPS pps;
H264RawSEI sei; H264RawSEI sei;
...@@ -77,6 +78,7 @@ typedef struct VAAPIEncodeH264Context { ...@@ -77,6 +78,7 @@ typedef struct VAAPIEncodeH264Context {
CodedBitstreamContext *cbc; CodedBitstreamContext *cbc;
CodedBitstreamFragment current_access_unit; CodedBitstreamFragment current_access_unit;
int aud_needed;
int sei_needed; int sei_needed;
} VAAPIEncodeH264Context; } VAAPIEncodeH264Context;
...@@ -86,6 +88,7 @@ typedef struct VAAPIEncodeH264Options { ...@@ -86,6 +88,7 @@ typedef struct VAAPIEncodeH264Options {
int low_power; int low_power;
// Entropy encoder type. // Entropy encoder type.
int coder; int coder;
int aud;
int sei; int sei;
} VAAPIEncodeH264Options; } VAAPIEncodeH264Options;
...@@ -145,6 +148,13 @@ static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx, ...@@ -145,6 +148,13 @@ static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx,
CodedBitstreamFragment *au = &priv->current_access_unit; CodedBitstreamFragment *au = &priv->current_access_unit;
int err; int err;
if (priv->aud_needed) {
err = vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
if (err < 0)
goto fail;
priv->aud_needed = 0;
}
err = vaapi_encode_h264_add_nal(avctx, au, &priv->sps); err = vaapi_encode_h264_add_nal(avctx, au, &priv->sps);
if (err < 0) if (err < 0)
goto fail; goto fail;
...@@ -169,6 +179,13 @@ static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx, ...@@ -169,6 +179,13 @@ static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx,
CodedBitstreamFragment *au = &priv->current_access_unit; CodedBitstreamFragment *au = &priv->current_access_unit;
int err; int err;
if (priv->aud_needed) {
err = vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
if (err < 0)
goto fail;
priv->aud_needed = 0;
}
err = vaapi_encode_h264_add_nal(avctx, au, &priv->slice); err = vaapi_encode_h264_add_nal(avctx, au, &priv->slice);
if (err < 0) if (err < 0)
goto fail; goto fail;
...@@ -191,6 +208,11 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, ...@@ -191,6 +208,11 @@ static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
int err, i; int err, i;
if (priv->sei_needed) { if (priv->sei_needed) {
if (priv->aud_needed) {
vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
priv->aud_needed = 0;
}
memset(&priv->sei, 0, sizeof(priv->sei)); memset(&priv->sei, 0, sizeof(priv->sei));
priv->sei.nal_unit_header.nal_unit_type = H264_NAL_SEI; priv->sei.nal_unit_header.nal_unit_type = H264_NAL_SEI;
...@@ -573,6 +595,14 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, ...@@ -573,6 +595,14 @@ static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
priv->pic_order_cnt = pic->display_order - priv->last_idr_frame; priv->pic_order_cnt = pic->display_order - priv->last_idr_frame;
priv->dpb_delay = pic->display_order - pic->encode_order + 1; priv->dpb_delay = pic->display_order - pic->encode_order + 1;
if (opt->aud) {
priv->aud_needed = 1;
priv->aud.nal_unit_header.nal_unit_type = H264_NAL_AUD;
priv->aud.primary_pic_type = priv->primary_pic_type;
} else {
priv->aud_needed = 0;
}
if (opt->sei & SEI_IDENTIFIER && pic->encode_order == 0) if (opt->sei & SEI_IDENTIFIER && pic->encode_order == 0)
priv->sei_needed = 1; priv->sei_needed = 1;
...@@ -931,6 +961,9 @@ static const AVOption vaapi_encode_h264_options[] = { ...@@ -931,6 +961,9 @@ static const AVOption vaapi_encode_h264_options[] = {
{ "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, "coder" }, { "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, "coder" },
{ "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, "coder" }, { "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, "coder" },
{ "aud", "Include AUD",
OFFSET(aud), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
{ "sei", "Set SEI to include", { "sei", "Set SEI to include",
OFFSET(sei), AV_OPT_TYPE_FLAGS, OFFSET(sei), AV_OPT_TYPE_FLAGS,
{ .i64 = SEI_IDENTIFIER | SEI_TIMING }, { .i64 = SEI_IDENTIFIER | SEI_TIMING },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment