How render a rtt from a video stream in ios

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
ariesliu
Gnoblar
Posts: 2
Joined: Fri Oct 12, 2012 11:04 am

How render a rtt from a video stream in ios

Post by ariesliu »

Hi,
I want to render a rtt from a video stream in ios. Now I use corevideo.framework to get video stream. But I can't put video stream into rtt.

I get video stream:

Code: Select all

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
    CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    if (CVPixelBufferLockBaseAddress(pixelBuffer, 0) == kCVReturnSuccess) {
        CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
    }
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    CVPixelBufferLockBaseAddress(imageBuffer, 0);
    
    uint8_t* baseAddress = (uint8_t*) CVPixelBufferGetBaseAddress(imageBuffer);
    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
    size_t width = CVPixelBufferGetWidth(imageBuffer);
    size_t height = CVPixelBufferGetHeight(imageBuffer);
    
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    if (!colorSpace) {
        NSLog(@"CGColorSpaceCreateDeviceRGB failure");
        return;
    }
    CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
    pixelBase = (unsigned char *)baseAddress;
    CGImageRef newImage = CGBitmapContextCreateImage(newContext);
    CGContextRelease(newContext);
    CGColorSpaceRelease(colorSpace);
    UIImage* image = [UIImage imageWithCGImage:newImage scale:1.0 orientation:UIImageOrientationUp];
    [img performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];

    CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
    CGImageRelease(newImage);
    [pool drain];
}
I render the rtt:

Code: Select all

PhysicsCameraViewController* camera = [[PhysicsCameraViewController alloc] init];
    Ogre::TexturePtr rtt_texture = Ogre::TextureManager::getSingleton().createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 480, 320, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
    Ogre::RenderTexture *renderTexture = rtt_texture->getBuffer()->getRenderTarget();

    Ogre::Camera* mCamera = mSceneBrowser->getCamera();
    Ogre::Image image = Ogre::Image();
    image.loadDynamicImage(camera.pixelBase, 480, 320, Ogre::PF_R8G8B8);
    rtt_texture->loadImage(image);
    renderTexture->setAutoUpdated(true);
    
    Ogre::Rectangle2D* bg = new Ogre::Rectangle2D(true);
    bg->setCorners(-1.0f, 1.0f, 1.0f, -1.0f);
    bg->setBoundingBox(Ogre::AxisAlignedBox(-100000.0f * Ogre::Vector3::UNIT_SCALE, 100000.0f * Ogre::Vector3::UNIT_SCALE));
    
    Ogre::SceneNode* bgNode = node->createChildSceneNode("bgNode");
    bgNode->attachObject(bg);
    
    Ogre::MaterialPtr renderMaterial = Ogre::MaterialManager::getSingleton().create("RttMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    renderMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    renderMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex");
    bg->setMaterial("RttMat");
When I loadImage it will asset pData is null.
It will stop at:

Code: Select all

const uchar* Image::getData() const
	{
		[b]assert( m_pBuffer );[/b]
		return m_pBuffer;
	}
in OgreImage.cpp.
ariesliu
Gnoblar
Posts: 2
Joined: Fri Oct 12, 2012 11:04 am

Re: How render a rtt from a video stream in ios

Post by ariesliu »

And I have the other problem about displaying 2d.
I use the function via http://www.ogre3d.org/tikiwiki/tiki-ind ... ackgrounds.

But I can't add 2d background to scene. There is only a image with below.

So what can i do.
And if I want to add "Default.png", how to do.

Code: Select all

material->getTechnique(0)->getPass(0)->createTextureUnitState(Ogre::macBundlePath()+"/Default.png");
or

Code: Select all

material->getTechnique(0)->getPass(0)->createTextureUnitState("Default.png");
You do not have the required permissions to view the files attached to this post.