2000-12-29 05:38:06 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
2005-10-15 15:30:24 +00:00
|
|
|
* gstfdsink.c:
|
2000-01-30 09:03:00 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 14:05:49 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstfdsink.h"
|
2004-05-07 02:36:28 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2000-02-27 23:18:38 +00:00
|
|
|
#include <unistd.h>
|
2004-05-07 02:36:28 +00:00
|
|
|
#endif
|
2000-01-30 09:03:00 +00:00
|
|
|
|
gst/: s/gst_pad_new/&_from_template/ register pad templates in the base_init function add static pad template definit...
Original commit message from CVS:
* gst/autoplug/gstspideridentity.c:
(gst_spider_identity_request_new_pad):
* gst/elements/gstaggregator.c: (gst_aggregator_base_init),
(gst_aggregator_init):
* gst/elements/gstfakesink.c: (gst_fakesink_base_init),
(gst_fakesink_init):
* gst/elements/gstfakesrc.c: (gst_fakesrc_base_init),
(gst_fakesrc_init):
* gst/elements/gstfdsink.c: (gst_fdsink_base_init),
(gst_fdsink_init):
* gst/elements/gstfdsrc.c: (gst_fdsrc_base_init), (gst_fdsrc_init):
* gst/elements/gstfilesink.c: (gst_filesink_base_init),
(gst_filesink_init):
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_init):
* gst/elements/gstidentity.c: (gst_identity_base_init),
(gst_identity_init):
* gst/elements/gstmultifilesrc.c: (gst_multifilesrc_base_init),
(gst_multifilesrc_init):
* gst/elements/gstpipefilter.c: (gst_pipefilter_base_init),
(gst_pipefilter_init):
* gst/elements/gststatistics.c: (gst_statistics_base_init),
(gst_statistics_init):
* gst/elements/gsttee.c: (gst_tee_base_init), (gst_tee_init):
* gst/gstqueue.c: (gst_queue_base_init), (gst_queue_init):
s/gst_pad_new/&_from_template/
register pad templates in the base_init function
add static pad template definitions
2004-08-17 14:11:23 +00:00
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_fdsink_debug);
|
2003-06-29 14:05:49 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_fdsink_debug
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2005-09-28 12:52:51 +00:00
|
|
|
static GstElementDetails gst_fdsink_details =
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_ELEMENT_DETAILS ("Filedescriptor Sink",
|
|
|
|
"Sink/File",
|
|
|
|
"Write data to a file descriptor",
|
|
|
|
"Erik Walthinsen <omega@cse.ogi.edu>");
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* FdSink signals and args */
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
enum
|
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
ARG_0,
|
|
|
|
ARG_FD
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-01-08 04:10:18 +00:00
|
|
|
#define _do_init(bla) \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_fdsink_debug, "fdsink", 0, "fdsink element");
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_BOILERPLATE_FULL (GstFdSink, gst_fdsink, GstElement, GST_TYPE_ELEMENT,
|
|
|
|
_do_init);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_fdsink_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_fdsink_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2000-11-25 14:18:47 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_fdsink_chain (GstPad * pad, GstData * _data);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
static void
|
|
|
|
gst_fdsink_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
gst/: s/gst_pad_new/&_from_template/ register pad templates in the base_init function add static pad template definit...
Original commit message from CVS:
* gst/autoplug/gstspideridentity.c:
(gst_spider_identity_request_new_pad):
* gst/elements/gstaggregator.c: (gst_aggregator_base_init),
(gst_aggregator_init):
* gst/elements/gstfakesink.c: (gst_fakesink_base_init),
(gst_fakesink_init):
* gst/elements/gstfakesrc.c: (gst_fakesrc_base_init),
(gst_fakesrc_init):
* gst/elements/gstfdsink.c: (gst_fdsink_base_init),
(gst_fdsink_init):
* gst/elements/gstfdsrc.c: (gst_fdsrc_base_init), (gst_fdsrc_init):
* gst/elements/gstfilesink.c: (gst_filesink_base_init),
(gst_filesink_init):
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_init):
* gst/elements/gstidentity.c: (gst_identity_base_init),
(gst_identity_init):
* gst/elements/gstmultifilesrc.c: (gst_multifilesrc_base_init),
(gst_multifilesrc_init):
* gst/elements/gstpipefilter.c: (gst_pipefilter_base_init),
(gst_pipefilter_init):
* gst/elements/gststatistics.c: (gst_statistics_base_init),
(gst_statistics_init):
* gst/elements/gsttee.c: (gst_tee_base_init), (gst_tee_init):
* gst/gstqueue.c: (gst_queue_base_init), (gst_queue_init):
s/gst_pad_new/&_from_template/
register pad templates in the base_init function
add static pad template definitions
2004-08-17 14:11:23 +00:00
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&sinktemplate));
|
2003-10-31 19:32:47 +00:00
|
|
|
gst_element_class_set_details (gstelement_class, &gst_fdsink_details);
|
|
|
|
}
|
2000-01-30 09:03:00 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_fdsink_class_init (GstFdSinkClass * klass)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2001-06-25 01:20:11 +00:00
|
|
|
GObjectClass *gobject_class;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2003-10-31 19:32:47 +00:00
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2005-03-08 17:42:29 +00:00
|
|
|
gobject_class->set_property = gst_fdsink_set_property;
|
|
|
|
gobject_class->get_property = gst_fdsink_get_property;
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2002-11-21 23:52:30 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FD,
|
2004-03-13 15:27:01 +00:00
|
|
|
g_param_spec_int ("fd", "fd", "An open file descriptor to write to",
|
2004-03-15 19:27:17 +00:00
|
|
|
0, G_MAXINT, 1, G_PARAM_READWRITE));
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void
|
|
|
|
gst_fdsink_init (GstFdSink * fdsink)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
gst/: s/gst_pad_new/&_from_template/ register pad templates in the base_init function add static pad template definit...
Original commit message from CVS:
* gst/autoplug/gstspideridentity.c:
(gst_spider_identity_request_new_pad):
* gst/elements/gstaggregator.c: (gst_aggregator_base_init),
(gst_aggregator_init):
* gst/elements/gstfakesink.c: (gst_fakesink_base_init),
(gst_fakesink_init):
* gst/elements/gstfakesrc.c: (gst_fakesrc_base_init),
(gst_fakesrc_init):
* gst/elements/gstfdsink.c: (gst_fdsink_base_init),
(gst_fdsink_init):
* gst/elements/gstfdsrc.c: (gst_fdsrc_base_init), (gst_fdsrc_init):
* gst/elements/gstfilesink.c: (gst_filesink_base_init),
(gst_filesink_init):
* gst/elements/gstfilesrc.c: (gst_filesrc_base_init),
(gst_filesrc_init):
* gst/elements/gstidentity.c: (gst_identity_base_init),
(gst_identity_init):
* gst/elements/gstmultifilesrc.c: (gst_multifilesrc_base_init),
(gst_multifilesrc_init):
* gst/elements/gstpipefilter.c: (gst_pipefilter_base_init),
(gst_pipefilter_init):
* gst/elements/gststatistics.c: (gst_statistics_base_init),
(gst_statistics_init):
* gst/elements/gsttee.c: (gst_tee_base_init), (gst_tee_init):
* gst/gstqueue.c: (gst_queue_base_init), (gst_queue_init):
s/gst_pad_new/&_from_template/
register pad templates in the base_init function
add static pad template definitions
2004-08-17 14:11:23 +00:00
|
|
|
fdsink->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate),
|
|
|
|
"sink");
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (fdsink), fdsink->sinkpad);
|
|
|
|
gst_pad_set_chain_function (fdsink->sinkpad, gst_fdsink_chain);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
|
|
|
fdsink->fd = 1;
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void
|
|
|
|
gst_fdsink_chain (GstPad * pad, GstData * _data)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2003-10-08 16:06:02 +00:00
|
|
|
GstBuffer *buf = GST_BUFFER (_data);
|
2000-01-30 09:03:00 +00:00
|
|
|
GstFdSink *fdsink;
|
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (pad != NULL);
|
|
|
|
g_return_if_fail (GST_IS_PAD (pad));
|
|
|
|
g_return_if_fail (buf != NULL);
|
|
|
|
|
2001-01-29 00:06:02 +00:00
|
|
|
fdsink = GST_FDSINK (gst_pad_get_parent (pad));
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (fdsink->fd >= 0);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2000-12-12 09:40:25 +00:00
|
|
|
if (GST_BUFFER_DATA (buf)) {
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DEBUG ("writing %d bytes to file descriptor %d", GST_BUFFER_SIZE (buf),
|
2004-03-15 19:27:17 +00:00
|
|
|
fdsink->fd);
|
2000-11-25 14:18:47 +00:00
|
|
|
write (fdsink->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
|
2000-12-12 09:40:25 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
gst_buffer_unref (buf);
|
2000-01-30 09:03:00 +00:00
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void
|
|
|
|
gst_fdsink_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstFdSink *fdsink;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (GST_IS_FDSINK (object));
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
fdsink = GST_FDSINK (object);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2000-01-30 09:03:00 +00:00
|
|
|
case ARG_FD:
|
2001-06-25 01:20:11 +00:00
|
|
|
fdsink->fd = g_value_get_int (value);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void
|
|
|
|
gst_fdsink_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2000-11-25 14:18:47 +00:00
|
|
|
{
|
2000-01-30 09:03:00 +00:00
|
|
|
GstFdSink *fdsink;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
g_return_if_fail (GST_IS_FDSINK (object));
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2000-11-25 14:18:47 +00:00
|
|
|
fdsink = GST_FDSINK (object);
|
2000-01-30 09:03:00 +00:00
|
|
|
|
2001-06-25 01:20:11 +00:00
|
|
|
switch (prop_id) {
|
2000-01-30 09:03:00 +00:00
|
|
|
case ARG_FD:
|
2001-06-25 01:20:11 +00:00
|
|
|
g_value_set_int (value, fdsink->fd);
|
2000-01-30 09:03:00 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|