diff options
author | chriszero <zerov83@gmail.com> | 2015-02-21 18:05:16 +0100 |
---|---|---|
committer | chriszero <zerov83@gmail.com> | 2015-02-21 18:05:16 +0100 |
commit | 36dd0bec49224987219e1e4ba57a1443202694fd (patch) | |
tree | 5367cfa11ea9a1bced6d35c289ee89d4cbf73da5 | |
parent | 2d8e03d177d20f22c2776b77b2d704a5009ce0fa (diff) | |
download | vdr-plugin-plex-36dd0bec49224987219e1e4ba57a1443202694fd.tar.gz vdr-plugin-plex-36dd0bec49224987219e1e4ba57a1443202694fd.tar.bz2 |
Bugfixes
Speedup jumping in hls
-rw-r--r-- | hlsPlayer.cpp | 122 | ||||
-rw-r--r-- | hlsPlayer.h | 1 | ||||
-rw-r--r-- | plex.cpp | 23 |
3 files changed, 85 insertions, 61 deletions
diff --git a/hlsPlayer.cpp b/hlsPlayer.cpp index 605280f..b5ea4c3 100644 --- a/hlsPlayer.cpp +++ b/hlsPlayer.cpp @@ -47,6 +47,16 @@ cHlsSegmentLoader::~cHlsSegmentLoader() delete m_pRingbuffer; } +void cHlsSegmentLoader::SkipEmptySegments(int segmentDuration) +{ + pcrecpp::RE re("&offset=(\\d+)", pcrecpp::RE_Options(PCRE_CASELESS)); + int value; + re.PartialMatch(m_startUri.getQuery(), &value); + if (value > segmentDuration) { + m_lastLoadedSegment = (value / segmentDuration) - 1; + } +} + bool cHlsSegmentLoader::LoadM3u8(std::string uri) { LOCK_THREAD; @@ -105,47 +115,55 @@ bool cHlsSegmentLoader::LoadLists(void) bool cHlsSegmentLoader::LoadIndexList(void) { bool res = false; - ConnectToServer(); - if(m_startParser.MasterPlaylist && m_startParser.vPlaylistItems.size() > 0) { - // Todo: make it universal, might only work for Plexmediaserver + try { ConnectToServer(); + if(m_startParser.MasterPlaylist && m_startParser.vPlaylistItems.size() > 0) { + // Todo: make it universal, might only work for Plexmediaserver + ConnectToServer(); - std::string startUri = m_startUri.toString(); - startUri = startUri.substr(0, startUri.find_last_of("/")+1); + std::string startUri = m_startUri.toString(); + startUri = startUri.substr(0, startUri.find_last_of("/")+1); - Poco::URI indexUri(startUri+m_startParser.vPlaylistItems[0].file); + Poco::URI indexUri(startUri+m_startParser.vPlaylistItems[0].file); - Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, indexUri.getPath()); - AddHeader(request); - // same server - m_pClientSession->sendRequest(request); + Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, indexUri.getPath()); + AddHeader(request); + // same server + m_pClientSession->sendRequest(request); - Poco::Net::HTTPResponse responseStart; - std::istream& indexFile = m_pClientSession->receiveResponse(responseStart); + Poco::Net::HTTPResponse responseStart; + std::istream& indexFile = m_pClientSession->receiveResponse(responseStart); - if(responseStart.getStatus() != 200) { - esyslog("[plex]%s Response Not Valid", __FUNCTION__); - return res; - } - m_indexParser = cM3u8Parser(); - res = m_indexParser.Parse(indexFile); + if(responseStart.getStatus() != 200) { + esyslog("[plex]%s Response Not Valid", __FUNCTION__); + return res; + } + m_indexParser = cM3u8Parser(); + res = m_indexParser.Parse(indexFile); - if(res) { - // Segment URI is relative to index.m3u8 - std::string path = indexUri.getPath(); - m_segmentUriPart = path.substr(0, path.find_last_of("/")+1); - } - if(m_indexParser.TargetDuration > 3) { - m_segmentsToBuffer = 2; - } else { - m_segmentsToBuffer = 3; - } + if(res) { + // Segment URI is relative to index.m3u8 + std::string path = indexUri.getPath(); + m_segmentUriPart = path.substr(0, path.find_last_of("/")+1); + } + if(m_indexParser.TargetDuration > 3) { + m_segmentsToBuffer = 2; + } else { + m_segmentsToBuffer = 3; + } + + SkipEmptySegments(m_indexParser.TargetDuration); - // Get stream lenght - m_streamlenght = 0; - for(unsigned int i = 0; i < m_indexParser.vPlaylistItems.size(); i++) { - m_streamlenght += m_indexParser.vPlaylistItems[i].length; + // Get stream lenght + m_streamlenght = 0; + for(unsigned int i = 0; i < m_indexParser.vPlaylistItems.size(); i++) { + m_streamlenght += m_indexParser.vPlaylistItems[i].length; + } } + + } catch (Poco::Exception &exc) { + esyslog("[plex] %s %s", __FUNCTION__, exc.displayText().c_str()); + res = false; } return res; } @@ -154,27 +172,31 @@ bool cHlsSegmentLoader::LoadStartList(void) { bool res = false; ConnectToServer(); + try { + Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, m_startUri.getPathAndQuery()); + AddHeader(request); + m_pClientSession->sendRequest(request); - Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, m_startUri.getPathAndQuery()); - AddHeader(request); - m_pClientSession->sendRequest(request); - - Poco::Net::HTTPResponse responseStart; - std::istream& startFile = m_pClientSession->receiveResponse(responseStart); + Poco::Net::HTTPResponse responseStart; + std::istream& startFile = m_pClientSession->receiveResponse(responseStart); - if(responseStart.getStatus() != 200) { - esyslog("[plex]%s Response Not Valid", __FUNCTION__); - return res; - } + if(responseStart.getStatus() != 200) { + esyslog("[plex]%s Response Not Valid", __FUNCTION__); + return res; + } - m_startParser = cM3u8Parser(); - res = m_startParser.Parse(startFile); - if(res) { - // Get GUID - pcrecpp::RE re("([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})", pcrecpp::RE_Options(PCRE_CASELESS)); - string value; - re.PartialMatch(m_startParser.vPlaylistItems[0].file, &value); - m_sessionCookie = value; + m_startParser = cM3u8Parser(); + res = m_startParser.Parse(startFile); + if(res) { + // Get GUID + pcrecpp::RE re("([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})", pcrecpp::RE_Options(PCRE_CASELESS)); + string value; + re.PartialMatch(m_startParser.vPlaylistItems[0].file, &value); + m_sessionCookie = value; + } + } catch (Poco::Exception &exc) { + esyslog("[plex] %s %s", __FUNCTION__, exc.displayText().c_str()); + res = false; } return res; } diff --git a/hlsPlayer.h b/hlsPlayer.h index 79e1abf..8b80378 100644 --- a/hlsPlayer.h +++ b/hlsPlayer.h @@ -50,6 +50,7 @@ private: int EstimateSegmentSize(); bool LoadLists(void); void ResizeRingbuffer(int newsize); + void SkipEmptySegments(int segmentLenght); protected: @@ -21,18 +21,20 @@ cPlexBrowser::cPlexBrowser(const char *title, std::shared_ptr<plexclient::Plexse pService->Authenticate(); if(pService == pLastService) { pCont = pService->GetLastSection(true); - } - else { + } else { pCont = pService->GetSection(pService->StartUri); } SetMenuCategory(mcRecording); CreateMenu(); } -cPlexBrowser* cPlexBrowser::RecoverLastState() +cPlexBrowser* cPlexBrowser::RecoverLastState() { - cPlexBrowser* pBrowser = new cPlexBrowser("", cPlexBrowser::pLastService); - return pBrowser; + if (cPlexBrowser::pLastService != NULL) { + cPlexBrowser* pBrowser = new cPlexBrowser("", cPlexBrowser::pLastService); + return pBrowser; + } + return NULL; } void cPlexBrowser::CreateMenu() @@ -57,14 +59,13 @@ void cPlexBrowser::CreateMenu() if(Count() < 1) { Add(new cPlexOsdItem("Empty")); - } - else if (pService == pLastService) { + } else if (pService == pLastService) { // recover last selected item cOsdItem* item = Get(lastCurrentItem); SetCurrent(item); pLastService = NULL; } - + Display(); } @@ -196,7 +197,7 @@ cPlayMenu::cPlayMenu(const char *title, int c0, int c1, int c2, int c3, int c4) auto s1 = std::make_shared<plexclient::Plexservice>( &(*it) ); s1->StartUri = "/library/sections"; Add(new cPlexOsdItem(Poco::format("%s - Library", it->GetServerName()).c_str(), s1)); - + auto s2 = std::make_shared<plexclient::Plexservice>( &(*it) ); s2->StartUri = "/video"; Add(new cPlexOsdItem(Poco::format("%s - Video Channels", it->GetServerName()).c_str(), s2 )); @@ -324,12 +325,12 @@ const char *cMyPlugin::MainMenuEntry(void) cOsdObject *cMyPlugin::MainMenuAction(void) { //dsyslog("[plex]%s:\n", __FUNCTION__); - + if(CalledFromCode) { CalledFromCode = false; return cPlexBrowser::RecoverLastState(); } - + if (ShowBrowser) { return new cPlexBrowser("Browse Plex", pPlexService); } |