From f3d792a866ba602458d5d6c521bafa66e56a5528 Mon Sep 17 00:00:00 2001 From: chriszero Date: Sun, 5 Apr 2015 22:33:05 +0200 Subject: Fixes some concurency bugs --- Config.cpp | 11 ++ Config.h | 10 ++ Makefile | 1 + MediaContainer.h | 1 + browserGrid.cpp | 30 +++-- browserGrid.h | 2 + detailView.cpp | 10 ++ detailView.h | 14 ++ pictureCache.cpp | 18 ++- pictureCache.h | 3 +- plex.cpp | 4 +- plexSdOsd.cpp | 10 +- plexSdOsd.h | 1 + .../themes/default/skinparts/plexplaceholder.svg | 130 ++++++++++++++++++ skins/blackhole/xmlfiles/plug-plex-root.xml | 146 ++++++++++++++++++++- 15 files changed, 366 insertions(+), 25 deletions(-) create mode 100644 detailView.cpp create mode 100644 detailView.h create mode 100644 skins/blackhole/themes/default/skinparts/plexplaceholder.svg diff --git a/Config.cpp b/Config.cpp index df577aa..6b37efb 100644 --- a/Config.cpp +++ b/Config.cpp @@ -4,6 +4,8 @@ Config::Config() { s_username = "username"; s_password = "password"; + GridColumns = 5; + GridRows = 2; } std::string Config::GetUUID() { @@ -70,6 +72,8 @@ cMyMenuSetupPage::cMyMenuSetupPage(void) UseConfiguredServer = Config::GetInstance().UseConfiguredServer; HideMainMenuEntry = Config::GetInstance().HideMainMenuEntry; UseCustomTranscodeProfile = Config::GetInstance().UseCustomTranscodeProfile; + GridColumns = Config::GetInstance().GridColumns; + GridRows = Config::GetInstance().GridRows; Add(new cMenuEditBoolItem(tr("Hide main menu entry"), (int*)&HideMainMenuEntry, trVDR("no"), trVDR("yes"))); Add(new cMenuEditBoolItem(tr("Use custom transcoding profile"), (int*)&UseCustomTranscodeProfile, trVDR("no"), trVDR("yes"))); @@ -81,6 +85,9 @@ cMyMenuSetupPage::cMyMenuSetupPage(void) Add(new cMenuEditStrItem(tr("Server Host"), ServerHost, STRING_SIZE)); Add(new cMenuEditIntItem(tr("Server Port"), &ServerPort)); + Add(new cMenuEditIntItem(tr("Grid Columns"), &GridColumns)); + Add(new cMenuEditIntItem(tr("Grid Rows"), &GridRows)); + cMenuEditStrItem* devUUID = new cMenuEditStrItem(tr("Current UUID"), Uuid, STRING_SIZE); devUUID->SetSelectable(false); Add(devUUID); @@ -99,6 +106,8 @@ void cMyMenuSetupPage::Store(void) Config::GetInstance().UseConfiguredServer = UseConfiguredServer; Config::GetInstance().s_serverHost = std::string(ServerHost); Config::GetInstance().ServerPort = ServerPort; + Config::GetInstance().GridColumns = GridColumns; + Config::GetInstance().GridRows = GridRows; SetupStore("UseCustomTranscodeProfile", Config::GetInstance().UseCustomTranscodeProfile); SetupStore("HideMainMenuEntry", Config::GetInstance().HideMainMenuEntry); @@ -109,4 +118,6 @@ void cMyMenuSetupPage::Store(void) SetupStore("UseConfiguredServer", Config::GetInstance().UseConfiguredServer); SetupStore("ServerHost", Config::GetInstance().s_serverHost.c_str()); SetupStore("ServerPort", Config::GetInstance().ServerPort); + SetupStore("GridColumns", Config::GetInstance().GridColumns); + SetupStore("GridRows", Config::GetInstance().GridRows); } \ No newline at end of file diff --git a/Config.h b/Config.h index 39ee8ad..d123864 100644 --- a/Config.h +++ b/Config.h @@ -33,6 +33,8 @@ public: bool UseCustomTranscodeProfile; bool UsePlexAccount; bool UseConfiguredServer; + int GridColumns; + int GridRows; std::string GetUUID(); void SetUUID(const char* uuid); @@ -40,6 +42,12 @@ public: std::string GetLanguage(); std::string GetUsername(); std::string GetPassword(); + int ThumbHeight() { return 1080 / GridRows; }; + int ThumbWidth() { return 1920 / GridColumns; }; + int ArtHeight() { return 1080; }; + int ArtWidth() { return 1920; }; + int BannerHeight() { return 1080 / 2; }; + int BannerWidth() { return 1920 / 2; }; private: @@ -68,6 +76,8 @@ class cMyMenuSetupPage:public cMenuSetupPage int HideMainMenuEntry; int UseCustomTranscodeProfile; int UsePlexAccount; + int GridColumns; + int GridRows; virtual void Store(void); diff --git a/Makefile b/Makefile index 5372c45..bb7a5b1 100644 --- a/Makefile +++ b/Makefile @@ -92,6 +92,7 @@ OBJS = $(PLUGIN).o \ viewGridNavigator.o \ browserGrid.o \ viewHeader.o \ + detailView.o \ pictureCache.o \ libskindesigner/skindesignerosdbase.o \ libskindesigner/osdelements.o \ diff --git a/MediaContainer.h b/MediaContainer.h index d806fd3..da2a210 100644 --- a/MediaContainer.h +++ b/MediaContainer.h @@ -18,6 +18,7 @@ #include "Directory.h" #include "PVideo.h" #include "PlexServer.h" +#include "Config.h" using Poco::XML::DOMParser; using Poco::XML::InputSource; diff --git a/browserGrid.cpp b/browserGrid.cpp index 0ce3fcc..f3637c6 100644 --- a/browserGrid.cpp +++ b/browserGrid.cpp @@ -12,36 +12,39 @@ cBrowserGrid::cBrowserGrid(cOsdView* rootView) : cViewGridNavigator(rootView, ro m_pViewHeader = std::shared_ptr( new cViewHeader(rootView->GetViewElement(eViewElementsRoot::verHeader))); m_pfooter = std::shared_ptr(rootView->GetViewElement(eViewElementsRoot::verFooter)); - m_rows = 2; - m_columns = 5; + m_rows = Config::GetInstance().GridRows; + m_columns = Config::GetInstance().GridColumns; m_pService = NULL; m_pContainer = NULL; - //SwitchGrid(m_pViewHeader->CurrentTab()); + SwitchGrid(m_pViewHeader->CurrentTab()); } void cBrowserGrid::Flush() { - //cMutexLock MutexLock(&cPlexSdOsd::RedrawMutex); + cMutexLock MutexLock(&cPlexSdOsd::RedrawMutex); + m_pBackground->Display(); m_pGrid->Display(); m_pRootView->Display(); } void cBrowserGrid::SwitchGrid(ePlexMenuTab currentTab) { + cPictureCache::GetInstance().RemoveAll(); if(currentTab == ePlexMenuTab::pmtOnDeck) { - std::cout << "OnDeck" << std::endl; m_pService = std::shared_ptr(new plexclient::Plexservice( plexclient::plexgdm::GetInstance().GetFirstServer(), "/library/onDeck" ) ); m_pContainer = m_pService->GetSection(m_pService->StartUri); + m_bServersAreRoot = false; + m_vServerElements.clear(); ProcessData(); } else if(currentTab == ePlexMenuTab::pmtRecentlyAdded) { - std::cout << "Recently Added" << std::endl; m_pService = std::shared_ptr(new plexclient::Plexservice( plexclient::plexgdm::GetInstance().GetFirstServer(), "/library/recentlyAdded" ) ); m_pContainer = m_pService->GetSection(m_pService->StartUri); + m_bServersAreRoot = false; + m_vServerElements.clear(); ProcessData(); } else if(currentTab == ePlexMenuTab::pmtLibrary) { - std::cout << "Lib" << std::endl; //Server View m_pService = NULL; m_pContainer = NULL; @@ -88,8 +91,6 @@ void cBrowserGrid::ProcessData() m_vElements.push_back(elem); } } - // Cache Images - //m_pContainer->PreCache(); } m_firstElementIter = m_vElements.begin(); @@ -144,6 +145,7 @@ eOSState cBrowserGrid::NavigateBack() void cBrowserGrid::DrawGrid() { DrawBackground(); + m_pViewHeader->Draw(SelectedObject()); DrawFooter(); } @@ -222,6 +224,16 @@ void cBrowserGrid::DrawFooter() m_pfooter->Display(); } +void cBrowserGrid::NextTab() +{ + SwitchGrid(m_pViewHeader->NextTab()); +} + +void cBrowserGrid::PrevTab() +{ + SwitchGrid(m_pViewHeader->PrevTab()); +} + /* * cDummyElement */ diff --git a/browserGrid.h b/browserGrid.h index b91c30c..2eed86c 100644 --- a/browserGrid.h +++ b/browserGrid.h @@ -60,6 +60,8 @@ public: void SwitchGrid(ePlexMenuTab currentTab); virtual eOSState NavigateSelect(); virtual eOSState NavigateBack(); + void NextTab(); + void PrevTab(); virtual void Flush(); }; diff --git a/detailView.cpp b/detailView.cpp new file mode 100644 index 0000000..b9bc9a1 --- /dev/null +++ b/detailView.cpp @@ -0,0 +1,10 @@ +#include "detailView.h" + +cDetailView::cDetailView(cOsdView *detailView, const cGridElement *element) +{ +} + +cDetailView::~cDetailView() +{ +} + diff --git a/detailView.h b/detailView.h new file mode 100644 index 0000000..9917fd0 --- /dev/null +++ b/detailView.h @@ -0,0 +1,14 @@ +#ifndef CDETAILVIEW_H +#define CDETAILVIEW_H + +#include "viewGridNavigator.h" + +class cDetailView +{ +public: + cDetailView(cOsdView *detailView, const cGridElement *element); + ~cDetailView(); + +}; + +#endif // CDETAILVIEW_H diff --git a/pictureCache.cpp b/pictureCache.cpp index 67e2fd4..42885ec 100644 --- a/pictureCache.cpp +++ b/pictureCache.cpp @@ -26,13 +26,13 @@ cPictureCache::cPictureCache() Poco::File f(path.toString()); f.createDirectories(); HTTPStreamFactory::registerFactory(); + m_bAllInvalidated = false; } void cPictureCache::Action() { while(Running()) { while (m_qImagesToLoad.size() > 0) { - //LOCK_THREAD; CacheInfo info = m_qImagesToLoad.front(); m_qImagesToLoad.pop_front(); @@ -42,8 +42,8 @@ void cPictureCache::Action() auto stream = DownloadFile(transcodeUri); if(stream) { SaveFileToDisk(stream, file); - cMutexLock MutexLock(&cPlexSdOsd::RedrawMutex); - if (info.onCached && info.calle && info.calle->IsVisible()) { + LOCK_THREAD; + if (!m_bAllInvalidated && info.onCached && info.calle && info.calle->IsVisible()) { info.onCached(info.calle); } } @@ -83,7 +83,7 @@ void cPictureCache::SaveFileToDisk(std::shared_ptr file, std::stri std::string cPictureCache::FileName(std::string uri, int width) { Poco::URI u(uri); - std::string file = Poco::format("%s_%d", u.getPath(), width); + std::string file = Poco::format("%s_%d", u.getPathAndQuery(), width); Poco::Path path(m_cacheDir); path.append(file); @@ -108,12 +108,12 @@ bool cPictureCache::Cached(std::string uri, int width) std::string cPictureCache::GetPath(std::string uri, int width, int height, bool& cached, std::function OnCached, cGridElement* calle) { + m_bAllInvalidated = false; cached = Cached(uri, width); std::string file = FileName(uri, width); if(cached) { return file; } else { - //LOCK_THREAD; CacheInfo info(uri, width, height, OnCached, calle); m_qImagesToLoad.push_back(info); } @@ -137,6 +137,7 @@ void cPictureCache::Remove(cGridElement* element) void cPictureCache::Remove(std::string uri) { + LOCK_THREAD; for(std::deque::iterator it = m_qImagesToLoad.begin() ; it != m_qImagesToLoad.end(); ++it) { if(it->uri == uri) { m_qImagesToLoad.erase(it); @@ -144,3 +145,10 @@ void cPictureCache::Remove(std::string uri) } } } + +void cPictureCache::RemoveAll() +{ + LOCK_THREAD; + m_bAllInvalidated = true; + m_qImagesToLoad.clear(); +} diff --git a/pictureCache.h b/pictureCache.h index e63d44b..3d66726 100644 --- a/pictureCache.h +++ b/pictureCache.h @@ -38,7 +38,7 @@ private: }; cPictureCache(); std::deque m_qImagesToLoad; - + volatile bool m_bAllInvalidated; std::string FileName(std::string uri, int width); @@ -62,6 +62,7 @@ public: std::string GetPath(std::string uri, int width, int height, bool& cached, std::function OnCached = NULL, cGridElement* calle = NULL); void Remove(cGridElement* element); void Remove(std::string uri); + void RemoveAll(); }; #endif // CPICTURECACHE_H diff --git a/plex.cpp b/plex.cpp index fc84f99..f8961cf 100644 --- a/plex.cpp +++ b/plex.cpp @@ -160,8 +160,10 @@ bool cMyPlugin::SetupParse(const char *name, const char *value) else if (strcasecmp(name, "UseConfiguredServer") == 0) Config::GetInstance().UseConfiguredServer = atoi(value) ? true : false; else if (strcasecmp(name, "ServerHost") == 0) Config::GetInstance().s_serverHost = std::string(value); else if (strcasecmp(name, "ServerPort") == 0) Config::GetInstance().ServerPort = atoi(value); + else if (strcasecmp(name, "GridColumns") == 0) Config::GetInstance().GridColumns = atoi(value); + else if (strcasecmp(name, "GridRows") == 0) Config::GetInstance().GridRows = atoi(value); else return false; - + return true; } diff --git a/plexSdOsd.cpp b/plexSdOsd.cpp index 0379dd7..db50168 100644 --- a/plexSdOsd.cpp +++ b/plexSdOsd.cpp @@ -9,6 +9,11 @@ cPlexSdOsd::cPlexSdOsd() { } +cPlexSdOsd::~cPlexSdOsd() +{ + cPictureCache::GetInstance().RemoveAll(); +} + void cPlexSdOsd::Show(void) { bool skinDesignerAvailable = InitSkindesignerInterface("plex"); @@ -23,7 +28,6 @@ void cPlexSdOsd::Show(void) } m_pBrowserGrid = std::shared_ptr(new cBrowserGrid(m_pRootView)); - m_pBrowserGrid->SwitchGrid(ePlexMenuTab::pmtOnDeck); Flush(); } @@ -65,12 +69,12 @@ eOSState cPlexSdOsd::ProcessKey(eKeys Key) break; case kRed: // Prev Tab - //SwitchGrid(m_pViewHeader->NextTab()); + m_pBrowserGrid->NextTab(); Flush(); break; case kGreen: // Next Tab - //SwitchGrid(m_pViewHeader->PrevTab()); + m_pBrowserGrid->PrevTab(); Flush(); break; default: diff --git a/plexSdOsd.h b/plexSdOsd.h index 2dbe59f..433522b 100644 --- a/plexSdOsd.h +++ b/plexSdOsd.h @@ -49,6 +49,7 @@ private: public: cPlexSdOsd(); + ~cPlexSdOsd(); virtual void Show(void); virtual eOSState ProcessKey(eKeys Key); diff --git a/skins/blackhole/themes/default/skinparts/plexplaceholder.svg b/skins/blackhole/themes/default/skinparts/plexplaceholder.svg new file mode 100644 index 0000000..747b38d --- /dev/null +++ b/skins/blackhole/themes/default/skinparts/plexplaceholder.svg @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/skins/blackhole/xmlfiles/plug-plex-root.xml b/skins/blackhole/xmlfiles/plug-plex-root.xml index 4f29e14..b67e9c1 100644 --- a/skins/blackhole/xmlfiles/plug-plex-root.xml +++ b/skins/blackhole/xmlfiles/plug-plex-root.xml @@ -10,7 +10,13 @@ --> - + + + + + + + @@ -49,8 +55,10 @@ {current} Currently active element {title} Name of the element {year} - {thumb} Image/Cover - {art} Fanart + {hasthumb} + {thumb} Image/Cover + {hasart} + {art} Fanart {isdummy} Condition @@ -71,7 +79,7 @@ {banner} --> - + @@ -79,10 +87,136 @@ - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3