diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ext/sdl/sdlvideosink.c | 80 | ||||
-rw-r--r-- | ext/sdl/sdlvideosink.h | 3 |
3 files changed, 88 insertions, 3 deletions
@@ -1,3 +1,11 @@ +2005-11-03 Edgard Lima <edgard.lima@indt.org.br> + + * ext/sdl/sdlvideosink.c: (SDL_WaitEventTimeout), + (gst_sdlvideosink_event_thread), (gst_sdlvideosink_initsdl), + (gst_sdlvideosink_change_state), (gst_sdlvideosink_deinitsdl): + * ext/sdl/sdlvideosink.h: + Add support to exit when 'Esc' key is pressed. + 2005-11-02 Julien MOUTTE <julien@moutte.net> * configure.ac: Requires DirectFB 0.9.24 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; |