/** ** sendBg.c **/ /* * Sending background images together with the foreground image * without any segmentation, which turned out to work pretty good * with campus network. */ #include #include #include #include #include #include #include #include "X11/Xlib.h" #include "X11/Xutil.h" #include "svm.h" #include "segment.h" #include "rawSend.h" #define OFFSET 0 /* headroom for image processing */ /* my definition starts here */ #define DISP_MAG 2 /* open socket or open file handler */ int sock[2]; /* output sockets */ extern char *optarg; extern int optind; static void usage(char *argv0); static void usage(char *argv0) { fprintf(stderr, "Usage: %s [-f [raw_date] [-b length_of_image][multicast]/port\n", argv0); } int main(int argc, char **argv) { unsigned char *stbuf; /* buffer to hold stereo results */ int width, height; /* width, height of image, number of images*/ XImage *xim1, *xim2, *xim3; /* image buffers for display */ Window win1, win2, win3; /* display windows */ GC gc1, gc2, gc3; unsigned char buf[320*120*2], *p; unsigned char fg[320*240]; int params[20]; Block * bp[MAX_B]; int bn = 0; /* transmission */ unsigned char ttl = 16; static struct sockaddr_in sin; int c; char *host; static int tt; /*XXX start_seq should be initialized with Randome32()*/ u_int32 start_seq = 0; struct timeval start; u_int32 ts; u_int32 ssrc; while ((c = getopt(argc, argv, "h")) != EOF) { switch(c) { case 'h': usage(argv[0]); break; } } if (optind < argc) { host = argv[optind]; } if(GetSendSocekt(host, &sin, &ttl, argv[0])<0) usage(argv[0]); /* get random source ssrc after opening send socket */ ssrc = random32(4); svmOpen(params); if (svmAlive() != 0) { printf("SVM is not responding.\n"); exit(1); } width = params[svmWIDTH]; height = params[svmLENGTH]; svmRestoreParams(); svmSetFunction(svmSTEREO); p = buf; stbuf = buf + width*height; printf ("width = %d height = %d\n", width, height); /******************* Create some windows for display *********** */ /* Connect to a Display. If the the display argument is null, * then open a new one. */ svmOpenDisplay(NULL); /* svmDisplay and svmScreen are the display and screen used by SVM. */ win1 = XCreateSimpleWindow(svmDisplay, DefaultRootWindow(svmDisplay), 0, 0, width*DISP_MAG, height*DISP_MAG, 2, BlackPixel(svmDisplay, svmScreen), BlackPixel(svmDisplay, svmScreen)); win2 = XCreateSimpleWindow(svmDisplay, DefaultRootWindow(svmDisplay), 0, 0, width*DISP_MAG, height*DISP_MAG, 2, BlackPixel(svmDisplay, svmScreen), BlackPixel(svmDisplay, svmScreen)); XMapWindow(svmDisplay, win1); XMapWindow(svmDisplay, win2); gc1 = XCreateGC(svmDisplay,win1,0,NULL); gc2 = XCreateGC(svmDisplay,win2,0,NULL); /* svmColormap is the colormap used by SVM */ XSetWindowColormap(svmDisplay,win1,svmColormap); XSetWindowColormap(svmDisplay,win2,svmColormap); /* get a place to store the images */ xim1 = svmGetImageBuffer(win1, width*DISP_MAG, height*DISP_MAG); xim2 = svmGetImageBuffer(win2, width*DISP_MAG, height*DISP_MAG); /************** Loop over the frames ************************* */ while (1) { /* get the next frame */ while (!svmWaitImage(400)); svmGetImage(params, p, stbuf); // send back ground bp[0] = (Block *)malloc (sizeof(Block)); if (bp[0] == NULL) { printf ("block malloc error"); exit(1); } bp[0]->ncols = FW; bp[0]->nrows = FH; bp[0]->left = 0; bp[0]->top = 0; bp[0]->buf = (unsigned char *)malloc (FW*FH); memcpy (bp[0]->buf, p, FW*FH); bn = 1; if (bp != NULL && bn > 0) { printf ("*************** %d %d %d %d **************\n", bp[0]->left, bp[0]->top, bp[0]->ncols, bp[0]->nrows); // ts is sampling timestamp gettimeofday(&start, 0); ts = (u_int32)(tdbl(&start)*1000); start_seq = SendFrame(start_seq, ts, ssrc, bp[0]->buf, (bp[0]->nrows)*(bp[0]->ncols), bp[0]->left, bp[0]->top, bp[0]->ncols, bp[0]->nrows); if (bp[0]->buf != NULL) { free (bp[0]->buf); } if (bp[0] != NULL) { free (bp[0]); } #ifdef DEBUG printf("returned sequence from sendFrame is; %d \n", start_seq); #endif } svmConvertImage(p, xim1->data, svmNONE, width, height, width, width, svmDepth, DISP_MAG, OFFSET, OFFSET); svmDisplayImage(xim1, win1, gc1, 0, 0); svmConvertImage(stbuf, xim2->data, svmSTEREO, width, height, width, width, svmDepth, DISP_MAG, OFFSET, OFFSET); svmDisplayImage(xim2, win2, gc2, 0, 0); } }