mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
multifile: port to 0.10
* use G_DEFINE_TYPE * adjust to new GstBuffer * misc caps handling
This commit is contained in:
parent
01fcf3f2ed
commit
70b561bc13
2 changed files with 60 additions and 61 deletions
|
@ -171,29 +171,14 @@ gst_multi_file_sink_next_get_type (void)
|
|||
return multi_file_sync_next_type;
|
||||
}
|
||||
|
||||
GST_BOILERPLATE (GstMultiFileSink, gst_multi_file_sink, GstBaseSink,
|
||||
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>");
|
||||
}
|
||||
#define gst_multi_file_sink_parent_class parent_class
|
||||
G_DEFINE_TYPE (GstMultiFileSink, gst_multi_file_sink, GST_TYPE_BASE_SINK);
|
||||
|
||||
static void
|
||||
gst_multi_file_sink_class_init (GstMultiFileSinkClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
||||
GstBaseSinkClass *gstbasesink_class = GST_BASE_SINK_CLASS (klass);
|
||||
|
||||
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->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
|
||||
gst_multi_file_sink_init (GstMultiFileSink * multifilesink,
|
||||
GstMultiFileSinkClass * g_class)
|
||||
gst_multi_file_sink_init (GstMultiFileSink * multifilesink)
|
||||
{
|
||||
multifilesink->filename = g_strdup (DEFAULT_LOCATION);
|
||||
multifilesink->index = DEFAULT_INDEX;
|
||||
|
@ -393,14 +387,13 @@ static GstFlowReturn
|
|||
gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
||||
{
|
||||
GstMultiFileSink *multifilesink;
|
||||
guint size;
|
||||
gsize size;
|
||||
guint8 *data;
|
||||
gchar *filename;
|
||||
gboolean ret;
|
||||
GError *error = NULL;
|
||||
|
||||
size = GST_BUFFER_SIZE (buffer);
|
||||
data = GST_BUFFER_DATA (buffer);
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
|
||||
multifilesink = GST_MULTI_FILE_SINK (sink);
|
||||
|
||||
|
@ -442,8 +435,7 @@ gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
|||
goto stdio_write_error;
|
||||
}
|
||||
|
||||
ret = fwrite (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer), 1,
|
||||
multifilesink->file);
|
||||
ret = fwrite (data, size, 1, multifilesink->file);
|
||||
if (ret != 1)
|
||||
goto stdio_write_error;
|
||||
|
||||
|
@ -486,17 +478,20 @@ gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
|||
|
||||
if (multifilesink->streamheaders) {
|
||||
for (i = 0; i < multifilesink->n_streamheaders; i++) {
|
||||
ret = fwrite (GST_BUFFER_DATA (multifilesink->streamheaders[i]),
|
||||
GST_BUFFER_SIZE (multifilesink->streamheaders[i]), 1,
|
||||
multifilesink->file);
|
||||
guint8 *sdata;
|
||||
gsize ssize;
|
||||
|
||||
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)
|
||||
goto stdio_write_error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret = fwrite (GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer), 1,
|
||||
multifilesink->file);
|
||||
ret = fwrite (data, size, 1, multifilesink->file);
|
||||
if (ret != 1)
|
||||
goto stdio_write_error;
|
||||
|
||||
|
@ -505,6 +500,7 @@ gst_multi_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
|||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
return GST_FLOW_OK;
|
||||
|
||||
/* ERRORS */
|
||||
|
@ -525,12 +521,16 @@ write_error:
|
|||
g_error_free (error);
|
||||
g_free (filename);
|
||||
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
stdio_write_error:
|
||||
GST_ELEMENT_ERROR (multifilesink, RESOURCE, WRITE,
|
||||
("Error while writing to file."), (NULL));
|
||||
return GST_FLOW_ERROR;
|
||||
{
|
||||
GST_ELEMENT_ERROR (multifilesink, RESOURCE, WRITE,
|
||||
("Error while writing to file."), (NULL));
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
@ -56,7 +56,7 @@ static void gst_multi_file_src_set_property (GObject * object, guint prop_id,
|
|||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_multi_file_src_get_property (GObject * object, guint prop_id,
|
||||
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);
|
||||
|
||||
|
||||
|
@ -80,30 +80,15 @@ enum
|
|||
#define DEFAULT_LOCATION "%05d"
|
||||
#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
|
||||
gst_multi_file_src_class_init (GstMultiFileSrcClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
||||
GstPushSrcClass *gstpushsrc_class = GST_PUSH_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,
|
||||
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
|
||||
gst_multi_file_src_init (GstMultiFileSrc * multifilesrc,
|
||||
GstMultiFileSrcClass * g_class)
|
||||
gst_multi_file_src_init (GstMultiFileSrc * multifilesrc)
|
||||
{
|
||||
multifilesrc->index = DEFAULT_INDEX;
|
||||
multifilesrc->filename = g_strdup (DEFAULT_LOCATION);
|
||||
|
@ -163,16 +157,23 @@ gst_multi_file_src_dispose (GObject * object)
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
GST_DEBUG_OBJECT (src, "returning %" GST_PTR_FORMAT, 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 {
|
||||
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++;
|
||||
|
||||
buf = gst_buffer_new ();
|
||||
GST_BUFFER_DATA (buf) = (unsigned char *) data;
|
||||
GST_BUFFER_MALLOCDATA (buf) = GST_BUFFER_DATA (buf);
|
||||
GST_BUFFER_SIZE (buf) = size;
|
||||
gst_buffer_take_memory (buf, -1,
|
||||
gst_memory_new_wrapped (0, data, g_free, size, 0, size));
|
||||
GST_BUFFER_OFFSET (buf) = multifilesrc->offset;
|
||||
GST_BUFFER_OFFSET_END (buf) = multifilesrc->offset + size;
|
||||
multifilesrc->offset += size;
|
||||
gst_buffer_set_caps (buf, multifilesrc->caps);
|
||||
|
||||
GST_DEBUG_OBJECT (multifilesrc, "read file \"%s\".", filename);
|
||||
|
||||
|
|
Loading…
Reference in a new issue