History

vaapi_encode: Clean up the packed header configuration

Add a larger warning more clearly explaining the consequences of missing packed header support in the driver. Also only write the extradata if the user actually requests it via the GLOBAL_HEADER flag.

Mark Thompson committed 8 years ago

Commit 851a63c1 parent bf726c28 files · +80 −68Browse files

Showing the changes to libavcodec/vaapi_encode.c (1 of 8 files). Show all

Unified · Split

libavcodec/vaapi_encode.c+63−56
@@ -1206,60 +1206,6 @@ fail: · 1205 unmodified lines
12061206 return err;
12071207 }
12081208
1209−static av_cold int vaapi_encode_config_attributes(AVCodecContext *avctx)
1210−{
1211− VAAPIEncodeContext *ctx = avctx->priv_data;
1212− VAStatus vas;
1213− int i;
1214−
1215− VAConfigAttrib attr[] = {
1216− { VAConfigAttribEncPackedHeaders },
1217− };
1218−
1219− vas = vaGetConfigAttributes(ctx->hwctx->display,
1220− ctx->va_profile, ctx->va_entrypoint,
1221− attr, FF_ARRAY_ELEMS(attr));
1222− if (vas != VA_STATUS_SUCCESS) {
1223− av_log(avctx, AV_LOG_ERROR, "Failed to fetch config "
1224− "attributes: %d (%s).\n", vas, vaErrorStr(vas));
1225− return AVERROR(EINVAL);
1226− }
1227−
1228− for (i = 0; i < FF_ARRAY_ELEMS(attr); i++) {
1229− if (attr[i].value == VA_ATTRIB_NOT_SUPPORTED) {
1230− // Unfortunately we have to treat this as "don't know" and hope
1231− // for the best, because the Intel MJPEG encoder returns this
1232− // for all the interesting attributes.
1233− av_log(avctx, AV_LOG_DEBUG, "Attribute (%d) is not supported.\n",
1234− attr[i].type);
1235− continue;
1236− }
1237− switch (attr[i].type) {
1238− case VAConfigAttribEncPackedHeaders:
1239− if (ctx->va_packed_headers & ~attr[i].value) {
1240− // This isn't fatal, but packed headers are always
1241− // preferable because they are under our control.
1242− // When absent, the driver is generating them and some
1243− // features may not work (e.g. VUI or SEI in H.264).
1244− av_log(avctx, AV_LOG_WARNING, "Warning: some packed "
1245− "headers are not supported (want %#x, got %#x).\n",
1246− ctx->va_packed_headers, attr[i].value);
1247− ctx->va_packed_headers &= attr[i].value;
1248− }
1249− ctx->config_attributes[ctx->nb_config_attributes++] =
1250− (VAConfigAttrib) {
1251− .type = VAConfigAttribEncPackedHeaders,
1252− .value = ctx->va_packed_headers,
1253− };
1254− break;
1255− default:
1256− av_assert0(0 && "Unexpected config attribute.");
1257− }
1258− }
1259−
1260− return 0;
1261−}
1262−
12631209 static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
12641210 {
12651211 VAAPIEncodeContext *ctx = avctx->priv_data;
@@ -1498,6 +1444,66 @@ static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx) · 232 unmodified lines
14981444 return 0;
14991445 }
15001446
1447+static av_cold int vaapi_encode_init_packed_headers(AVCodecContext *avctx)
1448+{
1449+ VAAPIEncodeContext *ctx = avctx->priv_data;
1450+ VAStatus vas;
1451+ VAConfigAttrib attr = { VAConfigAttribEncPackedHeaders };
1452+
1453+ vas = vaGetConfigAttributes(ctx->hwctx->display,
1454+ ctx->va_profile,
1455+ ctx->va_entrypoint,
1456+ &attr, 1);
1457+ if (vas != VA_STATUS_SUCCESS) {
1458+ av_log(avctx, AV_LOG_ERROR, "Failed to query packed headers "
1459+ "attribute: %d (%s).\n", vas, vaErrorStr(vas));
1460+ return AVERROR_EXTERNAL;
1461+ }
1462+
1463+ if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
1464+ if (ctx->desired_packed_headers) {
1465+ av_log(avctx, AV_LOG_WARNING, "Driver does not support any "
1466+ "packed headers (wanted %#x).\n",
1467+ ctx->desired_packed_headers);
1468+ } else {
1469+ av_log(avctx, AV_LOG_VERBOSE, "Driver does not support any "
1470+ "packed headers (none wanted).\n");
1471+ }
1472+ ctx->va_packed_headers = 0;
1473+ } else {
1474+ if (ctx->desired_packed_headers & ~attr.value) {
1475+ av_log(avctx, AV_LOG_WARNING, "Driver does not support some "
1476+ "wanted packed headers (wanted %#x, found %#x).\n",
1477+ ctx->desired_packed_headers, attr.value);
1478+ } else {
1479+ av_log(avctx, AV_LOG_VERBOSE, "All wanted packed headers "
1480+ "available (wanted %#x, found %#x).\n",
1481+ ctx->desired_packed_headers, attr.value);
1482+ }
1483+ ctx->va_packed_headers = ctx->desired_packed_headers & attr.value;
1484+ }
1485+
1486+ if (ctx->va_packed_headers) {
1487+ ctx->config_attributes[ctx->nb_config_attributes++] =
1488+ (VAConfigAttrib) {
1489+ .type = VAConfigAttribEncPackedHeaders,
1490+ .value = ctx->va_packed_headers,
1491+ };
1492+ }
1493+
1494+ if ( (ctx->desired_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE) &&
1495+ !(ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE) &&
1496+ (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)) {
1497+ av_log(avctx, AV_LOG_WARNING, "Driver does not support packed "
1498+ "sequence headers, but a global header is requested.\n");
1499+ av_log(avctx, AV_LOG_WARNING, "No global header will be written: "
1500+ "this may result in a stream which is not usable for some "
1501+ "purposes (e.g. not muxable to some containers).\n");
1502+ }
1503+
1504+ return 0;
1505+}
1506+
15011507 static av_cold int vaapi_encode_init_quality(AVCodecContext *avctx)
15021508 {
15031509 #if VA_CHECK_VERSION(0, 36, 0)
@@ -1728,7 +1734,7 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) · 224 unmodified lines
17281734 if (err < 0)
17291735 goto fail;
17301736
1731− err = vaapi_encode_config_attributes(avctx);
1737+ err = vaapi_encode_init_packed_headers(avctx);
17321738 if (err < 0)
17331739 goto fail;
17341740
@@ -1817,7 +1823,8 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) · 82 unmodified lines
18171823 ctx->issue_mode = ISSUE_MODE_MAXIMISE_THROUGHPUT;
18181824
18191825 if (ctx->va_packed_headers & VA_ENC_PACKED_HEADER_SEQUENCE &&
1820− ctx->codec->write_sequence_header) {
1826+ ctx->codec->write_sequence_header &&
1827+ avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
18211828 char data[MAX_PARAM_BUFFER_SIZE];
18221829 size_t bit_len = 8 * sizeof(data);
18231830

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