Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1085 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * Copyright (C) 1999 Luca Abeni and Massimiliano Giorgi
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 */
37
 
38
/*
39
 * CVS :        $Id: gvideo.c,v 1.1.1.1 2002-09-02 09:37:41 pj Exp $
40
 *
41
 * File:        $File$
42
 * Revision:    $Revision: 1.1.1.1 $
43
 * Last update: $Date: 2002-09-02 09:37:41 $
44
 */
45
 
46
#include "config.h"
47
 
48
#include <kernel/func.h>
49
#include <kernel/model.h>
50
#include <kernel/const.h>
51
 
52
#include <drivers/glib.h>
53
 
54
#include <stdlib.h>
55
 
56
#include "mpeg/video.h"
57
#include "mpeg/util.h"
58
#include "mpeg/dither.h"
59
#include "mpeg/mpeg.h"
60
 
61
#include "mutex.h"
62
#include "gvideo.h"
63
#include "gbuffer.h"
64
#include "xread.h"
65
 
66
#define STARTGROUP 513
67
 
68
#define VIDEORATE 70
69
#define READRATE  30
70
 
71
/*
72
 * colors
73
 */
74
 
75
#ifdef FULLCOLOR
76
 
77
#define COLORFG rgb16(255,255,255)
78
#define COLORBG rgb16(0,0,0)
79
 
80
#define SP rgb16(0,128,0)
81
#define FG rgb16(255,255,255)
82
#define BG rgb16(0,0,0)
83
 
84
#else
85
 
86
/* for writing */
87
#define COLORFG 255
88
#define COLORBG 0
89
 
90
/* for box */
91
#define SP 128
92
#define FG 255
93
#define BG 0
94
 
95
#endif
96
 
97
/* border size (pixels) */
98
#define BO 4
99
 
100
/*
101
 *
102
 */
103
 
104
#ifdef FULLCOLOR
105
/* 16bits format 5:6:5 */
106
/* 32bits format 8:8:8:0 */
107
void down32to16(WORD *dst, BYTE *src, int size)
108
{
109
  int i;
110
  return;
111
  for (i=0;i<size;i+=4,dst++,src+=4)
112
    /* blue green red */
113
    *dst=((src[2]&0xf8)>>3)|((src[1]&0xfc)<<3)|((src[0]&0xf8)<<8);
114
}
115
#endif
116
 
117
/*
118
 *
119
 */
120
 
121
void draw_frame(int x, int y, int dx, int dy)
122
{
123
#ifndef NOGRX
124
  grxlock();
125
  grx_box(x-1-BO,y-1-BO,x+dx+BO,y+dy+BO,SP);
126
  grx_rect(x-1-BO,y-1-BO,x+dx+BO,y+dy+BO,FG);
127
  grx_box(x,y,x+dx-1,y+dy-1,BG);
128
  grx_rect(x-1,y-1,x+dx,y+dy,FG);
129
  grxunlock();
130
#endif
131
}
132
 
133
struct info {
134
  int       x,y;
135
  ImageDesc *img;
136
};
137
 
138
static TASK play(void *arg)
139
{
140
  struct info *ptr=(struct info*)arg;
141
  int x1,y1,x2,y2;
142
  BYTE *pixels; //,*image;
143
  int moreframes;
144
 
145
  pixels=(BYTE*)malloc(ptr->img->Size*sizeof(BYTE));
146
#ifdef FULLCOLOR
147
  image=(BYTE*)malloc(ptr->img->Size/2*sizeof(BYTE));
148
#endif
149
  x1=ptr->x;
150
  y1=ptr->y;
151
  x2=x1+ptr->img->Width-1;
152
  y2=y1+ptr->img->Height-1;
153
 
154
  moreframes=1;
155
  for (;;) {
156
    while (moreframes) {
157
      moreframes=GetMPEGFrame(ptr->img,pixels);
158
#ifndef NOGRX
159
#ifdef FULLCOLOR
160
      down32to16((WORD*)image,pixels,ptr->img->Size);
161
      grxlock();
162
      grx_putimage(x1, y1, x2, y2, pixels);
163
      grxunlock();
164
#else
165
      grxlock();
166
      grx_putimage(x1, y1, x2, y2, pixels);
167
      grxunlock();
168
#endif
169
#else
170
      cprintf("%c",'0');      
171
#endif
172
      task_endcycle();
173
    }
174
    break;
175
 
176
    //if (!loop) break;
177
    //RewindMPEG (mpeg, img);
178
    //SetMPEGOption (img, MPEG_DITHER, GRAY_DITHER);
179
    //moreframes = TRUE;
180
  }
181
 
182
  return NULL;
183
}
184
 
185
int gvideo_init(char *title, struct gvideoinfo *ptr)
186
{
187
  //  static int      groupcounter=0;
188
  struct info     *info;
189
  SOFT_TASK_MODEL model;
190
  FILE            *fin;
191
  PID             pid,pid2;
192
  ImageDesc       *img;
193
  int             res;
194
  int             i;
195
  int             period,wcet;
196
  int             group;
197
 
198
  img=(ImageDesc*)malloc(sizeof(ImageDesc));
199
  if (img==NULL) return -3;
200
  img->vid_stream=NULL;
201
  img->Colormap=NULL;
202
 
203
  info=(struct info*)malloc(sizeof(struct info));
204
  if (info==NULL) return -11;
205
  info->img=img;
206
  info->x=ptr->x;
207
  info->y=ptr->y;
208
 
209
  fin=fopen(ptr->pathname, "r");  
210
  if (!fin) return -1;
211
 
212
  //group=STARTGROUP+groupcounter++;
213
  group=STARTGROUP;
214
  pid2=x_initbuffer(group,fin,ptr->bitrate,ptr->band*READRATE);
215
  if (pid2<0) return -2;
216
 
217
#ifdef ACTIVATE
218
  gbuffer_init(table[fileno(fin)],group,20+12,450);
219
#else
220
  gbuffer_init(NULL,group,20+12,450);
221
#endif
222
 
223
  res=OpenMPEG(fin,img);
224
  if (!res) return -4;
225
 
226
#ifdef FULLCOLOR  
227
  SetMPEGOption(img,MPEG_DITHER,HALF_COLOR_DITHER);
228
#else
229
  SetMPEGOption(img,MPEG_DITHER,GRAY_DITHER);
230
#endif  
231
 
232
  //cprintf("colrmap size=%8i\n",img->ColormapSize);
233
  //cprintf("picture rate=%8i\n",img->PictureRate);
234
  //cprintf("bit rate    =%8i\n",img->BitRate);
235
 
236
#ifndef FULLCOLOR
237
  if (group==STARTGROUP) {
238
    ColormapEntry *cp;
239
    cp=img->Colormap;
240
    for (i=0;i<img->ColormapSize;i++) {
241
#ifndef NOGRX
242
      grxlock();
243
      grx_setcolor (i,img->Colormap[i].red/4,
244
                    img->Colormap[i].green/4,
245
                    img->Colormap[i].blue/4);
246
      grxunlock();
247
#endif    
248
    }
249
  }
250
#endif
251
 
252
  draw_frame(info->x,info->y,img->Width,img->Height);
253
  ptr->w=img->Width;
254
  ptr->h=img->Height;
255
 
256
  {
257
    char buffer[256];
258
 
259
#ifndef NOGRX
260
    grxlock();
261
    grx_text(title,ptr->x,ptr->y-14,COLORFG,COLORBG);
262
    grxunlock();
263
    sprintf(buffer,"Average bit rate: %i.%03i Mb/s",
264
            ptr->bitrate/1024/1024,(ptr->bitrate%(1024*1024))*1000/1024/1000);
265
    grxlock();
266
    grx_text(buffer,ptr->x,ptr->y+ptr->h+BO*2+2,COLORFG,COLORBG);
267
    grxunlock();
268
    sprintf(buffer,"Frame rate      : %02.3f frame/sec",
269
            (double)ptr->framerate/100.0);
270
    grxlock();
271
    grx_text(buffer,ptr->x,ptr->y+ptr->h+BO*2+2+9,COLORFG,COLORBG);
272
    grxunlock();
273
#endif
274
  }
275
 
276
  period=100000000/ptr->framerate;
277
  wcet=period*ptr->band*VIDEORATE/10000;
278
 
279
  soft_task_default_model(model);        
280
  soft_task_def_met(model,wcet);
281
  soft_task_def_wcet(model,wcet);
282
  soft_task_def_period(model,period);
283
  soft_task_def_periodic(model);
284
  soft_task_def_arg(model,(void*)info);
285
  soft_task_def_group(model,group);
286
  soft_task_def_ctrl_jet(model);
287
 
288
  pid=task_create("Video",play,&model,NULL);
289
  if (pid==-1) return -6;
290
 
291
  return group;
292
}