blob: c8c21c4e2e0800e18b8423e8e91734dcf1d0c7c5 [file] [log] [blame]
wu@webrtc.orgea7b33e2013-08-05 20:36:571/*
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.org1bdf1862014-05-28 07:00:5111#include "webrtc/common_video/interface/texture_video_frame.h"
12
wu@webrtc.orgea7b33e2013-08-05 20:36:5713#include "testing/gtest/include/gtest/gtest.h"
14#include "webrtc/common_video/interface/native_handle.h"
wu@webrtc.orgea7b33e2013-08-05 20:36:5715
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
wuchengli@chromium.org1bdf1862014-05-28 07:00:5131bool EqualTextureFrames(const I420VideoFrame& frame1,
32 const I420VideoFrame& frame2);
33
wu@webrtc.orgea7b33e2013-08-05 20:36:5734TEST(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.orgea7b33e2013-08-05 20:36:5743 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
49TEST(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.org1bdf1862014-05-28 07:00:5158TEST(TestTextureVideoFrame, CloneFrame) {
59 NativeHandleImpl handle;
60 TextureVideoFrame frame1(&handle, 640, 480, 100, 200);
kwiberg@webrtc.orgdeb9dae2015-02-26 14:34:5561 rtc::scoped_ptr<I420VideoFrame> frame2(frame1.CloneFrame());
wuchengli@chromium.org1bdf1862014-05-28 07:00:5162 EXPECT_TRUE(frame2.get() != NULL);
63 EXPECT_TRUE(EqualTextureFrames(frame1, *frame2));
64}
65
66bool 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.orgea7b33e2013-08-05 20:36:5775} // namespace webrtc