Way, way, way too many files: Remove crack comment from the 2000 era.
[platform/upstream/gst-plugins-good.git] / gst / oldcore / gstfdsink.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstfdsink.c: 
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26
27 #include "gstfdsink.h"
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31
32 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
33     GST_PAD_SINK,
34     GST_PAD_ALWAYS,
35     GST_STATIC_CAPS_ANY);
36
37 GST_DEBUG_CATEGORY_STATIC (gst_fdsink_debug);
38 #define GST_CAT_DEFAULT gst_fdsink_debug
39
40 GstElementDetails gst_fdsink_details =
41 GST_ELEMENT_DETAILS ("Filedescriptor Sink",
42     "Sink/File",
43     "Write data to a file descriptor",
44     "Erik Walthinsen <omega@cse.ogi.edu>");
45
46
47 /* FdSink signals and args */
48 enum
49 {
50   /* FILL ME */
51   LAST_SIGNAL
52 };
53
54 enum
55 {
56   ARG_0,
57   ARG_FD
58 };
59
60
61 #define _do_init(bla) \
62     GST_DEBUG_CATEGORY_INIT (gst_fdsink_debug, "fdsink", 0, "fdsink element");
63
64 GST_BOILERPLATE_FULL (GstFdSink, gst_fdsink, GstElement, GST_TYPE_ELEMENT,
65     _do_init);
66
67 static void gst_fdsink_set_property (GObject * object, guint prop_id,
68     const GValue * value, GParamSpec * pspec);
69 static void gst_fdsink_get_property (GObject * object, guint prop_id,
70     GValue * value, GParamSpec * pspec);
71
72 static void gst_fdsink_chain (GstPad * pad, GstData * _data);
73
74
75 static void
76 gst_fdsink_base_init (gpointer g_class)
77 {
78   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
79
80   gst_element_class_add_pad_template (gstelement_class,
81       gst_static_pad_template_get (&sinktemplate));
82   gst_element_class_set_details (gstelement_class, &gst_fdsink_details);
83 }
84 static void
85 gst_fdsink_class_init (GstFdSinkClass * klass)
86 {
87   GObjectClass *gobject_class;
88
89   gobject_class = G_OBJECT_CLASS (klass);
90
91   gobject_class->set_property = gst_fdsink_set_property;
92   gobject_class->get_property = gst_fdsink_get_property;
93
94   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FD,
95       g_param_spec_int ("fd", "fd", "An open file descriptor to write to",
96           0, G_MAXINT, 1, G_PARAM_READWRITE));
97 }
98
99 static void
100 gst_fdsink_init (GstFdSink * fdsink)
101 {
102   fdsink->sinkpad =
103       gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate),
104       "sink");
105   gst_element_add_pad (GST_ELEMENT (fdsink), fdsink->sinkpad);
106   gst_pad_set_chain_function (fdsink->sinkpad, gst_fdsink_chain);
107
108   fdsink->fd = 1;
109 }
110
111 static void
112 gst_fdsink_chain (GstPad * pad, GstData * _data)
113 {
114   GstBuffer *buf = GST_BUFFER (_data);
115   GstFdSink *fdsink;
116
117   g_return_if_fail (pad != NULL);
118   g_return_if_fail (GST_IS_PAD (pad));
119   g_return_if_fail (buf != NULL);
120
121   fdsink = GST_FDSINK (gst_pad_get_parent (pad));
122
123   g_return_if_fail (fdsink->fd >= 0);
124
125   if (GST_BUFFER_DATA (buf)) {
126     GST_DEBUG ("writing %d bytes to file descriptor %d", GST_BUFFER_SIZE (buf),
127         fdsink->fd);
128     write (fdsink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
129   }
130
131   gst_buffer_unref (buf);
132 }
133
134 static void
135 gst_fdsink_set_property (GObject * object, guint prop_id, const GValue * value,
136     GParamSpec * pspec)
137 {
138   GstFdSink *fdsink;
139
140   g_return_if_fail (GST_IS_FDSINK (object));
141
142   fdsink = GST_FDSINK (object);
143
144   switch (prop_id) {
145     case ARG_FD:
146       fdsink->fd = g_value_get_int (value);
147       break;
148     default:
149       break;
150   }
151 }
152
153 static void
154 gst_fdsink_get_property (GObject * object, guint prop_id, GValue * value,
155     GParamSpec * pspec)
156 {
157   GstFdSink *fdsink;
158
159   g_return_if_fail (GST_IS_FDSINK (object));
160
161   fdsink = GST_FDSINK (object);
162
163   switch (prop_id) {
164     case ARG_FD:
165       g_value_set_int (value, fdsink->fd);
166       break;
167     default:
168       break;
169   }
170 }