2007-11-10 04:11:25 +00:00
|
|
|
/*
|
2005-07-16 19:50:21 +00:00
|
|
|
* GStreamer
|
|
|
|
* Copyright (c) 2005 INdT.
|
|
|
|
* @author Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>
|
|
|
|
* @author Rob Taylor <robtaylor@fastmail.fm>
|
|
|
|
* @author Philippe Khalaf <burger@speedy.org>
|
2007-11-10 04:11:25 +00:00
|
|
|
* @author Ole André Vadla Ravnås <oleavr@gmail.com>
|
2005-07-16 19:50:21 +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
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2005-07-16 19:50:21 +00:00
|
|
|
*/
|
2009-03-03 19:30:53 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-mimdec
|
|
|
|
* @see_also: mimenc
|
|
|
|
*
|
|
|
|
* The MIMIC codec is used by MSN Messenger's webcam support. It consumes the
|
|
|
|
* TCP header for the MIMIC codec.
|
|
|
|
*
|
|
|
|
* Its fourcc is ML20.
|
|
|
|
*/
|
2005-07-16 19:50:21 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
#include "gstmimdec.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (mimdec_debug);
|
|
|
|
#define GST_CAT_DEFAULT (mimdec_debug)
|
|
|
|
|
2009-03-03 19:20:37 +00:00
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-mimic")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
2005-07-16 19:50:21 +00:00
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2012-08-03 15:21:09 +00:00
|
|
|
GST_STATIC_CAPS ("video/x-raw, format= (string) \"RGB\", "
|
|
|
|
"framerate = (fraction) 0/1, width = (int) 320, height = (int) 240;"
|
|
|
|
"video/x-raw, format= (string) \"RGB\", "
|
|
|
|
"framerate = (fraction) 0/1, width = (int) 160, height = (int) 120")
|
2009-03-03 19:20:37 +00:00
|
|
|
);
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2009-10-12 22:36:58 +00:00
|
|
|
static void gst_mim_dec_finalize (GObject * object);
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
static GstFlowReturn gst_mim_dec_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * in);
|
2005-07-16 19:50:21 +00:00
|
|
|
static GstStateChangeReturn
|
2009-10-12 22:36:58 +00:00
|
|
|
gst_mim_dec_change_state (GstElement * element, GstStateChange transition);
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
static gboolean gst_mim_dec_sink_event (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event);
|
2009-07-20 17:45:54 +00:00
|
|
|
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
G_DEFINE_TYPE (GstMimDec, gst_mim_dec, GST_TYPE_ELEMENT);
|
2005-07-16 19:50:21 +00:00
|
|
|
|
|
|
|
static void
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_mim_dec_class_init (GstMimDecClass * klass)
|
2005-07-16 19:50:21 +00:00
|
|
|
{
|
2012-08-03 15:21:09 +00:00
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_mim_dec_change_state);
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &src_factory);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &sink_factory);
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class,
|
2009-10-12 23:36:29 +00:00
|
|
|
"Mimic Decoder",
|
2010-03-18 16:30:26 +00:00
|
|
|
"Codec/Decoder/Video",
|
2009-10-12 23:36:29 +00:00
|
|
|
"MSN Messenger compatible Mimic video decoder element",
|
2010-03-18 16:30:26 +00:00
|
|
|
"Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>, "
|
|
|
|
"Rob Taylor <robtaylor@fastmail.fm>, "
|
|
|
|
"Philippe Khalaf <burger@speedy.org>, "
|
2009-10-12 23:36:29 +00:00
|
|
|
"Ole André Vadla Ravnås <oleavr@gmail.com>,"
|
|
|
|
"Olivier Crête <olivier.crete@collabora.co.uk");
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2009-10-12 22:36:58 +00:00
|
|
|
gobject_class->finalize = gst_mim_dec_finalize;
|
2005-07-16 19:50:21 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (mimdec_debug, "mimdec", 0, "Mimic decoder plugin");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_mim_dec_init (GstMimDec * mimdec)
|
2005-07-16 19:50:21 +00:00
|
|
|
{
|
2009-07-21 02:08:52 +00:00
|
|
|
mimdec->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_pad_use_fixed_caps (mimdec->sinkpad);
|
2009-10-12 22:39:06 +00:00
|
|
|
gst_pad_set_chain_function (mimdec->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mim_dec_chain));
|
|
|
|
gst_pad_set_event_function (mimdec->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mim_dec_sink_event));
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (mimdec), mimdec->sinkpad);
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2009-07-21 02:08:52 +00:00
|
|
|
mimdec->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_pad_use_fixed_caps (mimdec->srcpad);
|
2005-07-16 19:50:21 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (mimdec), mimdec->srcpad);
|
|
|
|
|
|
|
|
mimdec->adapter = gst_adapter_new ();
|
|
|
|
|
|
|
|
mimdec->dec = NULL;
|
|
|
|
mimdec->buffer_size = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-10-12 22:36:58 +00:00
|
|
|
gst_mim_dec_finalize (GObject * object)
|
2005-07-16 19:50:21 +00:00
|
|
|
{
|
2009-10-12 22:36:58 +00:00
|
|
|
GstMimDec *mimdec = GST_MIM_DEC (object);
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2008-07-04 21:19:43 +00:00
|
|
|
gst_adapter_clear (mimdec->adapter);
|
|
|
|
g_object_unref (mimdec->adapter);
|
2012-08-03 15:21:09 +00:00
|
|
|
G_OBJECT_CLASS (gst_mim_dec_parent_class)->finalize (object);
|
2005-07-16 19:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_mim_dec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
2005-07-16 19:50:21 +00:00
|
|
|
{
|
2012-08-03 15:21:09 +00:00
|
|
|
GstMimDec *mimdec = GST_MIM_DEC (parent);
|
2009-10-12 23:57:50 +00:00
|
|
|
GstBuffer *out_buf;
|
2012-08-03 15:21:09 +00:00
|
|
|
const guchar *header, *frame_body;
|
2005-07-16 19:50:21 +00:00
|
|
|
guint32 fourcc;
|
|
|
|
guint16 header_size;
|
|
|
|
gint width, height;
|
2009-03-03 19:20:37 +00:00
|
|
|
GstCaps *caps;
|
2007-11-10 05:02:32 +00:00
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
2009-10-12 23:57:50 +00:00
|
|
|
GstClockTime in_time = GST_BUFFER_TIMESTAMP (buf);
|
2010-05-06 17:51:22 +00:00
|
|
|
GstEvent *event = NULL;
|
|
|
|
gboolean result = TRUE;
|
2009-10-13 00:06:13 +00:00
|
|
|
guint32 payload_size;
|
|
|
|
guint32 current_ts;
|
2012-08-03 15:21:09 +00:00
|
|
|
GstMapInfo map;
|
2005-07-16 19:50:21 +00:00
|
|
|
|
|
|
|
gst_adapter_push (mimdec->adapter, buf);
|
|
|
|
|
2008-07-04 22:02:43 +00:00
|
|
|
|
2009-10-12 23:17:30 +00:00
|
|
|
/* do we have enough bytes to read a header */
|
2009-10-13 00:06:13 +00:00
|
|
|
while (gst_adapter_available (mimdec->adapter) >= 24) {
|
2012-08-03 15:21:09 +00:00
|
|
|
header = gst_adapter_map (mimdec->adapter, 24);
|
2009-10-13 00:06:13 +00:00
|
|
|
header_size = header[0];
|
|
|
|
if (header_size != 24) {
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_adapter_unmap (mimdec->adapter);
|
2009-10-13 00:06:13 +00:00
|
|
|
gst_adapter_flush (mimdec->adapter, 24);
|
|
|
|
GST_ELEMENT_ERROR (mimdec, STREAM, DECODE, (NULL),
|
|
|
|
("invalid frame: header size %d incorrect", header_size));
|
2012-08-03 15:21:09 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2009-10-13 00:06:13 +00:00
|
|
|
}
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2009-10-13 00:06:13 +00:00
|
|
|
if (header[1] == 1) {
|
|
|
|
/* This is a a paused frame, skip it */
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_adapter_unmap (mimdec->adapter);
|
2009-10-13 00:06:13 +00:00
|
|
|
gst_adapter_flush (mimdec->adapter, 24);
|
|
|
|
continue;
|
|
|
|
}
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2009-10-13 00:06:13 +00:00
|
|
|
fourcc = GUINT32_FROM_LE (*((guint32 *) (header + 12)));
|
|
|
|
if (GST_MAKE_FOURCC ('M', 'L', '2', '0') != fourcc) {
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_adapter_unmap (mimdec->adapter);
|
2009-10-13 00:06:13 +00:00
|
|
|
gst_adapter_flush (mimdec->adapter, 24);
|
|
|
|
GST_ELEMENT_ERROR (mimdec, STREAM, WRONG_TYPE, (NULL),
|
2014-07-04 01:19:42 +00:00
|
|
|
("invalid frame: unknown FOURCC code 0x%" G_GINT32_MODIFIER "x",
|
|
|
|
fourcc));
|
2012-08-03 15:21:09 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2009-10-13 00:06:13 +00:00
|
|
|
}
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2009-10-13 00:06:13 +00:00
|
|
|
payload_size = GUINT32_FROM_LE (*((guint32 *) (header + 8)));
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2009-10-13 00:06:13 +00:00
|
|
|
current_ts = GUINT32_FROM_LE (*((guint32 *) (header + 20)));
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_adapter_unmap (mimdec->adapter);
|
|
|
|
|
2009-10-13 00:19:38 +00:00
|
|
|
GST_LOG_OBJECT (mimdec, "Got packet, payload size %d", payload_size);
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2009-10-13 00:06:13 +00:00
|
|
|
if (gst_adapter_available (mimdec->adapter) < payload_size + 24)
|
2012-08-03 15:21:09 +00:00
|
|
|
return GST_FLOW_OK;
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2009-10-13 00:06:13 +00:00
|
|
|
/* We have a whole packet and have read the header, lets flush it out */
|
|
|
|
gst_adapter_flush (mimdec->adapter, 24);
|
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
frame_body = gst_adapter_map (mimdec->adapter, payload_size);
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2009-10-12 23:50:52 +00:00
|
|
|
if (mimdec->buffer_size < 0) {
|
2008-07-25 19:48:33 +00:00
|
|
|
/* Check if its a keyframe, otherwise skip it */
|
2009-03-03 19:20:37 +00:00
|
|
|
if (GUINT32_FROM_LE (*((guint32 *) (frame_body + 12))) != 0) {
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_adapter_unmap (mimdec->adapter);
|
2009-10-13 00:06:13 +00:00
|
|
|
gst_adapter_flush (mimdec->adapter, payload_size);
|
2012-08-03 15:21:09 +00:00
|
|
|
return GST_FLOW_OK;
|
2008-07-25 19:48:33 +00:00
|
|
|
}
|
|
|
|
|
2008-07-04 21:19:43 +00:00
|
|
|
if (!mimic_decoder_init (mimdec->dec, frame_body)) {
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_adapter_unmap (mimdec->adapter);
|
2009-10-13 00:06:13 +00:00
|
|
|
gst_adapter_flush (mimdec->adapter, payload_size);
|
2009-10-12 23:16:26 +00:00
|
|
|
GST_ELEMENT_ERROR (mimdec, LIBRARY, INIT, (NULL),
|
|
|
|
("mimic_decoder_init error"));
|
2012-08-03 15:21:09 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2008-07-04 21:19:43 +00:00
|
|
|
}
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2009-03-03 19:20:37 +00:00
|
|
|
if (!mimic_get_property (mimdec->dec, "buffer_size",
|
|
|
|
&mimdec->buffer_size)) {
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_adapter_unmap (mimdec->adapter);
|
2009-10-13 00:06:13 +00:00
|
|
|
gst_adapter_flush (mimdec->adapter, payload_size);
|
2009-10-12 23:16:26 +00:00
|
|
|
GST_ELEMENT_ERROR (mimdec, LIBRARY, INIT, (NULL),
|
|
|
|
("mimic_get_property('buffer_size') error"));
|
2012-08-03 15:21:09 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2005-07-16 19:50:21 +00:00
|
|
|
}
|
2012-08-03 15:21:09 +00:00
|
|
|
|
|
|
|
mimic_get_property (mimdec->dec, "width", &width);
|
|
|
|
mimic_get_property (mimdec->dec, "height", &height);
|
|
|
|
GST_DEBUG_OBJECT (mimdec,
|
|
|
|
"Initialised decoder with %d x %d payload size %d buffer_size %d",
|
|
|
|
width, height, payload_size, mimdec->buffer_size);
|
|
|
|
caps = gst_caps_new_simple ("video/x-raw",
|
|
|
|
"format", G_TYPE_STRING, "RGB",
|
|
|
|
"framerate", GST_TYPE_FRACTION, 0, 1,
|
|
|
|
"width", G_TYPE_INT, width, "height", G_TYPE_INT, height, NULL);
|
|
|
|
gst_pad_set_caps (mimdec->srcpad, caps);
|
|
|
|
gst_caps_unref (caps);
|
2010-05-06 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-20 17:45:54 +00:00
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
if (mimdec->need_segment) {
|
|
|
|
GstSegment segment;
|
|
|
|
|
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
|
2010-05-06 17:51:22 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (in_time))
|
2012-08-03 15:21:09 +00:00
|
|
|
segment.start = in_time;
|
2010-05-06 17:51:22 +00:00
|
|
|
else
|
2012-08-03 15:21:09 +00:00
|
|
|
segment.start = current_ts * GST_MSECOND;
|
|
|
|
event = gst_event_new_segment (&segment);
|
2008-07-04 21:19:43 +00:00
|
|
|
}
|
2012-08-03 15:21:09 +00:00
|
|
|
mimdec->need_segment = FALSE;
|
2009-10-13 00:09:34 +00:00
|
|
|
|
2010-05-06 17:51:22 +00:00
|
|
|
if (event)
|
|
|
|
result = gst_pad_push_event (mimdec->srcpad, event);
|
2010-05-07 23:15:31 +00:00
|
|
|
event = NULL;
|
2009-10-13 00:09:34 +00:00
|
|
|
|
2010-05-06 17:51:22 +00:00
|
|
|
if (!result) {
|
|
|
|
GST_WARNING_OBJECT (mimdec, "gst_pad_push_event failed");
|
2012-08-03 15:21:09 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2010-05-06 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
out_buf = gst_buffer_new_allocate (NULL, mimdec->buffer_size, NULL);
|
|
|
|
gst_buffer_map (out_buf, &map, GST_MAP_READWRITE);
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
if (!mimic_decode_frame (mimdec->dec, frame_body, map.data)) {
|
2008-07-04 21:19:43 +00:00
|
|
|
GST_WARNING_OBJECT (mimdec, "mimic_decode_frame error\n");
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2009-10-13 00:06:13 +00:00
|
|
|
gst_adapter_flush (mimdec->adapter, payload_size);
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_buffer_unmap (out_buf, &map);
|
2008-07-04 21:19:43 +00:00
|
|
|
gst_buffer_unref (out_buf);
|
2009-10-12 23:16:26 +00:00
|
|
|
GST_ELEMENT_ERROR (mimdec, STREAM, DECODE, (NULL),
|
|
|
|
("mimic_decode_frame error"));
|
2012-08-03 15:21:09 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2008-07-04 21:19:43 +00:00
|
|
|
}
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_buffer_unmap (out_buf, &map);
|
2010-06-02 23:44:31 +00:00
|
|
|
gst_adapter_flush (mimdec->adapter, payload_size);
|
2008-07-04 21:19:43 +00:00
|
|
|
|
2009-07-20 18:00:17 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (in_time))
|
|
|
|
GST_BUFFER_TIMESTAMP (out_buf) = in_time;
|
|
|
|
else
|
2009-10-13 00:06:13 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (out_buf) = current_ts * GST_MSECOND;
|
2008-07-04 21:19:43 +00:00
|
|
|
|
|
|
|
res = gst_pad_push (mimdec->srcpad, out_buf);
|
2010-06-02 23:45:29 +00:00
|
|
|
|
|
|
|
if (res != GST_FLOW_OK)
|
|
|
|
break;
|
2005-07-16 19:50:21 +00:00
|
|
|
}
|
2007-11-10 04:11:25 +00:00
|
|
|
|
2007-11-10 05:03:51 +00:00
|
|
|
return res;
|
2005-07-16 19:50:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstStateChangeReturn
|
2009-10-12 22:36:58 +00:00
|
|
|
gst_mim_dec_change_state (GstElement * element, GstStateChange transition)
|
2005-07-16 19:50:21 +00:00
|
|
|
{
|
|
|
|
GstMimDec *mimdec;
|
2009-10-12 23:50:52 +00:00
|
|
|
GstStateChangeReturn ret;
|
2005-07-16 19:50:21 +00:00
|
|
|
|
2009-10-12 22:36:58 +00:00
|
|
|
mimdec = GST_MIM_DEC (element);
|
2008-07-25 22:47:26 +00:00
|
|
|
|
2009-10-12 23:50:52 +00:00
|
|
|
switch (transition) {
|
2012-08-03 15:21:09 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
|
|
|
mimdec->buffer_size = -1;
|
2009-10-12 23:50:52 +00:00
|
|
|
mimdec->dec = mimic_open ();
|
2014-04-09 17:12:58 +00:00
|
|
|
if (!mimdec->dec) {
|
2009-10-12 23:50:52 +00:00
|
|
|
GST_ERROR_OBJECT (mimdec, "mimic_open failed");
|
|
|
|
return GST_STATE_CHANGE_FAILURE;
|
|
|
|
}
|
2012-08-03 15:21:09 +00:00
|
|
|
mimdec->need_segment = TRUE;
|
2010-06-02 23:52:07 +00:00
|
|
|
gst_adapter_clear (mimdec->adapter);
|
2012-08-03 15:21:09 +00:00
|
|
|
|
2009-10-12 23:50:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
ret = GST_ELEMENT_CLASS (gst_mim_dec_parent_class)->change_state (element,
|
|
|
|
transition);
|
2009-10-12 23:50:52 +00:00
|
|
|
|
|
|
|
if (ret == GST_STATE_CHANGE_FAILURE)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
2005-07-16 19:50:21 +00:00
|
|
|
switch (transition) {
|
2012-08-03 15:21:09 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2005-07-16 19:50:21 +00:00
|
|
|
if (mimdec->dec != NULL) {
|
|
|
|
mimic_close (mimdec->dec);
|
|
|
|
mimdec->dec = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-12 23:50:52 +00:00
|
|
|
return ret;
|
2005-07-16 19:50:21 +00:00
|
|
|
}
|
2009-07-20 17:45:54 +00:00
|
|
|
|
|
|
|
static gboolean
|
2012-08-03 15:21:09 +00:00
|
|
|
gst_mim_dec_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
|
2009-07-20 17:45:54 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2012-08-03 15:21:09 +00:00
|
|
|
gboolean forward = TRUE;
|
|
|
|
GstMimDec *mimdec = GST_MIM_DEC (parent);
|
2009-07-20 17:45:54 +00:00
|
|
|
|
|
|
|
/*
|
2012-08-03 15:21:09 +00:00
|
|
|
* Ignore upstream segment event, its EVIL, we should implement
|
2009-07-20 17:45:54 +00:00
|
|
|
* proper seeking instead
|
|
|
|
*/
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2012-08-03 15:21:09 +00:00
|
|
|
case GST_EVENT_SEGMENT:
|
|
|
|
forward = FALSE;
|
2009-07-20 17:45:54 +00:00
|
|
|
break;
|
2012-08-03 15:21:09 +00:00
|
|
|
case GST_EVENT_STREAM_START:
|
2009-07-20 17:45:54 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2012-08-03 15:21:09 +00:00
|
|
|
case GST_EVENT_EOS:
|
2010-06-02 23:52:07 +00:00
|
|
|
gst_adapter_clear (mimdec->adapter);
|
2009-07-20 17:45:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
if (forward)
|
|
|
|
res = gst_pad_event_default (pad, parent, event);
|
|
|
|
else
|
2009-07-20 17:45:54 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
|
2012-08-03 15:21:09 +00:00
|
|
|
return res;
|
2009-07-20 17:45:54 +00:00
|
|
|
}
|