[hbbtv] reduce CPU usage
[vuplus_openvuplus] / meta-openvuplus / recipes-vuplus / tuxtxt / tuxbox-tuxtxt-32bpp / nonblocking.diff
1 diff -u tuxtxt_orig/tuxtxt.c tuxtxt/tuxtxt.c
2 --- tuxtxt_orig/tuxtxt.c        2008-12-26 19:41:28.000000000 +0100
3 +++ tuxtxt/tuxtxt.c     2009-01-29 21:36:31.000000000 +0100
4 @@ -535,7 +535,6 @@
5  
6  
7         /* setup rc */
8 -       fcntl(rc, F_SETFL, O_NONBLOCK);
9         ioctl(rc, RC_IOCTL_BCODES, 1);
10  
11  
12 @@ -1214,7 +1213,7 @@
13  
14  void ConfigMenu(int Init)
15  {
16 -       int val, menuitem = M_Start;
17 +       int menuitem = M_Start;
18         int current_pid = 0;
19         int hotindex;
20         int oldscreenmode;
21 @@ -1257,10 +1256,6 @@
22         renderinfo.clearbbcolor = tuxtxt_color_black;
23         Menu_Init(menu, current_pid, menuitem, hotindex);
24  
25 -       /* set blocking mode */
26 -       val = fcntl(rc, F_GETFL);
27 -       fcntl(rc, F_SETFL, val &~ O_NONBLOCK);
28 -
29         /* loop */
30         do {
31                 if (GetRCCode() == 1)
32 @@ -1721,7 +1716,6 @@
33                                                 current_service = current_pid;
34  //                                             RenderMessage(ShowServiceName);
35  
36 -                                               fcntl(rc, F_SETFL, O_NONBLOCK);
37                                                 RCCode = -1;
38                                                 if (oldscreenmode)
39                                                         tuxtxt_SwitchScreenMode(&renderinfo,oldscreenmode); /* restore divided screen */
40 @@ -1792,8 +1786,6 @@
41                 UpdateLCD(); /* update number of cached pages */
42         } while ((RCCode != RC_HOME) && (RCCode != RC_DBOX) && (RCCode != RC_MUTE));
43  
44 -       /* reset to nonblocking mode */
45 -       fcntl(rc, F_SETFL, O_NONBLOCK);
46         tuxtxt_cache.pageupdate = 1;
47         RCCode = -1;
48         if (oldscreenmode)
49 @@ -2013,7 +2005,7 @@
50  void PageCatching()
51  {
52         int active_national_subset=tuxtxt_cache.national_subset;
53 -       int val, byte;
54 +       int byte;
55         int oldzoommode = renderinfo.zoommode;
56  
57         renderinfo.pagecatching = 1;
58 @@ -2046,10 +2038,6 @@
59                 return;
60         }
61  
62 -       /* set blocking mode */
63 -       val = fcntl(rc, F_GETFL);
64 -       fcntl(rc, F_SETFL, val &~ O_NONBLOCK);
65 -
66         /* loop */
67         do {
68                 GetRCCode();
69 @@ -2088,7 +2076,6 @@
70                 case RC_HOME:
71                 case RC_HELP:
72                 case RC_MUTE:
73 -                       fcntl(rc, F_SETFL, O_NONBLOCK);
74                         tuxtxt_cache.pageupdate = 1;
75                         renderinfo.pagecatching = 0;
76                         RCCode = -1;
77 @@ -2112,9 +2099,6 @@
78                 tuxtxt_cache.subpage = subp;
79         else
80                 tuxtxt_cache.subpage = 0;
81 -
82 -       /* reset to nonblocking mode */
83 -       fcntl(rc, F_SETFL, O_NONBLOCK);
84  }
85  
86  /******************************************************************************
87 @@ -2712,16 +2696,34 @@
88  
89  int GetRCCode()
90  {
91 +       int maxfd = 0;
92 +       fd_set rset;
93 +       struct timeval timeout;
94  #if HAVE_DVB_API_VERSION < 3
95         static unsigned short LastKey = -1;
96  #else
97         struct input_event ev;
98         static __u16 rc_last_key = KEY_RESERVED;
99  #endif
100 +       FD_ZERO(&rset);
101 +       timeout.tv_sec = 0;
102 +       timeout.tv_usec = 100000;
103         /* get code */
104 -#if HAVE_DVB_API_VERSION < 3
105 -       if (read(rc, &RCCode, 2) == 2)
106 +       if (rc >= 0)
107 +       {
108 +               FD_SET(rc, &rset);
109 +               if (rc > maxfd)
110 +               {
111 +                       maxfd = rc;
112 +               }
113 +       }
114 +       if (select(maxfd + 1, &rset, NULL, NULL, &timeout) > 0)
115         {
116 +               if (rc >= 0 && FD_ISSET(rc, &rset))
117 +               {
118 +#if HAVE_DVB_API_VERSION < 3
119 +                       read(rc, &RCCode, 2);
120 +               }
121                 if (RCCode != LastKey)
122                 {
123                         LastKey = RCCode;
124 @@ -2730,8 +2732,8 @@
125                         {
126                                 switch (RCCode)
127  #else
128 -       if (read(rc, &ev, sizeof(ev)) == sizeof(ev))
129 -       {
130 +                       read(rc, &ev, sizeof(ev));
131 +               }
132                 if (ev.value)
133                 {
134                         if (ev.code != rc_last_key)
135 @@ -2789,7 +2791,6 @@
136         }
137  
138         RCCode = -1;
139 -       usleep(1000000/100);
140  
141         return 0;
142  }