gui/movieplayer.cpp: add non-blocking webtv zap, for testing

This commit is contained in:
[CST] Focus
2016-04-01 16:10:01 +03:00
parent 179d955075
commit a5a64d5159
2 changed files with 65 additions and 28 deletions

View File

@@ -74,6 +74,7 @@
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <iconv.h> #include <iconv.h>
#include <system/stacktrace.h>
extern cVideo * videoDecoder; extern cVideo * videoDecoder;
extern CRemoteControl *g_RemoteControl; /* neutrino.cpp */ extern CRemoteControl *g_RemoteControl; /* neutrino.cpp */
@@ -90,12 +91,13 @@ OpenThreads::Mutex CMoviePlayerGui::bgmutex;
OpenThreads::Condition CMoviePlayerGui::cond; OpenThreads::Condition CMoviePlayerGui::cond;
pthread_t CMoviePlayerGui::bgThread; pthread_t CMoviePlayerGui::bgThread;
cPlayback *CMoviePlayerGui::playback; cPlayback *CMoviePlayerGui::playback;
bool CMoviePlayerGui::webtv_started;
CMovieBrowser* CMoviePlayerGui::moviebrowser; CMovieBrowser* CMoviePlayerGui::moviebrowser;
CBookmarkManager * CMoviePlayerGui::bookmarkmanager; CBookmarkManager * CMoviePlayerGui::bookmarkmanager;
CMoviePlayerGui& CMoviePlayerGui::getInstance(bool background) CMoviePlayerGui& CMoviePlayerGui::getInstance(bool background)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(bgmutex); OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
if (!instance_mp ) if (!instance_mp )
{ {
instance_mp = new CMoviePlayerGui(); instance_mp = new CMoviePlayerGui();
@@ -656,13 +658,52 @@ void *CMoviePlayerGui::ShowStartHint(void *arg)
return NULL; 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) void* CMoviePlayerGui::bgPlayThread(void *arg)
{ {
set_threadname(__func__); set_threadname(__func__);
CMoviePlayerGui *mp = (CMoviePlayerGui *) arg; CMoviePlayerGui *mp = (CMoviePlayerGui *) arg;
printf("%s: starting... instance %p\n", __func__, mp);fflush(stdout);
int eof = 0, pos = 0; 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 (mp->playback->GetPosition(mp->position, mp->duration)) {
#if 0 #if 0
printf("CMoviePlayerGui::bgPlayThread: position %d duration %d (%d)\n", mp->position, mp->duration, mp->duration-mp->position); 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; eof = 0;
if (eof > 5) { if (eof > 5) {
printf("CMoviePlayerGui::bgPlayThread: playback stopped, try to rezap...\n"); 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); g_RCInput->postMsg(NeutrinoMessages::EVT_WEBTV_ZAP_COMPLETE, (neutrino_msg_data_t) chid);
break; break;
} }
@@ -687,7 +726,7 @@ void* CMoviePlayerGui::bgPlayThread(void *arg)
break; break;
mp->showSubtitle(0); mp->showSubtitle(0);
} }
printf("%s: play end...\n", __func__); printf("%s: play end...\n", __func__);fflush(stdout);
mp->PlayFileEnd(); mp->PlayFileEnd();
pthread_exit(NULL); 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) 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; static CZapProtection *zp = NULL;
if (zp) if (zp)
return true; 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; std::string _pretty_name = name;
cookie_header.clear(); cookie_header.clear();
if (!getLiveUrl(chan, file, script, realUrl, _pretty_name, livestreamInfo1, livestreamInfo2, cookie_header)) { if (!getLiveUrl(chan, file, script, realUrl, _pretty_name, livestreamInfo1, livestreamInfo2, cookie_header)) {
/* FIXME: lua->runScript calling channelRezap, which makes neutrino to loop at start, return false;
let playback start -> drop messages in ShowStartHint */
//return false;
} }
OpenThreads::ScopedLock<OpenThreads::Mutex> m_lock(mutex);
instance_bg->Cleanup(); instance_bg->Cleanup();
instance_bg->ClearFlags(); instance_bg->ClearFlags();
instance_bg->ClearQueue(); 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->movie_info.epgId = chan;
instance_bg->p_movie_info = &movie_info; instance_bg->p_movie_info = &movie_info;
bool res = instance_bg->PlayFileStart(); stopPlayBack();
if (res) { webtv_started = true;
if (pthread_create (&bgThread, 0, CMoviePlayerGui::bgPlayThread, instance_bg)) if (pthread_create (&bgThread, 0, CMoviePlayerGui::bgPlayThread, instance_bg)) {
fprintf(stderr, "ERROR: pthread_create(%s)\n", __func__); printf("ERROR: pthread_create(%s)\n", __func__);
} else webtv_started = false;
instance_bg->PlayFileEnd(); return false;
printf("%s: this %p started: res %d thread %lx\n", __func__, this, res, bgThread);fflush(stdout); }
return res;
printf("%s: this %p started, thread %lx\n", __func__, this, bgThread);fflush(stdout);
return true;
} }
void CMoviePlayerGui::stopPlayBack(void) void CMoviePlayerGui::stopPlayBack(void)
@@ -1009,6 +1046,10 @@ void CMoviePlayerGui::stopPlayBack(void)
repeat_mode = REPEAT_OFF; repeat_mode = REPEAT_OFF;
if (bgThread) { if (bgThread) {
printf("%s: this %p join background thread %lx\n", __func__, this, bgThread);fflush(stdout); 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(); cond.broadcast();
pthread_join(bgThread, NULL); pthread_join(bgThread, NULL);
bgThread = 0; bgThread = 0;
@@ -1033,9 +1074,7 @@ void CMoviePlayerGui::Pause(bool b)
void CMoviePlayerGui::PlayFile(void) void CMoviePlayerGui::PlayFile(void)
{ {
mutex.lock();
PlayFileStart(); PlayFileStart();
mutex.unlock();
PlayFileLoop(); PlayFileLoop();
bool repeat = (repeat_mode == REPEAT_OFF); bool repeat = (repeat_mode == REPEAT_OFF);
if (isLuaPlay) if (isLuaPlay)
@@ -1063,6 +1102,7 @@ bool CMoviePlayerGui::PlayFileStart(void)
cutNeutrino(); cutNeutrino();
if (isWebTV) if (isWebTV)
videoDecoder->setBlank(true); videoDecoder->setBlank(true);
clearSubtitle(); clearSubtitle();
printf("IS FILE PLAYER: %s\n", is_file_player ? "true": "false" ); printf("IS FILE PLAYER: %s\n", is_file_player ? "true": "false" );
@@ -1086,12 +1126,7 @@ bool CMoviePlayerGui::PlayFileStart(void)
showStartingHint = true; showStartingHint = true;
pthread_create(&thrStartHint, NULL, CMoviePlayerGui::ShowStartHint, this); pthread_create(&thrStartHint, NULL, CMoviePlayerGui::ShowStartHint, this);
} }
bool res = false; bool res = playback->Start((char *) file_name.c_str(), vpid, vtype, currentapid, currentac3, duration);
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
}
if (thrStartHint) { if (thrStartHint) {
showStartingHint = false; showStartingHint = false;

View File

@@ -183,6 +183,7 @@ class CMoviePlayerGui : public CMenuTarget
static OpenThreads::Mutex bgmutex; static OpenThreads::Mutex bgmutex;
static OpenThreads::Condition cond; static OpenThreads::Condition cond;
static pthread_t bgThread; static pthread_t bgThread;
static bool webtv_started;
static cPlayback *playback; static cPlayback *playback;
static CMoviePlayerGui* instance_mp; static CMoviePlayerGui* instance_mp;
@@ -194,6 +195,7 @@ class CMoviePlayerGui : public CMenuTarget
void PlayFileLoop(); void PlayFileLoop();
void PlayFileEnd(bool restore = true); void PlayFileEnd(bool restore = true);
void cutNeutrino(); void cutNeutrino();
bool StartWebtv();
void quickZap(neutrino_msg_t msg); void quickZap(neutrino_msg_t msg);
void showHelpTS(void); void showHelpTS(void);