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  <wingo@pobox.com>

* 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.
This commit is contained in:
Andy Wingo 2005-11-18 10:54:55 +00:00
parent 48d140df6f
commit 9188f69f3c
3 changed files with 86 additions and 4 deletions

View file

@ -1,3 +1,11 @@
2005-11-18 Andy Wingo <wingo@pobox.com>
* 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 <wim@fluendo.com> 2005-11-17 Wim Taymans <wim@fluendo.com>
* gst/net/gstnetclientclock.c: (gst_net_client_clock_finalize): * gst/net/gstnetclientclock.c: (gst_net_client_clock_finalize):

View file

@ -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)); "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_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT,
g_param_spec_int ("port", "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)); DEFAULT_PORT, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_WINDOW_SIZE, g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_WINDOW_SIZE,
g_param_spec_int ("window-size", "Window size", g_param_spec_int ("window-size", "Window size",
@ -448,7 +448,7 @@ gst_net_client_clock_thread (gpointer data)
stopped: stopped:
{ {
GST_DEBUG_OBJECT (self, "shutting down"); GST_DEBUG_OBJECT (self, "shutting down");
/* close socket */ /* socket gets closed in _stop() */
return NULL; return NULL;
} }
receive_error: receive_error:
@ -562,6 +562,8 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address,
gint remote_port, GstClockTime base_time) gint remote_port, GstClockTime base_time)
{ {
GstNetClientClock *ret; GstNetClientClock *ret;
GstClockTime internal;
GstClockTimeDiff offset;
gint iret; gint iret;
g_return_val_if_fail (remote_address != NULL, NULL); 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, ret = g_object_new (GST_TYPE_NET_CLIENT_CLOCK, "address", remote_address,
"port", remote_port, NULL); "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"); GST_DEBUG_OBJECT (ret, "creating socket pair");
if ((iret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (ret))) < 0) if ((iret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (ret))) < 0)
goto no_socket_pair; goto no_socket_pair;
@ -585,6 +614,14 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address,
/* all systems go, cap'n */ /* all systems go, cap'n */
return (GstClock *) ret; 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: no_socket_pair:
{ {
GST_ERROR_OBJECT (ret, "no socket pair %d: %s (%d)", iret, GST_ERROR_OBJECT (ret, "no socket pair %d: %s (%d)", iret,

View file

@ -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)); "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_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PORT,
g_param_spec_int ("port", "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)); DEFAULT_PORT, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_WINDOW_SIZE, g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_WINDOW_SIZE,
g_param_spec_int ("window-size", "Window size", g_param_spec_int ("window-size", "Window size",
@ -448,7 +448,7 @@ gst_net_client_clock_thread (gpointer data)
stopped: stopped:
{ {
GST_DEBUG_OBJECT (self, "shutting down"); GST_DEBUG_OBJECT (self, "shutting down");
/* close socket */ /* socket gets closed in _stop() */
return NULL; return NULL;
} }
receive_error: receive_error:
@ -562,6 +562,8 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address,
gint remote_port, GstClockTime base_time) gint remote_port, GstClockTime base_time)
{ {
GstNetClientClock *ret; GstNetClientClock *ret;
GstClockTime internal;
GstClockTimeDiff offset;
gint iret; gint iret;
g_return_val_if_fail (remote_address != NULL, NULL); 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, ret = g_object_new (GST_TYPE_NET_CLIENT_CLOCK, "address", remote_address,
"port", remote_port, NULL); "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"); GST_DEBUG_OBJECT (ret, "creating socket pair");
if ((iret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (ret))) < 0) if ((iret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (ret))) < 0)
goto no_socket_pair; goto no_socket_pair;
@ -585,6 +614,14 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address,
/* all systems go, cap'n */ /* all systems go, cap'n */
return (GstClock *) ret; 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: no_socket_pair:
{ {
GST_ERROR_OBJECT (ret, "no socket pair %d: %s (%d)", iret, GST_ERROR_OBJECT (ret, "no socket pair %d: %s (%d)", iret,