ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Restarting frame capture after resuming from sleep?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

whisper1980

USA
83 Posts

Posted - Jun 20 2023 :  14:42:20  Show Profile  Reply
In modern version of Windows, Windows 10 build 2004 and later, if you put the computer to sleep, it uses what is referred to as "Modern Standby" which provides for a quicker resume when sleeping for a short amount of time.

If I have the camera connected and receiving frames, the camera does not automatically turn back on when resuming from sleep. The Windows Camera App itself knows how to resume the camera capture, but the MMF or DirectShow I use for capturing snapshots or video does not know to resume the camera.

In older versions of Windows, I would receive the WM_PowerBroadcast, but for this "Modern Standby" I do not.

Is there a way to know the camera has been disconnected (if that is the case) so that I can reconnect to it? For example, the ImageEnView1MediaFoundationNotify does not seem to have an NotifyType for that.

Thoughts?

Eric

whisper1980

USA
83 Posts

Posted - Jun 20 2023 :  18:21:18  Show Profile  Reply
What I've done so far is to register for the monitor being powered on/off to reconnect to the camera. Not sure if that is the best solution or not, but seems to work for me. GUID_MONITOR_POWER_ON is sent when the monitor powers on and when powers off.

Note:
fPowerNotify: PVoid;


fPowerNotify := RegisterPowerSettingNotification(Self.Handle, GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);


Then when receiving a WM_PowerBroadcast message, I look for PBT_POWERSETTINGCHANGE like this:

PBT_POWERSETTINGCHANGE:
      begin
        if PPowerBroadcastSetting(Msg.LParam)^.Data[0] = 0 then
        begin
          Log('Power Setting Change - Monitor: Off.');   // Treating as sleeping
          // Do whatever to disconnect the camera
        end else
        begin
          Log('Power Setting Change - Monitor: On.');    // Treating as waking up
          // Do whatever to reconnect the camera
        end;
      end;



If my handle changes, like when changing the vcl style, I unregister and re-register it in the FormShow event:

if global.MainHandle <> Self.Handle then
  begin
    global.MainHandle := Self.Handle;
    // Re-setup notifications for "Modern Standby" with the updated handle
    if Assigned(fPowerNotify) then
      UnregisterPowerSettingNotification(fPowerNotify);
    fPowerNotify := RegisterPowerSettingNotification(Self.Handle, GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);
  end;



Eric
Go to Top of Page

xequte

38690 Posts

Posted - Jun 22 2023 :  02:07:26  Show Profile  Reply
Thanks for letting us know, Eric

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: