|
|
@@ -17,6 +17,7 @@
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
#include "movieVideo.h"
|
|
|
+#include "ffmpegVideo.h"
|
|
|
#include "config_movies.h"
|
|
|
|
|
|
TypeHandle MovieVideo::_type_handle;
|
|
|
@@ -30,9 +31,14 @@ TypeHandle MovieVideo::_type_handle;
|
|
|
// to construct a subclass of this class.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
MovieVideo::
|
|
|
-MovieVideo(CPT(Movie) source) :
|
|
|
- Namable(source->get_name()),
|
|
|
- _source(source),
|
|
|
+MovieVideo(const string &name) :
|
|
|
+ Namable(name),
|
|
|
+ _size_x(1),
|
|
|
+ _size_y(1),
|
|
|
+ _num_components(3),
|
|
|
+ _length(1.0E10),
|
|
|
+ _can_seek(true),
|
|
|
+ _can_seek_zero(true),
|
|
|
_aborted(false),
|
|
|
_last_start(-1.0),
|
|
|
_next_start(0.0)
|
|
|
@@ -65,12 +71,32 @@ allocate_conversion_buffer() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: MovieVideo::fetch_into_bitbucket
|
|
|
+// Access: Published, Virtual
|
|
|
+// Description: Discards the next video frame. Still sets
|
|
|
+// last_start and next_start.
|
|
|
+//
|
|
|
+// See fetch_into_buffer for more details.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+void MovieVideo::
|
|
|
+fetch_into_bitbucket(double time) {
|
|
|
+
|
|
|
+ // This generic implementation is layered on fetch_into_buffer.
|
|
|
+ // It will work for any derived class, so it is never necessary to
|
|
|
+ // redefine this. It is probably possible to make a faster
|
|
|
+ // implementation, but since this function is rarely used, it
|
|
|
+ // probably isn't worth the trouble.
|
|
|
+
|
|
|
+ allocate_conversion_buffer();
|
|
|
+ fetch_into_buffer(time, _conversion_buffer, false);
|
|
|
+}
|
|
|
+
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: MovieVideo::fetch_into_texture
|
|
|
// Access: Published, Virtual
|
|
|
-// Description: Reads frames from the stream until the specified
|
|
|
-// time is reached. The last frame read is stored in
|
|
|
-// the supplied texture.
|
|
|
+// Description: Reads the specified video frame into
|
|
|
+// the specified texture.
|
|
|
//
|
|
|
// See fetch_into_buffer for more details.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
@@ -112,8 +138,7 @@ fetch_into_texture(double time, Texture *t, int page) {
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: MovieVideo::fetch_into_texture_alpha
|
|
|
// Access: Published, Virtual
|
|
|
-// Description: Reads frames from the stream until the specified
|
|
|
-// time is reached. The last frame read is stored in
|
|
|
+// Description: Reads the specified video frame into
|
|
|
// the alpha channel of the supplied texture. The
|
|
|
// RGB channels of the texture are not touched.
|
|
|
//
|
|
|
@@ -170,8 +195,7 @@ fetch_into_texture_alpha(double time, 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
|
|
|
+// Description: Reads the specified video frame into
|
|
|
// the RGB channels of the supplied texture. The alpha
|
|
|
// channel of the texture is not touched.
|
|
|
//
|
|
|
@@ -217,21 +241,17 @@ fetch_into_texture_rgb(double time, Texture *t, int page) {
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
// Function: MovieVideo::fetch_into_buffer
|
|
|
// Access: Published, Virtual
|
|
|
-// 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.
|
|
|
+// Description: Reads the specified video frame into the supplied
|
|
|
+// RGB8 or RGBA8 buffer. The frame's begin and end
|
|
|
+// times are stored in last_start and next_start.
|
|
|
//
|
|
|
-// 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.
|
|
|
+// You may always specify a timestamp greater than or
|
|
|
+// equal to next_start --- ie, read forward through the
|
|
|
+// movie. If the movie reports that it can_seek_zero,
|
|
|
+// you may also specify a timestamp of 0.0 --- ie,
|
|
|
+// rewind the movie. If the movie reports that it
|
|
|
+// can_seek, you may specify any timestamp. It is
|
|
|
+// generally much faster to read frames sequentially.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void MovieVideo::
|
|
|
fetch_into_buffer(double time, unsigned char *data, bool rgba) {
|
|
|
@@ -239,16 +259,11 @@ 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 (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)_last_start) & 1) {
|
|
|
+ if (((int)_last_start) & 1) {
|
|
|
data[0] = 255;
|
|
|
data[1] = 128;
|
|
|
data[2] = 128;
|
|
|
@@ -262,3 +277,25 @@ fetch_into_buffer(double time, unsigned char *data, bool rgba) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: MovieVideo::make_copy
|
|
|
+// Access: Published, Virtual
|
|
|
+// Description: Make a copy of this video with a separate cursor.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+PT(MovieVideo) MovieVideo::
|
|
|
+make_copy() const {
|
|
|
+ return new MovieVideo();
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: MovieVideo::load
|
|
|
+// Access: Published, Static
|
|
|
+// Description: Load a movie from a file.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+PT(MovieVideo) MovieVideo::
|
|
|
+load(const Filename &name) {
|
|
|
+ // Someday, I'll probably put a dispatcher here.
|
|
|
+ // But for now, just hardwire it to go to FFMPEG.
|
|
|
+ return new FfmpegVideo(name);
|
|
|
+}
|
|
|
+
|