From eae79248361e923aadcb3173283484747a0c7ac7 Mon Sep 17 00:00:00 2001 From: "mflodman@webrtc.org" Date: Thu, 5 Jun 2014 09:32:51 +0000 Subject: [PATCH] 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@6339 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/test/mac/{run_tests.mm => run_test.mm} | 30 ++--- webrtc/test/{run_tests.cc => run_test.cc} | 9 +- webrtc/test/{run_tests.h => run_test.h} | 13 +- webrtc/test/test_main.cc | 3 +- webrtc/test/webrtc_test_common.gyp | 112 +++++++++++++++--- webrtc/video/loopback.cc | 4 +- webrtc/webrtc_tests.gypi | 13 ++ 7 files changed, 138 insertions(+), 46 deletions(-) rename webrtc/test/mac/{run_tests.mm => run_test.mm} (68%) rename webrtc/test/{run_tests.cc => run_test.cc} (83%) rename webrtc/test/{run_tests.h => run_test.h} (59%) diff --git a/webrtc/test/mac/run_tests.mm b/webrtc/test/mac/run_test.mm similarity index 68% rename from webrtc/test/mac/run_tests.mm rename to webrtc/test/mac/run_test.mm index c338773f1..e8f38401c 100644 --- a/webrtc/test/mac/run_tests.mm +++ b/webrtc/test/mac/run_test.mm @@ -10,15 +10,20 @@ #import -#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/webrtc/test/run_tests.cc b/webrtc/test/run_test.cc similarity index 83% rename from webrtc/test/run_tests.cc rename to webrtc/test/run_test.cc index 4692ba615..4daea42a1 100644 --- a/webrtc/test/run_tests.cc +++ b/webrtc/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 namespace webrtc { namespace test { -int RunAllTests() { - return RUN_ALL_TESTS(); +void RunTest(void(*test)()) { + (*test)(); } } // namespace test diff --git a/webrtc/test/run_tests.h b/webrtc/test/run_test.h similarity index 59% rename from webrtc/test/run_tests.h rename to webrtc/test/run_test.h index 3f42866fa..b51525468 100644 --- a/webrtc/test/run_tests.h +++ b/webrtc/test/run_test.h @@ -7,19 +7,16 @@ * 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_ +#ifndef WEBRTC_TEST_RUN_TEST_H +#define WEBRTC_TEST_RUN_TEST_H namespace webrtc { namespace test { -// Blocks until the user presses enter. -void PressEnterToContinue(); +// Running a test function on a separate thread, if required by the OS. +void RunTest(void(*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_ +#endif // WEBRTC_TEST_RUN_TEST_H diff --git a/webrtc/test/test_main.cc b/webrtc/test/test_main.cc index acce96f2c..733831f5b 100644 --- a/webrtc/test/test_main.cc +++ b/webrtc/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 @@ int main(int argc, char* argv[]) { webrtc::test::SetExecutablePath(argv[0]); webrtc::test::InitFieldTrialsFromString(FLAGS_force_fieldtrials); - return webrtc::test::RunAllTests(); + return RUN_ALL_TESTS(); } diff --git a/webrtc/test/webrtc_test_common.gyp b/webrtc/test/webrtc_test_common.gyp index 4c514986b..556a44501 100644 --- a/webrtc/test/webrtc_test_common.gyp +++ b/webrtc/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', + ], + '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', ], - # 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. '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/webrtc/video/loopback.cc b/webrtc/video/loopback.cc index 98e32c645..eb2d5ae31 100644 --- a/webrtc/video/loopback.cc +++ b/webrtc/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 @@ int main(int argc, char* argv[]) { ::testing::InitGoogleTest(&argc, argv); google::ParseCommandLineFlags(&argc, &argv, true); - webrtc::Loopback(); + webrtc::test::RunTest(webrtc::Loopback); return 0; } diff --git a/webrtc/webrtc_tests.gypi b/webrtc/webrtc_tests.gypi index 72db2816f..a76126c8d 100644 --- a/webrtc/webrtc_tests.gypi +++ b/webrtc/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': [