Detect recording in progress from external script (AHK) (1 Viewer)

Rob Hexenmeister

MP Donator
  • Premium Supporter
  • May 12, 2011
    207
    49
    Slaithwaite
    Home Country
    United Kingdom United Kingdom
    I use an AHK script to launch Mediaportal.

    The reason is that I can tell it to perform other tasks before launching the programme (for instance switching on my Energenie sockets etc) as well as remapping some of my remote control buttons.

    The one shortcoming is that doing it this way necessitates having certain Power Scheduler settings (it is all to do with wake up timings and waiting for the Energenie and other USB controllers to register as active again before I can send the socket-on request).

    However, I have got all of part that working and my script even detects whether the PC was woken by a timer or the Power Button

    What I want to do is script the HTPC to go back to sleep when it has finished recording after a wake timer. I am nearly there. But what I am struggling with is finding a DLL call or similar to detect if TV Server is recording.

    Does anyone know of a way of querying if a Recording is active?
     

    Rob Hexenmeister

    MP Donator
  • Premium Supporter
  • May 12, 2011
    207
    49
    Slaithwaite
    Home Country
    United Kingdom United Kingdom
    No Power Scheduler cannot do it for the reason given in the original post. I am hoping there is a DLL call that will return a value.
     

    CyberSimian

    Test Group
  • Team MediaPortal
  • June 10, 2013
    2,836
    1,753
    Southampton
    Home Country
    United Kingdom United Kingdom
    What I want to do is script the HTPC to go back to sleep when it has finished recording after a wake timer.
    There is a different solution to this, one that I use on my HTPC.

    The important factor to realise is that Windows will not sleep or hibernate the system whilst a recording is in progress. If the sleep or hibernation timeout is set to a very small value (e.g. one minute), the system will sleep or hibernate one minute after the unattended recording has finished. I think that this is the outcome that you want.

    The problem with using a very short sleep or hibernation timeout is that if you leave MP on a menu or with video paused in order (say) to make a cup of coffee, Windows will sleep or hibernate the system one minute after you have left the room. This is probably not the outcome that you want.

    So the solution is to vary the sleep or hibernation timeout according to the state of the system. When you start using the system, your script should set the timeout to a large value (e.g. one hour). When you have finished using the system, the script should set the timeout to a small value and allow Windows to sleep or hibernate the system.

    I wrote a tool in the C programming language to control this, but I prototyped it using a BAT file, so I think that you could do similar from an AutoHotKey script. I originally used the presence or absence of a display screen to decide how to set the timeout, and this is what the prototype BAT version checks. The refined C version checks a USB hub powered via an IR remote-controlled mains socket switched on and off by my Harmony 650 remote control.

    I still have the prototype BAT version and can post it if you are interested in exploring this solution further.

    -- from CyberSimian in the UK
     

    Rob Hexenmeister

    MP Donator
  • Premium Supporter
  • May 12, 2011
    207
    49
    Slaithwaite
    Home Country
    United Kingdom United Kingdom
    Interesting post CyberSimian.

    That wouldn't work for me though as that would shut down the computer on idle, no matter how it was switched on. The method I am using detects whether it was a wake timer or the power button that woke the computer. If it was the power button, it will not try to shut down. I will post the whole script when it is done.

    Meanwhile a little progress on the principle of accessing functions within DLLs - as per this AHK test script:

    DllCall ("C:\Program Files (x86)\Team Media Portal\MediaPortal TV Server\Hauppauge.dll\GetAudBitRate", "double", Recording)
    MsgBox %Recording%
    MsgBox %ErrorLevel%

    Now... unfortunately I cannot seem to find the function I want despite Edalex's helpful pointers above. Looking for IsAnyCardRecording in TVControl.dll generated a not found error code, which has baffled me for the time being.
     

    Rob Hexenmeister

    MP Donator
  • Premium Supporter
  • May 12, 2011
    207
    49
    Slaithwaite
    Home Country
    United Kingdom United Kingdom
    Well I have come up with something that works. It is very dirty and brutal but does the job. I tried other methods, such as SetThreadExecutionState to no avail - despite the DLL appearing to call and report success, it seemed to have no effect at all.

    So here is what I have:

    Three Autohotkey (AHK) Scripts.

    Wake Up.Exe is called by Task Scheduler, triggered by a power state change message. This therefore kicks in if the computer is woken up from sleep
    Start MP.Exe is scheduled to run at start up and is the "main" controller programme. It is also called by Wake Up.Exe to make sure everything starts afresh on wake.
    Dummy Process.Exe is exactly as it sounds it does nothing. It is run by Start MP if the computer was woken with the power button or switched on by the user. The key is to tell PowerScheduler not to shut down if "Dummy Process" is running and you can do that in the PowerScheduler configuration in TV Server.

    I include the compiled exe programmes and the ahk scripts for you to examine in notepad. There are other things in those, such as the switching on of my Energenie Sockets and the hiding of the mouse pointer (the latter which I cannot take full credit for at all, I just did the bit which repositions it to where it was when the mouse was disabled)

    I have left the failed experiments in the scripts as comments, in case anyone can tidy this up and make it work with the DLLs which would be much tidier.

    The original idea which I would still like to pursue if possible is to detect if TV recording has stopped, and send the PC to sleep if it wasn't switched on with the power button. Sadly, while the AHK DllCall function finds the DLL, it can't find the command that reports if any card is recording. It may be a privileges issue, or maybe it is a 32 bit issue. I just don't know, that is beyond my powers.
     

    Attachments

    • AHKs.zip
      1.1 MB

    Users who are viewing this thread

    Top Bottom