theonlineoasis

VideoCodec/Modules/RateControl/RateControl.cpp

#include "RateControl.h" namespace VideoCodec {    RateControl::RateControl() : Module(RATE_CONTROL_MODULE_ID)    {    }        RateControl::~RateControl()    {    }        ConfigurationStatus RateControl::Configure(ConfigurationElement* configuration)    {       if (configuration != NULL && configuration->GetValue("threshold") != NULL && configuration->GetValue("threshold")->GetType() == CONFIGURATION_INTEGER)       {          this->threshold = *configuration->GetValue("threshold")->GetInteger();          this->isEnabled = true;       }       else          this->isEnabled = false;              return MODULE_CONFIGURATION_OK;    }     #define ABS(x) (x) < 0 ? (-x) : (x);    bool RateControl::ShouldEncodeI(PictureInfo* residual)    {       SignedShort* data = residual->GetSignedShortData();       unsigned long int length = residual->GetSignedShortDataLength();              // To go faster, just use the luminance parameter and only use a few values.       unsigned int sae = 0;       for (unsigned long int index = 0; index < length; index += 16 * 3)          sae += ABS(data[index]);              return (sae > this->threshold);    } #undef ABS        bool RateControl::IsEnabled()    {       return this->isEnabled;    } }