/// <summary> /// Applies the custom power plan. /// </summary> /// <returns></returns> BOOL PowerSchemes::ApplyCustomPowerPlan() { BOOL bSuccess = TRUE; /************************************************************************/ /* Create power request */ /************************************************************************/ powerReasonContext = new REASON_CONTEXT; powerReasonContext->Version = POWER_REQUEST_CONTEXT_VERSION; powerReasonContext->Flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING; // POWER_REQUEST_CONTEXT_DETAILED_STRING powerReasonContext->Reason.SimpleReasonString = L"Power capping for SMJ"; hPowerRequest = PowerCreateRequest(powerReasonContext); // The calling process continues to run instead of being suspended or terminated // by process lifetime management mechanisms. When and how long the process // is allowed to run depends on the operating system and power policy settings. // // Value: // PowerRequestDisplayRequired : The display remains on even if there is no user input for an extended period of time // PowerRequestSystemRequired : The system continues to run instead of entering sleep after a period of user inactivity // PowerRequestAwayModeRequired : Continues to run but turns off audio and video to give the appearance of sleep // PowerRequestExecutionRequired : (win 8 or later)The calling process continues to run // instead of being suspended or terminated by process // lifetime management mechanisms if(!PowerSetRequest(hPowerRequest, PowerRequestSystemRequired)) { //printf("PowerSetRequest failed\n"); } DWORD mySchemeIndex; *mySchemeGuid = GUID_POWER_AWARE_SMJ; if( !IsPowerSchemeExist(*mySchemeGuid, mySchemeIndex)) { /* Not exist */ bSuccess&=CreateCustomPowerPlan(); } /************************************************************************/ /* Apply new power scheme */ /************************************************************************/ bSuccess&=ApplyPowerScheme(*mySchemeGuid); bSuccess&=GetCurrentPowerSettings(); return bSuccess; }
HRESULT CaptureManager::StartPreview() { if (m_pEngine == NULL) { return MF_E_NOT_INITIALIZED; } if (m_bPreviewing == true) { return S_OK; } IMFCaptureSink *pSink = NULL; IMFMediaType *pMediaType = NULL; IMFMediaType *pMediaType2 = NULL; IMFCaptureSource *pSource = NULL; HRESULT hr = S_OK; // Get a pointer to the preview sink. if (m_pPreview == NULL) { hr = m_pEngine->GetSink(MF_CAPTURE_ENGINE_SINK_TYPE_PREVIEW, &pSink); if (FAILED(hr)) { goto done; } hr = pSink->QueryInterface(IID_PPV_ARGS(&m_pPreview)); if (FAILED(hr)) { goto done; } hr = m_pPreview->SetRenderHandle(m_hwndPreview); if (FAILED(hr)) { goto done; } hr = m_pEngine->GetSource(&pSource); if (FAILED(hr)) { goto done; } // Configure the video format for the preview sink. hr = pSource->GetCurrentDeviceMediaType((DWORD)MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW , &pMediaType); if (FAILED(hr)) { goto done; } hr = CloneVideoMediaType(pMediaType, MFVideoFormat_RGB32, &pMediaType2); if (FAILED(hr)) { goto done; } hr = pMediaType2->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE); if (FAILED(hr)) { goto done; } // Connect the video stream to the preview sink. DWORD dwSinkStreamIndex; hr = m_pPreview->AddStream((DWORD)MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW, pMediaType2, NULL, &dwSinkStreamIndex); if (FAILED(hr)) { goto done; } } hr = m_pEngine->StartPreview(); if (!m_fPowerRequestSet && m_hpwrRequest != INVALID_HANDLE_VALUE) { // NOTE: By calling this, on SOC systems (AOAC enabled), we're asking the system to not go // into sleep/connected standby while we're streaming. However, since we don't want to block // the device from ever entering connected standby/sleep, we're going to latch ourselves to // the monitor on/off notification (RegisterPowerSettingNotification(GUID_MONITOR_POWER_ON)). // On SOC systems, this notification will fire when the user decides to put the device in // connected standby mode--we can trap this, turn off our media streams and clear this // power set request to allow the device to go into the lower power state. m_fPowerRequestSet = (TRUE == PowerSetRequest(m_hpwrRequest, PowerRequestExecutionRequired)); } done: SafeRelease(&pSink); SafeRelease(&pMediaType); SafeRelease(&pMediaType2); SafeRelease(&pSource); return hr; }