Reland of Add unit tests for RTCMTLVideoView. (patchset #1 id:1 of https://codereview.webrtc.org/2733953006/ )
Reason for revert: Dependant CL has been relanded Original issue's description: > Revert of Add unit tests for RTCMTLVideoView. (patchset #6 id:100001 of https://codereview.webrtc.org/2723903003/ ) > > Reason for revert: > This CL depends on a reverted CL. > > Original issue's description: > > Add unit tests for RTCMTLVideoView. > > > > To properly test the functionality, following changes were needed > > - Make RTCMTLVideoView compiliable for all cpu architectures not just arm64. > > This is needed so that the test can run on any device and on simulator as well. > > - Refactor RTCMTLVideoView to have mockable class methods. > > The unittest class, RTCMTLVideoViewTests was designed to provide easy transition > > to XCTest when the time comes for that. > > To transition to XCTest it would suffice to inherit from XCTestCase and remove > > the gtest methods. > > > > BUG=webrtc:7079 > > > > Review-Url: https://codereview.webrtc.org/2723903003 > > Cr-Commit-Position: refs/heads/master@{#17014} > > Committed:0ebe0199ac> > TBR=magjed@webrtc.org,denicija@webrtc.org > # Not skipping CQ checks because original CL landed more than 1 days ago. > BUG=webrtc:7079 > > Review-Url: https://codereview.webrtc.org/2733953006 > Cr-Commit-Position: refs/heads/master@{#17118} > Committed:96d91524faTBR=magjed@webrtc.org,denicija@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:7079 Review-Url: https://codereview.webrtc.org/2743663002 Cr-Commit-Position: refs/heads/master@{#17140}
This commit is contained in:
@ -24,12 +24,6 @@
|
||||
* @param frame The frame to be rendered.
|
||||
*/
|
||||
- (void)drawFrame:(RTCVideoFrame *)frame;
|
||||
@end
|
||||
|
||||
/**
|
||||
* Implementation of RTCMTLRenderer protocol for rendering native nv12 video frames.
|
||||
*/
|
||||
@interface RTCMTLNV12Renderer : NSObject <RTCMTLRenderer>
|
||||
|
||||
/**
|
||||
* Sets the provided view as rendering destination if possible.
|
||||
@ -37,5 +31,13 @@
|
||||
* If not possible method returns NO and callers of the method are responisble for performing
|
||||
* cleanups.
|
||||
*/
|
||||
- (BOOL)addRenderingDestination:(__kindof MTKView *)view;
|
||||
- (BOOL)addRenderingDestination:(__kindof UIView *)view;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* Implementation of RTCMTLRenderer protocol for rendering native nv12 video frames.
|
||||
*/
|
||||
@interface RTCMTLNV12Renderer : NSObject <RTCMTLRenderer>
|
||||
|
||||
@end
|
||||
|
||||
@ -18,15 +18,18 @@
|
||||
|
||||
#import "RTCMTLNV12Renderer.h"
|
||||
|
||||
// To avoid unreconized symbol linker errors, we're taking advantage of the objc runtime.
|
||||
// Linking errors occur when compiling for architectures that don't support Metal.
|
||||
#define MTKViewClass NSClassFromString(@"MTKView")
|
||||
#define RTCMTLNV12RendererClass NSClassFromString(@"RTCMTLNV12Renderer")
|
||||
|
||||
@interface RTCMTLVideoView () <MTKViewDelegate>
|
||||
@property(nonatomic, strong) id<RTCMTLRenderer> renderer;
|
||||
@property(nonatomic, strong) RTCMTLNV12Renderer *renderer;
|
||||
@property(nonatomic, strong) MTKView *metalView;
|
||||
@property(atomic, strong) RTCVideoFrame *videoFrame;
|
||||
@end
|
||||
|
||||
@implementation RTCMTLVideoView {
|
||||
id<RTCMTLRenderer> _renderer;
|
||||
}
|
||||
@implementation RTCMTLVideoView
|
||||
|
||||
@synthesize renderer = _renderer;
|
||||
@synthesize metalView = _metalView;
|
||||
@ -58,11 +61,41 @@
|
||||
#endif
|
||||
}
|
||||
|
||||
+ (MTKView *)createMetalView:(CGRect)frame {
|
||||
MTKView *view = [[MTKViewClass alloc] initWithFrame:frame];
|
||||
return view;
|
||||
}
|
||||
|
||||
+ (RTCMTLNV12Renderer *)createMetalRenderer {
|
||||
RTCMTLNV12Renderer *renderer = [[RTCMTLNV12RendererClass alloc] init];
|
||||
return renderer;
|
||||
}
|
||||
|
||||
- (void)configure {
|
||||
if ([RTCMTLVideoView isMetalAvailable]) {
|
||||
_metalView = [[MTKView alloc] initWithFrame:self.bounds];
|
||||
[self addSubview:_metalView];
|
||||
if (![RTCMTLVideoView isMetalAvailable]) {
|
||||
RTCLog("Metal unavailable");
|
||||
return;
|
||||
}
|
||||
|
||||
_metalView = [RTCMTLVideoView createMetalView:self.bounds];
|
||||
_renderer = [RTCMTLVideoView createMetalRenderer];
|
||||
|
||||
if ([self configureMetalRenderer]) {
|
||||
[self configureMetalView];
|
||||
} else {
|
||||
_renderer = nil;
|
||||
RTCLogError("Metal configuration falied.");
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)configureMetalRenderer {
|
||||
return [_renderer addRenderingDestination:_metalView];
|
||||
}
|
||||
|
||||
- (void)configureMetalView {
|
||||
if (_metalView) {
|
||||
_metalView.delegate = self;
|
||||
[self addSubview:_metalView];
|
||||
_metalView.contentMode = UIViewContentModeScaleAspectFit;
|
||||
_metalView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
UILayoutGuide *margins = self.layoutMarginsGuide;
|
||||
@ -70,20 +103,14 @@
|
||||
[_metalView.bottomAnchor constraintEqualToAnchor:margins.bottomAnchor].active = YES;
|
||||
[_metalView.leftAnchor constraintEqualToAnchor:margins.leftAnchor].active = YES;
|
||||
[_metalView.rightAnchor constraintEqualToAnchor:margins.rightAnchor].active = YES;
|
||||
|
||||
_renderer = [[RTCMTLNV12Renderer alloc] init];
|
||||
if (![(RTCMTLNV12Renderer *)_renderer addRenderingDestination:_metalView]) {
|
||||
_renderer = nil;
|
||||
};
|
||||
} else {
|
||||
RTCLogError("Metal configuration falied.");
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - MTKViewDelegate methods
|
||||
|
||||
- (void)drawInMTKView:(nonnull MTKView *)view {
|
||||
NSAssert(view == self.metalView, @"Receiving draw callbacks from foreign instance.");
|
||||
[_renderer drawFrame:self.videoFrame];
|
||||
[self.renderer drawFrame:self.videoFrame];
|
||||
}
|
||||
|
||||
- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {
|
||||
@ -92,8 +119,8 @@
|
||||
#pragma mark - RTCVideoRenderer
|
||||
|
||||
- (void)setSize:(CGSize)size {
|
||||
_metalView.drawableSize = size;
|
||||
[_metalView draw];
|
||||
self.metalView.drawableSize = size;
|
||||
[self.metalView draw];
|
||||
}
|
||||
|
||||
- (void)renderFrame:(nullable RTCVideoFrame *)frame {
|
||||
|
||||
Reference in New Issue
Block a user