#include <stdio.h>
#include "oggdec.h"
#include "avformat.h"
+#include "vorbiscomment.h"
#define MAX_PAGE_SIZE 65307
#define DECODER_BUFFER_SIZE MAX_PAGE_SIZE
idx, os->psize, os->pstart);
#endif
+ if (os->granule == -1)
+ av_log(s, AV_LOG_WARNING, "Page at %"PRId64" is missing granule\n", os->page_pos);
+
ogg->curidx = idx;
os->incomplete = 0;
- if (!ogg->headers){
- int hdr = os->codec->header (s, idx);
- os->header = os->seq;
- if (!hdr){
+ if (os->header) {
+ os->header = os->codec->header (s, idx);
+ if (!os->header){
os->segp = segp;
os->psize = psize;
+
+ // We have reached the first non-header packet. All header
+ // packets must be complete before the first non-header
+ // one, so everything that follows must be non-header.
ogg->headers = 1;
+
+ // Update the header state for all streams and
+ // compute the data_offset.
s->data_offset = os->sync_pos;
+ for (i = 0; i < ogg->nstreams; i++) {
+ struct ogg_stream *cur_os = ogg->streams + i;
+ // Set stream header state to 0 if its last packet
+ // was a header.
+ if (cur_os->header > 0)
+ cur_os->header = 0;
+
+ // if we have a partial non-header packet, its start is
+ // obviously at or after the data start
+ if (cur_os->incomplete)
+ s->data_offset = FFMIN(s->data_offset, cur_os->sync_pos);
+ }
}else{
os->pstart += os->psize;
os->psize = 0;
}
- }
-
- if (os->header > -1 && os->seq > os->header){
+ } else {
os->pflags = 0;
os->pduration = 0;
if (os->codec && os->codec->packet)
break;
}
- os->seq++;
if (os->segp == os->nsegs)
ogg->curidx = -1;
ogg_get_length (AVFormatContext * s)
{
struct ogg *ogg = s->priv_data;
- int idx = -1, i;
+ int i;
int64_t size, end;
if(url_is_streamed(s->pb))
while (!ogg_read_page (s, &i)){
if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
- ogg->streams[i].codec)
- idx = i;
- }
-
- if (idx != -1){
- s->streams[idx]->duration =
- ogg_gptopts (s, idx, ogg->streams[idx].granule, NULL);
- if (s->streams[idx]->start_time != AV_NOPTS_VALUE)
- s->streams[idx]->duration -= s->streams[idx]->start_time;
+ ogg->streams[i].codec) {
+ s->streams[i]->duration =
+ ogg_gptopts (s, i, ogg->streams[i].granule, NULL);
+ if (s->streams[i]->start_time != AV_NOPTS_VALUE)
+ s->streams[i]->duration -= s->streams[i]->start_time;
+ }
}
- ogg->size = size;
ogg_restore (s, 0);
return 0;
else
os->lastpts = ogg_gptopts(s, idx, os->granule, &os->lastdts);
os->granule = -1LL;
- } else
- av_log(s, AV_LOG_WARNING, "Packet is missing granule\n");
+ }
}
return pts;
}
// pflags might not be set until after this
pts = ogg_calc_pts(s, idx, &dts);
- if (os->keyframe_seek && !(os->pflags & PKT_FLAG_KEY))
+ if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY))
goto retry;
os->keyframe_seek = 0;
while (url_ftell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg)) {
if (i == stream_index) {
pts = ogg_calc_pts(s, i, NULL);
- if (os->keyframe_seek && !(os->pflags & PKT_FLAG_KEY))
+ if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY))
pts = AV_NOPTS_VALUE;
}
if (pts != AV_NOPTS_VALUE)
// Try seeking to a keyframe first. If this fails (very possible),
// av_seek_frame will fall back to ignoring keyframes
- if (s->streams[stream_index]->codec->codec_type == CODEC_TYPE_VIDEO
+ if (s->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO
&& !(flags & AVSEEK_FLAG_ANY))
os->keyframe_seek = 1;
return 0;
}
-AVInputFormat ogg_demuxer = {
+AVInputFormat ff_ogg_demuxer = {
"ogg",
NULL_IF_CONFIG_SMALL("Ogg"),
sizeof (struct ogg),
ogg_read_seek,
ogg_read_timestamp,
.extensions = "ogg",
- .metadata_conv = ff_vorbiscomment_metadata_conv,
+ .flags = AVFMT_GENERIC_INDEX,
};