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
28IPTVChannel::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
73 {
74 if (sd)
76
77 if (m_streamData)
79 }
80 else if (sd)
81 {
84 }
85
86 m_streamData = sd;
87}
88
90{
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
154bool 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
165bool 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: */
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:34
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:89
IPTVTuningData m_lastTuning
Definition: iptvchannel.h:66
~IPTVChannel() override
Definition: iptvchannel.cpp:34
bool Tune(const IPTVTuningData &tuning, bool scanning) override
Performs IPTV Tuning. Only implemented by IPTVChannel.
IPTVChannel(TVRec *rec, QString videodev)
Definition: iptvchannel.cpp:28
void SetStreamData(MPEGStreamData *sd)
Definition: iptvchannel.cpp:61
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:95
void CloseStreamHandler(void)
IPTVStreamHandler * m_streamHandler
Definition: iptvchannel.h:68
bool Open(void) override
Opens the channel changing hardware for use.
Definition: iptvchannel.cpp:40
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:66
bool IsRunning(void) const
virtual void RemoveListener(MPEGStreamData *data)
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:143
static guint32 * tmp
Definition: goom_core.cpp:26
#define LOC
-*- Mode: c++ -*- IPTVChannel Copyright (c) 2006-2009 Silicondust Engineering Ltd,...
Definition: iptvchannel.cpp:26
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
STL namespace.