Panda3D
movieVideo.cxx
1 // Filename: movieVideo.cxx
2 // Created by: jyelon (02Jul07)
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 #include "movieVideo.h"
16 #include "movieVideoCursor.h"
17 #include "config_movies.h"
18 #include "movieTypeRegistry.h"
19 #include "bamReader.h"
20 #include "bamWriter.h"
21 
22 TypeHandle MovieVideo::_type_handle;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: MovieVideo::Constructor
26 // Access: Public
27 // Description: This constructor returns a null video stream --- a
28 // stream of plain blue and white frames that last one
29 // second each. To get more interesting video, you need
30 // to construct a subclass of this class.
31 ////////////////////////////////////////////////////////////////////
33 MovieVideo(const string &name) :
34  Namable(name)
35 {
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: MovieVideo::Destructor
40 // Access: Public, Virtual
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 MovieVideo::
44 ~MovieVideo() {
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: MovieVideo::open
49 // Access: Published, Virtual
50 // Description: Open this video, returning a MovieVideoCursor of the
51 // appropriate type. Returns NULL on error.
52 ////////////////////////////////////////////////////////////////////
53 PT(MovieVideoCursor) MovieVideo::
54 open() {
55  return NULL;
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: MovieVideo::get
60 // Access: Published, Static
61 // Description: Obtains a MovieVideo that references a file.
62 // Just calls MovieTypeRegistry::make_video().
63 ////////////////////////////////////////////////////////////////////
64 PT(MovieVideo) MovieVideo::
65 get(const Filename &name) {
67  return reg->make_video(name);
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: MovieVideo::write_datagram
72 // Access: Public, Virtual
73 // Description: Writes the contents of this object to the datagram
74 // for shipping out to a Bam file.
75 ////////////////////////////////////////////////////////////////////
76 void MovieVideo::
79  dg.add_string(_filename);
80 
81  // Now we record the raw movie data directly into the bam stream.
82  // We always do this, regardless of bam-texture-mode; we generally
83  // won't get to this codepath if bam-texture-mode isn't rawdata
84  // anyway.
85 
86  SubfileInfo result;
87  if (!_subfile_info.is_empty()) {
88  dg.add_bool(true);
89  manager->write_file_data(result, _subfile_info);
90  } else if (!_filename.empty()) {
91  dg.add_bool(true);
92  manager->write_file_data(result, _filename);
93  } else {
94  dg.add_bool(false);
95  }
96 
97  /* Not sure yet if this is a good idea.
98  if (!result.is_empty()) {
99  // If we've just copied the data to a local file, read it from
100  // there in the future.
101  _subfile_info = result;
102  }
103  */
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: MovieVideo::fillin
108 // Access: Protected
109 // Description: This internal function is called by make_from_bam to
110 // read in all of the relevant data from the BamFile for
111 // the new MovieVideo.
112 ////////////////////////////////////////////////////////////////////
113 void MovieVideo::
114 fillin(DatagramIterator &scan, BamReader *manager) {
116  _filename = scan.get_string();
117 
118  bool got_info = scan.get_bool();
119  if (got_info) {
120  manager->read_file_data(_subfile_info);
121  }
122 }
void read_file_data(SubfileInfo &info)
Reads a block of auxiliary file data from the Bam file.
Definition: bamReader.cxx:731
bool get_bool()
Extracts a boolean value.
void add_string(const string &str)
Adds a variable-length string to the datagram.
Definition: datagram.I:351
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This class records the different types of MovieAudio and MovieVideo that are available for loading...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
string get_string()
Extracts a variable-length string.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void add_bool(bool value)
Adds a boolean value to the datagram.
Definition: datagram.I:118
A base class for all things which can have a name.
Definition: namable.h:29
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
A MovieVideo is actually any source that provides a sequence of video frames.
bool is_empty() const
Returns true if this SubfileInfo doesn't define any file, false if it has real data.
Definition: subfileInfo.I:86
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: movieVideo.cxx:77
MovieVideo(const string &name="Blank Video")
This constructor returns a null video stream — a stream of plain blue and white frames that last one...
Definition: movieVideo.cxx:33
static MovieTypeRegistry * get_global_ptr()
Returns a pointer to the global MovieTypeRegistry instance.
A MovieVideo is actually any source that provides a sequence of video frames.
Definition: movieVideo.h:42
This class records a particular byte sub-range within an existing file on disk.
Definition: subfileInfo.h:29
void write_file_data(SubfileInfo &result, const Filename &filename)
Writes a block of auxiliary file data from the indicated file (within the vfs).
Definition: bamWriter.cxx:329
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
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43