]> git.sesse.net Git - vlc/commitdiff
* ./plugins/lirc/lirc.c: non-blocking patch from Sigmund Augdal
authorSam Hocevar <sam@videolan.org>
Thu, 21 Feb 2002 21:55:40 +0000 (21:55 +0000)
committerSam Hocevar <sam@videolan.org>
Thu, 21 Feb 2002 21:55:40 +0000 (21:55 +0000)
    <sigmunau@stud.ntnu.no>; hope this time my enhancements don't break
    everything :-)

plugins/lirc/lirc.c

index 9ae859343180c92868813d1b8d8d35efdc81b42a..6b0898f10bc89963594027e0e45e3c150d3e4eed 100644 (file)
@@ -2,7 +2,7 @@
  * lirc.c : lirc plugin for vlc
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: lirc.c,v 1.6 2002/02/20 05:56:18 sam Exp $
+ * $Id: lirc.c,v 1.7 2002/02/21 21:55:40 sam Exp $
  *
  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
  *
@@ -27,6 +27,8 @@
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <string.h>
 
+#include <fcntl.h>
+
 #include <videolan/vlc.h>
 
 #include "stream_control.h"
@@ -95,21 +97,27 @@ static void intf_getfunctions( function_list_t * p_function_list )
  *****************************************************************************/
 static int intf_Open( intf_thread_t *p_intf )
 {
+    int i_fd;
+
     /* Allocate instance and initialize some members */
     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
     if( p_intf->p_sys == NULL )
     {
         intf_ErrMsg("no mem?");
         return 1;
-    };
+    }
 
-    if( lirc_init("vlc", 1) == -1 )
+    i_fd = lirc_init( "vlc", 1 );
+    if( i_fd == -1 )
     {
         intf_ErrMsg( "intf error: lirc_init failed" );
         free( p_intf->p_sys );
         return 1;
     }
 
+    /* We want polling */
+    fcntl( i_fd, F_SETFL, fcntl( i_fd, F_GETFL ) | O_NONBLOCK );
+
     if( lirc_readconfig( NULL, &p_intf->p_sys->config, NULL ) != 0 )
     {
         intf_ErrMsg( "intf error: lirc_readconfig failed" );
@@ -140,11 +148,18 @@ static void intf_Run( intf_thread_t *p_intf )
     char *code;
     char *c;
 
-    /* Manage core vlc functions through the callback */
-    p_intf->pf_manage( p_intf );
-
-    while( !p_intf->b_die && lirc_nextcode(&code) == 0 )
+    while( !p_intf->b_die )
     {
+        /* Manage core vlc functions through the callback */
+        p_intf->pf_manage( p_intf );
+        msleep( INTF_IDLE_SLEEP );
+
+        /* We poll the lircsocket */
+        if( lirc_nextcode(&code) != 0 )
+        {
+            break;
+        }
+
         if( code == NULL )
         {
             continue;
@@ -265,9 +280,6 @@ static void intf_Run( intf_thread_t *p_intf )
         }
 
         free( code );
-
-        /* Manage core vlc functions through the callback */
-        p_intf->pf_manage( p_intf );
     }
 }