File: gvFrame.c

package info (click to toggle)
openmohaa 0.81.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 29,124 kB
  • sloc: ansic: 270,865; cpp: 250,173; sh: 234; asm: 141; xml: 64; makefile: 7
file content (107 lines) | stat: -rw-r--r-- 2,315 bytes parent folder | download | duplicates (2)
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
107
#include "gvFrame.h"
#include "gvCodec.h"

// packets are only accepted if they are frameStamped to be played
// within this many frames from the current play clock
#define GVI_INCOMING_PACKET_TIMEFRAME_FRAMES      (GVI_FRAMESTAMP_MAX / 2)

#define GVI_PREALLOCATED_FRAMES                   200

#if defined(_PS2) || defined(_PSP)
#define GVI_DYNAMICALLY_ALLOCATE_FRAMES           0
#else
#define GVI_DYNAMICALLY_ALLOCATE_FRAMES           1
#endif

// list of available frames
static GVIPendingFrame * GVIAvailableFrames;

GVBool gviIsFrameStampGT(GVFrameStamp a, GVFrameStamp b)
{
	return ((GVFrameStamp)(b - a) > GVI_INCOMING_PACKET_TIMEFRAME_FRAMES);
}

GVBool gviIsFrameStampGTE(GVFrameStamp a, GVFrameStamp b)
{
	return ((GVFrameStamp)(b - a - 1) > GVI_INCOMING_PACKET_TIMEFRAME_FRAMES);
}

static void gviFreePendingFrame(GVIPendingFrame * frame)
{
	gsifree(frame);
}

static GVIPendingFrame * gviNewPendingFrame(void)
{
	GVIPendingFrame * frame;

	// allocate a new frame
#if GVI_PRE_DECODE
	frame = (GVIPendingFrame *)gsimalloc(sizeof(GVIPendingFrame) + GVIBytesPerFrame - sizeof(GVSample));
#else
	frame = (GVIPendingFrame *)gsimalloc(sizeof(GVIPendingFrame) + GVIEncodedFrameSize - 1);
#endif

	// return it
	return frame;
}

void gviPutPendingFrame(GVIPendingFrame * frame)
{
	// put the frame back in the available frames list
	frame->m_next = GVIAvailableFrames;
	GVIAvailableFrames = frame;
}

GVIPendingFrame * gviGetPendingFrame(void)
{
	GVIPendingFrame * frame;

	// check the available frames list
	if(GVIAvailableFrames)
	{
		frame = GVIAvailableFrames;
		GVIAvailableFrames = frame->m_next;
		return frame;
	}

#if GVI_DYNAMICALLY_ALLOCATE_FRAMES
	// allocate a new frame
	return gviNewPendingFrame();
#else
	// we can't dynamically allocate frames
	return NULL;
#endif
}

void gviFramesStartup(void)
{
	GVIPendingFrame * frame;
	int i;

	if(GVIAvailableFrames)
		gviFramesCleanup();

	GVIAvailableFrames = NULL;

	for(i = 0 ; i < GVI_PREALLOCATED_FRAMES ; i++)
	{
		frame = gviNewPendingFrame();
		if(!frame)
			return;
		frame->m_next = GVIAvailableFrames;
		GVIAvailableFrames = frame;
	}
}

void gviFramesCleanup(void)
{
	GVIPendingFrame * next;

	while(GVIAvailableFrames)
	{
		next = GVIAvailableFrames->m_next;
		gviFreePendingFrame(GVIAvailableFrames);
		GVIAvailableFrames = next;
	}
}