2003-06-22 03:58:04 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 1999-2001 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* Copyright (C) 2002 David A. Schleef <ds@schleef.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2003-06-22 03:58:04 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include "efence.h"
|
|
|
|
|
2003-08-21 04:42:56 +00:00
|
|
|
#ifndef MAP_ANONYMOUS
|
2004-02-02 18:28:46 +00:00
|
|
|
#ifdef MAP_ANON
|
2003-08-21 04:42:56 +00:00
|
|
|
#define MAP_ANONYMOUS MAP_ANON
|
2004-02-02 18:28:46 +00:00
|
|
|
#else
|
|
|
|
/* assume we don't need it */
|
|
|
|
#define MAP_ANONYMOUS 0
|
|
|
|
#endif
|
2003-08-21 04:42:56 +00:00
|
|
|
#endif
|
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
static GstElementDetails plugin_details = {
|
|
|
|
"Electric Fence",
|
|
|
|
"Testing/EFence",
|
|
|
|
"This element converts a stream of normal GStreamer buffers into a "
|
2004-03-14 22:34:33 +00:00
|
|
|
"stream of buffers that are allocated in such a way that out-of-bounds "
|
|
|
|
"access to data in the buffer is more likely to cause segmentation "
|
|
|
|
"faults. This allocation method is very similar to the debugging tool "
|
|
|
|
"\"Electric Fence\".",
|
2003-06-22 03:58:04 +00:00
|
|
|
"David A. Schleef <ds@schleef.org>",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Filter signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-06-22 03:58:04 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2003-06-22 03:58:04 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_FENCE_TOP
|
|
|
|
};
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate gst_efence_sink_factory =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate gst_efence_src_factory =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
static void gst_efence_base_init (gpointer g_class);
|
|
|
|
static void gst_efence_class_init (GstEFenceClass * klass);
|
|
|
|
static void gst_efence_init (GstEFence * filter);
|
|
|
|
|
|
|
|
static void gst_efence_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_efence_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
static void gst_efence_chain (GstPad * pad, GstData * _data);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
typedef struct _GstFencedBuffer GstFencedBuffer;
|
2004-03-14 22:34:33 +00:00
|
|
|
struct _GstFencedBuffer
|
|
|
|
{
|
2003-06-22 03:58:04 +00:00
|
|
|
GstBuffer buffer;
|
|
|
|
void *region;
|
|
|
|
unsigned int length;
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
void gst_fenced_buffer_default_free (GstData * data);
|
|
|
|
GstData *gst_fenced_buffer_default_copy (const GstData * data);
|
|
|
|
void *gst_fenced_buffer_alloc (GstBuffer * buffer, unsigned int length,
|
2003-06-22 03:58:04 +00:00
|
|
|
gboolean fence_top);
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstBuffer *gst_efence_buffer_alloc (GstPad * pad, guint64 offset,
|
|
|
|
guint size);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GstBuffer *gst_fenced_buffer_new (void);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
gst_gst_efence_get_type (void)
|
|
|
|
{
|
|
|
|
static GType plugin_type = 0;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!plugin_type) {
|
|
|
|
static const GTypeInfo plugin_info = {
|
2003-06-22 03:58:04 +00:00
|
|
|
sizeof (GstEFenceClass),
|
2003-11-01 12:24:33 +00:00
|
|
|
gst_efence_base_init,
|
2003-06-22 03:58:04 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_efence_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstEFence),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_efence_init,
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
plugin_type = g_type_register_static (GST_TYPE_ELEMENT,
|
2004-03-15 19:32:27 +00:00
|
|
|
"GstEFence", &plugin_info, 0);
|
2003-06-22 03:58:04 +00:00
|
|
|
}
|
|
|
|
return plugin_type;
|
|
|
|
}
|
|
|
|
|
2003-11-01 12:24:33 +00:00
|
|
|
static void
|
|
|
|
gst_efence_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&gst_efence_sink_factory));
|
2003-12-22 01:47:09 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&gst_efence_src_factory));
|
2003-11-01 12:24:33 +00:00
|
|
|
gst_element_class_set_details (element_class, &plugin_details);
|
|
|
|
}
|
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
/* initialize the plugin's class */
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_efence_class_init (GstEFenceClass * klass)
|
2003-06-22 03:58:04 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, ARG_FENCE_TOP,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_boolean ("fence_top", "Fence Top",
|
2004-03-15 19:32:27 +00:00
|
|
|
"Align buffers with top of fenced region", TRUE, G_PARAM_READWRITE));
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_efence_set_property;
|
|
|
|
gobject_class->get_property = gst_efence_get_property;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the new element
|
|
|
|
* instantiate pads and add them to element
|
|
|
|
* set functions
|
|
|
|
* initialize structure
|
|
|
|
*/
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_efence_init (GstEFence * filter)
|
2003-06-22 03:58:04 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
filter->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&gst_efence_sink_factory), "sink");
|
2004-01-12 23:24:05 +00:00
|
|
|
gst_pad_set_getcaps_function (filter->sinkpad, gst_pad_proxy_getcaps);
|
2004-01-02 07:25:10 +00:00
|
|
|
gst_pad_set_link_function (filter->sinkpad, gst_pad_proxy_pad_link);
|
2004-03-14 22:34:33 +00:00
|
|
|
filter->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&gst_efence_src_factory), "src");
|
2004-01-12 23:24:05 +00:00
|
|
|
gst_pad_set_getcaps_function (filter->srcpad, gst_pad_proxy_getcaps);
|
2004-01-02 07:25:10 +00:00
|
|
|
gst_pad_set_link_function (filter->srcpad, gst_pad_proxy_pad_link);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
|
|
|
|
gst_pad_set_chain_function (filter->sinkpad, gst_efence_chain);
|
2004-01-12 23:24:05 +00:00
|
|
|
gst_pad_set_bufferalloc_function (filter->sinkpad, gst_efence_buffer_alloc);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
filter->fence_top = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* chain function
|
|
|
|
* this function does the actual processing
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_efence_chain (GstPad * pad, GstData * _data)
|
2003-06-22 03:58:04 +00:00
|
|
|
{
|
2003-10-08 16:08:18 +00:00
|
|
|
GstBuffer *buffer = GST_BUFFER (_data);
|
2003-06-22 03:58:04 +00:00
|
|
|
GstEFence *efence;
|
|
|
|
GstBuffer *copy;
|
|
|
|
void *ptr;
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("gst_efence_chain");
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buffer != NULL);
|
|
|
|
|
|
|
|
efence = GST_EFENCE (GST_OBJECT_PARENT (pad));
|
|
|
|
g_return_if_fail (GST_IS_EFENCE (efence));
|
|
|
|
|
2004-01-12 23:24:05 +00:00
|
|
|
if (GST_DATA_FREE_FUNC (_data) == gst_fenced_buffer_default_free) {
|
|
|
|
gst_pad_push (efence->srcpad, _data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
copy = gst_fenced_buffer_new ();
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
ptr = gst_fenced_buffer_alloc (copy, GST_BUFFER_SIZE (buffer),
|
2003-06-22 03:58:04 +00:00
|
|
|
efence->fence_top);
|
2004-03-14 22:34:33 +00:00
|
|
|
memcpy (ptr, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
|
|
|
|
|
|
|
|
GST_BUFFER_DATA (copy) = ptr;
|
|
|
|
GST_BUFFER_SIZE (copy) = GST_BUFFER_SIZE (buffer);
|
|
|
|
GST_BUFFER_MAXSIZE (copy) = GST_BUFFER_SIZE (buffer);
|
|
|
|
GST_BUFFER_TIMESTAMP (copy) = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
GST_BUFFER_DURATION (copy) = GST_BUFFER_DURATION (buffer);
|
|
|
|
GST_BUFFER_OFFSET (copy) = GST_BUFFER_OFFSET (buffer);
|
2004-01-11 22:03:52 +00:00
|
|
|
GST_BUFFER_FREE_DATA_FUNC (copy) = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_PRIVATE (copy) = NULL;
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2003-10-08 16:08:18 +00:00
|
|
|
gst_pad_push (efence->srcpad, GST_DATA (copy));
|
2003-06-22 03:58:04 +00:00
|
|
|
}
|
|
|
|
|
2004-01-12 23:24:05 +00:00
|
|
|
static GstBuffer *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_efence_buffer_alloc (GstPad * pad, guint64 offset, guint size)
|
2004-01-12 23:24:05 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstEFence *efence;
|
|
|
|
|
|
|
|
efence = GST_EFENCE (GST_OBJECT_PARENT (pad));
|
|
|
|
|
|
|
|
buffer = gst_fenced_buffer_new ();
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_DATA (buffer) = gst_fenced_buffer_alloc (buffer, size,
|
2004-01-12 23:24:05 +00:00
|
|
|
efence->fence_top);
|
|
|
|
GST_BUFFER_SIZE (buffer) = size;
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_efence_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2003-06-22 03:58:04 +00:00
|
|
|
{
|
|
|
|
GstEFence *filter;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_EFENCE (object));
|
|
|
|
filter = GST_EFENCE (object);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_FENCE_TOP:
|
|
|
|
filter->fence_top = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2003-06-22 03:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_efence_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2003-06-22 03:58:04 +00:00
|
|
|
{
|
|
|
|
GstEFence *filter;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_EFENCE (object));
|
|
|
|
filter = GST_EFENCE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2004-03-14 22:34:33 +00:00
|
|
|
case ARG_FENCE_TOP:
|
|
|
|
g_value_set_boolean (value, filter->fence_top);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2003-06-22 03:58:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* entry point to initialize the plug-in
|
|
|
|
* initialize the plug-in itself
|
|
|
|
* register the element factories and pad templates
|
|
|
|
* register the features
|
|
|
|
*/
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2003-06-22 03:58:04 +00:00
|
|
|
{
|
2003-11-01 12:24:33 +00:00
|
|
|
if (!gst_element_register (plugin, "efence", GST_RANK_NONE, GST_TYPE_EFENCE))
|
|
|
|
return FALSE;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
/* plugin initialisation succeeded */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"efence",
|
|
|
|
"This element converts a stream of normal GStreamer buffers into a "
|
|
|
|
"stream of buffers that are allocated in such a way that out-of-bounds "
|
|
|
|
"access to data in the buffer is more likely to cause segmentation "
|
|
|
|
"faults. This allocation method is very similar to the debugging tool "
|
|
|
|
"\"Electric Fence\".",
|
|
|
|
plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
|
|
|
|
|
|
|
|
GstBuffer *gst_fenced_buffer_new (void)
|
2003-06-22 03:58:04 +00:00
|
|
|
{
|
|
|
|
GstBuffer *newbuf;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
newbuf = (GstBuffer *) g_new0 (GstFencedBuffer, 1);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
gst_data_init (GST_DATA (newbuf), _gst_buffer_type, 0,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_fenced_buffer_default_free, gst_fenced_buffer_default_copy);
|
|
|
|
|
|
|
|
GST_BUFFER_DATA (newbuf) = NULL;
|
|
|
|
GST_BUFFER_SIZE (newbuf) = 0;
|
|
|
|
GST_BUFFER_MAXSIZE (newbuf) = GST_BUFFER_MAXSIZE_NONE;
|
|
|
|
GST_BUFFER_TIMESTAMP (newbuf) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_DURATION (newbuf) = GST_CLOCK_TIME_NONE;
|
|
|
|
GST_BUFFER_OFFSET (newbuf) = GST_BUFFER_OFFSET_NONE;
|
2004-01-11 22:03:52 +00:00
|
|
|
GST_BUFFER_FREE_DATA_FUNC (newbuf) = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_PRIVATE (newbuf) = NULL;
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("new buffer=%p", newbuf);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
void
|
|
|
|
gst_fenced_buffer_default_free (GstData * data)
|
2003-06-22 03:58:04 +00:00
|
|
|
{
|
|
|
|
GstFencedBuffer *fenced_buffer;
|
2004-01-12 23:24:05 +00:00
|
|
|
GstBuffer *buffer = GST_BUFFER (data);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2004-01-12 23:24:05 +00:00
|
|
|
GST_DEBUG ("free buffer=%p", data);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2004-01-12 23:24:05 +00:00
|
|
|
g_return_if_fail (data != NULL);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2004-01-12 23:24:05 +00:00
|
|
|
fenced_buffer = (GstFencedBuffer *) data;
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
/* free our data */
|
|
|
|
if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_DONTFREE) &&
|
|
|
|
GST_BUFFER_DATA (buffer)) {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("free region %p %d", fenced_buffer->region,
|
2004-03-15 19:32:27 +00:00
|
|
|
fenced_buffer->length);
|
2004-03-14 22:34:33 +00:00
|
|
|
munmap (fenced_buffer->region, fenced_buffer->length);
|
|
|
|
} else {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("not freeing region %p %d %p", fenced_buffer->region,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_BUFFER_FLAGS (buffer), GST_BUFFER_DATA (buffer));
|
2003-06-22 03:58:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set to safe values */
|
|
|
|
GST_BUFFER_DATA (buffer) = NULL;
|
|
|
|
GST_BUFFER_SIZE (buffer) = 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
g_free (buffer);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GstData *
|
|
|
|
gst_fenced_buffer_default_copy (const GstData * data)
|
|
|
|
{
|
2004-01-12 23:24:05 +00:00
|
|
|
GstBuffer *buffer = GST_BUFFER (data);
|
|
|
|
GstData *copy;
|
2003-06-22 03:58:04 +00:00
|
|
|
void *ptr;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
g_return_val_if_fail (buffer != NULL, NULL);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
/* create a fresh new buffer */
|
2004-03-14 22:34:33 +00:00
|
|
|
copy = (GstData *) g_new0 (GstFencedBuffer, 1);
|
|
|
|
|
2004-01-12 23:24:05 +00:00
|
|
|
gst_data_init (copy, _gst_buffer_type, 0,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_fenced_buffer_default_free, gst_fenced_buffer_default_copy);
|
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
/* we simply copy everything from our parent */
|
2004-03-14 22:34:33 +00:00
|
|
|
ptr = gst_fenced_buffer_alloc (GST_BUFFER (copy),
|
|
|
|
GST_BUFFER_SIZE (buffer), TRUE);
|
|
|
|
memcpy (ptr, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
|
|
|
|
|
|
|
|
GST_BUFFER_SIZE (copy) = GST_BUFFER_SIZE (buffer);
|
|
|
|
GST_BUFFER_MAXSIZE (copy) = GST_BUFFER_SIZE (buffer);
|
|
|
|
GST_BUFFER_TIMESTAMP (copy) = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
GST_BUFFER_DURATION (copy) = GST_BUFFER_DURATION (buffer);
|
|
|
|
GST_BUFFER_OFFSET (copy) = GST_BUFFER_OFFSET (buffer);
|
2004-01-11 22:03:52 +00:00
|
|
|
GST_BUFFER_FREE_DATA_FUNC (copy) = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_BUFFER_PRIVATE (copy) = NULL;
|
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
void *
|
|
|
|
gst_fenced_buffer_alloc (GstBuffer * buffer, unsigned int length,
|
2003-06-22 03:58:04 +00:00
|
|
|
gboolean fence_top)
|
|
|
|
{
|
|
|
|
int alloc_size;
|
|
|
|
void *region;
|
|
|
|
GstFencedBuffer *fenced_buffer = (GstFencedBuffer *) buffer;
|
|
|
|
int page_size;
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("buffer=%p length=%d fence_top=%d", buffer, length, fence_top);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (length == 0)
|
|
|
|
return NULL;
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
#ifdef _SC_PAGESIZE
|
2004-03-14 22:34:33 +00:00
|
|
|
page_size = sysconf (_SC_PAGESIZE);
|
2003-06-22 03:58:04 +00:00
|
|
|
#else
|
2004-03-14 22:34:33 +00:00
|
|
|
page_size = getpagesize ();
|
2003-06-22 03:58:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
alloc_size = ((length - 1) & ~(page_size - 1)) + page_size;
|
2004-03-14 22:34:33 +00:00
|
|
|
alloc_size += 2 * page_size;
|
2003-06-22 03:58:04 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
region = mmap (NULL, alloc_size, PROT_READ | PROT_WRITE,
|
2003-06-22 03:58:04 +00:00
|
|
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
2004-03-14 22:34:33 +00:00
|
|
|
if (region == MAP_FAILED) {
|
|
|
|
g_warning ("mmap failed");
|
2003-06-22 03:58:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
munmap (region, page_size);
|
|
|
|
munmap (region + alloc_size - page_size, page_size);
|
2003-06-22 03:58:04 +00:00
|
|
|
|
|
|
|
fenced_buffer->region = region;
|
|
|
|
fenced_buffer->length = alloc_size;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG ("new region %p %d", fenced_buffer->region, fenced_buffer->length);
|
|
|
|
|
|
|
|
if (fence_top) {
|
2003-06-22 03:58:04 +00:00
|
|
|
int offset;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-22 03:58:04 +00:00
|
|
|
/* Align to top of region, but force alignment to 4 bytes */
|
|
|
|
offset = alloc_size - page_size - length;
|
|
|
|
offset &= ~0x3;
|
|
|
|
return region + offset;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2003-06-22 03:58:04 +00:00
|
|
|
return region + page_size;
|
|
|
|
}
|
|
|
|
}
|