Chromium Code Reviews| Index: libavformat/oggdec.c |
| diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c |
| index 3a1abc085f96779b7ddea1d97ff2423ae2007cb8..6fbafc4ee3511141f29e163fb32fa6817919e596 100644 |
| --- a/libavformat/oggdec.c |
| +++ b/libavformat/oggdec.c |
| @@ -39,14 +39,24 @@ |
| static const struct ogg_codec * const ogg_codecs[] = { |
| &ff_skeleton_codec, |
| +#if CONFIG_DIRAC_DEMUXER |
| &ff_dirac_codec, |
| +#endif |
| +#if CONFIG_LIBSPEEX |
| &ff_speex_codec, |
| +#endif |
| &ff_vorbis_codec, |
| &ff_theora_codec, |
| +#if CONFIG_FLAC_DECODER |
| &ff_flac_codec, |
| +#endif |
| &ff_celt_codec, |
| +#if CONFIG_DIRAC_DEMUXER |
| &ff_old_dirac_codec, |
| +#endif |
| +#if CONFIG_FLAC_DECODER |
| &ff_old_flac_codec, |
| +#endif |
| &ff_ogm_video_codec, |
| &ff_ogm_audio_codec, |
| &ff_ogm_text_codec, |
| @@ -497,24 +507,6 @@ static int ogg_get_length(AVFormatContext *s) |
| ogg_restore (s, 0); |
|
DaleCurtis
2012/02/04 18:06:20
Applied 35_oggdec_duration.patch, despite upstream
scherkus (not reviewing)
2012/02/06 17:46:29
We should sanity check those tests for accuracy as
DaleCurtis
2012/02/06 18:59:01
Without this patch it gets the duration wrong by >
|
| - ogg_save (s); |
| - avio_seek (s->pb, 0, SEEK_SET); |
| - while (!ogg_read_page (s, &i)){ |
| - if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && |
| - ogg->streams[i].codec) { |
| - if(s->streams[i]->duration && s->streams[i]->start_time == AV_NOPTS_VALUE && !ogg->streams[i].got_start){ |
| - int64_t start= ogg_gptopts (s, i, ogg->streams[i].granule, NULL); |
| - if(av_rescale_q(start, s->streams[i]->time_base, AV_TIME_BASE_Q) > AV_TIME_BASE) |
| - s->streams[i]->duration -= start; |
| - ogg->streams[i].got_start= 1; |
| - streams_left--; |
| - } |
| - if(streams_left<=0) |
| - break; |
| - } |
| - } |
| - ogg_restore (s, 0); |
| - |
| return 0; |
| } |
| @@ -631,6 +623,8 @@ static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index, |
| AVIOContext *bc = s->pb; |
| int64_t pts = AV_NOPTS_VALUE; |
| int i = -1; |
| + int packet = 0; |
| + int64_t start_pos = *pos_arg; |
| avio_seek(bc, *pos_arg, SEEK_SET); |
| ogg_reset(ogg); |
| @@ -640,6 +634,12 @@ static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index, |
| pts = ogg_calc_pts(s, i, NULL); |
| if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY)) |
| pts = AV_NOPTS_VALUE; |
| + |
| + // This is for the special case for the first packet in the stream. |
| + if (pts == AV_NOPTS_VALUE && start_pos <= s->data_offset && !packet) { |
| + pts = 0; |
| + } |
| + ++packet; |
| } |
| if (pts != AV_NOPTS_VALUE) |
| break; |
| @@ -654,6 +654,10 @@ static int ogg_read_seek(AVFormatContext *s, int stream_index, |
| struct ogg *ogg = s->priv_data; |
| struct ogg_stream *os = ogg->streams + stream_index; |
| int ret; |
| + int64_t seek_pos; |
| + int64_t pos_arg; |
| + int64_t seek_pts; |
| + int i; |
| // Try seeking to a keyframe first. If this fails (very possible), |
| // av_seek_frame will fall back to ignoring keyframes |
| @@ -665,6 +669,22 @@ static int ogg_read_seek(AVFormatContext *s, int stream_index, |
| os = ogg->streams + stream_index; |
| if (ret < 0) |
| os->keyframe_seek = 0; |
| + |
| + // Save the position seeked to. |
| + pos_arg = seek_pos = avio_tell(s->pb); |
|
DaleCurtis
2012/02/04 18:06:20
Patch required swapping url_ftell w/ avio_tell.
scherkus (not reviewing)
2012/02/06 17:46:29
For these function swaps is it because the patch w
DaleCurtis
2012/02/06 18:59:01
Yes.
|
| + seek_pts = ogg_read_timestamp(s, stream_index, &pos_arg, avio_size(s->pb)); |
|
DaleCurtis
2012/02/04 18:06:20
Patch required swapping url_fsize w/ avio_size.
|
| + os = ogg->streams + stream_index; |
| + |
| + // Since we have seeked to the beginning then reset lastpts and lastdts to 0. |
| + if (!seek_pts) { |
| + for (i = 0; i < ogg->nstreams; i++){ |
| + struct ogg_stream *stream = ogg->streams + i; |
| + stream->lastpts = 0; |
| + stream->lastdts = 0; |
| + } |
| + os->keyframe_seek = 0; |
| + } |
| + avio_seek(s->pb, seek_pos, SEEK_SET); |
|
DaleCurtis
2012/02/04 18:06:20
Patch required swapping url_fseek w/ avio_seek.
|
| return ret; |
| } |