Commit 95e2f469 authored by perkj@chromium.org's avatar perkj@chromium.org

Allow wrapping a media::VideoFrame with a new view_rect as long as the new...

Allow wrapping a media::VideoFrame with a new view_rect as long as the new view_rect is within the original rect.

BUG= 349450
R=fischman@chromium.org, tommi@chromium.org

Review URL: https://codereview.chromium.org/187573006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255353 0039d316-1c4b-4281-b951-d872f2087c98
parent 7a9570ed
...@@ -180,9 +180,11 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData( ...@@ -180,9 +180,11 @@ scoped_refptr<VideoFrame> VideoFrame::WrapExternalYuvData(
// static // static
scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame( scoped_refptr<VideoFrame> VideoFrame::WrapVideoFrame(
const scoped_refptr<VideoFrame>& frame, const scoped_refptr<VideoFrame>& frame,
const gfx::Rect& visible_rect,
const base::Closure& no_longer_needed_cb) { const base::Closure& no_longer_needed_cb) {
DCHECK(frame->visible_rect().Contains(visible_rect));
scoped_refptr<VideoFrame> wrapped_frame(new VideoFrame( scoped_refptr<VideoFrame> wrapped_frame(new VideoFrame(
frame->format(), frame->coded_size(), frame->visible_rect(), frame->format(), frame->coded_size(), visible_rect,
frame->natural_size(), frame->GetTimestamp(), frame->end_of_stream())); frame->natural_size(), frame->GetTimestamp(), frame->end_of_stream()));
for (size_t i = 0; i < NumPlanes(frame->format()); ++i) { for (size_t i = 0; i < NumPlanes(frame->format()); ++i) {
......
...@@ -150,9 +150,11 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> { ...@@ -150,9 +150,11 @@ class MEDIA_EXPORT VideoFrame : public base::RefCountedThreadSafe<VideoFrame> {
const base::Closure& no_longer_needed_cb); const base::Closure& no_longer_needed_cb);
// Wraps |frame| and calls |no_longer_needed_cb| when the wrapper VideoFrame // Wraps |frame| and calls |no_longer_needed_cb| when the wrapper VideoFrame
// gets destroyed. // gets destroyed. |visible_rect| must be a sub rect within
// frame->visible_rect().
static scoped_refptr<VideoFrame> WrapVideoFrame( static scoped_refptr<VideoFrame> WrapVideoFrame(
const scoped_refptr<VideoFrame>& frame, const scoped_refptr<VideoFrame>& frame,
const gfx::Rect& visible_rect,
const base::Closure& no_longer_needed_cb); const base::Closure& no_longer_needed_cb);
// Creates a frame which indicates end-of-stream. // Creates a frame which indicates end-of-stream.
......
...@@ -86,7 +86,8 @@ scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame( ...@@ -86,7 +86,8 @@ scoped_refptr<VideoFrame> VideoFramePool::PoolImpl::CreateFrame(
} }
return VideoFrame::WrapVideoFrame( return VideoFrame::WrapVideoFrame(
frame, base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame)); frame, frame->visible_rect(),
base::Bind(&VideoFramePool::PoolImpl::FrameReleased, this, frame));
} }
void VideoFramePool::PoolImpl::Shutdown() { void VideoFramePool::PoolImpl::Shutdown() {
......
...@@ -200,6 +200,39 @@ TEST(VideoFrame, CreateBlackFrame) { ...@@ -200,6 +200,39 @@ TEST(VideoFrame, CreateBlackFrame) {
} }
} }
static void FrameNoLongerNeededCallback(
const scoped_refptr<media::VideoFrame>& frame,
bool* triggered) {
*triggered = true;
}
TEST(VideoFrame, WrapVideoFrame) {
const int kWidth = 4;
const int kHeight = 4;
scoped_refptr<media::VideoFrame> frame;
bool no_longer_needed_triggered = false;
{
scoped_refptr<media::VideoFrame> wrapped_frame =
VideoFrame::CreateBlackFrame(gfx::Size(kWidth, kHeight));
ASSERT_TRUE(wrapped_frame.get());
gfx::Rect visible_rect(1, 1, 1, 1);
frame = media::VideoFrame::WrapVideoFrame(
wrapped_frame, visible_rect,
base::Bind(&FrameNoLongerNeededCallback, wrapped_frame,
&no_longer_needed_triggered));
EXPECT_EQ(wrapped_frame->coded_size(), frame->coded_size());
EXPECT_EQ(wrapped_frame->data(media::VideoFrame::kYPlane),
frame->data(media::VideoFrame::kYPlane));
EXPECT_NE(wrapped_frame->visible_rect(), frame->visible_rect());
EXPECT_EQ(visible_rect, frame->visible_rect());
}
EXPECT_FALSE(no_longer_needed_triggered);
frame = NULL;
EXPECT_TRUE(no_longer_needed_triggered);
}
// Ensure each frame is properly sized and allocated. Will trigger OOB reads // Ensure each frame is properly sized and allocated. Will trigger OOB reads
// and writes as well as incorrect frame hashes otherwise. // and writes as well as incorrect frame hashes otherwise.
TEST(VideoFrame, CheckFrameExtents) { TEST(VideoFrame, CheckFrameExtents) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment