2002-09-15 19:43:01 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
2003-04-22 08:23:08 +00:00
|
|
|
* Copyright (C) <2002,2003> David A. Schleef <ds@schleef.org>
|
2002-09-15 19:43:01 +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 19:46:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2002-09-15 19:43:01 +00:00
|
|
|
#include "gstswfdec.h"
|
|
|
|
#include <string.h>
|
2003-12-22 01:47:09 +00:00
|
|
|
#include <gst/video/video.h>
|
2004-10-14 23:19:58 +00:00
|
|
|
#include <swfdec_buffer.h>
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementDetails gst_swfdec_details =
|
|
|
|
GST_ELEMENT_DETAILS ("SWF video decoder",
|
|
|
|
"Codec/Decoder/Video",
|
|
|
|
"Uses libswfdec to decode Flash video streams",
|
|
|
|
"David Schleef <ds@schleef.org>");
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
/* Swfdec signals and args */
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2005-12-09 04:15:02 +00:00
|
|
|
SIGNAL_EMBED_URL,
|
2002-09-15 19:43:01 +00:00
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2004-05-21 23:28:57 +00:00
|
|
|
ARG_0
|
|
|
|
/* FILL ME */
|
2002-09-15 19:43:01 +00:00
|
|
|
};
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
#define __GST_VIDEO_CAPS_MAKE_32_new(R, G, B) \
|
|
|
|
"video/x-raw-rgb, " \
|
|
|
|
"bpp = (int) 32, " \
|
|
|
|
"depth = (int) 24, " \
|
|
|
|
"endianness = (int) BIG_ENDIAN, " \
|
|
|
|
"red_mask = (int) " GST_VIDEO_BYTE ## R ## _MASK_32 ", " \
|
|
|
|
"green_mask = (int) " GST_VIDEO_BYTE ## G ## _MASK_32 ", " \
|
|
|
|
"blue_mask = (int) " GST_VIDEO_BYTE ## B ## _MASK_32 ", " \
|
|
|
|
"width = " GST_VIDEO_SIZE_RANGE ", " \
|
|
|
|
"height = " GST_VIDEO_SIZE_RANGE ", " \
|
|
|
|
"framerate = (fraction) [ 0, MAX ]"
|
|
|
|
|
|
|
|
#define GST_VIDEO_CAPS_BGRx_new \
|
|
|
|
__GST_VIDEO_CAPS_MAKE_32 (3, 2, 1)
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate video_template_factory =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("video_00",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2005-12-09 04:15:02 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx_new)
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate audio_template_factory =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("audio_00",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
2004-03-15 19:32:27 +00:00
|
|
|
"rate = (int) 44100, "
|
|
|
|
"channels = (int) 2, "
|
|
|
|
"endianness = (int) BYTE_ORDER, "
|
2004-11-09 06:08:22 +00:00
|
|
|
"width = (int) 16, " "depth = (int) 16, " "signed = (boolean) true")
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
static GstStaticPadTemplate sink_template_factory =
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/x-shockwave-flash")
|
|
|
|
);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_swfdec_base_init (gpointer g_class);
|
|
|
|
static void gst_swfdec_class_init (GstSwfdecClass * klass);
|
|
|
|
static void gst_swfdec_init (GstSwfdec * swfdec);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_swfdec_dispose (GObject * object);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_swfdec_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_swfdec_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
static gboolean gst_swfdec_sink_event (GstPad * pad, GstEvent * event);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean gst_swfdec_src_event (GstPad * pad, GstEvent * event);
|
2005-12-09 04:15:02 +00:00
|
|
|
static gboolean gst_swfdec_src_query (GstPad * pad, GstQuery * query);
|
2004-10-14 23:19:58 +00:00
|
|
|
static const GstQueryType *gst_swfdec_get_query_types (GstPad * pad);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn gst_swfdec_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
static GstFlowReturn gst_swfdec_chain (GstPad * pad, GstBuffer * buffer);
|
|
|
|
static void gst_swfdec_render (GstSwfdec * swfdec, int ret);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2005-12-09 04:15:02 +00:00
|
|
|
static guint gst_swfdec_signals[LAST_SIGNAL];
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-12-12 09:29:21 +00:00
|
|
|
|
|
|
|
/* GstSwfdecBuffer */
|
|
|
|
|
|
|
|
typedef struct _GstSwfdecBuffer GstSwfdecBuffer;
|
|
|
|
struct _GstSwfdecBuffer
|
|
|
|
{
|
|
|
|
GstBuffer buffer;
|
|
|
|
|
|
|
|
SwfdecBuffer *swfdec_buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GstBufferClass *buffer_parent_class = NULL;
|
|
|
|
|
|
|
|
static void gst_swfdecbuffer_class_init (gpointer g_class, gpointer class_data);
|
|
|
|
static void gst_swfdecbuffer_finalize (GstSwfdecBuffer * swfdecbuffer);
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_swfdecbuffer_get_type (void)
|
|
|
|
{
|
|
|
|
static GType _gst_swfdecbuffer_type;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (_gst_swfdecbuffer_type == 0)) {
|
|
|
|
static const GTypeInfo swfdecbuffer_info = {
|
|
|
|
sizeof (GstBufferClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
gst_swfdecbuffer_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstSwfdecBuffer),
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
_gst_swfdecbuffer_type = g_type_register_static (GST_TYPE_BUFFER,
|
|
|
|
"GstSwfdecBuffer", &swfdecbuffer_info, 0);
|
|
|
|
}
|
|
|
|
return _gst_swfdecbuffer_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_swfdecbuffer_class_init (gpointer g_class, gpointer class_data)
|
|
|
|
{
|
|
|
|
GstBufferClass *swfdecbuffer_class = GST_BUFFER_CLASS (g_class);
|
|
|
|
|
|
|
|
swfdecbuffer_class->mini_object_class.finalize =
|
|
|
|
(GstMiniObjectFinalizeFunction) gst_swfdecbuffer_finalize;
|
|
|
|
|
|
|
|
buffer_parent_class = g_type_class_ref (GST_TYPE_BUFFER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_swfdecbuffer_finalize (GstSwfdecBuffer * swfdecbuffer)
|
|
|
|
{
|
|
|
|
g_return_if_fail (swfdecbuffer != NULL);
|
|
|
|
|
|
|
|
GST_LOG ("finalize %p", swfdecbuffer);
|
|
|
|
|
|
|
|
swfdec_buffer_unref (swfdecbuffer->swfdec_buffer);
|
|
|
|
|
|
|
|
((GstMiniObjectClass *) buffer_parent_class)->
|
|
|
|
finalize ((GstMiniObject *) swfdecbuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GstSwfdec */
|
|
|
|
|
2002-09-15 19:43:01 +00:00
|
|
|
GType
|
|
|
|
gst_swfdec_get_type (void)
|
|
|
|
{
|
|
|
|
static GType swfdec_type = 0;
|
|
|
|
|
|
|
|
if (!swfdec_type) {
|
|
|
|
static const GTypeInfo swfdec_info = {
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstSwfdecClass),
|
2003-11-03 15:48:38 +00:00
|
|
|
gst_swfdec_base_init,
|
2002-09-15 19:43:01 +00:00
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GClassInitFunc) gst_swfdec_class_init,
|
2002-09-15 19:43:01 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-03-14 22:34:33 +00:00
|
|
|
sizeof (GstSwfdec),
|
2002-09-15 19:43:01 +00:00
|
|
|
0,
|
2004-03-14 22:34:33 +00:00
|
|
|
(GInstanceInitFunc) gst_swfdec_init,
|
2002-09-15 19:43:01 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
swfdec_type =
|
2004-03-15 19:32:27 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstSwfdec", &swfdec_info, 0);
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
return swfdec_type;
|
|
|
|
}
|
|
|
|
|
2003-11-03 15:48:38 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_base_init (gpointer g_class)
|
2003-11-03 15:48:38 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_swfdec_details);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&video_template_factory));
|
2003-11-03 15:48:38 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&audio_template_factory));
|
2003-11-03 15:48:38 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_static_pad_template_get (&sink_template_factory));
|
2003-11-03 15:48:38 +00:00
|
|
|
}
|
2005-12-09 04:15:02 +00:00
|
|
|
|
2002-09-15 19:43:01 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_class_init (GstSwfdecClass * klass)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class->set_property = gst_swfdec_set_property;
|
|
|
|
gobject_class->get_property = gst_swfdec_get_property;
|
|
|
|
gobject_class->dispose = gst_swfdec_dispose;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
gstelement_class->change_state = gst_swfdec_change_state;
|
2005-12-09 04:15:02 +00:00
|
|
|
|
|
|
|
gst_swfdec_signals[SIGNAL_EMBED_URL] =
|
|
|
|
g_signal_new ("embed-url", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GstSwfdecClass, embed_url), NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2004-01-22 03:25:16 +00:00
|
|
|
static GstCaps *
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_video_getcaps (GstPad * pad)
|
2004-01-22 03:25:16 +00:00
|
|
|
{
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
|
|
|
|
if (swfdec->have_format) {
|
|
|
|
gst_caps_set_simple (caps,
|
2005-12-09 04:15:02 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION, swfdec->frame_rate_n,
|
|
|
|
swfdec->frame_rate_d, NULL);
|
2004-01-22 03:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
static gboolean
|
|
|
|
gst_swfdec_video_link (GstPad * pad, GstCaps * caps)
|
2004-01-22 03:25:16 +00:00
|
|
|
{
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
GstStructure *structure;
|
|
|
|
int width, height;
|
|
|
|
int ret;
|
2005-12-09 04:15:02 +00:00
|
|
|
gboolean res = FALSE;
|
2004-01-22 03:25:16 +00:00
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
gst_structure_get_int (structure, "width", &width);
|
|
|
|
gst_structure_get_int (structure, "height", &height);
|
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
ret = swfdec_decoder_set_image_size (swfdec->decoder, width, height);
|
2004-01-22 03:25:16 +00:00
|
|
|
if (ret == SWF_OK) {
|
|
|
|
swfdec->width = width;
|
|
|
|
swfdec->height = height;
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
res = TRUE;
|
2004-01-22 03:25:16 +00:00
|
|
|
}
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
g_object_unref (swfdec);
|
|
|
|
return res;
|
|
|
|
|
2004-01-22 03:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_swfdec_buffer_free (SwfdecBuffer * buf, void *priv)
|
2004-01-22 03:25:16 +00:00
|
|
|
{
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_buffer_unref (GST_BUFFER (priv));
|
|
|
|
}
|
|
|
|
|
|
|
|
static SwfdecBuffer *
|
|
|
|
gst_swfdec_buffer_to_swf (GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
SwfdecBuffer *sbuf;
|
|
|
|
|
|
|
|
sbuf = swfdec_buffer_new_with_data (GST_BUFFER_DATA (buffer),
|
|
|
|
GST_BUFFER_SIZE (buffer));
|
|
|
|
sbuf->free = gst_swfdec_buffer_free;
|
|
|
|
sbuf->priv = buffer;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
return sbuf;
|
2004-01-22 03:25:16 +00:00
|
|
|
}
|
|
|
|
|
2005-12-12 09:29:21 +00:00
|
|
|
static GstBuffer *
|
|
|
|
gst_swfdec_buffer_from_swf (SwfdecBuffer * buffer)
|
|
|
|
{
|
|
|
|
GstSwfdecBuffer *buf;
|
|
|
|
|
|
|
|
buf = (GstSwfdecBuffer *) gst_mini_object_new (gst_swfdecbuffer_get_type ());
|
|
|
|
GST_BUFFER_DATA (buf) = buffer->data;
|
|
|
|
GST_BUFFER_SIZE (buf) = buffer->length;
|
|
|
|
buf->swfdec_buffer = buffer;
|
|
|
|
|
|
|
|
return GST_BUFFER (buf);
|
|
|
|
}
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
GstFlowReturn
|
|
|
|
gst_swfdec_chain (GstPad * pad, GstBuffer * buffer)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
2005-12-09 04:15:02 +00:00
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
2004-03-14 22:34:33 +00:00
|
|
|
int ret;
|
2005-12-09 04:15:02 +00:00
|
|
|
GstSwfdec *swfdec = GST_SWFDEC (GST_PAD_PARENT (pad));
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
g_static_rec_mutex_lock (&swfdec->mutex);
|
2004-10-14 23:19:58 +00:00
|
|
|
ret = swfdec_decoder_parse (swfdec->decoder);
|
2004-03-14 22:34:33 +00:00
|
|
|
if (ret == SWF_NEEDBITS) {
|
2005-12-09 04:15:02 +00:00
|
|
|
guint buf_size;
|
|
|
|
GstBuffer *prev_buffer;
|
|
|
|
|
|
|
|
buf_size = gst_adapter_available (swfdec->adapter);
|
|
|
|
if (buf_size) {
|
|
|
|
prev_buffer = gst_buffer_new_and_alloc (buf_size);
|
|
|
|
memcpy (GST_BUFFER_DATA (prev_buffer), gst_adapter_peek (swfdec->adapter,
|
|
|
|
buf_size), buf_size);
|
|
|
|
gst_adapter_flush (swfdec->adapter, buf_size);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec_decoder_add_buffer (swfdec->decoder,
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_swfdec_buffer_to_swf (prev_buffer));
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2005-12-09 04:15:02 +00:00
|
|
|
|
|
|
|
swfdec_decoder_add_buffer (swfdec->decoder,
|
|
|
|
gst_swfdec_buffer_to_swf (buffer));
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
} else if (ret == SWF_CHANGE) {
|
2005-12-09 04:15:02 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GstCaps *caps;
|
2005-12-09 04:15:02 +00:00
|
|
|
double rate;
|
|
|
|
|
|
|
|
/* Let's not depend on features that are only in CVS */
|
|
|
|
#ifdef HAVE_SWFDEC_0_3_5
|
|
|
|
GstTagList *taglist;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gst_adapter_push (swfdec->adapter, buffer);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec_decoder_get_image_size (swfdec->decoder,
|
2004-03-15 19:32:27 +00:00
|
|
|
&swfdec->width, &swfdec->height);
|
2005-12-09 04:15:02 +00:00
|
|
|
swfdec_decoder_get_rate (swfdec->decoder, &rate);
|
|
|
|
swfdec->interval = GST_SECOND / rate;
|
|
|
|
|
|
|
|
swfdec->frame_rate_n = (int) (rate * 256.0);
|
|
|
|
swfdec->frame_rate_d = 256;
|
2004-01-22 03:25:16 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
caps = gst_caps_copy (gst_pad_get_pad_template_caps (swfdec->videopad));
|
|
|
|
gst_caps_set_simple (caps,
|
2005-12-09 04:15:02 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION, swfdec->frame_rate_n,
|
|
|
|
swfdec->frame_rate_d, "height", G_TYPE_INT, swfdec->height, "width",
|
|
|
|
G_TYPE_INT, swfdec->width, NULL);
|
|
|
|
if (gst_pad_set_caps (swfdec->videopad, caps)) {
|
2004-03-14 22:34:33 +00:00
|
|
|
/* good */
|
|
|
|
} else {
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_caps_unref (caps);
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_ELEMENT_ERROR (swfdec, CORE, NEGOTIATION, (NULL), (NULL));
|
2005-12-09 04:15:02 +00:00
|
|
|
res = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
caps = gst_caps_copy (gst_pad_get_pad_template_caps (swfdec->audiopad));
|
|
|
|
if (gst_pad_set_caps (swfdec->audiopad, caps)) {
|
|
|
|
swfdec->have_format = TRUE;
|
|
|
|
} else {
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
GST_ELEMENT_ERROR (swfdec, CORE, NEGOTIATION, (NULL), (NULL));
|
|
|
|
res = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2005-12-09 04:15:02 +00:00
|
|
|
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_SWFDEC_0_3_5
|
|
|
|
taglist = gst_tag_list_new ();
|
|
|
|
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_ENCODER_VERSION, swfdec_decoder_get_version (swfdec->decoder),
|
|
|
|
NULL);
|
|
|
|
gst_element_found_tags (GST_ELEMENT (swfdec), taglist);
|
|
|
|
gst_tag_list_free (taglist);
|
|
|
|
#endif
|
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
} else if (ret == SWF_EOF) {
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_swfdec_render (swfdec, ret);
|
|
|
|
gst_task_start (swfdec->task);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
g_static_rec_mutex_unlock (&swfdec->mutex);
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_swfdec_loop (GstSwfdec * swfdec)
|
|
|
|
{
|
|
|
|
|
|
|
|
gst_swfdec_render (swfdec, swfdec_decoder_parse (swfdec->decoder));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_swfdec_render (GstSwfdec * swfdec, int ret)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ret == SWF_EOF) {
|
2004-10-14 23:19:58 +00:00
|
|
|
SwfdecBuffer *audio_buffer;
|
|
|
|
SwfdecBuffer *video_buffer;
|
|
|
|
GstBuffer *videobuf;
|
|
|
|
GstBuffer *audiobuf;
|
|
|
|
gboolean ret;
|
2005-12-09 04:15:02 +00:00
|
|
|
const char *url;
|
|
|
|
|
|
|
|
swfdec_decoder_set_mouse (swfdec->decoder, swfdec->x, swfdec->y,
|
|
|
|
swfdec->button);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
ret = swfdec_render_iterate (swfdec->decoder);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
if (!ret) {
|
|
|
|
gst_task_stop (swfdec->task);
|
|
|
|
gst_pad_push_event (swfdec->videopad, gst_event_new_eos ());
|
|
|
|
gst_pad_push_event (swfdec->audiopad, gst_event_new_eos ());
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
if (swfdec->send_discont) {
|
|
|
|
GstEvent *event;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec->timestamp = swfdec_render_get_frame_index (swfdec->decoder) *
|
|
|
|
swfdec->interval;
|
2003-01-17 05:27:12 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
GST_DEBUG ("sending discont %" G_GINT64_FORMAT, swfdec->timestamp);
|
2003-01-17 05:27:12 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
|
|
|
|
swfdec->timestamp, GST_CLOCK_TIME_NONE, 0);
|
|
|
|
gst_pad_push_event (swfdec->videopad, event);
|
2003-01-17 05:27:12 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
|
|
|
|
swfdec->timestamp, GST_CLOCK_TIME_NONE, 0);
|
|
|
|
gst_pad_push_event (swfdec->audiopad, event);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec->send_discont = FALSE;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
GST_DEBUG ("pushing image/sound %" G_GINT64_FORMAT, swfdec->timestamp);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
if (swfdec->skip_index) {
|
|
|
|
video_buffer = NULL;
|
|
|
|
swfdec->skip_index--;
|
|
|
|
} else {
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
video_buffer = swfdec_render_get_image (swfdec->decoder);
|
|
|
|
|
|
|
|
if (!video_buffer) {
|
|
|
|
gst_task_stop (swfdec->task);
|
|
|
|
gst_pad_push_event (swfdec->videopad, gst_event_new_eos ());
|
|
|
|
gst_pad_push_event (swfdec->audiopad, gst_event_new_eos ());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
swfdec->skip_index = swfdec->skip_frames - 1;
|
|
|
|
|
2005-12-12 09:29:21 +00:00
|
|
|
videobuf = gst_swfdec_buffer_from_swf (video_buffer);
|
2005-12-09 04:15:02 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (videobuf) = swfdec->timestamp;
|
|
|
|
gst_buffer_set_caps (videobuf, GST_PAD_CAPS (swfdec->videopad));
|
|
|
|
|
|
|
|
gst_pad_push (swfdec->videopad, videobuf);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
audio_buffer = swfdec_render_get_audio (swfdec->decoder);
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
if (audio_buffer) {
|
|
|
|
|
2005-12-12 09:29:21 +00:00
|
|
|
audiobuf = gst_swfdec_buffer_from_swf (audio_buffer);
|
2005-12-09 04:15:02 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (audiobuf) = swfdec->timestamp;
|
|
|
|
gst_buffer_set_caps (audiobuf, GST_PAD_CAPS (swfdec->audiopad));
|
|
|
|
|
|
|
|
gst_pad_push (swfdec->audiopad, audiobuf);
|
|
|
|
|
|
|
|
}
|
2004-10-14 23:19:58 +00:00
|
|
|
|
|
|
|
swfdec->timestamp += swfdec->interval;
|
2005-12-09 04:15:02 +00:00
|
|
|
|
|
|
|
url = swfdec_decoder_get_url (swfdec->decoder);
|
|
|
|
if (url) {
|
|
|
|
g_signal_emit (G_OBJECT (swfdec), gst_swfdec_signals[SIGNAL_EMBED_URL],
|
|
|
|
0, url);
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_init (GstSwfdec * swfdec)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
/* create the sink and src pads */
|
2004-03-14 22:34:33 +00:00
|
|
|
swfdec->sinkpad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&sink_template_factory), "sink");
|
2002-09-15 19:43:01 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (swfdec), swfdec->sinkpad);
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_pad_set_chain_function (swfdec->sinkpad, gst_swfdec_chain);
|
|
|
|
gst_pad_set_event_function (swfdec->sinkpad, gst_swfdec_sink_event);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
swfdec->videopad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&video_template_factory), "video_00");
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_pad_set_query_function (swfdec->videopad, gst_swfdec_src_query);
|
2004-01-22 03:25:16 +00:00
|
|
|
gst_pad_set_getcaps_function (swfdec->videopad, gst_swfdec_video_getcaps);
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_pad_set_setcaps_function (swfdec->videopad, gst_swfdec_video_link);
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_pad_set_event_function (swfdec->videopad, gst_swfdec_src_event);
|
2005-12-09 04:15:02 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_pad_set_query_type_function (swfdec->videopad,
|
|
|
|
gst_swfdec_get_query_types);
|
2005-12-09 04:15:02 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (swfdec), swfdec->videopad);
|
2003-04-22 08:23:08 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
swfdec->audiopad =
|
|
|
|
gst_pad_new_from_template (gst_static_pad_template_get
|
|
|
|
(&audio_template_factory), "audio_00");
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_pad_set_query_function (swfdec->audiopad, gst_swfdec_src_query);
|
|
|
|
gst_pad_set_event_function (swfdec->audiopad, gst_swfdec_src_event);
|
2005-12-09 04:15:02 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_pad_set_query_type_function (swfdec->audiopad,
|
|
|
|
gst_swfdec_get_query_types);
|
2005-12-09 04:15:02 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (swfdec), swfdec->audiopad);
|
2003-04-22 08:23:08 +00:00
|
|
|
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
/* initialize the swfdec decoder state */
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec->decoder = swfdec_decoder_new ();
|
|
|
|
g_return_if_fail (swfdec->decoder != NULL);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec_decoder_set_colorspace (swfdec->decoder, SWF_COLORSPACE_RGB888);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
swfdec->frame_rate_n = 0;
|
|
|
|
swfdec->frame_rate_d = 1;
|
|
|
|
swfdec->x = -1;
|
|
|
|
swfdec->y = -1;
|
|
|
|
|
|
|
|
swfdec->skip_frames = 2;
|
|
|
|
swfdec->skip_index = 0;
|
|
|
|
|
|
|
|
swfdec->adapter = gst_adapter_new ();
|
|
|
|
swfdec->task = gst_task_create ((GstTaskFunction) gst_swfdec_loop, swfdec);
|
|
|
|
g_static_rec_mutex_init (&swfdec->mutex);
|
|
|
|
gst_task_set_lock (swfdec->task, &swfdec->mutex);
|
2003-07-06 20:49:52 +00:00
|
|
|
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_dispose (GObject * object)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
2004-10-14 23:19:58 +00:00
|
|
|
GstSwfdec *swfdec = GST_SWFDEC (object);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_task_stop (swfdec->task);
|
|
|
|
gst_task_join (swfdec->task);
|
|
|
|
gst_object_unref (swfdec->task);
|
|
|
|
g_static_rec_mutex_free (&swfdec->mutex);
|
|
|
|
|
|
|
|
g_object_unref (swfdec->adapter);
|
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec_decoder_free (swfdec->decoder);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
static const GstQueryType *
|
|
|
|
gst_swfdec_get_query_types (GstPad * pad)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
2004-10-14 23:19:58 +00:00
|
|
|
static const GstQueryType gst_swfdec_query_types[] = {
|
|
|
|
GST_QUERY_POSITION,
|
2005-12-09 04:15:02 +00:00
|
|
|
GST_QUERY_DURATION,
|
2004-10-14 23:19:58 +00:00
|
|
|
0
|
|
|
|
};
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
return gst_swfdec_query_types;
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_swfdec_src_query (GstPad * pad, GstQuery * query)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_POSITION:
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
2005-12-09 04:15:02 +00:00
|
|
|
GstFormat format;
|
|
|
|
gint64 value;
|
|
|
|
|
|
|
|
gst_query_parse_position (query, &format, NULL);
|
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
value = swfdec_render_get_frame_index (swfdec->decoder) *
|
|
|
|
swfdec->interval;
|
|
|
|
gst_query_set_position (query, GST_FORMAT_TIME, value);
|
|
|
|
res = TRUE;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_DURATION:
|
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
gint64 value;
|
|
|
|
|
|
|
|
gst_query_parse_duration (query, &format, NULL);
|
|
|
|
|
|
|
|
switch (format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
|
|
|
int n_frames;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
res = FALSE;
|
2004-10-14 23:19:58 +00:00
|
|
|
ret = swfdec_decoder_get_n_frames (swfdec->decoder, &n_frames);
|
2004-03-15 19:32:27 +00:00
|
|
|
if (ret == SWF_OK) {
|
2005-12-09 04:15:02 +00:00
|
|
|
value = n_frames * swfdec->interval;
|
|
|
|
gst_query_set_duration (query, GST_FORMAT_TIME, value);
|
2004-03-15 19:32:27 +00:00
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
g_object_unref (swfdec);
|
2002-09-15 19:43:01 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
#if 0
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_swfdec_get_event_masks (GstPad * pad)
|
|
|
|
{
|
|
|
|
static const GstEventMask gst_swfdec_event_masks[] = {
|
|
|
|
{GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH},
|
2005-12-09 04:15:02 +00:00
|
|
|
{GST_EVENT_NAVIGATION, 0},
|
2004-10-14 23:19:58 +00:00
|
|
|
{0,}
|
|
|
|
};
|
|
|
|
|
|
|
|
return gst_swfdec_event_masks;
|
|
|
|
}
|
2005-12-09 04:15:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_swfdec_sink_event (GstPad * pad, GstEvent * event)
|
|
|
|
{
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (GST_PAD_PARENT (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
swfdec_decoder_eof (swfdec->decoder);
|
|
|
|
gst_task_start (swfdec->task);
|
|
|
|
gst_event_unref (event);
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = gst_pad_event_default (pad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2004-10-14 23:19:58 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean
|
|
|
|
gst_swfdec_src_event (GstPad * pad, GstEvent * event)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstSwfdec *swfdec;
|
2004-10-14 23:19:58 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
#define MAX_SEEK_FORMATS 1 /* we can only do time seeking for now */
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2004-03-14 22:34:33 +00:00
|
|
|
/* the all-formats seek logic */
|
2002-09-15 19:43:01 +00:00
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
2005-12-09 04:15:02 +00:00
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType start_type, stop_type;
|
|
|
|
gint64 start, stop;
|
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
int new_frame;
|
|
|
|
int ret;
|
|
|
|
int n_frames;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags, &start_type, &start,
|
|
|
|
&stop_type, &stop);
|
|
|
|
|
|
|
|
new_frame = start / swfdec->interval;
|
2004-10-14 23:19:58 +00:00
|
|
|
ret = swfdec_decoder_get_n_frames (swfdec->decoder, &n_frames);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
if (new_frame >= 0 && new_frame < n_frames) {
|
|
|
|
GstEvent *event;
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
GST_DEBUG ("seeking to frame %d\n", new_frame);
|
|
|
|
swfdec_render_seek (swfdec->decoder, new_frame);
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
GST_DEBUG ("sending flush event\n");
|
2005-12-09 04:15:02 +00:00
|
|
|
|
|
|
|
event = gst_event_new_flush_start ();
|
|
|
|
gst_pad_push_event (swfdec->videopad, event);
|
|
|
|
event = gst_event_new_flush_start ();
|
|
|
|
gst_pad_push_event (swfdec->audiopad, event);
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec->send_discont = TRUE;
|
|
|
|
swfdec->seek_frame = new_frame;
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
2004-10-14 23:19:58 +00:00
|
|
|
|
|
|
|
res = TRUE;
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-12-09 04:15:02 +00:00
|
|
|
case GST_EVENT_NAVIGATION:
|
|
|
|
{
|
|
|
|
const GstStructure *structure = gst_event_get_structure (event);
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
type = gst_structure_get_string (structure, "event");
|
|
|
|
GST_DEBUG ("got nav event %s", type);
|
|
|
|
if (g_str_equal (type, "mouse-move")) {
|
|
|
|
gst_structure_get_double (structure, "pointer_x", &swfdec->x);
|
|
|
|
gst_structure_get_double (structure, "pointer_y", &swfdec->y);
|
|
|
|
} else if (g_str_equal (type, "mouse-button-press")) {
|
|
|
|
gst_structure_get_double (structure, "pointer_x", &swfdec->x);
|
|
|
|
gst_structure_get_double (structure, "pointer_y", &swfdec->y);
|
|
|
|
swfdec->button = 1;
|
|
|
|
} else if (g_str_equal (type, "mouse-button-release")) {
|
|
|
|
gst_structure_get_double (structure, "pointer_x", &swfdec->x);
|
|
|
|
gst_structure_get_double (structure, "pointer_y", &swfdec->y);
|
|
|
|
swfdec->button = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-09-15 19:43:01 +00:00
|
|
|
default:
|
2005-12-09 04:15:02 +00:00
|
|
|
res = gst_pad_event_default (pad, event);
|
|
|
|
event = NULL;
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-12-09 04:15:02 +00:00
|
|
|
if (event) {
|
|
|
|
gst_event_unref (event);
|
|
|
|
}
|
|
|
|
gst_object_unref (swfdec);
|
2002-09-15 19:43:01 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_swfdec_change_state (GstElement * element, GstStateChange transition)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
GstSwfdec *swfdec = GST_SWFDEC (element);
|
2005-12-09 04:15:02 +00:00
|
|
|
GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2005-09-05 17:20:29 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_adapter_clear (swfdec->adapter);
|
|
|
|
/*
|
|
|
|
gst_swfdec_vo_open (swfdec);
|
|
|
|
swfdec_decoder_new (swfdec->decoder, swfdec->accel, swfdec->vo);
|
|
|
|
|
|
|
|
swfdec->decoder->is_sequence_needed = 1;
|
|
|
|
swfdec->decoder->frame_rate_code = 0;
|
|
|
|
*/
|
2002-09-15 19:43:01 +00:00
|
|
|
swfdec->timestamp = 0;
|
|
|
|
swfdec->closed = FALSE;
|
|
|
|
|
|
|
|
/* reset the initial video state */
|
2004-01-22 03:25:16 +00:00
|
|
|
swfdec->have_format = FALSE;
|
2002-09-15 19:43:01 +00:00
|
|
|
swfdec->format = -1;
|
|
|
|
swfdec->width = -1;
|
|
|
|
swfdec->height = -1;
|
|
|
|
swfdec->first = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_task_start (swfdec->task);
|
|
|
|
break;
|
|
|
|
default:
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
2005-12-09 04:15:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
|
|
|
|
|
|
|
switch (transition) {
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_task_pause (swfdec->task);
|
|
|
|
gst_task_join (swfdec->task);
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2002-09-15 19:43:01 +00:00
|
|
|
/* if we are not closed by an EOS event do so now, this cen send a few frames but
|
|
|
|
* we are prepared to not really send them (see above) */
|
|
|
|
if (!swfdec->closed) {
|
2004-03-15 19:32:27 +00:00
|
|
|
/*swf_close (swfdec->decoder); */
|
|
|
|
swfdec->closed = TRUE;
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
2005-12-09 04:15:02 +00:00
|
|
|
/* gst_swfdec_vo_destroy (swfdec); */
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
2005-09-05 17:20:29 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2005-12-09 04:15:02 +00:00
|
|
|
gst_task_stop (swfdec->task);
|
|
|
|
gst_task_join (swfdec->task);
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
return ret;
|
|
|
|
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
GstSwfdec *src;
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2002-09-15 19:43:01 +00:00
|
|
|
g_return_if_fail (GST_IS_SWFDEC (object));
|
|
|
|
src = GST_SWFDEC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
|
2005-12-09 04:15:02 +00:00
|
|
|
/* it's not null if we got it, but it might not be ours */
|
2002-09-15 19:43:01 +00:00
|
|
|
g_return_if_fail (GST_IS_SWFDEC (object));
|
|
|
|
swfdec = GST_SWFDEC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
void
|
|
|
|
art_warn (const char *fmt, ...)
|
|
|
|
{
|
2005-12-09 04:15:02 +00:00
|
|
|
GST_LOG ("caught art_warn");
|
2004-10-14 23:19:58 +00:00
|
|
|
}
|
|
|
|
|
2002-09-15 19:43:01 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
return gst_element_register (plugin, "swfdec", GST_RANK_PRIMARY,
|
|
|
|
GST_TYPE_SWFDEC);
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"swfdec",
|
|
|
|
"Uses libswfdec to decode Flash video streams",
|
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)
|