- int idx2 = LanguageArrayIndex( p_sys->ppsz_sub_language,
- p_sys->p_es_sub->psz_language_code );
-
- msg_Dbg( p_sys->p_input, "idx1=%d(%s) idx2=%d(%s)",
- idx1, es->psz_language_code, idx2,
- p_sys->p_es_sub->psz_language_code );
-
- if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
- return;
- /* We found a SPU that matches our language request */
- i_wanted = es->i_channel;
+ int es_idx = LanguageArrayIndex( p_sys->ppsz_sub_language,
+ es->psz_language_code );
+ if( !p_sys->p_es_sub )
+ {
+ /* Select the language if it's in the list */
+ if( es_idx >= 0 ||
+ /*FIXME: Should default subtitle not in the list be
+ * displayed if not forbidden by none? */
+ ( p_sys->i_default_sub_id >= 0 &&
+ /* check if the subtitle isn't forbidden by none */
+ LanguageArrayIndex( p_sys->ppsz_sub_language, "none" ) < 0 &&
+ es->i_id == p_sys->i_default_sub_id ) )
+ i_wanted = es->i_channel;
+ }
+ else
+ {
+ int selected_es_idx =
+ LanguageArrayIndex( p_sys->ppsz_sub_language,
+ p_sys->p_es_sub->psz_language_code );
+
+ if( es_idx >= 0 &&
+ ( selected_es_idx < 0 || es_idx < selected_es_idx ||
+ ( es_idx == selected_es_idx &&
+ p_sys->p_es_sub->fmt.i_priority < es->fmt.i_priority ) ) )
+ i_wanted = es->i_channel;
+ }