bring ffmpeg, opencv into new interface

This commit is contained in:
David Rose 2008-09-11 23:16:15 +00:00
parent 3bd0d132b3
commit efad95a5ea
5 changed files with 70 additions and 37 deletions

View File

@ -46,6 +46,7 @@ FFMpegTexture(const FFMpegTexture &copy) :
VideoTexture(copy),
_pages(copy._pages)
{
nassertv(false);
}
////////////////////////////////////////////////////////////////////
@ -59,8 +60,8 @@ FFMpegTexture::
}
////////////////////////////////////////////////////////////////////
// Function: FFMpegTexture::make_copy
// Access: Published, Virtual
// Function: FFMpegTexture::do_make_copy
// Access: Protected, Virtual
// Description: Returns a new copy of the same Texture. This copy,
// if applied to geometry, will be copied into texture
// as a separate texture from the original, so it will
@ -72,10 +73,23 @@ FFMpegTexture::
// original.
////////////////////////////////////////////////////////////////////
PT(Texture) FFMpegTexture::
make_copy() {
return new FFMpegTexture(*this);
do_make_copy() {
PT(FFMpegTexture) tex = new FFMpegTexture(get_name());
tex->do_assign(*this);
return tex.p();
}
////////////////////////////////////////////////////////////////////
// Function: FFMpegTexture::do_assign
// Access: Protected
// Description: Implements make_copy().
////////////////////////////////////////////////////////////////////
void FFMpegTexture::
do_assign(const FFMpegTexture &copy) {
VideoTexture::do_assign(copy);
_pages = copy._pages;
}
////////////////////////////////////////////////////////////////////
// Function: FFMPegTexture::modify_page
@ -95,15 +109,15 @@ modify_page(int z) {
}
////////////////////////////////////////////////////////////////////
// Function: FFmpegTexture::reconsider_video_properties
// Function: FFmpegTexture::do_reconsider_video_properties
// Access: Private
// Description: Resets the internal Texture properties when a new
// video file is loaded. Returns true if the new image
// is valid, false otherwise.
////////////////////////////////////////////////////////////////////
bool FFMpegTexture::
reconsider_video_properties(const FFMpegTexture::VideoStream &stream,
int num_components, int z) {
do_reconsider_video_properties(const FFMpegTexture::VideoStream &stream,
int num_components, int z) {
double frame_rate = 0.0f;
int num_frames = 0;
if (!stream._codec_context) {
@ -146,8 +160,8 @@ reconsider_video_properties(const FFMpegTexture::VideoStream &stream,
<< y_size << " texels.\n";
}
if (!reconsider_image_properties(x_size, y_size, num_components,
T_unsigned_byte, z)) {
if (!do_reconsider_image_properties(x_size, y_size, num_components,
T_unsigned_byte, z)) {
return false;
}
@ -334,12 +348,12 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
set_name(fullpath.get_basename_wo_extension());
}
if (!has_filename()) {
set_filename(fullpath);
set_alpha_filename(alpha_fullpath);
_filename = fullpath;
_alpha_filename = alpha_fullpath;
}
set_fullpath(fullpath);
set_alpha_fullpath(alpha_fullpath);
_fullpath = fullpath;
_alpha_fullpath = alpha_fullpath;
}
if (page._color._codec_context->pix_fmt==PIX_FMT_RGBA32) {
// There had better not be an alpha interleave here.
@ -347,7 +361,7 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
_primary_file_num_channels = 4;
_alpha_file_channel = 0;
if (!reconsider_video_properties(page._color, 4, z)) {
if (!do_reconsider_video_properties(page._color, 4, z)) {
page._color.clear();
return false;
}
@ -357,18 +371,18 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
_alpha_file_channel = alpha_file_channel;
if (page._alpha.is_valid()) {
if (!reconsider_video_properties(page._color, 4, z)) {
if (!do_reconsider_video_properties(page._color, 4, z)) {
page._color.clear();
page._alpha.clear();
return false;
}
if (!reconsider_video_properties(page._alpha, 4, z)) {
if (!do_reconsider_video_properties(page._alpha, 4, z)) {
page._color.clear();
page._alpha.clear();
return false;
}
} else {
if (!reconsider_video_properties(page._color, 3, z)) {
if (!do_reconsider_video_properties(page._color, 3, z)) {
page._color.clear();
page._alpha.clear();
return false;

View File

@ -38,12 +38,13 @@ protected:
PUBLISHED:
virtual ~FFMpegTexture();
virtual PT(Texture) make_copy();
public:
static PT(Texture) make_texture();
protected:
virtual PT(Texture) do_make_copy();
void do_assign(const FFMpegTexture &copy);
virtual void update_frame(int frame);
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
int z, int n, int primary_file_num_channels, int alpha_file_channel,
@ -56,8 +57,8 @@ private:
class VideoStream;
VideoPage &modify_page(int z);
bool reconsider_video_properties(const VideoStream &stream,
int num_components, int z);
bool do_reconsider_video_properties(const VideoStream &stream,
int num_components, int z);
void do_update();
class VideoStream {

View File

@ -421,6 +421,8 @@ do_make_copy() {
////////////////////////////////////////////////////////////////////
void MovieTexture::
do_assign(const MovieTexture &copy) {
Texture::do_assign(copy);
// Since 'make_copy' can be a slow operation,
// I release the read lock before calling make_copy.

View File

@ -46,6 +46,7 @@ OpenCVTexture(const OpenCVTexture &copy) :
VideoTexture(copy),
_pages(copy._pages)
{
nassertv(false);
}
////////////////////////////////////////////////////////////////////
@ -58,8 +59,8 @@ OpenCVTexture::
}
////////////////////////////////////////////////////////////////////
// Function: OpenCVTexture::make_copy
// Access: Published, Virtual
// Function: OpenCVTexture::do_make_copy
// Access: Protected, Virtual
// Description: Returns a new copy of the same Texture. This copy,
// if applied to geometry, will be copied into texture
// as a separate texture from the original, so it will
@ -71,8 +72,22 @@ OpenCVTexture::
// original.
////////////////////////////////////////////////////////////////////
PT(Texture) OpenCVTexture::
make_copy() {
return new OpenCVTexture(*this);
do_make_copy() {
PT(OpenCVTexture) tex = new OpenCVTexture(get_name());
tex->do_assign(*this);
return tex.p();
}
////////////////////////////////////////////////////////////////////
// Function: OpenCVTexture::do_assign
// Access: Protected
// Description: Implements make_copy().
////////////////////////////////////////////////////////////////////
void OpenCVTexture::
do_assign(const OpenCVTexture &copy) {
VideoTexture::do_assign(copy);
_pages = copy._pages;
}
////////////////////////////////////////////////////////////////////
@ -85,7 +100,7 @@ make_copy() {
////////////////////////////////////////////////////////////////////
bool OpenCVTexture::
from_camera(int camera_index, int z) {
if (!reconsider_z_size(z)) {
if (!do_reconsider_z_size(z)) {
return false;
}
nassertr(z >= 0 && z < get_z_size(), false);
@ -96,7 +111,7 @@ from_camera(int camera_index, int z) {
return false;
}
if (!reconsider_video_properties(page._color, 3, z)) {
if (!do_reconsider_video_properties(page._color, 3, z)) {
page._color.clear();
return false;
}
@ -125,14 +140,14 @@ modify_page(int z) {
}
////////////////////////////////////////////////////////////////////
// Function: OpenCVTexture::reconsider_video_properties
// Function: OpenCVTexture::do_reconsider_video_properties
// Access: Private
// Description: Resets the internal Texture properties when a new
// video file is loaded. Returns true if the new image
// is valid, false otherwise.
////////////////////////////////////////////////////////////////////
bool OpenCVTexture::
reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
do_reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
int num_components, int z) {
double frame_rate = 0.0f;
int num_frames = 0;
@ -164,7 +179,7 @@ reconsider_video_properties(const OpenCVTexture::VideoStream &stream,
<< y_size << " texels.\n";
}
if (!reconsider_image_properties(x_size, y_size, num_components,
if (!do_reconsider_image_properties(x_size, y_size, num_components,
T_unsigned_byte, z)) {
return false;
}
@ -334,7 +349,7 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
if (alpha_fullpath.empty()) {
// Only one RGB movie.
if (!reconsider_video_properties(page._color, 3, z)) {
if (!do_reconsider_video_properties(page._color, 3, z)) {
page._color.clear();
return false;
}
@ -343,13 +358,13 @@ do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
// An RGB movie combined with an alpha movie.
_alpha_file_channel = alpha_file_channel;
if (!reconsider_video_properties(page._color, 4, z)) {
if (!do_reconsider_video_properties(page._color, 4, z)) {
page._color.clear();
page._alpha.clear();
return false;
}
if (!reconsider_video_properties(page._alpha, 4, z)) {
if (!do_reconsider_video_properties(page._alpha, 4, z)) {
page._color.clear();
page._alpha.clear();
return false;

View File

@ -39,14 +39,15 @@ protected:
PUBLISHED:
virtual ~OpenCVTexture();
virtual PT(Texture) make_copy();
bool from_camera(int camera_index = -1, int z = 0);
public:
static PT(Texture) make_texture();
protected:
virtual PT(Texture) do_make_copy();
void do_assign(const FFMpegTexture &copy);
virtual void update_frame(int frame);
virtual bool do_read_one(const Filename &fullpath, const Filename &alpha_fullpath,
@ -60,8 +61,8 @@ private:
class VideoStream;
VideoPage &modify_page(int z);
bool reconsider_video_properties(const VideoStream &stream,
int num_components, int z);
bool do_reconsider_video_properties(const VideoStream &stream,
int num_components, int z);
void do_update();
class VideoStream {