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: */
IPTVStreamHandler::Return
static void Return(IPTVStreamHandler *&ref, int inputid)
Definition: iptvstreamhandler.cpp:68
IPTVChannel::m_streamData
MPEGStreamData * m_streamData
Definition: iptvchannel.h:69
IPTVStreamHandler::AddListener
void AddListener(MPEGStreamData *data, bool=false, bool=false, QString output_file=QString()) override
Definition: iptvstreamhandler.h:89
mythdb.h
IPTVChannel::OpenStreamHandler
void OpenStreamHandler(void)
Definition: iptvchannel.cpp:100
IPTVChannel::~IPTVChannel
~IPTVChannel() override
Definition: iptvchannel.cpp:33
StreamHandler::HasError
bool HasError(void) const
Definition: streamhandler.h:64
IPTVChannel::Tune
virtual bool Tune(const DTVMultiplex &tuning)=0
This performs the actual frequency tuning and in some cases input switching.
IPTVChannel::m_streamHandler
IPTVStreamHandler * m_streamHandler
Definition: iptvchannel.h:68
arg
arg(title).arg(filename).arg(doDelete))
IPTVTuningData::GetDataURL
QUrl GetDataURL(void) const
Definition: iptvtuningdata.h:134
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
HLSStreamHandler
Definition: hlsstreamhandler.h:25
StreamHandler::RemoveListener
virtual void RemoveListener(MPEGStreamData *data)
Definition: streamhandler.cpp:78
tmp
static guint32 * tmp
Definition: goom_core.cpp:31
LOC
#define LOC
-*- Mode: c++ -*- IPTVChannel Copyright (c) 2006-2009 Silicondust Engineering Ltd,...
Definition: iptvchannel.cpp:25
mythlogging.h
IPTVChannel::EnterPowerSavingMode
bool EnterPowerSavingMode(void) override
Enters power saving mode if the card supports it.
Definition: iptvchannel.cpp:94
IPTVTuningData::IsHTTPTS
bool IsHTTPTS() const
Definition: iptvtuningdata.h:198
IPTVTuningData::GetDeviceName
QString GetDeviceName(void) const
Definition: iptvtuningdata.h:108
IPTVChannel::CloseStreamHandler
void CloseStreamHandler(void)
Definition: iptvchannel.cpp:119
HTTPTSStreamHandler
Definition: httptsstreamhandler.h:20
MPEGStreamData
Encapsulates data about MPEG stream and emits events for each table.
Definition: mpegstreamdata.h:86
IPTVTuningData
Definition: iptvtuningdata.h:17
IPTVStreamHandler::Get
static IPTVStreamHandler * Get(const IPTVTuningData &tuning, int inputid)
Definition: iptvstreamhandler.cpp:35
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:153
HTTPTSStreamHandler::Get
static HTTPTSStreamHandler * Get(const IPTVTuningData &tuning, int inputid)
Definition: httptsstreamhandler.cpp:18
IPTVChannel::SetStreamData
void SetStreamData(MPEGStreamData *sd)
Definition: iptvchannel.cpp:60
IPTVTuningData::IsHLS
bool IsHLS() const
Definition: iptvtuningdata.h:193
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:88
IPTVChannel::IPTVChannel
IPTVChannel(TVRec *rec, QString videodev)
Definition: iptvchannel.cpp:27
IPTVChannel::m_streamLock
QMutex m_streamLock
Definition: iptvchannel.h:67
IPTVChannel::m_lastTuning
IPTVTuningData m_lastTuning
Definition: iptvchannel.h:66
TVRec
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:143
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:167
iptvrecorder.h
DTVChannel
Class providing a generic interface to digital tuning hardware.
Definition: dtvchannel.h:35
IPTVChannel::Open
bool Open(void) override
Opens the channel changing hardware for use.
Definition: iptvchannel.cpp:39
iptvstreamhandler.h
IPTVChannel::m_tuneLock
QMutex m_tuneLock
Definition: iptvchannel.h:64
StreamHandler::IsRunning
bool IsRunning(void) const
Definition: streamhandler.cpp:161
ChannelBase::InitializeInput
virtual bool InitializeInput(void)
Fills in input map from DB.
Definition: channelbase.cpp:547