Cluster.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include "mkv_reader.h"
  3. #include <bfc/platform/types.h>
  4. const uint32_t mkv_segment_cluster = 0xf43b675;
  5. const uint32_t mkv_cluster_timecode = 0x67;
  6. const uint32_t mkv_cluster_blockgroup = 0x20;
  7. const uint32_t mkv_cluster_simpleblock = 0x23;
  8. const uint32_t mkv_blockgroup_referenceblock = 0x7b;
  9. const uint32_t mkv_blockgroup_block = 0x21;
  10. const uint32_t mkv_blockgroup_blockduration = 0x1b;
  11. /* TODO: benski>
  12. need to think this whole thing through.
  13. Ideally, we would be able to enumerate through the clusters/blocks,
  14. but the output plugin might have a different audio buffer size
  15. than the size that the encoder assumed.
  16. so the first attempt is going to be random access
  17. and we'll see if there is a better way after implementation
  18. */
  19. namespace nsmkv
  20. {
  21. class BlockBinary
  22. {
  23. public:
  24. BlockBinary()
  25. {
  26. data=0;
  27. data_size=0;
  28. track_number=0;
  29. flags=0;
  30. time_code=0;
  31. }
  32. ~BlockBinary()
  33. {
  34. free(data);
  35. }
  36. uint64_t track_number;
  37. int16_t time_code;
  38. uint8_t flags;
  39. size_t data_size;
  40. void *data; // maybe optionally allow the user to pass in the buffer to reduce mallocs
  41. enum
  42. {
  43. LACE_MASK = 0x6,
  44. XIPH_LACING= 0x2,
  45. FIXED_LACING = 0x4,
  46. EBML_LACING = 0x6,
  47. NO_LACING = 0x0,
  48. };
  49. };
  50. class Block
  51. {
  52. public:
  53. Block()
  54. #ifdef WA_VALIDATE
  55. :
  56. reference_block_found(false),
  57. block_duration_found(false)
  58. #endif
  59. {
  60. reference_block=0;
  61. block_duration=0;
  62. }
  63. BlockBinary binary;
  64. uint64_t reference_block;
  65. uint64_t block_duration;
  66. #ifdef WA_VALIDATE
  67. bool reference_block_found;
  68. bool block_duration_found;
  69. #endif
  70. };
  71. class Cluster
  72. {
  73. public:
  74. Cluster()
  75. #ifdef WA_VALIDATE
  76. :
  77. time_code_found(false)
  78. #endif
  79. {
  80. time_code = 0;
  81. position = 0;
  82. previous_size = 0;
  83. }
  84. uint64_t time_code;
  85. uint64_t position;
  86. uint64_t previous_size;
  87. #ifdef WA_VALIDATE
  88. bool time_code_found;
  89. #endif
  90. };
  91. class Clusters
  92. {
  93. };
  94. uint64_t ReadCluster(MKVReader *reader, uint64_t size, nsmkv::Cluster &cluster);
  95. uint64_t ReadBlockBinary(MKVReader *reader, uint64_t size, nsmkv::BlockBinary &binary, uint64_t *allowed_track_numbers, size_t num_allowed_track_numbers);
  96. uint64_t ReadBlockGroup(MKVReader *reader, uint64_t size, nsmkv::Block &block, uint64_t *allowed_track_numbers, size_t num_allowed_track_numbers);
  97. }