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