-
Notifications
You must be signed in to change notification settings - Fork 7
/
buffer.c
60 lines (48 loc) · 1.12 KB
/
buffer.c
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
/*
* EffecTV - Realtime Digital Video Effector
* Copyright (C) 2001-2006 FUKUCHI Kentaro
*
* buffer.c: shared buffer manager
*
*/
#include <stdlib.h>
#include <string.h>
#include "EffecTV.h"
#include "utils.h"
static unsigned char *sharedbuffer = NULL;
static int sharedbuffer_length;
static int tail;
int sharedbuffer_init(void)
{
/* maximum size of the frame buffer is for screen size * 2 */
sharedbuffer_length = screen_width * screen_height * PIXEL_SIZE * 2;
sharedbuffer = (unsigned char *)malloc(sharedbuffer_length);
if(sharedbuffer == NULL) {
return -1;
}
return 0;
}
void sharedbuffer_end(void)
{
free(sharedbuffer);
}
/* The effects uses shared buffer must call this function at first in
* each effect registrar.
*/
void sharedbuffer_reset(void)
{
tail = 0;
}
/* Allocates size bytes memory in shared buffer and returns a pointer to the
* memory. NULL is returned when the rest memory is not enough for the request.
*/
unsigned char *sharedbuffer_alloc(int size)
{
unsigned char *head;
if(sharedbuffer_length - tail < size) {
return NULL;
}
head = sharedbuffer + tail;
tail += size;
return head;
}