⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 videomancontrol.cpp

📁 VideoMan is a very easy image acquisition library. It is able to manage many video inputs at the sam
💻 CPP
字号:
#include "VideoManControl.h"
#include "VideoManFactory.h"
#include "renderers\VideoManRenderer.h"
#include "CameraInput.h"
#include "VideoFileInput.h"

#ifdef VM_OGLRenderer
	#include "renderers\VideoManRendererOGL.h"
#endif

#include <iostream>
using namespace std;

VideoManControl::VideoManControl(void) : factory(VideoManFactory::getInstance())
{
	#ifdef WIN32
		HINSTANCE hInstance = GetModuleHandle("videoman.dll");
		const DWORD bufSize = 512;
		char szFileName[bufSize];
		DWORD pathLength = GetModuleFileName(hInstance,szFileName,bufSize);
		path = szFileName;
		//remove videoman.dll from the path
		std::string::size_type index;
		index = path.find_last_of("\\");
		if ( index != std::string::npos )
			path = path.substr( 0, index );
	#endif

	std::cout << "Videoman loaded from " << path << std::endl;
	factory.LoadModules( path );

	renderer = NULL;
	#ifdef VM_OGLRenderer
		renderer = new VideoManRendererOGL();
	#endif
}


VideoManControl::~VideoManControl(void)
{
	for( size_t v = 0; v < videoList.size(); v++ )
	{
		delete videoList[v];
	}
	videoList.clear();
	if (renderer != NULL)
	{
		//renderer->terminate();
		delete renderer;
		renderer = NULL;
	}
}

int VideoManControl::addVideoInput( inputIdentification &identifier, VideoManInputFormat *format )
{
	VideoInput *video = factory.createVideoInput( identifier, format );	
	if ( video == NULL )
		return -1;

	identifier = video->getIdentification();

	if ( renderer != NULL )
	{
		if ( !renderer->addVideoInput( video ) )
		{
			cerr << "Failed renderer->addVideoInput" << endl;
			return -1;
		}
	}

	int inputIndex = -1;
    if ( emptyIndexes.size() > 0 )
	{
		inputIndex = static_cast<int>( emptyIndexes.front() );
		emptyIndexes.erase( emptyIndexes.begin() );
		videoList[inputIndex] = video;
	}
	else
	{
		inputIndex = static_cast<int>( videoList.size() );
		videoList.push_back( video );	
	}
	return inputIndex;
}

void VideoManControl::deleteInput( size_t input )
{
	assert( input >= 0 && input < videoList.size() && "deleteInput: Index out of range");
	if ( videoList[input] != NULL )
		delete videoList[input];
	videoList[input] = NULL;
	if ( renderer != NULL )
	{
		renderer->deleteVideoInput( input );
	}
    emptyIndexes.push_back( input );
	emptyIndexes.sort();
}

void VideoManControl::activateAllVideoInputs()
{
	assert( renderer !=NULL && "updateTexure(): Renderer not created");
	if ( renderer != NULL )
		renderer->activateAllVideoInputs( );
}

void VideoManControl::activateVideoInput( const size_t &input )
{
	assert( input >= 0 && input < videoList.size() && "activateVideoInput: Index out of range");
	assert( renderer !=NULL && "updateTexure(): Renderer not created");
	if ( renderer != NULL )
		renderer->activateVideoInput( input );	
}


void VideoManControl::deactivateAllVideoInputs()
{
	assert( renderer !=NULL && "updateTexure(): Renderer not created");
	if ( renderer != NULL )
		renderer->deactivateAllVideoInputs();
}


void VideoManControl::deactivateVideoInput( const size_t &input )
{
	assert( input >= 0 && input < videoList.size() && "deactivateVideoInput: Index out of range");
	assert( renderer !=NULL && "updateTexure(): Renderer not created");
	if ( renderer != NULL )
		renderer->deactivateVideoInput( input );
}

bool VideoManControl::isActivated( const size_t &input )
{
	assert( input >= 0 && input < videoList.size() && "isActivated: Index out of range");
	assert( renderer !=NULL && "updateTexure(): Renderer not created");
	if ( renderer != NULL )
		return renderer->isActivated( input );	
	return false;
}


VideoManInputController *VideoManControl::getController( size_t input ) const
{
	assert( input >= 0 && input < videoList.size() && "getController: Index out of range");
	return videoList[input]->getController();
}


void VideoManControl::showPropertyPage( size_t input) const
{
	assert( input >= 0 && input< videoList.size() && "getFrame: Index out of range");
	if ( videoList[input]->getType() == CAMERA )
	{
		CameraInput *camera;
		camera = (CameraInput*)videoList[input];
		camera->showPropertyPage();
	}
}


void VideoManControl::changeScreenSize( const int left, const int up, const int width, const int height )
{
	if ( renderer != NULL )
		renderer->changeScreenSize( left, up, width, height );
}

void VideoManControl::changeVisualizationMode( int vM )
{
	assert( renderer !=NULL && "changeVisualizationMode(): Renderer not created");
	if ( renderer != NULL )
		renderer->changeVisualizationMode( vM );
}

void VideoManControl::changeMainVisualizationInput( const size_t &input )
{
	assert( input >= 0 && input< videoList.size() && "changeMainVisualizationInput: Index out of range");
	assert( renderer !=NULL && "changeMainVisualizationInput(): Renderer not created");
	if ( renderer != NULL )
		renderer->changeMainVisualizationInput( input );
}

int VideoManControl::getMainVisualizationInput()
{
	assert( renderer !=NULL && "getMainVisualizationInput(): Renderer not created");
	if ( renderer != NULL )
		return renderer->getMainVisualizationInput();
	return -1;
}

void VideoManControl::setVerticalFlip( const size_t &input, bool value )
{
	assert( renderer !=NULL && "setVerticalFlip(): Renderer not created");
	assert( input >= 0 && input< videoList.size() && "setVerticalFlip: Index out of range");
	if ( renderer != NULL )
		renderer->setVerticalFlip( input, value );
}

bool VideoManControl::getVerticalFlip( const size_t &input )
{
	assert( renderer !=NULL && "getVerticalFlip(): Renderer not created");
	assert( input >= 0 && input< videoList.size() && "getVerticalFlip: Index out of range");
	if ( renderer != NULL )
		return renderer->getVerticalFlip( input );
	return false;
}

void VideoManControl::setHorizontalFlip( const size_t &input, bool value )
{
	assert( renderer !=NULL && "setHorizontalFlip(): Renderer not created");
	assert( input >= 0 && input< videoList.size() && "setHorizontalFlip: Index out of range");
	if ( renderer != NULL )
		renderer->setHorizontalFlip( input, value );
}

bool VideoManControl::getHorizontalFlip( const size_t &input )
{
	assert( renderer !=NULL && "getHorizontalFlip(): Renderer not created");
	assert( input >= 0 && input< videoList.size() && "getHorizontalFlip: Index out of range");
	if ( renderer != NULL )
		return renderer->getHorizontalFlip( input );
	return false;
}

void VideoManControl::pauseVideo( size_t input )
{
	assert( input >= 0 && input< videoList.size() && "pauseVideo: Index out of range");
	if ( videoList[input]->getType() == VIDEOFILE )
	{
		VideoFileInput *video;
		video =	(VideoFileInput*) videoList[input];
		video->pause();
	}
}

void VideoManControl::playVideo( size_t input )
{
	assert( input >= 0 && input< videoList.size() && "playVideo: Index out of range");
	if ( videoList[input]->getType() == VIDEOFILE )
	{
		VideoFileInput *video;
		video =	(VideoFileInput*) videoList[input];
		video->play();
	}
}



void VideoManControl::goToFrame( size_t input, int frame )
{
	assert( input >= 0 && input< videoList.size() && "goToFrame: Index out of range");
	if ( videoList[input]->getType() == VIDEOFILE )
	{
		VideoFileInput *video;
		video =	(VideoFileInput*) videoList[input];
		video->goToFrame( frame );
	}
}

void VideoManControl::goToMilisecond( size_t input, double milisecond )
{
	assert( input >= 0 && input< videoList.size() && "goToMilisecond: Index out of range");
	if ( videoList[input]->getType() == VIDEOFILE )
	{
		VideoFileInput *video;
		video =	(VideoFileInput*) videoList[input];
		video->goToMilisecond( milisecond );
	}
}

double VideoManControl::getLength( size_t input )
{
	assert( input >= 0 && input< videoList.size() && "getLength: Index out of range");
	if ( videoList[input]->getType() == VIDEOFILE )
	{
		VideoFileInput *video;
		video =	(VideoFileInput*) videoList[input];
		return video->getLength();
	}
	return 0.0f;
}

double VideoManControl::getPosition( size_t input )
{
	assert( input >= 0 && input< videoList.size() && "goToMilisecond: Index out of range");
	if ( videoList[input]->getType() == VIDEOFILE )
	{
		VideoFileInput *video;
		video =	(VideoFileInput*) videoList[input];
		return video->getPosition();
	}
	return 0.0f;
}



void VideoManControl::getFormat( size_t input, VideoManInputFormat &format )
{
	assert( input >= 0 && input< videoList.size() && "getFrame: Index out of range");
	format = videoList[input]->getVideoManInputFormat();
}


inline void VideoManControl::updateTexture( size_t input, const char *image )
{
	assert( input >= 0 && input < videoList.size() && "updateTexture: Index out of range");
	assert( renderer !=NULL && "updateTexure(): Renderer not created");	
	renderer->updateTexture( input, image );
}

inline void VideoManControl::updateTexture( size_t input )
{
	assert( input >= 0 && input < videoList.size() && "updateTexture: Index out of range");
	assert( renderer !=NULL && "updateTexure(): Renderer not created");
	renderer->updateTexture( input );
}

char *VideoManControl::getFrame( size_t input, bool wait )

{
	assert( input >= 0 && input < videoList.size() && "getFrame: Index out of range");

	char *img = videoList[input]->getFrame( wait );
//	if ( img != NULL  &&  renderer != NULL )
//		renderer->updateTexture( input );
	return img;
}


void VideoManControl::releaseFrame( size_t input )
{
	assert( input >= 0 && input < videoList.size() && "releaseFrame: Index out of range");
	videoList[input]->releaseFrame();
}


void VideoManControl::renderFrames() const
{
	assert( renderer !=NULL && "renderFrames(): Renderer not created");
	renderer->renderInputs();
}

void VideoManControl::renderFrame( size_t input ) const
{
	assert( renderer !=NULL && "renderFrames(): Renderer not created");
	renderer->renderInput( input );
}

int VideoManControl::screenToImageCoords( float &x, float &y )
{
	assert( renderer !=NULL && "inputCoords(): Renderer not created");
	return renderer->screenToImageCoords( x, y );
}

bool VideoManControl::imageToScreenCoords( const size_t &input, float &x, float &y )
{
	assert( renderer !=NULL && "inputCoords(): Renderer not created");
	return renderer->imageToScreenCoords( input, x, y );
}

bool VideoManControl::getScreenCoords( const size_t &input, int &left, int &up, int &width, int &height )
{
	assert( renderer !=NULL && "getScreenCoords(): Renderer not created");
	return renderer->getScreenCoords( input, left, up, width, height );
}

void VideoManControl::activateViewport( const size_t &input )
{
	assert( renderer !=NULL && "activateViewport(): Renderer not created");
	renderer->activateViewport( input );
}


void VideoManControl::activateTexture( const size_t &input )
{
	assert( renderer !=NULL && "activateTexture(): Renderer not created");
	renderer->activateTexture( input );
}

void VideoManControl::getTextureCoords( const size_t &input, float &left, float &bottom, float &right, float &up )
{
	assert( renderer !=NULL && "getTextureCoords(): Renderer not created");
	renderer->getTextureCoords( input, left, up, right, bottom );
}

void VideoManControl::getAvailableDevices( std::vector<inputIdentification> &deviceList )
{
	factory.getAvailableDevices( deviceList );
}

void VideoManControl::getAvailableDevices( const std::string &identifier, std::vector<inputIdentification> &deviceList )
{
	factory.getAvailableDevices( identifier, deviceList );
}

int VideoManControl::getNumberOfInputs()
{
	return static_cast<int>( videoList.size() - emptyIndexes.size() );
}

void VideoManControl::setUserInputImage(  size_t input, char* image )
{
	assert( input >= 0 && input< videoList.size() && "setUserInputImage: Index out of range");
	if ( videoList[input]->getType() == IMAGE )
	{
		UserInput *video;
		video =	(UserInput*) videoList[input];
		video->setImage( image );
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -