[vlc-commits] [Git][videolan/vlc][master] 8 commits: input: simplify slave auto selection

Jean-Baptiste Kempf gitlab at videolan.org
Wed May 12 07:44:08 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
df0a1b2f by Thomas Guillem at 2021-05-12T07:27:13+00:00
input: simplify slave auto selection

No need to store the forced state per category as the es_out won't
select track over the previous one.

- - - - -
1e03d1bd by Thomas Guillem at 2021-05-12T07:27:13+00:00
input: remove category handling when loading a slave

Since it's not used anymore.

- - - - -
f994a4b8 by Thomas Guillem at 2021-05-12T07:27:13+00:00
input: rename SLAVE_TYPE_AUDIO to SLAVE_TYPE_GENERIC

Indeed, video slaves are also valid.

- - - - -
e8a5f3e0 by Thomas Guillem at 2021-05-12T07:27:13+00:00
player: restore associated video loading

vlc_player_AddAssociatedMedia() was only accepting audio and spu.

- - - - -
872d9655 by Thomas Guillem at 2021-05-12T07:27:13+00:00
player: fix osd messages

- - - - -
91f51e02 by Thomas Guillem at 2021-05-12T07:27:13+00:00
libvlc: rename libvlc_media_slave_type audio to generic

- - - - -
55e5f204 by Thomas Guillem at 2021-05-12T07:27:13+00:00
input: simplify forced slave handling

We can add more than one forced slave, the es_out will only select the
first one (or all, depending on the es out mode option).

- - - - -
3fca93ef by Thomas Guillem at 2021-05-12T07:27:13+00:00
input: auto select all (perfectly) matched slaves

Historically, only local slaves or one added via the "input-slave" are
automatically selected. This commit adds autoselection for slaves found
by a network directory demuxer. To avoid false positives, only perfectly
matched slaves are auto-selected.

There is still a difference between local and network slaves:
 - Any matched local slaves will be auto-selected
 - Only perfectly matched network slaves will be auto-selected

Fixes #25673

- - - - -


12 changed files:

- include/vlc/libvlc_media.h
- include/vlc_input_item.h
- include/vlc_player.h
- lib/media.c
- modules/misc/medialibrary/fs/directory.cpp
- modules/services_discovery/upnp.cpp
- src/input/es_out.c
- src/input/input.c
- src/input/input_internal.h
- src/input/item.c
- src/player/player.c
- test/libvlc/slaves.c


Changes:

=====================================
include/vlc/libvlc_media.h
=====================================
@@ -196,7 +196,8 @@ typedef enum libvlc_media_parsed_status_t
 typedef enum libvlc_media_slave_type_t
 {
     libvlc_media_slave_type_subtitle,
-    libvlc_media_slave_type_audio,
+    libvlc_media_slave_type_generic,
+    libvlc_media_slave_type_audio = libvlc_media_slave_type_generic,
 } libvlc_media_slave_type_t;
 
 /**


=====================================
include/vlc_input_item.h
=====================================
@@ -142,7 +142,7 @@ enum input_item_net_type
 enum slave_type
 {
     SLAVE_TYPE_SPU,
-    SLAVE_TYPE_AUDIO,
+    SLAVE_TYPE_GENERIC, /* audio, video or subtitle not matched in SLAVE_SPU_EXTENSIONS */
 };
 
 enum slave_priority


=====================================
include/vlc_player.h
=====================================
@@ -879,7 +879,7 @@ vlc_player_ToggleRecording(vlc_player_t *player)
  * Add an associated (or external) media to the current media
  *
  * @param player locked player instance
- * @param cat AUDIO_ES or SPU_ES
+ * @param cat SPU_ES or UNKNOWN_ES
  * @param uri absolute uri of the external media
  * @param select true to select the track of this external media
  * @param notify true to notify the OSD


=====================================
lib/media.c
=====================================
@@ -1218,8 +1218,8 @@ int libvlc_media_slaves_add( libvlc_media_t *p_md,
     case libvlc_media_slave_type_subtitle:
         i_input_slave_type = SLAVE_TYPE_SPU;
         break;
-    case libvlc_media_slave_type_audio:
-        i_input_slave_type = SLAVE_TYPE_AUDIO;
+    case libvlc_media_slave_type_generic:
+        i_input_slave_type = SLAVE_TYPE_GENERIC;
         break;
     default:
         vlc_assert_unreachable();
@@ -1308,8 +1308,8 @@ unsigned int libvlc_media_slaves_get( libvlc_media_t *p_md,
         case SLAVE_TYPE_SPU:
             p_slave->i_type = libvlc_media_slave_type_subtitle;
             break;
-        case SLAVE_TYPE_AUDIO:
-            p_slave->i_type = libvlc_media_slave_type_audio;
+        case SLAVE_TYPE_GENERIC:
+            p_slave->i_type = libvlc_media_slave_type_generic;
             break;
         default:
             vlc_assert_unreachable();


=====================================
modules/misc/medialibrary/fs/directory.cpp
=====================================
@@ -221,7 +221,7 @@ SDDirectory::read() const
             for ( auto i = 0; i < m->i_slaves; ++i )
             {
                 const auto* slave = m->pp_slaves[i];
-                const auto linked_type = slave->i_type == SLAVE_TYPE_AUDIO
+                const auto linked_type = slave->i_type == SLAVE_TYPE_GENERIC
                                              ? IFile::LinkedFileType::SoundTrack
                                              : IFile::LinkedFileType::Subtitles;
 


=====================================
modules/services_discovery/upnp.cpp
=====================================
@@ -1139,7 +1139,7 @@ bool MediaServer::addItem( IXML_Element* itemElement )
             }
             else
                 holder.addSlave(xml_getChildElementValue( p_resource, "res" ),
-                                SLAVE_TYPE_AUDIO);
+                                SLAVE_TYPE_GENERIC);
         }
     }
     ixmlNodeList_free( p_resource_list );


=====================================
src/input/es_out.c
=====================================
@@ -2579,7 +2579,7 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
     }
 
     bool b_auto_selected = p_esprops->b_autoselect
-        || input_source_IsCatAutoselected( es->id.source, es->fmt.i_cat );
+        || input_source_IsAutoSelected( es->id.source );
     bool b_auto_unselect = p_sys->i_mode == ES_OUT_MODE_AUTO &&
                            policy == ES_OUT_ES_POLICY_EXCLUSIVE &&
                            p_esprops->p_main_es && p_esprops->p_main_es != es;


=====================================
src/input/input.c
=====================================
@@ -1043,7 +1043,7 @@ static void GetVarSlaves( input_thread_t *p_input,
             msg_Warn( p_input,
                      "Can't deduce slave type of `%s\" with file extension.",
                      uri );
-            i_type = SLAVE_TYPE_AUDIO;
+            i_type = SLAVE_TYPE_GENERIC;
         }
         input_item_slave_t *p_slave =
             input_item_slave_New( uri, i_type, SLAVE_PRIORITY_USER );
@@ -1137,13 +1137,12 @@ static void LoadSlaves( input_thread_t *p_input )
     TAB_CLEAN( p_item->i_slaves, p_item->pp_slaves );
     vlc_mutex_unlock( &p_item->lock );
 
-    if( i_slaves > 0 )
+    if( i_slaves > 0 ) /* Sort by priority */
         qsort( pp_slaves, i_slaves, sizeof (input_item_slave_t*),
                SlaveCompare );
 
     /* add all detected slaves */
-    bool p_forced[2] = { false, false };
-    static_assert( SLAVE_TYPE_AUDIO <= 1 && SLAVE_TYPE_SPU <= 1,
+    static_assert( SLAVE_TYPE_GENERIC <= 1 && SLAVE_TYPE_SPU <= 1,
                    "slave type size mismatch");
     for( int i = 0; i < i_slaves && pp_slaves[i] != NULL; i++ )
     {
@@ -1151,24 +1150,15 @@ static void LoadSlaves( input_thread_t *p_input )
         /* Slaves added via options should not fail */
         unsigned i_flags = p_slave->i_priority != SLAVE_PRIORITY_USER
                            ? SLAVE_ADD_CANFAIL : SLAVE_ADD_NOFLAG;
-        bool b_forced = false;
 
         /* Force the first subtitle with the highest priority or with the
          * forced flag */
-        if( !p_forced[p_slave->i_type]
-         && ( p_slave->b_forced || p_slave->i_priority == SLAVE_PRIORITY_USER ) )
-        {
+        if ( p_slave->b_forced || p_slave->i_priority >= SLAVE_PRIORITY_MATCH_ALL )
             i_flags |= SLAVE_ADD_FORCED;
-            b_forced = true;
-        }
 
         if( input_SlaveSourceAdd( p_input, p_slave->i_type, p_slave->psz_uri,
                                   i_flags ) == VLC_SUCCESS )
-        {
             input_item_AddSlave( input_priv(p_input)->p_item, p_slave );
-            if( b_forced )
-                p_forced[p_slave->i_type] = true;
-        }
         else
             input_item_slave_Delete( p_slave );
     }
@@ -1204,10 +1194,8 @@ static void LoadSlaves( input_thread_t *p_input )
 
             /* Force the first subtitle from attachment if there is no
              * subtitles already forced */
-            if( input_SlaveSourceAdd( p_input, SLAVE_TYPE_SPU, psz_mrl,
-                                      p_forced[ SLAVE_TYPE_SPU ] ?
-                                      SLAVE_ADD_NOFLAG : SLAVE_ADD_FORCED ) == VLC_SUCCESS )
-                p_forced[ SLAVE_TYPE_SPU ] = true;
+            input_SlaveSourceAdd( p_input, SLAVE_TYPE_SPU, psz_mrl,
+                                  SLAVE_ADD_FORCED );
 
             free( psz_mrl );
             /* Don't update item slaves for attachements */
@@ -2870,10 +2858,9 @@ int input_source_GetNewAutoId( input_source_t *in )
     return in->auto_id++;
 }
 
-bool input_source_IsCatAutoselected( input_source_t *in,
-                                     enum es_format_category_e cat )
+bool input_source_IsAutoSelected( input_source_t *in )
 {
-    return in->autoselect_cats[cat];
+    return in->autoselected;
 }
 
 /*****************************************************************************
@@ -3407,31 +3394,28 @@ static int input_SlaveSourceAdd( input_thread_t *p_input,
     const bool b_can_fail = i_flags & SLAVE_ADD_CANFAIL;
     const bool b_forced = i_flags & SLAVE_ADD_FORCED;
     const bool b_set_time = i_flags & SLAVE_ADD_SET_TIME;
-    enum es_format_category_e i_cat;
 
     switch( i_type )
     {
     case SLAVE_TYPE_SPU:
         psz_forced_demux = "subtitle";
-        i_cat = SPU_ES;
         break;
-    case SLAVE_TYPE_AUDIO:
+    case SLAVE_TYPE_GENERIC:
         psz_forced_demux = NULL;
-        i_cat = AUDIO_ES;
         break;
     default:
         vlc_assert_unreachable();
     }
 
     msg_Dbg( p_input, "loading %s slave: %s (forced: %d)",
-             i_cat == SPU_ES ? "spu" : "audio", psz_uri, b_forced );
+             i_type == SLAVE_TYPE_SPU ? "spu" : "generic", psz_uri, b_forced );
 
     input_source_t *p_source = InputSourceNew( psz_uri );
     if( !p_source )
         return VLC_EGENERIC;
 
     if( b_forced )
-        p_source->autoselect_cats[i_cat] = true;
+        p_source->autoselected = true;
 
     int ret = InputSourceInit( p_source, p_input, psz_uri,
                                psz_forced_demux,
@@ -3446,7 +3430,7 @@ static int input_SlaveSourceAdd( input_thread_t *p_input,
         return VLC_EGENERIC;
     }
 
-    if( i_type == SLAVE_TYPE_AUDIO )
+    if( i_type == SLAVE_TYPE_GENERIC )
     {
         if( b_set_time )
         {


=====================================
src/input/input_internal.h
=====================================
@@ -379,7 +379,7 @@ struct input_source_t
 
     char *str_id;
     int auto_id;
-    bool autoselect_cats[ES_CATEGORY_COUNT];
+    bool autoselected;
 
     /* Title infos for that input */
     bool         b_title_demux; /* Titles/Seekpoints provided by demux */
@@ -684,10 +684,9 @@ const char *input_source_GetStrId( input_source_t *in );
 int input_source_GetNewAutoId( input_source_t *in );
 
 /**
- * Returns true if a category should be auto-selected for a given source
+ * Returns true if a given source should be auto-selected
  */
-bool input_source_IsCatAutoselected( input_source_t *in,
-                                     enum es_format_category_e cat );
+bool input_source_IsAutoSelected( input_source_t *in );
 
 /* Bound pts_delay */
 #define INPUT_PTS_DELAY_MAX VLC_TICK_FROM_SEC(60)


=====================================
src/input/item.c
=====================================
@@ -612,7 +612,7 @@ bool input_item_slave_GetType(const char *psz_filename,
         size_t nmemb;
     } p_slave_list[] = {
         { SLAVE_TYPE_SPU, ppsz_sub_exts, ARRAY_SIZE(ppsz_sub_exts) },
-        { SLAVE_TYPE_AUDIO, ppsz_audio_exts, ARRAY_SIZE(ppsz_audio_exts) },
+        { SLAVE_TYPE_GENERIC, ppsz_audio_exts, ARRAY_SIZE(ppsz_audio_exts) },
     };
 
     const char *psz_ext = strrchr(psz_filename, '.');


=====================================
src/player/player.c
=====================================
@@ -1060,14 +1060,12 @@ vlc_player_AddAssociatedMedia(vlc_player_t *player,
     enum slave_type type;
     switch (cat)
     {
-        case AUDIO_ES:
-            type = SLAVE_TYPE_AUDIO;
-            break;
         case SPU_ES:
             type = SLAVE_TYPE_SPU;
             break;
         default:
-            return VLC_EGENERIC;
+            type = SLAVE_TYPE_GENERIC;
+            break;
     }
 
     if (check_ext && type == SLAVE_TYPE_SPU && !subtitles_Filter(uri))
@@ -1089,13 +1087,13 @@ vlc_player_AddAssociatedMedia(vlc_player_t *player,
     {
         switch( type )
         {
-            case SLAVE_TYPE_AUDIO:
+            case SLAVE_TYPE_GENERIC:
                 vlc_player_osd_Message(player, "%s",
-                                       vlc_gettext("Audio track added"));
+                                       vlc_gettext("Slave added"));
                 break;
             case SLAVE_TYPE_SPU:
                 vlc_player_osd_Message(player, "%s",
-                                       vlc_gettext("Subtitle track added"));
+                                       vlc_gettext("Subtitle slave added"));
                 break;
         }
     }


=====================================
test/libvlc/slaves.c
=====================================
@@ -136,7 +136,7 @@ main (void)
     };
 
     libvlc_media_slave_t p_expected_slaves[] = {
-        { NULL, libvlc_media_slave_type_audio, 3 /* all */ },
+        { NULL, libvlc_media_slave_type_generic, 3 /* all */ },
         { NULL, libvlc_media_slave_type_subtitle, 2 /* right */ },
         { NULL, libvlc_media_slave_type_subtitle, 1 /* left */ },
         { NULL, libvlc_media_slave_type_subtitle, 0 /* none */ },



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/749602aff10908bc8d254fcf12d59966950584ae...3fca93ef6e2271806093a260f5b672b14fcaef1f

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/749602aff10908bc8d254fcf12d59966950584ae...3fca93ef6e2271806093a260f5b672b14fcaef1f
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list