]> git.sesse.net Git - vlc/blobdiff - src/input/es_out.c
input: delete stream from demux_Delete() (refs #8455)
[vlc] / src / input / es_out.c
index 1a0053dbb878e00beb7d0303d476d3afd7cb86f6..6b0e9ad8aae75f812005ccda3c668eaf229116ae 100644 (file)
@@ -1756,28 +1756,34 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
 
         if( i_cat == AUDIO_ES )
         {
-            int idx1 = LanguageArrayIndex( p_sys->ppsz_audio_language,
-                                     es->psz_language_code );
-
-            if( p_sys->p_es_audio &&
-                p_sys->p_es_audio->fmt.i_priority >= es->fmt.i_priority )
+            if( p_sys->ppsz_audio_language )
             {
-                int idx2 = LanguageArrayIndex( p_sys->ppsz_audio_language,
-                                         p_sys->p_es_audio->psz_language_code );
-
-                if( idx1 < 0 || ( idx2 >= 0 && idx2 <= idx1 ) )
-                    return;
-                i_wanted = es->i_channel;
+                int es_idx = LanguageArrayIndex( p_sys->ppsz_audio_language,
+                                                 es->psz_language_code );
+                if( !p_sys->p_es_audio )
+                {
+                    /* Only select the language if it's in the list */
+                    if( es_idx >= 0 )
+                        i_wanted = es->i_channel;
+                }
+                else
+                {
+                    int selected_es_idx =
+                        LanguageArrayIndex( p_sys->ppsz_audio_language,
+                                            p_sys->p_es_audio->psz_language_code );
+                    if( es_idx >= 0 &&
+                        ( es_idx < selected_es_idx ||
+                          ( es_idx == selected_es_idx &&
+                            p_sys->p_es_audio->fmt.i_priority < es->fmt.i_priority ) ) )
+                        i_wanted = es->i_channel;
+                }
             }
             else
             {
-                /* Select audio if (no audio selected yet)
-                 * - no audio-language
-                 * - no audio code for the ES
-                 * - audio code in the requested list */
-                if( idx1 >= 0 ||
-                    !strcmp( es->psz_language_code, "??" ) ||
-                    !p_sys->ppsz_audio_language )
+                /* Select the first one if there is no selected audio yet 
+                 * then choose by ES priority */
+                if( !p_sys->p_es_audio ||
+                    p_sys->p_es_audio->fmt.i_priority < es->fmt.i_priority )
                     i_wanted = es->i_channel;
             }
 
@@ -1794,34 +1800,44 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
         }
         else if( i_cat == SPU_ES )
         {
-            int idx1 = LanguageArrayIndex( p_sys->ppsz_sub_language,
-                                     es->psz_language_code );
-
-            if( p_sys->p_es_sub &&
-                p_sys->p_es_sub->fmt.i_priority >= es->fmt.i_priority )
-            {
-                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;
-            }
-            else if( idx1 >= 0 )
+            if( p_sys->ppsz_sub_language )
             {
-                msg_Dbg( p_sys->p_input, "idx1=%d(%s)",
-                        idx1, es->psz_language_code );
-
-                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 &&
+                        ( 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;
+                }
             }
-            else if( p_sys->i_default_sub_id >= 0 )
+            else
             {
-                if( es->i_id == p_sys->i_default_sub_id )
+                /* If there is no user preference, select the default subtitle 
+                 * or adapt by ES priority */
+                if( ( !p_sys->p_es_sub &&
+                      ( p_sys->i_default_sub_id >= 0 &&
+                        es->i_id == p_sys->i_default_sub_id ) ) ||
+                    ( p_sys->p_es_sub && 
+                      p_sys->p_es_sub->fmt.i_priority < es->fmt.i_priority ) )
                     i_wanted = es->i_channel;
             }
 
@@ -2015,7 +2031,7 @@ static void EsOutDel( es_out_t *out, es_out_id_t *es )
     /* We don't try to reselect */
     if( es->p_dec )
     {
-        while( !p_sys->p_input->b_die && !p_sys->b_buffering && es->p_dec )
+        while( vlc_object_alive(p_sys->p_input) && !p_sys->b_buffering && es->p_dec )
         {
             if( input_DecoderIsEmpty( es->p_dec ) &&
                 ( !es->p_dec_record || input_DecoderIsEmpty( es->p_dec_record ) ))