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 ELPHEL_DEBUG_THIS   0
#define D(x)
#define USEHTTP10(x)   x
#define JPEG_HEADER_MAXSIZE   0x300
#define TRAILER_SIZE   0x02
#define MAP_OPTIONS   MAP_FILE|MAP_PRIVATE
#define saferead255(f, d, l)   read(f,d,((l)<256)?(l):255)

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 metaXML (int fd_circ, int mode)
int printExifXML (int exif_page)
 mode: 0 - new (send headers), 1 - continue, 2 - finish
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   ) 

Definition at line 141 of file imgsrv.c.

#define ELPHEL_DEBUG_THIS   0

*************************************************************************** ! FILE NAME : imgsrv.c ! DESCRIPTION: Simple and fast HTTP server to send camera still images ! Copyright (C) 2007-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
imgsrv.c,v
! Revision 1.1.1.1 2008/11/27 20:04:01 elphel ! ! ! Revision 1.11 2008/11/03 18:42:21 elphel ! comment typo ! ! Revision 1.10 2008/10/29 04:18:28 elphel ! v.8.0.alpha10 made a separate structure for global parameters (not related to particular frames in a frame queue) ! ! Revision 1.9 2008/10/25 19:51:40 elphel ! updated copyright year ! ! Revision 1.8 2008/10/21 21:28:52 elphel ! support for xml meta output ! ! Revision 1.7 2008/10/13 16:55:53 elphel ! removed (some) obsolete P_* parameters, renamed CIRCLSEEK to LSEEK_CIRC constants (same as other similar) ! ! Revision 1.6 2008/10/11 18:46:07 elphel ! snapshot ! ! Revision 1.5 2008/10/06 08:31:08 elphel ! snapshot, first images ! ! Revision 1.4 2008/09/07 19:48:08 elphel ! snapshot ! ! Revision 1.3 2008/08/11 19:10:45 elphel ! reduced syntax "complaints" from KDevelop ! ! Revision 1.2 2008/05/16 06:06:54 elphel ! supporting variable JPEG header length ! ! 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 134 of file imgsrv.c.

#define JPEG_HEADER_MAXSIZE   0x300

Definition at line 149 of file imgsrv.c.

#define MAP_OPTIONS   MAP_FILE|MAP_PRIVATE

Definition at line 152 of file imgsrv.c.

#define saferead255 ( f,
d,
 )     read(f,d,((l)<256)?(l):255)

Definition at line 194 of file imgsrv.c.

#define TRAILER_SIZE   0x02

Definition at line 151 of file imgsrv.c.

#define USEHTTP10 ( x   )     x

Definition at line 145 of file imgsrv.c.


Function Documentation

void errorMsgXML ( char *  msg  ) 

Definition at line 636 of file imgsrv.c.

References D, s, and stderr.

Referenced by listener_loop().

int framePointersXML ( int  fd_circ  ) 

Definition at line 515 of file imgsrv.c.

References ctlFileName, D, fd_fparmsall, framepars_all_t::framePars, framePars, frameParsAll, G_CIRCBUFSIZE, G_FREECIRCBUF, GLOBALPARS, framepars_all_t::globalPars, globalPars, LSEEK_CIRC_FREE, LSEEK_CIRC_PREV, LSEEK_CIRC_TORP, LSEEK_CIRC_TOWP, LSEEK_CIRC_USED, P_COMPRESSOR_RUN, P_SENSOR_RUN, framepars_t::pars, PARS_FRAMES_MASK, rp, s, SEEK_CUR, SEEK_END, SEEK_SET, stderr, and wp.

Referenced by listener_loop().

void listener_loop ( int  port  ) 

Definition at line 811 of file imgsrv.c.

References buf, buff_size, ccam_dma_buf, errorMsgXML(), exif_enable(), fd, fd_circ, framePointersXML(), LSEEK_CIRC_FIRST, LSEEK_CIRC_LAST, LSEEK_CIRC_NEXT, LSEEK_CIRC_PREV, LSEEK_CIRC_READY, LSEEK_CIRC_SCND, LSEEK_CIRC_SETP, LSEEK_CIRC_TORP, LSEEK_CIRC_TOWP, LSEEK_CIRC_VALID, LSEEK_CIRC_WAIT, memset(), metaXML(), out1x1gif(), SEEK_END, SEEK_SET, sendImage(), stderr, stdin, stdout, and url_args.

Referenced by main().

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

set port, start listening/answering HTTP requests

now try to mmap

These are read from frame zero (they are not frame-related)

now open circbuf

read pointer was invalid - try the earliest frame available

Definition at line 1008 of file imgsrv.c.

References listener_loop(), url_args, and usage.

int metaXML ( int  fd_circ,
int  mode 
)

Definition at line 439 of file imgsrv.c.

References buff_size, interframe_params_t::byrshift, ccam_dma_buf, CCAM_MMAP_META, CCAM_MMAP_META_SEC, interframe_params_t::color, D, interframe_params_t::frame_length, interframe_params_t::hash32_b, interframe_params_t::hash32_g, interframe_params_t::hash32_gb, interframe_params_t::hash32_r, interframe_params_t::height, memcpy(), interframe_params_t::meta_index, printExifXML(), interframe_params_t::quality2, SEEK_CUR, SEEK_END, SEEK_SET, interframe_params_t::signffff, stderr, interframe_params_t::timestamp_sec, and interframe_params_t::width.

Referenced by listener_loop().

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.1.1.1 2008/11/27 20:04:03 elphel ! ! ! Revision 1.4 2008/11/04 00:16:50 elphel ! started porting ! ! Revision 1.3 2008/11/02 07:26:41 elphel ! started porting ccam.php/camvc2 ! ! Revision 1.2 2008/09/28 00:31:42 elphel ! Some histogram related constants renamed from *AUTOEXP*, *AEXPWND* to *HISTWND* ! ! 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 623 of file imgsrv.c.

References header, s, and stdout.

Referenced by listener_loop().

int printExifXML ( int  exif_page  ) 

mode: 0 - new (send headers), 1 - continue, 2 - finish

store locations of the fields needed for KML generations in the Exif block

Create Exif directory Read the size of the Exif data

Error opening Exif directory

Create XML files iteslf

select specified Exif page

Error opening Exif

Image Description

Exif_Image_FrameNumber_Index 0x13

DateTimeOriginal (with subseconds)

Exif_Photo_ExposureTime

GPS measure mode

GPS date/time

GPS likes ".999", let's inc by one - anyway will round that out

knowing format provided from GPS - degrees and minutes only, no seconds: GPS Longitude

GPS Latitude

GPS Altitude

Compass Direction (magnetic)

Processing 'hacked' pitch and roll (made of Exif destination latitude/longitude) Compass Roll

Compass Pitch

Definition at line 195 of file imgsrv.c.

References exif_dir, Exif_GPSInfo_CompassDirection, Exif_GPSInfo_CompassDirection_Index, Exif_GPSInfo_CompassDirectionRef, Exif_GPSInfo_CompassDirectionRef_Index, Exif_GPSInfo_CompassPitch, Exif_GPSInfo_CompassPitch_Index, Exif_GPSInfo_CompassPitchRef, Exif_GPSInfo_CompassPitchRef_Index, Exif_GPSInfo_CompassRoll, Exif_GPSInfo_CompassRoll_Index, Exif_GPSInfo_CompassRollRef, Exif_GPSInfo_CompassRollRef_Index, Exif_GPSInfo_GPSAltitude, Exif_GPSInfo_GPSAltitude_Index, Exif_GPSInfo_GPSAltitudeRef, Exif_GPSInfo_GPSAltitudeRef_Index, Exif_GPSInfo_GPSDateStamp, Exif_GPSInfo_GPSDateStamp_Index, Exif_GPSInfo_GPSLatitude, Exif_GPSInfo_GPSLatitude_Index, Exif_GPSInfo_GPSLatitudeRef, Exif_GPSInfo_GPSLatitudeRef_Index, Exif_GPSInfo_GPSLongitude, Exif_GPSInfo_GPSLongitude_Index, Exif_GPSInfo_GPSLongitudeRef, Exif_GPSInfo_GPSLongitudeRef_Index, Exif_GPSInfo_GPSMeasureMode, Exif_GPSInfo_GPSMeasureMode_Index, Exif_GPSInfo_GPSTimeStamp, Exif_GPSInfo_GPSTimeStamp_Index, Exif_Image_FrameNumber, Exif_Image_FrameNumber_Index, Exif_Image_ImageDescription, Exif_Image_ImageDescription_Index, Exif_Photo_DateTimeOriginal, Exif_Photo_DateTimeOriginal_Index, Exif_Photo_ExposureTime, Exif_Photo_ExposureTime_Index, Exif_Photo_SubSecTimeOriginal, Exif_Photo_SubSecTimeOriginal_Index, EXIFDIR_DEV_NAME, ExifKmlNumber, fd_exifdir, exif_dir_table_t::ltag, memcpy(), and read.

Referenced by metaXML().

void sendBuffer ( void *  buffer,
int  len 
)

repeat writes to stdout until all data is sent

Definition at line 793 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)

create JPEG header, find out it's size TODO:

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) 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 657 of file imgsrv.c.

References buff_size, ccam_dma_buf, D, ExifFileName, exit, fd_exif, interframe_params_t::frame_length, free(), HeadFileName, JPEG_HEADER_MAXSIZE, malloc(), memcpy(), interframe_params_t::meta_index, read, SEEK_CUR, SEEK_END, SEEK_SET, sendBuffer(), interframe_params_t::signffff, stderr, and trailer.

Referenced by listener_loop().


Variable Documentation

unsigned long* ccam_dma_buf

Definition at line 154 of file imgsrv.c.

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

Definition at line 156 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 159 of file imgsrv.c.

Referenced by listener_loop(), and main().


Generated on Fri Nov 28 00:07:31 2008 for elphel by  doxygen 1.5.1