apps/camogm2/camogm_jpeg.c

Go to the documentation of this file.
00001 /*!***************************************************************************
00002 *! FILE NAME  : camogm_jpeg.c
00003 *! DESCRIPTION: Provides writing to series of individual JPEG files for camogm
00004 *! Copyright (C) 2007 Elphel, Inc.
00005 *! -----------------------------------------------------------------------------**
00006 *!  This program is free software: you can redistribute it and/or modify
00007 *!  it under the terms of the GNU General Public License as published by
00008 *!  the Free Software Foundation, either version 3 of the License, or
00009 *!  (at your option) any later version.
00010 *!
00011 *!  This program is distributed in the hope that it will be useful,
00012 *!  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *!  GNU General Public License for more details.
00015 *!
00016 *!  You should have received a copy of the GNU General Public License
00017 *!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 *! -----------------------------------------------------------------------------**
00019 *!
00020 *!  $Log: camogm_jpeg.c,v $
00021 *!  Revision 1.1.1.1  2008/11/27 20:04:02  elphel
00022 *!
00023 *!
00024 *!  Revision 1.1  2008/05/02 12:45:57  spectr_rain
00025 *!  initial revision with the sound support
00026 *!
00027 *!  Revision 1.3  2008/04/11 23:09:33  elphel
00028 *!  modified to handle kml generation
00029 *!
00030 *!  Revision 1.2  2007/11/19 03:23:21  elphel
00031 *!  7.1.5.5 Added support for *.mov files in camogm.
00032 *!
00033 *!  Revision 1.1  2007/11/16 08:49:57  elphel
00034 *!  Initial release of camogm - program to record video/image to the camera hard drive (or other storage)
00035 *!
00036 */
00038 #include <unistd.h>
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <signal.h>
00042 #include <fcntl.h>
00043 #include <sys/uio.h>
00044 #include <errno.h>
00045 #include <sys/types.h>
00046 #include <sys/socket.h>
00047 #include <sys/stat.h>
00048 //#include <ctype.h>
00049 //#include <getopt.h>
00050 #include <time.h>
00051 #include <string.h>
00052 
00053 #include <netinet/in.h> /*little <-> big endian ?*/
00054 #include <sys/mman.h>           /* mmap */
00055 #include <sys/ioctl.h>
00056 
00057 #include <asm/elphel/c313a.h>
00058 #include <asm/elphel/ext353.h>
00059 #include <asm/byteorder.h>
00060 
00061 
00062 #include <ogg/ogg.h> // has to be before ogmstreams.h
00063 #include "ogmstreams.h" // move it to <>?
00064 
00065 #include "camogm_jpeg.h"
00066 #include "camogm.h"
00068 int camogm_init_jpeg(void) {
00069   return 0;
00070 }
00071 void camogm_free_jpeg(void) {
00072 }
00073 
00074 int camogm_start_jpeg(void) {
00076   char * slash;
00077   int    rslt;
00078   strcpy (state->path,state->path_prefix); 
00079   slash=strrchr(state->path,'/');
00080 D2(fprintf (debug_file, "camogm_start_jpeg\n"));
00081   if (slash) {
00082     D3(fprintf (debug_file, "Full path %s\n", state->path));
00083     slash[0]='\0'; 
00084     D3(fprintf (debug_file, "directory path %s\n", state->path));
00085     rslt=mkdir(state->path, 0777);
00086     D3(fprintf (debug_file, "mkdir (%s, 0777) returned %d, errno=%d\n", state->path, rslt, errno));
00087     if ((rslt<0) && (errno != EEXIST)) { // already exists is OK
00088        D0(fprintf (debug_file, "Error creating directory %s, errno=%d\n", state->path, errno));
00089        return -CAMOGM_FRAME_FILE_ERR;
00090     }
00091   }
00092   return 0;
00093 }
00094 int camogm_frame_jpeg(void){
00095    int i,j;
00096 //   int fd;
00097    ssize_t iovlen,l;
00098    struct iovec chunks_iovec[7];
00099    l=0;
00100    for (i=0; i< (state->chunk_index)-1; i++) {
00101       chunks_iovec[i].iov_base=state->packetchunks[i+1].chunk;
00102       chunks_iovec[i].iov_len= state->packetchunks[i+1].bytes;
00103       l+=chunks_iovec[i].iov_len;
00104    }
00105 
00106    sprintf(state->path,"%s%010ld_%06ld.jpeg",state->path_prefix,state->this_frame_params.timestamp_sec,state->this_frame_params.timestamp_usec);
00107 // if ((devfd = open("/dev/fpgaio", O_RDWR))<0)  {printf("error opening /dev/fpgaio\r\n"); return -1;}
00108 //_1__12_Error opening /tmp/z/video1195147018_273452.jpeg for writing
00109 
00110    if (((state->ivf=open(state->path,O_RDWR | O_CREAT, 0777)))<0){
00111      D0(fprintf (debug_file, "Error opening %s for writing, returned %d, errno=%d\n", state->path,state->ivf,errno));
00112      return -CAMOGM_FRAME_FILE_ERR;
00113    }
00114 
00115    iovlen=writev(state->ivf,chunks_iovec, (state->chunk_index)-1);
00116    if (iovlen < l) {
00117           j=errno;
00118           D0(fprintf(debug_file,"writev error %d (returned %d, expected %d)\n",j,iovlen,l));
00119           close (state->ivf);
00120           return -CAMOGM_FRAME_FILE_ERR;
00121    }
00122    close (state->ivf);
00123    return 0;
00124 }
00125 
00126 int camogm_end_jpeg(void){
00127   return 0;
00128 }

Generated on Fri Nov 28 00:06:21 2008 for elphel by  doxygen 1.5.1