1/* 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11#include "webrtc/common_video/interface/texture_video_frame.h" 12 13#include "testing/gtest/include/gtest/gtest.h" 14#include "webrtc/common_video/interface/native_handle.h" 15 16namespace webrtc { 17 18class NativeHandleImpl : public NativeHandle { 19 public: 20 NativeHandleImpl() : ref_count_(0) {} 21 virtual ~NativeHandleImpl() {} 22 virtual int32_t AddRef() { return ++ref_count_; } 23 virtual int32_t Release() { return --ref_count_; } 24 virtual void* GetHandle() { return NULL; } 25 26 int32_t ref_count() { return ref_count_; } 27 private: 28 int32_t ref_count_; 29}; 30 31bool EqualTextureFrames(const I420VideoFrame& frame1, 32 const I420VideoFrame& frame2); 33 34TEST(TestTextureVideoFrame, InitialValues) { 35 NativeHandleImpl handle; 36 TextureVideoFrame frame(&handle, 640, 480, 100, 10); 37 EXPECT_EQ(640, frame.width()); 38 EXPECT_EQ(480, frame.height()); 39 EXPECT_EQ(100u, frame.timestamp()); 40 EXPECT_EQ(10, frame.render_time_ms()); 41 EXPECT_EQ(&handle, frame.native_handle()); 42 43 EXPECT_EQ(0, frame.set_width(320)); 44 EXPECT_EQ(320, frame.width()); 45 EXPECT_EQ(0, frame.set_height(240)); 46 EXPECT_EQ(240, frame.height()); 47 frame.set_timestamp(200); 48 EXPECT_EQ(200u, frame.timestamp()); 49 frame.set_render_time_ms(20); 50 EXPECT_EQ(20, frame.render_time_ms()); 51} 52 53TEST(TestTextureVideoFrame, RefCount) { 54 NativeHandleImpl handle; 55 EXPECT_EQ(0, handle.ref_count()); 56 TextureVideoFrame *frame = new TextureVideoFrame(&handle, 640, 480, 100, 200); 57 EXPECT_EQ(1, handle.ref_count()); 58 delete frame; 59 EXPECT_EQ(0, handle.ref_count()); 60} 61 62TEST(TestTextureVideoFrame, CloneFrame) { 63 NativeHandleImpl handle; 64 TextureVideoFrame frame1(&handle, 640, 480, 100, 200); 65 scoped_ptr<I420VideoFrame> frame2(frame1.CloneFrame()); 66 EXPECT_TRUE(frame2.get() != NULL); 67 EXPECT_TRUE(EqualTextureFrames(frame1, *frame2)); 68} 69 70bool EqualTextureFrames(const I420VideoFrame& frame1, 71 const I420VideoFrame& frame2) { 72 return ((frame1.native_handle() == frame2.native_handle()) && 73 (frame1.width() == frame2.width()) && 74 (frame1.height() == frame2.height()) && 75 (frame1.timestamp() == frame2.timestamp()) && 76 (frame1.render_time_ms() == frame2.render_time_ms())); 77} 78 79} // namespace webrtc 80