Luca Barbato <[email protected]> writes:
> 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.
>
> Emit a packet from the 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 | 3 +++
> libavformat/utils.c | 39 ++++++++++++++++++++++++++++++++++-----
> 2 files changed, 37 insertions(+), 5 deletions(-)
The title is still horrible. It tells nothing whatsoever about what the
patch does. Please change it to mention sparse streams.
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 5276af1..2f95405 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -887,6 +887,9 @@ typedef struct AVFormatContext {
> #if FF_API_PRELOAD
> attribute_deprecated int preload;
> #endif
> + /**
> + * maximum muxing/demuxing delay in microseconds
> + */
> int max_delay;
>
> #if FF_API_LOOP_OUTPUT
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 2b378ab..4741df3 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -3135,19 +3135,48 @@ static int ff_interleave_compare_dts(AVFormatContext
> *s, AVPacket *next, AVPacke
> return comp > 0;
> }
>
> -int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket
> *pkt, int flush){
> +int av_interleave_packet_per_dts(AVFormatContext *s,
> + AVPacket *out, AVPacket *pkt, int flush)
> +{
> + AVPacket *last_pkt;
> AVPacketList *pktl;
> - int stream_count=0;
> + int stream_count = 0;
> + int64_t delta_dts = INT64_MIN;
> + int64_t last_dts, cur_dts;
> int i;
>
> 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;
> + if (s->max_delay && s->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++) {
Space around = please.
> + const AVPacketList *cur = s->streams[i]->last_in_packet_buffer;
> + if (!cur) continue;
> +
> + cur_dts = av_rescale_q(cur->pkt.dts,
> + s->streams[i]->time_base,
> + AV_TIME_BASE_Q);
> + delta_dts = FFMAX(delta_dts, cur_dts - last_dts);
> + stream_count++;
> + }
Your definitions of 'cur' and 'last' are most confusing.
> + if (delta_dts > s->max_delay) {
> + av_log(s, AV_LOG_DEBUG,
> + "Deadline reached, emitting a packet\n");
> + flush = 1;
> + }
> + } else {
> + for (i=0; i < s->nb_streams; i++)
Space around = please.
> + stream_count += !!s->streams[i]->last_in_packet_buffer;
> + }
>
> - if(stream_count && (s->nb_streams == stream_count || flush)){
> + if (stream_count && (s->nb_streams == stream_count || flush)) {
> pktl= s->packet_buffer;
> *out= pktl->pkt;
>
> --
> 1.7.8.rc1
>
--
Måns Rullgård
[email protected]
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel