#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 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/>. ! -----------------------------------------------------------------------------** ! !
void errorMsgXML | ( | char * | msg | ) |
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().
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/>. ! -----------------------------------------------------------------------------** !
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 | |||
) |
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().
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 114 of file imgsrv.c.
Referenced by listener_loop(), and main().