Adding Mac test renderer, some test refactoring and made cpplint pass.

BUG=1667
TEST=Rendered video in Mac loopback test.
R=pbos@webrtc.org, xians@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4112 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2013-05-27 15:52:38 +00:00
parent acaf3a1b13
commit 7f944f3027
14 changed files with 414 additions and 66 deletions

View File

@ -11,7 +11,11 @@
#ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_GL_GL_RENDERER_H_
#define WEBRTC_VIDEO_ENGINE_TEST_COMMON_GL_GL_RENDERER_H_
#ifdef WEBRTC_MAC
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include "webrtc/video_engine/test/common/video_renderer.h"

View File

@ -0,0 +1,41 @@
/*
* 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/video_engine/test/common/video_renderer.h"
#ifdef WEBRTC_TEST_XV
#include "webrtc/video_engine/test/common/linux/xv_renderer.h"
#endif // WEBRTC_TEST_XV
#ifdef WEBRTC_TEST_GLX
#include "webrtc/video_engine/test/common/linux/glx_renderer.h"
#endif // WEBRTC_TEST_GLX
namespace webrtc {
namespace test {
VideoRenderer* VideoRenderer::CreatePlatformRenderer(const char* window_title,
size_t width,
size_t height) {
#ifdef WEBRTC_TEST_XV
XvRenderer* xv_renderer = XvRenderer::Create(window_title, width, height);
if (xv_renderer != NULL) {
return xv_renderer;
}
#endif // WEBRTC_TEST_XV
#ifdef WEBRTC_TEST_GLX
GlxRenderer* glx_renderer = GlxRenderer::Create(window_title, width, height);
if (glx_renderer != NULL) {
return glx_renderer;
}
#endif // WEBRTC_TEST_GLX
return NULL;
}
} // test
} // webrtc

View File

@ -0,0 +1,73 @@
/*
* 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.
*/
#import <Cocoa/Cocoa.h>
#include "testing/gtest/include/gtest/gtest.h"
@interface TestRunner : NSObject {
BOOL running_;
int testResult_;
}
- (void)runAllTests:(NSObject *)ignored;
- (BOOL)running;
- (int)result;
@end
@implementation TestRunner
- (id)init {
self = [super init];
if (self) {
running_ = YES;
}
return self;
}
- (void)runAllTests:(NSObject *)ignored {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
testResult_ = RUN_ALL_TESTS();
running_ = NO;
[pool release];
}
- (BOOL)running {
return running_;
}
- (int)result {
return testResult_;
}
@end
namespace webrtc {
namespace test {
int RunAllTests() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
TestRunner *testRunner = [[TestRunner alloc] init];
[NSThread detachNewThreadSelector:@selector(runAllTests:)
toTarget:testRunner
withObject:nil];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
while ([testRunner running] &&
[runLoop runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]]);
int result = [testRunner result];
[testRunner release];
[pool release];
return result;
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,40 @@
/*
* 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.
*/
#ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_MAC_VIDEO_RENDERER_MAC_H_
#define WEBRTC_VIDEO_ENGINE_TEST_COMMON_MAC_VIDEO_RENDERER_MAC_H_
#include "webrtc/system_wrappers/interface/constructor_magic.h"
#include "webrtc/video_engine/test/common/gl/gl_renderer.h"
@class CocoaWindow;
namespace webrtc {
namespace test {
class MacRenderer : public GlRenderer {
public:
MacRenderer();
virtual ~MacRenderer();
bool Init(const char* window_title, int width, int height);
// Implements GlRenderer.
virtual void RenderFrame(const I420VideoFrame& frame, int delta) OVERRIDE;
private:
CocoaWindow* window_;
DISALLOW_COPY_AND_ASSIGN(MacRenderer);
};
} // test
} // webrtc
#endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_MAC_VIDEO_RENDERER_MAC_H_

View File

@ -0,0 +1,134 @@
/*
* 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/video_engine/test/common/mac/video_renderer_mac.h"
#import <Cocoa/Cocoa.h>
// Creates a Cocoa Window with an OpenGL context, used together with an OpenGL
// renderer.
@interface CocoaWindow : NSObject {
@private
NSWindow *window_;
NSOpenGLContext *context_;
NSString *title_;
int width_;
int height_;
}
- (id)initWithTitle:(NSString *)title width:(int)width height:(int)height;
// 'createWindow' must be called on the main thread.
- (void)createWindow:(NSObject *)ignored;
- (void)makeCurrentContext;
@end
@implementation CocoaWindow
static NSInteger nextXOrigin_;
static NSInteger nextYOrigin_;
- (id)initWithTitle:(NSString *)title width:(int)width height:(int)height {
if (self = [super init]) {
title_ = title;
width_ = width;
height_ = height;
}
return self;
}
- (void)dealloc {
[window_ release];
[super dealloc];
}
- (void)createWindow:(NSObject *)ignored {
NSInteger xOrigin = nextXOrigin_;
NSRect screenFrame = [[NSScreen mainScreen] frame];
if (nextXOrigin_ + width_ < screenFrame.size.width) {
nextXOrigin_ += width_;
} else {
xOrigin = 0;
nextXOrigin_ = 0;
nextYOrigin_ += height_;
}
if (nextYOrigin_ + height_ > screenFrame.size.height) {
xOrigin = 0;
nextXOrigin_ = 0;
nextYOrigin_ = 0;
}
NSInteger yOrigin = nextYOrigin_;
NSRect windowFrame = NSMakeRect(xOrigin, yOrigin, width_, height_);
window_ = [[NSWindow alloc] initWithContentRect:windowFrame
styleMask:NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO];
NSRect viewFrame = NSMakeRect(0, 0, width_, height_);
NSOpenGLView *view = [[[NSOpenGLView alloc] initWithFrame:viewFrame
pixelFormat:nil] autorelease];
context_ = [view openGLContext];
[[window_ contentView] addSubview:view];
[window_ setTitle:title_];
[window_ makeKeyAndOrderFront:NSApp];
}
- (void)makeCurrentContext {
[context_ makeCurrentContext];
}
@end
namespace webrtc {
namespace test {
VideoRenderer* VideoRenderer::CreatePlatformRenderer(const char* window_title,
size_t width,
size_t height) {
MacRenderer* renderer = new MacRenderer();
if (!renderer->Init(window_title, width, height)) {
delete renderer;
return NULL;
}
return renderer;
}
MacRenderer::MacRenderer()
: window_(NULL) {}
MacRenderer::~MacRenderer() {
GlRenderer::Destroy();
[window_ release];
}
bool MacRenderer::Init(const char* window_title, int width, int height) {
window_ = [[CocoaWindow alloc]
initWithTitle:[NSString stringWithUTF8String:window_title]
width:width
height:height];
if (!window_)
return false;
[window_ performSelectorOnMainThread:@selector(createWindow:)
withObject:nil
waitUntilDone:YES];
[window_ makeCurrentContext];
GlRenderer::Init();
GlRenderer::ResizeViewport(width, height);
return true;
}
void MacRenderer::RenderFrame(const I420VideoFrame& frame, int /*delta*/) {
[window_ makeCurrentContext];
GlRenderer::RenderFrame(frame, 0);
}
} // test
} // webrtc

View File

@ -0,0 +1,23 @@
/*
* 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/video_engine/test/common/video_renderer.h"
namespace webrtc {
namespace test {
VideoRenderer* VideoRenderer::CreatePlatformRenderer(const char* window_title,
size_t width,
size_t height) {
return NULL;
}
} // test
} // webrtc

View File

@ -0,0 +1,21 @@
/*
* 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 "testing/gtest/include/gtest/gtest.h"
namespace webrtc {
namespace test {
int RunAllTests() {
return RUN_ALL_TESTS();
}
} // namespace test
} // namespace webrtc

View File

@ -0,0 +1,24 @@
/*
* 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.
*/
#ifndef WEBRTC_VIDEO_ENGINE_TEST_COMMON_TEST_RUNNER_H_
#define WEBRTC_VIDEO_ENGINE_TEST_COMMON_TEST_RUNNER_H_
namespace webrtc {
namespace test {
// Performs platform-dependent initializations and calls gtest's
// RUN_ALL_TESTS().
int RunAllTests();
} // namespace test
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_TEST_RUNNER_H_

View File

@ -27,8 +27,8 @@ class VcmCapturer : public VideoCapturer, public VideoCaptureDataCallback {
virtual void Start() OVERRIDE;
virtual void Stop() OVERRIDE;
virtual void OnIncomingCapturedFrame(const int32_t id, I420VideoFrame& frame)
OVERRIDE;
virtual void OnIncomingCapturedFrame(
const int32_t id, I420VideoFrame& frame) OVERRIDE; // NOLINT
virtual void OnIncomingCapturedEncodedFrame(const int32_t id,
VideoFrame& frame,
VideoCodecType codec_type)

View File

@ -36,4 +36,4 @@ class VideoCapturer {
} // test
} // webrtc
#endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_VIDEO_CAPTURER_H
#endif // WEBRTC_VIDEO_ENGINE_TEST_COMMON_VIDEO_CAPTURER_H_

View File

@ -10,19 +10,6 @@
#include "webrtc/video_engine/test/common/video_renderer.h"
#include "webrtc/modules/video_capture/include/video_capture_factory.h"
#include "webrtc/video_engine/new_include/video_send_stream.h"
#ifdef WEBRTC_TEST_XV
#include "webrtc/video_engine/test/common/linux/xv_renderer.h"
#endif // WEBRTC_TEST_XV
// Platform-specific renderers preferred over NullRenderer
#ifdef WEBRTC_TEST_GLX
#include "webrtc/video_engine/test/common/linux/glx_renderer.h"
#endif // WEBRTC_TEST_GLX
// TODO(pbos): Mac renderer
// TODO(pbos): Windows renderer
// TODO(pbos): Android renderer
@ -34,27 +21,13 @@ class NullRenderer : public VideoRenderer {
int time_to_render_ms) OVERRIDE {}
};
VideoRenderer* VideoRenderer::Create(const char* window_title,
size_t width,
VideoRenderer* VideoRenderer::Create(const char* window_title, size_t width,
size_t height) {
#ifdef WEBRTC_TEST_XV
XvRenderer* xv_renderer = XvRenderer::Create(window_title, width, height);
if (xv_renderer != NULL) {
return xv_renderer;
VideoRenderer* renderer = CreatePlatformRenderer(window_title, width, height);
if (renderer != NULL) {
// TODO(mflodman) Add a warning log.
return renderer;
}
#endif // WEBRTC_TEST_XV
#ifdef WEBRTC_TEST_GLX
GlxRenderer* glx_renderer = GlxRenderer::Create(window_title, width, height);
if (glx_renderer != NULL) {
return glx_renderer;
}
#endif // WEBRTC_TEST_GLX
// Avoid initialized-but-not-referenced errors when only building a
// NullRenderer
(void) width;
(void) height;
return new NullRenderer();
}
} // test

View File

@ -17,9 +17,17 @@ namespace test {
class VideoRenderer : public newapi::VideoRenderer {
public:
static VideoRenderer* Create(const char* window_title,
size_t width,
// Creates a platform-specific renderer if possible, or a null implementation
// if failing.
static VideoRenderer* Create(const char* window_title, size_t width,
size_t height);
// Returns a renderer rendering to a platform specific window if possible,
// NULL if none can be created.
// Creates a platform-specific renderer if possible, returns NULL if a
// platform renderer could not be created. This occurs, for instance, when
// running without an X environment on Linux.
static VideoRenderer* CreatePlatformRenderer(const char* window_title,
size_t width, size_t height);
virtual ~VideoRenderer() {}
protected:
VideoRenderer() {}

View File

@ -8,16 +8,17 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "testing/gtest/include/gtest/gtest.h"
#include <cstdio>
#include <map>
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/typedefs.h"
#include "webrtc/video_engine/new_include/video_engine.h"
#include "webrtc/video_engine/test/common/direct_transport.h"
#include "webrtc/video_engine/test/common/flags.h"
#include "webrtc/video_engine/test/common/generate_ssrcs.h"
#include "webrtc/video_engine/test/common/run_tests.h"
#include "webrtc/video_engine/test/common/video_capturer.h"
#include "webrtc/video_engine/test/common/video_renderer.h"
@ -51,8 +52,8 @@ TEST_F(LoopbackTest, Test) {
// TODO(pbos): static_cast shouldn't be required after mflodman refactors the
// VideoCodec struct.
send_config.codec.width = static_cast<unsigned short>(test::flags::Width());
send_config.codec.height = static_cast<unsigned short>(test::flags::Height());
send_config.codec.width = static_cast<uint16_t>(test::flags::Width());
send_config.codec.height = static_cast<uint16_t>(test::flags::Height());
send_config.codec.minBitrate =
static_cast<unsigned int>(test::flags::MinBitrate());
send_config.codec.startBitrate =
@ -106,5 +107,5 @@ int main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
webrtc::test::flags::Init(&argc, &argv);
return RUN_ALL_TESTS();
return webrtc::test::RunAllTests();
}

View File

@ -10,18 +10,6 @@
'variables': {
'xv_renderer%': 0,
},
'conditions': [
['OS=="linux"', {
'variables': {
'glx_renderer%': 1,
},
}, {
# OS != "linux"
'variables': {
'glx_renderer%': 0,
},
}],
],
'targets': [
{
'target_name': 'video_tests_common',
@ -32,25 +20,25 @@
'common/frame_generator.cc',
'common/frame_generator.h',
'common/generate_ssrcs.h',
'common/vcm_capturer.h',
'common/gl/gl_renderer.cc',
'common/gl/gl_renderer.h',
'common/linux/glx_renderer.cc',
'common/linux/glx_renderer.h',
'common/linux/video_renderer_linux.cc',
'common/mac/run_tests.mm',
'common/mac/video_renderer_mac.h',
'common/mac/video_renderer_mac.mm',
'common/null_platform_renderer.cc',
'common/run_tests.cc',
'common/run_tests.h',
'common/vcm_capturer.cc',
'common/vcm_capturer.h',
'common/video_capturer.cc',
'common/video_capturer.h',
'common/video_renderer.cc',
'common/video_renderer.h',
],
'conditions': [
['glx_renderer==1', {
'defines': [
'WEBRTC_TEST_GLX',
],
'sources' : [
'common/gl/gl_renderer.cc',
'common/gl/gl_renderer.h',
'common/linux/glx_renderer.cc',
'common/linux/glx_renderer.h',
],
}],
['xv_renderer==1', {
'defines': [
'WEBRTC_TEST_XV',
@ -60,6 +48,23 @@
'common/linux/xv_renderer.h',
],
}],
['OS=="linux"', {
'sources!': [
'common/null_platform_renderer.cc',
],
}],
['OS=="mac"', {
'sources!': [
'common/null_platform_renderer.cc',
'common/run_tests.cc',
],
}],
['OS!="linux" and OS!="mac"', {
'sources!' : [
'common/gl/gl_renderer.cc',
'common/gl/gl_renderer.h',
],
}],
],
'direct_dependent_settings': {
'conditions': [
@ -99,6 +104,7 @@
],
},
'dependencies': [
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/google-gflags/google-gflags.gyp:google-gflags',
'<(webrtc_root)/modules/modules.gyp:video_capture_module',
'video_engine_core',