From b3c9d3da8f3466a1969c2bbee308cb57105720f6 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 22 Sep 2021 11:53:38 -0400 Subject: [PATCH] [ios] Fix two rtc_unittests that fail when using lld as linker setExif: would create a CFDictionary using NULL for keyCallBacks and valueCallBacks. This has the effect of comparing the keys of the dictionary by pointer instead of by value. With ld64, this works because it always dedupes identical constant CFSTR("foo") literal, but lld currently doesn't do this. Using kCFTypeDictionaryKeyCallBacks and kCFTypeDictionaryValueCallBacks fixes the problem with lld and is "more correct" in general: Now the dictionary would work with computed CFStrings too, it shows up better in CFShow() output, etc. While here, also fix a memory leak in setExif:. Bug: chromium:1251763 Change-Id: I43c96d2189a4a77fe3bd0dfb3e33623925b0f900 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/232760 Reviewed-by: Harald Alvestrand Commit-Queue: Nico Weber Cr-Commit-Position: refs/heads/main@{#35067} --- sdk/objc/unittests/RTCCameraVideoCapturerTests.mm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sdk/objc/unittests/RTCCameraVideoCapturerTests.mm b/sdk/objc/unittests/RTCCameraVideoCapturerTests.mm index 34551e5ac8..1d47846dc9 100644 --- a/sdk/objc/unittests/RTCCameraVideoCapturerTests.mm +++ b/sdk/objc/unittests/RTCCameraVideoCapturerTests.mm @@ -20,6 +20,7 @@ #import "components/capturer/RTCCameraVideoCapturer.h" #import "helpers/AVCaptureSession+DevicePosition.h" #import "helpers/RTCDispatcher.h" +#import "helpers/scoped_cftyperef.h" #if TARGET_OS_IPHONE // Helper method. @@ -281,9 +282,10 @@ CMSampleBufferRef createTestSampleBufferRef() { } - (void)setExif:(CMSampleBufferRef)sampleBuffer { - CFMutableDictionaryRef exif = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, NULL); - CFDictionarySetValue(exif, CFSTR("LensModel"), CFSTR("iPhone SE back camera 4.15mm f/2.2")); - CMSetAttachment(sampleBuffer, CFSTR("{Exif}"), exif, kCMAttachmentMode_ShouldPropagate); + rtc::ScopedCFTypeRef exif(CFDictionaryCreateMutable( + kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); + CFDictionarySetValue(exif.get(), CFSTR("LensModel"), CFSTR("iPhone SE back camera 4.15mm f/2.2")); + CMSetAttachment(sampleBuffer, CFSTR("{Exif}"), exif.get(), kCMAttachmentMode_ShouldPropagate); } - (void)testRotationFrame { @@ -307,8 +309,8 @@ CMSampleBufferRef createTestSampleBufferRef() { [[self.delegateMock expect] capturer:self.capturer didCaptureVideoFrame:[OCMArg checkWithBlock:^BOOL(RTC_OBJC_TYPE(RTCVideoFrame) * expectedFrame) { - // Front camera and landscape left should return 180. But the frame says its - // from the back camera, so rotation should be 0. + // Front camera and landscape left should return 180. But the frame's exif + // we add below says its from the back camera, so rotation should be 0. EXPECT_EQ(expectedFrame.rotation, RTCVideoRotation_0); return YES; }]];