From 00739788942f04328765d8f2135b2ad62ec10780 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 28 Jul 2004 08:28:31 +0000 Subject: [PATCH] Added double buffer of video imagery so that the OpenGL never reads as Mpeg writes --- src/osgPlugins/mpeg/MpegImageStream.cpp | 51 ++++++++++++++----------- src/osgPlugins/mpeg/MpegImageStream.h | 4 +- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/osgPlugins/mpeg/MpegImageStream.cpp b/src/osgPlugins/mpeg/MpegImageStream.cpp index 60b0e4347..4b3392bb4 100644 --- a/src/osgPlugins/mpeg/MpegImageStream.cpp +++ b/src/osgPlugins/mpeg/MpegImageStream.cpp @@ -74,9 +74,14 @@ MpegImageStream::~MpegImageStream() mpg = NULL; } if (_rows) { - ::free(_rows); + delete [] _rows; _rows = NULL; } + + if (_videoWriteData) + { + delete [] _videoWriteData; + } } @@ -151,42 +156,42 @@ void MpegImageStream::load(const char* fileName) // Allocate image data // maybe use BGR888 and save some conversion somewhere? - unsigned char* data = (unsigned char*) ::malloc(s * t * 3); - + unsigned char* data = new unsigned char [s * t * 3]; + _videoWriteData = new unsigned char [s * t * 3]; setImage(s, t, 0, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, data, - osg::Image::USE_MALLOC_FREE); + osg::Image::USE_NEW_DELETE); + // Allocate decoder rows // documentation says we need add'l bytes at the end of each // row for MMX but this is more efficient and works so far. - _rows = (unsigned char**) ::malloc(t * sizeof(unsigned char*)); - unsigned char* dp = data; - for (int i = 0; i < t; i++) { - _rows[t-i-1] = dp; - dp += (s * 3); - } + _rows = new unsigned char* [t]; + + // set up the rows to the current view write data. + swapData(); + - // - // #if 0 - // // Setup texture matrix - // Matrix mat; - // mat.makeScale((float) s / (float) texWidth, - // ((float) t / (float) texHeight) * -1.0f, 1.0f); - // mat = mat * Matrix::translate(0.0f, (float) t / (float) texHeight, 0.0f); - // _texMat->setMatrix(mat); - // #else - // _texMat->setMatrix(osg::Matrix::scale(s,-t,1.0f)*osg::Matrix::translate(0.0f,t,0.0f)); - // #endif - // XXX osg::notify(INFO) << _frames << " @ " << _fps << " " << _len << "s" << std::endl; osg::notify(INFO) << "img " << s << "x" << t << std::endl; osg::notify(INFO) << "tex " << texWidth << "x" << texHeight << std::endl; } +void MpegImageStream::swapData() +{ + std::swap(_videoWriteData,_data); + unsigned char* dp = _videoWriteData; + for (int i = 0; i < t(); i++) + { + _rows[t()-i-1] = dp; + dp += (s() * 3); + } +} + + void MpegImageStream::quit(bool wiatForThreadToExit) { osg::notify(osg::DEBUG_INFO)<<"Sending quit"<