[FFmpeg-devel] [PATCH] miscelleneous NUT fixes

ods15 at ods15.dyndns.org ods15
Sat Feb 2 17:18:33 CET 2008


Some fixed for the lavf NUT demuxer/muxer:

muxer
1. nut->max_distance was not set at all anywhere in the muxer
2. I assume the syncpoint positioning was meant to be "put if this is a 
keyframe, and the last frame was NOT a keyframe", and the NOT was 
accidentaly flipped.
3. The back_ptr calculation was using wrong timebase when searching for 
back syncpoint
4. ff_nut_reset_ts() expected to get 'ts*time_base_count', but muxer only 
gave it 'ts'. I fixed this by changing ff_nut_reset_ts() and demuxer 
params...

demuxer
1. "Bleh, libnut muxed this ;)\n" please, I fixed this bug over a year ago :)
2. missing " && j<syncpoint_count" protection in the index parsing, as the 
spec instructs...
3. small bug in info packet parsing..

Shall I commit?

- ods15
-------------- next part --------------
Index: ffmpeg/libavformat/nut.c
===================================================================
--- ffmpeg/libavformat/nut.c	(revision 11727)
+++ ffmpeg/libavformat/nut.c	(working copy)
@@ -26,7 +26,7 @@
     int i;
     for(i=0; i<nut->avf->nb_streams; i++){
         nut->stream[i].last_pts= av_rescale_rnd(
-            val / nut->time_base_count,
+            val,
             time_base.num * (int64_t)nut->stream[i].time_base->den,
             time_base.den * (int64_t)nut->stream[i].time_base->num,
             AV_ROUND_DOWN);
Index: ffmpeg/libavformat/nutenc.c
===================================================================
--- ffmpeg/libavformat/nutenc.c	(revision 11727)
+++ ffmpeg/libavformat/nutenc.c	(working copy)
@@ -216,7 +216,7 @@
 
     put_v(bc, 3); /* version */
     put_v(bc, nut->avf->nb_streams);
-    put_v(bc, MAX_DISTANCE);
+    put_v(bc, nut->max_distance);
     put_v(bc, nut->time_base_count);
 
     for(i=0; i<nut->time_base_count; i++){
@@ -418,6 +418,7 @@
         nut->stream[i].max_pts_distance= FFMAX(1/av_q2d(time_base), 1);
     }
 
+    nut->max_distance = MAX_DISTANCE;
     build_frame_code(s);
     assert(nut->frame_code['N'].flags == FLAG_INVALID);
 
@@ -461,7 +462,7 @@
     if(1LL<<(20+3*nut->header_count) <= url_ftell(bc))
         write_headers(nut, bc);
 
-    if(key_frame && !!(nus->last_flags & FLAG_KEY))
+    if(key_frame && !(nus->last_flags & FLAG_KEY))
         store_sp= 1;
 
     if(pkt->size + 30/*FIXME check*/ + url_ftell(bc) >= nut->last_syncpoint_pos + nut->max_distance)
@@ -475,7 +476,11 @@
         ff_nut_reset_ts(nut, *nus->time_base, pkt->dts);
         for(i=0; i<s->nb_streams; i++){
             AVStream *st= s->streams[i];
-            int index= av_index_search_timestamp(st, pkt->dts, AVSEEK_FLAG_BACKWARD);
+            int64_t dts_tb = av_rescale_rnd(pkt->dts,
+                nus->time_base->num * (int64_t)nut->stream[i].time_base->den,
+                nus->time_base->den * (int64_t)nut->stream[i].time_base->num,
+                AV_ROUND_DOWN);
+            int index= av_index_search_timestamp(st, dts_tb, AVSEEK_FLAG_BACKWARD);
             if(index>=0) dummy.pos= FFMIN(dummy.pos, st->index_entries[index].pos);
         }
         if(dummy.pos == INT64_MAX)
Index: ffmpeg/libavformat/nutdec.c
===================================================================
--- ffmpeg/libavformat/nutdec.c	(revision 11727)
+++ ffmpeg/libavformat/nutdec.c	(working copy)
@@ -336,11 +336,7 @@
         ff_get_v(bc); /* csp type */
     }else if (st->codec->codec_type == CODEC_TYPE_AUDIO){
         GET_V(st->codec->sample_rate , tmp > 0)
-        tmp= ff_get_v(bc); // samplerate_den
-        if(tmp > st->codec->sample_rate){
-            av_log(s, AV_LOG_ERROR, "Bleh, libnut muxed this ;)\n");
-            st->codec->sample_rate= tmp;
-        }
+        ff_get_v(bc); // samplerate_den
         GET_V(st->codec->channels, tmp > 0)
     }
     if(skip_reserved(bc, end) || get_checksum(bc)){
@@ -376,7 +372,8 @@
             type= "UTF-8";
             get_str(bc, str_value, sizeof(str_value));
         }else if(value == -2){
-            get_str(bc, type, sizeof(type));
+            get_str(bc, type_str, sizeof(type_str));
+            type=type_str;
             get_str(bc, str_value, sizeof(str_value));
         }else if(value == -3){
             type= "s";
@@ -425,7 +422,7 @@
     if(*back_ptr < 0)
         return -1;
 
-    ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count], tmp);
+    ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count], tmp / nut->time_base_count);
 
     if(skip_reserved(bc, end) || get_checksum(bc)){
         av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
@@ -499,7 +496,7 @@
                 return -1;
             }
             assert(n<=syncpoint_count+1);
-            for(; j<n; j++){
+            for(; j<n && j<syncpoint_count; j++){
                 if(has_keyframe[j]){
                     uint64_t B, A= ff_get_v(bc);
                     if(!A){



More information about the ffmpeg-devel mailing list