Index: webrtc/sdk/objc/Framework/Classes/Video/RTCImageHelper.mm |
diff --git a/webrtc/sdk/objc/Framework/Classes/Video/RTCImageHelper.mm b/webrtc/sdk/objc/Framework/Classes/Video/RTCImageHelper.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8f348f11b7771b8c918896dece8ef757f291b6c0 |
--- /dev/null |
+++ b/webrtc/sdk/objc/Framework/Classes/Video/RTCImageHelper.mm |
@@ -0,0 +1,51 @@ |
+/* |
+ * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+#import "RTCImageHelper.h" |
tkchin_webrtc
2017/07/24 21:30:37
nit: blank line before #import
jtt_webrtc
2017/07/24 22:29:51
Done.
|
+ |
+BOOL CFStringContainsString(CFStringRef theString, CFStringRef stringToFind) { |
+ CFRange foundRange; |
tkchin_webrtc
2017/07/24 21:30:37
nit: always initialize vars
probably set length to
jtt_webrtc
2017/07/24 22:29:51
Since it's not used, I'll pass in nil.
|
+ return CFStringFindWithOptions(theString, |
+ stringToFind, |
+ CFRangeMake(0, CFStringGetLength(theString)), |
+ kCFCompareCaseInsensitive, |
+ &foundRange); |
+} |
+ |
+@implementation RTCImageHelper |
+ |
++ (AVCaptureDevicePosition)cameraFromSampleBuffer:(CMSampleBufferRef)sampleBuffer { |
+ // Check the image's EXIF for the actual camera the image came. |
+ AVCaptureDevicePosition cameraPosition = AVCaptureDevicePositionUnspecified; |
+ CFDictionaryRef attachments = CMCopyDictionaryOfAttachments( |
+ kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate); |
+ if (attachments) { |
+ int size = CFDictionaryGetCount(attachments); |
+ if (size > 0) { |
+ CFDictionaryRef cfExifDictVal = NULL; |
tkchin_webrtc
2017/07/24 21:30:37
nit: nullptr
jtt_webrtc
2017/07/24 22:29:51
Using nil as nullptr isn't defined here.
|
+ if (CFDictionaryGetValueIfPresent( |
+ attachments, (const void *)CFSTR("{Exif}"), (const void **)&cfExifDictVal)) { |
tkchin_webrtc
2017/07/24 21:30:37
Consider declaring NSString * and toll bridge to C
tkchin_webrtc
2017/07/24 21:30:37
does the return val need to be released? what are
jtt_webrtc
2017/07/24 22:29:51
Retain count on the returned value is 1. So it is
jtt_webrtc
2017/07/24 22:29:51
CFSTR calls __builtin___CFStringMakeConstantString
|
+ CFStringRef cfLensModelStrVal; |
+ if (CFDictionaryGetValueIfPresent(cfExifDictVal, |
+ (const void *)CFSTR("LensModel"), |
tkchin_webrtc
2017/07/24 21:30:37
similarly here
jtt_webrtc
2017/07/24 22:29:51
See above.
|
+ (const void **)&cfLensModelStrVal)) { |
+ if (CFStringContainsString(cfLensModelStrVal, CFSTR("front"))) { |
+ cameraPosition = AVCaptureDevicePositionFront; |
+ } else if (CFStringContainsString(cfLensModelStrVal, CFSTR("back"))) { |
+ cameraPosition = AVCaptureDevicePositionBack; |
+ } |
+ } |
+ } |
+ } |
+ CFRelease(attachments); |
+ } |
+ return cameraPosition; |
+} |
+ |
+@end |