Subversion Repositories shark

Rev

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