2002-01-19 14:50:50 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@temple-baptist.com>
|
2016-11-22 20:09:06 +00:00
|
|
|
* Copyright (C) <2016> Matthew Waters <matthew@centricular.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
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2001-12-22 23:27:31 +00:00
|
|
|
*/
|
2006-11-08 12:04:03 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-flxdec
|
2018-10-22 09:39:24 +00:00
|
|
|
* @title: flxdec
|
2006-11-08 12:04:03 +00:00
|
|
|
*
|
|
|
|
* 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
|
2016-11-22 20:09:06 +00:00
|
|
|
* http://www.compuphase.com/flic.htm
|
2006-11-08 12:04:03 +00:00
|
|
|
*/
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-12-22 23:27:31 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "flx_fmt.h"
|
|
|
|
#include "gstflxdec.h"
|
2003-07-06 20:49:52 +00:00
|
|
|
#include <gst/video/video.h>
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-06-16 21:56:49 +00:00
|
|
|
#define JIFFIE (GST_SECOND/70)
|
2002-01-13 22:27:25 +00:00
|
|
|
|
ext/flac/gstflacdec.c: Only return true if we actually filled something in. Prevents player applications from showing...
Original commit message from CVS:
* ext/flac/gstflacdec.c: (gst_flacdec_src_query):
Only return true if we actually filled something in. Prevents
player applications from showing a random length for flac files.
* gst-libs/gst/riff/riff-read.c: (gst_riff_read_class_init),
(gst_riff_read_use_event), (gst_riff_read_handle_event),
(gst_riff_read_seek), (gst_riff_read_skip), (gst_riff_read_strh),
(gst_riff_read_strf_vids_with_data),
(gst_riff_read_strf_auds_with_data), (gst_riff_read_strf_iavs):
OK, ok, so I implemented event handling. Apparently it's normal
that we receive random events at random points without asking
for it.
* gst/avi/gstavidemux.c: (gst_avi_demux_reset),
(gst_avi_demux_src_convert), (gst_avi_demux_handle_src_query),
(gst_avi_demux_handle_src_event), (gst_avi_demux_stream_index),
(gst_avi_demux_sync), (gst_avi_demux_stream_scan),
(gst_avi_demux_massage_index), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry),
(gst_avi_demux_stream_data), (gst_avi_demux_loop):
* gst/avi/gstavidemux.h:
Implement non-lineair chunk handling and subchunk processing.
The first solves playback of AVI files where the audio and video
data of individual buffers that we read are not synchronized.
This should not happen according to the wonderful AVI specs, but
of course it does happen in reality. It is also a prerequisite for
the second. Subchunk processing allows us to cut chunks in small
pieces and process each of these pieces separately. This is
required because I've seen several AVI files with incredibly large
audio chunks, even some files with only one audio chunk for the
whole file. This allows for proper playback including seeking.
This patch is supposed to fix all AVI A/V sync issues.
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(flx_decode_chunks), (flx_decode_color), (gst_flxdec_loop):
Work.
* gst/modplug/gstmodplug.cc:
Proper return value setting for the query() function.
* gst/playback/gstplaybasebin.c: (setup_source):
Being in non-playing state (after, e.g., EOS) is not necessarily
a bad thing. Allow for that. This fixes playback of short files.
They don't actually playback fully now, because the clock already
runs. This means that small files (<500kB) with a small length
(<2sec) will still not or barely play. Other files, such as mod
or flx, will work correctly, however.
2004-09-29 09:45:40 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (flxdec_debug);
|
|
|
|
#define GST_CAT_DEFAULT flxdec_debug
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
/* input */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-fli")
|
|
|
|
);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-02-24 23:46:09 +00:00
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
|
|
|
#define RGB_ORDER "xRGB"
|
|
|
|
#else
|
|
|
|
#define RGB_ORDER "BGRx"
|
|
|
|
#endif
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
/* output */
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstStaticPadTemplate src_video_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
2016-02-24 23:46:09 +00:00
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (RGB_ORDER))
|
2004-03-14 22:34:33 +00:00
|
|
|
);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
Fix a bunch of leaks shown by the newly-added states test.
Original commit message from CVS:
* ext/flac/gstflacenc.c: (gst_flac_enc_finalize):
* ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init),
(gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize):
* ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init),
(gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose),
(gst_gconf_audio_src_finalize), (do_toggle_element):
* ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init),
(gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize),
(do_toggle_element):
* ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init),
(gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose),
(gst_gconf_video_src_finalize), (do_toggle_element):
* ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init),
(gst_switch_sink_reset), (gst_switch_sink_set_child):
* ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init):
* ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init):
* ext/shout2/gstshout2.c: (gst_shout2send_class_init),
(gst_shout2send_init), (gst_shout2send_finalize):
* gst/debug/testplugin.c: (gst_test_class_init),
(gst_test_finalize):
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(gst_flxdec_dispose):
* gst/multipart/multipartmux.c: (gst_multipart_mux_finalize):
* gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize):
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init),
(gst_rtspsrc_finalize):
* gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context):
* gst/rtsp/rtspextwms.h:
* gst/smpte/gstsmpte.c: (gst_smpte_class_init),
(gst_smpte_finalize):
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize):
* gst/udp/gstudpsink.c: (gst_udpsink_class_init),
(gst_udpsink_finalize):
* gst/wavparse/gstwavparse.c: (gst_wavparse_dispose),
(gst_wavparse_sink_activate):
* sys/oss/gstosssink.c: (gst_oss_sink_finalise):
* sys/oss/gstosssrc.c: (gst_oss_src_class_init),
(gst_oss_src_finalize):
* sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_finalize):
* sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get):
Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
|
|
|
static void gst_flxdec_dispose (GstFlxDec * flxdec);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2012-04-13 14:54:46 +00:00
|
|
|
static GstFlowReturn gst_flxdec_chain (GstPad * pad, GstObject * parent,
|
|
|
|
GstBuffer * buf);
|
2012-04-13 14:54:50 +00:00
|
|
|
static gboolean gst_flxdec_sink_event_handler (GstPad * pad,
|
|
|
|
GstObject * parent, GstEvent * event);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-09-02 15:44:50 +00:00
|
|
|
static GstStateChangeReturn gst_flxdec_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2012-04-13 14:54:46 +00:00
|
|
|
static gboolean gst_flxdec_src_query_handler (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query);
|
2005-10-16 21:19:44 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
static gboolean flx_decode_color (GstFlxDec * flxdec, GstByteReader * reader,
|
|
|
|
GstByteWriter * writer, gint scale);
|
|
|
|
static gboolean flx_decode_brun (GstFlxDec * flxdec,
|
|
|
|
GstByteReader * reader, GstByteWriter * writer);
|
|
|
|
static gboolean flx_decode_delta_fli (GstFlxDec * flxdec,
|
|
|
|
GstByteReader * reader, GstByteWriter * writer);
|
|
|
|
static gboolean flx_decode_delta_flc (GstFlxDec * flxdec,
|
|
|
|
GstByteReader * reader, GstByteWriter * writer);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2006-02-19 11:57:58 +00:00
|
|
|
#define rndalign(off) ((off) + ((off) & 1))
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2012-04-13 14:54:46 +00:00
|
|
|
#define gst_flxdec_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstFlxDec, gst_flxdec, GST_TYPE_ELEMENT);
|
2021-02-16 08:51:16 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE (flxdec, "flxdec",
|
|
|
|
GST_RANK_PRIMARY, GST_TYPE_FLXDEC);
|
2003-11-02 17:36:30 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_flxdec_class_init (GstFlxDecClass * klass)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2006-04-08 21:21:45 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
Fix a bunch of leaks shown by the newly-added states test.
Original commit message from CVS:
* ext/flac/gstflacenc.c: (gst_flac_enc_finalize):
* ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init),
(gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize):
* ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init),
(gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose),
(gst_gconf_audio_src_finalize), (do_toggle_element):
* ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init),
(gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize),
(do_toggle_element):
* ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init),
(gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose),
(gst_gconf_video_src_finalize), (do_toggle_element):
* ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init),
(gst_switch_sink_reset), (gst_switch_sink_set_child):
* ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init):
* ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init):
* ext/shout2/gstshout2.c: (gst_shout2send_class_init),
(gst_shout2send_init), (gst_shout2send_finalize):
* gst/debug/testplugin.c: (gst_test_class_init),
(gst_test_finalize):
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(gst_flxdec_dispose):
* gst/multipart/multipartmux.c: (gst_multipart_mux_finalize):
* gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize):
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init),
(gst_rtspsrc_finalize):
* gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context):
* gst/rtsp/rtspextwms.h:
* gst/smpte/gstsmpte.c: (gst_smpte_class_init),
(gst_smpte_finalize):
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize):
* gst/udp/gstudpsink.c: (gst_udpsink_class_init),
(gst_udpsink_finalize):
* gst/wavparse/gstwavparse.c: (gst_wavparse_dispose),
(gst_wavparse_sink_activate):
* sys/oss/gstosssink.c: (gst_oss_sink_finalise):
* sys/oss/gstosssrc.c: (gst_oss_src_class_init),
(gst_oss_src_finalize):
* sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_finalize):
* sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get):
Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
|
|
|
gobject_class->dispose = (GObjectFinalizeFunc) gst_flxdec_dispose;
|
|
|
|
|
ext/flac/gstflacdec.c: Only return true if we actually filled something in. Prevents player applications from showing...
Original commit message from CVS:
* ext/flac/gstflacdec.c: (gst_flacdec_src_query):
Only return true if we actually filled something in. Prevents
player applications from showing a random length for flac files.
* gst-libs/gst/riff/riff-read.c: (gst_riff_read_class_init),
(gst_riff_read_use_event), (gst_riff_read_handle_event),
(gst_riff_read_seek), (gst_riff_read_skip), (gst_riff_read_strh),
(gst_riff_read_strf_vids_with_data),
(gst_riff_read_strf_auds_with_data), (gst_riff_read_strf_iavs):
OK, ok, so I implemented event handling. Apparently it's normal
that we receive random events at random points without asking
for it.
* gst/avi/gstavidemux.c: (gst_avi_demux_reset),
(gst_avi_demux_src_convert), (gst_avi_demux_handle_src_query),
(gst_avi_demux_handle_src_event), (gst_avi_demux_stream_index),
(gst_avi_demux_sync), (gst_avi_demux_stream_scan),
(gst_avi_demux_massage_index), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry),
(gst_avi_demux_stream_data), (gst_avi_demux_loop):
* gst/avi/gstavidemux.h:
Implement non-lineair chunk handling and subchunk processing.
The first solves playback of AVI files where the audio and video
data of individual buffers that we read are not synchronized.
This should not happen according to the wonderful AVI specs, but
of course it does happen in reality. It is also a prerequisite for
the second. Subchunk processing allows us to cut chunks in small
pieces and process each of these pieces separately. This is
required because I've seen several AVI files with incredibly large
audio chunks, even some files with only one audio chunk for the
whole file. This allows for proper playback including seeking.
This patch is supposed to fix all AVI A/V sync issues.
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(flx_decode_chunks), (flx_decode_color), (gst_flxdec_loop):
Work.
* gst/modplug/gstmodplug.cc:
Proper return value setting for the query() function.
* gst/playback/gstplaybasebin.c: (setup_source):
Being in non-playing state (after, e.g., EOS) is not necessarily
a bad thing. Allow for that. This fixes playback of short files.
They don't actually playback fully now, because the clock already
runs. This means that small files (<500kB) with a small length
(<2sec) will still not or barely play. Other files, such as mod
or flx, will work correctly, however.
2004-09-29 09:45:40 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (flxdec_debug, "flxdec", 0, "FLX video decoder");
|
|
|
|
|
2012-04-13 14:54:46 +00:00
|
|
|
gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_flxdec_change_state);
|
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (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));
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_flxdec_init (GstFlxDec * flxdec)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2006-03-15 16:17:12 +00:00
|
|
|
flxdec->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (flxdec), flxdec->sinkpad);
|
2012-04-13 14:54:46 +00:00
|
|
|
gst_pad_set_chain_function (flxdec->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_flxdec_chain));
|
2012-04-13 14:54:50 +00:00
|
|
|
gst_pad_set_event_function (flxdec->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_flxdec_sink_event_handler));
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2006-03-15 16:17:12 +00:00
|
|
|
flxdec->srcpad = gst_pad_new_from_static_template (&src_video_factory, "src");
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (flxdec), flxdec->srcpad);
|
2012-04-13 14:54:46 +00:00
|
|
|
gst_pad_set_query_function (flxdec->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_flxdec_src_query_handler));
|
2005-10-16 21:19:44 +00:00
|
|
|
|
|
|
|
gst_pad_use_fixed_caps (flxdec->srcpad);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
flxdec->adapter = gst_adapter_new ();
|
|
|
|
}
|
|
|
|
|
Fix a bunch of leaks shown by the newly-added states test.
Original commit message from CVS:
* ext/flac/gstflacenc.c: (gst_flac_enc_finalize):
* ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_class_init),
(gst_gconf_audio_sink_dispose), (gst_gconf_audio_sink_finalize):
* ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init),
(gst_gconf_audio_src_class_init), (gst_gconf_audio_src_dispose),
(gst_gconf_audio_src_finalize), (do_toggle_element):
* ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init),
(gst_gconf_video_sink_class_init), (gst_gconf_video_sink_finalize),
(do_toggle_element):
* ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init),
(gst_gconf_video_src_class_init), (gst_gconf_video_src_dispose),
(gst_gconf_video_src_finalize), (do_toggle_element):
* ext/gconf/gstswitchsink.c: (gst_switch_sink_class_init),
(gst_switch_sink_reset), (gst_switch_sink_set_child):
* ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init):
* ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init):
* ext/shout2/gstshout2.c: (gst_shout2send_class_init),
(gst_shout2send_init), (gst_shout2send_finalize):
* gst/debug/testplugin.c: (gst_test_class_init),
(gst_test_finalize):
* gst/flx/gstflxdec.c: (gst_flxdec_class_init),
(gst_flxdec_dispose):
* gst/multipart/multipartmux.c: (gst_multipart_mux_finalize):
* gst/rtp/gstrtpmp4gpay.c: (gst_rtp_mp4g_pay_finalize):
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_init),
(gst_rtspsrc_finalize):
* gst/rtsp/rtspextwms.c: (rtsp_ext_wms_free_context):
* gst/rtsp/rtspextwms.h:
* gst/smpte/gstsmpte.c: (gst_smpte_class_init),
(gst_smpte_finalize):
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_finalize):
* gst/udp/gstudpsink.c: (gst_udpsink_class_init),
(gst_udpsink_finalize):
* gst/wavparse/gstwavparse.c: (gst_wavparse_dispose),
(gst_wavparse_sink_activate):
* sys/oss/gstosssink.c: (gst_oss_sink_finalise):
* sys/oss/gstosssrc.c: (gst_oss_src_class_init),
(gst_oss_src_finalize):
* sys/v4l2/gstv4l2object.c: (gst_v4l2_object_destroy):
* sys/v4l2/gstv4l2object.h:
* sys/v4l2/gstv4l2src.c: (gst_v4l2src_class_init),
(gst_v4l2src_finalize):
* sys/ximage/gstximagesrc.c: (gst_ximage_src_ximage_get):
Fix a bunch of leaks shown by the newly-added states test.
2007-03-04 13:52:03 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-02-19 11:57:58 +00:00
|
|
|
static gboolean
|
2012-04-13 14:54:46 +00:00
|
|
|
gst_flxdec_src_query_handler (GstPad * pad, GstObject * parent,
|
|
|
|
GstQuery * query)
|
2006-02-19 11:57:58 +00:00
|
|
|
{
|
2012-04-13 14:54:46 +00:00
|
|
|
GstFlxDec *flxdec = (GstFlxDec *) parent;
|
2006-02-19 11:57:58 +00:00
|
|
|
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:
|
2012-04-13 14:54:46 +00:00
|
|
|
if (!ret)
|
|
|
|
ret = gst_pad_query_default (pad, parent, query);
|
2005-11-21 18:09:02 +00:00
|
|
|
|
|
|
|
return ret;
|
2005-10-16 21:19:44 +00:00
|
|
|
}
|
|
|
|
|
2012-04-13 14:54:50 +00:00
|
|
|
static gboolean
|
|
|
|
gst_flxdec_sink_event_handler (GstPad * pad, GstObject * parent,
|
|
|
|
GstEvent * event)
|
|
|
|
{
|
|
|
|
GstFlxDec *flxdec;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
flxdec = GST_FLXDEC (parent);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEGMENT:
|
|
|
|
{
|
2016-12-09 15:55:39 +00:00
|
|
|
gst_event_copy_segment (event, &flxdec->segment);
|
|
|
|
if (flxdec->segment.format != GST_FORMAT_TIME) {
|
2012-04-13 14:54:50 +00:00
|
|
|
GST_DEBUG_OBJECT (flxdec, "generating TIME segment");
|
2016-12-09 15:55:39 +00:00
|
|
|
gst_segment_init (&flxdec->segment, GST_FORMAT_TIME);
|
|
|
|
gst_event_unref (event);
|
|
|
|
event = gst_event_new_segment (&flxdec->segment);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gst_pad_has_current_caps (flxdec->srcpad)) {
|
|
|
|
ret = gst_pad_event_default (pad, parent, event);
|
|
|
|
} else {
|
|
|
|
flxdec->need_segment = TRUE;
|
2012-04-13 14:54:50 +00:00
|
|
|
gst_event_unref (event);
|
2016-12-09 15:55:39 +00:00
|
|
|
ret = TRUE;
|
2012-04-13 14:54:50 +00:00
|
|
|
}
|
2016-12-09 15:55:39 +00:00
|
|
|
break;
|
2012-04-13 14:54:50 +00:00
|
|
|
}
|
2016-12-09 15:55:39 +00:00
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
gst_segment_init (&flxdec->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
ret = gst_pad_event_default (pad, parent, event);
|
|
|
|
break;
|
2012-04-13 14:54:50 +00:00
|
|
|
default:
|
|
|
|
ret = gst_pad_event_default (pad, parent, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
static gboolean
|
2016-11-22 20:09:06 +00:00
|
|
|
flx_decode_chunks (GstFlxDec * flxdec, gulong n_chunks, GstByteReader * reader,
|
|
|
|
GstByteWriter * writer)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2016-11-22 08:05:00 +00:00
|
|
|
gboolean ret = TRUE;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
while (n_chunks--) {
|
|
|
|
GstByteReader chunk;
|
|
|
|
guint32 size;
|
|
|
|
guint16 type;
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &size))
|
|
|
|
goto parse_error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &type))
|
|
|
|
goto parse_error;
|
|
|
|
GST_LOG_OBJECT (flxdec, "chunk has type 0x%02x size %d", type, size);
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_sub_reader (reader, &chunk,
|
|
|
|
size - FlxFrameChunkSize)) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Incorrect size in the chunk header");
|
|
|
|
goto error;
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
switch (type) {
|
2001-12-22 23:27:31 +00:00
|
|
|
case FLX_COLOR64:
|
2016-11-22 20:09:06 +00:00
|
|
|
ret = flx_decode_color (flxdec, &chunk, writer, 2);
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2002-01-18 18:41:58 +00:00
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
case FLX_COLOR256:
|
2016-11-22 20:09:06 +00:00
|
|
|
ret = flx_decode_color (flxdec, &chunk, writer, 0);
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
case FLX_BRUN:
|
2016-11-22 20:09:06 +00:00
|
|
|
ret = flx_decode_brun (flxdec, &chunk, writer);
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
case FLX_LC:
|
2016-11-22 20:09:06 +00:00
|
|
|
ret = flx_decode_delta_fli (flxdec, &chunk, writer);
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
case FLX_SS2:
|
2016-11-22 20:09:06 +00:00
|
|
|
ret = flx_decode_delta_flc (flxdec, &chunk, writer);
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
case FLX_BLACK:
|
2016-11-22 20:09:06 +00:00
|
|
|
ret = gst_byte_writer_fill (writer, 0, flxdec->size);
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
case FLX_MINI:
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
default:
|
2016-11-22 20:09:06 +00:00
|
|
|
GST_WARNING ("Unimplemented chunk type: 0x%02x size: %d - skipping",
|
|
|
|
type, size);
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2016-11-22 08:05:00 +00:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2016-11-22 08:05:00 +00:00
|
|
|
|
|
|
|
return ret;
|
2016-11-22 20:09:06 +00:00
|
|
|
|
|
|
|
parse_error:
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Failed to decode chunk");
|
|
|
|
error:
|
|
|
|
return FALSE;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
static gboolean
|
|
|
|
flx_decode_color (GstFlxDec * flxdec, GstByteReader * reader,
|
|
|
|
GstByteWriter * writer, gint scale)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2016-11-22 20:09:06 +00:00
|
|
|
guint8 count, indx;
|
|
|
|
guint16 packs;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &packs))
|
|
|
|
goto error;
|
2004-03-14 22:34:33 +00:00
|
|
|
indx = 0;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
GST_LOG ("GstFlxDec: cmap packs: %d", (guint) packs);
|
2001-12-22 23:27:31 +00:00
|
|
|
while (packs--) {
|
2016-11-22 20:09:06 +00:00
|
|
|
const guint8 *data;
|
|
|
|
guint16 actual_count;
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
/* color map index + skip count */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_uint8 (reader, &indx))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* number of rgb triplets */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_uint8 (reader, &count))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
actual_count = count == 0 ? 256 : count;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_data (reader, count * 3, &data))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (flxdec, "cmap count: %d (indx: %d)", actual_count, indx);
|
|
|
|
flx_set_palette_vector (flxdec->converter, indx, actual_count,
|
|
|
|
(guchar *) data, scale);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2016-11-22 20:09:06 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Error decoding color palette");
|
|
|
|
return FALSE;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
static gboolean
|
2016-11-22 20:09:06 +00:00
|
|
|
flx_decode_brun (GstFlxDec * flxdec, GstByteReader * reader,
|
|
|
|
GstByteWriter * writer)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2016-11-22 20:09:06 +00:00
|
|
|
gulong lines, row;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
g_return_val_if_fail (flxdec != NULL, FALSE);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
lines = flxdec->hdr.height;
|
2004-03-14 22:34:33 +00:00
|
|
|
while (lines--) {
|
2001-12-22 23:27:31 +00:00
|
|
|
/* packet count.
|
|
|
|
* should not be used anymore, since the flc format can
|
|
|
|
* contain more then 255 RLE packets. we use the frame
|
|
|
|
* width instead.
|
|
|
|
*/
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_skip (reader, 1))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
row = flxdec->hdr.width;
|
2004-03-14 22:34:33 +00:00
|
|
|
while (row) {
|
2016-11-22 20:09:06 +00:00
|
|
|
gint8 count;
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_int8 (reader, &count))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (count <= 0) {
|
|
|
|
const guint8 *data;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
/* literal run */
|
2016-11-22 20:09:06 +00:00
|
|
|
count = ABS (count);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (flxdec, "have literal run of size %d", count);
|
|
|
|
|
|
|
|
if (count > row) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid BRUN line detected. "
|
|
|
|
"bytes to write exceeds the end of the row");
|
2016-11-22 08:05:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-15 19:32:27 +00:00
|
|
|
row -= count;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_data (reader, count, &data))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_writer_put_data (writer, data, count))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
} else {
|
2016-11-22 20:09:06 +00:00
|
|
|
guint8 x;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (flxdec, "have replicate run of size %d", count);
|
|
|
|
|
|
|
|
if (count > row) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid BRUN packet detected."
|
|
|
|
"bytes to write exceeds the end of the row");
|
2016-11-22 08:05:00 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
/* replicate run */
|
|
|
|
row -= count;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_uint8 (reader, &x))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_writer_fill (writer, x, count))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-22 08:05:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2016-11-22 20:09:06 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Failed to decode BRUN packet");
|
|
|
|
return FALSE;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
static gboolean
|
2016-11-22 20:09:06 +00:00
|
|
|
flx_decode_delta_fli (GstFlxDec * flxdec, GstByteReader * reader,
|
|
|
|
GstByteWriter * writer)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2016-11-22 20:09:06 +00:00
|
|
|
guint16 start_line, lines;
|
|
|
|
guint line_start_i;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
g_return_val_if_fail (flxdec != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (flxdec->delta_data != NULL, FALSE);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* use last frame for delta */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_writer_put_data (writer, flxdec->delta_data, flxdec->size))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &start_line))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &lines))
|
|
|
|
goto error;
|
|
|
|
GST_LOG_OBJECT (flxdec, "height %d start line %d line count %d",
|
|
|
|
flxdec->hdr.height, start_line, lines);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
if (start_line + lines > flxdec->hdr.height) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid FLI packet detected. too many lines.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
line_start_i = flxdec->hdr.width * start_line;
|
|
|
|
if (!gst_byte_writer_set_pos (writer, line_start_i))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
while (lines--) {
|
2016-11-22 20:09:06 +00:00
|
|
|
guint8 packets;
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
/* packet count */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_uint8 (reader, &packets))
|
|
|
|
goto error;
|
|
|
|
GST_LOG_OBJECT (flxdec, "have %d packets", packets);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
while (packets--) {
|
2001-12-22 23:27:31 +00:00
|
|
|
/* skip count */
|
2016-11-22 20:09:06 +00:00
|
|
|
guint8 skip;
|
|
|
|
gint8 count;
|
|
|
|
if (!gst_byte_reader_get_uint8 (reader, &skip))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* skip bytes */
|
|
|
|
if (!gst_byte_writer_set_pos (writer,
|
|
|
|
gst_byte_writer_get_pos (writer) + skip))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* RLE count */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_int8 (reader, &count))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (count < 0) {
|
|
|
|
guint8 x;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
/* literal run */
|
2016-11-22 20:09:06 +00:00
|
|
|
count = ABS (count);
|
|
|
|
GST_LOG_OBJECT (flxdec, "have literal run of size %d at offset %d",
|
|
|
|
count, skip);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
if (skip + count > flxdec->hdr.width) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid FLI packet detected. "
|
|
|
|
"line too long.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_uint8 (reader, &x))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_writer_fill (writer, x, count))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
} else {
|
2016-11-22 20:09:06 +00:00
|
|
|
const guint8 *data;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (flxdec, "have replicate run of size %d at offset %d",
|
|
|
|
count, skip);
|
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
if (skip + count > flxdec->hdr.width) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid FLI packet detected. "
|
|
|
|
"line too long.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
/* replicate run */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_data (reader, count, &data))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_writer_put_data (writer, data, count))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-22 20:09:06 +00:00
|
|
|
line_start_i += flxdec->hdr.width;
|
|
|
|
if (!gst_byte_writer_set_pos (writer, line_start_i))
|
|
|
|
goto error;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2016-11-22 08:05:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2016-11-22 20:09:06 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Failed to decode FLI packet");
|
|
|
|
return FALSE;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
static gboolean
|
2016-11-22 20:09:06 +00:00
|
|
|
flx_decode_delta_flc (GstFlxDec * flxdec, GstByteReader * reader,
|
|
|
|
GstByteWriter * writer)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2016-11-22 20:09:06 +00:00
|
|
|
guint16 lines, start_l;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
g_return_val_if_fail (flxdec != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (flxdec->delta_data != NULL, FALSE);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* use last frame for delta */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_writer_put_data (writer, flxdec->delta_data, flxdec->size))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &lines))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
if (lines > flxdec->hdr.height) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid FLC packet detected. too many lines.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
start_l = lines;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-18 19:41:04 +00:00
|
|
|
while (lines) {
|
2016-11-22 20:09:06 +00:00
|
|
|
guint16 opcode;
|
|
|
|
|
|
|
|
if (!gst_byte_writer_set_pos (writer,
|
|
|
|
flxdec->hdr.width * (start_l - lines)))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
|
|
|
/* process opcode(s) */
|
2016-11-22 20:09:06 +00:00
|
|
|
while (TRUE) {
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &opcode))
|
|
|
|
goto error;
|
|
|
|
if ((opcode & 0xc000) == 0)
|
|
|
|
break;
|
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
if ((opcode & 0xc000) == 0xc000) {
|
2016-11-22 08:05:00 +00:00
|
|
|
/* line skip count */
|
|
|
|
gulong skip = (0x10000 - opcode);
|
|
|
|
if (skip > flxdec->hdr.height) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid FLC packet detected. "
|
|
|
|
"skip line count too big.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
start_l += skip;
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_writer_set_pos (writer,
|
|
|
|
gst_byte_writer_get_pos (writer) + flxdec->hdr.width * skip))
|
|
|
|
goto error;
|
2001-12-22 23:27:31 +00:00
|
|
|
} else {
|
2004-03-15 19:32:27 +00:00
|
|
|
/* last pixel */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_writer_set_pos (writer,
|
|
|
|
gst_byte_writer_get_pos (writer) + flxdec->hdr.width))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_writer_put_uint8 (writer, opcode & 0xff))
|
|
|
|
goto error;
|
2004-03-14 22:34:33 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* last opcode is the packet count */
|
2016-11-22 20:09:06 +00:00
|
|
|
GST_LOG_OBJECT (flxdec, "have %d packets", opcode);
|
2004-03-14 22:34:33 +00:00
|
|
|
while (opcode--) {
|
2001-12-22 23:27:31 +00:00
|
|
|
/* skip count */
|
2016-11-22 20:09:06 +00:00
|
|
|
guint8 skip;
|
|
|
|
gint8 count;
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_uint8 (reader, &skip))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_writer_set_pos (writer,
|
|
|
|
gst_byte_writer_get_pos (writer) + skip))
|
|
|
|
goto error;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2001-12-22 23:27:31 +00:00
|
|
|
/* RLE count */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_int8 (reader, &count))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (count < 0) {
|
|
|
|
guint16 x;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
/* replicate word run */
|
2016-11-22 20:09:06 +00:00
|
|
|
count = ABS (count);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (flxdec, "have replicate run of size %d at offset %d",
|
|
|
|
count, skip);
|
2016-11-22 08:05:00 +00:00
|
|
|
|
|
|
|
if (skip + count > flxdec->hdr.width) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid FLC packet detected. "
|
|
|
|
"line too long.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &x))
|
|
|
|
goto error;
|
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
while (count--) {
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_writer_put_uint16_le (writer, x)) {
|
|
|
|
goto error;
|
|
|
|
}
|
2004-03-15 19:32:27 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
} else {
|
2016-11-22 20:09:06 +00:00
|
|
|
GST_LOG_OBJECT (flxdec, "have literal run of size %d at offset %d",
|
|
|
|
count, skip);
|
|
|
|
|
2016-11-22 08:05:00 +00:00
|
|
|
if (skip + count > flxdec->hdr.width) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid FLC packet detected. "
|
|
|
|
"line too long.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
while (count--) {
|
2016-11-22 20:09:06 +00:00
|
|
|
guint16 x;
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &x))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_writer_put_uint16_le (writer, x))
|
|
|
|
goto error;
|
2004-03-15 19:32:27 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-18 19:41:04 +00:00
|
|
|
lines--;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2016-11-22 08:05:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2016-11-22 20:09:06 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Failed to decode FLI packet");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_read_flx_header (GstFlxDec * flxdec, GstByteReader * reader, FlxHeader * flxh)
|
|
|
|
{
|
|
|
|
memset (flxh, 0, sizeof (*flxh));
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &flxh->size))
|
|
|
|
goto error;
|
|
|
|
if (flxh->size < FlxHeaderSize) {
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Invalid file size in the header");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->type))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->frames))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->width))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->height))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->depth))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->flags))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &flxh->speed))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_skip (reader, 2)) /* reserved */
|
|
|
|
goto error;
|
|
|
|
/* FLC */
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &flxh->created))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &flxh->creator))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &flxh->updated))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &flxh->updater))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->aspect_dx))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->aspect_dy))
|
|
|
|
goto error;
|
|
|
|
/* EGI */
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->ext_flags))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->keyframes))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->totalframes))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &flxh->req_memory))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->max_regions))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint16_le (reader, &flxh->transp_num))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_skip (reader, 24)) /* reserved */
|
|
|
|
goto error;
|
|
|
|
/* FLC */
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &flxh->oframe1))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_get_uint32_le (reader, &flxh->oframe2))
|
|
|
|
goto error;
|
|
|
|
if (!gst_byte_reader_skip (reader, 40)) /* reserved */
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
GST_ERROR_OBJECT (flxdec, "Error reading file header");
|
|
|
|
return FALSE;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
static GstFlowReturn
|
2012-04-13 14:54:46 +00:00
|
|
|
gst_flxdec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2016-11-22 20:09:06 +00:00
|
|
|
GstByteReader reader;
|
|
|
|
GstBuffer *input;
|
|
|
|
GstMapInfo map_info;
|
2004-03-14 22:34:33 +00:00
|
|
|
GstCaps *caps;
|
2016-11-22 20:09:06 +00:00
|
|
|
guint available;
|
2005-10-16 21:19:44 +00:00
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
GstFlxDec *flxdec;
|
|
|
|
FlxHeader *flxh;
|
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
|
2012-04-13 14:54:46 +00:00
|
|
|
flxdec = (GstFlxDec *) parent;
|
2005-10-16 21:19:44 +00:00
|
|
|
g_return_val_if_fail (flxdec != NULL, GST_FLOW_ERROR);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
gst_adapter_push (flxdec->adapter, buf);
|
2016-11-22 20:09:06 +00:00
|
|
|
available = gst_adapter_available (flxdec->adapter);
|
|
|
|
input = gst_adapter_get_buffer (flxdec->adapter, available);
|
|
|
|
if (!gst_buffer_map (input, &map_info, GST_MAP_READ)) {
|
|
|
|
GST_ELEMENT_ERROR (flxdec, STREAM, DECODE,
|
|
|
|
("%s", "Failed to map buffer"), (NULL));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
gst_byte_reader_init (&reader, map_info.data, map_info.size);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2002-01-13 22:27:25 +00:00
|
|
|
if (flxdec->state == GST_FLXDEC_READ_HEADER) {
|
2016-11-22 20:09:06 +00:00
|
|
|
if (available >= FlxHeaderSize) {
|
|
|
|
GstByteReader header;
|
2012-04-13 14:54:46 +00:00
|
|
|
GstCaps *templ;
|
2002-01-19 18:46:23 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_sub_reader (&reader, &header, FlxHeaderSize)) {
|
|
|
|
GST_ELEMENT_ERROR (flxdec, STREAM, DECODE,
|
|
|
|
("%s", "Could not read header"), (NULL));
|
|
|
|
goto unmap_input_error;
|
|
|
|
}
|
2005-10-16 21:19:44 +00:00
|
|
|
gst_adapter_flush (flxdec->adapter, FlxHeaderSize);
|
2016-11-22 20:09:06 +00:00
|
|
|
available -= FlxHeaderSize;
|
|
|
|
|
|
|
|
if (!_read_flx_header (flxdec, &header, &flxdec->hdr)) {
|
|
|
|
GST_ELEMENT_ERROR (flxdec, STREAM, DECODE,
|
|
|
|
("%s", "Failed to parse header"), (NULL));
|
|
|
|
goto unmap_input_error;
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
flxh = &flxdec->hdr;
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
/* check header */
|
|
|
|
if (flxh->type != FLX_MAGICHDR_FLI &&
|
2016-11-22 20:09:06 +00:00
|
|
|
flxh->type != FLX_MAGICHDR_FLC && flxh->type != FLX_MAGICHDR_FLX) {
|
|
|
|
GST_ELEMENT_ERROR (flxdec, STREAM, WRONG_TYPE, (NULL),
|
|
|
|
("not a flx file (type %x)", flxh->type));
|
|
|
|
goto unmap_input_error;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
GST_INFO_OBJECT (flxdec, "size : %d", flxh->size);
|
|
|
|
GST_INFO_OBJECT (flxdec, "frames : %d", flxh->frames);
|
|
|
|
GST_INFO_OBJECT (flxdec, "width : %d", flxh->width);
|
|
|
|
GST_INFO_OBJECT (flxdec, "height : %d", flxh->height);
|
|
|
|
GST_INFO_OBJECT (flxdec, "depth : %d", flxh->depth);
|
|
|
|
GST_INFO_OBJECT (flxdec, "speed : %d", flxh->speed);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
flxdec->next_time = 0;
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
if (flxh->type == FLX_MAGICHDR_FLI) {
|
|
|
|
flxdec->frame_time = JIFFIE * flxh->speed;
|
2005-12-13 10:45:04 +00:00
|
|
|
} else if (flxh->speed == 0) {
|
|
|
|
flxdec->frame_time = GST_SECOND / 70;
|
2005-10-16 21:19:44 +00:00
|
|
|
} else {
|
|
|
|
flxdec->frame_time = flxh->speed * GST_MSECOND;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2006-02-19 11:57:58 +00:00
|
|
|
flxdec->duration = flxh->frames * flxdec->frame_time;
|
2006-02-19 12:09:19 +00:00
|
|
|
GST_LOG ("duration : %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (flxdec->duration));
|
2006-02-19 11:57:58 +00:00
|
|
|
|
2012-04-13 14:54:46 +00:00
|
|
|
templ = gst_pad_get_pad_template_caps (flxdec->srcpad);
|
|
|
|
caps = gst_caps_copy (templ);
|
|
|
|
gst_caps_unref (templ);
|
2005-10-16 21:19:44 +00:00
|
|
|
gst_caps_set_simple (caps,
|
|
|
|
"width", G_TYPE_INT, flxh->width,
|
|
|
|
"height", G_TYPE_INT, flxh->height,
|
2005-11-22 22:21:37 +00:00
|
|
|
"framerate", GST_TYPE_FRACTION, (gint) GST_MSECOND,
|
|
|
|
(gint) flxdec->frame_time / 1000, NULL);
|
2005-10-16 21:19:44 +00:00
|
|
|
|
|
|
|
gst_pad_set_caps (flxdec->srcpad, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2016-12-09 15:55:39 +00:00
|
|
|
if (flxdec->need_segment) {
|
|
|
|
gst_pad_push_event (flxdec->srcpad,
|
|
|
|
gst_event_new_segment (&flxdec->segment));
|
|
|
|
flxdec->need_segment = FALSE;
|
|
|
|
}
|
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
/* zero means 8 */
|
|
|
|
if (flxh->depth == 0)
|
|
|
|
flxh->depth = 8;
|
|
|
|
|
|
|
|
if (flxh->depth != 8) {
|
|
|
|
GST_ELEMENT_ERROR (flxdec, STREAM, WRONG_TYPE,
|
|
|
|
("%s", "Don't know how to decode non 8 bit depth streams"), (NULL));
|
|
|
|
goto unmap_input_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
flxdec->converter =
|
|
|
|
flx_colorspace_converter_new (flxh->width, flxh->height);
|
2005-10-16 21:19:44 +00:00
|
|
|
|
|
|
|
if (flxh->type == FLX_MAGICHDR_FLC || flxh->type == FLX_MAGICHDR_FLX) {
|
2016-11-22 20:09:06 +00:00
|
|
|
GST_INFO_OBJECT (flxdec, "(FLC) aspect_dx : %d", flxh->aspect_dx);
|
|
|
|
GST_INFO_OBJECT (flxdec, "(FLC) aspect_dy : %d", flxh->aspect_dy);
|
|
|
|
GST_INFO_OBJECT (flxdec, "(FLC) oframe1 : 0x%08x", flxh->oframe1);
|
|
|
|
GST_INFO_OBJECT (flxdec, "(FLC) oframe2 : 0x%08x", flxh->oframe2);
|
2005-10-16 21:19:44 +00:00
|
|
|
}
|
2004-10-06 13:56:07 +00:00
|
|
|
|
2014-05-02 13:18:08 +00:00
|
|
|
flxdec->size = ((guint) flxh->width * (guint) flxh->height);
|
2016-11-22 20:09:06 +00:00
|
|
|
if (flxdec->size >= G_MAXSIZE / 4) {
|
|
|
|
GST_ELEMENT_ERROR (flxdec, STREAM, DECODE,
|
|
|
|
("%s", "Cannot allocate required memory"), (NULL));
|
|
|
|
goto unmap_input_error;
|
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
/* create delta and output frame */
|
2016-12-06 05:48:47 +00:00
|
|
|
flxdec->frame_data = g_malloc0 (flxdec->size);
|
|
|
|
flxdec->delta_data = g_malloc0 (flxdec->size);
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
flxdec->state = GST_FLXDEC_PLAYING;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
} 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
|
|
|
|
2006-02-19 11:57:58 +00:00
|
|
|
/* while we have enough data in the adapter */
|
2016-11-22 20:09:06 +00:00
|
|
|
while (available >= FlxFrameChunkSize && res == GST_FLOW_OK) {
|
|
|
|
guint32 size;
|
|
|
|
guint16 type;
|
2005-10-16 21:19:44 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!gst_byte_reader_get_uint32_le (&reader, &size))
|
|
|
|
goto parse_error;
|
|
|
|
if (available < size)
|
|
|
|
goto need_more_data;
|
2012-04-13 14:54:46 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
available -= size;
|
|
|
|
gst_adapter_flush (flxdec->adapter, size);
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_uint16_le (&reader, &type))
|
|
|
|
goto parse_error;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case FLX_FRAME_TYPE:{
|
|
|
|
GstByteReader chunks;
|
|
|
|
GstByteWriter writer;
|
|
|
|
guint16 n_chunks;
|
|
|
|
GstMapInfo map;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (flxdec, "Have frame type 0x%02x of size %d", type,
|
|
|
|
size);
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_sub_reader (&reader, &chunks,
|
|
|
|
size - FlxFrameChunkSize))
|
|
|
|
goto parse_error;
|
|
|
|
|
|
|
|
if (!gst_byte_reader_get_uint16_le (&chunks, &n_chunks))
|
|
|
|
goto parse_error;
|
|
|
|
GST_LOG_OBJECT (flxdec, "Have %d chunks", n_chunks);
|
|
|
|
|
|
|
|
if (n_chunks == 0)
|
|
|
|
break;
|
|
|
|
if (!gst_byte_reader_skip (&chunks, 8)) /* reserved */
|
|
|
|
goto parse_error;
|
|
|
|
|
|
|
|
gst_byte_writer_init_with_data (&writer, flxdec->frame_data,
|
|
|
|
flxdec->size, TRUE);
|
2005-10-16 21:19:44 +00:00
|
|
|
|
|
|
|
/* decode chunks */
|
2016-11-22 20:09:06 +00:00
|
|
|
if (!flx_decode_chunks (flxdec, n_chunks, &chunks, &writer)) {
|
2016-11-22 08:05:00 +00:00
|
|
|
GST_ELEMENT_ERROR (flxdec, STREAM, DECODE,
|
|
|
|
("%s", "Could not decode chunk"), NULL);
|
2016-11-22 20:09:06 +00:00
|
|
|
goto unmap_input_error;
|
2016-11-22 08:05:00 +00:00
|
|
|
}
|
2016-11-22 20:09:06 +00:00
|
|
|
gst_byte_writer_reset (&writer);
|
2005-10-16 21:19:44 +00:00
|
|
|
|
|
|
|
/* save copy of the current frame for possible delta. */
|
2012-04-13 14:54:46 +00:00
|
|
|
memcpy (flxdec->delta_data, flxdec->frame_data, flxdec->size);
|
2005-10-16 21:19:44 +00:00
|
|
|
|
2016-11-22 20:09:06 +00:00
|
|
|
out = gst_buffer_new_and_alloc (flxdec->size * 4);
|
|
|
|
if (!gst_buffer_map (out, &map, GST_MAP_WRITE)) {
|
|
|
|
GST_ELEMENT_ERROR (flxdec, STREAM, DECODE,
|
|
|
|
("%s", "Could not map output buffer"), NULL);
|
|
|
|
gst_buffer_unref (out);
|
|
|
|
goto unmap_input_error;
|
|
|
|
}
|
|
|
|
|
2005-10-16 21:19:44 +00:00
|
|
|
/* convert current frame. */
|
2012-04-13 14:54:46 +00:00
|
|
|
flx_colorspace_convert (flxdec->converter, flxdec->frame_data,
|
|
|
|
map.data);
|
|
|
|
gst_buffer_unmap (out, &map);
|
2005-10-16 21:19:44 +00:00
|
|
|
|
|
|
|
GST_BUFFER_TIMESTAMP (out) = flxdec->next_time;
|
|
|
|
flxdec->next_time += flxdec->frame_time;
|
|
|
|
|
2012-04-13 14:54:46 +00:00
|
|
|
res = gst_pad_push (flxdec->srcpad, out);
|
2004-03-15 19:32:27 +00:00
|
|
|
break;
|
2016-11-22 20:09:06 +00:00
|
|
|
}
|
2013-05-24 17:34:05 +00:00
|
|
|
default:
|
2016-11-22 20:09:06 +00:00
|
|
|
GST_DEBUG_OBJECT (flxdec, "Unknown frame type 0x%02x, skipping %d",
|
|
|
|
type, size);
|
|
|
|
if (!gst_byte_reader_skip (&reader, size - FlxFrameChunkSize))
|
|
|
|
goto parse_error;
|
2013-05-24 17:34:05 +00:00
|
|
|
break;
|
2005-10-16 21:19:44 +00:00
|
|
|
}
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
2016-11-22 20:09:06 +00:00
|
|
|
|
2016-12-09 15:49:40 +00:00
|
|
|
need_more_data:
|
2016-11-22 20:09:06 +00:00
|
|
|
gst_buffer_unmap (input, &map_info);
|
|
|
|
gst_buffer_unref (input);
|
2005-10-16 21:19:44 +00:00
|
|
|
return res;
|
2006-02-19 11:57:58 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2016-11-22 20:09:06 +00:00
|
|
|
parse_error:
|
|
|
|
GST_ELEMENT_ERROR (flxdec, STREAM, DECODE,
|
|
|
|
("%s", "Failed to parse stream"), (NULL));
|
|
|
|
unmap_input_error:
|
|
|
|
gst_buffer_unmap (input, &map_info);
|
|
|
|
error:
|
2016-12-09 15:49:40 +00:00
|
|
|
gst_buffer_unref (input);
|
2016-11-22 20:09:06 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2002-01-13 22:27:25 +00:00
|
|
|
}
|
|
|
|
|
2005-09-02 15:44:50 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_flxdec_change_state (GstElement * element, GstStateChange transition)
|
2002-01-13 22:27:25 +00:00
|
|
|
{
|
|
|
|
GstFlxDec *flxdec;
|
2005-11-16 17:00:32 +00:00
|
|
|
GstStateChangeReturn ret;
|
2002-01-13 22:27:25 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
flxdec = GST_FLXDEC (element);
|
2001-12-22 23:27:31 +00:00
|
|
|
|
2005-09-02 15:44:50 +00:00
|
|
|
switch (transition) {
|
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2002-01-13 22:27:25 +00:00
|
|
|
break;
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
2005-10-16 21:19:44 +00:00
|
|
|
gst_adapter_clear (flxdec->adapter);
|
2002-01-13 22:27:25 +00:00
|
|
|
flxdec->state = GST_FLXDEC_READ_HEADER;
|
2016-12-09 15:55:39 +00:00
|
|
|
gst_segment_init (&flxdec->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
flxdec->need_segment = TRUE;
|
2002-01-13 22:27:25 +00:00
|
|
|
break;
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
2002-01-13 22:27:25 +00:00
|
|
|
break;
|
2005-11-16 17:00:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-04-13 14:54:46 +00:00
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2005-11-16 17:00:32 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
2002-01-13 22:27:25 +00:00
|
|
|
break;
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2012-04-13 14:54:46 +00:00
|
|
|
if (flxdec->frame_data) {
|
|
|
|
g_free (flxdec->frame_data);
|
|
|
|
flxdec->frame_data = NULL;
|
|
|
|
}
|
|
|
|
if (flxdec->delta_data) {
|
|
|
|
g_free (flxdec->delta_data);
|
|
|
|
flxdec->delta_data = NULL;
|
2005-11-16 17:00:32 +00:00
|
|
|
}
|
2012-04-13 14:54:46 +00:00
|
|
|
if (flxdec->converter) {
|
|
|
|
flx_colorspace_converter_destroy (flxdec->converter);
|
|
|
|
flxdec->converter = NULL;
|
2005-11-16 17:00:32 +00:00
|
|
|
}
|
2002-01-13 22:27:25 +00:00
|
|
|
break;
|
2005-09-02 15:44:50 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2002-01-13 22:27:25 +00:00
|
|
|
break;
|
2005-11-16 17:00:32 +00:00
|
|
|
default:
|
|
|
|
break;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
2005-11-16 17:00:32 +00:00
|
|
|
return ret;
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
plugin_init (GstPlugin * plugin)
|
2001-12-22 23:27:31 +00:00
|
|
|
{
|
2021-02-16 08:51:16 +00:00
|
|
|
return GST_ELEMENT_REGISTER (flxdec, plugin);
|
2001-12-22 23:27:31 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
2012-04-05 15:36:38 +00:00
|
|
|
flxdec,
|
2006-11-08 12:04:03 +00:00
|
|
|
"FLC/FLI/FLX video decoder",
|
2005-11-14 02:13:35 +00:00
|
|
|
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|