[FFmpeg-cvslog] matroskaenc: change cluster_pos to use -1 as the "I' m not currently working on a cluster" signal instead of 0.

Aaron Colwell git at videolan.org
Wed Mar 14 22:10:58 CET 2012


ffmpeg | branch: master | Aaron Colwell <acolwell at chromium.org> | Wed Mar 14 21:40:29 2012 +0100| [bda5b6627a558cf10c4d09eeff264289a1370cc1] | committer: Michael Niedermayer

matroskaenc: change cluster_pos to use -1 as the "I'm not currently working on a cluster" signal instead of 0.

This avoids problems
where avio_tell() returns 0. I've updated all the checks against
cluster_pos

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavformat/matroskaenc.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 0b36725..8d024de 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -978,6 +978,7 @@ static int mkv_write_header(AVFormatContext *s)
     av_init_packet(&mkv->cur_audio_pkt);
     mkv->cur_audio_pkt.size = 0;
     mkv->audio_buffer_size  = 0;
+    mkv->cluster_pos = -1;
 
     avio_flush(pb);
     return 0;
@@ -1150,7 +1151,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
         pb = mkv->dyn_bc;
     }
 
-    if (!mkv->cluster_pos) {
+    if (mkv->cluster_pos == -1) {
         mkv->cluster_pos = avio_tell(s->pb);
         mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER, 0);
         put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, FFMAX(0, ts));
@@ -1204,14 +1205,14 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
 
     // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or
     // after 4k and on a keyframe
-    if (mkv->cluster_pos &&
+    if (mkv->cluster_pos != -1 &&
         ((!s->pb->seekable && (cluster_size > 32*1024 || ts > mkv->cluster_pts + 1000))
          ||                      cluster_size > 5*1024*1024 || ts > mkv->cluster_pts + 5000
          || (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe && cluster_size > 4*1024))) {
         av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64
                " bytes, pts %" PRIu64 "\n", avio_tell(pb), ts);
         end_ebml_master(pb, mkv->cluster);
-        mkv->cluster_pos = 0;
+        mkv->cluster_pos = -1;
         if (mkv->dyn_bc)
             mkv_flush_dynbuf(s);
     }
@@ -1255,7 +1256,7 @@ static int mkv_write_trailer(AVFormatContext *s)
     if (mkv->dyn_bc) {
         end_ebml_master(mkv->dyn_bc, mkv->cluster);
         mkv_flush_dynbuf(s);
-    } else if (mkv->cluster_pos) {
+    } else if (mkv->cluster_pos != -1) {
         end_ebml_master(pb, mkv->cluster);
     }
 



More information about the ffmpeg-cvslog mailing list