std::vector<ProcessVolume> GetProcessVolumes() {
  std::vector<ProcessVolume> volumes;

  CoInitialize(NULL);

  IAudioSessionEnumerator* enumerator = GetAudioSessionEnumerator();
  int sessionCount;
  enumerator->GetCount(&sessionCount);
  for (int index = 0; index < sessionCount; index++) {
    IAudioSessionControl* session = nullptr;
    IAudioSessionControl2* session2 = nullptr;
    enumerator->GetSession(index, &session);
    session->QueryInterface(__uuidof(IAudioSessionControl2), (void**)&session2);

    DWORD id = 0;
    session2->GetProcessId(&id);

    std::string processName = GetProcessNameFromPid(id);
    float peakVolume = GetPeakVolumeFromAudioSessionControl(session);

    ProcessVolume data;
    data.processName = processName;
    data.processId = id;
    data.peakVolume = peakVolume;
    volumes.push_back(data);

    session2->Release();
    session->Release();
  }
  enumerator->Release();

  return std::move(volumes);
}
Exemplo n.º 2
0
VOID CreateProcessNotifyRoutine(HANDLE hParentId, HANDLE hProcessId, BOOLEAN bCreate)
{
	char* processName = GetProcessNameFromPid(hProcessId); 
	if (bCreate)
	{	
		DbgPrint("Process %s have been created\n", processName);
		if (strcmp(processName, "notepad.exe") == 0)
		{	
			DbgPrint("%s detected, id = %d\n", processName, hProcessId);
		}
	}
	else 
	{	 
		DbgPrint("Process %s have been terminated\n", processName);
	}
}
Exemplo n.º 3
0
//--------------------------------------------------------------------------------------------------
static le_clk_Time_t GetConfigKickTimeoutInterval
(
    pid_t procId,  ///< The process id of the client
    uid_t appId    ///< The user id of the application
)
{
    char appName[LIMIT_MAX_APP_NAME_BYTES] = "";
    char procName[LIMIT_MAX_PROCESS_NAME_BYTES] = "";
    char configPath[LIMIT_MAX_PATH_BYTES] = "";

    const int defaultTimeout = TIMEOUT_DEFAULT;
    int proc_milliseconds = CFG_TIMEOUT_USE_DEFAULT;
    int app_milliseconds = CFG_TIMEOUT_USE_DEFAULT;

    if (LE_OK == user_GetAppName(appId, appName, sizeof(appName) ))
    {    // Check if there is a config for the process name first else check under the app name

        // It's a real app. Let's look up the config!
        LE_DEBUG("Getting configured watchdog timeout for app %s", appName);
        if (le_path_Concat("/", configPath, sizeof(configPath), "apps", appName,
                "watchdogTimeout", NULL) == LE_OK)
        {
            app_milliseconds = le_cfg_QuickGetInt(configPath, CFG_TIMEOUT_USE_DEFAULT);
        }

        if (LE_OK == GetProcessNameFromPid( procId, procName, sizeof(procName)))
        {
            // get the config
            configPath[0]='\0';
            LE_DEBUG("Getting configured watchdog timeout for process %s", procName);

            if(le_path_Concat("/", configPath, sizeof(configPath), "apps", appName, "procs",
                    procName, "watchdogTimeout", NULL) == LE_OK)
            {
                proc_milliseconds = le_cfg_QuickGetInt(configPath, CFG_TIMEOUT_USE_DEFAULT);
            }
        }

        // find a valid value starting at proc level and working up
        if (proc_milliseconds == CFG_TIMEOUT_USE_DEFAULT)
        {
            if (app_milliseconds == CFG_TIMEOUT_USE_DEFAULT)
            {
                proc_milliseconds = defaultTimeout;
                LE_WARN("No watchdog timeout configured for %s - using default %d ms", appName,
                  proc_milliseconds);
            }
            else
            {
                proc_milliseconds = app_milliseconds;
                LE_INFO("No watchdog timeout configured for process %s - using app timeout %d ms",
                    procName, proc_milliseconds);
            }
        }
        else
        {
            LE_DEBUG("Watchdog timeout configured for %s - timeout %d ms", procName,
              proc_milliseconds);
        }
    }
    else
    {
        // We have no idea what process is calling us, but we can set a default timeout
        // and play along.
        // TODO: Find a way to get the configured watchdog timeout duration for unsandboxed
        //       apps, which run as root.
        proc_milliseconds = defaultTimeout;
        LE_WARN("Unknown app with uid %u requested watchdog - using default timeout %d ms", appId,
          proc_milliseconds);
    }
    return MakeTimerInterval(proc_milliseconds);
}