title: Using NSImageView for video streaming
body: <p>I am making an voip application which also has video support, </p>
  
  <p>for video, i am getting data as a YUV format and to decode i am using libvpx, </p>
  
  <p>and then i will RGB data, </p>
  
  <p>Now to display i am using NSImageView where i will change the NSImage, please refer the code below  </p>
  
  <pre><code>-(void)gotNewRGBBuffer:(void *)imageData Height:(int)height Width:(int)width Scan:(int)scan VideoId:(const char *)pId{
  
      @autoreleasepool {
  
          // display the image (on the UI thread)
          NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
                                      initWithBitmapDataPlanes:(unsigned char **)&amp;imageData
                                      pixelsWide:width pixelsHigh:height
                                      bitsPerSample:8
                                      samplesPerPixel:3  // or 4 with alpha
                                      hasAlpha:NO
                                      isPlanar:NO
                                      colorSpaceName:NSDeviceRGBColorSpace
                                      bitmapFormat:0
                                      bytesPerRow:scan  // 0 == determine automatically
                                      bitsPerPixel:24];  // 0 == determine automatically
  
  
          NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
  
  
          [image addRepresentation:bitmap];
  
          if ( ![NSThread isMainThread]){
  
              [self performSelectorOnMainThread:@selector(updateImage:) withObject:image waitUntilDone:NO];
          }else{
              [self updateImage:image];
          }
      }
  }
  </code></pre>
  
  <p>and function to update the image here it goes, </p>
  
  <pre><code>-(void)updateImage:(NSImage *)pNewLocalImage{
              [self pImageView].image = pNewLocalImage;
              [[self pImageView] setNeedsDisplay:YES];
              NSLog(@" Updating the image ");
  
  }
  </code></pre>
  
  <p>this is working, but taking some considerable amount of memory , so i my question, is there any other way to optimize it! </p>