2002-01-19 14:50:50 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@temple-baptist.com>
|
2001-12-22 23:27:31 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "flx_fmt.h"
|
|
|
|
#include "gstflxdec.h"
|
|
|
|
|
2002-06-16 21:56:49 +00:00
|
|
|
#define JIFFIE (GST_SECOND/70)
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
static GstCaps* flxdec_type_find(GstBuffer *buf, gpointer private);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* flx element information */
|
|
|
|
static GstElementDetails flxdec_details = {
|
|
|
|
"FLX Decoder",
|
2002-04-20 21:42:51 +00:00
|
|
|
"Codec/Audio/Decoder",
|
2002-09-18 19:02:51 +00:00
|
|
|
"LGPL",
|
2001-12-22 23:27:31 +00:00
|
|
|
"FLX decoder",
|
|
|
|
VERSION,
|
|
|
|
"Sepp Wijnands <mrrazz@garbage-coderz.net>"
|
|
|
|
"(C) 2001",
|
|
|
|
};
|
|
|
|
|
|
|
|
static GstTypeDefinition flxdec_definition = {
|
|
|
|
"flxdec_video/fli",
|
|
|
|
"video/fli",
|
|
|
|
".flc .fli",
|
2002-04-11 20:42:25 +00:00
|
|
|
flxdec_type_find,
|
2001-12-22 23:27:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Flx signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0
|
|
|
|
};
|
|
|
|
|
|
|
|
/* input */
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (sink_factory,
|
2001-12-22 23:27:31 +00:00
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"flxdec_sink",
|
|
|
|
"video/fli",
|
|
|
|
NULL
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
/* output */
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (src_video_factory,
|
2001-12-22 23:27:31 +00:00
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"src_video",
|
|
|
|
"video/raw",
|
|
|
|
"format", GST_PROPS_FOURCC (GST_MAKE_FOURCC ('R', 'G', 'B', ' ')),
|
|
|
|
"bpp", GST_PROPS_INT (32),
|
|
|
|
"depth", GST_PROPS_INT (32),
|
|
|
|
"endianness", GST_PROPS_INT (G_LITTLE_ENDIAN),
|
|
|
|
"red_mask", GST_PROPS_INT (0x00ff0000),
|
|
|
|
"green_mask", GST_PROPS_INT (0x0000ff00),
|
|
|
|
"blue_mask", GST_PROPS_INT (0x000000ff),
|
|
|
|
"width", GST_PROPS_INT_RANGE(320, 1280),
|
|
|
|
"height", GST_PROPS_INT_RANGE(200, 1024)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
static void gst_flxdec_class_init (GstFlxDecClass *klass);
|
|
|
|
static void gst_flxdec_init (GstFlxDec *flxdec);
|
|
|
|
|
|
|
|
static void gst_flxdec_loop (GstElement *element);
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_flxdec_change_state (GstElement *element);
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
static void gst_flxdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_flxdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
|
|
|
|
|
|
|
|
|
2002-01-18 18:41:58 +00:00
|
|
|
static void flx_decode_color (GstFlxDec *, guchar *, guchar *, gint);
|
|
|
|
static void flx_decode_brun (GstFlxDec *, guchar *, guchar *);
|
|
|
|
static void flx_decode_delta_fli (GstFlxDec *, guchar *, guchar *);
|
|
|
|
static void flx_decode_delta_flc (GstFlxDec *, guchar *, guchar *);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
#define rndalign(off) ((off) + ((off) % 2))
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
static GstCaps*
|
2002-04-11 20:42:25 +00:00
|
|
|
flxdec_type_find (GstBuffer *buf, gpointer private)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
guchar *data = GST_BUFFER_DATA(buf);
|
|
|
|
GstCaps *new;
|
|
|
|
|
2003-06-06 20:24:13 +00:00
|
|
|
if(GST_BUFFER_SIZE(buf) < 134){
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* check magic */
|
2001-12-22 23:27:31 +00:00
|
|
|
if ((data[4] == 0x11 || data[4] == 0x12
|
|
|
|
|| data[4] == 0x30 || data[4] == 0x44) && data[5] == 0xaf) {
|
2002-01-13 22:27:25 +00:00
|
|
|
/* check the frame type of the first frame */
|
2001-12-22 23:27:31 +00:00
|
|
|
if ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1) {
|
|
|
|
g_print("GstFlxDec: found supported flx format\n");
|
2002-04-11 20:42:25 +00:00
|
|
|
new = gst_caps_new("flxdec_type_find","video/fli", NULL);
|
2001-12-22 23:27:31 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_flxdec_get_type(void)
|
|
|
|
{
|
|
|
|
static GType flxdec_type = 0;
|
|
|
|
|
|
|
|
if (!flxdec_type) {
|
|
|
|
static const GTypeInfo flxdec_info = {
|
|
|
|
sizeof(GstFlxDecClass), NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc)gst_flxdec_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof(GstFlxDec),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc)gst_flxdec_init,
|
|
|
|
};
|
|
|
|
flxdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstFlxDec", &flxdec_info, 0);
|
|
|
|
}
|
|
|
|
return flxdec_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_flxdec_class_init (GstFlxDecClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
|
|
|
gstelement_class = (GstElementClass*)klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
|
|
|
|
2002-02-02 13:56:02 +00:00
|
|
|
gobject_class->set_property = gst_flxdec_set_property;
|
|
|
|
gobject_class->get_property = gst_flxdec_get_property;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
gstelement_class->change_state = gst_flxdec_change_state;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_flxdec_init(GstFlxDec *flxdec)
|
|
|
|
{
|
|
|
|
flxdec->sinkpad = gst_pad_new_from_template (
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_GET (sink_factory), "sink");
|
2001-12-22 23:27:31 +00:00
|
|
|
gst_element_add_pad(GST_ELEMENT(flxdec),flxdec->sinkpad);
|
|
|
|
gst_element_set_loop_function(GST_ELEMENT(flxdec),gst_flxdec_loop);
|
|
|
|
|
|
|
|
flxdec->srcpad = gst_pad_new_from_template (
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_GET (src_video_factory), "src");
|
2001-12-22 23:27:31 +00:00
|
|
|
gst_element_add_pad(GST_ELEMENT(flxdec),flxdec->srcpad);
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
flxdec->bs = NULL;
|
|
|
|
flxdec->frame = NULL;
|
|
|
|
flxdec->delta = NULL;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
flx_decode_chunks (GstFlxDec *flxdec , gulong count, gchar *data, gchar *dest)
|
|
|
|
{
|
|
|
|
FlxFrameChunk *hdr;
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
hdr = (FlxFrameChunk *) data;
|
|
|
|
data += FlxFrameChunkSize;
|
|
|
|
|
|
|
|
switch(hdr->id)
|
|
|
|
{
|
|
|
|
case FLX_COLOR64:
|
2002-01-18 18:41:58 +00:00
|
|
|
flx_decode_color(flxdec, data, dest, 2);
|
|
|
|
data += rndalign(hdr->size) - FlxFrameChunkSize;
|
|
|
|
break;
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
case FLX_COLOR256:
|
2002-01-18 18:41:58 +00:00
|
|
|
flx_decode_color(flxdec, data, dest, 0);
|
2001-12-22 23:27:31 +00:00
|
|
|
data += rndalign(hdr->size) - FlxFrameChunkSize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLX_BRUN:
|
|
|
|
flx_decode_brun(flxdec, data, dest);
|
|
|
|
data += rndalign(hdr->size) - FlxFrameChunkSize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLX_LC:
|
|
|
|
flx_decode_delta_fli(flxdec, data, dest);
|
|
|
|
data += rndalign(hdr->size) - FlxFrameChunkSize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLX_SS2:
|
|
|
|
flx_decode_delta_flc(flxdec, data, dest);
|
|
|
|
data += rndalign(hdr->size) - FlxFrameChunkSize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLX_BLACK:
|
|
|
|
memset(dest, 0, flxdec->size);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLX_MINI:
|
|
|
|
data += rndalign(hdr->size) - FlxFrameChunkSize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_print("GstFlxDec: Unimplented chunk type: 0x%02x size: %d\n",
|
|
|
|
hdr->id, hdr->size);
|
|
|
|
g_print("GstFlxDec: Skipping...\n");
|
|
|
|
data += rndalign(hdr->size) - FlxFrameChunkSize;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-01-18 18:41:58 +00:00
|
|
|
flx_decode_color(GstFlxDec *flxdec, guchar *data, guchar *dest, gint scale)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
guint packs, count, indx;
|
|
|
|
|
|
|
|
g_return_if_fail(flxdec != NULL);
|
|
|
|
|
|
|
|
packs = (data[0] + (data[1] << 8));
|
|
|
|
|
|
|
|
data += 2;
|
|
|
|
indx = 0;
|
|
|
|
|
|
|
|
g_print("GstFlxDec: cmap packs: %d\n", packs);
|
|
|
|
while (packs--) {
|
|
|
|
/* color map index + skip count */
|
|
|
|
indx += *data++;
|
|
|
|
|
|
|
|
/* number of rgb triplets */
|
|
|
|
count = *data++ & 0xff;
|
|
|
|
if (count == 0)
|
|
|
|
count = 256;
|
|
|
|
|
|
|
|
g_print("GstFlxDec: cmap count: %d (indx: %d)\n", count, indx);
|
2002-01-18 18:41:58 +00:00
|
|
|
flx_set_palette_vector(flxdec->converter, indx, count, data, scale);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
data += (count * 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
flx_decode_brun(GstFlxDec *flxdec, guchar *data, guchar *dest)
|
|
|
|
{
|
|
|
|
gulong count, lines, row;
|
|
|
|
guchar x;
|
|
|
|
|
|
|
|
g_return_if_fail(flxdec != NULL);
|
|
|
|
|
|
|
|
lines = flxdec->hdr.height;
|
|
|
|
while(lines--) {
|
|
|
|
/* packet count.
|
|
|
|
* should not be used anymore, since the flc format can
|
|
|
|
* contain more then 255 RLE packets. we use the frame
|
|
|
|
* width instead.
|
|
|
|
*/
|
|
|
|
data++;
|
|
|
|
|
|
|
|
row = flxdec->hdr.width;
|
|
|
|
while(row) {
|
|
|
|
count = *data++;
|
|
|
|
|
|
|
|
if (count > 0x7f) {
|
|
|
|
/* literal run */
|
|
|
|
count = 0x100 - count;
|
|
|
|
row -= count;
|
|
|
|
|
|
|
|
while(count--)
|
|
|
|
*dest++ = *data++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* replicate run */
|
|
|
|
row -= count;
|
|
|
|
x = *data++;
|
|
|
|
|
|
|
|
while(count--)
|
|
|
|
*dest++ = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
flx_decode_delta_fli(GstFlxDec *flxdec, guchar *data, guchar *dest)
|
|
|
|
{
|
|
|
|
gulong count, packets, lines, start_line, start_l;
|
|
|
|
guchar *start_p, x;
|
|
|
|
|
|
|
|
g_return_if_fail(flxdec != NULL);
|
|
|
|
g_return_if_fail(flxdec->delta != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
/* use last frame for delta */
|
|
|
|
memcpy(dest, GST_BUFFER_DATA(flxdec->delta),
|
|
|
|
GST_BUFFER_SIZE(flxdec->delta));
|
|
|
|
|
|
|
|
start_line = (data[0] + (data[1] << 8));
|
|
|
|
lines = (data[2] + (data[3] << 8));
|
|
|
|
data += 4;
|
|
|
|
|
|
|
|
/* start position of delta */
|
|
|
|
dest += (flxdec->hdr.width * start_line);
|
|
|
|
start_p = dest;
|
|
|
|
start_l = lines;
|
|
|
|
|
|
|
|
while(lines--) {
|
|
|
|
/* packet count */
|
|
|
|
packets = *data++;
|
|
|
|
|
|
|
|
while(packets--) {
|
|
|
|
/* skip count */
|
|
|
|
dest += *data++;
|
|
|
|
|
|
|
|
/* RLE count */
|
|
|
|
count = *data++;
|
|
|
|
|
|
|
|
if (count > 0x7f) {
|
|
|
|
/* literal run */
|
|
|
|
count = 0x100 - count;
|
|
|
|
x = *data++;
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
*dest++ = x;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* replicate run */
|
|
|
|
while (count--)
|
|
|
|
*dest++ = *data++;
|
|
|
|
}
|
|
|
|
}
|
2002-01-18 19:41:04 +00:00
|
|
|
start_p += flxdec->hdr.width;
|
|
|
|
dest = start_p;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
flx_decode_delta_flc(GstFlxDec *flxdec, guchar *data, guchar *dest)
|
|
|
|
{
|
|
|
|
gulong count, lines, start_l, opcode;
|
|
|
|
guchar *start_p;
|
|
|
|
|
|
|
|
g_return_if_fail(flxdec != NULL);
|
|
|
|
g_return_if_fail(flxdec->delta != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
/* use last frame for delta */
|
|
|
|
memcpy(dest, GST_BUFFER_DATA(flxdec->delta),
|
|
|
|
GST_BUFFER_SIZE(flxdec->delta));
|
|
|
|
|
|
|
|
lines = (data[0] + (data[1] << 8));
|
|
|
|
data += 2;
|
|
|
|
|
|
|
|
start_p = dest;
|
|
|
|
start_l = lines;
|
|
|
|
|
2002-01-18 19:41:04 +00:00
|
|
|
while (lines) {
|
2001-12-22 23:27:31 +00:00
|
|
|
dest = start_p + (flxdec->hdr.width * (start_l - lines));
|
|
|
|
|
|
|
|
/* process opcode(s) */
|
|
|
|
while ((opcode = (data[0] + (data[1] << 8))) & 0xc000) {
|
|
|
|
data += 2;
|
|
|
|
if ((opcode & 0xc000) == 0xc000) {
|
|
|
|
/* skip count */
|
|
|
|
start_l += (0x10000 - opcode);
|
|
|
|
dest += flxdec->hdr.width * (0x10000 - opcode);
|
|
|
|
} else {
|
|
|
|
/* last pixel */
|
|
|
|
dest += flxdec->hdr.width;
|
|
|
|
*dest++ = (opcode & 0xff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data += 2;
|
|
|
|
|
|
|
|
/* last opcode is the packet count */
|
|
|
|
while(opcode--) {
|
|
|
|
/* skip count */
|
|
|
|
dest += *data++;
|
|
|
|
|
|
|
|
/* RLE count */
|
|
|
|
count = *data++;
|
|
|
|
|
|
|
|
if (count > 0x7f) {
|
|
|
|
/* replicate word run */
|
|
|
|
count = 0x100 - count;
|
|
|
|
while (count--) {
|
|
|
|
*dest++ = data[0];
|
|
|
|
*dest++ = data[1];
|
|
|
|
}
|
|
|
|
data += 2;
|
|
|
|
} else {
|
|
|
|
/* literal word run */
|
|
|
|
while (count--) {
|
|
|
|
*dest++ = *data++;
|
|
|
|
*dest++ = *data++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-01-18 19:41:04 +00:00
|
|
|
lines--;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstBuffer*
|
|
|
|
flx_get_data(GstFlxDec *flxdec, gulong size)
|
|
|
|
{
|
|
|
|
GstBuffer *retbuf;
|
2002-05-15 19:08:49 +00:00
|
|
|
guint32 got_bytes;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (flxdec != NULL, NULL);
|
|
|
|
|
2002-05-15 19:08:49 +00:00
|
|
|
got_bytes = gst_bytestream_read (flxdec->bs, &retbuf, size);
|
|
|
|
if (got_bytes < size) {
|
2002-01-13 22:27:25 +00:00
|
|
|
GstEvent *event;
|
|
|
|
guint32 remaining;
|
|
|
|
|
|
|
|
gst_bytestream_get_status (flxdec->bs, &remaining, &event);
|
|
|
|
gst_pad_event_default (flxdec->sinkpad, event);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return retbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_flxdec_loop (GstElement *element)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstBuffer *databuf;
|
|
|
|
guchar *data, *chunk;
|
|
|
|
|
|
|
|
GstFlxDec *flxdec;
|
|
|
|
FlxHeader *flxh;
|
|
|
|
FlxFrameChunk *flxfh;
|
|
|
|
|
|
|
|
g_return_if_fail (element != NULL);
|
|
|
|
g_return_if_fail (GST_IS_FLXDEC(element));
|
|
|
|
|
2002-03-24 22:07:03 +00:00
|
|
|
GST_DEBUG (0, "entering loop function");
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
flxdec = GST_FLXDEC(element);
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
if (flxdec->state == GST_FLXDEC_READ_HEADER) {
|
|
|
|
databuf = flx_get_data(flxdec, FlxHeaderSize);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-19 18:46:23 +00:00
|
|
|
if (!databuf) {
|
|
|
|
g_print ("empty buffer\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
data = GST_BUFFER_DATA(databuf);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
memcpy((char *) &flxdec->hdr, data, sizeof(FlxHeader));
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_buffer_unref (databuf);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
flxh = &flxdec->hdr;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* check header */
|
|
|
|
if (flxh->type != FLX_MAGICHDR_FLI &&
|
2001-12-22 23:27:31 +00:00
|
|
|
flxh->type != FLX_MAGICHDR_FLC &&
|
2002-01-19 18:46:23 +00:00
|
|
|
flxh->type != FLX_MAGICHDR_FLX) {
|
|
|
|
gst_element_error (element, "not a flx file (type %d)\n", flxh->type);
|
2001-12-22 23:27:31 +00:00
|
|
|
return;
|
2002-01-19 18:46:23 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
g_print("GstFlxDec: size : %d\n", flxh->size);
|
|
|
|
g_print("GstFlxDec: frames : %d\n", flxh->frames);
|
|
|
|
g_print("GstFlxDec: width : %d\n", flxh->width);
|
|
|
|
g_print("GstFlxDec: height : %d\n", flxh->height);
|
|
|
|
g_print("GstFlxDec: depth : %d\n", flxh->depth);
|
|
|
|
g_print("GstFlxDec: speed : %d\n", flxh->speed);
|
|
|
|
|
|
|
|
flxdec->next_time = 0;
|
|
|
|
|
|
|
|
if (flxh->type == FLX_MAGICHDR_FLI) {
|
|
|
|
flxdec->frame_time = JIFFIE * flxh->speed;
|
|
|
|
}
|
|
|
|
else {
|
2003-01-12 21:28:38 +00:00
|
|
|
flxdec->frame_time = flxh->speed * GST_MSECOND;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_pad_try_set_caps (flxdec->srcpad,
|
2001-12-22 23:27:31 +00:00
|
|
|
gst_caps_new (
|
|
|
|
"src_video",
|
|
|
|
"video/raw",
|
|
|
|
gst_props_new (
|
|
|
|
"format", GST_PROPS_FOURCC (GST_MAKE_FOURCC ('R', 'G', 'B', ' ')),
|
|
|
|
"bpp", GST_PROPS_INT (32),
|
|
|
|
"depth", GST_PROPS_INT (32),
|
|
|
|
"endianness", GST_PROPS_INT (G_LITTLE_ENDIAN),
|
|
|
|
"red_mask", GST_PROPS_INT (0x00ff0000),
|
|
|
|
"green_mask", GST_PROPS_INT (0x0000ff00),
|
|
|
|
"blue_mask", GST_PROPS_INT (0x000000ff),
|
|
|
|
"width", GST_PROPS_INT (flxh->width),
|
|
|
|
"height", GST_PROPS_INT (flxh->height),
|
|
|
|
NULL)));
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
if (flxh->depth <= 8)
|
|
|
|
flxdec->converter = flx_colorspace_converter_new(flxh->width, flxh->height);
|
|
|
|
|
|
|
|
if (flxh->type == FLX_MAGICHDR_FLC ||
|
|
|
|
flxh->type == FLX_MAGICHDR_FLX) {
|
|
|
|
g_print("GstFlxDec: (FLC) aspect_dx : %d\n", flxh->aspect_dx);
|
|
|
|
g_print("GstFlxDec: (FLC) aspect_dy : %d\n", flxh->aspect_dy);
|
|
|
|
g_print("GstFlxDec: (FLC) oframe1 : 0x%08x\n", flxh->oframe1);
|
|
|
|
g_print("GstFlxDec: (FLC) oframe2 : 0x%08x\n", flxh->oframe2);
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
flxdec->size = (flxh->width * flxh->height);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* create delta and output frame */
|
|
|
|
flxdec->frame = gst_buffer_new();
|
|
|
|
flxdec->delta = gst_buffer_new();
|
|
|
|
GST_BUFFER_DATA(flxdec->frame) = g_malloc(flxdec->size);
|
|
|
|
GST_BUFFER_SIZE(flxdec->frame) = flxdec->size;
|
|
|
|
GST_BUFFER_DATA(flxdec->delta) = g_malloc(flxdec->size);
|
|
|
|
GST_BUFFER_SIZE(flxdec->delta) = flxdec->size;
|
|
|
|
|
|
|
|
flxdec->state = GST_FLXDEC_PLAYING;
|
|
|
|
}
|
|
|
|
else if (flxdec->state == GST_FLXDEC_PLAYING) {
|
2002-01-19 18:26:20 +00:00
|
|
|
GstBuffer *out;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
databuf = flx_get_data(flxdec, FlxFrameChunkSize);
|
2002-01-19 18:26:20 +00:00
|
|
|
if (!databuf)
|
|
|
|
return;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
flxfh = (FlxFrameChunk *) GST_BUFFER_DATA(databuf);
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
switch(flxfh->id) {
|
2001-12-22 23:27:31 +00:00
|
|
|
case FLX_FRAME_TYPE:
|
|
|
|
buf = flx_get_data(flxdec, flxfh->size-FlxFrameChunkSize);
|
|
|
|
|
|
|
|
chunk = GST_BUFFER_DATA(buf);
|
|
|
|
|
|
|
|
if (((FlxFrameType *)chunk)->chunks == 0)
|
|
|
|
break;
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* create 32 bits output frame */
|
2002-01-19 18:26:20 +00:00
|
|
|
out = gst_buffer_new();
|
|
|
|
GST_BUFFER_DATA(out) = g_malloc(flxdec->size * 4);
|
|
|
|
GST_BUFFER_SIZE(out) = flxdec->size * 4;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* decode chunks */
|
2001-12-22 23:27:31 +00:00
|
|
|
flx_decode_chunks(flxdec,
|
|
|
|
((FlxFrameType *)chunk)->chunks,
|
|
|
|
GST_BUFFER_DATA(buf) + FlxFrameTypeSize,
|
|
|
|
GST_BUFFER_DATA(flxdec->frame));
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* destroy input buffer*/
|
2001-12-22 23:27:31 +00:00
|
|
|
gst_buffer_unref(buf);
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* save copy of the current frame for possible delta. */
|
2001-12-22 23:27:31 +00:00
|
|
|
memcpy(GST_BUFFER_DATA(flxdec->delta),
|
|
|
|
GST_BUFFER_DATA(flxdec->frame),
|
|
|
|
GST_BUFFER_SIZE(flxdec->delta));
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* convert current frame. */
|
2001-12-22 23:27:31 +00:00
|
|
|
flx_colorspace_convert(flxdec->converter,
|
|
|
|
GST_BUFFER_DATA(flxdec->frame),
|
2002-01-19 18:26:20 +00:00
|
|
|
GST_BUFFER_DATA(out));
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-19 18:26:20 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (out) = flxdec->next_time;
|
2002-01-13 22:27:25 +00:00
|
|
|
flxdec->next_time += flxdec->frame_time;
|
|
|
|
|
2002-01-19 18:26:20 +00:00
|
|
|
gst_pad_push(flxdec->srcpad, out);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* destroy header buffer */
|
2001-12-22 23:27:31 +00:00
|
|
|
gst_buffer_unref(databuf);
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_flxdec_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
GstFlxDec *flxdec;
|
|
|
|
|
|
|
|
flxdec = GST_FLXDEC(element);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2002-01-19 18:46:23 +00:00
|
|
|
flxdec->bs = gst_bytestream_new (flxdec->sinkpad);
|
2002-01-13 22:27:25 +00:00
|
|
|
flxdec->state = GST_FLXDEC_READ_HEADER;
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
gst_buffer_unref (flxdec->frame);
|
2002-01-19 18:26:20 +00:00
|
|
|
flxdec->frame = NULL;
|
2002-01-13 22:27:25 +00:00
|
|
|
gst_buffer_unref (flxdec->delta);
|
2002-01-19 18:26:20 +00:00
|
|
|
flxdec->delta = NULL;
|
2002-01-19 18:46:23 +00:00
|
|
|
gst_bytestream_destroy (flxdec->bs);
|
2002-01-13 22:27:25 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
|
|
|
|
parent_class->change_state (element);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
return GST_STATE_SUCCESS;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_flxdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstFlxDec *flxdec;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_FLXDEC(object));
|
|
|
|
flxdec = GST_FLXDEC(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_flxdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GstFlxDec *flxdec;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail(GST_IS_FLXDEC(object));
|
|
|
|
flxdec = GST_FLXDEC(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GModule *module, GstPlugin *plugin)
|
|
|
|
{
|
|
|
|
GstElementFactory *factory;
|
|
|
|
GstTypeFactory *type;
|
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
/* this filter needs the bytestream package */
|
2002-09-09 23:24:29 +00:00
|
|
|
if (!gst_library_load ("gstbytestream"))
|
2002-01-13 22:27:25 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
factory = gst_element_factory_new("flxdec", GST_TYPE_FLXDEC, &flxdec_details);
|
2001-12-22 23:27:31 +00:00
|
|
|
g_return_val_if_fail(factory != NULL, FALSE);
|
2002-05-31 08:24:31 +00:00
|
|
|
gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_PRIMARY);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (sink_factory));
|
|
|
|
gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (src_video_factory));
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
type = gst_type_factory_new (&flxdec_definition);
|
2001-12-22 23:27:31 +00:00
|
|
|
gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"flxdec",
|
|
|
|
plugin_init
|
|
|
|
};
|