title: WebRTC video artifacts from iPhone X and iPhone 8
body: <p>I have an iOS WebRTC application (with EasyRTC wrapper). It worked with all  iOS devices until iPhone X came out.<br>
  The problem is that video <em>from</em> iPhone X on other devices looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/TLT6P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TLT6P.png" alt="iphoneX broken video"></a></p>
  
  <p>What changes in iPhone X cause this kind of artifacts? And how to fix it?</p>
  
  <p>To start the video I'm using following code:</p>
  
  <pre><code>@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
  </code></pre>
  
  <p>My guess is <code>sessionPreset = AVCaptureSessionPresetHigh</code> doesn't work as it should in iPhone X. But unfortunately I can't check it at the moment.</p>
  
  <hr>
  
  <p>UPD.</p>
  
  <p>Same behavior is observed when transmitting video from iPhone 8.
  But on iPhone 7 with iOS 11.2.1 everything works fine.</p>
  
  <hr>
  
  <p>UPD. 2</p>
  
  <p>I've disabled this custom code that sets quality but the issue is still present.</p>
  
  <hr>
  
  <p>UPD. 3</p>
  
  <p>This happens on WebRTC version 58.</p>