From 60ec86c556c4e875c24425e2d4c46f2b99877cf0 Mon Sep 17 00:00:00 2001 From: xant Date: Mon, 9 Aug 2010 22:20:02 +0200 Subject: [PATCH] removed some more dead code + minor cleanings along the way --- src/filter_instance.cpp | 20 ++++--- xcode/CVCocoaLayer.h | 1 - xcode/CVF0rLayer.h | 2 - xcode/CVF0rLayer.mm | 43 ++++++-------- xcode/CVLayer.h | 6 +- xcode/CVLayer.mm | 58 +++++++++---------- xcode/CVLayerController.h | 2 - xcode/CVLayerController.mm | 2 - xcode/CVLayerView.h | 1 - xcode/CVPreview.h | 2 - xcode/CVPreview.mm | 1 - xcode/CVScreenView.h | 1 - xcode/CVScreenView.mm | 20 ++----- xcode/CVTexture.h | 34 ----------- xcode/CVTexture.m | 81 --------------------------- xcode/freej.xcodeproj/project.pbxproj | 6 -- 16 files changed, 63 insertions(+), 217 deletions(-) delete mode 100644 xcode/CVTexture.h delete mode 100644 xcode/CVTexture.m diff --git a/src/filter_instance.cpp b/src/filter_instance.cpp index cad26dd2..f9dfa8a6 100644 --- a/src/filter_instance.cpp +++ b/src/filter_instance.cpp @@ -34,18 +34,21 @@ FACTORY_REGISTER_INSTANTIATOR(FilterInstance, FilterInstance, FilterInstance, co FilterInstance::FilterInstance() : Entry() { - core = NULL; - intcore = 0; - outframe = NULL; - active = false; - layer = NULL; + core = NULL; + intcore = 0; + outframe = NULL; + active = false; + layer = NULL; } FilterInstance::FilterInstance(Filter *fr) + : Entry() { - FilterInstance(); - func("creating instance for filter %s",fr->name); - + core = NULL; + intcore = 0; + outframe = NULL; + active = false; + layer = NULL; init(fr); } @@ -62,6 +65,7 @@ FilterInstance::~FilterInstance() { void FilterInstance::init(Filter *fr) { + func("initializing instance for filter %s",fr->name); proto = fr; set_name(proto->name); active = true; diff --git a/xcode/CVCocoaLayer.h b/xcode/CVCocoaLayer.h index 71cab048..daaa7b0b 100644 --- a/xcode/CVCocoaLayer.h +++ b/xcode/CVCocoaLayer.h @@ -22,7 +22,6 @@ #import #import -#import #include @class CVLayerView; diff --git a/xcode/CVF0rLayer.h b/xcode/CVF0rLayer.h index 78c1ede4..9ee7d876 100644 --- a/xcode/CVF0rLayer.h +++ b/xcode/CVF0rLayer.h @@ -26,8 +26,6 @@ class CVF0rLayer : public CVLayer { protected: bool _init(); - void *currentFrame; - CVPixelBufferRef pixelBuffer; public: CVF0rLayer(CVLayerController *controller); diff --git a/xcode/CVF0rLayer.mm b/xcode/CVF0rLayer.mm index 08c07bbd..0a401cc2 100644 --- a/xcode/CVF0rLayer.mm +++ b/xcode/CVF0rLayer.mm @@ -76,48 +76,39 @@ CVF0rLayer::CVF0rLayer(CVLayerController *controller) generator = NULL; type = Layer::GL_COCOA; set_name([input name]); - currentFrame = NULL; - pixelBuffer = NULL; [input setLayer:this]; } CVF0rLayer::~CVF0rLayer() { close(); - if (pixelBuffer) - CVPixelBufferRelease(pixelBuffer); - if (currentFrame) - free(currentFrame); } void * CVF0rLayer::feed() { void *res; - + CVPixelBufferRef pixelBuffer; if (generator) res = generator->process(fps.get(), NULL); if (res) { // TODO - handle geometry changes - if (!currentFrame) { - currentFrame = malloc(geo.bytesize); - CVReturn err = CVPixelBufferCreateWithBytes ( - NULL, - geo.w, - geo.h, - k32ARGBPixelFormat, - currentFrame, - geo.w*4, - NULL, - NULL, - NULL, - &pixelBuffer - ); - } - CVPixelBufferLockBaseAddress(pixelBuffer, 0); - memcpy(currentFrame, res, geo.bytesize); - CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); - [(CVF0rLayerController *)input feedFrame:pixelBuffer]; + CVReturn err = CVPixelBufferCreateWithBytes ( + NULL, + geo.w, + geo.h, + k32ARGBPixelFormat, + res, + geo.w*4, + NULL, + NULL, + NULL, + &pixelBuffer + ); + if (err == noErr) { + [(CVF0rLayerController *)input feedFrame:pixelBuffer]; + CVPixelBufferRelease(pixelBuffer); + } } return CVLayer::feed(); } diff --git a/xcode/CVLayer.h b/xcode/CVLayer.h index cb5fd8e0..5f5e71f5 100644 --- a/xcode/CVLayer.h +++ b/xcode/CVLayer.h @@ -25,7 +25,6 @@ #import #import -#import #import @@ -52,9 +51,10 @@ public: virtual void *do_filters(void *buf); protected: virtual void *feed(); - + + CVPixelBufferRef pixelBuffer; private: - void *frame[2]; // double buffer + void *frame; unsigned int num; }; diff --git a/xcode/CVLayer.mm b/xcode/CVLayer.mm index 1d2e2074..636a1fc3 100644 --- a/xcode/CVLayer.mm +++ b/xcode/CVLayer.mm @@ -23,17 +23,15 @@ CVLayer::CVLayer() : CVCocoaLayer(this), Layer() { type = Layer::GL_COCOA; buffer = NULL; - memset(frame, 0, sizeof(void *) * 2); - num = 0; + frame = NULL; } CVLayer::CVLayer(CVLayerController *vin) : Layer(), CVCocoaLayer(this, vin) { type = Layer::GL_COCOA; buffer = NULL; - memset(frame, 0, sizeof(void *) * 2); - num = 0; - set_name([input name]); + frame = NULL; + set_name([input name]); [input setLayer:this]; } @@ -41,11 +39,8 @@ CVLayer::~CVLayer() { stop(); close(); - // release the double buffer if present - for (int i = 0; i < 2; i++) { - if (frame[i]) - free(frame[i]); - } + if (frame) + free(frame); } bool @@ -115,27 +110,16 @@ CVLayer::feed() void *output = NULL; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - CVPixelBufferRef pixelBuffer = [input currentFrame]; - if (pixelBuffer) { - num++; - int idx = num % 2; - //lock(); - // ensure providing the pixelbuffer to upper cocoa-related layers + CVPixelBufferRef newPixelBuffer = [input currentFrame]; + if (newPixelBuffer) { + if (pixelBuffer) + CVPixelBufferRelease(pixelBuffer); + pixelBuffer = newPixelBuffer; + CVPixelBufferLockBaseAddress(pixelBuffer, 0); + output = CVPixelBufferGetBaseAddress(pixelBuffer); + CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); + } - CVPixelBufferLockBaseAddress(pixelBuffer, 0); - - //void *frame = CVPixelBufferGetBaseAddress(pixelBuffer); - if (!frame[idx]) - frame[idx] = malloc(CVPixelBufferGetDataSize(pixelBuffer)); - // TODO - try to avoid this copy!! - //lock(); - memcpy(frame[idx], CVPixelBufferGetBaseAddress(pixelBuffer), CVPixelBufferGetDataSize(pixelBuffer)); - //unlock(); - CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); - output = frame[idx]; - CVPixelBufferRelease(pixelBuffer); - //unlock(); - } [pool release]; return output; } @@ -144,6 +128,8 @@ void *CVLayer::do_filters(void *buf) { bool no_opt = false; if( filters.len() ) { + // If we have filters to apply , we don't need to copy the frame + // since we will get a different buffer out of the filter chain FilterInstance *filt; filters.lock(); filt = (FilterInstance *)filters.begin(); @@ -154,7 +140,17 @@ void *CVLayer::do_filters(void *buf) { filt = (FilterInstance *)filt->next; } filters.unlock(); - } + } else { + // We are now at the end of video pipeline for a layer + // if there is no filter to apply we are still referencing + // the storage from the underlying CVLayerController. + // Note that the controller could reuse the buffer to render + // next frame and we need to make a copy here. + if (!frame) + frame = malloc(geo.bytesize); + memcpy(frame, buf, geo.bytesize); + buf = frame; + } if ([input respondsToSelector:@selector(frameFiltered:)]) [input frameFiltered:(void *)buf]; diff --git a/xcode/CVLayerController.h b/xcode/CVLayerController.h index 3bce6ce0..2a8a5306 100644 --- a/xcode/CVLayerController.h +++ b/xcode/CVLayerController.h @@ -36,9 +36,7 @@ class CVCocoaLayer; NSRecursiveLock *lock; CVPixelBufferRef currentFrame; // the current frame from the movie - CVTexture *cvTexture; CIImage *posterImage; - CVTexture *currentPreviewTexture; CGLContextObj glContext; // filters for CI rendering CIFilter *colorCorrectionFilter; // hue saturation brightness control through one CI filter diff --git a/xcode/CVLayerController.mm b/xcode/CVLayerController.mm index 632b5606..ba886b09 100644 --- a/xcode/CVLayerController.mm +++ b/xcode/CVLayerController.mm @@ -72,9 +72,7 @@ static OSStatus SetNumberValue(CFMutableDictionaryRef inDict, layer = NULL; doFilters = true; currentFrame = NULL; - cvTexture = NULL; posterImage = NULL; - currentPreviewTexture = NULL; doPreview = YES; imageParams = [[NSMutableDictionary dictionary] retain]; diff --git a/xcode/CVLayerView.h b/xcode/CVLayerView.h index 93bdacef..7e70180a 100644 --- a/xcode/CVLayerView.h +++ b/xcode/CVLayerView.h @@ -21,7 +21,6 @@ #define __CVLAYERVIEW_H__ #import -#import #import #include diff --git a/xcode/CVPreview.h b/xcode/CVPreview.h index bc8d65dc..c6c50c4a 100644 --- a/xcode/CVPreview.h +++ b/xcode/CVPreview.h @@ -18,7 +18,6 @@ */ #import -#import @class CFreej; @@ -26,7 +25,6 @@ CIContext *ciContext; bool needsReshape; NSRecursiveLock *lock; - CVTexture *texture; IBOutlet CFreej *freej; } diff --git a/xcode/CVPreview.mm b/xcode/CVPreview.mm index 73d97ea2..70d14e4e 100644 --- a/xcode/CVPreview.mm +++ b/xcode/CVPreview.mm @@ -29,7 +29,6 @@ // Initialization code here. lock = [[NSRecursiveLock alloc] init]; needsReshape = YES; - texture = nil; [lock retain]; return self; } diff --git a/xcode/CVScreenView.h b/xcode/CVScreenView.h index 82833938..1dd3c3a8 100644 --- a/xcode/CVScreenView.h +++ b/xcode/CVScreenView.h @@ -23,7 +23,6 @@ #import -#import #import class CVScreen; diff --git a/xcode/CVScreenView.mm b/xcode/CVScreenView.mm index 66ad0184..e80acddb 100644 --- a/xcode/CVScreenView.mm +++ b/xcode/CVScreenView.mm @@ -84,7 +84,6 @@ static CVReturn renderCallback(CVDisplayLinkRef displayLink, lastFrame = NULL; exportedFrame = NULL; streamerStatus = NO; - lastTextures = [[NSMutableArray array] retain]; lock = [[NSRecursiveLock alloc] init]; [lock retain]; [self setNeedsDisplay:NO]; @@ -433,14 +432,7 @@ static CVReturn renderCallback(CVDisplayLinkRef displayLink, [lastFrame autorelease]; lastFrame = outFrame; outFrame = NULL; - // release all textures - while ([lastTextures count]) { - CVTexture *texture = [lastTextures objectAtIndex:0]; - [lastTextures removeObjectAtIndex:0]; - // removing the texture from the array makes its refcnt reach 0 - // so it will be automagically released - //[texture release]; - } + } else { needsReshape = YES; } @@ -464,7 +456,6 @@ static CVReturn renderCallback(CVDisplayLinkRef displayLink, { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; CIFilter *blendFilter = nil; - CVTexture *texture = nil; CVPixelBufferRef pixelBufferOut = NULL; //_BGRA2ARGB(layer->buffer, layer->geo.w*layer->geo.h); // XXX - expensive conversion @@ -495,7 +486,6 @@ static CVReturn renderCallback(CVDisplayLinkRef displayLink, if (!pixelBufferOut) // return if we don't have anything to draw return; CIImage *inputImage = [CIImage imageWithCVImageBuffer:pixelBufferOut]; - texture = [CVTexture textureWithCIImage:inputImage pixelBuffer:pixelBufferOut]; // we can release our reference to the pixelBuffer now. // The CVTexture will retain it as long as it is needed CVPixelBufferRelease(pixelBufferOut); @@ -516,18 +506,16 @@ static CVReturn renderCallback(CVDisplayLinkRef displayLink, } [blendFilter setDefaults]; [lock lock]; - if (texture) { + if (inputImage) { if (!outFrame) { - outFrame = [[texture image] retain]; + outFrame = [inputImage retain]; } else { [blendFilter setValue:outFrame forKey:@"inputImage"]; - [blendFilter setValue:[texture image] forKey:@"inputBackgroundImage"]; + [blendFilter setValue:inputImage forKey:@"inputBackgroundImage"]; CIImage *temp = [blendFilter valueForKey:@"outputImage"]; [outFrame release]; outFrame = [temp retain]; } - [lastTextures addObject:texture]; // Note: we use this to keep the texture refcnt'd until necessary - // once removed from the array it will be free'd } [lock unlock]; [pool release]; diff --git a/xcode/CVTexture.h b/xcode/CVTexture.h deleted file mode 100644 index 9708d21b..00000000 --- a/xcode/CVTexture.h +++ /dev/null @@ -1,34 +0,0 @@ -/* FreeJ - * (c) Copyright 2009 Andrea Guzzo - * - * This source code is free software; you can redistribute it and/or - * modify it under the terms of the GNU Public License as published - * by the Free Software Foundation; either version 3 of the License, - * or (at your option) any later version. - * - * This source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * Please refer to the GNU Public License for more details. - * - * You should have received a copy of the GNU Public License along with - * this source code; if not, write to: - * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#import -#import -#import - -@interface CVTexture : NSObject { - CVPixelBufferRef _pixelBuffer; - CIImage *_image; -} -+ (id)alloc; -+ (id)textureWithCIImage:(CIImage *)image pixelBuffer:(CVPixelBufferRef)pixelBuffer; -- (id)initWithCIImage:(CIImage *)image pixelBuffer:(CVPixelBufferRef)pixelBuffer; -- (CIImage *)image; -- (CVPixelBufferRef)pixelBuffer; -- (void)dealloc; -@end diff --git a/xcode/CVTexture.m b/xcode/CVTexture.m deleted file mode 100644 index 2f2121a7..00000000 --- a/xcode/CVTexture.m +++ /dev/null @@ -1,81 +0,0 @@ -/* FreeJ - * (c) Copyright 2009 Andrea Guzzo - * - * This source code is free software; you can redistribute it and/or - * modify it under the terms of the GNU Public License as published - * by the Free Software Foundation; either version 3 of the License, - * or (at your option) any later version. - * - * This source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * Please refer to the GNU Public License for more details. - * - * You should have received a copy of the GNU Public License along with - * this source code; if not, write to: - * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#import - - -@implementation CVTexture - -+ (id)alloc -{ - return [super alloc]; -} - -+ (id)textureWithCIImage:(CIImage *)image pixelBuffer:(CVPixelBufferRef)pixelBuffer -{ - id obj = [self alloc]; - [obj autorelease]; - return [obj initWithCIImage:image pixelBuffer:pixelBuffer]; -} - -- (id)initWithCIImage:(CIImage *)image pixelBuffer:(CVPixelBufferRef)pixelBuffer -{ - _pixelBuffer = CVPixelBufferRetain(pixelBuffer); - _image = [image retain]; - return self; -} - -- (void) dealloc -{ - if (_pixelBuffer) { - //NSLog(@"%d", [_image retainCount]); - [_image release]; - CVPixelBufferRelease(_pixelBuffer); - } - [super dealloc]; -} - -- (CIImage *)image -{ - return _image; -} - -- (CVPixelBufferRef)pixelBuffer -{ - return _pixelBuffer; -} - -#if 0 -- (void)applyFilter:(FilterInstance *)filter -{ - CVPixelBufferLockBaseAddress(_pixelBuffer, 0); - void *inframe = CVPixelBufferGetBaseAddress(_pixelBuffer); - filter->process(filter->layer.fps.fps, (uint32_t *)inframe); - //filter->update(FilterInstance *inst, <#double time#>, <#uint32_t *inframe#>, <#uint32_t *outframe#>); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - [filter setValue:_image forKey:@"inputImage"]; - CIImage *outputImage = [filter valueForKey:@"outputImage"]; - [_image release]; - _image = [outputImage retain]; - [pool release]; -} -#endif - -@end diff --git a/xcode/freej.xcodeproj/project.pbxproj b/xcode/freej.xcodeproj/project.pbxproj index 81578b00..35620673 100644 --- a/xcode/freej.xcodeproj/project.pbxproj +++ b/xcode/freej.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ AA00100D0F77FD9200719D5B /* callback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA00100C0F77FD9200719D5B /* callback.cpp */; }; AA0E39820FBECC1E00123D3F /* CVPreview.mm in Sources */ = {isa = PBXBuildFile; fileRef = AA0E39810FBECC1E00123D3F /* CVPreview.mm */; }; - AA0E3E760FBF3C0100123D3F /* CVTexture.m in Sources */ = {isa = PBXBuildFile; fileRef = AA0E3E750FBF3C0100123D3F /* CVTexture.m */; }; AA1009DC120D49C0004389B5 /* cam_layer_js.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA1009DB120D49C0004389B5 /* cam_layer_js.cpp */; }; AA134AC01047B6D500BA39EB /* CKbdController.mm in Sources */ = {isa = PBXBuildFile; fileRef = AA134ABF1047B6D500BA39EB /* CKbdController.mm */; }; AA183B651186C3BC00E82D70 /* CVGeoLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = AA183B641186C3BC00E82D70 /* CVGeoLayer.mm */; }; @@ -189,8 +188,6 @@ AA00100E0F77FDA000719D5B /* callback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = callback.h; path = include/callback.h; sourceTree = ""; }; AA0E39800FBECC1E00123D3F /* CVPreview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CVPreview.h; sourceTree = ""; }; AA0E39810FBECC1E00123D3F /* CVPreview.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CVPreview.mm; sourceTree = ""; }; - AA0E3E740FBF3C0100123D3F /* CVTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CVTexture.h; sourceTree = ""; }; - AA0E3E750FBF3C0100123D3F /* CVTexture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CVTexture.m; sourceTree = ""; }; AA1009DB120D49C0004389B5 /* cam_layer_js.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cam_layer_js.cpp; sourceTree = ""; }; AA134ABE1047B6D500BA39EB /* CKbdController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CKbdController.h; sourceTree = ""; }; AA134ABF1047B6D500BA39EB /* CKbdController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CKbdController.mm; sourceTree = ""; }; @@ -563,8 +560,6 @@ AACBE4820F641605001B610F /* FrameRate.m */, AA0E39800FBECC1E00123D3F /* CVPreview.h */, AA0E39810FBECC1E00123D3F /* CVPreview.mm */, - AA0E3E740FBF3C0100123D3F /* CVTexture.h */, - AA0E3E750FBF3C0100123D3F /* CVTexture.m */, AA5846540FE162C60059D860 /* CVTextLayerController.h */, AA5846550FE162C60059D860 /* CVTextLayerController.mm */, AAB47C9E10EB44AF00B0E8D2 /* CVTextLayerView.h */, @@ -1105,7 +1100,6 @@ AA8858810F631E3C00778C03 /* CVGenerator.m in Sources */, AACBE4830F641605001B610F /* FrameRate.m in Sources */, AA0E39820FBECC1E00123D3F /* CVPreview.mm in Sources */, - AA0E3E760FBF3C0100123D3F /* CVTexture.m in Sources */, AA5846530FE1626E0059D860 /* GLString.m in Sources */, AA63CF8E102DAED400FDA024 /* QTExporter.mm in Sources */, AA134AC01047B6D500BA39EB /* CKbdController.mm in Sources */,