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
|
|
|
|
{
|
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
|
|
|
};
|
|
|
|
|
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,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx)
|
|
|
|
);
|
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
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static gboolean gst_swfdec_src_event (GstPad * pad, GstEvent * event);
|
|
|
|
static gboolean gst_swfdec_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value);
|
2004-10-14 23:19:58 +00:00
|
|
|
static const GstQueryType *gst_swfdec_get_query_types (GstPad * pad);
|
|
|
|
static const GstEventMask *gst_swfdec_get_event_masks (GstPad * pad);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstElementStateReturn gst_swfdec_change_state (GstElement * element);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
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,
|
2004-03-15 19:32:27 +00:00
|
|
|
"framerate", G_TYPE_DOUBLE, swfdec->frame_rate, NULL);
|
2004-01-22 03:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPadLinkReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_video_link (GstPad * pad, const GstCaps * caps)
|
2004-01-22 03:25:16 +00:00
|
|
|
{
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
GstStructure *structure;
|
|
|
|
int width, height;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (!swfdec->have_format) {
|
|
|
|
return GST_PAD_LINK_DELAYED;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
g_print ("setting size to %d x %d\n", width, height);
|
|
|
|
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;
|
|
|
|
|
|
|
|
return GST_PAD_LINK_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_PAD_LINK_REFUSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-09-15 19:43:01 +00:00
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_loop (GstElement * element)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
GstSwfdec *swfdec;
|
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
int ret;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_if_fail (element != NULL);
|
|
|
|
g_return_if_fail (GST_IS_SWFDEC (element));
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
swfdec = GST_SWFDEC (element);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!swfdec->videopad) {
|
|
|
|
}
|
2002-09-15 19:43:01 +00:00
|
|
|
|
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) {
|
|
|
|
buf = GST_BUFFER (gst_pad_pull (swfdec->sinkpad));
|
|
|
|
if (GST_IS_EVENT (buf)) {
|
|
|
|
switch (GST_EVENT_TYPE (buf)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_EVENT_EOS:
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec_decoder_eof (swfdec->decoder);
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_DEBUG ("got eos");
|
|
|
|
break;
|
|
|
|
default:
|
2004-10-14 23:19:58 +00:00
|
|
|
GST_DEBUG ("got other event");
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
|
|
|
if (!GST_BUFFER_DATA (buf)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_DEBUG ("expected non-null buffer");
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec_decoder_add_buffer (swfdec->decoder,
|
|
|
|
gst_swfdec_buffer_to_swf (buf));
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2004-10-14 23:19:58 +00:00
|
|
|
} else if (ret == SWF_CHANGE) {
|
2004-03-14 22:34:33 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
GstPadLinkReturn link_ret;
|
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);
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec_decoder_get_rate (swfdec->decoder, &swfdec->rate);
|
2004-03-14 22:34:33 +00:00
|
|
|
swfdec->interval = GST_SECOND / swfdec->rate;
|
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));
|
2004-10-14 23:19:58 +00:00
|
|
|
swfdec_decoder_get_rate (swfdec->decoder, &swfdec->frame_rate);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_caps_set_simple (caps,
|
2004-03-15 19:32:27 +00:00
|
|
|
"framerate", G_TYPE_DOUBLE, swfdec->frame_rate,
|
|
|
|
"height", G_TYPE_INT, swfdec->height,
|
|
|
|
"width", G_TYPE_INT, swfdec->width, NULL);
|
2004-03-14 22:34:33 +00:00
|
|
|
link_ret = gst_pad_try_set_caps (swfdec->videopad, caps);
|
|
|
|
if (GST_PAD_LINK_SUCCESSFUL (link_ret)) {
|
|
|
|
/* good */
|
|
|
|
} else {
|
|
|
|
GST_ELEMENT_ERROR (swfdec, CORE, NEGOTIATION, (NULL), (NULL));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
swfdec->have_format = TRUE;
|
2004-10-14 23:19:58 +00:00
|
|
|
} else if (ret == SWF_EOF) {
|
|
|
|
SwfdecBuffer *audio_buffer;
|
|
|
|
SwfdecBuffer *video_buffer;
|
|
|
|
GstBuffer *videobuf;
|
|
|
|
GstBuffer *audiobuf;
|
|
|
|
gboolean ret;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
ret = swfdec_render_iterate (swfdec->decoder);
|
|
|
|
if (!ret) {
|
|
|
|
gst_pad_push (swfdec->videopad, GST_DATA (gst_event_new (GST_EVENT_EOS)));
|
|
|
|
gst_pad_push (swfdec->audiopad, GST_DATA (gst_event_new (GST_EVENT_EOS)));
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_element_set_eos (GST_ELEMENT (swfdec));
|
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
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
event = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME,
|
|
|
|
swfdec->timestamp, GST_FORMAT_UNDEFINED);
|
|
|
|
gst_pad_push (swfdec->videopad, GST_DATA (event));
|
2003-01-17 05:27:12 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
event = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME,
|
|
|
|
swfdec->timestamp, GST_FORMAT_UNDEFINED);
|
|
|
|
gst_pad_push (swfdec->audiopad, GST_DATA (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
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
video_buffer = swfdec_render_get_image (swfdec->decoder);
|
|
|
|
videobuf = gst_buffer_new ();
|
|
|
|
GST_BUFFER_DATA (videobuf) = video_buffer->data;
|
|
|
|
GST_BUFFER_SIZE (videobuf) = video_buffer->length;
|
|
|
|
GST_BUFFER_TIMESTAMP (videobuf) = swfdec->timestamp;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
gst_pad_push (swfdec->videopad, GST_DATA (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);
|
|
|
|
audiobuf = gst_buffer_new ();
|
|
|
|
GST_BUFFER_DATA (audiobuf) = audio_buffer->data;
|
|
|
|
GST_BUFFER_SIZE (audiobuf) = audio_buffer->length;
|
|
|
|
GST_BUFFER_TIMESTAMP (audiobuf) = swfdec->timestamp;
|
|
|
|
|
|
|
|
gst_pad_push (swfdec->audiopad, GST_DATA (audiobuf));
|
|
|
|
|
|
|
|
swfdec->timestamp += swfdec->interval;
|
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);
|
|
|
|
|
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);
|
|
|
|
gst_pad_set_link_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);
|
|
|
|
gst_pad_set_event_mask_function (swfdec->videopad,
|
|
|
|
gst_swfdec_get_event_masks);
|
|
|
|
gst_pad_set_query_type_function (swfdec->videopad,
|
|
|
|
gst_swfdec_get_query_types);
|
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);
|
|
|
|
gst_pad_set_event_mask_function (swfdec->audiopad,
|
|
|
|
gst_swfdec_get_event_masks);
|
|
|
|
gst_pad_set_query_type_function (swfdec->audiopad,
|
|
|
|
gst_swfdec_get_query_types);
|
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
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_set_loop_function (GST_ELEMENT (swfdec), gst_swfdec_loop);
|
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
|
|
|
|
|
|
|
GST_FLAG_SET (GST_ELEMENT (swfdec), GST_ELEMENT_EVENT_AWARE);
|
2003-07-06 20:49:52 +00:00
|
|
|
|
|
|
|
swfdec->frame_rate = 0.;
|
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
|
|
|
|
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_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
|
|
|
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
|
|
|
|
gst_swfdec_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
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) {
|
|
|
|
*value = n_frames * swfdec->interval;
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
switch (*format) {
|
2004-10-14 23:19:58 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
*value = swfdec_render_get_frame_index (swfdec->decoder) *
|
|
|
|
swfdec->interval;
|
|
|
|
res = TRUE;
|
2004-03-15 19:32:27 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
static const GstEventMask *
|
|
|
|
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},
|
|
|
|
{0,}
|
|
|
|
};
|
|
|
|
|
|
|
|
return gst_swfdec_event_masks;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
//static const GstFormat formats[] = { GST_FORMAT_TIME, GST_FORMAT_BYTES };
|
2004-03-15 19:32:27 +00:00
|
|
|
|
|
|
|
#define MAX_SEEK_FORMATS 1 /* we can only do time seeking for now */
|
2004-10-14 23:19:58 +00:00
|
|
|
//gint i;
|
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:
|
|
|
|
{
|
2004-10-14 23:19:58 +00:00
|
|
|
int new_frame;
|
|
|
|
int ret;
|
|
|
|
int n_frames;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2004-10-14 23:19:58 +00:00
|
|
|
new_frame = event->event_data.seek.offset / swfdec->interval;
|
|
|
|
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");
|
|
|
|
event = gst_event_new (GST_EVENT_FLUSH);
|
|
|
|
gst_pad_push (swfdec->videopad, GST_DATA (event));
|
|
|
|
event = gst_event_new (GST_EVENT_FLUSH);
|
|
|
|
gst_pad_push (swfdec->audiopad, GST_DATA (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;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_event_unref (event);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_swfdec_change_state (GstElement * element)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
GstSwfdec *swfdec = GST_SWFDEC (element);
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
2002-09-15 19:43:01 +00:00
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
{
|
|
|
|
//gst_swfdec_vo_open (swfdec);
|
2003-01-17 05:27:12 +00:00
|
|
|
//swfdec_decoder_new (swfdec->decoder, swfdec->accel, swfdec->vo);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
//swfdec->decoder->is_sequence_needed = 1;
|
|
|
|
//swfdec->decoder->frame_rate_code = 0;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
//gst_swfdec_vo_destroy (swfdec);
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-16 11:07:45 +00:00
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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, ...)
|
|
|
|
{
|
|
|
|
GST_ERROR ("caught art_warn");
|
|
|
|
}
|
|
|
|
|
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)
|