summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hlsPlayer.cpp22
-rw-r--r--hlsPlayer.h1
-rw-r--r--hlsPlayerControl.cpp8
-rw-r--r--hlsPlayerControl.h1
-rw-r--r--plex.cpp213
5 files changed, 123 insertions, 122 deletions
diff --git a/hlsPlayer.cpp b/hlsPlayer.cpp
index 9245efb..d53c025 100644
--- a/hlsPlayer.cpp
+++ b/hlsPlayer.cpp
@@ -1,6 +1,6 @@
#include "hlsPlayer.h"
-#include <sys/time.h>
+#include <vdr/tools.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Exception.h>
@@ -341,6 +341,7 @@ cHlsPlayer::~cHlsPlayer()
{
delete m_pSegmentLoader;
m_pSegmentLoader = NULL;
+ Detach();
}
void cHlsPlayer::SetAudioAndSubtitleTracks(void)
@@ -363,6 +364,8 @@ void cHlsPlayer::Action(void)
{
// Start SegmentLoader
m_pSegmentLoader->Start();
+
+ m_bFirstPlay = true;
while (Running()) {
if(m_doJump && m_pSegmentLoader && m_pSegmentLoader->BufferFilled()) {
@@ -382,6 +385,7 @@ void cHlsPlayer::Action(void)
if(m_bFirstPlay) {
SetAudioAndSubtitleTracks();
ResetPlayedSeconds();
+ playMode = pmPlay;
m_bFirstPlay = false;
}
CountPlayedSeconds();
@@ -390,6 +394,8 @@ void cHlsPlayer::Action(void)
cCondWait::SleepMs(3);
}
}
+
+ DeviceClear();
}
bool cHlsPlayer::DoPlay(void)
@@ -500,6 +506,7 @@ void cHlsPlayer::JumpTo(int seconds)
void cHlsPlayer::SetAudioTrack(eTrackType Type __attribute__((unused)), const tTrackId* TrackId)
{
+ LOCK_THREAD;
dsyslog("[plex]%s %d %s", __FUNCTION__, TrackId->id, TrackId->language);
// Check if stream availiable
int streamId = 0;
@@ -533,13 +540,6 @@ void cHlsPlayer::SetAudioTrack(eTrackType Type __attribute__((unused)), const tT
}
}
-unsigned long long cHlsPlayer::MsNow(void)
-{
- static timeval tv;
- gettimeofday(&tv, 0);
- return tv.tv_sec * 1000 + tv.tv_usec / 1000;
-}
-
int cHlsPlayer::GetPlayedSeconds(void)
{
return m_timeOffset + (m_tTimeSum / 1000);
@@ -548,17 +548,17 @@ int cHlsPlayer::GetPlayedSeconds(void)
void cHlsPlayer::CountPlayedSeconds(void)
{
if (playMode == pmPlay) {
- unsigned long long tTmp = MsNow();
+ unsigned long long tTmp = cTimeMs::Now();
m_tTimeSum += (tTmp - m_tLastTime);
m_tLastTime = tTmp;
}
else {
- m_tLastTime = MsNow();
+ m_tLastTime = cTimeMs::Now();
}
}
void cHlsPlayer::ResetPlayedSeconds(void)
{
m_tTimeSum = 0;
- m_tLastTime = MsNow();
+ m_tLastTime = cTimeMs::Now();
}
diff --git a/hlsPlayer.h b/hlsPlayer.h
index 49561d8..4144659 100644
--- a/hlsPlayer.h
+++ b/hlsPlayer.h
@@ -90,7 +90,6 @@ private:
ePlayModes playMode;
virtual void Activate(bool On);
- unsigned long long MsNow(void);
int GetPlayedSeconds(void);
void CountPlayedSeconds(void);
void ResetPlayedSeconds(void);
diff --git a/hlsPlayerControl.cpp b/hlsPlayerControl.cpp
index f4e1330..b458f87 100644
--- a/hlsPlayerControl.cpp
+++ b/hlsPlayerControl.cpp
@@ -16,8 +16,7 @@ cControl* cHlsPlayerControl::Create(plexclient::Video* Video)
// get Metadata
std::string uri = Video->m_pServer->GetUri() + Video->m_sKey;
plexclient::MediaContainer *pmcontainer = plexclient::Plexservice::GetMediaContainer(uri);
-
- std::cout << "Video Size" << pmcontainer->m_vVideos.size() << " Video: " << pmcontainer->m_vVideos[0].m_sKey << std::endl;
+
std::string transcodeUri = plexclient::Plexservice::GetUniversalTranscodeUrl(&pmcontainer->m_vVideos[0]);
cHlsPlayerControl* playerControl = new cHlsPlayerControl(new cHlsPlayer(transcodeUri, &pmcontainer->m_vVideos[0]), pmcontainer);
@@ -41,11 +40,6 @@ cHlsPlayerControl::cHlsPlayerControl(cHlsPlayer* Player, plexclient::MediaContai
cStatus::MsgReplaying(this, m_title.c_str(), m_pVideo->m_Media.m_sPartFile.c_str(), true);
}
-cHlsPlayerControl::~cHlsPlayerControl()
-{
- //delete m_pMediaContainer;
-}
-
cString cHlsPlayerControl::GetHeader(void)
{
return m_title.c_str();
diff --git a/hlsPlayerControl.h b/hlsPlayerControl.h
index 2f7347b..9b51c97 100644
--- a/hlsPlayerControl.h
+++ b/hlsPlayerControl.h
@@ -34,7 +34,6 @@ protected:
public:
static cControl* Create(plexclient::Video* Video);
cHlsPlayerControl(cHlsPlayer* Player, plexclient::MediaContainer* Container);
- virtual ~cHlsPlayerControl();
virtual void Show(void);
virtual void Hide(void);
diff --git a/plex.cpp b/plex.cpp
index 9ae6acf..9ef5c4d 100644
--- a/plex.cpp
+++ b/plex.cpp
@@ -17,8 +17,11 @@ static const char *MAINMENUENTRY = "Plex for VDR";
*/
static void PlayFile(plexclient::Video* pVid)
{
- isyslog("[plex]: play file '%s'\n", pVid->m_sKey.c_str());
- cControl::Launch(cHlsPlayerControl::Create(pVid));
+ isyslog("[plex]: play file '%s'\n", pVid->m_sKey.c_str());
+ cControl* control = cHlsPlayerControl::Create(pVid);
+ if(control) {
+ cControl::Launch(control);
+ }
}
//////////////////////////////////////////////////////////////////////////////
@@ -29,119 +32,125 @@ static void PlayFile(plexclient::Video* pVid)
static char ShowBrowser; ///< flag show browser
static plexclient::PlexServer* pPlexServer;
-cPlexBrowser::cPlexBrowser(const char *title, plexclient::PlexServer* pServ) :cOsdMenu(title) {
-
+cPlexBrowser::cPlexBrowser(const char *title, plexclient::PlexServer* pServ) :cOsdMenu(title)
+{
+
dsyslog("[plex]%s:\n", __FUNCTION__);
pService = new plexclient::Plexservice(pServ);
pService->Authenticate();
- pCont = pService->GetAllSections();
+ pCont = pService->GetAllSections();
CreateMenu();
}
-cPlexBrowser::~cPlexBrowser() {
+cPlexBrowser::~cPlexBrowser()
+{
delete pService;
}
-void cPlexBrowser::CreateMenu() {
+void cPlexBrowser::CreateMenu()
+{
// Clear Menu
Clear();
// Directory or Video?
if(pCont->m_vDirectories.size() > 0) {
-
+
for(std::vector<plexclient::Directory>::iterator it = pCont->m_vDirectories.begin(); it != pCont->m_vDirectories.end(); ++it) {
plexclient::Directory *pDir = &(*it);
Add(new cPlexOsdItem( pDir->m_sTitle.c_str(), pDir) );
}
- }
-
+ }
+
if(pCont->m_vVideos.size() > 0) {
for(std::vector<plexclient::Video>::iterator it = pCont->m_vVideos.begin(); it != pCont->m_vVideos.end(); ++it) {
plexclient::Video *vid = &(*it); // cast raw pointer
Add(new cPlexOsdItem( vid->m_sTitle.c_str(), vid) );
- }
+ }
}
-
+
if(Count() < 1) {
Add(new cPlexOsdItem("Empty"));
}
-
+
Display();
}
-eOSState cPlexBrowser::ProcessKey(eKeys key) {
+eOSState cPlexBrowser::ProcessKey(eKeys key)
+{
eOSState state;
- // call standard function
- state = cOsdMenu::ProcessKey(key);
- if (state || key != kNone) {
+ // call standard function
+ state = cOsdMenu::ProcessKey(key);
+ if (state || key != kNone) {
dsyslog("[plex]%s: state=%d key=%d\n", __FUNCTION__, state, key);
- }
+ }
- switch (state) {
+ switch (state) {
case osUnknown:
- switch (key) {
+ switch (key) {
case kOk:
- return ProcessSelected();
+ return ProcessSelected();
case kBack:
return LevelUp();
default:
- break;
- }
- break;
+ break;
+ }
+ break;
case osBack:
- state = LevelUp();
- if (state == osEnd) { // top level reached
+ state = LevelUp();
+ if (state == osEnd) { // top level reached
return osPlugin;
- }
+ }
default:
- break;
- }
- return state;
+ break;
+ }
+ return state;
}
-eOSState cPlexBrowser::LevelUp() {
- if(m_vStack.size() <= 1){
+eOSState cPlexBrowser::LevelUp()
+{
+ if(m_vStack.size() <= 1) {
m_vStack.clear();
ShowBrowser = 0;
return osEnd;
}
-
+
m_vStack.pop_back();
-
+
std::string uri;
for(unsigned int i = 0; i < m_vStack.size(); i++) {
- if(m_vStack[i][0]=='/') {
- uri = m_vStack[i];
- continue;
- }
- uri += m_vStack[i];
- if(i+1 < m_vStack.size()) {
- uri += "/";
- }
+ if(m_vStack[i][0]=='/') {
+ uri = m_vStack[i];
+ continue;
}
-
+ uri += m_vStack[i];
+ if(i+1 < m_vStack.size()) {
+ uri += "/";
+ }
+ }
+
pCont = pService->GetSection(uri);
-
+
CreateMenu();
return osContinue;
}
-eOSState cPlexBrowser::ProcessSelected() {
- int current = Current(); // get current menu item index
- cPlexOsdItem *item = static_cast<cPlexOsdItem*>(Get(current));
-
-
+eOSState cPlexBrowser::ProcessSelected()
+{
+ int current = Current(); // get current menu item index
+ cPlexOsdItem *item = static_cast<cPlexOsdItem*>(Get(current));
+
+
if(item->IsVideo()) {
- plexclient::Video* pVid = item->GetAttachedVideo();
+ plexclient::Video* pVid = item->GetAttachedVideo();
PlayFile(pVid);
return osEnd;
}
-
-
+
+
if(item->IsDir()) {
plexclient::Directory* pDir = item->GetAttachedDirectory();
-
+
m_vStack.push_back(pDir->m_sKey);
std::string uri;
for(unsigned int i = 0; i < m_vStack.size(); i++) {
@@ -155,15 +164,15 @@ eOSState cPlexBrowser::ProcessSelected() {
}
}
std::cout << "m_sSection: " << uri << std::endl;
-
+
pCont = pService->GetSection(uri);
-
+
CreateMenu();
return osContinue;
}
-
+
//return osEnd;
- return osContinue;
+ return osContinue;
}
@@ -175,15 +184,15 @@ eOSState cPlexBrowser::ProcessSelected() {
** Play menu constructor.
*/
cPlayMenu::cPlayMenu(const char *title, int c0, int c1, int c2, int c3, int c4)
-:cOsdMenu(title, c0, c1, c2, c3, c4)
+ :cOsdMenu(title, c0, c1, c2, c3, c4)
{
SetHasHotkeys();
-
+
for(std::vector<plexclient::PlexServer>::iterator it = plexclient::plexgdm::GetInstance().GetPlexservers().begin(); it != plexclient::plexgdm::GetInstance().GetPlexservers().end(); ++it) {
plexclient::PlexServer *pServer = &(*it);
Add(new cPlexOsdItem(pServer->GetServerName().c_str(), pServer));
}
-
+
if(Count() < 1) {
Add(new cPlexOsdItem("No Plex Media Server found."), false);
}
@@ -203,31 +212,31 @@ cPlayMenu::~cPlayMenu()
*/
eOSState cPlayMenu::ProcessKey(eKeys key)
{
- eOSState state;
-
- if (key != kNone) {
- dsyslog("[plex]%s: key=%d\n", __FUNCTION__, key);
- }
- // call standard function
- state = cOsdMenu::ProcessKey(key);
-
+ eOSState state;
+
+ if (key != kNone) {
+ dsyslog("[plex]%s: key=%d\n", __FUNCTION__, key);
+ }
+ // call standard function
+ state = cOsdMenu::ProcessKey(key);
+
int current = Current(); // get current menu item index
cPlexOsdItem *item = static_cast<cPlexOsdItem*>(Get(current));
-
- switch (state) {
- case osUnknown:
- switch (key) {
- case kOk:
- pPlexServer = item->GetAttachedServer();
- ShowBrowser = 1;
- return osPlugin; // restart with OSD browser
- default:
- break;
- }
+
+ switch (state) {
+ case osUnknown:
+ switch (key) {
+ case kOk:
+ pPlexServer = item->GetAttachedServer();
+ ShowBrowser = 1;
+ return osPlugin; // restart with OSD browser
default:
break;
- }
- return state;
+ }
+ default:
+ break;
+ }
+ return state;
}
//////////////////////////////////////////////////////////////////////////////
@@ -242,7 +251,7 @@ eOSState cPlayMenu::ProcessKey(eKeys key)
*/
cMyPlugin::cMyPlugin(void)
{
- dsyslog("[plex]%s:\n", __FUNCTION__);
+ dsyslog("[plex]%s:\n", __FUNCTION__);
}
/**
@@ -250,7 +259,7 @@ cMyPlugin::cMyPlugin(void)
*/
cMyPlugin::~cMyPlugin(void)
{
- dsyslog("[plex]%s:\n", __FUNCTION__);
+ dsyslog("[plex]%s:\n", __FUNCTION__);
plexclient::plexgdm::GetInstance().stopRegistration();
plexclient::ControlServer::GetInstance().Stop();
}
@@ -262,7 +271,7 @@ cMyPlugin::~cMyPlugin(void)
*/
const char *cMyPlugin::Version(void)
{
- return VERSION;
+ return VERSION;
}
/**
@@ -272,7 +281,7 @@ const char *cMyPlugin::Version(void)
*/
const char *cMyPlugin::Description(void)
{
- return DESCRIPTION;
+ return DESCRIPTION;
}
/**
@@ -280,22 +289,22 @@ const char *cMyPlugin::Description(void)
*/
bool cMyPlugin::Initialize(void)
{
- // First Startup? Save UUID
+ // First Startup? Save UUID
SetupStore("UUID", Config::GetInstance().GetUUID().c_str());
-
+
plexclient::plexgdm::GetInstance().discover();
-
+
if (plexclient::plexgdm::GetInstance().GetPlexservers().size() > 0) {
plexclient::plexgdm::GetInstance().clientDetails(Config::GetInstance().GetUUID(), DESCRIPTION, "3200", "VDR", VERSION);
plexclient::plexgdm::GetInstance().Start();
-
+
plexclient::ControlServer::GetInstance().Start();
-
+
} else {
esyslog("[plex]No Plexmediaserver found");
}
- return true;
+ return true;
}
/**
@@ -303,7 +312,7 @@ bool cMyPlugin::Initialize(void)
*/
const char *cMyPlugin::MainMenuEntry(void)
{
- return Config::GetInstance().HideMainMenuEntry ? NULL : MAINMENUENTRY;
+ return Config::GetInstance().HideMainMenuEntry ? NULL : MAINMENUENTRY;
}
/**
@@ -311,12 +320,12 @@ const char *cMyPlugin::MainMenuEntry(void)
*/
cOsdObject *cMyPlugin::MainMenuAction(void)
{
- //dsyslog("[plex]%s:\n", __FUNCTION__);
+ //dsyslog("[plex]%s:\n", __FUNCTION__);
- if (ShowBrowser) {
+ if (ShowBrowser) {
return new cPlexBrowser("Browse Plex", pPlexServer);
- }
- return new cPlayMenu("Plex");
+ }
+ return new cPlayMenu("Plex");
}
/**
@@ -325,7 +334,7 @@ cOsdObject *cMyPlugin::MainMenuAction(void)
*/
void cMyPlugin::MainThreadHook(void)
{
- // dsyslog("[plex]%s:\n", __FUNCTION__);
+ // dsyslog("[plex]%s:\n", __FUNCTION__);
// Start Tasks, e.g. Play Video
if(plexclient::ActionManager::GetInstance().IsAction()) {
std::string file = plexclient::ActionManager::GetInstance().GetAction();
@@ -338,9 +347,9 @@ void cMyPlugin::MainThreadHook(void)
*/
cMenuSetupPage *cMyPlugin::SetupMenu(void)
{
- //dsyslog("[plex]%s:\n", __FUNCTION__);
+ //dsyslog("[plex]%s:\n", __FUNCTION__);
- return new cMyMenuSetupPage;
+ return new cMyMenuSetupPage;
}
/**
@@ -353,15 +362,15 @@ cMenuSetupPage *cMyPlugin::SetupMenu(void)
*/
bool cMyPlugin::SetupParse(const char *name, const char *value)
{
- //dsyslog("[plex]%s: '%s' = '%s'\n", __FUNCTION__, name, value);
+ //dsyslog("[plex]%s: '%s' = '%s'\n", __FUNCTION__, name, value);
- if (strcasecmp(name, "HideMainMenuEntry") == 0) Config::GetInstance().HideMainMenuEntry = atoi(value) ? true : false;
+ if (strcasecmp(name, "HideMainMenuEntry") == 0) Config::GetInstance().HideMainMenuEntry = atoi(value) ? true : false;
else if (strcasecmp(name, "Username") == 0) Config::GetInstance().s_username = std::string(value);
else if (strcasecmp(name, "Password") == 0) Config::GetInstance().s_password = std::string(value);
else if (strcasecmp(name, "UUID") == 0) Config::GetInstance().SetUUID(value);
else return false;
- return true;
+ return true;
}
VDRPLUGINCREATOR(cMyPlugin); // Don't touch this!