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