Skip to content

Commit

Permalink
Handle forced AV subtitles without needing a forced track to be selected
Browse files Browse the repository at this point in the history
This improves the behaviour of mythfrontend in its automatic handling of
forced subtitle tracks. The previous behaviour relied on automatically
selecting the forced track as a default for the user's preference. The new
behaviour attempts to find a non-forced track for the user's preference and
changes the subtitle toggle feature to be between forced and non-forced,
rather than on and off.
  • Loading branch information
Paul Gardiner committed Dec 17, 2023
1 parent 20027e2 commit 36bd127
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3916,6 +3916,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 isForcedTrack = m_selectedTrack[kTrackTypeSubtitle].m_forced;
m_trackLock.unlock();

Expand All @@ -3941,7 +3942,8 @@ bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)
}
}
}
else if (m_decodeAllSubtitles || pkt->stream_index == subIdx)
else if (m_decodeAllSubtitles || pkt->stream_index == subIdx
|| pkt->stream_index == forcedSubIdx)
{
m_avCodecLock.lock();
AVCodecContext *ctx = m_codecMap.GetCodecContext(curstream);
Expand All @@ -3950,6 +3952,9 @@ bool AvFormatDecoder::ProcessSubtitlePacket(AVStream *curstream, AVPacket *pkt)

subtitle.start_display_time += pts;
subtitle.end_display_time += pts;

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

if (gotSubtitles)
Expand Down
18 changes: 18 additions & 0 deletions mythtv/libs/libmythtv/decoders/decoderbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,24 @@ int DecoderBase::AutoSelectTrack(uint Type)
{
// Find best track favoring forced.
selTrack = BestTrack(Type, true);

if (Type == kTrackTypeSubtitle)
{
if (m_tracks[Type][selTrack].m_forced)
{
// A forced AV Subtitle tracks is handled without the user
// explicitly enabling subtitles. Try to find a good non-forced
// track that can be swapped to in the case the user does
// explicitly enable subtitles.
int nonForcedTrack = BestTrack(Type, false);

if (!m_tracks[Type][nonForcedTrack].m_forced)
{
m_selectedForcedSubtitleTrack = m_tracks[Type][selTrack];
selTrack = nonForcedTrack;
}
}
}
}

int oldTrack = m_currentTrack[Type];
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/decoders/decoderbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ class DecoderBase
std::array<sinfo_vec_t,kTrackTypeCount> m_tracks;
std::array<StreamInfo, kTrackTypeCount> m_wantedTrack;
std::array<StreamInfo, kTrackTypeCount> m_selectedTrack;
StreamInfo m_selectedForcedSubtitleTrack;

/// language preferences for auto-selection of streams
std::vector<int> m_languagePreference;
Expand Down

0 comments on commit 36bd127

Please sign in to comment.