aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Input/in_wmvdrm/Remaining.h
blob: acfbbffec6597cb190c1122dd8eaeb5f46c88941 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef NULLSOFT_REMAININGH
#define NULLSOFT_REMAININGH
#include <assert.h>
#include <memory.h>
/* this class is used to store leftover samples */

class Remaining
{
public:
	Remaining()
		: store(0), size(0), used(0)
	{}

	void Allocate(unsigned long _size)
	{
		assert(_size);
		used=0;
		size=_size;
		if (store)
			delete [] store;
		store = new unsigned char [size];
	}

	/* Saves the incoming data and updates the pointer positions */
	template <class storage_t>
	void UpdatingWrite(storage_t *&data,  unsigned long &bytes)
	{
		unsigned long bytesToWrite = min(bytes, SizeRemaining());
		Write(data, bytesToWrite);
		assert(bytesToWrite);
		data = (storage_t *)((char *)data + bytesToWrite);
		bytes -= bytesToWrite;
	}

	void Write(void *data,  unsigned long bytes)
	{
		unsigned char *copy = (unsigned char *)store;
		copy+=used;
		memcpy(copy, data, bytes);
		used+=bytes;
	}

	unsigned long SizeRemaining()
	{
		return size-used;
	}

	bool Empty()
	{
		return !used;
	}
	bool Full()
	{
		return size == used;
	}
	void *GetData()
	{
		return (void *)store;
	}

	void Flush()
	{
		used=0;
	}
	unsigned char *store;
	 long size, used;
};
#endif