* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+/**
+ * SECTION:element-flxdec
+ *
+ * This element decodes fli/flc/flx-video into raw video
+ */
+/*
+ * http://www.coolutils.com/Formats/FLI
+ * http://woodshole.er.usgs.gov/operations/modeling/flc.html
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#define JIFFIE (GST_SECOND/70)
-static GstCaps* flxdec_type_find (GstByteStream *bs, gpointer private);
-
-/* flx element information */
-static GstElementDetails flxdec_details = {
- "FLX Decoder",
- "Codec/Audio/Decoder",
- "LGPL",
- "FLX decoder",
- VERSION,
- "Sepp Wijnands <mrrazz@garbage-coderz.net>",
- "(C) 2001",
-};
-
-static GstTypeDefinition flxdec_definition = {
- "flxdec_video/fli",
- "video/fli",
- ".flc .fli",
- flxdec_type_find,
-};
-
-/* Flx signals and args */
-enum {
- /* FILL ME */
- LAST_SIGNAL
-};
-
-enum {
- ARG_0
-};
+GST_DEBUG_CATEGORY_STATIC (flxdec_debug);
+#define GST_CAT_DEFAULT flxdec_debug
/* input */
-GST_PAD_TEMPLATE_FACTORY (sink_factory,
- "sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_CAPS_NEW (
- "flxdec_sink",
- "video/x-fli",
- NULL
- )
-)
+static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("video/x-fli")
+ );
/* output */
-GST_PAD_TEMPLATE_FACTORY (src_video_factory,
- "src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_CAPS_NEW (
- "src_video",
- "video/x-raw-rgb",
- "bpp", GST_PROPS_INT (32),
- "depth", GST_PROPS_INT (32),
- "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
- "red_mask", GST_PROPS_INT (R_MASK_32),
- "green_mask", GST_PROPS_INT (G_MASK_32),
- "blue_mask", GST_PROPS_INT (B_MASK_32),
- "width", GST_PROPS_INT_RANGE(320, 1280),
- "height", GST_PROPS_INT_RANGE(200, 1024),
- "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT)
- )
-)
-
+static GstStaticPadTemplate src_video_factory = GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN)
+ );
-static void gst_flxdec_class_init (GstFlxDecClass *klass);
-static void gst_flxdec_init (GstFlxDec *flxdec);
-static void gst_flxdec_loop (GstElement *element);
+static void gst_flxdec_class_init (GstFlxDecClass * klass);
+static void gst_flxdec_base_init (GstFlxDecClass * klass);
+static void gst_flxdec_init (GstFlxDec * flxdec);
+static void gst_flxdec_dispose (GstFlxDec * flxdec);
-static GstElementStateReturn
- gst_flxdec_change_state (GstElement *element);
+static GstFlowReturn gst_flxdec_chain (GstPad * pad, GstBuffer * buf);
-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);
+static GstStateChangeReturn gst_flxdec_change_state (GstElement * element,
+ GstStateChange transition);
+static gboolean gst_flxdec_src_query_handler (GstPad * pad, GstQuery * query);
+static gboolean gst_flxdec_src_event_handler (GstPad * pad, GstEvent * event);
+static gboolean gst_flxdec_sink_event_handler (GstPad * pad, GstEvent * event);
-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 *);
+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 *);
-#define rndalign(off) ((off) + ((off) % 2))
+#define rndalign(off) ((off) + ((off) & 1))
static GstElementClass *parent_class = NULL;
-static GstCaps*
-flxdec_type_find (GstByteStream *bs, gpointer private)
-{
- GstBuffer *buf = NULL;
- GstCaps *new = NULL;
-
- if (gst_bytestream_peek (bs, &buf, 134) == 134) {
- guint8 *data = GST_BUFFER_DATA (buf);
-
- /* check magic */
- if ((data[4] == 0x11 || data[4] == 0x12 ||
- data[4] == 0x30 || data[4] == 0x44) &&
- data[5] == 0xaf) {
- /* check the frame type of the first frame */
- if ((data[132] == 0x00 || data[132] == 0xfa) && data[133] == 0xf1) {
- GST_DEBUG ("GstFlxDec: found supported flx format");
- new = gst_caps_new ("flxdec_type_find",
- "video/x-fli",
- NULL);
- }
- }
- }
-
- if (buf != NULL) {
- gst_buffer_unref (buf);
- }
-
- return new;
-}
-
-
GType
-gst_flxdec_get_type(void)
+gst_flxdec_get_type (void)
{
static GType flxdec_type = 0;
if (!flxdec_type) {
static const GTypeInfo flxdec_info = {
- sizeof(GstFlxDecClass), NULL,
+ sizeof (GstFlxDecClass),
+ (GBaseInitFunc) gst_flxdec_base_init,
NULL,
- (GClassInitFunc)gst_flxdec_class_init,
+ (GClassInitFunc) gst_flxdec_class_init,
NULL,
NULL,
- sizeof(GstFlxDec),
+ sizeof (GstFlxDec),
0,
- (GInstanceInitFunc)gst_flxdec_init,
+ (GInstanceInitFunc) gst_flxdec_init,
};
- flxdec_type = g_type_register_static(GST_TYPE_ELEMENT, "GstFlxDec", &flxdec_info, 0);
+
+ flxdec_type =
+ g_type_register_static (GST_TYPE_ELEMENT, "GstFlxDec", &flxdec_info, 0);
}
return flxdec_type;
}
-static void
-gst_flxdec_class_init (GstFlxDecClass *klass)
+static void
+gst_flxdec_base_init (GstFlxDecClass * klass)
+{
+ GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
+
+ gst_element_class_set_details_simple (gstelement_class, "FLX video decoder",
+ "Codec/Decoder/Video",
+ "FLC/FLI/FLX video decoder",
+ "Sepp Wijnands <mrrazz@garbage-coderz.net>, Zeeshan Ali <zeenix@gmail.com>");
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&sink_factory));
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&src_video_factory));
+}
+
+static void
+gst_flxdec_class_init (GstFlxDecClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
- gobject_class = (GObjectClass*)klass;
- gstelement_class = (GstElementClass*)klass;
+ gobject_class = (GObjectClass *) klass;
+ gstelement_class = (GstElementClass *) klass;
- parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
+ parent_class = g_type_class_peek_parent (klass);
- gobject_class->set_property = gst_flxdec_set_property;
- gobject_class->get_property = gst_flxdec_get_property;
+ gobject_class->dispose = (GObjectFinalizeFunc) gst_flxdec_dispose;
+
+ GST_DEBUG_CATEGORY_INIT (flxdec_debug, "flxdec", 0, "FLX video decoder");
gstelement_class->change_state = gst_flxdec_change_state;
}
-
-
-static void
-gst_flxdec_init(GstFlxDec *flxdec)
+static void
+gst_flxdec_init (GstFlxDec * flxdec)
{
- flxdec->sinkpad = gst_pad_new_from_template (
- GST_PAD_TEMPLATE_GET (sink_factory), "sink");
- gst_element_add_pad(GST_ELEMENT(flxdec),flxdec->sinkpad);
- gst_element_set_loop_function(GST_ELEMENT(flxdec),gst_flxdec_loop);
+ flxdec->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
+ gst_element_add_pad (GST_ELEMENT (flxdec), flxdec->sinkpad);
+ gst_pad_set_chain_function (flxdec->sinkpad, gst_flxdec_chain);
+ gst_pad_set_event_function (flxdec->sinkpad, gst_flxdec_sink_event_handler);
+
+ flxdec->srcpad = gst_pad_new_from_static_template (&src_video_factory, "src");
+ gst_element_add_pad (GST_ELEMENT (flxdec), flxdec->srcpad);
+ gst_pad_set_query_function (flxdec->srcpad, gst_flxdec_src_query_handler);
+ gst_pad_set_event_function (flxdec->srcpad, gst_flxdec_src_event_handler);
- flxdec->srcpad = gst_pad_new_from_template (
- GST_PAD_TEMPLATE_GET (src_video_factory), "src");
- gst_element_add_pad(GST_ELEMENT(flxdec),flxdec->srcpad);
+ gst_pad_use_fixed_caps (flxdec->srcpad);
- flxdec->bs = NULL;
flxdec->frame = NULL;
flxdec->delta = NULL;
+
+ flxdec->adapter = gst_adapter_new ();
+}
+
+static void
+gst_flxdec_dispose (GstFlxDec * flxdec)
+{
+ if (flxdec->adapter) {
+ g_object_unref (flxdec->adapter);
+ flxdec->adapter = NULL;
+ }
+
+ G_OBJECT_CLASS (parent_class)->dispose ((GObject *) flxdec);
+}
+
+static gboolean
+gst_flxdec_src_query_handler (GstPad * pad, GstQuery * query)
+{
+ GstFlxDec *flxdec = (GstFlxDec *) gst_pad_get_parent (pad);
+ gboolean ret = FALSE;
+
+ switch (GST_QUERY_TYPE (query)) {
+ case GST_QUERY_DURATION:
+ {
+ GstFormat format;
+
+ gst_query_parse_duration (query, &format, NULL);
+
+ if (format != GST_FORMAT_TIME)
+ goto done;
+
+ gst_query_set_duration (query, format, flxdec->duration);
+
+ ret = TRUE;
+ }
+ default:
+ break;
+ }
+done:
+ gst_object_unref (flxdec);
+
+ return ret;
+}
+
+static gboolean
+gst_flxdec_src_event_handler (GstPad * pad, GstEvent * event)
+{
+ GstFlxDec *flxdec = (GstFlxDec *) gst_pad_get_parent (pad);
+ gboolean ret;
+
+ /* TODO: implement the seek and other event handling */
+
+ ret = gst_pad_push_event (flxdec->sinkpad, event);
+
+ gst_object_unref (flxdec);
+
+ return ret;
+}
+
+static gboolean
+gst_flxdec_sink_event_handler (GstPad * pad, GstEvent * event)
+{
+ GstFlxDec *flxdec;
+ gboolean ret;
+
+ flxdec = GST_FLXDEC (gst_pad_get_parent (pad));
+
+ ret = gst_pad_push_event (flxdec->srcpad, event);
+
+ gst_object_unref (flxdec);
+ return ret;
}
static void
-flx_decode_chunks (GstFlxDec *flxdec , gulong count, gchar *data, gchar *dest)
+flx_decode_chunks (GstFlxDec * flxdec, gulong count, guchar * data,
+ guchar * dest)
{
- FlxFrameChunk *hdr;
+ FlxFrameChunk *hdr;
- g_return_if_fail(data != NULL);
+ g_return_if_fail (data != NULL);
while (count--) {
- hdr = (FlxFrameChunk *) data;
+ hdr = (FlxFrameChunk *) data;
+ FLX_FRAME_CHUNK_FIX_ENDIANNESS (hdr);
data += FlxFrameChunkSize;
- switch(hdr->id)
- {
+ switch (hdr->id) {
case FLX_COLOR64:
- flx_decode_color(flxdec, data, dest, 2);
- data += rndalign(hdr->size) - FlxFrameChunkSize;
+ flx_decode_color (flxdec, data, dest, 2);
+ data += rndalign (hdr->size) - FlxFrameChunkSize;
break;
case FLX_COLOR256:
- flx_decode_color(flxdec, data, dest, 0);
- data += rndalign(hdr->size) - FlxFrameChunkSize;
+ flx_decode_color (flxdec, data, dest, 0);
+ data += rndalign (hdr->size) - FlxFrameChunkSize;
break;
case FLX_BRUN:
- flx_decode_brun(flxdec, data, dest);
- data += rndalign(hdr->size) - FlxFrameChunkSize;
+ 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;
+ 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;
+ flx_decode_delta_flc (flxdec, data, dest);
+ data += rndalign (hdr->size) - FlxFrameChunkSize;
break;
case FLX_BLACK:
- memset(dest, 0, flxdec->size);
+ memset (dest, 0, flxdec->size);
break;
case FLX_MINI:
- data += rndalign(hdr->size) - FlxFrameChunkSize;
+ 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;
+ GST_WARNING ("Unimplented chunk type: 0x%02x size: %d - skipping",
+ hdr->id, hdr->size);
+ data += rndalign (hdr->size) - FlxFrameChunkSize;
break;
}
}
static void
-flx_decode_color(GstFlxDec *flxdec, guchar *data, guchar *dest, gint scale)
+flx_decode_color (GstFlxDec * flxdec, guchar * data, guchar * dest, gint scale)
{
guint packs, count, indx;
- g_return_if_fail(flxdec != NULL);
+ g_return_if_fail (flxdec != NULL);
packs = (data[0] + (data[1] << 8));
data += 2;
- indx = 0;
+ indx = 0;
- g_print("GstFlxDec: cmap packs: %d\n", packs);
+ GST_LOG ("GstFlxDec: cmap packs: %d", packs);
while (packs--) {
/* color map index + skip count */
indx += *data++;
if (count == 0)
count = 256;
- g_print("GstFlxDec: cmap count: %d (indx: %d)\n", count, indx);
- flx_set_palette_vector(flxdec->converter, indx, count, data, scale);
+ GST_LOG ("GstFlxDec: cmap count: %d (indx: %d)", count, indx);
+ flx_set_palette_vector (flxdec->converter, indx, count, data, scale);
data += (count * 3);
}
}
-static void
-flx_decode_brun(GstFlxDec *flxdec, guchar *data, guchar *dest)
+static void
+flx_decode_brun (GstFlxDec * flxdec, guchar * data, guchar * dest)
{
- gulong count, lines, row;
- guchar x;
-
- g_return_if_fail(flxdec != NULL);
+ gulong count, lines, row;
+ guchar x;
+
+ g_return_if_fail (flxdec != NULL);
lines = flxdec->hdr.height;
- while(lines--) {
+ while (lines--) {
/* packet count.
* should not be used anymore, since the flc format can
* contain more then 255 RLE packets. we use the frame
data++;
row = flxdec->hdr.width;
- while(row) {
+ while (row) {
count = *data++;
- if (count > 0x7f) {
+ if (count > 0x7f) {
/* literal run */
count = 0x100 - count;
row -= count;
- while(count--)
+ while (count--)
*dest++ = *data++;
-
+
} else {
/* replicate run */
row -= count;
x = *data++;
- while(count--)
+ while (count--)
*dest++ = x;
}
}
}
}
-static void
-flx_decode_delta_fli(GstFlxDec *flxdec, guchar *data, guchar *dest)
+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);
+ gulong count, packets, lines, start_line;
+ 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));
+ 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;
+ 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--) {
+ while (lines--) {
/* packet count */
packets = *data++;
- while(packets--) {
+ while (packets--) {
/* skip count */
dest += *data++;
/* RLE count */
count = *data++;
- if (count > 0x7f) {
+ if (count > 0x7f) {
/* literal run */
count = 0x100 - count;
x = *data++;
} else {
/* replicate run */
- while (count--)
+ while (count--)
*dest++ = *data++;
}
}
start_p += flxdec->hdr.width;
dest = start_p;
- }
+ }
}
-static void
-flx_decode_delta_flc(GstFlxDec *flxdec, guchar *data, guchar *dest)
+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);
+ 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));
+ memcpy (dest, GST_BUFFER_DATA (flxdec->delta),
+ GST_BUFFER_SIZE (flxdec->delta));
- lines = (data[0] + (data[1] << 8));
- data += 2;
+ lines = (data[0] + (data[1] << 8));
+ data += 2;
- start_p = dest;
- start_l = lines;
+ start_p = dest;
+ start_l = lines;
while (lines) {
dest = start_p + (flxdec->hdr.width * (start_l - lines));
data += 2;
if ((opcode & 0xc000) == 0xc000) {
/* skip count */
- start_l += (0x10000 - opcode);
- dest += flxdec->hdr.width * (0x10000 - opcode);
+ start_l += (0x10000 - opcode);
+ dest += flxdec->hdr.width * (0x10000 - opcode);
} else {
/* last pixel */
- dest += flxdec->hdr.width;
- *dest++ = (opcode & 0xff);
- }
+ dest += flxdec->hdr.width;
+ *dest++ = (opcode & 0xff);
+ }
}
data += 2;
/* last opcode is the packet count */
- while(opcode--) {
+ while (opcode--) {
/* skip count */
dest += *data++;
-
+
/* RLE count */
count = *data++;
-
+
if (count > 0x7f) {
/* replicate word run */
count = 0x100 - count;
lines--;
}
}
-
-static GstBuffer*
-flx_get_data(GstFlxDec *flxdec, gulong size)
-{
- GstBuffer *retbuf;
- guint32 got_bytes;
- g_return_val_if_fail (flxdec != NULL, NULL);
+static GstFlowReturn
+gst_flxdec_chain (GstPad * pad, GstBuffer * buf)
+{
+ GstCaps *caps;
+ guint avail;
+ GstFlowReturn res = GST_FLOW_OK;
- got_bytes = gst_bytestream_read (flxdec->bs, &retbuf, size);
- if (got_bytes < size) {
- GstEvent *event;
- guint32 remaining;
+ GstFlxDec *flxdec;
+ FlxHeader *flxh;
- gst_bytestream_get_status (flxdec->bs, &remaining, &event);
- gst_pad_event_default (flxdec->sinkpad, event);
- }
+ g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
+ flxdec = (GstFlxDec *) gst_pad_get_parent (pad);
+ g_return_val_if_fail (flxdec != NULL, GST_FLOW_ERROR);
- return retbuf;
-}
+ gst_adapter_push (flxdec->adapter, buf);
+ avail = gst_adapter_available (flxdec->adapter);
+ if (flxdec->state == GST_FLXDEC_READ_HEADER) {
+ if (avail >= FlxHeaderSize) {
+ const guint8 *data = gst_adapter_peek (flxdec->adapter, FlxHeaderSize);
-static void
-gst_flxdec_loop (GstElement *element)
-{
- GstBuffer *buf;
- GstBuffer *databuf;
- guchar *data, *chunk;
+ memcpy ((gchar *) & flxdec->hdr, data, FlxHeaderSize);
+ FLX_HDR_FIX_ENDIANNESS (&(flxdec->hdr));
+ gst_adapter_flush (flxdec->adapter, FlxHeaderSize);
- GstFlxDec *flxdec;
- FlxHeader *flxh;
- FlxFrameChunk *flxfh;
-
- g_return_if_fail (element != NULL);
- g_return_if_fail (GST_IS_FLXDEC(element));
+ flxh = &flxdec->hdr;
- GST_DEBUG ("entering loop function");
-
- flxdec = GST_FLXDEC(element);
+ /* check header */
+ if (flxh->type != FLX_MAGICHDR_FLI &&
+ flxh->type != FLX_MAGICHDR_FLC && flxh->type != FLX_MAGICHDR_FLX)
+ goto wrong_type;
- if (flxdec->state == GST_FLXDEC_READ_HEADER) {
- databuf = flx_get_data(flxdec, FlxHeaderSize);
+ GST_LOG ("size : %d", flxh->size);
+ GST_LOG ("frames : %d", flxh->frames);
+ GST_LOG ("width : %d", flxh->width);
+ GST_LOG ("height : %d", flxh->height);
+ GST_LOG ("depth : %d", flxh->depth);
+ GST_LOG ("speed : %d", flxh->speed);
- if (!databuf) {
- g_print ("empty buffer\n");
- return;
- }
+ flxdec->next_time = 0;
- data = GST_BUFFER_DATA(databuf);
+ if (flxh->type == FLX_MAGICHDR_FLI) {
+ flxdec->frame_time = JIFFIE * flxh->speed;
+ } else if (flxh->speed == 0) {
+ flxdec->frame_time = GST_SECOND / 70;
+ } else {
+ flxdec->frame_time = flxh->speed * GST_MSECOND;
+ }
- memcpy((char *) &flxdec->hdr, data, sizeof(FlxHeader));
+ flxdec->duration = flxh->frames * flxdec->frame_time;
+ GST_LOG ("duration : %" GST_TIME_FORMAT,
+ GST_TIME_ARGS (flxdec->duration));
+
+ caps = gst_caps_from_string (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN);
+ gst_caps_set_simple (caps,
+ "width", G_TYPE_INT, flxh->width,
+ "height", G_TYPE_INT, flxh->height,
+ "framerate", GST_TYPE_FRACTION, (gint) GST_MSECOND,
+ (gint) flxdec->frame_time / 1000, NULL);
+
+ gst_pad_set_caps (flxdec->srcpad, caps);
+ gst_caps_unref (caps);
+
+ 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) {
+ GST_LOG ("(FLC) aspect_dx : %d", flxh->aspect_dx);
+ GST_LOG ("(FLC) aspect_dy : %d", flxh->aspect_dy);
+ GST_LOG ("(FLC) oframe1 : 0x%08x", flxh->oframe1);
+ GST_LOG ("(FLC) oframe2 : 0x%08x", flxh->oframe2);
+ }
- gst_buffer_unref (databuf);
+ flxdec->size = (flxh->width * flxh->height);
- flxh = &flxdec->hdr;
+ /* 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_MALLOCDATA (flxdec->frame) = GST_BUFFER_DATA (flxdec->frame);
+ GST_BUFFER_SIZE (flxdec->frame) = flxdec->size;
+ GST_BUFFER_DATA (flxdec->delta) = g_malloc (flxdec->size);
+ GST_BUFFER_MALLOCDATA (flxdec->delta) = GST_BUFFER_DATA (flxdec->delta);
+ GST_BUFFER_SIZE (flxdec->delta) = flxdec->size;
- /* check header */
- if (flxh->type != FLX_MAGICHDR_FLI &&
- flxh->type != FLX_MAGICHDR_FLC &&
- flxh->type != FLX_MAGICHDR_FLX) {
- gst_element_error (element, "not a flx file (type %d)\n", flxh->type);
- return;
- }
-
-
- 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 {
- flxdec->frame_time = flxh->speed * GST_MSECOND;
- }
-
- gst_pad_try_set_caps (flxdec->srcpad,
- GST_CAPS_NEW (
- "src_video",
- "video/x-raw-rgb",
- "bpp", GST_PROPS_INT (32),
- "depth", GST_PROPS_INT (32),
- "endianness", GST_PROPS_INT (G_BIG_ENDIAN),
- "red_mask", GST_PROPS_INT (R_MASK_32),
- "green_mask", GST_PROPS_INT (G_MASK_32),
- "blue_mask", GST_PROPS_INT (B_MASK_32),
- "width", GST_PROPS_INT (flxh->width),
- "height", GST_PROPS_INT (flxh->height),
- "framerate", GST_PROPS_FLOAT (GST_SECOND/flxdec->frame_time)));
-
- 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);
+ flxdec->state = GST_FLXDEC_PLAYING;
}
-
-
- flxdec->size = (flxh->width * flxh->height);
-
- /* 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) {
+ } else if (flxdec->state == GST_FLXDEC_PLAYING) {
GstBuffer *out;
- databuf = flx_get_data(flxdec, FlxFrameChunkSize);
- if (!databuf)
- return;
-
- flxfh = (FlxFrameChunk *) GST_BUFFER_DATA(databuf);
-
- switch(flxfh->id) {
- case FLX_FRAME_TYPE:
- buf = flx_get_data(flxdec, flxfh->size-FlxFrameChunkSize);
-
- chunk = GST_BUFFER_DATA(buf);
-
- if (((FlxFrameType *)chunk)->chunks == 0)
+ /* while we have enough data in the adapter */
+ while (avail >= FlxFrameChunkSize) {
+ FlxFrameChunk flxfh;
+ guchar *chunk;
+ const guint8 *data;
+
+ chunk = NULL;
+ data = gst_adapter_peek (flxdec->adapter, FlxFrameChunkSize);
+ memcpy (&flxfh, data, FlxFrameChunkSize);
+ FLX_FRAME_CHUNK_FIX_ENDIANNESS (&flxfh);
+
+ switch (flxfh.id) {
+ case FLX_FRAME_TYPE:
+ /* check if we have the complete frame */
+ if (avail < flxfh.size)
+ goto need_more_data;
+
+ /* flush header */
+ gst_adapter_flush (flxdec->adapter, FlxFrameChunkSize);
+
+ chunk = gst_adapter_take (flxdec->adapter,
+ flxfh.size - FlxFrameChunkSize);
+ FLX_FRAME_TYPE_FIX_ENDIANNESS ((FlxFrameType *) chunk);
+ if (((FlxFrameType *) chunk)->chunks == 0)
+ break;
+
+ /* create 32 bits output frame */
+ res = gst_pad_alloc_buffer_and_set_caps (flxdec->srcpad,
+ GST_BUFFER_OFFSET_NONE,
+ flxdec->size * 4, GST_PAD_CAPS (flxdec->srcpad), &out);
+ if (res != GST_FLOW_OK)
+ break;
+
+ /* decode chunks */
+ flx_decode_chunks (flxdec,
+ ((FlxFrameType *) chunk)->chunks,
+ chunk + FlxFrameTypeSize, GST_BUFFER_DATA (flxdec->frame));
+
+ /* save copy of the current frame for possible delta. */
+ memcpy (GST_BUFFER_DATA (flxdec->delta),
+ GST_BUFFER_DATA (flxdec->frame), GST_BUFFER_SIZE (flxdec->delta));
+
+ /* convert current frame. */
+ flx_colorspace_convert (flxdec->converter,
+ GST_BUFFER_DATA (flxdec->frame), GST_BUFFER_DATA (out));
+
+ GST_BUFFER_TIMESTAMP (out) = flxdec->next_time;
+ flxdec->next_time += flxdec->frame_time;
+
+ gst_pad_push (flxdec->srcpad, out);
break;
+ }
- /* create 32 bits output frame */
- out = gst_buffer_new();
- GST_BUFFER_DATA(out) = g_malloc(flxdec->size * 4);
- GST_BUFFER_SIZE(out) = flxdec->size * 4;
-
- /* decode chunks */
- flx_decode_chunks(flxdec,
- ((FlxFrameType *)chunk)->chunks,
- GST_BUFFER_DATA(buf) + FlxFrameTypeSize,
- GST_BUFFER_DATA(flxdec->frame));
-
- /* destroy input buffer*/
- gst_buffer_unref(buf);
-
- /* save copy of the current frame for possible delta. */
- memcpy(GST_BUFFER_DATA(flxdec->delta),
- GST_BUFFER_DATA(flxdec->frame),
- GST_BUFFER_SIZE(flxdec->delta));
-
- /* convert current frame. */
- flx_colorspace_convert(flxdec->converter,
- GST_BUFFER_DATA(flxdec->frame),
- GST_BUFFER_DATA(out));
-
- GST_BUFFER_TIMESTAMP (out) = flxdec->next_time;
- flxdec->next_time += flxdec->frame_time;
-
- gst_pad_push(flxdec->srcpad, out);
-
- break;
- }
+ if (chunk)
+ g_free (chunk);
- /* destroy header buffer */
- gst_buffer_unref(databuf);
+ avail = gst_adapter_available (flxdec->adapter);
+ }
+ }
+need_more_data:
+ gst_object_unref (flxdec);
+ return res;
+
+ /* ERRORS */
+wrong_type:
+ {
+ GST_ELEMENT_ERROR (flxdec, STREAM, WRONG_TYPE, (NULL),
+ ("not a flx file (type %x)", flxh->type));
+ gst_object_unref (flxdec);
+ return GST_FLOW_ERROR;
}
}
-static GstElementStateReturn
-gst_flxdec_change_state (GstElement *element)
+static GstStateChangeReturn
+gst_flxdec_change_state (GstElement * element, GstStateChange transition)
{
GstFlxDec *flxdec;
+ GstStateChangeReturn ret;
- flxdec = GST_FLXDEC(element);
+ flxdec = GST_FLXDEC (element);
- switch (GST_STATE_TRANSITION (element)) {
- case GST_STATE_NULL_TO_READY:
+ switch (transition) {
+ case GST_STATE_CHANGE_NULL_TO_READY:
break;
- case GST_STATE_READY_TO_PAUSED:
- flxdec->bs = gst_bytestream_new (flxdec->sinkpad);
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
+ gst_adapter_clear (flxdec->adapter);
flxdec->state = GST_FLXDEC_READ_HEADER;
break;
- case GST_STATE_PAUSED_TO_PLAYING:
- break;
- case GST_STATE_PLAYING_TO_PAUSED:
+ case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
break;
- case GST_STATE_PAUSED_TO_READY:
- gst_buffer_unref (flxdec->frame);
- flxdec->frame = NULL;
- gst_buffer_unref (flxdec->delta);
- flxdec->delta = NULL;
- gst_bytestream_destroy (flxdec->bs);
- break;
- case GST_STATE_READY_TO_NULL:
- break;
- }
-
- parent_class->change_state (element);
-
- return GST_STATE_SUCCESS;
-}
-
-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);
+ ret = parent_class->change_state (element, transition);
- switch (prop_id) {
+ switch (transition) {
+ case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
+ break;
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
+ if (flxdec->frame) {
+ gst_buffer_unref (flxdec->frame);
+ flxdec->frame = NULL;
+ }
+ if (flxdec->delta) {
+ gst_buffer_unref (flxdec->delta);
+ flxdec->delta = NULL;
+ }
+ break;
+ case GST_STATE_CHANGE_READY_TO_NULL:
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
+ return ret;
}
static gboolean
-plugin_init (GModule *module, GstPlugin *plugin)
+plugin_init (GstPlugin * plugin)
{
- GstElementFactory *factory;
- GstTypeFactory *type;
-
- factory = gst_element_factory_new("flxdec", GST_TYPE_FLXDEC, &flxdec_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 (sink_factory));
- gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (src_video_factory));
-
- gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
-
- type = gst_type_factory_new (&flxdec_definition);
- gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
-
- return TRUE;
+ return gst_element_register (plugin, "flxdec",
+ GST_RANK_PRIMARY, GST_TYPE_FLXDEC);
}
-GstPluginDesc plugin_desc = {
- GST_VERSION_MAJOR,
- GST_VERSION_MINOR,
- "flxdec",
- plugin_init
-};
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "flxdec",
+ "FLC/FLI/FLX video decoder",
+ plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)