gstreamer/gst/freeze/gstfreeze.c

350 lines
9.6 KiB
C
Raw Normal View History

/* gst-freeze -- Source freezer
* Copyright (C) 2005 Gergely Nagy <gergely.nagy@neteyes.hu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1, as published by the Free Software Foundation.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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
*/
/**
* SECTION:element-freeze
*
* Makes a stream from buffers of data.
docs/plugins/: docs/plugins/inspect/plugin-mythtv.xml Original commit message from CVS: * docs/plugins/Makefile.am: * docs/plugins/gst-plugins-bad-plugins-docs.sgml: * docs/plugins/gst-plugins-bad-plugins-sections.txt: * docs/plugins/gst-plugins-bad-plugins.args: * docs/plugins/gst-plugins-bad-plugins.hierarchy: * docs/plugins/gst-plugins-bad-plugins.interfaces: * docs/plugins/gst-plugins-bad-plugins.prerequisites: * docs/plugins/gst-plugins-bad-plugins.signals: * docs/plugins/inspect/plugin-alsaspdif.xml: * docs/plugins/inspect/plugin-amrwb.xml: * docs/plugins/inspect/plugin-app.xml: * docs/plugins/inspect/plugin-bayer.xml: * docs/plugins/inspect/plugin-bz2.xml: * docs/plugins/inspect/plugin-cdaudio.xml: * docs/plugins/inspect/plugin-cdxaparse.xml: * docs/plugins/inspect/plugin-dtsdec.xml: * docs/plugins/inspect/plugin-dvb.xml: * docs/plugins/inspect/plugin-dvdspu.xml: * docs/plugins/inspect/plugin-faac.xml: * docs/plugins/inspect/plugin-faad.xml: * docs/plugins/inspect/plugin-fbdevsink.xml: * docs/plugins/inspect/plugin-festival.xml: * docs/plugins/inspect/plugin-filter.xml: * docs/plugins/inspect/plugin-flvdemux.xml: * docs/plugins/inspect/plugin-freeze.xml: * docs/plugins/inspect/plugin-gsm.xml: * docs/plugins/inspect/plugin-gstinterlace.xml: * docs/plugins/inspect/plugin-gstrtpmanager.xml: * docs/plugins/inspect/plugin-h264parse.xml: * docs/plugins/inspect/plugin-interleave.xml: * docs/plugins/inspect/plugin-jack.xml: * docs/plugins/inspect/plugin-ladspa.xml: * docs/plugins/inspect/plugin-metadata.xml: * docs/plugins/inspect/plugin-mms.xml: * docs/plugins/inspect/plugin-modplug.xml: * docs/plugins/inspect/plugin-mpeg2enc.xml: * docs/plugins/inspect/plugin-mpeg4videoparse.xml: * docs/plugins/inspect/plugin-mpegtsparse.xml: * docs/plugins/inspect/plugin-mpegvideoparse.xml: * docs/plugins/inspect/plugin-musepack.xml: * docs/plugins/inspect/plugin-musicbrainz.xml: * docs/plugins/inspect/plugin-mve.xml: * docs/plugins/inspect/plugin-mythtv.xml * docs/plugins/inspect/plugin-nas.xml: * docs/plugins/inspect/plugin-neon.xml: * docs/plugins/inspect/plugin-nsfdec.xml: * docs/plugins/inspect/plugin-nuvdemux.xml: * docs/plugins/inspect/plugin-oss4.xml * docs/plugins/inspect/plugin-rawparse.xml: * docs/plugins/inspect/plugin-real.xml: * docs/plugins/inspect/plugin-replaygain.xml: * docs/plugins/inspect/plugin-rfbsrc.xml: * docs/plugins/inspect/plugin-sdl.xml: * docs/plugins/inspect/plugin-sdp.xml: * docs/plugins/inspect/plugin-selector.xml: * docs/plugins/inspect/plugin-sndfile.xml: * docs/plugins/inspect/plugin-soundtouch.xml: * docs/plugins/inspect/plugin-spcdec.xml: * docs/plugins/inspect/plugin-speed.xml: * docs/plugins/inspect/plugin-speexresample.xml: * docs/plugins/inspect/plugin-stereo.xml: * docs/plugins/inspect/plugin-subenc.xml * docs/plugins/inspect/plugin-timidity.xml: * docs/plugins/inspect/plugin-tta.xml: * docs/plugins/inspect/plugin-vcdsrc.xml: * docs/plugins/inspect/plugin-videosignal.xml: * docs/plugins/inspect/plugin-vmnc.xml: * docs/plugins/inspect/plugin-wildmidi.xml: * docs/plugins/inspect/plugin-x264.xml: * docs/plugins/inspect/plugin-xvid.xml: * docs/plugins/inspect/plugin-y4menc.xml: * ext/amrwb/gstamrwbdec.c: * ext/amrwb/gstamrwbenc.c: * ext/amrwb/gstamrwbparse.c: * ext/dc1394/gstdc1394.c: * ext/directfb/dfbvideosink.c: * ext/ivorbis/vorbisdec.c: * ext/jack/gstjackaudiosink.c: * ext/mpeg2enc/gstmpeg2enc.cc: * ext/mplex/gstmplex.cc: * ext/musicbrainz/gsttrm.c: * ext/mythtv/gstmythtvsrc.c: * ext/theora/theoradec.c: * ext/timidity/gsttimidity.c: * ext/timidity/gstwildmidi.c: * gst-libs/gst/app/gstappsink.c: * gst/deinterlace/gstdeinterlace.c: * gst/dvdspu/gstdvdspu.c: * gst/festival/gstfestival.c: * gst/freeze/gstfreeze.c: * gst/interleave/deinterleave.c: * gst/interleave/interleave.c: * gst/modplug/gstmodplug.cc: * gst/nuvdemux/gstnuvdemux.c: Add missing elements to docs. Fix doc-markup: use convinience syntax for examples (produces valid docbook), add several refsec2 when we have several titles. Fix some types.
2008-06-13 11:59:23 +00:00
*
* <refsect2>
* <title>Example launch line</title>
* <para>
docs/plugins/: docs/plugins/inspect/plugin-mythtv.xml Original commit message from CVS: * docs/plugins/Makefile.am: * docs/plugins/gst-plugins-bad-plugins-docs.sgml: * docs/plugins/gst-plugins-bad-plugins-sections.txt: * docs/plugins/gst-plugins-bad-plugins.args: * docs/plugins/gst-plugins-bad-plugins.hierarchy: * docs/plugins/gst-plugins-bad-plugins.interfaces: * docs/plugins/gst-plugins-bad-plugins.prerequisites: * docs/plugins/gst-plugins-bad-plugins.signals: * docs/plugins/inspect/plugin-alsaspdif.xml: * docs/plugins/inspect/plugin-amrwb.xml: * docs/plugins/inspect/plugin-app.xml: * docs/plugins/inspect/plugin-bayer.xml: * docs/plugins/inspect/plugin-bz2.xml: * docs/plugins/inspect/plugin-cdaudio.xml: * docs/plugins/inspect/plugin-cdxaparse.xml: * docs/plugins/inspect/plugin-dtsdec.xml: * docs/plugins/inspect/plugin-dvb.xml: * docs/plugins/inspect/plugin-dvdspu.xml: * docs/plugins/inspect/plugin-faac.xml: * docs/plugins/inspect/plugin-faad.xml: * docs/plugins/inspect/plugin-fbdevsink.xml: * docs/plugins/inspect/plugin-festival.xml: * docs/plugins/inspect/plugin-filter.xml: * docs/plugins/inspect/plugin-flvdemux.xml: * docs/plugins/inspect/plugin-freeze.xml: * docs/plugins/inspect/plugin-gsm.xml: * docs/plugins/inspect/plugin-gstinterlace.xml: * docs/plugins/inspect/plugin-gstrtpmanager.xml: * docs/plugins/inspect/plugin-h264parse.xml: * docs/plugins/inspect/plugin-interleave.xml: * docs/plugins/inspect/plugin-jack.xml: * docs/plugins/inspect/plugin-ladspa.xml: * docs/plugins/inspect/plugin-metadata.xml: * docs/plugins/inspect/plugin-mms.xml: * docs/plugins/inspect/plugin-modplug.xml: * docs/plugins/inspect/plugin-mpeg2enc.xml: * docs/plugins/inspect/plugin-mpeg4videoparse.xml: * docs/plugins/inspect/plugin-mpegtsparse.xml: * docs/plugins/inspect/plugin-mpegvideoparse.xml: * docs/plugins/inspect/plugin-musepack.xml: * docs/plugins/inspect/plugin-musicbrainz.xml: * docs/plugins/inspect/plugin-mve.xml: * docs/plugins/inspect/plugin-mythtv.xml * docs/plugins/inspect/plugin-nas.xml: * docs/plugins/inspect/plugin-neon.xml: * docs/plugins/inspect/plugin-nsfdec.xml: * docs/plugins/inspect/plugin-nuvdemux.xml: * docs/plugins/inspect/plugin-oss4.xml * docs/plugins/inspect/plugin-rawparse.xml: * docs/plugins/inspect/plugin-real.xml: * docs/plugins/inspect/plugin-replaygain.xml: * docs/plugins/inspect/plugin-rfbsrc.xml: * docs/plugins/inspect/plugin-sdl.xml: * docs/plugins/inspect/plugin-sdp.xml: * docs/plugins/inspect/plugin-selector.xml: * docs/plugins/inspect/plugin-sndfile.xml: * docs/plugins/inspect/plugin-soundtouch.xml: * docs/plugins/inspect/plugin-spcdec.xml: * docs/plugins/inspect/plugin-speed.xml: * docs/plugins/inspect/plugin-speexresample.xml: * docs/plugins/inspect/plugin-stereo.xml: * docs/plugins/inspect/plugin-subenc.xml * docs/plugins/inspect/plugin-timidity.xml: * docs/plugins/inspect/plugin-tta.xml: * docs/plugins/inspect/plugin-vcdsrc.xml: * docs/plugins/inspect/plugin-videosignal.xml: * docs/plugins/inspect/plugin-vmnc.xml: * docs/plugins/inspect/plugin-wildmidi.xml: * docs/plugins/inspect/plugin-x264.xml: * docs/plugins/inspect/plugin-xvid.xml: * docs/plugins/inspect/plugin-y4menc.xml: * ext/amrwb/gstamrwbdec.c: * ext/amrwb/gstamrwbenc.c: * ext/amrwb/gstamrwbparse.c: * ext/dc1394/gstdc1394.c: * ext/directfb/dfbvideosink.c: * ext/ivorbis/vorbisdec.c: * ext/jack/gstjackaudiosink.c: * ext/mpeg2enc/gstmpeg2enc.cc: * ext/mplex/gstmplex.cc: * ext/musicbrainz/gsttrm.c: * ext/mythtv/gstmythtvsrc.c: * ext/theora/theoradec.c: * ext/timidity/gsttimidity.c: * ext/timidity/gstwildmidi.c: * gst-libs/gst/app/gstappsink.c: * gst/deinterlace/gstdeinterlace.c: * gst/dvdspu/gstdvdspu.c: * gst/festival/gstfestival.c: * gst/freeze/gstfreeze.c: * gst/interleave/deinterleave.c: * gst/interleave/interleave.c: * gst/modplug/gstmodplug.cc: * gst/nuvdemux/gstnuvdemux.c: Add missing elements to docs. Fix doc-markup: use convinience syntax for examples (produces valid docbook), add several refsec2 when we have several titles. Fix some types.
2008-06-13 11:59:23 +00:00
* |[
* gst-launch-0.10 filesrc location=gnome-home.png blocksize=4135 ! pngdec ! freeze ! ffmpegcolorspace ! xvimagesink
* ]| Produces a video stream from one picture.
* </para>
* </refsect2>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstfreeze.h"
GST_DEBUG_CATEGORY_STATIC (freeze_debug);
#define GST_CAT_DEFAULT freeze_debug
enum
{
ARG_0,
ARG_MAX_BUFFERS,
};
static GstStaticPadTemplate gst_freeze_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY);
static GstStaticPadTemplate gst_freeze_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY);
static void gst_freeze_dispose (GObject * object);
static void gst_freeze_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_freeze_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
2012-09-12 21:24:26 +00:00
static GstFlowReturn gst_freeze_chain (GstPad * pad, GstObject * parent,
GstBuffer * buffer);
static GstStateChangeReturn gst_freeze_change_state (GstElement * element,
GstStateChange transition);
2012-09-12 21:24:26 +00:00
static GstFlowReturn gst_freeze_play (GstFreeze * freeze, GstBuffer * buff);
static void gst_freeze_loop (GstFreeze * freeze);
static gboolean gst_freeze_sink_activate (GstPad * sinkpad, GstObject * parent);
static gboolean gst_freeze_sink_activate_mode (GstPad * sinkpad,
GstObject * parent, GstPadMode mode, gboolean active);
static gboolean gst_freeze_sink_event (GstPad * pad, GstObject * parent,
GstEvent * event);
static void gst_freeze_clear_buffer (GstFreeze * freeze);
2012-09-12 21:24:26 +00:00
G_DEFINE_TYPE (GstFreeze, gst_freeze, GST_TYPE_ELEMENT);
static void
2012-09-12 21:24:26 +00:00
gst_freeze_class_init (GstFreezeClass * klass)
{
2012-09-12 21:24:26 +00:00
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_set_details_simple (element_class, "Stream freezer",
"Generic",
"Makes a stream from buffers of data",
"Gergely Nagy <gergely.nagy@neteyes.hu>,"
" Renato Filho <renato.filho@indt.org.br>");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_freeze_sink_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_freeze_src_template));
element_class->change_state = gst_freeze_change_state;
object_class->set_property = gst_freeze_set_property;
object_class->get_property = gst_freeze_get_property;
g_object_class_install_property (object_class,
ARG_MAX_BUFFERS,
g_param_spec_uint ("max-buffers",
"max-buffers",
"Maximum number of buffers", 0, G_MAXUINT, 1,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
object_class->dispose = gst_freeze_dispose;
}
static void
2012-09-12 21:24:26 +00:00
gst_freeze_init (GstFreeze * freeze)
{
freeze->sinkpad =
Fix leaks. Original commit message from CVS: * ext/amrwb/gstamrwbdec.c: (gst_amrwbdec_init): * ext/amrwb/gstamrwbenc.c: (gst_amrwbenc_init): * ext/amrwb/gstamrwbparse.c: (gst_amrwbparse_init): * ext/audioresample/gstaudioresample.c: * ext/bz2/gstbz2dec.c: (gst_bz2dec_init): * ext/bz2/gstbz2enc.c: (gst_bz2enc_init): * ext/divx/gstdivxdec.c: (gst_divxdec_init): * ext/divx/gstdivxenc.c: (gst_divxenc_init): * ext/faac/gstfaac.c: (gst_faac_init): * ext/gsm/gstgsmdec.c: (gst_gsmdec_init): * ext/gsm/gstgsmenc.c: (gst_gsmenc_init): * ext/hermes/gsthermescolorspace.c: (gst_hermes_colorspace_init): * ext/lcs/gstcolorspace.c: (gst_colorspace_init): * ext/libfame/gstlibfame.c: (gst_fameenc_init): * ext/snapshot/gstsnapshot.c: (gst_snapshot_init): * ext/spc/gstspc.c: (gst_spc_dec_init): * ext/swfdec/gstswfdec.c: (gst_swfdec_init): * ext/xvid/gstxvidenc.c: (gst_xvidenc_init): * gst/cdxaparse/gstcdxaparse.c: (gst_cdxa_parse_init): * gst/cdxaparse/gstcdxastrip.c: (gst_cdxastrip_init): * gst/chart/gstchart.c: (gst_chart_init): * gst/colorspace/gstcolorspace.c: (gst_colorspace_init): * gst/festival/gstfestival.c: (gst_festival_init): * gst/freeze/gstfreeze.c: (gst_freeze_init): * gst/mixmatrix/mixmatrix.c: (gst_mixmatrix_request_new_pad): * gst/mpeg1sys/gstmpeg1systemencode.c: (gst_system_encode_init): * gst/mpeg2sub/gstmpeg2subt.c: (gst_mpeg2subt_init): * gst/nsf/gstnsf.c: (gst_nsfdec_init): * gst/overlay/gstoverlay.c: (gst_overlay_init): * gst/passthrough/gstpassthrough.c: (passthrough_init): * gst/playondemand/gstplayondemand.c: (play_on_demand_init): * gst/smooth/gstsmooth.c: (gst_smooth_init): * gst/smoothwave/gstsmoothwave.c: (gst_smoothwave_init): * gst/speed/gstspeed.c: (speed_init): * gst/vbidec/gstvbidec.c: (gst_vbidec_init): * gst/videodrop/gstvideodrop.c: (gst_videodrop_init): * sys/dxr3/dxr3spusink.c: (dxr3spusink_init): * sys/dxr3/dxr3videosink.c: (dxr3videosink_init): * sys/qcam/gstqcamsrc.c: (gst_qcamsrc_init): Fix leaks.
2007-06-22 10:46:33 +00:00
gst_pad_new_from_static_template (&gst_freeze_sink_template, "sink");
gst_pad_set_activate_function (freeze->sinkpad, gst_freeze_sink_activate);
2012-09-12 21:24:26 +00:00
gst_pad_set_activatemode_function (freeze->sinkpad,
gst_freeze_sink_activate_mode);
gst_pad_set_chain_function (freeze->sinkpad, gst_freeze_chain);
2012-09-12 21:24:26 +00:00
GST_PAD_SET_PROXY_CAPS (freeze->sinkpad);
GST_PAD_SET_PROXY_ALLOCATION (freeze->sinkpad);
gst_pad_set_event_function (freeze->sinkpad, gst_freeze_sink_event);
2012-09-12 21:24:26 +00:00
gst_element_add_pad (GST_ELEMENT (freeze), freeze->sinkpad);
Fix leaks. Original commit message from CVS: * ext/amrwb/gstamrwbdec.c: (gst_amrwbdec_init): * ext/amrwb/gstamrwbenc.c: (gst_amrwbenc_init): * ext/amrwb/gstamrwbparse.c: (gst_amrwbparse_init): * ext/audioresample/gstaudioresample.c: * ext/bz2/gstbz2dec.c: (gst_bz2dec_init): * ext/bz2/gstbz2enc.c: (gst_bz2enc_init): * ext/divx/gstdivxdec.c: (gst_divxdec_init): * ext/divx/gstdivxenc.c: (gst_divxenc_init): * ext/faac/gstfaac.c: (gst_faac_init): * ext/gsm/gstgsmdec.c: (gst_gsmdec_init): * ext/gsm/gstgsmenc.c: (gst_gsmenc_init): * ext/hermes/gsthermescolorspace.c: (gst_hermes_colorspace_init): * ext/lcs/gstcolorspace.c: (gst_colorspace_init): * ext/libfame/gstlibfame.c: (gst_fameenc_init): * ext/snapshot/gstsnapshot.c: (gst_snapshot_init): * ext/spc/gstspc.c: (gst_spc_dec_init): * ext/swfdec/gstswfdec.c: (gst_swfdec_init): * ext/xvid/gstxvidenc.c: (gst_xvidenc_init): * gst/cdxaparse/gstcdxaparse.c: (gst_cdxa_parse_init): * gst/cdxaparse/gstcdxastrip.c: (gst_cdxastrip_init): * gst/chart/gstchart.c: (gst_chart_init): * gst/colorspace/gstcolorspace.c: (gst_colorspace_init): * gst/festival/gstfestival.c: (gst_festival_init): * gst/freeze/gstfreeze.c: (gst_freeze_init): * gst/mixmatrix/mixmatrix.c: (gst_mixmatrix_request_new_pad): * gst/mpeg1sys/gstmpeg1systemencode.c: (gst_system_encode_init): * gst/mpeg2sub/gstmpeg2subt.c: (gst_mpeg2subt_init): * gst/nsf/gstnsf.c: (gst_nsfdec_init): * gst/overlay/gstoverlay.c: (gst_overlay_init): * gst/passthrough/gstpassthrough.c: (passthrough_init): * gst/playondemand/gstplayondemand.c: (play_on_demand_init): * gst/smooth/gstsmooth.c: (gst_smooth_init): * gst/smoothwave/gstsmoothwave.c: (gst_smoothwave_init): * gst/speed/gstspeed.c: (speed_init): * gst/vbidec/gstvbidec.c: (gst_vbidec_init): * gst/videodrop/gstvideodrop.c: (gst_videodrop_init): * sys/dxr3/dxr3spusink.c: (dxr3spusink_init): * sys/dxr3/dxr3videosink.c: (dxr3videosink_init): * sys/qcam/gstqcamsrc.c: (gst_qcamsrc_init): Fix leaks.
2007-06-22 10:46:33 +00:00
freeze->srcpad =
gst_pad_new_from_static_template (&gst_freeze_src_template, "src");
2012-09-12 21:24:26 +00:00
GST_PAD_SET_PROXY_CAPS (freeze->srcpad);
GST_PAD_SET_PROXY_ALLOCATION (freeze->srcpad);
GST_PAD_SET_PROXY_SCHEDULING (freeze->srcpad);
gst_element_add_pad (GST_ELEMENT (freeze), freeze->srcpad);
freeze->timestamp_offset = 0;
freeze->running_time = 0;
freeze->current = 0;
freeze->max_buffers = 1;
freeze->buffers = g_ptr_array_new_with_free_func (
(GDestroyNotify) gst_buffer_unref);
}
static void
gst_freeze_dispose (GObject * object)
{
GstFreeze *freeze = GST_FREEZE (object);
gst_freeze_clear_buffer (freeze);
g_ptr_array_free (freeze->buffers, TRUE);
2012-09-12 21:24:26 +00:00
G_OBJECT_CLASS (gst_freeze_parent_class)->dispose (object);
}
static void
gst_freeze_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstFreeze *freeze = GST_FREEZE (object);
switch (prop_id) {
case ARG_MAX_BUFFERS:
freeze->max_buffers = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_freeze_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstFreeze *freeze = GST_FREEZE (object);
switch (prop_id) {
case ARG_MAX_BUFFERS:
g_value_set_uint (value, freeze->max_buffers);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static GstFlowReturn
2012-09-12 21:24:26 +00:00
gst_freeze_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
{
2012-09-12 21:24:26 +00:00
GstFreeze *freeze = GST_FREEZE (parent);
return gst_freeze_play (freeze, buffer);
}
static GstStateChangeReturn
gst_freeze_change_state (GstElement * element, GstStateChange transition)
{
GstFreeze *freeze = GST_FREEZE (element);
switch (transition) {
case GST_STATE_CHANGE_READY_TO_PAUSED:
freeze->timestamp_offset = freeze->running_time = 0;
break;
default:
break;
}
2012-09-12 21:24:26 +00:00
return GST_ELEMENT_CLASS (gst_freeze_parent_class)->change_state (element,
transition);
}
static GstFlowReturn
2012-09-12 21:24:26 +00:00
gst_freeze_play (GstFreeze * freeze, GstBuffer * buf)
{
GstFlowReturn ret = GST_FLOW_OK;
2012-09-12 21:24:26 +00:00
GstBuffer *outbuf;
if (freeze->buffers->len == 0)
2012-09-12 21:24:26 +00:00
freeze->timestamp_offset = GST_BUFFER_TIMESTAMP (buf);
if (freeze->buffers->len < freeze->max_buffers || freeze->max_buffers == 0) {
g_ptr_array_add (freeze->buffers, buf);
GST_DEBUG_OBJECT (freeze, "accepted buffer %u", freeze->buffers->len - 1);
} else {
2012-09-12 21:24:26 +00:00
gst_buffer_unref (buf);
}
outbuf =
gst_buffer_copy (g_ptr_array_index (freeze->buffers, freeze->current));
freeze->current++;
freeze->current %= freeze->buffers->len;
2012-09-12 21:24:26 +00:00
GST_BUFFER_TIMESTAMP (outbuf) = freeze->timestamp_offset +
freeze->running_time;
freeze->running_time += GST_BUFFER_DURATION (outbuf);
2012-09-12 21:24:26 +00:00
ret = gst_pad_push (freeze->srcpad, outbuf);
return ret;
}
static void
2012-09-12 21:24:26 +00:00
gst_freeze_loop (GstFreeze * freeze)
{
2012-09-12 21:24:26 +00:00
GstBuffer *buf;
GstFlowReturn ret;
ret = gst_pad_pull_range (freeze->sinkpad, freeze->offset, 4096, &buf);
if (ret != GST_FLOW_OK)
return;
freeze->offset += gst_buffer_get_size (buf);
gst_freeze_play (freeze, buf);
}
static gboolean
2012-09-12 21:24:26 +00:00
gst_freeze_sink_activate (GstPad * sinkpad, GstObject * parent)
{
2012-09-12 21:24:26 +00:00
GstQuery *query;
GstPadMode mode;
query = gst_query_new_scheduling ();
if (!gst_pad_peer_query (sinkpad, query))
goto no_valid_mode;
if (gst_query_has_scheduling_mode (query, GST_PAD_MODE_PULL))
mode = GST_PAD_MODE_PULL;
else if (gst_query_has_scheduling_mode (query, GST_PAD_MODE_PUSH))
mode = GST_PAD_MODE_PUSH;
else
goto no_valid_mode;
gst_query_unref (query);
return gst_pad_activate_mode (sinkpad, mode, TRUE);
no_valid_mode:
return FALSE;
}
static gboolean
2012-09-12 21:24:26 +00:00
gst_freeze_sink_activate_mode (GstPad * sinkpad, GstObject * parent,
GstPadMode mode, gboolean active)
{
2012-09-12 21:24:26 +00:00
GstFreeze *freeze = GST_FREEZE (parent);
gboolean result;
2012-09-12 21:24:26 +00:00
if (mode != GST_PAD_MODE_PULL)
return TRUE;
if (active) {
/* if we have a scheduler we can start the task */
result = gst_pad_start_task (sinkpad,
2012-09-12 21:24:26 +00:00
(GstTaskFunction) gst_freeze_loop, freeze, NULL);
} else {
result = gst_pad_stop_task (sinkpad);
}
return result;
}
static void
gst_freeze_clear_buffer (GstFreeze * freeze)
{
g_ptr_array_set_size (freeze->buffers, 0);
freeze->current = 0;
freeze->running_time = 0;
}
static gboolean
2012-09-12 21:24:26 +00:00
gst_freeze_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
2012-09-12 21:24:26 +00:00
GstFreeze *freeze = GST_FREEZE (parent);
gboolean ret = TRUE;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS:
GST_DEBUG_OBJECT (freeze, "EOS on sink pad %s",
gst_pad_get_name (GST_PAD (freeze->sinkpad)));
gst_event_unref (event);
break;
2012-09-12 21:24:26 +00:00
case GST_EVENT_STREAM_START:
case GST_EVENT_FLUSH_STOP:
gst_freeze_clear_buffer (freeze);
/* FALL TROUGH */
default:
2012-09-12 21:24:26 +00:00
ret = gst_pad_event_default (GST_PAD (freeze->sinkpad), parent, event);
break;
}
return ret;
}
static gboolean
plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (freeze_debug, "freeze", 0, "Stream freezer");
return gst_element_register (plugin, "freeze", GST_RANK_NONE,
GST_TYPE_FREEZE);
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
freeze,
"Stream freezer",
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);