blob: f4021447956626c8e315cebfcc61fd5a3caa7cd8 (
plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/************************************************************************************
This source file is part of the Theora Video Playback Library
For latest info, see http://libtheoraplayer.googlecode.com
*************************************************************************************
Copyright (c) 2008-2014 Kresimir Spes (kspes@cateia.com)
This program is free software; you can redistribute it and/or modify it under
the terms of the BSD license: http://opensource.org/licenses/BSD-3-Clause
*************************************************************************************/
#include "TheoraFrameQueue.h"
#include "TheoraVideoFrame.h"
#include "TheoraVideoManager.h"
#include "TheoraUtil.h"
TheoraFrameQueue::TheoraFrameQueue(TheoraVideoClip* parent)
{
mParent = parent;
}
TheoraFrameQueue::~TheoraFrameQueue()
{
foreach_l(TheoraVideoFrame*, mQueue)
{
delete (*it);
}
mQueue.clear();
}
TheoraVideoFrame* TheoraFrameQueue::createFrameInstance(TheoraVideoClip* clip)
{
TheoraVideoFrame* frame = new TheoraVideoFrame(clip);
if (frame->getBuffer() == NULL) // This can happen if you run out of memory
{
delete frame;
return NULL;
}
return frame;
}
void TheoraFrameQueue::setSize(int n)
{
mMutex.lock();
if (mQueue.size() > 0)
{
foreach_l (TheoraVideoFrame*, mQueue)
{
delete (*it);
}
mQueue.clear();
}
TheoraVideoFrame* frame;
for (int i = 0;i < n; ++i)
{
frame = createFrameInstance(mParent);
if (frame != NULL) mQueue.push_back(frame);
else
{
TheoraVideoManager::getSingleton().logMessage("TheoraFrameQueue: unable to create " + str(n) + " frames, out of memory. Created " + str((int) mQueue.size()) + " frames.");
break;
}
}
mMutex.unlock();
}
int TheoraFrameQueue::getSize()
{
return (int) mQueue.size();
}
TheoraVideoFrame* TheoraFrameQueue::_getFirstAvailableFrame()
{
TheoraVideoFrame* frame = mQueue.front();
if (frame->mReady) return frame;
else return NULL;
}
TheoraVideoFrame* TheoraFrameQueue::getFirstAvailableFrame()
{
mMutex.lock();
TheoraVideoFrame* frame = _getFirstAvailableFrame();
mMutex.unlock();
return frame;
}
void TheoraFrameQueue::clear()
{
mMutex.lock();
foreach_l (TheoraVideoFrame*, mQueue)
(*it)->clear();
mMutex.unlock();
}
void TheoraFrameQueue::_pop(int n)
{
for (int i = 0; i < n; ++i)
{
TheoraVideoFrame* first = mQueue.front();
first->clear();
mQueue.pop_front();
mQueue.push_back(first);
}
}
void TheoraFrameQueue::pop(int n)
{
mMutex.lock();
_pop(n);
mMutex.unlock();
}
TheoraVideoFrame* TheoraFrameQueue::requestEmptyFrame()
{
TheoraVideoFrame* frame = NULL;
mMutex.lock();
foreach_l (TheoraVideoFrame*, mQueue)
{
if (!(*it)->mInUse)
{
(*it)->mInUse = 1;
(*it)->mReady = 0;
frame = (*it);
break;
}
}
mMutex.unlock();
return frame;
}
int TheoraFrameQueue::getUsedCount()
{
mMutex.lock();
int n=0;
foreach_l(TheoraVideoFrame*,mQueue)
if ((*it)->mInUse) ++n;
mMutex.unlock();
return n;
}
int TheoraFrameQueue::_getReadyCount()
{
int n = 0;
foreach_l (TheoraVideoFrame*, mQueue)
if ((*it)->mReady) ++n;
return n;
}
int TheoraFrameQueue::getReadyCount()
{
mMutex.lock();
int n = _getReadyCount();
mMutex.unlock();
return n;
}
bool TheoraFrameQueue::isFull()
{
return getReadyCount() == mQueue.size();
}
void TheoraFrameQueue::lock()
{
mMutex.lock();
}
void TheoraFrameQueue::unlock()
{
mMutex.unlock();
}
std::list<TheoraVideoFrame*>& TheoraFrameQueue::_getFrameQueue()
{
return mQueue;
}
|