videofilter.cpp:

- Replace data type unsigned int with size_t where appropriate.
- In the VideoFilter ctor, now require srcWidth and srcHeight to be specified.
- Be more conservative when generating SSurface structs.
This commit is contained in:
rogerman 2013-06-19 15:54:59 +00:00
parent 5e18fe732d
commit 593d82ca2b
2 changed files with 52 additions and 38 deletions

View File

@ -42,12 +42,17 @@ static const _VideoFilterParamAttributes _VideoFilterParamAttributesList[] = {
/******************************************************************************************** /********************************************************************************************
CLASS CONSTRUCTORS CLASS CONSTRUCTORS
********************************************************************************************/ ********************************************************************************************/
VideoFilter::VideoFilter(unsigned int srcWidth = 1, VideoFilter::VideoFilter(size_t srcWidth,
unsigned int srcHeight = 1, size_t srcHeight,
VideoFilterTypeID typeID = VideoFilterTypeID_None, VideoFilterTypeID typeID = VideoFilterTypeID_None,
unsigned int numberThreads = 0) size_t threadCount = 0)
{ {
SSurface newSurface = {NULL, srcWidth*2, srcWidth, srcHeight}; SSurface newSurface;
newSurface.Surface = NULL;
newSurface.Pitch = srcWidth*2;
newSurface.Width = srcWidth;
newSurface.Height = srcHeight;
_vfSrcSurface = newSurface; _vfSrcSurface = newSurface;
_vfDstSurface = newSurface; _vfDstSurface = newSurface;
@ -62,9 +67,9 @@ VideoFilter::VideoFilter(unsigned int srcWidth = 1,
pthread_cond_init(&_condRunning, NULL); pthread_cond_init(&_condRunning, NULL);
// Create all threads // Create all threads
_vfThread.resize(numberThreads); _vfThread.resize(threadCount);
for (unsigned int i = 0; i < numberThreads; i++) for (size_t i = 0; i < threadCount; i++)
{ {
_vfThread[i].param.srcSurface = _vfSrcSurface; _vfThread[i].param.srcSurface = _vfSrcSurface;
_vfThread[i].param.dstSurface = _vfDstSurface; _vfThread[i].param.dstSurface = _vfDstSurface;
@ -83,7 +88,7 @@ VideoFilter::VideoFilter(unsigned int srcWidth = 1,
VideoFilter::~VideoFilter() VideoFilter::~VideoFilter()
{ {
// Destroy all threads first // Destroy all threads first
for (unsigned int i = 0; i < _vfThread.size(); i++) for (size_t i = 0; i < _vfThread.size(); i++)
{ {
_vfThread[i].task->finish(); _vfThread[i].task->finish();
_vfThread[i].task->shutdown(); _vfThread[i].task->shutdown();
@ -135,7 +140,7 @@ VideoFilter::~VideoFilter()
A bool that reports if the resizing was successful. A value of true means success, A bool that reports if the resizing was successful. A value of true means success,
while a value of false means failure. while a value of false means failure.
********************************************************************************************/ ********************************************************************************************/
bool VideoFilter::SetSourceSize(const unsigned int width, const unsigned int height) bool VideoFilter::SetSourceSize(const size_t width, const size_t height)
{ {
bool result = false; bool result = false;
@ -162,7 +167,7 @@ bool VideoFilter::SetSourceSize(const unsigned int width, const unsigned int hei
// Update the surfaces on threads. // Update the surfaces on threads.
size_t threadCount = this->_vfThread.size(); size_t threadCount = this->_vfThread.size();
for (unsigned int i = 0; i < threadCount; i++) for (size_t i = 0; i < threadCount; i++)
{ {
SSurface &threadSrcSurface = this->_vfThread[i].param.srcSurface; SSurface &threadSrcSurface = this->_vfThread[i].param.srcSurface;
threadSrcSurface = this->_vfSrcSurface; threadSrcSurface = this->_vfSrcSurface;
@ -229,13 +234,13 @@ bool VideoFilter::ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr)
} }
pthread_mutex_lock(&this->_mutexSrc); pthread_mutex_lock(&this->_mutexSrc);
const unsigned int srcWidth = this->_vfSrcSurface.Width; const size_t srcWidth = this->_vfSrcSurface.Width;
const unsigned int srcHeight = this->_vfSrcSurface.Height; const size_t srcHeight = this->_vfSrcSurface.Height;
pthread_mutex_unlock(&this->_mutexSrc); pthread_mutex_unlock(&this->_mutexSrc);
const VideoFilterTypeID typeID = vfAttr->typeID; const VideoFilterTypeID typeID = vfAttr->typeID;
const unsigned int dstWidth = srcWidth * vfAttr->scaleMultiply / vfAttr->scaleDivide; const size_t dstWidth = srcWidth * vfAttr->scaleMultiply / vfAttr->scaleDivide;
const unsigned int dstHeight = srcHeight * vfAttr->scaleMultiply / vfAttr->scaleDivide; const size_t dstHeight = srcHeight * vfAttr->scaleMultiply / vfAttr->scaleDivide;
const char *typeString = vfAttr->typeString; const char *typeString = vfAttr->typeString;
const VideoFilterFunc filterFunction = vfAttr->filterFunction; const VideoFilterFunc filterFunction = vfAttr->filterFunction;
@ -258,7 +263,7 @@ bool VideoFilter::ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr)
// Update the surfaces on threads. // Update the surfaces on threads.
size_t threadCount = this->_vfThread.size(); size_t threadCount = this->_vfThread.size();
for (unsigned int i = 0; i < threadCount; i++) for (size_t i = 0; i < threadCount; i++)
{ {
SSurface &threadDstSurface = this->_vfThread[i].param.dstSurface; SSurface &threadDstSurface = this->_vfThread[i].param.dstSurface;
threadDstSurface = this->_vfDstSurface; threadDstSurface = this->_vfDstSurface;
@ -313,12 +318,12 @@ uint32_t* VideoFilter::RunFilter()
if (threadCount > 0) if (threadCount > 0)
{ {
for (unsigned int i = 0; i < threadCount; i++) for (size_t i = 0; i < threadCount; i++)
{ {
this->_vfThread[i].task->execute(&RunVideoFilterTask, &this->_vfThread[i].param); this->_vfThread[i].task->execute(&RunVideoFilterTask, &this->_vfThread[i].param);
} }
for (unsigned int i = 0; i < threadCount; i++) for (size_t i = 0; i < threadCount; i++)
{ {
this->_vfThread[i].task->finish(); this->_vfThread[i].task->finish();
} }
@ -367,7 +372,7 @@ uint32_t* VideoFilter::RunFilter()
Nothing. Nothing.
********************************************************************************************/ ********************************************************************************************/
void VideoFilter::RunFilterCustom(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ dstBuffer, void VideoFilter::RunFilterCustom(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ dstBuffer,
const unsigned int srcWidth, const unsigned int srcHeight, const size_t srcWidth, const size_t srcHeight,
const VideoFilterTypeID typeID) const VideoFilterTypeID typeID)
{ {
// Parameter check // Parameter check
@ -382,13 +387,22 @@ void VideoFilter::RunFilterCustom(const uint32_t *__restrict__ srcBuffer, uint32
// Get the filter attributes // Get the filter attributes
const VideoFilterAttributes *vfAttr = &VideoFilterAttributesList[typeID]; const VideoFilterAttributes *vfAttr = &VideoFilterAttributesList[typeID];
const unsigned int dstWidth = srcWidth * vfAttr->scaleMultiply / vfAttr->scaleDivide; const size_t dstWidth = srcWidth * vfAttr->scaleMultiply / vfAttr->scaleDivide;
const unsigned int dstHeight = srcHeight * vfAttr->scaleMultiply / vfAttr->scaleDivide; const size_t dstHeight = srcHeight * vfAttr->scaleMultiply / vfAttr->scaleDivide;
const VideoFilterFunc filterFunction = vfAttr->filterFunction; const VideoFilterFunc filterFunction = vfAttr->filterFunction;
// Assign the surfaces and run the filter // Assign the surfaces and run the filter
SSurface srcSurface = {(unsigned char *)srcBuffer, srcWidth*2, srcWidth, srcHeight}; SSurface srcSurface;
SSurface dstSurface = {(unsigned char *)dstBuffer, dstWidth*2, dstWidth, dstHeight}; srcSurface.Surface = (unsigned char *)srcBuffer;
srcSurface.Pitch = srcWidth*2;
srcSurface.Width = srcWidth;
srcSurface.Height = srcHeight;
SSurface dstSurface;
dstSurface.Surface = (unsigned char *)dstBuffer;
dstSurface.Pitch = dstWidth*2;
dstSurface.Width = dstWidth;
dstSurface.Height = dstHeight;
if (filterFunction == NULL) if (filterFunction == NULL)
{ {
@ -481,37 +495,37 @@ uint32_t* VideoFilter::GetDstBufferPtr()
return ptr; return ptr;
} }
unsigned int VideoFilter::GetSrcWidth() size_t VideoFilter::GetSrcWidth()
{ {
pthread_mutex_lock(&this->_mutexSrc); pthread_mutex_lock(&this->_mutexSrc);
unsigned int width = this->_vfSrcSurface.Width; size_t width = this->_vfSrcSurface.Width;
pthread_mutex_unlock(&this->_mutexSrc); pthread_mutex_unlock(&this->_mutexSrc);
return width; return width;
} }
unsigned int VideoFilter::GetSrcHeight() size_t VideoFilter::GetSrcHeight()
{ {
pthread_mutex_lock(&this->_mutexSrc); pthread_mutex_lock(&this->_mutexSrc);
unsigned int height = this->_vfSrcSurface.Height; size_t height = this->_vfSrcSurface.Height;
pthread_mutex_unlock(&this->_mutexSrc); pthread_mutex_unlock(&this->_mutexSrc);
return height; return height;
} }
unsigned int VideoFilter::GetDstWidth() size_t VideoFilter::GetDstWidth()
{ {
pthread_mutex_lock(&this->_mutexDst); pthread_mutex_lock(&this->_mutexDst);
unsigned int width = this->_vfDstSurface.Width; size_t width = this->_vfDstSurface.Width;
pthread_mutex_unlock(&this->_mutexDst); pthread_mutex_unlock(&this->_mutexDst);
return width; return width;
} }
unsigned int VideoFilter::GetDstHeight() size_t VideoFilter::GetDstHeight()
{ {
pthread_mutex_lock(&this->_mutexDst); pthread_mutex_lock(&this->_mutexDst);
unsigned int height = this->_vfDstSurface.Height; size_t height = this->_vfDstSurface.Height;
pthread_mutex_unlock(&this->_mutexDst); pthread_mutex_unlock(&this->_mutexDst);
return height; return height;

View File

@ -63,8 +63,8 @@ typedef struct
VideoFilterTypeID typeID; VideoFilterTypeID typeID;
const char *typeString; const char *typeString;
VideoFilterFunc filterFunction; VideoFilterFunc filterFunction;
unsigned int scaleMultiply; size_t scaleMultiply;
unsigned int scaleDivide; size_t scaleDivide;
} VideoFilterAttributes; } VideoFilterAttributes;
// Attributes list of known video filters, indexed using VideoFilterTypeID. // Attributes list of known video filters, indexed using VideoFilterTypeID.
@ -169,25 +169,25 @@ private:
void SetTypeString(std::string typeString); void SetTypeString(std::string typeString);
public: public:
VideoFilter(unsigned int srcWidth, unsigned int srcHeight, VideoFilterTypeID typeID, unsigned int numberThreads); VideoFilter(size_t srcWidth, size_t srcHeight, VideoFilterTypeID typeID, size_t threadCount);
~VideoFilter(); ~VideoFilter();
bool SetSourceSize(const unsigned int width, const unsigned int height); bool SetSourceSize(const size_t width, const size_t height);
bool ChangeFilterByID(const VideoFilterTypeID typeID); bool ChangeFilterByID(const VideoFilterTypeID typeID);
bool ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr); bool ChangeFilterByAttributes(const VideoFilterAttributes *vfAttr);
uint32_t* RunFilter(); uint32_t* RunFilter();
static void RunFilterCustom(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ dstBuffer, const unsigned int srcWidth, const unsigned int srcHeight, const VideoFilterTypeID typeID); static void RunFilterCustom(const uint32_t *__restrict__ srcBuffer, uint32_t *__restrict__ dstBuffer, const size_t srcWidth, const size_t srcHeight, const VideoFilterTypeID typeID);
static const char* GetTypeStringByID(const VideoFilterTypeID typeID); static const char* GetTypeStringByID(const VideoFilterTypeID typeID);
VideoFilterTypeID GetTypeID(); VideoFilterTypeID GetTypeID();
const char* GetTypeString(); const char* GetTypeString();
uint32_t* GetSrcBufferPtr(); uint32_t* GetSrcBufferPtr();
uint32_t* GetDstBufferPtr(); uint32_t* GetDstBufferPtr();
unsigned int GetSrcWidth(); size_t GetSrcWidth();
unsigned int GetSrcHeight(); size_t GetSrcHeight();
unsigned int GetDstWidth(); size_t GetDstWidth();
unsigned int GetDstHeight(); size_t GetDstHeight();
VideoFilterParamType GetFilterParameterType(VideoFilterParamID paramID); VideoFilterParamType GetFilterParameterType(VideoFilterParamID paramID);
int GetFilterParameteri(VideoFilterParamID paramID); int GetFilterParameteri(VideoFilterParamID paramID);
unsigned int GetFilterParameterui(VideoFilterParamID paramID); unsigned int GetFilterParameterui(VideoFilterParamID paramID);