This is a megapatch with the following changes:
[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_arg          (GtkObject *object, GtkArg *arg, guint id);
53 static void gst_fdsink_get_arg          (GtkObject *object, GtkArg *arg, guint id);
54
55 static void gst_fdsink_chain            (GstPad *pad,GstBuffer *buf);
56
57 static GstElementClass *parent_class = NULL;
58 //static guint gst_fdsink_signals[LAST_SIGNAL] = { 0 };
59
60 GtkType
61 gst_fdsink_get_type (void) 
62 {
63   static GtkType fdsink_type = 0;
64
65   if (!fdsink_type) {
66     static const GtkTypeInfo fdsink_info = {
67       "GstFdSink",
68       sizeof(GstFdSink),
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,
75     };
76     fdsink_type = gtk_type_unique (GST_TYPE_ELEMENT, &fdsink_info);
77   }
78   return fdsink_type;
79 }
80
81 static void
82 gst_fdsink_class_init (GstFdSinkClass *klass) 
83 {
84   GtkObjectClass *gtkobject_class;
85
86   gtkobject_class = (GtkObjectClass*)klass;
87
88   parent_class = gtk_type_class (GST_TYPE_ELEMENT);
89
90   gtk_object_add_arg_type ("GstFdSink::fd", GTK_TYPE_INT,
91                            GTK_ARG_READWRITE, ARG_FD);
92
93   gtkobject_class->set_arg = gst_fdsink_set_arg;
94   gtkobject_class->get_arg = gst_fdsink_get_arg;
95 }
96
97 static void 
98 gst_fdsink_init (GstFdSink *fdsink) 
99 {
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);
103
104   fdsink->fd = 1;
105 }
106
107 static void 
108 gst_fdsink_chain (GstPad *pad, GstBuffer *buf) 
109 {
110   GstFdSink *fdsink;
111
112   g_return_if_fail (pad != NULL);
113   g_return_if_fail (GST_IS_PAD (pad));
114   g_return_if_fail (buf != NULL);
115
116   fdsink = GST_FDSINK (gst_pad_get_parent (pad));
117   
118   g_return_if_fail (fdsink->fd >= 0);
119   
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));
123   }
124   
125   gst_buffer_unref (buf);
126 }
127
128 static void 
129 gst_fdsink_set_arg (GtkObject *object, GtkArg *arg, guint id) 
130 {
131   GstFdSink *fdsink;
132    
133   /* it's not null if we got it, but it might not be ours */
134   g_return_if_fail (GST_IS_FDSINK (object));
135   
136   fdsink = GST_FDSINK (object);
137
138   switch(id) {
139     case ARG_FD:
140       fdsink->fd = GTK_VALUE_INT (*arg);
141       break;
142     default:
143       break;
144   }
145 }
146
147 static void 
148 gst_fdsink_get_arg (GtkObject *object, GtkArg *arg, guint id) 
149 {
150   GstFdSink *fdsink;
151    
152   /* it's not null if we got it, but it might not be ours */
153   g_return_if_fail (GST_IS_FDSINK (object));
154   
155   fdsink = GST_FDSINK (object);
156
157   switch(id) {
158     case ARG_FD:
159       GTK_VALUE_INT (*arg) = fdsink->fd;
160       break;
161     default:
162       break;
163   }
164 }