apps/web/imgsrv/imgsrv.c File Reference

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>
#include <syslog.h>
#include <netinet/in.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <asm/elphel/c313a.h>
#include <asm/elphel/exifa.h>
#include <asm/elphel/ext353.h>
#include <asm/byteorder.h>

Include dependency graph for imgsrv.c:

Go to the source code of this file.

Defines

#define D(x)
#define USEHTTP10(x)   x
#define JPEG_HEADER_SIZE   0x26f
#define TRAILER_SIZE   0x02
#define MAP_OPTIONS   MAP_FILE|MAP_PRIVATE

Functions

int sendImage (int bufferImageData, int fd_circ, int use_Exif)
void sendBuffer (void *buffer, int len)
void listener_loop (int port)
void errorMsgXML (char *msg)
int framePointersXML (int fd_circ)
int out1x1gif (void)
int main (int argc, char *argv[])

Variables

unsigned long * ccam_dma_buf
char trailer [TRAILER_SIZE] = {0xff,0xd9}
const char url_args []


Define Documentation

#define D ( x   ) 

*************************************************************************** ! FILE NAME : imgsrv.c ! DESCRIPTION: Simple and fast HTTP server to send camera still images ! Copyright (C) 2007 Elphel, Inc. ! -----------------------------------------------------------------------------** ! 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 3 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, see <http://www.gnu.org/licenses/>. ! -----------------------------------------------------------------------------** ! !

Log
imgsrv.c,v
! Revision 1.14 2008/04/22 22:14:56 elphel ! Added malloc failures handling, syslog logging of such events ! ! Revision 1.13 2008/04/16 20:30:33 elphel ! added optional fps reduction to multipart JPEGs ! ! Revision 1.11 2008/04/07 09:13:35 elphel ! Changes related to new Exif generation/processing ! ! Revision 1.10 2008/03/22 04:39:53 elphel ! remove complaints about "&_time=..." ! ! Revision 1.9 2007/12/03 08:28:45 elphel ! Multiple changes, mostly cleanup ! ! Revision 1.8 2007/11/16 08:56:19 elphel ! Added support for 2 additional commands to check circbuf usage ! ! Revision 1.7 2007/11/04 23:25:16 elphel ! removed extra (used during debug) munmap that caused segfault after sending "img" (so no /nxt/save) ! ! Revision 1.6 2007/11/04 05:47:40 elphel ! Cleaned up from debug code inserted to fight mmap/caching bug (fixed by now) ! ! Revision 1.5 2007/11/01 18:59:37 elphel ! debugging mmap/caching problems ! ! Revision 1.4 2007/10/30 16:56:06 elphel ! release 7.1.4.5 - working on "can not find 0xffff in frame parameters" bug. Temporary fix ! ! Revision 1.3 2007/10/27 00:55:32 elphel ! untested revision - need to go ! ! Revision 1.2 2007/10/11 06:42:28 elphel ! Fixed bug - /meta command should return trivial xml file, not 1x1 pixel gif ! ! Revision 1.1.1.1 2007/10/02 19:44:54 elphel ! This is a fresh tree based on elphel353-2.10 ! ! Revision 1.4 2007/10/02 19:44:54 elphel ! More functionality (buffer manipulation commands, clean interface, xml responces) ! ! Revision 1.3 2007/09/29 16:21:25 elphel ! removed IOCTL usage from /dev/circbuf, improved comments, other minor changes ! ! Revision 1.2 2007/09/25 23:35:16 elphel ! added Exif initialization, made it to work in background mode ! ! Revision 1.1 2007/09/23 06:49:10 elphel ! Simple web server designed for particular task - serving camera JPEG images. It is faster, than through any of the web servers tested. Only some of the functionality is implemented (no Exif yet, no synchronization with the camera) ! !

Definition at line 98 of file imgsrv.c.

#define JPEG_HEADER_SIZE   0x26f

Definition at line 105 of file imgsrv.c.

#define MAP_OPTIONS   MAP_FILE|MAP_PRIVATE

Definition at line 108 of file imgsrv.c.

#define TRAILER_SIZE   0x02

Definition at line 107 of file imgsrv.c.

#define USEHTTP10 ( x   )     x

Definition at line 102 of file imgsrv.c.


Function Documentation

void errorMsgXML ( char *  msg  ) 

Definition at line 243 of file imgsrv.c.

References D, s, and stderr.

Referenced by listener_loop().

int framePointersXML ( int  fd_circ  ) 

Definition at line 145 of file imgsrv.c.

References CAMSEQ_JPEG, CAMSEQ_OFF, CAMSEQ_RUN, CAMSEQ_SINGLE, CAMSEQ_STOP, CIRCLSEEK_FREE, CIRCLSEEK_PREV, CIRCLSEEK_TORP, CIRCLSEEK_TOWP, CIRCLSEEK_USED, D, fd_sens, imageParamsR, P_CAMSEQSTATE, P_CIRCBUFSIZE, P_FREECIRCBUF, rp, s, SensParsFileName, stderr, and wp.

Referenced by listener_loop().

void listener_loop ( int  port  ) 

Definition at line 449 of file imgsrv.c.

References buf, buff_size, ccam_dma_buf, CIRCLSEEK_FIRST, CIRCLSEEK_LAST, CIRCLSEEK_NEXT, CIRCLSEEK_PREV, CIRCLSEEK_READY, CIRCLSEEK_SCND, CIRCLSEEK_SETP, CIRCLSEEK_TORP, CIRCLSEEK_TOWP, CIRCLSEEK_VALID, CIRCLSEEK_WAIT, errorMsgXML(), exif_enable(), fd, fd_circ, framePointersXML(), memset(), out1x1gif(), sendImage(), stderr, stdin, stdout, and url_args.

Referenced by main().

int main ( int  argc,
char *  argv[] 
)

set port, start listening/answering HTTP requests

circbuf does not suppoty ioctl anymore

no more ioctl-s

now open circbuf

read pointer was invalid - try the earliest frame available

Definition at line 644 of file imgsrv.c.

References listener_loop(), url_args, and usage.

int out1x1gif ( void   ) 

******************************************************************************* ! FILE NAME : ccam.php ! DESCRIPTION: Programs major sensor parameters similar (not exactly) to ccam.cgi, ! returns xml OK ! Copyright (C) 2008 Elphel, Inc ! -----------------------------------------------------------------------------** ! ! 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 3 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, see <http://www.gnu.org/licenses/>. ! -----------------------------------------------------------------------------** !

Log
ccam.php,v
! Revision 1.8 2008/04/24 18:20:40 elphel ! added retrieval of circbuf structure ! ! Revision 1.4 2008/04/16 20:39:32 elphel ! removed actions that are unneeded with the current drivers, limited number of retries to stop compressor in "mode=set", added "mode=force" that unconditionally reprograms camera without an attempt to nicely stop the compressor ! ! Revision 1.3 2008/03/25 07:38:43 elphel ! just troubleshooting ! ! Revision 1.2 2008/03/22 04:43:03 elphel ! few minor changes ! ! Revision 1.1 2008/03/20 22:32:12 elphel ! sensor/compressor control, similar commands as ccam.cgi, but no images returned (use imgsrv - port 8081) ! !

we have zeros in the string

always good

Definition at line 230 of file imgsrv.c.

References header, s, and stdout.

Referenced by listener_loop().

void sendBuffer ( void *  buffer,
int  len 
)

repeat writes to stdout until all data is sent

Definition at line 431 of file imgsrv.c.

References D, stderr, and stdout.

Referenced by sendImage().

int sendImage ( int  bufferImageData,
int  fd_circ,
int  use_Exif 
)

read pointer in fd_circ should be at the start of the frame to be sent mmap will be opened in this function

int exifIndexPointer=0;

struct frame_exif_t frame_exif; //just 8 bytes

int metadata_start; //metadata pointer (in bytes, from the start of the ccam_dma_buf)

find total buffer length (it is in defines, actually in c313a.h

restore file poinetr after lseek-ing the end

now let's try mmap itself

exifIndexPointer=jpeg_start-8;

read Exif to buffer:

Maybe make buffer that will fit both Exif and JPEG? Get metadata, update Exif and JFIF headers if ep and ed poinetrs are non-zero (NULL will generate files with JFIF-only headers)

rebuild JFIF header from the metadata (width, height, quality) next line will trigger re-calculation of the JPEG header (if the w,h,q parameters have changed since it was built) now it uses global buffer in the driver - TODO: make it individual per opened file

+1 to avoid condition when jpeg_start==0. overloaded lseek will ignore 5 LSBs when SEEK_END

Now we always malloc buffer, before - only for bimg, using fixed-size header buffer - was it faster?

header+frame

only header

If we really want it, but don't get it - let's try more

insert Exif

copy first 2 bytes of the JFIF header before Exif

select meta page to use (matching frame)

Insert Exif itself

Buffer the whole file before sending over the network to make sure it will not be corrupted if the circular buffer will be overrun)

JPEG image data may be split in two segments (rolled over buffer end) - process both variants

single segment

fast connection, no need to buffer image, so we'll try to run it faster

JPEG image data may be split in two segments (rolled over buffer end) - process both variants

copy from the beginning of the frame to the end of the buffer

copy from the beginning of the buffer to the end of the frame

copy from the beginning of the frame to the end of the frame (no buffer rollovers)

Definition at line 264 of file imgsrv.c.

References buff_size, ccam_dma_buf, D, ExifFileName, fd_exif, frame_params_t::frame_length, frame_params, free(), HeadFileName, JPEG_HEADER_SIZE, malloc(), memcpy(), frame_params_t::meta_index, read, sendBuffer(), frame_params_t::signffff, stderr, and trailer.

Referenced by listener_loop().


Variable Documentation

unsigned long* ccam_dma_buf

Definition at line 110 of file imgsrv.c.

char trailer[TRAILER_SIZE] = {0xff,0xd9}

Definition at line 112 of file imgsrv.c.

const char url_args[]

Initial value:

"This server supports sequence of commands entered in the URL (separated by \"/\", case sensitive )\n" 
                      "executing them from left to right as they appear in the URL\n" 
                      "img -      send image at the current pointer (if it is first command - use last acquired image, if none availabe - send 1x1 gif)\n" 
                      "bimg -     same as above, but save the whole image in the memory before sending - useful to avoid overruns with slow connection \n" 
                      "mimg[n] -  send images as a multipart JPEG (all commands after will be ignored), possible to specify optional fps reduction\n" 
                      "           i.e. mimg4 - skip 3 frames for each frame output (1/4 fps) \n" 
                      "bmimg[n] - same as above, buffered\n" 
                      "pointers - send XML-formatted data about frames available in the camera circular buffer)\n\n" 
                      "Any of the 5 commands above can appear only once in the URL string, the second instance will be ignored. If none of the 5\n" 
                      "are present in the URL 1x1 pixel gif will be returned to the client after executing the URL command.\n\n" 
                      "torp -   set frame pointer to global read pointer, maintained by the camera driver. If frame at that pointer\n" 
                      "         is invalid, use scnd (see below)\n" 
                      "towp -   set frame pointer to hardware write pointer - position where next frame will be aquired\n" 
                      "prev -   move to previous frame in buffer, nop if there are none\n" 
                      "next -   move to the next frame in buffer (will stop at write pointer, see towp above)\n" 
                      "last -   move to the most recently acquired frame, or to write pointer if there are none.\n" 
                      "         this command is implied at the start of the url command sequence.\n" 
                      "first -  move to the oldest frame still available in the buffer. It is not safe to rely on it if\n" 
                      "         more frames are expected - data might be overwritten at any moment and the output will be corrupted.\n" 
                      "second - move to the second oldest frame in the buffer - somewhat safer than \"first\" - there will be time for\n" 
                      "         \"next\" command at least before frame data (and pointer structures) will be overwritten.\n" 
                      "save   - save current frame pointer as a global read pointer that holds it values between server requests.\n" 
                      "         This pointer is shared between all the clients and applications that use it.\n" 
                      "wait   - Wait until there will be a frame at current pointer ready\n"

Definition at line 114 of file imgsrv.c.

Referenced by listener_loop(), and main().


Generated on Thu Aug 7 16:20:01 2008 for elphel by  doxygen 1.5.1