//---------------------------------------------------------------------------
bool ofVideoPlayer::loadMovie(string name){
	//#ifndef TARGET_ANDROID
		if( player == NULL ){
			setPlayer( ofPtr<OF_VID_PLAYER_TYPE>(new OF_VID_PLAYER_TYPE) );
			player->setPixelFormat(internalPixelFormat);
		}
	//#endif
	
	bool bOk = player->loadMovie(name);
	width	 = player->getWidth();
	height	 = player->getHeight();

	if( bOk){
        moviePath = name;
        if(bUseTexture ){
            if(width!=0 && height!=0) {
                tex.allocate(width, height, ofGetGLInternalFormatFromPixelFormat(internalPixelFormat));
        		if(ofGetGLProgrammableRenderer() && internalPixelFormat == OF_PIXELS_MONO){
        			tex.setRGToRGBASwizzles(true);
        		}
            }
        }
    }
	
	return bOk;
}
//--------------------------------------------------------------------
void ofVideoPlayer::update(){
	if(	player != NULL ){

		player->update();
		
		if( bUseTexture && player->isFrameNew() ) {
			
			playerTex = player->getTexture();
			
			if(playerTex == NULL){
				unsigned char *pxls = player->getPixels();
				
				bool bDiffPixFormat = ( tex.bAllocated() && tex.texData.glTypeInternal != ofGetGLInternalFormatFromPixelFormat(internalPixelFormat) );
				
				//TODO: we might be able to do something smarter here for not re-allocating movies of the same size and type. 
				if(width==0 || height==0 || bDiffPixFormat ){ //added a check if the pixel format and the texture don't match
					if(player->getWidth() != 0 && player->getHeight() != 0) {
						
						width = player->getWidth();
						height = player->getHeight();
					
						if(tex.bAllocated())
							tex.clear();

						tex.allocate(width, height, ofGetGLInternalFormatFromPixelFormat(internalPixelFormat));
		        		if(ofGetGLProgrammableRenderer() && internalPixelFormat == OF_PIXELS_MONO){
		        			tex.setRGToRGBASwizzles(true);
		        		}
						tex.loadData(pxls, tex.getWidth(), tex.getHeight(), ofGetGLTypeFromPixelFormat(internalPixelFormat));
					}
				}else{					
					tex.loadData(pxls, width, height, ofGetGLTypeFromPixelFormat(internalPixelFormat));
				}
			}
		}
	}
}
//------------------------------------
void ofVideoPlayer::setUseTexture(bool bUse){
	bUseTexture = bUse;
	if(bUse && player && !player->getTexture() && getWidth()!=0 && getHeight()!=0){
		for(int i=0;i<player->getPixels().getNumPlanes();i++){
			ofPixels plane = player->getPixels().getPlane(i);
			bool bDiffPixFormat = ( tex[i].bAllocated() && tex[i].texData.glTypeInternal != ofGetGLInternalFormatFromPixelFormat(plane.getPixelFormat()) );
			if(!tex[i].isAllocated() || bDiffPixFormat){
				tex[i].allocate(plane);
			}
			if(ofGetGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){
				tex[i].setRGToRGBASwizzles(true);
			}
		}
	}
}
//--------------------------------------------------------------------
void ofVideoGrabber::update(){
	if(grabber){
		grabber->update();
		width = grabber->getWidth();
		height = grabber->getHeight();
		if( bUseTexture && !grabber->getTexture() && grabber->isFrameNew() ){
			if(int(tex.size())!=grabber->getPixelsRef().getNumPlanes()){
				tex.resize(grabber->getPixelsRef().getNumPlanes());
			}
			for(int i=0;i<grabber->getPixelsRef().getNumPlanes();i++){
				ofPixels plane = grabber->getPixelsRef().getPlane(i);
				bool bDiffPixFormat = ( tex[i].isAllocated() && tex[i].texData.glTypeInternal != ofGetGLInternalFormatFromPixelFormat(plane.getPixelFormat()) );
				if(width==0 || height==0 || bDiffPixFormat || !tex[i].isAllocated() ){
					tex[i].allocate(plane);
					if(ofGetGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){
						tex[i].setRGToRGBASwizzles(true);
					}
				}
				tex[i].loadData(plane);
			}
		}
	}
}
//--------------------------------------------------------------------
bool ofVideoGrabber::initGrabber(int w, int h, bool setUseTexture){

#ifndef OF_VID_GRABBER_TYPE
#error OF_VID_GRABBER_TYPE is not #defined! 
#endif
    
	if( grabber == NULL ){
		setGrabber( ofPtr<OF_VID_GRABBER_TYPE>(new OF_VID_GRABBER_TYPE) );
	}

	bInitialized = true;
	bUseTexture = setUseTexture;

	if( RequestedDeviceID >= 0 ){
		grabber->setDeviceID(RequestedDeviceID);
	}

	setPixelFormat(internalPixelFormat); //this safely handles checks for supported format

	if( desiredFramerate!=-1 ){
		grabber->setDesiredFrameRate(desiredFramerate);
	}

	grabberRunning	= grabber->initGrabber(w, h);
	width			= (int)grabber->getWidth();
	height			= (int)grabber->getHeight();

	if( grabberRunning && bUseTexture ){
		if(!grabber->getTexture()) tex.allocate(width, height, ofGetGLInternalFormatFromPixelFormat(internalPixelFormat));
		if(ofGetGLProgrammableRenderer() && internalPixelFormat == OF_PIXELS_MONO){
			tex.setRGToRGBASwizzles(true);
		}
	}

	return grabberRunning;
}
//--------------------------------------------------------------------
void ofVideoPlayer::update(){
	if( player ){

		player->update();
		width = player->getWidth();
		height = player->getHeight();
		
		if( bUseTexture && player->isFrameNew() ) {
			
			playerTex = player->getTexture();
			
			if(playerTex == NULL){
				if(int(tex.size())!=player->getPixels().getNumPlanes()){
					tex.resize(max(player->getPixels().getNumPlanes(),1));
				}
				if(player->getWidth() != 0 && player->getHeight() != 0) {
					for(int i=0;i<player->getPixels().getNumPlanes();i++){
						ofPixels plane = player->getPixels().getPlane(i);
						bool bDiffPixFormat = ( tex[i].isAllocated() && tex[i].texData.glTypeInternal != ofGetGLInternalFormatFromPixelFormat(plane.getPixelFormat()) );
						if(bDiffPixFormat || !tex[i].isAllocated() || tex[i].getWidth() != plane.getWidth() || tex[i].getHeight() != plane.getHeight()){
							tex[i].allocate(plane);
							if(ofGetGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY){
								tex[i].setRGToRGBASwizzles(true);
							}
						}
						tex[i].loadData(plane);
					}
				}
			}
		}
	}
}
Example #7
0
//---------------------------------
int ofGetGlInternalFormat(const ofPixels& pix) {
	return ofGetGLInternalFormatFromPixelFormat(pix.getPixelFormat());
}