Fix valgrind issue.
Code was removed by mistake in r2983. BUG=1020 Review URL: https://webrtc-codereview.appspot.com/938006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3021 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
f6a4a49ab8
commit
c381a8487a
@ -25,119 +25,106 @@ VideoFramesQueue::VideoFramesQueue()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoFramesQueue::~VideoFramesQueue()
|
VideoFramesQueue::~VideoFramesQueue() {
|
||||||
{
|
while (!_incomingFrames.Empty()) {
|
||||||
while (!_incomingFrames.Empty())
|
ListItem* item = _incomingFrames.First();
|
||||||
{
|
if (item) {
|
||||||
ListItem* item = _incomingFrames.First();
|
I420VideoFrame* ptrFrame = static_cast<I420VideoFrame*>(item->GetItem());
|
||||||
if (item)
|
assert(ptrFrame != NULL);
|
||||||
{
|
delete ptrFrame;
|
||||||
I420VideoFrame* ptrFrame =
|
|
||||||
static_cast<I420VideoFrame*>(item->GetItem());
|
|
||||||
assert(ptrFrame != NULL);
|
|
||||||
delete ptrFrame;
|
|
||||||
}
|
|
||||||
_incomingFrames.Erase(item);
|
|
||||||
}
|
}
|
||||||
while (!_emptyFrames.Empty())
|
_incomingFrames.Erase(item);
|
||||||
{
|
}
|
||||||
ListItem* item = _emptyFrames.First();
|
while (!_emptyFrames.Empty()) {
|
||||||
_emptyFrames.Erase(item);
|
ListItem* item = _emptyFrames.First();
|
||||||
|
if (item) {
|
||||||
|
I420VideoFrame* ptrFrame =
|
||||||
|
static_cast<I420VideoFrame*>(item->GetItem());
|
||||||
|
assert(ptrFrame != NULL);
|
||||||
|
delete ptrFrame;
|
||||||
}
|
}
|
||||||
|
_emptyFrames.Erase(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_Word32 VideoFramesQueue::AddFrame(const I420VideoFrame& newFrame)
|
WebRtc_Word32 VideoFramesQueue::AddFrame(const I420VideoFrame& newFrame) {
|
||||||
{
|
I420VideoFrame* ptrFrameToAdd = NULL;
|
||||||
I420VideoFrame* ptrFrameToAdd = NULL;
|
// Try to re-use a VideoFrame. Only allocate new memory if it is necessary.
|
||||||
// Try to re-use a VideoFrame. Only allocate new memory if it is necessary.
|
if (!_emptyFrames.Empty()) {
|
||||||
if (!_emptyFrames.Empty())
|
ListItem* item = _emptyFrames.First();
|
||||||
{
|
if (item) {
|
||||||
ListItem* item = _emptyFrames.First();
|
ptrFrameToAdd = static_cast<I420VideoFrame*>(item->GetItem());
|
||||||
if (item)
|
_emptyFrames.Erase(item);
|
||||||
{
|
|
||||||
ptrFrameToAdd = static_cast<I420VideoFrame*>(item->GetItem());
|
|
||||||
_emptyFrames.Erase(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!ptrFrameToAdd)
|
}
|
||||||
{
|
if (!ptrFrameToAdd) {
|
||||||
if (_emptyFrames.GetSize() + _incomingFrames.GetSize() >
|
if (_emptyFrames.GetSize() + _incomingFrames.GetSize() >
|
||||||
KMaxNumberOfFrames)
|
KMaxNumberOfFrames) {
|
||||||
{
|
WEBRTC_TRACE(kTraceWarning, kTraceVideoRenderer, -1,
|
||||||
WEBRTC_TRACE(kTraceWarning, kTraceVideoRenderer, -1,
|
"%s: too many frames, limit: %d", __FUNCTION__,
|
||||||
"%s: too many frames, limit: %d", __FUNCTION__,
|
KMaxNumberOfFrames);
|
||||||
KMaxNumberOfFrames);
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
WEBRTC_TRACE(kTraceMemory, kTraceVideoRenderer, -1,
|
|
||||||
"%s: allocating buffer %d", __FUNCTION__,
|
|
||||||
_emptyFrames.GetSize() + _incomingFrames.GetSize());
|
|
||||||
|
|
||||||
ptrFrameToAdd = new I420VideoFrame();
|
|
||||||
if (!ptrFrameToAdd)
|
|
||||||
{
|
|
||||||
WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, -1,
|
|
||||||
"%s: could not create new frame for", __FUNCTION__);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ptrFrameToAdd->CopyFrame(newFrame);
|
|
||||||
_incomingFrames.PushBack(ptrFrameToAdd);
|
WEBRTC_TRACE(kTraceMemory, kTraceVideoRenderer, -1,
|
||||||
return 0;
|
"%s: allocating buffer %d", __FUNCTION__,
|
||||||
|
_emptyFrames.GetSize() + _incomingFrames.GetSize());
|
||||||
|
|
||||||
|
ptrFrameToAdd = new I420VideoFrame();
|
||||||
|
if (!ptrFrameToAdd) {
|
||||||
|
WEBRTC_TRACE(kTraceError, kTraceVideoRenderer, -1,
|
||||||
|
"%s: could not create new frame for", __FUNCTION__);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ptrFrameToAdd->CopyFrame(newFrame);
|
||||||
|
_incomingFrames.PushBack(ptrFrameToAdd);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the most recent frame that has a VideoFrame::RenderTimeMs() that is
|
// Find the most recent frame that has a VideoFrame::RenderTimeMs() that is
|
||||||
// lower than current time in ms (TickTime::MillisecondTimestamp()).
|
// lower than current time in ms (TickTime::MillisecondTimestamp()).
|
||||||
// Note _incomingFrames is sorted so that the oldest frame is first.
|
// Note _incomingFrames is sorted so that the oldest frame is first.
|
||||||
// Recycle all frames that are older than the most recent frame.
|
// Recycle all frames that are older than the most recent frame.
|
||||||
I420VideoFrame* VideoFramesQueue::FrameToRecord()
|
I420VideoFrame* VideoFramesQueue::FrameToRecord() {
|
||||||
{
|
I420VideoFrame* ptrRenderFrame = NULL;
|
||||||
I420VideoFrame* ptrRenderFrame = NULL;
|
ListItem* item = _incomingFrames.First();
|
||||||
ListItem* item = _incomingFrames.First();
|
while(item) {
|
||||||
while(item)
|
I420VideoFrame* ptrOldestFrameInList =
|
||||||
{
|
static_cast<I420VideoFrame*>(item->GetItem());
|
||||||
I420VideoFrame* ptrOldestFrameInList =
|
if (ptrOldestFrameInList->render_time_ms() <=
|
||||||
static_cast<I420VideoFrame*>(item->GetItem());
|
TickTime::MillisecondTimestamp() + _renderDelayMs) {
|
||||||
if (ptrOldestFrameInList->render_time_ms() <=
|
if (ptrRenderFrame) {
|
||||||
TickTime::MillisecondTimestamp() + _renderDelayMs)
|
// List is traversed beginning to end. If ptrRenderFrame is not
|
||||||
{
|
// NULL it must be the first, and thus oldest, VideoFrame in the
|
||||||
if (ptrRenderFrame)
|
// queue. It can be recycled.
|
||||||
{
|
ReturnFrame(ptrRenderFrame);
|
||||||
// List is traversed beginning to end. If ptrRenderFrame is not
|
_incomingFrames.PopFront();
|
||||||
// NULL it must be the first, and thus oldest, VideoFrame in the
|
}
|
||||||
// queue. It can be recycled.
|
item = _incomingFrames.Next(item);
|
||||||
ReturnFrame(ptrRenderFrame);
|
ptrRenderFrame = ptrOldestFrameInList;
|
||||||
_incomingFrames.PopFront();
|
} else {
|
||||||
}
|
// All VideoFrames following this one will be even newer. No match
|
||||||
item = _incomingFrames.Next(item);
|
// will be found.
|
||||||
ptrRenderFrame = ptrOldestFrameInList;
|
break;
|
||||||
}else
|
|
||||||
{
|
|
||||||
// All VideoFrames following this one will be even newer. No match
|
|
||||||
// will be found.
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ptrRenderFrame;
|
}
|
||||||
|
return ptrRenderFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtc_Word32 VideoFramesQueue::ReturnFrame(I420VideoFrame* ptrOldFrame)
|
WebRtc_Word32 VideoFramesQueue::ReturnFrame(I420VideoFrame* ptrOldFrame) {
|
||||||
{
|
ptrOldFrame->set_timestamp(0);
|
||||||
ptrOldFrame->set_timestamp(0);
|
ptrOldFrame->set_width(0);
|
||||||
ptrOldFrame->set_width(0);
|
ptrOldFrame->set_height(0);
|
||||||
ptrOldFrame->set_height(0);
|
ptrOldFrame->set_render_time_ms(0);
|
||||||
ptrOldFrame->set_render_time_ms(0);
|
ptrOldFrame->ResetSize();
|
||||||
ptrOldFrame->ResetSize();
|
_emptyFrames.PushBack(ptrOldFrame);
|
||||||
_emptyFrames.PushBack(ptrOldFrame);
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
WebRtc_Word32 VideoFramesQueue::SetRenderDelay(WebRtc_UWord32 renderDelay) {
|
||||||
WebRtc_Word32 VideoFramesQueue::SetRenderDelay(WebRtc_UWord32 renderDelay)
|
_renderDelayMs = renderDelay;
|
||||||
{
|
return 0;
|
||||||
_renderDelayMs = renderDelay;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
#endif // WEBRTC_MODULE_UTILITY_VIDEO
|
#endif // WEBRTC_MODULE_UTILITY_VIDEO
|
||||||
|
@ -20,42 +20,41 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class VideoFramesQueue
|
class VideoFramesQueue {
|
||||||
{
|
public:
|
||||||
public:
|
VideoFramesQueue();
|
||||||
VideoFramesQueue();
|
~VideoFramesQueue();
|
||||||
~VideoFramesQueue();
|
|
||||||
|
|
||||||
// Put newFrame (last) in the queue.
|
// Put newFrame (last) in the queue.
|
||||||
WebRtc_Word32 AddFrame(const I420VideoFrame& newFrame);
|
WebRtc_Word32 AddFrame(const I420VideoFrame& newFrame);
|
||||||
|
|
||||||
// Return the most current frame. I.e. the frame with the highest
|
// Return the most current frame. I.e. the frame with the highest
|
||||||
// VideoFrame::RenderTimeMs() that is lower than
|
// VideoFrame::RenderTimeMs() that is lower than
|
||||||
// TickTime::MillisecondTimestamp().
|
// TickTime::MillisecondTimestamp().
|
||||||
I420VideoFrame* FrameToRecord();
|
I420VideoFrame* FrameToRecord();
|
||||||
|
|
||||||
// Set the render delay estimate to renderDelay ms.
|
// Set the render delay estimate to renderDelay ms.
|
||||||
WebRtc_Word32 SetRenderDelay(WebRtc_UWord32 renderDelay);
|
WebRtc_Word32 SetRenderDelay(WebRtc_UWord32 renderDelay);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Make ptrOldFrame available for re-use. I.e. put it in the empty frames
|
// Make ptrOldFrame available for re-use. I.e. put it in the empty frames
|
||||||
// queue.
|
// queue.
|
||||||
WebRtc_Word32 ReturnFrame(I420VideoFrame* ptrOldFrame);
|
WebRtc_Word32 ReturnFrame(I420VideoFrame* ptrOldFrame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Don't allow the buffer to expand beyond KMaxNumberOfFrames VideoFrames.
|
// Don't allow the buffer to expand beyond KMaxNumberOfFrames VideoFrames.
|
||||||
// 300 frames correspond to 10 seconds worth of frames at 30 fps.
|
// 300 frames correspond to 10 seconds worth of frames at 30 fps.
|
||||||
enum {KMaxNumberOfFrames = 300};
|
enum {KMaxNumberOfFrames = 300};
|
||||||
|
|
||||||
// List of VideoFrame pointers. The list is sorted in the order of when the
|
// List of VideoFrame pointers. The list is sorted in the order of when the
|
||||||
// VideoFrame was inserted into the list. The first VideoFrame in the list
|
// VideoFrame was inserted into the list. The first VideoFrame in the list
|
||||||
// was inserted first.
|
// was inserted first.
|
||||||
ListWrapper _incomingFrames;
|
ListWrapper _incomingFrames;
|
||||||
// A list of frames that are free to be re-used.
|
// A list of frames that are free to be re-used.
|
||||||
ListWrapper _emptyFrames;
|
ListWrapper _emptyFrames;
|
||||||
|
|
||||||
// Estimated render delay.
|
// Estimated render delay.
|
||||||
WebRtc_UWord32 _renderDelayMs;
|
WebRtc_UWord32 _renderDelayMs;
|
||||||
};
|
};
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
#endif // WEBRTC_MODULE_UTILITY_VIDEO
|
#endif // WEBRTC_MODULE_UTILITY_VIDEO
|
||||||
|
Loading…
x
Reference in New Issue
Block a user