From 1f59906ec1a20645b1c299e835fa2d14c197b5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Thu, 24 Feb 2011 15:32:00 +0000 Subject: [PATCH] filesrc, filesink: fix URI creation regression for non-absolute locations Passing e.g. location=foo would lead to warnings because g_filename_to_uri() wants an absolute file path and returns NULL otherwise. Use brand-new gst_filename_to_uri() instead, which will try harder to create a proper URI for us. Also add unit test. --- plugins/elements/gstfilesink.c | 4 ++- plugins/elements/gstfilesrc.c | 6 ++-- tests/check/elements/filesrc.c | 62 ++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/plugins/elements/gstfilesink.c b/plugins/elements/gstfilesink.c index 2431c14338..d5fa283298 100644 --- a/plugins/elements/gstfilesink.c +++ b/plugins/elements/gstfilesink.c @@ -302,7 +302,9 @@ gst_file_sink_set_location (GstFileSink * sink, const gchar * location) /* we store the filename as we received it from the application. On Windows * this should be in UTF8 */ sink->filename = g_strdup (location); - sink->uri = g_filename_to_uri (sink->filename, NULL, NULL); + sink->uri = gst_filename_to_uri (location, NULL); + GST_INFO ("filename : %s", sink->filename); + GST_INFO ("uri : %s", sink->uri); } else { sink->filename = NULL; sink->uri = NULL; diff --git a/plugins/elements/gstfilesrc.c b/plugins/elements/gstfilesrc.c index b14bf2d185..16a3e0300f 100644 --- a/plugins/elements/gstfilesrc.c +++ b/plugins/elements/gstfilesrc.c @@ -367,10 +367,12 @@ gst_file_src_set_location (GstFileSrc * src, const gchar * location) src->filename = NULL; src->uri = NULL; } else { - /* we store the filename as received by the application. On Windoes this + /* we store the filename as received by the application. On Windows this * should be UTF8 */ src->filename = g_strdup (location); - src->uri = g_filename_to_uri (src->filename, NULL, NULL); + src->uri = gst_filename_to_uri (location, NULL); + GST_INFO ("filename : %s", src->filename); + GST_INFO ("uri : %s", src->uri); } g_object_notify (G_OBJECT (src), "location"); gst_uri_handler_new_uri (GST_URI_HANDLER (src), src->uri); diff --git a/tests/check/elements/filesrc.c b/tests/check/elements/filesrc.c index 71a09f0f0f..970ca9ad0b 100644 --- a/tests/check/elements/filesrc.c +++ b/tests/check/elements/filesrc.c @@ -384,6 +384,67 @@ GST_START_TEST (test_uri_interface) GST_END_TEST; +static void +check_uri_for_location (GstElement * e, const gchar * location, + const gchar * uri) +{ + GstQuery *query; + gchar *query_uri = NULL; + + g_object_set (e, "location", location, NULL); + query = gst_query_new_uri (); + fail_unless (gst_element_query (e, query)); + gst_query_parse_uri (query, &query_uri); + gst_query_unref (query); + + if (uri != NULL) { + fail_unless_equals_string (query_uri, uri); + } else { + gchar *fn; + + fail_unless (gst_uri_is_valid (query_uri)); + fn = g_filename_from_uri (query_uri, NULL, NULL); + fail_unless (g_path_is_absolute (fn)); + fail_unless (fn != NULL); + g_free (fn); + } + + g_free (query_uri); +} + +GST_START_TEST (test_uri_query) +{ + GstElement *src; + + src = setup_filesrc (); + +#ifdef G_OS_UNIX + { + GST_INFO ("*nix"); + check_uri_for_location (src, "/i/do/not/exist", "file:///i/do/not/exist"); + check_uri_for_location (src, "/i/do/not/../exist", "file:///i/do/exist"); + check_uri_for_location (src, "/i/do/not/.././exist", "file:///i/do/exist"); + check_uri_for_location (src, "/i/./do/not/../exist", "file:///i/do/exist"); + check_uri_for_location (src, "/i/do/./not/../exist", "file:///i/do/exist"); + check_uri_for_location (src, "/i/do/not/./../exist", "file:///i/do/exist"); + check_uri_for_location (src, "/i/./do/./././././exist", + "file:///i/do/exist"); + check_uri_for_location (src, "/i/do/not/../../exist", "file:///i/exist"); + check_uri_for_location (src, "/i/../not/../exist", "file:///exist"); + /* hard to test relative URIs, just make sure it returns an URI of sorts */ + check_uri_for_location (src, "foo", NULL); + check_uri_for_location (src, "foo/../bar", NULL); + check_uri_for_location (src, "./foo", NULL); + check_uri_for_location (src, "../foo", NULL); + check_uri_for_location (src, "foo/./bar", NULL); + } +#endif + + cleanup_filesrc (src); +} + +GST_END_TEST; + static Suite * filesrc_suite (void) { @@ -396,6 +457,7 @@ filesrc_suite (void) tcase_add_test (tc_chain, test_pull); tcase_add_test (tc_chain, test_coverage); tcase_add_test (tc_chain, test_uri_interface); + tcase_add_test (tc_chain, test_uri_query); return s; }