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

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: Renamed RTCCameraVideoCapturer.mm back to RTCCameraVideoCapturer.m. 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
11 #import <OCMock/OCMock.h> 11 #import <OCMock/OCMock.h>
12 12
13 #if TARGET_OS_IPHONE 13 #if TARGET_OS_IPHONE
14 #import <UIKit/UIKit.h> 14 #import <UIKit/UIKit.h>
15 #endif 15 #endif
16 16
17 #include "webrtc/rtc_base/gunit.h" 17 #include "webrtc/rtc_base/gunit.h"
18 18
19 #import <WebRTC/RTCCameraVideoCapturer.h> 19 #import <WebRTC/RTCCameraVideoCapturer.h>
20 #import <WebRTC/RTCDispatcher.h> 20 #import <WebRTC/RTCDispatcher.h>
21 #import <WebRTC/RTCVideoFrame.h> 21 #import <WebRTC/RTCVideoFrame.h>
22 #import "AVCaptureSession+Device.h"
22 23
23 #if TARGET_OS_IPHONE 24 #if TARGET_OS_IPHONE
24 // Helper method. 25 // Helper method.
25 CMSampleBufferRef createTestSampleBufferRef() { 26 CMSampleBufferRef createTestSampleBufferRef() {
26 27
27 // This image is already in the testing bundle. 28 // This image is already in the testing bundle.
28 UIImage *image = [UIImage imageNamed:@"Default.png"]; 29 UIImage *image = [UIImage imageNamed:@"Default.png"];
29 CGSize size = image.size; 30 CGSize size = image.size;
30 CGImageRef imageRef = [image CGImage]; 31 CGImageRef imageRef = [image CGImage];
31 32
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 [self.delegateMock verify]; 212 [self.delegateMock verify];
212 213
213 [(id)currentDeviceMock stopMocking]; 214 [(id)currentDeviceMock stopMocking];
214 currentDeviceMock = nil; 215 currentDeviceMock = nil;
215 [classMock stopMocking]; 216 [classMock stopMocking];
216 classMock = nil; 217 classMock = nil;
217 CFRelease(sampleBuffer); 218 CFRelease(sampleBuffer);
218 #endif 219 #endif
219 } 220 }
220 221
222 - (void)testRotationCamera:(AVCaptureDevicePosition)camera
223 withOrientation:(UIDeviceOrientation)deviceOrientation {
224 #if TARGET_OS_IPHONE
225 // Mock the AVCaptureConnection as we will get the camera position from the co nnection's
226 // input ports.
227 AVCaptureDeviceInput *inputPortMock = OCMClassMock([AVCaptureDeviceInput class ]);
228 AVCaptureInputPort *captureInputPort = OCMClassMock([AVCaptureInputPort class] );
229 NSArray *inputPortsArrayMock = @[captureInputPort];
230 AVCaptureDevice *captureDeviceMock = OCMClassMock([AVCaptureDevice class]);
231 OCMStub(((AVCaptureConnection *)self.captureConnectionMock).inputPorts).
232 andReturn(inputPortsArrayMock);
233 OCMStub(captureInputPort.input).andReturn(inputPortMock);
234 OCMStub(inputPortMock.device).andReturn(captureDeviceMock);
235 OCMStub(captureDeviceMock.position).andReturn(camera);
236
237 // UpsideDown -> RTCVideoRotation_0.
238 UIDevice *currentDeviceMock = OCMClassMock([UIDevice class]);
239 OCMStub(currentDeviceMock.orientation).andReturn(deviceOrientation);
240 id classMock = OCMClassMock([UIDevice class]);
241 OCMStub([classMock currentDevice]).andReturn(currentDeviceMock);
242
243 CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
244
245 [[self.delegateMock expect] capturer:self.capturer
246 didCaptureVideoFrame:[OCMArg checkWithBlock:^BOOL(RTCVideoFram e *expectedFrame) {
247 if (camera == AVCaptureDevicePositionFront) {
248 if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
249 EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_180);
250 } else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
251 EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_0);
252 }
253 } else if (camera == AVCaptureDevicePositionBack) {
254 if (deviceOrientation == UIDeviceOrientationLandscapeLeft) {
255 EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_0);
256 } else if (deviceOrientation == UIDeviceOrientationLandscapeRight) {
257 EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_180);
258 }
259 }
260 return YES;
261 }]];
262
263 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
264 [center postNotificationName:UIDeviceOrientationDidChangeNotification object:n il];
265
266 // We need to wait for the dispatch to finish.
267 WAIT(0, 1000);
268
269 [self.capturer captureOutput:self.capturer.captureSession.outputs[0]
270 didOutputSampleBuffer:sampleBuffer
271 fromConnection:self.captureConnectionMock];
272
273 [self.delegateMock verify];
274
275 [(id)currentDeviceMock stopMocking];
276 currentDeviceMock = nil;
277 [classMock stopMocking];
278 classMock = nil;
279 CFRelease(sampleBuffer);
280 #endif
281 }
282
283 - (void)testImageExif {
284 #if TARGET_OS_IPHONE
285 CMSampleBufferRef sampleBuffer = createTestSampleBufferRef();
286 CFMutableDictionaryRef exif = CFDictionaryCreateMutable(kCFAllocatorDefault, 0 , NULL, NULL);
287 CFDictionarySetValue(exif, CFSTR("LensModel"), CFSTR("iPhone SE back camera 4. 15mm f/2.2"));
288 CMSetAttachment(sampleBuffer, CFSTR("{Exif}"), exif, kCMAttachmentMode_ShouldP ropagate);
289
290 AVCaptureDevicePosition cameraPosition = [AVCaptureSession
291 devicePositionForSampleBuffer:sample Buffer];
292 EXPECT_EQ(cameraPosition, AVCaptureDevicePositionBack);
293 #endif
294 }
295
221 @end 296 @end
222 297
223 // TODO(kthelgason): Reenable these tests on simulator. 298 // TODO(kthelgason): Reenable these tests on simulator.
224 // See bugs.webrtc.org/7813 299 // See bugs.webrtc.org/7813
225 #if TARGET_IPHONE_SIMULATOR 300 #if TARGET_IPHONE_SIMULATOR
226 #define MAYBE_TEST(f, name) TEST(f, DISABLED_##name) 301 #define MAYBE_TEST(f, name) TEST(f, DISABLED_##name)
227 #else 302 #else
228 #define MAYBE_TEST TEST 303 #define MAYBE_TEST TEST
229 #endif 304 #endif
230 305
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 [test testDelegateCallbackNotCalledWhenInvalidBuffer]; 337 [test testDelegateCallbackNotCalledWhenInvalidBuffer];
263 [test tearDown]; 338 [test tearDown];
264 } 339 }
265 340
266 MAYBE_TEST(RTCCameraVideoCapturerTests, DelegateCallbackWithValidBufferAndOrient ationUpdate) { 341 MAYBE_TEST(RTCCameraVideoCapturerTests, DelegateCallbackWithValidBufferAndOrient ationUpdate) {
267 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ; 342 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
268 [test setup]; 343 [test setup];
269 [test testDelegateCallbackWithValidBufferAndOrientationUpdate]; 344 [test testDelegateCallbackWithValidBufferAndOrientationUpdate];
270 [test tearDown]; 345 [test tearDown];
271 } 346 }
347
348 MAYBE_TEST(RTCCameraVideoCapturerTests, RotationCameraBackLandscapeLeft) {
349 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
350 [test setup];
351 [test testRotationCamera:AVCaptureDevicePositionBack
352 withOrientation:UIDeviceOrientationLandscapeLeft];
353 [test tearDown];
354 }
355
356 MAYBE_TEST(RTCCameraVideoCapturerTests, RotationCameraFrontLandscapeLeft) {
357 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
358 [test setup];
359 [test testRotationCamera:AVCaptureDevicePositionFront
360 withOrientation:UIDeviceOrientationLandscapeLeft];
361 [test tearDown];
362 }
363
364 MAYBE_TEST(RTCCameraVideoCapturerTests, RotationCameraBackLandscapeRight) {
365 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
366 [test setup];
367 [test testRotationCamera:AVCaptureDevicePositionBack
368 withOrientation:UIDeviceOrientationLandscapeRight];
369 [test tearDown];
370 }
371
372 MAYBE_TEST(RTCCameraVideoCapturerTests, RotationCameraFrontLandscapeRight) {
373 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
374 [test setup];
375 [test testRotationCamera:AVCaptureDevicePositionFront
376 withOrientation:UIDeviceOrientationLandscapeRight];
377 [test tearDown];
378 }
379
380 MAYBE_TEST(RTCCameraVideoCapturerTests, ImageExif) {
381 RTCCameraVideoCapturerTests *test = [[RTCCameraVideoCapturerTests alloc] init] ;
382 [test setup];
383 [test testImageExif];
384 [test tearDown];
385 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698