History

vaapi_encode: Clean up the encode quality configuration

Mark Thompson committed 8 years ago

Commit ac31d841 parent 95f6f7b2 files · +54 −37Browse files

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

Unified · Split

libavcodec/vaapi_encode.c+51−33
@@ -1387,6 +1387,51 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx) · 1386 unmodified lines
13871387 return 0;
13881388 }
13891389
1390+static av_cold int vaapi_encode_init_quality(AVCodecContext *avctx)
1391+{
1392+#if VA_CHECK_VERSION(0, 36, 0)
1393+ VAAPIEncodeContext *ctx = avctx->priv_data;
1394+ VAStatus vas;
1395+ VAConfigAttrib attr = { VAConfigAttribEncQualityRange };
1396+ int quality = avctx->compression_level;
1397+
1398+ vas = vaGetConfigAttributes(ctx->hwctx->display,
1399+ ctx->va_profile,
1400+ ctx->va_entrypoint,
1401+ &attr, 1);
1402+ if (vas != VA_STATUS_SUCCESS) {
1403+ av_log(avctx, AV_LOG_ERROR, "Failed to query quality "
1404+ "config attribute: %d (%s).\n", vas, vaErrorStr(vas));
1405+ return AVERROR_EXTERNAL;
1406+ }
1407+
1408+ if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
1409+ if (quality != 0) {
1410+ av_log(avctx, AV_LOG_WARNING, "Quality attribute is not "
1411+ "supported: will use default quality level.\n");
1412+ }
1413+ } else {
1414+ if (quality > attr.value) {
1415+ av_log(avctx, AV_LOG_WARNING, "Invalid quality level: "
1416+ "valid range is 0-%d, using %d.\n",
1417+ attr.value, attr.value);
1418+ quality = attr.value;
1419+ }
1420+
1421+ ctx->quality_params.misc.type = VAEncMiscParameterTypeQualityLevel;
1422+ ctx->quality_params.quality.quality_level = quality;
1423+
1424+ vaapi_encode_add_global_param(avctx, &ctx->quality_params.misc,
1425+ sizeof(ctx->quality_params));
1426+ }
1427+#else
1428+ av_log(avctx, AV_LOG_WARNING, "The encode quality option is "
1429+ "not supported with this VAAPI version.\n");
1430+#endif
1431+
1432+ return 0;
1433+}
1434+
13901435 static void vaapi_encode_free_output_buffer(void *opaque,
13911436 uint8_t *data)
13921437 {
@@ -1568,6 +1613,12 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) · 175 unmodified lines
15681613 if (err < 0)
15691614 goto fail;
15701615
1616+ if (avctx->compression_level >= 0) {
1617+ err = vaapi_encode_init_quality(avctx);
1618+ if (err < 0)
1619+ goto fail;
1620+ }
1621+
15711622 vas = vaCreateConfig(ctx->hwctx->display,
15721623 ctx->va_profile, ctx->va_entrypoint,
15731624 ctx->config_attributes, ctx->nb_config_attributes,
@@ -1617,39 +1668,6 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) · 43 unmodified lines
16171668 goto fail;
16181669 }
16191670
1620− if (avctx->compression_level >= 0) {
1621−#if VA_CHECK_VERSION(0, 36, 0)
1622− VAConfigAttrib attr = { VAConfigAttribEncQualityRange };
1623−
1624− vas = vaGetConfigAttributes(ctx->hwctx->display,
1625− ctx->va_profile,
1626− ctx->va_entrypoint,
1627− &attr, 1);
1628− if (vas != VA_STATUS_SUCCESS) {
1629− av_log(avctx, AV_LOG_WARNING, "Failed to query quality "
1630− "attribute: will use default compression level.\n");
1631− } else {
1632− if (avctx->compression_level > attr.value) {
1633− av_log(avctx, AV_LOG_WARNING, "Invalid compression "
1634− "level: valid range is 0-%d, using %d.\n",
1635− attr.value, attr.value);
1636− avctx->compression_level = attr.value;
1637− }
1638−
1639− ctx->quality_params.misc.type =
1640− VAEncMiscParameterTypeQualityLevel;
1641− ctx->quality_params.quality.quality_level =
1642− avctx->compression_level;
1643−
1644− vaapi_encode_add_global_param(avctx, &ctx->quality_params.misc,
1645− sizeof(ctx->quality_params));
1646− }
1647−#else
1648− av_log(avctx, AV_LOG_WARNING, "The encode compression level "
1649− "option is not supported with this VAAPI version.\n");
1650−#endif
1651− }
1652−
16531671 ctx->input_order = 0;
16541672 ctx->output_delay = avctx->max_b_frames;
16551673 ctx->decode_delay = 1;

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