⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gstnetclientclock.c

📁 gnash 在pc和嵌入式下开发需要的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
        ret = 1;      }#else      ret = select (max_sock + 1, readfds, NULL, NULL, (struct timeval *) ptv);#endif      diff = gst_clock_get_internal_time (GST_CLOCK (self)) - diff;      if (diff > self->current_timeout)        self->current_timeout = 0;      else        self->current_timeout -= diff;    }    GST_LOG_OBJECT (self, "select returned %d", ret);    if (ret < 0) {      if (errno != EAGAIN && errno != EINTR)        goto select_error;      else        continue;    } else {      return ret;    }    g_assert_not_reached ();    /* log errors and keep going */  select_error:    {      GST_WARNING_OBJECT (self, "select error %d: %s (%d)", ret,          g_strerror (errno), errno);      continue;    }  }  g_assert_not_reached ();  return -1;}static gpointergst_net_client_clock_thread (gpointer data){  GstNetClientClock *self = data;  struct sockaddr_in tmpaddr;  socklen_t len;  fd_set read_fds;  GstNetTimePacket *packet;  gint ret;  GstClock *clock = data;  while (TRUE) {    ret = gst_net_client_clock_do_select (self, &read_fds);    if (FD_ISSET (READ_SOCKET (self), &read_fds)) {      /* got control message */      while (TRUE) {        gchar command;        int res;        READ_COMMAND (self, command, res);        if (res <= 0) {          GST_LOG_OBJECT (self, "no more commands");          break;        }        GST_LOG_OBJECT (self, "control message: '%c'", command);        switch (command) {          case CONTROL_STOP:            /* break out of the select loop */            GST_LOG_OBJECT (self, "stop");            goto stopped;          default:            GST_WARNING_OBJECT (self, "unknown message: '%c'", command);            g_warning ("netclientclock: unknown control message received");            continue;        }        g_assert_not_reached ();      }      continue;    } else if (ret == 0) {      /* timed out, let's send another packet */      GST_DEBUG_OBJECT (self, "timed out");      packet = gst_net_time_packet_new (NULL);      packet->local_time = gst_clock_get_internal_time (GST_CLOCK (self));      GST_DEBUG_OBJECT (self, "sending packet, local time = %" GST_TIME_FORMAT,          GST_TIME_ARGS (packet->local_time));      gst_net_time_packet_send (packet, self->sock,          (struct sockaddr *) self->servaddr, sizeof (struct sockaddr_in));      g_free (packet);      /* reset timeout */      self->current_timeout = clock->timeout;      continue;    } else if (FD_ISSET (self->sock, &read_fds)) {      /* got data in */      GstClockTime new_local = gst_clock_get_internal_time (GST_CLOCK (self));      len = sizeof (struct sockaddr);      packet = gst_net_time_packet_receive (self->sock,          (struct sockaddr *) &tmpaddr, &len);      if (!packet)        goto receive_error;      GST_LOG_OBJECT (self, "got packet back");      GST_LOG_OBJECT (self, "local_1 = %" GST_TIME_FORMAT,          GST_TIME_ARGS (packet->local_time));      GST_LOG_OBJECT (self, "remote = %" GST_TIME_FORMAT,          GST_TIME_ARGS (packet->remote_time));      GST_LOG_OBJECT (self, "local_2 = %" GST_TIME_FORMAT,          GST_TIME_ARGS (new_local));      /* observe_times will reset the timeout */      gst_net_client_clock_observe_times (self, packet->local_time,          packet->remote_time, new_local);      g_free (packet);      continue;    } else {      GST_WARNING_OBJECT (self, "unhandled select return state?");      continue;    }    g_assert_not_reached ();  stopped:    {      GST_DEBUG_OBJECT (self, "shutting down");      /* socket gets closed in _stop() */      return NULL;    }  receive_error:    {      GST_WARNING_OBJECT (self, "receive error");      continue;    }    g_assert_not_reached ();  }  g_assert_not_reached ();  return NULL;}static gbooleangst_net_client_clock_start (GstNetClientClock * self){  struct sockaddr_in servaddr, myaddr;  socklen_t len;  gint ret;  GError *error;  g_return_val_if_fail (self->address != NULL, FALSE);  g_return_val_if_fail (self->servaddr == NULL, FALSE);  if ((ret = socket (AF_INET, SOCK_DGRAM, 0)) < 0)    goto no_socket;  self->sock = ret;  len = sizeof (myaddr);  ret = getsockname (self->sock, (struct sockaddr *) &myaddr, &len);  if (ret < 0)    goto getsockname_error;  memset (&servaddr, 0, sizeof (servaddr));  servaddr.sin_family = AF_INET;        /* host byte order */  servaddr.sin_port = htons (self->port);       /* short, network byte order */  GST_DEBUG_OBJECT (self, "socket opened on UDP port %hd",      ntohs (servaddr.sin_port));  if (!inet_aton (self->address, &servaddr.sin_addr))    goto bad_address;  self->servaddr = g_malloc (sizeof (struct sockaddr_in));  memcpy (self->servaddr, &servaddr, sizeof (servaddr));  GST_DEBUG_OBJECT (self, "will communicate with %s:%d", self->address,      self->port);  self->thread = g_thread_create (gst_net_client_clock_thread, self, TRUE,      &error);  if (!self->thread)    goto no_thread;  return TRUE;  /* ERRORS */no_socket:  {    GST_ERROR_OBJECT (self, "socket failed %d: %s (%d)", ret,        g_strerror (errno), errno);    return FALSE;  }getsockname_error:  {    GST_ERROR_OBJECT (self, "getsockname failed %d: %s (%d)", ret,        g_strerror (errno), errno);    close (self->sock);    self->sock = -1;    return FALSE;  }bad_address:  {    GST_ERROR_OBJECT (self, "inet_aton failed %d: %s (%d)", ret,        g_strerror (errno), errno);    close (self->sock);    self->sock = -1;    return FALSE;  }no_thread:  {    GST_ERROR_OBJECT (self, "could not create thread: %s", error->message);    close (self->sock);    self->sock = -1;    g_free (self->servaddr);    self->servaddr = NULL;    g_error_free (error);    return FALSE;  }}static voidgst_net_client_clock_stop (GstNetClientClock * self){  SEND_COMMAND (self, CONTROL_STOP);  g_thread_join (self->thread);  self->thread = NULL;  if (self->sock != -1) {    close (self->sock);    self->sock = -1;  }}/** * gst_net_client_clock_new: * @name: a name for the clock * @remote_address: the address of the remote clock provider * @remote_port: the port of the remote clock provider * @base_time: initial time of the clock * * Create a new #GstNetClientClock that will report the time * provided by the #GstNetClockProvider on @remote_address and  * @remote_port. * * Returns: a new #GstClock that receives a time from the remote * clock. */GstClock *gst_net_client_clock_new (gchar * name, const gchar * remote_address,    gint remote_port, GstClockTime base_time){  GstNetClientClock *ret;  GstClockTime internal;  gint iret;  g_return_val_if_fail (remote_address != NULL, NULL);  g_return_val_if_fail (remote_port > 0, NULL);  g_return_val_if_fail (remote_port <= G_MAXUINT16, NULL);  g_return_val_if_fail (base_time != GST_CLOCK_TIME_NONE, NULL);  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));  gst_clock_set_calibration (GST_CLOCK (ret), internal, base_time, 1, 1);  {    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!");  }#ifdef G_OS_WIN32  GST_DEBUG_OBJECT (ret, "creating pipe");  if ((iret = _pipe (CONTROL_SOCKETS (ret), 4096, _O_BINARY)) < 0)    goto no_socket_pair;#else  GST_DEBUG_OBJECT (ret, "creating socket pair");  if ((iret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (ret))) < 0)    goto no_socket_pair;  fcntl (READ_SOCKET (ret), F_SETFL, O_NONBLOCK);  fcntl (WRITE_SOCKET (ret), F_SETFL, O_NONBLOCK);#endif  if (!gst_net_client_clock_start (ret))    goto failed_start;  /* all systems go, cap'n */  return (GstClock *) ret;no_socket_pair:  {    GST_ERROR_OBJECT (ret, "no socket pair %d: %s (%d)", iret,        g_strerror (errno), errno);    gst_object_unref (ret);    return NULL;  }failed_start:  {    /* already printed a nice error */    gst_object_unref (ret);    return NULL;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -