Subversion Repositories shark

Rev

Details | 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: mplay.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
#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
 
203
#define MAINSLEEP 20000
204
 
205
void drawload(TIME l)
206
{
207
    #define LLPWINSIZE 20
208
    int actl;
209
//  struct load l;
210
    #define LOADX 500
211
    #define LOADY 300
212
    #define LOADYDIM 50
213
    #define LOADXDIM 100
214
    static int th = 0;
215
    static int x = 0;
216
    static int hy[LLPWINSIZE];
217
    static int somma = 0;
218
    int i;
219
 
220
/*    for (i = 0; i < LLPWINSIZE; i++) hy[i] = 0; */
221
 
222
//    load_actual(&l);
223
//    actl = (LOADYDIM * l.actual) / l.rif + 1;
224
//    {
225
//      char str[80];
226
//      sprintf(str,"%d",actl);
227
//      /*grx_text("Ciao", 200, 200, color16(31, 63, 31), 0);*/
228
//      grx_text("    ", 100, 400, 100, 0);
229
//      grx_text(str, 100, 400, 100,0);
230
//    }
231
/*              LowPass Filter                  */
232
 
233
 
234
    actl=((long)l*LOADYDIM)/MAINSLEEP+1;
235
 
236
    somma += actl - hy[th];
237
    hy[th] = actl;
238
    th = (th + 1) % LLPWINSIZE;
239
    actl = somma / LLPWINSIZE;
240
    grx_line(LOADX+x,LOADY,LOADX+x,(LOADY+LOADYDIM),0);
241
    if (actl > LOADYDIM) actl = LOADYDIM;
242
    grx_line(LOADX+x,(LOADY + actl),LOADX+x,(LOADY+LOADYDIM),255);
243
 
244
    x = (x + 1) % LOADXDIM;
245
 
246
}
247
 
248
 
249
 
250
TASK play(void *arg)
251
{
252
  int i=(int)arg;
253
    int loop = TRUE;
254
  BYTE *pixels;
255
  int moreframes = TRUE;
256
  FILE *mpeg = sd[i].f;
257
  ImageDesc *img = sd[i].i;
258
  int x1, y1, x2, y2;
259
 
260
  /*printf ("Task %d: Movie is %d x %d pixels\n", i, img->Width, img->Height);
261
    printf ("Required picture rate = %d, required bit rate = %d\n",
262
    img->PictureRate, img->BitRate);*/
263
 
264
  pixels = (BYTE *) malloc(img->Size * sizeof(BYTE));
265
  x1 = sd[i].x1;
266
  y1 = sd[i].y1;
267
  x2 = x1 + img->Width-1;
268
  y2 = y1 + img->Height-1;
269
  while (loop) {                        /* play the whole movie forever */
270
    loop = 1;
271
    n = 0;
272
    ttt = sys_gettime(NULL);
273
    while (moreframes) {
274
      //cprintf("°");    
275
      moreframes = GetMPEGFrame (img, pixels);
276
      grx_putimage(x1, y1, x2, y2, pixels);
277
      n++;
278
      task_endcycle();
279
    }
280
    ttt = sys_gettime(NULL) - ttt;
281
    RewindMPEG (mpeg, img);
282
    SetMPEGOption (img, MPEG_DITHER, GRAY_DITHER);
283
    moreframes = TRUE;
284
  }
285
 
286
  return 0;
287
}
288
 
289
 
290
 
291
int main(int argc, char *argv[])
292
{
293
  //    SYS_PARMS sp = BASE_SYS;
294
  KEY_EVT k;
295
  //    MODEL m = BASE_MODEL;
296
  PID pid;
297
 
298
  //    DOS_FILE *Infile;
299
//  BYTE *mpegbuff[10], *p;
300
//  WORD res;
301
//  DWORD cnt[10];
302
 
303
 
304
TIME sum;
305
 
306
  SOFT_TASK_MODEL model;
307
 
308
  FILE       *mpeg;
309
  ImageDesc   img[10];
310
  int full_color = FALSE;
311
 
312
  int mode;
313
  int esc;
314
  int i;
315
  int actx = 10, acty = 10;
316
  ColormapEntry *cp;
317
 
318
  //cprintf("file '%s'\n",argv[1]);
319
 
320
  if (argc < 2) {
321
    fprintf (stderr, "Usage: %s mpegfile\n", argv[0]);
322
    sys_abort(301);
323
  }
324
 
325
  /*
326
    for (i = 0; i < argc - 1; i++) {
327
    Infile = DOS_fopen(argv[i + 1], "r");
328
    if (!Infile) {
329
    cprintf("%s not found!!!\n", argv[i + 1]);
330
    sys_abort(300);
331
    }
332
    cprintf("\n %s Opened!!!\n\n", argv[i + 1]);
333
 
334
    mpegbuff[i] = nextphbyte;
335
    p = mpegbuff[i]; cnt[i] = 0;
336
    res = 0x1000;
337
    while (res > 0) {
338
    res = DOS_fread(p, 0x1000, 1, Infile);
339
    cnt[i] += res;
340
    p += res;
341
    }
342
    p += res;
343
    nextphbyte = p;
344
    }
345
    */
346
 
347
  /* OK, Now we can start the system!!! */
348
  //sys_init(&sp);
349
  //keyb_init(SOFT, 100);
350
  //    keyb_init(NULL);
351
  //    k.flag = CNTR_BIT;
352
  //    k.scan = KEY_C;
353
  //    k.ascii = 'c';
354
  //keyb_excset(k,endfun);
355
 
356
  //vfs_init();
357
  /*
358
    for (i = 0; i < argc - 1; i++) {
359
    vfs_assign(argv[i + 1], mpegbuff[i], cnt[i]);
360
    }
361
    */
362
 
363
 
364
 
365
 
366
 
367
 
368
  /* Init the graph... */
369
  if (grx_init() == -1) {
370
    cprintf("No init!!!\n");
371
    sys_abort(255);
372
  }
373
 
374
  mode = grx_getmode(SCREENX, SCREENY, 8);
375
  cprintf("Mode num: %x\n", mode);
376
  grx_cardinfo();
377
  cprintf("[hit enter to continue]\n");
378
  esc = FALSE;
379
  while (!esc) {
380
    keyb_getcode(&k,BLOCK);
381
    if (k.ascii == 13) esc = TRUE;
382
  }
383
 
384
 
385
  if (mode == -1) {
386
    cprintf("Mode not present!!!\n");
387
    sys_abort(255);
388
  }
389
 
390
  if (grx_setmode(mode) == -1) {
391
    cprintf("No SetMode!!!\n");
392
    sys_abort(255);
393
  }
394
 
395
  //sys_atexit(txtreset,NULL,AFTER_EXIT);
396
 
397
 
398
  //cprintf("Û0Û");
399
 
400
  for (i = 0; i < argc - 1; i++) {
401
    mpeg = fopen(argv[i + 1], "r");
402
 
403
    if (!mpeg) {
404
      perror (argv[1]);
405
      sys_abort(301);
406
    }
407
 
408
 
409
    setvbuf(mpeg,NULL,_IOFBF,BUFSIZ*100);
410
 
411
 
412
    //cprintf("Û0.5Û");
413
 
414
    /* !!! */
415
    img[i].vid_stream=NULL;
416
    img[i].Colormap=NULL;
417
 
418
    if (!OpenMPEG(mpeg, &(img[i]))) {
419
      fprintf (stderr, "OpenMPEG on %s failed\n", argv[i + 1]);
420
      sys_abort(301);
421
    }
422
 
423
 
424
    //cprintf("Û1Û");
425
 
426
 
427
 
428
    SetMPEGOption (&(img[i]), MPEG_DITHER, GRAY_DITHER);
429
    //SetMPEGOption (&(img[i]), MPEG_DITHER, FS4_DITHER);
430
 
431
 
432
    /*  SetMPEGOption(MPEG_DITHER, GRAY_DITHER);        */
433
 
434
    /* printf ("Movie is %d x %d pixels\n", img[i].Width, img[i].Height);
435
       printf ("Required picture rate = %d, required bit rate = %d\n",
436
       img[i].PictureRate, img[i].BitRate); */
437
 
438
    //cprintf("Û2Û");
439
 
440
    if (i == 0) {
441
      cp = img[i].Colormap;
442
 
443
      if (!full_color) {
444
        int  ii;
445
 
446
        for (ii = 0; ii < img[i].ColormapSize; ii++) {
447
 
448
 
449
          grx_setcolor (ii, img[i].Colormap[ii].red / 4,
450
                        img[i].Colormap[ii].green / 4,
451
                        img[i].Colormap[ii].blue / 4);
452
 
453
 
454
        }
455
 
456
        /*NO!!! Colormap is an array of short, setpalette wants an array of BYTE!!!*/
457
        /*      grx_setpalette(0, 255, img.Colormap);*/
458
      }
459
    }
460
    if (actx + img[i].Width > SCREENX) {
461
      actx = 10;
462
      acty += 200;
463
    }
464
    sd[i].x1 = actx;
465
    sd[i].y1 = acty;
466
    sd[i].f = mpeg;
467
    sd[i].i = &(img[i]);
468
 
469
    //cprintf("Û3Û");
470
 
471
    soft_task_default_model(model);    
472
    ////soft_task_def_system(model);
473
    //soft_task_def_met(model,9000);
474
    //soft_task_def_wcet(model,9000);
475
    //soft_task_def_period(model,50000);  
476
 
477
    soft_task_def_met(model,5000);
478
    soft_task_def_wcet(model,15000);
479
    soft_task_def_period(model,40000);  
480
    soft_task_def_periodic(model);
481
    soft_task_def_arg(model,(void*)i);
482
    soft_task_def_ctrl_jet(model);
483
 
484
    //task_def_arg(m, i);
485
    //task_def_wcet(m, 9000);
486
    pid = task_create("video", play, &model, NULL);
487
    if (pid == -1) {
488
      cprintf(" task --> Not Guaranteed!!!\n");
489
      sys_abort(20000);
490
    }
491
    task_activate(pid);
492
 
493
    //cprintf("Û4Û");
494
 
495
    actx += img[i].Width + 10;
496
  }
497
 
498
  /*   play(0);*/
499
  esc = FALSE;
500
  //jet_delstat(pid);
501
  while (!esc) {
502
    if (keyb_getcode(&k,NON_BLOCK) && (k.ascii == 13)) esc = TRUE;
503
    task_delay(MAINSLEEP);
504
    //jet_getstat(pid,&sum,NULL,NULL,NULL);
505
    //jet_delstat(pid);
506
    //drawload(sum);
507
  }
508
 
509
  sys_abort(59000);
510
 
511
  return 0;
512
}