From 004e8940e25c3bca2b9219a5494e80b3c9b3ab9c Mon Sep 17 00:00:00 2001 From: chriszero Date: Sun, 27 Sep 2015 15:52:23 +0200 Subject: Own replay control for skinning --- Makefile | 3 +- Plexservice.cpp | 17 +- hlsPlayer.cpp | 13 + hlsPlayer.h | 1 + hlsPlayerControl.h | 1 + plex.cpp | 5 + plexSdOsd.h | 1 + sdDisplayReplay.cpp | 131 +++++++ sdDisplayReplay.h | 48 +++ .../themes/default/skinparts/plexplaceholder.svg | 130 ------- skins/blackhole/xmlfiles/plug-plex-detail.xml | 16 - skins/blackhole/xmlfiles/plug-plex-root.xml | 405 --------------------- 12 files changed, 216 insertions(+), 555 deletions(-) create mode 100644 sdDisplayReplay.cpp create mode 100644 sdDisplayReplay.h delete mode 100644 skins/blackhole/themes/default/skinparts/plexplaceholder.svg delete mode 100644 skins/blackhole/xmlfiles/plug-plex-detail.xml delete mode 100644 skins/blackhole/xmlfiles/plug-plex-root.xml diff --git a/Makefile b/Makefile index b11e68e..d75fe52 100644 --- a/Makefile +++ b/Makefile @@ -95,7 +95,8 @@ OBJS = $(PLUGIN).o \ browserGrid.o \ viewHeader.o \ detailView.o \ - pictureCache.o + pictureCache.o \ + sdDisplayReplay.o SRCS = $(wildcard $(OBJS:.o=.c)) $(PLUGIN).cpp diff --git a/Plexservice.cpp b/Plexservice.cpp index 20db51e..0a7cd58 100644 --- a/Plexservice.cpp +++ b/Plexservice.cpp @@ -194,11 +194,13 @@ std::string Plexservice::GetUniversalTranscodeUrl(Video* video, int offset, Plex { PlexServer* pSrv = server ? server : video->m_pServer; std::stringstream params; - params << "/video/:/transcode/universal/start.m3u8?"; + //params << "/video/:/transcode/universal/start.m3u8?"; + params << "/video/:/transcode/universal/start?"; params << "path=" << encode(pSrv->GetUri() + video->m_sKey); params << "&mediaIndex=0"; params << "&partIndex=0"; params << "&protocol=hls"; + //params << "&protocol=dash"; params << "&offset=" << offset; params << "&fastSeek=1"; params << "&directPlay=0"; @@ -211,8 +213,17 @@ std::string Plexservice::GetUniversalTranscodeUrl(Video* video, int offset, Plex params << "&videoResolution=1920x1080"; params << "&videoQuality=100"; params << "&session=" << encode(Config::GetInstance().GetUUID()); // TODO: generate Random SessionID - - + + params << "&X-Plex-Client-Identifier=" << encode(Config::GetInstance().GetUUID()); + params << "&X-Plex-Device=PC"; + params << "&X-Plex-Device-Name=" << encode(Config::GetInstance().GetHostname()); + params << "&X-Plex-Language=" << Config::GetInstance().GetLanguage(); + params << "&X-Plex-Model=Linux"; + params << "&X-Plex-Platform=" << encode("VDR Plex Plugin");; + params << "&X-Plex-Product=" << encode("VDR Plex Plugin"); + params << "&X-Plex-Provides=player"; + + //std::cout << pSrv->GetUri() << params.str() << std::endl; return pSrv->GetUri() + params.str(); } diff --git a/hlsPlayer.cpp b/hlsPlayer.cpp index 4a19a2a..8e0892c 100644 --- a/hlsPlayer.cpp +++ b/hlsPlayer.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "Plexservice.h" #include "XmlObject.h" @@ -438,12 +439,20 @@ cHlsPlayer::cHlsPlayer(std::string startm3u8, plexclient::Video Video, int offse m_isBuffering = false; AudioIndexOffset = 1000; // Just a magic number m_tTimer.Set(1); + m_pDebugFile = NULL; + + m_pDebugFile = new std::ofstream(); + m_pDebugFile->open("debug.ts", std::ios::out); } cHlsPlayer::~cHlsPlayer() { dsyslog("[plex]: '%s'", __FUNCTION__); Cancel(); + if(m_pDebugFile) m_pDebugFile->close(); + delete m_pDebugFile; + m_pDebugFile = NULL; + delete m_pSegmentLoader; m_pSegmentLoader = NULL; Detach(); @@ -530,6 +539,10 @@ bool cHlsPlayer::DoPlay(void) uchar* toPlay = m_pSegmentLoader->m_pRingbuffer->Get(bytesAvaliable); if(bytesAvaliable >= TS_SIZE) { int playedBytes = PlayTs(toPlay, TS_SIZE, false); + // save stream to disk to debug data + if(m_pDebugFile) + m_pDebugFile-> write((char*)toPlay, playedBytes); + m_pSegmentLoader->m_pRingbuffer->Del(playedBytes); res = true; } else { diff --git a/hlsPlayer.h b/hlsPlayer.h index f08505a..1e88deb 100644 --- a/hlsPlayer.h +++ b/hlsPlayer.h @@ -75,6 +75,7 @@ public: class cHlsPlayer : public cPlayer, cThread { private: + std::ofstream* m_pDebugFile; int AudioIndexOffset; cHlsSegmentLoader* m_pSegmentLoader; plexclient::Video m_Video; diff --git a/hlsPlayerControl.h b/hlsPlayerControl.h index fb2ba3f..90dc0e2 100644 --- a/hlsPlayerControl.h +++ b/hlsPlayerControl.h @@ -3,6 +3,7 @@ #include #include +//#include #include "hlsPlayer.h" #include "MediaContainer.h" diff --git a/plex.cpp b/plex.cpp index cf09120..d4b3030 100644 --- a/plex.cpp +++ b/plex.cpp @@ -5,6 +5,7 @@ #include "plexSdOsd.h" #include "pictureCache.h" #include "services.h" +#include "sdDisplayReplay.h" #include @@ -73,6 +74,10 @@ bool cMyPlugin::Start(void) reg.SetViewElement(viRootView, verWatch, "time"); reg.SetViewElement(viRootView, verMessage, "message"); reg.SetViewElement(viRootView, verScrollbar, "scrollbar"); + + reg.SetView(viReplay, "replay.xml"); + reg.SetViewElement(viReplay, cSdDisplayReplay::eElements::Info, "info"); + reg.SetViewElement(viReplay, cSdDisplayReplay::eElements::Replay, "replay"); /* reg.SetSubView(viRootView, viDetailView, "detail.xml"); reg.SetViewElement(viDetailView, vedBackground, "background"); diff --git a/plexSdOsd.h b/plexSdOsd.h index bacf3dc..d620001 100644 --- a/plexSdOsd.h +++ b/plexSdOsd.h @@ -22,6 +22,7 @@ enum eViews { viRootView, + viReplay, viDetailView }; diff --git a/sdDisplayReplay.cpp b/sdDisplayReplay.cpp new file mode 100644 index 0000000..8e67904 --- /dev/null +++ b/sdDisplayReplay.cpp @@ -0,0 +1,131 @@ +#include "sdDisplayReplay.h" +#include "plexSdOsd.h" + +cSdDisplayReplay::cSdDisplayReplay(plexclient::Video Video, cHlsPlayerControl* Control) +{ + m_video = Video; + m_pContol = Control; + m_pRootView = NULL; + m_lastsecond = 0; +} + +cSdDisplayReplay::~cSdDisplayReplay() +{ + delete m_pRootView; +} + +void cSdDisplayReplay::Show(void) +{ + bool skinDesignerAvailable = InitSkindesignerInterface("plex"); + if (!skinDesignerAvailable) { + return; + } + + m_pRootView = GetOsdView(eViews::viReplay); + if (!m_pRootView) { + esyslog("[plex]: used skindesigner skin does not support plex"); + return; + } + m_pInfo = std::shared_ptr(m_pRootView->GetViewElement(eElements::Info)); + m_pReplay = std::shared_ptr(m_pRootView->GetViewElement(eElements::Replay)); + m_pTime = std::shared_ptr(m_pRootView->GetViewElement(eElements::Time)); + m_pBackground = std::shared_ptr(m_pRootView->GetViewElement(eElements::Background)); +} + +//eOSState cSdDisplayReplay::ProcessKey(eKeys Key) +//{ +//} + +void cSdDisplayReplay::DrawInfo() +{ + m_pInfo->Clear(); + m_video.AddTokens(m_pInfo); +} + +void cSdDisplayReplay::DrawReplay() +{ + m_pReplay->ClearTokens(); + m_video.AddTokens(m_pReplay, false); + + int current, total; + m_pContol->GetIndex(current, total); + + m_pReplay->AddIntToken("progresstotal", total / m_pContol->FramesPerSecond()); + m_pReplay->AddIntToken("progresscurrent", current / m_pContol->FramesPerSecond()); + + bool play, forward; + int speed; + m_pContol->GetReplayMode(play, forward, speed); + + m_pReplay->AddIntToken("playing", speed >= 0); + m_pReplay->AddIntToken("pausing", !play); + //m_pReplay->AddIntToken("seeking", 0); + m_pReplay->AddStringToken("totaltime", IndexToHMS(total)); + m_pReplay->AddStringToken("currenttime", IndexToHMS(current)); + m_pReplay->AddStringToken("endtime", "hh:mm"); +} + +void cSdDisplayReplay::Flush() +{ + m_pInfo->Display(); + m_pReplay->Display(); + m_pRootView->Display(); +} + +bool cSdDisplayReplay::DrawTime() +{ + time_t t = time(0); // get time now + struct tm * now = localtime(&t); + int sec = now->tm_sec; + if (sec == m_lastsecond) + return false; + + int min = now->tm_min; + int hour = now->tm_hour; + int hourMinutes = hour%12 * 5 + min / 12; + + char monthname[20]; + char monthshort[10]; + strftime(monthshort, sizeof(monthshort), "%b", now); + strftime(monthname, sizeof(monthname), "%B", now); + + m_pTime->Clear(); + m_pTime->ClearTokens(); + m_pTime->AddIntToken("sec", sec); + m_pTime->AddIntToken("min", min); + m_pTime->AddIntToken("hour", hour); + m_pTime->AddIntToken("hmins", hourMinutes); + m_pTime->AddIntToken("year", now->tm_year + 1900); + m_pTime->AddIntToken("day", now->tm_mday); + m_pTime->AddStringToken("time", *TimeString(t)); + m_pTime->AddStringToken("monthname", monthname); + m_pTime->AddStringToken("monthnameshort", monthshort); + m_pTime->AddStringToken("month", *cString::sprintf("%02d", now->tm_mon + 1)); + m_pTime->AddStringToken("dayleadingzero", *cString::sprintf("%02d", now->tm_mday)); + m_pTime->AddStringToken("dayname", *WeekDayNameFull(now->tm_wday)); + m_pTime->AddStringToken("daynameshort", *WeekDayName(now->tm_wday)); + m_pTime->Display(); + + m_lastsecond = sec; + return true; +} + +std::string cSdDisplayReplay::IndexToHMS(int Index, bool WithSeconds) +{ + std::stringstream ss; + if (Index < 0) { + Index = -Index; + ss << "-"; + } + + int s = Index / m_pContol->FramesPerSecond(); + int m = s / 60 % 60; + int h = s / 3600; + s %= 60; + ss << h << ":" << m; + + if(WithSeconds) { + ss << ":" << s; + } + return ss.str(); +} diff --git a/sdDisplayReplay.h b/sdDisplayReplay.h new file mode 100644 index 0000000..e580e16 --- /dev/null +++ b/sdDisplayReplay.h @@ -0,0 +1,48 @@ +#ifndef CSDDISPLAYREPLAY_H +#define CSDDISPLAYREPLAY_H + +#include +#include +#include +#include + +#include "PVideo.h" +#include "hlsPlayerControl.h" + +class cSdDisplayReplay : public skindesignerapi::cSkindesignerOsdObject +{ +public: + enum eElements { + Background, + Replay, + Info, + Time + }; + + cSdDisplayReplay(plexclient::Video Video, cHlsPlayerControl* Control); + ~cSdDisplayReplay(); + + virtual void Show(void); + //virtual eOSState ProcessKey(eKeys Key); + +private: + plexclient::Video m_video; + cHlsPlayerControl* m_pContol; + + skindesignerapi::cOsdView* m_pRootView; + std::shared_ptr m_pBackground; + std::shared_ptr m_pReplay; + std::shared_ptr m_pInfo; + std::shared_ptr m_pTime; + + int m_lastsecond; + + void DrawReplay(); + void DrawInfo(); + bool DrawTime(); + void Flush(); + + std::string IndexToHMS(int index, bool WithSeconds = true); +}; + +#endif // CSDDISPLAYREPLAY_H diff --git a/skins/blackhole/themes/default/skinparts/plexplaceholder.svg b/skins/blackhole/themes/default/skinparts/plexplaceholder.svg deleted file mode 100644 index 747b38d..0000000 --- a/skins/blackhole/themes/default/skinparts/plexplaceholder.svg +++ /dev/null @@ -1,130 +0,0 @@ - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - diff --git a/skins/blackhole/xmlfiles/plug-plex-detail.xml b/skins/blackhole/xmlfiles/plug-plex-detail.xml deleted file mode 100644 index 425d18f..0000000 --- a/skins/blackhole/xmlfiles/plug-plex-detail.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/skins/blackhole/xmlfiles/plug-plex-root.xml b/skins/blackhole/xmlfiles/plug-plex-root.xml deleted file mode 100644 index 04b33c8..0000000 --- a/skins/blackhole/xmlfiles/plug-plex-root.xml +++ /dev/null @@ -1,405 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3