Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit bac6cd7ac0c2f0f87f7953d4c4c49cfcc0d8d704 1 parent fd72879
Mark Kendall authored
View
9 mythtv/libs/libmythtv/avformatdecoder.cpp
@@ -3398,11 +3398,10 @@ bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)
.arg(subtitle.start_display_time)
.arg(subtitle.end_display_time));
- if (m_parent->GetSubReader(pkt->stream_index)->AddAVSubtitle(
- subtitle, curstream->codec->codec_id == CODEC_ID_XSUB))
- {
- m_parent->EnableForcedSubtitles();
- }
+ bool forcedon = m_parent->GetSubReader(pkt->stream_index)->AddAVSubtitle(
+ subtitle, curstream->codec->codec_id == CODEC_ID_XSUB,
+ m_parent->GetAllowForcedSubtitles());
+ m_parent->EnableForcedSubtitles(forcedon);
}
return true;
View
42 mythtv/libs/libmythtv/mythplayer.cpp
@@ -167,7 +167,8 @@ MythPlayer::MythPlayer(bool muted)
ttPageNum(0x888),
// Support for captions, teletext, etc. decoded by libav
textDesired(false), enableCaptions(false), disableCaptions(false),
- enableForcedSubtitles(false), allowForcedSubtitles(true),
+ enableForcedSubtitles(false), disableForcedSubtitles(false),
+ allowForcedSubtitles(true),
// CC608/708
db_prefer708(true), cc608(this), cc708(this),
// MHEG/MHI Interactive TV visible in OSD
@@ -227,6 +228,7 @@ MythPlayer::MythPlayer(bool muted)
endExitPrompt = gCoreContext->GetNumSetting("EndOfRecordingExitPrompt");
pip_default_loc = (PIPLocation)gCoreContext->GetNumSetting("PIPLocation", kPIPTopLeft);
tc_wrap[TC_AUDIO] = gCoreContext->GetNumSetting("AudioSyncOffset", 0);
+ allowForcedSubtitles = gCoreContext->GetNumSetting("AllowForcedSubtitles", 1);
// Get VBI page number
QString mypage = gCoreContext->GetSetting("VBIpageNr", "888");
@@ -1537,6 +1539,38 @@ void MythPlayer::EnableSubtitles(bool enable)
disableCaptions = true;
}
+void MythPlayer::EnableForcedSubtitles(bool enable)
+{
+ if (enable)
+ enableForcedSubtitles = true;
+ else
+ disableForcedSubtitles = true;
+}
+
+void MythPlayer::SetAllowForcedSubtitles(bool allow)
+{
+ bool old = allowForcedSubtitles;
+ allowForcedSubtitles = allow;
+ SetOSDMessage(allowForcedSubtitles ?
+ QObject::tr("Forced Subtitles On") :
+ QObject::tr("Forced Subtitles Off"),
+ kOSDTimeout_Med);
+ if (old != allowForcedSubtitles)
+ {
+ gCoreContext->SaveSetting("AllowForcedSubtitles",
+ allowForcedSubtitles);
+ }
+}
+
+void MythPlayer::DoDisableForcedSubtitles(void)
+{
+ disableForcedSubtitles = false;
+ osdLock.lock();
+ if (osd)
+ osd->DisableForcedSubtitles();
+ osdLock.unlock();
+}
+
void MythPlayer::DoEnableForcedSubtitles(void)
{
enableForcedSubtitles = false;
@@ -1545,7 +1579,7 @@ void MythPlayer::DoEnableForcedSubtitles(void)
osdLock.lock();
if (osd)
- osd->InitSubtitles();
+ osd->EnableSubtitles(kDisplayAVSubtitle, true /*forced only*/);
osdLock.unlock();
}
@@ -2616,9 +2650,11 @@ void MythPlayer::EventLoop(void)
if (disableCaptions)
SetCaptionsEnabled(false, false);
- // enable forced subtitles if signalled by the decoder
+ // enable/disable forced subtitles if signalled by the decoder
if (enableForcedSubtitles)
DoEnableForcedSubtitles();
+ if (disableForcedSubtitles)
+ DoDisableForcedSubtitles();
// reset the scan (and hence deinterlacers) if triggered by the decoder
if (resetScan != kScan_Ignore)
View
6 mythtv/libs/libmythtv/mythplayer.h
@@ -258,7 +258,9 @@ class MTV_PUBLIC MythPlayer
// Public Audio/Subtitle/EIA-608/EIA-708 stream selection - thread safe
void TracksChanged(uint trackType);
void EnableSubtitles(bool enable);
- void EnableForcedSubtitles(void) { enableForcedSubtitles = true; }
+ void EnableForcedSubtitles(bool enable);
+ void SetAllowForcedSubtitles(bool allow);
+ bool GetAllowForcedSubtitles(void) { return allowForcedSubtitles; }
// Public MHEG/MHI stream selection
bool SetAudioByComponentTag(int tag);
@@ -442,6 +444,7 @@ class MTV_PUBLIC MythPlayer
int ChangeTrack(uint type, int dir);
void ChangeCaptionTrack(int dir);
int NextCaptionTrack(int mode);
+ void DoDisableForcedSubtitles(void);
void DoEnableForcedSubtitles(void);
// Teletext Menu and non-NUV teletext decoder
@@ -656,6 +659,7 @@ class MTV_PUBLIC MythPlayer
bool enableCaptions;
bool disableCaptions;
bool enableForcedSubtitles;
+ bool disableForcedSubtitles;
bool allowForcedSubtitles;
// CC608/708
View
13 mythtv/libs/libmythtv/osd.cpp
@@ -1150,11 +1150,20 @@ SubtitleScreen* OSD::InitSubtitles(void)
return sub;
}
-void OSD::EnableSubtitles(int type)
+void OSD::EnableSubtitles(int type, bool forced_only)
{
SubtitleScreen *sub = InitSubtitles();
if (sub)
- sub->EnableSubtitles(type);
+ sub->EnableSubtitles(type, forced_only);
+}
+
+void OSD::DisableForcedSubtitles(void)
+{
+ if (!HasWindow(OSD_WIN_SUBTITLE))
+ return;
+
+ SubtitleScreen *sub = InitSubtitles();
+ sub->DisableForcedSubtitles();
}
void OSD::ClearSubtitles(void)
View
3  mythtv/libs/libmythtv/osd.h
@@ -177,7 +177,8 @@ class OSD
void TeletextClear(void);
SubtitleScreen* InitSubtitles(void);
- void EnableSubtitles(int type);
+ void EnableSubtitles(int type, bool forced_only = false);
+ void DisableForcedSubtitles(void);
void ClearSubtitles(void);
void DisplayDVDButton(AVSubtitle* dvdButton, QRect &pos);
View
17 mythtv/libs/libmythtv/subtitlereader.cpp
@@ -30,7 +30,8 @@ void SubtitleReader::EnableRawTextSubtitles(bool enable)
}
bool SubtitleReader::AddAVSubtitle(const AVSubtitle &subtitle,
- bool fix_position)
+ bool fix_position,
+ bool allow_forced)
{
bool enableforced = false;
if (!m_AVSubtitlesEnabled && !subtitle.forced)
@@ -40,7 +41,18 @@ bool SubtitleReader::AddAVSubtitle(const AVSubtitle &subtitle,
}
if (!m_AVSubtitlesEnabled && subtitle.forced)
+ {
+ if (!allow_forced)
+ {
+ LOG(VB_PLAYBACK, LOG_INFO,
+ "SubtitleReader: Ignoring forced AV subtitle.");
+ FreeAVSubtitle(subtitle);
+ return enableforced;
+ }
+ LOG(VB_PLAYBACK, LOG_INFO,
+ "SubtitleReader: Allowing forced AV subtitle.");
enableforced = true;
+ }
bool clearsubs = false;
m_AVSubtitles.lock.lock();
@@ -50,7 +62,8 @@ bool SubtitleReader::AddAVSubtitle(const AVSubtitle &subtitle,
// manually clearing the subtitles
if (m_AVSubtitles.buffers.size() > 20)
{
- LOG(VB_GENERAL, LOG_ERR, ">20 AVSubtitles queued - clearing.");
+ LOG(VB_GENERAL, LOG_ERR,
+ "SubtitleReader: >20 AVSubtitles queued - clearing.");
clearsubs = true;
}
m_AVSubtitles.lock.unlock();
View
3  mythtv/libs/libmythtv/subtitlereader.h
@@ -38,7 +38,8 @@ class SubtitleReader
void EnableRawTextSubtitles(bool enable);
AVSubtitles* GetAVSubtitles(void) { return &m_AVSubtitles; }
- bool AddAVSubtitle(const AVSubtitle& subtitle, bool fix_position);
+ bool AddAVSubtitle(const AVSubtitle& subtitle, bool fix_position,
+ bool allow_forced);
void ClearAVSubtitles(void);
void FreeAVSubtitle(const AVSubtitle &sub);
View
24 mythtv/libs/libmythtv/subtitlescreen.cpp
@@ -48,8 +48,15 @@ SubtitleScreen::~SubtitleScreen(void)
#endif
}
-void SubtitleScreen::EnableSubtitles(int type)
+void SubtitleScreen::EnableSubtitles(int type, bool forced_only)
{
+ if (forced_only)
+ {
+ SetVisible(true);
+ SetArea(MythRect());
+ return;
+ }
+
m_subtitleType = type;
if (m_subreader)
{
@@ -66,6 +73,15 @@ void SubtitleScreen::EnableSubtitles(int type)
SetArea(MythRect());
}
+void SubtitleScreen::DisableForcedSubtitles(void)
+{
+ if (kDisplayNone != m_subtitleType)
+ return;
+ ClearAllSubtitles();
+ SetVisible(false);
+ SetArea(MythRect());
+}
+
bool SubtitleScreen::Create(void)
{
if (!m_player)
@@ -302,10 +318,12 @@ void SubtitleScreen::DisplayAVSubtitles(void)
if (uiimage)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC +
- QString("Display AV sub for %1 ms").arg(displayfor));
+ QString("Display %1AV subtitle for %2ms")
+ .arg(subtitle.forced ? "FORCED " : "")
+ .arg(displayfor));
if (late > 50)
LOG(VB_PLAYBACK, LOG_INFO, LOC +
- QString("AV Sub was %1 ms late").arg(late));
+ QString("AV Sub was %1ms late").arg(late));
}
}
#ifdef USING_LIBASS
View
3  mythtv/libs/libmythtv/subtitlescreen.h
@@ -22,7 +22,8 @@ class SubtitleScreen : public MythScreenType
SubtitleScreen(MythPlayer *player, const char * name, int fontStretch);
virtual ~SubtitleScreen();
- void EnableSubtitles(int type);
+ void EnableSubtitles(int type, bool forced_only = false);
+ void DisableForcedSubtitles(void);
int EnabledSubtitleType(void) { return m_subtitleType; }
void ClearAllSubtitles(void);
View
3  mythtv/libs/libmythtv/tv_actions.h
@@ -43,6 +43,9 @@
#define ACTION_EXITSHOWNOPROMPTS "EXITSHOWNOPROMPTS"
+#define ACTION_ENABLEFORCEDSUBS "ENABLEFORCEDSUBS"
+#define ACTION_DISABLEFORCEDSUBS "DISABLEFORCEDSUBS"
+
/* Interactive Television keys */
#define ACTION_MENURED "MENURED"
#define ACTION_MENUGREEN "MENUGREEN"
View
22 mythtv/libs/libmythtv/tv_play.cpp
@@ -3262,6 +3262,16 @@ bool TV::HandleTrackAction(PlayerContext *ctx, const QString &action)
handled = true;
ctx->player->ToggleCaptions(kTrackTypeTextSubtitle);
}
+ else if (ACTION_ENABLEFORCEDSUBS == action)
+ {
+ handled = true;
+ ctx->player->SetAllowForcedSubtitles(true);
+ }
+ else if (ACTION_DISABLEFORCEDSUBS == action)
+ {
+ handled = true;
+ ctx->player->SetAllowForcedSubtitles(false);
+ }
else if (action == "TOGGLECC" && !browsehelper->IsBrowsing())
{
handled = true;
@@ -10149,11 +10159,13 @@ void TV::FillOSDMenuSubtitles(const PlayerContext *ctx, OSD *osd,
uint ttx_curtrack = ~0;
uint text_curtrack = ~0;
bool havetext = false;
+ bool forcedon = true;
ctx->LockDeletePlayer(__FILE__, __LINE__);
if (ctx->player)
{
// capmode = ctx->player->GetCaptionMode();
havetext = ctx->player->HasTextSubtitles();
+ forcedon = ctx->player->GetAllowForcedSubtitles();
av_tracks = ctx->player->GetTracks(kTrackTypeSubtitle);
cc708_tracks = ctx->player->GetTracks(kTrackTypeCC708);
cc608_tracks = ctx->player->GetTracks(kTrackTypeCC608);
@@ -10195,6 +10207,16 @@ void TV::FillOSDMenuSubtitles(const PlayerContext *ctx, OSD *osd,
osd->DialogAddButton(tr("Toggle Subtitles"), "TOGGLECC");
if (!av_tracks.empty())
{
+ if (forcedon)
+ {
+ osd->DialogAddButton(tr("Disable Forced Subtitles"),
+ ACTION_DISABLEFORCEDSUBS);
+ }
+ else
+ {
+ osd->DialogAddButton(tr("Enable Forced Subtitles"),
+ ACTION_ENABLEFORCEDSUBS);
+ }
osd->DialogAddButton(tr("Select Subtitle"),
"DIALOG_MENU_AVSUBTITLES_0",
true, selected == "AVSUBTITLES");
Please sign in to comment.
Something went wrong with that request. Please try again.