gui/movieplayer.cpp: try to fix starting MB playback on webtv channel:

create another CMoviePlayerGui instance for background playback.
remove define __STDC_CONSTANT_MACROS, should be added to CXXFLAGS
This commit is contained in:
[CST] Focus
2015-10-07 13:41:58 +03:00
parent b34c31e8df
commit 21aeb82d49
2 changed files with 57 additions and 29 deletions

View File

@@ -27,7 +27,6 @@
#include <config.h> #include <config.h>
#endif #endif
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS
#include <stdint.h> #include <stdint.h>
#include <global.h> #include <global.h>
@@ -77,8 +76,14 @@ extern CInfoClock *InfoClock;
#define ISO_MOUNT_POINT "/media/iso" #define ISO_MOUNT_POINT "/media/iso"
CMoviePlayerGui* CMoviePlayerGui::instance_mp = NULL; CMoviePlayerGui* CMoviePlayerGui::instance_mp = NULL;
CMoviePlayerGui* CMoviePlayerGui::instance_bg = NULL;
OpenThreads::Mutex CMoviePlayerGui::mutex;
OpenThreads::Mutex CMoviePlayerGui::bgmutex; OpenThreads::Mutex CMoviePlayerGui::bgmutex;
OpenThreads::Condition CMoviePlayerGui::cond; OpenThreads::Condition CMoviePlayerGui::cond;
pthread_t CMoviePlayerGui::bgThread;
cPlayback *CMoviePlayerGui::playback;
CMovieBrowser* CMoviePlayerGui::moviebrowser;
CBookmarkManager * CMoviePlayerGui::bookmarkmanager;
CMoviePlayerGui& CMoviePlayerGui::getInstance() CMoviePlayerGui& CMoviePlayerGui::getInstance()
{ {
@@ -86,6 +91,7 @@ CMoviePlayerGui& CMoviePlayerGui::getInstance()
if (!instance_mp ) if (!instance_mp )
{ {
instance_mp = new CMoviePlayerGui(); instance_mp = new CMoviePlayerGui();
instance_bg = new CMoviePlayerGui();
printf("[neutrino CMoviePlayerGui] Instance created...\n"); printf("[neutrino CMoviePlayerGui] Instance created...\n");
} }
return *instance_mp; return *instance_mp;
@@ -99,11 +105,20 @@ CMoviePlayerGui::CMoviePlayerGui()
CMoviePlayerGui::~CMoviePlayerGui() CMoviePlayerGui::~CMoviePlayerGui()
{ {
//playback->Close(); //playback->Close();
stopPlayBack(); if (this == instance_mp)
stopPlayBack();
delete moviebrowser; delete moviebrowser;
moviebrowser = NULL;
delete filebrowser; delete filebrowser;
filebrowser = NULL;
delete bookmarkmanager; delete bookmarkmanager;
bookmarkmanager = NULL;
delete playback; delete playback;
playback = NULL;
if (this == instance_mp) {
delete instance_bg;
instance_bg = NULL;
}
instance_mp = NULL; instance_mp = NULL;
} }
@@ -114,9 +129,12 @@ void CMoviePlayerGui::Init(void)
frameBuffer = CFrameBuffer::getInstance(); frameBuffer = CFrameBuffer::getInstance();
playback = new cPlayback(0); if (playback == NULL)
moviebrowser = new CMovieBrowser(); playback = new cPlayback(0);
bookmarkmanager = new CBookmarkManager(); if (moviebrowser == NULL)
moviebrowser = new CMovieBrowser();
if (bookmarkmanager == NULL)
bookmarkmanager = new CBookmarkManager();
tsfilefilter.addFilter("ts"); tsfilefilter.addFilter("ts");
tsfilefilter.addFilter("avi"); tsfilefilter.addFilter("avi");
@@ -465,7 +483,7 @@ bool CMoviePlayerGui::prepareFile(CFile *file)
else { else {
file_name = file->Url; file_name = file->Url;
pretty_name = file->Name; pretty_name = file->Name;
} }
if (isMovieBrowser) { if (isMovieBrowser) {
if (filelist_it != filelist.end()) { if (filelist_it != filelist.end()) {
unsigned idx = filelist_it - filelist.begin(); unsigned idx = filelist_it - filelist.begin();
@@ -511,6 +529,7 @@ bool CMoviePlayerGui::SelectFile()
p_movie_info = CRecordManager::getInstance()->GetMovieInfo(live_channel_id); p_movie_info = CRecordManager::getInstance()->GetMovieInfo(live_channel_id);
file_name = CRecordManager::getInstance()->GetFileName(live_channel_id) + ".ts"; file_name = CRecordManager::getInstance()->GetFileName(live_channel_id) + ".ts";
fillPids(); fillPids();
makeFilename();
ret = true; ret = true;
} }
#if 0 // TODO #if 0 // TODO
@@ -679,28 +698,28 @@ bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::st
} }
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex); OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
Cleanup(); instance_bg->Cleanup();
ClearFlags(); instance_bg->ClearFlags();
ClearQueue(); instance_bg->ClearQueue();
isWebTV = true; instance_bg->isWebTV = true;
is_file_player = true; instance_bg->is_file_player = true;
isHTTP = true; instance_bg->isHTTP = true;
file_name = file; instance_bg->file_name = file;
pretty_name = name; instance_bg->pretty_name = name;
movie_info.epgTitle = name; instance_bg->movie_info.epgTitle = name;
movie_info.epgChannel = file; instance_bg->movie_info.epgChannel = file;
movie_info.epgId = chan; instance_bg->movie_info.epgId = chan;
p_movie_info = &movie_info; instance_bg->p_movie_info = &movie_info;
bool res = PlayFileStart(); bool res = instance_bg->PlayFileStart();
if (res) { if (res) {
if (pthread_create (&bgThread, 0, CMoviePlayerGui::bgPlayThread, this)) if (pthread_create (&bgThread, 0, CMoviePlayerGui::bgPlayThread, instance_bg))
fprintf(stderr, "ERROR: pthread_create(%s)\n", __func__); fprintf(stderr, "ERROR: pthread_create(%s)\n", __func__);
} else } else
PlayFileEnd(); instance_bg->PlayFileEnd();
printf("%s: this %p started: res %d thread %lx\n", __func__, this, res, bgThread);fflush(stdout); printf("%s: this %p started: res %d thread %lx\n", __func__, this, res, bgThread);fflush(stdout);
return res; return res;
} }
@@ -802,7 +821,13 @@ bool CMoviePlayerGui::PlayFileStart(void)
startposition = -1; startposition = -1;
int i; int i;
int towait = (timeshift == TSHIFT_MODE_ON) ? TIMESHIFT_SECONDS+1 : TIMESHIFT_SECONDS; int towait = (timeshift == TSHIFT_MODE_ON) ? TIMESHIFT_SECONDS+1 : TIMESHIFT_SECONDS;
for(i = 0; i < 500; i++) { int cnt = 500;
if (IS_WEBTV(movie_info.epgId)) {
videoDecoder->setBlank(false);
cnt = 200;
towait = 20;
}
for(i = 0; i < cnt; i++) {
playback->GetPosition(position, duration); playback->GetPosition(position, duration);
startposition = (duration - position); startposition = (duration - position);
@@ -812,6 +837,7 @@ bool CMoviePlayerGui::PlayFileStart(void)
usleep(20000); usleep(20000);
} }
printf("CMoviePlayerGui::PlayFile: waiting for data: i=%d position %d duration %d (%d), start %d\n", i, position, duration, towait, startposition);
if (timeshift == TSHIFT_MODE_REWIND) { if (timeshift == TSHIFT_MODE_REWIND) {
startposition = duration; startposition = duration;
} else { } else {
@@ -820,13 +846,14 @@ bool CMoviePlayerGui::PlayFileStart(void)
if (timeshift == TSHIFT_MODE_ON) if (timeshift == TSHIFT_MODE_ON)
startposition = 0; startposition = 0;
else else
startposition = duration - TIMESHIFT_SECONDS*1000; startposition = std::max(0, duration - towait*1000);
} }
printf("******************* Timeshift %d, position %d, seek to %d seconds\n", timeshift, position, startposition/1000); printf("******************* Timeshift %d, position %d, seek to %d seconds\n", timeshift, position, startposition/1000);
} }
if (/* !is_file_player && */ startposition >= 0)//FIXME no jump for file at start yet if (/* !is_file_player && */ startposition >= 0)
playback->SetPosition(startposition, true); playback->SetPosition(startposition, true);
/* playback->Start() starts paused */ /* playback->Start() starts paused */
if (timeshift == TSHIFT_MODE_REWIND) { if (timeshift == TSHIFT_MODE_REWIND) {
speed = -1; speed = -1;

View File

@@ -123,7 +123,7 @@ class CMoviePlayerGui : public CMenuTarget
bool isWebTV; bool isWebTV;
bool isYT; bool isYT;
bool showStartingHint; bool showStartingHint;
CMovieBrowser* moviebrowser; static CMovieBrowser* moviebrowser;
MI_MOVIE_INFO * p_movie_info; MI_MOVIE_INFO * p_movie_info;
MI_MOVIE_INFO movie_info; MI_MOVIE_INFO movie_info;
P_MI_MOVIE_LIST milist; P_MI_MOVIE_LIST milist;
@@ -142,16 +142,17 @@ class CMoviePlayerGui : public CMenuTarget
bool autoshot_done; bool autoshot_done;
/* playback from bookmark */ /* playback from bookmark */
CBookmarkManager * bookmarkmanager; static CBookmarkManager * bookmarkmanager;
bool isBookmark; bool isBookmark;
OpenThreads::Mutex mutex; static OpenThreads::Mutex mutex;
static OpenThreads::Mutex bgmutex; static OpenThreads::Mutex bgmutex;
static OpenThreads::Condition cond; static OpenThreads::Condition cond;
pthread_t bgThread; static pthread_t bgThread;
cPlayback *playback; static cPlayback *playback;
static CMoviePlayerGui* instance_mp; static CMoviePlayerGui* instance_mp;
static CMoviePlayerGui* instance_bg;
void Init(void); void Init(void);
void PlayFile(); void PlayFile();