Merge commit 'a1aa37dd0b96710d4a17718198a3f56aea2040c1'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 1 May 2014 13:02:44 +0000 (15:02 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 1 May 2014 13:56:38 +0000 (15:56 +0200)
* commit 'a1aa37dd0b96710d4a17718198a3f56aea2040c1':
  matroskaenc: write CodecDelay

Conflicts:
libavformat/matroskaenc.c
tests/ref/lavf/mkv
tests/ref/seek/lavf-mkv

This is largely not merged as it causes assertion failures and av sync errors
Further investigation of this is warranted if the changes are found to
fix/improve something in relation to d92b1b1babe69268971863649c225e1747358a74

See: d92b1b1babe69268971863649c225e1747358a74
Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/matroskaenc.c
libavformat/version.h

@@@ -84,7 -78,7 +84,8 @@@ typedef struct 
  
  typedef struct {
      int             write_dts;
 +    int             has_cue;
+     int64_t         ts_offset;
  } mkv_track;
  
  #define MODE_MATROSKAv2 0x01
@@@ -660,47 -598,27 +661,51 @@@ static int mkv_write_tracks(AVFormatCon
  
          // The default value for TRACKFLAGDEFAULT is 1, so add element
          // if we need to clear it.
 -        if (!(st->disposition & AV_DISPOSITION_DEFAULT))
 +        if (default_stream_exists && !(st->disposition & AV_DISPOSITION_DEFAULT))
              put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
  
 -        if (codec->codec_type == AVMEDIA_TYPE_AUDIO && codec->delay) {
 -            mkv->tracks[i].ts_offset = av_rescale_q(codec->delay,
 -                                                    (AVRational){ 1, codec->sample_rate },
 -                                                    st->time_base);
 +        if (st->disposition & AV_DISPOSITION_FORCED)
 +            put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGFORCED, 1);
 +
 +        if (mkv->mode == MODE_WEBM && codec->codec_id == AV_CODEC_ID_WEBVTT) {
 +            const char *codec_id;
 +            if (st->disposition & AV_DISPOSITION_CAPTIONS) {
 +                codec_id = "D_WEBVTT/CAPTIONS";
 +                native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
 +            } else if (st->disposition & AV_DISPOSITION_DESCRIPTIONS) {
 +                codec_id = "D_WEBVTT/DESCRIPTIONS";
 +                native_id = MATROSKA_TRACK_TYPE_METADATA;
 +            } else if (st->disposition & AV_DISPOSITION_METADATA) {
 +                codec_id = "D_WEBVTT/METADATA";
 +                native_id = MATROSKA_TRACK_TYPE_METADATA;
 +            } else {
 +                codec_id = "D_WEBVTT/SUBTITLES";
 +                native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
 +            }
 +            put_ebml_string(pb, MATROSKA_ID_CODECID, codec_id);
 +        } else {
 +            // look for a codec ID string specific to mkv to use,
 +            // if none are found, use AVI codes
 +            for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
 +                if (ff_mkv_codec_tags[j].id == codec->codec_id) {
 +                    put_ebml_string(pb, MATROSKA_ID_CODECID, ff_mkv_codec_tags[j].str);
 +                    native_id = 1;
 +                    break;
 +                }
 +            }
 +        }
 +
++        if (codec->codec_type == AVMEDIA_TYPE_AUDIO && codec->delay && codec->codec_id == AV_CODEC_ID_OPUS) {
++//             mkv->tracks[i].ts_offset = av_rescale_q(codec->delay,
++//                                                     (AVRational){ 1, codec->sample_rate },
++//                                                     st->time_base);
+             put_ebml_uint(pb, MATROSKA_ID_CODECDELAY,
+                           av_rescale_q(codec->delay, (AVRational){ 1, codec->sample_rate },
+                                        (AVRational){ 1, 1000000000 }));
+         }
 -
 -        // look for a codec ID string specific to mkv to use,
 -        // if none are found, use AVI codes
 -        for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
 -            if (ff_mkv_codec_tags[j].id == codec->codec_id) {
 -                put_ebml_string(pb, MATROSKA_ID_CODECID, ff_mkv_codec_tags[j].str);
 -                native_id = 1;
 -                break;
 -            }
 +        if (codec->codec_id == AV_CODEC_ID_OPUS) {
-             uint64_t codec_delay =av_rescale_q(codec->delay,
-                                                (AVRational){1, codec->sample_rate},
-                                                (AVRational){1, 1000000000});
-             put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codec_delay);
 +            put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL);
          }
  
          if (mkv->mode == MODE_WEBM && !(codec->codec_id == AV_CODEC_ID_VP8 ||
@@@ -1549,14 -1272,11 +1554,15 @@@ static int mkv_write_packet_internal(AV
          av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n");
          return AVERROR(EINVAL);
      }
+     ts += mkv->tracks[pkt->stream_index].ts_offset;
  
      if (!s->pb->seekable) {
 -        if (!mkv->dyn_bc)
 -            avio_open_dyn_buf(&mkv->dyn_bc);
 +        if (!mkv->dyn_bc) {
 +            if ((ret = avio_open_dyn_buf(&mkv->dyn_bc)) < 0) {
 +                av_log(s, AV_LOG_ERROR, "Failed to open dynamic buffer\n");
 +                return ret;
 +            }
 +        }
          pb = mkv->dyn_bc;
      }
  
@@@ -30,8 -30,8 +30,8 @@@
  #include "libavutil/version.h"
  
  #define LIBAVFORMAT_VERSION_MAJOR 55
 -#define LIBAVFORMAT_VERSION_MINOR 16
 -#define LIBAVFORMAT_VERSION_MICRO  0
 +#define LIBAVFORMAT_VERSION_MINOR 37
- #define LIBAVFORMAT_VERSION_MICRO 101
++#define LIBAVFORMAT_VERSION_MICRO 102
  
  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                 LIBAVFORMAT_VERSION_MINOR, \