Adding back platform specific renderer to video loopback test.
BUG=3039
TEST=locally on Mac and Win, video_loopback test
R=pbos@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/10689004
git-svn-id: http://webrtc.googlecode.com/svn/trunk/webrtc@6339 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/test/mac/run_tests.mm b/test/mac/run_test.mm
similarity index 68%
rename from test/mac/run_tests.mm
rename to test/mac/run_test.mm
index c338773..e8f3840 100644
--- a/test/mac/run_tests.mm
+++ b/test/mac/run_test.mm
@@ -10,15 +10,20 @@
#import <Cocoa/Cocoa.h>
-#include "testing/gtest/include/gtest/gtest.h"
+#include "webrtc/test/run_test.h"
+// Converting a C++ function pointer to an Objective-C block.
+typedef void(^TestBlock)();
+TestBlock functionToBlock(void(*function)()) {
+ return [^(void) { function(); } copy];
+}
+
+// Class calling the test function on the platform specific thread.
@interface TestRunner : NSObject {
BOOL running_;
- int testResult_;
}
-- (void)runAllTests:(NSObject *)ignored;
+- (void)runAllTests:(TestBlock)ignored;
- (BOOL)running;
-- (int)result;
@end
@implementation TestRunner
@@ -30,9 +35,9 @@
return self;
}
-- (void)runAllTests:(NSObject *)ignored {
+- (void)runAllTests:(TestBlock)testBlock {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- testResult_ = RUN_ALL_TESTS();
+ testBlock();
running_ = NO;
[pool release];
}
@@ -40,33 +45,30 @@
- (BOOL)running {
return running_;
}
-
-- (int)result {
- return testResult_;
-}
@end
namespace webrtc {
namespace test {
-int RunAllTests() {
+void RunTest(void(*test)()) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
+ // Convert the function pointer to an Objective-C block and call on a
+ // separate thread, to avoid blocking the main thread.
TestRunner *testRunner = [[TestRunner alloc] init];
+ TestBlock testBlock = functionToBlock(test);
[NSThread detachNewThreadSelector:@selector(runAllTests:)
toTarget:testRunner
- withObject:nil];
+ withObject:testBlock];
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
diff --git a/test/run_tests.cc b/test/run_test.cc
similarity index 83%
rename from test/run_tests.cc
rename to test/run_test.cc
index 4692ba6..4daea42 100644
--- a/test/run_tests.cc
+++ b/test/run_test.cc
@@ -7,13 +7,16 @@
* 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"
+
+#include "webrtc/test/run_test.h"
+
+#include <stdio.h>
namespace webrtc {
namespace test {
-int RunAllTests() {
- return RUN_ALL_TESTS();
+void RunTest(void(*test)()) {
+ (*test)();
}
} // namespace test
diff --git a/test/run_tests.cc b/test/run_test.h
similarity index 71%
copy from test/run_tests.cc
copy to test/run_test.h
index 4692ba6..b515254 100644
--- a/test/run_tests.cc
+++ b/test/run_test.h
@@ -7,14 +7,16 @@
* 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"
+#ifndef WEBRTC_TEST_RUN_TEST_H
+#define WEBRTC_TEST_RUN_TEST_H
namespace webrtc {
namespace test {
-int RunAllTests() {
- return RUN_ALL_TESTS();
-}
+// Running a test function on a separate thread, if required by the OS.
+void RunTest(void(*test)());
} // namespace test
} // namespace webrtc
+
+#endif // WEBRTC_TEST_RUN_TEST_H
diff --git a/test/run_tests.h b/test/run_tests.h
deleted file mode 100644
index 3f42866..0000000
--- a/test/run_tests.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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 {
-
-// Blocks until the user presses enter.
-void PressEnterToContinue();
-
-// 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_
diff --git a/test/test_main.cc b/test/test_main.cc
index acce96f..733831f 100644
--- a/test/test_main.cc
+++ b/test/test_main.cc
@@ -11,7 +11,6 @@
#include "gflags/gflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/test/field_trial.h"
-#include "webrtc/test/run_tests.h"
#include "webrtc/test/testsupport/fileutils.h"
DEFINE_string(force_fieldtrials, "",
@@ -29,5 +28,5 @@
webrtc::test::SetExecutablePath(argv[0]);
webrtc::test::InitFieldTrialsFromString(FLAGS_force_fieldtrials);
- return webrtc::test::RunAllTests();
+ return RUN_ALL_TESTS();
}
diff --git a/test/webrtc_test_common.gyp b/test/webrtc_test_common.gyp
index 4c51498..556a445 100644
--- a/test/webrtc_test_common.gyp
+++ b/test/webrtc_test_common.gyp
@@ -31,12 +31,9 @@
'frame_generator_capturer.cc',
'frame_generator_capturer.h',
'mock_transport.h',
- 'null_platform_renderer.cc',
'null_transport.cc',
'null_transport.h',
'rtp_rtcp_observer.h',
- 'run_tests.cc',
- 'run_tests.h',
'run_loop.cc',
'run_loop.h',
'statistics.cc',
@@ -45,12 +42,71 @@
'vcm_capturer.h',
'video_capturer.cc',
'video_capturer.h',
+ 'win/run_loop_win.cc',
+ ],
+ 'conditions': [
+ ['OS=="win"', {
+ 'sources!': [
+ 'run_loop.cc',
+ ],
+ }],
+ ],
+ 'dependencies': [
+ '<(DEPTH)/testing/gtest.gyp:gtest',
+ '<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
+ '<(webrtc_root)/modules/modules.gyp:video_capture_module',
+ '<(webrtc_root)/modules/modules.gyp:media_file',
+ '<(webrtc_root)/test/test.gyp:frame_generator',
+ '<(webrtc_root)/test/test.gyp:test_support',
+ ],
+ },
+ {
+ 'target_name': 'webrtc_test_renderer',
+ 'type': 'static_library',
+ 'sources': [
+ 'gl/gl_renderer.cc',
+ 'gl/gl_renderer.h',
+ 'linux/glx_renderer.cc',
+ 'linux/glx_renderer.h',
+ 'linux/video_renderer_linux.cc',
+ 'mac/video_renderer_mac.h',
+ 'mac/video_renderer_mac.mm',
+ 'null_platform_renderer.cc',
'video_renderer.cc',
'video_renderer.h',
+ 'win/d3d_renderer.cc',
+ 'win/d3d_renderer.h',
],
- # TODO(pbos): As far as I can tell these are dependencies from
- # video_render and they should really not be here. This target provides
- # no platform-specific rendering.
+ 'conditions': [
+ ['OS=="linux"', {
+ 'sources!': [
+ 'null_platform_renderer.cc',
+ ],
+ }],
+ ['OS=="mac"', {
+ 'sources!': [
+ 'null_platform_renderer.cc',
+ ],
+ }],
+ ['OS!="linux" and OS!="mac"', {
+ 'sources!' : [
+ 'gl/gl_renderer.cc',
+ 'gl/gl_renderer.h',
+ ],
+ }],
+ ['OS=="win"', {
+ 'sources!': [
+ 'null_platform_renderer.cc',
+ ],
+ }],
+ ],
+ 'dependencies': [
+ '<(DEPTH)/testing/gtest.gyp:gtest',
+ '<(webrtc_root)/modules/modules.gyp:video_capture_module',
+ '<(webrtc_root)/modules/modules.gyp:media_file',
+ '<(webrtc_root)/test/test.gyp:frame_generator',
+ '<(webrtc_root)/test/test.gyp:test_support',
+ ],
'direct_dependent_settings': {
'conditions': [
['OS=="linux"', {
@@ -68,25 +124,47 @@
['OS=="mac"', {
'xcode_settings' : {
'OTHER_LDFLAGS' : [
- '-framework Foundation',
- '-framework AppKit',
'-framework Cocoa',
'-framework OpenGL',
'-framework CoreVideo',
- '-framework CoreAudio',
- '-framework AudioToolbox',
],
},
}],
],
},
- 'dependencies': [
- '<(DEPTH)/testing/gtest.gyp:gtest',
- '<(webrtc_root)/modules/modules.gyp:video_capture_module',
- '<(webrtc_root)/modules/modules.gyp:media_file',
- '<(webrtc_root)/test/test.gyp:frame_generator',
- '<(webrtc_root)/test/test.gyp:test_support',
- ],
+ },
+ {
+ # This target is only needed since the video render module builds platform
+ # specific code and depends on these libraries. This target should be
+ # removed as soon as the new video API doesn't depend on the module.
+ # TODO(mflodman) Remove this target as described above.
+ 'target_name': 'webrtc_test_video_render_dependencies',
+ 'type': 'static_library',
+ 'direct_dependent_settings': {
+ 'conditions': [
+ ['OS=="linux"', {
+ 'libraries': [
+ '-lXext',
+ '-lX11',
+ '-lGL',
+ ],
+ }],
+ ['OS=="android"', {
+ 'libraries' : [
+ '-lGLESv2', '-llog',
+ ],
+ }],
+ ['OS=="mac"', {
+ 'xcode_settings' : {
+ 'OTHER_LDFLAGS' : [
+ '-framework Cocoa',
+ '-framework OpenGL',
+ '-framework CoreVideo',
+ ],
+ },
+ }],
+ ],
+ },
},
],
'conditions': [
diff --git a/video/loopback.cc b/video/loopback.cc
index 98e32c6..eb2d5ae 100644
--- a/video/loopback.cc
+++ b/video/loopback.cc
@@ -23,7 +23,7 @@
#include "webrtc/test/encoder_settings.h"
#include "webrtc/test/fake_encoder.h"
#include "webrtc/test/run_loop.h"
-#include "webrtc/test/run_tests.h"
+#include "webrtc/test/run_test.h"
#include "webrtc/test/video_capturer.h"
#include "webrtc/test/video_renderer.h"
#include "webrtc/typedefs.h"
@@ -127,6 +127,6 @@
::testing::InitGoogleTest(&argc, argv);
google::ParseCommandLineFlags(&argc, &argv, true);
- webrtc::Loopback();
+ webrtc::test::RunTest(webrtc::Loopback);
return 0;
}
diff --git a/webrtc_tests.gypi b/webrtc_tests.gypi
index 72db281..a76126c 100644
--- a/webrtc_tests.gypi
+++ b/webrtc_tests.gypi
@@ -20,12 +20,23 @@
'target_name': 'video_loopback',
'type': 'executable',
'sources': [
+ 'test/mac/run_test.mm',
+ 'test/run_test.cc',
+ 'test/run_test.h',
'video/loopback.cc',
],
+ 'conditions': [
+ ['OS=="mac"', {
+ 'sources!': [
+ 'test/run_test.cc',
+ ],
+ }],
+ ],
'dependencies': [
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/gflags/gflags.gyp:gflags',
'test/webrtc_test_common.gyp:webrtc_test_common',
+ 'test/webrtc_test_common.gyp:webrtc_test_renderer',
'<(webrtc_root)/system_wrappers/source/system_wrappers.gyp:field_trial_default',
'webrtc',
],
@@ -47,6 +58,7 @@
'test/metrics.gyp:metrics',
'test/webrtc_test_common.gyp:webrtc_test_common',
'test/test.gyp:test_main',
+ 'test/webrtc_test_common.gyp:webrtc_test_video_render_dependencies',
'webrtc',
],
'conditions': [
@@ -74,6 +86,7 @@
'modules/modules.gyp:rtp_rtcp',
'test/webrtc_test_common.gyp:webrtc_test_common',
'test/test.gyp:test_main',
+ 'test/webrtc_test_common.gyp:webrtc_test_video_render_dependencies',
'webrtc',
],
'conditions': [