Quoting Martin Storsjö (2016-06-24 22:44:56)
> If the calculated offset from write_packet would be cached somewhere,
> that can be used instead of recalculating the offset for the stream.
> ---
>  libavformat/internal.h |  3 ++-
>  libavformat/movenc.c   |  3 ++-
>  libavformat/mux.c      | 18 +++++++++++++++---
>  3 files changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index bbdfd2f..1d970dc 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -449,6 +449,7 @@ void ff_format_io_close(AVFormatContext *s, AVIOContext 
> **pb);
>   * @return a pointer to the next packet, or NULL if no packet is queued
>   *         for this stream.
>   */
> -const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream);
> +const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream,
> +                                    AVPacket *buf, int add_offset);
>  
>  #endif /* AVFORMAT_INTERNAL_H */
> diff --git a/libavformat/movenc.c b/libavformat/movenc.c
> index aadfa06..866a402 100644
> --- a/libavformat/movenc.c
> +++ b/libavformat/movenc.c
> @@ -3262,7 +3262,8 @@ static int mov_flush_fragment(AVFormatContext *s, int 
> force)
>      for (i = 0; i < s->nb_streams; i++) {
>          MOVTrack *track = &mov->tracks[i];
>          if (!track->end_reliable) {
> -            const AVPacket *next = ff_interleaved_peek(s, i);
> +            AVPacket buf;
> +            const AVPacket *next = ff_interleaved_peek(s, i, &buf, 1);
>              if (next) {
>                  track->track_duration = next->dts - track->start_dts;
>                  if (next->pts != AV_NOPTS_VALUE)
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index c41c477..6ed46ae 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -614,12 +614,24 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, 
> AVPacket *out,
>      }
>  }
>  
> -const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream)
> +const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream,
> +                                    AVPacket *buf, int add_offset)
>  {
>      AVPacketList *pktl = s->internal->packet_buffer;
>      while (pktl) {
> -        if (pktl->pkt.stream_index == stream)
> -            return &pktl->pkt;
> +        if (pktl->pkt.stream_index == stream) {
> +            *buf = pktl->pkt;
> +            if (add_offset && s->internal->offset != AV_NOPTS_VALUE) {
> +                int64_t offset = av_rescale_q(s->internal->offset,
> +                                              s->internal->offset_timebase,
> +                                              
> s->streams[buf->stream_index]->time_base);
> +                if (buf->dts != AV_NOPTS_VALUE)
> +                    buf->dts += offset;
> +                if (buf->pts != AV_NOPTS_VALUE)
> +                    buf->pts += offset;
> +            }
> +            return buf;
> +        }
>          pktl = pktl->next;
>      }
>      return NULL;
> -- 
> 2.7.4 (Apple Git-66)

This is starting to look a bit messy IMO. The return value and the buf
parameter are now redundant, so I think the return value can now be an
int. And I would feel better if you stripped the data/size/buf/side_data
fields from the returned packet, since it's now neither a plain pointer
into the intereleaving queue nor a proper reference.

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

Reply via email to