MythTV  master
iptvchannel.cpp
Go to the documentation of this file.
1 
10 // C++ headers
11 #include <utility>
12 
13 // Qt headers
14 #include <QUrl>
15 
16 // MythTV headers
17 #include "libmythbase/mythdb.h"
19 
20 #include "hlsstreamhandler.h"
21 #include "httptsstreamhandler.h"
22 #include "iptvchannel.h"
23 #include "iptvrecorder.h"
24 #include "iptvstreamhandler.h"
25 
26 #define LOC QString("IPTVChan[%1]: ").arg(m_inputId)
27 
28 IPTVChannel::IPTVChannel(TVRec *rec, QString videodev) :
29  DTVChannel(rec), m_videoDev(std::move(videodev))
30 {
31  LOG(VB_CHANNEL, LOG_INFO, LOC + "ctor");
32 }
33 
35 {
36  LOG(VB_CHANNEL, LOG_INFO, LOC + "dtor");
38 }
39 
41 {
42  LOG(VB_CHANNEL, LOG_INFO, LOC + "Open()");
43 
44  if (IsOpen())
45  return true;
46 
47  QMutexLocker locker(&m_tuneLock);
48 
49  if (!InitializeInput())
50  {
51  Close();
52  return false;
53  }
54 
55  if (m_streamData)
57 
58  return true;
59 }
60 
62 {
63  LOG(VB_CHANNEL, LOG_INFO, LOC +
64  QString("SetStreamData(0x%1) StreamHandler(0x%2)")
65  .arg((intptr_t)sd,0,16).arg((intptr_t)m_streamHandler,0,16));
66 
67  QMutexLocker locker(&m_streamLock);
68 
69  if (m_streamData == sd && m_streamHandler)
70  return;
71 
72  if (m_streamHandler)
73  {
74  if (sd)
76 
77  if (m_streamData)
79  }
80  else if (sd)
81  {
84  }
85 
86  m_streamData = sd;
87 }
88 
90 {
91  if (m_streamHandler)
93 }
94 
96 {
98  return true;
99 }
100 
102 {
103  if (m_lastTuning.IsHLS())
104  {
105  LOG(VB_CHANNEL, LOG_INFO, LOC + "Creating HLSStreamHandler");
107  }
108  else if (m_lastTuning.IsHTTPTS())
109  {
110  LOG(VB_CHANNEL, LOG_INFO, LOC + "Creating HTTPTSStreamHandler");
112  }
113  else
114  {
115  LOG(VB_CHANNEL, LOG_INFO, LOC + "Creating IPTVStreamHandler");
117  }
118 }
119 
121 {
122  LOG(VB_CHANNEL, LOG_INFO, LOC + "CloseStreamHandler()");
123 
124  QMutexLocker locker(&m_streamLock);
125 
126  if (m_streamHandler)
127  {
128  if (m_streamData)
129  {
131  m_streamData = nullptr; //see trac ticket #12773
132  }
133 
134  auto* hsh = dynamic_cast<HLSStreamHandler*>(m_streamHandler);
135  auto* httpsh = dynamic_cast<HTTPTSStreamHandler*>(m_streamHandler);
136 
137  if (hsh)
138  {
140  m_streamHandler = hsh;
141  }
142  else if (httpsh)
143  {
145  m_streamHandler = httpsh;
146  }
147  else
148  {
150  }
151  }
152 }
153 
154 bool IPTVChannel::IsOpen(void) const
155 {
156  QMutexLocker locker(&m_streamLock);
157  bool ret = (m_streamHandler && !m_streamHandler->HasError() &&
159  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("IsOpen(%1) %2")
161  ret ? "true" : "false"));
162  return ret;
163 }
164 
165 bool IPTVChannel::Tune(const IPTVTuningData &tuning, bool scanning)
166 {
167  QMutexLocker locker(&m_tuneLock);
168 
169  LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Tune(%1)")
170  .arg(tuning.GetDeviceName()));
171 
172  if (tuning.GetDataURL().scheme().toUpper() == "RTSP")
173  {
174  // TODO get RTP info using RTSP
175  }
176 
177  if (!tuning.IsValid())
178  {
179  LOG(VB_CHANNEL, LOG_ERR, LOC + QString("Invalid tuning info %1")
180  .arg(tuning.GetDeviceName()));
181  return false;
182  }
183 
184  if (m_lastTuning == tuning)
185  {
186  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("Already tuned to %1")
187  .arg(tuning.GetDeviceName()));
188  return true;
189  }
190 
191  m_lastTuning = tuning;
192 
193  if (!m_firstTune || scanning)
194  // for historical reason, an initial tune is requested at
195  // startup so don't open the stream handler just yet it will
196  // be opened after the next Tune or SetStreamData)
197  {
199 
201  if (tmp)
203  else
205  }
206 
207  m_firstTune = false;
208 
209  LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Tuned to (%1)")
210  .arg(tuning.GetDeviceName()));
211 
212  return true;
213 }
214 
215 /* vim: set expandtab tabstop=4 shiftwidth=4: */
IPTVStreamHandler::Return
static void Return(IPTVStreamHandler *&ref, int inputid)
Definition: iptvstreamhandler.cpp:69
IPTVChannel::m_streamData
MPEGStreamData * m_streamData
Definition: iptvchannel.h:69
mythdb.h
IPTVChannel::OpenStreamHandler
void OpenStreamHandler(void)
Definition: iptvchannel.cpp:101
IPTVChannel::~IPTVChannel
~IPTVChannel() override
Definition: iptvchannel.cpp:34
StreamHandler::HasError
bool HasError(void) const
Definition: streamhandler.h:67
IPTVChannel::m_streamHandler
IPTVStreamHandler * m_streamHandler
Definition: iptvchannel.h:68
IPTVStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, const QString &output_file=QString()) override
Definition: iptvstreamhandler.h:88
IPTVTuningData::GetDataURL
QUrl GetDataURL(void) const
Definition: iptvtuningdata.h:139
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
HLSStreamHandler
Definition: hlsstreamhandler.h:23
StreamHandler::RemoveListener
virtual void RemoveListener(MPEGStreamData *data)
Definition: streamhandler.cpp:80
tmp
static guint32 * tmp
Definition: goom_core.cpp:26
LOC
#define LOC
-*- Mode: c++ -*- IPTVChannel Copyright (c) 2006-2009 Silicondust Engineering Ltd,...
Definition: iptvchannel.cpp:26
mythlogging.h
IPTVChannel::EnterPowerSavingMode
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
Definition: iptvchannel.cpp:95
IPTVTuningData::IsHTTPTS
bool IsHTTPTS() const
Definition: iptvtuningdata.h:203
IPTVTuningData::GetDeviceName
QString GetDeviceName(void) const
Definition: iptvtuningdata.h:113
IPTVChannel::CloseStreamHandler
void CloseStreamHandler(void)
Definition: iptvchannel.cpp:120
HTTPTSStreamHandler
Definition: httptsstreamhandler.h:18
MPEGStreamData
Encapsulates data about MPEG stream and emits events for each table.
Definition: mpegstreamdata.h:85
IPTVTuningData
Definition: iptvtuningdata.h:21
IPTVStreamHandler::Get
static IPTVStreamHandler * Get(const IPTVTuningData &tuning, int inputid)
Definition: iptvstreamhandler.cpp:36
IPTVChannel::m_firstTune
volatile bool m_firstTune
Definition: iptvchannel.h:65
HLSStreamHandler::Get
static HLSStreamHandler * Get(const IPTVTuningData &tuning, int inputid)
Definition: hlsstreamhandler.cpp:26
IPTVChannel::IsOpen
bool IsOpen(void) const override
Reports whether channel is already open.
Definition: iptvchannel.cpp:154
HTTPTSStreamHandler::Get
static HTTPTSStreamHandler * Get(const IPTVTuningData &tuning, int inputid)
Definition: httptsstreamhandler.cpp:18
IPTVChannel::SetStreamData
void SetStreamData(MPEGStreamData *sd)
Definition: iptvchannel.cpp:61
IPTVTuningData::IsHLS
bool IsHLS() const
Definition: iptvtuningdata.h:198
iptvchannel.h
HLSStreamHandler::Return
static void Return(HLSStreamHandler *&ref, int inputid)
Definition: hlsstreamhandler.cpp:58
hlsstreamhandler.h
httptsstreamhandler.h
IPTVChannel::Close
void Close(void) override
Closes the channel changing hardware to use.
Definition: iptvchannel.cpp:89
IPTVChannel::IPTVChannel
IPTVChannel(TVRec *rec, QString videodev)
Definition: iptvchannel.cpp:28
IPTVChannel::m_streamLock
QMutex m_streamLock
Definition: iptvchannel.h:67
IPTVChannel::m_lastTuning
IPTVTuningData m_lastTuning
Definition: iptvchannel.h:66
std
Definition: mythchrono.h:23
TVRec
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:144
HTTPTSStreamHandler::Return
static void Return(HTTPTSStreamHandler *&ref, int inputid)
Definition: httptsstreamhandler.cpp:51
ChannelBase::GetInputID
virtual int GetInputID(void) const
Definition: channelbase.h:67
IPTVTuningData::IsValid
bool IsValid(void) const
Definition: iptvtuningdata.h:172
iptvrecorder.h
DTVChannel
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:33
IPTVChannel::Open
bool Open(void) override
Opens the channel changing hardware for use.
Definition: iptvchannel.cpp:40
iptvstreamhandler.h
IPTVChannel::m_tuneLock
QMutex m_tuneLock
Definition: iptvchannel.h:64
StreamHandler::IsRunning
bool IsRunning(void) const
Definition: streamhandler.cpp:163
ChannelBase::InitializeInput
virtual bool InitializeInput(void)
Fills in input map from DB.
Definition: channelbase.cpp:550
IPTVChannel::Tune
bool Tune(const IPTVTuningData &tuning, bool scanning) override
Performs IPTV Tuning. Only implemented by IPTVChannel.
Definition: iptvchannel.cpp:165