Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: webrtc/sdk/objc/Framework/UnitTests/RTCCameraVideoCapturerTests.mm

Issue 2964703002: [iOS] Fix incorrectly oriented frames when rapidly switching between cameras. (Closed)
Patch Set: Change true/false to YES/NO Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 [self.delegateMock verify]; 211 [self.delegateMock verify];
212 212
213 [(id)currentDeviceMock stopMocking]; 213 [(id)currentDeviceMock stopMocking];
214 currentDeviceMock = nil; 214 currentDeviceMock = nil;
215 [classMock stopMocking]; 215 [classMock stopMocking];
216 classMock = nil; 216 classMock = nil;
217 CFRelease(sampleBuffer); 217 CFRelease(sampleBuffer);
218 #endif 218 #endif
219 } 219 }
220 220
221 - (void)testRotationCamera:(AVCaptureDevicePosition)camera
222 withOrientation:(UIDeviceOrientation)deviceOrientation {
223 #if TARGET_OS_IPHONE
224 // Mock the AVCaptureConnection as we will get the camera position from the co nnection's
225 // input ports.
226 AVCaptureDeviceInput *inputPortMock = OCMClassMock([AVCaptureDeviceInput class ]);
227 AVCaptureInputPort *captureInputPort = OCMClassMock([AVCaptureInputPort class] );
228 NSArray *inputPortsArrayMock = @[captureInputPort];
229 AVCaptureDevice *captureDeviceMock = OCMClassMock([AVCaptureDevice class]);
230 OCMStub(((AVCaptureConnection *)self.captureConnectionMock).inputPorts).
231 andReturn(inputPortsArrayMock);
232 OCMStub(captureInputPort.input).andReturn(inputPortMock);
233 OCMStub(inputPortMock.device).andReturn(captureDeviceMock);
234 OCMStub(captureDeviceMock.position).andReturn(camera);
235
236 // UpsideDown -> RTCVideoRotation_0.
237 UIDevice *currentDeviceMock = OCMClassMock([UIDevice class]);
238 OCMStub(currentDeviceMock.orientation).andReturn(deviceOrientation);
239 id classMock = OCMClassMock([UIDevice class]);
240 OCMStub([classMock currentDevice]).andReturn(currentDeviceMock);
241
242 CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
243
244 [[self.delegateMock expect] capturer:self.capturer
245 didCaptureVideoFrame:[OCMArg checkWithBlock:^BOOL(RTCVideoFram e *expectedFrame) {
246 if (camera == AVCaptureDevicePositionFront) {
247 if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
248 EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_180);
249 } else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
250 EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_0);
251 }
252 } else if (camera == AVCaptureDevicePositionBack) {
253 if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
254 EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_0);
255 } else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
256 EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_180);
257 }
258 }
259 return YES;
260 }]];
261
262 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
263 [center postNotificationName:UIDeviceOrientationDidChangeNotification object:n il];
264
265 // We need to wait for the dispatch to finish.
266 WAIT(0, 1000);
267
268 [self.capturer captureOutput:self.capturer.captureSession.outputs[0]
269 didOutputSampleBuffer:sampleBuffer
270 fromConnection:self.captureConnectionMock];
271
272 [self.delegateMock verify];
273
274 [(id)currentDeviceMock stopMocking];
275 currentDeviceMock = nil;
276 [classMock stopMocking];
277 classMock = nil;
278 CFRelease(sampleBuffer);
279 #endif
280 }
281
282 - (void)testRotationFrame {
283 #if TARGET_OS_IPHONE
284 // Mock the AVCaptureConnection as we will get the camera position from the co nnection's
285 // input ports.
286 AVCaptureDeviceInput *inputPortMock = OCMClassMock([AVCaptureDeviceInput class ]);
287 AVCaptureInputPort *captureInputPort = OCMClassMock([AVCaptureInputPort class] );
288 NSArray *inputPortsArrayMock = @[captureInputPort];
289 AVCaptureDevice *captureDeviceMock = OCMClassMock([AVCaptureDevice class]);
290 OCMStub(((AVCaptureConnection *)self.captureConnectionMock).inputPorts).
291 andReturn(inputPortsArrayMock);
292 OCMStub(captureInputPort.input).andReturn(inputPortMock);
293 OCMStub(inputPortMock.device).andReturn(captureDeviceMock);
294 OCMStub(captureDeviceMock.position).andReturn(AVCaptureDevicePositionFront);
295
296 // UpsideDown -> RTCVideoRotation_0.
297 UIDevice *currentDeviceMock = OCMClassMock([UIDevice class]);
298 OCMStub(currentDeviceMock.orientation).andReturn(UIDeviceOrientationLandscapeL eft);
299 id classMock = OCMClassMock([UIDevice class]);
300 OCMStub([classMock currentDevice]).andReturn(currentDeviceMock);
301
302 CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
303
304 [[self.delegateMock expect] capturer:self.capturer
305 didCaptureVideoFrame:[OCMArg checkWithBlock:^BOOL(RTCVideoFram e *expectedFrame) {
306 // Front camera and landscape left should return 180. But the frame says its from the back
307 // camera, so rotation should be 0.
308 EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_0);
309 return YES;
310 }]];
311
312 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
313 [center postNotificationName:UIDeviceOrientationDidChangeNotification object:n il];
314
315 // We need to wait for the dispatch to finish.
316 WAIT(0, 1000);
317
318 CFMutableDictionaryRef exif = CFDictionaryCreateMutable(kCFAllocatorDefault, 0 , NULL, NULL);
319 CFDictionarySetValue(exif, CFSTR("LensModel"), CFSTR("iPhone SE back camera 4. 15mm f/2.2"));
320 CMSetAttachment(sampleBuffer, CFSTR("{Exif}"), exif, kCMAttachmentMode_ShouldP ropagate);
321
322 // switchingCameras is not public, so use invocation to set it.
323 SEL selector = NSSelectorFromString(@"setSwitchingCameras:");
324 if ([self.capturer respondsToSelector:selector]) {
325 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
326 [[self.capturer class]
327 instanceMethodSignatureForSelector:selector] ];
328 [invocation setSelector:selector];
329 [invocation setTarget:self.capturer];
330 BOOL arg = true;
331 [invocation setArgument:(void *)&arg atIndex:2];
332 [invocation invoke];
333 }
334
335 [self.capturer captureOutput:self.capturer.captureSession.outputs[0]
336 didOutputSampleBuffer:sampleBuffer
337 fromConnection:self.captureConnectionMock];
338
339 [self.delegateMock verify];
340
341 [(id)currentDeviceMock stopMocking];
342 currentDeviceMock = nil;
343 [classMock stopMocking];
344 classMock = nil;
345 CFRelease(sampleBuffer);
346 #endif
347 }
348
221 @end 349 @end
222 350
223 // TODO(kthelgason): Reenable these tests on simulator. 351 // TODO(kthelgason): Reenable these tests on simulator.
224 // See bugs.webrtc.org/7813 352 // See bugs.webrtc.org/7813
225 #if TARGET_IPHONE_SIMULATOR 353 #if TARGET_IPHONE_SIMULATOR
226 #define MAYBE_TEST(f, name) TEST(f, DISABLED_##name) 354 #define MAYBE_TEST(f, name) TEST(f, DISABLED_##name)
227 #else 355 #else
228 #define MAYBE_TEST TEST 356 #define MAYBE_TEST TEST
229 #endif 357 #endif
230 358
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 [test testDelegateCallbackNotCalledWhenInvalidBuffer]; 390 [test testDelegateCallbackNotCalledWhenInvalidBuffer];
263 [test tearDown]; 391 [test tearDown];
264 } 392 }
265 393
266 MAYBE_TEST(RTCCameraVideoCapturerTests, DelegateCallbackWithValidBufferAndOrient ationUpdate) { 394 MAYBE_TEST(RTCCameraVideoCapturerTests, DelegateCallbackWithValidBufferAndOrient ationUpdate) {
267 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ; 395 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
268 [test setup]; 396 [test setup];
269 [test testDelegateCallbackWithValidBufferAndOrientationUpdate]; 397 [test testDelegateCallbackWithValidBufferAndOrientationUpdate];
270 [test tearDown]; 398 [test tearDown];
271 } 399 }
400
401 MAYBE_TEST(RTCCameraVideoCapturerTests, RotationCameraBackLandscapeLeft) {
402 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
403 [test setup];
404 [test testRotationCamera:AVCaptureDevicePositionBack
405 withOrientation:UIDeviceOrientationLandscapeLeft];
406 [test tearDown];
407 }
408
409 MAYBE_TEST(RTCCameraVideoCapturerTests, RotationCameraFrontLandscapeLeft) {
410 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
411 [test setup];
412 [test testRotationCamera:AVCaptureDevicePositionFront
413 withOrientation:UIDeviceOrientationLandscapeLeft];
414 [test tearDown];
415 }
416
417 MAYBE_TEST(RTCCameraVideoCapturerTests, RotationCameraBackLandscapeRight) {
418 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
419 [test setup];
420 [test testRotationCamera:AVCaptureDevicePositionBack
421 withOrientation:UIDeviceOrientationLandscapeRight];
422 [test tearDown];
423 }
424
425 MAYBE_TEST(RTCCameraVideoCapturerTests, RotationCameraFrontLandscapeRight) {
426 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
427 [test setup];
428 [test testRotationCamera:AVCaptureDevicePositionFront
429 withOrientation:UIDeviceOrientationLandscapeRight];
430 [test tearDown];
431 }
432
433 MAYBE_TEST(RTCCameraVideoCapturerTests, RotationCameraFrame) {
434 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
435 [test setup];
436 [test testRotationFrame];
437 [test tearDown];
438 }
439
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698