cricket::VideoFrameFactory: Don't overwrite frames in use
VideoFrameFactory has a single frame buffer that is used when scaling frames. If the previous frame is still in use, we need to allocate a new frame. BUG=4347 R=perkj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/36359004 Cr-Commit-Position: refs/heads/master@{#8549} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8549 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -132,9 +132,14 @@ class VideoFrame {
|
|||||||
virtual VideoFrame *Copy() const = 0;
|
virtual VideoFrame *Copy() const = 0;
|
||||||
|
|
||||||
// Since VideoFrame supports shallow copy and the internal frame buffer might
|
// Since VideoFrame supports shallow copy and the internal frame buffer might
|
||||||
// be shared, in case VideoFrame needs exclusive access of the frame buffer,
|
// be shared, this function can be used to check exclusive ownership. The
|
||||||
// user can call MakeExclusive() to make sure the frame buffer is exclusive
|
// default implementation is conservative and returns false. Subclasses with
|
||||||
// accessable to the current object. This might mean a deep copy of the frame
|
// knowledge of implementation specific details can override this.
|
||||||
|
virtual bool IsExclusive() const { return false; }
|
||||||
|
|
||||||
|
// In case VideoFrame needs exclusive access of the frame buffer, user can
|
||||||
|
// call MakeExclusive() to make sure the frame buffer is exclusively
|
||||||
|
// accessible to the current object. This might mean a deep copy of the frame
|
||||||
// buffer if it is currently shared by other objects.
|
// buffer if it is currently shared by other objects.
|
||||||
virtual bool MakeExclusive() = 0;
|
virtual bool MakeExclusive() = 0;
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ VideoFrame* VideoFrameFactory::CreateAliasedFrame(
|
|||||||
return cropped_input_frame.release();
|
return cropped_input_frame.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create and stretch the output frame if it has not been created yet or its
|
// Create and stretch the output frame if it has not been created yet, is
|
||||||
// size is not same as the expected.
|
// still in use by others, or its size is not same as the expected.
|
||||||
if (!output_frame_ ||
|
if (!output_frame_ || !output_frame_->IsExclusive() ||
|
||||||
output_frame_->GetWidth() != static_cast<size_t>(output_width) ||
|
output_frame_->GetWidth() != static_cast<size_t>(output_width) ||
|
||||||
output_frame_->GetHeight() != static_cast<size_t>(output_height)) {
|
output_frame_->GetHeight() != static_cast<size_t>(output_height)) {
|
||||||
output_frame_.reset(
|
output_frame_.reset(
|
||||||
|
@ -244,7 +244,15 @@ VideoFrame* WebRtcVideoFrame::Copy() const {
|
|||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebRtcVideoFrame::IsExclusive() const {
|
||||||
|
return video_buffer_->HasOneRef();
|
||||||
|
}
|
||||||
|
|
||||||
bool WebRtcVideoFrame::MakeExclusive() {
|
bool WebRtcVideoFrame::MakeExclusive() {
|
||||||
|
if (IsExclusive())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Not exclusive already, need to copy.
|
||||||
const size_t length = video_buffer_->length();
|
const size_t length = video_buffer_->length();
|
||||||
RefCountedBuffer* exclusive_buffer = new RefCountedBuffer(length);
|
RefCountedBuffer* exclusive_buffer = new RefCountedBuffer(length);
|
||||||
memcpy(exclusive_buffer->data(), video_buffer_->data(), length);
|
memcpy(exclusive_buffer->data(), video_buffer_->data(), length);
|
||||||
|
@ -137,6 +137,7 @@ class WebRtcVideoFrame : public VideoFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual VideoFrame* Copy() const;
|
virtual VideoFrame* Copy() const;
|
||||||
|
virtual bool IsExclusive() const;
|
||||||
virtual bool MakeExclusive();
|
virtual bool MakeExclusive();
|
||||||
virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
|
virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
|
||||||
size_t size, int stride_rgb) const;
|
size_t size, int stride_rgb) const;
|
||||||
|
Reference in New Issue
Block a user