Panda3D
|
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(MovieVideo *video); 00038 private: 00039 MovieTexture(const MovieTexture ©); 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 00047 INLINE MovieVideoCursor *get_color_cursor(int page); 00048 INLINE MovieVideoCursor *get_alpha_cursor(int page); 00049 00050 void restart(); 00051 void stop(); 00052 void play(); 00053 void set_time(double t); 00054 double get_time() const; 00055 void set_loop(bool enable); 00056 bool get_loop() const; 00057 void set_loop_count(int count); 00058 int get_loop_count() const; 00059 void set_play_rate(double play_rate); 00060 double get_play_rate() const; 00061 bool is_playing() const; 00062 void synchronize_to(AudioSound *sound); 00063 void unsynchronize(); 00064 00065 public: 00066 static PT(Texture) make_texture(); 00067 virtual bool has_cull_callback() const; 00068 virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const; 00069 00070 protected: 00071 class CData; 00072 00073 virtual PT(Texture) make_copy_impl(); 00074 void do_assign(CData *cdata, Texture::CData *cdata_tex, const MovieTexture *copy, 00075 const CData *cdata_copy, const Texture::CData *cdata_copy_tex); 00076 00077 virtual void do_reload_ram_image(Texture::CData *cdata, bool allow_compression); 00078 virtual bool get_keep_ram_image() const; 00079 virtual bool do_has_bam_rawdata(const Texture::CData *cdata) const; 00080 virtual void do_get_bam_rawdata(Texture::CData *cdata); 00081 virtual bool do_can_reload(const Texture::CData *cdata) const; 00082 00083 virtual bool do_adjust_this_size(const Texture::CData *cdata, 00084 int &x_size, int &y_size, const string &name, 00085 bool for_padding) const; 00086 00087 virtual bool do_read_one(Texture::CData *cdata, 00088 const Filename &fullpath, const Filename &alpha_fullpath, 00089 int z, int n, int primary_file_num_channels, int alpha_file_channel, 00090 const LoaderOptions &options, 00091 bool header_only, BamCacheRecord *record); 00092 virtual bool do_load_one(Texture::CData *cdata, 00093 const PNMImage &pnmimage, const string &name, 00094 int z, int n, const LoaderOptions &options); 00095 bool do_load_one(Texture::CData *cdata, 00096 PT(MovieVideoCursor) color, PT(MovieVideoCursor) alpha, 00097 int z, const LoaderOptions &options); 00098 virtual void do_allocate_pages(Texture::CData *cdata); 00099 00100 class VideoPage { 00101 public: 00102 PT(MovieVideoCursor) _color; 00103 PT(MovieVideoCursor) _alpha; 00104 00105 // The current (but not yet applied) frame for each video. 00106 PT(MovieVideoCursor::Buffer) _cbuffer; 00107 PT(MovieVideoCursor::Buffer) _abuffer; 00108 }; 00109 00110 typedef pvector<VideoPage> Pages; 00111 00112 class EXPCL_PANDA_GRUTIL CData : public CycleData { 00113 public: 00114 CData(); 00115 CData(const CData ©); 00116 virtual CycleData *make_copy() const; 00117 virtual TypeHandle get_parent_type() const { 00118 return MovieTexture::get_class_type(); 00119 } 00120 00121 Pages _pages; 00122 int _video_width; 00123 int _video_height; 00124 double _video_length; 00125 00126 double _clock; 00127 bool _playing; 00128 int _loop_count; 00129 double _play_rate; 00130 PT(AudioSound) _synchronize; 00131 00132 // The remaining values represent a local cache only; it is not 00133 // preserved through the pipeline. 00134 bool _has_offset; 00135 double _offset; 00136 int _true_loop_count; 00137 }; 00138 00139 PipelineCycler<CData> _cycler; 00140 typedef CycleDataReader<CData> CDReader; 00141 typedef CycleDataWriter<CData> CDWriter; 00142 00143 void do_recalculate_image_properties(CData *cdata, Texture::CData *cdata_tex, 00144 const LoaderOptions &options); 00145 00146 private: 00147 bool do_update_frames(const CData *cdata) const; 00148 00149 public: 00150 static void register_with_read_factory(); 00151 00152 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00153 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00154 virtual void do_write_datagram_rawdata(Texture::CData *cdata, BamWriter *manager, Datagram &me); 00155 virtual void do_fillin_rawdata(Texture::CData *cdata, DatagramIterator &scan, BamReader *manager); 00156 00157 virtual void finalize(BamReader *manager); 00158 00159 public: 00160 static TypeHandle get_class_type() { 00161 return _type_handle; 00162 } 00163 static void init_type() { 00164 Texture::init_type(); 00165 register_type(_type_handle, "MovieTexture", 00166 Texture::get_class_type()); 00167 } 00168 virtual TypeHandle get_type() const { 00169 return get_class_type(); 00170 } 00171 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00172 00173 private: 00174 static TypeHandle _type_handle; 00175 }; 00176 00177 #include "movieTexture.I" 00178 00179 #endif // HAVE_AUDIO 00180 00181 #endif