Skip to content

Commit

Permalink
Fix SIGINT/SIGTERM handling during video playback.
Browse files Browse the repository at this point in the history
This was broken when SignalHandler was introduced.
There were two problems:
  1/ Calling QCoreApplication::exit()/quit() doesn't actually make the
     program exit if it is in the video playback loop since we take
     over the UI event loop. This has been fixed by periodically
     checking SignalHandler::IsExiting() and setting TV::wantsToExit
     if it is true.
  2/ The VideoOutputXv already had a signal handler for SIGINT, but
     so when we exit playback the first time we were resetting the
     SIGINT handler. This has been fixed by using the
     SignalHandler::SetHandler() method introduced in the last commit
     instead of registering a signal handler ourselves and making the
     new signal handler call QCoreApplication::exit() instead of exit().
  • Loading branch information
daniel-kristjansson committed Jul 30, 2012
1 parent f3fb6f0 commit f9a46e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
6 changes: 6 additions & 0 deletions mythtv/libs/libmythtv/tv_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ using namespace std;
#include <QFile>
#include <QDir>

#include "signalhandling.h"
#include "mythdb.h"
#include "tv_play.h"
#include "tv_rec.h"
Expand Down Expand Up @@ -1369,6 +1370,11 @@ void TV::PlaybackLoop(void)
while (true)
{
qApp->processEvents();
if (SignalHandler::IsExiting())
{
wantsToQuit = true;
return;
}

TVState state = GetState(0);
if ((kState_Error == state) || (kState_None == state))
Expand Down
33 changes: 22 additions & 11 deletions mythtv/libs/libmythtv/util-xv.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// POSIX headers
#include <signal.h>

// C++ headers
#include <iostream>
#include <cstdlib>
using namespace std;

// MythTH headers
// Qt headers
#include <QCoreApplication>

// MythTV headers
#include "signalhandling.h"
#include "mythlogging.h"
#include "mythxdisplay.h"
#include "util-xv.h"
Expand All @@ -22,16 +23,24 @@ QMap<int,port_info> open_xv_ports;

void close_all_xv_ports_signal_handler(int sig)
{
LOG(VB_GENERAL, LOG_INFO, QString("Signal: %1").arg(sys_siglist[sig]));
LOG(VB_GENERAL, LOG_CRIT, QString("Signal: %1").arg(sys_siglist[sig]));
QMap<int,port_info>::iterator it;
for (it = open_xv_ports.begin(); it != open_xv_ports.end(); ++it)
{
restore_port_attributes((*it).port);
LOG(VB_GENERAL, LOG_INFO, QString("Ungrabbing XVideo port: %1")
LOG(VB_GENERAL, LOG_CRIT, QString("Ungrabbing XVideo port: %1")
.arg((*it).port));
XvUngrabPort((*it).disp->GetDisplay(), (*it).port, CurrentTime);
}
exit(GENERIC_EXIT_NOT_OK);
QCoreApplication::exit(GENERIC_EXIT_NOT_OK);
}
static void close_all_xv_ports_signal_handler_SIGINT(void)
{
close_all_xv_ports_signal_handler(SIGINT);
}
static void close_all_xv_ports_signal_handler_SIGTERM(void)
{
close_all_xv_ports_signal_handler(SIGTERM);
}

void save_port_attributes(int port)
Expand Down Expand Up @@ -94,8 +103,10 @@ bool add_open_xv_port(MythXDisplay *disp, int port)
QByteArray ascii_name = "XV_SET_DEFAULTS";
const char *name = ascii_name.constData();
ret = xv_is_attrib_supported(disp, port, name);
// TODO enable more catches after 0.19 is out -- dtk
signal(SIGINT, close_all_xv_ports_signal_handler);
SignalHandler::SetHandler(
SIGINT, close_all_xv_ports_signal_handler_SIGINT);
SignalHandler::SetHandler(
SIGTERM, close_all_xv_ports_signal_handler_SIGTERM);
}
return ret;
}
Expand All @@ -108,8 +119,8 @@ void del_open_xv_port(int port)

if (!open_xv_ports.count())
{
// TODO enable more catches 0.19 is out -- dtk
signal(SIGINT, SIG_DFL);
SignalHandler::SetHandler(SIGINT, NULL);
SignalHandler::SetHandler(SIGTERM, NULL);
}
}
}
Expand Down

0 comments on commit f9a46e0

Please sign in to comment.