00001 #ifndef _OF_VIDEO_PLAYER 00002 #define _OF_VIDEO_PLAYER 00003 00004 #include "ofConstants.h" 00005 #include "ofTexture.h" 00006 00007 00008 #ifdef OF_VIDEO_PLAYER_GSTREAMER 00009 #include <gst/gst.h> 00010 #include <pthread.h> 00011 00012 typedef struct{ 00013 GMainLoop * loop; 00014 GstElement * pipeline; 00015 unsigned char * pixels; 00016 pthread_mutex_t buffer_mutex; 00017 bool bHasPixelsChanged; 00018 00019 guint64 durationNanos; 00020 guint64 nFrames; 00021 int pipelineState; 00022 float speed; 00023 }ofGstVideoData; 00024 00025 #else 00026 #include "ofQtUtils.h" 00027 #endif 00028 00029 00030 00031 #define OF_LOOP_NONE 0x01 00032 #define OF_LOOP_PALINDROME 0x02 00033 #define OF_LOOP_NORMAL 0x03 00034 00035 00036 //--------------------------------------------- 00037 00038 class ofVideoPlayer : public ofBaseVideo{ 00039 00040 public: 00041 00042 00043 ofVideoPlayer (); 00044 virtual ~ofVideoPlayer(); 00045 00046 bool loadMovie(string name); 00047 void closeMovie(); 00048 void close(); 00049 00050 void update(); //same as idleMovie 00051 void idleMovie(); // rename to updateMovie? 00052 void play(); 00053 void stop(); 00054 00055 int width, height; 00056 float speed; 00057 bool bLoaded; 00058 00059 bool isFrameNew(); 00060 unsigned char * getPixels(); 00061 float getPosition(); 00062 float getSpeed(); 00063 float getDuration(); 00064 bool getIsMovieDone(); 00065 00066 void setPosition(float pct); 00067 void setVolume(int volume); 00068 void setLoopState(int state); 00069 void setSpeed(float speed); 00070 void setFrame(int frame); // frame 0 = first frame... 00071 00072 void setUseTexture(bool bUse); 00073 ofTexture & getTextureReference(); 00074 void draw(float x, float y, float w, float h); 00075 void draw(float x, float y); 00076 00077 //the anchor is the point the image is drawn around. 00078 //this can be useful if you want to rotate an image around a particular point. 00079 void setAnchorPercent(float xPct, float yPct); //set the anchor as a percentage of the image width/height ( 0.0-1.0 range ) 00080 void setAnchorPoint(int x, int y); //set the anchor point in pixels 00081 void resetAnchor(); //resets the anchor to (0, 0) 00082 00083 void setPaused(bool bPause); 00084 00085 int getCurrentFrame(); 00086 int getTotalNumFrames(); 00087 00088 void firstFrame(); 00089 void nextFrame(); 00090 void previousFrame(); 00091 00092 float getHeight(); 00093 float getWidth(); 00094 00095 //-------------------------------------- 00096 #ifdef OF_VIDEO_PLAYER_QUICKTIME 00097 //-------------------------------------- 00098 MovieController thePlayer; 00099 GWorldPtr offscreenGWorld; 00100 Movie moviePtr; 00101 unsigned char * offscreenGWorldPixels; // 32 bit: argb (qt k32ARGBPixelFormat) 00102 void qtGetFrameCount(Movie & movForcount); 00103 //-------------------------------------- 00104 #endif 00105 //-------------------------------------- 00106 00107 int nFrames; // number of frames 00108 unsigned char * pixels; // 24 bit: rgb 00109 bool bHavePixelsChanged; 00110 ofTexture tex; // a ptr to the texture we are utilizing 00111 bool bUseTexture; // are we using a texture 00112 bool allocated; // so we know to free pixels or not 00113 00114 protected: 00115 00116 00117 void start(); 00118 void createImgMemAndGWorld(); 00119 bool bStarted; 00120 bool bPlaying; 00121 bool bPaused; 00122 bool bIsFrameNew; // if we are new 00123 00124 //-------------------------------------- 00125 #ifdef OF_VIDEO_PLAYER_GSTREAMER 00126 //-------------------------------------- 00127 ofGstVideoData gstData; 00128 bool bIsMovieDone; 00129 bool isStream; 00130 GstElement * gstPipeline; 00131 GstElement * gstSink; 00132 gint64 durationNanos; 00133 int loopMode; 00134 00135 bool posChangingPaused; 00136 00137 00138 pthread_mutex_t seek_mutex; 00139 void seek_lock(); 00140 void seek_unlock(); 00141 void gstHandleMessage(); 00142 bool allocate(); 00143 //-------------------------------------- 00144 #endif 00145 //-------------------------------------- 00146 00147 00148 }; 00149 #endif 00150 00151 00152 00153 00154 00155