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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gstfdsink.h>
|
2000-02-27 23:18:38 +00:00
|
|
|
#include <unistd.h>
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
GstElementDetails gst_fdsink_details = {
|
|
|
|
"Filedescriptor Sink",
|
|
|
|
"Sink",
|
|
|
|
"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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-11-25 14:18:47 +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
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void gst_fdsink_set_arg (GtkObject *object, GtkArg *arg, guint id);
|
|
|
|
static void gst_fdsink_get_arg (GtkObject *object, GtkArg *arg, guint id);
|
|
|
|
|
|
|
|
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;
|
2000-02-27 23:18:38 +00:00
|
|
|
//static guint gst_fdsink_signals[LAST_SIGNAL] = { 0 };
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
GtkType
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_fdsink_get_type (void)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
static GtkType fdsink_type = 0;
|
|
|
|
|
|
|
|
if (!fdsink_type) {
|
|
|
|
static const GtkTypeInfo fdsink_info = {
|
|
|
|
"GstFdSink",
|
|
|
|
sizeof(GstFdSink),
|
|
|
|
sizeof(GstFdSinkClass),
|
|
|
|
(GtkClassInitFunc)gst_fdsink_class_init,
|
|
|
|
(GtkObjectInitFunc)gst_fdsink_init,
|
|
|
|
(GtkArgSetFunc)gst_fdsink_set_arg,
|
|
|
|
(GtkArgGetFunc)gst_fdsink_get_arg,
|
|
|
|
(GtkClassInitFunc)NULL,
|
|
|
|
};
|
2000-12-29 02:28:04 +00:00
|
|
|
fdsink_type = gtk_type_unique (GST_TYPE_ELEMENT, &fdsink_info);
|
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)
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GtkObjectClass *gtkobject_class;
|
|
|
|
|
|
|
|
gtkobject_class = (GtkObjectClass*)klass;
|
|
|
|
|
2000-12-29 02:28:04 +00:00
|
|
|
parent_class = gtk_type_class (GST_TYPE_ELEMENT);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
gtk_object_add_arg_type ("GstFdSink::fd", GTK_TYPE_INT,
|
|
|
|
GTK_ARG_READWRITE, ARG_FD);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
gtkobject_class->set_arg = gst_fdsink_set_arg;
|
|
|
|
gtkobject_class->get_arg = gst_fdsink_get_arg;
|
|
|
|
}
|
|
|
|
|
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)) {
|
2001-01-01 03:14:40 +00:00
|
|
|
GST_DEBUG (0,"writing %d bytes to file descriptor %d\n",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
|
|
|
|
gst_fdsink_set_arg (GtkObject *object, GtkArg *arg, guint id)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
switch(id) {
|
|
|
|
case ARG_FD:
|
2000-11-25 14:18:47 +00:00
|
|
|
fdsink->fd = GTK_VALUE_INT (*arg);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
static void
|
|
|
|
gst_fdsink_get_arg (GtkObject *object, GtkArg *arg, guint id)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
switch(id) {
|
|
|
|
case ARG_FD:
|
2000-11-25 14:18:47 +00:00
|
|
|
GTK_VALUE_INT (*arg) = fdsink->fd;
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|