Skip to content

Commit bac6cd7

Browse files
author
Mark Kendall
committed
Forced Subtitles: Extend and fix forced subtitle support.
- add an OSD menu entry to enable/disable forced subtitles. - the setting is persistent. - ensure forced subs are properly disabled when requested. - extra debugging output. This *should* work as expected for matroska DVD material but there are still issues with automatic track selection in the DVD code that I'm looking at.
1 parent fd72879 commit bac6cd7

File tree

11 files changed

+126
-19
lines changed

11 files changed

+126
-19
lines changed

mythtv/libs/libmythtv/avformatdecoder.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,11 +3398,10 @@ bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)
33983398
.arg(subtitle.start_display_time)
33993399
.arg(subtitle.end_display_time));
34003400

3401-
if (m_parent->GetSubReader(pkt->stream_index)->AddAVSubtitle(
3402-
subtitle, curstream->codec->codec_id == CODEC_ID_XSUB))
3403-
{
3404-
m_parent->EnableForcedSubtitles();
3405-
}
3401+
bool forcedon = m_parent->GetSubReader(pkt->stream_index)->AddAVSubtitle(
3402+
subtitle, curstream->codec->codec_id == CODEC_ID_XSUB,
3403+
m_parent->GetAllowForcedSubtitles());
3404+
m_parent->EnableForcedSubtitles(forcedon);
34063405
}
34073406

34083407
return true;

mythtv/libs/libmythtv/mythplayer.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ MythPlayer::MythPlayer(bool muted)
167167
ttPageNum(0x888),
168168
// Support for captions, teletext, etc. decoded by libav
169169
textDesired(false), enableCaptions(false), disableCaptions(false),
170-
enableForcedSubtitles(false), allowForcedSubtitles(true),
170+
enableForcedSubtitles(false), disableForcedSubtitles(false),
171+
allowForcedSubtitles(true),
171172
// CC608/708
172173
db_prefer708(true), cc608(this), cc708(this),
173174
// MHEG/MHI Interactive TV visible in OSD
@@ -227,6 +228,7 @@ MythPlayer::MythPlayer(bool muted)
227228
endExitPrompt = gCoreContext->GetNumSetting("EndOfRecordingExitPrompt");
228229
pip_default_loc = (PIPLocation)gCoreContext->GetNumSetting("PIPLocation", kPIPTopLeft);
229230
tc_wrap[TC_AUDIO] = gCoreContext->GetNumSetting("AudioSyncOffset", 0);
231+
allowForcedSubtitles = gCoreContext->GetNumSetting("AllowForcedSubtitles", 1);
230232

231233
// Get VBI page number
232234
QString mypage = gCoreContext->GetSetting("VBIpageNr", "888");
@@ -1537,6 +1539,38 @@ void MythPlayer::EnableSubtitles(bool enable)
15371539
disableCaptions = true;
15381540
}
15391541

1542+
void MythPlayer::EnableForcedSubtitles(bool enable)
1543+
{
1544+
if (enable)
1545+
enableForcedSubtitles = true;
1546+
else
1547+
disableForcedSubtitles = true;
1548+
}
1549+
1550+
void MythPlayer::SetAllowForcedSubtitles(bool allow)
1551+
{
1552+
bool old = allowForcedSubtitles;
1553+
allowForcedSubtitles = allow;
1554+
SetOSDMessage(allowForcedSubtitles ?
1555+
QObject::tr("Forced Subtitles On") :
1556+
QObject::tr("Forced Subtitles Off"),
1557+
kOSDTimeout_Med);
1558+
if (old != allowForcedSubtitles)
1559+
{
1560+
gCoreContext->SaveSetting("AllowForcedSubtitles",
1561+
allowForcedSubtitles);
1562+
}
1563+
}
1564+
1565+
void MythPlayer::DoDisableForcedSubtitles(void)
1566+
{
1567+
disableForcedSubtitles = false;
1568+
osdLock.lock();
1569+
if (osd)
1570+
osd->DisableForcedSubtitles();
1571+
osdLock.unlock();
1572+
}
1573+
15401574
void MythPlayer::DoEnableForcedSubtitles(void)
15411575
{
15421576
enableForcedSubtitles = false;
@@ -1545,7 +1579,7 @@ void MythPlayer::DoEnableForcedSubtitles(void)
15451579

15461580
osdLock.lock();
15471581
if (osd)
1548-
osd->InitSubtitles();
1582+
osd->EnableSubtitles(kDisplayAVSubtitle, true /*forced only*/);
15491583
osdLock.unlock();
15501584
}
15511585

@@ -2616,9 +2650,11 @@ void MythPlayer::EventLoop(void)
26162650
if (disableCaptions)
26172651
SetCaptionsEnabled(false, false);
26182652

2619-
// enable forced subtitles if signalled by the decoder
2653+
// enable/disable forced subtitles if signalled by the decoder
26202654
if (enableForcedSubtitles)
26212655
DoEnableForcedSubtitles();
2656+
if (disableForcedSubtitles)
2657+
DoDisableForcedSubtitles();
26222658

26232659
// reset the scan (and hence deinterlacers) if triggered by the decoder
26242660
if (resetScan != kScan_Ignore)

mythtv/libs/libmythtv/mythplayer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ class MTV_PUBLIC MythPlayer
258258
// Public Audio/Subtitle/EIA-608/EIA-708 stream selection - thread safe
259259
void TracksChanged(uint trackType);
260260
void EnableSubtitles(bool enable);
261-
void EnableForcedSubtitles(void) { enableForcedSubtitles = true; }
261+
void EnableForcedSubtitles(bool enable);
262+
void SetAllowForcedSubtitles(bool allow);
263+
bool GetAllowForcedSubtitles(void) { return allowForcedSubtitles; }
262264

263265
// Public MHEG/MHI stream selection
264266
bool SetAudioByComponentTag(int tag);
@@ -442,6 +444,7 @@ class MTV_PUBLIC MythPlayer
442444
int ChangeTrack(uint type, int dir);
443445
void ChangeCaptionTrack(int dir);
444446
int NextCaptionTrack(int mode);
447+
void DoDisableForcedSubtitles(void);
445448
void DoEnableForcedSubtitles(void);
446449

447450
// Teletext Menu and non-NUV teletext decoder
@@ -656,6 +659,7 @@ class MTV_PUBLIC MythPlayer
656659
bool enableCaptions;
657660
bool disableCaptions;
658661
bool enableForcedSubtitles;
662+
bool disableForcedSubtitles;
659663
bool allowForcedSubtitles;
660664

661665
// CC608/708

mythtv/libs/libmythtv/osd.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,11 +1150,20 @@ SubtitleScreen* OSD::InitSubtitles(void)
11501150
return sub;
11511151
}
11521152

1153-
void OSD::EnableSubtitles(int type)
1153+
void OSD::EnableSubtitles(int type, bool forced_only)
11541154
{
11551155
SubtitleScreen *sub = InitSubtitles();
11561156
if (sub)
1157-
sub->EnableSubtitles(type);
1157+
sub->EnableSubtitles(type, forced_only);
1158+
}
1159+
1160+
void OSD::DisableForcedSubtitles(void)
1161+
{
1162+
if (!HasWindow(OSD_WIN_SUBTITLE))
1163+
return;
1164+
1165+
SubtitleScreen *sub = InitSubtitles();
1166+
sub->DisableForcedSubtitles();
11581167
}
11591168

11601169
void OSD::ClearSubtitles(void)

mythtv/libs/libmythtv/osd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ class OSD
177177
void TeletextClear(void);
178178

179179
SubtitleScreen* InitSubtitles(void);
180-
void EnableSubtitles(int type);
180+
void EnableSubtitles(int type, bool forced_only = false);
181+
void DisableForcedSubtitles(void);
181182
void ClearSubtitles(void);
182183
void DisplayDVDButton(AVSubtitle* dvdButton, QRect &pos);
183184

mythtv/libs/libmythtv/subtitlereader.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ void SubtitleReader::EnableRawTextSubtitles(bool enable)
3030
}
3131

3232
bool SubtitleReader::AddAVSubtitle(const AVSubtitle &subtitle,
33-
bool fix_position)
33+
bool fix_position,
34+
bool allow_forced)
3435
{
3536
bool enableforced = false;
3637
if (!m_AVSubtitlesEnabled && !subtitle.forced)
@@ -40,7 +41,18 @@ bool SubtitleReader::AddAVSubtitle(const AVSubtitle &subtitle,
4041
}
4142

4243
if (!m_AVSubtitlesEnabled && subtitle.forced)
44+
{
45+
if (!allow_forced)
46+
{
47+
LOG(VB_PLAYBACK, LOG_INFO,
48+
"SubtitleReader: Ignoring forced AV subtitle.");
49+
FreeAVSubtitle(subtitle);
50+
return enableforced;
51+
}
52+
LOG(VB_PLAYBACK, LOG_INFO,
53+
"SubtitleReader: Allowing forced AV subtitle.");
4354
enableforced = true;
55+
}
4456

4557
bool clearsubs = false;
4658
m_AVSubtitles.lock.lock();
@@ -50,7 +62,8 @@ bool SubtitleReader::AddAVSubtitle(const AVSubtitle &subtitle,
5062
// manually clearing the subtitles
5163
if (m_AVSubtitles.buffers.size() > 20)
5264
{
53-
LOG(VB_GENERAL, LOG_ERR, ">20 AVSubtitles queued - clearing.");
65+
LOG(VB_GENERAL, LOG_ERR,
66+
"SubtitleReader: >20 AVSubtitles queued - clearing.");
5467
clearsubs = true;
5568
}
5669
m_AVSubtitles.lock.unlock();

mythtv/libs/libmythtv/subtitlereader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class SubtitleReader
3838
void EnableRawTextSubtitles(bool enable);
3939

4040
AVSubtitles* GetAVSubtitles(void) { return &m_AVSubtitles; }
41-
bool AddAVSubtitle(const AVSubtitle& subtitle, bool fix_position);
41+
bool AddAVSubtitle(const AVSubtitle& subtitle, bool fix_position,
42+
bool allow_forced);
4243
void ClearAVSubtitles(void);
4344
void FreeAVSubtitle(const AVSubtitle &sub);
4445

mythtv/libs/libmythtv/subtitlescreen.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ SubtitleScreen::~SubtitleScreen(void)
4848
#endif
4949
}
5050

51-
void SubtitleScreen::EnableSubtitles(int type)
51+
void SubtitleScreen::EnableSubtitles(int type, bool forced_only)
5252
{
53+
if (forced_only)
54+
{
55+
SetVisible(true);
56+
SetArea(MythRect());
57+
return;
58+
}
59+
5360
m_subtitleType = type;
5461
if (m_subreader)
5562
{
@@ -66,6 +73,15 @@ void SubtitleScreen::EnableSubtitles(int type)
6673
SetArea(MythRect());
6774
}
6875

76+
void SubtitleScreen::DisableForcedSubtitles(void)
77+
{
78+
if (kDisplayNone != m_subtitleType)
79+
return;
80+
ClearAllSubtitles();
81+
SetVisible(false);
82+
SetArea(MythRect());
83+
}
84+
6985
bool SubtitleScreen::Create(void)
7086
{
7187
if (!m_player)
@@ -302,10 +318,12 @@ void SubtitleScreen::DisplayAVSubtitles(void)
302318
if (uiimage)
303319
{
304320
LOG(VB_PLAYBACK, LOG_INFO, LOC +
305-
QString("Display AV sub for %1 ms").arg(displayfor));
321+
QString("Display %1AV subtitle for %2ms")
322+
.arg(subtitle.forced ? "FORCED " : "")
323+
.arg(displayfor));
306324
if (late > 50)
307325
LOG(VB_PLAYBACK, LOG_INFO, LOC +
308-
QString("AV Sub was %1 ms late").arg(late));
326+
QString("AV Sub was %1ms late").arg(late));
309327
}
310328
}
311329
#ifdef USING_LIBASS

mythtv/libs/libmythtv/subtitlescreen.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class SubtitleScreen : public MythScreenType
2222
SubtitleScreen(MythPlayer *player, const char * name, int fontStretch);
2323
virtual ~SubtitleScreen();
2424

25-
void EnableSubtitles(int type);
25+
void EnableSubtitles(int type, bool forced_only = false);
26+
void DisableForcedSubtitles(void);
2627
int EnabledSubtitleType(void) { return m_subtitleType; }
2728

2829
void ClearAllSubtitles(void);

mythtv/libs/libmythtv/tv_actions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343

4444
#define ACTION_EXITSHOWNOPROMPTS "EXITSHOWNOPROMPTS"
4545

46+
#define ACTION_ENABLEFORCEDSUBS "ENABLEFORCEDSUBS"
47+
#define ACTION_DISABLEFORCEDSUBS "DISABLEFORCEDSUBS"
48+
4649
/* Interactive Television keys */
4750
#define ACTION_MENURED "MENURED"
4851
#define ACTION_MENUGREEN "MENUGREEN"

0 commit comments

Comments
 (0)