From b8db4739551401c653f2ae55f39d1ab77e3a5ef5 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Thu, 11 Apr 2024 19:54:45 -0300 Subject: [PATCH] rsvgdec: Fix uses of librsvg functions deprecated since 2.52 Part-of: --- .../gst-plugins-bad/ext/rsvg/gstrsvgdec.c | 33 ++++++++++++++++--- .../gst-plugins-bad/ext/rsvg/gstrsvgdec.h | 11 ++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/rsvg/gstrsvgdec.c b/subprojects/gst-plugins-bad/ext/rsvg/gstrsvgdec.c index ac0c4ddd1a..b119a3abc5 100644 --- a/subprojects/gst-plugins-bad/ext/rsvg/gstrsvgdec.c +++ b/subprojects/gst-plugins-bad/ext/rsvg/gstrsvgdec.c @@ -156,8 +156,12 @@ gst_rsvg_decode_image (GstRsvgDec * rsvg, GstBuffer * buffer, cairo_surface_t *surface; RsvgHandle *handle; GError *error = NULL; - RsvgDimensionData dimension; +#if LIBRSVG_MAJOR_VERSION > (2) || (LIBRSVG_MAJOR_VERSION == (2) && LIBRSVG_MINOR_VERSION > (52)) + RsvgRectangle viewport; +#else gdouble scalex, scaley; +#endif + GstRsvgDimension dimension; GstMapInfo minfo; GstVideoFrame vframe; GstVideoCodecState *output_state; @@ -174,8 +178,12 @@ gst_rsvg_decode_image (GstRsvgDec * rsvg, GstBuffer * buffer, g_error_free (error); return GST_FLOW_ERROR; } - +#if LIBRSVG_MAJOR_VERSION > (2) || (LIBRSVG_MAJOR_VERSION == (2) && LIBRSVG_MINOR_VERSION > (52)) + rsvg_handle_get_intrinsic_size_in_pixels (handle, &dimension.width, + &dimension.height); +#else rsvg_handle_get_dimensions (handle, &dimension); +#endif output_state = gst_video_decoder_get_output_state (decoder); if ((output_state == NULL) @@ -191,8 +199,9 @@ gst_rsvg_decode_image (GstRsvgDec * rsvg, GstBuffer * buffer, gst_pad_peer_query_caps (GST_VIDEO_DECODER_SRC_PAD (rsvg), templ_caps); GST_DEBUG_OBJECT (rsvg, - "Trying to negotiate for SVG resolution %ux%u with downstream caps %" - GST_PTR_FORMAT, dimension.width, dimension.height, peer_caps); + "Trying to negotiate for SVG resolution %" G_GUINT64_FORMAT "x %" + G_GUINT64_FORMAT " with downstream caps %" GST_PTR_FORMAT, + (guint64) dimension.width, (guint64) dimension.height, peer_caps); source_caps = gst_caps_make_writable (g_steal_pointer (&templ_caps)); gst_caps_set_simple (source_caps, "width", G_TYPE_INT, dimension.width, @@ -274,6 +283,21 @@ gst_rsvg_decode_image (GstRsvgDec * rsvg, GstBuffer * buffer, cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0); +#if LIBRSVG_MAJOR_VERSION > (2) || (LIBRSVG_MAJOR_VERSION == (2) && LIBRSVG_MINOR_VERSION > (52)) + viewport.x = 0; + viewport.y = 0; + viewport.width = GST_VIDEO_INFO_WIDTH (&output_state->info); + viewport.height = GST_VIDEO_INFO_HEIGHT (&output_state->info); + if (!rsvg_handle_render_document (handle, cr, &viewport, &error)) { + GST_ERROR_OBJECT (rsvg, "Failed to render SVG image: %s", error->message); + g_error_free (error); + g_object_unref (handle); + cairo_destroy (cr); + cairo_surface_destroy (surface); + gst_video_codec_state_unref (output_state); + return GST_FLOW_ERROR; + } +#else scalex = scaley = 1.0; if (GST_VIDEO_INFO_WIDTH (&output_state->info) != dimension.width) { scalex = @@ -288,6 +312,7 @@ gst_rsvg_decode_image (GstRsvgDec * rsvg, GstBuffer * buffer, cairo_scale (cr, scalex, scaley); rsvg_handle_render_cairo (handle, cr); +#endif g_object_unref (handle); cairo_destroy (cr); diff --git a/subprojects/gst-plugins-bad/ext/rsvg/gstrsvgdec.h b/subprojects/gst-plugins-bad/ext/rsvg/gstrsvgdec.h index 33a875789b..2c90776b48 100644 --- a/subprojects/gst-plugins-bad/ext/rsvg/gstrsvgdec.h +++ b/subprojects/gst-plugins-bad/ext/rsvg/gstrsvgdec.h @@ -44,6 +44,15 @@ G_BEGIN_DECLS typedef struct _GstRsvgDec GstRsvgDec; typedef struct _GstRsvgDecClass GstRsvgDecClass; +#if LIBRSVG_MAJOR_VERSION > (2) || (LIBRSVG_MAJOR_VERSION == (2) && LIBRSVG_MINOR_VERSION > (52)) +typedef struct +{ + gdouble width, height; +} GstRsvgDimension; +#else +typedef RsvgDimensionData GstRsvgDimension; +#endif + struct _GstRsvgDec { GstVideoDecoder decoder; @@ -57,7 +66,7 @@ struct _GstRsvgDec guint64 frame_count; GstVideoCodecState *input_state; - RsvgDimensionData dimension; + GstRsvgDimension dimension; GstSegment segment; gboolean need_newsegment;