Merge commit '91eee2af87278b3c2008f7a86d2cdfe6934e9f42'
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 2 Mar 2015 19:52:34 +0000 (20:52 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 2 Mar 2015 19:52:34 +0000 (20:52 +0100)
* commit '91eee2af87278b3c2008f7a86d2cdfe6934e9f42':
  Revert "mov: Change DTS-based seek into CTS-based seek."

Conflicts:
libavformat/mov.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/mov.c

@@@ -2413,9 -2129,11 +2411,11 @@@ static void mov_build_index(MOVContext 
          unsigned int rap_group_index = 0;
          unsigned int rap_group_sample = 0;
          int rap_group_present = sc->rap_group_count && sc->rap_group;
 -        int key_off = (sc->keyframes && sc->keyframes[0] > 0) || (sc->stps_data && sc->stps_data[0] > 0);
 +        int key_off = (sc->keyframe_count && sc->keyframes[0] > 0) || (sc->stps_count && sc->stps_data[0] > 0);
  
 -        if (!sc->sample_count)
+         current_dts -= sc->dts_shift;
 +        if (!sc->sample_count || st->nb_index_entries)
              return;
          if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
              return;
                      e->size = sample_size;
                      e->min_distance = distance;
                      e->flags = keyframe ? AVINDEX_KEYFRAME : 0;
-                     av_dlog(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", cts %"PRId64", "
+                     av_dlog(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
                              "size %d, distance %d, keyframe %d\n", st->index, current_sample,
-                             current_offset, current_cts, sample_size, distance, keyframe);
+                             current_offset, current_dts, sample_size, distance, keyframe);
 +                    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->nb_index_entries < 100)
 +                        ff_rfps_add_frame(mov->fc, st, current_dts);
                  }
  
                  current_offset += sample_size;
@@@ -3181,34 -2793,9 +3173,32 @@@ static int mov_read_trun(MOVContext *c
          if (flags & MOV_TRUN_SAMPLE_DURATION) sample_duration = avio_rb32(pb);
          if (flags & MOV_TRUN_SAMPLE_SIZE)     sample_size     = avio_rb32(pb);
          if (flags & MOV_TRUN_SAMPLE_FLAGS)    sample_flags    = avio_rb32(pb);
-         if (flags & MOV_TRUN_SAMPLE_CTS)      sample_cts      = avio_rb32(pb);
-         sc->ctts_data[sc->ctts_count].count    = 1;
-         sc->ctts_data[sc->ctts_count].duration = sample_cts;
+         sc->ctts_data[sc->ctts_count].count = 1;
+         sc->ctts_data[sc->ctts_count].duration = (flags & MOV_TRUN_SAMPLE_CTS) ?
+                                                   avio_rb32(pb) : 0;
 +        mov_update_dts_shift(sc, sc->ctts_data[sc->ctts_count].duration);
 +        if (frag->time != AV_NOPTS_VALUE) {
 +            if (c->use_mfra_for == FF_MOV_FLAG_MFRA_PTS) {
 +                int64_t pts = frag->time;
 +                av_log(c->fc, AV_LOG_DEBUG, "found frag time %"PRId64
 +                        " sc->dts_shift %d ctts.duration %d"
 +                        " sc->time_offset %"PRId64" flags & MOV_TRUN_SAMPLE_CTS %d\n", pts,
 +                        sc->dts_shift, sc->ctts_data[sc->ctts_count].duration,
 +                        sc->time_offset, flags & MOV_TRUN_SAMPLE_CTS);
 +                dts = pts - sc->dts_shift;
 +                if (flags & MOV_TRUN_SAMPLE_CTS) {
 +                    dts -= sc->ctts_data[sc->ctts_count].duration;
 +                } else {
 +                    dts -= sc->time_offset;
 +                }
 +                av_log(c->fc, AV_LOG_DEBUG, "calculated into dts %"PRId64"\n", dts);
 +            } else {
 +                dts = frag->time;
 +                av_log(c->fc, AV_LOG_DEBUG, "found frag time %"PRId64
 +                        ", using it for dts\n", dts);
 +            }
 +            frag->time = AV_NOPTS_VALUE;
 +        }
-         cts = dts + sample_cts;
          sc->ctts_count++;
          if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
              keyframe = 1;
                                    MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES));
          if (keyframe)
              distance = 0;
-         err = av_add_index_entry(st, offset, cts, sample_size, distance,
 -        av_add_index_entry(st, offset, dts, sample_size, distance,
 -                           keyframe ? AVINDEX_KEYFRAME : 0);
++        err = av_add_index_entry(st, offset, dts, sample_size, distance,
 +                                 keyframe ? AVINDEX_KEYFRAME : 0);
 +        if (err < 0) {
 +            av_log(c->fc, AV_LOG_ERROR, "Failed to add index entry\n");
 +        }
-         av_dlog(c->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", cts %"PRId64", "
+         av_dlog(c->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
                  "size %d, distance %d, keyframe %d\n", st->index, sc->sample_count+i,
-                 offset, cts, sample_size, distance, keyframe);
+                 offset, dts, sample_size, distance, keyframe);
          distance++;
          dts += sample_duration;
          offset += sample_size;