Subversion Repositories shark

Rev

Rev 1085 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 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 2002-09-02 09:37:48 pj Exp $
39
 *
40
 * File:        $File$
41
 * Revision:    $Revision: 1.1.1.1 $
42
 * Last update: $Date: 2002-09-02 09:37:48 $
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
  //sys_status(SCHED_STATUS);
100
#ifndef NOSHOW
101
  grx_modeinfo();
102
#endif
103
  sys_end();
104
}
105
 
106
#include <fs/bdevinit.h>
107
#include <fs/fsinit.h>
108
#include <fs/bdev.h>
109
 
110
#include <sys/types.h>
111
#include <sys/mount.h>
112
 
113
int __register_sub_init_prologue(void)
114
{
115
  int id;
116
  TRC_init_phase1(NULL);
117
  trc_register_fixed_queue();
118
  id=trc_create_queue(TRC_FIXED_QUEUE,NULL);
119
  trc_trace_class(TRC_CLASS_USER);
120
  trc_assign_class_to_queue(TRC_CLASS_USER,id);
121
  return 0;
122
}
123
 
124
int __register_sub_init(void)
125
{
126
  return 0;
127
}
128
 
129
dev_t root_device;
130
dev_t temp_device;
131
 
132
int choose_root_callback(dev_t dev,u_int8_t fs)
133
{
134
  if (fs==FS_MSDOS) return dev;
135
  return -1;
136
}
137
 
138
int choose_temp_callback(__dev_t dev,__uint8_t fs)
139
{
140
  static int flag=0;
141
  if (fs==FS_MSDOS) {
142
    if (flag) return dev;
143
    flag=1;
144
  }
145
  return -1;
146
}
147
 
148
int __bdev_sub_init(void)
149
{
150
  BDEV_PARMS bdev=BASE_BDEV;
151
 
152
  bdev_def_showinfo(bdev,FALSE);
153
  bdev_init(&bdev);
154
 
155
  root_device=bdev_scan_devices(choose_root_callback);
156
  if (root_device<0) {
157
    cprintf("can't find root device to mount on /!!!\n");
158
    sys_end();
159
    return -1;
160
  }
161
 
162
  temp_device=bdev_scan_devices(choose_temp_callback);
163
  if (temp_device<0) {
164
    cprintf("can't find a filesystem to mount on /TEMP!!!\n");
165
  }
166
 
167
  return 0;
168
}
169
 
170
extern int libc_initialize(void);
171
 
172
int __fs_sub_init(void)
173
{
174
  FILESYSTEM_PARMS fs=BASE_FILESYSTEM;
175
  struct mount_opts opts;
176
  int res;
177
 
178
  filesystem_def_rootdevice(fs,root_device);
179
  filesystem_def_fs(fs,FS_MSDOS);
180
  filesystem_def_showinfo(fs,FALSE);
181
  filesystem_init(&fs);
182
 
183
  if (temp_device>=0) {
184
    memset(&opts,0,sizeof(struct mount_opts));
185
    opts.flags=MOUNT_FLAG_RW;
186
    res=mount(temp_device,FS_MSDOS,"/TEMP",&opts);
187
    if (res!=0) {
188
      cprintf("can't mount XXX on /TEMP (errno: %i)\n",errno);
189
    } else
190
      cprintf("mounted /TEMP rw\n");
191
 
192
  }
193
 
194
  libc_initialize();
195
 
196
  TRC_init_phase2();
197
 
198
  return 0;
199
}
200
 
201
int x_fseek(FILE *file, long where, int from)
202
{
203
  return fseek(file,where,from);
204
}
205
 
206
size_t x_fread(void *buffer, size_t size, size_t n, FILE *file)
207
{
208
  return fread(buffer,size,n,file);
209
}
210
 
211
 
212
 
213
 
214
 
215
 
216
 
217
 
218
 
219
 
220
 
221
 
222
 
223
 
224
 
225
 
226
 
227
 
228
 
229
 
230
 
231
 
232
 
233
TIME ttt;
234
 
235
DWORD n[10];
236
 
237
///* #define GPHBDIM 4097152 */
238
//#define GPHBDIM 1000000
239
 
240
//BYTE   gphb[GPHBDIM];           /*  Std Dim:    2M      */
241
//BYTE   *nextphbyte = gphb;
242
 
243
struct streamdescr {
244
    FILE *f;
245
    ImageDesc *i;
246
    int x1, y1;
247
} sd[10];
248
 
249
#define SCREENX 800
250
#define SCREENY 600
251
 
252
void txtreset(void *dummy)
253
{
254
#ifndef NOSHOW
255
  grx_close();
256
  grx_modeinfo();
257
  /*    cprintf("Total frames:  %ld\n", i);
258
        cprintf("Total time:    %lu\n", t);*/
259
  //cprintf("Frame rate:        %lu\n", (n * 1000) / ttt);
260
  /*    cprintf("Max frame time:        %lu\n", mft);*/
261
  /*
262
    sys_status(READY_RT_STATUS | READY_NRT_STATUS | BLOCKED_STATUS |
263
    IDLE_STATUS | SLEEP_STATUS | EXEC_STATUS);
264
    */
265
#endif
266
}
267
 
268
#define MAINSLEEP 20000
269
 
270
void drawload(TIME l)
271
{
272
    #define LLPWINSIZE 20
273
    int actl;
274
//  struct load l;
275
    #define LOADX 500
276
    #define LOADY 300
277
    #define LOADYDIM 50
278
    #define LOADXDIM 100
279
    static int th = 0;
280
    static int x = 0;
281
    static int hy[LLPWINSIZE];
282
    static int somma = 0;
283
    int i;
284
 
285
/*    for (i = 0; i < LLPWINSIZE; i++) hy[i] = 0; */
286
 
287
//    load_actual(&l);
288
//    actl = (LOADYDIM * l.actual) / l.rif + 1;
289
//    {
290
//      char str[80];
291
//      sprintf(str,"%d",actl);
292
//      /*grx_text("Ciao", 200, 200, color16(31, 63, 31), 0);*/
293
//      grx_text("    ", 100, 400, 100, 0);
294
//      grx_text(str, 100, 400, 100,0);
295
//    }
296
/*              LowPass Filter                  */
297
 
298
 
299
    actl=((long)l*LOADYDIM)/MAINSLEEP+1;
300
 
301
    somma += actl - hy[th];
302
    hy[th] = actl;
303
    th = (th + 1) % LLPWINSIZE;
304
    actl = somma / LLPWINSIZE;
305
#ifndef NOSHOW    
306
    grx_line(LOADX+x,LOADY,LOADX+x,(LOADY+LOADYDIM),0);
307
    if (actl > LOADYDIM) actl = LOADYDIM;
308
    grx_line(LOADX+x,(LOADY + actl),LOADX+x,(LOADY+LOADYDIM),255);
309
#endif
310
    x = (x + 1) % LOADXDIM;
311
 
312
}
313
 
314
 
315
 
316
TASK play(void *arg)
317
{
318
  int i=(int)arg;
319
    int loop = TRUE;
320
  BYTE *pixels;
321
  int moreframes = TRUE;
322
  FILE *mpeg = sd[i].f;
323
  ImageDesc *img = sd[i].i;
324
  int x1, y1, x2, y2;
325
 
326
  /*printf ("Task %d: Movie is %d x %d pixels\n", i, img->Width, img->Height);
327
    printf ("Required picture rate = %d, required bit rate = %d\n",
328
    img->PictureRate, img->BitRate);*/
329
 
330
  pixels = (BYTE *) malloc(img->Size * sizeof(BYTE));
331
  x1 = sd[i].x1;
332
  y1 = sd[i].y1;
333
  x2 = x1 + img->Width-1;
334
  y2 = y1 + img->Height-1;
335
  while (loop) {                        /* play the whole movie forever */
336
    loop = 0;
337
    n[i] = 0;
338
    ttt = sys_gettime(NULL);
339
    while (moreframes && n[i]<250) {
340
 
341
      if (mustdied) break;
342
 
343
#ifdef NOSHOW            
344
      cprintf("%c",'°'+i);
345
#endif
346
 
347
      moreframes = GetMPEGFrame (img, pixels);
348
#ifndef NOSHOW      
349
      grx_putimage(x1, y1, x2, y2, pixels);
350
#endif
351
      n[i]++;
352
      task_endcycle();
353
    }
354
    ttt = sys_gettime(NULL) - ttt;
355
    if (!loop) break;
356
    RewindMPEG (mpeg, img);
357
    SetMPEGOption (img, MPEG_DITHER, GRAY_DITHER);
358
    moreframes = TRUE;
359
  }
360
 
361
  return 0;
362
}
363
 
364
 
365
 
366
int main(int argc, char *argv[])
367
{
368
  //    SYS_PARMS sp = BASE_SYS;
369
  KEY_EVT k;
370
  //    MODEL m = BASE_MODEL;
371
  PID pid;
372
 
373
  //    DOS_FILE *Infile;
374
//  BYTE *mpegbuff[10], *p;
375
//  WORD res;
376
//  DWORD cnt[10];
377
 
378
 
379
TIME sum;
380
 
381
  SOFT_TASK_MODEL model;
382
 
383
  FILE       *mpeg;
384
  ImageDesc   img[10];
385
  int full_color = FALSE;
386
 
387
  int mode;
388
  int esc;
389
  int i;
390
  int actx = 10, acty = 10;
391
  ColormapEntry *cp;
392
 
393
  //cprintf("file '%s'\n",argv[1]);
394
 
395
  if (argc < 2) {
396
    fprintf (stderr, "Usage: %s mpegfile\n", argv[0]);
397
    sys_abort(301);
398
  }
399
 
400
  /*
401
    for (i = 0; i < argc - 1; i++) {
402
    Infile = DOS_fopen(argv[i + 1], "r");
403
    if (!Infile) {
404
    cprintf("%s not found!!!\n", argv[i + 1]);
405
    sys_abort(300);
406
    }
407
    cprintf("\n %s Opened!!!\n\n", argv[i + 1]);
408
 
409
    mpegbuff[i] = nextphbyte;
410
    p = mpegbuff[i]; cnt[i] = 0;
411
    res = 0x1000;
412
    while (res > 0) {
413
    res = DOS_fread(p, 0x1000, 1, Infile);
414
    cnt[i] += res;
415
    p += res;
416
    }
417
    p += res;
418
    nextphbyte = p;
419
    }
420
    */
421
 
422
  /* OK, Now we can start the system!!! */
423
  //sys_init(&sp);
424
  //keyb_init(SOFT, 100);
425
  //    keyb_init(NULL);
426
  //    k.flag = CNTR_BIT;
427
  //    k.scan = KEY_C;
428
  //    k.ascii = 'c';
429
  //keyb_excset(k,endfun);
430
 
431
  //vfs_init();
432
  /*
433
    for (i = 0; i < argc - 1; i++) {
434
    vfs_assign(argv[i + 1], mpegbuff[i], cnt[i]);
435
    }
436
    */
437
 
438
 
439
 
440
 
441
 
442
 
443
  /* Init the graph... */
444
#ifndef NOSHOW
445
 
446
  if (grx_init() == -1) {
447
    cprintf("No init!!!\n");
448
    sys_abort(255);
449
  }
450
 
451
  mode = grx_getmode(SCREENX, SCREENY, 8);
452
  cprintf("Mode num: %x\n", mode);
453
  grx_cardinfo();
454
#endif
455
 
456
  cprintf("[hit enter to continue]\n");
457
  esc = FALSE;
458
  while (!esc) {
459
    keyb_getcode(&k,BLOCK);
460
    if (k.ascii == 13) esc = TRUE;
461
  }
462
 
463
 
464
  if (mode == -1) {
465
    cprintf("Mode not present!!!\n");
466
    sys_abort(255);
467
  }
468
 
469
#ifndef NOSHOW  
470
  if (grx_setmode(mode) == -1) {
471
    cprintf("No SetMode!!!\n");
472
    sys_abort(255);
473
  }
474
#endif
475
 
476
  //sys_atexit(txtreset,NULL,AFTER_EXIT);
477
 
478
 
479
  //cprintf("Û0Û");
480
 
481
  for (i = 0; i < argc - 1; i++) {
482
    mpeg = fopen(argv[i + 1], "r");
483
 
484
    if (!mpeg) {
485
      perror (argv[1]);
486
      sys_abort(301);
487
    }
488
 
489
    //cprintf("Û0.5Û");
490
 
491
    /* !!! */
492
    img[i].vid_stream=NULL;
493
    img[i].Colormap=NULL;
494
 
495
    if (!OpenMPEG(mpeg, &(img[i]))) {
496
      fprintf (stderr, "OpenMPEG on %s failed\n", argv[i + 1]);
497
      sys_abort(301);
498
    }
499
 
500
 
501
    //cprintf("Û1Û");
502
 
503
 
504
 
505
    SetMPEGOption (&(img[i]), MPEG_DITHER, GRAY_DITHER);
506
    //SetMPEGOption (&(img[i]), MPEG_DITHER, FS4_DITHER);
507
 
508
 
509
    /*  SetMPEGOption(MPEG_DITHER, GRAY_DITHER);        */
510
 
511
    /* printf ("Movie is %d x %d pixels\n", img[i].Width, img[i].Height);
512
       printf ("Required picture rate = %d, required bit rate = %d\n",
513
       img[i].PictureRate, img[i].BitRate); */
514
 
515
    //cprintf("Û2Û");
516
 
517
    if (i == 0) {
518
      cp = img[i].Colormap;
519
 
520
      if (!full_color) {
521
        int  ii;
522
 
523
        for (ii = 0; ii < img[i].ColormapSize; ii++) {
524
 
525
#ifndef NOSHOW
526
 
527
          grx_setcolor (ii, img[i].Colormap[ii].red / 4,
528
                        img[i].Colormap[ii].green / 4,
529
                        img[i].Colormap[ii].blue / 4);
530
 
531
#endif
532
 
533
        }
534
 
535
        /*NO!!! Colormap is an array of short, setpalette wants an array of BYTE!!!*/
536
        /*      grx_setpalette(0, 255, img.Colormap);*/
537
      }
538
    }
539
    if (actx + img[i].Width > SCREENX) {
540
      actx = 10;
541
      acty += 200;
542
    }
543
    sd[i].x1 = actx;
544
    sd[i].y1 = acty;
545
    sd[i].f = mpeg;
546
    sd[i].i = &(img[i]);
547
 
548
    //cprintf("Û3Û");
549
 
550
    soft_task_default_model(model);    
551
    ////soft_task_def_system(model);
552
    //soft_task_def_met(model,9000);
553
    //soft_task_def_wcet(model,9000);
554
    //soft_task_def_period(model,50000);  
555
 
556
    soft_task_def_met(model,5000);
557
    soft_task_def_wcet(model,5000);
558
    soft_task_def_period(model,40000);  
559
    soft_task_def_periodic(model);
560
    soft_task_def_arg(model,(void*)i);
561
    soft_task_def_ctrl_jet(model);
562
 
563
    //task_def_arg(m, i);
564
    //task_def_wcet(m, 9000);
565
    pid = task_create("Shower", play, &model, NULL);
566
    if (pid == -1) {
567
      cprintf(" task --> Not Guaranteed!!!\n");
568
      sys_abort(20000);
569
    }
570
    task_activate(pid);
571
 
572
    //cprintf("Û4Û");
573
 
574
    actx += img[i].Width + 10;
575
  }
576
 
577
  /*   play(0);*/
578
  esc = FALSE;
579
  //jet_delstat(pid);
580
  while (!esc) {
581
    if (keyb_getcode(&k,NON_BLOCK) && (k.ascii == 13)) esc = TRUE;
582
    task_delay(MAINSLEEP);
583
    //jet_getstat(pid,&sum,NULL,NULL,NULL);
584
    //jet_delstat(pid);
585
    //drawload(sum);
586
  }
587
 
588
  sys_abort(59000);
589
 
590
  return 0;
591
}