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>
|
|
|
|
|
|
|
|
/* elementfactory information */
|
|
|
|
static GstElementDetails gst_swfdec_details = {
|
|
|
|
"SWF video decoder",
|
|
|
|
"Codec/Video/Decoder",
|
2002-09-18 19:02:52 +00:00
|
|
|
"LGPL",
|
2002-09-15 19:43:01 +00:00
|
|
|
"Uses libswfdec to decode Flash video streams",
|
|
|
|
VERSION,
|
|
|
|
"David Schleef <ds@schleef.org>",
|
|
|
|
"(C) 2002",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Swfdec signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
|
|
|
GST_PAD_TEMPLATE_FACTORY (video_template_factory,
|
2003-04-22 08:23:08 +00:00
|
|
|
"video_00",
|
2002-09-15 19:43:01 +00:00
|
|
|
GST_PAD_SRC,
|
2003-04-22 08:23:08 +00:00
|
|
|
GST_PAD_ALWAYS,
|
2002-09-15 19:43:01 +00:00
|
|
|
GST_CAPS_NEW (
|
2003-04-22 08:23:08 +00:00
|
|
|
"swfdec_videosrc",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-rgb",
|
2003-04-22 08:23:08 +00:00
|
|
|
"width", GST_PROPS_INT_RANGE (16, 4096),
|
|
|
|
"height", GST_PROPS_INT_RANGE (16, 4096),
|
|
|
|
"bpp", GST_PROPS_INT (24),
|
|
|
|
"depth", GST_PROPS_INT (24),
|
|
|
|
"endianness", GST_PROPS_INT (G_BIG_ENDIAN),
|
|
|
|
"red_mask", GST_PROPS_INT (0xff0000),
|
|
|
|
"green_mask", GST_PROPS_INT (0x00ff00),
|
2003-07-06 20:49:52 +00:00
|
|
|
"blue_mask", GST_PROPS_INT (0x0000ff),
|
|
|
|
"framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT)
|
2002-09-15 19:43:01 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
GST_PAD_TEMPLATE_FACTORY (audio_template_factory,
|
2003-04-22 08:23:08 +00:00
|
|
|
"audio_00",
|
2002-09-15 19:43:01 +00:00
|
|
|
GST_PAD_SRC,
|
2003-04-22 08:23:08 +00:00
|
|
|
GST_PAD_ALWAYS,
|
2002-09-15 19:43:01 +00:00
|
|
|
GST_CAPS_NEW (
|
|
|
|
"swfdec_audiosrc",
|
2003-07-06 20:49:52 +00:00
|
|
|
"audio/x-raw-int",
|
2002-09-15 19:43:01 +00:00
|
|
|
"endianness", GST_PROPS_INT(G_BYTE_ORDER),
|
|
|
|
"signed", GST_PROPS_BOOLEAN(TRUE),
|
|
|
|
"width", GST_PROPS_INT(16),
|
|
|
|
"depth", GST_PROPS_INT(16),
|
|
|
|
"rate", GST_PROPS_INT(44100),
|
2003-01-17 05:27:12 +00:00
|
|
|
"channels", GST_PROPS_INT(2)
|
2002-09-15 19:43:01 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
GST_PAD_TEMPLATE_FACTORY (sink_template_factory,
|
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"swfdec_sink",
|
|
|
|
"application/x-shockwave-flash",
|
2003-04-22 08:23:08 +00:00
|
|
|
NULL
|
2002-09-15 19:43:01 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
static void gst_swfdec_class_init (GstSwfdecClass *klass);
|
|
|
|
static void gst_swfdec_init (GstSwfdec *swfdec);
|
|
|
|
|
|
|
|
static void gst_swfdec_dispose (GObject *object);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static gboolean gst_swfdec_src_event (GstPad *pad, GstEvent *event);
|
2003-01-23 21:06:30 +00:00
|
|
|
#endif
|
2002-12-30 17:53:18 +00:00
|
|
|
static gboolean gst_swfdec_src_query (GstPad *pad, GstQueryType type,
|
2002-09-15 19:43:01 +00:00
|
|
|
GstFormat *format, gint64 *value);
|
|
|
|
|
2003-01-23 21:06:30 +00:00
|
|
|
#if 0
|
2002-09-15 19:43:01 +00:00
|
|
|
static gboolean gst_swfdec_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value);
|
|
|
|
static gboolean gst_swfdec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value);
|
|
|
|
#endif
|
|
|
|
|
2003-04-22 08:23:08 +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 = {
|
|
|
|
sizeof(GstSwfdecClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_swfdec_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstSwfdec),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_swfdec_init,
|
|
|
|
};
|
|
|
|
swfdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSwfdec", &swfdec_info, 0);
|
|
|
|
}
|
|
|
|
return swfdec_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_swfdec_class_init(GstSwfdecClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_swfdec_set_property;
|
|
|
|
gobject_class->get_property = gst_swfdec_get_property;
|
|
|
|
gobject_class->dispose = gst_swfdec_dispose;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_swfdec_change_state;
|
|
|
|
}
|
|
|
|
|
2003-04-22 08:23:08 +00:00
|
|
|
static GstCaps *gst_swfdec_videosrc_getcaps(GstPad *pad, GstCaps *caps)
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
GstSwfdec *swfdec;
|
2003-04-22 08:23:08 +00:00
|
|
|
GstCaps *c;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2003-04-22 08:23:08 +00:00
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2003-04-22 08:23:08 +00:00
|
|
|
c = GST_CAPS_NEW (
|
|
|
|
"swfdec_videosrc",
|
2003-07-06 20:49:52 +00:00
|
|
|
"video/x-raw-rgb",
|
2003-04-22 08:23:08 +00:00
|
|
|
"width", GST_PROPS_INT_RANGE (16, 4096),
|
|
|
|
"height", GST_PROPS_INT_RANGE (16, 4096),
|
|
|
|
"bpp", GST_PROPS_INT (24),
|
|
|
|
"depth", GST_PROPS_INT (24),
|
|
|
|
"endianness", GST_PROPS_INT (G_BIG_ENDIAN),
|
|
|
|
"red_mask", GST_PROPS_INT (0xff0000),
|
|
|
|
"green_mask", GST_PROPS_INT (0x00ff00),
|
2003-07-06 20:49:52 +00:00
|
|
|
"blue_mask", GST_PROPS_INT (0x0000ff),
|
|
|
|
"framerate", GST_PROPS_FLOAT (swfdec->frame_rate)
|
2003-04-22 08:23:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if(swfdec->height){
|
|
|
|
gst_caps_set(c,"height",GST_PROPS_INT(swfdec->height));
|
|
|
|
gst_caps_set(c,"width",GST_PROPS_INT(swfdec->width));
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2003-04-22 08:23:08 +00:00
|
|
|
return c;
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_swfdec_loop(GstElement *element)
|
|
|
|
{
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
GstBuffer *buf = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
g_return_if_fail(element != NULL);
|
|
|
|
g_return_if_fail(GST_IS_SWFDEC(element));
|
|
|
|
|
|
|
|
swfdec = GST_SWFDEC(element);
|
|
|
|
|
|
|
|
if(!swfdec->videopad){
|
|
|
|
}
|
|
|
|
|
2003-01-17 05:27:12 +00:00
|
|
|
ret = swfdec_decoder_parse(swfdec->state);
|
2002-09-15 19:43:01 +00:00
|
|
|
if(ret==SWF_NEEDBITS){
|
2003-10-08 16:08:19 +00:00
|
|
|
buf = GST_BUFFER (gst_pad_pull(swfdec->sinkpad));
|
2002-09-15 19:43:01 +00:00
|
|
|
if(GST_IS_EVENT(buf)){
|
|
|
|
switch (GST_EVENT_TYPE (buf)) {
|
|
|
|
case GST_EVENT_EOS:
|
2003-10-16 21:36:14 +00:00
|
|
|
GST_DEBUG("got eos");
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-10-16 21:36:14 +00:00
|
|
|
GST_DEBUG("got event");
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
if(!GST_BUFFER_DATA(buf)){
|
2003-10-16 21:36:14 +00:00
|
|
|
GST_DEBUG("expected non-null buffer");
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
2003-01-17 05:27:12 +00:00
|
|
|
ret = swfdec_decoder_addbits(swfdec->state,
|
|
|
|
GST_BUFFER_DATA(buf), GST_BUFFER_SIZE(buf));
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret==SWF_CHANGE){
|
2003-01-17 05:27:12 +00:00
|
|
|
swfdec_decoder_get_image_size(swfdec->state,
|
|
|
|
&swfdec->width, &swfdec->height);
|
|
|
|
swfdec_decoder_get_rate(swfdec->state, &swfdec->rate);
|
|
|
|
swfdec->interval = GST_SECOND / swfdec->rate;
|
2003-04-22 08:23:08 +00:00
|
|
|
|
|
|
|
gst_caps_debug(gst_swfdec_videosrc_getcaps(swfdec->videopad,NULL),"ack");
|
2002-09-15 19:43:01 +00:00
|
|
|
gst_pad_try_set_caps(swfdec->videopad,
|
2003-04-22 08:23:08 +00:00
|
|
|
gst_swfdec_videosrc_getcaps(swfdec->videopad,NULL));
|
2002-09-15 19:43:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ret==SWF_IMAGE){
|
|
|
|
GstBuffer *newbuf = NULL;
|
2003-01-17 05:27:12 +00:00
|
|
|
unsigned char *data;
|
|
|
|
int len;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
/* video stuff */
|
2003-01-17 05:27:12 +00:00
|
|
|
newbuf = gst_buffer_new();
|
|
|
|
GST_BUFFER_SIZE(newbuf) = swfdec->width * swfdec->height * 3;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2003-01-17 05:27:12 +00:00
|
|
|
swfdec_decoder_get_image(swfdec->state, &data);
|
|
|
|
GST_BUFFER_DATA(newbuf) = data;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
swfdec->timestamp += swfdec->interval;
|
|
|
|
GST_BUFFER_TIMESTAMP(newbuf) = swfdec->timestamp;
|
|
|
|
|
2003-10-08 16:08:19 +00:00
|
|
|
gst_pad_push(swfdec->videopad, GST_DATA (newbuf));
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
/* audio stuff */
|
|
|
|
|
2003-01-17 05:27:12 +00:00
|
|
|
data = swfdec_decoder_get_sound_chunk(swfdec->state, &len);
|
|
|
|
while(data){
|
|
|
|
newbuf = gst_buffer_new();
|
|
|
|
|
|
|
|
GST_BUFFER_SIZE(newbuf) = len;
|
|
|
|
GST_BUFFER_DATA(newbuf) = data;
|
|
|
|
GST_BUFFER_TIMESTAMP(newbuf) = swfdec->timestamp;
|
|
|
|
|
2003-10-08 16:08:19 +00:00
|
|
|
gst_pad_push(swfdec->audiopad, GST_DATA (newbuf));
|
2003-01-17 05:27:12 +00:00
|
|
|
|
|
|
|
data = swfdec_decoder_get_sound_chunk(swfdec->state, &len);
|
|
|
|
}
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(ret==SWF_EOF){
|
2003-10-08 16:08:19 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_swfdec_init (GstSwfdec *swfdec)
|
|
|
|
{
|
|
|
|
/* create the sink and src pads */
|
|
|
|
swfdec->sinkpad = gst_pad_new_from_template (
|
|
|
|
GST_PAD_TEMPLATE_GET (sink_template_factory), "sink");
|
|
|
|
gst_element_add_pad (GST_ELEMENT (swfdec), swfdec->sinkpad);
|
|
|
|
|
2003-04-22 08:23:08 +00:00
|
|
|
swfdec->videopad = gst_pad_new_from_template(
|
|
|
|
GST_PAD_TEMPLATE_GET(video_template_factory),
|
|
|
|
"video_00");
|
|
|
|
gst_pad_set_query_function (swfdec->videopad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_swfdec_src_query));
|
|
|
|
gst_pad_set_getcaps_function (swfdec->videopad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_swfdec_videosrc_getcaps));
|
|
|
|
gst_element_add_pad(GST_ELEMENT(swfdec), swfdec->videopad);
|
|
|
|
|
|
|
|
swfdec->audiopad = gst_pad_new_from_template(
|
|
|
|
GST_PAD_TEMPLATE_GET(audio_template_factory),
|
|
|
|
"audio_00");
|
|
|
|
gst_pad_set_query_function (swfdec->audiopad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_swfdec_src_query));
|
|
|
|
|
|
|
|
gst_element_add_pad(GST_ELEMENT(swfdec), swfdec->audiopad);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
gst_element_set_loop_function(GST_ELEMENT(swfdec), gst_swfdec_loop);
|
|
|
|
|
|
|
|
/* initialize the swfdec decoder state */
|
2003-01-17 05:27:12 +00:00
|
|
|
swfdec->state = swfdec_decoder_new();
|
2002-12-05 00:26:19 +00:00
|
|
|
g_return_if_fail(swfdec->state != NULL);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2003-01-17 05:27:12 +00:00
|
|
|
swfdec_decoder_set_colorspace(swfdec->state, 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
|
|
|
|
gst_swfdec_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
//GstSwfdec *swfdec = GST_SWFDEC (object);
|
|
|
|
|
|
|
|
/* FIXME */
|
2003-01-17 05:27:12 +00:00
|
|
|
//swfdec_decoder_free(swfdec->state);
|
2002-09-15 19:43:01 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static gboolean
|
|
|
|
gst_swfdec_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static gboolean
|
|
|
|
gst_swfdec_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * 6 * (swfdec->width * swfdec->height >> 2) *
|
|
|
|
video_rates[swfdec->decoder->frame_rate_code] / GST_SECOND;
|
|
|
|
break;
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-09-15 19:43:01 +00:00
|
|
|
*dest_value = src_value * video_rates[swfdec->decoder->frame_rate_code] / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-09-15 19:43:01 +00:00
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
if (video_rates[swfdec->decoder->frame_rate_code] != 0.0) {
|
|
|
|
*dest_value = src_value * GST_SECOND /
|
|
|
|
video_rates[swfdec->decoder->frame_rate_code];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * 6 * (swfdec->width * swfdec->height >> 2);
|
|
|
|
break;
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-09-15 19:43:01 +00:00
|
|
|
*dest_value = src_value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static gboolean
|
2002-12-30 17:53:18 +00:00
|
|
|
gst_swfdec_src_query (GstPad *pad, GstQueryType type,
|
2002-09-15 19:43:01 +00:00
|
|
|
GstFormat *format, gint64 *value)
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
2003-01-23 21:06:30 +00:00
|
|
|
int n_frames;
|
|
|
|
int ret;
|
2002-09-15 19:43:01 +00:00
|
|
|
|
2003-01-23 21:06:30 +00:00
|
|
|
res = FALSE;
|
|
|
|
ret = swfdec_decoder_get_n_frames(swfdec->state, &n_frames);
|
|
|
|
if(ret == SWF_OK){
|
|
|
|
*value = n_frames * swfdec->interval;
|
|
|
|
res = TRUE;
|
2002-09-15 19:43:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-09-15 19:43:01 +00:00
|
|
|
{
|
|
|
|
switch (*format) {
|
|
|
|
default:
|
2003-01-23 21:06:30 +00:00
|
|
|
res = FALSE;
|
2002-09-15 19:43:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static gboolean
|
|
|
|
gst_swfdec_src_event (GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
static const GstFormat formats[] = { GST_FORMAT_TIME, GST_FORMAT_BYTES };
|
|
|
|
#define MAX_SEEK_FORMATS 1 /* we can only do time seeking for now */
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
swfdec = GST_SWFDEC (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
/* the all-formats seek logic */
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
gint64 src_offset;
|
|
|
|
gboolean flush;
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
|
|
|
|
/* first bring the src_format to TIME */
|
|
|
|
if (!gst_pad_convert (pad,
|
|
|
|
GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event),
|
|
|
|
&format, &src_offset))
|
|
|
|
{
|
|
|
|
/* didn't work, probably unsupported seek format then */
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shave off the flush flag, we'll need it later */
|
|
|
|
flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
|
|
|
|
|
|
|
|
/* assume the worst */
|
|
|
|
res = FALSE;
|
|
|
|
|
|
|
|
/* while we did not exhaust our seek formats without result */
|
|
|
|
for (i = 0; i < MAX_SEEK_FORMATS && !res; i++) {
|
|
|
|
gint64 desired_offset;
|
|
|
|
|
|
|
|
format = formats[i];
|
|
|
|
|
|
|
|
/* try to convert requested format to one we can seek with on the sinkpad */
|
|
|
|
if (gst_pad_convert (swfdec->sinkpad, GST_FORMAT_TIME, src_offset, &format, &desired_offset))
|
|
|
|
{
|
|
|
|
GstEvent *seek_event;
|
|
|
|
|
|
|
|
/* conversion succeeded, create the seek */
|
|
|
|
seek_event = gst_event_new_seek (formats[i] | GST_SEEK_METHOD_SET | flush, desired_offset);
|
|
|
|
/* do the seekk */
|
|
|
|
if (gst_pad_send_event (GST_PAD_PEER (swfdec->sinkpad), seek_event)) {
|
|
|
|
/* seek worked, we're done, loop will exit */
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* at this point, either the seek worked or res == FALSE */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_event_unref (event);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_swfdec_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstSwfdec *swfdec = GST_SWFDEC (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
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->pool = NULL;
|
|
|
|
swfdec->closed = FALSE;
|
|
|
|
|
|
|
|
/* reset the initial video state */
|
|
|
|
swfdec->format = -1;
|
|
|
|
swfdec->width = -1;
|
|
|
|
swfdec->height = -1;
|
|
|
|
swfdec->first = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
/* try to get a bufferpool */
|
|
|
|
#if 0
|
|
|
|
swfdec->pool = gst_pad_get_bufferpool (swfdec->videopad);
|
|
|
|
if (swfdec->pool)
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_INFO ( "got pool %p", swfdec->pool);
|
2002-09-15 19:43:01 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
/* need to clear things we get from other plugins, since we could be reconnected */
|
|
|
|
if (swfdec->pool) {
|
|
|
|
gst_buffer_pool_unref (swfdec->pool);
|
|
|
|
swfdec->pool = NULL;
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
/*swf_close (swfdec->decoder); */
|
|
|
|
swfdec->closed = TRUE;
|
|
|
|
}
|
|
|
|
//gst_swfdec_vo_destroy (swfdec);
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_swfdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstSwfdec *src;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_SWFDEC (object));
|
|
|
|
src = GST_SWFDEC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_swfdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstSwfdec *swfdec;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_SWFDEC (object));
|
|
|
|
swfdec = GST_SWFDEC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module, GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
|
|
|
|
/* create an elementfactory for the swfdec element */
|
|
|
|
factory = gst_element_factory_new("swfdec",GST_TYPE_SWFDEC,
|
|
|
|
&gst_swfdec_details);
|
|
|
|
g_return_val_if_fail(factory != NULL, FALSE);
|
|
|
|
gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_PRIMARY);
|
|
|
|
|
|
|
|
gst_element_factory_add_pad_template (factory,
|
|
|
|
GST_PAD_TEMPLATE_GET (video_template_factory));
|
|
|
|
gst_element_factory_add_pad_template (factory,
|
|
|
|
GST_PAD_TEMPLATE_GET (audio_template_factory));
|
|
|
|
gst_element_factory_add_pad_template (factory,
|
|
|
|
GST_PAD_TEMPLATE_GET (sink_template_factory));
|
|
|
|
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"swfdec",
|
|
|
|
plugin_init
|
|
|
|
};
|