aboutsummaryrefslogtreecommitdiff
path: root/Src/h264dec/lcommon/src/memcache.c
blob: ce3b29d13ca107ef2a1172d5b259811ec1c6330d (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "memcache.h"
#include "mbuffer.h"
#include "memalloc.h"

void image_cache_flush(ImageCache *cache)
{
	while (cache->head)
	{
		VideoImage *next = cache->head->next;
		free_memImage(cache->head);
		cache->head = next;
	}
	cache->size_x = 0;
	cache->size_y = 0;
}

void image_cache_set_dimensions(ImageCache *cache, int width, int height)
{
	if (width != cache->size_x || height != cache->size_y)
	{
		image_cache_flush(cache);
		cache->size_x = width;
		cache->size_y = height;
	}
}

int image_cache_dimensions_match(ImageCache *cache, int width, int height)
{
	if (width != cache->size_x || height != cache->size_y)
		return 0;

	return 1;
}

void image_cache_add(ImageCache *cache, VideoImage *image)
{
	image->next = cache->head;
	cache->head = image;
}

struct video_image *image_cache_get(ImageCache *cache)
{
	if (cache->head)
	{
		VideoImage *ret = cache->head;
		cache->head = ret->next;
		ret->next = 0;
		return ret;
	}
	return 0;
}

/* ------------- 

PicMotion arrays are allowed with one extra slot in the first dimension
which we use as the next pointer
------------- */


void motion_cache_flush(MotionCache *cache)
{
	while (cache->head)
	{
		PicMotion **next = (PicMotion **)cache->head[cache->size_y];
		free_mem2DPicMotion(cache->head);
		cache->head = next;
	}
	cache->size_x = 0;
	cache->size_y = 0;
}

void motion_cache_set_dimensions(MotionCache *cache, int width, int height)
{
	if (width != cache->size_x || height != cache->size_y)
	{
		motion_cache_flush(cache);
		cache->size_x = width;
		cache->size_y = height;
	}
}

int motion_cache_dimensions_match(MotionCache *cache, int width, int height)
{
	if (width != cache->size_x || height != cache->size_y)
		return 0;

	return 1;
}

void motion_cache_add(MotionCache *cache, PicMotion **image)
{
	image[cache->size_y] = (PicMotion *)cache->head;
	cache->head = image;
}

struct pic_motion **motion_cache_get(MotionCache *cache)
{
	if (cache->head)
	{
		PicMotion **ret = cache->head;
		cache->head = (PicMotion **)ret[cache->size_y];
		ret[cache->size_y] = 0;
		return ret;
	}
	return 0;
}