Skip to content

Commit

Permalink
Avoid displaying two AV subtitle tracks simultaneously
Browse files Browse the repository at this point in the history
Recent changes to the handling of forced AV subtitle tracks require that
two tracks may be considered for processing simultaneously. This happens
if there is a forced track and a user enabled one. This commit ensures
that the user enabled one inhibits the forced one.
  • Loading branch information
Paul Gardiner committed Dec 17, 2023
1 parent 36bd127 commit 17d0137
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
10 changes: 9 additions & 1 deletion mythtv/libs/libmythtv/captions/subtitlereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ void SubtitleReader::SeekFrame(int64_t ts, int flags)

bool SubtitleReader::AddAVSubtitle(AVSubtitle &subtitle,
bool fix_position,
bool is_selected_forced_track,
bool allow_forced,
bool isExternal)
bool isExternal)
{
bool enableforced = false;
bool forced = false;

if (m_avSubtitlesEnabled && is_selected_forced_track)
{
FreeAVSubtitle(subtitle);
return enableforced;
}

for (unsigned i = 0; i < subtitle.num_rects; i++)
{
forced = forced || static_cast<bool>(subtitle.rects[i]->flags & AV_SUBTITLE_FLAG_FORCED);
Expand Down
3 changes: 2 additions & 1 deletion mythtv/libs/libmythtv/captions/subtitlereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class SubtitleReader : public QObject

AVSubtitles* GetAVSubtitles(void) { return &m_avSubtitles; }
bool AddAVSubtitle(AVSubtitle& subtitle, bool fix_position,
bool allow_forced, bool isExternal);
bool is_selected_forced_track, bool allow_forced,
bool isExternal);
void ClearAVSubtitles(void);
static void FreeAVSubtitle(AVSubtitle &sub);

Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/captions/textsubtitleparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ int TextSubtitleParser::ReadNextSubtitle(void)
sub.start_display_time = av_q2d(m_stream->time_base) * m_pkt->dts * 1000;
sub.end_display_time = av_q2d(m_stream->time_base) * (m_pkt->dts + m_pkt->duration) * 1000;

m_parent->AddAVSubtitle(sub, m_decCtx->codec_id == AV_CODEC_ID_XSUB, false, true);
m_parent->AddAVSubtitle(sub, m_decCtx->codec_id == AV_CODEC_ID_XSUB, false, false, true);
return ret;
}

Expand Down
5 changes: 5 additions & 0 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3917,6 +3917,7 @@ bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)
m_trackLock.lock();
int subIdx = m_selectedTrack[kTrackTypeSubtitle].m_av_stream_index;
int forcedSubIdx = m_selectedForcedSubtitleTrack.m_av_stream_index;
bool isSelectedForcedTrack = false;
bool isForcedTrack = m_selectedTrack[kTrackTypeSubtitle].m_forced;
m_trackLock.unlock();

Expand Down Expand Up @@ -3954,7 +3955,10 @@ bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)
subtitle.end_display_time += pts;

if (pkt->stream_index == forcedSubIdx)
{
isSelectedForcedTrack = true;
isForcedTrack = true;
}
}

if (gotSubtitles)
Expand All @@ -3974,6 +3978,7 @@ bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)

bool forcedon = m_parent->GetSubReader(pkt->stream_index)->AddAVSubtitle(
subtitle, curstream->codecpar->codec_id == AV_CODEC_ID_XSUB,
isSelectedForcedTrack,
m_parent->GetAllowForcedSubtitles(), false);
m_parent->EnableForcedSubtitles(forcedon || isForcedTrack);
}
Expand Down

0 comments on commit 17d0137

Please sign in to comment.