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

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: 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;
magjed_webrtc 2016/11/24 13:42:59 Is this really a fix? The previous implementation
daniela-webrtc 2016/11/25 08:58:15 Ah you are right! I got i mixed up. Basically we w
26 } 26 }
27 27
28 namespace webrtc {
magjed_webrtc 2016/11/24 13:42:59 Why have you moved the namespace up here? Function
daniela-webrtc 2016/11/25 08:58:15 Done.
28 // Returns filtered array of device formats based on predefined constraints our 29 // Returns filtered array of device formats based on predefined constraints our
29 // stack imposes. 30 // stack imposes.
30 static NSArray<AVCaptureDeviceFormat*>* GetEligibleDeviceFormats( 31 NSArray<AVCaptureDeviceFormat*>* GetEligibleDeviceFormats(
31 const AVCaptureDevice* device, 32 const AVCaptureDevice* device,
32 int supportedFps) { 33 int supportedFps) {
33 NSMutableArray<AVCaptureDeviceFormat*>* eligibleDeviceFormats = 34 NSMutableArray<AVCaptureDeviceFormat*>* eligibleDeviceFormats =
34 [NSMutableArray array]; 35 [NSMutableArray array];
35 36
36 for (AVCaptureDeviceFormat* format in device.formats) { 37 for (AVCaptureDeviceFormat* format in device.formats) {
37 // Filter out subTypes that we currently don't support in the stack 38 // Filter out subTypes that we currently don't support in the stack
38 FourCharCode mediaSubType = 39 FourCharCode mediaSubType =
39 CMFormatDescriptionGetMediaSubType(format.formatDescription); 40 CMFormatDescriptionGetMediaSubType(format.formatDescription);
40 if (!IsMediaSubTypeSupported(mediaSubType)) { 41 if (!IsMediaSubTypeSupported(mediaSubType)) {
41 continue; 42 continue;
42 } 43 }
43 44
44 // Filter out frame rate ranges that we currently don't support in the stack 45 // Filter out frame rate ranges that we currently don't support in the stack
45 for (AVFrameRateRange* frameRateRange in format.videoSupportedFrameRateRange s) { 46 for (AVFrameRateRange* frameRateRange in format.videoSupportedFrameRateRange s) {
46 if (IsFrameRateWithinRange(supportedFps, frameRateRange)) { 47 if (IsFrameRateWithinRange(supportedFps, frameRateRange)) {
47 [eligibleDeviceFormats addObject:format]; 48 [eligibleDeviceFormats addObject:format];
48 break; 49 break;
49 } 50 }
50 } 51 }
51 } 52 }
52 53
53 return [eligibleDeviceFormats copy]; 54 return [eligibleDeviceFormats copy];
54 } 55 }
55 56
56 // Mapping from cricket::VideoFormat to AVCaptureDeviceFormat. 57 // Mapping from cricket::VideoFormat to AVCaptureDeviceFormat.
57 static AVCaptureDeviceFormat* GetDeviceFormatForVideoFormat( 58 AVCaptureDeviceFormat* GetDeviceFormatForVideoFormat(
58 const AVCaptureDevice* device, 59 const AVCaptureDevice* device,
59 const cricket::VideoFormat& videoFormat) { 60 const cricket::VideoFormat& videoFormat) {
60 AVCaptureDeviceFormat* desiredDeviceFormat = nil; 61 AVCaptureDeviceFormat* desiredDeviceFormat = nil;
61 NSArray<AVCaptureDeviceFormat*>* eligibleFormats = 62 NSArray<AVCaptureDeviceFormat*>* eligibleFormats =
62 GetEligibleDeviceFormats(device, videoFormat.framerate()); 63 GetEligibleDeviceFormats(device, videoFormat.framerate());
63 64
64 for (AVCaptureDeviceFormat* deviceFormat in eligibleFormats) { 65 for (AVCaptureDeviceFormat* deviceFormat in eligibleFormats) {
65 CMVideoDimensions dimension = 66 CMVideoDimensions dimension =
66 CMVideoFormatDescriptionGetDimensions(deviceFormat.formatDescription); 67 CMVideoFormatDescriptionGetDimensions(deviceFormat.formatDescription);
67 FourCharCode mediaSubType = 68 FourCharCode mediaSubType =
68 CMFormatDescriptionGetMediaSubType(deviceFormat.formatDescription); 69 CMFormatDescriptionGetMediaSubType(deviceFormat.formatDescription);
69 70
70 if (videoFormat.width == dimension.width && 71 if (videoFormat.width == dimension.width &&
71 videoFormat.height == dimension.height) { 72 videoFormat.height == dimension.height) {
72 if (mediaSubType == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) { 73 if (mediaSubType == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) {
73 // This is the preferred format so no need to wait for better option. 74 // This is the preferred format so no need to wait for better option.
74 return deviceFormat; 75 return deviceFormat;
75 } else { 76 } else {
76 // This is good candidate, but let's wait for something better. 77 // This is good candidate, but let's wait for something better.
77 desiredDeviceFormat = deviceFormat; 78 desiredDeviceFormat = deviceFormat;
78 } 79 }
79 } 80 }
80 } 81 }
81 82
82 return desiredDeviceFormat; 83 return desiredDeviceFormat;
83 } 84 }
84 namespace webrtc { 85
85 std::set<cricket::VideoFormat> GetSupportedVideoFormatsForDevice( 86 std::set<cricket::VideoFormat> GetSupportedVideoFormatsForDevice(
86 AVCaptureDevice* device) { 87 AVCaptureDevice* device) {
87 std::set<cricket::VideoFormat> supportedFormats; 88 std::set<cricket::VideoFormat> supportedFormats;
88 89
89 NSArray<AVCaptureDeviceFormat*>* eligibleFormats = 90 NSArray<AVCaptureDeviceFormat*>* eligibleFormats =
90 GetEligibleDeviceFormats(device, kFramesPerSecond); 91 GetEligibleDeviceFormats(device, kFramesPerSecond);
91 92
92 for (AVCaptureDeviceFormat* deviceFormat in eligibleFormats) { 93 for (AVCaptureDeviceFormat* deviceFormat in eligibleFormats) {
93 CMVideoDimensions dimension = 94 CMVideoDimensions dimension =
94 CMVideoFormatDescriptionGetDimensions(deviceFormat.formatDescription); 95 CMVideoFormatDescriptionGetDimensions(deviceFormat.formatDescription);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } else { 127 } else {
127 RTCLogError(@"Failed to lock device %@. Error: %@", device, error.userInfo); 128 RTCLogError(@"Failed to lock device %@. Error: %@", device, error.userInfo);
128 success = false; 129 success = false;
129 } 130 }
130 [session commitConfiguration]; 131 [session commitConfiguration];
131 132
132 return success; 133 return success;
133 } 134 }
134 135
135 } // namespace webrtc 136 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698