2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <gstfdsink.h>
27 GstElementDetails gst_fdsink_details = {
28 "Filedescriptor Sink",
30 "Write data to a file descriptor",
32 "Erik Walthinsen <omega@cse.ogi.edu>",
37 /* FdSink signals and args */
49 static void gst_fdsink_class_init (GstFdSinkClass *klass);
50 static void gst_fdsink_init (GstFdSink *fdsink);
52 static void gst_fdsink_set_arg (GtkObject *object, GtkArg *arg, guint id);
53 static void gst_fdsink_get_arg (GtkObject *object, GtkArg *arg, guint id);
55 static void gst_fdsink_chain (GstPad *pad,GstBuffer *buf);
57 static GstElementClass *parent_class = NULL;
58 //static guint gst_fdsink_signals[LAST_SIGNAL] = { 0 };
61 gst_fdsink_get_type (void)
63 static GtkType fdsink_type = 0;
66 static const GtkTypeInfo fdsink_info = {
69 sizeof(GstFdSinkClass),
70 (GtkClassInitFunc)gst_fdsink_class_init,
71 (GtkObjectInitFunc)gst_fdsink_init,
72 (GtkArgSetFunc)gst_fdsink_set_arg,
73 (GtkArgGetFunc)gst_fdsink_get_arg,
74 (GtkClassInitFunc)NULL,
76 fdsink_type = gtk_type_unique (GST_TYPE_ELEMENT, &fdsink_info);
82 gst_fdsink_class_init (GstFdSinkClass *klass)
84 GtkObjectClass *gtkobject_class;
86 gtkobject_class = (GtkObjectClass*)klass;
88 parent_class = gtk_type_class (GST_TYPE_ELEMENT);
90 gtk_object_add_arg_type ("GstFdSink::fd", GTK_TYPE_INT,
91 GTK_ARG_READWRITE, ARG_FD);
93 gtkobject_class->set_arg = gst_fdsink_set_arg;
94 gtkobject_class->get_arg = gst_fdsink_get_arg;
98 gst_fdsink_init (GstFdSink *fdsink)
100 fdsink->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
101 gst_element_add_pad (GST_ELEMENT (fdsink), fdsink->sinkpad);
102 gst_pad_set_chain_function (fdsink->sinkpad, gst_fdsink_chain);
108 gst_fdsink_chain (GstPad *pad, GstBuffer *buf)
112 g_return_if_fail (pad != NULL);
113 g_return_if_fail (GST_IS_PAD (pad));
114 g_return_if_fail (buf != NULL);
116 fdsink = GST_FDSINK (gst_pad_get_parent (pad));
118 g_return_if_fail (fdsink->fd >= 0);
120 if (GST_BUFFER_DATA (buf)) {
121 GST_DEBUG (0,"writing %d bytes to file descriptor %d\n",GST_BUFFER_SIZE (buf), fdsink->fd);
122 write (fdsink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
125 gst_buffer_unref (buf);
129 gst_fdsink_set_arg (GtkObject *object, GtkArg *arg, guint id)
133 /* it's not null if we got it, but it might not be ours */
134 g_return_if_fail (GST_IS_FDSINK (object));
136 fdsink = GST_FDSINK (object);
140 fdsink->fd = GTK_VALUE_INT (*arg);
148 gst_fdsink_get_arg (GtkObject *object, GtkArg *arg, guint id)
152 /* it's not null if we got it, but it might not be ours */
153 g_return_if_fail (GST_IS_FDSINK (object));
155 fdsink = GST_FDSINK (object);
159 GTK_VALUE_INT (*arg) = fdsink->fd;