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