From 916be7a8b3f2deb4ddef6b6e3438d3ead24825ca Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 27 Jun 2004 14:42:09 +0000 Subject: [PATCH] ext/dv/gstdvdec.*: Fix timestamp, duration and offset of the buffers. Original commit message from CVS: * ext/dv/gstdvdec.c: (gst_dvdec_push), (gst_dvdec_loop), (gst_dvdec_change_state): * ext/dv/gstdvdec.h: Fix timestamp, duration and offset of the buffers. --- ChangeLog | 7 +++++++ ext/dv/gstdvdec.c | 28 +++++++++++++++++++++------- ext/dv/gstdvdec.h | 1 + 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index fcda8ec79c..5805768931 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-06-27 Wim Taymans + + * ext/dv/gstdvdec.c: (gst_dvdec_push), (gst_dvdec_loop), + (gst_dvdec_change_state): + * ext/dv/gstdvdec.h: + Fix timestamp, duration and offset of the buffers. + 2004-06-27 Wim Taymans * gst/tcp/gstmultifdsink.c: (gst_recover_policy_get_type), diff --git a/ext/dv/gstdvdec.c b/ext/dv/gstdvdec.c index de547145a6..92b6cdd114 100644 --- a/ext/dv/gstdvdec.c +++ b/ext/dv/gstdvdec.c @@ -798,8 +798,6 @@ static void gst_dvdec_push (GstDVDec * dvdec, GstBuffer * outbuf, GstPad * pad, GstClockTime ts) { - GST_BUFFER_TIMESTAMP (outbuf) = ts; - if ((dvdec->need_discont) || (dvdec->new_media)) { GstEvent *discont; @@ -827,7 +825,7 @@ gst_dvdec_loop (GstElement * element) guint8 *inframe; gint height; guint32 length, got_bytes; - guint64 ts; + GstClockTime ts, duration; gdouble fps; dvdec = GST_DVDEC (element); @@ -874,13 +872,13 @@ gst_dvdec_loop (GstElement * element) ts = dvdec->next_ts; dvdec->next_ts += GST_SECOND / dvdec->framerate; + duration = dvdec->next_ts - ts; dv_parse_packs (dvdec->decoder, GST_BUFFER_DATA (buf)); if (dv_is_new_recording (dvdec->decoder, GST_BUFFER_DATA (buf))) dvdec->new_media = TRUE; if (GST_PAD_IS_LINKED (dvdec->audiosrcpad)) { - gint16 *a_ptr; - gint i, j; + gint num_samples; dv_decode_full_audio (dvdec->decoder, GST_BUFFER_DATA (buf), dvdec->audio_buffers); @@ -905,7 +903,12 @@ gst_dvdec_loop (GstElement * element) dvdec->channels = dv_get_num_channels (dvdec->decoder); } - if (dv_get_num_samples (dvdec->decoder) > 0) { + num_samples = dv_get_num_samples (dvdec->decoder); + + if (num_samples) { + gint16 *a_ptr; + gint i, j; + outbuf = gst_buffer_new (); GST_BUFFER_SIZE (outbuf) = dv_get_num_samples (dvdec->decoder) * sizeof (gint16) * dv_get_num_channels (dvdec->decoder); @@ -913,11 +916,18 @@ gst_dvdec_loop (GstElement * element) a_ptr = (gint16 *) GST_BUFFER_DATA (outbuf); - for (i = 0; i < dv_get_num_samples (dvdec->decoder); i++) { + for (i = 0; i < num_samples; i++) { for (j = 0; j < dv_get_num_channels (dvdec->decoder); j++) { *(a_ptr++) = dvdec->audio_buffers[j][i]; } } + + GST_BUFFER_TIMESTAMP (outbuf) = ts; + GST_BUFFER_DURATION (outbuf) = duration; + GST_BUFFER_OFFSET (outbuf) = dvdec->audio_offset; + dvdec->audio_offset += num_samples; + GST_BUFFER_OFFSET_END (outbuf) = dvdec->audio_offset; + gst_dvdec_push (dvdec, outbuf, dvdec->audiosrcpad, ts); } } else { @@ -959,6 +969,9 @@ gst_dvdec_loop (GstElement * element) dv_decode_full_frame (dvdec->decoder, GST_BUFFER_DATA (buf), dvdec->space, outframe_ptrs, outframe_pitches); + GST_BUFFER_TIMESTAMP (outbuf) = ts; + GST_BUFFER_DURATION (outbuf) = duration; + gst_dvdec_push (dvdec, outbuf, dvdec->videosrcpad, ts); } else { dvdec->height = height; @@ -989,6 +1002,7 @@ gst_dvdec_change_state (GstElement * element) dvdec->decoder = dv_decoder_new (0, dvdec->clamp_luma, dvdec->clamp_chroma); dvdec->decoder->quality = qualities[dvdec->quality]; + dvdec->audio_offset = 0; /* * Enable this function call when libdv2 0.100 or higher is more * common diff --git a/ext/dv/gstdvdec.h b/ext/dv/gstdvdec.h index dda0a2aeed..902273716e 100644 --- a/ext/dv/gstdvdec.h +++ b/ext/dv/gstdvdec.h @@ -64,6 +64,7 @@ struct _GstDVDec { gint length; guint64 next_ts; + guint64 audio_offset; guint64 end_position; gboolean need_discont; gboolean new_media;