diff options
author | chriszero <zerov83@gmail.com> | 2015-02-11 15:57:06 +0100 |
---|---|---|
committer | chriszero <zerov83@gmail.com> | 2015-02-11 15:57:06 +0100 |
commit | 2ee181403f1c332ee34f658916035524e766cd7b (patch) | |
tree | 1bee6b63cd3df9c105e976f6edd0e383887c23b2 | |
parent | 158d1055599205ccca462f97c190994fa28af8f0 (diff) | |
download | vdr-plugin-plex-2ee181403f1c332ee34f658916035524e766cd7b.tar.gz vdr-plugin-plex-2ee181403f1c332ee34f658916035524e766cd7b.tar.bz2 |
Fixes proper handling of "end of stream".
Proper display of totaltime when playing a Plexchannel
-rw-r--r-- | SubscriptionManager.cpp | 4 | ||||
-rw-r--r-- | hlsPlayer.cpp | 34 | ||||
-rw-r--r-- | hlsPlayer.h | 2 |
3 files changed, 32 insertions, 8 deletions
diff --git a/SubscriptionManager.cpp b/SubscriptionManager.cpp index e9830df..a6f35c5 100644 --- a/SubscriptionManager.cpp +++ b/SubscriptionManager.cpp @@ -234,9 +234,7 @@ void Subscriber::SendUpdate(std::string msg, bool isNav) Poco::Net::HTTPResponse response; session.receiveResponse(response); - } catch (Poco::Exception& e) { - std::cout << e.displayText() << std::endl; - } + } catch (Poco::Exception& e) {} } ActionManager::ActionManager() {} diff --git a/hlsPlayer.cpp b/hlsPlayer.cpp index 96c0f55..df62b0d 100644 --- a/hlsPlayer.cpp +++ b/hlsPlayer.cpp @@ -23,6 +23,7 @@ cHlsSegmentLoader::cHlsSegmentLoader(std::string startm3u8) m_bufferFilled = false; m_lastLoadedSegment = 0; m_segmentsToBuffer = 2; + m_streamlenght = 0; m_pBuffer = new uchar[8192]; // Initialize members @@ -75,7 +76,9 @@ void cHlsSegmentLoader::Action(void) isyslog("[plex] Ringbuffer Cleared, loading new segments"); hlsMutex.Unlock(); } - if (!DoLoad() && m_pRingbuffer->Available() < TS_SIZE) { + int count = 0; + m_pRingbuffer->Get(count); + if (!DoLoad() && count < TS_SIZE) { isyslog("[plex] No further segments to load and buffer empty, end of stream!"); Cancel(); @@ -137,6 +140,12 @@ bool cHlsSegmentLoader::LoadIndexList(void) } else { m_segmentsToBuffer = 3; } + + // Get stream lenght + m_streamlenght = 0; + for(unsigned int i = 0; i < m_indexParser.vPlaylistItems.size(); i++) { + m_streamlenght += m_indexParser.vPlaylistItems[i].length; + } } return res; } @@ -237,7 +246,7 @@ int cHlsSegmentLoader::GetSegmentSize(int segmentIndex) return m_indexParser.vPlaylistItems[segmentIndex].size = reqResponse.getContentLength(); } catch(Poco::IOException& exc) { esyslog("[plex]%s %s ", __FUNCTION__, exc.displayText().c_str()); - return INT_MAX; + return 0; } } @@ -363,6 +372,11 @@ void cHlsSegmentLoader::ResizeRingbuffer(int newsize) hlsMutex.Unlock(); } +int cHlsSegmentLoader::GetStreamLenght() +{ + return m_streamlenght; +} + //--- cHlsPlayer cHlsPlayer::cHlsPlayer(std::string startm3u8, plexclient::Video* Video, int offset) @@ -382,6 +396,7 @@ cHlsPlayer::cHlsPlayer(std::string startm3u8, plexclient::Video* Video, int offs cHlsPlayer::~cHlsPlayer() { dsyslog("[plex]: '%s'", __FUNCTION__); + Cancel(); delete m_pSegmentLoader; m_pSegmentLoader = NULL; Detach(); @@ -491,8 +506,14 @@ void cHlsPlayer::Activate(bool On) bool cHlsPlayer::GetIndex(int& Current, int& Total, bool SnapToIFrame __attribute__((unused))) { - Total = m_pVideo->m_Media.m_lDuration / 1000 * FramesPerSecond(); // milliseconds - Current = GetPlayedSeconds() * FramesPerSecond(); + if(m_pVideo) { + if( m_pVideo->m_Media.m_lDuration == 0) { + Total = m_pSegmentLoader->GetStreamLenght() * FramesPerSecond(); + } else { + Total = m_pVideo->m_Media.m_lDuration / 1000 * FramesPerSecond(); // milliseconds + } + Current = GetPlayedSeconds() * FramesPerSecond(); + } return true; } @@ -543,7 +564,10 @@ void cHlsPlayer::Stop(void) double cHlsPlayer::FramesPerSecond(void) { - return m_pVideo->m_Media.m_VideoFrameRate ? m_pVideo->m_Media.m_VideoFrameRate : DEFAULTFRAMESPERSECOND; + if(m_pVideo) { + return m_pVideo->m_Media.m_VideoFrameRate ? m_pVideo->m_Media.m_VideoFrameRate : DEFAULTFRAMESPERSECOND; + } + return DEFAULTFRAMESPERSECOND; } void cHlsPlayer::JumpRelative(int seconds) diff --git a/hlsPlayer.h b/hlsPlayer.h index 111a367..ee27049 100644 --- a/hlsPlayer.h +++ b/hlsPlayer.h @@ -27,6 +27,7 @@ private: unsigned int m_lastLoadedSegment; bool m_bufferFilled; bool m_newList; + int m_streamlenght; uchar* m_pBuffer; @@ -66,6 +67,7 @@ public: bool LoadM3u8(std::string uri); void AddHeader(Poco::Net::HTTPRequest& req); void Ping(void); + int GetStreamLenght(); }; class cHlsPlayer : public cPlayer, cThread |