MythTV  0.26-pre
firewirechannel.cpp
Go to the documentation of this file.
00001 
00008 #include "mythlogging.h"
00009 #include "tv_rec.h"
00010 #include "linuxfirewiredevice.h"
00011 #if USING_OSX_FIREWIRE
00012 #include "darwinfirewiredevice.h"
00013 #endif
00014 #include "firewirechannel.h"
00015 
00016 #define LOC QString("FireChan(%1): ").arg(GetDevice())
00017 
00018 FirewireChannel::FirewireChannel(TVRec *parent, const QString &_videodevice,
00019                                  const FireWireDBOptions &firewire_opts) :
00020     DTVChannel(parent),
00021     videodevice(_videodevice),
00022     fw_opts(firewire_opts),
00023     device(NULL),
00024     current_channel(0),
00025     isopen(false)
00026 {
00027     uint64_t guid = string_to_guid(videodevice);
00028     uint subunitid = 0; // we only support first tuner on STB...
00029 
00030 #ifdef USING_LINUX_FIREWIRE
00031     device = new LinuxFirewireDevice(
00032         guid, subunitid, fw_opts.speed,
00033         LinuxFirewireDevice::kConnectionP2P == (uint) fw_opts.connection);
00034 #endif // USING_LINUX_FIREWIRE
00035 
00036 #ifdef USING_OSX_FIREWIRE
00037     device = new DarwinFirewireDevice(guid, subunitid, fw_opts.speed);
00038 #endif // USING_OSX_FIREWIRE
00039 }
00040 
00041 FirewireChannel::~FirewireChannel()
00042 {
00043     Close();
00044     delete device;
00045 }
00046 
00047 bool FirewireChannel::Open(void)
00048 {
00049     LOG(VB_CHANNEL, LOG_INFO, LOC + "Open()");
00050 
00051     if (!device)
00052         return false;
00053 
00054     if (isopen)
00055         return true;
00056 
00057     if (!InitializeInputs())
00058         return false;
00059 
00060     if (m_inputs.find(m_currentInputID) == m_inputs.end())
00061         return false;
00062 
00063     InputMap::const_iterator it = m_inputs.find(m_currentInputID);
00064     if (!FirewireDevice::IsSTBSupported(fw_opts.model) &&
00065         (*it)->externalChanger.isEmpty())
00066     {
00067         LOG(VB_GENERAL, LOG_ERR, LOC +
00068             QString("Model: '%1' is not supported.").arg(fw_opts.model));
00069 
00070         return false;
00071     }
00072 
00073     if (!device->OpenPort())
00074         return false;
00075 
00076     isopen = true;
00077 
00078     return true;
00079 }
00080 
00081 void FirewireChannel::Close(void)
00082 {
00083     LOG(VB_CHANNEL, LOG_INFO, LOC + "Close()");
00084     if (isopen)
00085     {
00086         device->ClosePort();
00087         isopen = false;
00088     }
00089 }
00090 
00091 QString FirewireChannel::GetDevice(void) const
00092 {
00093     return videodevice;
00094 }
00095 
00096 bool FirewireChannel::SetPowerState(bool on)
00097 {
00098     if (!isopen)
00099     {
00100         LOG(VB_GENERAL, LOG_ERR, LOC +
00101             "SetPowerState() called on closed FirewireChannel.");
00102 
00103         return false;
00104     }
00105 
00106     return device->SetPowerState(on);
00107 }
00108 
00109 FirewireDevice::PowerState FirewireChannel::GetPowerState(void) const
00110 {
00111     if (!isopen)
00112     {
00113         LOG(VB_GENERAL, LOG_ERR, LOC +
00114             "GetPowerState() called on closed FirewireChannel.");
00115 
00116         return FirewireDevice::kAVCPowerQueryFailed;
00117     }
00118 
00119     return device->GetPowerState();
00120 }
00121 
00122 bool FirewireChannel::Retune(void)
00123 {
00124     LOG(VB_CHANNEL, LOG_INFO, LOC + "Retune()");
00125 
00126     if (FirewireDevice::kAVCPowerOff == GetPowerState())
00127     {
00128         LOG(VB_GENERAL, LOG_ERR, LOC +
00129             "STB is turned off, must be on to retune.");
00130 
00131         return false;
00132     }
00133 
00134     if (current_channel)
00135     {
00136         QString freqid = QString::number(current_channel);
00137         return Tune(freqid, 0);
00138     }
00139 
00140     return false;
00141 }
00142 
00143 bool FirewireChannel::Tune(const QString &freqid, int /*finetune*/)
00144 {
00145     LOG(VB_CHANNEL, LOG_INFO, QString("Tune(%1)").arg(freqid));
00146 
00147     bool ok;
00148     uint channel = freqid.toUInt(&ok);
00149     if (!ok)
00150         return false;
00151 
00152     if (FirewireDevice::kAVCPowerOff == GetPowerState())
00153     {
00154         LOG(VB_GENERAL, LOG_WARNING, LOC +
00155                 "STB is turned off, must be on to set channel.");
00156 
00157         return true; // signal monitor will call retune later...
00158     }
00159 
00160     if (!device->SetChannel(fw_opts.model, 0, channel))
00161         return false;
00162 
00163     current_channel = channel;
00164 
00165     return true;
00166 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends