Sebastian Smyczyński <[email protected]> added the comment:
I had the same problem (with seeking in oggs) and I solved it changing the code
as shown in the attached patch.
Since in our software (http://klango.net) we are using libavcodec library for
playing radio stations we have also other problem related to ogg decoding - some
radios changes the ogg stream serial number with every new song what causes
reaching MAX_STREAMS number of opened streams in a short time. Of course it is
material for a new issue but since it is strictly related to playing radio
stations I do not know if I should report it or not.
Best Regards,
Sebastian Smyczyński
____________________________________________________
FFmpeg issue tracker <[email protected]>
<https://roundup.ffmpeg.org/roundup/ffmpeg/issue592>
____________________________________________________
Index: libavformat/oggdec.c
===================================================================
--- libavformat/oggdec.c (revision 21693)
+++ libavformat/oggdec.c (working copy)
@@ -292,10 +292,14 @@
if (get_buffer (bc, os->buf + os->bufpos, size) < size)
return -1;
- os->bufpos += size;
+ os->bufpos += size;
os->granule = gp;
os->flags = flags;
+ // remember the current page size (used in ogg_read_timestamp)
+ // header + number of segments + summarized size of segments
+ os->pagesize = 27 + os->nsegs + size;
+
if (str)
*str = idx;
@@ -587,12 +591,14 @@
int i;
url_fseek(bc, *pos_arg, SEEK_SET);
while (url_ftell(bc) < pos_limit && !ogg_read_page (s, &i)) {
- if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
+ if (ogg->streams[i].granule != -1 &&
ogg->streams[i].codec && i == stream_index) {
+
pts = ogg_gptopts(s, i, ogg->streams[i].granule, NULL);
- // FIXME: this is the position of the packet after the one with above
- // pts.
- *pos_arg = url_ftell(bc);
+
+ // store the position of the page with above pts.
+ *pos_arg = url_ftell(bc) - ogg->streams[i].pagesize;
+
break;
}
}
Index: libavformat/oggdec.h
===================================================================
--- libavformat/oggdec.h (revision 21693)
+++ libavformat/oggdec.h (working copy)
@@ -71,6 +71,7 @@
int header;
int nsegs, segp;
uint8_t segments[255];
+ uint32_t pagesize;
int incomplete; ///< whether we're expecting a continuation in the next page
int page_end; ///< current packet is the last one completed in the page
void *private;