Video Camera Real Time Streaming

Hello,

I have developed a game and people can activate their cameras up to 20 players. But CPU usage is very high.

Currently I am using this code to process each frame for each player:

void Player::camera(unsigned char *video, int len)
{
	auto img = new Image();
	if (img->initWithImageData(video, len))
	{
		img->autorelease();
	}
	else
	{
		img->release();
		return;
	}
 
	auto tex = new Texture2D();
	if (tex->initWithImage(img))
	{
		tex->autorelease();
	}
	else
	{
		tex->release();
		return;
	}
 
	this->lastCam = 0;
 
	cam->setOpacity(255);
 
	Rect rect = Rect::ZERO;
	rect.size = tex->getContentSize();
 
	cam->sprite->setTexture(tex);
	cam->sprite->setTextureRect(rect);
	cam->sprite->setScale(Director::getInstance()->getContentScaleFactor() * PLAYER_SIZE / tex->getContentSizeInPixels().height);
 
	updateDisplay();
}

The display is done in the cocos thread.

May I display image differently since they are only displayed once ?
Is their a better approch ? natively ?

Thank you

could you explain to me better what you need?

I would like to know if there is a better way to display a different image each frame without taking much CPU ?

Well, when the “camera” to show image in “screen” don’t passed image in RGB the format that used is “YUV” YUV - Wikipedia this kind of format show direct Image in the hardware. this is the best way. the Video process and transfer video take a lot of resources, what is it the origin of the video that you should show?

The origin is camera of each player with 20 fps each one. Texture2D initWithImage take 30ms and it’s my problem. His there an other where to display Image in cocos2d without creating Texture given that the image is only used once?

I tested natively but picture always on top so it’s not the best way but I noticed that it was working fine so how to do? With custom render commands?

Thank you

Sorry, I could not understand what you are doing here, How much devices are you using? what are the system operation (Android/Windows/IOS)? how are you doing the broadcast of the streaming? Are you using UTP or Http?

Solved by using updateWithData in Texture2D

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.