From 262ee4dd1c813a2b1175beb74022e2ebe6a9e79b Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Fri, 28 Jun 2019 11:33:12 +0200 Subject: [PATCH] [PVR] PVRRecordings: Prevent concurrent calls to video database. --- xbmc/pvr/PVRGUIDirectory.cpp | 11 ++--------- xbmc/pvr/recordings/PVRRecordings.cpp | 5 +++++ xbmc/pvr/recordings/PVRRecordings.h | 12 ++++++------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/xbmc/pvr/PVRGUIDirectory.cpp b/xbmc/pvr/PVRGUIDirectory.cpp index b2ce07ef85534..e5033dd03e9ca 100644 --- a/xbmc/pvr/PVRGUIDirectory.cpp +++ b/xbmc/pvr/PVRGUIDirectory.cpp @@ -162,7 +162,6 @@ bool IsDirectoryMember(const std::string& strDirectory, } void GetSubDirectories(const CPVRRecordingsPath& recParentPath, - CVideoDatabase& videoDB, const std::vector>& recordings, CFileItemList& results) { @@ -187,8 +186,6 @@ void GetSubDirectories(const CPVRRecordingsPath& recParentPath, recChildPath.AppendSegment(strCurrent); const std::string strFilePath = recChildPath; - recording->UpdateMetadata(videoDB); - std::shared_ptr item; if (!results.Contains(strFilePath)) { @@ -223,9 +220,7 @@ void GetSubDirectories(const CPVRRecordingsPath& recParentPath, bool CPVRGUIDirectory::GetRecordingsDirectory(CFileItemList& results) const { bool bGrouped = false; - const std::shared_ptr recs = CServiceBroker::GetPVRManager().Recordings(); - const std::vector> recordings = recs->GetAll(); - CVideoDatabase& videoDB = recs->GetVideoDatabase(); + const std::vector> recordings = CServiceBroker::GetPVRManager().Recordings()->GetAll(); if (m_url.HasOption("view")) { @@ -252,7 +247,7 @@ bool CPVRGUIDirectory::GetRecordingsDirectory(CFileItemList& results) const // Deleted view is always flatten. So only for an active view const std::string strDirectory = recPath.GetUnescapedDirectoryPath(); if (!recPath.IsDeleted() && bGrouped) - GetSubDirectories(recPath, videoDB, recordings, results); + GetSubDirectories(recPath, recordings, results); // get all files of the current directory or recursively all files starting at the current directory if in flatten mode std::shared_ptr item; @@ -264,8 +259,6 @@ bool CPVRGUIDirectory::GetRecordingsDirectory(CFileItemList& results) const !IsDirectoryMember(strDirectory, recording->m_strDirectory, bGrouped)) continue; - recording->UpdateMetadata(videoDB); - item = std::make_shared(recording); item->SetOverlayImage(CGUIListItem::ICON_OVERLAY_UNWATCHED, recording->GetPlayCount() > 0); results.Add(item); diff --git a/xbmc/pvr/recordings/PVRRecordings.cpp b/xbmc/pvr/recordings/PVRRecordings.cpp index ee69673d87eb2..62f922e392ceb 100644 --- a/xbmc/pvr/recordings/PVRRecordings.cpp +++ b/xbmc/pvr/recordings/PVRRecordings.cpp @@ -254,6 +254,7 @@ void CPVRRecordings::UpdateFromClient(const CPVRRecordingPtr &tag) { newTag = CPVRRecordingPtr(new CPVRRecording); newTag->Update(*tag); + newTag->UpdateMetadata(GetVideoDatabase()); newTag->m_iRecordingId = ++m_iLastId; m_recordings.insert(std::make_pair(CPVRRecordingUid(newTag->m_iClientId, newTag->m_strRecordingId), newTag)); if (newTag->IsRadio()) @@ -302,6 +303,8 @@ bool CPVRRecordings::ChangeRecordingsPlayCount(const CFileItemPtr &item, int cou { bool bResult = false; + CSingleLock lock(m_critSection); + CVideoDatabase& db = GetVideoDatabase(); if (db.IsOpen()) { @@ -378,6 +381,8 @@ bool CPVRRecordings::ResetResumePoint(const CFileItemPtr item) const CPVRRecordingPtr recording = item->GetPVRRecordingInfoTag(); if (recording) { + CSingleLock lock(m_critSection); + CVideoDatabase& db = GetVideoDatabase(); if (db.IsOpen()) { diff --git a/xbmc/pvr/recordings/PVRRecordings.h b/xbmc/pvr/recordings/PVRRecordings.h index 79352d0d90faf..da82f1481b64e 100644 --- a/xbmc/pvr/recordings/PVRRecordings.h +++ b/xbmc/pvr/recordings/PVRRecordings.h @@ -83,12 +83,6 @@ namespace PVR */ CPVRRecordingPtr GetRecordingForEpgTag(const CPVREpgInfoTagPtr &epgTag) const; - /** - * @brief Get/Open the video database. - * @return A reference to the video database. - */ - CVideoDatabase& GetVideoDatabase(); - private: mutable CCriticalSection m_critSection; bool m_bIsUpdating = false; @@ -102,6 +96,12 @@ namespace PVR void UpdateFromClients(void); + /*! + * @brief Get/Open the video database. + * @return A reference to the video database. + */ + CVideoDatabase& GetVideoDatabase(); + /** * @brief recursively deletes all recordings in the specified directory * @param item the directory