mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-05-18 00:12:46 +00:00
rsvgdec: Negotiate resolution with downstream and scale accordingly
Prefer the resolution given by the input but if downstream request a specific resolution then scale to this without regards to the aspect ratio. Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1538 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6613>
This commit is contained in:
parent
46a41667a3
commit
5d876ff774
|
@ -179,15 +179,64 @@ gst_rsvg_decode_image (GstRsvgDec * rsvg, GstBuffer * buffer,
|
||||||
|
|
||||||
output_state = gst_video_decoder_get_output_state (decoder);
|
output_state = gst_video_decoder_get_output_state (decoder);
|
||||||
if ((output_state == NULL)
|
if ((output_state == NULL)
|
||||||
|| GST_VIDEO_INFO_WIDTH (&output_state->info) != dimension.width
|
|| rsvg->dimension.width != dimension.width
|
||||||
|| GST_VIDEO_INFO_HEIGHT (&output_state->info) != dimension.height) {
|
|| rsvg->dimension.height != dimension.height) {
|
||||||
|
GstCaps *peer_caps;
|
||||||
|
GstCaps *source_caps;
|
||||||
|
GstCaps *templ_caps;
|
||||||
|
|
||||||
/* Create the output state */
|
templ_caps =
|
||||||
if (output_state)
|
gst_pad_get_pad_template_caps (GST_VIDEO_DECODER_SRC_PAD (rsvg));
|
||||||
gst_video_codec_state_unref (output_state);
|
peer_caps =
|
||||||
output_state =
|
gst_pad_peer_query_caps (GST_VIDEO_DECODER_SRC_PAD (rsvg), templ_caps);
|
||||||
gst_video_decoder_set_output_state (decoder, GST_RSVG_VIDEO_FORMAT,
|
|
||||||
dimension.width, dimension.height, rsvg->input_state);
|
GST_DEBUG_OBJECT (rsvg,
|
||||||
|
"Trying to negotiate for SVG resolution %ux%u with downstream caps %"
|
||||||
|
GST_PTR_FORMAT, dimension.width, 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,
|
||||||
|
"height", G_TYPE_INT, dimension.height, "pixel-aspect-ratio",
|
||||||
|
GST_TYPE_FRACTION, 1, 1, NULL);
|
||||||
|
|
||||||
|
if (gst_caps_can_intersect (source_caps, peer_caps)
|
||||||
|
|| gst_caps_is_empty (peer_caps)) {
|
||||||
|
GST_DEBUG_OBJECT (rsvg, "Using input resolution");
|
||||||
|
if (output_state)
|
||||||
|
gst_video_codec_state_unref (output_state);
|
||||||
|
output_state =
|
||||||
|
gst_video_decoder_set_output_state (decoder, GST_RSVG_VIDEO_FORMAT,
|
||||||
|
dimension.width, dimension.height, rsvg->input_state);
|
||||||
|
output_state->info.par_n = 1;
|
||||||
|
output_state->info.par_d = 1;
|
||||||
|
} else {
|
||||||
|
GstVideoInfo info;
|
||||||
|
GstStructure *s;
|
||||||
|
|
||||||
|
peer_caps = gst_caps_make_writable (peer_caps);
|
||||||
|
peer_caps = gst_caps_truncate (peer_caps);
|
||||||
|
s = gst_caps_get_structure (peer_caps, 0);
|
||||||
|
gst_structure_fixate_field_nearest_int (s, "width", dimension.width);
|
||||||
|
gst_structure_fixate_field_nearest_int (s, "height", dimension.height);
|
||||||
|
peer_caps = gst_caps_fixate (peer_caps);
|
||||||
|
|
||||||
|
gst_video_info_from_caps (&info, peer_caps);
|
||||||
|
|
||||||
|
if (output_state)
|
||||||
|
gst_video_codec_state_unref (output_state);
|
||||||
|
output_state =
|
||||||
|
gst_video_decoder_set_output_state (decoder, GST_RSVG_VIDEO_FORMAT,
|
||||||
|
info.width, info.height, rsvg->input_state);
|
||||||
|
GST_DEBUG_OBJECT (rsvg,
|
||||||
|
"Using resolution %ux%u with pixel-aspect-ratio %u/%u",
|
||||||
|
output_state->info.width, output_state->info.height,
|
||||||
|
output_state->info.par_n, output_state->info.par_d);
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_clear_caps (&source_caps);
|
||||||
|
gst_clear_caps (&peer_caps);
|
||||||
|
|
||||||
|
rsvg->dimension = dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gst_video_decoder_allocate_output_frame (decoder, frame);
|
ret = gst_video_decoder_allocate_output_frame (decoder, frame);
|
||||||
|
@ -236,6 +285,7 @@ gst_rsvg_decode_image (GstRsvgDec * rsvg, GstBuffer * buffer,
|
||||||
((gdouble) GST_VIDEO_INFO_HEIGHT (&output_state->info)) /
|
((gdouble) GST_VIDEO_INFO_HEIGHT (&output_state->info)) /
|
||||||
((gdouble) dimension.height);
|
((gdouble) dimension.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_scale (cr, scalex, scaley);
|
cairo_scale (cr, scalex, scaley);
|
||||||
rsvg_handle_render_cairo (handle, cr);
|
rsvg_handle_render_cairo (handle, cr);
|
||||||
|
|
||||||
|
@ -259,18 +309,11 @@ static gboolean
|
||||||
gst_rsvg_dec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
|
gst_rsvg_dec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
|
||||||
{
|
{
|
||||||
GstRsvgDec *rsvg = GST_RSVG_DEC (decoder);
|
GstRsvgDec *rsvg = GST_RSVG_DEC (decoder);
|
||||||
GstVideoInfo *info = &state->info;
|
|
||||||
|
|
||||||
if (rsvg->input_state)
|
if (rsvg->input_state)
|
||||||
gst_video_codec_state_unref (rsvg->input_state);
|
gst_video_codec_state_unref (rsvg->input_state);
|
||||||
rsvg->input_state = gst_video_codec_state_ref (state);
|
rsvg->input_state = gst_video_codec_state_ref (state);
|
||||||
|
|
||||||
/* Create the output state */
|
|
||||||
state = gst_video_decoder_set_output_state (decoder, GST_RSVG_VIDEO_FORMAT,
|
|
||||||
GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info),
|
|
||||||
rsvg->input_state);
|
|
||||||
gst_video_codec_state_unref (state);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,5 +413,7 @@ gst_rsvg_dec_stop (GstVideoDecoder * decoder)
|
||||||
rsvg->input_state = NULL;
|
rsvg->input_state = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memset (&rsvg->dimension, 0, sizeof (RsvgDimensionData));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ struct _GstRsvgDec
|
||||||
guint64 frame_count;
|
guint64 frame_count;
|
||||||
|
|
||||||
GstVideoCodecState *input_state;
|
GstVideoCodecState *input_state;
|
||||||
|
RsvgDimensionData dimension;
|
||||||
|
|
||||||
GstSegment segment;
|
GstSegment segment;
|
||||||
gboolean need_newsegment;
|
gboolean need_newsegment;
|
||||||
|
|
Loading…
Reference in a new issue