diff --git a/webrtc/common_video/i420_video_frame_unittest.cc b/webrtc/common_video/i420_video_frame_unittest.cc index 0eb1c2e678..012cf87742 100644 --- a/webrtc/common_video/i420_video_frame_unittest.cc +++ b/webrtc/common_video/i420_video_frame_unittest.cc @@ -11,9 +11,11 @@ #include #include -#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 ref_count_frame( + new RefCountImpl()); + 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); } diff --git a/webrtc/common_video/interface/i420_video_frame.h b/webrtc/common_video/interface/i420_video_frame.h index 0e528c1e4f..09ee9d0386 100644 --- a/webrtc/common_video/interface/i420_video_frame.h +++ b/webrtc/common_video/interface/i420_video_frame.h @@ -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.