diff options
author | Edgard Lima <edgard.lima@indt.org.br> | 2005-11-03 16:59:20 +0000 |
---|---|---|
committer | Edgard Lima <edgard.lima@indt.org.br> | 2005-11-03 16:59:20 +0000 |
commit | abaa4ba211e9da97f200831a8b0f0a84251e154a (patch) | |
tree | 56736a3a82f5556babf37f689c586c2ccf1314fd /ext | |
parent | 353fd82fdb6231eda9f71515f8e154f548fac8a3 (diff) | |
download | gst-plugins-bad-abaa4ba211e9da97f200831a8b0f0a84251e154a.tar.gz gst-plugins-bad-abaa4ba211e9da97f200831a8b0f0a84251e154a.tar.bz2 gst-plugins-bad-abaa4ba211e9da97f200831a8b0f0a84251e154a.zip |
Add support to exit when 'Esc' key is pressed.
Original commit message from CVS:
Add support to exit when 'Esc' key is pressed.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/sdl/sdlvideosink.c | 80 | ||||
-rw-r--r-- | ext/sdl/sdlvideosink.h | 3 |
2 files changed, 80 insertions, 3 deletions
diff --git a/ext/sdl/sdlvideosink.c b/ext/sdl/sdlvideosink.c index a23a573a..6d5f4129 100644 --- a/ext/sdl/sdlvideosink.c +++ b/ext/sdl/sdlvideosink.c @@ -319,6 +319,9 @@ gst_sdlvideosink_init (GstSDLVideoSink * sdlvideosink) sdlvideosink->init = FALSE; + sdlvideosink->event_thread = NULL; + sdlvideosink->running = FALSE; + sdlvideosink->lock = g_mutex_new (); } @@ -402,8 +405,6 @@ gst_sdlvideosink_lock (GstSDLVideoSink * sdlvideosink) if (SDL_LockYUVOverlay (sdlvideosink->overlay) < 0) goto lock_yuv; - sdlvideosink->init = TRUE; - return TRUE; /* ERRORS */ @@ -443,13 +444,83 @@ gst_sdlvideosink_deinitsdl (GstSDLVideoSink * sdlvideosink) g_mutex_lock (sdlvideosink->lock); if (sdlvideosink->init) { + sdlvideosink->running = FALSE; + if (sdlvideosink->event_thread) { + g_thread_join (sdlvideosink->event_thread); + sdlvideosink->event_thread = NULL; + } + SDL_Quit (); sdlvideosink->init = FALSE; + } g_mutex_unlock (sdlvideosink->lock); } +int +SDL_WaitEventTimeout (SDL_Event * event, Uint32 timeout) +{ + Uint32 i; + int numevents = 0; + + for (i = 0; i < timeout; i += 10) { + SDL_PumpEvents (); + /* numevents = SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS); */ + numevents = + SDL_PeepEvents (event, 1, SDL_GETEVENT, + SDL_KEYDOWNMASK | SDL_KEYUPMASK | + /* SDL_MOUSEMOTIONMASK | SDL_MOUSEBUTTONDOWNMASK | SDL_MOUSEBUTTONUPMASK | */ + SDL_QUITMASK); + switch (numevents) { + case -1: + return 0; + break; + case 0: + SDL_Delay (10); + break; + default: + return numevents; + break; + } + } + + return 0; +} + +static gpointer +gst_sdlvideosink_event_thread (GstSDLVideoSink * sdlvideosink) +{ + + SDL_Event event; + + while (sdlvideosink->running) { + if (SDL_WaitEventTimeout (&event, 50)) { + + switch (event.type) { + case SDL_KEYDOWN: + if (SDLK_ESCAPE != event.key.keysym.sym) { + break; + } else { + /* fall through */ + } + case SDL_QUIT: + sdlvideosink->running = FALSE; + GST_ELEMENT_ERROR (sdlvideosink, RESOURCE, OPEN_WRITE, + ("Video output device is gone."), + ("We were running fullscreen and user " + "pressed the ESC key, stopping playback.")); + break; + } + + } + + } + + return NULL; + +} + static gboolean gst_sdlvideosink_initsdl (GstSDLVideoSink * sdlvideosink) { @@ -472,6 +543,11 @@ gst_sdlvideosink_initsdl (GstSDLVideoSink * sdlvideosink) sdlvideosink->init = TRUE; + sdlvideosink->running = TRUE; + sdlvideosink->event_thread = + g_thread_create ((GThreadFunc) gst_sdlvideosink_event_thread, + sdlvideosink, TRUE, NULL); + g_mutex_unlock (sdlvideosink->lock); return TRUE; diff --git a/ext/sdl/sdlvideosink.h b/ext/sdl/sdlvideosink.h index e597efcf..c2d9b60a 100644 --- a/ext/sdl/sdlvideosink.h +++ b/ext/sdl/sdlvideosink.h @@ -59,7 +59,8 @@ struct _GstSDLVideoSink { gboolean full_screen; gboolean init; - + gboolean running; + GThread *event_thread; SDL_Surface *screen; SDL_Overlay *overlay; SDL_Rect rect; |