static gboolean gst_fd_sink_start (GstBaseSink * basesink) { GstFdSink *fdsink; GstPollFD fd = GST_POLL_FD_INIT; fdsink = GST_FD_SINK (basesink); if (!gst_fd_sink_check_fd (fdsink, fdsink->fd, NULL)) return FALSE; if ((fdsink->fdset = gst_poll_new (TRUE)) == NULL) goto socket_pair; fd.fd = fdsink->fd; gst_poll_add_fd (fdsink->fdset, &fd); gst_poll_fd_ctl_write (fdsink->fdset, &fd, TRUE); fdsink->bytes_written = 0; fdsink->current_pos = 0; fdsink->seekable = gst_fd_sink_do_seek (fdsink, 0); GST_INFO_OBJECT (fdsink, "seeking supported: %d", fdsink->seekable); return TRUE; /* ERRORS */ socket_pair: { GST_ELEMENT_ERROR (fdsink, RESOURCE, OPEN_READ_WRITE, (NULL), GST_ERROR_SYSTEM); return FALSE; } }
static gboolean gst_fd_sink_update_fd (GstFdSink * fdsink, int new_fd) { if (new_fd < 0) return FALSE; if (!gst_fd_sink_check_fd (fdsink, new_fd)) goto invalid; /* assign the fd */ GST_OBJECT_LOCK (fdsink); if (fdsink->fdset) { GstPollFD fd = GST_POLL_FD_INIT; fd.fd = fdsink->fd; gst_poll_remove_fd (fdsink->fdset, &fd); fd.fd = new_fd; gst_poll_add_fd (fdsink->fdset, &fd); gst_poll_fd_ctl_write (fdsink->fdset, &fd, TRUE); } fdsink->fd = new_fd; g_free (fdsink->uri); fdsink->uri = g_strdup_printf ("fd://%d", fdsink->fd); GST_OBJECT_UNLOCK (fdsink); return TRUE; invalid: { return FALSE; } }
static gboolean gst_fd_sink_update_fd (GstFdSink * fdsink, int new_fd, GError ** error) { if (new_fd < 0) { g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_REFERENCE, "File descriptor %d is not valid", new_fd); return FALSE; } if (!gst_fd_sink_check_fd (fdsink, new_fd, error)) goto invalid; /* assign the fd */ GST_OBJECT_LOCK (fdsink); if (fdsink->fdset) { GstPollFD fd = GST_POLL_FD_INIT; fd.fd = fdsink->fd; gst_poll_remove_fd (fdsink->fdset, &fd); fd.fd = new_fd; gst_poll_add_fd (fdsink->fdset, &fd); gst_poll_fd_ctl_write (fdsink->fdset, &fd, TRUE); } fdsink->fd = new_fd; g_free (fdsink->uri); fdsink->uri = g_strdup_printf ("fd://%d", fdsink->fd); GST_OBJECT_UNLOCK (fdsink); return TRUE; invalid: { return FALSE; } }