Making I420VideoFrame ref-counted
BUG=937 TEST=trybots Review URL: https://webrtc-codereview.appspot.com/1009004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@3312 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
b13dfbffd7
commit
e239bf0940
@ -11,9 +11,11 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "common_video/interface/i420_video_frame.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "system_wrappers/interface/scoped_ptr.h"
|
||||
#include "webrtc/common_video/interface/i420_video_frame.h"
|
||||
#include "webrtc/system_wrappers/interface/ref_count.h"
|
||||
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
|
||||
#include "webrtc/system_wrappers/interface/scoped_refptr.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -211,6 +213,17 @@ TEST(TestI420VideoFrame, FrameSwap) {
|
||||
EXPECT_TRUE(EqualFrames(frame2_copy, frame1));
|
||||
}
|
||||
|
||||
TEST(TestI420VideoFrame, RefCountedInstantiation) {
|
||||
// Refcounted instantiation - ref_count should correspond to the number of
|
||||
// instances.
|
||||
scoped_refptr<I420VideoFrame> ref_count_frame(
|
||||
new RefCountImpl<I420VideoFrame>());
|
||||
EXPECT_EQ(2, ref_count_frame->AddRef());
|
||||
EXPECT_EQ(3, ref_count_frame->AddRef());
|
||||
EXPECT_EQ(2, ref_count_frame->Release());
|
||||
EXPECT_EQ(1, ref_count_frame->Release());
|
||||
}
|
||||
|
||||
bool EqualFrames(const I420VideoFrame& frame1,
|
||||
const I420VideoFrame& frame2) {
|
||||
if (!EqualFramesExceptSize(frame1, frame2))
|
||||
@ -252,9 +265,9 @@ bool EqualFramesExceptSize(const I420VideoFrame& frame1,
|
||||
}
|
||||
|
||||
int ExpectedSize(int plane_stride, int image_height, PlaneType type) {
|
||||
if (type == kYPlane)
|
||||
if (type == kYPlane) {
|
||||
return (plane_stride * image_height);
|
||||
else {
|
||||
} else {
|
||||
int half_height = (image_height + 1) / 2;
|
||||
return (plane_stride * half_height);
|
||||
}
|
||||
|
@ -15,8 +15,12 @@
|
||||
//
|
||||
// Storing and handling of YUV (I420) video frames.
|
||||
|
||||
#include "common_video/plane.h"
|
||||
#include "typedefs.h" //NOLINT
|
||||
#include "webrtc/common_video/plane.h"
|
||||
#include "webrtc/typedefs.h"
|
||||
|
||||
/*
|
||||
* I420VideoFrame includes support for a reference counted impl.
|
||||
*/
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -30,7 +34,15 @@ enum PlaneType {
|
||||
class I420VideoFrame {
|
||||
public:
|
||||
I420VideoFrame();
|
||||
~I420VideoFrame();
|
||||
virtual ~I420VideoFrame();
|
||||
// Infrastructure for refCount implementation.
|
||||
// Implements dummy functions for reference counting so that non reference
|
||||
// counted instantiation can be done. These functions should not be called
|
||||
// when creating the frame with new I420VideoFrame().
|
||||
// Note: do not pass a I420VideoFrame created with new I420VideoFrame() or
|
||||
// equivalent to a scoped_refptr or memory leak will occur.
|
||||
virtual int32_t AddRef() {assert(false); return -1;}
|
||||
virtual int32_t Release() {assert(false); return -1;}
|
||||
|
||||
// CreateEmptyFrame: Sets frame dimensions and allocates buffers based
|
||||
// on set dimensions - height and plane stride.
|
||||
|
Loading…
x
Reference in New Issue
Block a user