aboutsummaryrefslogtreecommitdiff
path: root/Src/nsmkv/SeekTable.h
blob: 774ddcf95dfbd1056dd5bf7f9c3dd3da00e76ee3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <map>
#include <vector>
#include "mkv_reader.h"

const uint32_t mkv_metaseek_seekhead = 0x14d9b74;
const uint32_t mkv_metaseek_seek=0xdbb;
const uint32_t mkv_metaseek_seekid = 0x13ab;
const uint32_t mkv_metaseek_seekposition=0x13ac;

/* this represents a seek table of other nodes in EBML 
 be careful, CuePoints (CuePoints.h) is for seeking to a certain time in the song
the SeekTable (SeekTable.h) is for fast indexing of the mkv file structure 
*/
namespace nsmkv
{
	class SeekEntry
	{
	public:
		SeekEntry()
		{
			id=0;
			position=0;
		}
		SeekEntry(uint64_t id, uint64_t position) : id(id), position(position)
		{
		}
		uint64_t id; // ID of the EBML node
		uint64_t position;
	};

	class SeekTable
	{
	public:
		void AddEntry(SeekEntry &entry, int flags=0);
		void Dump();
		bool GetEntry(uint64_t id, uint64_t *position);
		bool EnumEntry(size_t i, uint64_t id, uint64_t *position);

		enum // flags for AddEntry
		{
			ADDENTRY_SINGLE = 0x1, // if there can only be one
			ADDENTRY_FOUND = 0x2, // pass this is you physically found the entry in the file - this takes priority over the SeekHead
		};
	private:
		bool EnumEntry(size_t i, uint64_t id, SeekEntry **seek_entry);
		typedef std::vector<SeekEntry> SeekEntries;
		typedef std::map<uint64_t, SeekEntries*> SeekMap;
		SeekMap seekMap;
	};

	// returns bytes read.  0 means EOF
	uint64_t ReadSeekHead(nsmkv::MKVReader *reader, uint64_t size, nsmkv::SeekTable &seekTable);
}