From b660f258a6ba0a6f6d2b78904bb994779f403b78 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Tue, 22 Jun 2021 12:28:03 +0200 Subject: [PATCH] theoradec: make sure the selected pool accepts the new config If gst_buffer_pool_set_config() fails then the pool will use its old config. This may include different width or height when pic_width/pic_height != frame_width/frame_height. As a result, the assertions in theora_handle_image() will fail. So check the result of gst_buffer_pool_set_config() and only use the pool if it succeeds. Otherwise let the parrent decide_allocation() create a new pool. Part-of: --- .../ext/theora/gsttheoradec.c | 85 ++++++----- .../tests/check/elements/theoradec.c | 138 ++++++++++++++++++ .../gst-plugins-base/tests/check/meson.build | 1 + .../gst-plugins-base/tests/files/theora.ogg | Bin 0 -> 5746 bytes 4 files changed, 188 insertions(+), 36 deletions(-) create mode 100644 subprojects/gst-plugins-base/tests/check/elements/theoradec.c create mode 100644 subprojects/gst-plugins-base/tests/files/theora.ogg diff --git a/subprojects/gst-plugins-base/ext/theora/gsttheoradec.c b/subprojects/gst-plugins-base/ext/theora/gsttheoradec.c index 827a7c85a5..351e6f92da 100644 --- a/subprojects/gst-plugins-base/ext/theora/gsttheoradec.c +++ b/subprojects/gst-plugins-base/ext/theora/gsttheoradec.c @@ -926,46 +926,59 @@ theora_dec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) guint size, min, max; GstStructure *config; - if (!GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder, - query)) - return FALSE; + if ((dec->info.pic_width != dec->info.frame_width || + dec->info.pic_height != dec->info.frame_height) && + (gst_query_get_n_allocation_pools (query) > 0)) { + gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max); - gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max); + if (pool) { + dec->can_crop = FALSE; + config = gst_buffer_pool_get_config (pool); + if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) { + gst_buffer_pool_config_add_option (config, + GST_BUFFER_POOL_OPTION_VIDEO_META); + dec->can_crop = + gst_query_find_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, + NULL); + } - dec->can_crop = FALSE; - config = gst_buffer_pool_get_config (pool); - if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) { - gst_buffer_pool_config_add_option (config, - GST_BUFFER_POOL_OPTION_VIDEO_META); - dec->can_crop = - gst_query_find_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, - NULL); + if (dec->can_crop) { + GstVideoInfo *info = &dec->uncropped_info; + GstCaps *caps; + + GST_LOG_OBJECT (decoder, + "Using GstVideoCropMeta, uncropped wxh = %dx%d", info->width, + info->height); + + gst_video_info_set_format (info, info->finfo->format, + dec->info.frame_width, dec->info.frame_height); + + /* Calculate uncropped size */ + size = MAX (size, info->size); + caps = gst_video_info_to_caps (info); + gst_buffer_pool_config_set_params (config, caps, size, min, max); + gst_caps_unref (caps); + } + + if (gst_buffer_pool_set_config (pool, config)) { + gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max); + } else { + GstVideoInfo *info = &dec->uncropped_info; + + GST_DEBUG_OBJECT (dec, "ignoring unusable pool"); + + gst_query_remove_nth_allocation_pool (query, 0); + gst_video_info_set_format (info, info->finfo->format, + dec->info.pic_width, dec->info.pic_height); + dec->can_crop = FALSE; + } + + gst_object_unref (pool); + } } - if (dec->can_crop) { - GstVideoInfo *info = &dec->uncropped_info; - GstCaps *caps; - - GST_LOG_OBJECT (decoder, "Using GstVideoCropMeta, uncropped wxh = %dx%d", - info->width, info->height); - - gst_video_info_set_format (info, info->finfo->format, dec->info.frame_width, - dec->info.frame_height); - - /* Calculate uncropped size */ - size = MAX (size, info->size); - caps = gst_video_info_to_caps (info); - gst_buffer_pool_config_set_params (config, caps, size, min, max); - gst_caps_unref (caps); - } - - gst_buffer_pool_set_config (pool, config); - - gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max); - - gst_object_unref (pool); - - return TRUE; + return GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder, + query); } static void diff --git a/subprojects/gst-plugins-base/tests/check/elements/theoradec.c b/subprojects/gst-plugins-base/tests/check/elements/theoradec.c new file mode 100644 index 0000000000..909dd1d2dd --- /dev/null +++ b/subprojects/gst-plugins-base/tests/check/elements/theoradec.c @@ -0,0 +1,138 @@ +/* GStreamer + * + * Copyright (C) <2021> Michael Olbrich + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +static GstPadProbeReturn +query_handler (GstPad * pad, GstPadProbeInfo * info, gpointer user_data) +{ + GstQuery *query = GST_PAD_PROBE_INFO_QUERY (info); + GstBufferPool *pool; + GstStructure *config; + GstVideoInfo vinfo; + GstCaps *caps; + + if (GST_QUERY_TYPE (query) != GST_QUERY_ALLOCATION) + return GST_PAD_PROBE_OK; + + gst_query_parse_allocation (query, &caps, NULL); + fail_unless (caps != NULL); + + gst_video_info_init (&vinfo); + gst_video_info_from_caps (&vinfo, caps); + + pool = gst_video_buffer_pool_new (); + config = gst_buffer_pool_get_config (pool); + gst_buffer_pool_config_set_params (config, caps, vinfo.size, 0, 1); + gst_buffer_pool_set_config (pool, config); + /* activate the pool to ensure that gst_buffer_pool_set_config() will + * fail later */ + gst_buffer_pool_set_active (pool, TRUE); + gst_query_add_allocation_pool (query, pool, vinfo.size, 0, 1); + gst_object_unref (pool); + gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL); + gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, NULL); + + return GST_PAD_PROBE_OK; +} + +static void +demux_pad_added_cb (GstElement * dec, GstPad * pad, gpointer user_data) +{ + GstElement *sink = user_data; + GstPad *sinkpad; + + sinkpad = gst_element_get_static_pad (sink, "sink"); + gst_pad_link (pad, sinkpad); + gst_object_unref (sinkpad); +} + +GST_START_TEST (test_decide_allocation) +{ + GstElement *pipe, *src, *demux, *decode, *sink; + GstStateChangeReturn sret; + GstMessage *msg; + GstPad *pad; + gchar *path; + + pipe = gst_pipeline_new (NULL); + + src = gst_element_factory_make ("filesrc", NULL); + fail_unless (src != NULL, "Failed to create filesrc element"); + + demux = gst_element_factory_make ("oggdemux", NULL); + fail_unless (demux != NULL, "Failed to create oggdemux element"); + + decode = gst_element_factory_make ("theoradec", NULL); + fail_unless (decode != NULL, "Failed to create theoradec element"); + + sink = gst_element_factory_make ("fakesink", NULL); + fail_unless (sink != NULL, "Failed to create fakesink element"); + + gst_bin_add_many (GST_BIN (pipe), src, demux, decode, sink, NULL); + gst_element_link (src, demux); + gst_element_link (decode, sink); + + path = g_build_filename (GST_TEST_FILES_PATH, "theora.ogg", NULL); + g_object_set (src, "location", path, NULL); + g_free (path); + + g_signal_connect (demux, "pad-added", + G_CALLBACK (demux_pad_added_cb), decode); + + pad = gst_element_get_static_pad (decode, "src"); + gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM, + query_handler, NULL, NULL); + gst_object_unref (pad); + + sret = gst_element_set_state (pipe, GST_STATE_PLAYING); + fail_unless_equals_int (sret, GST_STATE_CHANGE_ASYNC); + + /* wait for EOS or error */ + msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipe), + GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); + fail_unless (msg != NULL); + fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS); + gst_message_unref (msg); + + gst_element_set_state (pipe, GST_STATE_NULL); + gst_object_unref (pipe); +} + +GST_END_TEST; + + +static Suite * +theoradec_suite (void) +{ + Suite *s = suite_create ("theoradec"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_decide_allocation); + + return s; +} + +GST_CHECK_MAIN (theoradec); diff --git a/subprojects/gst-plugins-base/tests/check/meson.build b/subprojects/gst-plugins-base/tests/check/meson.build index b5a749429c..dfcb92b547 100644 --- a/subprojects/gst-plugins-base/tests/check/meson.build +++ b/subprojects/gst-plugins-base/tests/check/meson.build @@ -73,6 +73,7 @@ if host_machine.system() != 'windows' [ 'elements/multisocketsink.c', not core_conf.has('HAVE_SYS_SOCKET_H') or not core_conf.has('HAVE_UNISTD_H') ], [ 'elements/playbin-complex.c', not ogg_dep.found() ], [ 'elements/textoverlay.c', not pango_dep.found() ], + [ 'elements/theoradec.c', not ogg_dep.found() and theoradec_dep.found() ], [ 'elements/vorbisdec.c', not vorbis_dep.found(), [ vorbis_dep, vorbisenc_dep ] ], [ 'elements/vorbistag.c', not vorbisenc_dep.found(), [ vorbis_dep, vorbisenc_dep ] ], [ 'pipelines/oggmux.c', not ogg_dep.found(), [ ogg_dep, ] ], diff --git a/subprojects/gst-plugins-base/tests/files/theora.ogg b/subprojects/gst-plugins-base/tests/files/theora.ogg new file mode 100644 index 0000000000000000000000000000000000000000..7f2a7789c3e8a96d0bb846faf01e6bc21a2649f0 GIT binary patch literal 5746 zcmai0Rag|<+8w03LqPA)v&SA20Q@#i;v}nZue%jI8p$O6YBQH%E{Fn{Q(-_A%Gl! z77swBSDzf2}oDQ{eHGNXCglAl_YMJs_j8O%h2 z9h}fLZYe+&jR^_lPX;sI1@gMSnsHO&h6FJjzu~92&Y+%7(bb_K`#zBn|5AgPaC9Ul zT2)mA4-e<-*Macx@GvkK{2cQR=skbY9rOP#d++~;02&&aY+(0;z<((CU&8ns4937fyUX1X2HHP__293Eh4U}r zps(LFjS~uyf0p~Ox)<5eV$HOqNV_WS8p&j`Iy>lRSN6#I734q;W7F&+wpewCfBr{U zzb=P~Ut9QQPOtD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