2005-11-16 16:49:49 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2005-11-16 16:49:49 +00:00
|
|
|
*/
|
2005-11-24 09:44:07 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstnettimeprovider
|
2017-01-16 14:26:16 +00:00
|
|
|
* @title: GstNetTimeProvider
|
2005-11-24 09:44:07 +00:00
|
|
|
* @short_description: Special object that exposed the time of a clock
|
|
|
|
* on the network.
|
|
|
|
* @see_also: #GstClock, #GstNetClientClock, #GstPipeline
|
|
|
|
*
|
|
|
|
* This object exposes the time of a #GstClock on the network.
|
|
|
|
*
|
|
|
|
* A #GstNetTimeProvider is created with gst_net_time_provider_new() which
|
2006-03-12 20:40:19 +00:00
|
|
|
* takes a #GstClock, an address and a port number as arguments.
|
2005-11-24 09:44:07 +00:00
|
|
|
*
|
|
|
|
* After creating the object, a client clock such as #GstNetClientClock can
|
2006-03-12 20:40:19 +00:00
|
|
|
* query the exposed clock over the network for its values.
|
2005-11-24 09:44:07 +00:00
|
|
|
*
|
|
|
|
* The #GstNetTimeProvider typically wraps the clock used by a #GstPipeline.
|
|
|
|
*/
|
2005-11-16 16:49:49 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstnettimeprovider.h"
|
2005-11-16 17:52:04 +00:00
|
|
|
#include "gstnettimepacket.h"
|
2017-10-30 09:49:06 +00:00
|
|
|
#include "gstnetutils.h"
|
2005-11-16 17:52:04 +00:00
|
|
|
|
2006-06-23 13:16:46 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (ntp_debug);
|
2005-11-16 16:49:49 +00:00
|
|
|
#define GST_CAT_DEFAULT (ntp_debug)
|
|
|
|
|
2005-12-06 19:29:15 +00:00
|
|
|
#define DEFAULT_ADDRESS "0.0.0.0"
|
|
|
|
#define DEFAULT_PORT 5637
|
2017-06-01 13:48:16 +00:00
|
|
|
#define DEFAULT_QOS_DSCP -1
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
#define IS_ACTIVE(self) (g_atomic_int_get (&((self)->priv->active)))
|
2005-12-12 15:02:02 +00:00
|
|
|
|
2005-11-16 16:49:49 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_PORT,
|
|
|
|
PROP_ADDRESS,
|
2005-12-12 15:02:02 +00:00
|
|
|
PROP_CLOCK,
|
2017-06-01 13:48:16 +00:00
|
|
|
PROP_ACTIVE,
|
|
|
|
PROP_QOS_DSCP
|
2005-11-16 16:49:49 +00:00
|
|
|
};
|
|
|
|
|
Use a private stuct to not break ABI.
Original commit message from CVS:
* docs/libs/gstreamer-libs-sections.txt:
* libs/gst/net/gstnetclientclock.c:
(gst_net_client_clock_class_init), (gst_net_client_clock_init),
(gst_net_client_clock_finalize), (gst_net_client_clock_do_select),
(gst_net_client_clock_thread), (gst_net_client_clock_start),
(gst_net_client_clock_stop), (gst_net_client_clock_new):
* libs/gst/net/gstnetclientclock.h:
* libs/gst/net/gstnettimeprovider.c:
(gst_net_time_provider_class_init), (gst_net_time_provider_init),
(gst_net_time_provider_finalize), (gst_net_time_provider_thread),
(gst_net_time_provider_start), (gst_net_time_provider_stop),
(gst_net_time_provider_new):
* libs/gst/net/gstnettimeprovider.h:
Use a private stuct to not break ABI.
2008-02-27 19:01:12 +00:00
|
|
|
struct _GstNetTimeProviderPrivate
|
|
|
|
{
|
2010-05-05 15:33:51 +00:00
|
|
|
gchar *address;
|
|
|
|
int port;
|
2017-06-01 13:48:16 +00:00
|
|
|
gint qos_dscp; /* ATOMIC */
|
2010-05-05 15:33:51 +00:00
|
|
|
|
|
|
|
GThread *thread;
|
|
|
|
|
|
|
|
GstClock *clock;
|
|
|
|
|
|
|
|
gboolean active; /* ATOMIC */
|
|
|
|
|
|
|
|
GSocket *socket;
|
|
|
|
GCancellable *cancel;
|
2015-05-19 13:34:04 +00:00
|
|
|
gboolean made_cancel_fd;
|
Use a private stuct to not break ABI.
Original commit message from CVS:
* docs/libs/gstreamer-libs-sections.txt:
* libs/gst/net/gstnetclientclock.c:
(gst_net_client_clock_class_init), (gst_net_client_clock_init),
(gst_net_client_clock_finalize), (gst_net_client_clock_do_select),
(gst_net_client_clock_thread), (gst_net_client_clock_start),
(gst_net_client_clock_stop), (gst_net_client_clock_new):
* libs/gst/net/gstnetclientclock.h:
* libs/gst/net/gstnettimeprovider.c:
(gst_net_time_provider_class_init), (gst_net_time_provider_init),
(gst_net_time_provider_finalize), (gst_net_time_provider_thread),
(gst_net_time_provider_start), (gst_net_time_provider_stop),
(gst_net_time_provider_new):
* libs/gst/net/gstnettimeprovider.h:
Use a private stuct to not break ABI.
2008-02-27 19:01:12 +00:00
|
|
|
};
|
|
|
|
|
2016-01-04 08:39:27 +00:00
|
|
|
static void gst_net_time_provider_initable_iface_init (gpointer g_iface);
|
|
|
|
|
|
|
|
static gboolean gst_net_time_provider_start (GstNetTimeProvider * bself,
|
|
|
|
GError ** error);
|
2005-11-16 16:49:49 +00:00
|
|
|
static void gst_net_time_provider_stop (GstNetTimeProvider * bself);
|
|
|
|
|
|
|
|
static gpointer gst_net_time_provider_thread (gpointer data);
|
|
|
|
|
|
|
|
static void gst_net_time_provider_finalize (GObject * object);
|
|
|
|
static void gst_net_time_provider_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_net_time_provider_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2011-04-16 13:23:46 +00:00
|
|
|
#define _do_init \
|
2016-01-04 08:39:27 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (ntp_debug, "nettime", 0, "Network time provider"); \
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, gst_net_time_provider_initable_iface_init)
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2011-04-16 13:23:46 +00:00
|
|
|
#define gst_net_time_provider_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstNetTimeProvider, gst_net_time_provider,
|
2018-06-23 15:01:09 +00:00
|
|
|
GST_TYPE_OBJECT, G_ADD_PRIVATE (GstNetTimeProvider) _do_init);
|
2005-11-16 16:49:49 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_net_time_provider_class_init (GstNetTimeProviderClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
2006-05-11 18:10:34 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2005-11-16 16:49:49 +00:00
|
|
|
|
Don't use base_init where not absolutely necessary. For example it's not necessary anymore for adding pad templates o...
Original commit message from CVS:
* gst/gstbin.c: (gst_bin_get_type), (gst_bin_class_init):
* gst/gstpipeline.c: (gst_pipeline_get_type),
(gst_pipeline_class_init):
* libs/gst/base/gstbasesink.c: (gst_base_sink_get_type),
(gst_base_sink_class_init):
* libs/gst/base/gstbasesrc.c: (gst_base_src_get_type),
(gst_base_src_class_init):
* libs/gst/base/gstbasetransform.c: (gst_base_transform_get_type),
(gst_base_transform_class_init):
* libs/gst/base/gstcollectpads.c: (gst_collect_pads_base_init),
(gst_collect_pads_class_init):
* libs/gst/base/gstdataqueue.c: (gst_data_queue_get_type):
* libs/gst/net/gstnettimeprovider.c:
(gst_net_time_provider_base_init),
(gst_net_time_provider_class_init):
* plugins/elements/gstcapsfilter.c: (gst_capsfilter_base_init),
(gst_capsfilter_class_init):
* plugins/elements/gstfakesink.c: (gst_fake_sink_base_init),
(gst_fake_sink_class_init):
* plugins/elements/gstfakesrc.c: (gst_fake_src_base_init),
(gst_fake_src_class_init):
* plugins/elements/gstfdsink.c: (gst_fd_sink_base_init),
(gst_fd_sink_class_init):
* plugins/elements/gstfdsrc.c: (gst_fd_src_base_init),
(gst_fd_src_class_init):
* plugins/elements/gstfilesink.c: (gst_file_sink_base_init),
(gst_file_sink_class_init):
* plugins/elements/gstfilesrc.c: (gst_file_src_base_init),
(gst_file_src_class_init):
* plugins/elements/gstidentity.c: (gst_identity_base_init),
(gst_identity_class_init):
* plugins/elements/gstmultiqueue.c: (gst_multi_queue_base_init),
(gst_multi_queue_class_init):
* plugins/elements/gstqueue.c: (gst_queue_base_init),
(gst_queue_class_init):
* plugins/elements/gsttee.c: (gst_tee_base_init),
(gst_tee_class_init):
* plugins/elements/gsttypefindelement.c:
(gst_type_find_element_base_init),
(gst_type_find_element_class_init):
Don't use base_init where not absolutely necessary. For example it's
not necessary anymore for adding pad templates or setting element
details.
Leave empty base_init functions in several places as GST_BOILERPLATE
still defines and uses them.
2008-02-03 12:04:37 +00:00
|
|
|
g_assert (sizeof (GstClockTime) == 8);
|
|
|
|
|
2005-11-16 16:49:49 +00:00
|
|
|
gobject_class->finalize = gst_net_time_provider_finalize;
|
|
|
|
gobject_class->set_property = gst_net_time_provider_set_property;
|
|
|
|
gobject_class->get_property = gst_net_time_provider_get_property;
|
|
|
|
|
2006-05-11 18:10:34 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_PORT,
|
2005-11-16 16:49:49 +00:00
|
|
|
g_param_spec_int ("port", "port",
|
2005-11-18 11:57:30 +00:00
|
|
|
"The port to receive the packets from, 0=allocate", 0, G_MAXUINT16,
|
2016-01-03 12:06:16 +00:00
|
|
|
DEFAULT_PORT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2005-11-16 16:49:49 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ADDRESS,
|
|
|
|
g_param_spec_string ("address", "address",
|
2016-01-03 12:06:16 +00:00
|
|
|
"The address to bind on, as a dotted quad (x.x.x.x)", DEFAULT_ADDRESS,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2005-11-16 16:49:49 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CLOCK,
|
|
|
|
g_param_spec_object ("clock", "Clock",
|
|
|
|
"The clock to export over the network", GST_TYPE_CLOCK,
|
2016-01-03 12:06:16 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2005-12-12 15:02:02 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ACTIVE,
|
|
|
|
g_param_spec_boolean ("active", "Active",
|
|
|
|
"TRUE if the clock will respond to queries over the network", TRUE,
|
2008-03-22 14:56:17 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2017-06-01 13:48:16 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_QOS_DSCP,
|
|
|
|
g_param_spec_int ("qos-dscp", "QoS diff srv code point",
|
|
|
|
"Quality of Service, differentiated services code point (-1 default)",
|
|
|
|
-1, 63, DEFAULT_QOS_DSCP,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2005-11-16 16:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-16 13:23:46 +00:00
|
|
|
gst_net_time_provider_init (GstNetTimeProvider * self)
|
2005-11-16 16:49:49 +00:00
|
|
|
{
|
2018-06-23 15:01:09 +00:00
|
|
|
self->priv = gst_net_time_provider_get_instance_private (self);
|
2006-09-05 08:35:20 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
self->priv->port = DEFAULT_PORT;
|
|
|
|
self->priv->address = g_strdup (DEFAULT_ADDRESS);
|
2017-06-01 13:48:16 +00:00
|
|
|
self->priv->qos_dscp = DEFAULT_QOS_DSCP;
|
2010-05-05 15:33:51 +00:00
|
|
|
self->priv->thread = NULL;
|
|
|
|
self->priv->active = TRUE;
|
2005-11-16 16:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_net_time_provider_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstNetTimeProvider *self = GST_NET_TIME_PROVIDER (object);
|
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
if (self->priv->thread) {
|
2005-11-16 16:49:49 +00:00
|
|
|
gst_net_time_provider_stop (self);
|
2010-05-05 15:33:51 +00:00
|
|
|
g_assert (self->priv->thread == NULL);
|
2005-11-16 16:49:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
g_free (self->priv->address);
|
|
|
|
self->priv->address = NULL;
|
2005-11-16 17:22:36 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
if (self->priv->clock)
|
|
|
|
gst_object_unref (self->priv->clock);
|
|
|
|
self->priv->clock = NULL;
|
2006-09-05 08:35:20 +00:00
|
|
|
|
2005-11-16 17:22:36 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2005-11-16 16:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
gst_net_time_provider_thread (gpointer data)
|
|
|
|
{
|
|
|
|
GstNetTimeProvider *self = data;
|
2010-05-05 15:33:51 +00:00
|
|
|
GCancellable *cancel = self->priv->cancel;
|
|
|
|
GSocket *socket = self->priv->socket;
|
2005-11-16 17:52:04 +00:00
|
|
|
GstNetTimePacket *packet;
|
2010-05-05 15:33:51 +00:00
|
|
|
GError *err = NULL;
|
2017-06-01 13:48:16 +00:00
|
|
|
gint cur_qos_dscp = DEFAULT_QOS_DSCP;
|
|
|
|
gint new_qos_dscp;
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
GST_INFO_OBJECT (self, "time provider thread is running");
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
while (TRUE) {
|
|
|
|
GSocketAddress *sender_addr = NULL;
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2017-06-01 13:48:16 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
GST_LOG_OBJECT (self, "waiting on socket");
|
|
|
|
if (!g_socket_condition_wait (socket, G_IO_IN, cancel, &err)) {
|
|
|
|
GST_INFO_OBJECT (self, "socket error: %s", err->message);
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
if (err->code == G_IO_ERROR_CANCELLED)
|
|
|
|
break;
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
/* try again */
|
|
|
|
g_usleep (G_USEC_PER_SEC / 10);
|
|
|
|
g_error_free (err);
|
|
|
|
err = NULL;
|
2005-11-16 16:49:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
/* got data in */
|
|
|
|
packet = gst_net_time_packet_receive (socket, &sender_addr, &err);
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
if (err != NULL) {
|
|
|
|
GST_DEBUG_OBJECT (self, "receive error: %s", err->message);
|
|
|
|
g_usleep (G_USEC_PER_SEC / 10);
|
|
|
|
g_error_free (err);
|
|
|
|
err = NULL;
|
2005-11-16 16:49:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-01 13:48:16 +00:00
|
|
|
/* before next sending check if need to change QoS */
|
|
|
|
new_qos_dscp = self->priv->qos_dscp;
|
2017-10-30 09:49:06 +00:00
|
|
|
if (cur_qos_dscp != new_qos_dscp &&
|
2018-11-13 12:41:53 +00:00
|
|
|
gst_net_utils_set_socket_tos (socket, new_qos_dscp)) {
|
2017-06-01 13:48:16 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "changed QoS DSCP to: %d", new_qos_dscp);
|
|
|
|
cur_qos_dscp = new_qos_dscp;
|
|
|
|
}
|
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
if (IS_ACTIVE (self)) {
|
|
|
|
/* do what we were asked to and send the packet back */
|
|
|
|
packet->remote_time = gst_clock_get_time (self->priv->clock);
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
/* ignore errors */
|
|
|
|
gst_net_time_packet_send (packet, socket, sender_addr, NULL);
|
|
|
|
g_object_unref (sender_addr);
|
|
|
|
g_free (packet);
|
|
|
|
}
|
2005-11-16 16:49:49 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 16:10:08 +00:00
|
|
|
g_error_free (err);
|
2013-12-30 16:05:47 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
GST_INFO_OBJECT (self, "time provider thread is stopping");
|
2005-11-16 16:49:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_net_time_provider_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstNetTimeProvider *self = GST_NET_TIME_PROVIDER (object);
|
2010-05-05 15:33:51 +00:00
|
|
|
GstClock **clock_p = &self->priv->clock;
|
2005-11-16 16:49:49 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PORT:
|
2010-05-05 15:33:51 +00:00
|
|
|
self->priv->port = g_value_get_int (value);
|
2005-11-16 16:49:49 +00:00
|
|
|
break;
|
|
|
|
case PROP_ADDRESS:
|
2010-05-05 15:33:51 +00:00
|
|
|
g_free (self->priv->address);
|
2005-11-16 16:49:49 +00:00
|
|
|
if (g_value_get_string (value) == NULL)
|
2010-05-05 15:33:51 +00:00
|
|
|
self->priv->address = g_strdup (DEFAULT_ADDRESS);
|
2005-11-16 16:49:49 +00:00
|
|
|
else
|
2019-12-18 14:57:35 +00:00
|
|
|
self->priv->address = g_value_dup_string (value);
|
2005-11-16 16:49:49 +00:00
|
|
|
break;
|
|
|
|
case PROP_CLOCK:
|
2006-03-21 14:14:49 +00:00
|
|
|
gst_object_replace ((GstObject **) clock_p,
|
2005-11-16 16:49:49 +00:00
|
|
|
(GstObject *) g_value_get_object (value));
|
|
|
|
break;
|
2005-12-12 15:02:02 +00:00
|
|
|
case PROP_ACTIVE:
|
2010-05-05 15:33:51 +00:00
|
|
|
g_atomic_int_set (&self->priv->active, g_value_get_boolean (value));
|
2005-12-12 15:02:02 +00:00
|
|
|
break;
|
2017-06-01 13:48:16 +00:00
|
|
|
case PROP_QOS_DSCP:
|
|
|
|
g_atomic_int_set (&self->priv->qos_dscp, g_value_get_int (value));
|
|
|
|
break;
|
2005-11-16 16:49:49 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_net_time_provider_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstNetTimeProvider *self = GST_NET_TIME_PROVIDER (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PORT:
|
2010-05-05 15:33:51 +00:00
|
|
|
g_value_set_int (value, self->priv->port);
|
2005-11-16 16:49:49 +00:00
|
|
|
break;
|
|
|
|
case PROP_ADDRESS:
|
2010-05-05 15:33:51 +00:00
|
|
|
g_value_set_string (value, self->priv->address);
|
2005-11-16 16:49:49 +00:00
|
|
|
break;
|
|
|
|
case PROP_CLOCK:
|
2010-05-05 15:33:51 +00:00
|
|
|
g_value_set_object (value, self->priv->clock);
|
2005-11-16 16:49:49 +00:00
|
|
|
break;
|
2005-12-12 15:02:02 +00:00
|
|
|
case PROP_ACTIVE:
|
|
|
|
g_value_set_boolean (value, IS_ACTIVE (self));
|
|
|
|
break;
|
2017-06-01 13:48:16 +00:00
|
|
|
case PROP_QOS_DSCP:
|
|
|
|
g_value_set_int (value, self->priv->qos_dscp);
|
|
|
|
break;
|
2005-11-16 16:49:49 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-01-04 08:39:27 +00:00
|
|
|
gst_net_time_provider_start (GstNetTimeProvider * self, GError ** error)
|
2005-11-16 16:49:49 +00:00
|
|
|
{
|
2010-05-05 15:33:51 +00:00
|
|
|
GSocketAddress *socket_addr, *bound_addr;
|
|
|
|
GInetAddress *inet_addr;
|
2015-05-19 13:34:04 +00:00
|
|
|
GPollFD dummy_pollfd;
|
2010-05-05 15:33:51 +00:00
|
|
|
GSocket *socket;
|
2005-11-16 16:49:49 +00:00
|
|
|
int port;
|
2013-04-11 13:04:45 +00:00
|
|
|
gchar *address;
|
2016-01-04 08:39:27 +00:00
|
|
|
GError *err = NULL;
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
if (self->priv->address) {
|
|
|
|
inet_addr = g_inet_address_new_from_string (self->priv->address);
|
2016-01-04 08:39:27 +00:00
|
|
|
if (inet_addr == NULL) {
|
|
|
|
err =
|
|
|
|
g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
"Failed to parse address '%s'", self->priv->address);
|
2010-05-05 15:33:51 +00:00
|
|
|
goto invalid_address;
|
2016-01-04 08:39:27 +00:00
|
|
|
}
|
2010-05-05 15:33:51 +00:00
|
|
|
} else {
|
|
|
|
inet_addr = g_inet_address_new_any (G_SOCKET_FAMILY_IPV4);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (self, "creating socket");
|
|
|
|
socket = g_socket_new (g_inet_address_get_family (inet_addr),
|
|
|
|
G_SOCKET_TYPE_DATAGRAM, G_SOCKET_PROTOCOL_UDP, &err);
|
|
|
|
|
2016-01-04 08:39:27 +00:00
|
|
|
if (!socket)
|
2005-11-16 16:49:49 +00:00
|
|
|
goto no_socket;
|
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "binding on port %d", self->priv->port);
|
|
|
|
socket_addr = g_inet_socket_address_new (inet_addr, self->priv->port);
|
2016-01-04 08:39:27 +00:00
|
|
|
if (!g_socket_bind (socket, socket_addr, TRUE, &err)) {
|
|
|
|
g_object_unref (socket_addr);
|
|
|
|
g_object_unref (inet_addr);
|
|
|
|
goto bind_error;
|
|
|
|
}
|
2010-05-05 15:33:51 +00:00
|
|
|
g_object_unref (socket_addr);
|
|
|
|
g_object_unref (inet_addr);
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
bound_addr = g_socket_get_local_address (socket, NULL);
|
|
|
|
port = g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (bound_addr));
|
2013-04-11 13:04:45 +00:00
|
|
|
inet_addr =
|
|
|
|
g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (bound_addr));
|
|
|
|
address = g_inet_address_to_string (inet_addr);
|
|
|
|
|
|
|
|
if (g_strcmp0 (address, self->priv->address)) {
|
|
|
|
g_free (self->priv->address);
|
|
|
|
self->priv->address = address;
|
|
|
|
GST_DEBUG_OBJECT (self, "notifying address %s", address);
|
|
|
|
g_object_notify (G_OBJECT (self), "address");
|
|
|
|
} else {
|
|
|
|
g_free (address);
|
|
|
|
}
|
2010-05-05 15:33:51 +00:00
|
|
|
if (port != self->priv->port) {
|
|
|
|
self->priv->port = port;
|
|
|
|
GST_DEBUG_OBJECT (self, "notifying port %d", port);
|
2005-11-16 16:49:49 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "port");
|
|
|
|
}
|
2014-05-09 12:46:59 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "bound on UDP address %s, port %d",
|
|
|
|
self->priv->address, port);
|
2013-04-11 13:04:45 +00:00
|
|
|
g_object_unref (bound_addr);
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
self->priv->socket = socket;
|
|
|
|
self->priv->cancel = g_cancellable_new ();
|
2015-05-19 13:34:04 +00:00
|
|
|
self->priv->made_cancel_fd =
|
|
|
|
g_cancellable_make_pollfd (self->priv->cancel, &dummy_pollfd);
|
libs/gst/net/: Massive code removal and cleanups because of GstPoll.
Original commit message from CVS:
Patch by: Peter Kjellerstedt <pkj at axis dot com>
* libs/gst/net/gstnetclientclock.c: (gst_net_client_clock_init),
(gst_net_client_clock_finalize), (gst_net_client_clock_do_select),
(gst_net_client_clock_thread), (gst_net_client_clock_start),
(gst_net_client_clock_stop), (gst_net_client_clock_new):
* libs/gst/net/gstnetclientclock.h:
* libs/gst/net/gstnettimeprovider.c: (gst_net_time_provider_init),
(gst_net_time_provider_finalize), (gst_net_time_provider_thread),
(gst_net_time_provider_start), (gst_net_time_provider_stop),
(gst_net_time_provider_new):
* libs/gst/net/gstnettimeprovider.h:
Massive code removal and cleanups because of GstPoll.
Fixes #505417.
2008-02-27 18:27:59 +00:00
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
self->priv->thread = g_thread_try_new ("GstNetTimeProvider",
|
|
|
|
gst_net_time_provider_thread, self, &err);
|
2011-12-03 13:58:51 +00:00
|
|
|
|
2016-01-04 08:39:27 +00:00
|
|
|
if (!self->priv->thread)
|
2005-11-16 16:49:49 +00:00
|
|
|
goto no_thread;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2010-05-05 15:33:51 +00:00
|
|
|
invalid_address:
|
2005-11-16 16:49:49 +00:00
|
|
|
{
|
2010-05-05 15:33:51 +00:00
|
|
|
GST_ERROR_OBJECT (self, "invalid address: %s", self->priv->address);
|
2016-01-04 08:39:27 +00:00
|
|
|
g_propagate_error (error, err);
|
2005-11-16 16:49:49 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-05 15:33:51 +00:00
|
|
|
no_socket:
|
2011-01-12 10:58:44 +00:00
|
|
|
{
|
2010-05-05 15:33:51 +00:00
|
|
|
GST_ERROR_OBJECT (self, "could not create socket: %s", err->message);
|
2016-01-04 08:39:27 +00:00
|
|
|
g_propagate_error (error, err);
|
2010-05-05 15:33:51 +00:00
|
|
|
g_object_unref (inet_addr);
|
2011-01-12 10:58:44 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2005-11-16 16:49:49 +00:00
|
|
|
bind_error:
|
|
|
|
{
|
2010-05-05 15:33:51 +00:00
|
|
|
GST_ERROR_OBJECT (self, "bind failed: %s", err->message);
|
2016-01-04 08:39:27 +00:00
|
|
|
g_propagate_error (error, err);
|
2010-05-05 15:33:51 +00:00
|
|
|
g_object_unref (socket);
|
2005-11-16 16:49:49 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_thread:
|
|
|
|
{
|
2010-05-05 15:33:51 +00:00
|
|
|
GST_ERROR_OBJECT (self, "could not create thread: %s", err->message);
|
2016-01-04 08:39:27 +00:00
|
|
|
g_propagate_error (error, err);
|
2010-05-05 15:33:51 +00:00
|
|
|
g_object_unref (self->priv->socket);
|
|
|
|
self->priv->socket = NULL;
|
|
|
|
g_object_unref (self->priv->cancel);
|
|
|
|
self->priv->cancel = NULL;
|
2005-11-16 16:49:49 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_net_time_provider_stop (GstNetTimeProvider * self)
|
|
|
|
{
|
2010-05-05 15:33:51 +00:00
|
|
|
g_return_if_fail (self->priv->thread != NULL);
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (self, "stopping..");
|
|
|
|
g_cancellable_cancel (self->priv->cancel);
|
|
|
|
|
|
|
|
g_thread_join (self->priv->thread);
|
|
|
|
self->priv->thread = NULL;
|
|
|
|
|
2015-05-19 13:34:04 +00:00
|
|
|
if (self->priv->made_cancel_fd)
|
|
|
|
g_cancellable_release_fd (self->priv->cancel);
|
|
|
|
|
2010-05-05 15:33:51 +00:00
|
|
|
g_object_unref (self->priv->cancel);
|
|
|
|
self->priv->cancel = NULL;
|
|
|
|
|
|
|
|
g_object_unref (self->priv->socket);
|
|
|
|
self->priv->socket = NULL;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (self, "stopped");
|
2005-11-16 16:49:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 08:39:27 +00:00
|
|
|
static gboolean
|
|
|
|
gst_net_time_provider_initable_init (GInitable * initable,
|
|
|
|
GCancellable * cancellable, GError ** error)
|
|
|
|
{
|
|
|
|
GstNetTimeProvider *self = GST_NET_TIME_PROVIDER (initable);
|
|
|
|
|
|
|
|
return gst_net_time_provider_start (self, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_net_time_provider_initable_iface_init (gpointer g_iface)
|
|
|
|
{
|
|
|
|
GInitableIface *iface = g_iface;
|
|
|
|
|
|
|
|
iface->init = gst_net_time_provider_initable_init;
|
|
|
|
}
|
|
|
|
|
2005-11-16 16:49:49 +00:00
|
|
|
/**
|
|
|
|
* gst_net_time_provider_new:
|
|
|
|
* @clock: a #GstClock to export over the network
|
2013-07-16 13:44:03 +00:00
|
|
|
* @address: (allow-none): an address to bind on as a dotted quad
|
|
|
|
* (xxx.xxx.xxx.xxx), IPv6 address, or NULL to bind to all addresses
|
2006-03-12 20:40:19 +00:00
|
|
|
* @port: a port to bind on, or 0 to let the kernel choose
|
2005-11-16 16:49:49 +00:00
|
|
|
*
|
|
|
|
* Allows network clients to get the current time of @clock.
|
|
|
|
*
|
2017-05-15 15:58:38 +00:00
|
|
|
* Returns: (transfer full): the new #GstNetTimeProvider, or NULL on error
|
2005-11-16 16:49:49 +00:00
|
|
|
*/
|
|
|
|
GstNetTimeProvider *
|
|
|
|
gst_net_time_provider_new (GstClock * clock, const gchar * address, gint port)
|
|
|
|
{
|
|
|
|
GstNetTimeProvider *ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (clock && GST_IS_CLOCK (clock), NULL);
|
2005-11-18 11:57:30 +00:00
|
|
|
g_return_val_if_fail (port >= 0 && port <= G_MAXUINT16, NULL);
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2016-01-04 08:39:27 +00:00
|
|
|
ret =
|
|
|
|
g_initable_new (GST_TYPE_NET_TIME_PROVIDER, NULL, NULL, "clock", clock,
|
|
|
|
"address", address, "port", port, NULL);
|
2005-11-16 16:49:49 +00:00
|
|
|
|
2017-05-15 15:58:38 +00:00
|
|
|
/* Clear floating flag */
|
|
|
|
g_object_ref_sink (ret);
|
|
|
|
|
2005-11-16 16:49:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|