Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

175 lines
4.8 KiB
Mathematica
Raw Normal View History

/*
* Copyright 2017 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 "WebRTC/RTCMTLVideoView.h"
#import <Metal/Metal.h>
#import <MetalKit/MetalKit.h>
#import "WebRTC/RTCLogging.h"
#import "WebRTC/RTCVideoFrame.h"
Revert "Revert "Revert "Revert "Support more formats in RTCVideoFrame"""" This reverts commit 1cfeb435427a2fa677a495e34c882096efc193d0. Reason for revert: Fix unit test Original change's description: > Revert "Revert "Revert "Support more formats in RTCVideoFrame""" > > This reverts commit 7583390d1a3a7c4e9a77da0d77250abac0c34d1d. > > Reason for revert: Breaks unit tests > > Original change's description: > > Revert "Revert "Support more formats in RTCVideoFrame"" > > > > This reverts commit 0789dab2cbd1617e94d7300e375163d42345f3d4. > > > > Reason for revert: Include obc_corevideoframebuffer target > > > > Original change's description: > > > Revert "Support more formats in RTCVideoFrame" > > > > > > This reverts commit bd2220a9c496ef2e8567b68d4be9435a110bdc34. > > > > > > Reason for revert: Broke external clients > > > > > > Original change's description: > > > > Support more formats in RTCVideoFrame > > > > > > > > Implement Obj-C version of webrtc::VideoFrameBuffer and use that in > > > > RTCVideoFrame. > > > > > > > > Bug: webrtc:7785 > > > > Change-Id: I49f42bcf451dd6769b3a79a65fe7b400dce22677 > > > > Reviewed-on: https://chromium-review.googlesource.com/536773 > > > > Commit-Queue: Anders Carlsson <andersc@webrtc.org> > > > > Reviewed-by: Magnus Jedvert <magjed@webrtc.org> > > > > Cr-Commit-Position: refs/heads/master@{#18691} > > > > > > TBR=magjed@webrtc.org,andersc@webrtc.org > > > > > > Change-Id: Id765dd9543ed0613a6b2de108b268c3501025fcd > > > No-Presubmit: true > > > No-Tree-Checks: true > > > No-Try: true > > > Bug: webrtc:7785 > > > Reviewed-on: https://chromium-review.googlesource.com/542837 > > > Reviewed-by: Anders Carlsson <andersc@webrtc.org> > > > Commit-Queue: Anders Carlsson <andersc@webrtc.org> > > > Cr-Commit-Position: refs/heads/master@{#18697} > > > > TBR=magjed@webrtc.org,andersc@webrtc.org > > > > Change-Id: I1ef5313b4a6c56eb8c7fd02d95db62c4e3c00255 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: webrtc:7785 > > Reviewed-on: https://chromium-review.googlesource.com/542838 > > Commit-Queue: Anders Carlsson <andersc@webrtc.org> > > Reviewed-by: Anders Carlsson <andersc@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#18716} > > TBR=magjed@webrtc.org,andersc@webrtc.org > > Change-Id: Id12f33698eb02041607cb9a5c54f37f01bfac5b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:7785 > Reviewed-on: https://chromium-review.googlesource.com/544840 > Reviewed-by: Anders Carlsson <andersc@webrtc.org> > Commit-Queue: Anders Carlsson <andersc@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#18718} TBR=magjed@webrtc.org,andersc@webrtc.org Change-Id: I184303ecba8db91ef7de709f982a295a2efe92eb Bug: webrtc:7785 Reviewed-on: https://chromium-review.googlesource.com/544841 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Anders Carlsson <andersc@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18731}
2017-06-22 15:26:30 +02:00
#import "WebRTC/RTCVideoFrameBuffer.h"
#import "RTCMTLI420Renderer.h"
#import "RTCMTLNV12Renderer.h"
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: https://chromium.googlesource.com/external/webrtc/+/0ebe0199acd1070f17ca2abc5bc22fdd8b0861ca > > 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: https://chromium.googlesource.com/external/webrtc/+/96d91524fa66b9a2e4f9fbbbc9c5e5149021a3f0 TBR=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}
2017-03-09 03:36:58 -08:00
// 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")
#define RTCMTLI420RendererClass NSClassFromString(@"RTCMTLI420Renderer")
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: https://chromium.googlesource.com/external/webrtc/+/0ebe0199acd1070f17ca2abc5bc22fdd8b0861ca > > 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: https://chromium.googlesource.com/external/webrtc/+/96d91524fa66b9a2e4f9fbbbc9c5e5149021a3f0 TBR=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}
2017-03-09 03:36:58 -08:00
@interface RTCMTLVideoView () <MTKViewDelegate>
@property(nonatomic, strong) RTCMTLI420Renderer *rendererI420;
@property(nonatomic, strong) RTCMTLNV12Renderer *rendererNV12;
@property(nonatomic, strong) MTKView *metalView;
@property(atomic, strong) RTCVideoFrame *videoFrame;
@end
@implementation RTCMTLVideoView {
int64_t _lastFrameTimeNs;
CGSize _videoFrameSize;
}
@synthesize delegate = _delegate;
@synthesize rendererI420 = _rendererI420;
@synthesize rendererNV12 = _rendererNV12;
@synthesize metalView = _metalView;
@synthesize videoFrame = _videoFrame;
- (instancetype)initWithFrame:(CGRect)frameRect {
self = [super initWithFrame:frameRect];
if (self) {
[self configure];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aCoder {
self = [super initWithCoder:aCoder];
if (self) {
[self configure];
}
return self;
}
#pragma mark - Private
+ (BOOL)isMetalAvailable {
Reland of Add Metal video view in AppRTCMobile and metal availability macro. (patchset #1 id:1 of https://codereview.webrtc.org/2739793003/ ) Reason for revert: Fixing rendering issues in AppRTCMobile Original issue's description: > Revert of Add Metal video view in AppRTCMobile and metal availability macro. (patchset #5 id:80001 of https://codereview.webrtc.org/2722583002/ ) > > Reason for revert: > Breaks AppRTCMobile > > Original issue's description: > > Add Metal video view in AppRTCMobile and Metal availability macro. > > > > - The RTC_SUPPORTS_METAL macro allows consumers to gracefully handle compilation for different archs that are not supporting Metal. > > > > BUG=webrtc:7079 > > > > Review-Url: https://codereview.webrtc.org/2722583002 > > Cr-Commit-Position: refs/heads/master@{#17004} > > Committed: https://chromium.googlesource.com/external/webrtc/+/154a7bb877abefada22afe28b0a755cf621e8d9e > > TBR=magjed@webrtc.org,tkchin@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/2739793003 > Cr-Commit-Position: refs/heads/master@{#17119} > Committed: https://chromium.googlesource.com/external/webrtc/+/cbbd8c76e8a8a1cf3f1193ea50980bc9d858458d TBR=magjed@webrtc.org,tkchin@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/2742603003 Cr-Commit-Position: refs/heads/master@{#17139}
2017-03-09 03:34:27 -08:00
#if defined(RTC_SUPPORTS_METAL)
return MTLCreateSystemDefaultDevice() != nil;
Reland of Add Metal video view in AppRTCMobile and metal availability macro. (patchset #1 id:1 of https://codereview.webrtc.org/2739793003/ ) Reason for revert: Fixing rendering issues in AppRTCMobile Original issue's description: > Revert of Add Metal video view in AppRTCMobile and metal availability macro. (patchset #5 id:80001 of https://codereview.webrtc.org/2722583002/ ) > > Reason for revert: > Breaks AppRTCMobile > > Original issue's description: > > Add Metal video view in AppRTCMobile and Metal availability macro. > > > > - The RTC_SUPPORTS_METAL macro allows consumers to gracefully handle compilation for different archs that are not supporting Metal. > > > > BUG=webrtc:7079 > > > > Review-Url: https://codereview.webrtc.org/2722583002 > > Cr-Commit-Position: refs/heads/master@{#17004} > > Committed: https://chromium.googlesource.com/external/webrtc/+/154a7bb877abefada22afe28b0a755cf621e8d9e > > TBR=magjed@webrtc.org,tkchin@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/2739793003 > Cr-Commit-Position: refs/heads/master@{#17119} > Committed: https://chromium.googlesource.com/external/webrtc/+/cbbd8c76e8a8a1cf3f1193ea50980bc9d858458d TBR=magjed@webrtc.org,tkchin@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/2742603003 Cr-Commit-Position: refs/heads/master@{#17139}
2017-03-09 03:34:27 -08:00
#else
return NO;
#endif
}
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: https://chromium.googlesource.com/external/webrtc/+/0ebe0199acd1070f17ca2abc5bc22fdd8b0861ca > > 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: https://chromium.googlesource.com/external/webrtc/+/96d91524fa66b9a2e4f9fbbbc9c5e5149021a3f0 TBR=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}
2017-03-09 03:36:58 -08:00
+ (MTKView *)createMetalView:(CGRect)frame {
MTKView *view = [[MTKViewClass alloc] initWithFrame:frame];
return view;
}
+ (RTCMTLNV12Renderer *)createNV12Renderer {
return [[RTCMTLNV12RendererClass alloc] init];
}
+ (RTCMTLI420Renderer *)createI420Renderer {
return [[RTCMTLI420RendererClass alloc] init];
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: https://chromium.googlesource.com/external/webrtc/+/0ebe0199acd1070f17ca2abc5bc22fdd8b0861ca > > 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: https://chromium.googlesource.com/external/webrtc/+/96d91524fa66b9a2e4f9fbbbc9c5e5149021a3f0 TBR=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}
2017-03-09 03:36:58 -08:00
}
- (void)configure {
NSAssert([RTCMTLVideoView isMetalAvailable], @"Metal not availiable on this device");
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: https://chromium.googlesource.com/external/webrtc/+/0ebe0199acd1070f17ca2abc5bc22fdd8b0861ca > > 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: https://chromium.googlesource.com/external/webrtc/+/96d91524fa66b9a2e4f9fbbbc9c5e5149021a3f0 TBR=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}
2017-03-09 03:36:58 -08:00
_metalView = [RTCMTLVideoView createMetalView:self.bounds];
[self configureMetalView];
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: https://chromium.googlesource.com/external/webrtc/+/0ebe0199acd1070f17ca2abc5bc22fdd8b0861ca > > 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: https://chromium.googlesource.com/external/webrtc/+/96d91524fa66b9a2e4f9fbbbc9c5e5149021a3f0 TBR=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}
2017-03-09 03:36:58 -08:00
}
- (void)configureMetalView {
if (_metalView) {
_metalView.delegate = self;
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: https://chromium.googlesource.com/external/webrtc/+/0ebe0199acd1070f17ca2abc5bc22fdd8b0861ca > > 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: https://chromium.googlesource.com/external/webrtc/+/96d91524fa66b9a2e4f9fbbbc9c5e5149021a3f0 TBR=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}
2017-03-09 03:36:58 -08:00
[self addSubview:_metalView];
_metalView.contentMode = UIViewContentModeScaleAspectFit;
_videoFrameSize = CGSizeZero;
}
}
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: https://chromium.googlesource.com/external/webrtc/+/0ebe0199acd1070f17ca2abc5bc22fdd8b0861ca > > 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: https://chromium.googlesource.com/external/webrtc/+/96d91524fa66b9a2e4f9fbbbc9c5e5149021a3f0 TBR=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}
2017-03-09 03:36:58 -08:00
- (void)setVideoContentMode:(UIViewContentMode)mode {
_metalView.contentMode = mode;
}
#pragma mark - Private
- (void)layoutSubviews {
[super layoutSubviews];
CGRect bounds = self.bounds;
_metalView.frame = bounds;
if (!CGSizeEqualToSize(_videoFrameSize, CGSizeZero)) {
_metalView.drawableSize = _videoFrameSize;
} else {
_metalView.drawableSize = bounds.size;
}
}
#pragma mark - MTKViewDelegate methods
- (void)drawInMTKView:(nonnull MTKView *)view {
NSAssert(view == self.metalView, @"Receiving draw callbacks from foreign instance.");
RTCVideoFrame *videoFrame = self.videoFrame;
// Skip rendering if we've already rendered this frame.
if (!videoFrame || videoFrame.timeStampNs == _lastFrameTimeNs) {
return;
}
if ([videoFrame.buffer isKindOfClass:[RTCCVPixelBuffer class]]) {
if (!self.rendererNV12) {
self.rendererNV12 = [RTCMTLVideoView createNV12Renderer];
if (![self.rendererNV12 addRenderingDestination:self.metalView]) {
self.rendererNV12 = nil;
RTCLogError(@"Failed to create NV12 renderer");
return;
}
}
[self.rendererNV12 drawFrame:videoFrame];
} else {
if (!self.rendererI420) {
self.rendererI420 = [RTCMTLVideoView createI420Renderer];
if (![self.rendererI420 addRenderingDestination:self.metalView]) {
self.rendererI420 = nil;
RTCLogError(@"Failed to create I420 renderer");
return;
}
}
[self.rendererI420 drawFrame:videoFrame];
}
_lastFrameTimeNs = videoFrame.timeStampNs;
}
- (void)mtkView:(MTKView *)view drawableSizeWillChange:(CGSize)size {
}
#pragma mark - RTCVideoRenderer
- (void)setSize:(CGSize)size {
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: https://chromium.googlesource.com/external/webrtc/+/0ebe0199acd1070f17ca2abc5bc22fdd8b0861ca > > 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: https://chromium.googlesource.com/external/webrtc/+/96d91524fa66b9a2e4f9fbbbc9c5e5149021a3f0 TBR=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}
2017-03-09 03:36:58 -08:00
self.metalView.drawableSize = size;
dispatch_async(dispatch_get_main_queue(), ^{
_videoFrameSize = size;
[self.delegate videoView:self didChangeVideoSize:size];
});
}
- (void)renderFrame:(nullable RTCVideoFrame *)frame {
if (frame == nil) {
RTCLogInfo(@"Incoming frame is nil. Exiting render callback.");
return;
}
self.videoFrame = frame;
}
@end