Merge commit '9deaec782810d098bca11c9332fab2d2f4c5fb78'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 11 Feb 2015 01:13:46 +0000 (02:13 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 11 Feb 2015 01:47:54 +0000 (02:47 +0100)
* commit '9deaec782810d098bca11c9332fab2d2f4c5fb78':
  lavf: move internal fields from public to internal context

Conflicts:
libavformat/avformat.h
libavformat/internal.h
libavformat/mux.c
libavformat/utils.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
18 files changed:
1  2 
libavformat/asfdec.c
libavformat/avformat.h
libavformat/boadec.c
libavformat/dv.c
libavformat/internal.h
libavformat/mp3dec.c
libavformat/mtv.c
libavformat/mux.c
libavformat/mxfenc.c
libavformat/nutdec.c
libavformat/oggdec.c
libavformat/options.c
libavformat/pcm.c
libavformat/r3d.c
libavformat/utils.c
libavformat/version.h
libavformat/vqf.c
libavformat/yop.c

@@@ -1445,17 -1361,15 +1445,17 @@@ static int64_t asf_read_pts(AVFormatCon
          start_pos[i] = pos;
  
      if (s->packet_size > 0)
-         pos = (pos + s->packet_size - 1 - s->data_offset) /
+         pos = (pos + s->packet_size - 1 - s->internal->data_offset) /
                s->packet_size * s->packet_size +
-               s->data_offset;
+               s->internal->data_offset;
      *ppos = pos;
 -    avio_seek(s->pb, pos, SEEK_SET);
 +    if (avio_seek(s->pb, pos, SEEK_SET) < 0)
 +        return AV_NOPTS_VALUE;
  
 +    ff_read_frame_flush(s);
      asf_reset_header(s);
      for (;;) {
 -        if (asf_read_packet(s, pkt) < 0) {
 +        if (av_read_frame(s, pkt) < 0) {
              av_log(s, AV_LOG_INFO, "asf_read_pts failed\n");
              return AV_NOPTS_VALUE;
          }
@@@ -1503,171 -1210,7 +1503,120 @@@ typedef struct AVFormatContext 
  #define AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE 1 ///< Shift timestamps so they are non negative
  #define AVFMT_AVOID_NEG_TS_MAKE_ZERO         2 ///< Shift timestamps so that they start at 0
  
      /**
-     /*****************************************************************
-      * All fields below this line are not part of the public API. They
-      * may not be used outside of libavformat and can be changed and
-      * removed at will.
-      * New public fields should be added right above.
-      *****************************************************************
-      */
-     /**
-      * This buffer is only needed when packets were already buffered but
-      * not decoded, for example to get the codec parameters in MPEG
-      * streams.
-      */
-     struct AVPacketList *packet_buffer;
-     struct AVPacketList *packet_buffer_end;
-     /* av_seek_frame() support */
-     int64_t data_offset; /**< offset of the first packet */
-     /**
-      * Raw packets from the demuxer, prior to parsing and decoding.
-      * This buffer is used for buffering packets until the codec can
-      * be identified, as parsing cannot be done without knowing the
-      * codec.
-      */
-     struct AVPacketList *raw_packet_buffer;
-     struct AVPacketList *raw_packet_buffer_end;
-     /**
-      * Packets split by the parser get queued here.
-      */
-     struct AVPacketList *parse_queue;
-     struct AVPacketList *parse_queue_end;
-     /**
-      * Remaining size available for raw_packet_buffer, in bytes.
-      */
- #define RAW_PACKET_BUFFER_SIZE 2500000
-     int raw_packet_buffer_remaining_size;
-     /**
-      * Offset to remap timestamps to be non-negative.
-      * Expressed in timebase units.
-      * @see AVStream.mux_ts_offset
-      */
-     int64_t offset;
-     /**
-      * Timebase for the timestamp offset.
-      */
-     AVRational offset_timebase;
 +     * Transport stream id.
 +     * This will be moved into demuxer private options. Thus no API/ABI compatibility
 +     */
 +    int ts_id;
 +
 +    /**
 +     * Audio preload in microseconds.
 +     * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
 +     * - encoding: Set by user via AVOptions (NO direct access)
 +     * - decoding: unused
 +     */
 +    int audio_preload;
 +
 +    /**
 +     * Max chunk time in microseconds.
 +     * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
 +     * - encoding: Set by user via AVOptions (NO direct access)
 +     * - decoding: unused
 +     */
 +    int max_chunk_duration;
 +
 +    /**
 +     * Max chunk size in bytes
 +     * Note, not all formats support this and unpredictable things may happen if it is used when not supported.
 +     * - encoding: Set by user via AVOptions (NO direct access)
 +     * - decoding: unused
 +     */
 +    int max_chunk_size;
 +
 +    /**
 +     * forces the use of wallclock timestamps as pts/dts of packets
 +     * This has undefined results in the presence of B frames.
 +     * - encoding: unused
 +     * - decoding: Set by user via AVOptions (NO direct access)
 +     */
 +    int use_wallclock_as_timestamps;
 +
 +    /**
 +     * avio flags, used to force AVIO_FLAG_DIRECT.
 +     * - encoding: unused
 +     * - decoding: Set by user via AVOptions (NO direct access)
 +     */
 +    int avio_flags;
 +
 +    /**
 +     * The duration field can be estimated through various ways, and this field can be used
 +     * to know how the duration was estimated.
 +     * - encoding: unused
 +     * - decoding: Read by user via AVOptions (NO direct access)
 +     */
 +    enum AVDurationEstimationMethod duration_estimation_method;
 +
 +    /**
 +     * Skip initial bytes when opening stream
 +     * - encoding: unused
 +     * - decoding: Set by user via AVOptions (NO direct access)
 +     */
 +    int64_t skip_initial_bytes;
 +
 +    /**
 +     * Correct single timestamp overflows
 +     * - encoding: unused
 +     * - decoding: Set by user via AVOptions (NO direct access)
 +     */
 +    unsigned int correct_ts_overflow;
 +
 +    /**
 +     * Force seeking to any (also non key) frames.
 +     * - encoding: unused
 +     * - decoding: Set by user via AVOptions (NO direct access)
 +     */
 +    int seek2any;
 +
 +    /**
 +     * Flush the I/O context after each packet.
 +     * - encoding: Set by user via AVOptions (NO direct access)
 +     * - decoding: unused
 +     */
 +    int flush_packets;
 +
 +    /**
 +     * format probing score.
 +     * The maximal score is AVPROBE_SCORE_MAX, its set when the demuxer probes
 +     * the format.
 +     * - encoding: unused
 +     * - decoding: set by avformat, read by user via av_format_get_probe_score() (NO direct access)
 +     */
 +    int probe_score;
 +
 +    /**
 +     * number of bytes to read maximally to identify format.
 +     * - encoding: unused
 +     * - decoding: set by user through AVOPtions (NO direct access)
 +     */
 +    int format_probesize;
 +
 +    /**
 +     * ',' separated list of allowed decoders.
 +     * If NULL then all are allowed
 +     * - encoding: unused
 +     * - decoding: set by user through AVOptions (NO direct access)
 +     */
 +    char *codec_whitelist;
 +
 +    /**
 +     * ',' separated list of allowed demuxers.
 +     * If NULL then all are allowed
 +     * - encoding: unused
 +     * - decoding: set by user through AVOptions (NO direct access)
 +     */
 +    char *format_whitelist;
 +
 +    /**
       * An opaque field for libavformat internal usage.
       * Must not be accessed in any way by callers.
       */
index 45f6b39,0000000..be003e5
mode 100644,000000..100644
--- /dev/null
@@@ -1,78 -1,0 +1,79 @@@
-     s->data_offset         = avio_rl32(s->pb);
 +/*
 + * Black ops audio demuxer
 + * Copyright (c) 2013 Michael Niedermayer
 + *
 + * This file is part of FFmpeg.
 + *
 + * FFmpeg is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2.1 of the License, or (at your option) any later version.
 + *
 + * FFmpeg is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with FFmpeg; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 + */
 +
 +#include "libavutil/intreadwrite.h"
 +#include "avformat.h"
++#include "internal.h"
 +
 +static int probe(AVProbeData *p)
 +{
 +    if (p->buf_size < 2096)
 +        return 0;
 +    if (   AV_RL32(p->buf     ) != 1
 +        || AV_RL32(p->buf +  8) > 100000
 +        || AV_RL32(p->buf + 12) > 8
 +        || AV_RL32(p->buf + 16) != 2096
 +        ||!AV_RL32(p->buf + 21)
 +        || AV_RL16(p->buf + 25) != 2096
 +        || AV_RL32(p->buf + 48) % AV_RL32(p->buf + 21)
 +        )
 +        return 0;
 +    return AVPROBE_SCORE_EXTENSION;
 +}
 +
 +
 +static int read_header(AVFormatContext *s)
 +{
 +    AVStream *st = avformat_new_stream(s, NULL);
 +    if (!st)
 +        return AVERROR(ENOMEM);
 +
 +    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
 +    st->codec->codec_id = AV_CODEC_ID_ADPCM_MS;
 +
 +    avio_rl32(s->pb);
 +    avio_rl32(s->pb);
 +    st->codec->sample_rate = avio_rl32(s->pb);
 +    st->codec->channels    = avio_rl32(s->pb);
-     avio_seek(s->pb, s->data_offset, SEEK_SET);
++    s->internal->data_offset = avio_rl32(s->pb);
 +    avio_r8(s->pb);
 +    st->codec->block_align = st->codec->channels * avio_rl32(s->pb);
 +
++    avio_seek(s->pb, s->internal->data_offset, SEEK_SET);
 +
 +    return 0;
 +}
 +
 +static int read_packet(AVFormatContext *s, AVPacket *pkt)
 +{
 +    AVStream *st = s->streams[0];
 +
 +    return av_get_packet(s->pb, pkt, st->codec->block_align);
 +}
 +
 +AVInputFormat ff_boa_demuxer = {
 +    .name           = "boa",
 +    .long_name      = NULL_IF_CONFIG_SMALL("Black Ops Audio"),
 +    .read_probe     = probe,
 +    .read_header    = read_header,
 +    .read_packet    = read_packet,
 +    .flags          = AVFMT_GENERIC_INDEX,
 +};
@@@ -422,10 -395,10 +422,10 @@@ static int64_t dv_frame_offset(AVFormat
                                 int64_t timestamp, int flags)
  {
      // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk)
 -    const AVDVProfile *sys = av_dv_codec_profile(c->vst->codec->width, c->vst->codec->height,
 -                                                 c->vst->codec->pix_fmt);
 +    const AVDVProfile *sys = av_dv_codec_profile2(c->vst->codec->width, c->vst->codec->height,
 +                                                 c->vst->codec->pix_fmt, c->vst->codec->time_base);
      int64_t offset;
-     int64_t size       = avio_size(s->pb) - s->data_offset;
+     int64_t size       = avio_size(s->pb) - s->internal->data_offset;
      int64_t max_offset = ((size - 1) / sys->frame_size) * sys->frame_size;
  
      offset = sys->frame_size * timestamp;
@@@ -54,8 -50,49 +54,50 @@@ struct AVFormatInternal 
       */
      int nb_interleaved_streams;
  
 -};
+     /**
+      * This buffer is only needed when packets were already buffered but
+      * not decoded, for example to get the codec parameters in MPEG
+      * streams.
+      */
+     struct AVPacketList *packet_buffer;
+     struct AVPacketList *packet_buffer_end;
+     /* av_seek_frame() support */
+     int64_t data_offset; /**< offset of the first packet */
+     /**
+      * Raw packets from the demuxer, prior to parsing and decoding.
+      * This buffer is used for buffering packets until the codec can
+      * be identified, as parsing cannot be done without knowing the
+      * codec.
+      */
+     struct AVPacketList *raw_packet_buffer;
+     struct AVPacketList *raw_packet_buffer_end;
+     /**
+      * Packets split by the parser get queued here.
+      */
+     struct AVPacketList *parse_queue;
+     struct AVPacketList *parse_queue_end;
+     /**
+      * Remaining size available for raw_packet_buffer, in bytes.
+      */
+ #define RAW_PACKET_BUFFER_SIZE 2500000
+     int raw_packet_buffer_remaining_size;
+     /**
+      * Offset to remap timestamps to be non-negative.
+      * Expressed in timebase units.
++     * @see AVStream.mux_ts_offset
+      */
+     int64_t offset;
+     /**
+      * Timebase for the timestamp offset.
+      */
+     AVRational offset_timebase;
 -void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
 +    int inject_global_side_data;
 +};
  
  #ifdef __GNUC__
  #define dynarray_add(tab, nb_ptr, elem)\
@@@ -413,40 -363,18 +413,40 @@@ static int mp3_seek(AVFormatContext *s
                      int flags)
  {
      MP3DecContext *mp3 = s->priv_data;
 -    AVIndexEntry *ie;
 +    AVIndexEntry *ie, ie1;
      AVStream *st = s->streams[0];
      int64_t ret  = av_index_search_timestamp(st, timestamp, flags);
 -    uint32_t header = 0;
 -
 -    if (!mp3->xing_toc)
 -        return AVERROR(ENOSYS);
 +    int i, j;
 +    int dir = (flags&AVSEEK_FLAG_BACKWARD) ? -1 : 1;
 +    int64_t best_pos;
 +    int best_score;
 +
 +    if (   mp3->is_cbr
 +        && st->duration > 0
-         && mp3->header_filesize > s->data_offset
++        && mp3->header_filesize > s->internal->data_offset
 +        && mp3->frames) {
 +        int64_t filesize = avio_size(s->pb);
 +        int64_t duration;
-         if (filesize <= s->data_offset)
++        if (filesize <= s->internal->data_offset)
 +            filesize = mp3->header_filesize;
-         filesize -= s->data_offset;
-         duration = av_rescale(st->duration, filesize, mp3->header_filesize - s->data_offset);
++        filesize -= s->internal->data_offset;
++        duration = av_rescale(st->duration, filesize, mp3->header_filesize - s->internal->data_offset);
 +        ie = &ie1;
 +        timestamp = av_clip64(timestamp, 0, duration);
 +        ie->timestamp = timestamp;
-         ie->pos       = av_rescale(timestamp, filesize, duration) + s->data_offset;
++        ie->pos       = av_rescale(timestamp, filesize, duration) + s->internal->data_offset;
 +    } else if (mp3->xing_toc) {
 +        if (ret < 0)
 +            return ret;
 +
 +        ie = &st->index_entries[ret];
 +    } else {
 +        st->skip_samples = timestamp <= 0 ? mp3->start_pad + 528 + 1 : 0;
  
 -    if (ret < 0)
 -        return ret;
 +        return -1;
 +    }
  
 -    ie = &st->index_entries[ret];
 +    avio_seek(s->pb, FFMAX(ie->pos - 4096, 0), SEEK_SET);
      ret = avio_seek(s->pb, ie->pos, SEEK_SET);
      if (ret < 0)
          return ret;
Simple merge
@@@ -537,37 -321,21 +537,37 @@@ static int compute_pkt_fields2(AVFormat
   * Those additional safety checks should be dropped once the correct checks
   * are set in the callers.
   */
 -
  static int write_packet(AVFormatContext *s, AVPacket *pkt)
  {
 -    int ret;
 +    int ret, did_split;
 +
 +    if (s->output_ts_offset) {
 +        AVStream *st = s->streams[pkt->stream_index];
 +        int64_t offset = av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
 +
 +        if (pkt->dts != AV_NOPTS_VALUE)
 +            pkt->dts += offset;
 +        if (pkt->pts != AV_NOPTS_VALUE)
 +            pkt->pts += offset;
 +    }
 +
      if (s->avoid_negative_ts > 0) {
 -        AVRational time_base = s->streams[pkt->stream_index]->time_base;
 -        int64_t offset = 0;
 +        AVStream *st = s->streams[pkt->stream_index];
 +        int64_t offset = st->mux_ts_offset;
  
-         if (s->offset == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE &&
+         if (s->internal->offset == AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE &&
              (pkt->dts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
-             s->offset = -pkt->dts;
-             s->offset_timebase = st->time_base;
+             s->internal->offset = -pkt->dts;
 -            s->internal->offset_timebase = time_base;
++            s->internal->offset_timebase = st->time_base;
 +        }
 +
-         if (s->offset != AV_NOPTS_VALUE && !offset) {
++        if (s->internal->offset != AV_NOPTS_VALUE && !offset) {
 +            offset = st->mux_ts_offset =
-                 av_rescale_q_rnd(s->offset,
-                                  s->offset_timebase,
++                av_rescale_q_rnd(s->internal->offset,
++                                 s->internal->offset_timebase,
 +                                 st->time_base,
 +                                 AV_ROUND_UP);
          }
 -        if (s->internal->offset != AV_NOPTS_VALUE)
 -            offset = av_rescale_q(s->internal->offset, s->internal->offset_timebase, time_base);
  
          if (pkt->dts != AV_NOPTS_VALUE)
              pkt->dts += offset;
@@@ -692,46 -426,22 +692,46 @@@ FF_ENABLE_DEPRECATION_WARNING
      }
  
      if (s->streams[pkt->stream_index]->last_in_packet_buffer) {
 -        next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next);
 -    } else
 +        next_point = &(st->last_in_packet_buffer->next);
 +    } else {
-         next_point = &s->packet_buffer;
+         next_point = &s->internal->packet_buffer;
 +    }
  
 +    if (chunked) {
 +        uint64_t max= av_rescale_q_rnd(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base, AV_ROUND_UP);
 +        st->interleaver_chunk_size     += pkt->size;
 +        st->interleaver_chunk_duration += pkt->duration;
 +        if (   (s->max_chunk_size && st->interleaver_chunk_size > s->max_chunk_size)
 +            || (max && st->interleaver_chunk_duration           > max)) {
 +            st->interleaver_chunk_size      = 0;
 +            this_pktl->pkt.flags |= CHUNK_START;
 +            if (max && st->interleaver_chunk_duration > max) {
 +                int64_t syncoffset = (st->codec->codec_type == AVMEDIA_TYPE_VIDEO)*max/2;
 +                int64_t syncto = av_rescale(pkt->dts + syncoffset, 1, max)*max - syncoffset;
 +
 +                st->interleaver_chunk_duration += (pkt->dts - syncto)/8 - max;
 +            } else
 +                st->interleaver_chunk_duration = 0;
 +        }
 +    }
      if (*next_point) {
-         if (compare(s, &s->packet_buffer_end->pkt, pkt)) {
 +        if (chunked && !(this_pktl->pkt.flags & CHUNK_START))
 +            goto next_non_null;
 +
 -            while (!compare(s, &(*next_point)->pkt, pkt))
+         if (compare(s, &s->internal->packet_buffer_end->pkt, pkt)) {
 +            while (   *next_point
 +                   && ((chunked && !((*next_point)->pkt.flags&CHUNK_START))
 +                       || !compare(s, &(*next_point)->pkt, pkt)))
                  next_point = &(*next_point)->next;
 -            goto next_non_null;
 +            if (*next_point)
 +                goto next_non_null;
          } else {
-             next_point = &(s->packet_buffer_end->next);
+             next_point = &(s->internal->packet_buffer_end->next);
          }
      }
 -    assert(!*next_point);
 +    av_assert1(!*next_point);
  
-     s->packet_buffer_end = this_pktl;
+     s->internal->packet_buffer_end = this_pktl;
  next_non_null:
  
      this_pktl->next = *next_point;
@@@ -778,25 -477,8 +778,25 @@@ int ff_interleave_packet_per_dts(AVForm
              return ret;
      }
  
 -    if (s->max_interleave_delta > 0 && s->internal->packet_buffer && !flush) {
 +    for (i = 0; i < s->nb_streams; i++) {
 +        if (s->streams[i]->last_in_packet_buffer) {
 +            ++stream_count;
 +        } else if (s->streams[i]->codec->codec_type != AVMEDIA_TYPE_ATTACHMENT &&
 +                   s->streams[i]->codec->codec_id != AV_CODEC_ID_VP8 &&
 +                   s->streams[i]->codec->codec_id != AV_CODEC_ID_VP9) {
 +            ++noninterleaved_count;
 +        }
 +    }
 +
 +    if (s->internal->nb_interleaved_streams == stream_count)
 +        flush = 1;
 +
 +    if (s->max_interleave_delta > 0 &&
-         s->packet_buffer &&
++        s->internal->packet_buffer &&
 +        !flush &&
 +        s->internal->nb_interleaved_streams == stream_count+noninterleaved_count
 +    ) {
-         AVPacket *top_pkt = &s->packet_buffer->pkt;
+         AVPacket *top_pkt = &s->internal->packet_buffer->pkt;
          int64_t delta_dts = INT64_MIN;
          int64_t top_dts = av_rescale_q(top_pkt->dts,
                                         s->streams[top_pkt->stream_index]->time_base,
                     delta_dts, s->max_interleave_delta);
              flush = 1;
          }
 -    } else {
 -        for (i = 0; i < s->nb_streams; i++)
 -            stream_count += !!s->streams[i]->last_in_packet_buffer;
      }
  
 -
 -    if (stream_count && (s->internal->nb_interleaved_streams == stream_count || flush)) {
 +    if (stream_count && flush) {
 +        AVStream *st;
-         pktl = s->packet_buffer;
+         pktl = s->internal->packet_buffer;
          *out = pktl->pkt;
 +        st   = s->streams[out->stream_index];
  
-         s->packet_buffer = pktl->next;
-         if (!s->packet_buffer)
-             s->packet_buffer_end = NULL;
+         s->internal->packet_buffer = pktl->next;
+         if (!s->internal->packet_buffer)
+             s->internal->packet_buffer_end = NULL;
  
 -        if (s->streams[out->stream_index]->last_in_packet_buffer == pktl)
 -            s->streams[out->stream_index]->last_in_packet_buffer = NULL;
 +        if (st->last_in_packet_buffer == pktl)
 +            st->last_in_packet_buffer = NULL;
          av_freep(&pktl);
 +
          return 1;
      } else {
          av_init_packet(out);
Simple merge
Simple merge
@@@ -141,16 -132,8 +141,16 @@@ static int ogg_reset(AVFormatContext *s
          os->nsegs      = 0;
          os->segp       = 0;
          os->incomplete = 0;
-         if (start_pos <= s->data_offset) {
 +        os->got_data = 0;
++        if (start_pos <= s->internal->data_offset) {
 +            os->lastpts = 0;
 +        }
 +        os->end_trimming = 0;
 +        av_freep(&os->new_metadata);
 +        os->new_metadata_size = 0;
      }
  
 +    ogg->page_pos = -1;
      ogg->curidx = -1;
  
      return 0;
@@@ -612,24 -528,6 +612,24 @@@ static int ogg_get_length(AVFormatConte
  
      ogg_restore(s, 0);
  
-     avio_seek (s->pb, s->data_offset, SEEK_SET);
 +    ogg_save (s);
++    avio_seek (s->pb, s->internal->data_offset, SEEK_SET);
 +    ogg_reset(s);
 +    while (streams_left > 0 && !ogg_packet(s, &i, NULL, NULL, NULL)) {
 +        int64_t pts;
 +        if (i < 0) continue;
 +        pts = ogg_calc_pts(s, i, NULL);
 +        if (pts != AV_NOPTS_VALUE && s->streams[i]->start_time == AV_NOPTS_VALUE && !ogg->streams[i].got_start) {
 +            s->streams[i]->duration -= pts;
 +            ogg->streams[i].got_start= 1;
 +            streams_left--;
 +        }else if(s->streams[i]->start_time != AV_NOPTS_VALUE && !ogg->streams[i].got_start) {
 +            ogg->streams[i].got_start= 1;
 +            streams_left--;
 +        }
 +    }
 +    ogg_restore (s, 0);
 +
      return 0;
  }
  
Simple merge
  
  #include "libavutil/mathematics.h"
  #include "avformat.h"
+ #include "internal.h"
  #include "pcm.h"
  
 +#define RAW_SAMPLES     1024
 +
 +int ff_pcm_read_packet(AVFormatContext *s, AVPacket *pkt)
 +{
 +    int ret, size;
 +
 +    size= RAW_SAMPLES*s->streams[0]->codec->block_align;
 +    if (size <= 0)
 +        return AVERROR(EINVAL);
 +
 +    ret= av_get_packet(s->pb, pkt, size);
 +
 +    pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
 +    pkt->stream_index = 0;
 +
 +    return ret;
 +}
 +
  int ff_pcm_read_seek(AVFormatContext *s,
                       int stream_index, int64_t timestamp, int flags)
  {
Simple merge
@@@ -305,26 -179,6 +305,26 @@@ static int set_codec_from_probe_data(AV
  /************************************************************/
  /* input media file */
  
-     if (ic->pb && !ic->data_offset)
-         ic->data_offset = avio_tell(ic->pb);
 +int av_demuxer_open(AVFormatContext *ic) {
 +    int err;
 +
 +    if (ic->format_whitelist && av_match_list(ic->iformat->name, ic->format_whitelist, ',') <= 0) {
 +        av_log(ic, AV_LOG_ERROR, "Format not on whitelist\n");
 +        return AVERROR(EINVAL);
 +    }
 +
 +    if (ic->iformat->read_header) {
 +        err = ic->iformat->read_header(ic);
 +        if (err < 0)
 +            return err;
 +    }
 +
++    if (ic->pb && !ic->internal->data_offset)
++        ic->internal->data_offset = avio_tell(ic->pb);
 +
 +    return 0;
 +}
 +
  /* Open input file and probe the format if necessary. */
  static int init_input(AVFormatContext *s, const char *filename,
                        AVDictionary **options)
@@@ -466,23 -299,18 +466,23 @@@ int avformat_open_input(AVFormatContex
          if ((ret = s->iformat->read_header(s)) < 0)
              goto fail;
  
 -    if (id3v2_extra_meta &&
 -        (ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0)
 -        goto fail;
 +    if (id3v2_extra_meta) {
 +        if (!strcmp(s->iformat->name, "mp3") || !strcmp(s->iformat->name, "aac") ||
 +            !strcmp(s->iformat->name, "tta")) {
 +            if ((ret = ff_id3v2_parse_apic(s, &id3v2_extra_meta)) < 0)
 +                goto fail;
 +        } else
 +            av_log(s, AV_LOG_DEBUG, "demuxer does not support additional id3 data, skipping\n");
 +    }
      ff_id3v2_free_extra_meta(&id3v2_extra_meta);
  
 -    if ((ret = queue_attached_pictures(s)) < 0)
 +    if ((ret = avformat_queue_attached_pictures(s)) < 0)
          goto fail;
  
-     if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset)
-         s->data_offset = avio_tell(s->pb);
 -    if (s->pb && !s->internal->data_offset)
++    if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->internal->data_offset)
+         s->internal->data_offset = avio_tell(s->pb);
  
-     s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
+     s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
  
      if (options) {
          av_dict_free(options);
@@@ -550,22 -354,16 +550,22 @@@ no_packet
              }
          }
  
-         end=    s->raw_packet_buffer_remaining_size <= 0
 -        if (!st->probe_packets ||
 -            av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) {
 -            set_codec_from_probe_data(s, st, pd, st->probe_packets > 0
 -                                                 ? AVPROBE_SCORE_MAX / 4 : 0);
 -            if (st->codec->codec_id != AV_CODEC_ID_PROBE) {
++        end=    s->internal->raw_packet_buffer_remaining_size <= 0
 +                || st->probe_packets<= 0;
 +
 +        if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) {
 +            int score = set_codec_from_probe_data(s, st, pd);
 +            if (    (st->codec->codec_id != AV_CODEC_ID_NONE && score > AVPROBE_SCORE_STREAM_RETRY)
 +                || end) {
                  pd->buf_size = 0;
                  av_freep(&pd->buf);
 -                av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index);
 +                st->request_probe = -1;
 +                if (st->codec->codec_id != AV_CODEC_ID_NONE) {
 +                    av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index);
 +                } else
 +                    av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index);
              }
 +            force_codec_ids(s, st);
          }
      }
      return 0;
@@@ -648,12 -380,18 +648,12 @@@ int ff_read_packet(AVFormatContext *s, 
          if (pktl) {
              *pkt = pktl->pkt;
              st   = s->streams[pkt->stream_index];
-             if (s->raw_packet_buffer_remaining_size <= 0)
 -            if (st->codec->codec_id != AV_CODEC_ID_PROBE ||
 -                !st->probe_packets ||
 -                s->internal->raw_packet_buffer_remaining_size < pkt->size) {
 -                AVProbeData *pd;
 -                if (st->probe_packets)
 -                    if ((err = probe_codec(s, st, NULL)) < 0)
 -                        return err;
 -                pd = &st->probe_data;
 -                av_freep(&pd->buf);
 -                pd->buf_size = 0;
++            if (s->internal->raw_packet_buffer_remaining_size <= 0)
 +                if ((err = probe_codec(s, st, NULL)) < 0)
 +                    return err;
 +            if (st->request_probe <= 0) {
-                 s->raw_packet_buffer                 = pktl->next;
-                 s->raw_packet_buffer_remaining_size += pkt->size;
+                 s->internal->raw_packet_buffer                 = pktl->next;
+                 s->internal->raw_packet_buffer_remaining_size += pkt->size;
                  av_free(pktl);
                  return 0;
              }
              continue;
          }
  
 +        if (pkt->stream_index >= (unsigned)s->nb_streams) {
 +            av_log(s, AV_LOG_ERROR, "Invalid stream index %d\n", pkt->stream_index);
 +            continue;
 +        }
 +
          st = s->streams[pkt->stream_index];
  
 -        switch (st->codec->codec_type) {
 -        case AVMEDIA_TYPE_VIDEO:
 -            if (s->video_codec_id)
 -                st->codec->codec_id = s->video_codec_id;
 -            break;
 -        case AVMEDIA_TYPE_AUDIO:
 -            if (s->audio_codec_id)
 -                st->codec->codec_id = s->audio_codec_id;
 -            break;
 -        case AVMEDIA_TYPE_SUBTITLE:
 -            if (s->subtitle_codec_id)
 -                st->codec->codec_id = s->subtitle_codec_id;
 -            break;
 +        if (update_wrap_reference(s, st, pkt->stream_index, pkt) && st->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) {
 +            // correct first time stamps to negative values
 +            if (!is_relative(st->first_dts))
 +                st->first_dts = wrap_timestamp(st, st->first_dts);
 +            if (!is_relative(st->start_time))
 +                st->start_time = wrap_timestamp(st, st->start_time);
 +            if (!is_relative(st->cur_dts))
 +                st->cur_dts = wrap_timestamp(st, st->cur_dts);
          }
  
 -        if (!pktl && (st->codec->codec_id != AV_CODEC_ID_PROBE ||
 -                      !st->probe_packets))
 +        pkt->dts = wrap_timestamp(st, pkt->dts);
 +        pkt->pts = wrap_timestamp(st, pkt->pts);
 +
 +        force_codec_ids(s, st);
 +
 +        /* TODO: audio: time filter; video: frame reordering (pts != dts) */
 +        if (s->use_wallclock_as_timestamps)
 +            pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base);
 +
 +        if (!pktl && st->request_probe <= 0)
              return ret;
  
-         add_to_pktbuf(&s->raw_packet_buffer, pkt, &s->raw_packet_buffer_end);
-         s->raw_packet_buffer_remaining_size -= pkt->size;
+         add_to_pktbuf(&s->internal->raw_packet_buffer, pkt,
+                       &s->internal->raw_packet_buffer_end);
+         s->internal->raw_packet_buffer_remaining_size -= pkt->size;
  
          if ((err = probe_codec(s, st, pkt)) < 0)
              return err;
@@@ -789,99 -502,21 +790,99 @@@ void ff_compute_frame_duration(AVFormat
      }
  }
  
 -static int is_intra_only(enum AVCodecID id)
 +static int is_intra_only(AVCodecContext *enc) {
 +    const AVCodecDescriptor *desc;
 +
 +    if (enc->codec_type != AVMEDIA_TYPE_VIDEO)
 +        return 1;
 +
 +    desc = av_codec_get_codec_descriptor(enc);
 +    if (!desc) {
 +        desc = avcodec_descriptor_get(enc->codec_id);
 +        av_codec_set_codec_descriptor(enc, desc);
 +    }
 +    if (desc)
 +        return !!(desc->props & AV_CODEC_PROP_INTRA_ONLY);
 +    return 0;
 +}
 +
 +static int has_decode_delay_been_guessed(AVStream *st)
  {
 -    const AVCodecDescriptor *d = avcodec_descriptor_get(id);
 -    if (!d)
 -        return 0;
 -    if (d->type == AVMEDIA_TYPE_VIDEO && !(d->props & AV_CODEC_PROP_INTRA_ONLY))
 -        return 0;
 -    return 1;
 +    if (st->codec->codec_id != AV_CODEC_ID_H264) return 1;
 +    if (!st->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy
 +        return 1;
 +#if CONFIG_H264_DECODER
 +    if (st->codec->has_b_frames &&
 +       avpriv_h264_has_num_reorder_frames(st->codec) == st->codec->has_b_frames)
 +        return 1;
 +#endif
 +    if (st->codec->has_b_frames<3)
 +        return st->nb_decoded_frames >= 7;
 +    else if (st->codec->has_b_frames<4)
 +        return st->nb_decoded_frames >= 18;
 +    else
 +        return st->nb_decoded_frames >= 20;
 +}
 +
 +static AVPacketList *get_next_pkt(AVFormatContext *s, AVStream *st, AVPacketList *pktl)
 +{
 +    if (pktl->next)
 +        return pktl->next;
-     if (pktl == s->packet_buffer_end)
-         return s->parse_queue;
++    if (pktl == s->internal->packet_buffer_end)
++        return s->internal->parse_queue;
 +    return NULL;
 +}
 +
 +static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t dts) {
 +    int onein_oneout = st->codec->codec_id != AV_CODEC_ID_H264 &&
 +                       st->codec->codec_id != AV_CODEC_ID_HEVC;
 +
 +    if(!onein_oneout) {
 +        int delay = st->codec->has_b_frames;
 +        int i;
 +
 +        if (dts == AV_NOPTS_VALUE) {
 +            int64_t best_score = INT64_MAX;
 +            for (i = 0; i<delay; i++) {
 +                if (st->pts_reorder_error_count[i]) {
 +                    int64_t score = st->pts_reorder_error[i] / st->pts_reorder_error_count[i];
 +                    if (score < best_score) {
 +                        best_score = score;
 +                        dts = pts_buffer[i];
 +                    }
 +                }
 +            }
 +        } else {
 +            for (i = 0; i<delay; i++) {
 +                if (pts_buffer[i] != AV_NOPTS_VALUE) {
 +                    int64_t diff =  FFABS(pts_buffer[i] - dts)
 +                                    + (uint64_t)st->pts_reorder_error[i];
 +                    diff = FFMAX(diff, st->pts_reorder_error[i]);
 +                    st->pts_reorder_error[i] = diff;
 +                    st->pts_reorder_error_count[i]++;
 +                    if (st->pts_reorder_error_count[i] > 250) {
 +                        st->pts_reorder_error[i] >>= 1;
 +                        st->pts_reorder_error_count[i] >>= 1;
 +                    }
 +                }
 +            }
 +        }
 +    }
 +
 +    if (dts == AV_NOPTS_VALUE)
 +        dts = pts_buffer[0];
 +
 +    return dts;
  }
  
  static void update_initial_timestamps(AVFormatContext *s, int stream_index,
 -                                      int64_t dts, int64_t pts)
 +                                      int64_t dts, int64_t pts, AVPacket *pkt)
  {
      AVStream *st       = s->streams[stream_index];
-     AVPacketList *pktl = s->packet_buffer ? s->packet_buffer : s->parse_queue;
 -    AVPacketList *pktl = s->internal->packet_buffer;
++    AVPacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
 +    int64_t pts_buffer[MAX_REORDER_DELAY+1];
 +    int64_t shift;
 +    int i, delay;
  
      if (st->first_dts != AV_NOPTS_VALUE ||
          dts           == AV_NOPTS_VALUE ||
  static void update_initial_durations(AVFormatContext *s, AVStream *st,
                                       int stream_index, int duration)
  {
-     AVPacketList *pktl = s->packet_buffer ? s->packet_buffer : s->parse_queue;
 -    AVPacketList *pktl = s->internal->packet_buffer;
 -    int64_t cur_dts    = 0;
++    AVPacketList *pktl = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
 +    int64_t cur_dts    = RELATIVE_TS_BASE;
  
      if (st->first_dts != AV_NOPTS_VALUE) {
 +        if (st->update_initial_durations_done)
 +            return;
 +        st->update_initial_durations_done = 1;
          cur_dts = st->first_dts;
 -        for (; pktl; pktl = pktl->next) {
 +        for (; pktl; pktl = get_next_pkt(s, st, pktl)) {
              if (pktl->pkt.stream_index == stream_index) {
                  if (pktl->pkt.pts != pktl->pkt.dts  ||
                      pktl->pkt.dts != AV_NOPTS_VALUE ||
                  cur_dts -= duration;
              }
          }
 -        pktl          = s->internal->packet_buffer;
 +        if (pktl && pktl->pkt.dts != st->first_dts) {
 +            av_log(s, AV_LOG_DEBUG, "first_dts %s not matching first dts %s (pts %s, duration %d) in the queue\n",
 +                   av_ts2str(st->first_dts), av_ts2str(pktl->pkt.dts), av_ts2str(pktl->pkt.pts), pktl->pkt.duration);
 +            return;
 +        }
 +        if (!pktl) {
 +            av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(st->first_dts));
 +            return;
 +        }
-         pktl          = s->packet_buffer ? s->packet_buffer : s->parse_queue;
++        pktl          = s->internal->packet_buffer ? s->internal->packet_buffer : s->internal->parse_queue;
          st->first_dts = cur_dts;
 -    } else if (st->cur_dts)
 +    } else if (st->cur_dts != RELATIVE_TS_BASE)
          return;
  
 -    for (; pktl; pktl = pktl->next) {
 +    for (; pktl; pktl = get_next_pkt(s, st, pktl)) {
          if (pktl->pkt.stream_index != stream_index)
              continue;
          if (pktl->pkt.pts == pktl->pkt.dts  &&
@@@ -1064,9 -631,10 +1065,9 @@@ static void compute_pkt_fields(AVFormat
          }
      }
  
-     if (pkt->duration != 0 && (s->packet_buffer || s->parse_queue))
++    if (pkt->duration != 0 && (s->internal->packet_buffer || s->internal->parse_queue))
 +        update_initial_durations(s, st, pkt->stream_index, pkt->duration);
 +
      /* Correct timestamps with byte offset if demuxers only have timestamps
       * on packet boundaries */
      if (pc && st->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size) {
@@@ -1383,65 -945,11 +1384,65 @@@ static int read_frame_internal(AVFormat
              /* free packet */
              av_free_packet(&cur_pkt);
          }
 +        if (pkt->flags & AV_PKT_FLAG_KEY)
 +            st->skip_to_keyframe = 0;
 +        if (st->skip_to_keyframe) {
 +            av_free_packet(&cur_pkt);
 +            if (got_packet) {
 +                *pkt = cur_pkt;
 +            }
 +            got_packet = 0;
 +        }
      }
  
-     if (!got_packet && s->parse_queue)
-         ret = read_from_packet_buffer(&s->parse_queue, &s->parse_queue_end, pkt);
+     if (!got_packet && s->internal->parse_queue)
+         ret = read_from_packet_buffer(&s->internal->parse_queue, &s->internal->parse_queue_end, pkt);
  
 +    if (ret >= 0) {
 +        AVStream *st = s->streams[pkt->stream_index];
 +        int discard_padding = 0;
 +        if (st->first_discard_sample && pkt->pts != AV_NOPTS_VALUE) {
 +            int64_t pts = pkt->pts - (is_relative(pkt->pts) ? RELATIVE_TS_BASE : 0);
 +            int64_t sample = ts_to_samples(st, pts);
 +            int duration = ts_to_samples(st, pkt->duration);
 +            int64_t end_sample = sample + duration;
 +            if (duration > 0 && end_sample >= st->first_discard_sample &&
 +                sample < st->last_discard_sample)
 +                discard_padding = FFMIN(end_sample - st->first_discard_sample, duration);
 +        }
 +        if (st->skip_samples || discard_padding) {
 +            uint8_t *p = av_packet_new_side_data(pkt, AV_PKT_DATA_SKIP_SAMPLES, 10);
 +            if (p) {
 +                AV_WL32(p, st->skip_samples);
 +                AV_WL32(p + 4, discard_padding);
 +                av_log(s, AV_LOG_DEBUG, "demuxer injecting skip %d\n", st->skip_samples);
 +            }
 +            st->skip_samples = 0;
 +        }
 +
 +        if (st->inject_global_side_data) {
 +            for (i = 0; i < st->nb_side_data; i++) {
 +                AVPacketSideData *src_sd = &st->side_data[i];
 +                uint8_t *dst_data;
 +
 +                if (av_packet_get_side_data(pkt, src_sd->type, NULL))
 +                    continue;
 +
 +                dst_data = av_packet_new_side_data(pkt, src_sd->type, src_sd->size);
 +                if (!dst_data) {
 +                    av_log(s, AV_LOG_WARNING, "Could not inject global side data\n");
 +                    continue;
 +                }
 +
 +                memcpy(dst_data, src_sd->data, src_sd->size);
 +            }
 +            st->inject_global_side_data = 0;
 +        }
 +
 +        if (!(s->flags & AVFMT_FLAG_KEEP_SIDE_DATA))
 +            av_packet_merge_side_data(pkt);
 +    }
 +
      av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata);
      if (metadata) {
          s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
@@@ -1466,21 -972,16 +1467,21 @@@ int av_read_frame(AVFormatContext *s, A
  {
      const int genpts = s->flags & AVFMT_FLAG_GENPTS;
      int eof = 0;
 +    int ret;
 +    AVStream *st;
  
 -    if (!genpts)
 -        return s->internal->packet_buffer
 -               ? read_from_packet_buffer(&s->internal->packet_buffer,
 -                                         &s->internal->packet_buffer_end, pkt)
 -               : read_frame_internal(s, pkt);
 +    if (!genpts) {
-         ret = s->packet_buffer
-               ? read_from_packet_buffer(&s->packet_buffer,
-                                         &s->packet_buffer_end, pkt)
++        ret = s->internal->packet_buffer
++              ? read_from_packet_buffer(&s->internal->packet_buffer,
++                                        &s->internal->packet_buffer_end, pkt)
 +              : read_frame_internal(s, pkt);
 +        if (ret < 0)
 +            return ret;
 +        goto return_packet;
 +    }
  
      for (;;) {
-         AVPacketList *pktl = s->packet_buffer;
 -        int ret;
+         AVPacketList *pktl = s->internal->packet_buffer;
  
          if (pktl) {
              AVPacket *next_pkt = &pktl->pkt;
                      }
                      pktl = pktl->next;
                  }
-                 pktl = s->packet_buffer;
 +                if (eof && next_pkt->pts == AV_NOPTS_VALUE && last_dts != AV_NOPTS_VALUE) {
 +                    // Fixing the last reference frame had none pts issue (For MXF etc).
 +                    // We only do this when
 +                    // 1. eof.
 +                    // 2. we are not able to resolve a pts value for current packet.
 +                    // 3. the packets for this stream at the end of the files had valid dts.
 +                    next_pkt->pts = last_dts + next_pkt->duration;
 +                }
+                 pktl = s->internal->packet_buffer;
              }
  
              /* read packet from packet buffer, if there is data */
 -            if (!(next_pkt->pts == AV_NOPTS_VALUE &&
 -                  next_pkt->dts != AV_NOPTS_VALUE && !eof))
 -                return read_from_packet_buffer(&s->internal->packet_buffer,
 +            st = s->streams[next_pkt->stream_index];
 +            if (!(next_pkt->pts == AV_NOPTS_VALUE && st->discard < AVDISCARD_ALL &&
 +                  next_pkt->dts != AV_NOPTS_VALUE && !eof)) {
-                 ret = read_from_packet_buffer(&s->packet_buffer,
-                                                &s->packet_buffer_end, pkt);
++                ret = read_from_packet_buffer(&s->internal->packet_buffer,
+                                                &s->internal->packet_buffer_end, pkt);
 +                goto return_packet;
 +            }
          }
  
          ret = read_frame_internal(s, pkt);
                  return ret;
          }
  
-         if (av_dup_packet(add_to_pktbuf(&s->packet_buffer, pkt,
-                                         &s->packet_buffer_end)) < 0)
+         if (av_dup_packet(add_to_pktbuf(&s->internal->packet_buffer, pkt,
+                                         &s->internal->packet_buffer_end)) < 0)
              return AVERROR(ENOMEM);
      }
 +
 +return_packet:
 +
 +    st = s->streams[pkt->stream_index];
 +    if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY) {
 +        ff_reduce_index(s, st->index);
 +        av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME);
 +    }
 +
 +    if (is_relative(pkt->dts))
 +        pkt->dts -= RELATIVE_TS_BASE;
 +    if (is_relative(pkt->pts))
 +        pkt->pts -= RELATIVE_TS_BASE;
 +
 +    return ret;
  }
  
  /* XXX: suppress the packet queue */
  static void flush_packet_queue(AVFormatContext *s)
  {
-     free_packet_buffer(&s->parse_queue,       &s->parse_queue_end);
-     free_packet_buffer(&s->packet_buffer,     &s->packet_buffer_end);
-     free_packet_buffer(&s->raw_packet_buffer, &s->raw_packet_buffer_end);
++    if (!s->internal)
++        return;
+     free_packet_buffer(&s->internal->parse_queue,       &s->internal->parse_queue_end);
+     free_packet_buffer(&s->internal->packet_buffer,     &s->internal->packet_buffer_end);
+     free_packet_buffer(&s->internal->raw_packet_buffer, &s->internal->raw_packet_buffer_end);
  
-     s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
+     s->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
  }
  
  /*******************************************************/
@@@ -1893,15 -1282,14 +1896,15 @@@ int64_t ff_gen_search(AVFormatContext *
                                                  int64_t *, int64_t))
  {
      int64_t pos, ts;
 -    int64_t start_pos, filesize;
 +    int64_t start_pos;
      int no_change;
 +    int ret;
  
 -    av_dlog(s, "gen_seek: %d %"PRId64"\n", stream_index, target_ts);
 +    av_dlog(s, "gen_seek: %d %s\n", stream_index, av_ts2str(target_ts));
  
      if (ts_min == AV_NOPTS_VALUE) {
-         pos_min = s->data_offset;
+         pos_min = s->internal->data_offset;
 -        ts_min  = read_timestamp(s, stream_index, &pos_min, INT64_MAX);
 +        ts_min  = ff_read_timestamp(s, stream_index, &pos_min, INT64_MAX, read_timestamp);
          if (ts_min == AV_NOPTS_VALUE)
              return -1;
      }
@@@ -2347,18 -1668,14 +2350,18 @@@ static void estimate_timings_from_bit_r
      if (ic->duration == AV_NOPTS_VALUE &&
          ic->bit_rate != 0) {
          filesize = ic->pb ? avio_size(ic->pb) : 0;
-         if (filesize > ic->data_offset) {
-             filesize -= ic->data_offset;
 -        if (filesize > 0) {
++        if (filesize > ic->internal->data_offset) {
++            filesize -= ic->internal->data_offset;
              for (i = 0; i < ic->nb_streams; i++) {
 -                st       = ic->streams[i];
 -                duration = av_rescale(8 * filesize, st->time_base.den,
 -                                      ic->bit_rate *
 -                                      (int64_t) st->time_base.num);
 -                if (st->duration == AV_NOPTS_VALUE)
 +                st      = ic->streams[i];
 +                if (   st->time_base.num <= INT64_MAX / ic->bit_rate
 +                    && st->duration == AV_NOPTS_VALUE) {
 +                    duration = av_rescale(8 * filesize, st->time_base.den,
 +                                          ic->bit_rate *
 +                                          (int64_t) st->time_base.num);
                      st->duration = duration;
 +                    show_warning = 1;
 +                }
              }
          }
      }
@@@ -3177,15 -2145,41 +3180,16 @@@ int avformat_find_stream_info(AVFormatC
              break;
          }
  
 -        if (ic->flags & AVFMT_FLAG_NOBUFFER) {
 -            pkt = &pkt1;
 -        } else {
 +        if (ic->flags & AVFMT_FLAG_NOBUFFER)
-             free_packet_buffer(&ic->packet_buffer, &ic->packet_buffer_end);
++            free_packet_buffer(&ic->internal->packet_buffer,
++                               &ic->internal->packet_buffer_end);
 +        {
-             pkt = add_to_pktbuf(&ic->packet_buffer, &pkt1,
-                                 &ic->packet_buffer_end);
+             pkt = add_to_pktbuf(&ic->internal->packet_buffer, &pkt1,
+                                 &ic->internal->packet_buffer_end);
 +            if (!pkt) {
 +                ret = AVERROR(ENOMEM);
 +                goto find_stream_info_err;
 +            }
              if ((ret = av_dup_packet(pkt)) < 0)
                  goto find_stream_info_err;
          }
@@@ -30,8 -30,8 +30,8 @@@
  #include "libavutil/version.h"
  
  #define LIBAVFORMAT_VERSION_MAJOR 56
 -#define LIBAVFORMAT_VERSION_MINOR 11
 -#define LIBAVFORMAT_VERSION_MICRO  0
 +#define LIBAVFORMAT_VERSION_MINOR  19
- #define LIBAVFORMAT_VERSION_MICRO 100
++#define LIBAVFORMAT_VERSION_MICRO 101
  
  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                 LIBAVFORMAT_VERSION_MINOR, \
Simple merge
Simple merge