Esempio n. 1
0
/**
 * shm_reader_connect
 * @self: the #ShmReader to use to connect
 * @socket_path: the path to the socket to connect to.
 *
 * Connects an unconnected #ShmReader to the given @socket_path. After
 * a successful connection, #ShmReader::got-data will be triggered when
 * data buffers are received.
 *
 * Returns: %TRUE if succeeded; %FALSE otherwise
 */
gboolean
shm_reader_connect (ShmReader *self, const gchar *socket_path)
{
  ShmReaderPrivate *priv = self->priv;
  int fd;

  if (priv->connected)
    return FALSE;

  priv->client = sp_client_open (socket_path);

  if (priv->client == NULL)
    return FALSE;

  priv->socket_path = g_strdup (socket_path);
  fd = sp_get_fd (priv->client);

  shm_reader_add_fd_source (self, fd, shm_reader_fd_cb,
      self, NULL);

  priv->connected = TRUE;
  g_object_notify (G_OBJECT (self), "connected");

  return TRUE;
}
Esempio n. 2
0
static gboolean
gst_shm_src_start_reading (GstShmSrc * self)
{
  GstShmPipe *gstpipe;

  if (!self->socket_path) {
    GST_ELEMENT_ERROR (self, RESOURCE, NOT_FOUND,
        ("No path specified for socket."), (NULL));
    return FALSE;
  }

  gstpipe = g_slice_new0 (GstShmPipe);
  gstpipe->use_count = 1;
  gstpipe->src = gst_object_ref (self);

  GST_DEBUG_OBJECT (self, "Opening socket %s", self->socket_path);

  GST_OBJECT_LOCK (self);
  gstpipe->pipe = sp_client_open (self->socket_path);
  GST_OBJECT_UNLOCK (self);

  if (!gstpipe->pipe) {
    GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ_WRITE,
        ("Could not open socket %s: %d %s", self->socket_path, errno,
            strerror (errno)), (NULL));
    gst_shm_pipe_dec (gstpipe);
    return FALSE;
  }

  self->pipe = gstpipe;

  gst_poll_set_flushing (self->poll, FALSE);

  gst_poll_fd_init (&self->pollfd);
  self->pollfd.fd = sp_get_fd (self->pipe->pipe);
  gst_poll_add_fd (self->poll, &self->pollfd);
  gst_poll_fd_ctl_read (self->poll, &self->pollfd, TRUE);

  return TRUE;
}