HRESULT CX264Encoder::Init( X264ENCPARAM param ) { memset(m_level, (unsigned char)tp_lvl_2, sizeof(m_level)); m_stEncParam = param; x264_param_t st264Param; ConfigParam( &st264Param ); x264_t *h; if ( ( h = x264_encoder_open( &st264Param ) ) == NULL ) { LOG(stderr, "x264 [error]: x264_encoder_open failed\n"); return false; } m_px264Handle = (void*)h; x264_picture_t *pic = (x264_picture_t*)x264_malloc(sizeof(x264_picture_t)); memset( pic, 0, sizeof( x264_picture_t ) ); pic->i_type = X264_TYPE_AUTO; pic->i_qpplus1 = X264_QP_AUTO; pic->i_pic_struct = X264_CSP_I420; pic->img.i_csp = X264_CSP_I420; pic->img.i_plane = 3; pic->img.i_stride[0] = m_stEncParam.iWidth; pic->img.i_stride[1] = pic->img.i_stride[2] = m_stEncParam.iWidth>>1; m_pPic = (void*)pic; return true; }
HRESULT CX264Encoder::SetParam(int nBitrate, int nFPS) { if(!m_px264Handle) return false; if ( nBitrate <= 0 || nFPS <= 0 ) { LOG(stderr, "ChangeParam(): invalid value\n"); return E_INVALIDARG; } if ( nBitrate == m_stEncParam.iBitrate && nFPS == m_stEncParam.iFPS ) { return S_FALSE; } //x264_t *h = (x264_t*)m_px264Handle; //x264_picture_t *pic = (x264_picture_t*)m_pPic; m_stEncParam.iBitrate = nBitrate; m_stEncParam.iFPS = nFPS; x264_param_t st264Param; ConfigParam( &st264Param ); if ( x264_encoder_reconfig( (x264_t*)m_px264Handle, &st264Param ) < 0 ) { return false; } return true; }
void Config::newNode( const std::string &name, const std::string &optionsStr ) { if(mParamsInitialized) mParams->addText(name, optionsStr); mConfigParameters.push_back( ConfigParam(name, 0, _NODE) ); }
void Config::addConfigParam( const std::string &name, const std::string &keyName, void* param, ConfigParamTypes type) { std::string _keyName; (keyName == "") ? _keyName = name : _keyName = keyName; mConfigParameters.push_back( ConfigParam(_keyName, param, type) ); }
bool RecpathConfig::LoadConfig(const std::string & path_to_config) { logD(recpath, _func_); //m_mutex.lock(); m_configs.clear(); m_bIsEmpty = true; Json::Value root; // will contains the root value after parsing. Json::Reader reader; std::ifstream config_file(path_to_config, std::ifstream::binary); if(!config_file.good()) { //m_mutex.unlock(); logE_(_func_, "fail to load config"); return false; } bool parsingSuccessful = reader.parse( config_file, root, false ); if(!parsingSuccessful) { //m_mutex.unlock(); logE_(_func_, "fail to parse config"); return false; } Json::Value configs = root["configs"]; if(configs.empty()) { //m_mutex.unlock(); logE_(_func_, "fail to find \"configs\" section"); return false; } for( Json::ValueIterator itr = configs.begin() ; itr != configs.end() ; itr++ ) { Json::Value value = (*itr); Json::Value path = value["path"]; // Json::Value quota = value["quota"]; // Json::Value mode = value["mode"]; if(path.empty())// || quota.empty() || mode.empty()) { m_configs.clear(); //m_mutex.unlock(); logE_(_func_, "fail to parse params for section No ", itr.index()); return false; } m_configs[path.asString()] = ConfigParam(); } // dump config in log int i = 0; for(ConfigMap::const_iterator it = m_configs.begin(); it != m_configs.end(); ++it) { logD(recpath, _func_, "PathEntry ", i++); logD(recpath, _func_, "Path: ", it->first.c_str()); // logD(recpath, _func_, "Quota: ", it->second.quota); // logD(recpath, _func_, "Mode: ", it->second.write_mode); } m_configJson = root.toStyledString(); m_bIsInit = true; //m_mutex.unlock(); return true; }