From a16cd5d2a5cbdf084163ead68b59d537d7db99f7 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Thu, 5 Jun 2014 14:50:15 +0100 Subject: [PATCH] vorbisenc: push an updated segment stop time when we know it When encoding, libvorbis will tell us how many samples are encoded in the buffer it returns. This number may be less than the maximum of samples in the block, if this is the last packet. In we have no segment end time, we set it to the end time of that last sample to tell downstream that the buffer contains less samples. --- ext/vorbis/gstvorbisenc.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ext/vorbis/gstvorbisenc.c b/ext/vorbis/gstvorbisenc.c index cdb92739f4..8dec47762a 100644 --- a/ext/vorbis/gstvorbisenc.c +++ b/ext/vorbis/gstvorbisenc.c @@ -800,6 +800,27 @@ gst_vorbis_enc_output_buffers (GstVorbisEnc * vorbisenc) while (vorbis_bitrate_flushpacket (&vorbisenc->vd, &op)) { GstBuffer *buf; + if (op.e_o_s) { + GstAudioEncoder *enc = GST_AUDIO_ENCODER (vorbisenc); + GstClockTime duration; + + GST_DEBUG_OBJECT (vorbisenc, "Got EOS packet from libvorbis"); + GST_AUDIO_ENCODER_STREAM_LOCK (enc); + if (!GST_CLOCK_TIME_IS_VALID (enc->output_segment.stop)) { + GST_DEBUG_OBJECT (vorbisenc, + "Output segment has no end time, setting"); + duration = + gst_util_uint64_scale (op.granulepos, GST_SECOND, + vorbisenc->frequency); + enc->output_segment.stop = enc->output_segment.start + duration; + GST_DEBUG_OBJECT (enc, "new output segment %" GST_SEGMENT_FORMAT, + &enc->output_segment); + gst_pad_push_event (GST_AUDIO_ENCODER_SRC_PAD (enc), + gst_event_new_segment (&enc->output_segment)); + } + GST_AUDIO_ENCODER_STREAM_UNLOCK (enc); + } + GST_LOG_OBJECT (vorbisenc, "pushing out a data packet"); buf = gst_audio_encoder_allocate_output_buffer (GST_AUDIO_ENCODER