2015-03-17 11:40:45 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "common_video/include/i420_buffer_pool.h"
|
|
|
|
|
#include "test/gtest.h"
|
2015-03-17 11:40:45 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
TEST(TestI420BufferPool, SimpleFrameReuse) {
|
|
|
|
|
I420BufferPool pool;
|
2017-06-01 10:02:26 -07:00
|
|
|
rtc::scoped_refptr<I420BufferInterface> buffer = pool.CreateBuffer(16, 16);
|
2015-03-17 11:40:45 +00:00
|
|
|
EXPECT_EQ(16, buffer->width());
|
|
|
|
|
EXPECT_EQ(16, buffer->height());
|
|
|
|
|
// Extract non-refcounted pointers for testing.
|
2016-04-18 05:34:40 -07:00
|
|
|
const uint8_t* y_ptr = buffer->DataY();
|
|
|
|
|
const uint8_t* u_ptr = buffer->DataU();
|
|
|
|
|
const uint8_t* v_ptr = buffer->DataV();
|
2015-03-17 11:40:45 +00:00
|
|
|
// Release buffer so that it is returned to the pool.
|
|
|
|
|
buffer = nullptr;
|
|
|
|
|
// Check that the memory is resued.
|
|
|
|
|
buffer = pool.CreateBuffer(16, 16);
|
2016-04-18 05:34:40 -07:00
|
|
|
EXPECT_EQ(y_ptr, buffer->DataY());
|
|
|
|
|
EXPECT_EQ(u_ptr, buffer->DataU());
|
|
|
|
|
EXPECT_EQ(v_ptr, buffer->DataV());
|
2015-03-17 11:40:45 +00:00
|
|
|
EXPECT_EQ(16, buffer->width());
|
|
|
|
|
EXPECT_EQ(16, buffer->height());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(TestI420BufferPool, FailToReuse) {
|
|
|
|
|
I420BufferPool pool;
|
2017-06-01 10:02:26 -07:00
|
|
|
rtc::scoped_refptr<I420BufferInterface> buffer = pool.CreateBuffer(16, 16);
|
2015-03-17 11:40:45 +00:00
|
|
|
// Extract non-refcounted pointers for testing.
|
2016-04-18 05:34:40 -07:00
|
|
|
const uint8_t* u_ptr = buffer->DataU();
|
|
|
|
|
const uint8_t* v_ptr = buffer->DataV();
|
2015-03-17 11:40:45 +00:00
|
|
|
// Release buffer so that it is returned to the pool.
|
|
|
|
|
buffer = nullptr;
|
|
|
|
|
// Check that the pool doesn't try to reuse buffers of incorrect size.
|
|
|
|
|
buffer = pool.CreateBuffer(32, 16);
|
|
|
|
|
EXPECT_EQ(32, buffer->width());
|
|
|
|
|
EXPECT_EQ(16, buffer->height());
|
2016-04-18 05:34:40 -07:00
|
|
|
EXPECT_NE(u_ptr, buffer->DataU());
|
|
|
|
|
EXPECT_NE(v_ptr, buffer->DataV());
|
2015-03-17 11:40:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(TestI420BufferPool, FrameValidAfterPoolDestruction) {
|
Reland of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #1 id:1 of https://codereview.webrtc.org/2354223002/ )
Reason for revert:
Downstream application now fixed.
Original issue's description:
> Revert of Move MutableDataY{,U,V} methods to I420Buffer only. (patchset #14 id:260001 of https://codereview.webrtc.org/2278883002/ )
>
> Reason for revert:
> Broke downstream application.
>
> Original issue's description:
> > Move MutableDataY{,U,V} methods to I420Buffer only.
> >
> > Deleted from the VideoFrameBuffer base class.
> >
> > BUG=webrtc:5921
> >
> > Committed: https://crrev.com/5539ef6c03c273f39fadae41ace47fdc11ac6d60
> > Cr-Commit-Position: refs/heads/master@{#14317}
>
> TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=webrtc:5921
>
> Committed: https://crrev.com/776870a2599b8f43ad56987f9031690e3ccecde8
> Cr-Commit-Position: refs/heads/master@{#14325}
TBR=perkj@webrtc.org,magjed@webrtc.org,pthatcher@webrtc.org,honghaiz@webrtc.org,stefan@webrtc.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:5921
Review-Url: https://codereview.webrtc.org/2372483002
Cr-Commit-Position: refs/heads/master@{#14389}
2016-09-27 00:17:25 -07:00
|
|
|
rtc::scoped_refptr<I420Buffer> buffer;
|
2015-03-17 11:40:45 +00:00
|
|
|
{
|
|
|
|
|
I420BufferPool pool;
|
|
|
|
|
buffer = pool.CreateBuffer(16, 16);
|
|
|
|
|
}
|
|
|
|
|
EXPECT_EQ(16, buffer->width());
|
|
|
|
|
EXPECT_EQ(16, buffer->height());
|
|
|
|
|
// Try to trigger use-after-free errors by writing to y-plane.
|
2016-04-18 05:34:40 -07:00
|
|
|
memset(buffer->MutableDataY(), 0xA5, 16 * buffer->StrideY());
|
2015-03-17 11:40:45 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-04 08:57:26 +01:00
|
|
|
TEST(TestI420BufferPool, MaxNumberOfBuffers) {
|
|
|
|
|
I420BufferPool pool(false, 1);
|
2017-06-01 10:02:26 -07:00
|
|
|
rtc::scoped_refptr<I420BufferInterface> buffer1 = pool.CreateBuffer(16, 16);
|
2016-11-04 08:57:26 +01:00
|
|
|
EXPECT_NE(nullptr, buffer1.get());
|
|
|
|
|
EXPECT_EQ(nullptr, pool.CreateBuffer(16, 16).get());
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 11:40:45 +00:00
|
|
|
} // namespace webrtc
|