From 9f15224b03f4142de042a25449eaead8b18de0ce Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Mon, 2 Jul 2007 22:32:48 +0000 Subject: [PATCH] Stubs in place, now it compiles. --- panda/src/movies/config_movies.cxx | 6 ++- panda/src/movies/config_movies.h | 8 ++-- panda/src/movies/movieAudio.I | 46 ++++++++++++++++++++++ panda/src/movies/movieAudio.cxx | 50 +++++++++++++++++++++--- panda/src/movies/movieAudio.h | 27 ++++++++++--- panda/src/movies/movieVideo.I | 62 ++++++++++++++++++++++++++++++ panda/src/movies/movieVideo.cxx | 20 ++++++++++ panda/src/movies/movieVideo.h | 26 ++++++++++--- 8 files changed, 223 insertions(+), 22 deletions(-) diff --git a/panda/src/movies/config_movies.cxx b/panda/src/movies/config_movies.cxx index 6cfa265bcb..98295e2f02 100644 --- a/panda/src/movies/config_movies.cxx +++ b/panda/src/movies/config_movies.cxx @@ -1,5 +1,5 @@ // Filename: config_movies.cxx -// Created by: cary (04Jan00) +// Created by: jyelon (02Jul07) // //////////////////////////////////////////////////////////////////// // @@ -22,6 +22,10 @@ ConfigureDef(config_movies); NotifyCategoryDef(movies, ""); +ConfigureFn(config_movies) { + init_libmovies(); +} + //////////////////////////////////////////////////////////////////// // Function: init_libmovies // Description: Initializes the library. This must be called at diff --git a/panda/src/movies/config_movies.h b/panda/src/movies/config_movies.h index 4b8e06acdd..d30433fc64 100644 --- a/panda/src/movies/config_movies.h +++ b/panda/src/movies/config_movies.h @@ -1,5 +1,5 @@ // Filename: config_movies.h -// Created by: cary (04Jan00) +// Created by: jyelon (02Jul07) // //////////////////////////////////////////////////////////////////// // @@ -25,9 +25,9 @@ #include "configVariableDouble.h" #include "dconfig.h" -ConfigureDecl(config_movies, EXPCL_PANDA, EXPTP_PANDA); -NotifyCategoryDecl(movies, EXPCL_PANDA, EXPTP_PANDA); +ConfigureDecl(config_movies, EXPCL_PANDASKEL, EXPTP_PANDASKEL); +NotifyCategoryDecl(movies, EXPCL_PANDASKEL, EXPTP_PANDASKEL); -extern EXPCL_PANDA void init_libmovies(); +extern EXPCL_PANDASKEL void init_libmovies(); #endif /* __CONFIG_MOVIES_H__ */ diff --git a/panda/src/movies/movieAudio.I b/panda/src/movies/movieAudio.I index 91ecc0c5d1..bb48da499c 100644 --- a/panda/src/movies/movieAudio.I +++ b/panda/src/movies/movieAudio.I @@ -16,3 +16,49 @@ // //////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// Function: MovieAudio::rate +// Access: Public +// Description: Returns the audio sample rate, in samples per sec. +//////////////////////////////////////////////////////////////////// +INLINE int MovieAudio:: +rate() const { + return _rate; +} + +//////////////////////////////////////////////////////////////////// +// Function: MovieAudio::channels +// Access: Public +// Description: Returns the number of audio channels. Ie, 1 for +// mono, 2 for stereo. +//////////////////////////////////////////////////////////////////// +INLINE int MovieAudio:: +channels() const { + return _channels; +} + +//////////////////////////////////////////////////////////////////// +// Function: MovieAudio::samples_read +// Access: Public +// Description: Returns the number of audio samples you have read +// from the audio stream so far. +//////////////////////////////////////////////////////////////////// +INLINE int MovieAudio:: +samples_read() const { + return _samples_read; +} + +//////////////////////////////////////////////////////////////////// +// Function: MovieAudio::approx_time_remaining +// Access: Public +// Description: Returns a "best guess" amount of time left on the +// stream. For ffmpeg streams, this is usually a +// pretty close approximation --- ie, off by a few +// hundred samples. For infinite streams, always +// returns the constant value 1.0E10. +//////////////////////////////////////////////////////////////////// +INLINE double MovieAudio:: +approx_time_remaining() const { + return _approx_time_remaining; +} + diff --git a/panda/src/movies/movieAudio.cxx b/panda/src/movies/movieAudio.cxx index e492ce79c9..4f2419c4db 100644 --- a/panda/src/movies/movieAudio.cxx +++ b/panda/src/movies/movieAudio.cxx @@ -23,21 +23,59 @@ TypeHandle MovieAudio::_type_handle; //////////////////////////////////////////////////////////////////// // Function: MovieAudio::Constructor // Access: Protected -// Description: Normally, the MovieAudio constructor is not -// called directly; these are created by calling -// the MoviePool::load functions. Furthermore, -// MovieAudio itself is just an abstract base class. +// Description: //////////////////////////////////////////////////////////////////// MovieAudio:: -MovieAudio() { +MovieAudio(const string &name) : + Namable(name), + _rate(44100), + _samples_read(0), + _approx_time_remaining(1.0E10) +{ } //////////////////////////////////////////////////////////////////// // Function: MovieAudio::Destructor -// Access: Published, Virtual +// Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// MovieAudio:: ~MovieAudio() { } + +//////////////////////////////////////////////////////////////////// +// Function: MovieAudio::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 at least as large as N * channels. +// Multiple-channel audio will be interleaved. Returns +// the actual number of samples read. This will always +// be equal to N unless end-of-stream has been reached. +//////////////////////////////////////////////////////////////////// +int MovieAudio:: +read_samples(int n, PN_int16 *data) { + + // This is a dummy implementation. This method should be overridden. + nassertr(n > 0, 0); + for (int i=0; i 0, 0); + PN_int16 *data = new PN_int16[n]; + int res = read_samples(n, data); + delete data; + return res; +} diff --git a/panda/src/movies/movieAudio.h b/panda/src/movies/movieAudio.h index 057bacda0c..26c2857e3e 100644 --- a/panda/src/movies/movieAudio.h +++ b/panda/src/movies/movieAudio.h @@ -16,10 +16,11 @@ // //////////////////////////////////////////////////////////////////// -#ifndef MOVIEVIDEO_H -#define MOVIEVIDEO_H +#ifndef MOVIEAUDIO_H +#define MOVIEAUDIO_H #include "pandabase.h" +#include "namable.h" #include "texture.h" #include "pointerTo.h" @@ -27,21 +28,35 @@ // Class : MovieAudio // Description : A stream that generates a sequence of audio samples. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDA MovieAudio : public TypedWritableReferenceCount, public Namable { +class EXPCL_PANDASKEL MovieAudio : public TypedWritableReferenceCount, public Namable { protected: - MovieAudio(); + MovieAudio(const string &name); PUBLISHED: + INLINE int rate() const; + INLINE int channels() const; + INLINE int samples_read() const; + INLINE double approx_time_remaining() const; + virtual int skip_samples(int n); + +public: + virtual int read_samples(int n, PN_int16 *data); virtual ~MovieAudio(); +private: + int _rate; + int _channels; + int _samples_read; + double _approx_time_remaining; + public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { - GraphicsOutput::init_type(); + TypedWritableReferenceCount::init_type(); register_type(_type_handle, "MovieAudio", - MovieAudio::get_class_type()); + TypedWritableReferenceCount::get_class_type()); } virtual TypeHandle get_type() const { return get_class_type(); diff --git a/panda/src/movies/movieVideo.I b/panda/src/movies/movieVideo.I index ac16c311ee..80683b93d9 100644 --- a/panda/src/movies/movieVideo.I +++ b/panda/src/movies/movieVideo.I @@ -16,3 +16,65 @@ // //////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////// +// Function: MovieVideo::size_x +// Access: Published +// Description: Get the horizontal size of the movie. +//////////////////////////////////////////////////////////////////// +INLINE int MovieVideo:: +size_x() const { + return _size_x; +} + +//////////////////////////////////////////////////////////////////// +// Function: MovieVideo::size_y +// Access: Published +// Description: Get the vertical size of the movie. +//////////////////////////////////////////////////////////////////// +INLINE int MovieVideo:: +size_y() const { + return _size_y; +} + +//////////////////////////////////////////////////////////////////// +// Function: MovieVideo::frame_start +// Access: Published +// Description: MovieVideo streams have variable frame rates. Each +// frame will specify how long it is to be displayed. +// These lengths may not be equal from frame to frame. +// +// The frame_start function returns the time at which +// the current frame should start being displayed. This +// time is relative to the start of the stream. +//////////////////////////////////////////////////////////////////// +INLINE double MovieVideo:: +frame_start() const { + return _frame_start; +} + +//////////////////////////////////////////////////////////////////// +// Function: MovieVideo::frame_end +// Access: Published +// Description: Return the time at which this frame should stop +// being displayed. This time is relative to the start +// of the stream. +// +// The frame_end function returns the time at which +// the current frame should stop being displayed. This +// time is relative to the start of the stream. +//////////////////////////////////////////////////////////////////// +INLINE double MovieVideo:: +frame_end() const { + return _frame_end; +} + +//////////////////////////////////////////////////////////////////// +// Function: MovieVideo::approx_time_remaining +// Access: Published +// Description: Get the vertical size of the movie. +//////////////////////////////////////////////////////////////////// +INLINE double MovieVideo:: +approx_time_remaining() const { + return _approx_time_remaining; +} + diff --git a/panda/src/movies/movieVideo.cxx b/panda/src/movies/movieVideo.cxx index d156e9863d..f58d8b313e 100644 --- a/panda/src/movies/movieVideo.cxx +++ b/panda/src/movies/movieVideo.cxx @@ -17,6 +17,7 @@ //////////////////////////////////////////////////////////////////// #include "movieVideo.h" +#include "config_movies.h" TypeHandle MovieVideo::_type_handle; @@ -41,3 +42,22 @@ MovieVideo:: ~MovieVideo() { } +//////////////////////////////////////////////////////////////////// +// Function: MovieVideo::load_image +// Access: Published, Virtual +// Description: Copy the current frame into a texture's ram image. +//////////////////////////////////////////////////////////////////// +void MovieVideo:: +load_image(Texture *t) { + movies_cat.error() << "load_image: this virtual method must be overridden."; +} + +//////////////////////////////////////////////////////////////////// +// Function: MovieVideo::next_frame +// Access: Published, Virtual +// Description: Advances to the next frame. +//////////////////////////////////////////////////////////////////// +void MovieVideo:: +next_frame() { + movies_cat.error() << "next_frame: this virtual method must be overridden."; +} diff --git a/panda/src/movies/movieVideo.h b/panda/src/movies/movieVideo.h index 5ffb8ec6d0..bd8e6e0342 100644 --- a/panda/src/movies/movieVideo.h +++ b/panda/src/movies/movieVideo.h @@ -27,21 +27,37 @@ // Class : MovieVideo // Description : A stream that generates a series of images. //////////////////////////////////////////////////////////////////// -class EXPCL_PANDA MovieVideo : public TypedWritableReferenceCount, public Namable { +class EXPCL_PANDASKEL MovieVideo : public TypedWritableReferenceCount, public Namable { protected: MovieVideo(); -PUBLISHED: + PUBLISHED: + INLINE int size_x() const; + INLINE int size_y() const; + INLINE double frame_start() const; + INLINE double frame_end() const; + INLINE double approx_time_remaining() const; + virtual void load_image(Texture *t); + virtual void next_frame(); + + public: virtual ~MovieVideo(); - + + private: + int _size_x; + int _size_y; + double _frame_start; + double _frame_end; + double _approx_time_remaining; + public: static TypeHandle get_class_type() { return _type_handle; } static void init_type() { - GraphicsOutput::init_type(); + TypedWritableReferenceCount::init_type(); register_type(_type_handle, "MovieVideo", - MovieVideo::get_class_type()); + TypedWritableReferenceCount::get_class_type()); } virtual TypeHandle get_type() const { return get_class_type();