Merge commit 'eb3b5501e8b85bfea09d533314cb6920efc42639'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 1 May 2014 02:27:17 +0000 (04:27 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 1 May 2014 02:29:40 +0000 (04:29 +0200)
* commit 'eb3b5501e8b85bfea09d533314cb6920efc42639':
  matroskadec: read the CodecDelay element

Conflicts:
libavformat/matroska.h
libavformat/matroskadec.c

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

@@@ -170,12 -152,10 +171,12 @@@ typedef struct 
      uint64_t default_duration;
      uint64_t flag_default;
      uint64_t flag_forced;
-     uint64_t codec_delay;
 +    uint64_t seek_preroll;
      MatroskaTrackVideo video;
      MatroskaTrackAudio audio;
 +    MatroskaTrackOperation operation;
      EbmlList encodings;
+     uint64_t codec_delay;
  
      AVStream *stream;
      int64_t end_timecode;
@@@ -410,18 -356,15 +411,18 @@@ static EbmlSyntax matroska_track[] = 
      { MATROSKA_ID_TRACKTYPE,             EBML_UINT,  0, offsetof(MatroskaTrack, type) },
      { MATROSKA_ID_CODECID,               EBML_STR,   0, offsetof(MatroskaTrack, codec_id) },
      { MATROSKA_ID_CODECPRIVATE,          EBML_BIN,   0, offsetof(MatroskaTrack, codec_priv) },
 -    { MATROSKA_ID_TRACKLANGUAGE,         EBML_UTF8,  0, offsetof(MatroskaTrack, language),     { .s = "eng"  } },
+     { MATROSKA_ID_CODECDELAY,            EBML_UINT,  0, offsetof(MatroskaTrack, codec_delay) },
 +    { MATROSKA_ID_TRACKLANGUAGE,         EBML_UTF8,  0, offsetof(MatroskaTrack, language),     { .s = "eng" } },
      { MATROSKA_ID_TRACKDEFAULTDURATION,  EBML_UINT,  0, offsetof(MatroskaTrack, default_duration) },
 -    { MATROSKA_ID_TRACKTIMECODESCALE,    EBML_FLOAT, 0, offsetof(MatroskaTrack, time_scale),   { .f = 1.0  } },
 -    { MATROSKA_ID_TRACKFLAGDEFAULT,      EBML_UINT,  0, offsetof(MatroskaTrack, flag_default), { .u = 1  } },
 -    { MATROSKA_ID_TRACKFLAGFORCED,       EBML_UINT,  0, offsetof(MatroskaTrack, flag_forced),  { .u = 0   } },
 +    { MATROSKA_ID_TRACKTIMECODESCALE,    EBML_FLOAT, 0, offsetof(MatroskaTrack, time_scale),   { .f = 1.0 } },
 +    { MATROSKA_ID_TRACKFLAGDEFAULT,      EBML_UINT,  0, offsetof(MatroskaTrack, flag_default), { .u = 1 } },
 +    { MATROSKA_ID_TRACKFLAGFORCED,       EBML_UINT,  0, offsetof(MatroskaTrack, flag_forced),  { .u = 0 } },
      { MATROSKA_ID_TRACKVIDEO,            EBML_NEST,  0, offsetof(MatroskaTrack, video),        { .n = matroska_track_video } },
      { MATROSKA_ID_TRACKAUDIO,            EBML_NEST,  0, offsetof(MatroskaTrack, audio),        { .n = matroska_track_audio } },
 +    { MATROSKA_ID_TRACKOPERATION,        EBML_NEST,  0, offsetof(MatroskaTrack, operation),    { .n = matroska_track_operation } },
      { MATROSKA_ID_TRACKCONTENTENCODINGS, EBML_NEST,  0, 0,                                     { .n = matroska_track_encodings } },
-     { MATROSKA_ID_CODECDELAY,            EBML_UINT,  0, offsetof(MatroskaTrack, codec_delay) },
 +    { MATROSKA_ID_TRACKMAXBLKADDID,      EBML_UINT,  0, offsetof(MatroskaTrack, max_block_additional_id) },
 +    { MATROSKA_ID_SEEKPREROLL,           EBML_UINT,  0, offsetof(MatroskaTrack, seek_preroll) },
      { MATROSKA_ID_TRACKFLAGENABLED,      EBML_NONE },
      { MATROSKA_ID_TRACKFLAGLACING,       EBML_NONE },
      { MATROSKA_ID_CODECNAME,             EBML_NONE },
@@@ -1931,8 -1733,13 +1932,13 @@@ static int matroska_read_header(AVForma
          avpriv_set_pts_info(st, 64, matroska->time_scale * track->time_scale,
                              1000 * 1000 * 1000);    /* 64 bit pts in ns */
  
+         /* convert the delay from ns to the track timebase */
+         track->codec_delay = av_rescale_q(track->codec_delay,
+                                           (AVRational){ 1, 1000000000 },
+                                           st->time_base);
          st->codec->codec_id = codec_id;
 -        st->start_time      = 0;
 +
          if (strcmp(track->language, "und"))
              av_dict_set(&st->metadata, "language", track->language, 0);
          av_dict_set(&st->metadata, "title", track->name, 0);
              st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
              st->codec->sample_rate = track->audio.out_samplerate;
              st->codec->channels    = track->audio.channels;
 +            if (!st->codec->bits_per_coded_sample)
 +                st->codec->bits_per_coded_sample = track->audio.bitdepth;
              if (st->codec->codec_id != AV_CODEC_ID_AAC)
                  st->need_parsing = AVSTREAM_PARSE_HEADERS;
-                                                 (AVRational){1, 1000000000},
 +            if (track->codec_delay > 0) {
 +                st->codec->delay = av_rescale_q(track->codec_delay,
++                                                st->time_base,
 +                                                (AVRational){1, st->codec->sample_rate});
 +            }
 +            if (track->seek_preroll > 0) {
 +                av_codec_set_seek_preroll(st->codec,
 +                                          av_rescale_q(track->seek_preroll,
 +                                                       (AVRational){1, 1000000000},
 +                                                       (AVRational){1, st->codec->sample_rate}));
 +            }
 +        } else if (codec_id == AV_CODEC_ID_WEBVTT) {
 +            st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
 +
 +            if (!strcmp(track->codec_id, "D_WEBVTT/CAPTIONS")) {
 +                st->disposition |= AV_DISPOSITION_CAPTIONS;
 +            } else if (!strcmp(track->codec_id, "D_WEBVTT/DESCRIPTIONS")) {
 +                st->disposition |= AV_DISPOSITION_DESCRIPTIONS;
 +            } else if (!strcmp(track->codec_id, "D_WEBVTT/METADATA")) {
 +                st->disposition |= AV_DISPOSITION_METADATA;
 +            }
          } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
              st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
 -            if (st->codec->codec_id == AV_CODEC_ID_SSA)
 +#if FF_API_ASS_SSA
 +            if (st->codec->codec_id == AV_CODEC_ID_SSA ||
 +                st->codec->codec_id == AV_CODEC_ID_ASS)
 +#else
 +            if (st->codec->codec_id == AV_CODEC_ID_ASS)
 +#endif
                  matroska->contains_ssa = 1;
          }
      }