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

Rob Hexenmeister

MP Donator
  • Premium Supporter
  • May 12, 2011
    164
    38
    Slaithwaite
    United Kingdom United Kingdom
    Country flag
    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
    164
    38
    Slaithwaite
    United Kingdom United Kingdom
    Country flag
    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,264
    1,361
    Southampton
    United Kingdom United Kingdom
    Country flag
    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
    164
    38
    Slaithwaite
    United Kingdom United Kingdom
    Country flag
    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
    164
    38
    Slaithwaite
    United Kingdom United Kingdom
    Country flag
    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

    Users who are viewing this thread

    Similar threads
    OP Title Forum Replies Date
    I MP Server goes into suspend, because it doesn't detect the MP Client General Support 6
    M What does MP homeserver detection need at the client end, and what does the server need to transmit? General 6
    morpheus_xx Some stats of IPInfo (detecting location for Weather plugin) MediaPortal 2 0
    rsbrux "Enter" no longer reliably adds a recording from TV Guide Electronic Program Guide 21
    R remotely record tv MPExtended 1
    T MP2 - V2.3.2 Reimport Recording Has Dead Interface Submit: Bug Reports 7
    T MP2 - V2.3.2 Recorded TV Program Won't Delete Submit: Bug Reports 3
    rsbrux 1.27.0 Recorded TV Thumbnail Oddities MediaPortal 1 Talk 11
    rsbrux No recordings for several days; no errors General Support 7
    B Importing recordings and schedules from TVmosaic General 4
    P MP2 TV Recording Logs General 1
    D Free text recording TV-Server 1
    Peter PROMS MediaPortal2 V2.3.1 Crash in Recorded TV playback Newcomers Forum 13
    R HDHomeRun CONNECT QUATRO - can MP record more than 4 channels MediaPortal 1 Talk 2
    F Completed Delete recordings fail. HTPC Projects 0
    R Deadlock in TV Server if recording while importing EPG TV-Server 10
    C MP2 - V2.3 Nereus: doesn't show a recording in extended scheduling option General 5
    404 Recording problems Television (MyTV frontend and TV-Server) 6
    D wintv doesn’t stop recording on time Newcomers Forum 7
    P [solved] Blocking TV recordings on client? General 10
    1gkar [solved] LiveTV Records Causing 100% Drive Activity Television (MyTV frontend and TV-Server) 10
    toricred Recordings Change : to _ in Series Name General 0
    P Recording films that have an "intermission" General 3
    H MP2 database won't keep in synch with recordings General 8
    toricred Only Show Actual Recordings General 1

    Similar threads

    Top Bottom