OSErr 	DrawCompleteProc(Movie theMovie, long refCon){

	ofQuickTimePlayer * ofvp = (ofQuickTimePlayer *)refCon;

	#if defined(TARGET_OSX) && defined(__BIG_ENDIAN__)
        if (pixelFormat == OF_PIXELS_RGBA) {
            convertPixels(ofvp->offscreenGWorldPixels, ofvp->pixels.getPixels(), ofvp->width, ofvp->height, 4);
        } else {
            convertPixels(ofvp->offscreenGWorldPixels, ofvp->pixels.getPixels(), ofvp->width, ofvp->height, 3);
        }
	#endif

	ofvp->bHavePixelsChanged = true;
	return noErr;
}
//--------------------------------------------------------------------
void ofQuickTimeGrabber::update(){

	//---------------------------------
	#ifdef OF_VIDEO_CAPTURE_QUICKTIME
	//---------------------------------

		if (bGrabberInited == true){
			SGIdle(gSeqGrabber);
			// set the top pixel alpha = 0, so we can know if it
			// was a new frame or not..
			// or else we will process way more than necessary
			// (ie opengl is running at 60fps +, capture at 30fps)
			if (bHavePixelsChanged){
				
				#if defined(TARGET_OSX) && defined(__BIG_ENDIAN__)
					convertPixels(offscreenGWorldPixels, pixels.getPixels(), width, height);
				#endif
			}
		}

		// newness test for quicktime:
		if (bGrabberInited == true){
			bIsFrameNew = false;
			if (bHavePixelsChanged == true){
				bIsFrameNew = true;
				bHavePixelsChanged = false;
			}
		}


	//---------------------------------
	#endif
	//---------------------------------

}
//--------------------------------------------------------
void ofQuickTimePlayer::start(){

	//--------------------------------------
	#ifdef OF_VIDEO_PLAYER_QUICKTIME
	//--------------------------------------

	if (bLoaded == true && bStarted == false){
		SetMovieActive(moviePtr, true);

		//------------------ set the movie rate to default
		//------------------ and preroll, so the first frames come correct

		TimeValue timeNow 	= 	GetMovieTime(moviePtr, 0);
		Fixed playRate 		=	GetMoviePreferredRate(moviePtr); 		//Not being used!

		PrerollMovie(moviePtr, timeNow, X2Fix(speed));
		SetMovieRate(moviePtr,  X2Fix(speed));
		setLoopState(currentLoopState);

		// get some pixels in there right away:
		MoviesTask(moviePtr,0);
		#if defined(TARGET_OSX) && defined(__BIG_ENDIAN__)
			convertPixels(offscreenGWorldPixels, pixels.getPixels(), width, height);
		#endif
		bHavePixelsChanged = true;

		bStarted = true;
		bPlaying = true;
	}

	//--------------------------------------
	#endif
	//--------------------------------------
}
//--------------------------------------------------------
void ofVideoPlayer::start(){

	//--------------------------------------
	#ifdef OF_VIDEO_PLAYER_QUICKTIME
	//--------------------------------------

	if (bLoaded == true && bStarted == false){
		SetMovieActive(moviePtr, true);

		//------------------ set the movie rate to default
		//------------------ and preroll, so the first frames come correct

		TimeValue timeNow 	= 	GetMovieTime(moviePtr, 0);
		Fixed playRate 		=	GetMoviePreferredRate(moviePtr); 		//Not being used!

		PrerollMovie(moviePtr, timeNow, X2Fix(speed));
		SetMovieRate(moviePtr,  X2Fix(speed));
		setLoopState(OF_LOOP_NORMAL);

		// get some pixels in there right away:
		MoviesTask(moviePtr,0);
		convertPixels(offscreenGWorldPixels, pixels, width, height);
		bHavePixelsChanged = true;
		if (bUseTexture == true){
			tex.loadData(pixels, width, height, GL_RGB);
		}

		bStarted = true;
		bPlaying = true;
	}

	//--------------------------------------
	#endif
	//--------------------------------------
}
OSErr 	DrawCompleteProc(Movie theMovie, long refCon){

	ofVideoPlayer * ofvp = (ofVideoPlayer *)refCon;
	convertPixels(ofvp->offscreenGWorldPixels, ofvp->pixels, ofvp->width, ofvp->height);
	ofvp->bHavePixelsChanged = true;
	if (ofvp->bUseTexture == true){
		ofvp->tex.loadData(ofvp->pixels, ofvp->width, ofvp->height, GL_RGB);
	}

	return noErr;
}
Example #6
0
//--------------------------------------------------------------
void ofApp::update(){

    boids.update(pointX, pointY);
    osc.update();
    
    if(bRecording){
        cap.readToPixels(recordPixels);
        convertPixels();
        vidRecorder.addFrame(converted);
    }

}
Example #7
0
//--------------------------------------------------------------
void ofApp::update(){

    storm.particle_size = (GLfloat)calcSize.update();
    storm.update(pointX, pointY);
    osc->update();
    
    //VideoCapture
    if(bRecording){
        cap.readToPixels(recordPixels);
        convertPixels();
        vidRecorder.addFrame(converted);
    }

}
OSErr 	DrawCompleteProc(Movie theMovie, long refCon){

	ofVideoPlayer * ofvp = (ofVideoPlayer *)refCon;

	#if defined(TARGET_OSX) && defined(__BIG_ENDIAN__)
		convertPixels(ofvp->offscreenGWorldPixels, ofvp->pixels, ofvp->width, ofvp->height);
	#endif

	ofvp->bHavePixelsChanged = true;
	if (ofvp->bUseTexture == true){
		ofvp->tex.loadData(ofvp->pixels, ofvp->width, ofvp->height, GL_RGB);
	}

	return noErr;
}
Example #9
0
//--------------------------------------------------------------------
void ofVideoGrabber::grabFrame(){

	//---------------------------------
	#ifdef OF_VIDEO_CAPTURE_QUICKTIME
	//---------------------------------

		if (bGrabberInited == true){
			SGIdle(gSeqGrabber);
			// set the top pixel alpha = 0, so we can know if it
			// was a new frame or not..
			// or else we will process way more than necessary
			// (ie opengl is running at 60fps +, capture at 30fps)
			if (offscreenGWorldPixels[0] != 0x00){
				offscreenGWorldPixels[0] = 0x00;
				bHavePixelsChanged = true;
				convertPixels(offscreenGWorldPixels, pixels, width, height);
				if (bUseTexture){
					tex.loadData(pixels, width, height, GL_RGB);
				}
			}
		}

		// newness test for quicktime:
		if (bGrabberInited == true){
			bIsFrameNew = false;
			if (bHavePixelsChanged == true){
				bIsFrameNew = true;
				bHavePixelsChanged = false;
			}
		}


	//---------------------------------
	#endif
	//---------------------------------

	//---------------------------------
	#ifdef OF_VIDEO_CAPTURE_DIRECTSHOW
	//---------------------------------

		if (bGrabberInited == true){
			bIsFrameNew = false;
			if (VI.isFrameNew(device)){

				bIsFrameNew = true;


				/*
				 	rescale --
				 	currently this is nearest neighbor scaling
				 	not the greatest, but fast
				 	this can be optimized too
				 	with pointers, etc

				 	better --
				 	make sure that you ask for a "good" size....

				*/

				unsigned char * viPixels = VI.getPixels(device, true, true);


				if (bDoWeNeedToResize == true){

					int inputW = VI.getWidth(device);
					int inputH = VI.getHeight(device);

					float scaleW =	(float)inputW / (float)width;
					float scaleH =	(float)inputH / (float)height;

					for(int i=0;i<width;i++){
						for(int j=0;j<height;j++){

							float posx = i * scaleW;
							float posy = j * scaleH;

							/*

							// start of calculating
							// for linear interpolation

							int xbase = (int)floor(posx);
							int xhigh = (int)ceil(posx);
							float pctx = (posx - xbase);

							int ybase = (int)floor(posy);
							int yhigh = (int)ceil(posy);
							float pcty = (posy - ybase);
							*/

							int posPix = (((int)posy * inputW * 3) + ((int)posx * 3));

							pixels[(j*width*3) + i*3    ] = viPixels[posPix  ];
							pixels[(j*width*3) + i*3 + 1] = viPixels[posPix+1];
							pixels[(j*width*3) + i*3 + 2] = viPixels[posPix+2];

						}
					}

				} else {

					memcpy(pixels, viPixels, width*height*3);

				}

				if (bUseTexture){
					tex.loadData(pixels, width, height, GL_RGB);
				}
			}
		}

	//---------------------------------
	#endif
	//---------------------------------


	//---------------------------------
	#ifdef OF_VIDEO_CAPTURE_UNICAP
	//--------------------------------

		if (bGrabberInited){
			bIsFrameNew = ucGrabber.getFrameUC(&pixels);
			if(bIsFrameNew) {
				if (bUseTexture){
					tex.loadData(pixels, width, height, GL_RGB);
				}
			}
		}

	//---------------------------------
	#endif
	//---------------------------------

	//---------------------------------
	#ifdef OF_VIDEO_CAPTURE_GSTREAMER
	//--------------------------------

		if (bGrabberInited){
			gstUtils.update();
			bIsFrameNew = gstUtils.isFrameNew();
			if(bIsFrameNew) {
				if (bUseTexture){
					tex.loadData(gstUtils.getPixels(), width, height, GL_RGB);
				}
			}
		}

	//---------------------------------
	#endif
	//---------------------------------

	//---------------------------------
	#ifdef OF_VIDEO_CAPTURE_V4L
	//--------------------------------

		if (bV4LGrabberInited == true){
			bIsFrameNew = getFrameV4L(pixels);
			if(bIsFrameNew) {
				if (bUseTexture){
					tex.loadData(pixels, width, height, GL_RGB);
				}
			}
		}

	//---------------------------------
	#endif
	//---------------------------------

}
//---------------------------------------------------------------------------
bool ofQuickTimePlayer::loadMovie(string name){


	//--------------------------------------
	#ifdef OF_VIDEO_PLAYER_QUICKTIME
	//--------------------------------------

		initializeQuicktime();			// init quicktime
		closeMovie();					// if we have a movie open, close it
		bLoaded 				= false;	// try to load now

		if( name.substr(0, 7) == "http://" || name.substr(0,7) == "rtsp://" ){
			if(! createMovieFromURL(name, moviePtr) ) return false;
		}else{
			name 					= ofToDataPath(name);
			if( !createMovieFromPath((char *)name.c_str(), moviePtr) ) return false;
		}

		bool bDoWeAlreadyHaveAGworld = false;
		if (width != 0 && height != 0){
			bDoWeAlreadyHaveAGworld = true;
		}
		Rect 				movieRect;
		GetMovieBox(moviePtr, &(movieRect));
		if (bDoWeAlreadyHaveAGworld){
			// is the gworld the same size, then lets *not* de-allocate and reallocate:
			if (width == movieRect.right &&
				height == movieRect.bottom){
				SetMovieGWorld (moviePtr, offscreenGWorld, nil);
			} else {
				width 	= movieRect.right;
				height 	= movieRect.bottom;
				pixels.clear();
				delete(offscreenGWorldPixels);
				if ((offscreenGWorld)) DisposeGWorld((offscreenGWorld));
				createImgMemAndGWorld();
			}
		} else {
			width	= movieRect.right;
			height 	= movieRect.bottom;
			createImgMemAndGWorld();
		}

		if (moviePtr == NULL){
			return false;
		}

		//----------------- callback method
	    myDrawCompleteProc = NewMovieDrawingCompleteUPP (DrawCompleteProc);
		SetMovieDrawingCompleteProc (moviePtr, movieDrawingCallWhenChanged,  myDrawCompleteProc, (long)this);

		// ------------- get the total # of frames:
		nFrames				= 0;
		TimeValue			curMovieTime;
		curMovieTime		= 0;
		TimeValue			duration;

		//OSType whichMediaType	= VIDEO_TYPE; // mingw chokes on this
		OSType whichMediaType	= FOUR_CHAR_CODE('vide');

		short flags				= nextTimeMediaSample + nextTimeEdgeOK;

		while( curMovieTime >= 0 ) {
			nFrames++;
			GetMovieNextInterestingTime(moviePtr,flags,1,&whichMediaType,curMovieTime,0,&curMovieTime,&duration);
			flags = nextTimeMediaSample;
		}
		nFrames--; // there's an extra time step at the end of themovie




		// ------------- get some pixels in there ------
		GoToBeginningOfMovie(moviePtr);
		SetMovieActiveSegment(moviePtr, -1,-1);
		MoviesTask(moviePtr,0);

		#if defined(TARGET_OSX) && defined(__BIG_ENDIAN__)
			convertPixels(offscreenGWorldPixels, pixels.getPixels(), width, height);
		#endif

		bStarted 				= false;
		bLoaded 				= true;
		bPlaying 				= false;
		bHavePixelsChanged 		= false;
		speed 					= 1;

		return true;

	//--------------------------------------
	#endif
	//--------------------------------------



}
//---------------------------------------------------------------------------
bool ofQuickTimePlayer::loadMovie(string name) {


    //--------------------------------------
#ifdef OF_VIDEO_PLAYER_QUICKTIME
    //--------------------------------------

    initializeQuicktime();			// init quicktime
    closeMovie();					// if we have a movie open, close it
    bLoaded 				= false;	// try to load now


    // from : https://github.com/openframeworks/openFrameworks/issues/244
    // http://developer.apple.com/library/mac/#documentation/QuickTime/RM/QTforWindows/QTforWindows/C-Chapter/3BuildingQuickTimeCa.html
    // Apple's documentation *seems* to state that a Gworld should have been set prior to calling NewMovieFromFile
    // So I set a dummy Gworld (1x1 pixel) before calling createMovieFromPath
    // it avoids crash at the creation of objet ofVideoPlayer after a previous ofVideoPlayer have been deleted

#ifdef TARGET_WIN32
    if (width != 0 && height != 0) {
        pixels.clear();
        delete [] offscreenGWorldPixels;
    }
    width = 1;
    height = 1;
    createImgMemAndGWorld();
#endif


    if( name.substr(0, 7) == "http://" || name.substr(0,7) == "rtsp://" ) {
        if(! createMovieFromURL(name, moviePtr) ) return false;
    } else {
        name 					= ofToDataPath(name);
        if( !createMovieFromPath((char *)name.c_str(), moviePtr) ) return false;
    }

    bool bDoWeAlreadyHaveAGworld = false;
    if (width != 0 && height != 0) {
        bDoWeAlreadyHaveAGworld = true;
    }
    Rect 				movieRect;
    GetMovieBox(moviePtr, &(movieRect));
    if (bDoWeAlreadyHaveAGworld) {
        // is the gworld the same size, then lets *not* de-allocate and reallocate:
        if (width == movieRect.right &&
                height == movieRect.bottom) {
            SetMovieGWorld (moviePtr, offscreenGWorld, nil);
        } else {
            width 	= movieRect.right;
            height 	= movieRect.bottom;
            pixels.clear();
            delete [] offscreenGWorldPixels;
            if ((offscreenGWorld)) DisposeGWorld((offscreenGWorld));
            createImgMemAndGWorld();
        }
    } else {
        width	= movieRect.right;
        height 	= movieRect.bottom;
        createImgMemAndGWorld();
    }

    if (moviePtr == NULL) {
        return false;
    }

    //----------------- callback method
    myDrawCompleteProc = NewMovieDrawingCompleteUPP (DrawCompleteProc);
    SetMovieDrawingCompleteProc (moviePtr, movieDrawingCallWhenChanged,  myDrawCompleteProc, (long)this);

    // ------------- get the total # of frames:
    nFrames				= 0;
    TimeValue			curMovieTime;
    curMovieTime		= 0;
    TimeValue			duration;

    //OSType whichMediaType	= VIDEO_TYPE; // mingw chokes on this
    OSType whichMediaType	= FOUR_CHAR_CODE('vide');

    short flags				= nextTimeMediaSample + nextTimeEdgeOK;

    while( curMovieTime >= 0 ) {
        nFrames++;
        GetMovieNextInterestingTime(moviePtr,flags,1,&whichMediaType,curMovieTime,0,&curMovieTime,&duration);
        flags = nextTimeMediaSample;
    }
    nFrames--; // there's an extra time step at the end of themovie




    // ------------- get some pixels in there ------
    GoToBeginningOfMovie(moviePtr);
    SetMovieActiveSegment(moviePtr, -1,-1);
    MoviesTask(moviePtr,0);

#if defined(TARGET_OSX) && defined(__BIG_ENDIAN__)
    convertPixels(offscreenGWorldPixels, pixels.getPixels(), width, height);
#endif

    bStarted 				= false;
    bLoaded 				= true;
    bPlaying 				= false;
    bHavePixelsChanged 		= false;
    speed 					= 1;

    return true;

    //--------------------------------------
#endif
    //--------------------------------------



}
//---------------------------------------------------------------------------
bool ofVideoPlayer::loadMovie(string name){


	//--------------------------------------
	#ifdef OF_VIDEO_PLAYER_QUICKTIME
	//--------------------------------------

		initializeQuicktime();			// init quicktime
		closeMovie();					// if we have a movie open, close it
		bLoaded 				= false;	// try to load now
		
		if( name.substr(0, 7) == "http://"){
			if(! createMovieFromURL(name, moviePtr) ) return false;
		}else{
			name 					= ofToDataPath(name);
			if( !createMovieFromPath((char *)name.c_str(), moviePtr) ) return false;
		}
		
		bool bDoWeAlreadyHaveAGworld = false;
		if (width != 0 && height != 0){
			bDoWeAlreadyHaveAGworld = true;
		}
		Rect 				movieRect;
		GetMovieBox(moviePtr, &(movieRect));
		if (bDoWeAlreadyHaveAGworld){
			// is the gworld the same size, then lets *not* de-allocate and reallocate:
			if (width == movieRect.right &&
				height == movieRect.bottom){
				SetMovieGWorld (moviePtr, offscreenGWorld, nil);
			} else {
				width 	= movieRect.right;
				height 	= movieRect.bottom;
				delete(pixels);
				delete(offscreenGWorldPixels);
				if ((offscreenGWorld)) DisposeGWorld((offscreenGWorld));
				createImgMemAndGWorld();
			}
		} else {
			width	= movieRect.right;
			height 	= movieRect.bottom;
			createImgMemAndGWorld();
		}

		if (moviePtr == NULL){
			return false;
		}

		//----------------- callback method
	    MovieDrawingCompleteUPP myDrawCompleteProc;
	    myDrawCompleteProc = NewMovieDrawingCompleteUPP (DrawCompleteProc);
		SetMovieDrawingCompleteProc (moviePtr, movieDrawingCallWhenChanged,  myDrawCompleteProc, (long)this);

		// ------------- get some pixels in there ------
		GoToBeginningOfMovie(moviePtr);
		SetMovieActiveSegment(moviePtr, -1,-1);
		MoviesTask(moviePtr,0);
		convertPixels(offscreenGWorldPixels, pixels, width, height);
		if (bUseTexture == true){
			tex.loadData(pixels, width, height, GL_RGB);
		}
		
		bStarted 				= false;
		bLoaded 				= true;
		bPlaying 				= false;
		bHavePixelsChanged 		= false;
		speed 					= 1;

		return true;

	//--------------------------------------
	#else
	//--------------------------------------

		bLoaded      		= false;
		bPaused 			= false;
		speed 				= 1.0f;
		bHavePixelsChanged 	= false;
		name 					= ofToDataPath(name);
		fobsDecoder 		= new omnividea::fobs::Decoder(name.c_str());
		omnividea::fobs::ReturnCode error = fobsDecoder->open();

		width 					= fobsDecoder->getWidth();
		height 					= fobsDecoder->getHeight();
		pixels					= new unsigned char[width*height*3];

		if (!fobsDecoder->isVideoPresent()){
			return false;
		}

		bLoaded = true;

		if (bUseTexture){
			// create the texture, set the pixels to black and
			// upload them to the texture (so at least we see nothing black the callback)
			tex.allocate(width,height,GL_RGB);
			memset(pixels, 0, width*height*3);
			tex.loadData(pixels, width, height, GL_RGB);
		}


		error = fobsDecoder->setFrame(0);

		if(error == omnividea::fobs::NoFrameError) {
			error = omnividea::fobs::OkCode;
			printf("NoFrameError\n");
		}

		if(omnividea::fobs::isOk(error)){
			// get some pixels in:
			unsigned char *rgb = fobsDecoder->getRGB();
			if(rgb == NULL) error = omnividea::fobs::GenericError;
			if(isOk(error))
			{
				memcpy(pixels, rgb, width*height*3);
				tex.loadData(pixels, width, height, GL_RGB);
			}
		}


		iTotalFrames		= (int)(fobsDecoder->getFrameRate()*fobsDecoder->getDurationSeconds());
		positionPct 		= 0;
		timeLastIdle 		= ofGetElapsedTimef();
        durationMillis      = fobsDecoder->getDurationSeconds() * 1000.0f;


		return true;


	//--------------------------------------
	#endif
	//--------------------------------------



}