00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00032 #include <unistd.h>
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <signal.h>
00036 #include <fcntl.h>
00037 #include <sys/uio.h>
00038 #include <errno.h>
00039 #include <sys/types.h>
00040 #include <sys/socket.h>
00041 #include <sys/stat.h>
00042
00043
00044 #include <time.h>
00045 #include <string.h>
00046
00047 #include <netinet/in.h>
00048 #include <sys/mman.h>
00049 #include <sys/ioctl.h>
00050
00051 #include <asm/elphel/c313a.h>
00052 #include <asm/elphel/ext353.h>
00053 #include <asm/byteorder.h>
00054
00055
00056 #include <ogg/ogg.h>
00057 #include "ogmstreams.h"
00058
00059 #include "camogm_jpeg.h"
00060 #include "camogm.h"
00062 int camogm_init_jpeg(void) {
00063 return 0;
00064 }
00065 void camogm_free_jpeg(void) {
00066 }
00067
00068 int camogm_start_jpeg(void) {
00070 char * slash;
00071 int rslt;
00072 strcpy (state->path,state->path_prefix);
00073 slash=strrchr(state->path,'/');
00074 D2(fprintf (debug_file, "camogm_start_jpeg\n"));
00075 if (slash) {
00076 D3(fprintf (debug_file, "Full path %s\n", state->path));
00077 slash[0]='\0';
00078 D3(fprintf (debug_file, "directory path %s\n", state->path));
00079 rslt=mkdir(state->path, 0777);
00080 D3(fprintf (debug_file, "mkdir (%s, 0777) returned %d, errno=%d\n", state->path, rslt, errno));
00081 if ((rslt<0) && (errno != EEXIST)) {
00082 D0(fprintf (debug_file, "Error creating directory %s, errno=%d\n", state->path, errno));
00083 return -CAMOGM_FRAME_FILE_ERR;
00084 }
00085 }
00086 return 0;
00087 }
00088 int camogm_frame_jpeg(void){
00089 int i,j;
00090
00091 ssize_t iovlen,l;
00092 struct iovec chunks_iovec[7];
00093 l=0;
00094 for (i=0; i< (state->chunk_index)-1; i++) {
00095 chunks_iovec[i].iov_base=state->packetchunks[i+1].chunk;
00096 chunks_iovec[i].iov_len= state->packetchunks[i+1].bytes;
00097 l+=chunks_iovec[i].iov_len;
00098 }
00099
00100 sprintf(state->path,"%s%010ld_%06ld.jpeg",state->path_prefix,state->this_frame_params.timestamp_sec,state->this_frame_params.timestamp_usec);
00101
00102
00103
00104 if (((state->ivf=open(state->path,O_RDWR | O_CREAT, 0777)))<0){
00105 D0(fprintf (debug_file, "Error opening %s for writing, returned %d, errno=%d\n", state->path,state->ivf,errno));
00106 return -CAMOGM_FRAME_FILE_ERR;
00107 }
00108
00109 iovlen=writev(state->ivf,chunks_iovec, (state->chunk_index)-1);
00110 if (iovlen < l) {
00111 j=errno;
00112 D0(fprintf(debug_file,"writev error %d (returned %d, expected %d)\n",j,iovlen,l));
00113 close (state->ivf);
00114 return -CAMOGM_FRAME_FILE_ERR;
00115 }
00116 close (state->ivf);
00117 return 0;
00118 }
00119
00120 int camogm_end_jpeg(void){
00121 return 0;
00122 }