diff options
Diffstat (limited to 'test/Analysis/retain-release.m')
-rw-r--r-- | test/Analysis/retain-release.m | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m index f0d91e34c1b06..b883a86602ba3 100644 --- a/test/Analysis/retain-release.m +++ b/test/Analysis/retain-release.m @@ -1247,6 +1247,108 @@ CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height, pixelBufferAttributes, pixelBufferOut) ; } +#pragma clang arc_cf_code_audited begin +typedef struct SomeOpaqueStruct *CMSampleBufferRef; +CVImageBufferRef _Nonnull CMSampleBufferGetImageBuffer(CMSampleBufferRef _Nonnull sbuf); +#pragma clang arc_cf_code_audited end + +CVBufferRef _Nullable CVBufferRetain(CVBufferRef _Nullable buffer); +void CVBufferRelease(CF_CONSUMED CVBufferRef _Nullable buffer); + +void testCVPrefixRetain(CMSampleBufferRef sbuf) { + // Make sure RetainCountChecker treats CVFooRetain() as a CF-style retain. + CVPixelBufferRef pixelBuf = CMSampleBufferGetImageBuffer(sbuf); + CVBufferRetain(pixelBuf); + CVBufferRelease(pixelBuf); // no-warning + + + // Make sure result of CVFooRetain() is the same as its argument. + CVPixelBufferRef pixelBufAlias = CVBufferRetain(pixelBuf); + CVBufferRelease(pixelBufAlias); // no-warning +} + +typedef signed long SInt32; +typedef SInt32 OSStatus; +typedef FourCharCode CMVideoCodecType; + + +typedef UInt32 VTEncodeInfoFlags; enum { + kVTEncodeInfo_Asynchronous = 1UL << 0, + kVTEncodeInfo_FrameDropped = 1UL << 1, +}; +typedef struct +{ + int ignore; +} CMTime; + + +typedef void (*VTCompressionOutputCallback)( + void * _Nullable outputCallbackRefCon, + void * _Nullable sourceFrameRefCon, + OSStatus status, + VTEncodeInfoFlags infoFlags, + _Nullable CMSampleBufferRef sampleBuffer ); + +typedef struct OpaqueVTCompressionSession* VTCompressionSessionRef; + +extern OSStatus +VTCompressionSessionCreate(_Nullable CFAllocatorRef allocator, + int32_t width, + int32_t height, + CMVideoCodecType codecType, + _Nullable CFDictionaryRef encoderSpecification, + _Nullable CFDictionaryRef sourceImageBufferAttributes, + _Nullable CFAllocatorRef compressedDataAllocator, + _Nullable VTCompressionOutputCallback outputCallback, + void * _Nullable outputCallbackRefCon, + CF_RETURNS_RETAINED _Nullable VTCompressionSessionRef * _Nonnull compressionSessionOut); + +extern OSStatus +VTCompressionSessionEncodeFrame( + _Nonnull VTCompressionSessionRef session, + _Nonnull CVImageBufferRef imageBuffer, + CMTime presentationTimeStamp, + CMTime duration, + _Nullable CFDictionaryRef frameProperties, + void * _Nullable sourceFrameRefCon, + VTEncodeInfoFlags * _Nullable infoFlagsOut); + +OSStatus test_VTCompressionSessionCreateAndEncode_CallbackReleases( + _Nullable CFAllocatorRef allocator, + int32_t width, + int32_t height, + CMVideoCodecType codecType, + _Nullable CFDictionaryRef encoderSpecification, + _Nullable CFDictionaryRef sourceImageBufferAttributes, + _Nullable CFAllocatorRef compressedDataAllocator, + _Nullable VTCompressionOutputCallback outputCallback, + + _Nonnull CVImageBufferRef imageBuffer, + CMTime presentationTimeStamp, + CMTime duration, + _Nullable CFDictionaryRef frameProperties +) { + + // The outputCallback is passed both contexts and so can release either. + NSNumber *contextForCreate = [[NSNumber alloc] initWithInt:5]; // no-warning + NSNumber *contextForEncode = [[NSNumber alloc] initWithInt:6]; // no-warning + + VTCompressionSessionRef session = 0; + OSStatus status = VTCompressionSessionCreate(allocator, + width, height, codecType, encoderSpecification, + sourceImageBufferAttributes, + compressedDataAllocator, outputCallback, contextForCreate, + &session); + + VTEncodeInfoFlags encodeInfoFlags; + + status = VTCompressionSessionEncodeFrame(session, imageBuffer, + presentationTimeStamp, duration, frameProperties, contextForEncode, + &encodeInfoFlags); + + return status; +} + //===----------------------------------------------------------------------===// // <rdar://problem/7358899> False leak associated with // CGBitmapContextCreateWithData |