static void gst_fd_src_uri_handler_init (gpointer g_iface, gpointer iface_data);
-static void
-_do_init (GType fd_src_type)
-{
- static const GInterfaceInfo urihandler_info = {
- gst_fd_src_uri_handler_init,
- NULL,
- NULL
- };
-
- g_type_add_interface_static (fd_src_type, GST_TYPE_URI_HANDLER,
- &urihandler_info);
-
+#define _do_init \
+ G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER, gst_fd_src_uri_handler_init); \
GST_DEBUG_CATEGORY_INIT (gst_fd_src_debug, "fdsrc", 0, "fdsrc element");
-}
-
-GST_BOILERPLATE_FULL (GstFdSrc, gst_fd_src, GstPushSrc, GST_TYPE_PUSH_SRC,
- _do_init);
+#define gst_fd_src_parent_class parent_class
+G_DEFINE_TYPE_WITH_CODE (GstFdSrc, gst_fd_src, GST_TYPE_PUSH_SRC, _do_init);
static void gst_fd_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static gboolean gst_fd_src_is_seekable (GstBaseSrc * bsrc);
static gboolean gst_fd_src_get_size (GstBaseSrc * src, guint64 * size);
static gboolean gst_fd_src_do_seek (GstBaseSrc * src, GstSegment * segment);
-static gboolean gst_fd_src_query (GstBaseSrc * src, GstQuery * query);
+static gboolean gst_fd_src_query (GstBaseSrc * src, GstQuery ** query);
static GstFlowReturn gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf);
static void
-gst_fd_src_base_init (gpointer g_class)
-{
- GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
-
- gst_element_class_set_details_simple (gstelement_class,
- "Filedescriptor Source",
- "Source/File",
- "Read from a file descriptor", "Erik Walthinsen <omega@cse.ogi.edu>");
- gst_element_class_add_pad_template (gstelement_class,
- gst_static_pad_template_get (&srctemplate));
-}
-
-static void
gst_fd_src_class_init (GstFdSrcClass * klass)
{
GObjectClass *gobject_class;
+ GstElementClass *gstelement_class;
GstBaseSrcClass *gstbasesrc_class;
GstPushSrcClass *gstpush_src_class;
gobject_class = G_OBJECT_CLASS (klass);
+ gstelement_class = GST_ELEMENT_CLASS (klass);
gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
gstpush_src_class = GST_PUSH_SRC_CLASS (klass);
G_MAXUINT64, DEFAULT_TIMEOUT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ gst_element_class_set_details_simple (gstelement_class,
+ "Filedescriptor Source",
+ "Source/File",
+ "Read from a file descriptor", "Erik Walthinsen <omega@cse.ogi.edu>");
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&srctemplate));
+
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_fd_src_start);
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_fd_src_stop);
gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_fd_src_unlock);
}
static void
-gst_fd_src_init (GstFdSrc * fdsrc, GstFdSrcClass * klass)
+gst_fd_src_init (GstFdSrc * fdsrc)
{
fdsrc->new_fd = DEFAULT_FD;
fdsrc->seekable_fd = FALSE;
gssize readbytes;
guint blocksize;
GstClockTime timeout;
+ guint8 *data;
+ gsize maxsize;
#ifndef HAVE_WIN32
gboolean try_again;
blocksize = GST_BASE_SRC (src)->blocksize;
/* create the buffer */
- buf = gst_buffer_try_new_and_alloc (blocksize);
- if (G_UNLIKELY (buf == NULL)) {
- GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", blocksize);
- return GST_FLOW_ERROR;
- }
+ buf = gst_buffer_new_and_alloc (blocksize);
+ if (G_UNLIKELY (buf == NULL))
+ goto alloc_failed;
+
+ data = gst_buffer_map (buf, NULL, &maxsize, GST_MAP_WRITE);
do {
- readbytes = read (src->fd, GST_BUFFER_DATA (buf), blocksize);
+ readbytes = read (src->fd, data, blocksize);
GST_LOG_OBJECT (src, "read %" G_GSSIZE_FORMAT, readbytes);
} while (readbytes == -1 && errno == EINTR); /* retry if interrupted */
if (readbytes < 0)
goto read_error;
+ gst_buffer_unmap (buf, data, readbytes);
+
if (readbytes == 0)
goto eos;
GST_BUFFER_OFFSET (buf) = src->curoffset;
- GST_BUFFER_SIZE (buf) = readbytes;
GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE;
src->curoffset += readbytes;
return GST_FLOW_WRONG_STATE;
}
#endif
+alloc_failed:
+ {
+ GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", blocksize);
+ return GST_FLOW_ERROR;
+ }
eos:
{
GST_DEBUG_OBJECT (psrc, "Read 0 bytes. EOS.");
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
("read on file descriptor: %s.", g_strerror (errno)));
GST_DEBUG_OBJECT (psrc, "Error reading from fd");
+ gst_buffer_unmap (buf, data, 0);
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
}
static gboolean
-gst_fd_src_query (GstBaseSrc * basesrc, GstQuery * query)
+gst_fd_src_query (GstBaseSrc * basesrc, GstQuery ** query)
{
gboolean ret = FALSE;
GstFdSrc *src = GST_FD_SRC (basesrc);
- switch (GST_QUERY_TYPE (query)) {
+ switch (GST_QUERY_TYPE (*query)) {
case GST_QUERY_URI:
- gst_query_set_uri (query, src->uri);
+ gst_query_set_uri (*query, src->uri);
ret = TRUE;
break;
default:
if (G_UNLIKELY (res < 0 || res != offset))
goto seek_failed;
- segment->last_stop = segment->start;
+ segment->position = segment->start;
segment->time = segment->start;
return TRUE;