Detect recording in progress from external script (AHK)

Discussion in 'General Support' started by Rob Hexenmeister, April 2, 2018.

  1. Rob Hexenmeister
    • Premium Supporter

    Rob Hexenmeister MP Donator

    Joined:
    May 12, 2011
    Messages:
    73
    Likes Received:
    4
    Gender:
    Male
    Location:
    Slaithwaite
    Ratings:
    +7 / 0
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    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?
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Edalex
    • Premium Supporter

    Edalex Community Plugin Dev

    Joined:
    January 3, 2008
    Messages:
    2,893
    Likes Received:
    707
    Gender:
    Male
    Location:
    Saratov
    Ratings:
    +1,212 / 9
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
    It is possible in C#
     
  4. Rob Hexenmeister
    • Premium Supporter

    Rob Hexenmeister MP Donator

    Joined:
    May 12, 2011
    Messages:
    73
    Likes Received:
    4
    Gender:
    Male
    Location:
    Slaithwaite
    Ratings:
    +7 / 0
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    Thank you. If you know how, I may be able to adapt it for AHK
     
  5. Edalex
    • Premium Supporter

    Edalex Community Plugin Dev

    Joined:
    January 3, 2008
    Messages:
    2,893
    Likes Received:
    707
    Gender:
    Male
    Location:
    Saratov
    Ratings:
    +1,212 / 9
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
  6. Edalex
    • Premium Supporter

    Edalex Community Plugin Dev

    Joined:
    January 3, 2008
    Messages:
    2,893
    Likes Received:
    707
    Gender:
    Male
    Location:
    Saratov
    Ratings:
    +1,212 / 9
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
  7. Rob Hexenmeister
    • Premium Supporter

    Rob Hexenmeister MP Donator

    Joined:
    May 12, 2011
    Messages:
    73
    Likes Received:
    4
    Gender:
    Male
    Location:
    Slaithwaite
    Ratings:
    +7 / 0
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    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.
     
  8. CyberSimian
    • Team MediaPortal

    CyberSimian Test Group

    Joined:
    June 10, 2013
    Messages:
    1,462
    Likes Received:
    409
    Gender:
    Male
    Location:
    Southampton
    Ratings:
    +808 / 3
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    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
     
  9. Rob Hexenmeister
    • Premium Supporter

    Rob Hexenmeister MP Donator

    Joined:
    May 12, 2011
    Messages:
    73
    Likes Received:
    4
    Gender:
    Male
    Location:
    Slaithwaite
    Ratings:
    +7 / 0
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    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.
     
  10. Rob Hexenmeister
    • Premium Supporter

    Rob Hexenmeister MP Donator

    Joined:
    May 12, 2011
    Messages:
    73
    Likes Received:
    4
    Gender:
    Male
    Location:
    Slaithwaite
    Ratings:
    +7 / 0
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    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.
     

    Attached Files:

    • AHKs.zip
      File size:
      1.1 MB
      Uploaded:
      April 21, 2018
      Views:
      30
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!