webrtc_m130/webrtc/common_video/texture_video_frame_unittest.cc
wuchengli@chromium.org 637c55f45b Add support of texture frames for video capturer.
This is a reland of r6252. The video_capture_tests failure on
builder Android Chromium-APK Tests should be flaky.

- Add ViECapturer unittest.
- Add CloneFrame function in I420VideoFrame.
- Encoders do not support texture yet and texture frames
are dropped in ViEEncoder for now.

Corresponding CLs:
https://codereview.chromium.org/277943002
http://cl/66620352

BUG=chromium:362437
TEST=WebRTC video stream forwarding, video_engine_core_unittests,
     common_video_unittests and video_capture_tests_apk.
TBR=fischman@webrtc.org, perkj@webrtc.org, stefan@webrtc.org, wu@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/12609004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6258 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-05-28 07:00:51 +00:00

80 lines
2.6 KiB
C++

/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/common_video/interface/texture_video_frame.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/common_video/interface/native_handle.h"
namespace webrtc {
class NativeHandleImpl : public NativeHandle {
public:
NativeHandleImpl() : ref_count_(0) {}
virtual ~NativeHandleImpl() {}
virtual int32_t AddRef() { return ++ref_count_; }
virtual int32_t Release() { return --ref_count_; }
virtual void* GetHandle() { return NULL; }
int32_t ref_count() { return ref_count_; }
private:
int32_t ref_count_;
};
bool EqualTextureFrames(const I420VideoFrame& frame1,
const I420VideoFrame& frame2);
TEST(TestTextureVideoFrame, InitialValues) {
NativeHandleImpl handle;
TextureVideoFrame frame(&handle, 640, 480, 100, 10);
EXPECT_EQ(640, frame.width());
EXPECT_EQ(480, frame.height());
EXPECT_EQ(100u, frame.timestamp());
EXPECT_EQ(10, frame.render_time_ms());
EXPECT_EQ(&handle, frame.native_handle());
EXPECT_EQ(0, frame.set_width(320));
EXPECT_EQ(320, frame.width());
EXPECT_EQ(0, frame.set_height(240));
EXPECT_EQ(240, frame.height());
frame.set_timestamp(200);
EXPECT_EQ(200u, frame.timestamp());
frame.set_render_time_ms(20);
EXPECT_EQ(20, frame.render_time_ms());
}
TEST(TestTextureVideoFrame, RefCount) {
NativeHandleImpl handle;
EXPECT_EQ(0, handle.ref_count());
TextureVideoFrame *frame = new TextureVideoFrame(&handle, 640, 480, 100, 200);
EXPECT_EQ(1, handle.ref_count());
delete frame;
EXPECT_EQ(0, handle.ref_count());
}
TEST(TestTextureVideoFrame, CloneFrame) {
NativeHandleImpl handle;
TextureVideoFrame frame1(&handle, 640, 480, 100, 200);
scoped_ptr<I420VideoFrame> frame2(frame1.CloneFrame());
EXPECT_TRUE(frame2.get() != NULL);
EXPECT_TRUE(EqualTextureFrames(frame1, *frame2));
}
bool EqualTextureFrames(const I420VideoFrame& frame1,
const I420VideoFrame& frame2) {
return ((frame1.native_handle() == frame2.native_handle()) &&
(frame1.width() == frame2.width()) &&
(frame1.height() == frame2.height()) &&
(frame1.timestamp() == frame2.timestamp()) &&
(frame1.render_time_ms() == frame2.render_time_ms()));
}
} // namespace webrtc