Skip to content

Commit

Permalink
Subtitles: Add initial forced subtitle support.
Browse files Browse the repository at this point in the history
This enables forced subtitles when they are part of the current,
automatically selected subtitle stream (i.e. if your language is
English, an English subtitle track is automatically selected in the
existing code. Any forced subtitle detected will now be displayed).

I will add an OSD menu option to toggle forced subtitles.

This will not work for blu ray material where the forced subtitles are
on a different track entirely.

There are still some intermittent issues with DVD material that seem to
be related to the existing code. In these cases the forced subtitles may
no display.
  • Loading branch information
Mark Kendall committed Oct 17, 2011
1 parent 9e0786b commit 4fe1522
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
7 changes: 5 additions & 2 deletions mythtv/libs/libmythtv/avformatdecoder.cpp
Expand Up @@ -3398,8 +3398,11 @@ bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)
.arg(subtitle.start_display_time)
.arg(subtitle.end_display_time));

m_parent->GetSubReader(pkt->stream_index)->AddAVSubtitle(
subtitle, curstream->codec->codec_id == CODEC_ID_XSUB);
if (m_parent->GetSubReader(pkt->stream_index)->AddAVSubtitle(
subtitle, curstream->codec->codec_id == CODEC_ID_XSUB))
{
m_parent->EnableForcedSubtitles();
}
}

return true;
Expand Down
17 changes: 17 additions & 0 deletions mythtv/libs/libmythtv/mythplayer.cpp
Expand Up @@ -167,6 +167,7 @@ MythPlayer::MythPlayer(bool muted)
ttPageNum(0x888),
// Support for captions, teletext, etc. decoded by libav
textDesired(false), enableCaptions(false), disableCaptions(false),
enableForcedSubtitles(false), allowForcedSubtitles(true),
// CC608/708
db_prefer708(true), cc608(this), cc708(this),
// MHEG/MHI Interactive TV visible in OSD
Expand Down Expand Up @@ -1536,6 +1537,18 @@ void MythPlayer::EnableSubtitles(bool enable)
disableCaptions = true;
}

void MythPlayer::DoEnableForcedSubtitles(void)
{
enableForcedSubtitles = false;
if (!allowForcedSubtitles)
return;

osdLock.lock();
if (osd)
osd->InitSubtitles();
osdLock.unlock();
}

int MythPlayer::GetTrack(uint type)
{
if (decoder)
Expand Down Expand Up @@ -2603,6 +2616,10 @@ void MythPlayer::EventLoop(void)
if (disableCaptions)
SetCaptionsEnabled(false, false);

// enable forced subtitles if signalled by the decoder
if (enableForcedSubtitles)
DoEnableForcedSubtitles();

// reset the scan (and hence deinterlacers) if triggered by the decoder
if (resetScan != kScan_Ignore)
SetScanType(resetScan);
Expand Down
4 changes: 4 additions & 0 deletions mythtv/libs/libmythtv/mythplayer.h
Expand Up @@ -258,6 +258,7 @@ 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; }

// Public MHEG/MHI stream selection
bool SetAudioByComponentTag(int tag);
Expand Down Expand Up @@ -441,6 +442,7 @@ class MTV_PUBLIC MythPlayer
int ChangeTrack(uint type, int dir);
void ChangeCaptionTrack(int dir);
int NextCaptionTrack(int mode);
void DoEnableForcedSubtitles(void);

// Teletext Menu and non-NUV teletext decoder
void EnableTeletext(int page = 0x100);
Expand Down Expand Up @@ -653,6 +655,8 @@ class MTV_PUBLIC MythPlayer
bool textDesired;
bool enableCaptions;
bool disableCaptions;
bool enableForcedSubtitles;
bool allowForcedSubtitles;

// CC608/708
bool db_prefer708;
Expand Down
25 changes: 22 additions & 3 deletions mythtv/libs/libmythtv/subtitlereader.cpp
@@ -1,3 +1,4 @@
#include "mythlogging.h"
#include "subtitlereader.h"

SubtitleReader::SubtitleReader()
Expand Down Expand Up @@ -28,18 +29,36 @@ void SubtitleReader::EnableRawTextSubtitles(bool enable)
m_RawTextSubtitlesEnabled = enable;
}

void SubtitleReader::AddAVSubtitle(const AVSubtitle &subtitle,
bool SubtitleReader::AddAVSubtitle(const AVSubtitle &subtitle,
bool fix_position)
{
if (!m_AVSubtitlesEnabled)
bool enableforced = false;
if (!m_AVSubtitlesEnabled && !subtitle.forced)
{
FreeAVSubtitle(subtitle);
return;
return enableforced;
}

if (!m_AVSubtitlesEnabled && subtitle.forced)
enableforced = true;

bool clearsubs = false;
m_AVSubtitles.lock.lock();
m_AVSubtitles.fixPosition = fix_position;
m_AVSubtitles.buffers.push_back(subtitle);
// in case forced subtitles aren't displayed, avoid leaking by
// manually clearing the subtitles
if (m_AVSubtitles.buffers.size() > 20)
{
LOG(VB_GENERAL, LOG_ERR, ">20 AVSubtitles queued - clearing.");
clearsubs = true;
}
m_AVSubtitles.lock.unlock();

if (clearsubs)
ClearAVSubtitles();

return enableforced;
}

void SubtitleReader::ClearAVSubtitles(void)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/subtitlereader.h
Expand Up @@ -38,7 +38,7 @@ class SubtitleReader
void EnableRawTextSubtitles(bool enable);

AVSubtitles* GetAVSubtitles(void) { return &m_AVSubtitles; }
void AddAVSubtitle(const AVSubtitle& subtitle, bool fix_position);
bool AddAVSubtitle(const AVSubtitle& subtitle, bool fix_position);
void ClearAVSubtitles(void);
void FreeAVSubtitle(const AVSubtitle &sub);

Expand Down
7 changes: 4 additions & 3 deletions mythtv/libs/libmythtv/subtitlescreen.cpp
Expand Up @@ -88,9 +88,10 @@ bool SubtitleScreen::Create(void)
void SubtitleScreen::Pulse(void)
{
ExpireSubtitles();
if (kDisplayAVSubtitle == m_subtitleType)
DisplayAVSubtitles();
else if (kDisplayTextSubtitle == m_subtitleType)

DisplayAVSubtitles(); // allow forced subtitles to work

if (kDisplayTextSubtitle == m_subtitleType)
DisplayTextSubtitles();
else if (kDisplayCC608 == m_subtitleType)
DisplayCC608Subtitles();
Expand Down

0 comments on commit 4fe1522

Please sign in to comment.