Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ICMCompressionSessionEncodeFrame and Memory Problems



I'm not sure it si the most effient way to do it, but I see least on memory management error.

CVPixelBufferPoolCreatePixelBuffer() returns a buffer that you MUST release when done. (count = 1)
You retain the buffer later in your code using CVPixelBufferRetain() (count = 2)
You release your buffer once at end (count = 1)

=> leak

1) Why are you using CVPixelBufferRetain() ?
2) If an error occured after the buffer creation, make sure it release it before returning.


Le 24 juin 08 à 14:09, Hannes Osius a écrit :

Hi,

I'm trying to create a Movie via ICMCompressionSession. The input comes from an QTCaptureSession via the QTCaptureDecompressedVideoOutput. I started to feed the frame over the didOutputVideiFrame is works fine:

- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer: (QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection
{
err = ICMCompressionSessionEncodeFrame( mCompressionSession, videoFrame , timeStamp,  [sampleBuffer duration].timeValuekICMValidTime_DisplayTimeStampIsValid, NULL, NULL, NULL );
timeStamptimeStamp + timescale;
} 

so now I tried to modify the a CIImage that i get from videoFrame and write it into the ICMCompressionSession using an CVPixelBuffer. The pixelBuffer came from a ICMCompression-Pixelbufferpool. Now I have memory problems the app does alloc more and more memory, even if only pass an PixelBuffer directly from the pool like this:


CVImageBufferRef buffer;
    theError = CVPixelBufferPoolCreatePixelBuffer(NULL, mBufferPool, &buffer);
  if(theError)....
    else{
CVPixelBufferRetain(buffer);
err = ICMCompressionSessionEncodeFrame( mCompressionSession, buffer , timeStamp,  [sampleBuffer duration].timeValue, kICMValidTime_DisplayTimeStampIsValid, NULL, NULL, NULL );
timeStamp = timeStamp + timescale;
CVPixelBufferRelease(buffer);
}
Someday it should look like this:

CVImageBufferRef buffer;
theError = CVPixelBufferPoolCreatePixelBuffer(NULL, mBufferPool, &buffer);
if(theError)...
CVPixelBufferRetain(buffer);
theError = CVPixelBufferLockBaseAddress(buffer, 0);
if(theError)....
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
void * rasterData = CVPixelBufferGetBaseAddress(buffer);
CGContextRef cgContextRef = CGBitmapContextCreate( rasterData, CVPixelBufferGetWidth(buffer), CVPixelBufferGetHeight(buffer), 8CVPixelBufferGetBytesPerRow(buffer), colorSpace, kCGImageAlphaPremultipliedLast);
if(cgContextRef == nil)... 
CIContext * cicontext = [CIContext contextWithCGContext:cgContextRef options:nil];
CIImage* inputImage1 = [CIImage imageWithCVImageBuffer:videoFrame];
//do CIFilter stuff .....
CGImageRef cgImage = [cicontext createCGImage:inputImage1 fromRect:[inputImage1 extent]];
CGContextDrawImage(cgContextRef, [inputImage1 extent], cgImage);
err = ICMCompressionSessionEncodeFrame( mCompressionSession, buffer , timeStamp,  [sampleBuffer duration].timeValue, kICMValidTime_DisplayTimeStampIsValid, NULL, NULL, NULL );
timeStamp = timeStamp +timescale;
if(err)...
CGColorSpaceRelease(colorSpace);
CGImageRelease(cgImage);
[cicontext release];
CGContextRelease(cgContextRef);
CVPixelBufferRelease(buffer);

So i must do something wrong: 
- did I forget to register a Callback for clean up the buffer?
- do I have to copy the CVBufferAttachments from the videoframe to the buffer?
- do I have to call something for clean up?
- Not enough Performance? Is does no look  like. i am working on an 8-Core MacPro and all CPU's are working between 50-60%.  

Datails about the ICMCompressionSession: 
- Codec: Appel Prores 422 HQ 
- Format is Full HD 1920x1080
- Input via AJA Card


Thanks for help

Hannes Osius


_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/email@hidden

This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/email@hidden

This email sent to email@hidden

References: 
 >ICMCompressionSessionEncodeFrame and Memory Problems (From: Hannes Osius <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.