multifile: port to 0.10

* use G_DEFINE_TYPE
* adjust to new GstBuffer
* misc caps handling
This commit is contained in:
Mark Nauwelaerts 2011-06-30 12:30:22 +02:00
parent 01fcf3f2ed
commit 70b561bc13
2 changed files with 60 additions and 61 deletions

View file

@ -171,29 +171,14 @@ gst_multi_file_sink_next_get_type (void)
return multi_file_sync_next_type; return multi_file_sync_next_type;
} }
GST_BOILERPLATE (GstMultiFileSink, gst_multi_file_sink, GstBaseSink, #define gst_multi_file_sink_parent_class parent_class
GST_TYPE_BASE_SINK); G_DEFINE_TYPE (GstMultiFileSink, gst_multi_file_sink, GST_TYPE_BASE_SINK);
static void
gst_multi_file_sink_base_init (gpointer g_class)
{
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
GST_DEBUG_CATEGORY_INIT (gst_multi_file_sink_debug, "multifilesink", 0,
"multifilesink element");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sinktemplate));
gst_element_class_set_details_simple (gstelement_class, "Multi-File Sink",
"Sink/File",
"Write buffers to a sequentially named set of files",
"David Schleef <ds@schleef.org>");
}
static void static void
gst_multi_file_sink_class_init (GstMultiFileSinkClass * klass) gst_multi_file_sink_class_init (GstMultiFileSinkClass * klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
GstBaseSinkClass *gstbasesink_class = GST_BASE_SINK_CLASS (klass); GstBaseSinkClass *gstbasesink_class = GST_BASE_SINK_CLASS (klass);
gobject_class->set_property = gst_multi_file_sink_set_property; gobject_class->set_property = gst_multi_file_sink_set_property;
@ -241,11 +226,20 @@ gst_multi_file_sink_class_init (GstMultiFileSinkClass * klass)
gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_multi_file_sink_render); gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_multi_file_sink_render);
gstbasesink_class->set_caps = gstbasesink_class->set_caps =
GST_DEBUG_FUNCPTR (gst_multi_file_sink_set_caps); GST_DEBUG_FUNCPTR (gst_multi_file_sink_set_caps);
GST_DEBUG_CATEGORY_INIT (gst_multi_file_sink_debug, "multifilesink", 0,
"multifilesink element");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sinktemplate));
gst_element_class_set_details_simple (gstelement_class, "Multi-File Sink",
"Sink/File",
"Write buffers to a sequentially named set of files",
"David Schleef <ds@schleef.org>");
} }
static void static void
gst_multi_file_sink_init (GstMultiFileSink * multifilesink, gst_multi_file_sink_init (GstMultiFileSink * multifilesink)
GstMultiFileSinkClass * g_class)
{ {
multifilesink->filename = g_strdup (DEFAULT_LOCATION); multifilesink->filename = g_strdup (DEFAULT_LOCATION);
multifilesink->index = DEFAULT_INDEX; multifilesink->index = DEFAULT_INDEX;
@ -393,14 +387,13 @@ static GstFlowReturn
gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer) gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
{ {
GstMultiFileSink *multifilesink; GstMultiFileSink *multifilesink;
guint size; gsize size;
guint8 *data; guint8 *data;
gchar *filename; gchar *filename;
gboolean ret; gboolean ret;
GError *error = NULL; GError *error = NULL;
size = GST_BUFFER_SIZE (buffer); data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
data = GST_BUFFER_DATA (buffer);
multifilesink = GST_MULTI_FILE_SINK (sink); multifilesink = GST_MULTI_FILE_SINK (sink);
@ -442,8 +435,7 @@ gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
goto stdio_write_error; goto stdio_write_error;
} }
ret = fwrite (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer), 1, ret = fwrite (data, size, 1, multifilesink->file);
multifilesink->file);
if (ret != 1) if (ret != 1)
goto stdio_write_error; goto stdio_write_error;
@ -486,17 +478,20 @@ gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
if (multifilesink->streamheaders) { if (multifilesink->streamheaders) {
for (i = 0; i < multifilesink->n_streamheaders; i++) { for (i = 0; i < multifilesink->n_streamheaders; i++) {
ret = fwrite (GST_BUFFER_DATA (multifilesink->streamheaders[i]), guint8 *sdata;
GST_BUFFER_SIZE (multifilesink->streamheaders[i]), 1, gsize ssize;
multifilesink->file);
sdata = gst_buffer_map (multifilesink->streamheaders[i], &ssize,
NULL, GST_MAP_READ);
ret = fwrite (data, ssize, 1, multifilesink->file);
gst_buffer_unmap (multifilesink->streamheaders[i], sdata, ssize);
if (ret != 1) if (ret != 1)
goto stdio_write_error; goto stdio_write_error;
} }
} }
} }
ret = fwrite (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer), 1, ret = fwrite (data, size, 1, multifilesink->file);
multifilesink->file);
if (ret != 1) if (ret != 1)
goto stdio_write_error; goto stdio_write_error;
@ -505,6 +500,7 @@ gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
g_assert_not_reached (); g_assert_not_reached ();
} }
gst_buffer_unmap (buffer, data, size);
return GST_FLOW_OK; return GST_FLOW_OK;
/* ERRORS */ /* ERRORS */
@ -525,12 +521,16 @@ write_error:
g_error_free (error); g_error_free (error);
g_free (filename); g_free (filename);
gst_buffer_unmap (buffer, data, size);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
stdio_write_error: stdio_write_error:
GST_ELEMENT_ERROR (multifilesink, RESOURCE, WRITE, {
("Error while writing to file."), (NULL)); GST_ELEMENT_ERROR (multifilesink, RESOURCE, WRITE,
return GST_FLOW_ERROR; ("Error while writing to file."), (NULL));
gst_buffer_unmap (buffer, data, size);
return GST_FLOW_ERROR;
}
} }
static gboolean static gboolean

View file

@ -56,7 +56,7 @@ static void gst_multi_file_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_multi_file_src_get_property (GObject * object, guint prop_id, static void gst_multi_file_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static GstCaps *gst_multi_file_src_getcaps (GstBaseSrc * src); static GstCaps *gst_multi_file_src_getcaps (GstBaseSrc * src, GstCaps * filter);
static gboolean gst_multi_file_src_query (GstBaseSrc * src, GstQuery * query); static gboolean gst_multi_file_src_query (GstBaseSrc * src, GstQuery * query);
@ -80,30 +80,15 @@ enum
#define DEFAULT_LOCATION "%05d" #define DEFAULT_LOCATION "%05d"
#define DEFAULT_INDEX 0 #define DEFAULT_INDEX 0
#define gst_multi_file_src_parent_class parent_class
G_DEFINE_TYPE (GstMultiFileSrc, gst_multi_file_src, GST_TYPE_PUSH_SRC);
GST_BOILERPLATE (GstMultiFileSrc, gst_multi_file_src, GstPushSrc,
GST_TYPE_PUSH_SRC);
static void
gst_multi_file_src_base_init (gpointer g_class)
{
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
GST_DEBUG_CATEGORY_INIT (gst_multi_file_src_debug, "multifilesrc", 0,
"multifilesrc element");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_multi_file_src_pad_template));
gst_element_class_set_details_simple (gstelement_class, "Multi-File Source",
"Source/File",
"Read a sequentially named set of files into buffers",
"David Schleef <ds@schleef.org>");
}
static void static void
gst_multi_file_src_class_init (GstMultiFileSrcClass * klass) gst_multi_file_src_class_init (GstMultiFileSrcClass * klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass); GstPushSrcClass *gstpushsrc_class = GST_PUSH_SRC_CLASS (klass);
GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass); GstBaseSrcClass *gstbasesrc_class = GST_BASE_SRC_CLASS (klass);
@ -138,11 +123,20 @@ gst_multi_file_src_class_init (GstMultiFileSrcClass * klass)
GST_LOG ("No large file support, sizeof (off_t) = %" G_GSIZE_FORMAT, GST_LOG ("No large file support, sizeof (off_t) = %" G_GSIZE_FORMAT,
sizeof (off_t)); sizeof (off_t));
} }
GST_DEBUG_CATEGORY_INIT (gst_multi_file_src_debug, "multifilesrc", 0,
"multifilesrc element");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_multi_file_src_pad_template));
gst_element_class_set_details_simple (gstelement_class, "Multi-File Source",
"Source/File",
"Read a sequentially named set of files into buffers",
"David Schleef <ds@schleef.org>");
} }
static void static void
gst_multi_file_src_init (GstMultiFileSrc * multifilesrc, gst_multi_file_src_init (GstMultiFileSrc * multifilesrc)
GstMultiFileSrcClass * g_class)
{ {
multifilesrc->index = DEFAULT_INDEX; multifilesrc->index = DEFAULT_INDEX;
multifilesrc->filename = g_strdup (DEFAULT_LOCATION); multifilesrc->filename = g_strdup (DEFAULT_LOCATION);
@ -163,16 +157,23 @@ gst_multi_file_src_dispose (GObject * object)
} }
static GstCaps * static GstCaps *
gst_multi_file_src_getcaps (GstBaseSrc * src) gst_multi_file_src_getcaps (GstBaseSrc * src, GstCaps * filter)
{ {
GstMultiFileSrc *multi_file_src = GST_MULTI_FILE_SRC (src); GstMultiFileSrc *multi_file_src = GST_MULTI_FILE_SRC (src);
GST_DEBUG_OBJECT (src, "returning %" GST_PTR_FORMAT, multi_file_src->caps); GST_DEBUG_OBJECT (src, "returning %" GST_PTR_FORMAT, multi_file_src->caps);
if (multi_file_src->caps) { if (multi_file_src->caps) {
return gst_caps_ref (multi_file_src->caps); if (filter)
return gst_caps_intersect_full (filter, multi_file_src->caps,
GST_CAPS_INTERSECT_FIRST);
else
return gst_caps_ref (multi_file_src->caps);
} else { } else {
return gst_caps_new_any (); if (filter)
return gst_caps_ref (filter);
else
return gst_caps_new_any ();
} }
} }
@ -322,13 +323,11 @@ gst_multi_file_src_create (GstPushSrc * src, GstBuffer ** buffer)
multifilesrc->index++; multifilesrc->index++;
buf = gst_buffer_new (); buf = gst_buffer_new ();
GST_BUFFER_DATA (buf) = (unsigned char *) data; gst_buffer_take_memory (buf, -1,
GST_BUFFER_MALLOCDATA (buf) = GST_BUFFER_DATA (buf); gst_memory_new_wrapped (0, data, g_free, size, 0, size));
GST_BUFFER_SIZE (buf) = size;
GST_BUFFER_OFFSET (buf) = multifilesrc->offset; GST_BUFFER_OFFSET (buf) = multifilesrc->offset;
GST_BUFFER_OFFSET_END (buf) = multifilesrc->offset + size; GST_BUFFER_OFFSET_END (buf) = multifilesrc->offset + size;
multifilesrc->offset += size; multifilesrc->offset += size;
gst_buffer_set_caps (buf, multifilesrc->caps);
GST_DEBUG_OBJECT (multifilesrc, "read file \"%s\".", filename); GST_DEBUG_OBJECT (multifilesrc, "read file \"%s\".", filename);