#ifndef _QT_VIDEO_PLAYER
#define _QT_VIDEO_PLAYER

#include "ofConstants.h"
#include "ofQtUtils.h"
#include "ofTexture.h"

//-------------------------------------------------
//	(notes, links, etc)
//
// 	intersting technique employed here to get to RGB24
// 	from YUV2 - worthwhile?  
// 	paste.lisp.org/display/1051
//-----------------------------
//	http://viewcvs.osafoundation.org/chandler/trunk/internal/wx/src/msw/mediactrl.cpp?rev=6281&view=markup
//	http://developer.apple.com/documentation/QuickTime/INMAC/QT/iqMovieToolbox.34.htm
// 	look for "QTURL_NewMovieFromURL", useful for loading URL based movies..
//-------------------------------------------------
// 
//  http://lists.apple.com/archives/QuickTime-API/2002/Feb/msg00118.html
//
//-------------------------------------------------
//
//  note about callbacks:
//	
//	we use here a callback provided by quicktime to see if pixels have actually changed
// 	the callback is "DrawCompleteProc" and int he quicktime code, 	
// 	is defined as "static pascal OsErr ...."
//  in windows, I have dropped the pascal declaration as my compiler was 
//	having trouble with that... necessary for mac?
//
//	the alternative is to do what is done in qtVideoGrabber
//	set the alpha of the top pixel to 0x00 and every idle call
//  check to see if there are new pixels...

#define OF_QT_LOOP_NONE					0x01
#define OF_QT_LOOP_PALINDROME			0x02
#define OF_QT_LOOP_NORMAL				0x03

//---------------------------------------------
// this struct has all the info we need to play 1 movie
// kept in a struct, because the callback will 
// need to reference it... 
typedef struct {
	MovieController  	thePlayer;
	GWorldPtr 			offscreenGWorld;
	Movie 			 	moviePtr;
	Rect 				movieRect;
	unsigned char * 	offscreenGWorldPixels;	// 32 bit: argb (qt k32ARGBPixelFormat)	
	unsigned char * 	pixels;					// 24 bit: rgb
	int					w;
	int 				h;
	bool 				bHavePixelsChanged;
	ofTexture 			* tex;					// a ptr to the texture we are utilizing
	bool 				bUseTexture;			// are we using a texture
} videoPlayerData;
//---------------------------------------------

class ofQtVideoPlayer{
	
	public:
	
	
		ofQtVideoPlayer ();
				
		void 	closeMovie();
		bool 	loadMovie(char * name);
		void 	idleMovie();				// rename to updateMovie?
		
		int 				width, height;
		float  				speed;
		bool 				bLoadedMovie;	
		
		bool 				isFrameNew();
		unsigned char * 	getPixels();
		float 				getPosition();
		float 				getSpeed();
		float 				getDuration();	
		
		void 				setPosition(float pct);
		void 				setVolume(int volume);
		void 				setLoopState(int state);
		void   				setSpeed(float speed);
		
		void 				setUseTexture(bool bUse);
		void 				draw(float x, float y, float w, float h);	
		void 				draw(float x, float y);	
		
		void 				setPaused(bool bPause);
		
	private:
	
		//---------------------------
		videoPlayerData				* vpd;
		ofTexture 					tex;
		bool						bUseTexture;	
					
}; 
#endif

