summaryrefslogtreecommitdiffstats
path: root/media/tools
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 02:03:45 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-02 02:03:45 +0000
commit9f68dde6768d35fb3428ae8a5207c6b988ef55f1 (patch)
tree2f7b231f2b65a9054c11fcc9668a5b67e1ec29fe /media/tools
parent5351134c816752b5671c0a64f7d46c0a2c5c375f (diff)
downloadchromium_src-9f68dde6768d35fb3428ae8a5207c6b988ef55f1.zip
chromium_src-9f68dde6768d35fb3428ae8a5207c6b988ef55f1.tar.gz
chromium_src-9f68dde6768d35fb3428ae8a5207c6b988ef55f1.tar.bz2
Signal handler for player_x11 application
SIGTERM and SIGINT handler for player_x11 tool so that it terminates the media pipeline properly when CTRL+C is received. Review URL: http://codereview.chromium.org/450030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33536 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/tools')
-rw-r--r--media/tools/player_x11/player_x11.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/media/tools/player_x11/player_x11.cc b/media/tools/player_x11/player_x11.cc
index 9e7261a..ac8bbdd 100644
--- a/media/tools/player_x11/player_x11.cc
+++ b/media/tools/player_x11/player_x11.cc
@@ -3,6 +3,7 @@
// LICENSE file.
#include <iostream>
+#include <signal.h>
#include <X11/Xlib.h>
#include "base/at_exit.h"
@@ -20,8 +21,9 @@
#include "media/filters/null_audio_renderer.h"
#include "media/tools/player_x11/x11_video_renderer.h"
-Display* g_display;
-Window g_window;
+Display* g_display = NULL;
+Window g_window = 0;
+bool g_running = false;
// Initialize X11. Returns true if successful. This method creates the X11
// window. Further initialization is done in X11VideoRenderer.
@@ -91,6 +93,10 @@ bool InitPipeline(MessageLoop* message_loop,
return true;
}
+void TerminateHandler(int signal) {
+ g_running = false;
+}
+
int main(int argc, char** argv) {
// Read arguments.
if (argc == 1) {
@@ -105,6 +111,10 @@ int main(int argc, char** argv) {
CommandLine::ForCurrentProcess()->GetSwitchValueASCII("file");
bool enable_audio = CommandLine::ForCurrentProcess()->HasSwitch("audio");
+ // Install the signal handler.
+ signal(SIGTERM, &TerminateHandler);
+ signal(SIGINT, &TerminateHandler);
+
// Initialize X11.
if (!InitX11())
return 1;
@@ -118,7 +128,8 @@ int main(int argc, char** argv) {
if (InitPipeline(thread->message_loop(), filename.c_str(),
enable_audio, &pipeline)) {
// Main loop of the application.
- while (true) {
+ g_running = true;
+ while (g_running) {
if (XPending(g_display)) {
XEvent e;
XNextEvent(g_display, &e);
@@ -128,8 +139,6 @@ int main(int argc, char** argv) {
X11VideoRenderer::instance()->Paint();
} else if (e.type == ButtonPress) {
// Stop the playback.
- std::cout << "Stopping..." << std::endl;
- pipeline->Stop(NULL);
break;
}
} else {
@@ -146,6 +155,9 @@ int main(int argc, char** argv) {
}
}
+ std::cout << "Stopping..." << std::endl;
+ pipeline->Stop(NULL);
+
// Cleanup tasks.
thread->Stop();
XDestroyWindow(g_display, g_window);