Blame gst/gio/gstgiostreamsink.c

Packit 971217
/* GStreamer
Packit 971217
 *
Packit 971217
 * Copyright (C) 2007 Rene Stadler <mail@renestadler.de>
Packit 971217
 * Copyright (C) 2007-2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
Packit 971217
 * 
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
/**
Packit 971217
 * SECTION:element-giostreamsink
Packit 971217
 * @title: giostreamsink
Packit 971217
 *
Packit 971217
 * This plugin writes incoming data to a custom GIO #GOutputStream.
Packit 971217
 *
Packit 971217
 * It can, for example, be used to write a stream to memory with a
Packit 971217
 * #GMemoryOuputStream or to write to a file with a #GFileOuputStream.
Packit 971217
 *
Packit 971217
 * ## Example code
Packit 971217
 *
Packit 971217
 * The following example writes the received data to a #GMemoryOutputStream.
Packit 971217
 * |[
Packit 971217
Packit 971217
#include <gst/gst.h>
Packit 971217
#include <gio/gio.h>
Packit 971217
Packit 971217
...
Packit 971217
Packit 971217
GstElement *sink;
Packit 971217
GMemoryOuputStream *stream;
Packit 971217
// out_data will contain the received data
Packit 971217
guint8 *out_data;
Packit 971217
Packit 971217
...
Packit 971217
Packit 971217
stream = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (NULL, 0,
Packit 971217
          (GReallocFunc) g_realloc, (GDestroyNotify) g_free));
Packit 971217
sink = gst_element_factory_make ("giostreamsink", "sink");
Packit 971217
g_object_set (G_OBJECT (sink), "stream", stream, NULL);
Packit 971217
Packit 971217
...
Packit 971217
Packit 971217
// after processing get the written data
Packit 971217
out_data = g_memory_ouput_stream_get_data (G_MEMORY_OUTPUT_STREAM (stream));
Packit 971217
Packit 971217
...
Packit 971217
Packit 971217
 * ]|
Packit 971217
 *
Packit 971217
 */
Packit 971217
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include <config.h>
Packit 971217
#endif
Packit 971217
Packit 971217
#include "gstgiostreamsink.h"
Packit 971217
Packit 971217
GST_DEBUG_CATEGORY_STATIC (gst_gio_stream_sink_debug);
Packit 971217
#define GST_CAT_DEFAULT gst_gio_stream_sink_debug
Packit 971217
Packit 971217
/* Filter signals and args */
Packit 971217
enum
Packit 971217
{
Packit 971217
  LAST_SIGNAL
Packit 971217
};
Packit 971217
Packit 971217
enum
Packit 971217
{
Packit 971217
  PROP_0,
Packit 971217
  PROP_STREAM
Packit 971217
};
Packit 971217
Packit 971217
#define gst_gio_stream_sink_parent_class parent_class
Packit 971217
G_DEFINE_TYPE (GstGioStreamSink, gst_gio_stream_sink, GST_TYPE_GIO_BASE_SINK);
Packit 971217
Packit 971217
static void gst_gio_stream_sink_finalize (GObject * object);
Packit 971217
static void gst_gio_stream_sink_set_property (GObject * object, guint prop_id,
Packit 971217
    const GValue * value, GParamSpec * pspec);
Packit 971217
static void gst_gio_stream_sink_get_property (GObject * object, guint prop_id,
Packit 971217
    GValue * value, GParamSpec * pspec);
Packit 971217
static GOutputStream *gst_gio_stream_sink_get_stream (GstGioBaseSink * bsink);
Packit 971217
Packit 971217
static void
Packit 971217
gst_gio_stream_sink_class_init (GstGioStreamSinkClass * klass)
Packit 971217
{
Packit 971217
  GObjectClass *gobject_class = (GObjectClass *) klass;
Packit 971217
  GstElementClass *gstelement_class = (GstElementClass *) klass;
Packit 971217
  GstGioBaseSinkClass *ggbsink_class = (GstGioBaseSinkClass *) klass;
Packit 971217
Packit 971217
  GST_DEBUG_CATEGORY_INIT (gst_gio_stream_sink_debug, "gio_stream_sink", 0,
Packit 971217
      "GIO stream sink");
Packit 971217
Packit 971217
  gobject_class->finalize = gst_gio_stream_sink_finalize;
Packit 971217
  gobject_class->set_property = gst_gio_stream_sink_set_property;
Packit 971217
  gobject_class->get_property = gst_gio_stream_sink_get_property;
Packit 971217
Packit 971217
  g_object_class_install_property (gobject_class, PROP_STREAM,
Packit 971217
      g_param_spec_object ("stream", "Stream", "Stream to write to",
Packit 971217
          G_TYPE_OUTPUT_STREAM, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 971217
Packit 971217
  gst_element_class_set_static_metadata (gstelement_class, "GIO stream sink",
Packit 971217
      "Sink",
Packit 971217
      "Write to any GIO stream",
Packit 971217
      "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
Packit 971217
Packit 971217
  ggbsink_class->get_stream =
Packit 971217
      GST_DEBUG_FUNCPTR (gst_gio_stream_sink_get_stream);
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
gst_gio_stream_sink_init (GstGioStreamSink * sink)
Packit 971217
{
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
gst_gio_stream_sink_finalize (GObject * object)
Packit 971217
{
Packit 971217
  GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object);
Packit 971217
Packit 971217
  if (sink->stream) {
Packit 971217
    g_object_unref (sink->stream);
Packit 971217
    sink->stream = NULL;
Packit 971217
  }
Packit 971217
Packit 971217
  GST_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
gst_gio_stream_sink_set_property (GObject * object, guint prop_id,
Packit 971217
    const GValue * value, GParamSpec * pspec)
Packit 971217
{
Packit 971217
  GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object);
Packit 971217
Packit 971217
  switch (prop_id) {
Packit 971217
    case PROP_STREAM:{
Packit 971217
      GObject *stream;
Packit 971217
Packit 971217
      if (GST_STATE (sink) == GST_STATE_PLAYING ||
Packit 971217
          GST_STATE (sink) == GST_STATE_PAUSED) {
Packit 971217
        GST_WARNING
Packit 971217
            ("Setting a new stream not supported in PLAYING or PAUSED state");
Packit 971217
        break;
Packit 971217
      }
Packit 971217
Packit 971217
      stream = g_value_dup_object (value);
Packit 971217
      if (sink->stream)
Packit 971217
        g_object_unref (sink->stream);
Packit 971217
      sink->stream = G_OUTPUT_STREAM (stream);
Packit 971217
      break;
Packit 971217
    }
Packit 971217
    default:
Packit 971217
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit 971217
      break;
Packit 971217
  }
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
gst_gio_stream_sink_get_property (GObject * object, guint prop_id,
Packit 971217
    GValue * value, GParamSpec * pspec)
Packit 971217
{
Packit 971217
  GstGioStreamSink *sink = GST_GIO_STREAM_SINK (object);
Packit 971217
Packit 971217
  switch (prop_id) {
Packit 971217
    case PROP_STREAM:
Packit 971217
      g_value_set_object (value, GST_GIO_BASE_SINK (sink)->stream);
Packit 971217
      break;
Packit 971217
    default:
Packit 971217
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit 971217
      break;
Packit 971217
  }
Packit 971217
}
Packit 971217
Packit 971217
static GOutputStream *
Packit 971217
gst_gio_stream_sink_get_stream (GstGioBaseSink * bsink)
Packit 971217
{
Packit 971217
  GstGioStreamSink *sink = GST_GIO_STREAM_SINK (bsink);
Packit 971217
Packit 971217
  return (sink->stream) ? g_object_ref (sink->stream) : NULL;
Packit 971217
}