/** * shm_writer_open * @self: the #ShmWriter instance to open * @preferred_socket_path: the preferred socket path to use for this #ShmWriter * * Opens an unopened #ShmWriter to start accepting connections from clients. * The @preferred_socket_path is a suggestion for the path of the socket the * #ShmWriter will use. If the path is available it will be used. Otherwise, * the ShmWriter will pick a name derived from it. * * Returns: the path actually chosen by the #ShmWriter. */ const gchar * shm_writer_open (ShmWriter *self, const gchar *preferred_socket_path) { ShmWriterPrivate *priv = self->priv; int fd; if (priv->open) return NULL; priv->writer = sp_writer_create (preferred_socket_path, priv->size, priv->mode); if (priv->writer == NULL) { g_warning ("Unable to open ShmWriter: %p", self); return NULL; } fd = sp_get_fd (priv->writer); /* Listen for events on the writer's fd. * This fd is used for accepting connections from ShmReaders * (or anything that knows the protocol used). Separate fds * are then opened for actual data signaling */ shm_writer_add_fd_source (self, fd, shm_writer_fd_cb, self, NULL); priv->socket_path = g_strdup (sp_writer_get_path (priv->writer)); priv->open = TRUE; g_object_notify (G_OBJECT (self), "open"); return priv->socket_path; }
/** * 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; }
static gboolean gst_shm_sink_start (GstBaseSink * bsink) { GstShmSink *self = GST_SHM_SINK (bsink); GError *err = NULL; self->stop = FALSE; if (!self->socket_path) { GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ_WRITE, ("Could not open socket."), (NULL)); return FALSE; } GST_DEBUG_OBJECT (self, "Creating new socket at %s" " with shared memory of %d bytes", self->socket_path, self->size); self->pipe = sp_writer_create (self->socket_path, self->size, self->perms); if (!self->pipe) { GST_ELEMENT_ERROR (self, RESOURCE, OPEN_READ_WRITE, ("Could not open socket."), (NULL)); return FALSE; } sp_set_data (self->pipe, self); g_free (self->socket_path); self->socket_path = g_strdup (sp_writer_get_path (self->pipe)); GST_DEBUG ("Created socket at %s", self->socket_path); self->poll = gst_poll_new (TRUE); gst_poll_fd_init (&self->serverpollfd); self->serverpollfd.fd = sp_get_fd (self->pipe); gst_poll_add_fd (self->poll, &self->serverpollfd); gst_poll_fd_ctl_read (self->poll, &self->serverpollfd, TRUE); self->pollthread = g_thread_try_new ("gst-shmsink-poll-thread", pollthread_func, self, &err); if (!self->pollthread) goto thread_error; self->allocator = gst_shm_sink_allocator_new (self); return TRUE; thread_error: sp_writer_close (self->pipe, NULL, NULL); self->pipe = NULL; gst_poll_free (self->poll); GST_ELEMENT_ERROR (self, CORE, THREAD, ("Could not start thread"), ("%s", err->message)); g_error_free (err); return FALSE; }
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; }