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