Memory Leak CVPixelBufferCreate

LarmeLarme Membre
novembre 2012 modifié dans API UIKit #1
Bonjour tout le monde !



J'ai commencé à  utiliser un peu plus Instruments, et notamment la partie Leak...

J'ai compris pas mal de trucs hier/avant-hier, mais un irréductible résiste !



Il me détecte un leak que je ne comprends pas.



Voici ce qu'il me pointe du doigt :





[/size][/font]<br />
[font=Menlo][size=2]- ([color=#7c1fae]CVPixelBufferRef[/color]) pixelBufferFromCGImage: ([color=#7c1fae]CGImageRef[/color])image  size:([color=#7c1fae]CGSize[/color])imageSize[/size][/font]<br />
[font=Menlo][size=2]{[/size][/font]<br />
[color=#E40000][font=Menlo][size=2][color=#460085]NSLog[/color][color=#000000]([/color]@&quot;Entree dans pixelBufferFromCGIImage&quot;[color=#000000]);[/color][/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]//Settings Options[/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2][color=#000000]	[/color][color=#7c1fae]NSDictionary[/color][color=#000000] *options = [[/color][color=#7c1fae]NSDictionary[/color][color=#000000] [/color]dictionaryWithObjectsAndKeys[color=#000000]:[/color][/size][/font][/color]<br />
[color=#7C1FAE][font=Menlo][size=2][color=#000000]							 [[/color]NSNumber[color=#000000] [/color][color=#460085]numberWithBool[/color][color=#000000]:[/color][color=#cd00a5]YES[/color][color=#000000]], [/color]kCVPixelBufferCGImageCompatibilityKey[color=#000000],[/color][/size][/font][/color]<br />
[color=#7C1FAE][font=Menlo][size=2][color=#000000]							 [[/color]NSNumber[color=#000000] [/color][color=#460085]numberWithBool[/color][color=#000000]:[/color][color=#cd00a5]YES[/color][color=#000000]], [/color]kCVPixelBufferCGBitmapContextCompatibilityKey[color=#000000],[/color][/size][/font][/color]<br />
[font=Menlo][size=2]							 [color=#cd00a5]nil[/color]];[/size][/font]<br />
<br />
[color=#7C1FAE][font=Menlo][size=2]CVPixelBufferRef[color=#000000] pxbuffer = [/color][color=#cd00a5]NULL[/color][color=#000000];[/color][/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]//Creates a single pixel buffer for a given size and pixel format.[/size][/font][/color]<br />
[color=#7C1FAE][font=Menlo][size=2][b]CVReturn[color=#000000] status = [/color][color=#460085]CVPixelBufferCreate[/color][color=#000000]([/color]kCFAllocatorDefault[color=#000000], imageSize.[/color]width[color=#000000],[/color][/b][/size][/font][/color]<br />
[font=Menlo][size=2][b]										  imageSize.[color=#7c1fae]height[/color], [color=#460085]kCVPixelFormatType_32ARGB[/color], ([color=#7c1fae]CFDictionaryRef[/color]) options, [/b][/size][/font]<br />
[font=Menlo][size=2][b]										  &amp;pxbuffer);[/b][/size][/font]<br />
<br />
[color=#E40000][font=Menlo][size=2][color=#460085]NSLog[/color][color=#000000]([/color]@&quot;status : %@&quot;[color=#000000], status);[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	[color=#804623]NSParameterAssert[/color](status == [color=#460085]kCVReturnSuccess[/color] &amp;&amp; pxbuffer &#33;= [color=#cd00a5]NULL[/color]); [color=#008c00]//To Validate[/color][/size][/font]<br />
[font=Menlo][size=2]	[/size][/font]<br />
[color=#460085][font=Menlo][size=2][color=#000000]	[/color]CVPixelBufferLockBaseAddress[color=#000000](pxbuffer, [/color][color=#3800df]0[/color][color=#000000]);[/color][/size][/font][/color]<br />
<br />
[color=#460085][font=Menlo][size=2][color=#000000]	[/color][color=#cd00a5]void[/color][color=#000000] *pxdata = [/color]CVPixelBufferGetBaseAddress[color=#000000](pxbuffer);[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	[/size][/font]<br />
[color=#804623][font=Menlo][size=2]NSParameterAssert[color=#000000](pxdata &#33;= [/color][color=#cd00a5]NULL[/color][color=#000000]); [/color][color=#008c00]//To Validate[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	[/size][/font]<br />
[color=#460085][font=Menlo][size=2][color=#000000]	[/color][color=#7c1fae]CGColorSpaceRef[/color][color=#000000] rgbColorSpace = [/color]CGColorSpaceCreateDeviceRGB[color=#000000]();[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	[color=#7c1fae]CGContextRef[/color] context = [color=#460085]CGBitmapContextCreate[/color](pxdata, imageSize.[color=#7c1fae]width[/color],[/size][/font]<br />
[font=Menlo][size=2]												 imageSize.[color=#7c1fae]height[/color], [color=#3800df]8[/color], [color=#3800df]4[/color]*imageSize.[color=#7c1fae]width[/color], rgbColorSpace, [/size][/font]<br />
[font=Menlo][size=2]												 [color=#460085]kCGImageAlphaNoneSkipFirst[/color]);[/size][/font]<br />
[font=Menlo][size=2]	[/size][/font]<br />
[color=#804623][font=Menlo][size=2]NSParameterAssert[color=#000000](context); [/color][color=#008c00]//To Validate[/color][/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//	CGContextConcatCTM(context, frameTransform);[/size][/font][/color]<br />
<br />
[color=#460085][font=Menlo][size=2]CGContextDrawImage[color=#000000](context, [/color]CGRectMake[color=#000000]([/color][color=#3800df]0[/color][color=#000000], [/color][color=#3800df]0[/color][color=#000000], [/color]CGImageGetWidth[color=#000000](image), [/color][/size][/font][/color]<br />
[font=Menlo][size=2]										   [color=#460085]CGImageGetHeight[/color](image)), image);[/size][/font]<br />
[font=Menlo][size=2]	[/size][/font]<br />
[color=#008C00][font=Menlo][size=2]//Release[/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2]CGColorSpaceRelease[color=#000000](rgbColorSpace);[/color][/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2]CGContextRelease[color=#000000](context);[/color][/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//CVPixelBufferRelease(status);[/size][/font][/color]<br />
<br />
[color=#460085][font=Menlo][size=2][color=#000000]	[/color]CVPixelBufferUnlockBaseAddress[color=#000000](pxbuffer, [/color][color=#3800df]0[/color][color=#000000]);[/color][/size][/font][/color]<br />
[font=Menlo][size=2]	[/size][/font]<br />
[font=Menlo][size=2]	[color=#cd00a5]return[/color] pxbuffer;[/size][/font]<br />
[font=Menlo][size=2]}[/size][/font]<br />




Donc voilà , j'ai mis en gras l'incriminé.







Sinon, je l'appelle ici, et vous comprendrez qu'il me pointe du doit l'appel de cette méthode.






<br />
[color=#008C00][font=Menlo][size=2]/********************************************************************[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]Essential : Returns Boolean[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]Returns True if it totally worked : filed created (does exist)[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]Returns False in the other case[/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]What does it do :[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]Create a movie from images (in a NSMutableArray)[/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]Parameters :[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]monMutableArrayImage : NSMutableArray contening every UIImages[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]path : NSString path where the video will be created/saved[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]withSize : CGSize of the video[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]duration : float of the  duration of the video (seconds)[/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]For Debug :[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]NSLog which UIImage from the NSMutableArray failed[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]NSLog when video is created[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]********************************************************************/[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//-(BOOL)ImagesToVideo:(NSMutableArray *)monMutableArrayImage toPath:(NSString *)path withSize:(CGSize)size framePerSeconds:(int)fps[/size][/font][/color]<br />
[font=Menlo][size=2]-([color=#cd00a5]BOOL[/color])ImagesToVideo:([color=#7c1fae]NSMutableArray[/color] *)monMutableArrayImage toPath:([color=#7c1fae]NSString[/color] *)path withSize:([color=#7c1fae]CGSize[/color])size duration:([color=#cd00a5]float[/color])duree[/size][/font]<br />
[font=Menlo][size=2]{[/size][/font]<br />
[color=#E40000][font=Menlo][size=2][color=#460085]NSLog[/color][color=#000000]([/color]@&quot;Entree dans ImagesToVideo&quot;[color=#000000]);[/color][/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2][color=#cd00a5]int[/color][color=#000000] fps; [/color]//Duration of the video, calculate with the FramePerSecond and number of the UIImages[/size][/font][/color]<br />
[font=Menlo][size=2]fps = monMutableArrayImage.[color=#7c1fae]count[/color]/duree;[/size][/font]<br />
[color=#E40000][font=Menlo][size=2][color=#460085]NSLog[/color][color=#000000]([/color]@&quot;Duration : %f\t Nombre d&#39;images : %d\t, fps : %d&quot;[color=#000000], duree, monMutableArrayImage.[/color][color=#7c1fae]count[/color][color=#000000], fps);[/color][/size][/font][/color]<br />
[font=Menlo][size=2][color=#7c1fae]NSError[/color] *error = [color=#cd00a5]nil[/color];[/size][/font]<br />
[font=Menlo][size=2][color=#7c1fae]NSError[/color] *erreur = [color=#cd00a5]nil[/color];[/size][/font]<br />
<br />
[color=#008C00][font=Menlo][size=2]//If a video exists at path[/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2][color=#cd00a5]if[/color][color=#000000] ([[[/color][color=#7c1fae]NSFileManager[/color][color=#000000] [/color]defaultManager[color=#000000]] [/color]fileExistsAtPath[color=#000000]:path])[/color][/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2][color=#000000][[[/color][color=#7c1fae]NSFileManager[/color][color=#000000] [/color]defaultManager[color=#000000]] [/color]removeItemAtPath[color=#000000]:path [/color]error[color=#000000]:&amp;erreur];[/color][/size][/font][/color]<br />
[font=Menlo][size=2][color=#cd00a5]if[/color] (erreur)[/size][/font]<br />
[color=#E40000][font=Menlo][size=2][color=#460085]NSLog[/color][color=#000000]([/color]@&quot;ErrorDeleting : %@&quot;[color=#000000], erreur);[/color][/size][/font][/color]<br />
<br />
<br />
[color=#008C00][font=Menlo][size=2]//To write media data to a new file of a specified audiovisual container type, such as MPEG-4 file[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:path] [/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//	fileType:AVFileTypeMPEG4 [/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//   error:&amp;error];[/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2][color=#3d8389]videoWriter[/color][color=#000000] = [[[/color][color=#7c1fae]AVAssetWriter[/color][color=#000000] [/color]alloc[color=#000000]] [/color]initWithURL[color=#000000]:[[/color][color=#7c1fae]NSURL[/color][color=#000000] [/color]fileURLWithPath[color=#000000]:path] [/color][/size][/font][/color]<br />
[color=#7C1FAE][font=Menlo][size=2][color=#000000]  [/color][color=#460085]fileType[/color][color=#000000]:[/color]AVFileTypeQuickTimeMovie[color=#000000] [/color][/size][/font][/color]<br />
[font=Menlo][size=2]  [color=#460085]error[/color]:&amp;error];[/size][/font]<br />
<br />
[color=#804623][font=Menlo][size=2]NSParameterAssert[color=#000000]([/color][color=#3d8389]videoWriter[/color][color=#000000]); [/color][color=#008c00]//To Validate[/color][/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]//Settings video[/size][/font][/color]<br />
[color=#7C1FAE][font=Menlo][size=2]NSDictionary[color=#000000] *videoSettings = [[/color]NSDictionary[color=#000000] [/color][color=#460085]dictionaryWithObjectsAndKeys[/color][color=#000000]:[/color]AVVideoCodecH264[color=#000000], [/color][/size][/font][/color]<br />
[font=Menlo][size=2][color=#7c1fae]AVVideoCodecKey[/color], [/size][/font]<br />
[font=Menlo][size=2][[color=#7c1fae]NSNumber[/color] [color=#460085]numberWithInt[/color]:size.[color=#7c1fae]width[/color]], [/size][/font]<br />
[font=Menlo][size=2][color=#7c1fae]AVVideoWidthKey[/color], [/size][/font]<br />
[font=Menlo][size=2][[color=#7c1fae]NSNumber[/color] [color=#460085]numberWithInt[/color]:size.[color=#7c1fae]height[/color]], [/size][/font]<br />
[font=Menlo][size=2][color=#7c1fae]AVVideoHeightKey[/color], [/size][/font]<br />
[font=Menlo][size=2][color=#cd00a5]nil[/color]];[/size][/font]<br />
<br />
[color=#008C00][font=Menlo][size=2]//To append media samples packages as CMSampleBuffer objects or collections of metadata[/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2][color=#3d8389]writerInput[/color][color=#000000] = [[[/color][color=#7c1fae]AVAssetWriterInput[/color][color=#000000] [/color]assetWriterInputWithMediaType[color=#000000]:[/color][color=#7c1fae]AVMediaTypeVideo[/color][color=#000000] [/color]outputSettings[color=#000000]:videoSettings][/color]retain[color=#000000]];[/color][/size][/font][/color]<br />
<br />
[color=#804623][font=Menlo][size=2]NSParameterAssert[color=#000000]([/color][color=#3d8389]writerInput[/color][color=#000000]); [/color][color=#008c00]//To Validate[/color][/size][/font][/color]<br />
[color=#3D8389][font=Menlo][size=2][color=#804623]NSParameterAssert[/color][color=#000000]([[/color]videoWriter[color=#000000] [/color][color=#460085]canAddInput[/color][color=#000000]:[/color]writerInput[color=#000000]]); [/color][color=#008c00]//To Validate[/color][/size][/font][/color]<br />
<br />
[color=#460085][font=Menlo][size=2][color=#3d8389]adaptator[/color][color=#000000] = [[/color][color=#7c1fae]AVAssetWriterInputPixelBufferAdaptor[/color][color=#000000] [/color]assetWriterInputPixelBufferAdaptorWithAssetWriterInput[color=#000000]:[/color][color=#3d8389]writerInput[/color][color=#000000] [/color]sourcePixelBufferAttributes[color=#000000]:[/color][color=#cd00a5]nil[/color][color=#000000]];[/color][/size][/font][/color]<br />
<br />
[color=#3D8389][font=Menlo][size=2][color=#000000][[/color]videoWriter[color=#000000] [/color][color=#460085]addInput[/color][color=#000000]:[/color]writerInput[color=#000000]]; [/color][color=#008c00]//Link between[/color][/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]//Start session[/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2][color=#000000][[/color][color=#3d8389]videoWriter[/color][color=#000000] [/color]startWriting[color=#000000]]; [/color][color=#008c00]//Start[/color][/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2][color=#000000][[/color][color=#3d8389]videoWriter[/color][color=#000000] [/color]startSessionAtSourceTime[color=#000000]:[/color][color=#7c1fae]kCMTimeZero[/color][color=#000000]]; [/color][color=#008c00]//Init time[/color][/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2][color=#7c1fae]CVPixelBufferRef[/color][color=#000000] buffer = [/color][color=#cd00a5]NULL[/color][color=#000000]; [/color]//CVPixelBufferRef : Reference to a CoreVideo Pixel Buffer Object[/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]//Attention, paramètre de size par rapport taille initiale ?[/size][/font][/color]<br />
[font=Menlo][size=2][b]buffer = [[color=#cd00a5]self[/color] [color=#225a5f]pixelBufferFromCGImage[/color]:[[monMutableArrayImage [color=#460085]objectAtIndex[/color]:[color=#3800df]0[/color]] [color=#460085]CGImage[/color]] [color=#225a5f]size[/color]:size];  [/b][/size][/font]<br />
[color=#008C00][font=Menlo][size=2]//Create a pixel buffer from a pixel buffer pool[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//Null : default allocator[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//adaptator.pixelBufferpool : the pixelbuffer pool FOR creating the new pixel buffer[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//&amp;buffer : ouput[/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2]CVPixelBufferPoolCreatePixelBuffer[color=#000000]([/color][color=#cd00a5]NULL[/color][color=#000000], [/color][color=#3d8389]adaptator[/color][color=#000000].[/color][color=#7c1fae]pixelBufferPool[/color][color=#000000], &amp;buffer);[/color][/size][/font][/color]<br />
<br />
[color=#460085][font=Menlo][size=2][color=#000000][[/color][color=#3d8389]adaptator[/color][color=#000000] [/color]appendPixelBuffer[color=#000000]:buffer [/color]withPresentationTime[color=#000000]:[/color][color=#7c1fae]kCMTimeZero[/color][color=#000000]]; [/color][color=#008c00]//append[/color][/size][/font][/color]<br />
[font=Menlo][size=2][color=#cd00a5]int[/color] i = [color=#3800df]1[/color];[/size][/font]<br />
[color=#CD00A5][font=Menlo][size=2]while[color=#000000]([/color][color=#3800df]1[/color][color=#000000])[/color][/size][/font][/color]<br />
[font=Menlo][size=2]{[/size][/font]<br />
[color=#7C1FAE][font=Menlo][size=2][color=#cd00a5]if[/color][color=#000000] ([/color][color=#3d8389]writerInput[/color][color=#000000].[/color]readyForMoreMediaData[color=#000000])[/color][/size][/font][/color]<br />
[font=Menlo][size=2]{[/size][/font]<br />
<br />
[font=Menlo][size=2][color=#7c1fae]CMTime[/color] frameTimer = [color=#460085]CMTimeMake[/color]([color=#3800df]1[/color], fps);[/size][/font]<br />
[font=Menlo][size=2][color=#7c1fae]CMTime[/color] lastTimer = [color=#460085]CMTimeMake[/color](i, fps);[/size][/font]<br />
[font=Menlo][size=2][color=#7c1fae]CMTime[/color] presentTime = [color=#460085]CMTimeAdd[/color](lastTimer, frameTimer);[/size][/font]<br />
<br />
<br />
<br />
[font=Menlo][size=2][color=#cd00a5]if[/color](i &lt; [monMutableArrayImage [color=#460085]count[/color]]) [color=#008c00]//If there are Images left[/color][/size][/font]<br />
[font=Menlo][size=2]{[/size][/font]<br />
<br />
[font=Menlo][size=2][b]buffer = [[color=#cd00a5]self[/color] [color=#225a5f]pixelBufferFromCGImage[/color]:[[monMutableArrayImage [color=#460085]objectAtIndex[/color]:i] [color=#460085]CGImage[/color]] [color=#225a5f]size[/color]:size];[/b][/size][/font]<br />
<br />
[font=Menlo][size=2][color=#cd00a5]if[/color] (buffer)[/size][/font]<br />
[font=Menlo][size=2]{[/size][/font]<br />
[color=#460085][font=Menlo][size=2][color=#000000][[/color][color=#3d8389]adaptator[/color][color=#000000] [/color]appendPixelBuffer[color=#000000]:buffer [/color]withPresentationTime[color=#000000]:presentTime]; [/color][color=#008c00]//append buffer[/color][/size][/font][/color]<br />
[font=Menlo][size=2]i++;[/size][/font]<br />
[font=Menlo][size=2]}[/size][/font]<br />
[font=Menlo][size=2][color=#cd00a5]else[/color][/size][/font]<br />
[font=Menlo][size=2]{[/size][/font]<br />
[color=#E40000][font=Menlo][size=2][color=#460085]NSLog[/color][color=#000000]([/color]@&quot;Error on frame n°%i&quot;[color=#000000], i);[/color][/size][/font][/color]<br />
[font=Menlo][size=2]}[/size][/font]<br />
[font=Menlo][size=2]}[/size][/font]<br />
[color=#008C00][font=Menlo][size=2][color=#cd00a5]else[/color][color=#000000] [/color]//There is no Image left[/size][/font][/color]<br />
[font=Menlo][size=2]{[/size][/font]<br />
[color=#008C00][font=Menlo][size=2]//buffer = NULL;[/size][/font][/color]<br />
[color=#008C00][font=Menlo][size=2]//Finish Session[/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2][color=#000000][[/color][color=#3d8389]writerInput[/color][color=#000000] [/color]markAsFinished[color=#000000]];[/color][/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2][color=#000000][[/color][color=#3d8389]videoWriter[/color][color=#000000] [/color]finishWriting[color=#000000]];[/color][/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]//Release[/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2]CVPixelBufferPoolRelease[color=#000000]([/color][color=#3d8389]adaptator[/color][color=#000000].[/color][color=#7c1fae]pixelBufferPool[/color][color=#000000]);[/color][/size][/font][/color]<br />
[color=#460085][font=Menlo][size=2]CVPixelBufferRelease[color=#000000](buffer);[/color][/size][/font][/color]<br />
[color=#3D8389][font=Menlo][size=2][color=#000000][[/color]videoWriter[color=#000000] [/color][color=#460085]release[/color][color=#000000]];[/color][/size][/font][/color]<br />
[color=#3D8389][font=Menlo][size=2][color=#000000][[/color]writerInput[color=#000000] [/color][color=#460085]release[/color][color=#000000]];[/color][/size][/font][/color]<br />
[color=#E40000][font=Menlo][size=2][color=#460085]NSLog[/color][color=#000000]([/color]@&quot;Video created&quot;[color=#000000]);[/color][/size][/font][/color]<br />
<br />
[color=#008C00][font=Menlo][size=2]//Checking existence of the video[/size][/font][/color]<br />
[font=Menlo][size=2][color=#cd00a5]bool[/color] videoExists = [[[color=#7c1fae]NSFileManager[/color] [color=#460085]defaultManager[/color]] [color=#460085]fileExistsAtPath[/color]:path];[/size][/font]<br />
<br />
[font=Menlo][size=2][color=#cd00a5]return[/color] videoExists;[/size][/font]<br />
[font=Menlo][size=2]}[/size][/font]<br />
[font=Menlo][size=2]}[/size][/font]<br />
[font=Menlo][size=2]}[/size][/font]<br />
[font=Menlo][size=2]}[/size][/font]<br />








Bon, un peu plus d'explication sur ce que je souhaite faire.

J'ai un NSArray (ou plutôt un NSMutableArray) d'images que je souhaites transformer en .mov.

ça marche, (à  quelques frames vertes au début de chaque vidéo pour une raison qui m'échappe encore), mais ça me créer pas mal de fuites mémoire...



Auriez-vous une idée du problème ?





Edit : Rajout de ce qu'il y a dans le .h :




[font=Menlo][size=2]<br />
[color=#7c1fae]AVAssetWriter[/color] *videoWriter;[/size][/font][color=#7C1FAE][font=Menlo][size=2]<br />
AVAssetWriterInput[color=#000000] *writerInput;[/color][/size][/font][/color][color=#7C1FAE][font=Menlo][size=2]<br />
AVAssetWriterInputPixelBufferAdaptor[color=#000000] *adaptator;[/color][/size][/font][/color]<br />
Mots clés:

Réponses

  • AliGatorAliGator Membre, Modérateur
    novembre 2012 modifié #2
    On a un peu de mal à  lire ton 2e bloc de code car tu n'as pas mis l'indentation, donc c'est difficile de voir où commencent et se terminent tes if/else, mais j'ai l'impression que tu ne fais le CVPixelBufferRelease que à  la toute fin quand tu n'as plus d'image (donc que du dernier buffer), et pas à  chaque itération après avoir utilisé le buffer de chaque image avant d'aller à  l'image suivante ?
  • CéroceCéroce Membre, Modérateur
    novembre 2012 modifié #3
    Ta première méthode réserve de la mémoire avec CVCreatePixelBuffer(), mais ne la libère pas. C'est normal parce que si tu faisais un CVPixelBufferRelease() à  la fin, le buffer n'existerait plus au sortir de la méthode. Cette méthode est un peu mal nommée, elle devrait s'appeler newPixelBufferFromCGImage:size:, parce qu'elle ne renvoie pas un objet autoreleasé.



    La deuxième méthode n'a pas l'air d'appeler CVPixelBufferRelease() dans la boucle pour libérer les pixels buffers quand elle n'en n'a plus besoin. D'où les fuites que tu observes.
  • Merci bien.

    Je vais regarder donc ça de plus près...



    L'indentation de ma deuxième méthode est partie, je ne sais pas pourquoi...



    Mais sinon...

    Pour la première remarque de Céroce, si je le mets en attribut de ma classe, et que je le release à  la suite de l'appel, ça marcherait, non ?



    Concernant la deuxième (qui me semble être la même qu'Ali), je vais voir ça de plus près. Si j'ai zappé un MachinRelease() dans mes boucles.



    Quoiqu'il en soit, si j'arrive à  m'en dépatouiller, je mettrais la solution qui pourrait être utile si certains s'intéressent à  ça...

    Car mon cas n'est pas si atypique je pense, car il s'agit de récupérer le stream d'une caméra MJPEG (qui m'envoie donc des .jpg) et d'enregistrer au besoin, avec la récupération du flux.
  • CéroceCéroce Membre, Modérateur
    'Larme' a écrit:


    Pour la première remarque de Céroce, si je le mets en attribut de ma classe, et que je le release à  la suite de l'appel, ça marcherait, non ?


    À quoi bon ? Ta méthode renvoie déjà  un CVPixelBufferRef. À vrai dire, pixelBufferFromCGImage:size: devrait être une méthode de classe puisqu'elle n'a pas besoin d'accéder aux variables d'instance.



    Comme CVPixelBuffer n'est pas un NSObject, il ne peut pas être autoreleasé, c'est pourquoi tu n'as le choix que de faire un CVBufferRelease() qu'en dehors de la 1ère méthode. Mais ce n'est pas vraiment un problème, libère le CVBuffer quand tu n'en n'as plus besoin, et c'est tout.
  • Merci à  Céroce et Ali d'avoir pointé du doigt l'absence de CVPixelBufferRelease(buffer); que j'ai rajouté à  la fin du test if (buffer), et avant de rentrer dans le while.



    Maintenant (enfin toujours), mais j'avais zappé de le citer, il m'indique que cette ligne pose problème :






    [color=#7C1FAE][font=Menlo][size=2]<br />
    CVReturn[color=#000000] status = [/color][color=#460085]CVPixelBufferCreate[/color][color=#000000]([/color]kCFAllocatorDefault[color=#000000], imageSize.[/color]width[color=#000000],[/color][/size][/font][/color][font=Menlo][size=2]<br />
                                              imageSize.[color=#7c1fae]height[/color], [color=#460085]kCVPixelFormatType_32ARGB[/color], ([color=#7c1fae]CFDictionaryRef[/color]) options, [/size][/font][font=Menlo][size=2]<br />
                                              &amp;pxbuffer);[/size][/font]<br />
    








    La doc m'indique ceci.<p>




    CVPixelBufferCreate

    Creates a single pixel buffer for a given size and pixel format.

    CVReturn CVPixelBufferCreate (

    CFAllocatorRef allocator,

    size_t width,

    size_t height,

    OSType pixelFormatType,

    CFDictionaryRef pixelBufferAttributes,

    CVPixelBufferRef *pixelBufferOut

    );





    Parameters

    allocator

    The allocator to use to create the pixel buffer. Pass NULL to specify the default allocator. width

    Width of the pixel buffer, in pixels. height

    Height of the pixel buffer, in pixels. pixelFormatType

    The pixel format identified by its respective four-character code (type OSType). pixelBufferAttributes

    A dictionary with additional attributes for a pixel buffer. This parameter is optional. See [url="file:///Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_0.iOSLibrary.docset/Contents/Resources/Documents/documentation/QuartzCore/Reference/CVPixelBufferRef/Reference/reference.html#//apple_ref/doc/constant_group/Pixel_Buffer_Attribute_Keys"]“Pixel Buffer Attribute Keys”[/url] for more details. pixelBufferOut

    On output, pixelBufferOut points to the newly created pixel buffer.



    Return Value



    A Core Video result code. See [url="file:///Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_0.iOSLibrary.docset/Contents/Resources/Documents/documentation/QuartzCore/Reference/CVConstantsRef/Reference/reference.html#//apple_ref/doc/uid/TP40010164"]Core Video Constants Reference[/url] for possible values.



    Discussion



    This function allocates the necessary memory based on the pixel dimensions, format, and extended pixels described in the pixel buffer's attributes.

    Some of the parameters specified in this call override equivalent pixel buffer attributes. For example, if you define the kCVPixelBufferWidth andkCVPixelBufferHeight keys in the pixel buffer attributes parameter (pixelBufferAttributes), these values are overridden by the width and height parameters.



    Availability
    • Available in iOS 4.0 and later.




    Declared In

    CVPixelBuffer.h






    Je ne vois pas ce qui pose problème...

    Est-ce toujours le pxbuffer ?
Connectez-vous ou Inscrivez-vous pour répondre.