Rev 1655 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Project: HARTIK (HA-rd R-eal TI-me K-ernel)
*
* Coordinators: Giorgio Buttazzo <giorgio@sssup.it>
* Gerardo Lamastra <gerardo@sssup.it>
*
* Authors : Luca Abeni <luca@hartik.sssup.it>
* Massimiliano Giorgi <massy@hartik.sssup.it>
* (see authors.txt for full list of hartik's authors)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://hartik.sssup.it
*/
/*
* Copyright (C) 1999 Luca Abeni and Massimiliano Giorgi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/*
* CVS : $Id: mplay.c,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $
*
* File: $File$
* Revision: $Revision: 1.1.1.1 $
* Last update: $Date: 2004-05-24 18:03:39 $
*/
#include <ll/sys/types.h>
#include <kernel/func.h>
#include <kernel/const.h>
//#include <hartik.h>
#include <drivers/keyb.h>
#include <stdlib.h>
#include <stdio.h>
//#include <xdos.h>
#include <drivers/glib.h>
#include "mpeg/video.h"
/*#include "proto.h"*/
#include "mpeg/util.h"
#include "mpeg/dither.h"
#include "mpeg/mpeg.h"
#include <drivers/keyb.h>
void ctrlc_exit
(KEY_EVT
*k
)
{
extern void dump_sem_table
(void);
extern void dump_nop_table
(void);
grx_close
();
cprintf
("CTRL-C pressed!\n");
grx_modeinfo
();
sys_end
();
}
#include <fs/bdevinit.h>
#include <fs/fsinit.h>
#include <fs/bdev.h>
#include <sys/types.h>
#include <sys/mount.h>
int __register_sub_init_prologue
(void)
{
return 0;
}
int __register_sub_init
(void)
{
return 0;
}
dev_t root_device
;
int choose_root_callback
(dev_t dev
,u_int8_t fs
)
{
if (fs
==FS_MSDOS
) return dev
;
return -1;
}
int __bdev_sub_init
(void)
{
BDEV_PARMS bdev
=BASE_BDEV
;
bdev_def_showinfo
(bdev
,TRUE
);
bdev_init
(&bdev
);
root_device
=bdev_scan_devices
(choose_root_callback
);
if (root_device
<0) {
cprintf
("can't find root device to mount on /!!!\n");
sys_end
();
return -1;
}
return 0;
}
extern int libc_initialize
(void);
int __fs_sub_init
(void)
{
FILESYSTEM_PARMS fs
=BASE_FILESYSTEM
;
//struct mount_opts opts;
//memset(&opts,0,sizeof(struct mount_opts));
//opts.flags=MOUNT_FLAG_RW;
filesystem_def_rootdevice
(fs
,root_device
);
filesystem_def_fs
(fs
,FS_MSDOS
);
filesystem_def_showinfo
(fs
,TRUE
);
filesystem_init
(&fs
);
libc_initialize
();
return 0;
}
int x_fseek
(FILE
*file
, long where
, int from
)
{
return fseek(file
,where
,from
);
}
size_t x_fread
(void *buffer
, size_t size
, size_t n
, FILE
*file
)
{
return fread(buffer
,size
,n
,file
);
}
TIME ttt
;
DWORD n
;
///* #define GPHBDIM 4097152 */
//#define GPHBDIM 1000000
//BYTE gphb[GPHBDIM]; /* Std Dim: 2M */
//BYTE *nextphbyte = gphb;
struct streamdescr
{
FILE
*f
;
ImageDesc
*i
;
int x1
, y1
;
} sd
[10];
#define SCREENX 800
#define SCREENY 600
void txtreset
(void *dummy
)
{
grx_close
();
grx_modeinfo
();
/* cprintf("Total frames: %ld\n", i);
cprintf("Total time: %lu\n", t);*/
//cprintf("Frame rate: %lu\n", (n * 1000) / ttt);
/* cprintf("Max frame time: %lu\n", mft);*/
}
#define MAINSLEEP 20000
void drawload
(TIME l
)
{
#define LLPWINSIZE 20
int actl
;
// struct load l;
#define LOADX 500
#define LOADY 300
#define LOADYDIM 50
#define LOADXDIM 100
static int th
= 0;
static int x
= 0;
static int hy
[LLPWINSIZE
];
static int somma
= 0;
int i
;
/* for (i = 0; i < LLPWINSIZE; i++) hy[i] = 0; */
// load_actual(&l);
// actl = (LOADYDIM * l.actual) / l.rif + 1;
// {
// char str[80];
// sprintf(str,"%d",actl);
// /*grx_text("Ciao", 200, 200, color16(31, 63, 31), 0);*/
// grx_text(" ", 100, 400, 100, 0);
// grx_text(str, 100, 400, 100,0);
// }
/* LowPass Filter */
actl
=((long)l
*LOADYDIM
)/MAINSLEEP
+1;
somma
+= actl
- hy
[th
];
hy
[th
] = actl
;
th
= (th
+ 1) % LLPWINSIZE
;
actl
= somma
/ LLPWINSIZE
;
grx_line
(LOADX
+x
,LOADY
,LOADX
+x
,(LOADY
+LOADYDIM
),0);
if (actl
> LOADYDIM
) actl
= LOADYDIM
;
grx_line
(LOADX
+x
,(LOADY
+ actl
),LOADX
+x
,(LOADY
+LOADYDIM
),255);
x
= (x
+ 1) % LOADXDIM
;
}
TASK play
(void *arg
)
{
int i
=(int)arg
;
int loop
= TRUE
;
BYTE
*pixels
;
int moreframes
= TRUE
;
FILE
*mpeg
= sd
[i
].
f;
ImageDesc
*img
= sd
[i
].
i;
int x1
, y1
, x2
, y2
;
/*printf ("Task %d: Movie is %d x %d pixels\n", i, img->Width, img->Height);
printf ("Required picture rate = %d, required bit rate = %d\n",
img->PictureRate, img->BitRate);*/
pixels
= (BYTE
*) malloc(img
->Size
* sizeof(BYTE
));
x1
= sd
[i
].
x1;
y1
= sd
[i
].
y1;
x2
= x1
+ img
->Width
-1;
y2
= y1
+ img
->Height
-1;
while (loop
) { /* play the whole movie forever */
loop
= 1;
n
= 0;
ttt
= sys_gettime
(NULL
);
while (moreframes
) {
//cprintf("°");
moreframes
= GetMPEGFrame
(img
, pixels
);
grx_putimage
(x1
, y1
, x2
, y2
, pixels
);
n
++;
task_endcycle
();
}
ttt
= sys_gettime
(NULL
) - ttt
;
RewindMPEG
(mpeg
, img
);
SetMPEGOption
(img
, MPEG_DITHER
, GRAY_DITHER
);
moreframes
= TRUE
;
}
return 0;
}
int main
(int argc
, char *argv
[])
{
// SYS_PARMS sp = BASE_SYS;
KEY_EVT k
;
// MODEL m = BASE_MODEL;
PID pid
;
// DOS_FILE *Infile;
// BYTE *mpegbuff[10], *p;
// WORD res;
// DWORD cnt[10];
TIME sum
;
SOFT_TASK_MODEL model
;
FILE
*mpeg
;
ImageDesc img
[10];
int full_color
= FALSE
;
int mode
;
int esc
;
int i
;
int actx
= 10, acty
= 10;
ColormapEntry
*cp
;
//cprintf("file '%s'\n",argv[1]);
if (argc
< 2) {
fprintf (stderr
, "Usage: %s mpegfile\n", argv
[0]);
sys_abort
(301);
}
/*
for (i = 0; i < argc - 1; i++) {
Infile = DOS_fopen(argv[i + 1], "r");
if (!Infile) {
cprintf("%s not found!!!\n", argv[i + 1]);
sys_abort(300);
}
cprintf("\n %s Opened!!!\n\n", argv[i + 1]);
mpegbuff[i] = nextphbyte;
p = mpegbuff[i]; cnt[i] = 0;
res = 0x1000;
while (res > 0) {
res = DOS_fread(p, 0x1000, 1, Infile);
cnt[i] += res;
p += res;
}
p += res;
nextphbyte = p;
}
*/
/* OK, Now we can start the system!!! */
//sys_init(&sp);
//keyb_init(SOFT, 100);
// keyb_init(NULL);
// k.flag = CNTR_BIT;
// k.scan = KEY_C;
// k.ascii = 'c';
//keyb_excset(k,endfun);
//vfs_init();
/*
for (i = 0; i < argc - 1; i++) {
vfs_assign(argv[i + 1], mpegbuff[i], cnt[i]);
}
*/
/* Init the graph... */
if (grx_init
() == -1) {
cprintf
("No init!!!\n");
sys_abort
(255);
}
mode
= grx_getmode
(SCREENX
, SCREENY
, 8);
cprintf
("Mode num: %x\n", mode
);
grx_cardinfo
();
cprintf
("[hit enter to continue]\n");
esc
= FALSE
;
while (!esc
) {
keyb_getcode
(&k
,BLOCK
);
if (k.
ascii == 13) esc
= TRUE
;
}
if (mode
== -1) {
cprintf
("Mode not present!!!\n");
sys_abort
(255);
}
if (grx_setmode
(mode
) == -1) {
cprintf
("No SetMode!!!\n");
sys_abort
(255);
}
//sys_atexit(txtreset,NULL,AFTER_EXIT);
//cprintf("Û0Û");
for (i
= 0; i
< argc
- 1; i
++) {
mpeg
= fopen(argv
[i
+ 1], "r");
if (!mpeg
) {
perror (argv
[1]);
sys_abort
(301);
}
setvbuf(mpeg
,NULL
,_IOFBF
,BUFSIZ
*100);
//cprintf("Û0.5Û");
/* !!! */
img
[i
].
vid_stream=NULL
;
img
[i
].
Colormap=NULL
;
if (!OpenMPEG
(mpeg
, &(img
[i
]))) {
fprintf (stderr
, "OpenMPEG on %s failed\n", argv
[i
+ 1]);
sys_abort
(301);
}
//cprintf("Û1Û");
SetMPEGOption
(&(img
[i
]), MPEG_DITHER
, GRAY_DITHER
);
//SetMPEGOption (&(img[i]), MPEG_DITHER, FS4_DITHER);
/* SetMPEGOption(MPEG_DITHER, GRAY_DITHER); */
/* printf ("Movie is %d x %d pixels\n", img[i].Width, img[i].Height);
printf ("Required picture rate = %d, required bit rate = %d\n",
img[i].PictureRate, img[i].BitRate); */
//cprintf("Û2Û");
if (i
== 0) {
cp
= img
[i
].
Colormap;
if (!full_color
) {
int ii
;
for (ii
= 0; ii
< img
[i
].
ColormapSize; ii
++) {
grx_setcolor
(ii
, img
[i
].
Colormap[ii
].
red / 4,
img
[i
].
Colormap[ii
].
green / 4,
img
[i
].
Colormap[ii
].
blue / 4);
}
/*NO!!! Colormap is an array of short, setpalette wants an array of BYTE!!!*/
/* grx_setpalette(0, 255, img.Colormap);*/
}
}
if (actx
+ img
[i
].
Width > SCREENX
) {
actx
= 10;
acty
+= 200;
}
sd
[i
].
x1 = actx
;
sd
[i
].
y1 = acty
;
sd
[i
].
f = mpeg
;
sd
[i
].
i = &(img
[i
]);
//cprintf("Û3Û");
soft_task_default_model
(model
);
////soft_task_def_system(model);
//soft_task_def_met(model,9000);
//soft_task_def_wcet(model,9000);
//soft_task_def_period(model,50000);
soft_task_def_met
(model
,5000);
soft_task_def_wcet
(model
,15000);
soft_task_def_period
(model
,40000);
soft_task_def_periodic
(model
);
soft_task_def_arg
(model
,(void*)i
);
soft_task_def_ctrl_jet
(model
);
//task_def_arg(m, i);
//task_def_wcet(m, 9000);
pid
= task_create
("video", play
, &model
, NULL
);
if (pid
== -1) {
cprintf
(" task --> Not Guaranteed!!!\n");
sys_abort
(20000);
}
task_activate
(pid
);
//cprintf("Û4Û");
actx
+= img
[i
].
Width + 10;
}
/* play(0);*/
esc
= FALSE
;
//jet_delstat(pid);
while (!esc
) {
if (keyb_getcode
(&k
,NON_BLOCK
) && (k.
ascii == 13)) esc
= TRUE
;
task_delay
(MAINSLEEP
);
//jet_getstat(pid,&sum,NULL,NULL,NULL);
//jet_delstat(pid);
//drawload(sum);
}
sys_abort
(59000);
return 0;
}