1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
|
/*
* Marcus Meissner, 1997
*/
#ifndef lint
/*
static char rcsid[] =
"@(#) $Header: /cs/research/mice/starship/src/local/CVS_repository/vic/output-fileStream.cc,v 1.1 1998/11/26 17:33:56 piers Exp $ (LBL)";
*/
#endif
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <xil/xil.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/ipc.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "Tcl.h"
#include "inet.h"
#include "rtp.h"
#include "decoder.h"
#include "vw.h"
#include "renderer.h"
#include "device-output.h"
#include "xil.h"
#define M_SOI 0xd8
#define M_APP0 0xe0
#define M_DQT 0xdb
#define M_SOF0 0xc0 /* marks BASELINE DCT */
#define M_DHT 0xc4
#define M_SOS 0xda
#define M_EOI 0xd9
class FILEOutputDevice : public OutputDevice {
public:
FILEOutputDevice();
virtual int command(int argc, const char*const* argv);
};
class FILEOutputAssistor : public Renderer {
public:
FILEOutputAssistor(int type);
~FILEOutputAssistor();
protected:
virtual int command(int argc,const char*const* argv);
void reset(int type, int inq,int inw,int inh);
void setq(int q);
virtual int consume(const VideoFrame* vf);
int decimation_;
int lastjpegtype_;
int type_;
int inq_; //jpeg.
int xfd_;
int visual;
int sentfirstheader;
u_int targetw_,targeth_,lastcisw,lastcish;
u_char jfif_header1[sizeof(jfif_header1_)];
u_char jfif_header2[sizeof(jfif_header2_)];
char *filename_;
int sigalarmpid_,xtime_,lasttime_;
struct deviceattributes deviceattributes_;
};
extern jpeg_luma_qt(int,int[]);
extern jpeg_chroma_qt(int,int[]);
static int
mapkoord2jfifentry[] = {
0, 1,8, 16,9,2, 3,10,17,24, 32,25,18,11,4, 5,12,19,26,33,40,
48,41,34,27,20,13,6, 7,14,21,28,35,42,49,56, 57,50,43,36,29,22,15,
23,30,37,44,51,58, 59,52,45,38,31, 39,46,53,60, 61,54,47, 55,62, 63
};
FILEOutputAssistor::FILEOutputAssistor(int type) : Renderer(type) {
char *cisname;
XilDevice device;
char *interval,*sigalarm;
interval = getenv("VIC_DROPINTERVAL");
sigalarm = getenv("VIC_SIGALARM");
if (!interval || !sscanf(interval,"%d",&xtime_))
xtime_ = 15; // 15 seconds
if (sigalarm)
sigalarmpid_=atoi(sigalarm);
lasttime_=0;
cisname=NULL;
switch (type) {
case FT_YUV_411:
break;
case FT_JPEG|FT_HW:
memcpy(jfif_header1,jfif_header1_,sizeof(jfif_header1_));
memcpy(jfif_header2,jfif_header2_,sizeof(jfif_header2_));
break;
case FT_H261:
cisname = "H261";
break;
case FT_CELLB:
cisname = "CellB";
break;
default:
fprintf(stderr," unknown type %d???\n",type&~FT_HW);
break;
}
type_ = type;
xfd_ = open("/tmp/vic.out",O_WRONLY|O_CREAT,0644);
if (xfd_==-1)
perror("open /tmp/vic.out");
}
FILEOutputAssistor::~FILEOutputAssistor() {
close(xfd_);
}
void FILEOutputAssistor::setq(int q)
{
int qt[8][8];
XilJpegQTable xq;
inq_ = q;
sentfirstheader=0;
jpeg_luma_qt(q, (int*)qt);
xq.table = 0;
xq.value = qt;
//(void)xil_cis_set_attribute(cis_, "QUANTIZATION_TABLE", (void*)&xq);
jpeg_chroma_qt(q, (int*)qt);
xq.table = 1;
xq.value = qt;
//(void)xil_cis_set_attribute(cis_, "QUANTIZATION_TABLE", (void*)&xq);
}
void FILEOutputAssistor::reset(int type, int q, int w, int h)
{
int qt[64];
unsigned int i,j;
// blblbl.
//fprintf(stderr,"XILWindowAssistor::"__FUNCTION__"\n");
Module::size(w, h);
inq_ = q;
sentfirstheader=0;
lastjpegtype_ = type;
switch (type) {
case 1: /* 411 */
decimation_ = 411;
break;
default:
decimation_ = 422;
break;
}
for (i=0;i<sizeof(jfif_header1_);i++) {
if (jfif_header1[i]!=0xff)
continue;
i++;if (i==sizeof(jfif_header1)) break;
switch (jfif_header1[i]) {
case M_DQT:
//well the size is correct. we have defined the table
i+=3;
switch (jfif_header1[i]) {
case 0:/* LUMA */
i++;
jpeg_luma_qt(q,qt);
for (j=0;j<64;j++)
jfif_header1[i+j]=qt[mapkoord2jfifentry[j]];
break;
case 1:/* CHROMA */
i++;
jpeg_chroma_qt(q,qt);
for (j=0;j<64;j++)
jfif_header1[i+j]=qt[mapkoord2jfifentry[j]];
break;
}
break;
case M_SOF0:
i+=3;
i++; /* sample precision */
jfif_header1[i++] = h>>8;
jfif_header1[i++] = h&0xff;
jfif_header1[i++] = w>>8;
jfif_header1[i++] = w&0xff;
i++; /* components (3) */
i++; /* comp id 0 */
if (decimation_ == 411)
jfif_header1[i++] = 0x22;/* 0x22 for 2 hor/2 vert */
else
jfif_header1[i++] = 0x21;/* 0x21 for 2 hor/1 vert */
i++; /* quant dest */
i++; /* comp id 1 */
i++; /* hor/ver quant 1:1 */
i++; /* quant dest */
i++; /* comp id 2 */
i++; /* hor/ver quant 1:1 */
i++; /* quant dest */
break;
default:
//fprintf(stderr,"blocktype %02x\n",jfif_header1[i]);
break;
}
}
for (i=0;i<sizeof(jfif_header2);i++) {
if (jfif_header2[i]!=0xff)
continue;
i++;if (i==sizeof(jfif_header2)) break;
switch (jfif_header2[i]) {
case M_SOF0:
i+=3;
i++; /* sample precision */
jfif_header2[i++] = h>>8;
jfif_header2[i++] = h&0xff;
jfif_header2[i++] = w>>8;
jfif_header2[i++] = w&0xff;
i++; /* components (3) */
i++; /* comp id 0 */
if (decimation_ == 411)
jfif_header2[i++] = 0x22;/* 0x22 for 2 hor/2 vert */
else
jfif_header2[i++] = 0x21;/* 0x21 for 2 hor/1 vert */
i++; /* quant dest */
i++; /* comp id 1 */
i++; /* hor/ver quant 1:1 */
i++; /* quant dest */
i++; /* comp id 2 */
i++; /* hor/ver quant 1:1 */
i++; /* quant dest */
break;
default:
break;
}
}
}
int FILEOutputAssistor::command(int argc, const char*const* argv) {
/*
fprintf(stderr,"FILEOutputAsssitor()::"__FUNCTION__"(");
for (int i=1;i<argc;i++)
fprintf(stderr,"%s,",argv[i]);
fprintf(stderr,")\n");
*/
if (argc == 3 ) {
if ( strcmp(argv[1],"scale") == 0) {
/* ignore !?! */
return (TCL_OK);
}
}
return Renderer::command(argc,argv);
}
int FILEOutputAssistor::consume(const VideoFrame* vf) {
int res,len=0,dofree=0;
u_char *bp,*p=NULL;
//fprintf(stderr,"FILEOutputAssistor()::"__FUNCTION__"\n");
if (time(NULL)<lasttime_+xtime_)
return 0;
lasttime_ = time(NULL);
switch (type_) {
case FT_JPEG|FT_HW: {
JpegFrame* jf = (JpegFrame*)vf;
if ( (jf->q_ != inq_) ||
(jf->width_ != width_) ||
(jf->height_ != height_)
)
reset(jf->type_, jf->q_, jf->width_, jf->height_);
len=jf->len_;
bp=jf->bp_;
dofree=1;
// kill marcus
if (sentfirstheader) {
p = new u_char[sizeof(jfif_header2)+len+2];
memcpy(p,jfif_header2,sizeof(jfif_header2));
memcpy(p+sizeof(jfif_header2),bp,len);
// kill me
memcpy(p+sizeof(jfif_header2)+len,"\0xff\0xd9",2);
len+=sizeof(jfif_header2)+2;
} else {
p = new u_char [sizeof(jfif_header1)+len+2];
memcpy(p,jfif_header1,sizeof(jfif_header1));
memcpy(p+sizeof(jfif_header1),bp,len);
// kill me
memcpy(p+sizeof(jfif_header1)+len,"\0xff\0xd9",2);
len+=sizeof(jfif_header1)+2;
sentfirstheader=1;
}
break;
}
case FT_CELLB: {
CellBFrame* hf = (CellBFrame*) vf;
len=hf->len_;
p=hf->bp_;
// xil_cis_set_attribute(cis_, "WIDTH", (void *)hf->width_);
// xil_cis_set_attribute(cis_, "HEIGHT", (void *)hf->height_);
break;
}
case FT_YUV_411:
p=vf->bp_;
len=vf->width_*vf->height_*6/4;
break;
case FT_H261: {
H261Frame* hf = (H261Frame*) vf;
len=hf->len_;
p=hf->bp_;
while ((p[0]==0)&&(p[1]==0)) {
p++;len--;
}
break;
}
}
res=write(xfd_,p,len);
if (res==-1)
perror("FILEOutputAssistor::write");
if (res<=0) {
//hmmm...
}
if (sigalarmpid_)
kill(sigalarmpid_,SIGALRM);
return (0);
}
FILEOutputDevice fileoutputdevice;
FILEOutputDevice::FILEOutputDevice() : OutputDevice("file")
{
}
int FILEOutputDevice::command(int argc, const char*const* argv) {
Tcl& tcl = Tcl::instance();
/*
fprintf(stderr,"FILEOutputDevice::command(");
for (int i=1;i<argc;i++)
fprintf(stderr,"%s,",argv[i]);
fprintf(stderr,")\n");
*/
if (argc == 3 ) {
if (!strcmp(argv[1],"renderer")) {
if (!strcmp(argv[2],"411")) {
FILEOutputAssistor* p = new FILEOutputAssistor(FT_YUV_411);
tcl.result(p->name());
return (TCL_OK);
}
}
if ( !strcmp(argv[1],"assistor")) {
#if 0
if (!strcmp(argv[2],"cellb")) {
FILEOutputAssistor* p = new FILEOutputAssistor(FT_CELLB,filename_,&deviceattributes_);
tcl.result(p->name());
return (TCL_OK);
}
#endif
if (!strcmp(argv[2],"h261")) {
FILEOutputAssistor* p = new FILEOutputAssistor(FT_H261);
tcl.result(p->name());
return (TCL_OK);
}
if (!strcmp(argv[2],"jpeg/411") || !strcmp(argv[2],"jpeg/422")) {
//FILEOutputAssistor* p = new FILEOutputAssistor(FT_JPEG|FT_HW,filename_,&deviceattributes_);
FILEOutputAssistor* p = new FILEOutputAssistor(FT_JPEG|FT_HW);
tcl.result(p->name());
return (TCL_OK);
}
}
}
return OutputDevice::command(argc,argv);
}
|