1/* 2 * libjingle 3 * Copyright 2013 Google Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#include "talk/media/webrtc/webrtctexturevideoframe.h" 29 30#include "talk/media/base/videocommon.h" 31#include "webrtc/base/gunit.h" 32 33class NativeHandleImpl : public webrtc::NativeHandle { 34 public: 35 NativeHandleImpl() : ref_count_(0) {} 36 virtual ~NativeHandleImpl() {} 37 virtual int32_t AddRef() { return ++ref_count_; } 38 virtual int32_t Release() { return --ref_count_; } 39 virtual void* GetHandle() { return NULL; } 40 41 int32_t ref_count() { return ref_count_; } 42 private: 43 int32_t ref_count_; 44}; 45 46TEST(WebRtcTextureVideoFrameTest, InitialValues) { 47 NativeHandleImpl handle; 48 cricket::WebRtcTextureVideoFrame frame(&handle, 640, 480, 100, 200); 49 EXPECT_EQ(&handle, frame.GetNativeHandle()); 50 EXPECT_EQ(640u, frame.GetWidth()); 51 EXPECT_EQ(480u, frame.GetHeight()); 52 EXPECT_EQ(100, frame.GetElapsedTime()); 53 EXPECT_EQ(200, frame.GetTimeStamp()); 54 frame.SetElapsedTime(300); 55 EXPECT_EQ(300, frame.GetElapsedTime()); 56 frame.SetTimeStamp(400); 57 EXPECT_EQ(400, frame.GetTimeStamp()); 58} 59 60TEST(WebRtcTextureVideoFrameTest, CopyFrame) { 61 NativeHandleImpl handle; 62 cricket::WebRtcTextureVideoFrame frame1(&handle, 640, 480, 100, 200); 63 cricket::VideoFrame* frame2 = frame1.Copy(); 64 EXPECT_EQ(frame1.GetNativeHandle(), frame2->GetNativeHandle()); 65 EXPECT_EQ(frame1.GetWidth(), frame2->GetWidth()); 66 EXPECT_EQ(frame1.GetHeight(), frame2->GetHeight()); 67 EXPECT_EQ(frame1.GetElapsedTime(), frame2->GetElapsedTime()); 68 EXPECT_EQ(frame1.GetTimeStamp(), frame2->GetTimeStamp()); 69 delete frame2; 70} 71 72TEST(WebRtcTextureVideoFrameTest, RefCount) { 73 NativeHandleImpl handle; 74 EXPECT_EQ(0, handle.ref_count()); 75 cricket::WebRtcTextureVideoFrame* frame1 = 76 new cricket::WebRtcTextureVideoFrame(&handle, 640, 480, 100, 200); 77 EXPECT_EQ(1, handle.ref_count()); 78 cricket::VideoFrame* frame2 = frame1->Copy(); 79 EXPECT_EQ(2, handle.ref_count()); 80 delete frame2; 81 EXPECT_EQ(1, handle.ref_count()); 82 delete frame1; 83 EXPECT_EQ(0, handle.ref_count()); 84} 85