Ported to 0.9 (faad, amrnb, mpeg2dec)

Original commit message from CVS:
Ported to 0.9 (faad, amrnb, mpeg2dec)
This commit is contained in:
Edgard Lima 2005-07-19 20:51:16 +00:00
parent 553dfaf95d
commit 43f5b4009a
6 changed files with 452 additions and 252 deletions

View file

@ -378,6 +378,50 @@ GST_CHECK_FEATURE(AALIB, [aasink plug-in], aasink, [
AS_SCRUB_INCLUDE(AALIB_CFLAGS) AS_SCRUB_INCLUDE(AALIB_CFLAGS)
]) ])
dnl *** AMR-NB ***
translit(dnm, m, l) AM_CONDITIONAL(USE_AMRNB, true)
GST_CHECK_FEATURE(AMRNB, [AMR-NB], amrnbdec amrnbenc, [
GST_CHECK_LIBHEADER(AMRNB, amrnb,
Decoder_Interface_init, -lm,
amrnb/interf_dec.h,
AMRNB_LIBS="-lamrnb -lm"
AC_SUBST(AMRNB_LIBS))
])
dnl **** Free AAC Decoder (FAAD) ****
translit(dnm, m, l) AM_CONDITIONAL(USE_FAAD, true)
GST_CHECK_FEATURE(FAAD, [AAC decoder plug-in], faad, [
HAVE_FAAD="yes"
GST_CHECK_LIBHEADER(FAAD, faad, faacDecOpen, -lm, faad.h, FAAD_LIBS="-lfaad -lm", HAVE_FAAD="no")
if test $HAVE_FAAD = "yes"; then
AC_MSG_CHECKING([Checking for FAAD >= 2])
AC_TRY_RUN([
#include <faad.h>
#if !defined(FAAD2_VERSION) || !defined(FAAD_FMT_DOUBLE)
#error Not faad2
#else
#include <string.h>
int main()
{
char version[9] = FAAD2_VERSION;
// a release candidate of 2.0 is not enought for us
if ( strstr( version, "2.0 RC" ) ) { return 1; }
return 0;
}
#endif
],
[ HAVE_FAAD="yes" && AC_MSG_RESULT(yes)],
[ HAVE_FAAD="no" && AC_MSG_RESULT(no)])
fi;
AS_SCRUB_INCLUDE(FAAD_CFLAGS)
AC_SUBST(FAAD_LIBS)
])
dnl *** libcaca *** dnl *** libcaca ***
translit(dnm, m, l) AM_CONDITIONAL(USE_LIBCACA, true) translit(dnm, m, l) AM_CONDITIONAL(USE_LIBCACA, true)
GST_CHECK_FEATURE(LIBCACA, [libcaca], libcaca, [ GST_CHECK_FEATURE(LIBCACA, [libcaca], libcaca, [
@ -434,6 +478,15 @@ GST_CHECK_FEATURE(MAD, [mad mp3 decoder], mad, [
]) ])
AC_SUBST(MAD_LIBS) AC_SUBST(MAD_LIBS)
dnl *** mpeg2dec ***
translit(dnm, m, l) AM_CONDITIONAL(USE_MPEG2DEC, true)
GST_CHECK_FEATURE(MPEG2DEC, [mpeg2dec], mpeg2dec, [
PKG_CHECK_MODULES(MPEG2DEC, libmpeg2 >= 0.4.0,
HAVE_MPEG2DEC="yes", HAVE_MPEG2DEC="no")
AC_SUBST(MPEG2DEC_CFLAGS)
AC_SUBST(MPEG2DEC_LIBS)
])
dnl *** dv1394 *** dnl *** dv1394 ***
translit(dnm, m, l) AM_CONDITIONAL(USE_DV1394, true) translit(dnm, m, l) AM_CONDITIONAL(USE_DV1394, true)
GST_CHECK_FEATURE(DV1394, [raw1394 and avc1394 library], dv1394src, [ GST_CHECK_FEATURE(DV1394, [raw1394 and avc1394 library], dv1394src, [
@ -555,6 +608,9 @@ ext/raw1394/Makefile
ext/shout2/Makefile ext/shout2/Makefile
ext/sidplay/Makefile ext/sidplay/Makefile
ext/esd/Makefile ext/esd/Makefile
ext/mpeg2dec/Makefile
ext/faad/Makefile
ext/amrnb/Makefile
po/Makefile.in po/Makefile.in
common/Makefile common/Makefile
common/m4/Makefile common/m4/Makefile

View file

@ -10,11 +10,11 @@ else
AALIB_DIR= AALIB_DIR=
endif endif
# if USE_AMRNB if USE_AMRNB
# AMRNB_DIR=amrnb AMRNB_DIR=amrnb
# else else
AMRNB_DIR= AMRNB_DIR=
# endif endif
# if USE_ARTS # if USE_ARTS
# ARTS_DIR=arts # ARTS_DIR=arts
@ -106,11 +106,11 @@ endif
FAAC_DIR= FAAC_DIR=
# endif # endif
# if USE_FAAD if USE_FAAD
# FAAD_DIR=faad FAAD_DIR=faad
# else else
FAAD_DIR= FAAD_DIR=
# endif endif
## if USE_FESTIVAL ## if USE_FESTIVAL
## FESTIVAL_DIR=festival ## FESTIVAL_DIR=festival
@ -238,11 +238,11 @@ endif
MIKMOD_DIR= MIKMOD_DIR=
# endif # endif
# if USE_MPEG2DEC if USE_MPEG2DEC
# MPEG2DEC_DIR=mpeg2dec MPEG2DEC_DIR=mpeg2dec
# else else
MPEG2DEC_DIR= MPEG2DEC_DIR=
#endif endif
# if USE_MPEG2ENC # if USE_MPEG2ENC
# MPEG2ENC_DIR=mpeg2enc # MPEG2ENC_DIR=mpeg2enc
@ -440,4 +440,7 @@ DIST_SUBDIRS=\
libcaca \ libcaca \
esd \ esd \
raw1394 \ raw1394 \
dv dv \
amrnb \
faad \
mpeg2dec

View file

@ -206,7 +206,7 @@ gst_amrnbdec_chain (GstPad * pad, GstBuffer * buffer)
(amrnbdec->rate * amrnbdec->channels); (amrnbdec->rate * amrnbdec->channels);
GST_BUFFER_TIMESTAMP (out) = amrnbdec->ts; GST_BUFFER_TIMESTAMP (out) = amrnbdec->ts;
amrnbdec->ts += GST_BUFFER_DURATION (out); amrnbdec->ts += GST_BUFFER_DURATION (out);
gst_buffer_set_caps (out, GST_RPAD_CAPS (amrnbdec->srcpad)); gst_buffer_set_caps (out, gst_pad_get_caps (amrnbdec->srcpad));
/* decode */ /* decode */
Decoder_Interface_Decode (amrnbdec->handle, data, Decoder_Interface_Decode (amrnbdec->handle, data,

View file

@ -213,7 +213,7 @@ gst_amrnbenc_chain (GstPad * pad, GstBuffer * buffer)
(amrnbenc->rate * amrnbenc->channels); (amrnbenc->rate * amrnbenc->channels);
GST_BUFFER_TIMESTAMP (out) = amrnbenc->ts; GST_BUFFER_TIMESTAMP (out) = amrnbenc->ts;
amrnbenc->ts += GST_BUFFER_DURATION (out); amrnbenc->ts += GST_BUFFER_DURATION (out);
gst_buffer_set_caps (out, GST_RPAD_CAPS (amrnbenc->srcpad)); gst_buffer_set_caps (out, gst_pad_get_caps (amrnbenc->srcpad));
data = (guint8 *) gst_adapter_peek (amrnbenc->adapter, 320); data = (guint8 *) gst_adapter_peek (amrnbenc->adapter, 320);

View file

@ -56,8 +56,7 @@ static gboolean gst_amrnbparse_query (GstPad * pad, GstQuery * query);
static gboolean gst_amrnbparse_event (GstPad * pad, GstEvent * event); static gboolean gst_amrnbparse_event (GstPad * pad, GstEvent * event);
static GstFlowReturn gst_amrnbparse_chain (GstPad * pad, GstBuffer * buffer); static GstFlowReturn gst_amrnbparse_chain (GstPad * pad, GstBuffer * buffer);
static void gst_amrnbparse_loop (GstPad * pad); static void gst_amrnbparse_loop (GstPad * pad);
static gboolean gst_amrnbparse_sink_activate (GstPad * sinkpad, static gboolean gst_amrnbparse_sink_activate (GstPad * sinkpad);
GstActivateMode mode);
static GstElementStateReturn gst_amrnbparse_state_change (GstElement * element); static GstElementStateReturn gst_amrnbparse_state_change (GstElement * element);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -130,10 +129,11 @@ gst_amrnbparse_init (GstAmrnbParse * amrnbparse)
GST_DEBUG_FUNCPTR (gst_amrnbparse_chain)); GST_DEBUG_FUNCPTR (gst_amrnbparse_chain));
gst_pad_set_event_function (amrnbparse->sinkpad, gst_pad_set_event_function (amrnbparse->sinkpad,
GST_DEBUG_FUNCPTR (gst_amrnbparse_event)); GST_DEBUG_FUNCPTR (gst_amrnbparse_event));
gst_pad_set_loop_function (amrnbparse->sinkpad, /* gst_pad_set_loop_function (amrnbparse->sinkpad,
GST_DEBUG_FUNCPTR (gst_amrnbparse_loop)); GST_DEBUG_FUNCPTR (gst_amrnbparse_loop));
*/
gst_pad_set_activate_function (amrnbparse->sinkpad, gst_pad_set_activate_function (amrnbparse->sinkpad,
GST_DEBUG_FUNCPTR (gst_amrnbparse_sink_activate)); gst_amrnbparse_sink_activate);
gst_element_add_pad (GST_ELEMENT (amrnbparse), amrnbparse->sinkpad); gst_element_add_pad (GST_ELEMENT (amrnbparse), amrnbparse->sinkpad);
/* create the src pad */ /* create the src pad */
@ -174,7 +174,6 @@ gst_amrnbparse_querytypes (GstPad * pad)
{ {
static const GstQueryType list[] = { static const GstQueryType list[] = {
GST_QUERY_POSITION, GST_QUERY_POSITION,
GST_QUERY_TOTAL,
0 0
}; };
@ -260,7 +259,7 @@ gst_amrnbparse_chain (GstPad * pad, GstBuffer * buffer)
{ {
GstAmrnbParse *amrnbparse; GstAmrnbParse *amrnbparse;
GstFlowReturn res; GstFlowReturn res;
gint block, mode, read; gint block, mode;
const guint8 *data; const guint8 *data;
GstBuffer *out; GstBuffer *out;
@ -365,7 +364,7 @@ gst_amrnbparse_loop (GstPad * pad)
GstBuffer *buffer; GstBuffer *buffer;
guint8 *data; guint8 *data;
gint size; gint size;
gint block, mode, read; gint block, mode;
GstFlowReturn ret; GstFlowReturn ret;
amrnbparse = GST_AMRNBPARSE (GST_PAD_PARENT (pad)); amrnbparse = GST_AMRNBPARSE (GST_PAD_PARENT (pad));
@ -438,20 +437,25 @@ eos:
} }
static gboolean static gboolean
gst_amrnbparse_sink_activate (GstPad * sinkpad, GstActivateMode mode) gst_amrnbparse_sink_activate (GstPad * sinkpad)
{ {
gboolean result = FALSE; gboolean result = FALSE;
GstAmrnbParse *amrnbparse; GstAmrnbParse *amrnbparse;
GstActivateMode mode;
amrnbparse = GST_AMRNBPARSE (GST_OBJECT_PARENT (sinkpad)); amrnbparse = GST_AMRNBPARSE (GST_OBJECT_PARENT (sinkpad));
GST_LOCK (sinkpad);
mode = GST_PAD_ACTIVATE_MODE (sinkpad);
GST_UNLOCK (sinkpad);
switch (mode) { switch (mode) {
case GST_ACTIVATE_PUSH: case GST_ACTIVATE_PUSH:
amrnbparse->seekable = FALSE; amrnbparse->seekable = FALSE;
result = TRUE; result = TRUE;
break; break;
case GST_ACTIVATE_PULL: case GST_ACTIVATE_PULL:
gst_pad_peer_set_active (sinkpad, mode); /*gst_pad_peer_set_active (sinkpad, mode); */
amrnbparse->need_header = TRUE; amrnbparse->need_header = TRUE;
amrnbparse->seekable = TRUE; amrnbparse->seekable = TRUE;

View file

@ -28,7 +28,7 @@
/* mpeg2dec changed a struct name after 0.3.1, here's a workaround */ /* mpeg2dec changed a struct name after 0.3.1, here's a workaround */
/* mpeg2dec also only defined MPEG2_RELEASE after 0.3.1 /* mpeg2dec also only defined MPEG2_RELEASE after 0.3.1
#if MPEG2_RELEASE < MPEG2_VERSION(0,3,2) #if MPEG2_RELEASE < MPEG2_VERSION(0,3,2)
*/ */
#ifndef MPEG2_RELEASE #ifndef MPEG2_RELEASE
#define MPEG2_VERSION(a,b,c) ((((a)&0xff)<<16)|(((b)&0xff)<<8)|((c)&0xff)) #define MPEG2_VERSION(a,b,c) ((((a)&0xff)<<16)|(((b)&0xff)<<8)|((c)&0xff))
@ -158,22 +158,31 @@ static void gst_mpeg2dec_get_property (GObject * object, guint prop_id,
static void gst_mpeg2dec_set_index (GstElement * element, GstIndex * index); static void gst_mpeg2dec_set_index (GstElement * element, GstIndex * index);
static GstIndex *gst_mpeg2dec_get_index (GstElement * element); static GstIndex *gst_mpeg2dec_get_index (GstElement * element);
static const GstFormat *gst_mpeg2dec_get_src_formats (GstPad * pad);
static const GstEventMask *gst_mpeg2dec_get_src_event_masks (GstPad * pad);
static gboolean gst_mpeg2dec_src_event (GstPad * pad, GstEvent * event); static gboolean gst_mpeg2dec_src_event (GstPad * pad, GstEvent * event);
static const GstQueryType *gst_mpeg2dec_get_src_query_types (GstPad * pad); static const GstQueryType *gst_mpeg2dec_get_src_query_types (GstPad * pad);
static gboolean gst_mpeg2dec_src_query (GstPad * pad, GstQueryType type,
GstFormat * format, gint64 * value);
static const GstFormat *gst_mpeg2dec_get_sink_formats (GstPad * pad); static gboolean gst_mpeg2dec_src_query (GstPad * pad, GstQuery * query);
static gboolean gst_mpeg2dec_convert_sink (GstPad * pad, GstFormat src_format,
static gboolean gst_mpeg2dec_sink_convert (GstPad * pad, GstFormat src_format,
gint64 src_value, GstFormat * dest_format, gint64 * dest_value); gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
static gboolean gst_mpeg2dec_convert_src (GstPad * pad, GstFormat src_format, static gboolean gst_mpeg2dec_src_convert (GstPad * pad, GstFormat src_format,
gint64 src_value, GstFormat * dest_format, gint64 * dest_value); gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
static GstElementStateReturn gst_mpeg2dec_change_state (GstElement * element); static GstElementStateReturn gst_mpeg2dec_change_state (GstElement * element);
static void gst_mpeg2dec_chain (GstPad * pad, GstData * _data); static gboolean gst_mpeg2dec_sink_event (GstPad * pad, GstEvent * event);
static GstFlowReturn gst_mpeg2dec_chain (GstPad * pad, GstBuffer * buf);
//static gboolean gst_mpeg2dec_sink_query (GstPad * pad, GstQuery * query);
static GstCaps *gst_mpeg2dec_src_getcaps (GstPad * pad);
#if 0
static const GstFormat *gst_mpeg2dec_get_formats (GstPad * pad);
#endif
#if 0
static const GstEventMask *gst_mpeg2dec_get_event_masks (GstPad * pad);
#endif
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
@ -260,26 +269,21 @@ gst_mpeg2dec_init (GstMpeg2dec * mpeg2dec)
gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->sinkpad); gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->sinkpad);
gst_pad_set_chain_function (mpeg2dec->sinkpad, gst_pad_set_chain_function (mpeg2dec->sinkpad,
GST_DEBUG_FUNCPTR (gst_mpeg2dec_chain)); GST_DEBUG_FUNCPTR (gst_mpeg2dec_chain));
gst_pad_set_formats_function (mpeg2dec->sinkpad, //gst_pad_set_query_function (mpeg2dec->sinkpad,
GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_sink_formats)); // GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_sink_query));
gst_pad_set_convert_function (mpeg2dec->sinkpad, gst_pad_set_event_function (mpeg2dec->sinkpad,
GST_DEBUG_FUNCPTR (gst_mpeg2dec_convert_sink)); GST_DEBUG_FUNCPTR (gst_mpeg2dec_sink_event));
mpeg2dec->srcpad = gst_pad_new_from_template (src_templ (), "src"); mpeg2dec->srcpad = gst_pad_new_from_template (src_templ (), "src");
gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->srcpad); gst_element_add_pad (GST_ELEMENT (mpeg2dec), mpeg2dec->srcpad);
gst_pad_use_explicit_caps (mpeg2dec->srcpad); gst_pad_set_getcaps_function (mpeg2dec->srcpad,
gst_pad_set_formats_function (mpeg2dec->srcpad, GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_getcaps));
GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_formats));
gst_pad_set_event_mask_function (mpeg2dec->srcpad,
GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_event_masks));
gst_pad_set_event_function (mpeg2dec->srcpad, gst_pad_set_event_function (mpeg2dec->srcpad,
GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_event)); GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_event));
gst_pad_set_query_type_function (mpeg2dec->srcpad, gst_pad_set_query_type_function (mpeg2dec->srcpad,
GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_query_types)); GST_DEBUG_FUNCPTR (gst_mpeg2dec_get_src_query_types));
gst_pad_set_query_function (mpeg2dec->srcpad, gst_pad_set_query_function (mpeg2dec->srcpad,
GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_query)); GST_DEBUG_FUNCPTR (gst_mpeg2dec_src_query));
gst_pad_set_convert_function (mpeg2dec->srcpad,
GST_DEBUG_FUNCPTR (gst_mpeg2dec_convert_src));
#ifdef enable_user_data #ifdef enable_user_data
mpeg2dec->userdatapad = mpeg2dec->userdatapad =
@ -297,7 +301,6 @@ gst_mpeg2dec_init (GstMpeg2dec * mpeg2dec)
for (i = 0; i < GST_MPEG2DEC_NUM_BUFS; i++) for (i = 0; i < GST_MPEG2DEC_NUM_BUFS; i++)
mpeg2dec->buffers[i] = NULL; mpeg2dec->buffers[i] = NULL;
GST_FLAG_SET (GST_ELEMENT (mpeg2dec), GST_ELEMENT_EVENT_AWARE);
} }
static void static void
@ -342,7 +345,7 @@ gst_mpeg2dec_reset (GstMpeg2dec * mpeg2dec)
mpeg2dec->segment_end = -1; mpeg2dec->segment_end = -1;
mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE; mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE;
mpeg2dec->frame_period = 0; mpeg2dec->frame_period = 0;
gst_pad_set_explicit_caps (mpeg2dec->srcpad, NULL); gst_pad_use_fixed_caps (mpeg2dec->srcpad);
gst_mpeg2dec_open_decoder (mpeg2dec); gst_mpeg2dec_open_decoder (mpeg2dec);
mpeg2dec->need_sequence = TRUE; mpeg2dec->need_sequence = TRUE;
} }
@ -436,13 +439,13 @@ crop_buffer (GstMpeg2dec * mpeg2dec, GstBuffer * input)
/*We crop only if the target region is smaller than the input one */ /*We crop only if the target region is smaller than the input one */
if ((mpeg2dec->decoded_width > mpeg2dec->width) || if ((mpeg2dec->decoded_width > mpeg2dec->width) ||
(mpeg2dec->decoded_height > mpeg2dec->height)) { (mpeg2dec->decoded_height > mpeg2dec->height)) {
/* If we don't know about the format, we just return the original /* If we don't know about the format, we just return the original
* buffer. * buffer.
*/ */
if (mpeg2dec->format == MPEG2DEC_FORMAT_I422 || if (mpeg2dec->format == MPEG2DEC_FORMAT_I422 ||
mpeg2dec->format == MPEG2DEC_FORMAT_I420 || mpeg2dec->format == MPEG2DEC_FORMAT_I420 ||
mpeg2dec->format == MPEG2DEC_FORMAT_YV12) { mpeg2dec->format == MPEG2DEC_FORMAT_YV12) {
/*FIXME: I have tried to use gst_buffer_copy_on_write, but it /*FIXME: I have tried to use gst_buffer_copy_on_write, but it
* still have some artifact, so I'me allocating new buffer * still have some artifact, so I'me allocating new buffer
* for each frame decoded... * for each frame decoded...
*/ */
@ -498,62 +501,94 @@ gst_mpeg2dec_alloc_buffer (GstMpeg2dec * mpeg2dec, gint64 offset)
{ {
GstBuffer *outbuf = NULL; GstBuffer *outbuf = NULL;
gint size = mpeg2dec->decoded_width * mpeg2dec->decoded_height; gint size = mpeg2dec->decoded_width * mpeg2dec->decoded_height;
guint8 *buf[3], *out; guint8 *buf[3], *out = NULL;
GstFlowReturn ret = GST_FLOW_OK;
if (mpeg2dec->format == MPEG2DEC_FORMAT_I422) { do {
outbuf =
gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE,
size * 2);
if (!outbuf) { if (mpeg2dec->format == MPEG2DEC_FORMAT_I422) {
GST_ELEMENT_ERROR (mpeg2dec, RESOURCE, FAILED, (NULL), ret =
("Failed to allocate memory for buffer")); gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE,
size * 2, GST_PAD_CAPS (mpeg2dec->srcpad), &outbuf);
if (ret != GST_FLOW_OK) {
GST_ELEMENT_ERROR (mpeg2dec, RESOURCE, FAILED, (NULL),
("Failed to allocate memory for buffer"));
break;
}
/* 0.9
outbuf =
gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE,
size * 2);
if (!outbuf) {
GST_ELEMENT_ERROR (mpeg2dec, RESOURCE, FAILED, (NULL),
("Failed to allocate memory for buffer"));
return NULL;
}
*/
out = GST_BUFFER_DATA (outbuf);
buf[0] = out;
buf[1] = buf[0] + size;
buf[2] = buf[1] + size / 2;
} else {
/* 0.9
outbuf =
gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE,
(size * 3) / 2);
*/
ret =
gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE,
size * 2, GST_PAD_CAPS (mpeg2dec->srcpad), &outbuf);
if (ret != GST_FLOW_OK) {
GST_ELEMENT_ERROR (mpeg2dec, RESOURCE, FAILED, (NULL),
("Failed to allocate memory for buffer"));
break;
}
out = GST_BUFFER_DATA (outbuf);
buf[0] = out;
if (mpeg2dec->format == MPEG2DEC_FORMAT_I420) {
buf[0] = out;
buf[1] = buf[0] + size;
buf[2] = buf[1] + size / 4;
} else {
buf[0] = out;
buf[2] = buf[0] + size;
buf[1] = buf[2] + size / 4;
}
}
if (!put_buffer (mpeg2dec, outbuf)) {
#if 0
GST_ELEMENT_ERROR (mpeg2dec, LIBRARY, TOO_LAZY, (NULL),
("No free slot. libmpeg2 did not discard buffers."));
#else
GST_WARNING_OBJECT (mpeg2dec,
"No free slot. libmpeg2 did not discard buffers.");
#endif
return NULL; return NULL;
} }
out = GST_BUFFER_DATA (outbuf); mpeg2_custom_fbuf (mpeg2dec->decoder, 1);
mpeg2_set_buf (mpeg2dec->decoder, buf, outbuf);
buf[0] = out; /* we store the original byteoffset of this picture in the stream here
buf[1] = buf[0] + size; * because we need it for indexing */
buf[2] = buf[1] + size / 2; GST_BUFFER_OFFSET (outbuf) = offset;
} else {
outbuf =
gst_pad_alloc_buffer (mpeg2dec->srcpad, GST_BUFFER_OFFSET_NONE,
(size * 3) / 2);
out = GST_BUFFER_DATA (outbuf);
buf[0] = out;
if (mpeg2dec->format == MPEG2DEC_FORMAT_I420) {
buf[0] = out;
buf[1] = buf[0] + size;
buf[2] = buf[1] + size / 4;
} else {
buf[0] = out;
buf[2] = buf[0] + size;
buf[1] = buf[2] + size / 4;
}
} }
while (FALSE);
if (!put_buffer (mpeg2dec, outbuf)) { if (ret != GST_FLOW_OK) {
#if 0 outbuf = NULL; /* just to asure NULL return, looking the path
GST_ELEMENT_ERROR (mpeg2dec, LIBRARY, TOO_LAZY, (NULL), above it happens only when gst_pad_alloc_buffer
("No free slot. libmpeg2 did not discard buffers.")); fails to alloc outbf */
#else
GST_WARNING_OBJECT (mpeg2dec,
"No free slot. libmpeg2 did not discard buffers.");
#endif
return NULL;
} }
mpeg2_custom_fbuf (mpeg2dec->decoder, 1);
mpeg2_set_buf (mpeg2dec->decoder, buf, outbuf);
/* we store the original byteoffset of this picture in the stream here
* because we need it for indexing */
GST_BUFFER_OFFSET (outbuf) = offset;
return outbuf; return outbuf;
} }
@ -562,7 +597,7 @@ gst_mpeg2dec_negotiate_format (GstMpeg2dec * mpeg2dec)
{ {
GstCaps *caps; GstCaps *caps;
guint32 fourcc, myFourcc; guint32 fourcc, myFourcc;
gboolean ret; gboolean ret = TRUE;
const mpeg2_info_t *info; const mpeg2_info_t *info;
const mpeg2_sequence_t *sequence; const mpeg2_sequence_t *sequence;
@ -593,7 +628,8 @@ gst_mpeg2dec_negotiate_format (GstMpeg2dec * mpeg2dec)
mpeg2dec->pixel_height, mpeg2dec->pixel_height,
"framerate", G_TYPE_DOUBLE, mpeg2dec->frame_rate, NULL); "framerate", G_TYPE_DOUBLE, mpeg2dec->frame_rate, NULL);
ret = gst_pad_set_explicit_caps (mpeg2dec->srcpad, caps); // ret = gst_pad_set_explicit_caps (mpeg2dec->srcpad, caps);
ret = gst_pad_set_caps (mpeg2dec->srcpad, caps);
if (!ret) if (!ret)
return FALSE; return FALSE;
@ -721,7 +757,8 @@ handle_slice (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
GST_DEBUG_OBJECT (mpeg2dec, "picture keyframe %d", key_frame); GST_DEBUG_OBJECT (mpeg2dec, "picture keyframe %d", key_frame);
if (key_frame) { if (key_frame) {
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT); /* not need for decode GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_DELTA_UNIT); */
/* 0.9 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT); */
} }
if (mpeg2dec->discont_state == MPEG2DEC_DISC_NEW_KEYFRAME && key_frame) if (mpeg2dec->discont_state == MPEG2DEC_DISC_NEW_KEYFRAME && key_frame)
mpeg2dec->discont_state = MPEG2DEC_DISC_NONE; mpeg2dec->discont_state = MPEG2DEC_DISC_NONE;
@ -776,7 +813,7 @@ handle_slice (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
GST_DEBUG_OBJECT (mpeg2dec, "dropping buffer because of skip flag"); GST_DEBUG_OBJECT (mpeg2dec, "dropping buffer because of skip flag");
gst_buffer_unref (outbuf); gst_buffer_unref (outbuf);
} else if (!GST_PAD_IS_USABLE (mpeg2dec->srcpad) } else if (!GST_PAD_IS_USABLE (mpeg2dec->srcpad)
|| !gst_pad_is_negotiated (mpeg2dec->srcpad)) { || gst_pad_get_negotiated_caps (mpeg2dec->srcpad) == NULL) {
GST_DEBUG_OBJECT (mpeg2dec, "dropping buffer, pad not usable"); GST_DEBUG_OBJECT (mpeg2dec, "dropping buffer, pad not usable");
gst_buffer_unref (outbuf); gst_buffer_unref (outbuf);
} else if (mpeg2dec->discont_state != MPEG2DEC_DISC_NONE) { } else if (mpeg2dec->discont_state != MPEG2DEC_DISC_NONE) {
@ -805,11 +842,13 @@ handle_slice (GstMpeg2dec * mpeg2dec, const mpeg2_info_t * info)
if (info->current_picture if (info->current_picture
&& (info->current_picture->flags & PIC_MASK_CODING_TYPE) == && (info->current_picture->flags & PIC_MASK_CODING_TYPE) ==
PIC_FLAG_CODING_TYPE_I) { PIC_FLAG_CODING_TYPE_I) {
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT); /* not need for decode GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_DELTA_UNIT); */
/* 0.9 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_KEY_UNIT); */
} else { } else {
GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_KEY_UNIT); /* not need for decode GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_DELTA_UNIT); */
/* 0.9 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_KEY_UNIT); */
} }
gst_pad_push (mpeg2dec->srcpad, GST_DATA (outbuf)); gst_pad_push (mpeg2dec->srcpad, GST_BUFFER (outbuf));
} }
} else if (info->display_fbuf && !info->display_fbuf->id) { } else if (info->display_fbuf && !info->display_fbuf->id) {
GST_ELEMENT_ERROR (mpeg2dec, LIBRARY, TOO_LAZY, (NULL), GST_ELEMENT_ERROR (mpeg2dec, LIBRARY, TOO_LAZY, (NULL),
@ -926,11 +965,11 @@ gst_mpeg2dec_flush_decoder (GstMpeg2dec * mpeg2dec)
} }
} }
static void static GstFlowReturn
gst_mpeg2dec_chain (GstPad * pad, GstData * _data) gst_mpeg2dec_chain (GstPad * pad, GstBuffer * buf)
{ {
GstBuffer *buf = GST_BUFFER (_data); /* 0.9 GstBuffer *buf = GST_BUFFER (_data); */
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
guint32 size; guint32 size;
guint8 *data, *end; guint8 *data, *end;
GstClockTime pts; GstClockTime pts;
@ -938,54 +977,7 @@ gst_mpeg2dec_chain (GstPad * pad, GstData * _data)
mpeg2_state_t state; mpeg2_state_t state;
gboolean done = FALSE; gboolean done = FALSE;
if (GST_IS_EVENT (buf)) {
GstEvent *event = GST_EVENT (buf);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_DISCONTINUOUS:
{
GstClockTime time;
if (!gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)
|| !GST_CLOCK_TIME_IS_VALID (time)) {
GST_WARNING_OBJECT (mpeg2dec,
"No new time offset in discont event %p", event);
} else {
mpeg2dec->next_time = time;
GST_DEBUG_OBJECT (mpeg2dec,
"discont, reset next_time to %" G_GUINT64_FORMAT " (%"
GST_TIME_FORMAT ")", mpeg2dec->next_time,
GST_TIME_ARGS (mpeg2dec->next_time));
}
if (GST_EVENT_DISCONT_NEW_MEDIA (event)) {
gst_mpeg2dec_reset (mpeg2dec);
} else {
mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE;
gst_mpeg2dec_flush_decoder (mpeg2dec);
}
gst_pad_event_default (pad, event);
return;
}
case GST_EVENT_FLUSH:
{
mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE;
gst_mpeg2dec_flush_decoder (mpeg2dec);
gst_pad_event_default (pad, event);
return;
}
case GST_EVENT_EOS:
if (mpeg2dec->index && mpeg2dec->closed) {
gst_index_commit (mpeg2dec->index, mpeg2dec->index_id);
}
default:
GST_DEBUG_OBJECT (mpeg2dec, "Got event of type %d on sink pad",
GST_EVENT_TYPE (event));
gst_pad_event_default (pad, event);
return;
}
}
size = GST_BUFFER_SIZE (buf); size = GST_BUFFER_SIZE (buf);
data = GST_BUFFER_DATA (buf); data = GST_BUFFER_DATA (buf);
@ -1011,6 +1003,7 @@ gst_mpeg2dec_chain (GstPad * pad, GstData * _data)
#else #else
mpeg2_pts (mpeg2dec->decoder, mpeg_pts); mpeg2_pts (mpeg2dec->decoder, mpeg_pts);
#endif #endif
} else { } else {
GST_LOG ("no pts"); GST_LOG ("no pts");
} }
@ -1081,6 +1074,7 @@ gst_mpeg2dec_chain (GstPad * pad, GstData * _data)
break; break;
default: default:
GST_ERROR_OBJECT (mpeg2dec, "Unknown libmpeg2 state %d, FIXME", state); GST_ERROR_OBJECT (mpeg2dec, "Unknown libmpeg2 state %d, FIXME", state);
break; break;
} }
@ -1094,13 +1088,14 @@ gst_mpeg2dec_chain (GstPad * pad, GstData * _data)
memcpy (GST_BUFFER_DATA (udbuf), info->user_data, info->user_data_len); memcpy (GST_BUFFER_DATA (udbuf), info->user_data, info->user_data_len);
gst_pad_push (mpeg2dec->userdatapad, GST_DATA (udbuf)); gst_pad_push (mpeg2dec->userdatapad, GST_BUFFER (udbuf));
} }
} }
#endif #endif
} }
gst_buffer_unref (buf); gst_buffer_unref (buf);
return; return GST_FLOW_OK;
exit: exit:
/* /*
@ -1110,33 +1105,138 @@ exit:
gst_mpeg2dec_close_decoder (mpeg2dec); gst_mpeg2dec_close_decoder (mpeg2dec);
gst_mpeg2dec_open_decoder (mpeg2dec); gst_mpeg2dec_open_decoder (mpeg2dec);
gst_buffer_unref (buf); gst_buffer_unref (buf);
return GST_FLOW_ERROR;
} }
static const GstFormat * static gboolean
gst_mpeg2dec_get_sink_formats (GstPad * pad) gst_mpeg2dec_sink_event (GstPad * pad, GstEvent * event)
{ {
static const GstFormat formats[] = {
GstMpeg2dec *mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
gboolean ret = TRUE;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_DISCONTINUOUS:
{
GstClockTime time;
GstClockTime end_time; /* 0.9 just to call
gst_event_discont_get_value, non
used anywhere else */
GST_STREAM_LOCK (pad);
if (!gst_event_discont_get_value (event, GST_FORMAT_TIME, &time,
&end_time)
|| !GST_CLOCK_TIME_IS_VALID (time)) {
GST_WARNING_OBJECT (mpeg2dec,
"No new time offset in discont event %p", event);
} else {
mpeg2dec->next_time = time;
GST_DEBUG_OBJECT (mpeg2dec,
"discont, reset next_time to %" G_GUINT64_FORMAT " (%"
GST_TIME_FORMAT ")", mpeg2dec->next_time,
GST_TIME_ARGS (mpeg2dec->next_time));
}
// what's hell is that
/*
if (GST_EVENT_DISCONT_NEW_MEDIA (event))
{
gst_mpeg2dec_reset (mpeg2dec);
}
else
{
mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE;
gst_mpeg2dec_flush_decoder (mpeg2dec);
}
*/
GST_STREAM_UNLOCK (pad);
ret = gst_pad_event_default (pad, event);
break;
}
case GST_EVENT_FLUSH:
{
mpeg2dec->discont_state = MPEG2DEC_DISC_NEW_PICTURE;
gst_mpeg2dec_flush_decoder (mpeg2dec);
ret = gst_pad_event_default (pad, event);
break;
}
case GST_EVENT_EOS:
GST_STREAM_LOCK (pad);
if (mpeg2dec->index && mpeg2dec->closed) {
gst_index_commit (mpeg2dec->index, mpeg2dec->index_id);
}
GST_STREAM_UNLOCK (pad);
ret = gst_pad_event_default (pad, event);
break;
default:
GST_DEBUG_OBJECT (mpeg2dec, "Got event of type %d on sink pad",
GST_EVENT_TYPE (event));
ret = gst_pad_event_default (pad, event);
break;
}
return ret;
}
#if 0
static const GstFormat *
gst_mpeg2dec_get_formats (GstPad * pad)
{
static GstFormat src_formats[] = {
GST_FORMAT_BYTES,
GST_FORMAT_TIME,
GST_FORMAT_DEFAULT,
0
};
static GstFormat sink_formats[] = {
GST_FORMAT_BYTES, GST_FORMAT_BYTES,
GST_FORMAT_TIME, GST_FORMAT_TIME,
0 0
}; };
return formats; return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
}
#endif
static GstCaps *
gst_mpeg2dec_src_getcaps (GstPad * pad)
{
GstCaps *caps;
GST_LOCK (pad);
if (!(caps = GST_PAD_CAPS (pad)))
caps = (GstCaps *) gst_pad_get_pad_template_caps (pad);
caps = gst_caps_ref (caps);
GST_UNLOCK (pad);
return caps;
} }
static gboolean static gboolean
gst_mpeg2dec_convert_sink (GstPad * pad, GstFormat src_format, gint64 src_value, gst_mpeg2dec_sink_convert (GstPad * pad, GstFormat src_format, gint64 src_value,
GstFormat * dest_format, gint64 * dest_value) GstFormat * dest_format, gint64 * dest_value)
{ {
gboolean res = TRUE; gboolean res = TRUE;
GstMpeg2dec *mpeg2dec; GstMpeg2dec *mpeg2dec;
const mpeg2_info_t *info; const mpeg2_info_t *info;
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
if (mpeg2dec->decoder == NULL) if (mpeg2dec->decoder == NULL)
return FALSE; return FALSE;
if (src_format == *dest_format) {
*dest_value = src_value;
return TRUE;
}
info = mpeg2_info (mpeg2dec->decoder); info = mpeg2_info (mpeg2dec->decoder);
switch (src_format) { switch (src_format) {
@ -1168,21 +1268,9 @@ gst_mpeg2dec_convert_sink (GstPad * pad, GstFormat src_format, gint64 src_value,
return res; return res;
} }
static const GstFormat *
gst_mpeg2dec_get_src_formats (GstPad * pad)
{
static const GstFormat formats[] = {
GST_FORMAT_BYTES,
GST_FORMAT_TIME,
GST_FORMAT_DEFAULT,
0
};
return formats;
}
static gboolean static gboolean
gst_mpeg2dec_convert_src (GstPad * pad, GstFormat src_format, gint64 src_value, gst_mpeg2dec_src_convert (GstPad * pad, GstFormat src_format, gint64 src_value,
GstFormat * dest_format, gint64 * dest_value) GstFormat * dest_format, gint64 * dest_value)
{ {
gboolean res = TRUE; gboolean res = TRUE;
@ -1190,11 +1278,16 @@ gst_mpeg2dec_convert_src (GstPad * pad, GstFormat src_format, gint64 src_value,
const mpeg2_info_t *info; const mpeg2_info_t *info;
guint64 scale = 1; guint64 scale = 1;
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
if (mpeg2dec->decoder == NULL) if (mpeg2dec->decoder == NULL)
return FALSE; return FALSE;
if (src_format == *dest_format) {
*dest_value = src_value;
return TRUE;
}
info = mpeg2_info (mpeg2dec->decoder); info = mpeg2_info (mpeg2dec->decoder);
switch (src_format) { switch (src_format) {
@ -1241,7 +1334,6 @@ static const GstQueryType *
gst_mpeg2dec_get_src_query_types (GstPad * pad) gst_mpeg2dec_get_src_query_types (GstPad * pad)
{ {
static const GstQueryType types[] = { static const GstQueryType types[] = {
GST_QUERY_TOTAL,
GST_QUERY_POSITION, GST_QUERY_POSITION,
0 0
}; };
@ -1250,80 +1342,93 @@ gst_mpeg2dec_get_src_query_types (GstPad * pad)
} }
static gboolean static gboolean
gst_mpeg2dec_src_query (GstPad * pad, GstQueryType type, gst_mpeg2dec_src_query (GstPad * pad, GstQuery * query)
GstFormat * format, gint64 * value)
{ {
gboolean res = TRUE; gboolean res = TRUE;
GstMpeg2dec *mpeg2dec; GstMpeg2dec *mpeg2dec;
static const GstFormat *formats = NULL;
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
switch (type) { switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_TOTAL:
{
switch (*format) {
case GST_FORMAT_TIME:
case GST_FORMAT_BYTES:
case GST_FORMAT_DEFAULT:
{
res = FALSE;
/* get our peer formats */
if (GST_PAD_PEER (mpeg2dec->sinkpad))
formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad));
/* while we did not exhaust our seek formats without result */
while (formats && *formats && !res) {
GstFormat peer_format;
gint64 peer_value;
peer_format = *formats;
/* do the probe */
if (gst_pad_query (GST_PAD_PEER (mpeg2dec->sinkpad),
GST_QUERY_TOTAL, &peer_format, &peer_value)) {
GstFormat conv_format;
/* convert to TIME */
conv_format = GST_FORMAT_TIME;
res = gst_pad_convert (mpeg2dec->sinkpad,
peer_format, peer_value, &conv_format, value);
/* and to final format */
res &= gst_pad_convert (pad,
GST_FORMAT_TIME, *value, format, value);
}
formats++;
}
break;
}
default:
res = FALSE;
break;
}
break;
}
case GST_QUERY_POSITION: case GST_QUERY_POSITION:
{ {
switch (*format) { GstFormat format;
default: GstFormat rformat;
res = gst_pad_convert (pad, gint64 cur, total, total_bytes;
GST_FORMAT_TIME, mpeg2dec->next_time, format, value); GstPad *peer;
break;
/* save requested format */
gst_query_parse_position (query, &format, NULL, NULL);
/* query peer for total length in bytes */
gst_query_set_position (query, GST_FORMAT_BYTES, -1, -1);
if ((peer = gst_pad_get_peer (mpeg2dec->sinkpad)) == NULL)
goto error;
if (!gst_pad_query (peer, query)) {
GST_LOG_OBJECT (mpeg2dec, "query on peer pad failed");
goto error;
} }
gst_object_unref (peer);
/* get the returned format */
gst_query_parse_position (query, &rformat, NULL, &total_bytes);
if (rformat == GST_FORMAT_BYTES)
GST_LOG_OBJECT (mpeg2dec, "peer pad returned total=%lld bytes",
total_bytes);
else if (rformat == GST_FORMAT_TIME)
GST_LOG_OBJECT (mpeg2dec, "peer pad returned time=%lld", total_bytes);
/* Check if requested format is returned format */
if (format == rformat)
return TRUE;
/* and convert to the requested format */
if (format != GST_FORMAT_DEFAULT) {
if (!gst_mpeg2dec_src_convert (pad, GST_FORMAT_DEFAULT,
mpeg2dec->next_time, &format, &cur))
goto error;
} else {
cur = mpeg2dec->next_time;
}
if (total_bytes != -1) {
if (format != GST_FORMAT_BYTES) {
if (!gst_mpeg2dec_sink_convert (pad, GST_FORMAT_BYTES, total_bytes,
&format, &total))
goto error;
} else {
total = total_bytes;
}
} else {
total = -1;
}
gst_query_set_position (query, format, cur, total);
GST_LOG_OBJECT (mpeg2dec,
"position query: peer returned total: %llu - we return %llu (format %u)",
total, cur, format);
break; break;
} }
default: default:
res = FALSE; res = FALSE;
break; break;
} }
return res; return res;
error:
GST_DEBUG ("error handling query");
return FALSE;
} }
#if 0
static const GstEventMask * static const GstEventMask *
gst_mpeg2dec_get_src_event_masks (GstPad * pad) gst_mpeg2dec_get_event_masks (GstPad * pad)
{ {
static const GstEventMask masks[] = { static const GstEventMask masks[] = {
{GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH}, {GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH},
@ -1333,6 +1438,7 @@ gst_mpeg2dec_get_src_event_masks (GstPad * pad)
return masks; return masks;
} }
#endif
static gboolean static gboolean
index_seek (GstPad * pad, GstEvent * event) index_seek (GstPad * pad, GstEvent * event)
@ -1340,7 +1446,7 @@ index_seek (GstPad * pad, GstEvent * event)
GstIndexEntry *entry; GstIndexEntry *entry;
GstMpeg2dec *mpeg2dec; GstMpeg2dec *mpeg2dec;
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
entry = gst_index_get_assoc_entry (mpeg2dec->index, mpeg2dec->index_id, entry = gst_index_get_assoc_entry (mpeg2dec->index, mpeg2dec->index_id,
GST_INDEX_LOOKUP_BEFORE, GST_ASSOCIATION_FLAG_KEY_UNIT, GST_INDEX_LOOKUP_BEFORE, GST_ASSOCIATION_FLAG_KEY_UNIT,
@ -1357,7 +1463,12 @@ index_seek (GstPad * pad, GstEvent * event)
}; };
try_formats = try_all_formats; try_formats = try_all_formats;
#if 0
peer_formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad)); peer_formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad));
#else
peer_formats = try_all_formats; /* FIXE ME */
#endif
while (gst_formats_contains (peer_formats, *try_formats)) { while (gst_formats_contains (peer_formats, *try_formats)) {
gint64 value; gint64 value;
@ -1394,28 +1505,55 @@ index_seek (GstPad * pad, GstEvent * event)
static gboolean static gboolean
normal_seek (GstPad * pad, GstEvent * event) normal_seek (GstPad * pad, GstEvent * event)
{ {
gint64 src_offset; gint64 time_offset, bytes_offset;
gboolean flush;
GstFormat format; GstFormat format;
const GstFormat *peer_formats = NULL; guint flush;
gboolean res = FALSE;
GstMpeg2dec *mpeg2dec; GstMpeg2dec *mpeg2dec;
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
/* const GstFormat *peer_formats; */
gboolean res;
GST_DEBUG ("normal seek");
format = GST_FORMAT_TIME; format = GST_FORMAT_TIME;
if (GST_EVENT_SEEK_FORMAT (event) != GST_FORMAT_TIME) {
/* first bring the src_format to TIME */ if (!gst_mpeg2dec_src_convert (pad, GST_EVENT_SEEK_FORMAT (event),
if (!gst_pad_convert (pad, GST_EVENT_SEEK_OFFSET (event), &format, &time_offset)) {
GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event), /* probably unsupported seek format */
&format, &src_offset)) { GST_DEBUG ("failed to convert format %u into GST_FORMAT_TIME",
/* didn't work, probably unsupported seek format then */ GST_EVENT_SEEK_FORMAT (event));
return res; return FALSE;
}
} else {
time_offset = GST_EVENT_SEEK_OFFSET (event);
} }
GST_DEBUG ("seek to time %" GST_TIME_FORMAT, GST_TIME_ARGS (time_offset));
/* shave off the flush flag, we'll need it later */ /* shave off the flush flag, we'll need it later */
flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH; flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
/* assume the worst */
res = FALSE;
format = GST_FORMAT_BYTES;
if (gst_mpeg2dec_sink_convert (pad, GST_FORMAT_TIME, time_offset,
&format, &bytes_offset)) {
GstEvent *seek_event;
/* conversion succeeded, create the seek */
seek_event =
gst_event_new_seek (format | GST_EVENT_SEEK_METHOD (event) | flush,
bytes_offset);
/* do the seek */
res = gst_pad_send_event (GST_PAD_PEER (mpeg2dec->sinkpad), seek_event);
}
#if 0
/* get our peer formats */ /* get our peer formats */
if (GST_PAD_PEER (mpeg2dec->sinkpad)) if (GST_PAD_PEER (mpeg2dec->sinkpad))
peer_formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad)); peer_formats = gst_pad_get_formats (GST_PAD_PEER (mpeg2dec->sinkpad));
@ -1427,8 +1565,8 @@ normal_seek (GstPad * pad, GstEvent * event)
format = *peer_formats; format = *peer_formats;
/* try to convert requested format to one we can seek with on the sinkpad */ /* try to convert requested format to one we can seek with on the sinkpad */
if (gst_pad_convert (mpeg2dec->sinkpad, GST_FORMAT_TIME, src_offset, if (gst_mpeg2dec_sink_convert (mpeg2dec->sinkpad, GST_FORMAT_TIME,
&format, &desired_offset)) { src_offset, &format, &desired_offset)) {
GstEvent *seek_event; GstEvent *seek_event;
/* conversion succeeded, create the seek */ /* conversion succeeded, create the seek */
@ -1438,9 +1576,6 @@ normal_seek (GstPad * pad, GstEvent * event)
/* do the seekk */ /* do the seekk */
if (gst_pad_send_event (GST_PAD_PEER (mpeg2dec->sinkpad), seek_event)) { if (gst_pad_send_event (GST_PAD_PEER (mpeg2dec->sinkpad), seek_event)) {
/* seek worked, we're done, loop will exit */ /* seek worked, we're done, loop will exit */
#if 0
mpeg2dec->segment_start = GST_EVENT_SEEK_OFFSET (event);
#endif
res = TRUE; res = TRUE;
break; break;
} }
@ -1453,17 +1588,19 @@ normal_seek (GstPad * pad, GstEvent * event)
/* if we need to flush, iterate until the buffer is empty */ /* if we need to flush, iterate until the buffer is empty */
gst_mpeg2dec_flush_decoder (mpeg2dec); gst_mpeg2dec_flush_decoder (mpeg2dec);
} }
#endif
return res; return res;
} }
static gboolean static gboolean
gst_mpeg2dec_src_event (GstPad * pad, GstEvent * event) gst_mpeg2dec_src_event (GstPad * pad, GstEvent * event)
{ {
gboolean res = TRUE; gboolean res = TRUE;
GstMpeg2dec *mpeg2dec; GstMpeg2dec *mpeg2dec;
mpeg2dec = GST_MPEG2DEC (gst_pad_get_parent (pad)); mpeg2dec = GST_MPEG2DEC (GST_PAD_PARENT (pad));
if (mpeg2dec->decoder == NULL) if (mpeg2dec->decoder == NULL)
return FALSE; return FALSE;
@ -1573,4 +1710,4 @@ plugin_init (GstPlugin * plugin)
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR, GST_VERSION_MINOR,
"mpeg2dec", "mpeg2dec",
"LibMpeg2 decoder", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN) "LibMpeg2 decoder", plugin_init, VERSION, "GPL", GST_PACKAGE, GST_ORIGIN);