Skip to content

Commit

Permalink
Attempt to match forced track language to that of the selected main t…
Browse files Browse the repository at this point in the history
…rack
  • Loading branch information
Paul Gardiner committed Jan 15, 2024
1 parent d280f65 commit 7a4fecf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion mythtv/libs/libmythtv/decoders/decoderbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,13 @@ int DecoderBase::SetTrack(uint Type, int TrackNo)
{
m_wantedTrack[Type] = m_tracks[Type][static_cast<size_t>(m_currentTrack[Type])];
m_selectedTrack[Type] = m_tracks[Type][static_cast<size_t>(m_currentTrack[Type])];
if (Type == kTrackTypeSubtitle)
{
// Rechoose the associated forced track, preferring the same language
int forcedTrackIndex = BestTrack(Type, true, m_selectedTrack[Type].m_language);
if (m_tracks[Type][forcedTrackIndex].m_forced)
m_selectedForcedTrack[Type] = m_tracks[Type][forcedTrackIndex];
}
}

return m_currentTrack[Type];
Expand Down Expand Up @@ -1047,11 +1054,14 @@ bool DecoderBase::InsertTrack(uint Type, const StreamInfo &Info)
* Whether to favor or disfavor forced is controlled by the second
* parameter.
*
* A preferredlanguage can be specified as third parameter, which
* will override the user's preferrence list.
*
* This function must not be called without taking m_trackLock
*
* \return the highest weighted track, or -1 if none.
*/
int DecoderBase::BestTrack(uint Type, bool forcedPreferred)
int DecoderBase::BestTrack(uint Type, bool forcedPreferred, int preferredLanguage)
{
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("Trying to select track (w/lang & %1forced)")
.arg(forcedPreferred ? "" : "!"));
Expand All @@ -1068,6 +1078,10 @@ int DecoderBase::BestTrack(uint Type, bool forcedPreferred)
m_tracks[Type][i].m_forced);
int position = static_cast<int>(numStreams) - static_cast<int>(i);
int language = 0;
if (preferredLanguage != 0 && m_tracks[Type][i].m_language == preferredLanguage)
{
language = static_cast<int>(m_languagePreference.size()) + 1;
}
for (uint j = 0; (language == 0) && (j < m_languagePreference.size()); ++j)
{
if (m_tracks[Type][i].m_language == m_languagePreference[j])
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/decoders/decoderbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class DecoderBase
static AVPixelFormat GetBestVideoFormat(AVPixelFormat* Formats, const VideoFrameTypes* RenderFormats);

protected:
int BestTrack(uint Type, bool forcedPreferred);
int BestTrack(uint Type, bool forcedPreferred, int preferredLanguage = 0);
virtual int AutoSelectTrack(uint Type);
void AutoSelectTracks(void);
void ResetTracks(void);
Expand Down

0 comments on commit 7a4fecf

Please sign in to comment.