Rev 1655 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1655 | giacomo | 1 | /* |
2 | * Project: HARTIK (HA-rd R-eal TI-me K-ernel) |
||
3 | * |
||
4 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
||
5 | * Gerardo Lamastra <gerardo@sssup.it> |
||
6 | * |
||
7 | * Authors : Luca Abeni <luca@hartik.sssup.it> |
||
8 | * Massimiliano Giorgi <massy@hartik.sssup.it> |
||
9 | * (see authors.txt for full list of hartik's authors) |
||
10 | * |
||
11 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
12 | * |
||
13 | * http://www.sssup.it |
||
14 | * http://retis.sssup.it |
||
15 | * http://hartik.sssup.it |
||
16 | */ |
||
17 | |||
18 | /* |
||
19 | * Copyright (C) 1999 Luca Abeni and Massimiliano Giorgi |
||
20 | * |
||
21 | * This program is free software; you can redistribute it and/or modify |
||
22 | * it under the terms of the GNU General Public License as published by |
||
23 | * the Free Software Foundation; either version 2 of the License, or |
||
24 | * (at your option) any later version. |
||
25 | * |
||
26 | * This program is distributed in the hope that it will be useful, |
||
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
29 | * GNU General Public License for more details. |
||
30 | * |
||
31 | * You should have received a copy of the GNU General Public License |
||
32 | * along with this program; if not, write to the Free Software |
||
33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
34 | * |
||
35 | */ |
||
36 | |||
37 | /* |
||
38 | * CVS : $Id: mplay2.c,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
||
39 | * |
||
40 | * File: $File$ |
||
41 | * Revision: $Revision: 1.1.1.1 $ |
||
42 | * Last update: $Date: 2004-05-24 18:03:39 $ |
||
43 | */ |
||
44 | |||
45 | #include <ll/sys/types.h> |
||
46 | |||
47 | #include <kernel/func.h> |
||
48 | #include <kernel/const.h> |
||
49 | |||
50 | //#include <hartik.h> |
||
51 | #include <drivers/keyb.h> |
||
52 | |||
53 | |||
54 | |||
55 | #include <trace/trace.h> |
||
56 | #include <trace/queues.h> |
||
57 | |||
58 | |||
59 | |||
60 | #include <stdlib.h> |
||
61 | #include <stdio.h> |
||
62 | |||
63 | //#include <xdos.h> |
||
64 | #include <drivers/glib.h> |
||
65 | |||
66 | #include "mpeg/video.h" |
||
67 | /*#include "proto.h"*/ |
||
68 | #include "mpeg/util.h" |
||
69 | #include "mpeg/dither.h" |
||
70 | #include "mpeg/mpeg.h" |
||
71 | |||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
77 | |||
78 | |||
79 | //#define NOSHOW 1 |
||
80 | |||
81 | |||
82 | |||
83 | |||
84 | #include <drivers/keyb.h> |
||
85 | |||
86 | |||
87 | int mustdied=0; |
||
88 | |||
89 | |||
90 | void ctrlc_exit(KEY_EVT *k) |
||
91 | { |
||
92 | extern void dump_sem_table(void); |
||
93 | extern void dump_nop_table(void); |
||
94 | mustdied=1; |
||
95 | #ifndef NOSHOW |
||
96 | grx_close(); |
||
97 | #endif |
||
98 | cprintf("CTRL-C pressed!\n"); |
||
99 | #ifndef NOSHOW |
||
100 | grx_modeinfo(); |
||
101 | #endif |
||
102 | sys_end(); |
||
103 | } |
||
104 | |||
105 | #include <fs/bdevinit.h> |
||
106 | #include <fs/fsinit.h> |
||
107 | #include <fs/bdev.h> |
||
108 | |||
109 | #include <sys/types.h> |
||
110 | #include <sys/mount.h> |
||
111 | |||
112 | int __register_sub_init_prologue(void) |
||
113 | { |
||
114 | int id; |
||
115 | TRC_init_phase1(NULL); |
||
116 | trc_register_fixed_queue(); |
||
117 | id=trc_create_queue(TRC_FIXED_QUEUE,NULL); |
||
118 | trc_trace_class(TRC_CLASS_USER); |
||
119 | trc_assign_class_to_queue(TRC_CLASS_USER,id); |
||
120 | return 0; |
||
121 | } |
||
122 | |||
123 | int __register_sub_init(void) |
||
124 | { |
||
125 | return 0; |
||
126 | } |
||
127 | |||
128 | dev_t root_device; |
||
129 | dev_t temp_device; |
||
130 | |||
131 | int choose_root_callback(dev_t dev,u_int8_t fs) |
||
132 | { |
||
133 | if (fs==FS_MSDOS) return dev; |
||
134 | return -1; |
||
135 | } |
||
136 | |||
137 | int choose_temp_callback(__dev_t dev,__uint8_t fs) |
||
138 | { |
||
139 | static int flag=0; |
||
140 | if (fs==FS_MSDOS) { |
||
141 | if (flag) return dev; |
||
142 | flag=1; |
||
143 | } |
||
144 | return -1; |
||
145 | } |
||
146 | |||
147 | int __bdev_sub_init(void) |
||
148 | { |
||
149 | BDEV_PARMS bdev=BASE_BDEV; |
||
150 | |||
151 | bdev_def_showinfo(bdev,FALSE); |
||
152 | bdev_init(&bdev); |
||
153 | |||
154 | root_device=bdev_scan_devices(choose_root_callback); |
||
155 | if (root_device<0) { |
||
156 | cprintf("can't find root device to mount on /!!!\n"); |
||
157 | sys_end(); |
||
158 | return -1; |
||
159 | } |
||
160 | |||
161 | temp_device=bdev_scan_devices(choose_temp_callback); |
||
162 | if (temp_device<0) { |
||
163 | cprintf("can't find a filesystem to mount on /TEMP!!!\n"); |
||
164 | } |
||
165 | |||
166 | return 0; |
||
167 | } |
||
168 | |||
169 | extern int libc_initialize(void); |
||
170 | |||
171 | int __fs_sub_init(void) |
||
172 | { |
||
173 | FILESYSTEM_PARMS fs=BASE_FILESYSTEM; |
||
174 | struct mount_opts opts; |
||
175 | int res; |
||
176 | |||
177 | filesystem_def_rootdevice(fs,root_device); |
||
178 | filesystem_def_fs(fs,FS_MSDOS); |
||
179 | filesystem_def_showinfo(fs,FALSE); |
||
180 | filesystem_init(&fs); |
||
181 | |||
182 | if (temp_device>=0) { |
||
183 | memset(&opts,0,sizeof(struct mount_opts)); |
||
184 | opts.flags=MOUNT_FLAG_RW; |
||
185 | res=mount(temp_device,FS_MSDOS,"/TEMP",&opts); |
||
186 | if (res!=0) { |
||
187 | cprintf("can't mount XXX on /TEMP (errno: %i)\n",errno); |
||
188 | } else |
||
189 | cprintf("mounted /TEMP rw\n"); |
||
190 | |||
191 | } |
||
192 | |||
193 | libc_initialize(); |
||
194 | |||
195 | TRC_init_phase2(); |
||
196 | |||
197 | return 0; |
||
198 | } |
||
199 | |||
200 | int x_fseek(FILE *file, long where, int from) |
||
201 | { |
||
202 | return fseek(file,where,from); |
||
203 | } |
||
204 | |||
205 | size_t x_fread(void *buffer, size_t size, size_t n, FILE *file) |
||
206 | { |
||
207 | return fread(buffer,size,n,file); |
||
208 | } |
||
209 | |||
210 | |||
211 | |||
212 | |||
213 | |||
214 | |||
215 | |||
216 | |||
217 | |||
218 | |||
219 | |||
220 | |||
221 | |||
222 | |||
223 | |||
224 | |||
225 | |||
226 | |||
227 | |||
228 | |||
229 | |||
230 | |||
231 | |||
232 | TIME ttt; |
||
233 | |||
234 | DWORD n[10]; |
||
235 | |||
236 | ///* #define GPHBDIM 4097152 */ |
||
237 | //#define GPHBDIM 1000000 |
||
238 | |||
239 | //BYTE gphb[GPHBDIM]; /* Std Dim: 2M */ |
||
240 | //BYTE *nextphbyte = gphb; |
||
241 | |||
242 | struct streamdescr { |
||
243 | FILE *f; |
||
244 | ImageDesc *i; |
||
245 | int x1, y1; |
||
246 | } sd[10]; |
||
247 | |||
248 | #define SCREENX 800 |
||
249 | #define SCREENY 600 |
||
250 | |||
251 | void txtreset(void *dummy) |
||
252 | { |
||
253 | #ifndef NOSHOW |
||
254 | grx_close(); |
||
255 | grx_modeinfo(); |
||
256 | /* cprintf("Total frames: %ld\n", i); |
||
257 | cprintf("Total time: %lu\n", t);*/ |
||
258 | //cprintf("Frame rate: %lu\n", (n * 1000) / ttt); |
||
259 | /* cprintf("Max frame time: %lu\n", mft);*/ |
||
260 | /* |
||
261 | sys_status(READY_RT_STATUS | READY_NRT_STATUS | BLOCKED_STATUS | |
||
262 | IDLE_STATUS | SLEEP_STATUS | EXEC_STATUS); |
||
263 | */ |
||
264 | #endif |
||
265 | } |
||
266 | |||
267 | #define MAINSLEEP 20000 |
||
268 | |||
269 | void drawload(TIME l) |
||
270 | { |
||
271 | #define LLPWINSIZE 20 |
||
272 | int actl; |
||
273 | // struct load l; |
||
274 | #define LOADX 500 |
||
275 | #define LOADY 300 |
||
276 | #define LOADYDIM 50 |
||
277 | #define LOADXDIM 100 |
||
278 | static int th = 0; |
||
279 | static int x = 0; |
||
280 | static int hy[LLPWINSIZE]; |
||
281 | static int somma = 0; |
||
282 | int i; |
||
283 | |||
284 | /* for (i = 0; i < LLPWINSIZE; i++) hy[i] = 0; */ |
||
285 | |||
286 | // load_actual(&l); |
||
287 | // actl = (LOADYDIM * l.actual) / l.rif + 1; |
||
288 | // { |
||
289 | // char str[80]; |
||
290 | // sprintf(str,"%d",actl); |
||
291 | // /*grx_text("Ciao", 200, 200, color16(31, 63, 31), 0);*/ |
||
292 | // grx_text(" ", 100, 400, 100, 0); |
||
293 | // grx_text(str, 100, 400, 100,0); |
||
294 | // } |
||
295 | /* LowPass Filter */ |
||
296 | |||
297 | |||
298 | actl=((long)l*LOADYDIM)/MAINSLEEP+1; |
||
299 | |||
300 | somma += actl - hy[th]; |
||
301 | hy[th] = actl; |
||
302 | th = (th + 1) % LLPWINSIZE; |
||
303 | actl = somma / LLPWINSIZE; |
||
304 | #ifndef NOSHOW |
||
305 | grx_line(LOADX+x,LOADY,LOADX+x,(LOADY+LOADYDIM),0); |
||
306 | if (actl > LOADYDIM) actl = LOADYDIM; |
||
307 | grx_line(LOADX+x,(LOADY + actl),LOADX+x,(LOADY+LOADYDIM),255); |
||
308 | #endif |
||
309 | x = (x + 1) % LOADXDIM; |
||
310 | |||
311 | } |
||
312 | |||
313 | |||
314 | |||
315 | TASK play(void *arg) |
||
316 | { |
||
317 | int i=(int)arg; |
||
318 | int loop = TRUE; |
||
319 | BYTE *pixels; |
||
320 | int moreframes = TRUE; |
||
321 | FILE *mpeg = sd[i].f; |
||
322 | ImageDesc *img = sd[i].i; |
||
323 | int x1, y1, x2, y2; |
||
324 | |||
325 | /*printf ("Task %d: Movie is %d x %d pixels\n", i, img->Width, img->Height); |
||
326 | printf ("Required picture rate = %d, required bit rate = %d\n", |
||
327 | img->PictureRate, img->BitRate);*/ |
||
328 | |||
329 | pixels = (BYTE *) malloc(img->Size * sizeof(BYTE)); |
||
330 | x1 = sd[i].x1; |
||
331 | y1 = sd[i].y1; |
||
332 | x2 = x1 + img->Width-1; |
||
333 | y2 = y1 + img->Height-1; |
||
334 | while (loop) { /* play the whole movie forever */ |
||
335 | loop = 0; |
||
336 | n[i] = 0; |
||
337 | ttt = sys_gettime(NULL); |
||
338 | while (moreframes && n[i]<250) { |
||
339 | |||
340 | if (mustdied) break; |
||
341 | |||
342 | #ifdef NOSHOW |
||
343 | cprintf("%c",'°'+i); |
||
344 | #endif |
||
345 | |||
346 | moreframes = GetMPEGFrame (img, pixels); |
||
347 | #ifndef NOSHOW |
||
348 | grx_putimage(x1, y1, x2, y2, pixels); |
||
349 | #endif |
||
350 | n[i]++; |
||
351 | task_endcycle(); |
||
352 | } |
||
353 | ttt = sys_gettime(NULL) - ttt; |
||
354 | if (!loop) break; |
||
355 | RewindMPEG (mpeg, img); |
||
356 | SetMPEGOption (img, MPEG_DITHER, GRAY_DITHER); |
||
357 | moreframes = TRUE; |
||
358 | } |
||
359 | |||
360 | return 0; |
||
361 | } |
||
362 | |||
363 | |||
364 | |||
365 | int main(int argc, char *argv[]) |
||
366 | { |
||
367 | // SYS_PARMS sp = BASE_SYS; |
||
368 | KEY_EVT k; |
||
369 | // MODEL m = BASE_MODEL; |
||
370 | PID pid; |
||
371 | |||
372 | // DOS_FILE *Infile; |
||
373 | // BYTE *mpegbuff[10], *p; |
||
374 | // WORD res; |
||
375 | // DWORD cnt[10]; |
||
376 | |||
377 | |||
378 | TIME sum; |
||
379 | |||
380 | SOFT_TASK_MODEL model; |
||
381 | |||
382 | FILE *mpeg; |
||
383 | ImageDesc img[10]; |
||
384 | int full_color = FALSE; |
||
385 | |||
386 | int mode; |
||
387 | int esc; |
||
388 | int i; |
||
389 | int actx = 10, acty = 10; |
||
390 | ColormapEntry *cp; |
||
391 | |||
392 | //cprintf("file '%s'\n",argv[1]); |
||
393 | |||
394 | if (argc < 2) { |
||
395 | fprintf (stderr, "Usage: %s mpegfile\n", argv[0]); |
||
396 | sys_abort(301); |
||
397 | } |
||
398 | |||
399 | /* |
||
400 | for (i = 0; i < argc - 1; i++) { |
||
401 | Infile = DOS_fopen(argv[i + 1], "r"); |
||
402 | if (!Infile) { |
||
403 | cprintf("%s not found!!!\n", argv[i + 1]); |
||
404 | sys_abort(300); |
||
405 | } |
||
406 | cprintf("\n %s Opened!!!\n\n", argv[i + 1]); |
||
407 | |||
408 | mpegbuff[i] = nextphbyte; |
||
409 | p = mpegbuff[i]; cnt[i] = 0; |
||
410 | res = 0x1000; |
||
411 | while (res > 0) { |
||
412 | res = DOS_fread(p, 0x1000, 1, Infile); |
||
413 | cnt[i] += res; |
||
414 | p += res; |
||
415 | } |
||
416 | p += res; |
||
417 | nextphbyte = p; |
||
418 | } |
||
419 | */ |
||
420 | |||
421 | /* OK, Now we can start the system!!! */ |
||
422 | //sys_init(&sp); |
||
423 | //keyb_init(SOFT, 100); |
||
424 | // keyb_init(NULL); |
||
425 | // k.flag = CNTR_BIT; |
||
426 | // k.scan = KEY_C; |
||
427 | // k.ascii = 'c'; |
||
428 | //keyb_excset(k,endfun); |
||
429 | |||
430 | //vfs_init(); |
||
431 | /* |
||
432 | for (i = 0; i < argc - 1; i++) { |
||
433 | vfs_assign(argv[i + 1], mpegbuff[i], cnt[i]); |
||
434 | } |
||
435 | */ |
||
436 | |||
437 | |||
438 | |||
439 | |||
440 | |||
441 | |||
442 | /* Init the graph... */ |
||
443 | #ifndef NOSHOW |
||
444 | |||
445 | if (grx_init() == -1) { |
||
446 | cprintf("No init!!!\n"); |
||
447 | sys_abort(255); |
||
448 | } |
||
449 | |||
450 | mode = grx_getmode(SCREENX, SCREENY, 8); |
||
451 | cprintf("Mode num: %x\n", mode); |
||
452 | grx_cardinfo(); |
||
453 | #endif |
||
454 | |||
455 | cprintf("[hit enter to continue]\n"); |
||
456 | esc = FALSE; |
||
457 | while (!esc) { |
||
458 | keyb_getcode(&k,BLOCK); |
||
459 | if (k.ascii == 13) esc = TRUE; |
||
460 | } |
||
461 | |||
462 | |||
463 | if (mode == -1) { |
||
464 | cprintf("Mode not present!!!\n"); |
||
465 | sys_abort(255); |
||
466 | } |
||
467 | |||
468 | #ifndef NOSHOW |
||
469 | if (grx_setmode(mode) == -1) { |
||
470 | cprintf("No SetMode!!!\n"); |
||
471 | sys_abort(255); |
||
472 | } |
||
473 | #endif |
||
474 | |||
475 | //sys_atexit(txtreset,NULL,AFTER_EXIT); |
||
476 | |||
477 | |||
478 | //cprintf("Û0Û"); |
||
479 | |||
480 | for (i = 0; i < argc - 1; i++) { |
||
481 | mpeg = fopen(argv[i + 1], "r"); |
||
482 | |||
483 | if (!mpeg) { |
||
484 | perror (argv[1]); |
||
485 | sys_abort(301); |
||
486 | } |
||
487 | |||
488 | //cprintf("Û0.5Û"); |
||
489 | |||
490 | /* !!! */ |
||
491 | img[i].vid_stream=NULL; |
||
492 | img[i].Colormap=NULL; |
||
493 | |||
494 | if (!OpenMPEG(mpeg, &(img[i]))) { |
||
495 | fprintf (stderr, "OpenMPEG on %s failed\n", argv[i + 1]); |
||
496 | sys_abort(301); |
||
497 | } |
||
498 | |||
499 | |||
500 | //cprintf("Û1Û"); |
||
501 | |||
502 | |||
503 | |||
504 | SetMPEGOption (&(img[i]), MPEG_DITHER, GRAY_DITHER); |
||
505 | //SetMPEGOption (&(img[i]), MPEG_DITHER, FS4_DITHER); |
||
506 | |||
507 | |||
508 | /* SetMPEGOption(MPEG_DITHER, GRAY_DITHER); */ |
||
509 | |||
510 | /* printf ("Movie is %d x %d pixels\n", img[i].Width, img[i].Height); |
||
511 | printf ("Required picture rate = %d, required bit rate = %d\n", |
||
512 | img[i].PictureRate, img[i].BitRate); */ |
||
513 | |||
514 | //cprintf("Û2Û"); |
||
515 | |||
516 | if (i == 0) { |
||
517 | cp = img[i].Colormap; |
||
518 | |||
519 | if (!full_color) { |
||
520 | int ii; |
||
521 | |||
522 | for (ii = 0; ii < img[i].ColormapSize; ii++) { |
||
523 | |||
524 | #ifndef NOSHOW |
||
525 | |||
526 | grx_setcolor (ii, img[i].Colormap[ii].red / 4, |
||
527 | img[i].Colormap[ii].green / 4, |
||
528 | img[i].Colormap[ii].blue / 4); |
||
529 | |||
530 | #endif |
||
531 | |||
532 | } |
||
533 | |||
534 | /*NO!!! Colormap is an array of short, setpalette wants an array of BYTE!!!*/ |
||
535 | /* grx_setpalette(0, 255, img.Colormap);*/ |
||
536 | } |
||
537 | } |
||
538 | if (actx + img[i].Width > SCREENX) { |
||
539 | actx = 10; |
||
540 | acty += 200; |
||
541 | } |
||
542 | sd[i].x1 = actx; |
||
543 | sd[i].y1 = acty; |
||
544 | sd[i].f = mpeg; |
||
545 | sd[i].i = &(img[i]); |
||
546 | |||
547 | //cprintf("Û3Û"); |
||
548 | |||
549 | soft_task_default_model(model); |
||
550 | ////soft_task_def_system(model); |
||
551 | //soft_task_def_met(model,9000); |
||
552 | //soft_task_def_wcet(model,9000); |
||
553 | //soft_task_def_period(model,50000); |
||
554 | |||
555 | soft_task_def_met(model,5000); |
||
556 | soft_task_def_wcet(model,5000); |
||
557 | soft_task_def_period(model,40000); |
||
558 | soft_task_def_periodic(model); |
||
559 | soft_task_def_arg(model,(void*)i); |
||
560 | soft_task_def_ctrl_jet(model); |
||
561 | |||
562 | //task_def_arg(m, i); |
||
563 | //task_def_wcet(m, 9000); |
||
564 | pid = task_create("Shower", play, &model, NULL); |
||
565 | if (pid == -1) { |
||
566 | cprintf(" task --> Not Guaranteed!!!\n"); |
||
567 | sys_abort(20000); |
||
568 | } |
||
569 | task_activate(pid); |
||
570 | |||
571 | //cprintf("Û4Û"); |
||
572 | |||
573 | actx += img[i].Width + 10; |
||
574 | } |
||
575 | |||
576 | /* play(0);*/ |
||
577 | esc = FALSE; |
||
578 | //jet_delstat(pid); |
||
579 | while (!esc) { |
||
580 | if (keyb_getcode(&k,NON_BLOCK) && (k.ascii == 13)) esc = TRUE; |
||
581 | task_delay(MAINSLEEP); |
||
582 | //jet_getstat(pid,&sum,NULL,NULL,NULL); |
||
583 | //jet_delstat(pid); |
||
584 | //drawload(sum); |
||
585 | } |
||
586 | |||
587 | sys_abort(59000); |
||
588 | |||
589 | return 0; |
||
590 | } |