s/gst_element_install_std_props/gst_element_class_install_std_props/ -- it just makes...
[platform/upstream/gstreamer.git] / gst / elements / 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 #include <gstfdsink.h>
24 #include <unistd.h>
25
26
27 GstElementDetails gst_fdsink_details = {
28   "Filedescriptor Sink",
29   "Sink",
30   "Write data to a file descriptor",
31   VERSION,
32   "Erik Walthinsen <omega@cse.ogi.edu>",
33   "(C) 1999",
34 };
35
36
37 /* FdSink signals and args */
38 enum {
39   /* FILL ME */
40   LAST_SIGNAL
41 };
42
43 enum {
44   ARG_0,
45   ARG_FD
46 };
47
48
49 static void     gst_fdsink_class_init   (GstFdSinkClass *klass);
50 static void     gst_fdsink_init         (GstFdSink *fdsink);
51
52 static void     gst_fdsink_set_property (GObject *object, guint prop_id, 
53                                          const GValue *value, GParamSpec *pspec);
54 static void     gst_fdsink_get_property (GObject *object, guint prop_id, 
55                                          GValue *value, GParamSpec *pspec);
56
57 static void     gst_fdsink_chain        (GstPad *pad,GstBuffer *buf);
58
59 static GstElementClass *parent_class = NULL;
60 /*static guint gst_fdsink_signals[LAST_SIGNAL] = { 0 };*/
61
62 GType
63 gst_fdsink_get_type (void) 
64 {
65   static GType fdsink_type = 0;
66
67   if (!fdsink_type) {
68     static const GTypeInfo fdsink_info = {
69       sizeof(GstFdSinkClass),      NULL,
70       NULL,
71       (GClassInitFunc)gst_fdsink_class_init,
72       NULL,
73       NULL,
74       sizeof(GstFdSink),
75       0,
76       (GInstanceInitFunc)gst_fdsink_init,
77     };
78     fdsink_type = g_type_register_static (GST_TYPE_ELEMENT, "GstFdSink", &fdsink_info, 0);
79   }
80   return fdsink_type;
81 }
82
83 static void
84 gst_fdsink_class_init (GstFdSinkClass *klass) 
85 {
86   GObjectClass *gobject_class;
87
88   gobject_class = (GObjectClass*)klass;
89
90   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
91
92   gst_element_class_install_std_props (
93           GST_ELEMENT_CLASS (klass),
94           "fd", ARG_FD, G_PARAM_READWRITE,
95           NULL);
96
97   gobject_class->set_property = gst_fdsink_set_property;
98   gobject_class->get_property = gst_fdsink_get_property;
99 }
100
101 static void 
102 gst_fdsink_init (GstFdSink *fdsink) 
103 {
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);
107
108   fdsink->fd = 1;
109 }
110
111 static void 
112 gst_fdsink_chain (GstPad *pad, GstBuffer *buf) 
113 {
114   GstFdSink *fdsink;
115
116   g_return_if_fail (pad != NULL);
117   g_return_if_fail (GST_IS_PAD (pad));
118   g_return_if_fail (buf != NULL);
119
120   fdsink = GST_FDSINK (gst_pad_get_parent (pad));
121   
122   g_return_if_fail (fdsink->fd >= 0);
123   
124   if (GST_BUFFER_DATA (buf)) {
125     GST_DEBUG (0,"writing %d bytes to file descriptor %d\n",GST_BUFFER_SIZE (buf), fdsink->fd);
126     write (fdsink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
127   }
128   
129   gst_buffer_unref (buf);
130 }
131
132 static void 
133 gst_fdsink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) 
134 {
135   GstFdSink *fdsink;
136    
137   /* it's not null if we got it, but it might not be ours */
138   g_return_if_fail (GST_IS_FDSINK (object));
139   
140   fdsink = GST_FDSINK (object);
141
142   switch (prop_id) {
143     case ARG_FD:
144       fdsink->fd = g_value_get_int (value);
145       break;
146     default:
147       break;
148   }
149 }
150
151 static void 
152 gst_fdsink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) 
153 {
154   GstFdSink *fdsink;
155    
156   /* it's not null if we got it, but it might not be ours */
157   g_return_if_fail (GST_IS_FDSINK (object));
158   
159   fdsink = GST_FDSINK (object);
160
161   switch (prop_id) {
162     case ARG_FD:
163       g_value_set_int (value, fdsink->fd);
164       break;
165     default:
166       break;
167   }
168 }