1 | #include "../../titan/struct.h" |
---|
2 | #include "../../titan/debug.h" |
---|
3 | #include "../../titan/header.h" |
---|
4 | |
---|
5 | char pluginname[] = "Record cut"; |
---|
6 | char plugindesc[] = "Extensions"; |
---|
7 | char pluginpic[] = "%pluginpath%/tsSchnitt/plugin.png"; |
---|
8 | |
---|
9 | int pluginaktiv = 0; |
---|
10 | int pluginversion = 999999; |
---|
11 | |
---|
12 | int imarker, iindex, ischnitt; |
---|
13 | char* recfile = NULL; |
---|
14 | char* recname = NULL; |
---|
15 | char* cutfile = NULL; |
---|
16 | int zielsec = 0; |
---|
17 | |
---|
18 | struct stimerthread* tsSchnittThread = NULL; |
---|
19 | struct stimerthread* tsSchnittThreadKill = NULL; |
---|
20 | |
---|
21 | void tsSchnitt_thread_kill() |
---|
22 | { |
---|
23 | while (tsSchnittThread->aktion != STOP && tsSchnittThreadKill->aktion != STOP) |
---|
24 | { |
---|
25 | sleep(2); |
---|
26 | } |
---|
27 | if(tsSchnittThread->aktion == STOP) |
---|
28 | { |
---|
29 | system("killall -9 avconv"); |
---|
30 | } |
---|
31 | tsSchnittThreadKill = NULL; |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | void tsSchnitt_thread() |
---|
36 | { |
---|
37 | char* tmpstr = NULL; |
---|
38 | char* tmpstr2 = NULL; |
---|
39 | char* epgfile = NULL; |
---|
40 | char* epgcutfile = NULL; |
---|
41 | int z = 0; |
---|
42 | int rc; |
---|
43 | |
---|
44 | tsSchnittThreadKill = addtimer(&tsSchnitt_thread_kill, START, 10000, 1, NULL, NULL, NULL); |
---|
45 | |
---|
46 | if(ischnitt == 0 || ischnitt == 3) |
---|
47 | { |
---|
48 | |
---|
49 | |
---|
50 | off64_t pos; |
---|
51 | off64_t time; |
---|
52 | off64_t mtime = 0; |
---|
53 | epgfile = changefilenameext(recfile, ".epg"); |
---|
54 | tmpstr = changefilenameext(epgfile, ".cut"); |
---|
55 | epgcutfile = ostrcat(tmpstr, ".epg", 0, 0); |
---|
56 | free(tmpstr); tmpstr=NULL; |
---|
57 | tmpstr2 = changefilenameext(recfile, ".ma"); |
---|
58 | //tmpstr2 = ostrcat("\"",tmpstr2, 0, 0); |
---|
59 | //tmpstr2 = ostrcat(tmpstr2, "\"", 0, 0); |
---|
60 | printf("----> %s\n",tmpstr2); |
---|
61 | FILE* datei = fopen(tmpstr2, "r"); |
---|
62 | z = 0; |
---|
63 | if(datei!= NULL) |
---|
64 | { |
---|
65 | while(!feof(datei) && z < 2) |
---|
66 | { |
---|
67 | fscanf(datei, "%lld,%lld", &pos, &time); |
---|
68 | |
---|
69 | if(z == 0) |
---|
70 | { |
---|
71 | tmpstr = createpluginpath("/tsSchnitt/avconv", 0); |
---|
72 | //tmpstr = ostrcat("/mnt/swapextensions/usr/local/share/titan/plugins/tsSchnitt/avconv", " -ss ", 0, 0); |
---|
73 | tmpstr = ostrcat(tmpstr, " -ss ", 0, 0); |
---|
74 | tmpstr = ostrcat(tmpstr, convert_timesec(time), 0, 0); |
---|
75 | tmpstr = ostrcat(tmpstr, " -i \"",0, 0); |
---|
76 | tmpstr = ostrcat(tmpstr, recfile, 0, 0); |
---|
77 | tmpstr = ostrcat(tmpstr, "\"",0, 0); |
---|
78 | //tmpstr = ostrcat(tmpstr, " -vcodec copy -map 0:v -acodec copy -map 0:a -scodec copy -map 0:s",0, 0); |
---|
79 | tmpstr = ostrcat(tmpstr, " -vcodec copy -map 0:v -acodec copy -map 0:a",0, 0); |
---|
80 | mtime = time; |
---|
81 | } |
---|
82 | z = z + 1; |
---|
83 | } |
---|
84 | if(z > 1) |
---|
85 | { |
---|
86 | tmpstr = ostrcat(tmpstr, " -t ", 0, 0); |
---|
87 | tmpstr = ostrcat(tmpstr, convert_timesec(time - mtime), 0, 0); |
---|
88 | zielsec= time - mtime; |
---|
89 | tmpstr = ostrcat(tmpstr, " \"", 0, 0); |
---|
90 | tmpstr = ostrcat(tmpstr, cutfile, 0, 0); |
---|
91 | tmpstr = ostrcat(tmpstr, "\"",0, 0); |
---|
92 | } |
---|
93 | fclose(datei); |
---|
94 | free(tmpstr2); tmpstr2 = NULL; |
---|
95 | } |
---|
96 | if(z < 2) |
---|
97 | ischnitt = 3; |
---|
98 | else |
---|
99 | ischnitt = 1; |
---|
100 | |
---|
101 | if(ischnitt == 1) |
---|
102 | { |
---|
103 | tmpstr2 = ostrcat(tmpstr2, "Schnitt:\n\n von 00:00:00 bis ", 0, 0); |
---|
104 | tmpstr2 = ostrcat(tmpstr2, convert_timesec(mtime), 0, 0); |
---|
105 | tmpstr2 = ostrcat(tmpstr2, "\n von ", 0, 0); |
---|
106 | tmpstr2 = ostrcat(tmpstr2, convert_timesec(time), 0, 0); |
---|
107 | tmpstr2 = ostrcat(tmpstr2, " bis ende", 0, 0); |
---|
108 | if(textbox(_("Information"), tmpstr2, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 400, 250, 0, 0) == 1) |
---|
109 | { |
---|
110 | printf(" +++ %s +++\n",tmpstr); |
---|
111 | rc = system(tmpstr); |
---|
112 | free(tmpstr);tmpstr= NULL; |
---|
113 | if(rc == 0) |
---|
114 | { |
---|
115 | ischnitt = 2; |
---|
116 | tmpstr = ostrcat(tmpstr, "cp \"", 0, 0); |
---|
117 | tmpstr = ostrcat(tmpstr, epgfile, 0, 0); |
---|
118 | tmpstr = ostrcat(tmpstr, "\" \"", 0, 0); |
---|
119 | tmpstr = ostrcat(tmpstr, epgcutfile, 0, 0); |
---|
120 | tmpstr = ostrcat(tmpstr, "\"", 0, 0); |
---|
121 | rc = system(tmpstr); |
---|
122 | free(tmpstr);tmpstr= NULL; |
---|
123 | textbox(_("INFO"), _("Schnitt erfolgreich beendet"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
124 | } |
---|
125 | else |
---|
126 | { |
---|
127 | remove(cutfile); |
---|
128 | ischnitt = 3; |
---|
129 | textbox(_("ERROR"), _("Schnitt endet mit Fehler !!!!!"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
130 | } |
---|
131 | } |
---|
132 | else |
---|
133 | ischnitt = 0; |
---|
134 | free(tmpstr2);tmpstr2=NULL; |
---|
135 | } |
---|
136 | free(tmpstr); tmpstr = NULL; |
---|
137 | free(epgfile); epgfile=NULL; |
---|
138 | free(epgcutfile); epgcutfile=NULL; |
---|
139 | } |
---|
140 | |
---|
141 | if(tsSchnittThreadKill != NULL) |
---|
142 | { |
---|
143 | tsSchnittThreadKill->aktion = STOP; |
---|
144 | sleep(2); |
---|
145 | } |
---|
146 | tsSchnittThread = NULL; |
---|
147 | printf("ischnitt:--> %i\n",ischnitt); |
---|
148 | return; |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | //wird beim laden ausgefuehrt |
---|
153 | void init(void) |
---|
154 | { |
---|
155 | char* tmpstr = NULL; |
---|
156 | pluginaktiv = 1; |
---|
157 | tmpstr = createpluginpath("/tsSchnitt/skin.xml", 0); |
---|
158 | readscreen(tmpstr, 122, 1); |
---|
159 | free(tmpstr); tmpstr = NULL; |
---|
160 | |
---|
161 | debug(10, "Record cut Plugin loadet !!!"); |
---|
162 | } |
---|
163 | |
---|
164 | //wird beim entladen ausgefuehrt |
---|
165 | void deinit(void) |
---|
166 | { |
---|
167 | if(tsSchnittThread != NULL) |
---|
168 | { |
---|
169 | tsSchnittThread->aktion = STOP; |
---|
170 | sleep(2); |
---|
171 | } |
---|
172 | free(cutfile); cutfile=NULL; |
---|
173 | free(recfile); recfile=NULL; |
---|
174 | free(recname); recname=NULL; |
---|
175 | |
---|
176 | delmarkedscreen(122); |
---|
177 | pluginaktiv = 0; |
---|
178 | debug(10, "Record cut Plugin loadet !!!"); |
---|
179 | } |
---|
180 | |
---|
181 | //wird in der Pluginverwaltung bzw Menue ausfeguehrt |
---|
182 | void start(void) |
---|
183 | { |
---|
184 | |
---|
185 | long long unsigned int lenpts = 0; |
---|
186 | long long unsigned int startpts1 = 0; |
---|
187 | long long unsigned int endpts = 0; |
---|
188 | long long unsigned int aktbitrate = 0; |
---|
189 | int recfd = -1; |
---|
190 | |
---|
191 | char* tmpstr = NULL; |
---|
192 | char* tmpstr2 = NULL; |
---|
193 | int rcret; |
---|
194 | int help; |
---|
195 | struct stat64 rdat; |
---|
196 | struct stat64 cdat; |
---|
197 | |
---|
198 | struct skin* tsschnitt = getscreen("tsSchnitt"); |
---|
199 | struct skin* listbox = getscreennode(tsschnitt, "listbox"); |
---|
200 | struct skin* film = getscreennode(tsschnitt, "film"); |
---|
201 | struct skin* marker = getscreennode(tsschnitt, "marker"); |
---|
202 | struct skin* schnitt = getscreennode(tsschnitt, "schnitt"); |
---|
203 | struct skin* schnittprog = getscreennode(tsschnitt, "schnittprog"); |
---|
204 | struct skin* tmp = NULL; |
---|
205 | struct skin* load = getscreen("loading"); |
---|
206 | |
---|
207 | while(1) |
---|
208 | { |
---|
209 | |
---|
210 | if(recfile == NULL) |
---|
211 | recfile = ostrcat(recfile, getconfig("tsSchnitt_recfile", NULL), 0, 0); |
---|
212 | if(recfile == NULL && tsSchnittThread == NULL) |
---|
213 | { |
---|
214 | imarker = 0; |
---|
215 | ischnitt = 0; |
---|
216 | } |
---|
217 | else if(tsSchnittThread == NULL) |
---|
218 | { |
---|
219 | tmpstr = changefilenameext(recfile, ".ma"); |
---|
220 | if(isfile(tmpstr) == 0) |
---|
221 | imarker = 0; |
---|
222 | else |
---|
223 | imarker = 2; |
---|
224 | free(tmpstr); tmpstr=NULL; |
---|
225 | if(cutfile == NULL) |
---|
226 | { |
---|
227 | tmpstr = changefilenameext(recfile, ".cut"); |
---|
228 | cutfile = ostrcat(tmpstr, ".ts", 0, 0); |
---|
229 | free(tmpstr); tmpstr=NULL; |
---|
230 | } |
---|
231 | if(isfile(cutfile) == 1 && tsSchnittThread == NULL) |
---|
232 | ischnitt = 2; |
---|
233 | else if(tsSchnittThread == NULL && ischnitt != 3) |
---|
234 | ischnitt = 0; |
---|
235 | } |
---|
236 | |
---|
237 | if(recname == NULL && recfile != NULL) |
---|
238 | { |
---|
239 | tmpstr2 = strrchr(recfile, '/'); |
---|
240 | if(tmpstr2 != NULL) |
---|
241 | { |
---|
242 | recname = ostrcat(tmpstr2+1,"" ,0, 0); |
---|
243 | changetext(film, recname); |
---|
244 | tmpstr2 = NULL; |
---|
245 | } |
---|
246 | else |
---|
247 | changetext(film, recfile); |
---|
248 | } |
---|
249 | else if(recfile == NULL) |
---|
250 | changetext(film, recfile); |
---|
251 | |
---|
252 | if(imarker == 0) |
---|
253 | changetext(marker, "nein"); |
---|
254 | else if(imarker == 2) |
---|
255 | changetext(marker, "ja"); |
---|
256 | |
---|
257 | schnittprog->progresssize = 0; |
---|
258 | if(ischnitt == 0) |
---|
259 | { |
---|
260 | changetext(schnitt, "gestoppt"); |
---|
261 | changetext(schnittprog, "0.0%"); |
---|
262 | schnittprog->progresssize = 0; |
---|
263 | } |
---|
264 | else if(ischnitt == 1) |
---|
265 | { |
---|
266 | changetext(schnittprog, "0.0%"); |
---|
267 | changetext(schnitt, "in Arbeit"); |
---|
268 | if(stat64(cutfile, &cdat) == 0) |
---|
269 | { |
---|
270 | if(stat64(recfile, &rdat) == 0) |
---|
271 | { |
---|
272 | rdat.st_size = (rdat.st_size * zielsec) / getconfigint("tsSchnitt_lenrec", NULL); |
---|
273 | help = (100 * cdat.st_size) / rdat.st_size; |
---|
274 | schnittprog->progresssize = help; |
---|
275 | tmpstr2 = ostrcat(oitoa(help),"." ,0, 0); |
---|
276 | help = ((100 * cdat.st_size) % rdat.st_size) * 10 / rdat.st_size; |
---|
277 | tmpstr2 = ostrcat(tmpstr2, oitoa(help),0, 0); |
---|
278 | tmpstr2 = ostrcat(tmpstr2,"%" ,0, 0); |
---|
279 | changetext(schnittprog, tmpstr2); |
---|
280 | free(tmpstr2); tmpstr2=NULL; |
---|
281 | } |
---|
282 | } |
---|
283 | } |
---|
284 | else if(ischnitt == 2) |
---|
285 | { |
---|
286 | changetext(schnitt, "fertig"); |
---|
287 | changetext(schnittprog, "0.0%"); |
---|
288 | schnittprog->progresssize = 0; |
---|
289 | } |
---|
290 | else if(ischnitt == 3) |
---|
291 | { |
---|
292 | changetext(schnitt, "fehlerhaft"); |
---|
293 | changetext(schnittprog, "0.0%"); |
---|
294 | schnittprog->progresssize = 0; |
---|
295 | } |
---|
296 | |
---|
297 | drawscreen(tsschnitt, 0, 0); |
---|
298 | addscreenrc(tsschnitt, listbox); |
---|
299 | tmp = listbox->select; |
---|
300 | |
---|
301 | while(1) |
---|
302 | { |
---|
303 | addscreenrc(tsschnitt, tmp); |
---|
304 | rcret = waitrc(tsschnitt, 2000, 0); |
---|
305 | tmp = listbox->select; |
---|
306 | |
---|
307 | if (rcret == getrcconfigint("rcexit", NULL) && tsSchnittThread == NULL) break; |
---|
308 | if (rcret == getrcconfigint("rcyellow", NULL) && tsSchnittThread != NULL) break; |
---|
309 | if (rcret == getrcconfigint("rcgreen", NULL)) |
---|
310 | { |
---|
311 | if(tsSchnittThread == NULL) |
---|
312 | { |
---|
313 | recfile = screendir("/var/media/hdd/movie", "*.ts", NULL, NULL, NULL, NULL, 0, "SELECT", 0, NULL, 0, NULL, 0, 1200, 0, 600, 0, 0); |
---|
314 | addconfig("tsSchnitt_recfile", recfile); |
---|
315 | recfd = open(recfile, O_RDONLY | O_LARGEFILE); |
---|
316 | gettsinfo(recfd, &lenpts, &startpts1, &endpts, &aktbitrate, 188); |
---|
317 | lenpts = lenpts / 90000; |
---|
318 | addconfigint("tsSchnitt_lenrec", lenpts); |
---|
319 | close(recfd); |
---|
320 | free(recfile);recfile=NULL; |
---|
321 | free(recname);recname=NULL; |
---|
322 | free(cutfile); cutfile=NULL; |
---|
323 | break; |
---|
324 | } |
---|
325 | else |
---|
326 | { |
---|
327 | textbox(_("ERROR"), _("Schnitt ist in Arbeit"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
328 | } |
---|
329 | } |
---|
330 | if (rcret == getrcconfigint("rcblue", NULL)) |
---|
331 | { |
---|
332 | if(tsSchnittThread == NULL) |
---|
333 | { |
---|
334 | drawscreen(load, 0, 0); |
---|
335 | tsSchnittThread = addtimer(&tsSchnitt_thread, START, 10000, 1, NULL, NULL, NULL); |
---|
336 | sleep(4); |
---|
337 | clearscreen(load); |
---|
338 | break; |
---|
339 | } |
---|
340 | else |
---|
341 | { |
---|
342 | textbox(_("ERROR"), _("cut is running"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
343 | } |
---|
344 | } |
---|
345 | if (rcret == getrcconfigint("rcred", NULL) && tsSchnittThread != NULL) |
---|
346 | { |
---|
347 | if(textbox(_("Frage"), _("Soll der Schnitt wirklich abgebrochen werden?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0) == 1) |
---|
348 | { |
---|
349 | drawscreen(load, 0, 0); |
---|
350 | tsSchnittThread->aktion = STOP; |
---|
351 | sleep(2); |
---|
352 | clearscreen(load); |
---|
353 | break; |
---|
354 | } |
---|
355 | } |
---|
356 | if(ischnitt == 1) |
---|
357 | { |
---|
358 | changetext(schnitt, "in Arbeit"); |
---|
359 | if(stat64(cutfile, &cdat) == 0) |
---|
360 | { |
---|
361 | if(stat64(recfile, &rdat) == 0) |
---|
362 | { |
---|
363 | rdat.st_size = (rdat.st_size * zielsec) / getconfigint("tsSchnitt_lenrec", NULL); |
---|
364 | help = (100 * cdat.st_size) / rdat.st_size; |
---|
365 | schnittprog->progresssize = help; |
---|
366 | tmpstr2 = ostrcat(oitoa(help),"." ,0, 0); |
---|
367 | help = ((100 * cdat.st_size) % rdat.st_size) * 10 / rdat.st_size; |
---|
368 | tmpstr2 = ostrcat(tmpstr2, oitoa(help),0, 0); |
---|
369 | tmpstr2 = ostrcat(tmpstr2,"%" ,0, 0); |
---|
370 | changetext(schnittprog, tmpstr2); |
---|
371 | free(tmpstr2); tmpstr2=NULL; |
---|
372 | } |
---|
373 | } |
---|
374 | } |
---|
375 | else if(ischnitt == 2) |
---|
376 | { |
---|
377 | changetext(schnitt, "fertig"); |
---|
378 | changetext(schnittprog, "0.0%"); |
---|
379 | schnittprog->progresssize = 0; |
---|
380 | } |
---|
381 | else if(ischnitt == 3) |
---|
382 | { |
---|
383 | changetext(schnitt, "fehlerhaft"); |
---|
384 | changetext(schnittprog, "0.0%"); |
---|
385 | schnittprog->progresssize = 0; |
---|
386 | } |
---|
387 | drawscreen(tsschnitt, 0, 0); |
---|
388 | } |
---|
389 | if (rcret == getrcconfigint("rcexit", NULL) || rcret == getrcconfigint("rcyellow", NULL)) break; |
---|
390 | } |
---|
391 | delownerrc(tsschnitt); |
---|
392 | clearscreen(tsschnitt); |
---|
393 | |
---|
394 | |
---|
395 | |
---|
396 | |
---|
397 | } |
---|