8 #ifndef MKVPARSER_MKVPARSER_H_ 9 #define MKVPARSER_MKVPARSER_H_ 15 const int E_PARSE_FAILED = -1;
16 const int E_FILE_FORMAT_INVALID = -2;
17 const int E_BUFFER_NOT_FULL = -3;
21 virtual int Read(
long long pos,
long len,
unsigned char* buf) = 0;
22 virtual int Length(
long long* total,
long long* available) = 0;
28 template <
typename Type>
29 Type* SafeArrayAlloc(
unsigned long long num_elements,
30 unsigned long long element_size);
31 long long GetUIntLength(
IMkvReader*,
long long,
long&);
32 long long ReadUInt(
IMkvReader*,
long long,
long&);
33 long long ReadID(
IMkvReader* pReader,
long long pos,
long& len);
34 long long UnserializeUInt(
IMkvReader*,
long long pos,
long long size);
36 long UnserializeFloat(
IMkvReader*,
long long pos,
long long size,
double&);
37 long UnserializeInt(
IMkvReader*,
long long pos,
long long size,
40 long UnserializeString(
IMkvReader*,
long long pos,
long long size,
char*& str);
45 long long&
id,
long long& size);
47 bool Match(
IMkvReader*,
long long&,
unsigned long,
long long&);
48 bool Match(
IMkvReader*,
long long&,
unsigned long,
unsigned char*&,
size_t&);
50 void GetVersion(
int& major,
int& minor,
int& build,
int& revision);
56 long long m_readVersion;
57 long long m_maxIdLength;
58 long long m_maxSizeLength;
60 long long m_docTypeVersion;
61 long long m_docTypeReadVersion;
76 const long long m_start;
77 const long long m_size;
79 Block(
long long start,
long long size,
long long discard_padding);
84 long long GetTrackNumber()
const;
85 long long GetTimeCode(
const Cluster*)
const;
86 long long GetTime(
const Cluster*)
const;
89 bool IsInvisible()
const;
91 enum Lacing { kLacingNone, kLacingXiph, kLacingFixed, kLacingEbml };
92 Lacing GetLacing()
const;
94 int GetFrameCount()
const;
103 const Frame& GetFrame(
int frame_index)
const;
105 long long GetDiscardPadding()
const;
110 unsigned char m_flags;
116 const long long m_discard_padding;
129 bool EOS()
const {
return (GetKind() == kBlockEOS); }
130 const Cluster* GetCluster()
const;
131 long GetIndex()
const;
132 virtual const Block* GetBlock()
const = 0;
134 enum Kind { kBlockEOS, kBlockSimple, kBlockGroup };
135 virtual Kind GetKind()
const = 0;
150 Kind GetKind()
const;
151 const Block* GetBlock()
const;
163 long long block_start,
164 long long block_size,
165 long long prev,
long long next,
long long duration,
166 long long discard_padding);
170 Kind GetKind()
const;
171 const Block* GetBlock()
const;
173 long long GetPrevTimeCode()
const;
174 long long GetNextTimeCode()
const;
175 long long GetDurationTimeCode()
const;
179 const long long m_prev;
180 const long long m_next;
181 const long long m_duration;
200 unsigned long long algo;
201 unsigned char* settings;
202 long long settings_len;
210 unsigned long long cipher_mode;
218 unsigned long long algo;
219 unsigned char* key_id;
220 long long key_id_len;
221 unsigned char* signature;
222 long long signature_len;
223 unsigned char* sig_key_id;
224 long long sig_key_id_len;
225 unsigned long long sig_algo;
226 unsigned long long sig_hash_algo;
237 unsigned long GetCompressionCount()
const;
243 long ParseCompressionEntry(
long long start,
long long size,
253 unsigned long GetEncryptionCount()
const;
259 long ParseContentEncAESSettingsEntry(
long long start,
long long size,
266 long ParseContentEncodingEntry(
long long start,
long long size,
273 long ParseEncryptionEntry(
long long start,
long long size,
276 unsigned long long encoding_order()
const {
return encoding_order_; }
277 unsigned long long encoding_scope()
const {
return encoding_scope_; }
278 unsigned long long encoding_type()
const {
return encoding_type_; }
290 unsigned long long encoding_order_;
291 unsigned long long encoding_scope_;
292 unsigned long long encoding_type_;
305 static long Create(
Segment*,
const Info&,
long long element_start,
306 long long element_size,
Track*&);
308 enum Type { kVideo = 1, kAudio = 2, kSubtitle = 0x11, kMetadata = 0x21 };
311 const long long m_element_start;
312 const long long m_element_size;
315 long GetType()
const;
316 long GetNumber()
const;
317 unsigned long long GetUid()
const;
318 const char* GetNameAsUTF8()
const;
319 const char* GetLanguage()
const;
320 const char* GetCodecNameAsUTF8()
const;
321 const char* GetCodecId()
const;
322 const unsigned char* GetCodecPrivate(
size_t&)
const;
323 bool GetLacing()
const;
324 unsigned long long GetDefaultDuration()
const;
325 unsigned long long GetCodecDelay()
const;
326 unsigned long long GetSeekPreRoll()
const;
339 int Copy(
Info&)
const;
343 unsigned long long uid;
344 unsigned long long defaultDuration;
345 unsigned long long codecDelay;
346 unsigned long long seekPreRoll;
350 char* codecNameAsUTF8;
351 unsigned char* codecPrivate;
352 size_t codecPrivateSize;
359 int CopyStr(
char*
Info::*str,
Info&)
const;
364 virtual bool VetEntry(
const BlockEntry*)
const;
365 virtual long Seek(
long long time_ns,
const BlockEntry*&)
const;
367 const ContentEncoding* GetContentEncodingByIndex(
unsigned long idx)
const;
368 unsigned long GetContentEncodingCount()
const;
370 long ParseContentEncodingsEntry(
long long start,
long long size);
373 Track(
Segment*,
long long element_start,
long long element_size);
381 Kind GetKind()
const;
382 const Block* GetBlock()
const;
395 static bool Parse(
IMkvReader* reader,
long long read_pos,
396 long long value_size,
bool is_x,
403 static const float kValueNotPresent;
410 luminance_max(kValueNotPresent),
411 luminance_min(kValueNotPresent) {}
419 static bool Parse(
IMkvReader* reader,
long long element_start,
420 long long element_size,
432 static const long long kValueNotPresent;
437 : matrix_coefficients(kValueNotPresent),
438 bits_per_channel(kValueNotPresent),
439 chroma_subsampling_horz(kValueNotPresent),
440 chroma_subsampling_vert(kValueNotPresent),
441 cb_subsampling_horz(kValueNotPresent),
442 cb_subsampling_vert(kValueNotPresent),
443 chroma_siting_horz(kValueNotPresent),
444 chroma_siting_vert(kValueNotPresent),
445 range(kValueNotPresent),
446 transfer_characteristics(kValueNotPresent),
447 primaries(kValueNotPresent),
448 max_cll(kValueNotPresent),
449 max_fall(kValueNotPresent),
450 mastering_metadata(NULL) {}
452 delete mastering_metadata;
453 mastering_metadata = NULL;
456 static bool Parse(
IMkvReader* reader,
long long element_start,
457 long long element_size,
Colour** colour);
459 long long matrix_coefficients;
460 long long bits_per_channel;
461 long long chroma_subsampling_horz;
462 long long chroma_subsampling_vert;
463 long long cb_subsampling_horz;
464 long long cb_subsampling_vert;
465 long long chroma_siting_horz;
466 long long chroma_siting_vert;
468 long long transfer_characteristics;
477 enum ProjectionType {
478 kTypeNotPresent = -1,
480 kEquirectangular = 1,
484 static const float kValueNotPresent;
486 : type(kTypeNotPresent),
488 private_data_length(0),
489 pose_yaw(kValueNotPresent),
490 pose_pitch(kValueNotPresent),
491 pose_roll(kValueNotPresent) {}
493 static bool Parse(
IMkvReader* reader,
long long element_start,
494 long long element_size,
Projection** projection);
497 unsigned char* private_data;
498 size_t private_data_length;
512 static long Parse(
Segment*,
const Info&,
long long element_start,
515 long long GetWidth()
const;
516 long long GetHeight()
const;
517 long long GetDisplayWidth()
const;
518 long long GetDisplayHeight()
const;
519 long long GetDisplayUnit()
const;
520 long long GetStereoMode()
const;
521 double GetFrameRate()
const;
524 long Seek(
long long time_ns,
const BlockEntry*&)
const;
526 Colour* GetColour()
const;
530 const char* GetColourSpace()
const {
return m_colour_space; }
535 long long m_display_width;
536 long long m_display_height;
537 long long m_display_unit;
538 long long m_stereo_mode;
539 char* m_colour_space;
553 static long Parse(
Segment*,
const Info&,
long long element_start,
556 double GetSamplingRate()
const;
557 long long GetChannels()
const;
558 long long GetBitDepth()
const;
562 long long m_channels;
563 long long m_bitDepth;
572 const long long m_start;
573 const long long m_size;
574 const long long m_element_start;
575 const long long m_element_size;
577 Tracks(
Segment*,
long long start,
long long size,
long long element_start,
578 long long element_size);
584 unsigned long GetTracksCount()
const;
586 const Track* GetTrackByNumber(
long tn)
const;
587 const Track* GetTrackByIndex(
unsigned long idx)
const;
590 Track** m_trackEntries;
591 Track** m_trackEntriesEnd;
593 long ParseTrackEntry(
long long payload_start,
long long payload_size,
594 long long element_start,
long long element_size,
604 const long long m_start;
605 const long long m_size;
606 const long long m_element_start;
607 const long long m_element_size;
610 long long element_start,
long long element_size);
627 const char* GetString()
const;
628 const char* GetLanguage()
const;
629 const char* GetCountry()
const;
633 void ShallowCopy(
Display&)
const;
635 long Parse(
IMkvReader*,
long long pos,
long long size);
650 unsigned long long GetUID()
const;
651 const char* GetStringUID()
const;
653 long long GetStartTimecode()
const;
654 long long GetStopTimecode()
const;
656 long long GetStartTime(
const Chapters*)
const;
657 long long GetStopTime(
const Chapters*)
const;
659 int GetDisplayCount()
const;
660 const Display* GetDisplay(
int index)
const;
664 void ShallowCopy(
Atom&)
const;
666 long Parse(
IMkvReader*,
long long pos,
long long size);
667 static long long GetTime(
const Chapters*,
long long timecode);
669 long ParseDisplay(
IMkvReader*,
long long pos,
long long size);
670 bool ExpandDisplaysArray();
673 unsigned long long m_uid;
674 long long m_start_timecode;
675 long long m_stop_timecode;
679 int m_displays_count;
690 int GetAtomCount()
const;
691 const Atom* GetAtom(
int index)
const;
695 void ShallowCopy(
Edition&)
const;
697 long Parse(
IMkvReader*,
long long pos,
long long size);
699 long ParseAtom(
IMkvReader*,
long long pos,
long long size);
700 bool ExpandAtomsArray();
707 int GetEditionCount()
const;
708 const Edition* GetEdition(
int index)
const;
711 long ParseEdition(
long long pos,
long long size);
712 bool ExpandEditionsArray();
716 int m_editions_count;
725 const long long m_start;
726 const long long m_size;
727 const long long m_element_start;
728 const long long m_element_size;
730 Tags(
Segment*,
long long payload_start,
long long payload_size,
731 long long element_start,
long long element_size);
748 const char* GetTagName()
const;
749 const char* GetTagString()
const;
755 long Parse(
IMkvReader*,
long long pos,
long long size);
766 Tag& operator=(
const Tag&);
769 int GetSimpleTagCount()
const;
770 const SimpleTag* GetSimpleTag(
int index)
const;
774 void ShallowCopy(
Tag&)
const;
776 long Parse(
IMkvReader*,
long long pos,
long long size);
778 long ParseSimpleTag(
IMkvReader*,
long long pos,
long long size);
779 bool ExpandSimpleTagsArray();
782 int m_simple_tags_size;
783 int m_simple_tags_count;
786 int GetTagCount()
const;
787 const Tag* GetTag(
int index)
const;
790 long ParseTag(
long long pos,
long long size);
791 bool ExpandTagsArray();
804 const long long m_start;
805 const long long m_size;
806 const long long m_element_start;
807 const long long m_element_size;
810 long long element_start,
long long element_size);
816 long long GetTimeCodeScale()
const;
817 long long GetDuration()
const;
818 const char* GetMuxingAppAsUTF8()
const;
819 const char* GetWritingAppAsUTF8()
const;
820 const char* GetTitleAsUTF8()
const;
823 long long m_timecodeScale;
825 char* m_pMuxingAppAsUTF8;
826 char* m_pWritingAppAsUTF8;
827 char* m_pTitleAsUTF8;
836 const long long m_start;
837 const long long m_size;
838 const long long m_element_start;
839 const long long m_element_size;
841 SeekHead(
Segment*,
long long start,
long long size,
long long element_start,
842 long long element_size);
856 long long element_start;
859 long long element_size;
862 int GetCount()
const;
863 const Entry* GetEntry(
int idx)
const;
867 long long element_start;
870 long long element_size;
873 int GetVoidElementCount()
const;
881 int m_void_element_count;
885 long long size,
Entry*);
899 long long m_element_start;
900 long long m_element_size;
904 long long GetTimeCode()
const;
905 long long GetTime(
const Segment*)
const;
915 bool Parse(
IMkvReader*,
long long,
long long);
922 long long m_timecode;
924 size_t m_track_positions_count;
930 Cues(
Segment*,
long long start,
long long size,
long long element_start,
931 long long element_size);
939 const long long m_start;
940 const long long m_size;
941 const long long m_element_start;
942 const long long m_element_size;
955 bool LoadCuePoint()
const;
956 long GetCount()
const;
958 bool DoneParsing()
const;
962 bool PreloadCuePoint(
long&,
long long)
const;
965 mutable long m_count;
966 mutable long m_preload_count;
967 mutable long long m_pos;
990 long long GetTimeCode()
const;
991 long long GetTime()
const;
992 long long GetFirstTime()
const;
993 long long GetLastTime()
const;
1006 static long HasBlockEntries(
const Segment*,
long long idoff,
long long& pos,
1009 long GetEntryCount()
const;
1011 long Load(
long long& pos,
long& size)
const;
1013 long Parse(
long long& pos,
long& size)
const;
1021 const long long m_element_start;
1022 long long GetPosition()
const;
1024 long GetIndex()
const;
1025 long long GetElementSize()
const;
1032 mutable long long m_pos;
1034 mutable long long m_element_size;
1035 mutable long long m_timecode;
1037 mutable long m_entries_size;
1038 mutable long m_entries_count;
1040 long ParseSimpleBlock(
long long,
long long&,
long&);
1041 long ParseBlockGroup(
long long,
long long&,
long&);
1043 long CreateBlock(
long long id,
long long pos,
long long size,
1044 long long discard_padding);
1045 long CreateBlockGroup(
long long start_offset,
long long size,
1046 long long discard_padding);
1047 long CreateSimpleBlock(
long long,
long long);
1061 long long pos,
long long size);
1065 const long long m_element_start;
1067 const long long m_start;
1068 const long long m_size;
1078 bool DoneParsing()
const;
1079 long long ParseHeaders();
1081 long LoadCluster(
long long& pos,
long& size);
1084 long ParseNext(
const Cluster* pCurr,
const Cluster*& pNext,
long long& pos,
1087 const SeekHead* GetSeekHead()
const;
1088 const Tracks* GetTracks()
const;
1090 const Cues* GetCues()
const;
1091 const Chapters* GetChapters()
const;
1092 const Tags* GetTags()
const;
1094 long long GetDuration()
const;
1096 unsigned long GetCount()
const;
1097 const Cluster* GetFirst()
const;
1098 const Cluster* GetLast()
const;
1101 const Cluster* FindCluster(
long long time_nanoseconds)
const;
1104 const Cluster* FindOrPreloadCluster(
long long pos);
1106 long ParseCues(
long long cues_off,
1107 long long& parse_pos,
long& parse_len);
1120 long m_clusterCount;
1121 long m_clusterPreloadCount;
1124 long DoLoadCluster(
long long&,
long&);
1125 long DoLoadClusterUnknownSize(
long long&,
long&);
1126 long DoParseNext(
const Cluster*&,
long long&,
long&);
1129 bool PreloadCluster(
Cluster*, ptrdiff_t);
1140 inline long mkvparser::Segment::LoadCluster() {
1144 return LoadCluster(pos, size);
1147 #endif // MKVPARSER_MKVPARSER_H_ Definition: mkvparser.h:927
Definition: mkvparser.h:682
Definition: mkvparser.h:299
Definition: mkvparser.h:142
Definition: mkvparser.h:907
Definition: mkvparser.h:476
Definition: mkvparser.h:504
Definition: mkvparser.h:19
Definition: mkvparser.h:71
Definition: mkvparser.h:392
Definition: mkvparser.h:798
Definition: mkvparser.h:889
Definition: mkvparser.h:13
Definition: mkvparser.h:119
Definition: mkvparser.h:157
Definition: mkvparser.h:214
Definition: mkvparser.h:96
Definition: mkvparser.h:188
Definition: mkvparser.h:1050
Definition: mkvparser.h:335
Definition: mkvparser.h:431
Definition: mkvparser.h:830
Definition: mkvparser.h:206
Definition: mkvparser.h:566
Definition: mkvparser.h:970
Definition: mkvparser.h:848
Definition: mkvparser.h:546
Definition: mkvparser.h:865
Definition: mkvparser.h:196
Definition: mkvparser.h:377
Definition: mkvparser.h:598
Definition: mkvparser.h:619
Definition: mkvparser.h:642
Definition: mkvparser.h:330