2000-12-29 05:38:06 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
|
|
|
* gstfdsink.c:
|
2000-01-30 09:03:00 +00:00
|
|
|
*
|
|
|
|
* 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 14:05:49 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstfdsink.h"
|
2000-02-27 23:18:38 +00:00
|
|
|
#include <unistd.h>
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG_CATEGORY (gst_fdsink_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_fdsink_debug
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
GstElementDetails gst_fdsink_details = {
|
|
|
|
"Filedescriptor Sink",
|
2002-04-20 21:42:53 +00:00
|
|
|
"Sink/File",
|
2002-09-29 17:52:31 +00:00
|
|
|
"LGPL",
|
2000-01-30 09:03:00 +00:00
|
|
|
"Write data to a file descriptor",
|
|
|
|
VERSION,
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>",
|
|
|
|
"(C) 1999",
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* FdSink signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
ARG_FD
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2001-07-11 14:56:16 +00:00
|
|
|
static void gst_fdsink_class_init (GstFdSinkClass *klass);
|
|
|
|
static void gst_fdsink_init (GstFdSink *fdsink);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-07-11 14:56:16 +00:00
|
|
|
static void gst_fdsink_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_fdsink_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
2000-11-25 14:18:47 +00:00
|
|
|
|
2001-07-11 14:56:16 +00:00
|
|
|
static void gst_fdsink_chain (GstPad *pad,GstBuffer *buf);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-12-29 02:28:04 +00:00
|
|
|
static GstElementClass *parent_class = NULL;
|
2001-12-17 18:14:51 +00:00
|
|
|
/*static guint gst_fdsink_signals[LAST_SIGNAL] = { 0 };*/
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
GType
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_fdsink_get_type (void)
|
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
static GType fdsink_type = 0;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
if (!fdsink_type) {
|
2001-06-25 01:20:11 +00:00
|
|
|
static const GTypeInfo fdsink_info = {
|
|
|
|
sizeof(GstFdSinkClass), NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_fdsink_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2000-01-30 09:03:00 +00:00
|
|
|
sizeof(GstFdSink),
|
2001-06-25 01:20:11 +00:00
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_fdsink_init,
|
2000-01-30 09:03:00 +00:00
|
|
|
};
|
2001-06-25 01:20:11 +00:00
|
|
|
fdsink_type = g_type_register_static (GST_TYPE_ELEMENT, "GstFdSink", &fdsink_info, 0);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
return fdsink_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_fdsink_class_init (GstFdSinkClass *klass)
|
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
GObjectClass *gobject_class;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
gobject_class = (GObjectClass*)klass;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-11-21 23:52:30 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FD,
|
|
|
|
g_param_spec_int ("fd", "fd", "An open file descriptor to write to",
|
|
|
|
0, G_MAXINT, 1, G_PARAM_READWRITE));
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
gobject_class->set_property = gst_fdsink_set_property;
|
|
|
|
gobject_class->get_property = gst_fdsink_get_property;
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
|
|
|
gst_fdsink_init (GstFdSink *fdsink)
|
|
|
|
{
|
|
|
|
fdsink->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (fdsink), fdsink->sinkpad);
|
|
|
|
gst_pad_set_chain_function (fdsink->sinkpad, gst_fdsink_chain);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
fdsink->fd = 1;
|
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
|
|
|
gst_fdsink_chain (GstPad *pad, GstBuffer *buf)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstFdSink *fdsink;
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
fdsink = GST_FDSINK (gst_pad_get_parent (pad));
|
2000-11-25 14:18:47 +00:00
|
|
|
|
|
|
|
g_return_if_fail (fdsink->fd >= 0);
|
|
|
|
|
2000-12-12 09:40:25 +00:00
|
|
|
if (GST_BUFFER_DATA (buf)) {
|
2003-06-29 14:05:49 +00:00
|
|
|
GST_DEBUG ("writing %d bytes to file descriptor %d",GST_BUFFER_SIZE (buf), fdsink->fd);
|
2000-11-25 14:18:47 +00:00
|
|
|
write (fdsink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
2000-12-12 09:40:25 +00:00
|
|
|
}
|
2000-11-25 14:18:47 +00:00
|
|
|
|
|
|
|
gst_buffer_unref (buf);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_fdsink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstFdSink *fdsink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (GST_IS_FDSINK (object));
|
|
|
|
|
|
|
|
fdsink = GST_FDSINK (object);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2000-01-30 09:03:00 +00:00
|
|
|
case ARG_FD:
|
2001-06-25 01:20:11 +00:00
|
|
|
fdsink->fd = g_value_get_int (value);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
2001-06-25 01:20:11 +00:00
|
|
|
gst_fdsink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstFdSink *fdsink;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (GST_IS_FDSINK (object));
|
|
|
|
|
|
|
|
fdsink = GST_FDSINK (object);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2000-01-30 09:03:00 +00:00
|
|
|
case ARG_FD:
|
2001-06-25 01:20:11 +00:00
|
|
|
g_value_set_int (value, fdsink->fd);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|