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