[vlc-commits] player: medialib: save track StrIds instead of legacy int

Hugo Beauzée-Luyssen git at videolan.org
Fri Feb 28 20:46:49 CET 2020


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Feb 28 13:32:57 2020 +0100| [008920ff9cbe884bd19b740ffdcee66c5ab8a355] | committer: Thomas Guillem

player: medialib: save track StrIds instead of legacy int

Co-authored-by Thomas Guillem <thomas at gllm.fr>

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=008920ff9cbe884bd19b740ffdcee66c5ab8a355
---

 include/vlc_media_library.h            |  6 +--
 modules/misc/medialibrary/medialib.cpp | 20 ++++-----
 src/misc/medialibrary.c                |  3 ++
 src/player/input.c                     | 53 +----------------------
 src/player/medialib.c                  | 79 ++++++++++++----------------------
 src/player/player.h                    |  3 --
 6 files changed, 44 insertions(+), 120 deletions(-)

diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h
index 55a170db61..fd6dfb4505 100644
--- a/include/vlc_media_library.h
+++ b/include/vlc_media_library.h
@@ -506,9 +506,9 @@ typedef struct vlc_ml_playback_states_all
     float rate;
     float zoom;
     int current_title;
-    int current_video_track;
-    int current_audio_track;
-    int current_subtitle_track;
+    char* current_video_track;
+    char* current_audio_track;
+    char *current_subtitle_track;
     char* aspect_ratio;
     char* crop;
     char* deinterlace;
diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp
index 1b97b1ae38..4ba802c88d 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -1057,7 +1057,7 @@ int MediaLibrary::getMeta( const medialibrary::IMedia& media,
     res->current_title = -1;
     // For tracks, -1 means disabled, so we can't use it for "unset"
     res->current_video_track = res->current_audio_track =
-        res->current_subtitle_track = -2;
+        res->current_subtitle_track = nullptr;
     res->aspect_ratio = res->crop = res->deinterlace =
         res->video_filter = nullptr;
     for ( const auto& meta : metas )
@@ -1077,7 +1077,7 @@ int MediaLibrary::getMeta( const medialibrary::IMedia& media,
                 res->current_title = atoi( meta.second.c_str() );
                 break;
             case medialibrary::IMedia::MetadataType::VideoTrack:
-                res->current_video_track = atoi( meta.second.c_str() );
+                COPY_META( current_video_track );
                 break;
             case medialibrary::IMedia::MetadataType::AspectRatio:
                 COPY_META( aspect_ratio );
@@ -1095,10 +1095,10 @@ int MediaLibrary::getMeta( const medialibrary::IMedia& media,
                 COPY_META( video_filter );
                 break;
             case medialibrary::IMedia::MetadataType::AudioTrack:
-                res->current_audio_track = atoi( meta.second.c_str() );
+                COPY_META( current_audio_track );
                 break;
             case medialibrary::IMedia::MetadataType::SubtitleTrack:
-                res->current_subtitle_track = atoi( meta.second.c_str() );
+                COPY_META( current_subtitle_track );
                 break;
             default:
                 break;
@@ -1141,12 +1141,12 @@ int MediaLibrary::setMeta( medialibrary::IMedia& media,
         metas[MT::Deinterlace] = values->deinterlace;
     if ( values->video_filter != nullptr )
         metas[MT::VideoFilter] = values->video_filter;
-    if ( values->current_video_track != -2 )
-        metas[MT::VideoTrack] = std::to_string( values->current_video_track );
-    if ( values->current_audio_track != -2 )
-        metas[MT::AudioTrack] = std::to_string( values->current_audio_track );
-    if ( values->current_subtitle_track != -2 )
-        metas[MT::SubtitleTrack] = std::to_string( values->current_subtitle_track );
+    if ( values->current_video_track != nullptr )
+        metas[MT::VideoTrack] = values->current_video_track;
+    if ( values->current_audio_track != nullptr )
+        metas[MT::AudioTrack] = values->current_audio_track;
+    if ( values->current_subtitle_track != nullptr )
+        metas[MT::SubtitleTrack] = values->current_subtitle_track;
 
     if ( media.setMetadata( std::move( metas ) ) == false )
         return VLC_EGENERIC;
diff --git a/src/misc/medialibrary.c b/src/misc/medialibrary.c
index 10013c7f20..895f010ae9 100644
--- a/src/misc/medialibrary.c
+++ b/src/misc/medialibrary.c
@@ -339,6 +339,9 @@ void vlc_ml_entry_point_list_release( vlc_ml_entry_point_list_t* p_list )
 
 void vlc_ml_playback_states_all_release( vlc_ml_playback_states_all* prefs )
 {
+    free( prefs->current_video_track );
+    free( prefs->current_audio_track );
+    free( prefs->current_subtitle_track );
     free( prefs->aspect_ratio );
     free( prefs->crop );
     free( prefs->deinterlace );
diff --git a/src/player/input.c b/src/player/input.c
index 59c2d5655e..13616279ab 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -438,35 +438,6 @@ vlc_player_input_HandleEsEvent(struct vlc_player_input *input,
             }
             vlc_player_SendEvent(player, on_track_list_changed,
                                  VLC_PLAYER_LIST_ADDED, &trackpriv->t);
-            switch (ev->fmt->i_cat)
-            {
-                case VIDEO_ES:
-                    /* If we need to restore a specific track, let's do it upon
-                     * insertion. The initialization of the default track when
-                     * we don't have a value will be done when the first track
-                     * gets selected */
-                    if (input->ml.restore_states &&
-                        input->ml.states.current_video_track != -2 &&
-                        input->ml.states.current_video_track == ev->fmt->i_id)
-                        vlc_player_SelectTrack(input->player, &trackpriv->t,
-                                               VLC_PLAYER_SELECT_EXCLUSIVE);
-                    break;
-                case AUDIO_ES:
-                    if (input->ml.restore_states &&
-                        input->ml.states.current_audio_track != -2 &&
-                        input->ml.states.current_audio_track == ev->fmt->i_id)
-                        vlc_player_SelectTrack(input->player, &trackpriv->t,
-                                               VLC_PLAYER_SELECT_EXCLUSIVE);
-                    break;
-                case SPU_ES:
-                    if (input->ml.restore_states &&
-                        input->ml.states.current_subtitle_track != -2 &&
-                        input->ml.states.current_subtitle_track == ev->fmt->i_id)
-                        vlc_player_SelectTrack(input->player, &trackpriv->t,
-                                               VLC_PLAYER_SELECT_EXCLUSIVE);
-                default:
-                    break;
-            }
             break;
         case VLC_INPUT_ES_DELETED:
         {
@@ -499,26 +470,6 @@ vlc_player_input_HandleEsEvent(struct vlc_player_input *input,
                 vlc_player_SendEvent(player, on_track_selection_changed,
                                      NULL, trackpriv->t.es_id);
             }
-            switch (ev->fmt->i_cat)
-            {
-                /* Save the default selected track to know if it changed
-                 * when the playback stops, in order to save the user's
-                 * explicitely selected track */
-                case VIDEO_ES:
-                    if (input->ml.default_video_track == -2)
-                        input->ml.default_video_track = ev->fmt->i_id;
-                    break;
-                case AUDIO_ES:
-                    if (input->ml.default_audio_track == -2)
-                        input->ml.default_audio_track = ev->fmt->i_id;
-                    break;
-                case SPU_ES:
-                    if (input->ml.default_subtitle_track == -2)
-                        input->ml.default_subtitle_track = ev->fmt->i_id;
-                    break;
-                default:
-                    break;
-            }
             break;
         case VLC_INPUT_ES_UNSELECTED:
             trackpriv = vlc_player_track_vector_FindById(vec, ev->id, NULL);
@@ -921,9 +872,7 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
     input->ml.states.current_title = -1;
     input->ml.states.current_video_track =
         input->ml.states.current_audio_track =
-        input->ml.states.current_subtitle_track =
-        input->ml.default_video_track = input->ml.default_audio_track =
-        input->ml.default_subtitle_track = -2;
+        input->ml.states.current_subtitle_track = -2;
     input->ml.states.progress = -1.f;
     input->ml.restore = VLC_RESTOREPOINT_NONE;
     input->ml.restore_states = false;
diff --git a/src/player/medialib.c b/src/player/medialib.c
index 88d991eedb..1ff74b4def 100644
--- a/src/player/medialib.c
+++ b/src/player/medialib.c
@@ -75,34 +75,20 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
     if (input->ml.states.rate != .0f)
         vlc_player_ChangeRate(player, input->ml.states.rate);
 
-    /* Tracks are restored upon insertion, except when explicitely disabled */
-    if (input->ml.states.current_video_track == -1)
-    {
-        input->ml.default_video_track = -1;
-        input_ControlSync(input->thread, INPUT_CONTROL_SET_ES_AUTOSELECT,
-                          &(input_control_param_t) {
-                              .es_autoselect.cat = VIDEO_ES,
-                              .es_autoselect.enabled = false,
-                          });
-    }
-    if (input->ml.states.current_audio_track == -1)
-    {
-        input->ml.default_audio_track = -1;
-        input_ControlSync(input->thread, INPUT_CONTROL_SET_ES_AUTOSELECT,
-                          &(input_control_param_t) {
-                              .es_autoselect.cat = AUDIO_ES,
-                              .es_autoselect.enabled = false,
-                          });
-    }
-    if (input->ml.states.current_subtitle_track == -1)
-    {
-        input->ml.default_subtitle_track = -1;
-        input_ControlSync(input->thread, INPUT_CONTROL_SET_ES_AUTOSELECT,
-                          &(input_control_param_t) {
-                              .es_autoselect.cat = SPU_ES,
-                              .es_autoselect.enabled = false,
-                          });
-    }
+
+    const char *video_track_ids = input->ml.states.current_video_track;
+    const char *audio_track_ids = input->ml.states.current_audio_track;
+    const char *subtitle_track_ids = input->ml.states.current_subtitle_track;
+
+    if (video_track_ids)
+        vlc_player_input_SelectTracksByStringIds(input, VIDEO_ES,
+                                                 video_track_ids);
+    if (audio_track_ids)
+        vlc_player_input_SelectTracksByStringIds(input, AUDIO_ES,
+                                                 audio_track_ids);
+    if (subtitle_track_ids)
+        vlc_player_input_SelectTracksByStringIds(input, SPU_ES,
+                                                 subtitle_track_ids);
 
     vout_thread_t* vout = vlc_player_vout_Hold(player);
     if (vout != NULL)
@@ -313,34 +299,23 @@ vlc_player_UpdateMLStates(vlc_player_t *player, struct vlc_player_input* input)
             input->ml.states.zoom = -1.f;
     }
 
-    if (input->ml.default_video_track != -2)
-    {
-        int current_video_track = vlc_player_GetFirstSelectedTrackId(&input->video_track_vector);
-        if (input->ml.default_video_track != current_video_track)
-            input->ml.states.current_video_track = current_video_track;
-        else
-            input->ml.states.current_video_track = -2;
-    }
+    char *video_track_ids =
+        vlc_player_input_GetSelectedTrackStringIds(input, VIDEO_ES);
+    char *audio_track_ids =
+        vlc_player_input_GetSelectedTrackStringIds(input, AUDIO_ES);
+    char *subtitle_track_ids =
+        vlc_player_input_GetSelectedTrackStringIds(input, SPU_ES);
 
-    if (input->ml.default_audio_track != -2)
-    {
-        int current_audio_track = vlc_player_GetFirstSelectedTrackId(&input->audio_track_vector);
-        if (input->ml.default_audio_track != current_audio_track)
-            input->ml.states.current_audio_track = current_audio_track;
-        else
-            input->ml.states.current_audio_track = -2;
-    }
+    vlc_player_CompareAssignState(&input->ml.states.current_video_track, &video_track_ids);
+    vlc_player_CompareAssignState(&input->ml.states.current_audio_track, &audio_track_ids);
+    vlc_player_CompareAssignState(&input->ml.states.current_subtitle_track, &subtitle_track_ids);
 
-    if (input->ml.default_subtitle_track != -2)
-    {
-        int current_subtitle_track = vlc_player_GetFirstSelectedTrackId(&input->spu_track_vector);
-        if (input->ml.default_subtitle_track != current_subtitle_track)
-            input->ml.states.current_subtitle_track = current_subtitle_track;
-        else
-            input->ml.states.current_subtitle_track = -2;
-    }
+    free(video_track_ids);
+    free(audio_track_ids);
+    free(subtitle_track_ids);
 
     vlc_ml_media_set_all_playback_states(ml, media->i_id, &input->ml.states);
+
     vlc_ml_release(&input->ml.states);
     vlc_ml_release(media);
 }
diff --git a/src/player/player.h b/src/player/player.h
index 2583ab8436..4ba6e061fa 100644
--- a/src/player/player.h
+++ b/src/player/player.h
@@ -108,9 +108,6 @@ struct vlc_player_input
     struct
     {
         vlc_ml_playback_states_all states;
-        int default_video_track;
-        int default_audio_track;
-        int default_subtitle_track;
         enum
         {
             VLC_RESTOREPOINT_TITLE,



More information about the vlc-commits mailing list