-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgvFrame.c
114 lines (93 loc) · 2.54 KB
/
gvFrame.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
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
108
109
110
111
112
113
114
///////////////////////////////////////////////////////////////////////////////
// File: gvFrame.c
// SDK: GameSpy Voice 2 SDK
//
// Copyright Notice: This file is part of the GameSpy SDK designed and
// developed by GameSpy Industries. Copyright (c) 2004-2009 GameSpy Industries, Inc.
#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;
}
}