diff --git a/src/Makefile.am b/src/Makefile.am index 468bd05f4..03ff59d3b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -123,8 +123,7 @@ noinst_LTLIBRARIES = TESTS_default = TESTS_norun = test-client \ - test-subscribe \ - test-v4l2 + test-subscribe # These tests need a running pulsevideo daemon TESTS_daemon = @@ -141,11 +140,6 @@ test_subscribe_CFLAGS = $(AM_CFLAGS) test_subscribe_LDADD = $(AM_LDADD) libpulsevideo-@PV_MAJORMINOR@.la test_subscribe_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) -test_v4l2_SOURCES = tests/test-v4l2.c -test_v4l2_CFLAGS = $(AM_CFLAGS) -test_v4l2_LDADD = $(AM_LDADD) libpulsevideo-@PV_MAJORMINOR@.la libpulsevideocore-@PV_MAJORMINOR@.la -test_v4l2_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) - ################################### # Client library # ################################### diff --git a/src/tests/test-client.c b/src/tests/test-client.c index 72f4ba37e..fec510027 100644 --- a/src/tests/test-client.c +++ b/src/tests/test-client.c @@ -23,7 +23,7 @@ #include -#define CAPS "video/x-raw, format=(string)YUY2, width=(int)640, height=(int)480, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, framerate=(fraction)30/1" +#define ANY_CAPS "ANY" static GMainLoop *loop; @@ -33,16 +33,33 @@ on_socket_notify (GObject *gobject, gpointer user_data) { GSocket *socket; - GstElement *pipeline, *src; + GstElement *pipeline, *src, *filter; + GBytes *format; + GstCaps *caps; + GError *error = NULL; + pipeline = gst_parse_launch ("socketsrc name=src ! pvfddepay ! capsfilter name=filter ! videoconvert ! xvimagesink", &error); + if (error != NULL) { + g_warning ("error creating pipeline: %s", error->message); + g_clear_error (&error); + g_assert (pipeline != NULL); + } + + /* configure socket in the socketsrc */ g_object_get (gobject, "socket", &socket, NULL); g_print ("got socket %p\n", socket); - - pipeline = gst_parse_launch ("socketsrc name=src ! pvfddepay ! "CAPS" ! videoconvert ! xvimagesink", NULL); src = gst_bin_get_by_name (GST_BIN (pipeline), "src"); - g_object_set (src, "socket", socket, NULL); + /* configure format as capsfilter */ + g_object_get (gobject, "format", &format, NULL); + caps = gst_caps_from_string (g_bytes_get_data (format, NULL)); + g_bytes_unref (format); + filter = gst_bin_get_by_name (GST_BIN (pipeline), "filter"); + g_object_set (filter, "caps", caps, NULL); + gst_caps_unref (caps); + + /* and set to playing */ gst_element_set_state (pipeline, GST_STATE_PLAYING); } @@ -61,21 +78,42 @@ on_stream_notify (GObject *gobject, case PV_STREAM_STATE_ERROR: g_main_loop_quit (loop); break; + case PV_STREAM_STATE_READY: { - GBytes *format; + GBytes *possible, *format; + GstCaps *caps; + GstStructure *structure; + gchar *str; - format = g_bytes_new_static (CAPS, strlen (CAPS) + 1); + g_object_get (s, "possible-formats", &possible, NULL); + + caps = gst_caps_from_string (g_bytes_get_data (possible, NULL)); + + structure = gst_caps_get_structure (caps, 0); + + /* set some reasonable defaults */ + if (gst_structure_has_field (structure, "width")) + gst_structure_fixate_field_nearest_int (structure, "width", 320); + if (gst_structure_has_field (structure, "height")) + gst_structure_fixate_field_nearest_int (structure, "height", 240); + if (gst_structure_has_field (structure, "framerate")) + gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1); + + /* use random fixation otherwise */ + caps = gst_caps_fixate (caps); + str = gst_caps_to_string (caps); + gst_caps_unref (caps); + + format = g_bytes_new_static (str, strlen (str) + 1); pv_stream_start (s, format, PV_STREAM_MODE_SOCKET); + g_bytes_unref (format); break; } - case PV_STREAM_STATE_STREAMING: - { - PvBufferInfo info; - pv_stream_capture_buffer (s, &info); + case PV_STREAM_STATE_STREAMING: break; - } + default: break; } @@ -105,8 +143,9 @@ on_state_notify (GObject *gobject, g_signal_connect (stream, "notify::state", (GCallback) on_stream_notify, stream); g_signal_connect (stream, "notify::socket", (GCallback) on_socket_notify, stream); - format = g_bytes_new_static (CAPS, strlen (CAPS) + 1); + format = g_bytes_new_static (ANY_CAPS, strlen (ANY_CAPS) + 1); pv_stream_connect_capture (stream, NULL, 0, format); + g_bytes_unref (format); break; } default: diff --git a/src/tests/test-v4l2.c b/src/tests/test-v4l2.c deleted file mode 100644 index 6bcca8df5..000000000 --- a/src/tests/test-v4l2.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Pulsevideo - * Copyright (C) 2015 Wim Taymans - * - * 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. - */ - -#include -#include - -#include - -#include - -static GMainLoop *loop; - -static void -on_state_notify (GObject *gobject, - GParamSpec *pspec, - gpointer user_data) -{ - PvContextState state; - //PvContext *c = user_data; - - g_object_get (gobject, "state", &state, NULL); - g_print ("got context state %d\n", state); - - switch (state) { - case PV_CONTEXT_STATE_ERROR: - g_main_loop_quit (loop); - break; - case PV_CONTEXT_STATE_READY: - { - //PvSource *source; - - //source = pv_v4l2_source_new (NULL); - //pv_context_register_source (c, source); - break; - } - default: - break; - } -} - -gint -main (gint argc, gchar *argv[]) -{ - PvContext *c; - - pv_init (&argc, &argv); - - loop = g_main_loop_new (NULL, FALSE); - - c = pv_context_new (NULL, "test-client", NULL); - g_signal_connect (c, "notify::state", (GCallback) on_state_notify, c); - pv_context_connect(c, PV_CONTEXT_FLAGS_NONE); - - g_main_loop_run (loop); - - g_object_unref (c); - - return 0; -}