Browse Source

HbbTV: Support Polish EPG.

Fix possibly crash when clearing profile.
chirpmodem-v8.0.0
Jon Beniston 1 month ago
parent
commit
6a9999f76d
  1. 13
      plugins/channelrx/demoddvb/dvbdemodgui.cpp
  2. 86
      plugins/channelrx/demoddvb/dvbdemodhbbtv.cpp
  3. 2
      plugins/channelrx/demoddvb/dvbdemodhbbtv.h
  4. 5
      plugins/channelrx/demoddvb/hbbtv/oipf.js
  5. 6
      plugins/channelrx/demoddvb/readme.md
  6. 13
      sdrgui/dtv/dtvguideoverlay.cpp
  7. 2
      sdrgui/dtv/dtvguideoverlay.h

13
plugins/channelrx/demoddvb/dvbdemodgui.cpp

@ -908,8 +908,6 @@ void DVBDemodGUI::hbbtvVideoArea(const QRectF& area)
void DVBDemodGUI::hbbtvChannelChange(int networkId, int transportStreamId, int serviceId) void DVBDemodGUI::hbbtvChannelChange(int networkId, int transportStreamId, int serviceId)
{ {
#ifdef DVBDEMOD_HBBTV #ifdef DVBDEMOD_HBBTV
(void) transportStreamId;
if (serviceId == m_playingService) if (serviceId == m_playingService)
{ {
m_hbbtv->channelChangeResult(true); m_hbbtv->channelChangeResult(true);
@ -917,9 +915,16 @@ void DVBDemodGUI::hbbtvChannelChange(int networkId, int transportStreamId, int s
} }
m_hbbtvChannelRequest = serviceId; m_hbbtvChannelRequest = serviceId;
selectService(networkId, serviceId, this, [this](const QString& error) { selectService(networkId, serviceId, this, [this, networkId, transportStreamId, serviceId](const QString& error) {
qDebug("DVBDemodGUI::hbbtvChannelChange: %s", qPrintable(error)); qDebug("DVBDemodGUI::hbbtvChannelChange: %d.%d.%d: %s", networkId, transportStreamId, serviceId, qPrintable(error));
m_hbbtvChannelRequest = 0; m_hbbtvChannelRequest = 0;
// Said over the video for a while, rather than in a message box, which would take the keys from the application
// (as the user's chosen the channel in it) and be hidden by full screen video
const QString text = QString("Can't play the channel the application chose: %1").arg(error);
setStatusText(text);
setStatusToolTip(text);
m_statusMessageTimer.start();
m_videoScreen.load()->setOverlay(text, 5.0);
if (m_hbbtv) { if (m_hbbtv) {
m_hbbtv->channelChangeResult(false); m_hbbtv->channelChangeResult(false);

86
plugins/channelrx/demoddvb/dvbdemodhbbtv.cpp

@ -39,6 +39,7 @@
#endif #endif
#include <QWebEnginePage> #include <QWebEnginePage>
#include <QWebEngineProfile> #include <QWebEngineProfile>
#include <QRegularExpression>
#include <QWebEngineScript> #include <QWebEngineScript>
#include <QWebEngineScriptCollection> #include <QWebEngineScriptCollection>
#include <QWebEngineSettings> #include <QWebEngineSettings>
@ -291,13 +292,24 @@ void DVBDemodHbbTV::releaseProfile()
} }
} }
// The profile's kept until its cache is cleared: deleted while that's in progress (as when no application's running, so
// this is its only user), it corrupts the heap
void DVBDemodHbbTV::clearData() void DVBDemodHbbTV::clearData()
{ {
QWebEngineProfile *profile = acquireProfile(); QWebEngineProfile *profile = acquireProfile();
profile->cookieStore()->deleteAllCookies(); profile->cookieStore()->deleteAllCookies();
profile->clearHttpCache();
profile->clearAllVisitedLinks(); profile->clearAllVisitedLinks();
releaseProfile(); #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
QObject::connect(profile, &QWebEngineProfile::clearHttpCacheCompleted, profile, []() {
// Not in the profile's own signal, as it may be deleted
QTimer::singleShot(0, []() { releaseProfile(); });
}, Qt::SingleShotConnection);
profile->clearHttpCache();
#else
// No signal when it's done: a while later
profile->clearHttpCache();
QTimer::singleShot(10000, []() { releaseProfile(); });
#endif
} }
QWebEngineView *DVBDemodHbbTV::createView(QWidget *parent) QWebEngineView *DVBDemodHbbTV::createView(QWidget *parent)
@ -1154,11 +1166,15 @@ void DVBDemodHbbTV::createApplication(const QString& uri)
} }
} }
// An HbbTV application served as application/vnd.hbbtv.xhtml+xml, which the browser would download rather than show: // A page of the running application served as application/vnd.hbbtv.xhtml+xml, which the browser would download rather
// fetched, and given to it as HTML // than show: fetched, and given to it as HTML. Its first page, or one it goes to, or one it's redirected to (as
// index.php to index.html)
void DVBDemodHbbTV::downloadRequested(const QUrl& url, const QString& mimeType) void DVBDemodHbbTV::downloadRequested(const QUrl& url, const QString& mimeType)
{ {
if (!isRunning() || (url != QUrl(m_appUrl)) || !(mimeType.contains("hbbtv") || mimeType.contains("xhtml") || mimeType.contains("cehtml"))) // Fetched without the interceptor, so the internet's only used if allowed
const bool allowed = m_interceptor->m_networkAllowed || m_server->isServerUrl(url.toString());
if (!isRunning() || !allowed || !(mimeType.contains("hbbtv") || mimeType.contains("xhtml") || mimeType.contains("cehtml")))
{ {
emit log(QString("Download of %1 (%2) refused").arg(url.toString()).arg(mimeType)); emit log(QString("Download of %1 (%2) refused").arg(url.toString()).arg(mimeType));
return; return;
@ -1166,18 +1182,23 @@ void DVBDemodHbbTV::downloadRequested(const QUrl& url, const QString& mimeType)
QNetworkRequest request(url); QNetworkRequest request(url);
request.setHeader(QNetworkRequest::UserAgentHeader, m_profile->httpUserAgent()); request.setHeader(QNetworkRequest::UserAgentHeader, m_profile->httpUserAgent());
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); // Qt 5's default is not to follow them
QNetworkReply *reply = m_network->get(request); QNetworkReply *reply = m_network->get(request);
const QString appUrl = m_appUrl;
connect(reply, &QNetworkReply::finished, this, [this, reply, url]() { connect(reply, &QNetworkReply::finished, this, [this, reply, url, appUrl]() {
reply->deleteLater(); reply->deleteLater();
if ((reply->error() != QNetworkReply::NoError) || !isRunning() || (QUrl(m_appUrl) != url)) if ((reply->error() != QNetworkReply::NoError) || !isRunning() || (m_appUrl != appUrl))
{ {
emit log(QString("Can't load %1: %2").arg(url.toString()).arg(reply->errorString())); emit log(QString("Can't load %1: %2").arg(url.toString()).arg(reply->errorString()));
return; return;
} }
m_page->setContent(reply->readAll(), "text/html", url);
// With oipf.js in it as well: given so, a page's scripts aren't always injected (Qt WebEngine doesn't inject
// them in one given after another, as when the service changes from one application served so to another)
m_page->setContent(withScript(reply->readAll(), scriptSource()), "text/html", url);
}); });
} }
@ -1230,6 +1251,51 @@ QJsonObject DVBDemodHbbTV::configuration() const
return config; return config;
} }
// oipf.js, with the TV's state, as a script: escaped to ASCII (as a page's encoding may not be UTF-8), and without
// </ (so it can be in a page's <script> element)
QString DVBDemodHbbTV::scriptSource() const
{
// Not by arg(): the script has %s of its own
const QString source = "window.__sdrangelHbbTVConfig = " + QString::fromUtf8(QJsonDocument(configuration()).toJson(QJsonDocument::Compact))
+ ";\n" + m_oipfScript;
QString ascii;
ascii.reserve(source.size());
for (const QChar c : source)
{
if (c.unicode() > 0x7e) {
ascii += QString("\\u%1").arg((uint) c.unicode(), 4, 16, QChar('0'));
} else {
ascii += c;
}
}
return ascii.replace("</", "<\\/");
}
// A page with a script as its first: in its head, or after its html element or doctype if it has none
QByteArray DVBDemodHbbTV::withScript(const QByteArray& page, const QString& script)
{
const QByteArray element = "<script>" + script.toLatin1() + "</script>";
const QString text = QString::fromLatin1(page); // Only to find the tags, which are ASCII
int at = -1;
for (const QString& tag : {QString("<head"), QString("<html"), QString("<!doctype")})
{
const QRegularExpressionMatch match = QRegularExpression(tag + "(\\s[^>]*)?>", QRegularExpression::CaseInsensitiveOption).match(text);
if (match.hasMatch())
{
at = match.capturedEnd();
break;
}
}
QByteArray result = page;
result.insert(std::max(0, at), element);
return result;
}
// oipf.js, with the TV's state, in each page before its scripts // oipf.js, with the TV's state, in each page before its scripts
void DVBDemodHbbTV::updateScript() void DVBDemodHbbTV::updateScript()
{ {
@ -1250,8 +1316,6 @@ void DVBDemodHbbTV::updateScript()
script.setInjectionPoint(QWebEngineScript::DocumentCreation); script.setInjectionPoint(QWebEngineScript::DocumentCreation);
script.setWorldId(QWebEngineScript::MainWorld); script.setWorldId(QWebEngineScript::MainWorld);
script.setRunsOnSubFrames(true); script.setRunsOnSubFrames(true);
// Not by arg(): the script has %s of its own script.setSourceCode(scriptSource());
script.setSourceCode("window.__sdrangelHbbTVConfig = " + QString::fromUtf8(QJsonDocument(configuration()).toJson(QJsonDocument::Compact))
+ ";\n" + m_oipfScript);
scripts.insert(script); scripts.insert(script);
} }

2
plugins/channelrx/demoddvb/dvbdemodhbbtv.h

@ -165,6 +165,8 @@ private:
void showView(); void showView();
void loadFinished(bool ok); void loadFinished(bool ok);
void updateScript(); void updateScript();
QString scriptSource() const;
static QByteArray withScript(const QByteArray& page, const QString& script);
void showStatus(); //!< getStatus() in the page, over what the application shows void showStatus(); //!< getStatus() in the page, over what the application shows
void updateProxy(); void updateProxy();
QJsonObject configuration() const; QJsonObject configuration() const;

5
plugins/channelrx/demoddvb/hbbtv/oipf.js

@ -918,14 +918,17 @@
} }
var channel = makeChannel(config.channel); var channel = makeChannel(config.channel);
var requested = videoState(object).pendingChannel;
videoState(object).pendingChannel = null; videoState(object).pendingChannel = null;
if (ok) { if (ok) {
setPlayState(object, PLAYSTATE_PRESENTING); setPlayState(object, PLAYSTATE_PRESENTING);
fire(object, 'ChannelChangeSucceeded', { channel: channel }, [channel]); fire(object, 'ChannelChangeSucceeded', { channel: channel }, [channel]);
} else { } else {
// The channel asked for (OIPF DAE 7.13.1.3), not the one still playing
var failed = requested || channel;
setPlayState(object, PLAYSTATE_UNREALIZED, error); setPlayState(object, PLAYSTATE_UNREALIZED, error);
fire(object, 'ChannelChangeError', { channel: channel, errorState: error }, [channel, error]); fire(object, 'ChannelChangeError', { channel: failed, errorState: error }, [failed, error]);
} }
}); });
} }

6
plugins/channelrx/demoddvb/readme.md

@ -569,3 +569,9 @@ numbers (0 for the default region's).
The standard is 0 for automatic (DVB-T or T2), 1 DVB-T, 2 DVB-T2, 3 DVB-T2-Lite, 4 automatic (DVB-S or S2), 5 DVB-S and 6 DVB-S2. The DVB-S and S2 The standard is 0 for automatic (DVB-T or T2), 1 DVB-T, 2 DVB-T2, 3 DVB-T2-Lite, 4 automatic (DVB-S or S2), 5 DVB-S and 6 DVB-S2. The DVB-S and S2
report adds the symbol rate set and measured, the roll-off, and, for DVB-S2, the MODCOD, pilots, frame size, input stream, Es/N0, and frame, dummy frame report adds the symbol rate set and measured, the roll-off, and, for DVB-S2, the MODCOD, pilots, frame size, input stream, Es/N0, and frame, dummy frame
and header miss counts. and header miss counts.
<h2>Attribution</h2>
The Freesat and Freeview Huffman tables, which decode compressed programme guide text, were generated from freesat_huffman.c of
[tvheadend](https://github.com/tvheadend/tvheadend) (GNU GPL version 3 or later), code originally written for tv_grab_dvb_plus and
integrated into tvheadend by Adam Sutton.

13
sdrgui/dtv/dtvguideoverlay.cpp

@ -806,10 +806,17 @@ bool DTVGuideOverlay::handleMouse(QMouseEvent *event)
// A double-click's second click comes as MouseButtonDblClick, after its first as a press. If that opened or closed // A double-click's second click comes as MouseButtonDblClick, after its first as a press. If that opened or closed
// the guide or ribbon (or played a channel), what the second hits is something else: it's ignored, rather than // the guide or ribbon (or played a channel), what the second hits is something else: it's ignored, rather than
// playing whatever's now under the pointer, or leaving full screen // playing whatever's now under the pointer, or leaving full screen. Only if that press was the double-click's
if (type == QEvent::MouseButtonPress) { // first: the widget may have used it rather than give it here (as to give an HbbTV application the keys), leaving
// the last press here an earlier one
if (type == QEvent::MouseButtonPress)
{
m_pressMode = m_mode; m_pressMode = m_mode;
} else if ((type == QEvent::MouseButtonDblClick) && (m_mode != m_pressMode)) { m_pressTime.start();
}
else if ((type == QEvent::MouseButtonDblClick) && (m_mode != m_pressMode) && m_pressTime.isValid()
&& (m_pressTime.elapsed() <= QGuiApplication::styleHints()->mouseDoubleClickInterval()))
{
return true; return true;
} }

2
sdrgui/dtv/dtvguideoverlay.h

@ -25,6 +25,7 @@
#include <QColor> #include <QColor>
#include <QFont> #include <QFont>
#include <QImage> #include <QImage>
#include <QElapsedTimer>
#include <QRectF> #include <QRectF>
#include <QObject> #include <QObject>
#include <QPointer> #include <QPointer>
@ -187,6 +188,7 @@ private:
QSize m_renderSize; QSize m_renderSize;
QString m_message; //!< Shown on the ribbon or the guide, as why a channel can't be played QString m_message; //!< Shown on the ribbon or the guide, as why a channel can't be played
Mode m_pressMode; //!< Before the last mouse press, to ignore a double-click after one that opened or closed a view Mode m_pressMode; //!< Before the last mouse press, to ignore a double-click after one that opened or closed a view
QElapsedTimer m_pressTime; //!< Since the last mouse press
std::vector<HitArea> m_hits; std::vector<HitArea> m_hits;
static constexpr int m_windowSeconds = 2 * 3600; static constexpr int m_windowSeconds = 2 * 3600;

Loading…
Cancel
Save