matroskadec.c
Go to the documentation of this file.
1 /*
2  * Matroska file demuxer
3  * Copyright (c) 2003-2008 The FFmpeg Project
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Matroska file demuxer
25  * @author Ronald Bultje <rbultje@ronald.bitfreak.net>
26  * @author with a little help from Moritz Bunkus <moritz@bunkus.org>
27  * @author totally reworked by Aurelien Jacobs <aurel@gnuage.org>
28  * @see specs available on the Matroska project page: http://www.matroska.org/
29  */
30 
31 #include <stdio.h>
32 #include "avformat.h"
33 #include "internal.h"
34 #include "avio_internal.h"
35 /* For ff_codec_get_id(). */
36 #include "riff.h"
37 #include "isom.h"
38 #include "rmsipr.h"
39 #include "matroska.h"
40 #include "libavcodec/bytestream.h"
41 #include "libavcodec/mpeg4audio.h"
42 #include "libavutil/base64.h"
43 #include "libavutil/intfloat.h"
44 #include "libavutil/intreadwrite.h"
45 #include "libavutil/avstring.h"
46 #include "libavutil/lzo.h"
47 #include "libavutil/dict.h"
48 #if CONFIG_ZLIB
49 #include <zlib.h>
50 #endif
51 #if CONFIG_BZLIB
52 #include <bzlib.h>
53 #endif
54 
55 typedef enum {
66 } EbmlType;
67 
68 typedef const struct EbmlSyntax {
69  uint32_t id;
73  union {
74  uint64_t u;
75  double f;
76  const char *s;
77  const struct EbmlSyntax *n;
78  } def;
79 } EbmlSyntax;
80 
81 typedef struct {
82  int nb_elem;
83  void *elem;
84 } EbmlList;
85 
86 typedef struct {
87  int size;
89  int64_t pos;
90 } EbmlBin;
91 
92 typedef struct {
93  uint64_t version;
94  uint64_t max_size;
95  uint64_t id_length;
96  char *doctype;
97  uint64_t doctype_version;
98 } Ebml;
99 
100 typedef struct {
101  uint64_t algo;
104 
105 typedef struct {
106  uint64_t algo;
109 
110 typedef struct {
111  uint64_t scope;
112  uint64_t type;
116 
117 typedef struct {
118  double frame_rate;
119  uint64_t display_width;
120  uint64_t display_height;
121  uint64_t pixel_width;
122  uint64_t pixel_height;
124  uint64_t stereo_mode;
125  uint64_t alpha_mode;
127 
128 typedef struct {
129  double samplerate;
131  uint64_t bitdepth;
132  uint64_t channels;
133 
134  /* real audio header (extracted from extradata) */
140  int pkt_cnt;
141  uint64_t buf_timecode;
144 
145 typedef struct {
146  uint64_t uid;
147  uint64_t type;
149 
150 typedef struct {
153 
154 typedef struct {
155  uint64_t num;
156  uint64_t uid;
157  uint64_t type;
158  char *name;
159  char *codec_id;
161  char *language;
162  double time_scale;
164  uint64_t flag_default;
165  uint64_t flag_forced;
170 
172  int64_t end_timecode;
175 } MatroskaTrack;
176 
177 typedef struct {
178  uint64_t uid;
179  char *filename;
180  char *mime;
182 
185 
186 typedef struct {
187  uint64_t start;
188  uint64_t end;
189  uint64_t uid;
190  char *title;
191 
194 
195 typedef struct {
196  uint64_t track;
197  uint64_t pos;
199 
200 typedef struct {
201  uint64_t time;
203 } MatroskaIndex;
204 
205 typedef struct {
206  char *name;
207  char *string;
208  char *lang;
209  uint64_t def;
211 } MatroskaTag;
212 
213 typedef struct {
214  char *type;
215  uint64_t typevalue;
216  uint64_t trackuid;
217  uint64_t chapteruid;
218  uint64_t attachuid;
220 
221 typedef struct {
224 } MatroskaTags;
225 
226 typedef struct {
227  uint64_t id;
228  uint64_t pos;
230 
231 typedef struct {
232  uint64_t start;
233  uint64_t length;
234 } MatroskaLevel;
235 
236 typedef struct {
237  uint64_t timecode;
240 
241 typedef struct {
243 
244  /* EBML stuff */
247  int level_up;
248  uint32_t current_id;
249 
250  uint64_t time_scale;
251  double duration;
252  char *title;
260 
261  /* byte position of the segment inside the stream */
262  int64_t segment_start;
263 
264  /* the packet queue */
268 
269  int done;
270 
271  /* What to skip before effectively reading a packet. */
274 
275  /* File has a CUES element, but we defer parsing until it is needed. */
277 
281 
282  /* File has SSA subtitles which prevent incremental cluster parsing. */
285 
286 typedef struct {
287  uint64_t duration;
288  int64_t reference;
289  uint64_t non_simple;
291  uint64_t additional_id;
293 } MatroskaBlock;
294 
296  { EBML_ID_EBMLREADVERSION, EBML_UINT, 0, offsetof(Ebml,version), {.u=EBML_VERSION} },
297  { EBML_ID_EBMLMAXSIZELENGTH, EBML_UINT, 0, offsetof(Ebml,max_size), {.u=8} },
298  { EBML_ID_EBMLMAXIDLENGTH, EBML_UINT, 0, offsetof(Ebml,id_length), {.u=4} },
299  { EBML_ID_DOCTYPE, EBML_STR, 0, offsetof(Ebml,doctype), {.s="(none)"} },
300  { EBML_ID_DOCTYPEREADVERSION, EBML_UINT, 0, offsetof(Ebml,doctype_version), {.u=1} },
302  { EBML_ID_DOCTYPEVERSION, EBML_NONE },
303  { 0 }
304 };
305 
307  { EBML_ID_HEADER, EBML_NEST, 0, 0, {.n=ebml_header} },
308  { 0 }
309 };
310 
312  { MATROSKA_ID_TIMECODESCALE, EBML_UINT, 0, offsetof(MatroskaDemuxContext,time_scale), {.u=1000000} },
316  { MATROSKA_ID_MUXINGAPP, EBML_NONE },
317  { MATROSKA_ID_DATEUTC, EBML_BIN, 0, offsetof(MatroskaDemuxContext,date_utc) },
318  { MATROSKA_ID_SEGMENTUID, EBML_NONE },
319  { 0 }
320 };
321 
323  { MATROSKA_ID_VIDEOFRAMERATE, EBML_FLOAT,0, offsetof(MatroskaTrackVideo,frame_rate) },
324  { MATROSKA_ID_VIDEODISPLAYWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_width), {.u=-1} },
325  { MATROSKA_ID_VIDEODISPLAYHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_height), {.u=-1} },
326  { MATROSKA_ID_VIDEOPIXELWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_width) },
327  { MATROSKA_ID_VIDEOPIXELHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_height) },
328  { MATROSKA_ID_VIDEOCOLORSPACE, EBML_BIN, 0, offsetof(MatroskaTrackVideo,color_space) },
329  { MATROSKA_ID_VIDEOSTEREOMODE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,stereo_mode) },
330  { MATROSKA_ID_VIDEOALPHAMODE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,alpha_mode) },
332  { MATROSKA_ID_VIDEOPIXELCROPT, EBML_NONE },
333  { MATROSKA_ID_VIDEOPIXELCROPL, EBML_NONE },
334  { MATROSKA_ID_VIDEOPIXELCROPR, EBML_NONE },
335  { MATROSKA_ID_VIDEODISPLAYUNIT, EBML_NONE },
336  { MATROSKA_ID_VIDEOFLAGINTERLACED,EBML_NONE },
337  { MATROSKA_ID_VIDEOASPECTRATIO, EBML_NONE },
338  { 0 }
339 };
340 
342  { MATROSKA_ID_AUDIOSAMPLINGFREQ, EBML_FLOAT,0, offsetof(MatroskaTrackAudio,samplerate), {.f=8000.0} },
343  { MATROSKA_ID_AUDIOOUTSAMPLINGFREQ,EBML_FLOAT,0,offsetof(MatroskaTrackAudio,out_samplerate) },
345  { MATROSKA_ID_AUDIOCHANNELS, EBML_UINT, 0, offsetof(MatroskaTrackAudio,channels), {.u=1} },
346  { 0 }
347 };
348 
352  { 0 }
353 };
354 
359  { MATROSKA_ID_ENCODINGSIGALGO, EBML_NONE },
360  { MATROSKA_ID_ENCODINGSIGHASHALGO, EBML_NONE },
361  { MATROSKA_ID_ENCODINGSIGKEYID, EBML_NONE },
362  { MATROSKA_ID_ENCODINGSIGNATURE, EBML_NONE },
363  { 0 }
364 };
366  { MATROSKA_ID_ENCODINGSCOPE, EBML_UINT, 0, offsetof(MatroskaTrackEncoding,scope), {.u=1} },
368  { MATROSKA_ID_ENCODINGCOMPRESSION,EBML_NEST, 0, offsetof(MatroskaTrackEncoding,compression), {.n=matroska_track_encoding_compression} },
369  { MATROSKA_ID_ENCODINGENCRYPTION, EBML_NEST, 0, offsetof(MatroskaTrackEncoding,encryption), {.n=matroska_track_encoding_encryption} },
371  { 0 }
372 };
373 
375  { MATROSKA_ID_TRACKCONTENTENCODING, EBML_NEST, sizeof(MatroskaTrackEncoding), offsetof(MatroskaTrack,encodings), {.n=matroska_track_encoding} },
376  { 0 }
377 };
378 
382  { 0 }
383 };
384 
386  { MATROSKA_ID_TRACKPLANE, EBML_NEST, sizeof(MatroskaTrackPlane), offsetof(MatroskaTrackOperation,combine_planes), {.n=matroska_track_plane} },
387  { 0 }
388 };
389 
391  { MATROSKA_ID_TRACKCOMBINEPLANES, EBML_NEST, 0, 0, {.n=matroska_track_combine_planes} },
392  { 0 }
393 };
394 
396  { MATROSKA_ID_TRACKNUMBER, EBML_UINT, 0, offsetof(MatroskaTrack,num) },
398  { MATROSKA_ID_TRACKUID, EBML_UINT, 0, offsetof(MatroskaTrack,uid) },
401  { MATROSKA_ID_CODECPRIVATE, EBML_BIN, 0, offsetof(MatroskaTrack,codec_priv) },
402  { MATROSKA_ID_TRACKLANGUAGE, EBML_UTF8, 0, offsetof(MatroskaTrack,language), {.s="eng"} },
403  { MATROSKA_ID_TRACKDEFAULTDURATION, EBML_UINT, 0, offsetof(MatroskaTrack,default_duration) },
404  { MATROSKA_ID_TRACKTIMECODESCALE, EBML_FLOAT,0, offsetof(MatroskaTrack,time_scale), {.f=1.0} },
405  { MATROSKA_ID_TRACKFLAGDEFAULT, EBML_UINT, 0, offsetof(MatroskaTrack,flag_default), {.u=1} },
406  { MATROSKA_ID_TRACKFLAGFORCED, EBML_UINT, 0, offsetof(MatroskaTrack,flag_forced), {.u=0} },
407  { MATROSKA_ID_TRACKVIDEO, EBML_NEST, 0, offsetof(MatroskaTrack,video), {.n=matroska_track_video} },
408  { MATROSKA_ID_TRACKAUDIO, EBML_NEST, 0, offsetof(MatroskaTrack,audio), {.n=matroska_track_audio} },
409  { MATROSKA_ID_TRACKOPERATION, EBML_NEST, 0, offsetof(MatroskaTrack,operation), {.n=matroska_track_operation} },
410  { MATROSKA_ID_TRACKCONTENTENCODINGS,EBML_NEST, 0, 0, {.n=matroska_track_encodings} },
411  { MATROSKA_ID_TRACKMAXBLKADDID, EBML_UINT, 0, offsetof(MatroskaTrack,max_block_additional_id) },
413  { MATROSKA_ID_TRACKFLAGLACING, EBML_NONE },
414  { MATROSKA_ID_CODECNAME, EBML_NONE },
415  { MATROSKA_ID_CODECDECODEALL, EBML_NONE },
416  { MATROSKA_ID_CODECINFOURL, EBML_NONE },
417  { MATROSKA_ID_CODECDOWNLOADURL, EBML_NONE },
418  { MATROSKA_ID_TRACKMINCACHE, EBML_NONE },
419  { MATROSKA_ID_TRACKMAXCACHE, EBML_NONE },
420  { 0 }
421 };
422 
424  { MATROSKA_ID_TRACKENTRY, EBML_NEST, sizeof(MatroskaTrack), offsetof(MatroskaDemuxContext,tracks), {.n=matroska_track} },
425  { 0 }
426 };
427 
429  { MATROSKA_ID_FILEUID, EBML_UINT, 0, offsetof(MatroskaAttachement,uid) },
430  { MATROSKA_ID_FILENAME, EBML_UTF8, 0, offsetof(MatroskaAttachement,filename) },
431  { MATROSKA_ID_FILEMIMETYPE, EBML_STR, 0, offsetof(MatroskaAttachement,mime) },
432  { MATROSKA_ID_FILEDATA, EBML_BIN, 0, offsetof(MatroskaAttachement,bin) },
434  { 0 }
435 };
436 
438  { MATROSKA_ID_ATTACHEDFILE, EBML_NEST, sizeof(MatroskaAttachement), offsetof(MatroskaDemuxContext,attachments), {.n=matroska_attachment} },
439  { 0 }
440 };
441 
445  { 0 }
446 };
447 
451  { MATROSKA_ID_CHAPTERUID, EBML_UINT, 0, offsetof(MatroskaChapter,uid) },
452  { MATROSKA_ID_CHAPTERDISPLAY, EBML_NEST, 0, 0, {.n=matroska_chapter_display} },
454  { MATROSKA_ID_CHAPTERFLAGENABLED, EBML_NONE },
455  { MATROSKA_ID_CHAPTERPHYSEQUIV, EBML_NONE },
456  { MATROSKA_ID_CHAPTERATOM, EBML_NONE },
457  { 0 }
458 };
459 
461  { MATROSKA_ID_CHAPTERATOM, EBML_NEST, sizeof(MatroskaChapter), offsetof(MatroskaDemuxContext,chapters), {.n=matroska_chapter_entry} },
463  { MATROSKA_ID_EDITIONFLAGHIDDEN, EBML_NONE },
464  { MATROSKA_ID_EDITIONFLAGDEFAULT, EBML_NONE },
465  { MATROSKA_ID_EDITIONFLAGORDERED, EBML_NONE },
466  { 0 }
467 };
468 
470  { MATROSKA_ID_EDITIONENTRY, EBML_NEST, 0, 0, {.n=matroska_chapter} },
471  { 0 }
472 };
473 
478  { 0 }
479 };
480 
482  { MATROSKA_ID_CUETIME, EBML_UINT, 0, offsetof(MatroskaIndex,time) },
483  { MATROSKA_ID_CUETRACKPOSITION, EBML_NEST, sizeof(MatroskaIndexPos), offsetof(MatroskaIndex,pos), {.n=matroska_index_pos} },
484  { 0 }
485 };
486 
488  { MATROSKA_ID_POINTENTRY, EBML_NEST, sizeof(MatroskaIndex), offsetof(MatroskaDemuxContext,index), {.n=matroska_index_entry} },
489  { 0 }
490 };
491 
493  { MATROSKA_ID_TAGNAME, EBML_UTF8, 0, offsetof(MatroskaTag,name) },
494  { MATROSKA_ID_TAGSTRING, EBML_UTF8, 0, offsetof(MatroskaTag,string) },
495  { MATROSKA_ID_TAGLANG, EBML_STR, 0, offsetof(MatroskaTag,lang), {.s="und"} },
496  { MATROSKA_ID_TAGDEFAULT, EBML_UINT, 0, offsetof(MatroskaTag,def) },
498  { MATROSKA_ID_SIMPLETAG, EBML_NEST, sizeof(MatroskaTag), offsetof(MatroskaTag,sub), {.n=matroska_simpletag} },
499  { 0 }
500 };
501 
504  { MATROSKA_ID_TAGTARGETS_TYPEVALUE, EBML_UINT, 0, offsetof(MatroskaTagTarget,typevalue), {.u=50} },
505  { MATROSKA_ID_TAGTARGETS_TRACKUID, EBML_UINT, 0, offsetof(MatroskaTagTarget,trackuid) },
507  { MATROSKA_ID_TAGTARGETS_ATTACHUID, EBML_UINT, 0, offsetof(MatroskaTagTarget,attachuid) },
508  { 0 }
509 };
510 
512  { MATROSKA_ID_SIMPLETAG, EBML_NEST, sizeof(MatroskaTag), offsetof(MatroskaTags,tag), {.n=matroska_simpletag} },
513  { MATROSKA_ID_TAGTARGETS, EBML_NEST, 0, offsetof(MatroskaTags,target), {.n=matroska_tagtargets} },
514  { 0 }
515 };
516 
518  { MATROSKA_ID_TAG, EBML_NEST, sizeof(MatroskaTags), offsetof(MatroskaDemuxContext,tags), {.n=matroska_tag} },
519  { 0 }
520 };
521 
523  { MATROSKA_ID_SEEKID, EBML_UINT, 0, offsetof(MatroskaSeekhead,id) },
524  { MATROSKA_ID_SEEKPOSITION, EBML_UINT, 0, offsetof(MatroskaSeekhead,pos), {.u=-1} },
525  { 0 }
526 };
527 
529  { MATROSKA_ID_SEEKENTRY, EBML_NEST, sizeof(MatroskaSeekhead), offsetof(MatroskaDemuxContext,seekhead), {.n=matroska_seekhead_entry} },
530  { 0 }
531 };
532 
534  { MATROSKA_ID_INFO, EBML_NEST, 0, 0, {.n=matroska_info } },
535  { MATROSKA_ID_TRACKS, EBML_NEST, 0, 0, {.n=matroska_tracks } },
536  { MATROSKA_ID_ATTACHMENTS, EBML_NEST, 0, 0, {.n=matroska_attachments} },
537  { MATROSKA_ID_CHAPTERS, EBML_NEST, 0, 0, {.n=matroska_chapters } },
538  { MATROSKA_ID_CUES, EBML_NEST, 0, 0, {.n=matroska_index } },
539  { MATROSKA_ID_TAGS, EBML_NEST, 0, 0, {.n=matroska_tags } },
540  { MATROSKA_ID_SEEKHEAD, EBML_NEST, 0, 0, {.n=matroska_seekhead } },
542  { 0 }
543 };
544 
546  { MATROSKA_ID_SEGMENT, EBML_NEST, 0, 0, {.n=matroska_segment } },
547  { 0 }
548 };
549 
551  { MATROSKA_ID_BLOCKADDID, EBML_UINT, 0, offsetof(MatroskaBlock,additional_id) },
552  { MATROSKA_ID_BLOCKADDITIONAL, EBML_BIN, 0, offsetof(MatroskaBlock,additional) },
553  { 0 }
554 };
555 
557  { MATROSKA_ID_BLOCKMORE, EBML_NEST, 0, 0, {.n=matroska_blockmore} },
558  { 0 }
559 };
560 
562  { MATROSKA_ID_BLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) },
563  { MATROSKA_ID_BLOCKADDITIONS, EBML_NEST, 0, 0, {.n=matroska_blockadditions} },
564  { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) },
566  { MATROSKA_ID_BLOCKREFERENCE, EBML_UINT, 0, offsetof(MatroskaBlock,reference) },
567  { 1, EBML_UINT, 0, offsetof(MatroskaBlock,non_simple), {.u=1} },
568  { 0 }
569 };
570 
572  { MATROSKA_ID_CLUSTERTIMECODE,EBML_UINT,0, offsetof(MatroskaCluster,timecode) },
573  { MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
574  { MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
576  { MATROSKA_ID_CLUSTERPREVSIZE,EBML_NONE },
577  { 0 }
578 };
579 
581  { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, {.n=matroska_cluster} },
583  { MATROSKA_ID_CUES, EBML_NONE },
584  { MATROSKA_ID_TAGS, EBML_NONE },
585  { MATROSKA_ID_SEEKHEAD, EBML_NONE },
586  { 0 }
587 };
588 
590  { MATROSKA_ID_CLUSTERTIMECODE,EBML_UINT,0, offsetof(MatroskaCluster,timecode) },
591  { MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
592  { MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), offsetof(MatroskaCluster,blocks), {.n=matroska_blockgroup} },
594  { MATROSKA_ID_CLUSTERPREVSIZE,EBML_NONE },
595  { MATROSKA_ID_INFO, EBML_NONE },
596  { MATROSKA_ID_CUES, EBML_NONE },
597  { MATROSKA_ID_TAGS, EBML_NONE },
598  { MATROSKA_ID_SEEKHEAD, EBML_NONE },
600  { 0 }
601 };
602 
604  { MATROSKA_ID_CLUSTERTIMECODE,EBML_UINT,0, offsetof(MatroskaCluster,timecode) },
606  { MATROSKA_ID_SIMPLEBLOCK, EBML_STOP },
608  { MATROSKA_ID_CLUSTERPREVSIZE,EBML_NONE },
609  { 0 }
610 };
611 
613  { MATROSKA_ID_CLUSTER, EBML_NEST, 0, 0, {.n=matroska_cluster_incremental} },
615  { MATROSKA_ID_CUES, EBML_NONE },
616  { MATROSKA_ID_TAGS, EBML_NONE },
617  { MATROSKA_ID_SEEKHEAD, EBML_NONE },
618  { 0 }
619 };
620 
621 static const char *const matroska_doctypes[] = { "matroska", "webm" };
622 
623 static int matroska_resync(MatroskaDemuxContext *matroska, int64_t last_pos)
624 {
625  AVIOContext *pb = matroska->ctx->pb;
626  uint32_t id;
627  matroska->current_id = 0;
628  matroska->num_levels = 0;
629 
630  // seek to next position to resync from
631  if (avio_seek(pb, last_pos + 1, SEEK_SET) < 0 || avio_tell(pb) <= last_pos)
632  goto eof;
633 
634  id = avio_rb32(pb);
635 
636  // try to find a toplevel element
637  while (!url_feof(pb)) {
638  if (id == MATROSKA_ID_INFO || id == MATROSKA_ID_TRACKS ||
639  id == MATROSKA_ID_CUES || id == MATROSKA_ID_TAGS ||
642  {
643  matroska->current_id = id;
644  return 0;
645  }
646  id = (id << 8) | avio_r8(pb);
647  }
648 eof:
649  matroska->done = 1;
650  return AVERROR_EOF;
651 }
652 
653 /*
654  * Return: Whether we reached the end of a level in the hierarchy or not.
655  */
657 {
658  AVIOContext *pb = matroska->ctx->pb;
659  int64_t pos = avio_tell(pb);
660 
661  if (matroska->num_levels > 0) {
662  MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1];
663  if (pos - level->start >= level->length || matroska->current_id) {
664  matroska->num_levels--;
665  return 1;
666  }
667  }
668  return 0;
669 }
670 
671 /*
672  * Read: an "EBML number", which is defined as a variable-length
673  * array of bytes. The first byte indicates the length by giving a
674  * number of 0-bits followed by a one. The position of the first
675  * "one" bit inside the first byte indicates the length of this
676  * number.
677  * Returns: number of bytes read, < 0 on error
678  */
680  int max_size, uint64_t *number)
681 {
682  int read = 1, n = 1;
683  uint64_t total = 0;
684 
685  /* The first byte tells us the length in bytes - avio_r8() can normally
686  * return 0, but since that's not a valid first ebmlID byte, we can
687  * use it safely here to catch EOS. */
688  if (!(total = avio_r8(pb))) {
689  /* we might encounter EOS here */
690  if (!url_feof(pb)) {
691  int64_t pos = avio_tell(pb);
692  av_log(matroska->ctx, AV_LOG_ERROR,
693  "Read error at pos. %"PRIu64" (0x%"PRIx64")\n",
694  pos, pos);
695  return pb->error ? pb->error : AVERROR(EIO);
696  }
697  return AVERROR_EOF;
698  }
699 
700  /* get the length of the EBML number */
701  read = 8 - ff_log2_tab[total];
702  if (read > max_size) {
703  int64_t pos = avio_tell(pb) - 1;
704  av_log(matroska->ctx, AV_LOG_ERROR,
705  "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64")\n",
706  (uint8_t) total, pos, pos);
707  return AVERROR_INVALIDDATA;
708  }
709 
710  /* read out length */
711  total ^= 1 << ff_log2_tab[total];
712  while (n++ < read)
713  total = (total << 8) | avio_r8(pb);
714 
715  *number = total;
716 
717  return read;
718 }
719 
720 /**
721  * Read a EBML length value.
722  * This needs special handling for the "unknown length" case which has multiple
723  * encodings.
724  */
726  uint64_t *number)
727 {
728  int res = ebml_read_num(matroska, pb, 8, number);
729  if (res > 0 && *number + 1 == 1ULL << (7 * res))
730  *number = 0xffffffffffffffULL;
731  return res;
732 }
733 
734 /*
735  * Read the next element as an unsigned int.
736  * 0 is success, < 0 is failure.
737  */
738 static int ebml_read_uint(AVIOContext *pb, int size, uint64_t *num)
739 {
740  int n = 0;
741 
742  if (size > 8)
743  return AVERROR_INVALIDDATA;
744 
745  /* big-endian ordering; build up number */
746  *num = 0;
747  while (n++ < size)
748  *num = (*num << 8) | avio_r8(pb);
749 
750  return 0;
751 }
752 
753 /*
754  * Read the next element as a float.
755  * 0 is success, < 0 is failure.
756  */
757 static int ebml_read_float(AVIOContext *pb, int size, double *num)
758 {
759  if (size == 0) {
760  *num = 0;
761  } else if (size == 4) {
762  *num = av_int2float(avio_rb32(pb));
763  } else if (size == 8){
764  *num = av_int2double(avio_rb64(pb));
765  } else
766  return AVERROR_INVALIDDATA;
767 
768  return 0;
769 }
770 
771 /*
772  * Read the next element as an ASCII string.
773  * 0 is success, < 0 is failure.
774  */
775 static int ebml_read_ascii(AVIOContext *pb, int size, char **str)
776 {
777  char *res;
778 
779  /* EBML strings are usually not 0-terminated, so we allocate one
780  * byte more, read the string and NULL-terminate it ourselves. */
781  if (!(res = av_malloc(size + 1)))
782  return AVERROR(ENOMEM);
783  if (avio_read(pb, (uint8_t *) res, size) != size) {
784  av_free(res);
785  return AVERROR(EIO);
786  }
787  (res)[size] = '\0';
788  av_free(*str);
789  *str = res;
790 
791  return 0;
792 }
793 
794 /*
795  * Read the next element as binary data.
796  * 0 is success, < 0 is failure.
797  */
798 static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin)
799 {
800  av_fast_padded_malloc(&bin->data, &bin->size, length);
801  if (!bin->data)
802  return AVERROR(ENOMEM);
803 
804  bin->size = length;
805  bin->pos = avio_tell(pb);
806  if (avio_read(pb, bin->data, length) != length) {
807  av_freep(&bin->data);
808  bin->size = 0;
809  return AVERROR(EIO);
810  }
811 
812  return 0;
813 }
814 
815 /*
816  * Read the next element, but only the header. The contents
817  * are supposed to be sub-elements which can be read separately.
818  * 0 is success, < 0 is failure.
819  */
820 static int ebml_read_master(MatroskaDemuxContext *matroska, uint64_t length)
821 {
822  AVIOContext *pb = matroska->ctx->pb;
824 
825  if (matroska->num_levels >= EBML_MAX_DEPTH) {
826  av_log(matroska->ctx, AV_LOG_ERROR,
827  "File moves beyond max. allowed depth (%d)\n", EBML_MAX_DEPTH);
828  return AVERROR(ENOSYS);
829  }
830 
831  level = &matroska->levels[matroska->num_levels++];
832  level->start = avio_tell(pb);
833  level->length = length;
834 
835  return 0;
836 }
837 
838 /*
839  * Read signed/unsigned "EBML" numbers.
840  * Return: number of bytes processed, < 0 on error
841  */
843  uint8_t *data, uint32_t size, uint64_t *num)
844 {
845  AVIOContext pb;
846  ffio_init_context(&pb, data, size, 0, NULL, NULL, NULL, NULL);
847  return ebml_read_num(matroska, &pb, FFMIN(size, 8), num);
848 }
849 
850 /*
851  * Same as above, but signed.
852  */
854  uint8_t *data, uint32_t size, int64_t *num)
855 {
856  uint64_t unum;
857  int res;
858 
859  /* read as unsigned number first */
860  if ((res = matroska_ebmlnum_uint(matroska, data, size, &unum)) < 0)
861  return res;
862 
863  /* make signed (weird way) */
864  *num = unum - ((1LL << (7*res - 1)) - 1);
865 
866  return res;
867 }
868 
869 static int ebml_parse_elem(MatroskaDemuxContext *matroska,
870  EbmlSyntax *syntax, void *data);
871 
872 static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
873  uint32_t id, void *data)
874 {
875  int i;
876  for (i=0; syntax[i].id; i++)
877  if (id == syntax[i].id)
878  break;
879  if (!syntax[i].id && id == MATROSKA_ID_CLUSTER &&
880  matroska->num_levels > 0 &&
881  matroska->levels[matroska->num_levels-1].length == 0xffffffffffffff)
882  return 0; // we reached the end of an unknown size cluster
883  if (!syntax[i].id && id != EBML_ID_VOID && id != EBML_ID_CRC32) {
884  av_log(matroska->ctx, AV_LOG_INFO, "Unknown entry 0x%X\n", id);
885  if (matroska->ctx->error_recognition & AV_EF_EXPLODE)
886  return AVERROR_INVALIDDATA;
887  }
888  return ebml_parse_elem(matroska, &syntax[i], data);
889 }
890 
891 static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
892  void *data)
893 {
894  if (!matroska->current_id) {
895  uint64_t id;
896  int res = ebml_read_num(matroska, matroska->ctx->pb, 4, &id);
897  if (res < 0)
898  return res;
899  matroska->current_id = id | 1 << 7*res;
900  }
901  return ebml_parse_id(matroska, syntax, matroska->current_id, data);
902 }
903 
904 static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
905  void *data)
906 {
907  int i, res = 0;
908 
909  for (i=0; syntax[i].id; i++)
910  switch (syntax[i].type) {
911  case EBML_UINT:
912  *(uint64_t *)((char *)data+syntax[i].data_offset) = syntax[i].def.u;
913  break;
914  case EBML_FLOAT:
915  *(double *)((char *)data+syntax[i].data_offset) = syntax[i].def.f;
916  break;
917  case EBML_STR:
918  case EBML_UTF8:
919  *(char **)((char *)data+syntax[i].data_offset) = av_strdup(syntax[i].def.s);
920  break;
921  }
922 
923  while (!res && !ebml_level_end(matroska))
924  res = ebml_parse(matroska, syntax, data);
925 
926  return res;
927 }
928 
930  EbmlSyntax *syntax, void *data)
931 {
932  static const uint64_t max_lengths[EBML_TYPE_COUNT] = {
933  [EBML_UINT] = 8,
934  [EBML_FLOAT] = 8,
935  // max. 16 MB for strings
936  [EBML_STR] = 0x1000000,
937  [EBML_UTF8] = 0x1000000,
938  // max. 256 MB for binary data
939  [EBML_BIN] = 0x10000000,
940  // no limits for anything else
941  };
942  AVIOContext *pb = matroska->ctx->pb;
943  uint32_t id = syntax->id;
944  uint64_t length;
945  int res;
946  void *newelem;
947 
948  data = (char *)data + syntax->data_offset;
949  if (syntax->list_elem_size) {
950  EbmlList *list = data;
951  newelem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size);
952  if (!newelem)
953  return AVERROR(ENOMEM);
954  list->elem = newelem;
955  data = (char*)list->elem + list->nb_elem*syntax->list_elem_size;
956  memset(data, 0, syntax->list_elem_size);
957  list->nb_elem++;
958  }
959 
960  if (syntax->type != EBML_PASS && syntax->type != EBML_STOP) {
961  matroska->current_id = 0;
962  if ((res = ebml_read_length(matroska, pb, &length)) < 0)
963  return res;
964  if (max_lengths[syntax->type] && length > max_lengths[syntax->type]) {
965  av_log(matroska->ctx, AV_LOG_ERROR,
966  "Invalid length 0x%"PRIx64" > 0x%"PRIx64" for syntax element %i\n",
967  length, max_lengths[syntax->type], syntax->type);
968  return AVERROR_INVALIDDATA;
969  }
970  }
971 
972  switch (syntax->type) {
973  case EBML_UINT: res = ebml_read_uint (pb, length, data); break;
974  case EBML_FLOAT: res = ebml_read_float (pb, length, data); break;
975  case EBML_STR:
976  case EBML_UTF8: res = ebml_read_ascii (pb, length, data); break;
977  case EBML_BIN: res = ebml_read_binary(pb, length, data); break;
978  case EBML_NEST: if ((res=ebml_read_master(matroska, length)) < 0)
979  return res;
980  if (id == MATROSKA_ID_SEGMENT)
981  matroska->segment_start = avio_tell(matroska->ctx->pb);
982  return ebml_parse_nest(matroska, syntax->def.n, data);
983  case EBML_PASS: return ebml_parse_id(matroska, syntax->def.n, id, data);
984  case EBML_STOP: return 1;
985  default:
986  if(ffio_limit(pb, length) != length)
987  return AVERROR(EIO);
988  return avio_skip(pb,length)<0 ? AVERROR(EIO) : 0;
989  }
990  if (res == AVERROR_INVALIDDATA)
991  av_log(matroska->ctx, AV_LOG_ERROR, "Invalid element\n");
992  else if (res == AVERROR(EIO))
993  av_log(matroska->ctx, AV_LOG_ERROR, "Read error\n");
994  return res;
995 }
996 
997 static void ebml_free(EbmlSyntax *syntax, void *data)
998 {
999  int i, j;
1000  for (i=0; syntax[i].id; i++) {
1001  void *data_off = (char *)data + syntax[i].data_offset;
1002  switch (syntax[i].type) {
1003  case EBML_STR:
1004  case EBML_UTF8: av_freep(data_off); break;
1005  case EBML_BIN: av_freep(&((EbmlBin *)data_off)->data); break;
1006  case EBML_NEST:
1007  if (syntax[i].list_elem_size) {
1008  EbmlList *list = data_off;
1009  char *ptr = list->elem;
1010  for (j=0; j<list->nb_elem; j++, ptr+=syntax[i].list_elem_size)
1011  ebml_free(syntax[i].def.n, ptr);
1012  av_free(list->elem);
1013  } else
1014  ebml_free(syntax[i].def.n, data_off);
1015  default: break;
1016  }
1017  }
1018 }
1019 
1020 
1021 /*
1022  * Autodetecting...
1023  */
1025 {
1026  uint64_t total = 0;
1027  int len_mask = 0x80, size = 1, n = 1, i;
1028 
1029  /* EBML header? */
1030  if (AV_RB32(p->buf) != EBML_ID_HEADER)
1031  return 0;
1032 
1033  /* length of header */
1034  total = p->buf[4];
1035  while (size <= 8 && !(total & len_mask)) {
1036  size++;
1037  len_mask >>= 1;
1038  }
1039  if (size > 8)
1040  return 0;
1041  total &= (len_mask - 1);
1042  while (n < size)
1043  total = (total << 8) | p->buf[4 + n++];
1044 
1045  /* Does the probe data contain the whole header? */
1046  if (p->buf_size < 4 + size + total)
1047  return 0;
1048 
1049  /* The header should contain a known document type. For now,
1050  * we don't parse the whole header but simply check for the
1051  * availability of that array of characters inside the header.
1052  * Not fully fool-proof, but good enough. */
1053  for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++) {
1054  int probelen = strlen(matroska_doctypes[i]);
1055  if (total < probelen)
1056  continue;
1057  for (n = 4+size; n <= 4+size+total-probelen; n++)
1058  if (!memcmp(p->buf+n, matroska_doctypes[i], probelen))
1059  return AVPROBE_SCORE_MAX;
1060  }
1061 
1062  // probably valid EBML header but no recognized doctype
1063  return AVPROBE_SCORE_MAX/2;
1064 }
1065 
1067  int num)
1068 {
1069  MatroskaTrack *tracks = matroska->tracks.elem;
1070  int i;
1071 
1072  for (i=0; i < matroska->tracks.nb_elem; i++)
1073  if (tracks[i].num == num)
1074  return &tracks[i];
1075 
1076  av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %d\n", num);
1077  return NULL;
1078 }
1079 
1080 static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
1082 {
1083  MatroskaTrackEncoding *encodings = track->encodings.elem;
1084  uint8_t* data = *buf;
1085  int isize = *buf_size;
1086  uint8_t* pkt_data = NULL;
1087  uint8_t av_unused *newpktdata;
1088  int pkt_size = isize;
1089  int result = 0;
1090  int olen;
1091 
1092  if (pkt_size >= 10000000U)
1093  return AVERROR_INVALIDDATA;
1094 
1095  switch (encodings[0].compression.algo) {
1097  int header_size = encodings[0].compression.settings.size;
1098  uint8_t *header = encodings[0].compression.settings.data;
1099 
1100  if (header_size && !header) {
1101  av_log(NULL, AV_LOG_ERROR, "Compression size but no data in headerstrip\n");
1102  return -1;
1103  }
1104 
1105  if (!header_size)
1106  return 0;
1107 
1108  pkt_size = isize + header_size;
1109  pkt_data = av_malloc(pkt_size);
1110  if (!pkt_data)
1111  return AVERROR(ENOMEM);
1112 
1113  memcpy(pkt_data, header, header_size);
1114  memcpy(pkt_data + header_size, data, isize);
1115  break;
1116  }
1117 #if CONFIG_LZO
1119  do {
1120  olen = pkt_size *= 3;
1121  newpktdata = av_realloc(pkt_data, pkt_size + AV_LZO_OUTPUT_PADDING);
1122  if (!newpktdata) {
1123  result = AVERROR(ENOMEM);
1124  goto failed;
1125  }
1126  pkt_data = newpktdata;
1127  result = av_lzo1x_decode(pkt_data, &olen, data, &isize);
1128  } while (result==AV_LZO_OUTPUT_FULL && pkt_size<10000000);
1129  if (result) {
1130  result = AVERROR_INVALIDDATA;
1131  goto failed;
1132  }
1133  pkt_size -= olen;
1134  break;
1135 #endif
1136 #if CONFIG_ZLIB
1138  z_stream zstream = {0};
1139  if (inflateInit(&zstream) != Z_OK)
1140  return -1;
1141  zstream.next_in = data;
1142  zstream.avail_in = isize;
1143  do {
1144  pkt_size *= 3;
1145  newpktdata = av_realloc(pkt_data, pkt_size);
1146  if (!newpktdata) {
1147  inflateEnd(&zstream);
1148  goto failed;
1149  }
1150  pkt_data = newpktdata;
1151  zstream.avail_out = pkt_size - zstream.total_out;
1152  zstream.next_out = pkt_data + zstream.total_out;
1153  if (pkt_data) {
1154  result = inflate(&zstream, Z_NO_FLUSH);
1155  } else
1156  result = Z_MEM_ERROR;
1157  } while (result==Z_OK && pkt_size<10000000);
1158  pkt_size = zstream.total_out;
1159  inflateEnd(&zstream);
1160  if (result != Z_STREAM_END) {
1161  if (result == Z_MEM_ERROR)
1162  result = AVERROR(ENOMEM);
1163  else
1164  result = AVERROR_INVALIDDATA;
1165  goto failed;
1166  }
1167  break;
1168  }
1169 #endif
1170 #if CONFIG_BZLIB
1172  bz_stream bzstream = {0};
1173  if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
1174  return -1;
1175  bzstream.next_in = data;
1176  bzstream.avail_in = isize;
1177  do {
1178  pkt_size *= 3;
1179  newpktdata = av_realloc(pkt_data, pkt_size);
1180  if (!newpktdata) {
1181  BZ2_bzDecompressEnd(&bzstream);
1182  goto failed;
1183  }
1184  pkt_data = newpktdata;
1185  bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
1186  bzstream.next_out = pkt_data + bzstream.total_out_lo32;
1187  if (pkt_data) {
1188  result = BZ2_bzDecompress(&bzstream);
1189  } else
1190  result = BZ_MEM_ERROR;
1191  } while (result==BZ_OK && pkt_size<10000000);
1192  pkt_size = bzstream.total_out_lo32;
1193  BZ2_bzDecompressEnd(&bzstream);
1194  if (result != BZ_STREAM_END) {
1195  if (result == BZ_MEM_ERROR)
1196  result = AVERROR(ENOMEM);
1197  else
1198  result = AVERROR_INVALIDDATA;
1199  goto failed;
1200  }
1201  break;
1202  }
1203 #endif
1204  default:
1205  return AVERROR_INVALIDDATA;
1206  }
1207 
1208  *buf = pkt_data;
1209  *buf_size = pkt_size;
1210  return 0;
1211  failed:
1212  av_free(pkt_data);
1213  return result;
1214 }
1215 
1216 #if FF_API_ASS_SSA
1217 static void matroska_fix_ass_packet(MatroskaDemuxContext *matroska,
1218  AVPacket *pkt, uint64_t display_duration)
1219 {
1220  AVBufferRef *line;
1221  char *layer, *ptr = pkt->data, *end = ptr+pkt->size;
1222  for (; *ptr!=',' && ptr<end-1; ptr++);
1223  if (*ptr == ',')
1224  ptr++;
1225  layer = ptr;
1226  for (; *ptr!=',' && ptr<end-1; ptr++);
1227  if (*ptr == ',') {
1228  int64_t end_pts = pkt->pts + display_duration;
1229  int sc = matroska->time_scale * pkt->pts / 10000000;
1230  int ec = matroska->time_scale * end_pts / 10000000;
1231  int sh, sm, ss, eh, em, es, len;
1232  sh = sc/360000; sc -= 360000*sh;
1233  sm = sc/ 6000; sc -= 6000*sm;
1234  ss = sc/ 100; sc -= 100*ss;
1235  eh = ec/360000; ec -= 360000*eh;
1236  em = ec/ 6000; ec -= 6000*em;
1237  es = ec/ 100; ec -= 100*es;
1238  *ptr++ = '\0';
1239  len = 50 + end-ptr + FF_INPUT_BUFFER_PADDING_SIZE;
1240  if (!(line = av_buffer_alloc(len)))
1241  return;
1242  snprintf(line->data, len,"Dialogue: %s,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,%s\r\n",
1243  layer, sh, sm, ss, sc, eh, em, es, ec, ptr);
1244  av_buffer_unref(&pkt->buf);
1245  pkt->buf = line;
1246  pkt->data = line->data;
1247  pkt->size = strlen(line->data);
1248  }
1249 }
1250 
1251 static int matroska_merge_packets(AVPacket *out, AVPacket *in)
1252 {
1253  int ret = av_grow_packet(out, in->size);
1254  if (ret < 0)
1255  return ret;
1256 
1257  memcpy(out->data + out->size - in->size, in->data, in->size);
1258 
1259  av_free_packet(in);
1260  av_free(in);
1261  return 0;
1262 }
1263 #endif
1264 
1266  AVDictionary **metadata, char *prefix)
1267 {
1268  MatroskaTag *tags = list->elem;
1269  char key[1024];
1270  int i;
1271 
1272  for (i=0; i < list->nb_elem; i++) {
1273  const char *lang= (tags[i].lang && strcmp(tags[i].lang, "und")) ? tags[i].lang : NULL;
1274 
1275  if (!tags[i].name) {
1276  av_log(s, AV_LOG_WARNING, "Skipping invalid tag with no TagName.\n");
1277  continue;
1278  }
1279  if (prefix) snprintf(key, sizeof(key), "%s/%s", prefix, tags[i].name);
1280  else av_strlcpy(key, tags[i].name, sizeof(key));
1281  if (tags[i].def || !lang) {
1282  av_dict_set(metadata, key, tags[i].string, 0);
1283  if (tags[i].sub.nb_elem)
1284  matroska_convert_tag(s, &tags[i].sub, metadata, key);
1285  }
1286  if (lang) {
1287  av_strlcat(key, "-", sizeof(key));
1288  av_strlcat(key, lang, sizeof(key));
1289  av_dict_set(metadata, key, tags[i].string, 0);
1290  if (tags[i].sub.nb_elem)
1291  matroska_convert_tag(s, &tags[i].sub, metadata, key);
1292  }
1293  }
1295 }
1296 
1298 {
1299  MatroskaDemuxContext *matroska = s->priv_data;
1300  MatroskaTags *tags = matroska->tags.elem;
1301  int i, j;
1302 
1303  for (i=0; i < matroska->tags.nb_elem; i++) {
1304  if (tags[i].target.attachuid) {
1305  MatroskaAttachement *attachment = matroska->attachments.elem;
1306  for (j=0; j<matroska->attachments.nb_elem; j++)
1307  if (attachment[j].uid == tags[i].target.attachuid
1308  && attachment[j].stream)
1309  matroska_convert_tag(s, &tags[i].tag,
1310  &attachment[j].stream->metadata, NULL);
1311  } else if (tags[i].target.chapteruid) {
1312  MatroskaChapter *chapter = matroska->chapters.elem;
1313  for (j=0; j<matroska->chapters.nb_elem; j++)
1314  if (chapter[j].uid == tags[i].target.chapteruid
1315  && chapter[j].chapter)
1316  matroska_convert_tag(s, &tags[i].tag,
1317  &chapter[j].chapter->metadata, NULL);
1318  } else if (tags[i].target.trackuid) {
1319  MatroskaTrack *track = matroska->tracks.elem;
1320  for (j=0; j<matroska->tracks.nb_elem; j++)
1321  if (track[j].uid == tags[i].target.trackuid && track[j].stream)
1322  matroska_convert_tag(s, &tags[i].tag,
1323  &track[j].stream->metadata, NULL);
1324  } else {
1325  matroska_convert_tag(s, &tags[i].tag, &s->metadata,
1326  tags[i].target.type);
1327  }
1328  }
1329 }
1330 
1332 {
1333  EbmlList *seekhead_list = &matroska->seekhead;
1334  MatroskaSeekhead *seekhead = seekhead_list->elem;
1335  uint32_t level_up = matroska->level_up;
1336  int64_t before_pos = avio_tell(matroska->ctx->pb);
1337  uint32_t saved_id = matroska->current_id;
1339  int64_t offset;
1340  int ret = 0;
1341 
1342  if (idx >= seekhead_list->nb_elem
1343  || seekhead[idx].id == MATROSKA_ID_SEEKHEAD
1344  || seekhead[idx].id == MATROSKA_ID_CLUSTER)
1345  return 0;
1346 
1347  /* seek */
1348  offset = seekhead[idx].pos + matroska->segment_start;
1349  if (avio_seek(matroska->ctx->pb, offset, SEEK_SET) == offset) {
1350  /* We don't want to lose our seekhead level, so we add
1351  * a dummy. This is a crude hack. */
1352  if (matroska->num_levels == EBML_MAX_DEPTH) {
1353  av_log(matroska->ctx, AV_LOG_INFO,
1354  "Max EBML element depth (%d) reached, "
1355  "cannot parse further.\n", EBML_MAX_DEPTH);
1356  ret = AVERROR_INVALIDDATA;
1357  } else {
1358  level.start = 0;
1359  level.length = (uint64_t)-1;
1360  matroska->levels[matroska->num_levels] = level;
1361  matroska->num_levels++;
1362  matroska->current_id = 0;
1363 
1364  ret = ebml_parse(matroska, matroska_segment, matroska);
1365 
1366  /* remove dummy level */
1367  while (matroska->num_levels) {
1368  uint64_t length = matroska->levels[--matroska->num_levels].length;
1369  if (length == (uint64_t)-1)
1370  break;
1371  }
1372  }
1373  }
1374  /* seek back */
1375  avio_seek(matroska->ctx->pb, before_pos, SEEK_SET);
1376  matroska->level_up = level_up;
1377  matroska->current_id = saved_id;
1378 
1379  return ret;
1380 }
1381 
1383 {
1384  EbmlList *seekhead_list = &matroska->seekhead;
1385  int64_t before_pos = avio_tell(matroska->ctx->pb);
1386  int i;
1387 
1388  // we should not do any seeking in the streaming case
1389  if (!matroska->ctx->pb->seekable ||
1390  (matroska->ctx->flags & AVFMT_FLAG_IGNIDX))
1391  return;
1392 
1393  for (i = 0; i < seekhead_list->nb_elem; i++) {
1394  MatroskaSeekhead *seekhead = seekhead_list->elem;
1395  if (seekhead[i].pos <= before_pos)
1396  continue;
1397 
1398  // defer cues parsing until we actually need cue data.
1399  if (seekhead[i].id == MATROSKA_ID_CUES) {
1400  matroska->cues_parsing_deferred = 1;
1401  continue;
1402  }
1403 
1404  if (matroska_parse_seekhead_entry(matroska, i) < 0) {
1405  // mark index as broken
1406  matroska->cues_parsing_deferred = -1;
1407  break;
1408  }
1409  }
1410 }
1411 
1413  EbmlList *index_list;
1415  int index_scale = 1;
1416  int i, j;
1417 
1418  index_list = &matroska->index;
1419  index = index_list->elem;
1420  if (index_list->nb_elem
1421  && index[0].time > 1E14/matroska->time_scale) {
1422  av_log(matroska->ctx, AV_LOG_WARNING, "Working around broken index.\n");
1423  index_scale = matroska->time_scale;
1424  }
1425  for (i = 0; i < index_list->nb_elem; i++) {
1426  EbmlList *pos_list = &index[i].pos;
1427  MatroskaIndexPos *pos = pos_list->elem;
1428  for (j = 0; j < pos_list->nb_elem; j++) {
1429  MatroskaTrack *track = matroska_find_track_by_num(matroska, pos[j].track);
1430  if (track && track->stream)
1431  av_add_index_entry(track->stream,
1432  pos[j].pos + matroska->segment_start,
1433  index[i].time/index_scale, 0, 0,
1435  }
1436  }
1437 }
1438 
1440  EbmlList *seekhead_list = &matroska->seekhead;
1441  MatroskaSeekhead *seekhead = seekhead_list->elem;
1442  int i;
1443 
1444  for (i = 0; i < seekhead_list->nb_elem; i++)
1445  if (seekhead[i].id == MATROSKA_ID_CUES)
1446  break;
1447  av_assert1(i <= seekhead_list->nb_elem);
1448 
1449  if (matroska_parse_seekhead_entry(matroska, i) < 0)
1450  matroska->cues_parsing_deferred = -1;
1451  matroska_add_index_entries(matroska);
1452 }
1453 
1455 {
1456  static const char * const aac_profiles[] = { "MAIN", "LC", "SSR" };
1457  int profile;
1458 
1459  for (profile=0; profile<FF_ARRAY_ELEMS(aac_profiles); profile++)
1460  if (strstr(codec_id, aac_profiles[profile]))
1461  break;
1462  return profile + 1;
1463 }
1464 
1465 static int matroska_aac_sri(int samplerate)
1466 {
1467  int sri;
1468 
1469  for (sri=0; sri<FF_ARRAY_ELEMS(avpriv_mpeg4audio_sample_rates); sri++)
1470  if (avpriv_mpeg4audio_sample_rates[sri] == samplerate)
1471  break;
1472  return sri;
1473 }
1474 
1475 static void matroska_metadata_creation_time(AVDictionary **metadata, int64_t date_utc)
1476 {
1477  char buffer[32];
1478  /* Convert to seconds and adjust by number of seconds between 2001-01-01 and Epoch */
1479  time_t creation_time = date_utc / 1000000000 + 978307200;
1480  struct tm *ptm = gmtime(&creation_time);
1481  if (!ptm) return;
1482  strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", ptm);
1483  av_dict_set(metadata, "creation_time", buffer, 0);
1484 }
1485 
1487 {
1488  MatroskaDemuxContext *matroska = s->priv_data;
1489  EbmlList *attachements_list = &matroska->attachments;
1490  MatroskaAttachement *attachements;
1491  EbmlList *chapters_list = &matroska->chapters;
1492  MatroskaChapter *chapters;
1493  MatroskaTrack *tracks;
1494  uint64_t max_start = 0;
1495  int64_t pos;
1496  Ebml ebml = { 0 };
1497  AVStream *st;
1498  int i, j, k, res;
1499 
1500  matroska->ctx = s;
1501 
1502  /* First read the EBML header. */
1503  if (ebml_parse(matroska, ebml_syntax, &ebml)
1504  || ebml.version > EBML_VERSION || ebml.max_size > sizeof(uint64_t)
1505  || ebml.id_length > sizeof(uint32_t) || ebml.doctype_version > 3 || !ebml.doctype) {
1506  av_log(matroska->ctx, AV_LOG_ERROR,
1507  "EBML header using unsupported features\n"
1508  "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n",
1509  ebml.version, ebml.doctype, ebml.doctype_version);
1510  ebml_free(ebml_syntax, &ebml);
1511  return AVERROR_PATCHWELCOME;
1512  } else if (ebml.doctype_version == 3) {
1513  av_log(matroska->ctx, AV_LOG_WARNING,
1514  "EBML header using unsupported features\n"
1515  "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n",
1516  ebml.version, ebml.doctype, ebml.doctype_version);
1517  }
1518  for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++)
1519  if (!strcmp(ebml.doctype, matroska_doctypes[i]))
1520  break;
1521  if (i >= FF_ARRAY_ELEMS(matroska_doctypes)) {
1522  av_log(s, AV_LOG_WARNING, "Unknown EBML doctype '%s'\n", ebml.doctype);
1523  if (matroska->ctx->error_recognition & AV_EF_EXPLODE) {
1524  ebml_free(ebml_syntax, &ebml);
1525  return AVERROR_INVALIDDATA;
1526  }
1527  }
1528  ebml_free(ebml_syntax, &ebml);
1529 
1530  /* The next thing is a segment. */
1531  pos = avio_tell(matroska->ctx->pb);
1532  res = ebml_parse(matroska, matroska_segments, matroska);
1533  // try resyncing until we find a EBML_STOP type element.
1534  while (res != 1) {
1535  res = matroska_resync(matroska, pos);
1536  if (res < 0)
1537  return res;
1538  pos = avio_tell(matroska->ctx->pb);
1539  res = ebml_parse(matroska, matroska_segment, matroska);
1540  }
1541  matroska_execute_seekhead(matroska);
1542 
1543  if (!matroska->time_scale)
1544  matroska->time_scale = 1000000;
1545  if (matroska->duration)
1546  matroska->ctx->duration = matroska->duration * matroska->time_scale
1547  * 1000 / AV_TIME_BASE;
1548  av_dict_set(&s->metadata, "title", matroska->title, 0);
1549 
1550  if (matroska->date_utc.size == 8)
1552 
1553  tracks = matroska->tracks.elem;
1554  for (i=0; i < matroska->tracks.nb_elem; i++) {
1555  MatroskaTrack *track = &tracks[i];
1557  EbmlList *encodings_list = &track->encodings;
1558  MatroskaTrackEncoding *encodings = encodings_list->elem;
1559  uint8_t *extradata = NULL;
1560  int extradata_size = 0;
1561  int extradata_offset = 0;
1562  uint32_t fourcc = 0;
1563  AVIOContext b;
1564  char* key_id_base64 = NULL;
1565 
1566  /* Apply some sanity checks. */
1567  if (track->type != MATROSKA_TRACK_TYPE_VIDEO &&
1568  track->type != MATROSKA_TRACK_TYPE_AUDIO &&
1569  track->type != MATROSKA_TRACK_TYPE_SUBTITLE) {
1570  av_log(matroska->ctx, AV_LOG_INFO,
1571  "Unknown or unsupported track type %"PRIu64"\n",
1572  track->type);
1573  continue;
1574  }
1575  if (track->codec_id == NULL)
1576  continue;
1577 
1578  if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
1579  if (!track->default_duration && track->video.frame_rate > 0)
1580  track->default_duration = 1000000000/track->video.frame_rate;
1581  if (track->video.display_width == -1)
1582  track->video.display_width = track->video.pixel_width;
1583  if (track->video.display_height == -1)
1584  track->video.display_height = track->video.pixel_height;
1585  if (track->video.color_space.size == 4)
1586  fourcc = AV_RL32(track->video.color_space.data);
1587  } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
1588  if (!track->audio.out_samplerate)
1589  track->audio.out_samplerate = track->audio.samplerate;
1590  }
1591  if (encodings_list->nb_elem > 1) {
1592  av_log(matroska->ctx, AV_LOG_ERROR,
1593  "Multiple combined encodings not supported");
1594  } else if (encodings_list->nb_elem == 1) {
1595  if (encodings[0].type) {
1596  if (encodings[0].encryption.key_id.size > 0) {
1597  /* Save the encryption key id to be stored later as a
1598  metadata tag. */
1599  const int b64_size = AV_BASE64_SIZE(encodings[0].encryption.key_id.size);
1600  key_id_base64 = av_malloc(b64_size);
1601  if (key_id_base64 == NULL)
1602  return AVERROR(ENOMEM);
1603 
1604  av_base64_encode(key_id_base64, b64_size,
1605  encodings[0].encryption.key_id.data,
1606  encodings[0].encryption.key_id.size);
1607  } else {
1608  encodings[0].scope = 0;
1609  av_log(matroska->ctx, AV_LOG_ERROR,
1610  "Unsupported encoding type");
1611  }
1612  } else if (
1613 #if CONFIG_ZLIB
1614  encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_ZLIB &&
1615 #endif
1616 #if CONFIG_BZLIB
1618 #endif
1619 #if CONFIG_LZO
1621 #endif
1623  encodings[0].scope = 0;
1624  av_log(matroska->ctx, AV_LOG_ERROR,
1625  "Unsupported encoding type");
1626  } else if (track->codec_priv.size && encodings[0].scope&2) {
1627  uint8_t *codec_priv = track->codec_priv.data;
1628  int ret = matroska_decode_buffer(&track->codec_priv.data,
1629  &track->codec_priv.size,
1630  track);
1631  if (ret < 0) {
1632  track->codec_priv.data = NULL;
1633  track->codec_priv.size = 0;
1634  av_log(matroska->ctx, AV_LOG_ERROR,
1635  "Failed to decode codec private data\n");
1636  }
1637 
1638  if (codec_priv != track->codec_priv.data)
1639  av_free(codec_priv);
1640  }
1641  }
1642 
1643  for(j=0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++){
1644  if(!strncmp(ff_mkv_codec_tags[j].str, track->codec_id,
1645  strlen(ff_mkv_codec_tags[j].str))){
1646  codec_id= ff_mkv_codec_tags[j].id;
1647  break;
1648  }
1649  }
1650 
1651  st = track->stream = avformat_new_stream(s, NULL);
1652  if (st == NULL) {
1653  av_free(key_id_base64);
1654  return AVERROR(ENOMEM);
1655  }
1656 
1657  if (key_id_base64) {
1658  /* export encryption key id as base64 metadata tag */
1659  av_dict_set(&st->metadata, "enc_key_id", key_id_base64, 0);
1660  av_freep(&key_id_base64);
1661  }
1662 
1663  if (!strcmp(track->codec_id, "V_MS/VFW/FOURCC")
1664  && track->codec_priv.size >= 40
1665  && track->codec_priv.data != NULL) {
1666  track->ms_compat = 1;
1667  fourcc = AV_RL32(track->codec_priv.data + 16);
1668  codec_id = ff_codec_get_id(ff_codec_bmp_tags, fourcc);
1669  extradata_offset = 40;
1670  } else if (!strcmp(track->codec_id, "A_MS/ACM")
1671  && track->codec_priv.size >= 14
1672  && track->codec_priv.data != NULL) {
1673  int ret;
1674  ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size,
1675  0, NULL, NULL, NULL, NULL);
1676  ret = ff_get_wav_header(&b, st->codec, track->codec_priv.size);
1677  if (ret < 0)
1678  return ret;
1679  codec_id = st->codec->codec_id;
1680  extradata_offset = FFMIN(track->codec_priv.size, 18);
1681  } else if (!strcmp(track->codec_id, "V_QUICKTIME")
1682  && (track->codec_priv.size >= 86)
1683  && (track->codec_priv.data != NULL)) {
1684  fourcc = AV_RL32(track->codec_priv.data);
1685  codec_id = ff_codec_get_id(ff_codec_movvideo_tags, fourcc);
1686  } else if (codec_id == AV_CODEC_ID_ALAC && track->codec_priv.size && track->codec_priv.size < INT_MAX - 12 - FF_INPUT_BUFFER_PADDING_SIZE) {
1687  /* Only ALAC's magic cookie is stored in Matroska's track headers.
1688  Create the "atom size", "tag", and "tag version" fields the
1689  decoder expects manually. */
1690  extradata_size = 12 + track->codec_priv.size;
1691  extradata = av_mallocz(extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
1692  if (extradata == NULL)
1693  return AVERROR(ENOMEM);
1694  AV_WB32(extradata, extradata_size);
1695  memcpy(&extradata[4], "alac", 4);
1696  AV_WB32(&extradata[8], 0);
1697  memcpy(&extradata[12], track->codec_priv.data, track->codec_priv.size);
1698  } else if (codec_id == AV_CODEC_ID_PCM_S16BE) {
1699  switch (track->audio.bitdepth) {
1700  case 8: codec_id = AV_CODEC_ID_PCM_U8; break;
1701  case 24: codec_id = AV_CODEC_ID_PCM_S24BE; break;
1702  case 32: codec_id = AV_CODEC_ID_PCM_S32BE; break;
1703  }
1704  } else if (codec_id == AV_CODEC_ID_PCM_S16LE) {
1705  switch (track->audio.bitdepth) {
1706  case 8: codec_id = AV_CODEC_ID_PCM_U8; break;
1707  case 24: codec_id = AV_CODEC_ID_PCM_S24LE; break;
1708  case 32: codec_id = AV_CODEC_ID_PCM_S32LE; break;
1709  }
1710  } else if (codec_id==AV_CODEC_ID_PCM_F32LE && track->audio.bitdepth==64) {
1711  codec_id = AV_CODEC_ID_PCM_F64LE;
1712  } else if (codec_id == AV_CODEC_ID_AAC && !track->codec_priv.size) {
1713  int profile = matroska_aac_profile(track->codec_id);
1714  int sri = matroska_aac_sri(track->audio.samplerate);
1715  extradata = av_mallocz(5 + FF_INPUT_BUFFER_PADDING_SIZE);
1716  if (extradata == NULL)
1717  return AVERROR(ENOMEM);
1718  extradata[0] = (profile << 3) | ((sri&0x0E) >> 1);
1719  extradata[1] = ((sri&0x01) << 7) | (track->audio.channels<<3);
1720  if (strstr(track->codec_id, "SBR")) {
1721  sri = matroska_aac_sri(track->audio.out_samplerate);
1722  extradata[2] = 0x56;
1723  extradata[3] = 0xE5;
1724  extradata[4] = 0x80 | (sri<<3);
1725  extradata_size = 5;
1726  } else
1727  extradata_size = 2;
1728  } else if (codec_id == AV_CODEC_ID_TTA) {
1729  extradata_size = 30;
1730  extradata = av_mallocz(extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
1731  if (extradata == NULL)
1732  return AVERROR(ENOMEM);
1733  ffio_init_context(&b, extradata, extradata_size, 1,
1734  NULL, NULL, NULL, NULL);
1735  avio_write(&b, "TTA1", 4);
1736  avio_wl16(&b, 1);
1737  avio_wl16(&b, track->audio.channels);
1738  avio_wl16(&b, track->audio.bitdepth);
1739  avio_wl32(&b, track->audio.out_samplerate);
1740  avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate);
1741  } else if (codec_id == AV_CODEC_ID_RV10 || codec_id == AV_CODEC_ID_RV20 ||
1742  codec_id == AV_CODEC_ID_RV30 || codec_id == AV_CODEC_ID_RV40) {
1743  extradata_offset = 26;
1744  } else if (codec_id == AV_CODEC_ID_RA_144) {
1745  track->audio.out_samplerate = 8000;
1746  track->audio.channels = 1;
1747  } else if ((codec_id == AV_CODEC_ID_RA_288 || codec_id == AV_CODEC_ID_COOK ||
1748  codec_id == AV_CODEC_ID_ATRAC3 || codec_id == AV_CODEC_ID_SIPR)
1749  && track->codec_priv.data) {
1750  int flavor;
1751 
1752  ffio_init_context(&b, track->codec_priv.data,track->codec_priv.size,
1753  0, NULL, NULL, NULL, NULL);
1754  avio_skip(&b, 22);
1755  flavor = avio_rb16(&b);
1756  track->audio.coded_framesize = avio_rb32(&b);
1757  avio_skip(&b, 12);
1758  track->audio.sub_packet_h = avio_rb16(&b);
1759  track->audio.frame_size = avio_rb16(&b);
1760  track->audio.sub_packet_size = avio_rb16(&b);
1761  track->audio.buf = av_malloc(track->audio.frame_size * track->audio.sub_packet_h);
1762  if (codec_id == AV_CODEC_ID_RA_288) {
1763  st->codec->block_align = track->audio.coded_framesize;
1764  track->codec_priv.size = 0;
1765  } else {
1766  if (codec_id == AV_CODEC_ID_SIPR && flavor < 4) {
1767  const int sipr_bit_rate[4] = { 6504, 8496, 5000, 16000 };
1768  track->audio.sub_packet_size = ff_sipr_subpk_size[flavor];
1769  st->codec->bit_rate = sipr_bit_rate[flavor];
1770  }
1771  st->codec->block_align = track->audio.sub_packet_size;
1772  extradata_offset = 78;
1773  }
1774  }
1775  track->codec_priv.size -= extradata_offset;
1776 
1777  if (codec_id == AV_CODEC_ID_NONE)
1778  av_log(matroska->ctx, AV_LOG_INFO,
1779  "Unknown/unsupported AVCodecID %s.\n", track->codec_id);
1780 
1781  if (track->time_scale < 0.01)
1782  track->time_scale = 1.0;
1783  avpriv_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */
1784 
1785  st->codec->codec_id = codec_id;
1786  st->start_time = 0;
1787  if (strcmp(track->language, "und"))
1788  av_dict_set(&st->metadata, "language", track->language, 0);
1789  av_dict_set(&st->metadata, "title", track->name, 0);
1790 
1791  if (track->flag_default)
1793  if (track->flag_forced)
1795 
1796  if (!st->codec->extradata) {
1797  if(extradata){
1798  st->codec->extradata = extradata;
1799  st->codec->extradata_size = extradata_size;
1800  } else if(track->codec_priv.data && track->codec_priv.size > 0){
1801  st->codec->extradata = av_mallocz(track->codec_priv.size +
1803  if(st->codec->extradata == NULL)
1804  return AVERROR(ENOMEM);
1805  st->codec->extradata_size = track->codec_priv.size;
1806  memcpy(st->codec->extradata,
1807  track->codec_priv.data + extradata_offset,
1808  track->codec_priv.size);
1809  }
1810  }
1811 
1812  if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
1814 
1816  st->codec->codec_tag = fourcc;
1817  st->codec->width = track->video.pixel_width;
1818  st->codec->height = track->video.pixel_height;
1820  &st->sample_aspect_ratio.den,
1821  st->codec->height * track->video.display_width,
1822  st->codec-> width * track->video.display_height,
1823  255);
1825  if (track->default_duration) {
1827  1000000000, track->default_duration, 30000);
1828 #if FF_API_R_FRAME_RATE
1829  st->r_frame_rate = st->avg_frame_rate;
1830 #endif
1831  }
1832 
1833  /* export stereo mode flag as metadata tag */
1835  av_dict_set(&st->metadata, "stereo_mode", ff_matroska_video_stereo_mode[track->video.stereo_mode], 0);
1836 
1837  /* export alpha mode flag as metadata tag */
1838  if (track->video.alpha_mode)
1839  av_dict_set(&st->metadata, "alpha_mode", "1", 0);
1840 
1841  /* if we have virtual track, mark the real tracks */
1842  for (j=0; j < track->operation.combine_planes.nb_elem; j++) {
1843  char buf[32];
1844  if (planes[j].type >= MATROSKA_VIDEO_STEREO_PLANE_COUNT)
1845  continue;
1846  snprintf(buf, sizeof(buf), "%s_%d",
1847  ff_matroska_video_stereo_plane[planes[j].type], i);
1848  for (k=0; k < matroska->tracks.nb_elem; k++)
1849  if (planes[j].uid == tracks[k].uid) {
1850  av_dict_set(&s->streams[k]->metadata,
1851  "stereo_mode", buf, 0);
1852  break;
1853  }
1854  }
1855  } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
1857  st->codec->sample_rate = track->audio.out_samplerate;
1858  st->codec->channels = track->audio.channels;
1859  st->codec->bits_per_coded_sample = track->audio.bitdepth;
1860  if (st->codec->codec_id != AV_CODEC_ID_AAC)
1862  } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
1864 #if FF_API_ASS_SSA
1865  if (st->codec->codec_id == AV_CODEC_ID_SSA ||
1866  st->codec->codec_id == AV_CODEC_ID_ASS)
1867 #else
1868  if (st->codec->codec_id == AV_CODEC_ID_ASS)
1869 #endif
1870  matroska->contains_ssa = 1;
1871  }
1872  }
1873 
1874  attachements = attachements_list->elem;
1875  for (j=0; j<attachements_list->nb_elem; j++) {
1876  if (!(attachements[j].filename && attachements[j].mime &&
1877  attachements[j].bin.data && attachements[j].bin.size > 0)) {
1878  av_log(matroska->ctx, AV_LOG_ERROR, "incomplete attachment\n");
1879  } else {
1880  AVStream *st = avformat_new_stream(s, NULL);
1881  if (st == NULL)
1882  break;
1883  av_dict_set(&st->metadata, "filename",attachements[j].filename, 0);
1884  av_dict_set(&st->metadata, "mimetype", attachements[j].mime, 0);
1887  st->codec->extradata = av_malloc(attachements[j].bin.size + FF_INPUT_BUFFER_PADDING_SIZE);
1888  if(st->codec->extradata == NULL)
1889  break;
1890  st->codec->extradata_size = attachements[j].bin.size;
1891  memcpy(st->codec->extradata, attachements[j].bin.data, attachements[j].bin.size);
1892 
1893  for (i=0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) {
1894  if (!strncmp(ff_mkv_mime_tags[i].str, attachements[j].mime,
1895  strlen(ff_mkv_mime_tags[i].str))) {
1897  break;
1898  }
1899  }
1900  attachements[j].stream = st;
1901  }
1902  }
1903 
1904  chapters = chapters_list->elem;
1905  for (i=0; i<chapters_list->nb_elem; i++)
1906  if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid
1907  && (max_start==0 || chapters[i].start > max_start)) {
1908  chapters[i].chapter =
1909  avpriv_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000},
1910  chapters[i].start, chapters[i].end,
1911  chapters[i].title);
1912  av_dict_set(&chapters[i].chapter->metadata,
1913  "title", chapters[i].title, 0);
1914  max_start = chapters[i].start;
1915  }
1916 
1917  matroska_add_index_entries(matroska);
1918 
1920 
1921  return 0;
1922 }
1923 
1924 /*
1925  * Put one packet in an application-supplied AVPacket struct.
1926  * Returns 0 on success or -1 on failure.
1927  */
1929  AVPacket *pkt)
1930 {
1931  if (matroska->num_packets > 0) {
1932  memcpy(pkt, matroska->packets[0], sizeof(AVPacket));
1933  av_free(matroska->packets[0]);
1934  if (matroska->num_packets > 1) {
1935  void *newpackets;
1936  memmove(&matroska->packets[0], &matroska->packets[1],
1937  (matroska->num_packets - 1) * sizeof(AVPacket *));
1938  newpackets = av_realloc(matroska->packets,
1939  (matroska->num_packets - 1) * sizeof(AVPacket *));
1940  if (newpackets)
1941  matroska->packets = newpackets;
1942  } else {
1943  av_freep(&matroska->packets);
1944  matroska->prev_pkt = NULL;
1945  }
1946  matroska->num_packets--;
1947  return 0;
1948  }
1949 
1950  return -1;
1951 }
1952 
1953 /*
1954  * Free all packets in our internal queue.
1955  */
1957 {
1958  matroska->prev_pkt = NULL;
1959  if (matroska->packets) {
1960  int n;
1961  for (n = 0; n < matroska->num_packets; n++) {
1962  av_free_packet(matroska->packets[n]);
1963  av_free(matroska->packets[n]);
1964  }
1965  av_freep(&matroska->packets);
1966  matroska->num_packets = 0;
1967  }
1968 }
1969 
1971  int* buf_size, int type,
1972  uint32_t **lace_buf, int *laces)
1973 {
1974  int res = 0, n, size = *buf_size;
1975  uint8_t *data = *buf;
1976  uint32_t *lace_size;
1977 
1978  if (!type) {
1979  *laces = 1;
1980  *lace_buf = av_mallocz(sizeof(int));
1981  if (!*lace_buf)
1982  return AVERROR(ENOMEM);
1983 
1984  *lace_buf[0] = size;
1985  return 0;
1986  }
1987 
1988  av_assert0(size > 0);
1989  *laces = *data + 1;
1990  data += 1;
1991  size -= 1;
1992  lace_size = av_mallocz(*laces * sizeof(int));
1993  if (!lace_size)
1994  return AVERROR(ENOMEM);
1995 
1996  switch (type) {
1997  case 0x1: /* Xiph lacing */ {
1998  uint8_t temp;
1999  uint32_t total = 0;
2000  for (n = 0; res == 0 && n < *laces - 1; n++) {
2001  while (1) {
2002  if (size <= total) {
2003  res = AVERROR_INVALIDDATA;
2004  break;
2005  }
2006  temp = *data;
2007  total += temp;
2008  lace_size[n] += temp;
2009  data += 1;
2010  size -= 1;
2011  if (temp != 0xff)
2012  break;
2013  }
2014  }
2015  if (size <= total) {
2016  res = AVERROR_INVALIDDATA;
2017  break;
2018  }
2019 
2020  lace_size[n] = size - total;
2021  break;
2022  }
2023 
2024  case 0x2: /* fixed-size lacing */
2025  if (size % (*laces)) {
2026  res = AVERROR_INVALIDDATA;
2027  break;
2028  }
2029  for (n = 0; n < *laces; n++)
2030  lace_size[n] = size / *laces;
2031  break;
2032 
2033  case 0x3: /* EBML lacing */ {
2034  uint64_t num;
2035  uint64_t total;
2036  n = matroska_ebmlnum_uint(matroska, data, size, &num);
2037  if (n < 0 || num > INT_MAX) {
2038  av_log(matroska->ctx, AV_LOG_INFO,
2039  "EBML block data error\n");
2040  res = n<0 ? n : AVERROR_INVALIDDATA;
2041  break;
2042  }
2043  data += n;
2044  size -= n;
2045  total = lace_size[0] = num;
2046  for (n = 1; res == 0 && n < *laces - 1; n++) {
2047  int64_t snum;
2048  int r;
2049  r = matroska_ebmlnum_sint(matroska, data, size, &snum);
2050  if (r < 0 || lace_size[n - 1] + snum > (uint64_t)INT_MAX) {
2051  av_log(matroska->ctx, AV_LOG_INFO,
2052  "EBML block data error\n");
2053  res = r<0 ? r : AVERROR_INVALIDDATA;
2054  break;
2055  }
2056  data += r;
2057  size -= r;
2058  lace_size[n] = lace_size[n - 1] + snum;
2059  total += lace_size[n];
2060  }
2061  if (size <= total) {
2062  res = AVERROR_INVALIDDATA;
2063  break;
2064  }
2065  lace_size[*laces - 1] = size - total;
2066  break;
2067  }
2068  }
2069 
2070  *buf = data;
2071  *lace_buf = lace_size;
2072  *buf_size = size;
2073 
2074  return res;
2075 }
2076 
2079  AVStream *st,
2080  uint8_t *data, int size,
2081  uint64_t timecode,
2082  int64_t pos)
2083 {
2084  int a = st->codec->block_align;
2085  int sps = track->audio.sub_packet_size;
2086  int cfs = track->audio.coded_framesize;
2087  int h = track->audio.sub_packet_h;
2088  int y = track->audio.sub_packet_cnt;
2089  int w = track->audio.frame_size;
2090  int x;
2091 
2092  if (!track->audio.pkt_cnt) {
2093  if (track->audio.sub_packet_cnt == 0)
2094  track->audio.buf_timecode = timecode;
2095  if (st->codec->codec_id == AV_CODEC_ID_RA_288) {
2096  if (size < cfs * h / 2) {
2097  av_log(matroska->ctx, AV_LOG_ERROR,
2098  "Corrupt int4 RM-style audio packet size\n");
2099  return AVERROR_INVALIDDATA;
2100  }
2101  for (x=0; x<h/2; x++)
2102  memcpy(track->audio.buf+x*2*w+y*cfs,
2103  data+x*cfs, cfs);
2104  } else if (st->codec->codec_id == AV_CODEC_ID_SIPR) {
2105  if (size < w) {
2106  av_log(matroska->ctx, AV_LOG_ERROR,
2107  "Corrupt sipr RM-style audio packet size\n");
2108  return AVERROR_INVALIDDATA;
2109  }
2110  memcpy(track->audio.buf + y*w, data, w);
2111  } else {
2112  if (size < sps * w / sps || h<=0) {
2113  av_log(matroska->ctx, AV_LOG_ERROR,
2114  "Corrupt generic RM-style audio packet size\n");
2115  return AVERROR_INVALIDDATA;
2116  }
2117  for (x=0; x<w/sps; x++)
2118  memcpy(track->audio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps);
2119  }
2120 
2121  if (++track->audio.sub_packet_cnt >= h) {
2122  if (st->codec->codec_id == AV_CODEC_ID_SIPR)
2123  ff_rm_reorder_sipr_data(track->audio.buf, h, w);
2124  track->audio.sub_packet_cnt = 0;
2125  track->audio.pkt_cnt = h*w / a;
2126  }
2127  }
2128 
2129  while (track->audio.pkt_cnt) {
2130  AVPacket *pkt = NULL;
2131  if (!(pkt = av_mallocz(sizeof(AVPacket))) || av_new_packet(pkt, a) < 0){
2132  av_free(pkt);
2133  return AVERROR(ENOMEM);
2134  }
2135  memcpy(pkt->data, track->audio.buf
2136  + a * (h*w / a - track->audio.pkt_cnt--), a);
2137  pkt->pts = track->audio.buf_timecode;
2139  pkt->pos = pos;
2140  pkt->stream_index = st->index;
2141  dynarray_add(&matroska->packets,&matroska->num_packets,pkt);
2142  }
2143 
2144  return 0;
2145 }
2148  AVStream *st,
2149  uint8_t *data, int pkt_size,
2150  uint64_t timecode, uint64_t lace_duration,
2151  int64_t pos, int is_keyframe,
2152  uint8_t *additional, uint64_t additional_id, int additional_size)
2153 {
2154  MatroskaTrackEncoding *encodings = track->encodings.elem;
2155  uint8_t *pkt_data = data;
2156  int offset = 0, res;
2157  AVPacket *pkt;
2158 
2159  if (encodings && !encodings->type && encodings->scope & 1) {
2160  res = matroska_decode_buffer(&pkt_data, &pkt_size, track);
2161  if (res < 0)
2162  return res;
2163  }
2164 
2165  if (st->codec->codec_id == AV_CODEC_ID_PRORES)
2166  offset = 8;
2167 
2168  pkt = av_mallocz(sizeof(AVPacket));
2169  /* XXX: prevent data copy... */
2170  if (av_new_packet(pkt, pkt_size + offset) < 0) {
2171  av_free(pkt);
2172  return AVERROR(ENOMEM);
2173  }
2174 
2175  if (st->codec->codec_id == AV_CODEC_ID_PRORES) {
2176  uint8_t *buf = pkt->data;
2177  bytestream_put_be32(&buf, pkt_size);
2178  bytestream_put_be32(&buf, MKBETAG('i', 'c', 'p', 'f'));
2179  }
2180 
2181  memcpy(pkt->data + offset, pkt_data, pkt_size);
2182 
2183  if (pkt_data != data)
2184  av_free(pkt_data);
2185 
2186  pkt->flags = is_keyframe;
2187  pkt->stream_index = st->index;
2188 
2189  if (additional_size > 0) {
2190  uint8_t *side_data = av_packet_new_side_data(pkt,
2192  additional_size + 8);
2193  if(side_data == NULL) {
2194  av_free_packet(pkt);
2195  av_free(pkt);
2196  return AVERROR(ENOMEM);
2197  }
2198  AV_WB64(side_data, additional_id);
2199  memcpy(side_data + 8, additional, additional_size);
2200  }
2201 
2202  if (track->ms_compat)
2203  pkt->dts = timecode;
2204  else
2205  pkt->pts = timecode;
2206  pkt->pos = pos;
2207  if (st->codec->codec_id == AV_CODEC_ID_SUBRIP) {
2208  /*
2209  * For backward compatibility.
2210  * Historically, we have put subtitle duration
2211  * in convergence_duration, on the off chance
2212  * that the time_scale is less than 1us, which
2213  * could result in a 32bit overflow on the
2214  * normal duration field.
2215  */
2216  pkt->convergence_duration = lace_duration;
2217  }
2218 
2219  if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE ||
2220  lace_duration <= INT_MAX) {
2221  /*
2222  * For non subtitle tracks, just store the duration
2223  * as normal.
2224  *
2225  * If it's a subtitle track and duration value does
2226  * not overflow a uint32, then also store it normally.
2227  */
2228  pkt->duration = lace_duration;
2229  }
2230 
2231 #if FF_API_ASS_SSA
2232  if (st->codec->codec_id == AV_CODEC_ID_SSA)
2233  matroska_fix_ass_packet(matroska, pkt, lace_duration);
2234 
2235  if (matroska->prev_pkt &&
2236  timecode != AV_NOPTS_VALUE &&
2237  matroska->prev_pkt->pts == timecode &&
2238  matroska->prev_pkt->stream_index == st->index &&
2239  st->codec->codec_id == AV_CODEC_ID_SSA)
2240  matroska_merge_packets(matroska->prev_pkt, pkt);
2241  else {
2242  dynarray_add(&matroska->packets,&matroska->num_packets,pkt);
2243  matroska->prev_pkt = pkt;
2244  }
2245 #else
2246  dynarray_add(&matroska->packets, &matroska->num_packets, pkt);
2247  matroska->prev_pkt = pkt;
2248 #endif
2249 
2250  return 0;
2251 }
2252 
2254  int size, int64_t pos, uint64_t cluster_time,
2255  uint64_t block_duration, int is_keyframe,
2256  uint8_t *additional, uint64_t additional_id, int additional_size,
2257  int64_t cluster_pos)
2258 {
2259  uint64_t timecode = AV_NOPTS_VALUE;
2261  int res = 0;
2262  AVStream *st;
2263  int16_t block_time;
2264  uint32_t *lace_size = NULL;
2265  int n, flags, laces = 0;
2266  uint64_t num;
2267 
2268  if ((n = matroska_ebmlnum_uint(matroska, data, size, &num)) < 0) {
2269  av_log(matroska->ctx, AV_LOG_ERROR, "EBML block data error\n");
2270  return n;
2271  }
2272  data += n;
2273  size -= n;
2274 
2275  track = matroska_find_track_by_num(matroska, num);
2276  if (!track || !track->stream) {
2277  av_log(matroska->ctx, AV_LOG_INFO,
2278  "Invalid stream %"PRIu64" or size %u\n", num, size);
2279  return AVERROR_INVALIDDATA;
2280  } else if (size <= 3)
2281  return 0;
2282  st = track->stream;
2283  if (st->discard >= AVDISCARD_ALL)
2284  return res;
2285  av_assert1(block_duration != AV_NOPTS_VALUE);
2286 
2287  block_time = AV_RB16(data);
2288  data += 2;
2289  flags = *data++;
2290  size -= 3;
2291  if (is_keyframe == -1)
2292  is_keyframe = flags & 0x80 ? AV_PKT_FLAG_KEY : 0;
2293 
2294  if (cluster_time != (uint64_t)-1
2295  && (block_time >= 0 || cluster_time >= -block_time)) {
2296  timecode = cluster_time + block_time;
2297  if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE
2298  && timecode < track->end_timecode)
2299  is_keyframe = 0; /* overlapping subtitles are not key frame */
2300  if (is_keyframe)
2301  av_add_index_entry(st, cluster_pos, timecode, 0,0,AVINDEX_KEYFRAME);
2302  }
2303 
2304  if (matroska->skip_to_keyframe && track->type != MATROSKA_TRACK_TYPE_SUBTITLE) {
2305  if (timecode < matroska->skip_to_timecode)
2306  return res;
2307  if (!st->skip_to_keyframe) {
2308  av_log(matroska->ctx, AV_LOG_ERROR, "File is broken, keyframes not correctly marked!\n");
2309  matroska->skip_to_keyframe = 0;
2310  }
2311  if (is_keyframe)
2312  matroska->skip_to_keyframe = 0;
2313  }
2314 
2315  res = matroska_parse_laces(matroska, &data, &size, (flags & 0x06) >> 1,
2316  &lace_size, &laces);
2317 
2318  if (res)
2319  goto end;
2320 
2321  if (!block_duration)
2322  block_duration = track->default_duration * laces / matroska->time_scale;
2323 
2324  if (cluster_time != (uint64_t)-1 && (block_time >= 0 || cluster_time >= -block_time))
2325  track->end_timecode =
2326  FFMAX(track->end_timecode, timecode + block_duration);
2327 
2328  for (n = 0; n < laces; n++) {
2329  int64_t lace_duration = block_duration*(n+1) / laces - block_duration*n / laces;
2330 
2331  if (lace_size[n] > size) {
2332  av_log(matroska->ctx, AV_LOG_ERROR, "Invalid packet size\n");
2333  break;
2334  }
2335 
2336  if ((st->codec->codec_id == AV_CODEC_ID_RA_288 ||
2337  st->codec->codec_id == AV_CODEC_ID_COOK ||
2338  st->codec->codec_id == AV_CODEC_ID_SIPR ||
2339  st->codec->codec_id == AV_CODEC_ID_ATRAC3) &&
2340  st->codec->block_align && track->audio.sub_packet_size) {
2341 
2342  res = matroska_parse_rm_audio(matroska, track, st, data,
2343  lace_size[n],
2344  timecode, pos);
2345  if (res)
2346  goto end;
2347 
2348  } else {
2349  res = matroska_parse_frame(matroska, track, st, data, lace_size[n],
2350  timecode, lace_duration,
2351  pos, !n? is_keyframe : 0,
2352  additional, additional_id, additional_size);
2353  if (res)
2354  goto end;
2355  }
2356 
2357  if (timecode != AV_NOPTS_VALUE)
2358  timecode = lace_duration ? timecode + lace_duration : AV_NOPTS_VALUE;
2359  data += lace_size[n];
2360  size -= lace_size[n];
2361  }
2362 
2363 end:
2364  av_free(lace_size);
2365  return res;
2366 }
2367 
2369 {
2370  EbmlList *blocks_list;
2371  MatroskaBlock *blocks;
2372  int i, res;
2373  res = ebml_parse(matroska,
2374  matroska_cluster_incremental_parsing,
2375  &matroska->current_cluster);
2376  if (res == 1) {
2377  /* New Cluster */
2378  if (matroska->current_cluster_pos)
2379  ebml_level_end(matroska);
2380  ebml_free(matroska_cluster, &matroska->current_cluster);
2381  memset(&matroska->current_cluster, 0, sizeof(MatroskaCluster));
2382  matroska->current_cluster_num_blocks = 0;
2383  matroska->current_cluster_pos = avio_tell(matroska->ctx->pb);
2384  matroska->prev_pkt = NULL;
2385  /* sizeof the ID which was already read */
2386  if (matroska->current_id)
2387  matroska->current_cluster_pos -= 4;
2388  res = ebml_parse(matroska,
2389  matroska_clusters_incremental,
2390  &matroska->current_cluster);
2391  /* Try parsing the block again. */
2392  if (res == 1)
2393  res = ebml_parse(matroska,
2394  matroska_cluster_incremental_parsing,
2395  &matroska->current_cluster);
2396  }
2397 
2398  if (!res &&
2399  matroska->current_cluster_num_blocks <
2400  matroska->current_cluster.blocks.nb_elem) {
2401  blocks_list = &matroska->current_cluster.blocks;
2402  blocks = blocks_list->elem;
2403 
2404  matroska->current_cluster_num_blocks = blocks_list->nb_elem;
2405  i = blocks_list->nb_elem - 1;
2406  if (blocks[i].bin.size > 0 && blocks[i].bin.data) {
2407  int is_keyframe = blocks[i].non_simple ? !blocks[i].reference : -1;
2408  uint8_t* additional = blocks[i].additional.size > 0 ?
2409  blocks[i].additional.data : NULL;
2410  if (!blocks[i].non_simple)
2411  blocks[i].duration = 0;
2412  res = matroska_parse_block(matroska,
2413  blocks[i].bin.data, blocks[i].bin.size,
2414  blocks[i].bin.pos,
2415  matroska->current_cluster.timecode,
2416  blocks[i].duration, is_keyframe,
2417  additional, blocks[i].additional_id,
2418  blocks[i].additional.size,
2419  matroska->current_cluster_pos);
2420  }
2421  }
2422 
2423  if (res < 0) matroska->done = 1;
2424  return res;
2425 }
2426 
2428 {
2429  MatroskaCluster cluster = { 0 };
2430  EbmlList *blocks_list;
2431  MatroskaBlock *blocks;
2432  int i, res;
2433  int64_t pos;
2434  if (!matroska->contains_ssa)
2435  return matroska_parse_cluster_incremental(matroska);
2436  pos = avio_tell(matroska->ctx->pb);
2437  matroska->prev_pkt = NULL;
2438  if (matroska->current_id)
2439  pos -= 4; /* sizeof the ID which was already read */
2440  res = ebml_parse(matroska, matroska_clusters, &cluster);
2441  blocks_list = &cluster.blocks;
2442  blocks = blocks_list->elem;
2443  for (i=0; i<blocks_list->nb_elem; i++)
2444  if (blocks[i].bin.size > 0 && blocks[i].bin.data) {
2445  int is_keyframe = blocks[i].non_simple ? !blocks[i].reference : -1;
2446  res=matroska_parse_block(matroska,
2447  blocks[i].bin.data, blocks[i].bin.size,
2448  blocks[i].bin.pos, cluster.timecode,
2449  blocks[i].duration, is_keyframe, NULL, 0, 0,
2450  pos);
2451  }
2452  ebml_free(matroska_cluster, &cluster);
2453  return res;
2454 }
2455 
2457 {
2458  MatroskaDemuxContext *matroska = s->priv_data;
2459 
2460  while (matroska_deliver_packet(matroska, pkt)) {
2461  int64_t pos = avio_tell(matroska->ctx->pb);
2462  if (matroska->done)
2463  return AVERROR_EOF;
2464  if (matroska_parse_cluster(matroska) < 0)
2465  matroska_resync(matroska, pos);
2466  }
2467 
2468  return 0;
2469 }
2470 
2471 static int matroska_read_seek(AVFormatContext *s, int stream_index,
2472  int64_t timestamp, int flags)
2473 {
2474  MatroskaDemuxContext *matroska = s->priv_data;
2475  MatroskaTrack *tracks = matroska->tracks.elem;
2476  AVStream *st = s->streams[stream_index];
2477  int i, index, index_sub, index_min;
2478 
2479  /* Parse the CUES now since we need the index data to seek. */
2480  if (matroska->cues_parsing_deferred > 0) {
2481  matroska->cues_parsing_deferred = 0;
2482  matroska_parse_cues(matroska);
2483  }
2484 
2485  if (!st->nb_index_entries)
2486  goto err;
2487  timestamp = FFMAX(timestamp, st->index_entries[0].timestamp);
2488 
2489  if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) {
2490  avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET);
2491  matroska->current_id = 0;
2492  while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) {
2493  matroska_clear_queue(matroska);
2494  if (matroska_parse_cluster(matroska) < 0)
2495  break;
2496  }
2497  }
2498 
2499  matroska_clear_queue(matroska);
2500  if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->nb_index_entries - 1))
2501  goto err;
2502 
2503  index_min = index;
2504  for (i=0; i < matroska->tracks.nb_elem; i++) {
2505  tracks[i].audio.pkt_cnt = 0;
2506  tracks[i].audio.sub_packet_cnt = 0;
2507  tracks[i].audio.buf_timecode = AV_NOPTS_VALUE;
2508  tracks[i].end_timecode = 0;
2509  if (tracks[i].type == MATROSKA_TRACK_TYPE_SUBTITLE
2510  && tracks[i].stream->discard != AVDISCARD_ALL) {
2511  index_sub = av_index_search_timestamp(tracks[i].stream, st->index_entries[index].timestamp, AVSEEK_FLAG_BACKWARD);
2512  if (index_sub >= 0
2513  && st->index_entries[index_sub].pos < st->index_entries[index_min].pos
2514  && st->index_entries[index].timestamp - st->index_entries[index_sub].timestamp < 30000000000/matroska->time_scale)
2515  index_min = index_sub;
2516  }
2517  }
2518 
2519  avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET);
2520  matroska->current_id = 0;
2521  if (flags & AVSEEK_FLAG_ANY) {
2522  st->skip_to_keyframe = 0;
2523  matroska->skip_to_timecode = timestamp;
2524  } else {
2525  st->skip_to_keyframe = 1;
2526  matroska->skip_to_timecode = st->index_entries[index].timestamp;
2527  }
2528  matroska->skip_to_keyframe = 1;
2529  matroska->done = 0;
2530  matroska->num_levels = 0;
2531  ff_update_cur_dts(s, st, st->index_entries[index].timestamp);
2532  return 0;
2533 err:
2534  // slightly hackish but allows proper fallback to
2535  // the generic seeking code.
2536  matroska_clear_queue(matroska);
2537  matroska->current_id = 0;
2538  st->skip_to_keyframe =
2539  matroska->skip_to_keyframe = 0;
2540  matroska->done = 0;
2541  matroska->num_levels = 0;
2542  return -1;
2543 }
2544 
2546 {
2547  MatroskaDemuxContext *matroska = s->priv_data;
2548  MatroskaTrack *tracks = matroska->tracks.elem;
2549  int n;
2550 
2551  matroska_clear_queue(matroska);
2552 
2553  for (n=0; n < matroska->tracks.nb_elem; n++)
2554  if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO)
2555  av_free(tracks[n].audio.buf);
2556  ebml_free(matroska_cluster, &matroska->current_cluster);
2557  ebml_free(matroska_segment, matroska);
2558 
2559  return 0;
2560 }
2561 
2563  .name = "matroska,webm",
2564  .long_name = NULL_IF_CONFIG_SMALL("Matroska / WebM"),
2565  .priv_data_size = sizeof(MatroskaDemuxContext),
2571 };
const char * name
Definition: avisynth_c.h:675
const char * s
Definition: matroskadec.c:76
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:1743
Definition: start.py:1
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
static EbmlSyntax matroska_simpletag[]
Definition: matroskadec.c:492
#define MATROSKA_ID_BLOCKADDID
Definition: matroska.h:190
#define MATROSKA_ID_TRACKDEFAULTDURATION
Definition: matroska.h:102
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:367
static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, MatroskaTrack *track, AVStream *st, uint8_t *data, int size, uint64_t timecode, int64_t pos)
Definition: matroskadec.c:2077
static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, int idx)
Definition: matroskadec.c:1331
Bytestream IO Context.
Definition: avio.h:68
#define MATROSKA_ID_VIDEOFLAGINTERLACED
Definition: matroska.h:119
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
const char *const ff_matroska_video_stereo_plane[MATROSKA_VIDEO_STEREO_PLANE_COUNT]
Definition: matroska.c:138
static void matroska_convert_tags(AVFormatContext *s)
Definition: matroskadec.c:1297
#define MATROSKA_ID_DATEUTC
Definition: matroska.h:71
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:242
uint64_t type
Definition: matroskadec.c:157
#define MATROSKA_ID_TRACKFLAGLACING
Definition: matroska.h:99
#define MATROSKA_ID_TRACKENTRY
Definition: matroska.h:75
static int matroska_deliver_packet(MatroskaDemuxContext *matroska, AVPacket *pkt)
Definition: matroskadec.c:1928
#define MATROSKA_ID_VIDEODISPLAYHEIGHT
Definition: matroska.h:111
uint64_t version
Definition: matroskadec.c:93
static EbmlSyntax matroska_blockmore[]
Definition: matroskadec.c:550
AVInputFormat ff_matroska_demuxer
Definition: matroskadec.c:2562
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
#define MATROSKA_ID_CUETRACKPOSITION
Definition: matroska.h:154
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
#define MATROSKA_ID_CODECPRIVATE
Definition: matroska.h:89
const unsigned char ff_sipr_subpk_size[4]
Definition: rmsipr.c:25
#define MATROSKA_ID_TAGTARGETS_TYPE
Definition: matroska.h:170
static int ebml_level_end(MatroskaDemuxContext *matroska)
Definition: matroskadec.c:656
int64_t pos
byte position in stream, -1 if unknown
#define AV_RB64
static int matroska_ebmlnum_sint(MatroskaDemuxContext *matroska, uint8_t *data, uint32_t size, int64_t *num)
Definition: matroskadec.c:853
else temp
Definition: vf_mcdeint.c:148
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
int64_t pos
Definition: avformat.h:592
#define MATROSKA_ID_ENCODINGTYPE
Definition: matroska.h:135
#define MATROSKA_ID_AUDIOBITDEPTH
Definition: matroska.h:129
uint64_t chapteruid
Definition: matroskadec.c:217
#define AVSEEK_FLAG_ANY
seek to any frame, even non-keyframes
Definition: avformat.h:1745
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
Definition: intfloat.h:40
#define MATROSKA_ID_TRACKFLAGDEFAULT
Definition: matroska.h:97
uint64_t additional_id
Definition: matroskadec.c:291
EbmlList tag
Definition: matroskadec.c:223
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
uint64_t uid
Definition: matroskadec.c:156
static EbmlSyntax matroska_segments[]
Definition: matroskadec.c:545
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
MatroskaCluster current_cluster
Definition: matroskadec.c:280
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:709
#define MATROSKA_ID_TAGTARGETS_ATTACHUID
Definition: matroska.h:174
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:644
title('Sinusoid at 1/4 the Spampling Rate')
#define MATROSKA_ID_CLUSTERPOSITION
Definition: matroska.h:185
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:199
#define MATROSKA_ID_FILEDATA
Definition: matroska.h:204
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:822
#define EBML_ID_DOCTYPEREADVERSION
Definition: matroska.h:42
#define MATROSKA_ID_BLOCKREFERENCE
Definition: matroska.h:197
uint64_t flag_forced
Definition: matroskadec.c:165
uint64_t max_size
Definition: matroskadec.c:94
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
#define MATROSKA_ID_TRACKTYPE
Definition: matroska.h:80
#define MATROSKA_ID_TAGTARGETS_CHAPTERUID
Definition: matroska.h:173
uint64_t flag_default
Definition: matroskadec.c:164
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end w...
#define MATROSKA_ID_VIDEOASPECTRATIO
Definition: matroska.h:122
#define MATROSKA_ID_MUXINGAPP
Definition: matroska.h:70
#define MATROSKA_ID_AUDIOCHANNELS
Definition: matroska.h:130
char * name
Definition: matroskadec.c:206
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:256
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:141
#define FF_ARRAY_ELEMS(a)
int version
Definition: avisynth_c.h:666
MatroskaLevel levels[EBML_MAX_DEPTH]
Definition: matroskadec.c:246
static EbmlSyntax matroska_track_audio[]
Definition: matroskadec.c:341
#define MATROSKA_ID_CUECLUSTERPOSITION
Definition: matroska.h:158
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:595
MatroskaTrackAudio audio
Definition: matroskadec.c:167
uint64_t duration
Definition: matroskadec.c:287
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
const struct EbmlSyntax * n
Definition: matroskadec.c:77
#define MATROSKA_ID_EDITIONFLAGDEFAULT
Definition: matroska.h:217
#define MATROSKA_ID_CLUSTERTIMECODE
Definition: matroska.h:184
#define EBML_ID_DOCTYPE
Definition: matroska.h:40
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static EbmlSyntax matroska_tag[]
Definition: matroskadec.c:511
#define MATROSKA_ID_ENCODINGENCALGO
Definition: matroska.h:142
static EbmlSyntax matroska_attachment[]
Definition: matroskadec.c:428
#define MATROSKA_ID_CHAPTERTIMEEND
Definition: matroska.h:211
output residual component w
static EbmlSyntax matroska_track[]
Definition: matroskadec.c:395
#define MATROSKA_ID_TRACKCONTENTENCODINGS
Definition: matroska.h:103
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
#define AV_LZO_OUTPUT_FULL
decoded data did not fit into output buffer
Definition: lzo.h:39
AVChapter * avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
#define EBML_VERSION
Definition: matroska.h:30
#define MATROSKA_ID_FILEDESC
Definition: matroska.h:201
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
Format I/O context.
Definition: avformat.h:944
#define EBML_ID_CRC32
Definition: matroska.h:46
uint64_t def
Definition: matroskadec.c:209
#define AV_WB32(p, darg)
Definition: intreadwrite.h:265
void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp)
Update cur_dts of all streams based on the given timestamp and AVStream.
#define MATROSKA_ID_TRACKCONTENTENCODING
Definition: matroska.h:104
#define MATROSKA_ID_CODECDOWNLOADURL
Definition: matroska.h:92
int64_t end_timecode
Definition: matroskadec.c:172
static EbmlSyntax matroska_track_operation[]
Definition: matroskadec.c:390
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define AVFMT_FLAG_IGNIDX
Ignore index.
Definition: avformat.h:1023
Public dictionary API.
int ffio_limit(AVIOContext *s, int size)
uint64_t pixel_height
Definition: matroskadec.c:122
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:291
static av_always_inline double av_int2double(uint64_t i)
Reinterpret a 64-bit integer as a double.
Definition: intfloat.h:60
uint8_t
#define MATROSKA_ID_CHAPLANG
Definition: matroska.h:214
uint64_t stereo_mode
Definition: matroskadec.c:124
MatroskaTrackOperation operation
Definition: matroskadec.c:168
MatroskaTrackVideo video
Definition: matroskadec.c:166
#define MATROSKA_ID_EDITIONFLAGORDERED
Definition: matroska.h:218
void * elem
Definition: matroskadec.c:83
#define MATROSKA_ID_TRACKLANGUAGE
Definition: matroska.h:95
MatroskaTrackCompression compression
Definition: matroskadec.c:113
uint8_t * data
Definition: matroskadec.c:88
const AVCodecTag ff_codec_movvideo_tags[]
Definition: isom.c:68
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:610
uint64_t time
Definition: matroskadec.c:201
#define AV_RB32
static AVPacket pkt
Definition: demuxing.c:56
#define MATROSKA_ID_VIDEOPIXELCROPT
Definition: matroska.h:115
#define MATROSKA_ID_TIMECODESCALE
Definition: matroska.h:66
static int matroska_aac_sri(int samplerate)
Definition: matroskadec.c:1465
enum AVStreamParseType need_parsing
Definition: avformat.h:811
#define b
Definition: input.c:42
end end
#define MATROSKA_ID_SIMPLEBLOCK
Definition: matroska.h:192
#define MATROSKA_ID_TAGTARGETS_TYPEVALUE
Definition: matroska.h:171
#define MATROSKA_ID_EDITIONFLAGHIDDEN
Definition: matroska.h:216
#define AV_LZO_OUTPUT_PADDING
Definition: lzo.h:47
static EbmlSyntax matroska_cluster[]
Definition: matroskadec.c:571
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
#define MATROSKA_ID_CODECNAME
Definition: matroska.h:90
char * language
Definition: matroskadec.c:161
#define MATROSKA_ID_BLOCKMORE
Definition: matroska.h:189
AVStream ** streams
Definition: avformat.h:992
#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ
Definition: matroska.h:127
uint8_t * data
uint64_t typevalue
Definition: matroskadec.c:215
static int matroska_parse_cluster_incremental(MatroskaDemuxContext *matroska)
Definition: matroskadec.c:2368
#define MATROSKA_ID_VIDEODISPLAYWIDTH
Definition: matroska.h:110
#define MATROSKA_ID_EDITIONUID
Definition: matroska.h:215
#define MATROSKA_ID_BLOCKADDITIONS
Definition: matroska.h:188
uint32_t tag
Definition: movenc.c:894
static EbmlSyntax ebml_header[]
Definition: matroskadec.c:295
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define MATROSKA_ID_CODECDECODEALL
Definition: matroska.h:93
#define MATROSKA_ID_ENCODINGENCRYPTION
Definition: matroska.h:140
enum AVCodecID id
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
const uint8_t ff_log2_tab[256]
#define MATROSKA_ID_CUES
Definition: matroska.h:58
#define EBML_MAX_DEPTH
Definition: matroska.h:269
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:675
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#define MATROSKA_ID_TRACKNUMBER
Definition: matroska.h:78
static int64_t duration
Definition: ffplay.c:294
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:173
int duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
#define MATROSKA_ID_SEGMENTUID
Definition: matroska.h:72
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:478
static EbmlSyntax matroska_tracks[]
Definition: matroskadec.c:423
EbmlList sub
Definition: matroskadec.c:210
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int matroska_parse_cluster(MatroskaDemuxContext *matroska)
Definition: matroskadec.c:2427
static int ebml_parse_nest(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, void *data)
Definition: matroskadec.c:904
#define MATROSKA_ID_CUEBLOCKNUMBER
Definition: matroska.h:159
#define MATROSKA_ID_TRACKUID
Definition: matroska.h:79
Discrete Time axis x
uint64_t display_height
Definition: matroskadec.c:120
#define U(x)
static EbmlSyntax matroska_info[]
Definition: matroskadec.c:311
#define MATROSKA_ID_ENCODINGORDER
Definition: matroska.h:133
#define MATROSKA_ID_VIDEOSTEREOMODE
Definition: matroska.h:120
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:73
#define AVINDEX_KEYFRAME
Definition: avformat.h:599
static EbmlSyntax matroska_blockadditions[]
Definition: matroskadec.c:556
EbmlType type
Definition: matroskadec.c:70
AVCodecID
Identify the syntax and semantics of the bitstream.
AVDictionary * metadata
Definition: avformat.h:1092
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
#define MATROSKA_ID_BLOCKDURATION
Definition: matroska.h:196
#define EBML_ID_EBMLREADVERSION
Definition: matroska.h:37
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
#define AV_EF_EXPLODE
static int ebml_read_length(MatroskaDemuxContext *matroska, AVIOContext *pb, uint64_t *number)
Read a EBML length value.
Definition: matroskadec.c:725
#define AV_RB16
AVChapter * chapter
Definition: matroskadec.c:192
static EbmlSyntax matroska_index[]
Definition: matroskadec.c:487
int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
int64_t timestamp
Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are...
Definition: avformat.h:593
#define MATROSKA_ID_CLUSTER
Definition: matroska.h:62
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define MATROSKA_ID_FILEMIMETYPE
Definition: matroska.h:203
static int matroska_ebmlnum_uint(MatroskaDemuxContext *matroska, uint8_t *data, uint32_t size, uint64_t *num)
Definition: matroskadec.c:842
Spectrum Plot time data
const char * r
Definition: vf_curves.c:94
int64_t convergence_duration
Time difference in AVStream->time_base units from the pts of this packet to the point at which the ou...
uint64_t display_width
Definition: matroskadec.c:119
#define MATROSKA_ID_WRITINGAPP
Definition: matroska.h:69
EbmlBin additional
Definition: matroskadec.c:292
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
#define MATROSKA_ID_TAGDEFAULT_BUG
Definition: matroska.h:168
static EbmlSyntax matroska_clusters[]
Definition: matroskadec.c:580
static EbmlSyntax matroska_chapter[]
Definition: matroskadec.c:460
enum AVCodecID id
Definition: matroska.h:265
#define MATROSKA_ID_VIDEOPIXELCROPR
Definition: matroska.h:117
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define MATROSKA_ID_TRACKPLANEUID
Definition: matroska.h:86
#define MATROSKA_ID_ENCODINGCOMPSETTINGS
Definition: matroska.h:138
#define EBML_ID_EBMLMAXIDLENGTH
Definition: matroska.h:38
#define MATROSKA_ID_CHAPTERFLAGHIDDEN
Definition: matroska.h:220
enum AVCodecID codec_id
Definition: mov_chan.c:433
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:716
uint64_t timecode
Definition: matroskadec.c:237
#define CONFIG_ZLIB
Definition: config.h:351
#define FFMAX(a, b)
Definition: common.h:56
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:82
int size
static EbmlSyntax matroska_attachments[]
Definition: matroskadec.c:437
int flags
A combination of AV_PKT_FLAG values.
static EbmlSyntax matroska_cluster_incremental_parsing[]
Definition: matroskadec.c:589
Only parse headers, do not repack.
Definition: avformat.h:583
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:469
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
static void ebml_free(EbmlSyntax *syntax, void *data)
Definition: matroskadec.c:997
const CodecMime ff_mkv_mime_tags[]
Definition: matroska.c:101
int nb_elem
Definition: matroskadec.c:82
#define MATROSKA_ID_TAG
Definition: matroska.h:162
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:36
int buf_size
Size of buf except extra allocated bytes.
Definition: avformat.h:337
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:336
char * lang
Definition: matroskadec.c:208
#define AV_DISPOSITION_FORCED
Track should be used during playback by default.
Definition: avformat.h:617
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static EbmlSyntax matroska_chapters[]
Definition: matroskadec.c:469
#define MATROSKA_ID_ENCODINGSIGHASHALGO
Definition: matroska.h:145
uint64_t skip_to_timecode
Definition: matroskadec.c:273
Definition: dct-test.c:68
static int matroska_read_header(AVFormatContext *s)
Definition: matroskadec.c:1486
static void matroska_parse_cues(MatroskaDemuxContext *matroska)
Definition: matroskadec.c:1439
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:117
int bit_rate
the average bitrate
static void matroska_execute_seekhead(MatroskaDemuxContext *matroska)
Definition: matroskadec.c:1382
#define dynarray_add(tab, nb_ptr, elem)
uint64_t start
Definition: matroskadec.c:187
#define EBML_ID_EBMLVERSION
Definition: matroska.h:36
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
Definition: base64.h:61
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:196
#define FFMIN(a, b)
Definition: common.h:58
#define MATROSKA_ID_TAGTARGETS
Definition: matroska.h:169
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:35
union EbmlSyntax::@144 def
AVPacket ** packets
Definition: matroskadec.c:265
#define MATROSKA_VIDEO_STEREO_PLANE_COUNT
Definition: matroska.h:272
#define MATROSKA_ID_TAGNAME
Definition: matroska.h:164
#define MATROSKA_ID_TRACKTIMECODESCALE
Definition: matroska.h:105
static int read_probe(AVProbeData *pd)
static int ebml_parse_elem(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, void *data)
Definition: matroskadec.c:929
static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb, int max_size, uint64_t *number)
Definition: matroskadec.c:679
ret
Definition: avfilter.c:821
int width
picture width / height.
const char *const ff_matroska_video_stereo_mode[MATROSKA_VIDEO_STEREO_MODE_COUNT]
Definition: matroska.c:120
#define MATROSKA_ID_CHAPTERFLAGENABLED
Definition: matroska.h:221
uint64_t id_length
Definition: matroskadec.c:95
static EbmlSyntax matroska_track_encodings[]
Definition: matroskadec.c:374
static MatroskaTrack * matroska_find_track_by_num(MatroskaDemuxContext *matroska, int num)
Definition: matroskadec.c:1066
#define MATROSKA_ID_SIMPLETAG
Definition: matroska.h:163
uint64_t doctype_version
Definition: matroskadec.c:97
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
static EbmlSyntax matroska_track_encoding[]
Definition: matroskadec.c:365
#define MATROSKA_ID_TRACKMAXCACHE
Definition: matroska.h:101
int data_offset
Definition: matroskadec.c:72
#define MATROSKA_ID_CHAPTERPHYSEQUIV
Definition: matroska.h:222
static int matroska_read_close(AVFormatContext *s)
Definition: matroskadec.c:2545
EbmlBin codec_priv
Definition: matroskadec.c:160
static int ebml_read_ascii(AVIOContext *pb, int size, char **str)
Definition: matroskadec.c:775
static int matroska_decode_buffer(uint8_t **buf, int *buf_size, MatroskaTrack *track)
Definition: matroskadec.c:1080
#define MATROSKA_ID_CHAPTERATOM
Definition: matroska.h:209
#define AV_RL32
int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen)
Decodes LZO 1x compressed data.
Definition: lzo.c:126
AVDictionary * metadata
Definition: avformat.h:711
Opaque data information usually sparse.
Definition: avutil.h:147
#define MATROSKA_ID_VIDEOCOLORSPACE
Definition: matroska.h:123
static EbmlSyntax matroska_segment[]
Definition: matroskadec.c:533
#define MATROSKA_ID_CHAPTERS
Definition: matroska.h:63
static int matroska_probe(AVProbeData *p)
Definition: matroskadec.c:1024
FIXME Range Coding of cr are level
Definition: snow.txt:367
#define EBML_ID_VOID
Definition: matroska.h:45
static void matroska_convert_tag(AVFormatContext *s, EbmlList *list, AVDictionary **metadata, char *prefix)
Definition: matroskadec.c:1265
uint64_t max_block_additional_id
Definition: matroskadec.c:174
int url_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:280
#define MATROSKA_ID_AUDIOSAMPLINGFREQ
Definition: matroska.h:126
double f
Definition: matroskadec.c:75
#define MATROSKA_ID_TRACKMINCACHE
Definition: matroska.h:100
static void matroska_metadata_creation_time(AVDictionary **metadata, int64_t date_utc)
Definition: matroskadec.c:1475
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
static int matroska_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: matroskadec.c:2471
static EbmlSyntax matroska_seekhead[]
Definition: matroskadec.c:528
Stream structure.
Definition: avformat.h:643
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define MATROSKA_ID_TRACKPLANETYPE
Definition: matroska.h:87
for k
NULL
Definition: eval.c:55
EbmlList encodings
Definition: matroskadec.c:169
char * codec_id
Definition: matroskadec.c:159
#define AV_DISPOSITION_DEFAULT
Definition: avformat.h:605
static int width
Definition: tests/utils.c:158
int64_t current_cluster_pos
Definition: matroskadec.c:279
#define MATROSKA_ID_VIDEOPIXELCROPB
Definition: matroska.h:114
#define MATROSKA_ID_TRACKFLAGFORCED
Definition: matroska.h:98
#define MATROSKA_ID_TAGS
Definition: matroska.h:59
enum AVMediaType codec_type
static EbmlSyntax matroska_track_plane[]
Definition: matroskadec.c:379
static int ebml_read_master(MatroskaDemuxContext *matroska, uint64_t length)
Definition: matroskadec.c:820
enum AVCodecID codec_id
#define MATROSKA_ID_TAGDEFAULT
Definition: matroska.h:167
#define MATROSKA_ID_SEEKID
Definition: matroska.h:180
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:220
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
#define MATROSKA_ID_ENCODINGCOMPALGO
Definition: matroska.h:137
#define MATROSKA_ID_BLOCK
Definition: matroska.h:195
#define MATROSKA_ID_INFO
Definition: matroska.h:56
#define MATROSKA_ID_TAGTARGETS_TRACKUID
Definition: matroska.h:172
uint8_t * data
The data buffer.
Definition: buffer.h:89
#define MATROSKA_ID_TAGLANG
Definition: matroska.h:166
static EbmlSyntax matroska_tags[]
Definition: matroskadec.c:517
uint64_t pixel_width
Definition: matroskadec.c:121
#define MATROSKA_ID_TRACKCOMBINEPLANES
Definition: matroska.h:84
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
#define MATROSKA_ID_TRACKFLAGENABLED
Definition: matroska.h:96
#define MATROSKA_ID_TRACKS
Definition: matroska.h:57
void * buf
Definition: avisynth_c.h:594
#define MATROSKA_ID_TRACKPLANE
Definition: matroska.h:85
Data found in BlockAdditional element of matroska container.
#define MATROSKA_ID_TRACKNAME
Definition: matroska.h:94
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
uint64_t start
Definition: matroskadec.c:232
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:62
static EbmlSyntax matroska_cluster_incremental[]
Definition: matroskadec.c:603
int nb_index_entries
Definition: avformat.h:824
#define MATROSKA_ID_SEEKENTRY
Definition: matroska.h:177
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
EbmlList pos
Definition: matroskadec.c:202
uint64_t u
Definition: matroskadec.c:74
#define MATROSKA_ID_EDITIONENTRY
Definition: matroska.h:208
int index
Definition: gxfenc.c:89
#define MATROSKA_ID_BLOCKGROUP
Definition: matroska.h:187
#define MATROSKA_ID_VIDEOPIXELHEIGHT
Definition: matroska.h:113
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
AVStream * stream
Definition: matroskadec.c:171
static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, int *buf_size, int type, uint32_t **lace_buf, int *laces)
Definition: matroskadec.c:1970
#define MATROSKA_ID_CUETIME
Definition: matroska.h:153
#define MATROSKA_ID_ENCODINGSIGALGO
Definition: matroska.h:144
static int matroska_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: matroskadec.c:2456
static EbmlSyntax matroska_blockgroup[]
Definition: matroskadec.c:561
static EbmlSyntax matroska_track_encoding_encryption[]
Definition: matroskadec.c:355
static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, void *data)
Definition: matroskadec.c:891
#define MATROSKA_ID_ENCODINGSIGKEYID
Definition: matroska.h:146
#define MATROSKA_ID_TITLE
Definition: matroska.h:68
#define snprintf
Definition: snprintf.h:34
AVFormatContext * ctx
Definition: matroskadec.c:242
#define MATROSKA_ID_TRACKVIDEO
Definition: matroska.h:81
static EbmlSyntax matroska_track_combine_planes[]
Definition: matroskadec.c:385
int size
Definition: matroskadec.c:87
int error
contains the error code or 0 if no error happened
Definition: avio.h:102
This structure contains the data a format has to probe a file.
Definition: avformat.h:334
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, uint32_t id, void *data)
Definition: matroskadec.c:872
int list_elem_size
Definition: matroskadec.c:71
static EbmlSyntax ebml_syntax[]
Definition: matroskadec.c:306
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
Definition: avstring.c:92
#define MATROSKA_ID_VIDEOFRAMERATE
Definition: matroska.h:109
#define AV_WB64(p, darg)
Definition: intreadwrite.h:303
#define MATROSKA_ID_ATTACHMENTS
Definition: matroska.h:61
#define MATROSKA_ID_TRACKOPERATION
Definition: matroska.h:83
int64_t pos
Definition: matroskadec.c:89
track
Definition: brsc.py:18
#define MATROSKA_ID_CHAPTERDISPLAY
Definition: matroska.h:212
static int flags
Definition: cpu.c:23
#define MATROSKA_ID_FILENAME
Definition: matroska.h:202
#define MATROSKA_ID_BLOCKADDITIONAL
Definition: matroska.h:191
const int avpriv_mpeg4audio_sample_rates[16]
Definition: mpeg4audio.c:57
const AVMetadataConv ff_mkv_metadata_conv[]
Definition: matroska.c:114
#define CONFIG_LZO
Definition: config.h:380
#define MATROSKA_ID_CODECID
Definition: matroska.h:88
static EbmlSyntax matroska_clusters_incremental[]
Definition: matroskadec.c:612
#define MATROSKA_ID_VIDEOALPHAMODE
Definition: matroska.h:121
#define AVPROBE_SCORE_MAX
maximum score, half of that is used for file-extension-based detection
Definition: avformat.h:340
A reference to a data buffer.
Definition: buffer.h:81
int64_t reference
Definition: matroskadec.c:288
void ff_rm_reorder_sipr_data(uint8_t *buf, int sub_packet_h, int framesize)
Perform 4-bit block reordering for SIPR data.
Definition: rmsipr.c:41
Main libavformat public API header.
uint64_t buf_timecode
Definition: matroskadec.c:141
#define MATROSKA_ID_ENCODINGENCAESSETTINGS
Definition: matroska.h:141
uint64_t num
Definition: matroskadec.c:155
const struct EbmlSyntax EbmlSyntax
#define MATROSKA_ID_CUETRACK
Definition: matroska.h:157
static EbmlSyntax matroska_track_encoding_compression[]
Definition: matroskadec.c:349
EbmlType
Definition: matroskadec.c:55
#define MATROSKA_ID_SEEKPOSITION
Definition: matroska.h:181
static int matroska_resync(MatroskaDemuxContext *matroska, int64_t last_pos)
Definition: matroskadec.c:623
#define MATROSKA_ID_CHAPTERTIMESTART
Definition: matroska.h:210
double time_scale
Definition: matroskadec.c:162
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:71
char * string
Definition: matroskadec.c:207
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:689
int error_recognition
Error recognition; higher values will detect more errors but may misdetect some more or less valid pa...
Definition: avformat.h:1114
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:700
char * doctype
Definition: matroskadec.c:96
the buffer and buffer reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFilterBuffer structures They must not be accessed but through references stored in AVFilterBufferRef structures Several references can point to the same buffer
static EbmlSyntax matroska_seekhead_entry[]
Definition: matroskadec.c:522
int av_grow_packet(AVPacket *pkt, int grow_by)
Increase packet size, correctly zeroing padding.
Definition: avpacket.c:105
int den
denominator
Definition: rational.h:45
function y
Definition: D.m:1
#define MATROSKA_ID_ENCODINGSIGNATURE
Definition: matroska.h:147
#define MATROSKA_ID_SEGMENT
Definition: matroska.h:53
uint32_t id
Definition: matroskadec.c:69
static EbmlSyntax matroska_tagtargets[]
Definition: matroskadec.c:502
MatroskaTagTarget target
Definition: matroskadec.c:222
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
#define MKBETAG(a, b, c, d)
Definition: common.h:283
#define MATROSKA_ID_SEEKHEAD
Definition: matroska.h:60
ASS as defined in Matroska.
#define EBML_ID_HEADER
Definition: matroska.h:33
int skip_to_keyframe
Indicates that everything up to the next keyframe should be discarded.
Definition: avformat.h:839
#define MATROSKA_ID_ENCODINGCOMPRESSION
Definition: matroska.h:136
#define MATROSKA_ID_CLUSTERPREVSIZE
Definition: matroska.h:186
A Quick Description Of Rate Distortion Theory We want to encode a video
#define MATROSKA_ID_POINTENTRY
Definition: matroska.h:150
int len
int channels
number of audio channels
#define MATROSKA_VIDEO_STEREO_MODE_COUNT
Definition: matroska.h:271
#define MATROSKA_ID_FILEUID
Definition: matroska.h:205
#define MATROSKA_ID_VIDEOPIXELCROPL
Definition: matroska.h:116
void * priv_data
Format private data.
Definition: avformat.h:964
uint64_t non_simple
Definition: matroskadec.c:289
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip please avoid problems through this extra level of scrutiny For cosmetics only commits you should e g by running git config global user name My Name git config global user email my email which is either set in your personal configuration file through git config core editor or set by one of the following environment VISUAL or EDITOR Log messages should be concise but descriptive Explain why you made a what you did will be obvious from the changes themselves most of the time Saying just bug fix or is bad Remember that people of varying skill levels look at and educate themselves while reading through your code Don t include filenames in log Git provides that information Possibly make the commit message have a descriptive first line
Definition: git-howto.txt:153
#define MATROSKA_ID_CHAPTERUID
Definition: matroska.h:219
static EbmlSyntax matroska_index_entry[]
Definition: matroskadec.c:481
static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin)
Definition: matroskadec.c:798
#define MATROSKA_ID_VIDEODISPLAYUNIT
Definition: matroska.h:118
static int ebml_read_uint(AVIOContext *pb, int size, uint64_t *num)
Definition: matroskadec.c:738
#define MATROSKA_ID_TRACKMAXBLKADDID
Definition: matroska.h:106
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
#define EBML_ID_EBMLMAXSIZELENGTH
Definition: matroska.h:39
int64_t duration
Decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1009
MatroskaTrackEncryption encryption
Definition: matroskadec.c:114
#define MATROSKA_ID_CHAPSTRING
Definition: matroska.h:213
#define AV_LOG_INFO
Definition: log.h:156
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
#define MATROSKA_ID_TAGSTRING
Definition: matroska.h:165
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
static int matroska_parse_frame(MatroskaDemuxContext *matroska, MatroskaTrack *track, AVStream *st, uint8_t *data, int pkt_size, uint64_t timecode, uint64_t lace_duration, int64_t pos, int is_keyframe, uint8_t *additional, uint64_t additional_id, int additional_size)
Definition: matroskadec.c:2146
static EbmlSyntax matroska_index_pos[]
Definition: matroskadec.c:474
const char int length
Definition: avisynth_c.h:668
static int ebml_read_float(AVIOContext *pb, int size, double *num)
Definition: matroskadec.c:757
#define MATROSKA_ID_DURATION
Definition: matroska.h:67
uint64_t length
Definition: matroskadec.c:233
static int matroska_aac_profile(char *codec_id)
Definition: matroskadec.c:1454
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
Definition: avpacket.c:264
#define EBML_ID_DOCTYPEVERSION
Definition: matroska.h:41
static void matroska_clear_queue(MatroskaDemuxContext *matroska)
Definition: matroskadec.c:1956
static EbmlSyntax matroska_chapter_entry[]
Definition: matroskadec.c:448
uint8_t bitdepth
Definition: dirac.c:81
#define CONFIG_BZLIB
Definition: config.h:300
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:702
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:738
#define MATROSKA_ID_ATTACHEDFILE
Definition: matroska.h:200
EbmlList blocks
Definition: matroskadec.c:238
This structure stores compressed data.
static EbmlSyntax matroska_chapter_display[]
Definition: matroskadec.c:442
uint64_t default_duration
Definition: matroskadec.c:163
static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, int64_t pos, uint64_t cluster_time, uint64_t block_duration, int is_keyframe, uint8_t *additional, uint64_t additional_id, int additional_size, int64_t cluster_pos)
Definition: matroskadec.c:2253
#define MATROSKA_ID_CODECINFOURL
Definition: matroska.h:91
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define MATROSKA_ID_VIDEOPIXELWIDTH
Definition: matroska.h:112
static void matroska_add_index_entries(MatroskaDemuxContext *matroska)
Definition: matroskadec.c:1412
#define MATROSKA_ID_TRACKAUDIO
Definition: matroska.h:82
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:190
#define av_unused
Definition: attributes.h:114
#define MATROSKA_ID_ENCODINGSCOPE
Definition: matroska.h:134
const CodecTags ff_mkv_codec_tags[]
Definition: matroska.c:27
#define MATROSKA_ID_ENCODINGENCKEYID
Definition: matroska.h:143
static const char *const matroska_doctypes[]
Definition: matroskadec.c:621
static EbmlSyntax matroska_track_video[]
Definition: matroskadec.c:322
uint64_t attachuid
Definition: matroskadec.c:218