On 11/19/2011 01:55 AM, Luca Barbato wrote:

> av_interleave_packet_per_dts waits untill it gets a frame for each
> stream before outputting packets in interleaved order.
> 
> Sparse streams tend to add up latency and in specific cases end up
> allocating a large amount of memory.
> 
> Flush the packet queue if the packets in the queue have a delay
> larger than the max_delay.
> 
> Original report of the issue and initial proposed solution by
> [email protected] on bug 31.
> ---
>  libavformat/avformat.h |    5 ++++-
>  libavformat/utils.c    |   34 +++++++++++++++++++++++++++-------
>  2 files changed, 31 insertions(+), 8 deletions(-)
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 33e820e..d47fd92 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h


as a general comment, why all the unrelated cosmetic changes? it makes
the patch more difficult to read.

> +    AVPacket *last_pkt;
>      AVPacketList *pktl;
> -    int stream_count=0;
> +    int stream_count = 0;
> +    int64_t delta_dts = INT64_MIN;
> +    int64_t last_dts;
>      int i;
>  
> -    if(pkt){
> +    if (pkt) {
>          ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts);
>      }
>  
> -    for(i=0; i < s->nb_streams; i++)
> -        stream_count+= !!s->streams[i]->last_in_packet_buffer;
> +    last_pkt = &s->packet_buffer->pkt;
> +    last_dts = av_rescale_q(last_pkt->dts,
> +                         s->streams[last_pkt->stream_index]->time_base,
> +                            AV_TIME_BASE_Q);
> +
> +    for (i=0; i < s->nb_streams; i++)
> +        if (s->streams[i]->last_in_packet_buffer) {
> +            delta_dts = FFMAX(delta_dts,
> +                av_rescale_q(s->streams[i]->last_in_packet_buffer->pkt.dts,
> +                          s->streams[i]->time_base,
> +                          AV_TIME_BASE_Q) - last_dts);
> +            stream_count++;
> +        }
> +    if (s->max_delay && delta_dts > s->max_delay) {
> +        av_log(s, AV_LOG_DEBUG, "Sparse stream detected, forcing flush\n");
> +        flush = 1;
> +    }


It doesn't look like it's necessary to do all the timestamp conversion
and comparison if s->max_delay is not set. It's only a few extra lines
to do:
if (s->max_delay) {
    calculate delta_dts and stream_count
} else {
    only calculate stream_count
}

-Justin

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to