Panda3D
movieTexture.h
1 // Filename: movieTexture.h
2 // Created by: jyelon (01Aug2007)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef MOVIETEXTURE_H
16 #define MOVIETEXTURE_H
17 
18 #include "pandabase.h"
19 
20 #ifdef HAVE_AUDIO
21 
22 #include "movieVideo.h"
23 #include "movieVideoCursor.h"
24 #include "audioSound.h"
25 #include "pipelineCycler.h"
26 #include "cycleData.h"
27 #include "cycleDataWriter.h"
28 #include "cycleDataReader.h"
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : MovieTexture
32 // Description : A texture that fetches video frames from an
33 // underlying object of class Movie.
34 ////////////////////////////////////////////////////////////////////
35 class EXPCL_PANDA_GRUTIL MovieTexture : public Texture {
36 PUBLISHED:
37  MovieTexture(const string &name);
38  MovieTexture(MovieVideo *video);
39 private:
40  MovieTexture(const MovieTexture &copy);
41 PUBLISHED:
42  virtual ~MovieTexture();
43 
44  INLINE double get_video_length() const;
45  INLINE int get_video_width() const;
46  INLINE int get_video_height() const;
47 
48  INLINE MovieVideoCursor *get_color_cursor(int page);
49  INLINE MovieVideoCursor *get_alpha_cursor(int page);
50 
51  void restart();
52  void stop();
53  void play();
54  void set_time(double t);
55  double get_time() const;
56  void set_loop(bool enable);
57  bool get_loop() const;
58  void set_loop_count(int count);
59  int get_loop_count() const;
60  void set_play_rate(double play_rate);
61  double get_play_rate() const;
62  bool is_playing() const;
63  void synchronize_to(AudioSound *sound);
64  void unsynchronize();
65 
66 public:
67  virtual void ensure_loader_type(const Filename &filename);
68 
69  static PT(Texture) make_texture();
70  virtual bool has_cull_callback() const;
71  virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const;
72 
73 protected:
74  class CData;
75 
76  virtual PT(Texture) make_copy_impl();
77  void do_assign(CData *cdata, Texture::CData *cdata_tex, const MovieTexture *copy,
78  const CData *cdata_copy, const Texture::CData *cdata_copy_tex);
79 
80  virtual void do_reload_ram_image(Texture::CData *cdata, bool allow_compression);
81  virtual bool get_keep_ram_image() const;
82  virtual bool do_has_bam_rawdata(const Texture::CData *cdata) const;
83  virtual void do_get_bam_rawdata(Texture::CData *cdata);
84  virtual bool do_can_reload(const Texture::CData *cdata) const;
85 
86  virtual bool do_adjust_this_size(const Texture::CData *cdata,
87  int &x_size, int &y_size, const string &name,
88  bool for_padding) const;
89 
90  virtual bool do_read_one(Texture::CData *cdata,
91  const Filename &fullpath, const Filename &alpha_fullpath,
92  int z, int n, int primary_file_num_channels, int alpha_file_channel,
93  const LoaderOptions &options,
94  bool header_only, BamCacheRecord *record);
95  virtual bool do_load_one(Texture::CData *cdata,
96  const PNMImage &pnmimage, const string &name,
97  int z, int n, const LoaderOptions &options);
98  bool do_load_one(Texture::CData *cdata,
99  PT(MovieVideoCursor) color, PT(MovieVideoCursor) alpha,
100  int z, const LoaderOptions &options);
101  virtual void do_allocate_pages(Texture::CData *cdata);
102 
103  class VideoPage {
104  public:
105  PT(MovieVideoCursor) _color;
106  PT(MovieVideoCursor) _alpha;
107 
108  // The current (but not yet applied) frame for each video.
109  PT(MovieVideoCursor::Buffer) _cbuffer;
110  PT(MovieVideoCursor::Buffer) _abuffer;
111  };
112 
113  typedef pvector<VideoPage> Pages;
114 
115  class EXPCL_PANDA_GRUTIL CData : public CycleData {
116  public:
117  CData();
118  CData(const CData &copy);
119  virtual CycleData *make_copy() const;
120  virtual TypeHandle get_parent_type() const {
121  return MovieTexture::get_class_type();
122  }
123 
124  Pages _pages;
125  int _video_width;
126  int _video_height;
127  double _video_length;
128 
129  double _clock;
130  bool _playing;
131  int _loop_count;
132  double _play_rate;
133  PT(AudioSound) _synchronize;
134 
135  // The remaining values represent a local cache only; it is not
136  // preserved through the pipeline.
137  bool _has_offset;
138  double _offset;
139  int _true_loop_count;
140  };
141 
142  PipelineCycler<CData> _cycler;
143  typedef CycleDataReader<CData> CDReader;
144  typedef CycleDataWriter<CData> CDWriter;
145 
146  void do_recalculate_image_properties(CData *cdata, Texture::CData *cdata_tex,
147  const LoaderOptions &options);
148 
149 private:
150  bool do_update_frames(const CData *cdata) const;
151 
152 public:
153  static void register_with_read_factory();
154 
155  static TypedWritable *make_from_bam(const FactoryParams &params);
156  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
157  virtual void do_write_datagram_rawdata(Texture::CData *cdata, BamWriter *manager, Datagram &me);
158  virtual void do_fillin_rawdata(Texture::CData *cdata, DatagramIterator &scan, BamReader *manager);
159 
160  virtual void finalize(BamReader *manager);
161 
162 public:
163  static TypeHandle get_class_type() {
164  return _type_handle;
165  }
166  static void init_type() {
167  Texture::init_type();
168  register_type(_type_handle, "MovieTexture",
169  Texture::get_class_type());
170  }
171  virtual TypeHandle get_type() const {
172  return get_class_type();
173  }
174  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
175 
176 private:
177  static TypeHandle _type_handle;
178 };
179 
180 #include "movieTexture.I"
181 
182 #endif // HAVE_AUDIO
183 
184 #endif
virtual void ensure_loader_type(const Filename &filename)
May be called prior to calling read_txo() or any bam-related Texture-creating callback, to ensure that the proper dynamic libraries for a Texture of the current class type, and the indicated filename, have been already loaded.
Definition: texture.cxx:2607
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:68
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Specifies parameters that may be passed to the loader.
Definition: loaderOptions.h:26
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition: texture.h:75
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
virtual bool cull_callback(CullTraverser *trav, const CullTraverserData &data) const
If has_cull_callback() returns true, this function will be called during the cull traversal to perfor...
Definition: texture.cxx:2379
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
A MovieVideo is actually any source that provides a sequence of video frames.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
A MovieVideo is actually any source that provides a sequence of video frames.
Definition: movieVideo.h:42
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool get_keep_ram_image() const
Returns the flag that indicates whether this Texture is eligible to have its main RAM copy of the tex...
Definition: texture.cxx:964
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
virtual bool has_cull_callback() const
Should be overridden by derived classes to return true if cull_callback() has been defined...
Definition: texture.cxx:2361