[FFmpeg-devel] [PATCH] avformat/demux: allow total size of packets in raw_packet_buffer to reach probesize

Marton Balint cus at passwd.hu
Sat Nov 13 15:17:24 EET 2021



On Sun, 7 Nov 2021, Marton Balint wrote:

> Previously this was hardcoded to 2500000 bytes, so probing of the stream codecs
> was always limited by this, and not probesize.
>
> Also keep track of the actual size of packets in raw_packet_buffer and not the
> remaining size for simplicity.
>
> Fixes ticket #5860.

Will apply soon.

Regards,
Marton

>
> Signed-off-by: Marton Balint <cus at passwd.hu>
> ---
> libavformat/demux.c    | 10 +++++-----
> libavformat/internal.h |  5 ++---
> libavformat/options.c  |  1 -
> libavformat/utils.c    |  2 +-
> 4 files changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/libavformat/demux.c b/libavformat/demux.c
> index 71a1a9bf03..745dc8687c 100644
> --- a/libavformat/demux.c
> +++ b/libavformat/demux.c
> @@ -328,7 +328,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename,
>     if (s->pb && !si->data_offset)
>         si->data_offset = avio_tell(s->pb);
>
> -    si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
> +    si->raw_packet_buffer_size = 0;
>
>     update_stream_avctx(s);
>
> @@ -432,7 +432,7 @@ no_packet:
>             }
>         }
>
> -        end = si->raw_packet_buffer_remaining_size <= 0
> +        end = si->raw_packet_buffer_size >= s->probesize
>                 || sti->probe_packets <= 0;
>
>         if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) {
> @@ -544,13 +544,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
>
>         if (pktl) {
>             AVStream *const st = s->streams[pktl->pkt.stream_index];
> -            if (si->raw_packet_buffer_remaining_size <= 0)
> +            if (si->raw_packet_buffer_size >= s->probesize)
>                 if ((err = probe_codec(s, st, NULL)) < 0)
>                     return err;
>             if (ffstream(st)->request_probe <= 0) {
>                 avpriv_packet_list_get(&si->raw_packet_buffer,
>                                        &si->raw_packet_buffer_end, pkt);
> -                si->raw_packet_buffer_remaining_size += pkt->size;
> +                si->raw_packet_buffer_size -= pkt->size;
>                 return 0;
>             }
>         }
> @@ -631,7 +631,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>             return err;
>         }
>         pkt1 = &si->raw_packet_buffer_end->pkt;
> -        si->raw_packet_buffer_remaining_size -= pkt1->size;
> +        si->raw_packet_buffer_size += pkt1->size;
>
>         if ((err = probe_codec(s, st, pkt1)) < 0)
>             return err;
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index f1ae7db365..1f301dd17a 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -127,10 +127,9 @@ typedef struct FFFormatContext {
>      */
>     AVPacket *pkt;
>     /**
> -     * Remaining size available for raw_packet_buffer, in bytes.
> +     * Sum of the size of packets in raw_packet_buffer, in bytes.
>      */
> -#define RAW_PACKET_BUFFER_SIZE 2500000
> -    int raw_packet_buffer_remaining_size;
> +    int raw_packet_buffer_size;
>
>     /**
>      * Offset to remap timestamps to be non-negative.
> diff --git a/libavformat/options.c b/libavformat/options.c
> index 753aa9b8dc..72c9bdcefe 100644
> --- a/libavformat/options.c
> +++ b/libavformat/options.c
> @@ -174,7 +174,6 @@ AVFormatContext *avformat_alloc_context(void)
>     }
>
>     si->offset = AV_NOPTS_VALUE;
> -    si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
>     si->shortest_end = AV_NOPTS_VALUE;
>
>     return s;
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 509c0ecdce..bbc61dccbb 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -303,7 +303,7 @@ void ff_flush_packet_queue(AVFormatContext *s)
>     avpriv_packet_list_free(&si->packet_buffer,     &si->packet_buffer_end);
>     avpriv_packet_list_free(&si->raw_packet_buffer, &si->raw_packet_buffer_end);
>
> -    si->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
> +    si->raw_packet_buffer_size = 0;
> }
>
> int av_find_default_stream_index(AVFormatContext *s)
> -- 
> 2.31.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>


More information about the ffmpeg-devel mailing list