mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-27 03:23:16 +00:00
netclock: Add simple network clock server and client examples
This commit is contained in:
parent
1c9c9847fd
commit
f9f45834e7
6 changed files with 133 additions and 0 deletions
|
@ -801,6 +801,7 @@ tests/examples/launch/Makefile
|
|||
tests/examples/manual/Makefile
|
||||
tests/examples/memory/Makefile
|
||||
tests/examples/metadata/Makefile
|
||||
tests/examples/netclock/Makefile
|
||||
tests/examples/queue/Makefile
|
||||
tests/examples/streams/Makefile
|
||||
tests/examples/typefind/Makefile
|
||||
|
|
|
@ -17,6 +17,7 @@ always_dirs = \
|
|||
manual \
|
||||
memory \
|
||||
metadata \
|
||||
netclock \
|
||||
queue \
|
||||
stepping \
|
||||
streams \
|
||||
|
|
2
tests/examples/netclock/.gitignore
vendored
Normal file
2
tests/examples/netclock/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
netclock-server
|
||||
netclock-client
|
11
tests/examples/netclock/Makefile.am
Normal file
11
tests/examples/netclock/Makefile.am
Normal file
|
@ -0,0 +1,11 @@
|
|||
noinst_PROGRAMS = netclock-server netclock-client
|
||||
|
||||
netclock_server_LDADD = \
|
||||
$(top_builddir)/libs/gst/net/libgstnet-@GST_API_VERSION@.la \
|
||||
$(GST_OBJ_LIBS)
|
||||
netclock_server_CFLAGS = $(GST_OBJ_CFLAGS)
|
||||
|
||||
netclock_client_LDADD = \
|
||||
$(top_builddir)/libs/gst/net/libgstnet-@GST_API_VERSION@.la \
|
||||
$(GST_OBJ_LIBS)
|
||||
netclock_client_CFLAGS = $(GST_OBJ_CFLAGS)
|
59
tests/examples/netclock/netclock-client.c
Normal file
59
tests/examples/netclock/netclock-client.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/net/gstnetclientclock.h>
|
||||
|
||||
static gboolean
|
||||
handle_bus_message (GstBus * bus, GstMessage * message, GstClock * client_clock)
|
||||
{
|
||||
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) {
|
||||
const GstStructure *s = gst_message_get_structure (message);
|
||||
gchar *str;
|
||||
|
||||
if (s == NULL)
|
||||
return TRUE;
|
||||
str = gst_structure_to_string (s);
|
||||
g_print ("%s\n", str);
|
||||
g_free (str);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
main (gint argc, gchar * argv[])
|
||||
{
|
||||
GMainLoop *loop;
|
||||
gchar *host;
|
||||
guint16 port;
|
||||
GstClock *client_clock;
|
||||
GstBus *bus;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc < 3) {
|
||||
g_print ("Usage: netclock-client <host> <port>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
host = argv[1];
|
||||
port = atoi (argv[2]);
|
||||
|
||||
client_clock = gst_net_client_clock_new (NULL, host, port, 0);
|
||||
if (client_clock == NULL) {
|
||||
g_printerr ("Failed to create network clock client\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
bus = gst_bus_new ();
|
||||
gst_bus_add_watch (bus, (GstBusFunc) handle_bus_message, client_clock);
|
||||
g_object_set (G_OBJECT (client_clock), "bus", bus, NULL);
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
g_main_loop_run (loop);
|
||||
|
||||
/* cleanup */
|
||||
g_main_loop_unref (loop);
|
||||
g_object_unref (client_clock);
|
||||
|
||||
return 0;
|
||||
}
|
59
tests/examples/netclock/netclock-server.c
Normal file
59
tests/examples/netclock/netclock-server.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2014 Jan Schmidt <jan@centricular.com>
|
||||
*
|
||||
* netclock-server.c: Publish a network clock provider
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/net/gstnettimeprovider.h>
|
||||
|
||||
gint
|
||||
main (gint argc, gchar * argv[])
|
||||
{
|
||||
GMainLoop *loop;
|
||||
GstClock *clock;
|
||||
GstNetTimeProvider *net_clock;
|
||||
int clock_port = 0;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
if (argc > 1) {
|
||||
clock_port = atoi (argv[1]);
|
||||
}
|
||||
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
clock = gst_system_clock_obtain ();
|
||||
net_clock = gst_net_time_provider_new (clock, NULL, clock_port);
|
||||
gst_object_unref (clock);
|
||||
|
||||
g_object_get (net_clock, "port", &clock_port, NULL);
|
||||
|
||||
g_print ("Published network clock on port %u\n", clock_port);
|
||||
|
||||
g_main_loop_run (loop);
|
||||
|
||||
/* cleanup */
|
||||
g_main_loop_unref (loop);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue