From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- third_party/libwebrtc/test/mac/Info.plist | 16 +++ third_party/libwebrtc/test/mac/run_test.mm | 73 ++++++++++++ .../libwebrtc/test/mac/video_renderer_mac.h | 40 +++++++ .../libwebrtc/test/mac/video_renderer_mac.mm | 127 +++++++++++++++++++++ 4 files changed, 256 insertions(+) create mode 100644 third_party/libwebrtc/test/mac/Info.plist create mode 100644 third_party/libwebrtc/test/mac/run_test.mm create mode 100644 third_party/libwebrtc/test/mac/video_renderer_mac.h create mode 100644 third_party/libwebrtc/test/mac/video_renderer_mac.mm (limited to 'third_party/libwebrtc/test/mac') diff --git a/third_party/libwebrtc/test/mac/Info.plist b/third_party/libwebrtc/test/mac/Info.plist new file mode 100644 index 0000000000..8a2b5cf0a0 --- /dev/null +++ b/third_party/libwebrtc/test/mac/Info.plist @@ -0,0 +1,16 @@ + + + + + CFBundleIdentifier + org.webrtc.video_loopback + CFBundleName + video_loopback + CFBundlePackageType + APPL + NSCameraUsageDescription + Camera access needed for video calling + NSMicrophoneUsageDescription + Microphone access needed for video calling + + diff --git a/third_party/libwebrtc/test/mac/run_test.mm b/third_party/libwebrtc/test/mac/run_test.mm new file mode 100644 index 0000000000..38c6c8f8c1 --- /dev/null +++ b/third_party/libwebrtc/test/mac/run_test.mm @@ -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 + +#include "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_; +} +- (void)runAllTests:(TestBlock)ignored; +- (BOOL)running; +@end + +@implementation TestRunner +- (id)init { + self = [super init]; + if (self) { + running_ = YES; + } + return self; +} + +- (void)runAllTests:(TestBlock)testBlock { + @autoreleasepool { + testBlock(); + running_ = NO; + } +} + +- (BOOL)running { + return running_; +} +@end + +namespace webrtc { +namespace test { + +void RunTest(void(*test)()) { + @autoreleasepool { + [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:testBlock]; + + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + while ([testRunner running] && [runLoop runMode:NSDefaultRunLoopMode + beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]) + ; + } +} + +} // namespace test +} // namespace webrtc diff --git a/third_party/libwebrtc/test/mac/video_renderer_mac.h b/third_party/libwebrtc/test/mac/video_renderer_mac.h new file mode 100644 index 0000000000..8e629b0a49 --- /dev/null +++ b/third_party/libwebrtc/test/mac/video_renderer_mac.h @@ -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 TEST_MAC_VIDEO_RENDERER_MAC_H_ +#define TEST_MAC_VIDEO_RENDERER_MAC_H_ + +#include "test/gl/gl_renderer.h" + +@class CocoaWindow; + +namespace webrtc { +namespace test { + +class MacRenderer : public GlRenderer { + public: + MacRenderer(); + virtual ~MacRenderer(); + + MacRenderer(const MacRenderer&) = delete; + MacRenderer& operator=(const MacRenderer&) = delete; + + bool Init(const char* window_title, int width, int height); + + // Implements GlRenderer. + void OnFrame(const VideoFrame& frame) override; + + private: + CocoaWindow* window_; +}; +} // namespace test +} // namespace webrtc + +#endif // TEST_MAC_VIDEO_RENDERER_MAC_H_ diff --git a/third_party/libwebrtc/test/mac/video_renderer_mac.mm b/third_party/libwebrtc/test/mac/video_renderer_mac.mm new file mode 100644 index 0000000000..7103375383 --- /dev/null +++ b/third_party/libwebrtc/test/mac/video_renderer_mac.mm @@ -0,0 +1,127 @@ +/* + * 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 "test/mac/video_renderer_mac.h" + +#import + +// 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)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:NSWindowStyleMaskTitled + backing:NSBackingStoreBuffered + defer:NO]; + + NSRect viewFrame = NSMakeRect(0, 0, width_, height_); + NSOpenGLView *view = [[NSOpenGLView alloc] initWithFrame:viewFrame pixelFormat:nil]; + 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(); +} + +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::OnFrame(const VideoFrame& frame) { + [window_ makeCurrentContext]; + GlRenderer::OnFrame(frame); +} + +} // test +} // webrtc -- cgit v1.2.3