Commit b4d28290 authored by Wim Taymans's avatar Wim Taymans

gst/flx/: Set MALLOCDATA for the temp buffers so we don't leak.

Original commit message from CVS:
* gst/flx/flx_color.h:
* gst/flx/flx_fmt.h:
* gst/flx/gstflxdec.c: (gst_flxdec_init),
(gst_flxdec_src_query_handler), (flx_decode_color),
(gst_flxdec_chain):
* gst/flx/gstflxdec.h:
Set MALLOCDATA for the temp buffers so we don't leak.
Some debug cleanups.
Consume all data in the adapter before leaving the chain
function. Fixes #330678.
parent c64021f8
2006-02-19 Wim Taymans <wim@fluendo.com>
* gst/flx/flx_color.h:
* gst/flx/flx_fmt.h:
* gst/flx/gstflxdec.c: (gst_flxdec_init),
(gst_flxdec_src_query_handler), (flx_decode_color),
(gst_flxdec_chain):
* gst/flx/gstflxdec.h:
Set MALLOCDATA for the temp buffers so we don't leak.
Some debug cleanups.
Consume all data in the adapter before leaving the chain
function. Fixes #330678.
2006-02-18 Jan Schmidt <thaytan@mad.scientist.com> 2006-02-18 Jan Schmidt <thaytan@mad.scientist.com>
* gst/id3demux/id3tags.c: (id3demux_id3v2_frames_to_tag_list): * gst/id3demux/id3tags.c: (id3demux_id3v2_frames_to_tag_list):
......
...@@ -17,8 +17,13 @@ ...@@ -17,8 +17,13 @@
* Boston, MA 02111-1307, USA. * Boston, MA 02111-1307, USA.
*/ */
#ifndef __FLX_COLOR_H__
#define __FLX_COLOR_H__
#include <gst/gst.h> #include <gst/gst.h>
G_BEGIN_DECLS
typedef enum { typedef enum {
FLX_COLORSPACE_RGB8, FLX_COLORSPACE_RGB8,
FLX_COLORSPACE_RGB32, FLX_COLORSPACE_RGB32,
...@@ -42,3 +47,6 @@ void flx_set_palette_vector(FlxColorSpaceConverter *flxpal, guint start, guint n ...@@ -42,3 +47,6 @@ void flx_set_palette_vector(FlxColorSpaceConverter *flxpal, guint start, guint n
void flx_set_color(FlxColorSpaceConverter *flxpal, guint colr, guint red, guint green, void flx_set_color(FlxColorSpaceConverter *flxpal, guint colr, guint red, guint green,
guint blue, gint scale); guint blue, gint scale);
G_END_DECLS
#endif /* __FLX_COLOR_H__ */
...@@ -23,9 +23,7 @@ ...@@ -23,9 +23,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#ifdef __cplusplus G_BEGIN_DECLS
extern "C" {
#endif /* __cplusplus */
enum Flx_TypeChunk enum Flx_TypeChunk
{ {
...@@ -197,9 +195,6 @@ typedef struct _FlxFrameType ...@@ -197,9 +195,6 @@ typedef struct _FlxFrameType
#endif /* G_BYTE_ORDER == G_BIG_ENDIAN */ #endif /* G_BYTE_ORDER == G_BIG_ENDIAN */
#ifdef __cplusplus G_END_DECLS
}
#endif /* __cplusplus */
#endif /* __GST_FLX_FMT_H__ */ #endif /* __GST_FLX_FMT_H__ */
...@@ -75,6 +75,7 @@ static GstFlowReturn gst_flxdec_chain (GstPad * pad, GstBuffer * buf); ...@@ -75,6 +75,7 @@ static GstFlowReturn gst_flxdec_chain (GstPad * pad, GstBuffer * buf);
static GstStateChangeReturn gst_flxdec_change_state (GstElement * element, static GstStateChangeReturn gst_flxdec_change_state (GstElement * element,
GstStateChange transition); 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_src_event_handler (GstPad * pad, GstEvent * event);
static gboolean gst_flxdec_sink_event_handler (GstPad * pad, GstEvent * event); static gboolean gst_flxdec_sink_event_handler (GstPad * pad, GstEvent * event);
...@@ -89,7 +90,7 @@ static void flx_decode_brun (GstFlxDec *, guchar *, guchar *); ...@@ -89,7 +90,7 @@ static void flx_decode_brun (GstFlxDec *, guchar *, guchar *);
static void flx_decode_delta_fli (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_delta_flc (GstFlxDec *, guchar *, guchar *);
#define rndalign(off) ((off) + ((off) % 2)) #define rndalign(off) ((off) + ((off) & 1))
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
...@@ -162,6 +163,7 @@ gst_flxdec_init (GstFlxDec * flxdec) ...@@ -162,6 +163,7 @@ gst_flxdec_init (GstFlxDec * flxdec)
gst_pad_new_from_template (gst_static_pad_template_get gst_pad_new_from_template (gst_static_pad_template_get
(&src_video_factory), "src"); (&src_video_factory), "src");
gst_element_add_pad (GST_ELEMENT (flxdec), flxdec->srcpad); 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); gst_pad_set_event_function (flxdec->srcpad, gst_flxdec_src_event_handler);
gst_pad_use_fixed_caps (flxdec->srcpad); gst_pad_use_fixed_caps (flxdec->srcpad);
...@@ -172,6 +174,35 @@ gst_flxdec_init (GstFlxDec * flxdec) ...@@ -172,6 +174,35 @@ gst_flxdec_init (GstFlxDec * flxdec)
flxdec->adapter = gst_adapter_new (); flxdec->adapter = gst_adapter_new ();
} }
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 static gboolean
gst_flxdec_src_event_handler (GstPad * pad, GstEvent * event) gst_flxdec_src_event_handler (GstPad * pad, GstEvent * event)
{ {
...@@ -280,7 +311,7 @@ flx_decode_color (GstFlxDec * flxdec, guchar * data, guchar * dest, gint scale) ...@@ -280,7 +311,7 @@ flx_decode_color (GstFlxDec * flxdec, guchar * data, guchar * dest, gint scale)
if (count == 0) if (count == 0)
count = 256; count = 256;
GST_LOG ("GstFlxDec: cmap count: %d (indx: %d)\n", count, indx); GST_LOG ("GstFlxDec: cmap count: %d (indx: %d)", count, indx);
flx_set_palette_vector (flxdec->converter, indx, count, data, scale); flx_set_palette_vector (flxdec->converter, indx, count, data, scale);
data += (count * 3); data += (count * 3);
...@@ -474,19 +505,15 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf) ...@@ -474,19 +505,15 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf)
/* check header */ /* check header */
if (flxh->type != FLX_MAGICHDR_FLI && if (flxh->type != FLX_MAGICHDR_FLI &&
flxh->type != FLX_MAGICHDR_FLC && flxh->type != FLX_MAGICHDR_FLX) { flxh->type != FLX_MAGICHDR_FLC && flxh->type != FLX_MAGICHDR_FLX)
GST_ELEMENT_ERROR (flxdec, STREAM, WRONG_TYPE, (NULL), goto wrong_type;
("not a flx file (type %x)\n", flxh->type));
return GST_FLOW_ERROR;
}
GST_LOG ("size : %d\n", flxh->size); GST_LOG ("size : %d", flxh->size);
GST_LOG ("frames : %d\n", flxh->frames); GST_LOG ("frames : %d", flxh->frames);
GST_LOG ("width : %d\n", flxh->width); GST_LOG ("width : %d", flxh->width);
GST_LOG ("height : %d\n", flxh->height); GST_LOG ("height : %d", flxh->height);
GST_LOG ("depth : %d\n", flxh->depth); GST_LOG ("depth : %d", flxh->depth);
GST_LOG ("speed : %d\n", flxh->speed); GST_LOG ("speed : %d", flxh->speed);
flxdec->next_time = 0; flxdec->next_time = 0;
...@@ -498,6 +525,8 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf) ...@@ -498,6 +525,8 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf)
flxdec->frame_time = flxh->speed * GST_MSECOND; flxdec->frame_time = flxh->speed * GST_MSECOND;
} }
flxdec->duration = flxh->frames * flxdec->frame_time;
caps = gst_caps_from_string (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN); caps = gst_caps_from_string (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN);
gst_caps_set_simple (caps, gst_caps_set_simple (caps,
"width", G_TYPE_INT, flxh->width, "width", G_TYPE_INT, flxh->width,
...@@ -513,10 +542,10 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf) ...@@ -513,10 +542,10 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf)
flx_colorspace_converter_new (flxh->width, flxh->height); flx_colorspace_converter_new (flxh->width, flxh->height);
if (flxh->type == FLX_MAGICHDR_FLC || flxh->type == FLX_MAGICHDR_FLX) { if (flxh->type == FLX_MAGICHDR_FLC || flxh->type == FLX_MAGICHDR_FLX) {
GST_LOG ("(FLC) aspect_dx : %d\n", flxh->aspect_dx); GST_LOG ("(FLC) aspect_dx : %d", flxh->aspect_dx);
GST_LOG ("(FLC) aspect_dy : %d\n", flxh->aspect_dy); GST_LOG ("(FLC) aspect_dy : %d", flxh->aspect_dy);
GST_LOG ("(FLC) oframe1 : 0x%08x\n", flxh->oframe1); GST_LOG ("(FLC) oframe1 : 0x%08x", flxh->oframe1);
GST_LOG ("(FLC) oframe2 : 0x%08x\n", flxh->oframe2); GST_LOG ("(FLC) oframe2 : 0x%08x", flxh->oframe2);
} }
flxdec->size = (flxh->width * flxh->height); flxdec->size = (flxh->width * flxh->height);
...@@ -525,8 +554,10 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf) ...@@ -525,8 +554,10 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf)
flxdec->frame = gst_buffer_new (); flxdec->frame = gst_buffer_new ();
flxdec->delta = gst_buffer_new (); flxdec->delta = gst_buffer_new ();
GST_BUFFER_DATA (flxdec->frame) = g_malloc (flxdec->size); 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_SIZE (flxdec->frame) = flxdec->size;
GST_BUFFER_DATA (flxdec->delta) = g_malloc (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; GST_BUFFER_SIZE (flxdec->delta) = flxdec->size;
flxdec->state = GST_FLXDEC_PLAYING; flxdec->state = GST_FLXDEC_PLAYING;
...@@ -534,27 +565,28 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf) ...@@ -534,27 +565,28 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf)
} else if (flxdec->state == GST_FLXDEC_PLAYING) { } else if (flxdec->state == GST_FLXDEC_PLAYING) {
GstBuffer *out; GstBuffer *out;
if (avail >= FlxFrameChunkSize) { /* while we have enough data in the adapter */
while (avail >= FlxFrameChunkSize) {
FlxFrameChunk flxfh; FlxFrameChunk flxfh;
guchar *chunk = NULL; guchar *chunk;
guint to_flush = 0; const guint8 *data;
const guint8 *data =
gst_adapter_peek (flxdec->adapter, FlxFrameChunkSize); chunk = NULL;
data = gst_adapter_peek (flxdec->adapter, FlxFrameChunkSize);
memcpy (&flxfh, data, FlxFrameChunkSize); memcpy (&flxfh, data, FlxFrameChunkSize);
FLX_FRAME_CHUNK_FIX_ENDIANNESS (&flxfh); FLX_FRAME_CHUNK_FIX_ENDIANNESS (&flxfh);
switch (flxfh.id) { switch (flxfh.id) {
case FLX_FRAME_TYPE: case FLX_FRAME_TYPE:
if (avail < flxfh.size) { /* check if we have the complete frame */
break; if (avail < flxfh.size)
} goto need_more_data;
/* flush header */
gst_adapter_flush (flxdec->adapter, FlxFrameChunkSize); gst_adapter_flush (flxdec->adapter, FlxFrameChunkSize);
data = gst_adapter_peek (flxdec->adapter,
flxfh.size - FlxFrameChunkSize);
chunk = g_memdup (data, flxfh.size - FlxFrameChunkSize);
to_flush = flxfh.size - FlxFrameChunkSize;
chunk = gst_adapter_take (flxdec->adapter,
flxfh.size - FlxFrameChunkSize);
FLX_FRAME_TYPE_FIX_ENDIANNESS ((FlxFrameType *) chunk); FLX_FRAME_TYPE_FIX_ENDIANNESS ((FlxFrameType *) chunk);
if (((FlxFrameType *) chunk)->chunks == 0) if (((FlxFrameType *) chunk)->chunks == 0)
break; break;
...@@ -563,7 +595,6 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf) ...@@ -563,7 +595,6 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf)
res = gst_pad_alloc_buffer_and_set_caps (flxdec->srcpad, res = gst_pad_alloc_buffer_and_set_caps (flxdec->srcpad,
GST_BUFFER_OFFSET_NONE, GST_BUFFER_OFFSET_NONE,
flxdec->size * 4, GST_PAD_CAPS (flxdec->srcpad), &out); flxdec->size * 4, GST_PAD_CAPS (flxdec->srcpad), &out);
if (res != GST_FLOW_OK) if (res != GST_FLOW_OK)
break; break;
...@@ -587,14 +618,23 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf) ...@@ -587,14 +618,23 @@ gst_flxdec_chain (GstPad * pad, GstBuffer * buf)
break; break;
} }
gst_adapter_flush (flxdec->adapter, to_flush);
if (chunk) if (chunk)
g_free (chunk); g_free (chunk);
avail = gst_adapter_available (flxdec->adapter);
} }
} }
need_more_data:
return res; return res;
/* ERRORS */
wrong_type:
{
GST_ELEMENT_ERROR (flxdec, STREAM, WRONG_TYPE, (NULL),
("not a flx file (type %x)", flxh->type));
return GST_FLOW_ERROR;
}
} }
static GstStateChangeReturn static GstStateChangeReturn
......
...@@ -25,9 +25,7 @@ ...@@ -25,9 +25,7 @@
#include <gst/base/gstadapter.h> #include <gst/base/gstadapter.h>
#include "flx_color.h" #include "flx_color.h"
#ifdef __cplusplus G_BEGIN_DECLS
extern "C" {
#endif /* __cplusplus */
typedef enum { typedef enum {
GST_FLXDEC_READ_HEADER, GST_FLXDEC_READ_HEADER,
...@@ -51,6 +49,7 @@ struct _GstFlxDec { ...@@ -51,6 +49,7 @@ struct _GstFlxDec {
GstFlxDecState state; GstFlxDecState state;
glong frame_time; glong frame_time;
gint64 next_time; gint64 next_time;
gint64 duration;
FlxColorSpaceConverter *converter; FlxColorSpaceConverter *converter;
...@@ -78,10 +77,6 @@ struct _GstFlxDecClass { ...@@ -78,10 +77,6 @@ struct _GstFlxDecClass {
/* Standard function returning type information. */ /* Standard function returning type information. */
GType gst_flxdec_get_type(void); GType gst_flxdec_get_type(void);
G_END_DECLS
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GST_FLX_DECODER_H__ */ #endif /* __GST_FLX_DECODER_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment