1 | #ifndef TIMESHIFT_H |
---|
2 | #define TIMESHIFT_H |
---|
3 | |
---|
4 | //flag 0: pause from rcpause |
---|
5 | //flag 1: pause from servicestart |
---|
6 | void timeshiftpause(int flag) |
---|
7 | { |
---|
8 | int ret = 0; |
---|
9 | |
---|
10 | if(flag == 0 && status.timeshift == 1 && status.playing == 0 && status.timeshifttype == 1 && status.timeshiftpos == 0) //stop service |
---|
11 | { |
---|
12 | ret = servicestop(status.aktservice, 0, 2); |
---|
13 | if(ret == 0) |
---|
14 | { |
---|
15 | struct service* snode = getservice(RECORDTIMESHIFT, 0); |
---|
16 | if(snode != NULL) |
---|
17 | { |
---|
18 | status.timeshiftstart = time(NULL); |
---|
19 | status.timeshiftpos = lseek64(snode->recdstfd, 0, SEEK_CUR); |
---|
20 | status.timeshiftpos = status.timeshiftpos - (status.timeshiftpos % snode->tssize); |
---|
21 | if(status.timeshiftpos <= 0) status.timeshiftpos = snode->tssize; |
---|
22 | } |
---|
23 | } |
---|
24 | } |
---|
25 | else if(status.timeshift == 0) //stop service an start timeshift record |
---|
26 | { |
---|
27 | //reset timeline |
---|
28 | struct skin* playinfobar = getscreen("playinfobar"); |
---|
29 | struct skin* sprogress = getscreennode(playinfobar, "progress"); |
---|
30 | sprogress->progresssize = 0; |
---|
31 | |
---|
32 | if(status.timeshifttype == 0) |
---|
33 | ret = servicestop(status.aktservice, 0, 2); |
---|
34 | if(ret == 0) |
---|
35 | { |
---|
36 | ret = recordstart(status.aktservice->channel, -1, 0, RECTIMESHIFT, 0, NULL); |
---|
37 | if(ret != 0) |
---|
38 | { |
---|
39 | status.timeshift = 0; |
---|
40 | if(status.timeshifttype == 0) |
---|
41 | servicecheckret(servicestart(status.aktservice->channel, NULL, NULL, 3), 0); |
---|
42 | } |
---|
43 | else |
---|
44 | status.timeshiftstart = time(NULL); |
---|
45 | recordcheckret(NULL, ret, 6); |
---|
46 | } |
---|
47 | } |
---|
48 | else if(status.playspeed == 0 && status.slowspeed == 0 && status.timeshift == 1 && status.playing == 1) //if playing, set pause |
---|
49 | { |
---|
50 | status.slowspeed = 0; |
---|
51 | status.playspeed = 0; |
---|
52 | status.play = 0; |
---|
53 | status.pause = 1; |
---|
54 | playerpausets(); |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | //flag 0: stop from rcstop |
---|
59 | //flag 1: stop from servicestop |
---|
60 | //flag 2: error in record thread |
---|
61 | //flag 3: stop from titan end |
---|
62 | void timeshiftstop(int flag) |
---|
63 | { |
---|
64 | int i = 0, ret = 0; |
---|
65 | char* file = NULL; |
---|
66 | |
---|
67 | if(flag == 1 && status.timeshifttype == 1 && status.playing == 0 && status.timeshiftpos > 0) |
---|
68 | return; |
---|
69 | if(flag == 0 && status.timeshifttype == 1) |
---|
70 | { |
---|
71 | if(status.timeshiftpos > 0 && status.playing == 0) |
---|
72 | goto startservice; |
---|
73 | else if(status.playing == 1) |
---|
74 | { |
---|
75 | if(status.playspeed != 0 || status.slowspeed != 0) |
---|
76 | { |
---|
77 | playerpausets(); |
---|
78 | playercontinuets(); |
---|
79 | } |
---|
80 | |
---|
81 | playerstopts(1, flag); |
---|
82 | |
---|
83 | writevfdmenu("Player"); |
---|
84 | screenplayinfobar(NULL, NULL, 1, 1, 4); |
---|
85 | |
---|
86 | goto startservice; |
---|
87 | } |
---|
88 | return; |
---|
89 | } |
---|
90 | |
---|
91 | struct service* snode = getservice(RECORDTIMESHIFT, flag); |
---|
92 | |
---|
93 | if(status.playspeed != 0 || status.slowspeed != 0) |
---|
94 | { |
---|
95 | playerpausets(); |
---|
96 | playercontinuets(); |
---|
97 | } |
---|
98 | |
---|
99 | playerstopts(1, flag); |
---|
100 | |
---|
101 | writevfdmenu("Player"); |
---|
102 | screenplayinfobar(NULL, NULL, 1, 1, 4); |
---|
103 | |
---|
104 | if(snode != NULL) |
---|
105 | { |
---|
106 | status.timeshift = 2; |
---|
107 | file = ostrcat(file, snode->recname, 1, 0); |
---|
108 | snode->recendtime = 1; |
---|
109 | |
---|
110 | ret = getconfigint("deltimeshift", NULL); |
---|
111 | if(ret == 0) |
---|
112 | { |
---|
113 | ret = textbox(_("Message"), _("Should Timeshift File deleted ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 400, 10, 0); |
---|
114 | if(ret == 0) ret = 1; |
---|
115 | } |
---|
116 | |
---|
117 | if(ret == 1) unlink(file); |
---|
118 | |
---|
119 | free(file); file = NULL; |
---|
120 | } |
---|
121 | |
---|
122 | if(flag == 0 || flag == 3) |
---|
123 | { |
---|
124 | while(status.timeshift > 0) |
---|
125 | { |
---|
126 | usleep(100000); |
---|
127 | i++; if(i > 20) break; |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | startservice: |
---|
132 | if(flag == 0 || flag == 2) |
---|
133 | servicecheckret(servicestart(status.aktservice->channel, NULL, NULL, 3), 0); |
---|
134 | |
---|
135 | //if timeshift ends in pause status, we must reactivate continue in player driver |
---|
136 | playercontinuets(); |
---|
137 | status.timeshiftstart = 0; |
---|
138 | status.timeshiftpos = 0; |
---|
139 | status.playspeed = 0; |
---|
140 | status.slowspeed = 0; |
---|
141 | status.pause = 0; |
---|
142 | status.play = 0; |
---|
143 | } |
---|
144 | |
---|
145 | void timeshiftplay(int* playinfobarstatus, int* playinfobarcount) |
---|
146 | { |
---|
147 | int ret = 1, waiting = 15; |
---|
148 | |
---|
149 | #ifdef MIPSEL |
---|
150 | waiting = 30; |
---|
151 | #endif |
---|
152 | |
---|
153 | struct service* snode = getservice(RECORDTIMESHIFT, 0); |
---|
154 | struct skin* playinfobarpic = getscreen("playinfobarpic"); |
---|
155 | |
---|
156 | if((status.timeshifttype == 0 && status.playing == 0) || (status.timeshifttype == 1 && status.playing == 0 && status.timeshiftpos > 0)) |
---|
157 | { |
---|
158 | |
---|
159 | if(status.timeshiftstart + waiting > time(NULL)) |
---|
160 | { |
---|
161 | textbox(_("Message"), _("Timeshift file to short\nplease wait a little and try again"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0); |
---|
162 | if(status.playpic == 0) |
---|
163 | { |
---|
164 | drawscreen(playinfobarpic, 0, 0); |
---|
165 | status.playpic = 1; |
---|
166 | } |
---|
167 | return; |
---|
168 | } |
---|
169 | |
---|
170 | if(snode != NULL) ret = playerstartts(snode->recname, 1); |
---|
171 | if(ret != 0) |
---|
172 | { |
---|
173 | textbox(_("Message"), _("Can't start timeshift play !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
174 | if(status.playpic == 0) |
---|
175 | { |
---|
176 | drawscreen(playinfobarpic, 0, 0); |
---|
177 | status.playpic = 1; |
---|
178 | } |
---|
179 | return; |
---|
180 | } |
---|
181 | } |
---|
182 | else if(status.playing == 0 && status.timeshifttype == 1) |
---|
183 | { |
---|
184 | status.playercan = 0x7FFF; |
---|
185 | *playinfobarstatus = 1; |
---|
186 | *playinfobarcount = 0; |
---|
187 | if(snode != NULL) screenplayinfobar(snode->recname, NULL, 0, 1, 5); |
---|
188 | } |
---|
189 | else if(status.playing == 1) |
---|
190 | { |
---|
191 | if(status.playspeed != 0 || status.slowspeed != 0) |
---|
192 | playerpausets(); |
---|
193 | if(status.slowspeed != 0) |
---|
194 | audioclearbuffer(status.aktservice->audiodev); |
---|
195 | playercontinuets(); |
---|
196 | if(status.playspeed != 0 || status.slowspeed != 0) |
---|
197 | playerresetts(); |
---|
198 | } |
---|
199 | |
---|
200 | if(status.playing == 0) return; |
---|
201 | |
---|
202 | status.slowspeed = 0; |
---|
203 | status.playspeed = 0; |
---|
204 | status.pause = 0; |
---|
205 | status.play = 1; |
---|
206 | status.playercan = 0x7FFF; |
---|
207 | *playinfobarstatus = 1; |
---|
208 | *playinfobarcount = 0; |
---|
209 | if(snode != NULL) screenplayinfobar(snode->recname, NULL, 0, 1, 4); |
---|
210 | } |
---|
211 | |
---|
212 | /* |
---|
213 | void timeshiftscreen(struct stimerthread* self, struct service* servicenode) |
---|
214 | { |
---|
215 | |
---|
216 | off64_t endoffile; |
---|
217 | off64_t currentpos; |
---|
218 | unsigned long long ptsend = 0; |
---|
219 | unsigned long long ptscurrent = 0; |
---|
220 | char* tmpstr = NULL; |
---|
221 | struct skin* framebuffer = getscreen("framebuffer"); |
---|
222 | struct skin* timeshift = getscreen("timeshift"); |
---|
223 | struct skin* seek = getscreennode(timeshift, "seek"); |
---|
224 | struct skin* timeshiftbar = getscreennode(timeshift, "timeshiftbar"); |
---|
225 | char* bg = NULL; |
---|
226 | int seeking = 0, timeout = 0, ret = 0, minuten = 0, sekunden = 0; |
---|
227 | struct service* snode = getservice(RECORDTIMESHIFT, 0); |
---|
228 | int fd = -1; |
---|
229 | |
---|
230 | if(servicenode == NULL) |
---|
231 | { |
---|
232 | err("NULL detect"); |
---|
233 | return; |
---|
234 | } |
---|
235 | |
---|
236 | if(snode != NULL) |
---|
237 | fd = open(snode->recname, O_RDONLY | O_LARGEFILE); |
---|
238 | |
---|
239 | if(fd < 0) |
---|
240 | { |
---|
241 | err("timeshift fd not ok"); |
---|
242 | return; |
---|
243 | } |
---|
244 | |
---|
245 | timeshiftbar->progresssize = 0; |
---|
246 | setnodeattr(timeshift, framebuffer, 0); |
---|
247 | bg = savescreen(timeshift); |
---|
248 | if(status.timeshiftseek == 999999) |
---|
249 | timeout = 5; |
---|
250 | |
---|
251 | while(status.timeshiftseek != 0 || seeking != 0) |
---|
252 | { |
---|
253 | currentpos = lseek64(servicenode->recsrcfd, 0, SEEK_CUR); |
---|
254 | currentpos = currentpos - 5000000; |
---|
255 | endoffile = lseek64(fd , 0, SEEK_END); |
---|
256 | |
---|
257 | if(endoffile != 0) |
---|
258 | { |
---|
259 | timeshiftbar->progresssize = currentpos * 100 / endoffile; |
---|
260 | if(status.timeshiftseek < 999999) |
---|
261 | { |
---|
262 | if(status.timeshiftseek > 10000) |
---|
263 | { |
---|
264 | tmpstr = oitoa(status.timeshiftseek - 10000); |
---|
265 | tmpstr = ostrcat(_(">> "), tmpstr, 0, 1); |
---|
266 | tmpstr = ostrcat(tmpstr, "x", 1, 0); |
---|
267 | changetext(seek, tmpstr); |
---|
268 | free(tmpstr); tmpstr = NULL; |
---|
269 | } |
---|
270 | if(status.timeshiftseek < 10000 && status.timeshiftseek > -10000) |
---|
271 | { |
---|
272 | if(seeking == 0) |
---|
273 | { |
---|
274 | seeking = status.timeshiftseek; |
---|
275 | tmpstr = oitoa(status.timeshiftseek); |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | tmpstr = oitoa(seeking); |
---|
280 | seeking = 0; |
---|
281 | } |
---|
282 | tmpstr = ostrcat(_("skip "), tmpstr, 0, 1); |
---|
283 | tmpstr = ostrcat(tmpstr, " sec", 1, 0); |
---|
284 | changetext(seek, tmpstr); |
---|
285 | free(tmpstr); tmpstr = NULL; |
---|
286 | } |
---|
287 | } |
---|
288 | else |
---|
289 | { |
---|
290 | ret = getptspos(fd, currentpos, &ptscurrent, ¤tpos, 1, servicenode->tssize); |
---|
291 | ret = getpts(fd, 0, 0, 256 * 1024, &ptsend, &endoffile, -1, servicenode->tssize); |
---|
292 | sekunden = (ptsend - ptscurrent) / 90000; |
---|
293 | minuten = sekunden / 60; |
---|
294 | sekunden = sekunden % 60; |
---|
295 | tmpstr = ostrcat(tmpstr, "-", 1, 0); |
---|
296 | tmpstr = ostrcat(tmpstr, oitoa(minuten), 1, 1); |
---|
297 | tmpstr = ostrcat(tmpstr, ":", 1, 0); |
---|
298 | |
---|
299 | if(sekunden < 10) |
---|
300 | tmpstr = ostrcat(tmpstr, "0", 1, 0); |
---|
301 | |
---|
302 | tmpstr = ostrcat(tmpstr, oitoa(sekunden), 1, 1); |
---|
303 | tmpstr = ostrcat(tmpstr, " min", 1, 0); |
---|
304 | changetext(seek, tmpstr); |
---|
305 | free(tmpstr); tmpstr = NULL; |
---|
306 | } |
---|
307 | } |
---|
308 | |
---|
309 | drawscreen(timeshift, 0, 0); |
---|
310 | sleep (1); |
---|
311 | if(status.timeshiftseek == 999999) { |
---|
312 | timeout = timeout - 1; |
---|
313 | if(timeout == 0) |
---|
314 | status.timeshiftseek = 0; |
---|
315 | } |
---|
316 | } |
---|
317 | |
---|
318 | restorescreen(bg, timeshift); |
---|
319 | blitfb(0); |
---|
320 | close(fd); |
---|
321 | } |
---|
322 | |
---|
323 | //flag 0: normal ff or fr |
---|
324 | //flag 1: ff or fr back |
---|
325 | void timeshiftseek(int sekunden, int* playinfobarstatus, int* playinfobarcount, int flag) |
---|
326 | { |
---|
327 | struct service* snode = getservice(RECORDPLAY, 0); |
---|
328 | |
---|
329 | if(sekunden < 999999) |
---|
330 | { |
---|
331 | status.timeshiftseek = sekunden; |
---|
332 | if(snode != 0) |
---|
333 | { |
---|
334 | if(sekunden > 10000) |
---|
335 | { |
---|
336 | if(sekunden < 20000) |
---|
337 | { |
---|
338 | if(sekunden >= 10128) |
---|
339 | { |
---|
340 | status.timeshiftseek = 10064; |
---|
341 | return; |
---|
342 | } |
---|
343 | status.play = 0; |
---|
344 | if(flag == 0) |
---|
345 | status.playspeed++; |
---|
346 | else |
---|
347 | status.playspeed--; |
---|
348 | sekunden = sekunden - 10000; |
---|
349 | playerffts(sekunden); |
---|
350 | } |
---|
351 | else |
---|
352 | { |
---|
353 | if(sekunden >= 20128) |
---|
354 | { |
---|
355 | status.timeshiftseek = 20064; |
---|
356 | return; |
---|
357 | } |
---|
358 | status.play = 0; |
---|
359 | if(flag == 0) |
---|
360 | status.playspeed--; |
---|
361 | else |
---|
362 | status.playspeed++; |
---|
363 | sekunden = sekunden - 20000; |
---|
364 | playerfrts(sekunden * -1, 1); |
---|
365 | //playerseekts(snode, -10, 0); |
---|
366 | } |
---|
367 | *playinfobarstatus = 2; |
---|
368 | *playinfobarcount = 0; |
---|
369 | screenplayinfobar(status.playfile, NULL, 0, 1, 4); |
---|
370 | } |
---|
371 | else |
---|
372 | { |
---|
373 | playerseekts(snode, sekunden, 0); |
---|
374 | *playinfobarstatus = 1; |
---|
375 | *playinfobarcount = 0; |
---|
376 | screenplayinfobar(status.playfile, NULL, 0, 1, 4); |
---|
377 | } |
---|
378 | } |
---|
379 | } |
---|
380 | else |
---|
381 | { |
---|
382 | if(*playinfobarstatus == 0) |
---|
383 | { |
---|
384 | *playinfobarstatus = 1; |
---|
385 | *playinfobarcount = 0; |
---|
386 | screenplayinfobar(status.playfile, NULL, 0, 1, 4); |
---|
387 | } |
---|
388 | else if(*playinfobarstatus == 1) |
---|
389 | { |
---|
390 | *playinfobarstatus = 0; |
---|
391 | screenplayinfobar(status.playfile, NULL, 1, 1, 4); |
---|
392 | } |
---|
393 | } |
---|
394 | } |
---|
395 | */ |
---|
396 | |
---|
397 | void timeshiftinfobar(int* playinfobarstatus, int* playinfobarcount) |
---|
398 | { |
---|
399 | if(status.playing == 0 && status.playspeed == 0) |
---|
400 | { |
---|
401 | *playinfobarstatus = 2; |
---|
402 | //player simmulieren fuer infobar |
---|
403 | status.playercan = 0xFFFF; |
---|
404 | status.pause = 1; |
---|
405 | } |
---|
406 | |
---|
407 | if(status.playing == 1 && status.pause == 1) |
---|
408 | { |
---|
409 | //*playinfobarstatus = 0; |
---|
410 | *playinfobarstatus = 2; |
---|
411 | //screenplayinfobar(NULL, NULL, 1, 1, 4); |
---|
412 | } |
---|
413 | if(status.playing == 1) |
---|
414 | { |
---|
415 | (*playinfobarcount)++; |
---|
416 | if(*playinfobarstatus == 2) |
---|
417 | { |
---|
418 | screenplayinfobar(status.playfile, NULL, 0, 1, 4); |
---|
419 | if(status.playspeed == 0 && status.slowspeed == 0) //used for begin of file with fr |
---|
420 | { |
---|
421 | *playinfobarstatus = 1; |
---|
422 | *playinfobarcount = 0; |
---|
423 | } |
---|
424 | } |
---|
425 | if(*playinfobarstatus == 1) |
---|
426 | screenplayinfobar(status.playfile, NULL, 0, 1, 4); |
---|
427 | if(*playinfobarstatus == 1 && *playinfobarcount >= getconfigint("infobartimeout", NULL) && status.playspeed == 0 && status.slowspeed == 0) |
---|
428 | { |
---|
429 | *playinfobarstatus = 0; |
---|
430 | screenplayinfobar(NULL, NULL, 1, 1, 4); |
---|
431 | } |
---|
432 | } |
---|
433 | else if(*playinfobarstatus > 0) |
---|
434 | { |
---|
435 | *playinfobarstatus = 0; |
---|
436 | screenplayinfobar(NULL, NULL, 1, 1, 4); |
---|
437 | } |
---|
438 | } |
---|
439 | |
---|
440 | void timeshiftposplay(int* playinfobarstatus, int* playinfobarcount) |
---|
441 | { |
---|
442 | unsigned long long oldpos = status.timeshiftpos; |
---|
443 | struct service* snode = getservice(RECORDTIMESHIFT, 0); |
---|
444 | if(snode != NULL) |
---|
445 | { |
---|
446 | status.timeshiftpos = lseek64(snode->recdstfd, 0, SEEK_CUR) - 10000000; |
---|
447 | status.timeshiftpos = status.timeshiftpos - (status.timeshiftpos % snode->tssize); |
---|
448 | if(status.timeshiftpos <= 0) status.timeshiftpos = snode->tssize; |
---|
449 | } |
---|
450 | timeshiftplay(playinfobarstatus, playinfobarcount); |
---|
451 | if(status.playing == 0) |
---|
452 | status.timeshiftpos = oldpos; |
---|
453 | else |
---|
454 | status.timeshiftpos = 0; |
---|
455 | } |
---|
456 | |
---|
457 | |
---|
458 | #endif |
---|