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

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/avfoundationformatmapper.mm

Issue 2526813002: Add unit tests for avfoundation format mapper functions and fix wrong implementation. (Closed)
Patch Set: Address review comments Created 4 years 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 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 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 #include "avfoundationformatmapper.h" 11 #include "avfoundationformatmapper.h"
12 12
13 #import "WebRTC/RTCLogging.h" 13 #import "WebRTC/RTCLogging.h"
14 14
15 // TODO(denicija): add support for higher frame rates. 15 // TODO(denicija): add support for higher frame rates.
16 // See http://crbug/webrtc/6355 for more info. 16 // See http://crbug/webrtc/6355 for more info.
17 static const int kFramesPerSecond = 30; 17 static const int kFramesPerSecond = 30;
18 18
19 static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) { 19 static inline BOOL IsMediaSubTypeSupported(FourCharCode mediaSubType) {
20 return (mediaSubType == kCVPixelFormatType_420YpCbCr8PlanarFullRange || 20 return (mediaSubType == kCVPixelFormatType_420YpCbCr8PlanarFullRange ||
21 mediaSubType == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange); 21 mediaSubType == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange);
22 } 22 }
23 23
24 static inline BOOL IsFrameRateWithinRange(int fps, AVFrameRateRange* range) { 24 static inline BOOL IsFrameRateWithinRange(int fps, AVFrameRateRange* range) {
25 return range.minFrameRate <= fps && range.maxFrameRate >= fps; 25 return range.minFrameRate <= fps && range.maxFrameRate >= fps;
26 } 26 }
27 27
28 // Returns filtered array of device formats based on predefined constraints our 28 // Returns filtered array of device formats based on predefined constraints our
29 // stack imposes. 29 // stack imposes.
30 static NSArray<AVCaptureDeviceFormat*>* GetEligibleDeviceFormats( 30 NSArray<AVCaptureDeviceFormat*>* GetEligibleDeviceFormats(
magjed_webrtc 2016/11/28 12:21:23 You are not allowed to expose implementation detai
31 const AVCaptureDevice* device, 31 const AVCaptureDevice* device,
32 int supportedFps) { 32 int supportedFps) {
33 NSMutableArray<AVCaptureDeviceFormat*>* eligibleDeviceFormats = 33 NSMutableArray<AVCaptureDeviceFormat*>* eligibleDeviceFormats =
34 [NSMutableArray array]; 34 [NSMutableArray array];
35 35
36 for (AVCaptureDeviceFormat* format in device.formats) { 36 for (AVCaptureDeviceFormat* format in device.formats) {
37 // Filter out subTypes that we currently don't support in the stack 37 // Filter out subTypes that we currently don't support in the stack
38 FourCharCode mediaSubType = 38 FourCharCode mediaSubType =
39 CMFormatDescriptionGetMediaSubType(format.formatDescription); 39 CMFormatDescriptionGetMediaSubType(format.formatDescription);
40 if (!IsMediaSubTypeSupported(mediaSubType)) { 40 if (!IsMediaSubTypeSupported(mediaSubType)) {
41 continue; 41 continue;
42 } 42 }
43 43
44 // Filter out frame rate ranges that we currently don't support in the stack 44 // Filter out frame rate ranges that we currently don't support in the stack
45 for (AVFrameRateRange* frameRateRange in format.videoSupportedFrameRateRange s) { 45 for (AVFrameRateRange* frameRateRange in format.videoSupportedFrameRateRange s) {
46 if (IsFrameRateWithinRange(supportedFps, frameRateRange)) { 46 if (IsFrameRateWithinRange(supportedFps, frameRateRange)) {
47 [eligibleDeviceFormats addObject:format]; 47 [eligibleDeviceFormats addObject:format];
48 break; 48 break;
49 } 49 }
50 } 50 }
51 } 51 }
52 52
53 return [eligibleDeviceFormats copy]; 53 return [eligibleDeviceFormats copy];
54 } 54 }
55 55
56 // Mapping from cricket::VideoFormat to AVCaptureDeviceFormat. 56 // Mapping from cricket::VideoFormat to AVCaptureDeviceFormat.
57 static AVCaptureDeviceFormat* GetDeviceFormatForVideoFormat( 57 AVCaptureDeviceFormat* GetDeviceFormatForVideoFormat(
58 const AVCaptureDevice* device, 58 const AVCaptureDevice* device,
59 const cricket::VideoFormat& videoFormat) { 59 const cricket::VideoFormat& videoFormat) {
60 AVCaptureDeviceFormat* desiredDeviceFormat = nil; 60 AVCaptureDeviceFormat* desiredDeviceFormat = nil;
61 NSArray<AVCaptureDeviceFormat*>* eligibleFormats = 61 NSArray<AVCaptureDeviceFormat*>* eligibleFormats =
62 GetEligibleDeviceFormats(device, videoFormat.framerate()); 62 GetEligibleDeviceFormats(device, videoFormat.framerate());
63 63
64 for (AVCaptureDeviceFormat* deviceFormat in eligibleFormats) { 64 for (AVCaptureDeviceFormat* deviceFormat in eligibleFormats) {
65 CMVideoDimensions dimension = 65 CMVideoDimensions dimension =
66 CMVideoFormatDescriptionGetDimensions(deviceFormat.formatDescription); 66 CMVideoFormatDescriptionGetDimensions(deviceFormat.formatDescription);
67 FourCharCode mediaSubType = 67 FourCharCode mediaSubType =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } else { 126 } else {
127 RTCLogError(@"Failed to lock device %@. Error: %@", device, error.userInfo); 127 RTCLogError(@"Failed to lock device %@. Error: %@", device, error.userInfo);
128 success = false; 128 success = false;
129 } 129 }
130 [session commitConfiguration]; 130 [session commitConfiguration];
131 131
132 return success; 132 return success;
133 } 133 }
134 134
135 } // namespace webrtc 135 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698