From 9188f69f3cadc7587848b9ebdf855d0aff4ab635 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 18 Nov 2005 10:54:55 +0000 Subject: [PATCH] gst/net/gstnetclientclock.c (gst_net_client_clock_new): Adjust the clock initially so it produces values around the b... Original commit message from CVS: 2005-11-18 Andy Wingo * gst/net/gstnetclientclock.c (gst_net_client_clock_new): Adjust the clock initially so it produces values around the base time. (gst_net_client_clock_class_init): Typo fix. (gst_net_client_clock_thread): Add note on when the socket gets closed. --- ChangeLog | 8 +++++++ gst/net/gstnetclientclock.c | 41 ++++++++++++++++++++++++++++++-- libs/gst/net/gstnetclientclock.c | 41 ++++++++++++++++++++++++++++++-- 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14526b51e3..76cede332a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-11-18 Andy Wingo + + * gst/net/gstnetclientclock.c (gst_net_client_clock_new): Adjust + the clock initially so it produces values around the base time. + (gst_net_client_clock_class_init): Typo fix. + (gst_net_client_clock_thread): Add note on when the socket gets + closed. + 2005-11-17 Wim Taymans * gst/net/gstnetclientclock.c: (gst_net_client_clock_finalize): diff --git a/gst/net/gstnetclientclock.c b/gst/net/gstnetclientclock.c index 30e559f400..64cb27215a 100644 --- a/gst/net/gstnetclientclock.c +++ b/gst/net/gstnetclientclock.c @@ -104,7 +104,7 @@ gst_net_client_clock_class_init (GstNetClientClockClass * klass) "as a dotted quad (x.x.x.x)", DEFAULT_ADDRESS, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT, g_param_spec_int ("port", "port", - "The port on which the remote server is listenind", 0, 32768, + "The port on which the remote server is listening", 0, 32768, DEFAULT_PORT, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_WINDOW_SIZE, g_param_spec_int ("window-size", "Window size", @@ -448,7 +448,7 @@ gst_net_client_clock_thread (gpointer data) stopped: { GST_DEBUG_OBJECT (self, "shutting down"); - /* close socket */ + /* socket gets closed in _stop() */ return NULL; } receive_error: @@ -562,6 +562,8 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address, gint remote_port, GstClockTime base_time) { GstNetClientClock *ret; + GstClockTime internal; + GstClockTimeDiff offset; gint iret; g_return_val_if_fail (remote_address != NULL, NULL); @@ -572,6 +574,33 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address, ret = g_object_new (GST_TYPE_NET_CLIENT_CLOCK, "address", remote_address, "port", remote_port, NULL); + /* gst_clock_get_time() values are guaranteed to be increasing. because no one + * has called get_time on this clock yet we are free to adjust to any value + * without worrying about worrying about MAX() issues with the clock's + * internal time. + */ + + /* update our internal time so get_time() give something around base_time. + assume that the rate is 1 in the beginning. */ + internal = gst_clock_get_internal_time (GST_CLOCK (ret)); + /* MAXINT64 + 1 so as to avoid overflow */ + if ((base_time > internal + && base_time - internal > ((guint64) G_MAXINT64) + 1) + || (base_time < internal && internal - base_time > G_MAXINT64)) + goto bad_base_time; + + offset = base_time > internal ? (base_time - internal) + : -(gint64) (internal - base_time); + + gst_clock_set_rate_offset (GST_CLOCK (ret), 1.0, offset); + + { + GstClockTime now = gst_clock_get_time (GST_CLOCK (ret)); + + if (now < base_time || now > base_time + GST_SECOND) + g_warning ("unable to set the base time, expect sync problems!"); + } + GST_DEBUG_OBJECT (ret, "creating socket pair"); if ((iret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (ret))) < 0) goto no_socket_pair; @@ -585,6 +614,14 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address, /* all systems go, cap'n */ return (GstClock *) ret; +bad_base_time: + { + GST_ERROR_OBJECT (ret, "base time (%" GST_TIME_FORMAT ") too far off from " + "internal time (%" GST_TIME_FORMAT ")", GST_TIME_ARGS (base_time), + GST_TIME_ARGS (internal)); + gst_object_unref (ret); + return NULL; + } no_socket_pair: { GST_ERROR_OBJECT (ret, "no socket pair %d: %s (%d)", iret, diff --git a/libs/gst/net/gstnetclientclock.c b/libs/gst/net/gstnetclientclock.c index 30e559f400..64cb27215a 100644 --- a/libs/gst/net/gstnetclientclock.c +++ b/libs/gst/net/gstnetclientclock.c @@ -104,7 +104,7 @@ gst_net_client_clock_class_init (GstNetClientClockClass * klass) "as a dotted quad (x.x.x.x)", DEFAULT_ADDRESS, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT, g_param_spec_int ("port", "port", - "The port on which the remote server is listenind", 0, 32768, + "The port on which the remote server is listening", 0, 32768, DEFAULT_PORT, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_WINDOW_SIZE, g_param_spec_int ("window-size", "Window size", @@ -448,7 +448,7 @@ gst_net_client_clock_thread (gpointer data) stopped: { GST_DEBUG_OBJECT (self, "shutting down"); - /* close socket */ + /* socket gets closed in _stop() */ return NULL; } receive_error: @@ -562,6 +562,8 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address, gint remote_port, GstClockTime base_time) { GstNetClientClock *ret; + GstClockTime internal; + GstClockTimeDiff offset; gint iret; g_return_val_if_fail (remote_address != NULL, NULL); @@ -572,6 +574,33 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address, ret = g_object_new (GST_TYPE_NET_CLIENT_CLOCK, "address", remote_address, "port", remote_port, NULL); + /* gst_clock_get_time() values are guaranteed to be increasing. because no one + * has called get_time on this clock yet we are free to adjust to any value + * without worrying about worrying about MAX() issues with the clock's + * internal time. + */ + + /* update our internal time so get_time() give something around base_time. + assume that the rate is 1 in the beginning. */ + internal = gst_clock_get_internal_time (GST_CLOCK (ret)); + /* MAXINT64 + 1 so as to avoid overflow */ + if ((base_time > internal + && base_time - internal > ((guint64) G_MAXINT64) + 1) + || (base_time < internal && internal - base_time > G_MAXINT64)) + goto bad_base_time; + + offset = base_time > internal ? (base_time - internal) + : -(gint64) (internal - base_time); + + gst_clock_set_rate_offset (GST_CLOCK (ret), 1.0, offset); + + { + GstClockTime now = gst_clock_get_time (GST_CLOCK (ret)); + + if (now < base_time || now > base_time + GST_SECOND) + g_warning ("unable to set the base time, expect sync problems!"); + } + GST_DEBUG_OBJECT (ret, "creating socket pair"); if ((iret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (ret))) < 0) goto no_socket_pair; @@ -585,6 +614,14 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address, /* all systems go, cap'n */ return (GstClock *) ret; +bad_base_time: + { + GST_ERROR_OBJECT (ret, "base time (%" GST_TIME_FORMAT ") too far off from " + "internal time (%" GST_TIME_FORMAT ")", GST_TIME_ARGS (base_time), + GST_TIME_ARGS (internal)); + gst_object_unref (ret); + return NULL; + } no_socket_pair: { GST_ERROR_OBJECT (ret, "no socket pair %d: %s (%d)", iret,