Hi Christophe,

I don't know for the network things, but I sure that you have to do this line 
differently:

>   [sendBuffer appendData:[NSData dataWithBytes:imgData length:[imgData 
> length]] ];

imgData is just a point to an Object and NOT the pointer to your data. You have 
to use [NSData bytes] to get the pointer :

> [sendBuffer appendData:[NSData dataWithBytes:[imgData bytes] length:[imgData 
> length]] ];



Why do you have this line?

>   if(counter % 100 == 0)

this means that only every 100th render cycle get sent, right? if so you can 
abort much earlier your process of fetching images and so one, if you won't 
send it anyways.


You have lots of [NSData dataWithData:] in your code, causing lots of copis of 
all your data. In my opinion, mostly they are obsolete. e.g. [endString 
dataUsingEncoding:NSASCIIStringEncoding] is already returning an NSData object 
and you don't need to put it in another NSData object by wrapping it with 
[NSData dataWithData:] 

Just my two cents.

Achim Breidenbach
Boinx Software Ltd.


On 08.11.2012, at 14:13, Christophe Leske wrote:

> Hi Tom,
> 
> I changed the buffer copying method to your suggested
> 
> [NSData dataWithData:]
> 
> Now it runs for a couple of seconds, before the same EXC_BAD_ACCESS code 13 
> 0x0 occurs...
> 
> The crash occurs in objc_msgSend_vtable7 in Thread 6 (number can vary) with a 
> callstack of GCDAsyncSocket doWriteData as precursor (which again got called 
> from GCDAszncSocket maybeDequeueWrite) which again was called by the real 
> GCDASynchSocket writeData method I am calling in my code.
> 
> It looks to me as if some sort of buffer is running full.
> 
> Strangely enough, the counterpart is also registering a connection, yet none 
> of the data is being received - this can however be related to my 
> programming.  I need to check that.
> 
> I appreciate your help though.
> 
> 
> 
> 
> This is what I do in the execute-Method of the patch:
> 
> 
> 
> 
> 
> 
> - (BOOL)execute:(id <QCPlugInContext>)context atTime:(NSTimeInterval)time 
> withArguments:(NSDictionary *)arguments
> {
>       /*
>       Called by Quartz Composer whenever the plug-in instance needs to 
> execute.
>       Only read from the plug-in inputs and produce a result (by writing to 
> the plug-in outputs or rendering to the destination OpenGL context) within 
> that method and nowhere else.
>       Return NO in case of failure during the execution (this will prevent 
> rendering of the current frame to complete).
>       
>       The OpenGL context for rendering can be accessed and defined for CGL 
> macros using:
>       CGLContextObj cgl_ctx = [context CGLContextObj];
>       */
> 
>   if([connectSocket isDisconnected] || [self 
> didValueForInputKeyChange:@"inputPort"] || [self 
> didValueForInputKeyChange:@"inputHost"])
>       {
>               // stop listening for incomming connections
>               [connectSocket disconnect];
> 
>               if(![connectSocket connectToHost:self.inputIpAddressPixelmaster 
> onPort:self.inputPort error:nil])
>                       NSLog(@"could not connect to host, port");
>       }
> 
> 
> 
>   // get the image to use
>   id<QCPlugInInputImageSource> imageToUse = self.inputImage;
> 
>   CGColorSpaceRef  colorSpace = (CGColorSpaceGetModel([imageToUse 
> imageColorSpace]) == kCGColorSpaceModelRGB ? [imageToUse imageColorSpace] : 
> [context colorSpace]);
> 
>   NSLog(@"Colorspace: %@", colorSpace);
> 
>   NSLog(@"Bounds: %@", [imageToUse imageBounds]);
> 
> 
>   if (![imageToUse 
> lockBufferRepresentationWithPixelFormat:QCPlugInPixelFormatARGB8
>                                                 colorSpace:colorSpace
>                                                 forBounds:[imageToUse 
> imageBounds]])
>   {
> 
>       NSLog(@"Locking of image failed.");
>       return NO;
> 
>   }
> 
>   // we got the image locked now, read out the pixels...
> 
>   vImage_Buffer           buffer;
>   vImage_Buffer           vDestBuffer;
> 
> 
>   // downsampling needed!
> 
>   NSBitmapImageRep* newRep = [[[NSBitmapImageRep alloc] 
> initWithBitmapDataPlanes:NULL
>                                                                       
> pixelsWide:48
>                                                                       
> pixelsHigh:50
>                                                                       
> bitsPerSample:8
>                                                                        
> samplesPerPixel:3
>                                                                        
> hasAlpha:NO
>                                                                        
> isPlanar:NO
>                                                                   
> colorSpaceName:NSDeviceRGBColorSpace
>                                                                       
> bitmapFormat:0
>                                                                      
> bytesPerRow:0
>                                                                     
> bitsPerPixel:0] autorelease];
> 
>   vDestBuffer.data = newRep.bitmapData;
>   vDestBuffer.height = newRep.pixelsHigh;
>   vDestBuffer.width = newRep.pixelsWide;
>   vDestBuffer.rowBytes = newRep.bytesPerRow;
> 
> 
>   // Set up the vImage buffer
>   buffer.data     = (void*)[imageToUse bufferBaseAddress];
>   buffer.rowBytes = [imageToUse bufferBytesPerRow];
>   buffer.width    = [imageToUse bufferPixelsWide];
>   buffer.height   = [imageToUse bufferPixelsHigh];
> 
>   //Do the scale
>   if (vImageScale_ARGB8888(&buffer, &vDestBuffer, NULL, 0))
>   {
> 
>       [imageToUse unlockBufferRepresentation];
> 
>       return NO;
> 
>   }
> 
> 
>   NSMutableData* imgData = [[NSMutableData alloc] init];
> 
>   for(int y=0;y<vDestBuffer.height;y++)
>   {
> 
>       long currentLineOffset = y * vDestBuffer.rowBytes;
> 
>       for(int x=0;x<vDestBuffer.width;x++)
>       {
>           Byte aPixel[3];
> 
>           // RGB
> 
>           //R
>           aPixel[0] = (Byte)&vDestBuffer.data[currentLineOffset] ;
>           aPixel[1] = (Byte)&vDestBuffer.data[currentLineOffset + 1] ;
>           aPixel[2] = (Byte)&vDestBuffer.data[currentLineOffset + 2] ;
> 
>           [imgData appendBytes:aPixel length:3];
> 
>       }
> 
>   }
> 
> 
> 
> 
>   // send the data over the wire!
>   // for that to happen, we need to build the protocol
>   NSLog(@"connected %d¸", [connectSocket isConnected]);
> 
> 
>   int lengthByte = 7235;
> 
> 
>   NSMutableData* sendBuffer = [[NSMutableData alloc] init];
> 
> 
>   // build the header
>   NSString* header = @"pixmaster-prot-vers1";
> 
>   [sendBuffer appendData:[NSMutableData dataWithData:[header 
> dataUsingEncoding:NSASCIIStringEncoding]]];
> 
>   // typeByte
>   Byte typeByte = 4;
> 
>   [sendBuffer appendBytes:&typeByte length:1];
> 
> 
>   //databytes per protocol
>   Byte lengthBytes[2] = {28, 72};
> 
>   [sendBuffer appendBytes:lengthBytes length:2 ] ;
> 
>   // TBA MESSAGE ID (=A COUNTER)
>   counter++;
>   Byte messageID[2] = { counter/256, counter % 256};
> 
>   [sendBuffer appendBytes:messageID length:2];
> 
>   Byte filterEnable = 0;
> 
>   [sendBuffer appendBytes:&filterEnable length:1];
> 
> 
>   Byte fixImagesEnable =0;
> 
>   [sendBuffer appendBytes:&fixImagesEnable length:1];
> 
> 
> 
>   // Byte 27 = 50 in the recorded stream, is this the fps  in Hz?
> 
>   Byte reserved[5] = {0,0,0,0,0};
> 
>   [sendBuffer appendBytes:reserved length:5];
> 
> 
>   // now apprend image data!
> 
>   [sendBuffer appendData:[NSData dataWithBytes:imgData length:[imgData 
> length]] ];
> 
> 
>   // now end the buffer
>   NSString* endString = @"end";
> 
>   [sendBuffer appendData:[NSMutableData dataWithData:[endString 
> dataUsingEncoding:NSASCIIStringEncoding]]];
> 
>   if(counter % 100 == 0)
>   {
>       [connectSocket writeData:[NSData dataWithData:sendBuffer]  
> withTimeout:-1 tag:0];
>   }
> 
>   [imageToUse unlockBufferRepresentation];    
>   [imgData release];
>   [sendBuffer release];
> 
>       return YES;
> 
> }
> 
> --
> Christophe Leske
> multimedial.de
> 
> ----------------------------------------
> www.multimedial.de - [email protected]
> Hohler Strasse 17 - 51645 Gummersbach
> +49(0)2261-99824540 // +49(0)177-2497031
> ----------------------------------------
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Quartzcomposer-dev mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/quartzcomposer-dev/achim%40boinx.com
> 
> This email sent to [email protected]


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to