SeekTable.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include <map>
  3. #include <vector>
  4. #include "mkv_reader.h"
  5. const uint32_t mkv_metaseek_seekhead = 0x14d9b74;
  6. const uint32_t mkv_metaseek_seek=0xdbb;
  7. const uint32_t mkv_metaseek_seekid = 0x13ab;
  8. const uint32_t mkv_metaseek_seekposition=0x13ac;
  9. /* this represents a seek table of other nodes in EBML
  10. be careful, CuePoints (CuePoints.h) is for seeking to a certain time in the song
  11. the SeekTable (SeekTable.h) is for fast indexing of the mkv file structure
  12. */
  13. namespace nsmkv
  14. {
  15. class SeekEntry
  16. {
  17. public:
  18. SeekEntry()
  19. {
  20. id=0;
  21. position=0;
  22. }
  23. SeekEntry(uint64_t id, uint64_t position) : id(id), position(position)
  24. {
  25. }
  26. uint64_t id; // ID of the EBML node
  27. uint64_t position;
  28. };
  29. class SeekTable
  30. {
  31. public:
  32. void AddEntry(SeekEntry &entry, int flags=0);
  33. void Dump();
  34. bool GetEntry(uint64_t id, uint64_t *position);
  35. bool EnumEntry(size_t i, uint64_t id, uint64_t *position);
  36. enum // flags for AddEntry
  37. {
  38. ADDENTRY_SINGLE = 0x1, // if there can only be one
  39. ADDENTRY_FOUND = 0x2, // pass this is you physically found the entry in the file - this takes priority over the SeekHead
  40. };
  41. private:
  42. bool EnumEntry(size_t i, uint64_t id, SeekEntry **seek_entry);
  43. typedef std::vector<SeekEntry> SeekEntries;
  44. typedef std::map<uint64_t, SeekEntries*> SeekMap;
  45. SeekMap seekMap;
  46. };
  47. // returns bytes read. 0 means EOF
  48. uint64_t ReadSeekHead(nsmkv::MKVReader *reader, uint64_t size, nsmkv::SeekTable &seekTable);
  49. }