Merge commit '82cebc0e0544dce507749dd9b1c2983f083de836' into release/2.2
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 4 May 2014 19:01:38 +0000 (21:01 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 4 May 2014 19:01:38 +0000 (21:01 +0200)
* commit '82cebc0e0544dce507749dd9b1c2983f083de836':
  matroskadec: read the CodecDelay element

Conflicts:
libavformat/matroska.h

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

@@@ -44,7 -43,8 +44,8 @@@
  #include "libavutil/intreadwrite.h"
  #include "libavutil/avstring.h"
  #include "libavutil/lzo.h"
 -#include "libavutil/dict.h"
+ #include "libavutil/mathematics.h"
 +#include "libavutil/dict.h"
  #if CONFIG_ZLIB
  #include <zlib.h>
  #endif
@@@ -164,12 -146,10 +165,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;
@@@ -404,6 -350,7 +405,7 @@@ 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_CODECDELAY,           EBML_UINT, 0, offsetof(MatroskaTrack, codec_delay) },
++    { 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_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 },
@@@ -1852,8 -1661,13 +1853,13 @@@ static int matroska_read_header(AVForma
              track->time_scale = 1.0;
          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;
          }
      }