#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 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/>. ! -----------------------------------------------------------------------------** ! !
void errorMsgXML | ( | char * | msg | ) |
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/>. ! -----------------------------------------------------------------------------** !
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 | |||
) |
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().
unsigned long* ccam_dma_buf |
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().