header.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #include <bfc/platform/types.h>
  3. #include "mkv_reader.h"
  4. // IDs
  5. // these are slightly different from the matroska spec because we specify
  6. // values after vint decoding and they specify before
  7. const uint32_t mkv_header=0xa45dfa3;
  8. const uint32_t mkv_header_ebml_version=0x286;
  9. const uint32_t mkv_header_ebml_read_version=0x2f7;
  10. const uint32_t mkv_header_ebml_max_id_length=0x2f2;
  11. const uint32_t mkv_header_ebml_max_size_length=0x2f3;
  12. const uint32_t mkv_header_doctype=0x282;
  13. const uint32_t mkv_header_doctype_read_version=0x285;
  14. const uint32_t mkv_header_doctype_version=0x287;
  15. namespace nsmkv
  16. {
  17. class Header
  18. {
  19. public:
  20. // defaults provided as per spec for matroska
  21. // *_found variables indicate whether the field was found in the file
  22. Header() :
  23. ebml_version(1),
  24. ebml_read_version(1),
  25. ebml_max_id_length(4),
  26. ebml_max_size_length(8),
  27. doctype(0),
  28. doctype_version(1),
  29. doctype_read_version(1),
  30. ebml_header_found(false)
  31. #ifdef WA_VALIDATE
  32. ,
  33. ebml_version_found(false),
  34. ebml_read_version_found(false),
  35. ebml_max_id_length_found(false),
  36. ebml_max_size_length_found(false),
  37. doctype_version_found(false),
  38. doctype_found(false),
  39. doctype_read_version_found(false)
  40. #endif
  41. {
  42. }
  43. ~Header()
  44. {
  45. if (doctype)
  46. free(doctype);
  47. }
  48. void OwnDocType(char *_doctype)
  49. {
  50. if (doctype)
  51. free(doctype);
  52. doctype = _doctype;
  53. }
  54. uint64_t ebml_version;
  55. uint64_t ebml_read_version;
  56. uint64_t ebml_max_id_length;
  57. uint64_t ebml_max_size_length;
  58. char *doctype;
  59. uint64_t doctype_version;
  60. uint64_t doctype_read_version;
  61. bool ebml_header_found;
  62. #ifdef WA_VALIDATE
  63. bool ebml_version_found;
  64. bool ebml_read_version_found;
  65. bool ebml_max_id_length_found;
  66. bool doctype_found;
  67. bool ebml_max_size_length_found;
  68. bool doctype_version_found;
  69. bool doctype_read_version_found;
  70. #endif
  71. };
  72. // returns bytes read. 0 means EOF
  73. uint64_t ReadHeader(nsmkv::MKVReader *reader, uint64_t size, nsmkv::Header &header);
  74. };