changeset 5808:9145ca829bce libavformat

oggdec: Save offset of the page needed to reconstruct the current packet
author conrad
date Thu, 11 Mar 2010 07:17:24 +0000
parents f4ca0041b4f4
children 32f77ddb93fa
files oggdec.c oggdec.h
diffstat 2 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/oggdec.c	Wed Mar 10 22:21:39 2010 +0000
+++ b/oggdec.c	Thu Mar 11 07:17:24 2010 +0000
@@ -120,6 +120,8 @@
         os->granule = -1;
         os->lastpts = AV_NOPTS_VALUE;
         os->lastdts = AV_NOPTS_VALUE;
+        os->sync_pos = -1;
+        os->page_pos = 0;
         os->nsegs = 0;
         os->segp = 0;
         os->incomplete = 0;
@@ -255,6 +257,7 @@
     }
 
     os = ogg->streams + idx;
+    os->page_pos = url_ftell(bc) - 27;
 
     if(os->psize > 0)
         ogg_new_buf(ogg, idx);
@@ -277,9 +280,11 @@
                 if (seg < 255)
                     break;
             }
+            os->sync_pos = os->page_pos;
         }
     }else{
         os->psize = 0;
+        os->sync_pos = os->page_pos;
     }
 
     if (os->bufsize - os->bufpos < size){
@@ -303,7 +308,7 @@
 }
 
 static int
-ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize)
+ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize, int64_t *fpos)
 {
     struct ogg *ogg = s->priv_data;
     int idx, i;
@@ -394,8 +399,11 @@
             *dstart = os->pstart;
         if (dsize)
             *dsize = os->psize;
+        if (fpos)
+            *fpos = os->sync_pos;
         os->pstart += os->psize;
         os->psize = 0;
+        os->sync_pos = os->page_pos;
     }
 
     // determine whether there are more complete packets in this page
@@ -420,7 +428,7 @@
     struct ogg *ogg = s->priv_data;
 
     do{
-        if (ogg_packet (s, NULL, NULL, NULL) < 0)
+        if (ogg_packet (s, NULL, NULL, NULL, NULL) < 0)
             return -1;
     }while (!ogg->headers);
 
@@ -520,10 +528,11 @@
     struct ogg_stream *os;
     int idx = -1;
     int pstart, psize;
+    int64_t fpos;
 
     //Get an ogg packet
     do{
-        if (ogg_packet (s, &idx, &pstart, &psize) < 0)
+        if (ogg_packet (s, &idx, &pstart, &psize, &fpos) < 0)
             return AVERROR(EIO);
     }while (idx < 0 || !s->streams[idx]);
 
@@ -557,6 +566,7 @@
 
     pkt->flags = os->pflags;
     pkt->duration = os->pduration;
+    pkt->pos = fpos;
 
     return psize;
 }
--- a/oggdec.h	Wed Mar 10 22:21:39 2010 +0000
+++ b/oggdec.h	Thu Mar 11 07:17:24 2010 +0000
@@ -66,6 +66,8 @@
     uint64_t granule;
     int64_t lastpts;
     int64_t lastdts;
+    int64_t sync_pos;   ///< file offset of the first page needed to reconstruct the current packet
+    int64_t page_pos;   ///< file offset of the current page
     int flags;
     const struct ogg_codec *codec;
     int header;