[FFmpeg-devel] [PATCH] reset avio buffer when ffm wrapped around

Michael Niedermayer michaelni at gmx.at
Thu Sep 8 20:50:48 CEST 2011


On Tue, Aug 09, 2011 at 01:40:42PM +0800, Yan Jing wrote:
[...]
> diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c
> index 2fd154f..46d71b7 100644
> --- a/libavformat/ffmdec.c
> +++ b/libavformat/ffmdec.c
> @@ -121,6 +121,11 @@ static int ffm_read_data(AVFormatContext *s,
>              if (avio_tell(pb) == ffm->file_size)
>                  avio_seek(pb, ffm->packet_size, SEEK_SET);
>      retry_read:
> +            if (pb->buffer_size != ffm->packet_size) {
> +                int64_t tell = avio_tell(pb);
> +                ffio_set_buf_size(pb, ffm->packet_size);
> +                avio_seek(pb, tell, SEEK_SET);
> +            }
>              id = avio_rb16(pb); /* PACKET_ID */
>              if (id != PACKET_ID)
>                  if (ffm_resync(s, id) < 0)

applied


> @@ -137,8 +142,12 @@ static int ffm_read_data(AVFormatContext *s,
>              if (ffm->first_packet || (frame_offset & 0x8000)) {
>                  if (!frame_offset) {
>                      /* This packet has no frame headers in it */
> -                    if (avio_tell(pb) >= ffm->packet_size * 3) {
> -                        avio_seek(pb, -ffm->packet_size * 2, SEEK_CUR);
> +                    if (ffm->write_index >= ffm->file_size && avio_tell(pb) >= ffm->packet_size * 3 ||
> +                        ffm->write_index < ffm->file_size && (avio_tell(pb) <= ffm->write_index || avio_tell(pb) >= ffm->write_index + ffm->packet_size * 2)) {
> +                        if (avio_tell(pb) <= ffm->packet_size * 2)
> +                            avio_seek(pb, ffm->file_size - ffm->packet_size * 3 + avio_tell(pb), SEEK_SET);
> +                        else
> +                            avio_seek(pb, -ffm->packet_size * 2, SEEK_CUR);
>                          goto retry_read;
>                      }
>                      /* This is bad, we cannot find a valid frame header */

this is buggy when write_index=0


> @@ -461,11 +470,25 @@ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, in
>      av_dlog(s, "wanted_pts=%0.6f\n", wanted_pts / 1000000.0);
>      /* find the position using linear interpolation (better than
>         dichotomy in typical cases) */
> -    pos_min = FFM_PACKET_SIZE;
> -    pos_max = ffm->file_size - FFM_PACKET_SIZE;
> +    if (ffm->write_index < ffm->file_size) {
> +        if (get_dts(s, FFM_PACKET_SIZE) < wanted_pts) {
> +            pos_min = FFM_PACKET_SIZE;
> +            pos_max = ffm->write_index - FFM_PACKET_SIZE;
> +        } else {
> +            pos_min = ffm->write_index;
> +            pos_max = ffm->file_size - FFM_PACKET_SIZE;
> +        }
> +    } else {
> +        pos_min = FFM_PACKET_SIZE;
> +        pos_max = ffm->file_size - FFM_PACKET_SIZE;
> +    }
>      while (pos_min <= pos_max) {
>          pts_min = get_dts(s, pos_min);
>          pts_max = get_dts(s, pos_max);
> +        if (pts_min > wanted_pts || pts_max < wanted_pts) {
> +            pos = pts_min > wanted_pts ? pos_min : pos_max;
> +            goto found;
> +        }
>          /* linear interpolation */
>          pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) /
>              (double)(pts_max - pts_min);

applied with minor changes

thanks alot for the bugfixes

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 3
"Rare item" - "Common item with rare defect or maybe just a lie"
"Professional" - "'Toy' made in china, not functional except as doorstop"
"Experts will know" - "The seller hopes you are not an expert"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110908/b7d91b03/attachment.asc>


More information about the ffmpeg-devel mailing list