1 | #ifndef OPERA_H
|
---|
2 | #define OPERA_H
|
---|
3 |
|
---|
4 | #define NAME "YWNATIVE"
|
---|
5 | #define CONTROL_PIPE_W "/tmp/"NAME"_control_w"
|
---|
6 | #define CONTROL_PIPE_R "/tmp/"NAME"_control_r"
|
---|
7 | #define RC_TITAN "/tmp/rc_enigma2"
|
---|
8 | #define OPERA_ROOT "/var/swap/titanplugins/hbbtv/opera"
|
---|
9 | #define OPERA_BIN OPERA_ROOT"/bin/opera"
|
---|
10 |
|
---|
11 | extern struct skin* skin;
|
---|
12 |
|
---|
13 | void operareceivercb(char* cmd);
|
---|
14 |
|
---|
15 | int operarcsockfd = -1;
|
---|
16 | int operarcconnfd = -1;
|
---|
17 | int control_r_fd = -1;
|
---|
18 | int operarcthread_ok = 0;
|
---|
19 | int operareceiverthread_ok = 0;
|
---|
20 | char* operaplayurl = NULL;
|
---|
21 |
|
---|
22 | void operarcthread()
|
---|
23 | {
|
---|
24 | int ret = 0;
|
---|
25 |
|
---|
26 | debug(788, "opera create rc socket");
|
---|
27 |
|
---|
28 | ret = sockcreate(&operarcsockfd, RC_TITAN, 1);
|
---|
29 | if(ret != 0) return;
|
---|
30 |
|
---|
31 | debug(788, "opera wait for rc accept");
|
---|
32 | operarcthread_ok = 1;
|
---|
33 | operarcconnfd = sockaccept(&operarcsockfd, 0);
|
---|
34 | debug(788, "opera got rc accept");
|
---|
35 | }
|
---|
36 |
|
---|
37 | void operareceiverthread(struct stimerthread* self)
|
---|
38 | {
|
---|
39 | int ret = 0, control_w_fd = -1;
|
---|
40 | fd_set rfds;
|
---|
41 | struct timeval tv;
|
---|
42 | unsigned char* buf = NULL;
|
---|
43 |
|
---|
44 | if(self == NULL) return;
|
---|
45 |
|
---|
46 | control_w_fd = open(CONTROL_PIPE_W, O_RDONLY);
|
---|
47 | if(control_w_fd < 0)
|
---|
48 | {
|
---|
49 | perr("open or create %s", CONTROL_PIPE_W);
|
---|
50 | return;
|
---|
51 | }
|
---|
52 |
|
---|
53 | fcntl(control_w_fd, F_SETFL, fcntl(control_w_fd, F_GETFL) | O_NONBLOCK);
|
---|
54 | closeonexec(control_w_fd);
|
---|
55 |
|
---|
56 | buf = malloc(MINMALLOC);
|
---|
57 | if(buf == NULL)
|
---|
58 | {
|
---|
59 | close(control_w_fd);
|
---|
60 | err("no mem");
|
---|
61 | return;
|
---|
62 | }
|
---|
63 |
|
---|
64 | debug(788, "opera receive thread start");
|
---|
65 |
|
---|
66 | operareceiverthread_ok = 1;
|
---|
67 | while(self->aktion != STOP)
|
---|
68 | {
|
---|
69 | tv.tv_sec = 1;
|
---|
70 | tv.tv_usec = 0;
|
---|
71 | FD_ZERO(&rfds);
|
---|
72 | FD_SET(control_w_fd, &rfds);
|
---|
73 |
|
---|
74 | ret = TEMP_FAILURE_RETRY(select(control_w_fd + 1, &rfds, NULL, NULL, &tv));
|
---|
75 |
|
---|
76 | if(ret > 0)
|
---|
77 | {
|
---|
78 | memset(buf, 0, MINMALLOC);
|
---|
79 | unsigned char* pbuf = buf;
|
---|
80 | while(pbuf - buf < MINMALLOC)
|
---|
81 | {
|
---|
82 | unsigned char c;
|
---|
83 |
|
---|
84 | ret = read(control_w_fd, &c, 1);
|
---|
85 | if(ret == 1)
|
---|
86 | {
|
---|
87 | if(c == '\n') break;
|
---|
88 | *pbuf = c;
|
---|
89 | pbuf++;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | if(pbuf != buf)
|
---|
93 | operareceivercb((char*)buf);
|
---|
94 | }
|
---|
95 | else if(ret == 0) //timeout
|
---|
96 | continue;
|
---|
97 | else //error
|
---|
98 | {
|
---|
99 | perr("select failed");
|
---|
100 | usleep(10000);
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | close(control_w_fd); control_w_fd = -1;
|
---|
105 | free(buf); buf = NULL;
|
---|
106 | debug(788, "opera receive thread end");
|
---|
107 | }
|
---|
108 |
|
---|
109 | void operasendkey(char* rckey)
|
---|
110 | {
|
---|
111 | if(operarcconnfd > -1 && rckey != NULL)
|
---|
112 | socksend(&operarcconnfd, (unsigned char*)rckey, strlen(rckey), -1);
|
---|
113 | else
|
---|
114 | {
|
---|
115 | err("no opera rc context sockfd=%d", operarcconnfd);
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | void screenopera(char* url)
|
---|
120 | {
|
---|
121 | int rcret = 0, i = 0;
|
---|
122 | char* tmpstr = NULL;
|
---|
123 | void* threadstatus;
|
---|
124 | struct stimerthread* operareceiver = NULL;
|
---|
125 |
|
---|
126 | drawscreen(skin, 0);
|
---|
127 |
|
---|
128 | debug(788, "step 1, set env");
|
---|
129 | //setenv("DFBARGS", "pixelformat=ARGB,no-cursor,bg-none,no-linux-input-grab,no-vt", 1);
|
---|
130 | setenv("OPERA_MULTITAP", "NO", 1);
|
---|
131 | setenv("OPERA_SHOW_STATUSWINDOW", "NO", 1);
|
---|
132 | setenv("OPERA_FB_BORDERWIDTH", "0", 1);
|
---|
133 | setenv("OPERA_SHOW_IMEWINDOW", "NO", 1);
|
---|
134 | setenv("OPERA_SHOW_NAVIGATIONWINDOW", "NO", 1);
|
---|
135 | setenv("OPERA_SHOW_MOUSEPOINTER", "NO", 1);
|
---|
136 | setenv("OPERA_SHOW_HIGHLIGHT", "NO", 1);
|
---|
137 | setenv("OPERA_ESC_EXIT", "YES", 1);
|
---|
138 | setenv("FREETYPE_FONT_SET", "YES", 1);
|
---|
139 | setenv("OPERA_ROOT", OPERA_ROOT, 1);
|
---|
140 | setenv("OPERA_FB_SIZE", "1280x720", 1);
|
---|
141 | setenv("OPERA_DIR", OPERA_ROOT"/opera_dir", 1);
|
---|
142 | setenv("OPERA_HOME", OPERA_ROOT"/opera_home/", 1);
|
---|
143 | setenv("OPERA_FONTS", OPERA_ROOT"/fonts", 1);
|
---|
144 | setenv("OPERA_WIDGETS", OPERA_ROOT"/widgets", 1);
|
---|
145 | setenv("LD_LIBRARY_PATH", OPERA_ROOT, 1); // + ":" + os.environ["LD_LIBRARY_PATH"]
|
---|
146 |
|
---|
147 | unlink(CONTROL_PIPE_W);
|
---|
148 | unlink(CONTROL_PIPE_R);
|
---|
149 | unlink(RC_TITAN);
|
---|
150 |
|
---|
151 | mkfifo(CONTROL_PIPE_W, 0666);
|
---|
152 | mkfifo(CONTROL_PIPE_R, 0666);
|
---|
153 | //mkfifo(RC_TITAN, 0666);
|
---|
154 |
|
---|
155 | debug(788, "step 2, start opera");
|
---|
156 | writesys("/proc/cpu/alignment", "0", 0);
|
---|
157 |
|
---|
158 | operarcthread_ok = 0;
|
---|
159 | operareceiverthread_ok = 0;
|
---|
160 | addtimer(&operarcthread, START, 10, 1, NULL, NULL, NULL);
|
---|
161 | operareceiver = addtimer(&operareceiverthread, START, 10, 1, NULL, NULL, NULL);
|
---|
162 |
|
---|
163 | //wait for threads
|
---|
164 | int count = 0;
|
---|
165 | while(operarcthread_ok == 0 || operareceiverthread_ok == 0)
|
---|
166 | {
|
---|
167 | usleep(100000);
|
---|
168 | count++;
|
---|
169 | if(count > 20) break;
|
---|
170 | }
|
---|
171 |
|
---|
172 | //TODO change working dir to OPERA_ROOT
|
---|
173 | chdir(OPERA_ROOT);
|
---|
174 |
|
---|
175 | tmpstr = ostrcat(tmpstr, OPERA_BIN, 1, 0);
|
---|
176 | tmpstr = ostrcat(tmpstr, " -u ", 1, 0);
|
---|
177 | tmpstr = ostrcat(tmpstr, url, 1, 0);
|
---|
178 | tmpstr = ostrcat(tmpstr, " --dfb:mode=1280x720,no-debug,no-vt,no-vt-switch &", 1, 0);
|
---|
179 | system(tmpstr);
|
---|
180 | free(tmpstr); tmpstr = NULL;
|
---|
181 |
|
---|
182 | while(1)
|
---|
183 | {
|
---|
184 | rcret = waitrc(NULL, 0, 0);
|
---|
185 |
|
---|
186 | if(rcret == getrcconfigint("rcexit", NULL))
|
---|
187 | {
|
---|
188 | //operasendkey("ESC");
|
---|
189 | break;
|
---|
190 | }
|
---|
191 | //TODO
|
---|
192 | //operasendkey("BACK");
|
---|
193 | else if(rcret == getrcconfigint("rcred", NULL))
|
---|
194 | operasendkey("RED");
|
---|
195 | else if(rcret == getrcconfigint("rcgreen", NULL))
|
---|
196 | operasendkey("GREEN");
|
---|
197 | else if(rcret == getrcconfigint("rcyellow", NULL))
|
---|
198 | operasendkey("YELLOW");
|
---|
199 | else if(rcret == getrcconfigint("rcblue", NULL))
|
---|
200 | operasendkey("BLUE");
|
---|
201 | else if(rcret == getrcconfigint("rcok", NULL))
|
---|
202 | {
|
---|
203 | operasendkey("OK");
|
---|
204 | operasendkey("ENTER");
|
---|
205 | }
|
---|
206 | else if(rcret == getrcconfigint("rcup", NULL))
|
---|
207 | operasendkey("UP");
|
---|
208 | else if(rcret == getrcconfigint("rcdown", NULL))
|
---|
209 | operasendkey("DOWN");
|
---|
210 | else if(rcret == getrcconfigint("rcleft", NULL))
|
---|
211 | operasendkey("LEFT");
|
---|
212 | else if(rcret == getrcconfigint("rcright", NULL))
|
---|
213 | operasendkey("RIGHT");
|
---|
214 | else if(rcret == getrcconfigint("rc1", NULL))
|
---|
215 | operasendkey("1");
|
---|
216 | else if(rcret == getrcconfigint("rc2", NULL))
|
---|
217 | operasendkey("2");
|
---|
218 | else if(rcret == getrcconfigint("rc3", NULL))
|
---|
219 | operasendkey("3");
|
---|
220 | else if(rcret == getrcconfigint("rc4", NULL))
|
---|
221 | operasendkey("4");
|
---|
222 | else if(rcret == getrcconfigint("rc5", NULL))
|
---|
223 | operasendkey("5");
|
---|
224 | else if(rcret == getrcconfigint("rc6", NULL))
|
---|
225 | operasendkey("6");
|
---|
226 | else if(rcret == getrcconfigint("rc7", NULL))
|
---|
227 | operasendkey("7");
|
---|
228 | else if(rcret == getrcconfigint("rc8", NULL))
|
---|
229 | operasendkey("8");
|
---|
230 | else if(rcret == getrcconfigint("rc9", NULL))
|
---|
231 | operasendkey("9");
|
---|
232 | else if(rcret == getrcconfigint("rc0", NULL))
|
---|
233 | operasendkey("0");
|
---|
234 | }
|
---|
235 |
|
---|
236 | if(operareceiver != NULL)
|
---|
237 | {
|
---|
238 | operareceiver->aktion = STOP;
|
---|
239 | while(operareceiver->status != DEACTIVE)
|
---|
240 | {
|
---|
241 | usleep(100000);
|
---|
242 | i++; if(i > 20) break;
|
---|
243 | }
|
---|
244 |
|
---|
245 | if(i > 20)
|
---|
246 | {
|
---|
247 | err("detect hanging timer sub thread (operareceiver)");
|
---|
248 | }
|
---|
249 | else if(operareceiver->count < 0 && operareceiver->thread != '\0')
|
---|
250 | pthread_join(operareceiver->thread, &threadstatus);
|
---|
251 | pthread_attr_destroy(&operareceiver->attr);
|
---|
252 | }
|
---|
253 |
|
---|
254 | sockclose(&operarcsockfd);
|
---|
255 | sockclose(&operarcconnfd);
|
---|
256 | close(control_r_fd);
|
---|
257 |
|
---|
258 | sleep(5);
|
---|
259 |
|
---|
260 | debug(788, "kill opera");
|
---|
261 | tmpstr = ostrcat(tmpstr, "killall opera", 1, 0);
|
---|
262 | system(tmpstr);
|
---|
263 | free(tmpstr); tmpstr = NULL;
|
---|
264 |
|
---|
265 | free(operaplayurl); operaplayurl = NULL;
|
---|
266 |
|
---|
267 | writesys("/proc/cpu/alignment", "1", 0);
|
---|
268 |
|
---|
269 | //setvideomode("720p50", 0);
|
---|
270 | //changefbresolution("720p50");
|
---|
271 |
|
---|
272 | drawscreen(skin, 0);
|
---|
273 | }
|
---|
274 |
|
---|
275 | void operareceivercb(char* cmd)
|
---|
276 | {
|
---|
277 | int count = 0;
|
---|
278 | char* tmpstr = NULL;
|
---|
279 | struct splitstr* ret = NULL;
|
---|
280 |
|
---|
281 | debug(788, "cmd=%s", cmd);
|
---|
282 |
|
---|
283 | tmpstr = ostrcat(cmd, NULL, 0, 0);
|
---|
284 | ret = strsplit(tmpstr, " ", &count);
|
---|
285 |
|
---|
286 | if(ret != NULL && count > 0)
|
---|
287 | {
|
---|
288 | if(ostrcmp("HELLO", (&ret[0])->part) == 0)
|
---|
289 | {
|
---|
290 |
|
---|
291 | printf("xccccccccccccccccccccccccccccccccc");
|
---|
292 | control_r_fd = open(CONTROL_PIPE_R, O_WRONLY);
|
---|
293 | if(control_r_fd < 0)
|
---|
294 | {
|
---|
295 | perr("open or create "CONTROL_PIPE_R);
|
---|
296 | }
|
---|
297 | }
|
---|
298 | else if(ostrcmp("AvSetWin", (&ret[0])->part) == 0)
|
---|
299 | {
|
---|
300 | int x = 0, y = 0, w = 0, h = 0;
|
---|
301 | float xw = 720.0 / 1280.0;
|
---|
302 | float yh = 576.0 / 720.0;
|
---|
303 | char* position = NULL;
|
---|
304 |
|
---|
305 | if(count > 1) x = atoi((&ret[1])->part) * xw;
|
---|
306 | if(count > 2) y = atoi((&ret[2])->part) * yh;
|
---|
307 | if(count > 3) w = atoi((&ret[3])->part) * xw;
|
---|
308 | if(count > 4) h = atoi((&ret[4])->part) * yh;
|
---|
309 |
|
---|
310 | if(w == 0 && h == 0)
|
---|
311 | {
|
---|
312 | w = 720;
|
---|
313 | h = 576;
|
---|
314 | }
|
---|
315 |
|
---|
316 | //TODO
|
---|
317 | //position = "%x %x %x %x" % (x, y, w, h)
|
---|
318 | writesys("/proc/stb/vmpeg/0/dst_all", position, 0);
|
---|
319 | }
|
---|
320 | else if(ostrcmp("AvGetFullScreen", (&ret[0])->part) == 0)
|
---|
321 | {
|
---|
322 | char* w = NULL, *h = NULL;
|
---|
323 |
|
---|
324 | w = readsys("/proc/stb/vmpeg/0/dst_width", 1);
|
---|
325 | h = readsys("/proc/stb/vmpeg/0/dst_height", 1);
|
---|
326 |
|
---|
327 | if(ostrcmp(w, "2d0") == 0 && ostrcmp(h, "240") == 0)
|
---|
328 | write(control_r_fd, "AvGetFullScreen 1\n", 18);
|
---|
329 | else
|
---|
330 | write(control_r_fd, "AvGetFullScreen 0\n", 18);
|
---|
331 |
|
---|
332 | free(w); w = NULL;
|
---|
333 | free(h); h = NULL;
|
---|
334 | }
|
---|
335 | else if(ostrcmp("AvGetVisible", (&ret[0])->part) == 0)
|
---|
336 | {
|
---|
337 | unsigned long val = readsysul("/proc/stb/video/alpha", 1);
|
---|
338 |
|
---|
339 | if(val == 0)
|
---|
340 | write(control_r_fd, "AvGetVisible 1\n", 15);
|
---|
341 | else
|
---|
342 | write(control_r_fd, "AvGetVisible 0\n", 15);
|
---|
343 | }
|
---|
344 | /*
|
---|
345 | else if(ostrncmp("AvSetVisible", (&ret[0])->part) == 0)
|
---|
346 | {
|
---|
347 | //if(count > 1 && ostrcmp("1", (&ret[1])->part) == 0)
|
---|
348 | //{
|
---|
349 | // writesys("/proc/stb/video/alpha", "255", 0);
|
---|
350 | //else
|
---|
351 | // writesys("/proc/stb/video/alpha", "0", 0);
|
---|
352 | //}
|
---|
353 | }
|
---|
354 | */
|
---|
355 | else if(ostrcmp("AvPlay", (&ret[0])->part) == 0)
|
---|
356 | {
|
---|
357 | //TODO
|
---|
358 | if(count > 2)
|
---|
359 | {
|
---|
360 | if(ostrcmp("100", (&ret[2])->part) == 0) //PLAY OR RESUME
|
---|
361 | {
|
---|
362 | if(ostrcmp(operaplayurl, (&ret[1])->part) != 0) //DIFFERENT URI SO PLAY
|
---|
363 | {
|
---|
364 | free(operaplayurl); operaplayurl = NULL;
|
---|
365 | operaplayurl = ostrcat((&ret[1])->part, NULL, 0, 0);
|
---|
366 | //self.mp.stopStream()
|
---|
367 | //self.mp.startStream(operaplayurl)
|
---|
368 | }
|
---|
369 | else
|
---|
370 | {
|
---|
371 | //self.mp.resumeStream()
|
---|
372 | }
|
---|
373 | }
|
---|
374 | else if(ostrcmp("0", (&ret[2])->part) == 0) //PAUSE
|
---|
375 | {
|
---|
376 | //self.mp.pauseStream()
|
---|
377 | }
|
---|
378 | }
|
---|
379 | }
|
---|
380 | else if(ostrcmp("AvStop", (&ret[0])->part) == 0)
|
---|
381 | {
|
---|
382 | //TODO
|
---|
383 | //self.mp.stopStream()
|
---|
384 | }
|
---|
385 | else if(ostrcmp("AvGetPos", (&ret[0])->part) == 0)
|
---|
386 | {
|
---|
387 | char* tmppos = NULL;
|
---|
388 | unsigned long long int pos = 0;
|
---|
389 | //TODO
|
---|
390 | //pos = self.mp.getPosition()
|
---|
391 |
|
---|
392 | tmppos = ostrcat(tmppos, "AvGetPos ", 1, 0);
|
---|
393 | tmppos = ostrcat(tmppos, oitoa(pos), 1, 1);
|
---|
394 | tmppos = ostrcat(tmppos, "\n", 1, 0);
|
---|
395 | if(tmppos != NULL)
|
---|
396 | write(control_r_fd, tmppos, strlen(tmppos));
|
---|
397 | free(tmppos); tmppos = NULL;
|
---|
398 | }
|
---|
399 | else if(ostrcmp("AvGetDuration", (&ret[0])->part) == 0)
|
---|
400 | {
|
---|
401 | char* tmplen = NULL;
|
---|
402 | unsigned long long int len = 0;
|
---|
403 | //TODO
|
---|
404 | //len = self.mp.getDuration()
|
---|
405 |
|
---|
406 | tmplen = ostrcat(tmplen, "AvGetDuration ", 1, 0);
|
---|
407 | tmplen = ostrcat(tmplen, oitoa(len), 1, 1);
|
---|
408 | tmplen = ostrcat(tmplen, "\n", 1, 0);
|
---|
409 | if(tmplen != NULL)
|
---|
410 | write(control_r_fd, tmplen, strlen(tmplen));
|
---|
411 | free(tmplen); tmplen = NULL;
|
---|
412 | }
|
---|
413 | else if(ostrcmp("AvGetState", (&ret[0])->part) == 0)
|
---|
414 | {
|
---|
415 | char* tmpstate = NULL;
|
---|
416 | int state = 0;
|
---|
417 | //TODO
|
---|
418 | //state = self.mp.getState()
|
---|
419 |
|
---|
420 | tmpstate = ostrcat(tmpstate, "AvGetState ", 1, 0);
|
---|
421 | tmpstate = ostrcat(tmpstate, oitoa(state), 1, 1);
|
---|
422 | tmpstate = ostrcat(tmpstate, "\n", 1, 0);
|
---|
423 | if(tmpstate != NULL)
|
---|
424 | write(control_r_fd, tmpstate, strlen(tmpstate));
|
---|
425 | free(tmpstate); tmpstate = NULL;
|
---|
426 | }
|
---|
427 | else if(ostrcmp("ReleaseHandle", (&ret[0])->part) == 0)
|
---|
428 | {
|
---|
429 | if(count > 1 && ostrcmp("1", (&ret[1])->part) == 0) //VOD
|
---|
430 | {
|
---|
431 | //Switch back to live tv after vod session ended
|
---|
432 | //TODO
|
---|
433 | //gSession.nav.playService(self.service)
|
---|
434 | }
|
---|
435 | }
|
---|
436 | }
|
---|
437 |
|
---|
438 | free(tmpstr); tmpstr = NULL;
|
---|
439 | free(ret); ret = NULL;
|
---|
440 | }
|
---|
441 |
|
---|
442 | #endif
|
---|