<div dir="auto"><div>Thanks<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 13 Aug, 2021, 18:27 Laurent Pinchart, <<a href="mailto:laurent.pinchart@ideasonboard.com">laurent.pinchart@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Vedant,<br>
<br>
Thank you for the patch.<br>
<br>
On Fri, Aug 13, 2021 at 04:13:02PM +0530, Vedant Paranjape wrote:<br>
> This patch adds a test to test if single stream using<br>
> libcamera's gstreamer element works.<br>
> <br>
> Signed-off-by: Vedant Paranjape <<a href="mailto:vedantparanjape160201@gmail.com" target="_blank" rel="noreferrer">vedantparanjape160201@gmail.com</a>><br>
> Reviewed-by: Paul Elder <<a href="mailto:paul.elder@ideasonboard.com" target="_blank" rel="noreferrer">paul.elder@ideasonboard.com</a>><br>
> Reviewed-by: Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank" rel="noreferrer">kieran.bingham@ideasonboard.com</a>><br>
> ---<br>
>  .../gstreamer_single_stream_test.cpp          | 153 ++++++++++++++++++<br>
>  test/gstreamer/meson.build                    |  19 +++<br>
>  test/meson.build                              |   1 +<br>
>  3 files changed, 173 insertions(+)<br>
>  create mode 100644 test/gstreamer/gstreamer_single_stream_test.cpp<br>
>  create mode 100644 test/gstreamer/meson.build<br>
> <br>
> diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp<br>
> new file mode 100644<br>
> index 00000000..eecd3274<br>
> --- /dev/null<br>
> +++ b/test/gstreamer/gstreamer_single_stream_test.cpp<br>
> @@ -0,0 +1,153 @@<br>
> +/* SPDX-License-Identifier: GPL-2.0-or-later */<br>
> +/*<br>
> + * Copyright (C) 2021, Vedant Paranjape<br>
> + *<br>
> + * ipa_interface_test.cpp - Test the IPA interface<br>
> + */<br>
> +<br>
> +#include <iostream><br>
> +<br>
> +#include <libcamera/base/utils.h><br>
> +<br>
> +#include <gst/gst.h><br>
> +<br>
> +#include "test.h"<br>
> +<br>
> +using namespace std;<br>
> +<br>
> +class GstreamerSingleStreamTest : public Test<br>
> +{<br>
> +protected:<br>
> +     int init() override<br>
> +     {<br>
> +             /* Initialize GStreamer */<br>
> +             GError *errInit = nullptr;<br>
> +             if (!gst_init_check(nullptr, nullptr, &errInit)) {<br>
> +                     g_printerr("Could not initialize GStreamer: %s\n",<br>
> +                                errInit ? errInit->message : "unknown error");<br>
> +                     if (errInit)<br>
> +                             g_error_free(errInit);<br>
> +<br>
> +                     return TestFail;<br>
> +             }<br>
> +<br>
> +             /*<br>
> +             * Remove the system libcamera plugin, if any, and add the<br>
> +             * plugin from the build directory.<br>
> +             */<br>
<br>
Missing space before *<br>
<br>
> +             GstRegistry *registry = gst_registry_get();<br>
> +             GstPlugin *plugin = gst_registry_lookup(registry, "libgstlibcamera.so");<br>
> +             if (plugin) {<br>
> +                     gst_registry_remove_plugin(registry, plugin);<br>
> +                     gst_object_unref(plugin);<br>
> +             }<br>
> +             <br>
<br>
Extra blank spaces at the end of the line.<br>
<br>
> +             std::string path = std::string(libcamera::utils::libcameraBuildPath()<br>
> +                                     + "src/gstreamer");<br>
<br>
No need for calling the std::string constructor explictly,<br>
libcamera::utils::libcameraBuildPath() returns an std::string and the<br>
result of the operator+() call is also an std::string.<br>
<br>
You should #include "libcamera/internal/source_paths.h"" for<br>
libcamera::utils::libcameraBuildPath().<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">I thought, It's "internal" so shouldn't be used in a public library. :D</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'll fix these small issues when applying.<br>
<br>
> +             if (!gst_registry_scan_path(registry, path.c_str())) {<br>
> +                     g_printerr("Failed to add plugin to registry\n");<br>
> +                     gst_deinit();<br>
> +                     return TestFail;<br>
> +             }<br>
> +<br>
> +             /* Create the elements */<br>
> +             libcameraSrc_ = gst_element_factory_make("libcamerasrc", "libcamera");<br>
> +             convert0_ = gst_element_factory_make("videoconvert", "convert0");<br>
> +             sink0_ = gst_element_factory_make("fakesink", "sink0");<br>
> +<br>
> +             /* Create the empty pipeline_ */<br>
> +             pipeline_ = gst_pipeline_new("test-pipeline");<br>
> +<br>
> +             if (!pipeline_ || !convert0_ || !sink0_ || !libcameraSrc_) {<br>
> +                     g_printerr("Not all elements could be created. %p.%p.%p.%p\n",<br>
> +                                pipeline_, convert0_, sink0_, libcameraSrc_);<br>
> +                     if (pipeline_)<br>
> +                             gst_object_unref(pipeline_);<br>
> +                     if (convert0_)<br>
> +                             gst_object_unref(convert0_);<br>
> +                     if (sink0_)<br>
> +                             gst_object_unref(sink0_);<br>
> +                     if (libcameraSrc_)<br>
> +                             gst_object_unref(libcameraSrc_);<br>
> +                     gst_deinit();<br>
> +<br>
> +                     return TestFail;<br>
> +             }<br>
> +<br>
> +             return TestPass;<br>
> +     }<br>
> +<br>
> +     void cleanup() override<br>
> +     {<br>
> +             gst_object_unref(pipeline_);<br>
> +             gst_deinit();<br>
> +     }<br>
> +<br>
> +     int run() override<br>
> +     {<br>
> +             GstStateChangeReturn ret;<br>
> +             g_autoptr(GstBus) bus;<br>
> +             g_autoptr(GstMessage) msg;<br>
> +<br>
> +             /* Build the pipeline */<br>
> +             gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, convert0_, sink0_, NULL);<br>
> +             if (gst_element_link_many(libcameraSrc_, convert0_, sink0_, NULL) != TRUE) {<br>
> +                     g_printerr("Elements could not be linked.\n");<br>
> +                     return TestFail;<br>
> +             }<br>
> +<br>
> +             /* Start playing */<br>
> +             ret = gst_element_set_state(pipeline_, GST_STATE_PLAYING);<br>
> +             if (ret == GST_STATE_CHANGE_FAILURE) {<br>
> +                     g_printerr("Unable to set the pipeline to the playing state.\n");<br>
> +                     return TestFail;<br>
> +             }<br>
> +<br>
> +             /* Wait until error or EOS or timeout after 2 seconds */<br>
> +             GstClockTime timeout = 2000000000;<br>
> +             bus = gst_element_get_bus(pipeline_);<br>
> +             msg = gst_bus_timed_pop_filtered(bus, timeout,<br>
> +                                              GstMessageType((uint)GST_MESSAGE_ERROR | (uint)GST_MESSAGE_EOS));<br>
> +             gst_element_set_state(pipeline_, GST_STATE_NULL);<br>
> +<br>
> +             /* Parse error message */<br>
> +             if (msg == NULL)<br>
> +                     return TestPass;<br>
> +<br>
> +             switch (GST_MESSAGE_TYPE(msg)) {<br>
> +             case GST_MESSAGE_ERROR:<br>
> +                     gstreamer_print_error(msg);<br>
> +                     break;<br>
> +             case GST_MESSAGE_EOS:<br>
> +                     g_print("End-Of-Stream reached.\n");<br>
> +                     break;<br>
> +             default:<br>
> +                     g_printerr("Unexpected message received.\n");<br>
> +                     break;<br>
> +             }<br>
> +<br>
> +             return TestFail;<br>
> +     }<br>
> +<br>
> +private:<br>
> +     void gstreamer_print_error(GstMessage *msg)<br>
> +     {<br>
> +             GError *err;<br>
> +             gchar *debug_info;<br>
> +<br>
> +             gst_message_parse_error(msg, &err, &debug_info);<br>
> +             g_printerr("Error received from element %s: %s\n",<br>
> +                        GST_OBJECT_NAME(msg->src), err->message);<br>
> +             g_printerr("Debugging information: %s\n",<br>
> +                        debug_info ? debug_info : "none");<br>
> +             g_clear_error(&err);<br>
> +             g_free(debug_info);<br>
> +     }<br>
> +<br>
> +     GstElement *pipeline_;<br>
> +     GstElement *libcameraSrc_;<br>
> +     GstElement *convert0_;<br>
> +     GstElement *sink0_;<br>
> +};<br>
> +<br>
> +TEST_REGISTER(GstreamerSingleStreamTest)<br>
> diff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build<br>
> new file mode 100644<br>
> index 00000000..b99aa0da<br>
> --- /dev/null<br>
> +++ b/test/gstreamer/meson.build<br>
> @@ -0,0 +1,19 @@<br>
> +# SPDX-License-Identifier: CC0-1.0<br>
> +<br>
> +if not gst_enabled<br>
> +    subdir_done()<br>
> +endif<br>
> +<br>
> +gstreamer_tests = [<br>
> +    ['single_stream_test',   'gstreamer_single_stream_test.cpp'],<br>
> +]<br>
> +gstreamer_dep = dependency('gstreamer-1.0', required: true)<br>
> +<br>
> +foreach t : gstreamer_tests<br>
> +    exe = executable(t[0], t[1],<br>
> +                     dependencies : [libcamera_private, gstreamer_dep],<br>
> +                     link_with : test_libraries,<br>
> +                     include_directories : test_includes_internal)<br>
> +<br>
> +    test(t[0], exe, suite : 'gstreamer', is_parallel : false)<br>
> +endforeach<br>
> diff --git a/test/meson.build b/test/meson.build<br>
> index 3bceb5df..d0466f17 100644<br>
> --- a/test/meson.build<br>
> +++ b/test/meson.build<br>
> @@ -11,6 +11,7 @@ subdir('libtest')<br>
>  <br>
>  subdir('camera')<br>
>  subdir('controls')<br>
> +subdir('gstreamer')<br>
>  subdir('ipa')<br>
>  subdir('ipc')<br>
>  subdir('log')<br>
<br>
-- <br>
Regards,<br>
<br>
Laurent Pinchart</blockquote></div></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Regards</blockquote></div></div><div dir="auto">Vedant Paranjape</div><div dir="auto"></div></div>