gui/movieplayer.cpp: add support to play files from upnp browser,

add support to stop playback while open in progress, to interrupt i.e. ffmpeg analyze etc, based on code (c) martii <m4rtii@gmx.de>
This commit is contained in:
[CST] Focus
2013-09-03 12:18:02 +04:00
parent 2df40249d6
commit 6fe70ff17d
2 changed files with 80 additions and 20 deletions

View File

@@ -50,6 +50,8 @@
#include <video.h>
#include <libtuxtxt/teletext.h>
#include <zapit/zapit.h>
#include <system/set_threadname.h>
#include <fstream>
#include <iostream>
#include <sstream>
@@ -138,6 +140,7 @@ void CMoviePlayerGui::Init(void)
speed = 1;
timeshift = 0;
numpida = 0;
showStartingHint = false;
}
void CMoviePlayerGui::cutNeutrino()
@@ -146,13 +149,17 @@ void CMoviePlayerGui::cutNeutrino()
return;
playing = true;
/* set g_InfoViewer update timer to 1 sec, should be reset to default from restoreNeutrino->set neutrino mode */
g_InfoViewer->setUpdateTimer(1000 * 1000);
if (isUPNP)
return;
g_Zapit->lockPlayBack();
g_Sectionsd->setPauseScanning(true);
CNeutrinoApp::getInstance()->handleMsg(NeutrinoMessages::CHANGEMODE, NeutrinoMessages::mode_ts);
m_LastMode = (CNeutrinoApp::getInstance()->getLastMode() | NeutrinoMessages::norezap);
/* set g_InfoViewer update timer to 1 sec, should be reset to default from restoreNeutrino->set neutrino mode */
g_InfoViewer->setUpdateTimer(1000 * 1000);
}
void CMoviePlayerGui::restoreNeutrino()
@@ -162,6 +169,9 @@ void CMoviePlayerGui::restoreNeutrino()
playing = false;
if (isUPNP)
return;
g_Zapit->unlockPlayBack();
g_Sectionsd->setPauseScanning(false);
@@ -175,18 +185,12 @@ int CMoviePlayerGui::exec(CMenuTarget * parent, const std::string & actionKey)
if (parent)
parent->hide();
file_name = "";
full_name = "";
startposition = 0;
puts("[movieplayer.cpp] executing " MOVIEPLAYER_START_SCRIPT ".");
if (my_system(MOVIEPLAYER_START_SCRIPT) != 0)
perror(MOVIEPLAYER_START_SCRIPT " failed");
isMovieBrowser = false;
isBookmark = false;
timeshift = 0;
Cleanup();
if (actionKey == "tsmoviebrowser") {
isMovieBrowser = true;
moviebrowser->setMode(MB_SHOW_RECORDS);
@@ -212,11 +216,17 @@ int CMoviePlayerGui::exec(CMenuTarget * parent, const std::string & actionKey)
isBookmark = true;
}
#endif
else if (actionKey == "upnp") {
isUPNP = true;
p_movie_info = NULL;
is_file_player = 1;
PlayFile();
}
else {
return menu_return::RETURN_REPAINT;
}
while(SelectFile()) {
while(!isHTTP && !isUPNP && SelectFile()) {
PlayFile();
if(timeshift)
break;
@@ -304,11 +314,8 @@ void CMoviePlayerGui::fillPids()
vtype = p_movie_info->VideoType;
}
bool CMoviePlayerGui::SelectFile()
void CMoviePlayerGui::Cleanup()
{
bool ret = false;
menu_ret = menu_return::RETURN_REPAINT;
/*clear audiopids */
for (int i = 0; i < numpida; i++) {
apids[i] = 0;
@@ -319,9 +326,23 @@ bool CMoviePlayerGui::SelectFile()
currentspid = -1;
numsubs = 0;
startposition = 0;
isMovieBrowser = false;
isBookmark = false;
timeshift = 0;
isHTTP = false;
isUPNP = false;
is_file_player = false;
p_movie_info = NULL;
}
bool CMoviePlayerGui::SelectFile()
{
bool ret = false;
menu_ret = menu_return::RETURN_REPAINT;
file_name = "";
full_name = "";
printf("CMoviePlayerGui::SelectFile: isBookmark %d timeshift %d isMovieBrowser %d\n", isBookmark, timeshift, isMovieBrowser);
if (has_hdd)
@@ -363,7 +384,7 @@ bool CMoviePlayerGui::SelectFile()
is_file_player = true;
}
fillPids();
// get the start position for the movie
startposition = 1000 * moviebrowser->getCurrentStartPos();
printf("CMoviePlayerGui::SelectFile: file %s start %d apid %X atype %d vpid %x vtype %d\n", full_name.c_str(), startposition, currentapid, currentac3, vpid, vtype);
@@ -431,6 +452,27 @@ bool CMoviePlayerGui::SelectFile()
return ret;
}
void *CMoviePlayerGui::ShowStartHint(void *arg)
{
set_threadname(__func__);
CMoviePlayerGui *caller = (CMoviePlayerGui *)arg;
CHintBox hintbox(LOCALE_MOVIEPLAYER_STARTING, caller->file_name.c_str(), 450, NEUTRINO_ICON_MOVIEPLAYER);
hintbox.paint();
while (caller->showStartingHint) {
neutrino_msg_t msg;
neutrino_msg_data_t data;
g_RCInput->getMsg(&msg, &data, 1);
if (msg == CRCInput::RC_home || msg == CRCInput::RC_stop) {
if(caller->playback)
caller->playback->RequestAbort();
}
}
hintbox.hide();
return NULL;
}
void CMoviePlayerGui::PlayFile(void)
{
neutrino_msg_t msg;
@@ -463,7 +505,18 @@ void CMoviePlayerGui::PlayFile(void)
}
file_prozent = 0;
if(!playback->Start((char *) full_name.c_str(), vpid, vtype, currentapid, currentac3, duration)) {
pthread_t thrStartHint;
if (is_file_player) {
showStartingHint = true;
pthread_create(&thrStartHint, NULL, CMoviePlayerGui::ShowStartHint, this);
}
bool res = playback->Start((char *) full_name.c_str(), vpid, vtype, currentapid, currentac3, duration);
if (thrStartHint) {
showStartingHint = false;
pthread_join(thrStartHint, NULL);
}
if(!res) {
playback->Close();
} else {
playstate = CMoviePlayerGui::PLAY;
@@ -847,7 +900,7 @@ void CMoviePlayerGui::addAudioFormat(int count, std::string &apidtitle, bool& en
void CMoviePlayerGui::getCurrentAudioName( bool file_player, std::string &audioname)
{
if(file_player && !numpida){
if(file_player && !numpida){
playback->FindAllPids(apids, ac3flags, &numpida, language);
if(numpida)
currentapid = apids[0];
@@ -1344,7 +1397,7 @@ void CMoviePlayerGui::showSubtitle(neutrino_msg_data_t data)
if (sub->format == 0) {
int xres = 0, yres = 0, framerate;
videoDecoder->getPictureInfo(xres, yres, framerate);
double xc = (double) CFrameBuffer::getInstance()->getScreenWidth(/*true*/)/(double) xres;
double yc = (double) CFrameBuffer::getInstance()->getScreenHeight(/*true*/)/(double) yres;

View File

@@ -98,6 +98,9 @@ class CMoviePlayerGui : public CMenuTarget
/* playback from MB */
bool isMovieBrowser;
bool isHTTP;
bool isUPNP;
bool showStartingHint;
CMovieBrowser* moviebrowser;
MI_MOVIE_INFO * p_movie_info;
const static short MOVIE_HINT_BOX_TIMER = 5; // time to show bookmark hints in seconds
@@ -138,6 +141,9 @@ class CMoviePlayerGui : public CMenuTarget
void clearSubtitle();
void selectChapter();
void Cleanup();
static void *ShowStartHint(void *arg);
CMoviePlayerGui(const CMoviePlayerGui&) {};
CMoviePlayerGui();
@@ -155,6 +161,7 @@ class CMoviePlayerGui : public CMenuTarget
void UpdatePosition();
int timeshift;
int file_prozent;
void SetFile(std::string &name, std::string &file) { file_name = name; full_name = file; }
};
#endif