MythTV  master
iptvchannel.cpp
Go to the documentation of this file.
1 
10 // Qt headers
11 #include <QUrl>
12 
13 // MythTV headers
14 #include "iptvstreamhandler.h"
15 #include "httptsstreamhandler.h"
16 #include "hlsstreamhandler.h"
17 #include "iptvrecorder.h"
18 #include "iptvchannel.h"
19 #include "mythlogging.h"
20 #include "mythdb.h"
21 
22 #define LOC QString("IPTVChan[%1]: ").arg(m_inputid)
23 
24 IPTVChannel::IPTVChannel(TVRec *rec, const QString &videodev) :
25  DTVChannel(rec), m_videodev(videodev)
26 {
27  LOG(VB_CHANNEL, LOG_INFO, LOC + "ctor");
28 }
29 
31 {
32  LOG(VB_CHANNEL, LOG_INFO, LOC + "dtor");
34 }
35 
37 {
38  LOG(VB_CHANNEL, LOG_INFO, LOC + "Open()");
39 
40  if (IsOpen())
41  return true;
42 
43  QMutexLocker locker(&m_tune_lock);
44 
45  if (!InitializeInput())
46  {
47  Close();
48  return false;
49  }
50 
51  if (m_stream_data)
53 
54  return true;
55 }
56 
58 {
59  LOG(VB_CHANNEL, LOG_INFO, LOC +
60  QString("SetStreamData(0x%1) StreamHandler(0x%2)")
61  .arg((intptr_t)sd,0,16).arg((intptr_t)m_stream_handler,0,16));
62 
63  QMutexLocker locker(&m_stream_lock);
64 
65  if (m_stream_data == sd && m_stream_handler)
66  return;
67 
68  if (m_stream_handler)
69  {
70  if (sd)
72 
73  if (m_stream_data)
75  }
76  else if (sd)
77  {
80  }
81 
82  m_stream_data = sd;
83 }
84 
86 {
87  if (m_stream_handler)
89 }
90 
92 {
94  return true;
95 }
96 
98 {
99  if (m_last_tuning.IsHLS())
100  {
101  LOG(VB_CHANNEL, LOG_INFO, LOC + "Creating HLSStreamHandler");
103  }
104  else if (m_last_tuning.IsHTTPTS())
105  {
106  LOG(VB_CHANNEL, LOG_INFO, LOC + "Creating HTTPTSStreamHandler");
108  }
109  else
110  {
111  LOG(VB_CHANNEL, LOG_INFO, LOC + "Creating IPTVStreamHandler");
113  }
114 }
115 
117 {
118  LOG(VB_CHANNEL, LOG_INFO, LOC + "CloseStreamHandler()");
119 
120  QMutexLocker locker(&m_stream_lock);
121 
122  if (m_stream_handler)
123  {
124  if (m_stream_data)
125  {
127  m_stream_data = nullptr; //see trac ticket #12773
128  }
129 
130  HLSStreamHandler* hsh = dynamic_cast<HLSStreamHandler*>(m_stream_handler);
131  HTTPTSStreamHandler* httpsh = dynamic_cast<HTTPTSStreamHandler*>(m_stream_handler);
132 
133  if (hsh)
134  {
136  m_stream_handler = hsh;
137  }
138  else if (httpsh)
139  {
141  m_stream_handler = httpsh;
142  }
143  else
144  {
146  }
147  }
148 }
149 
150 bool IPTVChannel::IsOpen(void) const
151 {
152  QMutexLocker locker(&m_stream_lock);
153  bool ret = (m_stream_handler && !m_stream_handler->HasError() &&
155  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("IsOpen(%1) %2")
157  .arg(ret ? "true" : "false"));
158  return ret;
159 }
160 
161 bool IPTVChannel::Tune(const IPTVTuningData &tuning, bool scanning)
162 {
163  QMutexLocker locker(&m_tune_lock);
164 
165  LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Tune(%1)")
166  .arg(tuning.GetDeviceName()));
167 
168  if (tuning.GetDataURL().scheme().toUpper() == "RTSP")
169  {
170  // TODO get RTP info using RTSP
171  }
172 
173  if (!tuning.IsValid())
174  {
175  LOG(VB_CHANNEL, LOG_ERR, LOC + QString("Invalid tuning info %1")
176  .arg(tuning.GetDeviceName()));
177  return false;
178  }
179 
180  if (m_last_tuning == tuning)
181  {
182  LOG(VB_CHANNEL, LOG_DEBUG, LOC + QString("Already tuned to %1")
183  .arg(tuning.GetDeviceName()));
184  return true;
185  }
186 
187  m_last_tuning = tuning;
188 
189  if (!m_firsttune || scanning)
190  // for historical reason, an initial tune is requested at
191  // startup so don't open the stream handler just yet it will
192  // be opened after the next Tune or SetStreamData)
193  {
195 
197  if (tmp)
199  else
201  }
202 
203  m_firsttune = false;
204 
205  LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Tuned to (%1)")
206  .arg(tuning.GetDeviceName()));
207 
208  return true;
209 }
210 
211 /* vim: set expandtab tabstop=4 shiftwidth=4: */
QMutex m_tune_lock
Definition: iptvchannel.h:64
IPTVChannel(TVRec *, const QString &)
Definition: iptvchannel.cpp:24
bool IsValid(void) const
virtual void RemoveListener(MPEGStreamData *data)
#define LOC
-*- Mode: c++ -*- IPTVChannel Copyright (c) 2006-2009 Silicondust Engineering Ltd,...
Definition: iptvchannel.cpp:22
void OpenStreamHandler(void)
Definition: iptvchannel.cpp:97
bool HasError(void) const
Definition: streamhandler.h:64
bool Tune(const IPTVTuningData &, bool scanning) override
Performs IPTV Tuning. Only implemented by IPTVChannel.
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:150
static HTTPTSStreamHandler * Get(const IPTVTuningData &tuning, int inputid)
MPEGStreamData * m_stream_data
Definition: iptvchannel.h:69
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:91
void CloseStreamHandler(void)
QString GetDeviceName(void) const
volatile bool m_firsttune
Definition: iptvchannel.h:65
IPTVStreamHandler * m_stream_handler
Definition: iptvchannel.h:68
bool IsHTTPTS() const
void SetStreamData(MPEGStreamData *)
Definition: iptvchannel.cpp:57
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool Open(void) override
Opens the channel changing hardware for use.
Definition: iptvchannel.cpp:36
void Close(void) override
Closes the channel changing hardware to use.
Definition: iptvchannel.cpp:85
IPTVTuningData m_last_tuning
Definition: iptvchannel.h:66
QMutex m_stream_lock
Definition: iptvchannel.h:67
static void Return(HLSStreamHandler *&ref, int inputid)
virtual int GetInputID(void) const
Definition: channelbase.h:67
static void Return(IPTVStreamHandler *&ref, int inputid)
Encapsulates data about MPEG stream and emits events for each table.
bool IsRunning(void) const
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