vpxenc: Include vpx error details in errors and warnings

The vpx_codec_t err_detail string usually provides additional context about the
error, so include it in GStreamer warnings and errors, when it's not NULL.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6573>
This commit is contained in:
Philippe Normand 2024-04-08 13:04:31 +01:00 committed by GStreamer Marge Bot
parent 6e33a5da14
commit 8d3e7689e1

View file

@ -371,6 +371,12 @@ static gboolean gst_vpx_enc_propose_allocation (GstVideoEncoder * encoder,
static gboolean gst_vpx_enc_transform_meta (GstVideoEncoder * encoder, static gboolean gst_vpx_enc_transform_meta (GstVideoEncoder * encoder,
GstVideoCodecFrame * frame, GstMeta * meta); GstVideoCodecFrame * frame, GstMeta * meta);
#define GST_VPX_WARN(element, message, status) G_STMT_START { \
GST_WARNING_OBJECT (element, \
"%s: %s (details: %s)", \
#message, gst_vpx_error_name (status), GST_STR_NULL (element->encoder.err_detail)); \
} G_STMT_END
#define parent_class gst_vpx_enc_parent_class #define parent_class gst_vpx_enc_parent_class
G_DEFINE_TYPE_WITH_CODE (GstVPXEnc, gst_vpx_enc, GST_TYPE_VIDEO_ENCODER, G_DEFINE_TYPE_WITH_CODE (GstVPXEnc, gst_vpx_enc, GST_TYPE_VIDEO_ENCODER,
G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL); G_IMPLEMENT_INTERFACE (GST_TYPE_TAG_SETTER, NULL);
@ -915,7 +921,6 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
g_return_if_fail (GST_IS_VPX_ENC (object)); g_return_if_fail (GST_IS_VPX_ENC (object));
gst_vpx_enc = GST_VPX_ENC (object); gst_vpx_enc = GST_VPX_ENC (object);
GST_DEBUG_OBJECT (object, "gst_vpx_enc_set_property");
g_mutex_lock (&gst_vpx_enc->encoder_lock); g_mutex_lock (&gst_vpx_enc->encoder_lock);
switch (prop_id) { switch (prop_id) {
case PROP_RC_END_USAGE: case PROP_RC_END_USAGE:
@ -1141,9 +1146,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
status = status =
vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_SCALEMODE, &sm); vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_SCALEMODE, &sm);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_SCALEMODE",
"Failed to set VP8E_SET_SCALEMODE: %s", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1158,9 +1162,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
status = status =
vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_SCALEMODE, &sm); vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_SCALEMODE, &sm);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_SCALEMODE",
"Failed to set VP8E_SET_SCALEMODE: %s", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1171,8 +1174,7 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_CPUUSED, vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_CPUUSED,
gst_vpx_enc->cpu_used); gst_vpx_enc->cpu_used);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, "Failed to set VP8E_SET_CPUUSED: %s", GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_CPUUSED", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1183,9 +1185,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_ENABLEAUTOALTREF, vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_ENABLEAUTOALTREF,
(gst_vpx_enc->enable_auto_alt_ref ? 1 : 0)); (gst_vpx_enc->enable_auto_alt_ref ? 1 : 0));
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_ENABLEAUTOALTREF",
"Failed to set VP8E_SET_ENABLEAUTOALTREF: %s", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1196,9 +1197,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
vpx_codec_control (&gst_vpx_enc->encoder, vpx_codec_control (&gst_vpx_enc->encoder,
VP8E_SET_NOISE_SENSITIVITY, gst_vpx_enc->noise_sensitivity); VP8E_SET_NOISE_SENSITIVITY, gst_vpx_enc->noise_sensitivity);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_NOISE_SENSITIVITY",
"Failed to set VP8E_SET_NOISE_SENSITIVITY: %s", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1208,9 +1208,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
status = vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_SHARPNESS, status = vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_SHARPNESS,
gst_vpx_enc->sharpness); gst_vpx_enc->sharpness);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_SHARPNESS",
"Failed to set VP8E_SET_SHARPNESS: %s", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1221,9 +1220,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_STATIC_THRESHOLD, vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_STATIC_THRESHOLD,
gst_vpx_enc->static_threshold); gst_vpx_enc->static_threshold);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_STATIC_THRESHOLD",
"Failed to set VP8E_SET_STATIC_THRESHOLD: %s", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1234,9 +1232,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_TOKEN_PARTITIONS, vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_TOKEN_PARTITIONS,
gst_vpx_enc->token_partitions); gst_vpx_enc->token_partitions);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_TOKEN_PARTIONS",
"Failed to set VP8E_SET_TOKEN_PARTIONS: %s", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1247,9 +1244,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_ARNR_MAXFRAMES, vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_ARNR_MAXFRAMES,
gst_vpx_enc->arnr_maxframes); gst_vpx_enc->arnr_maxframes);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_ARNR_MAXFRAMES",
"Failed to set VP8E_SET_ARNR_MAXFRAMES: %s", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1260,9 +1256,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_ARNR_STRENGTH, vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_ARNR_STRENGTH,
gst_vpx_enc->arnr_strength); gst_vpx_enc->arnr_strength);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_ARNR_STRENGTH",
"Failed to set VP8E_SET_ARNR_STRENGTH: %s", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1277,8 +1272,7 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
status = vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_TUNING, status = vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_TUNING,
gst_vpx_enc->tuning); gst_vpx_enc->tuning);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_TUNING", status);
"Failed to set VP8E_SET_TUNING: %s", gst_vpx_error_name (status));
} }
} }
break; break;
@ -1288,9 +1282,7 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
status = vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_CQ_LEVEL, status = vpx_codec_control (&gst_vpx_enc->encoder, VP8E_SET_CQ_LEVEL,
gst_vpx_enc->cq_level); gst_vpx_enc->cq_level);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc, "Failed to set VP8E_SET_CQ_LEVEL", status);
"Failed to set VP8E_SET_CQ_LEVEL: %s",
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1301,9 +1293,8 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
vpx_codec_control (&gst_vpx_enc->encoder, vpx_codec_control (&gst_vpx_enc->encoder,
VP8E_SET_MAX_INTRA_BITRATE_PCT, gst_vpx_enc->max_intra_bitrate_pct); VP8E_SET_MAX_INTRA_BITRATE_PCT, gst_vpx_enc->max_intra_bitrate_pct);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (gst_vpx_enc, GST_VPX_WARN (gst_vpx_enc,
"Failed to set VP8E_SET_MAX_INTRA_BITRATE_PCT: %s", "Failed to set VP8E_SET_MAX_INTRA_BITRATE_PCT", status);
gst_vpx_error_name (status));
} }
} }
break; break;
@ -1327,9 +1318,12 @@ gst_vpx_enc_set_property (GObject * object, guint prop_id,
vpx_codec_enc_config_set (&gst_vpx_enc->encoder, &gst_vpx_enc->cfg); vpx_codec_enc_config_set (&gst_vpx_enc->encoder, &gst_vpx_enc->cfg);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
g_mutex_unlock (&gst_vpx_enc->encoder_lock); g_mutex_unlock (&gst_vpx_enc->encoder_lock);
GST_ELEMENT_ERROR (gst_vpx_enc, LIBRARY, INIT, GST_ELEMENT_ERROR_WITH_DETAILS (gst_vpx_enc, LIBRARY, INIT,
("Failed to set encoder configuration"), ("%s", ("Failed to set encoder configuration"), ("%s : %s",
gst_vpx_error_name (status))); gst_vpx_error_name (status),
GST_STR_NULL (gst_vpx_enc->encoder.err_detail)), ("details",
G_TYPE_STRING, GST_STR_NULL (gst_vpx_enc->encoder.err_detail),
NULL));
} else { } else {
g_mutex_unlock (&gst_vpx_enc->encoder_lock); g_mutex_unlock (&gst_vpx_enc->encoder_lock);
} }
@ -1829,8 +1823,11 @@ gst_vpx_enc_set_format (GstVideoEncoder * video_encoder,
vpx_codec_enc_init (&encoder->encoder, vpx_enc_class->get_algo (encoder), vpx_codec_enc_init (&encoder->encoder, vpx_enc_class->get_algo (encoder),
&encoder->cfg, flags); &encoder->cfg, flags);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_ELEMENT_ERROR (encoder, LIBRARY, INIT, GST_ELEMENT_ERROR_WITH_DETAILS (encoder, LIBRARY, INIT,
("Failed to initialize encoder"), ("%s", gst_vpx_error_name (status))); ("Failed to initialize encoder"), ("%s : %s",
gst_vpx_error_name (status),
GST_STR_NULL (encoder->encoder.err_detail)), ("details",
G_TYPE_STRING, GST_STR_NULL (encoder->encoder.err_detail), NULL));
g_mutex_unlock (&encoder->encoder_lock); g_mutex_unlock (&encoder->encoder_lock);
return FALSE; return FALSE;
} }
@ -1843,8 +1840,7 @@ gst_vpx_enc_set_format (GstVideoEncoder * video_encoder,
status = vpx_codec_control (&encoder->encoder, VP8E_SET_SCALEMODE, &sm); status = vpx_codec_control (&encoder->encoder, VP8E_SET_SCALEMODE, &sm);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, "Failed to set VP8E_SET_SCALEMODE: %s", GST_VPX_WARN (encoder, "Failed to set VP8E_SET_SCALEMODE", status);
gst_vpx_error_name (status));
} }
} }
@ -1852,77 +1848,60 @@ gst_vpx_enc_set_format (GstVideoEncoder * video_encoder,
vpx_codec_control (&encoder->encoder, VP8E_SET_CPUUSED, vpx_codec_control (&encoder->encoder, VP8E_SET_CPUUSED,
encoder->cpu_used); encoder->cpu_used);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, "Failed to set VP8E_SET_CPUUSED: %s", GST_VPX_WARN (encoder, "Failed to set VP8E_SET_CPUUSED", status);
gst_vpx_error_name (status));
} }
status = status =
vpx_codec_control (&encoder->encoder, VP8E_SET_ENABLEAUTOALTREF, vpx_codec_control (&encoder->encoder, VP8E_SET_ENABLEAUTOALTREF,
(encoder->enable_auto_alt_ref ? 1 : 0)); (encoder->enable_auto_alt_ref ? 1 : 0));
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_ENABLEAUTOALTREF", status);
"Failed to set VP8E_SET_ENABLEAUTOALTREF: %s",
gst_vpx_error_name (status));
} }
status = vpx_codec_control (&encoder->encoder, VP8E_SET_NOISE_SENSITIVITY, status = vpx_codec_control (&encoder->encoder, VP8E_SET_NOISE_SENSITIVITY,
encoder->noise_sensitivity); encoder->noise_sensitivity);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_NOISE_SENSITIVITY", status);
"Failed to set VP8E_SET_NOISE_SENSITIVITY: %s",
gst_vpx_error_name (status));
} }
status = vpx_codec_control (&encoder->encoder, VP8E_SET_SHARPNESS, status = vpx_codec_control (&encoder->encoder, VP8E_SET_SHARPNESS,
encoder->sharpness); encoder->sharpness);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_SHARPNESS", status);
"Failed to set VP8E_SET_SHARPNESS: %s", gst_vpx_error_name (status));
} }
status = vpx_codec_control (&encoder->encoder, VP8E_SET_STATIC_THRESHOLD, status = vpx_codec_control (&encoder->encoder, VP8E_SET_STATIC_THRESHOLD,
encoder->static_threshold); encoder->static_threshold);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_STATIC_THRESHOLD", status);
"Failed to set VP8E_SET_STATIC_THRESHOLD: %s",
gst_vpx_error_name (status));
} }
status = vpx_codec_control (&encoder->encoder, VP8E_SET_TOKEN_PARTITIONS, status = vpx_codec_control (&encoder->encoder, VP8E_SET_TOKEN_PARTITIONS,
encoder->token_partitions); encoder->token_partitions);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_TOKEN_PARTIONS", status);
"Failed to set VP8E_SET_TOKEN_PARTIONS: %s",
gst_vpx_error_name (status));
} }
status = vpx_codec_control (&encoder->encoder, VP8E_SET_ARNR_MAXFRAMES, status = vpx_codec_control (&encoder->encoder, VP8E_SET_ARNR_MAXFRAMES,
encoder->arnr_maxframes); encoder->arnr_maxframes);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_ARNR_MAXFRAMES", status);
"Failed to set VP8E_SET_ARNR_MAXFRAMES: %s",
gst_vpx_error_name (status));
} }
status = vpx_codec_control (&encoder->encoder, VP8E_SET_ARNR_STRENGTH, status = vpx_codec_control (&encoder->encoder, VP8E_SET_ARNR_STRENGTH,
encoder->arnr_strength); encoder->arnr_strength);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_ARNR_STRENGTH", status);
"Failed to set VP8E_SET_ARNR_STRENGTH: %s",
gst_vpx_error_name (status));
} }
status = vpx_codec_control (&encoder->encoder, VP8E_SET_TUNING, status = vpx_codec_control (&encoder->encoder, VP8E_SET_TUNING,
encoder->tuning); encoder->tuning);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_TUNING", status);
"Failed to set VP8E_SET_TUNING: %s", gst_vpx_error_name (status));
} }
status = vpx_codec_control (&encoder->encoder, VP8E_SET_CQ_LEVEL, status = vpx_codec_control (&encoder->encoder, VP8E_SET_CQ_LEVEL,
encoder->cq_level); encoder->cq_level);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_CQ_LEVEL", status);
"Failed to set VP8E_SET_CQ_LEVEL: %s", gst_vpx_error_name (status));
} }
status = vpx_codec_control (&encoder->encoder, VP8E_SET_MAX_INTRA_BITRATE_PCT, status = vpx_codec_control (&encoder->encoder, VP8E_SET_MAX_INTRA_BITRATE_PCT,
encoder->max_intra_bitrate_pct); encoder->max_intra_bitrate_pct);
if (status != VPX_CODEC_OK) { if (status != VPX_CODEC_OK) {
GST_WARNING_OBJECT (encoder, GST_VPX_WARN (encoder, "Failed to set VP8E_SET_MAX_INTRA_BITRATE_PCT",
"Failed to set VP8E_SET_MAX_INTRA_BITRATE_PCT: %s", status);
gst_vpx_error_name (status));
} }
if (vpx_enc_class->configure_encoder if (vpx_enc_class->configure_encoder
@ -2159,8 +2138,9 @@ gst_vpx_enc_drain (GstVideoEncoder * video_encoder)
g_mutex_unlock (&encoder->encoder_lock); g_mutex_unlock (&encoder->encoder_lock);
if (status != 0) { if (status != 0) {
GST_ERROR_OBJECT (encoder, "encode returned %d %s", status, GST_ERROR_OBJECT (encoder, "encode returned %d %s (details: %s)", status,
gst_vpx_error_name (status)); gst_vpx_error_name (status),
GST_STR_NULL (encoder->encoder.err_detail));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
@ -2342,8 +2322,10 @@ gst_vpx_enc_handle_frame (GstVideoEncoder * video_encoder,
gst_video_frame_unmap (&vframe); gst_video_frame_unmap (&vframe);
if (status != 0) { if (status != 0) {
GST_ELEMENT_ERROR (encoder, LIBRARY, ENCODE, GST_ELEMENT_ERROR_WITH_DETAILS (encoder, LIBRARY, ENCODE,
("Failed to encode frame"), ("%s", gst_vpx_error_name (status))); ("Failed to encode frame"), ("%s : %s", gst_vpx_error_name (status),
GST_STR_NULL (encoder->encoder.err_detail)), ("details",
G_TYPE_STRING, GST_STR_NULL (encoder->encoder.err_detail), NULL));
gst_video_codec_frame_set_user_data (frame, NULL, NULL); gst_video_codec_frame_set_user_data (frame, NULL, NULL);
gst_video_codec_frame_unref (frame); gst_video_codec_frame_unref (frame);