Date: Mon, 16 Dec 1996 19:01:54 -0700 (MST) From: Terry Lambert <terry@lambert.org> To: scrappy@hub.org (Marc G. Fournier) Cc: hackers@freebsd.org Subject: Re: Almost have mmap() figured, I think... Message-ID: <199612170201.TAA07421@phaeton.artisoft.com> In-Reply-To: <Pine.NEB.3.95.961216200508.283F-100000@hub.org> from "Marc G. Fournier" at Dec 16, 96 08:20:55 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> Altho I really hate to ask, I think I almost have this licked, but > there is something I'm still missing, so the code isn't *quite* working the > way it should. > > Essentially, to simplify things while I "understand it better", > I've created n mmap()'d regions, each representing a frame. There are > n corresponding mmap()'d regions, each of which correspond to the > *size* of the frame. (I know, inelegant, but I can make it more > elegant *after* I know better that which I'm doing...) [ ... ] > The regions are being created as: > > ====== > while(ii < FRAMES) { > sprintf(framestr, "/tmp/frame-%02d", ii); > > /* Setup Video Stream Buffer */ > if((fd = open(framestr, O_RDWR|O_CREAT, 0666)) < 0) { > fprintf(stderr, "cannot open %s\n", framestr); > exit(-1); > } > ftruncate(fd, FRAMESIZE); > if((frame[ii] = > mmap(0, FRAMESIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) > == (caddr_t) -1) { > fprintf(stderr, "cannot mmap frame buffer #%02d\n", ii); > exit(-1); > } > close(fd); > } Alternately: start = mmap( 0, FRAMESIZE * FRAMES, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)); for( i = 0; i < FRAMES; i++) frame[i] = start + i * FRAMESIZE; And use one file... 8-). Also: Are you mapping in both the client and the server? Or just the server? > The problem comes up when I try and print out the frame itself, > using 'printf("%s\n", frame[ii]);'...the value printed out each time > is exactly the same: <FF><D8><FF><E0> What is the data in the frame? Maybe that's right? printf("%s", ...) will stop printing if it hit a <FF><D8><FF><E0><00>... > So, I'm making the assumption that either the way I'm calling, or > using, readn() is incorrect for use with mmap()'d regions...would I be > better off to read in the socket, then memcpy() the data, or strncpy()? Or > is what I'm missing even more simple then that? No; reading directly is a win. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199612170201.TAA07421>