Merge branch 'opendreambox' of /home/tmbinc/openembedded.git/ into opendreambox
[vuplus_openembedded] / packages / enigma2 / enigma2 / tuxtxt_caching.patch
1 Index: enigma2/lib/python/Components/UsageConfig.py
2 ===================================================================
3 --- enigma2/lib/python/Components/UsageConfig.py        (revision 5639)
4 +++ enigma2/lib/python/Components/UsageConfig.py        (working copy)
5 @@ -1,6 +1,6 @@
6  from Components.Harddisk import harddiskmanager
7  from config import ConfigSubsection, ConfigYesNo, config, ConfigSelection, ConfigText, ConfigNumber, ConfigSet
8 -from enigma import Misc_Options, setTunerTypePriorityOrder;
9 +from enigma import Misc_Options, setTunerTypePriorityOrder, setEnableTtCachingOnOff;
10  from SystemInfo import SystemInfo
11  import os
12  
13 @@ -17,6 +17,7 @@
14         config.usage.show_infobar_on_zap = ConfigYesNo(default = True)
15         config.usage.show_infobar_on_skip = ConfigYesNo(default = True)
16         config.usage.show_infobar_on_event_change = ConfigYesNo(default = True)
17 +       config.usage.enable_tt_caching = ConfigYesNo(default = True)
18         config.usage.hdd_standby = ConfigSelection(default = "120", choices = [
19                 ("0", _("no standby")), ("2", "10 " + _("seconds")), ("6", "30 " + _("seconds")),
20                 ("12", "1 " + _("minute")), ("24", "2 " + _("minutes")),
21 @@ -56,7 +56,11 @@
22  
23         config.usage.blinking_display_clock_during_recording = ConfigYesNo(default = False)
24         config.usage.load_length_of_movies_in_moviellist = ConfigYesNo(default = True)
25 -       
26 +
27 +       def EnableTtCachingChanged(configElement):
28 +               setEnableTtCachingOnOff(int(configElement.value))
29 +       config.usage.enable_tt_caching.addNotifier(EnableTtCachingChanged)
30 +
31         def TunerTypePriorityOrderChanged(configElement):
32                 setTunerTypePriorityOrder(int(configElement.value))
33         config.usage.alternatives_priority.addNotifier(TunerTypePriorityOrderChanged)
34 Index: enigma2/lib/python/enigma_python.i
35 ===================================================================
36 --- enigma2/lib/python/enigma_python.i  (revision 5639)
37 +++ enigma2/lib/python/enigma_python.i  (working copy)
38 @@ -87,6 +87,7 @@
39  #include <lib/dvb/pmt.h>
40  #include <lib/components/scan.h>
41  #include <lib/components/file_eraser.h>
42 +#include <lib/components/tuxtxtapp.h>
43  #include <lib/driver/avswitch.h>
44  #include <lib/driver/rfmod.h>
45  #include <lib/driver/misc_options.h>
46 @@ -160,6 +161,9 @@
47  %immutable eAVSwitch::vcr_sb_notifier;
48  %immutable ePythonMessagePump::recv_msg;
49  %immutable eDVBLocalTimeHandler::m_timeUpdated;
50 +%immutable eTuxtxtApp::appClosed;
51 +%immutable eTuxtxtApp::dataAvail;
52 +%immutable eTuxtxtApp::dataSent;
53  %include <lib/base/message.h>
54  %include <lib/base/console.h>
55  %include <lib/base/nconfig.h>
56 @@ -205,6 +209,7 @@
57  %include <lib/dvb/pmt.h>
58  %include <lib/components/scan.h>
59  %include <lib/components/file_eraser.h>
60 +%include <lib/components/tuxtxtapp.h>
61  %include <lib/driver/avswitch.h>
62  %include <lib/driver/rfmod.h>
63  %include <lib/driver/misc_options.h>
64 @@ -309,6 +314,15 @@
65  }
66  %}
67  
68 +void setEnableTtCachingOnOff(int);
69 +%{
70 +void setEnableTtCachingOnOff(int onoff)
71 +{
72 +       eTuxtxtApp *tt = eTuxtxtApp::getInstance();
73 +       if (tt) tt->setEnableTtCachingOnOff(onoff);
74 +}
75 +%}
76 +
77  /************** temp *****************/
78  
79         /* need a better place for this, i agree. */
80 Index: enigma2/lib/components/Makefile.am
81 ===================================================================
82 --- enigma2/lib/components/Makefile.am  (revision 5639)
83 +++ enigma2/lib/components/Makefile.am  (working copy)
84 @@ -3,4 +3,4 @@
85  
86  noinst_LIBRARIES = libenigma_components.a
87  
88 -libenigma_components_a_SOURCES = scan.cpp file_eraser.cpp
89 +libenigma_components_a_SOURCES = scan.cpp file_eraser.cpp tuxtxtapp.cpp
90 Index: enigma2/lib/dvb/decoder.cpp
91 ===================================================================
92 --- enigma2/lib/dvb/decoder.cpp (revision 5639)
93 +++ enigma2/lib/dvb/decoder.cpp (working copy)
94 @@ -1,6 +1,7 @@
95  #include <lib/base/ebase.h>
96  #include <lib/base/eerror.h>
97  #include <lib/dvb/decoder.h>
98 +#include <lib/components/tuxtxtapp.h>
99  #if HAVE_DVB_API_VERSION < 3 
100  #define audioStatus audio_status
101  #define videoStatus video_status
102 @@ -880,14 +881,24 @@
103         if (m_changed & changeText)
104         {
105                 if (m_text)
106 +               {
107                         m_text->stop();
108 +                       if ( m_decoder == 0 )   // Tuxtxt caching actions only on primary decoder
109 +                               eTuxtxtApp::getInstance()->stopCaching();
110 +               }
111                 m_text = 0;
112                 if ((m_textpid >= 0) && (m_textpid < 0x1FFF) && !nott)
113                 {
114                         m_text = new eDVBTText(m_demux);
115                         if (m_text->startPid(m_textpid))
116                                 res = -1;
117 +
118 +                       if ( m_decoder == 0 )   // Tuxtxt caching actions only on primary decoder
119 +                               eTuxtxtApp::getInstance()->startCaching(m_textpid);
120                 }
121 +               else if ( m_decoder == 0 )      // Tuxtxt caching actions only on primary decoder
122 +                       eTuxtxtApp::getInstance()->resetPid();
123 +
124                 m_changed &= ~changeText;
125         }
126  #endif
127 @@ -938,10 +949,16 @@
128         demux->connectEvent(slot(*this, &eTSMPEGDecoder::demux_event), m_demux_event_conn);
129         CONNECT(m_showSinglePicTimer.timeout, eTSMPEGDecoder::finishShowSinglePic);
130         m_is_ff = m_is_sm = m_is_trickmode = 0;
131 +       
132 +       if ( m_decoder == 0 )   // Tuxtxt caching actions only on primary decoder
133 +               eTuxtxtApp::getInstance()->initCache();
134  }
135  
136  eTSMPEGDecoder::~eTSMPEGDecoder()
137  {
138 +       if ( m_decoder == 0 )   // Tuxtxt caching actions only on primary decoder
139 +               eTuxtxtApp::getInstance()->freeCache();
140 +
141         finishShowSinglePic();
142         m_vpid = m_apid = m_pcrpid = m_textpid = pidNone;
143         m_changed = -1;
144 Index: data/setup.xml
145 ===================================================================
146 RCS file: /cvs/enigma2/data/setup.xml,v
147 retrieving revision 1.48
148 diff -u -r1.48 setup.xml
149 --- enigma2/data/setup.xml      5 Oct 2008 22:37:19 -0000       1.48
150 +++ enigma2/data/setup.xml      21 Oct 2008 22:54:10 -0000
151 @@ -23,6 +23,7 @@
152                         <item level="0" text="Margin after record">config.recording.margin_after</item>
153                         <item level="0" text="Show blinking clock in display during recording">config.usage.blinking_display_clock_during_recording</item>
154                         <item level="2" text="Load Length of Movies in Movielist">config.usage.load_length_of_movies_in_moviellist</item>
155 +                       <item level="1" text="Enable teletext caching">config.usage.enable_tt_caching</item>
156                         <item level="1" text="Show positioner movement">config.usage.showdish</item>
157                         <item level="1" text="Enable multiple bouquets">config.usage.multibouquet</item>
158                         <item level="1" text="Change bouquets in quickzap">config.usage.quickzap_bouquet_change</item>
159 Index: enigma2/main/Makefile.am
160 ===================================================================
161 --- enigma2/main/Makefile.am    (revision 5639)
162 +++ enigma2/main/Makefile.am    (working copy)
163 @@ -52,7 +52,7 @@
164         @LIBUNGIF_LIBS@ \
165         @XML2_LIBS@ \
166         @XMLCCWRAP_LIBS@ \
167 -       -ldl -lpthread -lcrypt -lresolv -lrt
168 +       -ldl -lpthread -lcrypt -lresolv -lrt -ltuxtxt32bpp
169  
170  enigma2$(EXEEXT): $(enigma2_OBJECTS) $(enigma2_DEPENDENCIES) $(enigma2_LDADD_WHOLE)
171  #      @rm -f enigma2$(EXEEXT)
172 --- enigma2_orig/lib/components/tuxtxtapp.cpp   1970-01-01 00:00:00.000000000 +0000
173 +++ enigma2/lib/components/tuxtxtapp.cpp        2008-10-04 18:26:04.000000000 +0200
174 @@ -0,0 +1,112 @@
175 +#include <lib/components/tuxtxtapp.h>
176 +#include <lib/base/init.h>
177 +#include <lib/base/init_num.h>
178 +#include <lib/driver/rc.h>
179 +#include <lib/gdi/lcd.h>
180 +#include <lib/gdi/fb.h>
181 +
182 +extern "C" int tuxtxt_run_ui(int pid);
183 +extern "C" int tuxtxt_init();
184 +extern "C" void tuxtxt_start(int tpid);
185 +extern "C" int tuxtxt_stop();
186 +extern "C" void tuxtxt_close();
187 +
188 +eAutoInitP0<eTuxtxtApp> init_eTuxtxtApp(eAutoInitNumbers::lowlevel, "Tuxtxt");
189 +eTuxtxtApp *eTuxtxtApp::instance;
190 +
191 +eTuxtxtApp::eTuxtxtApp() : pid(0), enableTtCaching(false), uiRunning(false)
192 +{
193 +       pthread_mutex_init( &cacheChangeLock, 0 );
194 +       if (!instance)
195 +               instance=this;
196 +}
197 +
198 +eTuxtxtApp::~eTuxtxtApp()
199 +{
200 +       if (instance==this)
201 +               instance=0;
202 +       kill();
203 +       pthread_mutex_destroy( &cacheChangeLock );
204 +}
205 +
206 +int eTuxtxtApp::startUi()
207 +{
208 +       if (pid)
209 +       {
210 +               pthread_mutex_lock( &cacheChangeLock );
211 +               uiRunning = true;
212 +               pthread_mutex_unlock( &cacheChangeLock );
213 +               eDBoxLCD::getInstance()->lock();
214 +               eRCInput::getInstance()->lock();
215 +               fbClass::getInstance()->lock();
216 +               run();
217 +       }
218 +       return 0;
219 +}
220 +
221 +void eTuxtxtApp::thread()
222 +{
223 +       hasStarted();
224 +       tuxtxt_run_ui(pid);
225 +}
226 +
227 +void eTuxtxtApp::thread_finished()
228 +{
229 +       uiRunning = false;
230 +       fbClass::getInstance()->unlock();
231 +       eRCInput::getInstance()->unlock();
232 +       eDBoxLCD::getInstance()->unlock();
233 +}
234 +
235 +void eTuxtxtApp::initCache()
236 +{
237 +       if (enableTtCaching)
238 +               tuxtxt_init();
239 +}
240 +
241 +void eTuxtxtApp::freeCache()
242 +{
243 +       pthread_mutex_lock( &cacheChangeLock );
244 +       if ( !uiRunning )
245 +       {
246 +               tuxtxt_close();
247 +               pid = 0;
248 +       }
249 +       pthread_mutex_unlock( &cacheChangeLock );
250 +}
251 +
252 +void eTuxtxtApp::startCaching( int tpid )
253 +{
254 +       pid = tpid;
255 +       if (enableTtCaching)
256 +               tuxtxt_start(tpid);
257 +}
258 +
259 +void eTuxtxtApp::stopCaching()
260 +{
261 +       pthread_mutex_lock( &cacheChangeLock );
262 +       if ( !uiRunning )
263 +               tuxtxt_stop();
264 +
265 +       pthread_mutex_unlock( &cacheChangeLock );
266 +}
267 +
268 +void eTuxtxtApp::setEnableTtCachingOnOff( int onoff )
269 +{
270 +       if (onoff && !enableTtCaching)          // Switch caching on
271 +       {
272 +               enableTtCaching = true;
273 +               if (pid)
274 +               {
275 +                       initCache();
276 +                       startCaching(pid);
277 +               }
278 +       }
279 +       else if (!onoff && enableTtCaching)     // Switch caching off
280 +       {
281 +               enableTtCaching = false;
282 +               int savePid = pid;
283 +               freeCache();
284 +               pid = savePid;
285 +       }
286 +}
287 --- enigma2_orig/lib/components/tuxtxtapp.h     1970-01-01 00:00:00.000000000 +0000
288 +++ enigma2/lib/components/tuxtxtapp.h  2008-10-04 18:26:04.000000000 +0200
289 @@ -0,0 +1,32 @@
290 +#ifndef __LIB_COMPONENTS_TUXTXTAPP_H__
291 +#define __LIB_COMPONENTS_TUXTXTAPP_H__
292 +
293 +#include <string>
294 +#include <lib/base/ebase.h>
295 +#include <lib/base/thread.h>
296 +
297 +class eTuxtxtApp: private eThread, public Object
298 +{
299 +#ifndef SWIG
300 +       int pid;
301 +       bool enableTtCaching, uiRunning;
302 +       static eTuxtxtApp *instance;
303 +       pthread_mutex_t cacheChangeLock;
304 +
305 +       void thread();
306 +       void thread_finished();
307 +#endif
308 +public:
309 +       eTuxtxtApp();
310 +       ~eTuxtxtApp();
311 +       static eTuxtxtApp *getInstance() { return instance; }
312 +       int startUi();
313 +       void initCache();
314 +       void freeCache();
315 +       void startCaching( int tpid );
316 +       void stopCaching();
317 +       void resetPid() { pid = 0; }
318 +       void setEnableTtCachingOnOff( int onoff );
319 +};
320 +
321 +#endif // __LIB_COMPONENTS_TUXTXTAPP_H__