changeset 2349:a9dc7596498a libavformat

move syncpoint cache related stuff to common file
author michael
date Thu, 09 Aug 2007 23:24:02 +0000
parents b995891375b2
children a0fb5ef1ec7c
files nut.c nut.h nutdec.c
diffstat 3 files changed, 25 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/nut.c	Thu Aug 09 21:35:13 2007 +0000
+++ b/nut.c	Thu Aug 09 23:24:02 2007 +0000
@@ -42,3 +42,21 @@
     return  ((lsb - delta)&mask) + delta;
 }
 
+int ff_nut_sp_pos_cmp(syncpoint_t *a, syncpoint_t *b){
+    return (a->pos - b->pos>>32) - (b->pos - a->pos>>32);
+}
+
+int ff_nut_sp_pts_cmp(syncpoint_t *a, syncpoint_t *b){
+    return (a->ts - b->ts>>32) - (b->ts - a->ts>>32);
+}
+
+void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){
+    syncpoint_t *sp2, *sp= av_mallocz(sizeof(syncpoint_t));
+
+    sp->pos= pos;
+    sp->back_ptr= back_ptr;
+    sp->ts= ts;
+    sp2= av_tree_insert(&nut->syncpoints, sp, ff_nut_sp_pos_cmp);
+    if(sp2 && sp2 != sp)
+        av_free(sp);
+}
--- a/nut.h	Thu Aug 09 21:35:13 2007 +0000
+++ b/nut.h	Thu Aug 09 23:24:02 2007 +0000
@@ -95,5 +95,8 @@
 unsigned long av_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len);
 void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val);
 int64_t ff_lsb2full(StreamContext *stream, int64_t lsb);
+int ff_nut_sp_pos_cmp(syncpoint_t *a, syncpoint_t *b);
+int ff_nut_sp_pts_cmp(syncpoint_t *a, syncpoint_t *b);
+void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts);
 
 #endif /* AVFORMAT_NUT_H */
--- a/nutdec.c	Thu Aug 09 21:35:13 2007 +0000
+++ b/nutdec.c	Thu Aug 09 23:24:02 2007 +0000
@@ -421,25 +421,6 @@
     return 0;
 }
 
-static int sp_pos_cmp(syncpoint_t *a, syncpoint_t *b){
-    return (a->pos - b->pos>>32) - (b->pos - a->pos>>32);
-}
-
-static int sp_pts_cmp(syncpoint_t *a, syncpoint_t *b){
-    return (a->ts - b->ts>>32) - (b->ts - a->ts>>32);
-}
-
-static void add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){
-    syncpoint_t *sp2, *sp= av_mallocz(sizeof(syncpoint_t));
-
-    sp->pos= pos;
-    sp->back_ptr= back_ptr;
-    sp->ts= ts;
-    sp2= av_tree_insert(&nut->syncpoints, sp, sp_pos_cmp);
-    if(sp2 && sp2 != sp)
-        av_free(sp);
-}
-
 static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr){
     AVFormatContext *s= nut->avf;
     ByteIOContext *bc = &s->pb;
@@ -464,7 +445,7 @@
     }
 
     *ts= tmp / s->nb_streams * av_q2d(nut->time_base[tmp % s->nb_streams])*AV_TIME_BASE;
-    add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts);
+    ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts);
 
     return 0;
 }
@@ -812,7 +793,7 @@
         pos2= st->index_entries[index].pos;
         ts  = st->index_entries[index].timestamp;
     }else{
-        av_tree_find(nut->syncpoints, &dummy, sp_pts_cmp, next_node);
+        av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp, next_node);
         av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", next_node[0]->pos, next_node[1]->pos,
                                                     next_node[0]->ts , next_node[1]->ts);
         pos= av_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos,
@@ -821,7 +802,7 @@
         if(!(flags & AVSEEK_FLAG_BACKWARD)){
             dummy.pos= pos+16;
             next_node[1]= &nopts_sp;
-            av_tree_find(nut->syncpoints, &dummy, sp_pos_cmp, next_node);
+            av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, next_node);
             pos2= av_gen_search(s, -2, dummy.pos, next_node[0]->pos     , next_node[1]->pos, next_node[1]->pos,
                                                 next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp);
             if(pos2>=0)
@@ -829,7 +810,7 @@
             //FIXME dir but i think it does not matter
         }
         dummy.pos= pos;
-        sp= av_tree_find(nut->syncpoints, &dummy, sp_pos_cmp, NULL);
+        sp= av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, NULL);
 
         assert(sp);
         pos2= sp->back_ptr  - 15;