Skip to content
Browse files

Subtitles: Favor forced tracks for auto-track selection. Refs #10808

For first-time auto-track selection, we put highest priority on forced
tracks, second priority on user language preference, and third
priority on track order.

This changes the previous behavior only by adding the forced flag to
the criteria.
  • Loading branch information...
1 parent 6a64891 commit ea554c9cbe5fc86c4a4e301eb9f97fd90abbe7a4 @stichnot stichnot committed Jun 15, 2012
Showing with 27 additions and 17 deletions.
  1. +27 −17 mythtv/libs/libmythtv/decoderbase.cpp
View
44 mythtv/libs/libmythtv/decoderbase.cpp
@@ -977,29 +977,39 @@ int DecoderBase::AutoSelectTrack(uint type)
if (selTrack < 0 && numStreams)
{
- LOG(VB_PLAYBACK, LOG_INFO, LOC + "Trying to select track (w/lang)");
- // Find first track stream that matches a language in
- // order of most preferred to least preferred language.
- vector<int>::iterator it = languagePreference.begin();
- for (; it != languagePreference.end() && (selTrack < 0); ++it)
+ // Select the best track. Primary attribute is to favor a
+ // forced track. Secondary attribute is language preference,
+ // in order of most preferred to least preferred language.
+ // Third attribute is track order, preferring the earliest
+ // track.
+ LOG(VB_PLAYBACK, LOG_INFO,
+ LOC + "Trying to select track (w/lang & forced)");
+ const int kForcedWeight = (1 << 20);
+ const int kLanguageWeight = (1 << 10);
+ const int kPositionWeight = (1 << 0);
+ int bestScore = -1;
+ selTrack = 0;
+ for (uint i = 0; i < numStreams; i++)
{
- for (uint i = 0; i < numStreams; i++)
+ int forced = (tracks[type][i].forced ? 1 : 0);
+ int position = numStreams - i;
+ int language = 0;
+ for (int j = 0; language == 0 && j < languagePreference.size(); ++j)
{
- if (*it == tracks[type][i].language)
- {
- selTrack = i;
- break;
- }
+ if (tracks[type][i].language == languagePreference[j])
+ language = languagePreference.size() - j;
+ }
+ int score = kForcedWeight * forced
+ + kLanguageWeight * language
+ + kPositionWeight * position;
+ if (score > bestScore)
+ {
+ bestScore = score;
+ selTrack = i;
}
}
}
- if (selTrack < 0 && numStreams)
- {
- LOG(VB_PLAYBACK, LOG_INFO, LOC + "Selecting first track");
- selTrack = 0;
- }
-
int oldTrack = currentTrack[type];
currentTrack[type] = (selTrack < 0) ? -1 : selTrack;
StreamInfo tmp = tracks[type][currentTrack[type]];

0 comments on commit ea554c9

Please sign in to comment.
Something went wrong with that request. Please try again.