File tree Expand file tree Collapse file tree
iOS/APIExample/Common/Utils
macOS/APIExample/Commons/Utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ + (UIImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
2424 unsigned char * NV12buf = (unsigned char *)malloc (size);
2525 [self yuv420p_to_nv12: buf nv12: NV12buf width: width height: height];
2626
27+ free (buf);
28+
2729 int w = width;
2830 int h = height;
2931 NSDictionary *pixelAttributes = @{(NSString *)kCVPixelBufferIOSurfacePropertiesKey :@{}};
@@ -36,6 +38,7 @@ + (UIImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
3638 &pixelBuffer);
3739 if (result != kCVReturnSuccess ) {
3840 NSLog (@" Unable to create cvpixelbuffer %d " , result);
41+ free (NV12buf);
3942 return nil ;
4043 }
4144
@@ -58,11 +61,11 @@ + (UIImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
5861 CGImageRef videoImage = [temporaryContext createCGImage: coreImage
5962 fromRect: CGRectMake (0 , 0 , w, h)];
6063
61- UIImage *finalImage = [[UIImage alloc ] initWithCGImage: videoImage
62- scale: 1.0
63- orientation: UIImageOrientationRight];
64+ UIImage *finalImage = [[UIImage alloc ] initWithCGImage: videoImage];
6465 CVPixelBufferRelease (pixelBuffer);
6566 CGImageRelease (videoImage);
67+
68+ free (NV12buf);
6669 return finalImage;
6770}
6871
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ + (NSImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
2525 unsigned char * NV12buf = (unsigned char *)malloc (size);
2626 [self yuv420p_to_nv12: buf nv12: NV12buf width: width height: height];
2727
28+ free (buf);
29+
2830 int w = width;
2931 int h = height;
3032 NSDictionary *pixelAttributes = @{(NSString *)kCVPixelBufferIOSurfacePropertiesKey :@{}};
@@ -37,6 +39,7 @@ + (NSImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
3739 &pixelBuffer);
3840 if (result != kCVReturnSuccess ) {
3941 NSLog (@" Unable to create cvpixelbuffer %d " , result);
42+ free (NV12buf);
4043 return nil ;
4144 }
4245
@@ -62,6 +65,8 @@ + (NSImage *)i420ToImage:(void *)srcY srcU:(void *)srcU srcV:(void *)srcV width:
6265 NSImage *finalImage = [[NSImage alloc ] initWithCGImage: videoImage size: NSMakeSize (width, height)];
6366 CVPixelBufferRelease (pixelBuffer);
6467 CGImageRelease (videoImage);
68+
69+ free (NV12buf);
6570 return finalImage;
6671}
6772
You can’t perform that action at this time.
0 commit comments