<div dir="ltr"><div dir="ltr">Hi Laurent, Kieran<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 11, 2021 at 6:34 PM Laurent Pinchart <<a href="mailto:laurent.pinchart@ideasonboard.com">laurent.pinchart@ideasonboard.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
On Wed, Aug 11, 2021 at 01:56:08PM +0100, Kieran Bingham wrote:<br>
> On 11/08/2021 13:47, Kieran Bingham wrote:<br>
> > On 11/08/2021 08:03, 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">vedantparanjape160201@gmail.com</a>><br>
> >> Reviewed-by: Paul Elder <<a href="mailto:paul.elder@ideasonboard.com" target="_blank">paul.elder@ideasonboard.com</a>><br>
> > <br>
> > Is there anything specific needed to run this?<br>
> > <br>
> > When I ran it here I get:<br>
> > <br>
> > <br>
> > 12/66 libcamera:gstreamer / single_stream_test<br>
> >  FAIL            0.01s   (exit status 255 or signal 127 SIGinvalid)<br>
> > stderr:<br>
> > Not all elements could be created.<br>
> <br>
> Somehow we need to export the GST_PLUGIN_PATH from the build to the test<br>
> when it is run.<br>
<br>
I've run into the same issue. This needs to be fixed, as otherwise<br>
running 'ninja test' will fail.<br></blockquote><div><br></div><div>I think you need to set the path or install libcamera in root, not sure what needs to be fixed.</div><div><br></div><div> > Manually running the test, while manually setting the path gives:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> <br>
> <br>
> > GST_PLUGIN_PATH=./build/src/gstreamer/ ./build/test/gstreamer/single_stream_test<br>
> > [322:51:39.768296143] [2459570]  INFO IPAManager ipa_manager.cpp:138 libcamera is not installed. Adding '/home/kbingham/iob/libcamera/chromeos/src/third_party/libcamera/build/src/ipa' to the IPA search path<br>
> > [322:51:39.769209245] [2459570]  INFO Camera camera_manager.cpp:294 libcamera v0.0.0+2918-15014c37<br>
> > [322:51:39.772516638] [2459575]  INFO V4L2 v4l2_subdevice.cpp:242 'Sensor B': Using /dev/v4l-subdev1<br>
> > [322:51:39.773277255] [2459575]  WARN CameraSensorProperties camera_sensor_properties.cpp:123 No static properties available for 'Sensor B'<br>
> > [322:51:39.773290289] [2459575]  WARN CameraSensorProperties camera_sensor_properties.cpp:125 Please consider updating the camera sensor properties database<br>
> > [322:51:39.773298484] [2459575]  WARN CameraSensor camera_sensor.cpp:403 'Sensor B': Failed to retrieve the camera location<br>
> > [322:51:39.773317911] [2459575]  INFO V4L2 v4l2_subdevice.cpp:242 'Debayer B': Using /dev/v4l-subdev3<br>
> > [322:51:39.773365811] [2459575]  INFO V4L2 v4l2_subdevice.cpp:242 'Scaler': Using /dev/v4l-subdev5<br>
> > [322:51:39.773441643] [2459575]  WARN IPAManager ipa_manager.cpp:280 IPA module /home/kbingham/iob/libcamera/chromeos/src/third_party/libcamera/build/src/ipa/vimc/ipa_vimc.so signature regarded as valid<br>
> > [322:51:39.773731977] [2459575]  INFO IPAProxy ipa_proxy.cpp:130 libcamera is not installed. Loading IPA configuration from '/home/kbingham/iob/libcamera/chromeos/src/third_party/libcamera/src/ipa/vimc/data'<br>
> > [322:51:39.838754646] [2459576]  INFO Camera camera.cpp:873 configuring streams: (0) 156x120-BGR888<br>
> > <br>
> > (single_stream_test:2459570): GStreamer-CRITICAL **: 13:51:14.445: gst_mini_object_unref: assertion 'mini_object != NULL' failed<br>
> <br>
> But even that only showed me a black box that appeared, and then seemed<br>
> to disappear again.<br>
> <br>
> We might also want to run the automated tests on systems without a<br>
> display, so pop windows might not work there.<br>
> <br>
> But I'd be tempted to say we can deal with that when we find an actual<br>
> need for that, and keep the visual test, as ... (if It works, and shows<br>
> an image) it would be a nice visual confirmation while running the tests.<br>
> <br>
> Otherwise, perhaps a pipeline that generates an output PNG or encoded<br>
> video might be required, or even just a null sink if that's possible?<br>
<br>
A null sink would be better, as I already run tests on headless systems.<br>
It may be as simple as s/autovideosink/fakevideosink/ in the code below,<br>
so I think we should already address that. </blockquote><div><br></div><div>I tried this, it works, should I sent a new patch with this ?</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> But that can be later anyway.<br>
> <br>
> >> ---<br>
> >>  .../gstreamer_single_stream_test.cpp          | 116 ++++++++++++++++++<br>
> >>  test/gstreamer/meson.build                    |  19 +++<br>
> >>  test/meson.build                              |   1 +<br>
> >>  3 files changed, 136 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..c19da3f2<br>
> >> --- /dev/null<br>
> >> +++ b/test/gstreamer/gstreamer_single_stream_test.cpp<br>
> >> @@ -0,0 +1,116 @@<br>
> >> +#include <gst/gst.h><br>
> >> +#include <iostream><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 *err_init = nullptr;<br>
> >> +          if (!gst_init_check(nullptr, nullptr, &err_init)) {<br>
> >> +                  g_printerr("Could not initialize GStreamer: %s\n",<br>
> >> +                             err_init ? err_init->message : "unknown error");<br>
> >> +                  if (err_init)<br>
> >> +                          g_error_free(err_init);<br>
> >> +<br>
> >> +                  return TestFail;<br>
> >> +          }<br>
> >> +<br>
> >> +          /* Create the elements */<br>
> >> +          libcamera_src_ = gst_element_factory_make("libcamerasrc", "libcamera");<br>
> >> +          convert0_ = gst_element_factory_make("videoconvert", "convert0");<br>
> >> +          sink0_ = gst_element_factory_make("autovideosink", "sink0");<br>
> >> +<br>
> >> +          /* Create the empty pipeline_ */<br>
> >> +          pipeline_ = gst_pipeline_new("test-pipeline");<br>
> >> +<br>
> >> +          if (!pipeline_ || !convert0_ || !sink0_ || !libcamera_src_) {<br>
> >> +                  g_printerr("Not all elements could be created.\n");<br>
> >> +                  return TestFail;<br>
> >> +          }<br>
> >> +<br>
> >> +          return TestPass;<br>
> >> +  }<br>
> >> +<br>
> >> +  void cleanup() override<br>
> >> +  {<br>
> >> +          gst_message_unref(msg_);<br>
> >> +          gst_object_unref(bus_);<br>
> >> +          gst_element_set_state(pipeline_, GST_STATE_NULL);<br>
> >> +          gst_object_unref(pipeline_);<br>
> >> +  }<br>
> >> +<br>
> >> +  int run() override<br>
> >> +  {<br>
> >> +          /* Build the pipeline */<br>
> >> +          gst_bin_add_many(GST_BIN(pipeline_), libcamera_src_, convert0_, sink0_, NULL);<br>
> >> +          if (gst_element_link_many(libcamera_src_, convert0_, sink0_, NULL) != TRUE) {<br>
> >> +                  g_printerr("Elements could not be linked.\n");<br>
> >> +                  gst_object_unref(pipeline_);<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>
> >> +                  gst_object_unref(pipeline_);<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>
> >> +<br>
> >> +          /* Parse error message */<br>
> >> +          if (msg_ == NULL)<br>
> >> +                  return TestPass;<br>
> >> +<br>
> >> +          switch (GST_MESSAGE_TYPE(msg_)) {<br>
> >> +          case GST_MESSAGE_ERROR:<br>
> >> +                  GstreamerPrintError(msg_);<br>
> >> +                  return TestFail;<br>
> >> +                  break;<br>
> >> +          case GST_MESSAGE_EOS:<br>
> >> +                  g_print("End-Of-Stream reached.\n");<br>
> >> +                  return TestFail;<br>
> >> +                  break;<br>
> >> +          default:<br>
> >> +                  g_printerr("Unexpected message received.\n");<br>
> >> +                  return TestFail;<br>
> >> +                  break;<br>
> >> +          }<br>
> >> +<br>
> >> +          return TestPass;<br>
> >> +  }<br>
> >> +<br>
> >> +private:<br>
> >> +  GstElement *pipeline_, *libcamera_src_, *convert0_, *sink0_;<br>
> >> +  GstBus *bus_;<br>
> >> +  GstMessage *msg_;<br>
> >> +  GstStateChangeReturn ret_;<br>
> >> +<br>
> >> +  void GstreamerPrintError(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>
> >> +<br>
> >> +TEST_REGISTER(GstreamerSingleStreamTest)<br>
> >> +<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<br></blockquote><div><br></div><div>Regards,</div><div><i><b>Vedant Paranjape</b></i><br></div></div></div>