[vlc-devel] [PATCH 2/6] medialib: Bump contrib & reflect API changes

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Aug 21 08:15:09 CEST 2020


---
 configure.ac                                  |  2 +-
 contrib/src/medialibrary/rules.mak            |  4 +-
 include/vlc_media_library.h                   | 10 ++--
 .../library/VLCLibraryCollectionViewItem.m    |  2 +-
 .../gui/macosx/library/VLCLibraryController.m |  3 --
 .../gui/macosx/library/VLCLibraryDataTypes.h  |  4 +-
 .../gui/macosx/library/VLCLibraryDataTypes.m  | 16 +-----
 .../library/VLCLibraryInformationPanel.m      |  2 +-
 .../VLCPlaybackContinuityController.m         |  6 +--
 modules/gui/qt/medialibrary/mlvideo.cpp       |  9 +---
 .../misc/medialibrary/MetadataExtractor.cpp   |  5 +-
 modules/misc/medialibrary/entities.cpp        |  1 +
 modules/misc/medialibrary/fs/device.cpp       |  9 ++--
 modules/misc/medialibrary/fs/device.h         |  2 +-
 modules/misc/medialibrary/fs/file.cpp         | 10 ++++
 modules/misc/medialibrary/fs/file.h           |  3 ++
 modules/misc/medialibrary/fs/fs.cpp           |  6 +--
 modules/misc/medialibrary/fs/fs.h             |  2 +-
 modules/misc/medialibrary/medialib.cpp        | 14 ++---
 src/player/input.c                            |  6 +--
 src/player/medialib.c                         | 51 ++++---------------
 src/player/player.h                           |  1 +
 22 files changed, 58 insertions(+), 110 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4f7a46349b..8654e87d74 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4455,7 +4455,7 @@ dnl Libnotify notification plugin
 dnl
 PKG_ENABLE_MODULES_VLC([NOTIFY], [], [libnotify], [libnotify notification], [auto])
 
-PKG_ENABLE_MODULES_VLC([MEDIALIBRARY], [medialibrary], [medialibrary >= 0.8.0], (medialibrary support), [auto])
+PKG_ENABLE_MODULES_VLC([MEDIALIBRARY], [medialibrary], [medialibrary >= 0.9.0], (medialibrary support), [auto])
 
 dnl
 dnl  Endianness check
diff --git a/contrib/src/medialibrary/rules.mak b/contrib/src/medialibrary/rules.mak
index ff6d7c40d5..e2ba1c7a8e 100644
--- a/contrib/src/medialibrary/rules.mak
+++ b/contrib/src/medialibrary/rules.mak
@@ -1,9 +1,9 @@
-MEDIALIBRARY_HASH := cfc889fcd97ee9b1a71e100888715389025b12ea
+MEDIALIBRARY_HASH := b208f5b7f0e7981efbc779018d5ae7f117f331d2
 MEDIALIBRARY_VERSION := git-$(MEDIALIBRARY_HASH)
 MEDIALIBRARY_GITURL := https://code.videolan.org/videolan/medialibrary.git
 
 PKGS += medialibrary
-ifeq ($(call need_pkg,"medialibrary >= 0.8"),)
+ifeq ($(call need_pkg,"medialibrary >= 0.9"),)
 PKGS_FOUND += medialibrary
 endif
 
diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h
index fd82a71a23..aa12175979 100644
--- a/include/vlc_media_library.h
+++ b/include/vlc_media_library.h
@@ -201,6 +201,7 @@ typedef struct vlc_ml_media_t
     /* Duration in milliseconds */
     int64_t i_duration;
     uint32_t i_playcount;
+    float f_progress;
     time_t i_last_played_date;
     char* psz_title;
 
@@ -471,7 +472,7 @@ enum vlc_ml_control
     VLC_ML_NEW_STREAM,              /**< arg1: const char*; arg2(out): vlc_ml_media_t** */
 
     /* Media management */
-    VLC_ML_MEDIA_INCREASE_PLAY_COUNT,       /**< arg1: media id; can fail */
+    VLC_ML_MEDIA_UPDATE_PROGRESS,           /**< arg1: media id; arg2: playback position; can fail */
     VLC_ML_MEDIA_GET_MEDIA_PLAYBACK_STATE,  /**< arg1: media id; arg2: vlc_ml_playback_state; arg3: char**; */
     VLC_ML_MEDIA_SET_MEDIA_PLAYBACK_STATE,  /**< arg1: media id; arg2: vlc_ml_playback_state; arg3: const char*; */
     VLC_ML_MEDIA_GET_ALL_MEDIA_PLAYBACK_STATES, /**< arg1: media id; arg2(out): vlc_ml_playback_states_all* */
@@ -499,7 +500,6 @@ enum vlc_ml_control
 enum vlc_ml_playback_state
 {
     VLC_ML_PLAYBACK_STATE_RATING,
-    VLC_ML_PLAYBACK_STATE_PROGRESS,
     VLC_ML_PLAYBACK_STATE_SPEED,
     VLC_ML_PLAYBACK_STATE_TITLE,
     VLC_ML_PLAYBACK_STATE_CHAPTER,
@@ -521,7 +521,6 @@ enum vlc_ml_playback_state
 
 typedef struct vlc_ml_playback_states_all
 {
-    float progress;
     float rate;
     float zoom;
     int current_title;
@@ -932,9 +931,10 @@ static inline vlc_ml_media_t* vlc_ml_new_stream( vlc_medialibrary_t* p_ml, const
     return res;
 }
 
-static inline int vlc_ml_media_increase_playcount( vlc_medialibrary_t* p_ml, int64_t i_media_id )
+static inline int vlc_ml_media_update_progress( vlc_medialibrary_t* p_ml, int64_t i_media_id,
+                                                double progress )
 {
-    return vlc_ml_control( p_ml, VLC_ML_MEDIA_INCREASE_PLAY_COUNT, i_media_id );
+    return vlc_ml_control( p_ml, VLC_ML_MEDIA_UPDATE_PROGRESS, i_media_id, progress );
 }
 
 static inline int vlc_ml_media_get_playback_state( vlc_medialibrary_t* p_ml, int64_t i_media_id, int i_state, char** ppsz_result )
diff --git a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
index f6487a17d9..b836d52a7f 100644
--- a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
+++ b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
@@ -172,7 +172,7 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
     VLCMediaLibraryTrack *videoTrack = _representedMediaItem.firstVideoTrack;
     [self showVideoSizeIfNeededForWidth:videoTrack.videoWidth andHeight:videoTrack.videoHeight];
 
-    CGFloat position = _representedMediaItem.lastPlaybackPosition;
+    CGFloat position = _representedMediaItem.progress;
     if (position > VLCLibraryCollectionViewItemMinimalDisplayedProgress && position < VLCLibraryCollectionViewItemMaximumDisplayedProgress) {
         _progressIndicator.progress = position;
         _progressIndicator.hidden = NO;
diff --git a/modules/gui/macosx/library/VLCLibraryController.m b/modules/gui/macosx/library/VLCLibraryController.m
index b20b48ade8..58a100ad46 100644
--- a/modules/gui/macosx/library/VLCLibraryController.m
+++ b/modules/gui/macosx/library/VLCLibraryController.m
@@ -94,9 +94,6 @@
     }
     int ret = [[[VLCMain sharedInstance] playlistController] addInputItem:p_inputItem atPosition:-1 startPlayback:playImmediately];
     input_item_Release(p_inputItem);
-    if (ret == VLC_SUCCESS) {
-        [mediaItem increasePlayCount];
-    }
     return ret;
 }
 
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.h b/modules/gui/macosx/library/VLCLibraryDataTypes.h
index c643e5e6c8..b61dfde6a6 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.h
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.h
@@ -172,6 +172,7 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 @property (readonly) int64_t duration; /* Duration in milliseconds */
 @property (readonly) uint32_t playCount;
 @property (readonly) time_t lastPlayedDate;
+ at property (readonly) float progress;
 @property (readonly) NSString *title;
 
 @property (readonly, nullable) NSString *smallArtworkMRL;
@@ -185,7 +186,6 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 @property (readonly, nullable) VLCMediaLibraryAlbumTrack *albumTrack;
 
 @property (readwrite) int rating;
- at property (readwrite) float lastPlaybackPosition;
 @property (readwrite) float lastPlaybackRate;
 @property (readwrite) int lastTitle;
 @property (readwrite) int lastChapter;
@@ -203,8 +203,6 @@ extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
 @property (readwrite) int lastSubtitleTrack;
 @property (readwrite) int lastSubtitleDelay;
 
-- (int)increasePlayCount;
-
 @end
 
 @interface VLCMediaLibraryEntryPoint : NSObject
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.m b/modules/gui/macosx/library/VLCLibraryDataTypes.m
index 167ecaf38e..b9c0520050 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.m
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.m
@@ -383,6 +383,7 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
         _duration = p_mediaItem->i_duration;
         _playCount = p_mediaItem->i_playcount;
         _lastPlayedDate = p_mediaItem->i_last_played_date;
+        _progress = p_mediaItem->f_progress;
         _title = toNSStr(p_mediaItem->psz_title);
         _smallArtworkGenerated = p_mediaItem->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl != NULL;
         if (_smallArtworkGenerated) {
@@ -598,16 +599,6 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
     [self setIntegerPreference:rating forKey:VLC_ML_PLAYBACK_STATE_RATING];
 }
 
-- (float)lastPlaybackPosition
-{
-    return [self floatPreferenceForKey:VLC_ML_PLAYBACK_STATE_PROGRESS];
-}
-
-- (void)setLastPlaybackPosition:(float)lastPlaybackPosition
-{
-    [self setFloatPreference:lastPlaybackPosition forKey:VLC_ML_PLAYBACK_STATE_PROGRESS];
-}
-
 - (float)lastPlaybackRate
 {
     return [self floatPreferenceForKey:VLC_ML_PLAYBACK_STATE_SPEED];
@@ -768,11 +759,6 @@ NSString *VLCMediaLibraryMediaItemLibraryID = @"VLCMediaLibraryMediaItemLibraryI
     [self setIntegerPreference:lastSubtitleDelay forKey:VLC_ML_PLAYBACK_STATE_SUBTITLE_DELAY];
 }
 
-- (int)increasePlayCount
-{
-    return vlc_ml_media_increase_playcount(_p_mediaLibrary, _libraryID);
-}
-
 @end
 
 @implementation VLCMediaLibraryEntryPoint
diff --git a/modules/gui/macosx/library/VLCLibraryInformationPanel.m b/modules/gui/macosx/library/VLCLibraryInformationPanel.m
index 54b0e0a3e6..f81579c7a9 100644
--- a/modules/gui/macosx/library/VLCLibraryInformationPanel.m
+++ b/modules/gui/macosx/library/VLCLibraryInformationPanel.m
@@ -56,7 +56,7 @@
     [textContent appendFormat:@"Duration: %@\n", [NSString stringWithTime:_representedMediaItem.duration / VLCMediaLibraryMediaItemDurationDenominator]];
     [textContent appendFormat:@"Play count: %u, last played: %@\n", _representedMediaItem.playCount, [NSDateFormatter localizedStringFromDate:[NSDate dateWithTimeIntervalSince1970:_representedMediaItem.lastPlayedDate] dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle]];
     [textContent appendFormat:@"Small artwork generated? %@\n", _representedMediaItem.smallArtworkGenerated == YES ? _NS("Yes") : _NS("No")];
-    [textContent appendFormat:@"Favorited? %@, Playback progress: %2.f%%\n", _representedMediaItem.smallArtworkGenerated == YES ? _NS("Yes") : _NS("No"), _representedMediaItem.lastPlaybackPosition * 100.];
+    [textContent appendFormat:@"Favorited? %@, Playback progress: %2.f%%\n", _representedMediaItem.smallArtworkGenerated == YES ? _NS("Yes") : _NS("No"), _representedMediaItem.progress * 100.];
 
     NSArray *array = _representedMediaItem.files;
     NSUInteger count = array.count;
diff --git a/modules/gui/macosx/playlist/VLCPlaybackContinuityController.m b/modules/gui/macosx/playlist/VLCPlaybackContinuityController.m
index d9a719c6d7..5a490c5699 100644
--- a/modules/gui/macosx/playlist/VLCPlaybackContinuityController.m
+++ b/modules/gui/macosx/playlist/VLCPlaybackContinuityController.m
@@ -187,7 +187,7 @@ static NSString *VLCRecentlyPlayedMediaListKey = @"recentlyPlayedMediaList";
                                               ask:(BOOL)ask
                                            player:(VLCPlayerController *)playerController
 {
-    float lastPlaybackPosition = libraryMediaItem.lastPlaybackPosition;
+    float lastPlaybackPosition = libraryMediaItem.progress;
     int64_t duration = libraryMediaItem.duration;
 
     if (lastPlaybackPosition < MinimumStorePercent || duration < MinimumDuration) {
@@ -293,10 +293,6 @@ BOOL ShouldStorePlaybackPosition(float position, int64_t duration)
         // input item isn't part of the library
         [self storeLegacyPlaybackPositionForInputItem:inputItem withPlayer:playerController];
     }
-
-    if (ShouldStorePlaybackPosition(playerController.position, libraryMediaItem.duration)) {
-        libraryMediaItem.lastPlaybackPosition = playerController.position;
-    }
 }
 
 - (void)storeLegacyPlaybackPositionForInputItem:(VLCInputItem *)inputItem
diff --git a/modules/gui/qt/medialibrary/mlvideo.cpp b/modules/gui/qt/medialibrary/mlvideo.cpp
index 3092d9b3ce..e1c3b0d9c5 100644
--- a/modules/gui/qt/medialibrary/mlvideo.cpp
+++ b/modules/gui/qt/medialibrary/mlvideo.cpp
@@ -80,7 +80,7 @@ MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* pa
     , m_id( data->i_id, VLC_ML_PARENT_UNKNOWN )
     , m_title( QString::fromUtf8( data->psz_title ) )
     , m_thumbnail( QString::fromUtf8( data->thumbnails[VLC_ML_THUMBNAIL_SMALL].psz_mrl ) )
-    , m_progress( -1.f )
+    , m_progress( data->f_progress )
     , m_playCount( data->i_playcount )
     , m_thumbnailGenerated( data->thumbnails[VLC_ML_THUMBNAIL_SMALL].b_generated )
     , m_ml_event_handle( nullptr, [this](vlc_ml_event_callback_t* cb ) {
@@ -99,13 +99,6 @@ MLVideo::MLVideo(vlc_medialibrary_t* ml, const vlc_ml_media_t* data, QObject* pa
             m_mrl = QUrl::fromEncoded(file.psz_mrl);
             break;
         }
-    char *psz_progress;
-    if ( vlc_ml_media_get_playback_state( ml, data->i_id, VLC_ML_PLAYBACK_STATE_PROGRESS,
-                                    &psz_progress ) == VLC_SUCCESS && psz_progress != NULL )
-    {
-        m_progress = atof( psz_progress );
-        free( psz_progress );
-    }
 
     unsigned int numChannel = 0 , maxWidth = 0 , maxHeight = 0;
     for( const vlc_ml_media_track_t& track: ml_range_iterate<vlc_ml_media_track_t>( data->p_tracks ) ) {
diff --git a/modules/misc/medialibrary/MetadataExtractor.cpp b/modules/misc/medialibrary/MetadataExtractor.cpp
index 0896804f45..0d6d969cc9 100644
--- a/modules/misc/medialibrary/MetadataExtractor.cpp
+++ b/modules/misc/medialibrary/MetadataExtractor.cpp
@@ -131,7 +131,8 @@ void MetadataExtractor::addSubtree( ParseContext& ctx, input_item_node_t *root )
     for ( auto i = 0; i < root->i_children; ++i )
     {
         auto it = root->pp_children[i]->p_item;
-        auto& subItem = ctx.item.createSubItem( it->psz_uri, i );
+        auto& subItem = ctx.item.createLinkedItem( it->psz_uri,
+                                                   medialibrary::IFile::Type::Main, i );
         populateItem( subItem, it );
     }
 }
@@ -184,7 +185,7 @@ medialibrary::parser::Status MetadataExtractor::run( medialibrary::parser::IItem
         return medialibrary::parser::Status::Fatal;
 
     if ( item.fileType() == medialibrary::IFile::Type::Playlist &&
-         item.nbSubItems() == 0 )
+         item.nbLinkedItems() == 0 )
         return medialibrary::parser::Status::Fatal;
 
     populateItem( item, ctx.inputItem.get() );
diff --git a/modules/misc/medialibrary/entities.cpp b/modules/misc/medialibrary/entities.cpp
index 8c567f954a..2078ab3ba5 100644
--- a/modules/misc/medialibrary/entities.cpp
+++ b/modules/misc/medialibrary/entities.cpp
@@ -236,6 +236,7 @@ bool Convert( const medialibrary::IMedia* input, vlc_ml_media_t& output )
     output.i_duration = input->duration();
     output.b_is_favorite = input->isFavorite();
     output.i_playcount = input->playCount();
+    output.f_progress = input->progress();
     output.i_last_played_date = input->lastPlayedDate();
 
     output.psz_title = strdup( input->title().c_str() );
diff --git a/modules/misc/medialibrary/fs/device.cpp b/modules/misc/medialibrary/fs/device.cpp
index 226f158bad..87227d4b5b 100644
--- a/modules/misc/medialibrary/fs/device.cpp
+++ b/modules/misc/medialibrary/fs/device.cpp
@@ -62,10 +62,13 @@ bool SDDevice::isNetwork() const
     return m_isNetwork;
 }
 
-const
-std::string &SDDevice::mountpoint() const
+std::vector<std::string> SDDevice::mountpoints() const
 {
-    return m_mountpoints[0].mrl;
+    std::vector<std::string> res;
+    res.reserve( m_mountpoints.size() );
+    for ( const auto& m : m_mountpoints )
+        res.push_back( m.mrl );
+    return res;
 }
 
 void SDDevice::addMountpoint( std::string mrl )
diff --git a/modules/misc/medialibrary/fs/device.h b/modules/misc/medialibrary/fs/device.h
index ba9eb2822a..b4b0804bb0 100644
--- a/modules/misc/medialibrary/fs/device.h
+++ b/modules/misc/medialibrary/fs/device.h
@@ -43,7 +43,7 @@ public:
     bool isRemovable() const override;
     bool isPresent() const override;
     bool isNetwork() const override;
-    const std::string &mountpoint() const override;
+    std::vector<std::string> mountpoints() const override;
     void addMountpoint( std::string mrl ) override;
     void removeMountpoint( const std::string& mrl ) override;
     std::tuple<bool, std::string> matchesMountpoint( const std::string& mrl ) const override;
diff --git a/modules/misc/medialibrary/fs/file.cpp b/modules/misc/medialibrary/fs/file.cpp
index 1dd98a5c06..daa77f99f9 100644
--- a/modules/misc/medialibrary/fs/file.cpp
+++ b/modules/misc/medialibrary/fs/file.cpp
@@ -65,5 +65,15 @@ SDFile::size() const
     return 0;
 }
 
+IFile::LinkedFileType SDFile::linkedType() const
+{
+    return IFile::LinkedFileType::None;
+}
+
+const std::string &SDFile::linkedWith() const
+{
+    return m_linkedFile;
+}
+
   } /* namespace medialibrary */
 } /* namespace vlc */
diff --git a/modules/misc/medialibrary/fs/file.h b/modules/misc/medialibrary/fs/file.h
index bb0525b4d9..41584b2476 100644
--- a/modules/misc/medialibrary/fs/file.h
+++ b/modules/misc/medialibrary/fs/file.h
@@ -39,11 +39,14 @@ public:
     unsigned int lastModificationDate() const override;
     int64_t size() const override;
     inline bool isNetwork() const override { return true; }
+    LinkedFileType linkedType() const override;
+    const std::string &linkedWith() const override;
 
 private:
     std::string m_mrl;
     std::string m_name;
     std::string m_extension;
+    std::string m_linkedFile;
 };
 
   } /* namespace medialibrary */
diff --git a/modules/misc/medialibrary/fs/fs.cpp b/modules/misc/medialibrary/fs/fs.cpp
index b8d326a3f0..85323cb231 100644
--- a/modules/misc/medialibrary/fs/fs.cpp
+++ b/modules/misc/medialibrary/fs/fs.cpp
@@ -149,8 +149,8 @@ void SDFileSystemFactory::onDeviceMounted(const std::string& uuid,
         }
         device->addMountpoint(mountpoint);
     }
-
-    m_callbacks->onDeviceMounted( *device );
+    fprintf(stderr, "device mounted: %s %s\n", uuid.c_str(), mountpoint.c_str());
+    m_callbacks->onDeviceMounted( *device, mountpoint );
 }
 
 void vlc::medialibrary::SDFileSystemFactory::onDeviceUnmounted(const std::string& uuid,
@@ -170,7 +170,7 @@ void vlc::medialibrary::SDFileSystemFactory::onDeviceUnmounted(const std::string
         return;
     }
     device->removeMountpoint(mountpoint);
-    m_callbacks->onDeviceUnmounted(*device);
+    m_callbacks->onDeviceUnmounted(*device, mountpoint);
 }
 
 std::shared_ptr<IDevice> SDFileSystemFactory::deviceByUuid(const std::string& uuid)
diff --git a/modules/misc/medialibrary/fs/fs.h b/modules/misc/medialibrary/fs/fs.h
index 38867c0ca0..30025e6fb6 100644
--- a/modules/misc/medialibrary/fs/fs.h
+++ b/modules/misc/medialibrary/fs/fs.h
@@ -91,7 +91,7 @@ private:
     std::shared_ptr<fs::IDevice>
     deviceByUuid(const std::string& uuid);
 
-    bool isStarted() const;
+    bool isStarted() const override;
 
     std::shared_ptr<fs::IDevice> deviceByMrl(const std::string& mrl);
 
diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp
index b73cd46c55..8eb4a624dc 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -590,7 +590,7 @@ int MediaLibrary::Control( int query, va_list args )
             *va_arg( args, vlc_ml_media_t**) = CreateAndConvert<vlc_ml_media_t>( media.get() );
             return VLC_SUCCESS;
         }
-        case VLC_ML_MEDIA_INCREASE_PLAY_COUNT:
+        case VLC_ML_MEDIA_UPDATE_PROGRESS:
         case VLC_ML_MEDIA_GET_MEDIA_PLAYBACK_STATE:
         case VLC_ML_MEDIA_SET_MEDIA_PLAYBACK_STATE:
         case VLC_ML_MEDIA_GET_ALL_MEDIA_PLAYBACK_STATES:
@@ -961,8 +961,6 @@ medialibrary::IMedia::MetadataType MediaLibrary::metadataType( int meta )
     {
         case VLC_ML_PLAYBACK_STATE_RATING:
             return medialibrary::IMedia::MetadataType::Rating;
-        case VLC_ML_PLAYBACK_STATE_PROGRESS:
-            return medialibrary::IMedia::MetadataType::Progress;
         case VLC_ML_PLAYBACK_STATE_SPEED:
             return medialibrary::IMedia::MetadataType::Speed;
         case VLC_ML_PLAYBACK_STATE_TITLE:
@@ -1053,7 +1051,6 @@ int MediaLibrary::getMeta( const medialibrary::IMedia& media,
                            vlc_ml_playback_states_all* res )
 {
     auto metas = media.metadata();
-    res->progress = -1.f;
     res->rate = .0f;
     res->zoom = -1.f;
     res->current_title = -1;
@@ -1069,9 +1066,6 @@ int MediaLibrary::getMeta( const medialibrary::IMedia& media,
 
         switch ( meta.first )
         {
-            case medialibrary::IMedia::MetadataType::Progress:
-                res->progress = atof( meta.second.c_str() );
-                break;
             case medialibrary::IMedia::MetadataType::Speed:
                 res->rate = atof( meta.second.c_str() );
                 break;
@@ -1127,8 +1121,6 @@ int MediaLibrary::setMeta( medialibrary::IMedia& media,
 {
     using MT = medialibrary::IMedia::MetadataType;
     std::unordered_map<MT, std::string> metas;
-    if ( values->progress >= .0f )
-        metas[MT::Progress] = std::to_string( values->progress );
     if ( values->rate != .0f )
         metas[MT::Speed] = std::to_string( values->rate );
     if ( values->zoom != .0f )
@@ -1163,8 +1155,8 @@ int MediaLibrary::controlMedia( int query, va_list args )
         return VLC_EGENERIC;
     switch( query )
     {
-        case VLC_ML_MEDIA_INCREASE_PLAY_COUNT:
-            if ( m->increasePlayCount() == false )
+        case VLC_ML_MEDIA_UPDATE_PROGRESS:
+            if ( m->setProgress( va_arg( args, double ) ) == false )
                 return VLC_EGENERIC;
             return VLC_SUCCESS;
         case VLC_ML_MEDIA_GET_MEDIA_PLAYBACK_STATE:
diff --git a/src/player/input.c b/src/player/input.c
index 5dc311436d..59b4f7345d 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -604,9 +604,9 @@ vlc_player_input_HandleTitleEvent(struct vlc_player_input *input,
             if (input->ml.restore == VLC_RESTOREPOINT_POSITION &&
                 input->ml.states.current_title >= 0 &&
                 (size_t)input->ml.states.current_title == ev->selected_idx &&
-                input->ml.states.progress > .0f)
+                input->ml.pos > .0f)
             {
-                input_SetPosition(input->thread, input->ml.states.progress, false);
+                input_SetPosition(input->thread, input->ml.pos, false);
             }
             /* Reset the wanted title to avoid forcing it or the position
              * again during the next title change
@@ -945,10 +945,10 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
     input->ml.states.current_video_track =
         input->ml.states.current_audio_track =
         input->ml.states.current_subtitle_track = NULL;
-    input->ml.states.progress = -1.f;
     input->ml.restore = VLC_RESTOREPOINT_NONE;
     input->ml.restore_states = false;
     input->ml.delay_restore = false;
+    input->ml.pos = -1.f;
 
     input->thread = input_Create(player, input_thread_Events, input, item,
                                  player->resource, player->renderer);
diff --git a/src/player/medialib.c b/src/player/medialib.c
index a5f8a32bd9..b4deb94e0a 100644
--- a/src/player/medialib.c
+++ b/src/player/medialib.c
@@ -53,7 +53,6 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
         vlc_ml_release(media);
         return;
     }
-    vlc_ml_release(media);
 
     input->ml.restore = (restore_pos == VLC_PLAYER_RESTORE_PLAYBACK_POS_ALWAYS) ?
                             VLC_RESTOREPOINT_TITLE : VLC_RESTOREPOINT_NONE;
@@ -64,11 +63,16 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
      */
     if (restore_pos == VLC_PLAYER_RESTORE_PLAYBACK_POS_ALWAYS &&
             input->ml.states.current_title == -1 &&
-            input->ml.states.progress > .0f)
-        input_SetPosition(input->thread, input->ml.states.progress, false);
+            media->f_progress > .0f)
+        input_SetPosition(input->thread, media->f_progress, false);
     else if (restore_pos == VLC_PLAYER_RESTORE_PLAYBACK_POS_ASK &&
-             input->ml.states.progress > .0f)
+             media->f_progress > .0f)
+    {
         input->ml.delay_restore = true;
+        input->ml.pos = media->f_progress;
+    }
+
+    vlc_ml_release(media);
 
     if (!restore_states)
         return;
@@ -119,26 +123,6 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
     }
 }
 
-static const float beginning_of_media_percent = .05f;
-static const int64_t beginning_of_media_sec = 60;
-
-static int
-beginning_of_media(struct vlc_player_input *input)
-{
-    return input->position <= beginning_of_media_percent &&
-        input->time < VLC_TICK_FROM_SEC(beginning_of_media_sec);
-}
-
-static const float end_of_media_percent = .95f;
-static const int64_t end_of_media_sec = 60;
-
-static int
-end_of_media(struct vlc_player_input *input)
-{
-    return input->position >= end_of_media_percent &&
-        input->length - input->time < VLC_TICK_FROM_SEC(end_of_media_sec);
-}
-
 static bool
 vlc_player_UpdateMediaType(const struct vlc_player_input* input,
                            vlc_medialibrary_t* ml, vlc_ml_media_t* media)
@@ -214,24 +198,7 @@ vlc_player_UpdateMLStates(vlc_player_t *player, struct vlc_player_input* input)
     }
     assert(media->i_type != VLC_ML_MEDIA_TYPE_UNKNOWN);
 
-    /* If we reached end of the media, bump the play count & the media in the
-     * history */
-    if (end_of_media(input))
-        vlc_ml_media_increase_playcount(ml, media->i_id);
-
-    if (beginning_of_media(input) || end_of_media(input))
-    {
-        /* Ensure we remove any previously saved position to allow the playback
-         * of this media to restart from the begining */
-        if (input->ml.states.progress >= .0f )
-        {
-            vlc_ml_media_set_playback_state(ml, media->i_id,
-                                            VLC_ML_PLAYBACK_STATE_PROGRESS, NULL );
-            input->ml.states.progress = -1.f;
-        }
-    }
-    else
-        input->ml.states.progress = input->position;
+    vlc_ml_media_update_progress( ml, media->i_id, input->position );
 
     /* If the value changed during the playback, update it in the medialibrary.
      * If not, set each state to their "unset" values, so that they aren't saved
diff --git a/src/player/player.h b/src/player/player.h
index 87b9e43033..077086199a 100644
--- a/src/player/player.h
+++ b/src/player/player.h
@@ -114,6 +114,7 @@ struct vlc_player_input
             VLC_RESTOREPOINT_POSITION,
             VLC_RESTOREPOINT_NONE,
         } restore;
+        float pos;
         bool restore_states;
         bool delay_restore;
     } ml;
-- 
2.20.1



More information about the vlc-devel mailing list