Ticket #11524: power.patch

File power.patch, 10.7 KB (added by rwscott@…, 11 years ago)

Support power save mode with the Internal Firewire channel change with analog capture.

  • mythtv/libs/libmythtv/recorders/channelbase.cpp

    commit ea5e27ad32d6a72f58783e1e7ec12d75d48b7249
    Author: Rick Scott <rwscott@users.sourceforge.net>
    Date:   Sat May 4 07:10:47 2013 -0400
    
        Support power save mode with the Internal Firewire channel change with analog capture.
        
        Expand on d49f3f22d by adding support for EnterPowerSavingMode, allowing
        the firewire device to be powered off when not in use. Also avoids
        spinning up the port handler thread when only changing channels.
    
    diff --git a/mythtv/libs/libmythtv/recorders/channelbase.cpp b/mythtv/libs/libmythtv/recorders/channelbase.cpp
    index 35544fc..7c729e5 100644
    a b using namespace std; 
    1717#include <QCoreApplication>
    1818
    1919// MythTV headers
    20 #ifdef USING_OSX_FIREWIRE
    21 #include "darwinfirewiredevice.h"
    22 #endif
    23 #ifdef USING_LINUX_FIREWIRE
    24 #include "linuxfirewiredevice.h"
    25 #endif
    2620#include "firewirechannel.h"
    2721#include "mythcorecontext.h"
    2822#include "cetonchannel.h"
    void ChannelBase::HandleScript(const QString &freqid) 
    700694    }
    701695    else
    702696    {
    703         if ((*it)->externalChanger.toLower() == "internal")
    704         {
    705             ok = ChangeInternalChannel(freqid, (*it)->inputid);
    706             if (!ok)
    707             {
    708                 LOG(VB_GENERAL, LOG_ERR, LOC + "Can not execute internal channel "
    709                     "changer.");
    710                 m_system_status = 2; // failed
    711             }
    712             else
    713                 m_system_status = 3; // success
    714 
    715             HandleScriptEnd(ok);
    716         }
    717         else
    718         {
    719             ok = ChangeExternalChannel((*it)->externalChanger, freqid);
    720             if (!ok)
    721             {
    722                 LOG(VB_GENERAL, LOG_ERR, LOC + "Can not execute channel changer.");
    723                 m_system_status = 2; // failed
    724                 HandleScriptEnd(ok);
    725             }
    726         }
    727     }
    728 }
    729 
    730 bool ChannelBase::ChangeInternalChannel(const QString &freqid,
    731                                         uint inputid)
    732 {
    733 #ifdef USING_FIREWIRE
    734     FirewireDevice *device = NULL;
    735     QString fwnode = CardUtil::GetFirewireChangerNode(inputid);
    736     uint64_t guid = string_to_guid(fwnode);
    737     QString fwmodel = CardUtil::GetFirewireChangerModel(inputid);
    738 
    739     LOG(VB_GENERAL, LOG_ERR, LOC + QString("Internal channel change to %1 "
    740             "on inputid %2, GUID %3 (%4)").arg(freqid).arg(inputid)
    741             .arg(fwnode).arg(fwmodel));
    742 
    743 #ifdef USING_LINUX_FIREWIRE
    744     device = new LinuxFirewireDevice(
    745         guid, 0, 100, 1);
    746 #endif // USING_LINUX_FIREWIRE
    747 
    748 #ifdef USING_OSX_FIREWIRE
    749     device = new DarwinFirewireDevice(guid, 0, 100);
    750 #endif // USING_OSX_FIREWIRE
    751 
    752     if (!device)
    753         return false;
    754 
    755     if (!device->OpenPort())
    756         return false;
    757 
    758     if (!device->SetChannel(fwmodel, 0, freqid.toUInt()))
    759     {
    760         device->ClosePort();
    761         delete device;
    762         device = NULL;
    763         return false;
     697        ok = ChangeExternalChannel((*it)->externalChanger, freqid);
     698        if (!ok)
     699        {
     700            LOG(VB_GENERAL, LOG_ERR, LOC + "Can not execute channel changer.");
     701            m_system_status = 2; // failed
     702            HandleScriptEnd(ok);
     703        }
    764704    }
    765 
    766     device->ClosePort();
    767     delete device;
    768     device = NULL;
    769     return true;
    770 #else
    771     return false;
    772 #endif
    773705}
    774706
    775707/// \note m_system_lock must be held when this is called
  • mythtv/libs/libmythtv/recorders/channelbase.h

    diff --git a/mythtv/libs/libmythtv/recorders/channelbase.h b/mythtv/libs/libmythtv/recorders/channelbase.h
    index 5d87b13..751bd0f 100644
    a b class ChannelBase 
    151151
    152152    bool ChangeExternalChannel(const QString &changer,
    153153                               const QString &newchan);
    154     bool ChangeInternalChannel(const QString &newchan,
    155                                uint cardinputid);
    156154
    157155    TVRec   *m_pParent;
    158156    QString  m_curchannelname;
  • mythtv/libs/libmythtv/recorders/dtvchannel.cpp

    diff --git a/mythtv/libs/libmythtv/recorders/dtvchannel.cpp b/mythtv/libs/libmythtv/recorders/dtvchannel.cpp
    index 204f727..e6fa5f5 100644
    a b  
    33using namespace std;
    44
    55// MythTV headers
     6#ifdef USING_OSX_FIREWIRE
     7#include "darwinfirewiredevice.h"
     8#endif
     9#ifdef USING_LINUX_FIREWIRE
     10#include "linuxfirewiredevice.h"
     11#endif
    612#include "mythdb.h"
    713#include "tv_rec.h"
    814#include "cardutil.h"
    void DTVChannel::ReturnMasterLock(DTVChannelP &chan) 
    175181    }
    176182}
    177183
     184bool DTVChannel::InternalTune(bool power, uint channel)
     185{
     186bool ok;
     187FirewireDevice *device = NULL;
     188QString fwnode = CardUtil::GetFirewireChangerNode(m_currentInputID);
     189uint64_t guid = string_to_guid(fwnode);
     190
     191    LOG(VB_CHANNEL, LOG_INFO, LOC + "Internal channel change");
     192
     193#ifdef USING_LINUX_FIREWIRE
     194    device = new LinuxFirewireDevice(guid, 0, 100, 1);
     195#endif // USING_LINUX_FIREWIRE
     196
     197#ifdef USING_OSX_FIREWIRE
     198    device = new DarwinFirewireDevice(guid, 0, 100);
     199#endif // USING_OSX_FIREWIRE
     200    if (device && device->OpenPort(false))
     201    {
     202        ok = device->SetPowerState(power);
     203        LOG(VB_CHANNEL, LOG_INFO, LOC + QString("setting power state result %1").arg(ok));
     204        if (power)
     205        {
     206        QString fwmodel = CardUtil::GetFirewireChangerModel(m_currentInputID);
     207
     208            ok = device->SetChannel(fwmodel, 0, channel);
     209            LOG(VB_CHANNEL, LOG_INFO, LOC + QString("channel change result %1").arg(ok));
     210        }
     211        m_system_status = ok ? 3 : 2;
     212        device->ClosePort();
     213        delete device;
     214        device = NULL;
     215    }
     216    else
     217    {
     218        LOG(VB_CHANNEL, LOG_ERR, LOC + "Opening firewire device port failed");
     219        m_system_status = 2;
     220        ok = false;
     221    }
     222    return(ok);
     223}
     224
    178225bool DTVChannel::SetChannelByString(const QString &channum)
    179226{
    180227    QString loc = LOC + QString("SetChannelByString(%1): ").arg(channum);
    bool DTVChannel::SetChannelByString(const QString &channum) 
    339386            ok = Tune(freqid, finetune);
    340387        }
    341388    }
     389#ifdef USING_FIREWIRE
     390    else if ((*it)->externalChanger.toLower() == "internal")
     391    {
     392        ok = InternalTune(true, freqid.toUInt());
     393    }
     394#endif
    342395
    343396    LOG(VB_CHANNEL, LOG_INFO, loc + ((ok) ? "success" : "failure"));
    344397
    bool DTVChannel::SetChannelByString(const QString &channum) 
    401454        m_pParent->SetVideoFiltersForChannel(GetCurrentSourceID(), channum);
    402455    InitPictureAttributes();
    403456
    404     HandleScript(freqid);
     457#ifdef USING_FIREWIRE
     458    if ((*it)->externalChanger.toLower() != "internal")
     459#endif
     460    {
     461        HandleScript(freqid);
     462    }
    405463
    406464    return ok;
    407465}
    bool DTVChannel::TuneMultiplex(uint mplexid, QString inputname) 
    425483
    426484    return Tune(tuning, inputname);
    427485}
     486
     487bool DTVChannel::EnterPowerSavingMode(void)
     488{
     489#ifdef USING_FIREWIRE
     490    InternalTune(false, 0);
     491#endif
     492    return true;
     493}
  • mythtv/libs/libmythtv/recorders/dtvchannel.h

    diff --git a/mythtv/libs/libmythtv/recorders/dtvchannel.h b/mythtv/libs/libmythtv/recorders/dtvchannel.h
    index 36bb2ad..c835a5b 100644
    a b class DTVChannel : public ChannelBase 
    5252    /// \brief Performs IPTV Tuning. Only implemented by IPTVChannel.
    5353    virtual bool Tune(const IPTVTuningData&) { return false; }
    5454    /// \brief Enters power saving mode if the card supports it
    55     virtual bool EnterPowerSavingMode(void)
    56     {
    57         return true;
    58     }
     55    virtual bool EnterPowerSavingMode(void);
    5956    /// \brief This tunes on the frequency Identification parameter for
    6057    ///        hardware that supports it.
    6158    ///
    class DTVChannel : public ChannelBase 
    134131    void SetTuningMode(const QString &tuningmode);
    135132
    136133    void SaveCachedPids(const pid_cache_t &pid_cache) const;
     134    bool InternalTune(bool power, uint channel);
    137135
    138136  protected:
    139137    /// \brief Sets PSIP table standard: MPEG, DVB, ATSC, or OpenCable
  • mythtv/libs/libmythtv/recorders/firewiredevice.h

    diff --git a/mythtv/libs/libmythtv/recorders/firewiredevice.h b/mythtv/libs/libmythtv/recorders/firewiredevice.h
    index 4151220..58841b2 100644
    a b class FirewireDevice 
    194194
    195195    // Commands
    196196    virtual bool OpenPort(void) = 0;
     197    virtual bool OpenPort(bool allow_recording) = 0;
    197198    virtual bool ClosePort(void) = 0;
    198199    virtual bool ResetBus(void) { return false; }
    199200
  • mythtv/libs/libmythtv/recorders/linuxfirewiredevice.cpp

    diff --git a/mythtv/libs/libmythtv/recorders/linuxfirewiredevice.cpp b/mythtv/libs/libmythtv/recorders/linuxfirewiredevice.cpp
    index 0fd86a2..bdf27bb 100644
    a b void LinuxFirewireDevice::HandleBusReset(void) 
    235235    }
    236236}
    237237
    238 bool LinuxFirewireDevice::OpenPort(void)
     238bool LinuxFirewireDevice::OpenPort(bool allow_record)
    239239{
     240    if (allow_record)
     241    {
    240242    LOG(VB_RECORD, LOG_INFO, LOC + "Starting Port Handler Thread");
    241243    QMutexLocker locker(&m_priv->start_stop_port_handler_lock);
    242244    LOG(VB_RECORD, LOG_INFO, LOC + "Starting Port Handler Thread -- locked");
     245    }
    243246
    244247    LOG(VB_RECORD, LOG_INFO, LOC + "OpenPort()");
    245248
    bool LinuxFirewireDevice::OpenPort(void) 
    279282        return false;
    280283    }
    281284
     285    if (allow_record && !m_priv->port_handler_thread)
     286    {
    282287    m_priv->run_port_handler = true;
    283288
    284289    LOG(VB_RECORD, LOG_INFO, LOC + "Starting port handler thread");
    bool LinuxFirewireDevice::OpenPort(void) 
    289294        m_priv->port_handler_wait.wait(mlocker.mutex(), 100);
    290295
    291296    LOG(VB_RECORD, LOG_INFO, LOC + "Port handler thread started");
     297    }
    292298
    293299    m_open_port_cnt++;
    294300
    295301    return true;
    296302}
    297303
     304bool LinuxFirewireDevice::OpenPort(void)
     305{
     306    return OpenPort(true);
     307}
     308
    298309bool LinuxFirewireDevice::ClosePort(void)
    299310{
    300311    LOG(VB_RECORD, LOG_INFO, LOC + "Stopping Port Handler Thread");
    bool LinuxFirewireDevice::ClosePort(void) 
    321332        if (IsNodeOpen())
    322333            CloseNode();
    323334
     335        if (m_priv->port_handler_thread)
     336        {
    324337        LOG(VB_RECORD, LOG_INFO,
    325338            LOC + "Waiting for port handler thread to stop");
    326339        m_priv->run_port_handler = false;
    bool LinuxFirewireDevice::ClosePort(void) 
    334347        m_priv->port_handler_thread = NULL;
    335348
    336349        LOG(VB_RECORD, LOG_INFO, LOC + "Joined port handler thread");
     350        }
    337351
    338352        remove_handle(GetInfoPtr()->fw_handle);
    339353
  • mythtv/libs/libmythtv/recorders/linuxfirewiredevice.h

    diff --git a/mythtv/libs/libmythtv/recorders/linuxfirewiredevice.h b/mythtv/libs/libmythtv/recorders/linuxfirewiredevice.h
    index ee1ca0f..36ae48f 100644
    a b class LinuxFirewireDevice : public FirewireDevice, public QRunnable 
    2929
    3030    // Commands
    3131    virtual bool OpenPort(void);
     32    virtual bool OpenPort(bool allow_recording);
    3233    virtual bool ClosePort(void);
    3334    virtual bool ResetBus(void);
    3435