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",
31 "Write data to a file descriptor",
33 "Erik Walthinsen <omega@cse.ogi.edu>",
38 /* FdSink signals and args */
50 static void gst_fdsink_class_init (GstFdSinkClass *klass);
51 static void gst_fdsink_init (GstFdSink *fdsink);
53 static void gst_fdsink_set_property (GObject *object, guint prop_id,
54 const GValue *value, GParamSpec *pspec);
55 static void gst_fdsink_get_property (GObject *object, guint prop_id,
56 GValue *value, GParamSpec *pspec);
58 static void gst_fdsink_chain (GstPad *pad,GstBuffer *buf);
60 static GstElementClass *parent_class = NULL;
61 /*static guint gst_fdsink_signals[LAST_SIGNAL] = { 0 };*/
64 gst_fdsink_get_type (void)
66 static GType fdsink_type = 0;
69 static const GTypeInfo fdsink_info = {
70 sizeof(GstFdSinkClass), NULL,
72 (GClassInitFunc)gst_fdsink_class_init,
77 (GInstanceInitFunc)gst_fdsink_init,
79 fdsink_type = g_type_register_static (GST_TYPE_ELEMENT, "GstFdSink", &fdsink_info, 0);
85 gst_fdsink_class_init (GstFdSinkClass *klass)
87 GObjectClass *gobject_class;
89 gobject_class = (GObjectClass*)klass;
91 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
93 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FD,
94 g_param_spec_int ("fd", "fd", "An open file descriptor to write to",
95 0, G_MAXINT, 1, G_PARAM_READWRITE));
97 gobject_class->set_property = gst_fdsink_set_property;
98 gobject_class->get_property = gst_fdsink_get_property;
102 gst_fdsink_init (GstFdSink *fdsink)
104 fdsink->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
105 gst_element_add_pad (GST_ELEMENT (fdsink), fdsink->sinkpad);
106 gst_pad_set_chain_function (fdsink->sinkpad, gst_fdsink_chain);
112 gst_fdsink_chain (GstPad *pad, GstBuffer *buf)
116 g_return_if_fail (pad != NULL);
117 g_return_if_fail (GST_IS_PAD (pad));
118 g_return_if_fail (buf != NULL);
120 fdsink = GST_FDSINK (gst_pad_get_parent (pad));
122 g_return_if_fail (fdsink->fd >= 0);
124 if (GST_BUFFER_DATA (buf)) {
125 GST_DEBUG (0,"writing %d bytes to file descriptor %d",GST_BUFFER_SIZE (buf), fdsink->fd);
126 write (fdsink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
129 gst_buffer_unref (buf);
133 gst_fdsink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
137 /* it's not null if we got it, but it might not be ours */
138 g_return_if_fail (GST_IS_FDSINK (object));
140 fdsink = GST_FDSINK (object);
144 fdsink->fd = g_value_get_int (value);
152 gst_fdsink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
156 /* it's not null if we got it, but it might not be ours */
157 g_return_if_fail (GST_IS_FDSINK (object));
159 fdsink = GST_FDSINK (object);
163 g_value_set_int (value, fdsink->fd);