[FFmpeg-cvslog] ogg/speex: set correct timestamp and duration for the first packet.

Justin Ruggles git at videolan.org
Fri Oct 21 02:37:07 CEST 2011


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Wed Oct 19 13:28:12 2011 -0400| [0e69c0477399a5545d42456d6c3aec4a3650bb67] | committer: Justin Ruggles

ogg/speex: set correct timestamp and duration for the first packet.

The first timestamp should be negative due to delay.
Also, do not set AVCodecContext.frame_size unnecessarily.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0e69c0477399a5545d42456d6c3aec4a3650bb67
---

 libavformat/oggparsespeex.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c
index 2f4aec7..bbeeb20 100644
--- a/libavformat/oggparsespeex.c
+++ b/libavformat/oggparsespeex.c
@@ -31,6 +31,7 @@
 #include "oggdec.h"
 
 struct speex_params {
+    int packet_size;
     int final_packet_duration;
     int seq;
 };
@@ -58,14 +59,10 @@ static int speex_header(AVFormatContext *s, int idx) {
         st->codec->sample_rate = AV_RL32(p + 36);
         st->codec->channels = AV_RL32(p + 48);
 
-        /* We treat the whole Speex packet as a single frame everywhere Speex
-           is handled in Libav.  This avoids the complexities of splitting
-           and joining individual Speex frames, which are not always
-           byte-aligned. */
-        st->codec->frame_size = AV_RL32(p + 56);
-        frames_per_packet     = AV_RL32(p + 64);
+        spxp->packet_size  = AV_RL32(p + 56);
+        frames_per_packet  = AV_RL32(p + 64);
         if (frames_per_packet)
-            st->codec->frame_size *= frames_per_packet;
+            spxp->packet_size *= frames_per_packet;
 
         st->codec->extradata_size = os->psize;
         st->codec->extradata = av_malloc(st->codec->extradata_size
@@ -95,7 +92,7 @@ static int speex_packet(AVFormatContext *s, int idx)
     struct ogg *ogg = s->priv_data;
     struct ogg_stream *os = ogg->streams + idx;
     struct speex_params *spxp = os->private;
-    int packet_size = s->streams[idx]->codec->frame_size;
+    int packet_size = spxp->packet_size;
 
     if (os->flags & OGG_FLAG_EOS && os->lastpts != AV_NOPTS_VALUE &&
         os->granule > 0) {
@@ -108,9 +105,10 @@ static int speex_packet(AVFormatContext *s, int idx)
 
     if (!os->lastpts && os->granule > 0)
         /* first packet */
-        os->pduration = os->granule - packet_size * (ogg_page_packets(os) - 1);
-    else if (os->flags & OGG_FLAG_EOS && os->segp == os->nsegs &&
-             spxp->final_packet_duration)
+        os->lastpts = os->lastdts = os->granule - packet_size *
+                                    ogg_page_packets(os);
+    if (os->flags & OGG_FLAG_EOS && os->segp == os->nsegs &&
+        spxp->final_packet_duration)
         /* final packet */
         os->pduration = spxp->final_packet_duration;
     else



More information about the ffmpeg-cvslog mailing list