Josh Yelon 18 years ago
parent
commit
8fedd869e5

+ 15 - 0
panda/src/movies/Sources.pp

@@ -14,18 +14,33 @@
 	movie.h movie.I \
 	movieAudio.h movieAudio.I \
 	movieVideo.h movieVideo.I \
+        inkblotMovie.h inkblotMovie.I \
+        inkblotVideo.h inkblotVideo.I \
+        ffmpegMovie.h ffmpegMovie.I \
+        ffmpegVideo.h ffmpegVideo.I \
+        ffmpegAudio.h ffmpegAudio.I \
 	config_movies.h
     
   #define INCLUDED_SOURCES \
         movieVideo.cxx \
         movieAudio.cxx \
         movie.cxx \
+        inkblotVideo.cxx \
+        inkblotMovie.cxx \
+        ffmpegVideo.cxx \
+        ffmpegAudio.cxx \
+        ffmpegMovie.cxx \
         config_movies.cxx
     
   #define INSTALL_HEADERS \
 	movie.h movie.I \
 	movieAudio.h movieAudio.I \
 	movieVideo.h movieVideo.I \
+        inkblotMovie.h inkblotMovie.I \
+        inkblotVideo.h inkblotVideo.I \
+        ffmpegMovie.h ffmpegMovie.I \
+        ffmpegVideo.h ffmpegVideo.I \
+        ffmpegAudio.h ffmpegAudio.I \
 	config_movies.h
 
   #define IGATESCAN all

+ 5 - 0
panda/src/movies/config_movies.cxx

@@ -45,5 +45,10 @@ init_libmovies() {
   MovieVideo::init_type();
   MovieAudio::init_type();
   Movie::init_type();
+  InkblotVideo::init_type();
+  InkblotMovie::init_type();
+  FfmpegVideo::init_type();
+  FfmpegAudio::init_type();
+  FfmpegMovie::init_type();
 }
 

+ 4 - 0
panda/src/movies/config_movies.h

@@ -24,6 +24,10 @@
 #include "configVariableEnum.h"
 #include "configVariableDouble.h"
 #include "dconfig.h"
+#include "movie.h"
+#include "movieVideo.h"
+#include "movieAudio.h"
+#include "inkblotVideo.h"
 
 ConfigureDecl(config_movies, EXPCL_PANDA_MOVIES, EXPTP_PANDA_MOVIES);
 NotifyCategoryDecl(movies, EXPCL_PANDA_MOVIES, EXPTP_PANDA_MOVIES);

+ 18 - 0
panda/src/movies/ffmpegAudio.I

@@ -0,0 +1,18 @@
+// Filename: ffmpegAudio.I
+// Created by: jyelon (01Aug2007)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+

+ 67 - 0
panda/src/movies/ffmpegAudio.cxx

@@ -0,0 +1,67 @@
+// Filename: ffmpegAudio.cxx
+// Created by: jyelon (01Aug2007)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2007, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] 
+//
+////////////////////////////////////////////////////////////////////
+
+#include "ffmpegAudio.h"
+
+TypeHandle FfmpegAudio::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: FfmpegAudio::Constructor
+//       Access: Protected
+//  Description: xxx
+////////////////////////////////////////////////////////////////////
+FfmpegAudio::
+FfmpegAudio(CPT(FfmpegMovie) source, double offset) :
+  MovieAudio((const FfmpegMovie *)source),
+  _sourcep(source)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FfmpegAudio::Destructor
+//       Access: Protected, Virtual
+//  Description: xxx
+////////////////////////////////////////////////////////////////////
+FfmpegAudio::
+~FfmpegAudio() {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FfmpegAudio::read_samples
+//       Access: Public, Virtual
+//  Description: Read audio samples from the stream.  N is the
+//               number of samples you wish to read.  Your buffer
+//               must be equal in size to N * channels.  
+//               Multiple-channel audio will be interleaved. 
+////////////////////////////////////////////////////////////////////
+void FfmpegAudio::
+read_samples(int n, PN_int16 *data) {
+
+  // This is the null implementation, which generates pure silence.
+  // Normally, this method will be overridden by a subclass.
+
+  if (n <= 0) {
+    return;
+  }
+
+  for (int i=0; i<n; i++) {
+    data[i] = 0;
+  }
+  _samples_read += n;
+}
+

+ 62 - 0
panda/src/movies/ffmpegAudio.h

@@ -0,0 +1,62 @@
+// Filename: ffmpegAudio.h
+// Created by: jyelon (01Aug2007)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef FFMPEGAUDIO_H
+#define FFMPEGAUDIO_H
+
+#include "pandabase.h"
+#include "namable.h"
+#include "texture.h"
+#include "pointerTo.h"
+#include "ffmpegMovie.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : FfmpegAudio
+// Description : A stream that generates a sequence of audio samples.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA_MOVIES FfmpegAudio : public MovieAudio {
+
+public:
+  FfmpegAudio(CPT(FfmpegMovie) source, double offset);
+  virtual ~FfmpegAudio();
+  virtual void read_samples(int n, PN_int16 *data);
+  
+protected:
+  const FfmpegMovie *_sourcep;
+  
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    TypedWritableReferenceCount::init_type();
+    register_type(_type_handle, "FfmpegAudio",
+                  MovieAudio::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "ffmpegAudio.I"
+
+#endif

+ 18 - 0
panda/src/movies/ffmpegMovie.I

@@ -0,0 +1,18 @@
+// Filename: ffmpegMovie.I
+// Created by: jyelon (01Aug2007)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+

+ 66 - 0
panda/src/movies/ffmpegMovie.cxx

@@ -0,0 +1,66 @@
+// Filename: ffmpegMovie.cxx
+// Created by: jyelon (01Aug2007)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2007, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "ffmpegVideo.h"
+#include "ffmpegAudio.h"
+#include "ffmpegMovie.h"
+#include "config_movies.h"
+
+TypeHandle FfmpegMovie::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: FfmpegMovie::Constructor
+//       Access: Published
+//  Description: xxx
+////////////////////////////////////////////////////////////////////
+FfmpegMovie::
+FfmpegMovie(const string &filename) :
+  Movie(filename,1.0)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Movie::get_video
+//       Access: Published, Virtual
+//  Description: Fetch a video stream.  Always constructs a new
+//               MovieVideo or subclass of MovieVideo.
+////////////////////////////////////////////////////////////////////
+PT(MovieVideo) FfmpegMovie::
+get_video(double offset) const {
+  if (_dummy_video) {
+    return new MovieVideo(this);
+  } else {
+    return new FfmpegVideo(this, offset);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Movie::get_audio
+//       Access: Published, Virtual
+//  Description: Fetch an audio stream.  Always constructs a new
+//               MovieAudio or subclass of MovieAudio.
+////////////////////////////////////////////////////////////////////
+PT(MovieAudio) FfmpegMovie::
+get_audio(double offset) const {
+  if (_dummy_audio) {
+    return new MovieAudio(this);
+  } else {
+    return new FfmpegAudio(this, offset);
+  }
+}
+

+ 65 - 0
panda/src/movies/ffmpegMovie.h

@@ -0,0 +1,65 @@
+// Filename: ffmpegMovie.h
+// Created by: jyelon (01Aug2007)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef FFMPEGMOVIE_H
+#define FFMPEGMOVIE_H
+
+#include "pandabase.h"
+#include "texture.h"
+#include "pointerTo.h"
+#include "movie.h"
+
+class FfmpegVideo;
+class FfmpegAudio;
+
+////////////////////////////////////////////////////////////////////
+//       Class : FfmpegMovie
+// Description : A Movie loader class that uses FFMPEG as its
+//               underlying decoder.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA_MOVIES FfmpegMovie : public Movie {
+
+PUBLISHED:
+  FfmpegMovie(const string &filename);
+
+  virtual PT(MovieVideo) get_video(double offset=0.0) const;
+  virtual PT(MovieAudio) get_audio(double offset=0.0) const;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    Movie::init_type();
+    register_type(_type_handle, "FfmpegMovie",
+                  Movie::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+  friend class FfmpegVideo;
+  friend class FfmpegAudio;
+};
+
+#include "ffmpegMovie.I"
+
+#endif

+ 18 - 0
panda/src/movies/ffmpegVideo.I

@@ -0,0 +1,18 @@
+// Filename: ffmpegVideo.I
+// Created by: jyelon (01Aug2007)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+

+ 54 - 0
panda/src/movies/ffmpegVideo.cxx

@@ -0,0 +1,54 @@
+// Filename: ffmpegVideo.cxx
+// Created by: jyelon (01Aug2007)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2007, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "ffmpegVideo.h"
+#include "ffmpegMovie.h"
+#include "config_movies.h"
+
+TypeHandle FfmpegVideo::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: FfmpegVideo::Constructor
+//       Access: Public
+//  Description: xxx
+////////////////////////////////////////////////////////////////////
+FfmpegVideo::
+FfmpegVideo(CPT(FfmpegMovie) source, double offset) :
+  MovieVideo((const FfmpegMovie *)source),
+  _sourcep(source)
+{
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FfmpegVideo::Destructor
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+FfmpegVideo::
+~FfmpegVideo() {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FfmpegVideo::fetch_into_buffer
+//       Access: Public, Virtual
+//  Description: See MovieVideo::fetch_into_buffer.
+////////////////////////////////////////////////////////////////////
+void FfmpegVideo::
+fetch_into_buffer(double time, unsigned char *data, bool rgba) {
+}
+

+ 62 - 0
panda/src/movies/ffmpegVideo.h

@@ -0,0 +1,62 @@
+// Filename: ffmpegVideo.h
+// Created by: jyelon (01Aug2007)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://etc.cmu.edu/panda3d/docs/license/ .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef FFMPEGVIDEO_H
+#define FFMPEGVIDEO_H
+
+#include "pandabase.h"
+#include "texture.h"
+#include "pointerTo.h"
+#include "ffmpegMovie.h"
+
+////////////////////////////////////////////////////////////////////
+//       Class : FfmpegVideo
+// Description : A cellular automaton that generates an amusing
+//               pattern of swirling colors.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDA_MOVIES FfmpegVideo : public MovieVideo {
+
+ public:
+  FfmpegVideo(CPT(FfmpegMovie) source, double offset);
+  virtual ~FfmpegVideo();
+  virtual void fetch_into_buffer(double time, unsigned char *block, bool rgba);
+
+ protected:
+  const FfmpegMovie *_sourcep;
+  
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    MovieVideo::init_type();
+    register_type(_type_handle, "FfmpegVideo",
+                  MovieVideo::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+  static TypeHandle _type_handle;
+};
+
+#include "ffmpegVideo.I"
+
+#endif

+ 2 - 2
panda/src/movies/inkblotMovie.cxx

@@ -49,7 +49,7 @@ InkblotMovie(const string &name, double len, int sizex, int sizey, int fps) :
 ////////////////////////////////////////////////////////////////////
 PT(MovieVideo) InkblotMovie::
 get_video(double offset) const {
-  return new InkblotVideo(get_name(), this);
+  return new InkblotVideo(this);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -60,6 +60,6 @@ get_video(double offset) const {
 ////////////////////////////////////////////////////////////////////
 PT(MovieAudio) InkblotMovie::
 get_audio(double offset) const {
-  return new MovieAudio(get_name(), this);
+  return new MovieAudio(this);
 }
 

+ 1 - 0
panda/src/movies/inkblotMovie.h

@@ -72,6 +72,7 @@ public:
 
 private:
   static TypeHandle _type_handle;
+  friend class FfmpegVideo;
 };
 
 #include "inkblotMovie.I"

+ 5 - 5
panda/src/movies/inkblotVideo.cxx

@@ -53,14 +53,14 @@ static color colormap[17] = {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: InkblotVideo::Constructor
-//       Access: Published
+//       Access: Public
 //  Description: xxx
 ////////////////////////////////////////////////////////////////////
 InkblotVideo::
-InkblotVideo(const string &name, CPT(Movie) source) :
-  MovieVideo(name, source)
+InkblotVideo(CPT(InkblotMovie) source) :
+  MovieVideo((const InkblotMovie *)source)
 {
-  _sourcep = (const InkblotMovie*)(const Movie*)_source;
+  _sourcep = source;
   int padx = size_x() + 2;
   int pady = size_y() + 2;
   _cells = new unsigned char[padx * pady];
@@ -72,7 +72,7 @@ InkblotVideo(const string &name, CPT(Movie) source) :
 
 ////////////////////////////////////////////////////////////////////
 //     Function: InkblotVideo::Destructor
-//       Access: Published, Virtual
+//       Access: Public, Virtual
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 InkblotVideo::

+ 4 - 5
panda/src/movies/inkblotVideo.h

@@ -23,7 +23,6 @@
 #include "texture.h"
 #include "pointerTo.h"
 #include "inkblotMovie.h"
-#include "movieVideo.h"
 
 ////////////////////////////////////////////////////////////////////
 //       Class : InkblotVideo
@@ -32,18 +31,18 @@
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDA_MOVIES InkblotVideo : public MovieVideo {
 
- PUBLISHED:
-  InkblotVideo(const string &name, CPT(Movie) source);
+ public:
+  InkblotVideo(CPT(InkblotMovie) source);
   virtual ~InkblotVideo();
   virtual void fetch_into_buffer(double time, unsigned char *block, bool rgba);
-
+  
  protected:
   const InkblotMovie *_sourcep;
   unsigned char *_cells;
   unsigned char *_cells2;
   int _fps;
   int _frames_read;
-  
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;

+ 3 - 3
panda/src/movies/movie.cxx

@@ -63,7 +63,7 @@ Movie::
 ////////////////////////////////////////////////////////////////////
 PT(MovieVideo) Movie::
 get_video(double offset) const {
-  return new MovieVideo(get_name(), this);
+  return new MovieVideo(this);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -74,7 +74,7 @@ get_video(double offset) const {
 ////////////////////////////////////////////////////////////////////
 PT(MovieAudio) Movie::
 get_audio(double offset) const {
-  return new MovieAudio(get_name(), this);
+  return new MovieAudio(this);
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -82,7 +82,7 @@ get_audio(double offset) const {
 //       Access: Published, Static
 //  Description: Loads a movie from a file.
 ////////////////////////////////////////////////////////////////////
-PT(Movie) Movie::
+CPT(Movie) Movie::
 load(const Filename &path) {
   // For now, just return a dummy movie.
   return new Movie("dummy",30.0);

+ 3 - 4
panda/src/movies/movie.h

@@ -43,26 +43,25 @@ class EXPCL_PANDA_MOVIES Movie : public TypedWritableReferenceCount, public Nama
 
 PUBLISHED:
   Movie(const string &name, double len);
-
+  
   INLINE int size_x() const;
   INLINE int size_y() const;
   INLINE int get_num_components() const;
   INLINE double length() const;
   INLINE int audio_rate() const;
   INLINE int audio_channels() const;
-
   INLINE bool ignores_offset() const;
   INLINE bool dummy_video() const;
   INLINE bool dummy_audio() const;
 
   virtual PT(MovieVideo) get_video(double offset=0.0) const;
   virtual PT(MovieAudio) get_audio(double offset=0.0) const;
-  static PT(Movie) load(const Filename &path);
+  static CPT(Movie) load(const Filename &path);
   
 public:
   virtual ~Movie();
 
-private:
+protected:
   int _size_x;
   int _size_y;
   int _num_components;

+ 3 - 3
panda/src/movies/movieAudio.cxx

@@ -22,15 +22,15 @@ TypeHandle MovieAudio::_type_handle;
 
 ////////////////////////////////////////////////////////////////////
 //     Function: MovieAudio::Constructor
-//       Access: Protected
+//       Access: Public
 //  Description: This constructor returns a null audio stream --- a
 //               stream of total silence, at 8000 samples per second.
 //               To get more interesting audio, you need to construct
 //               a subclass of this class.
 ////////////////////////////////////////////////////////////////////
 MovieAudio::
-MovieAudio(const string &name, CPT(Movie) source) :
-  Namable(name),
+MovieAudio(CPT(Movie) source) :
+  Namable(source->get_name()),
   _source(source),
   _samples_read(0)
 {

+ 2 - 2
panda/src/movies/movieAudio.h

@@ -32,7 +32,6 @@
 class EXPCL_PANDA_MOVIES MovieAudio : public TypedWritableReferenceCount, public Namable {
 
 PUBLISHED:
-  MovieAudio(const string &name, CPT(Movie) source);
   INLINE CPT(Movie) get_source() const;
   INLINE int audio_rate() const;
   INLINE int audio_channels() const;
@@ -41,8 +40,9 @@ PUBLISHED:
   INLINE void skip_samples(int n);
   
 public:
-  virtual void read_samples(int n, PN_int16 *data);
+  MovieAudio(CPT(Movie) source);
   virtual ~MovieAudio();
+  virtual void read_samples(int n, PN_int16 *data);
   
 protected:
   CPT(Movie) _source;

+ 90 - 48
panda/src/movies/movieVideo.cxx

@@ -23,25 +23,25 @@ TypeHandle MovieVideo::_type_handle;
 
 ////////////////////////////////////////////////////////////////////
 //     Function: MovieVideo::Constructor
-//       Access: Published
+//       Access: Public
 //  Description: This constructor returns a null video stream --- a
 //               stream of plain blue and white frames that last one
 //               second each. To get more interesting video, you need
 //               to construct a subclass of this class.
 ////////////////////////////////////////////////////////////////////
 MovieVideo::
-MovieVideo(const string &name, CPT(Movie) source) :
-  Namable(name),
+MovieVideo(CPT(Movie) source) :
+  Namable(source->get_name()),
   _source(source),
   _aborted(false),
-  _curr_start(-1.0),
+  _last_start(-1.0),
   _next_start(0.0)
 {
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: MovieVideo::Destructor
-//       Access: Published, Virtual
+//       Access: Public, Virtual
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 MovieVideo::
@@ -65,40 +65,17 @@ allocate_conversion_buffer() {
   }
 }
   
-////////////////////////////////////////////////////////////////////
-//     Function: MovieVideo::seek_ahead
-//       Access: Published, Virtual
-//  Description: Seeks forward until the next frame contains time t.
-//               Also updates last_start and next_start.
-//               It is an error to pass in a value less than
-//               next_start (that would be a backward seek).
-//
-//               Arbitrary seeking (both forward and backward) can
-//               be accomplished by fetching the original Movie
-//               object, and then calling get_video with an offset.
-//               However, unlike seek_ahead, the result is not
-//               guaranteed to be quite precise, because AVI files
-//               often have inaccurate indices.
-////////////////////////////////////////////////////////////////////
-void MovieVideo::
-seek_ahead(double t) {
-
-  // The following is the implementation of the null video stream, ie,
-  // a stream of blinking red and blue frames.  This method must be
-  // overridden by the subclass.
-
-  nassertv(t >= _next_start);
-  _next_start = floor(t);
-  _last_start = _next_start - 1.0;
-}
-
 ////////////////////////////////////////////////////////////////////
 //     Function: MovieVideo::fetch_into_texture
 //       Access: Published, Virtual
-//  Description: Fetch the next frame into a page of a texture.
+//  Description: Reads frames from the stream until the specified 
+//               time is reached.  The last frame read is stored in
+//               the supplied texture.
+//
+//               See fetch_into_buffer for more details.
 ////////////////////////////////////////////////////////////////////
 void MovieVideo::
-fetch_into_texture(Texture *t, int page) {
+fetch_into_texture(double time, Texture *t, int page) {
 
   // This generic implementation is layered on fetch_into_buffer.
   // It will work for any derived class, so it is never necessary to
@@ -117,10 +94,10 @@ fetch_into_texture(Texture *t, int page) {
   unsigned char *data = img.p() + page * t->get_expected_ram_page_size();
 
   if (t->get_x_size() == size_x()) {
-    fetch_into_buffer(data, t->get_num_components() == 4);
+    fetch_into_buffer(time, data, t->get_num_components() == 4);
   } else {
     allocate_conversion_buffer();
-    fetch_into_buffer(_conversion_buffer, t->get_num_components() == 4);
+    fetch_into_buffer(time, _conversion_buffer, t->get_num_components() == 4);
     int src_stride = size_x() * t->get_num_components();
     int dst_stride = t->get_x_size() * t->get_num_components();
     unsigned char *p = _conversion_buffer;
@@ -135,11 +112,15 @@ fetch_into_texture(Texture *t, int page) {
 ////////////////////////////////////////////////////////////////////
 //     Function: MovieVideo::fetch_into_texture_alpha
 //       Access: Published, Virtual
-//  Description: Fetch the next frame into the alpha channel
-//               of a texture.
+//  Description: Reads frames from the stream until the specified 
+//               time is reached.  The last frame read is stored in
+//               the alpha channel of the supplied texture.  The
+//               RGB channels of the texture are not touched.
+//
+//               See fetch_into_buffer for more details.
 ////////////////////////////////////////////////////////////////////
 void MovieVideo::
-fetch_into_texture_alpha(Texture *t, int page, int alpha_src) {
+fetch_into_texture_alpha(double time, Texture *t, int page, int alpha_src) {
 
   // This generic implementation is layered on fetch_into_buffer.
   // It will work for any derived class, so it is never necessary to
@@ -156,7 +137,7 @@ fetch_into_texture_alpha(Texture *t, int page, int alpha_src) {
 
   allocate_conversion_buffer();
   
-  fetch_into_buffer(_conversion_buffer, true);
+  fetch_into_buffer(time, _conversion_buffer, true);
   
   PTA_uchar img = t->modify_ram_image();
   
@@ -186,24 +167,88 @@ fetch_into_texture_alpha(Texture *t, int page, int alpha_src) {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: MovieVideo::fetch_into_texture_rgb
+//       Access: Published, Virtual
+//  Description: Reads frames from the stream until the specified 
+//               time is reached.  The last frame read is stored in
+//               the RGB channels of the supplied texture.  The alpha
+//               channel of the texture is not touched.
+//
+//               See fetch_into_buffer for more details.
+////////////////////////////////////////////////////////////////////
+void MovieVideo::
+fetch_into_texture_rgb(double time, Texture *t, int page) {
+
+  // This generic implementation is layered on fetch_into_buffer.
+  // It will work for any derived class, so it is never necessary to
+  // redefine this.  However, it may be possible to make a faster
+  // implementation that uses fewer intermediate copies, depending
+  // on the capabilities of the underlying codec software.
+
+  nassertv(t->get_x_size() >= size_x());
+  nassertv(t->get_y_size() >= size_y());
+  nassertv(t->get_num_components() == 4);
+  nassertv(t->get_component_width() == 1);
+  nassertv(page < t->get_z_size());
+
+  allocate_conversion_buffer();
+  
+  fetch_into_buffer(time, _conversion_buffer, true);
+  
+  PTA_uchar img = t->modify_ram_image();
+  
+  unsigned char *data = img.p() + page * t->get_expected_ram_page_size();
+  
+  int src_stride = size_x() * 4;
+  int dst_stride = t->get_x_size() * 4;
+  unsigned char *p = _conversion_buffer;
+  for (int y=0; y<size_y(); y++) {
+    for (int x=0; x<size_x(); x++) {
+      data[x*4+0] = p[x*4+0];
+      data[x*4+1] = p[x*4+1];
+      data[x*4+2] = p[x*4+2];
+    }
+    data += dst_stride;
+    p += src_stride;
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: MovieVideo::fetch_into_buffer
 //       Access: Published, Virtual
-//  Description: Fetch the next frame into a supplied RGB8 or RGBA8
-//               buffer.
+//  Description: Reads frames from the stream until the specified 
+//               time is reached.  The last frame read is stored in
+//               the supplied RGB8 or RGBA8 buffer.
+//
+//               The fetch methods do not seek: they just reads frames
+//               from the stream.  Therefore, they cannot move backward.
+//               If you specify a time value less than next_start, they
+//               will just read one frame and return.
+//
+//               To truly seek, you must call get_video with an
+//               offset.  This is sometimes inaccurate, because AVI
+//               file indices often contain errors.  Therefore, it
+//               is sometimes advantageous to use fetch methods to 
+//               just read frames from the stream until you get
+//               to the target location.
 ////////////////////////////////////////////////////////////////////
 void MovieVideo::
-fetch_into_buffer(unsigned char *data, bool rgba) {
+fetch_into_buffer(double time, unsigned char *data, bool rgba) {
   
   // The following is the implementation of the null video stream, ie,
   // a stream of blinking red and blue frames.  This method must be
   // overridden by the subclass.
 
-  if (_next_start >= length()) {
+  if (time < _next_start) time = _next_start;
+  _last_start = floor(time);
+  _next_start = _last_start + 1;
+
+  if (_last_start >= length()) {
     data[0] = 0;
     data[1] = 0;
     data[2] = 0;
-  } else if (((int)_next_start) & 1) {
+  } else if (((int)_last_start) & 1) {
     data[0] = 255;
     data[1] = 128;
     data[2] = 128;
@@ -215,8 +260,5 @@ fetch_into_buffer(unsigned char *data, bool rgba) {
   if (rgba) {
     data[3] = 255;
   }
-  
-  _curr_start = _next_start;
-  _next_start = _next_start + 1.0;
 }
 

+ 8 - 7
panda/src/movies/movieVideo.h

@@ -31,8 +31,6 @@
 class EXPCL_PANDA_MOVIES MovieVideo : public TypedWritableReferenceCount, public Namable {
 
  PUBLISHED:
-  MovieVideo(const string &name, CPT(Movie) source);
-  virtual ~MovieVideo();
   INLINE CPT(Movie) get_source() const;
   INLINE int size_x() const;
   INLINE int size_y() const;
@@ -41,11 +39,15 @@ class EXPCL_PANDA_MOVIES MovieVideo : public TypedWritableReferenceCount, public
   INLINE bool aborted() const;
   INLINE double last_start() const;
   INLINE double next_start() const;
-  virtual void seek_ahead(double t);
-  virtual void fetch_into_texture(Texture *t, int page);
-  virtual void fetch_into_texture_alpha(Texture *t, int page, int alpha_src);
-  virtual void fetch_into_buffer(unsigned char *block, bool rgba);
+  virtual void fetch_into_texture(double time, Texture *t, int page);
+  virtual void fetch_into_texture_rgb(double time, Texture *t, int page);
+  virtual void fetch_into_texture_alpha(double time, Texture *t, int page, int alpha_src);
 
+ public:
+  MovieVideo(CPT(Movie) source);
+  virtual ~MovieVideo();
+  virtual void fetch_into_buffer(double time, unsigned char *block, bool rgba);
+  
  private:
   void allocate_conversion_buffer();
   unsigned char *_conversion_buffer;
@@ -54,7 +56,6 @@ class EXPCL_PANDA_MOVIES MovieVideo : public TypedWritableReferenceCount, public
   CPT(Movie) _source;
   bool _aborted;
   double _last_start;
-  double _curr_start;
   double _next_start;
   
 public:

+ 6 - 1
panda/src/movies/movies_composite1.cxx

@@ -1,4 +1,9 @@
+#include "movie.cxx"
 #include "movieVideo.cxx"
 #include "movieAudio.cxx"
-#include "movie.cxx"
+#include "inkblotMovie.cxx"
+#include "inkblotVideo.cxx"
+#include "ffmpegMovie.cxx"
+#include "ffmpegAudio.cxx"
+#include "ffmpegVideo.cxx"
 #include "config_movies.cxx"