我有一个iOS WebRTC应用程序(带有EasyRTC包装器)。直到iPhone X发布之前,它与所有iOS设备都能正常运行。
问题在于来自iPhone X的视频在其他设备上看起来像这样:
iPhone X中的哪些更改导致了这种伪影?如何解决?
使用以下代码启动视频:
问题在于来自iPhone X的视频在其他设备上看起来像这样:
![iphoneX broken video](https://istack.dev59.com/TLT6P.webp)
使用以下代码启动视频:
@implementation WebRTCModule (RTCMediaStream)
- (RTCMediaConstraints *)defaultMediaStreamConstraints {
NSDictionary *mandatoryConstraints
= @{ kRTCMediaConstraintsMinWidth : @"1280",
kRTCMediaConstraintsMinHeight : @"720",
kRTCMediaConstraintsMinFrameRate : @"30" };
RTCMediaConstraints* constraints =
[[RTCMediaConstraints alloc] initWithMandatoryConstraints:mandatoryConstraints optionalConstraints:nil];
return constraints;
}
typedef void (^NavigatorUserMediaErrorCallback)(NSString *errorType, NSString *errorMessage);
typedef void (^NavigatorUserMediaSuccessCallback)(RTCMediaStream *mediaStream);
- (void)getUserVideo:(NSDictionary *)constraints
successCallback:(NavigatorUserMediaSuccessCallback)successCallback
errorCallback:(NavigatorUserMediaErrorCallback)errorCallback
mediaStream:(RTCMediaStream *)mediaStream {
id videoConstraints = constraints[@"video"];
AVCaptureDevice *videoDevice;
if ([videoConstraints isKindOfClass:[NSDictionary class]]) {
for (AVCaptureDevice *aVideoDevice in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
if (aVideoDevice.position == AVCaptureDevicePositionFront) {
videoDevice = aVideoDevice;
break;
}
}
if (!videoDevice) {
videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
}
}
if (videoDevice) {
RTCMediaConstraints* constraints = [self defaultMediaStreamConstraints];
RTCAVFoundationVideoSource *videoSource = [self.peerConnectionFactory avFoundationVideoSourceWithConstraints:constraints];
dispatch_queue_t backgroundQueue = dispatch_queue_create("com.app.videoquality", 0);
dispatch_async(backgroundQueue, ^{
videoSource.captureSession.sessionPreset = AVCaptureSessionPresetHigh;
switch (videoDevice.position) {
case AVCaptureDevicePositionBack:
if (videoSource.canUseBackCamera) {
videoSource.useBackCamera = YES;
}
break;
case AVCaptureDevicePositionFront:
videoSource.useBackCamera = NO;
break;
}
NSString *trackUUID = [[NSUUID UUID] UUIDString];
RTCVideoTrack *videoTrack = [self.peerConnectionFactory videoTrackWithSource:videoSource trackId:trackUUID];
[mediaStream addVideoTrack:videoTrack];
dispatch_async(dispatch_get_main_queue(), ^{
successCallback(mediaStream);
});
});
} else {
errorCallback(@"OverconstrainedError", /* errorMessage */ nil);
}
}
@end
我的猜测是sessionPreset = AVCaptureSessionPresetHigh
在iPhone X上不像应该的那样工作。但不幸的是,我目前无法检查它。
更新。
从iPhone 8传输视频时观察到相同的行为。但在安装了iOS 11.2.1的iPhone 7上一切正常。
更新2
我已禁用设置质量的自定义代码,但问题仍然存在。
更新3
这发生在WebRTC版本58上。
adaptOutputFormat
就可以了。 - Teivaz