1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/* 2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * libjingle 3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Copyright 2013 Google Inc. 4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * 5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * Redistribution and use in source and binary forms, with or without 6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * modification, are permitted provided that the following conditions are met: 7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * 8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * 1. Redistributions of source code must retain the above copyright notice, 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * this list of conditions and the following disclaimer. 10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * 2. Redistributions in binary form must reproduce the above copyright notice, 11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * this list of conditions and the following disclaimer in the documentation 12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * and/or other materials provided with the distribution. 13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * 3. The name of the author may not be used to endorse or promote products 14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * derived from this software without specific prior written permission. 15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * 16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */ 27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "talk/media/webrtc/webrtctexturevideoframe.h" 29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "talk/base/gunit.h" 31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "talk/media/base/videocommon.h" 32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 33baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass NativeHandleImpl : public webrtc::NativeHandle { 34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync public: 35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync NativeHandleImpl() : ref_count_(0) {} 36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync virtual ~NativeHandleImpl() {} 37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 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