wu@webrtc.org | ea7b33e | 2013-08-05 20:36:57 | [diff] [blame] | 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 | |
wuchengli@chromium.org | 1bdf186 | 2014-05-28 07:00:51 | [diff] [blame] | 11 | #include "webrtc/common_video/interface/texture_video_frame.h" |
| 12 | |
wu@webrtc.org | ea7b33e | 2013-08-05 20:36:57 | [diff] [blame] | 13 | #include "testing/gtest/include/gtest/gtest.h" |
| 14 | #include "webrtc/common_video/interface/native_handle.h" |
wu@webrtc.org | ea7b33e | 2013-08-05 20:36:57 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | class 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 | |
wuchengli@chromium.org | 1bdf186 | 2014-05-28 07:00:51 | [diff] [blame] | 31 | bool EqualTextureFrames(const I420VideoFrame& frame1, |
| 32 | const I420VideoFrame& frame2); |
| 33 | |
wu@webrtc.org | ea7b33e | 2013-08-05 20:36:57 | [diff] [blame] | 34 | TEST(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 | |
wu@webrtc.org | ea7b33e | 2013-08-05 20:36:57 | [diff] [blame] | 43 | frame.set_timestamp(200); |
| 44 | EXPECT_EQ(200u, frame.timestamp()); |
| 45 | frame.set_render_time_ms(20); |
| 46 | EXPECT_EQ(20, frame.render_time_ms()); |
| 47 | } |
| 48 | |
| 49 | TEST(TestTextureVideoFrame, RefCount) { |
| 50 | NativeHandleImpl handle; |
| 51 | EXPECT_EQ(0, handle.ref_count()); |
| 52 | TextureVideoFrame *frame = new TextureVideoFrame(&handle, 640, 480, 100, 200); |
| 53 | EXPECT_EQ(1, handle.ref_count()); |
| 54 | delete frame; |
| 55 | EXPECT_EQ(0, handle.ref_count()); |
| 56 | } |
| 57 | |
wuchengli@chromium.org | 1bdf186 | 2014-05-28 07:00:51 | [diff] [blame] | 58 | TEST(TestTextureVideoFrame, CloneFrame) { |
| 59 | NativeHandleImpl handle; |
| 60 | TextureVideoFrame frame1(&handle, 640, 480, 100, 200); |
kwiberg@webrtc.org | deb9dae | 2015-02-26 14:34:55 | [diff] [blame] | 61 | rtc::scoped_ptr<I420VideoFrame> frame2(frame1.CloneFrame()); |
wuchengli@chromium.org | 1bdf186 | 2014-05-28 07:00:51 | [diff] [blame] | 62 | EXPECT_TRUE(frame2.get() != NULL); |
| 63 | EXPECT_TRUE(EqualTextureFrames(frame1, *frame2)); |
| 64 | } |
| 65 | |
| 66 | bool EqualTextureFrames(const I420VideoFrame& frame1, |
| 67 | const I420VideoFrame& frame2) { |
| 68 | return ((frame1.native_handle() == frame2.native_handle()) && |
| 69 | (frame1.width() == frame2.width()) && |
| 70 | (frame1.height() == frame2.height()) && |
| 71 | (frame1.timestamp() == frame2.timestamp()) && |
| 72 | (frame1.render_time_ms() == frame2.render_time_ms())); |
| 73 | } |
| 74 | |
wu@webrtc.org | ea7b33e | 2013-08-05 20:36:57 | [diff] [blame] | 75 | } // namespace webrtc |