source: titan/titan/timeshift.h @ 15338

Last change on this file since 15338 was 14355, checked in by nit, 12 years ago

[titan] next step make tssize dynamic

File size: 5.4 KB
Line 
1#ifndef TIMESHIFT_H
2#define TIMESHIFT_H
3
4void timeshiftpause()
5{
6        int ret = 0;
7
8        if(status.timeshift == 0)
9        {
10                ret = servicestop(status.aktservice, 0, 2);
11                if(ret == 0)
12                {
13                        ret = recordstart(status.aktservice->channel, -1, 0, RECTIMESHIFT, 0, NULL);
14                        if(ret != 0)
15                        {
16                                status.timeshift = 0;
17                                servicecheckret(servicestart(status.aktservice->channel, NULL, NULL, 3), 0);
18                        }
19                        recordcheckret(NULL, ret, 6);
20                }
21        }
22        else {
23                if(status.timeshiftseek != 0)
24                        status.timeshiftseek = 0;
25                playerpausets();
26        }
27}
28
29//flag 0: stop from rcstop
30//flag 1: stop from servicestop
31void timeshiftstop(int flag)
32{
33        int i = 0, ret = 0;
34        char* file = NULL;
35        struct service* snode = getservice(RECORDTIMESHIFT, flag);
36
37        if(status.timeshiftseek != 0) {
38                status.timeshiftseek = 0;
39                playerpausets();
40                playercontinuets();
41        }
42       
43        playerstopts(1, flag);
44
45        if(snode != NULL)
46        {
47                file = ostrcat(file, snode->recname, 1, 0);
48                snode->recendtime = 1;
49
50                ret = getconfigint("deltimeshift", NULL);
51                if(ret == 0)
52                        ret = textbox(_("Message"), _("Should Timeshift File deleted ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 400, 10, 0);
53
54                if(ret == 0 || ret == 1) unlink(file);
55                free(file); file = NULL;
56        }
57
58        if(flag == 0)
59        {
60                while(status.timeshift == 1)
61                {
62                        usleep(100000);
63                        i++; if(i > 20) break;
64                }
65                servicecheckret(servicestart(status.aktservice->channel, NULL, NULL, 3), 0);
66        }
67       
68        //if timeshift ends in pause status, we must reactivate continue in player driver
69        playercontinuets();
70}
71
72void timeshiftplay()
73{
74        int ret = 1;
75        struct service* snode = getservice(RECORDTIMESHIFT, 0);
76       
77        if(status.playing == 0)
78        {
79                if(snode != NULL) ret = playerstartts(snode->recname, 1);
80                if(ret != 0)
81                {
82                        textbox(_("Message"), _("Can't start timeshift play !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
83                }
84        }
85        else {
86                if(status.timeshiftseek != 0) {
87                        status.timeshiftseek = 0;
88                        playerpausets();
89                }
90                playercontinuets();
91        }
92}
93
94void timeshiftscreen(struct stimerthread* self, struct service* servicenode)
95{
96       
97        off64_t endoffile;
98        off64_t currentpos;
99        unsigned long long ptsend = 0;
100        unsigned long long ptscurrent = 0;
101        char* tmpstr = NULL;
102        struct skin* framebuffer = getscreen("framebuffer");
103        struct skin* timeshift = getscreen("timeshift");
104        struct skin* seek = getscreennode(timeshift, "seek");
105        struct skin* timeshiftbar = getscreennode(timeshift, "timeshiftbar");
106        char* bg = NULL;
107        int seeking = 0, timeout = 0, ret = 0, minuten = 0, sekunden = 0;
108        struct service* snode = getservice(RECORDTIMESHIFT, 0);
109        int fd = -1;
110       
111        if(servicenode == NULL)
112        {
113                err("NULL detect");
114                return;
115        }
116       
117        if(snode != NULL)
118                fd = open(snode->recname, O_RDONLY | O_LARGEFILE);
119       
120        if(fd < 0)
121        {
122                err("timeshift fd not ok");
123                return;
124        }
125       
126        timeshiftbar->progresssize = 0;
127        setnodeattr(timeshift, framebuffer);
128        bg = savescreen(timeshift);
129        if(status.timeshiftseek == 999999)
130                timeout = 5;
131       
132        while(status.timeshiftseek != 0 || seeking != 0)
133        {
134                currentpos = lseek64(servicenode->recsrcfd, 0, SEEK_CUR);
135                currentpos = currentpos - 5000000;
136                endoffile = lseek64(fd , 0, SEEK_END);
137               
138                if(endoffile != 0)
139                {
140                        timeshiftbar->progresssize = currentpos * 100 / endoffile;
141                        if(status.timeshiftseek < 999999)
142                        {
143                                if(status.timeshiftseek > 10000)
144                                {
145                                        tmpstr = oitoa(status.timeshiftseek - 10000);
146                                        tmpstr = ostrcat(_(">> "), tmpstr, 0, 1);
147                                        tmpstr = ostrcat(tmpstr, "x", 1, 0);
148                                        changetext(seek, tmpstr);
149                                        free(tmpstr); tmpstr = NULL;
150                                }
151                                if(status.timeshiftseek < 10000 && status.timeshiftseek > -10000)
152                                {
153                                        if(seeking == 0)
154                                        {
155                                                seeking = status.timeshiftseek;
156                                                tmpstr = oitoa(status.timeshiftseek);
157                                        }
158                                        else
159                                        {
160                                                tmpstr = oitoa(seeking);
161                                                seeking = 0;
162                                        }
163                                        tmpstr = ostrcat(_("skip "), tmpstr, 0, 1);
164                                        tmpstr = ostrcat(tmpstr, " sec", 1, 0);
165                                        changetext(seek, tmpstr);
166                                        free(tmpstr); tmpstr = NULL;
167                                }
168                        }
169                        else
170                        {
171                                ret = getptspos(fd, currentpos, &ptscurrent, &currentpos, 1, servicenode->tssize);
172                                ret = getpts(fd, 0, 0, 256 * 1024, &ptsend, &endoffile, -1, servicenode->tssize);
173                                sekunden = (ptsend - ptscurrent) / 90000;
174                                minuten = sekunden / 60;
175                                sekunden = sekunden % 60;
176                                tmpstr = ostrcat(tmpstr, "-", 1, 0);
177                                tmpstr = ostrcat(tmpstr, oitoa(minuten), 1, 1);
178                                tmpstr = ostrcat(tmpstr, ":", 1, 0);
179                               
180                                if(sekunden < 10)
181                                        tmpstr = ostrcat(tmpstr, "0", 1, 0);
182                                       
183                                tmpstr = ostrcat(tmpstr, oitoa(sekunden), 1, 1);
184                                tmpstr = ostrcat(tmpstr, " min", 1, 0);
185                                changetext(seek, tmpstr);
186                                free(tmpstr); tmpstr = NULL;
187                        }
188                }
189               
190                drawscreen(timeshift, 0);
191                sleep (1);
192                if(status.timeshiftseek == 999999) {
193                        timeout = timeout - 1;
194                        if(timeout == 0)
195                                status.timeshiftseek = 0;
196                }
197        }
198       
199        restorescreen(bg, timeshift);
200        blitfb(0);
201        close(fd);
202}
203
204void timeshiftseek(int sekunden)
205{
206        struct service* snode = getservice(RECORDPLAY, 0);
207       
208        if(status.timeshiftseek == 0)
209        {
210                status.timeshiftseek = sekunden;
211                addtimer(&timeshiftscreen, START, 10000, 1, (void*)snode, NULL, NULL);
212        }
213       
214        if(status.timeshiftseek < 999999)
215        {
216                status.timeshiftseek = sekunden;
217                if(snode != 0)
218                {
219                        if(sekunden > 10000)
220                        {
221                                if(sekunden >= 10032)
222                                {
223                                        status.timeshiftseek = 10016;
224                                        return;
225                                }
226                                status.timeshiftseek = sekunden;
227                                sekunden = sekunden - 10000;
228                                playerffts(sekunden);
229                        }       
230                        else
231                        {
232                                playerseekts(snode, sekunden, 1);
233                        }
234                }
235        }
236}
237
238
239#endif
Note: See TracBrowser for help on using the repository browser.