diff --git a/src/gui/movieplayer.cpp b/src/gui/movieplayer.cpp index 749584f85..0781aba21 100644 --- a/src/gui/movieplayer.cpp +++ b/src/gui/movieplayer.cpp @@ -74,6 +74,7 @@ #include #include #include +#include extern cVideo * videoDecoder; extern CRemoteControl *g_RemoteControl; /* neutrino.cpp */ @@ -90,12 +91,13 @@ OpenThreads::Mutex CMoviePlayerGui::bgmutex; OpenThreads::Condition CMoviePlayerGui::cond; pthread_t CMoviePlayerGui::bgThread; cPlayback *CMoviePlayerGui::playback; +bool CMoviePlayerGui::webtv_started; CMovieBrowser* CMoviePlayerGui::moviebrowser; CBookmarkManager * CMoviePlayerGui::bookmarkmanager; CMoviePlayerGui& CMoviePlayerGui::getInstance(bool background) { - OpenThreads::ScopedLock m_lock(bgmutex); + OpenThreads::ScopedLock m_lock(mutex); if (!instance_mp ) { instance_mp = new CMoviePlayerGui(); @@ -656,13 +658,52 @@ void *CMoviePlayerGui::ShowStartHint(void *arg) return NULL; } +bool CMoviePlayerGui::StartWebtv(void) +{ + printf("%s: starting...\n", __func__);fflush(stdout); + last_read = position = duration = 0; + + cutNeutrino(); + clearSubtitle(); + + playback->Open(is_file_player ? PLAYMODE_FILE : PLAYMODE_TS); + + bool res = playback->Start((char *) file_name.c_str(), cookie_header);//url with cookies + + playback->SetSpeed(1); + if (!res) { + playback->Close(); + } else { + getCurrentAudioName(is_file_player, currentaudioname); + if (is_file_player) + selectAutoLang(); + } + + return res; +} + void* CMoviePlayerGui::bgPlayThread(void *arg) { set_threadname(__func__); CMoviePlayerGui *mp = (CMoviePlayerGui *) arg; + printf("%s: starting... instance %p\n", __func__, mp);fflush(stdout); int eof = 0, pos = 0; - while(true) { + unsigned char *chid = new unsigned char[sizeof(t_channel_id)]; + *(t_channel_id*)chid = mp->movie_info.epgId; + + bool started = mp->StartWebtv(); + printf("%s: started: %d\n", __func__, started);fflush(stdout); + + mutex.lock(); + if (!webtv_started) + started = false; + else if (!started) + g_RCInput->postMsg(NeutrinoMessages::EVT_ZAP_FAILED, (neutrino_msg_data_t) chid); + webtv_started = started; + mutex.unlock(); + + while(webtv_started) { if (mp->playback->GetPosition(mp->position, mp->duration)) { #if 0 printf("CMoviePlayerGui::bgPlayThread: position %d duration %d (%d)\n", mp->position, mp->duration, mp->duration-mp->position); @@ -673,8 +714,6 @@ void* CMoviePlayerGui::bgPlayThread(void *arg) eof = 0; if (eof > 5) { printf("CMoviePlayerGui::bgPlayThread: playback stopped, try to rezap...\n"); - unsigned char *chid = new unsigned char[sizeof(t_channel_id)]; - *(t_channel_id*)chid = mp->movie_info.epgId; g_RCInput->postMsg(NeutrinoMessages::EVT_WEBTV_ZAP_COMPLETE, (neutrino_msg_data_t) chid); break; } @@ -687,7 +726,7 @@ void* CMoviePlayerGui::bgPlayThread(void *arg) break; mp->showSubtitle(0); } - printf("%s: play end...\n", __func__); + printf("%s: play end...\n", __func__);fflush(stdout); mp->PlayFileEnd(); pthread_exit(NULL); } @@ -934,7 +973,7 @@ bool CMoviePlayerGui::getLiveUrl(const t_channel_id chan, const std::string &url bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::string &name, t_channel_id chan, const std::string &script) { - printf("%s: starting...\n", __func__); + printf("%s: starting...\n", __func__);fflush(stdout); static CZapProtection *zp = NULL; if (zp) return true; @@ -964,17 +1003,13 @@ bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::st } } - std::string realUrl = file; + std::string realUrl; std::string _pretty_name = name; cookie_header.clear(); if (!getLiveUrl(chan, file, script, realUrl, _pretty_name, livestreamInfo1, livestreamInfo2, cookie_header)) { - /* FIXME: lua->runScript calling channelRezap, which makes neutrino to loop at start, - let playback start -> drop messages in ShowStartHint */ - //return false; + return false; } - OpenThreads::ScopedLock m_lock(mutex); - instance_bg->Cleanup(); instance_bg->ClearFlags(); instance_bg->ClearQueue(); @@ -991,14 +1026,16 @@ bool CMoviePlayerGui::PlayBackgroundStart(const std::string &file, const std::st instance_bg->movie_info.epgId = chan; instance_bg->p_movie_info = &movie_info; - bool res = instance_bg->PlayFileStart(); - if (res) { - if (pthread_create (&bgThread, 0, CMoviePlayerGui::bgPlayThread, instance_bg)) - fprintf(stderr, "ERROR: pthread_create(%s)\n", __func__); - } else - instance_bg->PlayFileEnd(); - printf("%s: this %p started: res %d thread %lx\n", __func__, this, res, bgThread);fflush(stdout); - return res; + stopPlayBack(); + webtv_started = true; + if (pthread_create (&bgThread, 0, CMoviePlayerGui::bgPlayThread, instance_bg)) { + printf("ERROR: pthread_create(%s)\n", __func__); + webtv_started = false; + return false; + } + + printf("%s: this %p started, thread %lx\n", __func__, this, bgThread);fflush(stdout); + return true; } void CMoviePlayerGui::stopPlayBack(void) @@ -1009,6 +1046,10 @@ void CMoviePlayerGui::stopPlayBack(void) repeat_mode = REPEAT_OFF; if (bgThread) { printf("%s: this %p join background thread %lx\n", __func__, this, bgThread);fflush(stdout); + mutex.lock(); + webtv_started = false; + playback->RequestAbort(); + mutex.unlock(); cond.broadcast(); pthread_join(bgThread, NULL); bgThread = 0; @@ -1033,9 +1074,7 @@ void CMoviePlayerGui::Pause(bool b) void CMoviePlayerGui::PlayFile(void) { - mutex.lock(); PlayFileStart(); - mutex.unlock(); PlayFileLoop(); bool repeat = (repeat_mode == REPEAT_OFF); if (isLuaPlay) @@ -1063,6 +1102,7 @@ bool CMoviePlayerGui::PlayFileStart(void) cutNeutrino(); if (isWebTV) videoDecoder->setBlank(true); + clearSubtitle(); printf("IS FILE PLAYER: %s\n", is_file_player ? "true": "false" ); @@ -1086,12 +1126,7 @@ bool CMoviePlayerGui::PlayFileStart(void) showStartingHint = true; pthread_create(&thrStartHint, NULL, CMoviePlayerGui::ShowStartHint, this); } - bool res = false; - if(cookie_header.empty()){ - res = playback->Start((char *) file_name.c_str(), vpid, vtype, currentapid, currentac3, duration); - }else{ - res = playback->Start((char *) file_name.c_str(), cookie_header);//url with cookies - } + bool res = playback->Start((char *) file_name.c_str(), vpid, vtype, currentapid, currentac3, duration); if (thrStartHint) { showStartingHint = false; diff --git a/src/gui/movieplayer.h b/src/gui/movieplayer.h index 4585aca37..c2101cdf7 100644 --- a/src/gui/movieplayer.h +++ b/src/gui/movieplayer.h @@ -183,6 +183,7 @@ class CMoviePlayerGui : public CMenuTarget static OpenThreads::Mutex bgmutex; static OpenThreads::Condition cond; static pthread_t bgThread; + static bool webtv_started; static cPlayback *playback; static CMoviePlayerGui* instance_mp; @@ -194,6 +195,7 @@ class CMoviePlayerGui : public CMenuTarget void PlayFileLoop(); void PlayFileEnd(bool restore = true); void cutNeutrino(); + bool StartWebtv(); void quickZap(neutrino_msg_t msg); void showHelpTS(void);