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:
mikhal@webrtc.org 2012-10-30 18:22:02 +00:00
parent f6a4a49ab8
commit c381a8487a
2 changed files with 111 additions and 125 deletions

View File

@ -25,119 +25,106 @@ VideoFramesQueue::VideoFramesQueue()
{
}
VideoFramesQueue::~VideoFramesQueue()
{
while (!_incomingFrames.Empty())
{
ListItem* item = _incomingFrames.First();
if (item)
{
I420VideoFrame* ptrFrame =
static_cast<I420VideoFrame*>(item->GetItem());
assert(ptrFrame != NULL);
delete ptrFrame;
}
_incomingFrames.Erase(item);
VideoFramesQueue::~VideoFramesQueue() {
while (!_incomingFrames.Empty()) {
ListItem* item = _incomingFrames.First();
if (item) {
I420VideoFrame* ptrFrame = static_cast<I420VideoFrame*>(item->GetItem());
assert(ptrFrame != NULL);
delete ptrFrame;
}
while (!_emptyFrames.Empty())
{
ListItem* item = _emptyFrames.First();
_emptyFrames.Erase(item);
_incomingFrames.Erase(item);
}
while (!_emptyFrames.Empty()) {
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)
{
I420VideoFrame* ptrFrameToAdd = NULL;
// Try to re-use a VideoFrame. Only allocate new memory if it is necessary.
if (!_emptyFrames.Empty())
{
ListItem* item = _emptyFrames.First();
if (item)
{
ptrFrameToAdd = static_cast<I420VideoFrame*>(item->GetItem());
_emptyFrames.Erase(item);
}
WebRtc_Word32 VideoFramesQueue::AddFrame(const I420VideoFrame& newFrame) {
I420VideoFrame* ptrFrameToAdd = NULL;
// Try to re-use a VideoFrame. Only allocate new memory if it is necessary.
if (!_emptyFrames.Empty()) {
ListItem* item = _emptyFrames.First();
if (item) {
ptrFrameToAdd = static_cast<I420VideoFrame*>(item->GetItem());
_emptyFrames.Erase(item);
}
if (!ptrFrameToAdd)
{
if (_emptyFrames.GetSize() + _incomingFrames.GetSize() >
KMaxNumberOfFrames)
{
WEBRTC_TRACE(kTraceWarning, kTraceVideoRenderer, -1,
"%s: too many frames, limit: %d", __FUNCTION__,
KMaxNumberOfFrames);
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;
}
}
if (!ptrFrameToAdd) {
if (_emptyFrames.GetSize() + _incomingFrames.GetSize() >
KMaxNumberOfFrames) {
WEBRTC_TRACE(kTraceWarning, kTraceVideoRenderer, -1,
"%s: too many frames, limit: %d", __FUNCTION__,
KMaxNumberOfFrames);
return -1;
}
ptrFrameToAdd->CopyFrame(newFrame);
_incomingFrames.PushBack(ptrFrameToAdd);
return 0;
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);
return 0;
}
// Find the most recent frame that has a VideoFrame::RenderTimeMs() that is
// lower than current time in ms (TickTime::MillisecondTimestamp()).
// Note _incomingFrames is sorted so that the oldest frame is first.
// Recycle all frames that are older than the most recent frame.
I420VideoFrame* VideoFramesQueue::FrameToRecord()
{
I420VideoFrame* ptrRenderFrame = NULL;
ListItem* item = _incomingFrames.First();
while(item)
{
I420VideoFrame* ptrOldestFrameInList =
static_cast<I420VideoFrame*>(item->GetItem());
if (ptrOldestFrameInList->render_time_ms() <=
TickTime::MillisecondTimestamp() + _renderDelayMs)
{
if (ptrRenderFrame)
{
// List is traversed beginning to end. If ptrRenderFrame is not
// NULL it must be the first, and thus oldest, VideoFrame in the
// queue. It can be recycled.
ReturnFrame(ptrRenderFrame);
_incomingFrames.PopFront();
}
item = _incomingFrames.Next(item);
ptrRenderFrame = ptrOldestFrameInList;
}else
{
// All VideoFrames following this one will be even newer. No match
// will be found.
break;
}
I420VideoFrame* VideoFramesQueue::FrameToRecord() {
I420VideoFrame* ptrRenderFrame = NULL;
ListItem* item = _incomingFrames.First();
while(item) {
I420VideoFrame* ptrOldestFrameInList =
static_cast<I420VideoFrame*>(item->GetItem());
if (ptrOldestFrameInList->render_time_ms() <=
TickTime::MillisecondTimestamp() + _renderDelayMs) {
if (ptrRenderFrame) {
// List is traversed beginning to end. If ptrRenderFrame is not
// NULL it must be the first, and thus oldest, VideoFrame in the
// queue. It can be recycled.
ReturnFrame(ptrRenderFrame);
_incomingFrames.PopFront();
}
item = _incomingFrames.Next(item);
ptrRenderFrame = ptrOldestFrameInList;
} 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)
{
ptrOldFrame->set_timestamp(0);
ptrOldFrame->set_width(0);
ptrOldFrame->set_height(0);
ptrOldFrame->set_render_time_ms(0);
ptrOldFrame->ResetSize();
_emptyFrames.PushBack(ptrOldFrame);
return 0;
WebRtc_Word32 VideoFramesQueue::ReturnFrame(I420VideoFrame* ptrOldFrame) {
ptrOldFrame->set_timestamp(0);
ptrOldFrame->set_width(0);
ptrOldFrame->set_height(0);
ptrOldFrame->set_render_time_ms(0);
ptrOldFrame->ResetSize();
_emptyFrames.PushBack(ptrOldFrame);
return 0;
}
//
WebRtc_Word32 VideoFramesQueue::SetRenderDelay(WebRtc_UWord32 renderDelay)
{
_renderDelayMs = renderDelay;
return 0;
WebRtc_Word32 VideoFramesQueue::SetRenderDelay(WebRtc_UWord32 renderDelay) {
_renderDelayMs = renderDelay;
return 0;
}
} // namespace webrtc
#endif // WEBRTC_MODULE_UTILITY_VIDEO

View File

@ -20,42 +20,41 @@
namespace webrtc {
class VideoFramesQueue
{
public:
VideoFramesQueue();
~VideoFramesQueue();
class VideoFramesQueue {
public:
VideoFramesQueue();
~VideoFramesQueue();
// Put newFrame (last) in the queue.
WebRtc_Word32 AddFrame(const I420VideoFrame& newFrame);
// Put newFrame (last) in the queue.
WebRtc_Word32 AddFrame(const I420VideoFrame& newFrame);
// Return the most current frame. I.e. the frame with the highest
// VideoFrame::RenderTimeMs() that is lower than
// TickTime::MillisecondTimestamp().
I420VideoFrame* FrameToRecord();
// Return the most current frame. I.e. the frame with the highest
// VideoFrame::RenderTimeMs() that is lower than
// TickTime::MillisecondTimestamp().
I420VideoFrame* FrameToRecord();
// Set the render delay estimate to renderDelay ms.
WebRtc_Word32 SetRenderDelay(WebRtc_UWord32 renderDelay);
// Set the render delay estimate to renderDelay ms.
WebRtc_Word32 SetRenderDelay(WebRtc_UWord32 renderDelay);
protected:
// Make ptrOldFrame available for re-use. I.e. put it in the empty frames
// queue.
WebRtc_Word32 ReturnFrame(I420VideoFrame* ptrOldFrame);
protected:
// Make ptrOldFrame available for re-use. I.e. put it in the empty frames
// queue.
WebRtc_Word32 ReturnFrame(I420VideoFrame* ptrOldFrame);
private:
// Don't allow the buffer to expand beyond KMaxNumberOfFrames VideoFrames.
// 300 frames correspond to 10 seconds worth of frames at 30 fps.
enum {KMaxNumberOfFrames = 300};
private:
// Don't allow the buffer to expand beyond KMaxNumberOfFrames VideoFrames.
// 300 frames correspond to 10 seconds worth of frames at 30 fps.
enum {KMaxNumberOfFrames = 300};
// 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
// was inserted first.
ListWrapper _incomingFrames;
// A list of frames that are free to be re-used.
ListWrapper _emptyFrames;
// 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
// was inserted first.
ListWrapper _incomingFrames;
// A list of frames that are free to be re-used.
ListWrapper _emptyFrames;
// Estimated render delay.
WebRtc_UWord32 _renderDelayMs;
// Estimated render delay.
WebRtc_UWord32 _renderDelayMs;
};
} // namespace webrtc
#endif // WEBRTC_MODULE_UTILITY_VIDEO