Panda3D

movieTexture.h

00001 // Filename: movieTexture.h
00002 // Created by: jyelon (01Aug2007)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef MOVIETEXTURE_H
00016 #define MOVIETEXTURE_H
00017 
00018 #include "pandabase.h"
00019 
00020 #ifdef HAVE_AUDIO
00021 
00022 #include "movieVideo.h"
00023 #include "audioSound.h"
00024 #include "pipelineCycler.h"
00025 #include "cycleData.h"
00026 #include "cycleDataWriter.h"
00027 #include "cycleDataReader.h"
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //       Class : MovieTexture
00031 // Description : A texture that fetches video frames from an
00032 //               underlying object of class Movie.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_PANDA_GRUTIL MovieTexture : public Texture {
00035 PUBLISHED:
00036   MovieTexture(const string &name);
00037   MovieTexture(PT(MovieVideo) video);
00038 private:
00039   MovieTexture(const MovieTexture &copy);
00040 PUBLISHED:
00041   virtual ~MovieTexture();
00042 
00043   INLINE double get_video_length() const;
00044   INLINE int get_video_width() const;
00045   INLINE int get_video_height() const;
00046   INLINE LVecBase2f get_tex_scale() const;
00047   
00048   void   restart();
00049   void   stop();
00050   void   play();
00051   void   set_time(double t);
00052   double get_time() const;
00053   void   set_loop(bool enable);
00054   bool   get_loop() const;
00055   void   set_loop_count(int count);
00056   int    get_loop_count() const;
00057   void   set_play_rate(double play_rate);
00058   double get_play_rate() const;
00059   bool   is_playing() const;
00060   void   synchronize_to(AudioSound *sound);
00061   void   unsynchronize();
00062   
00063 public:
00064   static PT(Texture) make_texture();
00065   virtual bool has_cull_callback() const;
00066   virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const;
00067  
00068 protected:
00069   virtual PT(Texture) do_make_copy();
00070   void do_assign(const MovieTexture &copy);
00071 
00072   virtual void do_reload_ram_image();
00073   virtual bool get_keep_ram_image() const;
00074   virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
00075                            int z, int n, int primary_file_num_channels, int alpha_file_channel,
00076                            const LoaderOptions &options,
00077                            bool header_only, BamCacheRecord *record);
00078   virtual bool do_load_one(const PNMImage &pnmimage, const string &name,
00079                            int z, int n, const LoaderOptions &options);
00080   bool do_load_one(PT(MovieVideoCursor) color, PT(MovieVideoCursor) alpha, 
00081                    int z, const LoaderOptions &options);
00082 
00083   class VideoPage {
00084   public:
00085     VideoPage();
00086     PT(MovieVideoCursor) _color;
00087     PT(MovieVideoCursor) _alpha;
00088   };
00089   
00090   typedef pvector<VideoPage> Pages;
00091 
00092   class EXPCL_PANDA_GRUTIL CData : public CycleData {
00093   public:
00094     CData();
00095     CData(const CData &copy);
00096     virtual CycleData *make_copy() const;
00097     virtual TypeHandle get_parent_type() const {
00098       return MovieTexture::get_class_type();
00099     }
00100     
00101     Pages _pages;
00102     int _video_width;
00103     int _video_height;
00104     double _video_length;
00105 
00106     double         _clock;
00107     bool           _playing;
00108     int            _loop_count;
00109     int            _loops_total;
00110     double         _play_rate;
00111     PT(AudioSound) _synchronize;
00112   };
00113 
00114   PipelineCycler<CData> _cycler;
00115   typedef CycleDataReader<CData> CDReader;
00116   typedef CycleDataWriter<CData> CDWriter;
00117   
00118   void do_recalculate_image_properties(CDWriter &cdata, const LoaderOptions &options);
00119 
00120 public:
00121   static void register_with_read_factory();
00122 
00123 public:
00124   static TypeHandle get_class_type() {
00125     return _type_handle;
00126   }
00127   static void init_type() {
00128     Texture::init_type();
00129     register_type(_type_handle, "MovieTexture",
00130                   Texture::get_class_type());
00131   }
00132   virtual TypeHandle get_type() const {
00133     return get_class_type();
00134   }
00135   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00136 
00137 private:
00138   static TypeHandle _type_handle;
00139 };
00140 
00141 #include "movieTexture.I"
00142 
00143 #endif  // HAVE_AUDIO
00144 
00145 #endif
 All Classes Functions Variables Enumerations