예제 #1
0
	void LinuxBackend::Update ()
	{
		const int prevCpuCount = GetCpuCount ();

		auto savedLast = ReadProcStat ();
		std::swap (savedLast, LastCummulative_);

		const auto curCpuCount = GetCpuCount ();
		if (curCpuCount != prevCpuCount)
		{
			emit cpuCountChanged (curCpuCount);
			return;
		}

		Loads_.clear ();
		Loads_.resize (LastCummulative_.size ());

		for (int i = 0; i < curCpuCount; ++i)
		{
			auto& cpuLoad = Loads_ [i];

			auto lastCpuStats = LastCummulative_ [i];
			const auto& prevCpuStats = savedLast [i];
			for (int j = 0; j < lastCpuStats.size (); ++j)
				lastCpuStats [j] -= prevCpuStats [j];

			const auto total = lastCpuStats [0] + lastCpuStats [1] + lastCpuStats [2] + lastCpuStats [3] + lastCpuStats [4];

			auto setLoadPart = [&cpuLoad, total, &lastCpuStats] (int idx, LoadPriority prio)
			{
				const auto thisLoad = static_cast<double> (lastCpuStats [idx]) / total;
				cpuLoad [prio] = LoadTypeInfo { thisLoad };
			};

			setLoadPart (4, LoadPriority::IO);
			setLoadPart (1, LoadPriority::Low);
			setLoadPart (0, LoadPriority::Medium);
			setLoadPart (2, LoadPriority::High);
		}
	}
예제 #2
0
int GetConcurrencyFactor()
{
	static Cache<int> Value;

	return Value.Get([]()
	{
		int ThreadCount = 0;

		for (int i = 0; i < GetCpuCount(); i++)
		{
			CpuInfo Info = GetCpuInfo(i);
			ThreadCount += Info.ThreadCount;
		}

		return ThreadCount;
	});
}
예제 #3
0
static unsigned GetThreadCount(int argc, char **argv)
{
    // If there's no explicit thread parameter, use the number of CPU's
    // but not less than 2 and not more than 8.
    //
    if (argc <= 1)
    {
        unsigned ncpus = GetCpuCount();
        if (ncpus < 2)
            ncpus = 2;
        if (ncpus > 8)
            ncpus = 8;
        return ncpus;
    }

    if (std::strcmp(argv[1], "-t") != 0)
    {
        std::cerr << "Unknown option: " << argv[1] << std::endl;
        return 0;
    }

    if (argc < 3)
    {
        std::cerr << "Must specify a parameter to '-t'" << std::endl;
        return 0;
    }

    char *end;
    unsigned long val = std::strtoul(argv[2], &end, 10);
    if (*(argv[2]) == '\0' || val > UINT_MAX || val == 0 || *end != '\0')
    {
        std::cerr << "Invalid parameter to -t: " << argv[2] << std::endl;
        return 0;
    }
    return static_cast<unsigned>(val);
}
예제 #4
0
BOOL EncryptionThreadPoolStart ()
{
	size_t cpuCount, i;

	if (ThreadPoolRunning)
		return TRUE;

#ifdef DEVICE_DRIVER
	cpuCount = GetCpuCount();
#else
	{
		SYSTEM_INFO sysInfo;
		GetSystemInfo (&sysInfo);
		cpuCount = sysInfo.dwNumberOfProcessors;
	}
#endif

	if (cpuCount < 2)
		return TRUE;

	if (cpuCount > TC_ENC_THREAD_POOL_MAX_THREAD_COUNT)
		cpuCount = TC_ENC_THREAD_POOL_MAX_THREAD_COUNT;

	StopPending = FALSE;
	DequeuePosition = 0;
	EnqueuePosition = 0;

#ifdef DEVICE_DRIVER
	KeInitializeEvent (&WorkItemReadyEvent, SynchronizationEvent, FALSE);
	KeInitializeEvent (&WorkItemCompletedEvent, SynchronizationEvent, FALSE);
#else
	WorkItemReadyEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
	if (!WorkItemReadyEvent)
		return FALSE;
	
	WorkItemCompletedEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
	if (!WorkItemCompletedEvent)
	{
		CloseHandle (WorkItemReadyEvent);
		return FALSE;
	}
#endif
	
	TC_INIT_MUTEX (&DequeueMutex);
	TC_INIT_MUTEX (&EnqueueMutex);

	memset (WorkItemQueue, 0, sizeof (WorkItemQueue));

	for (i = 0; i < sizeof (WorkItemQueue) / sizeof (WorkItemQueue[0]); ++i)
	{
		WorkItemQueue[i].State = WorkItemFree;

#ifdef DEVICE_DRIVER
		KeInitializeEvent (&WorkItemQueue[i].ItemCompletedEvent, SynchronizationEvent, FALSE);
#else
		WorkItemQueue[i].ItemCompletedEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
		if (!WorkItemQueue[i].ItemCompletedEvent)
		{
			EncryptionThreadPoolStop();
			return FALSE;
		}
#endif
	}

	for (ThreadCount = 0; ThreadCount < cpuCount; ++ThreadCount)
	{
#ifdef DEVICE_DRIVER
		if (!NT_SUCCESS (TCStartThread (EncryptionThreadProc, NULL, &ThreadHandles[ThreadCount])))
#else
		if (!(ThreadHandles[ThreadCount] = (HANDLE) _beginthreadex (NULL, 0, EncryptionThreadProc, NULL, 0, NULL)))
#endif
		{
			EncryptionThreadPoolStop();
			return FALSE;
		}
	}

	ThreadPoolRunning = TRUE;
	return TRUE;
}
예제 #5
0
파일: H264Enc.cpp 프로젝트: yujun1703/264
int CX264Enc::Init(VIDEOCODECINFO stCodecInfo)
{
#ifndef _SIMULATOR_    
    m_stEncParam.iWidth = stCodecInfo.nMaxWidth;
    m_stEncParam.iHeight = stCodecInfo.nMaxHeight;
    m_stEncParam.iFPS= 15;
    m_stEncParam.iBitrate= 200;  //kbps	
	m_stEncParam.iMaxQP = stCodecInfo.nMaxQp;
	m_stEncParam.iMinQP = stCodecInfo.nMinQp;

    m_stEncParam.iGOP = m_stEncParam.iFPS;
    m_stEncParam.igfGOP = 0;
    m_stEncParam.ispGOP = 0;
	
	switch (stCodecInfo.nEncMode)
    {
	case def_EncMode_Dsk:
		m_stEncParam.mode = X264ENCPARAM::emMode_Dsktop;
        break;

	case def_EncMode_Normal_abr:
		m_stEncParam.mode = X264ENCPARAM::emMode_Normal_abr;
        break;

	case def_EncMode_Normal:
    default:
		m_stEncParam.mode = X264ENCPARAM::emMode_Normal;
        break;
    }

#ifdef WIN32
	switch (stCodecInfo.nComplexity)
	{
	case def_Complexity_Best:
		m_stEncParam.cp = X264ENCPARAM::cp_best;
		break;

	case def_Complexity_Fast:
		m_stEncParam.cp = X264ENCPARAM::cp_fast;
		break;

	case def_Complexity_Normal:
	default:
		m_stEncParam.cp = X264ENCPARAM::cp_normal;
		break;
	}
#else   
    m_stEncParam.cp = X264ENCPARAM::cp_normal;
#endif

#if defined(ANDROID)
    int nCpuCount = GetCpuCount();
	int nCpuFreq = GetCpuFreq();
    if ( nCpuCount == 1 )
    {
		if ( m_stEncParam.iWidth >= 320 )
		{
			m_stEncParam.cp = X264ENCPARAM::cp_fast;
		}
    }
    else if ( nCpuCount == 2 && nCpuFreq <= 1500000)
    {
		if ( m_stEncParam.iWidth >= 320 )
		{
			m_stEncParam.cp = X264ENCPARAM::cp_fast;
		}
    }
	else if ( nCpuCount >= 4 && nCpuFreq >= 1700000 && m_stEncParam.iWidth == 320
             || m_stEncParam.iWidth < 320 )
	{
		m_stEncParam.cp = X264ENCPARAM::cp_best;
	}
	int cmplx = 0;
	GetEncCfgFromTxt(&cmplx);
	switch (cmplx)
	{
        case 0:
            m_stEncParam.cp = X264ENCPARAM::cp_fast;
            break;
        case 2:
            m_stEncParam.cp = X264ENCPARAM::cp_best;
            break;
        case 1:
        default:
            m_stEncParam.cp = X264ENCPARAM::cp_normal;
            break;
	}
    
#endif
    
#if defined(TARGET_OS_IPHONE)
    CiOSDevInfo appleDev;
    IOSDEV_DEVICE devCapa;
    if (appleDev.getCurrentAbility(devCapa))
    {
        if ( devCapa.type == iOSDev_iPhone4 )
        {
			if ( m_stEncParam.iWidth >= 320 )
			{
				m_stEncParam.cp = X264ENCPARAM::cp_fast;
			}
        }
		else if ( devCapa.type == iOSDev_iPhone5S && m_stEncParam.iWidth == 320
                 || m_stEncParam.iWidth < 320 )
		{
			m_stEncParam.cp = X264ENCPARAM::cp_best;
		}
    }
#endif
    
    switch (stCodecInfo.nCodecType)
    {
    case def_CodecType_H264HighProfile:
        m_stEncParam.eProfileLevel = X264ENCPARAM::emProfileLevel_High;
        break;

    case def_CodecType_H264MainProfile:
        m_stEncParam.eProfileLevel = X264ENCPARAM::emProfileLevel_Main;
        break;

    case def_CodecType_H264Baseline:
    default:
        m_stEncParam.eProfileLevel = X264ENCPARAM::emProfileLevel_Base;
        break;
    }
   
    m_x264Enc.Init(m_stEncParam);
    m_bIsInit = true;

#endif
    return m_bIsInit;
}
예제 #6
0
파일: H264Enc.cpp 프로젝트: yujun1703/264
int H264Enc::Init(VIDEOENCLEVEL stCodecInfo)
{
    if(m_bIsInit)
        return true;
    
#ifndef _SIMULATOR_
    m_stEncParam.iWidth = stCodecInfo.nWidth;
    m_stEncParam.iHeight = stCodecInfo.nHeight;
    m_stEncParam.iFPS    = stCodecInfo.nFPS;
    m_stEncParam.iBitrate= stCodecInfo.nBitrate;  //kbps
    m_stEncParam.iMaxQP = stCodecInfo.nMaxQp;
    m_stEncParam.iMinQP = stCodecInfo.nMinQp;
    m_stEncParam.iGOP = stCodecInfo.nIGop;
    m_stEncParam.igfGOP = stCodecInfo.nGfGop;
    m_stEncParam.ispGOP = stCodecInfo.nSpGop;

#ifdef WIN32
	switch (stCodecInfo.nEncMode)
	{
	case def_EncMode_Dsk:
		m_stEncParam.mode = X264ENCPARAM::emMode_Dsktop;
		break;

	case def_EncMode_Normal_abr:
		m_stEncParam.mode = X264ENCPARAM::emMode_Normal_abr;
		break;

	case def_EncMode_Normal:
	default:
		m_stEncParam.mode = X264ENCPARAM::emMode_Normal;
		break;
	}

	switch (stCodecInfo.nComplexity)
	{
	case def_Complexity_Best:
		m_stEncParam.cp = X264ENCPARAM::cp_best;
		break;

	case def_Complexity_Fast:
		m_stEncParam.cp = X264ENCPARAM::cp_fast;
		break;

	case def_Complexity_Normal:
	default:
		m_stEncParam.cp = X264ENCPARAM::cp_normal;
		break;
	}
#else	
    m_stEncParam.mode = X264ENCPARAM::emMode_Normal;
    m_stEncParam.cp = X264ENCPARAM::cp_normal;
#endif

    switch (stCodecInfo.nCodecType)
    {
    case def_CodecType_H264HighProfile:
        m_stEncParam.eProfileLevel = X264ENCPARAM::emProfileLevel_High;
        break;

    case def_CodecType_H264MainProfile:
        m_stEncParam.eProfileLevel = X264ENCPARAM::emProfileLevel_Main;
        break;

    case def_CodecType_H264Baseline:
    default:
        m_stEncParam.eProfileLevel = X264ENCPARAM::emProfileLevel_Base;
        break;
    }

    //turn off this mode for new ratecontrol
    //use complexmode and size is less than 320x240, change ana_cap_inter

#if defined(ANDROID)
    int nCpuCount = GetCpuCount();
	int nCpuFreq = GetCpuFreq();
    if ( nCpuCount == 1 )
    {
		if ( m_stEncParam.iWidth >= 320 )
		{
			m_stEncParam.cp = X264ENCPARAM::cp_fast;
		}
    }
    else if ( nCpuCount == 2 && nCpuFreq <= 1500000)
    {
		if ( m_stEncParam.iWidth >= 320 ) 
		{
			m_stEncParam.cp = X264ENCPARAM::cp_fast;
		}
    }	
	else if ( nCpuCount >= 4 && nCpuFreq >= 1700000 && m_stEncParam.iWidth == 320 
		|| m_stEncParam.iWidth < 320 )
	{
		m_stEncParam.cp = X264ENCPARAM::cp_best;
	}
	int cmplx = 0;
	GetEncCfgFromTxt(&cmplx);
	switch (cmplx)
	{
	case 0:
		m_stEncParam.cp = X264ENCPARAM::cp_fast;
		break;
	case 2:
		m_stEncParam.cp = X264ENCPARAM::cp_best;
		break;
	case 1:
	default:
		m_stEncParam.cp = X264ENCPARAM::cp_normal;
		break;
	}

#endif

#if defined(TARGET_OS_IPHONE)
    CiOSDevInfo appleDev;
    IOSDEV_DEVICE devCapa;
    if (appleDev.getCurrentAbility(devCapa))
    {
        if ( devCapa.type == iOSDev_iPhone4 )
        {
			if ( m_stEncParam.iWidth >= 320 )
			{
				m_stEncParam.cp = X264ENCPARAM::cp_fast;
			}
        }
		else if ( devCapa.type == iOSDev_iPhone5S && m_stEncParam.iWidth == 320 
			|| m_stEncParam.iWidth < 320 )
		{
			m_stEncParam.cp = X264ENCPARAM::cp_best;
		}
    }
#endif

	m_x264Enc.Init(m_stEncParam);

#endif

    m_bIsInit = true;
    return true;
}