Panda3D

movieVideo.cxx

00001 // Filename: movieVideo.cxx
00002 // Created by: jyelon (02Jul07)
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 #include "movieVideo.h"
00016 #include "config_movies.h"
00017 #include "ffmpegVideo.h"
00018 #include "bamReader.h"
00019 #include "bamWriter.h"
00020 
00021 TypeHandle MovieVideo::_type_handle;
00022 
00023 ////////////////////////////////////////////////////////////////////
00024 //     Function: MovieVideo::Constructor
00025 //       Access: Public
00026 //  Description: This constructor returns a null video stream --- a
00027 //               stream of plain blue and white frames that last one
00028 //               second each. To get more interesting video, you need
00029 //               to construct a subclass of this class.
00030 ////////////////////////////////////////////////////////////////////
00031 MovieVideo::
00032 MovieVideo(const string &name) :
00033   Namable(name)
00034 {
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: MovieVideo::Destructor
00039 //       Access: Public, Virtual
00040 //  Description: 
00041 ////////////////////////////////////////////////////////////////////
00042 MovieVideo::
00043 ~MovieVideo() {
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: MovieVideo::open
00048 //       Access: Published, Virtual
00049 //  Description: Open this video, returning a MovieVideoCursor of the
00050 //               appropriate type.  Returns NULL on error.
00051 ////////////////////////////////////////////////////////////////////
00052 PT(MovieVideoCursor) MovieVideo::
00053 open() {
00054   return NULL;
00055 }
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: MovieVideo::get
00059 //       Access: Published, Static
00060 //  Description: Obtains a MovieVideo that references a file.
00061 ////////////////////////////////////////////////////////////////////
00062 PT(MovieVideo) MovieVideo::
00063 get(const Filename &name) {
00064 #ifdef HAVE_FFMPEG
00065   // Someday, I'll probably put a dispatcher here.
00066   // But for now, just hardwire it to go to FFMPEG.
00067   return new FfmpegVideo(name);
00068 #else
00069   return new MovieVideo("Load-Failure Stub");
00070 #endif
00071 }
00072 
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: MovieVideo::write_datagram
00076 //       Access: Public, Virtual
00077 //  Description: Writes the contents of this object to the datagram
00078 //               for shipping out to a Bam file.
00079 ////////////////////////////////////////////////////////////////////
00080 void MovieVideo::
00081 write_datagram(BamWriter *manager, Datagram &dg) {
00082   TypedWritableReferenceCount::write_datagram(manager, dg);
00083   dg.add_string(_filename);
00084   
00085   // Now we record the raw movie data directly into the bam stream.
00086   // We always do this, regardless of bam-texture-mode; we generally
00087   // won't get to this codepath if bam-texture-mode isn't rawdata
00088   // anyway.
00089 
00090   SubfileInfo result;
00091   if (!_subfile_info.is_empty()) {
00092     dg.add_bool(true);
00093     manager->write_file_data(result, _subfile_info);
00094   } else if (!_filename.empty()) {
00095     dg.add_bool(true);
00096     manager->write_file_data(result, _filename);
00097   } else {
00098     dg.add_bool(false);
00099   }
00100 
00101   /* Not sure yet if this is a good idea.
00102   if (!result.is_empty()) {
00103     // If we've just copied the data to a local file, read it from
00104     // there in the future.
00105     _subfile_info = result;
00106   }
00107   */
00108 }
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function: MovieVideo::fillin
00112 //       Access: Protected
00113 //  Description: This internal function is called by make_from_bam to
00114 //               read in all of the relevant data from the BamFile for
00115 //               the new MovieVideo.
00116 ////////////////////////////////////////////////////////////////////
00117 void MovieVideo::
00118 fillin(DatagramIterator &scan, BamReader *manager) {
00119   TypedWritableReferenceCount::fillin(scan, manager);
00120   _filename = scan.get_string();
00121 
00122   bool got_info = scan.get_bool();
00123   if (got_info) {
00124     manager->read_file_data(_subfile_info);
00125   }
00126 }
 All Classes Functions Variables Enumerations