apps/camogm2/camogm.c File Reference

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/uio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>
#include <netinet/in.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <asm/elphel/c313a.h>
#include <asm/elphel/ext353.h>
#include <asm/byteorder.h>
#include <ogg/ogg.h>
#include "ogmstreams.h"
#include "camogm_ogm.h"
#include "camogm_jpeg.h"
#include "camogm_mov.h"
#include "camogm_kml.h"
#include "camogm.h"
#include "camogm_wav.h"
#include <alsa/asoundlib.h>

Include dependency graph for camogm.c:

Go to the source code of this file.

Defines

#define TRAILER_SIZE   0x02
#define MAP_OPTIONS   MAP_FILE|MAP_PRIVATE
#define DEFAULT_DURATION   60
#define DEFAULT_LENGTH   100000000
#define DEFAULT_FRAMES   16384
 Next 2 for Quicktime (mostly).
#define DEFAULT_FRAMES_PER_CHUNK   10
#define DEFAULT_LENGTH   100000000
#define DEFAULT_EXIF   1
#define DEFAULT_AUDIO_RATE   44100
#define DEFAULT_AUDIO_CHANNELS   2
#define AUDIO_RATE_MAX   44100
#define AUDIO_RATE_MIN   11025
#define AUDIO_CHANNELS_MAX   2
#define AUDIO_CHANNELS_MIN   1
#define COMMAND_LOOP_DELAY   500000
#define SBUFFER_PREFIX   16

Functions

int camogm_init (void)
int camogm_start (int by_command)
int camogm_stop (int by_command)
int camogm_reset (void)
int camogm_debug (const char *fname)
 reset circbuf read pointer
int camogm_debug_level (int d)
void camogm_set_segment_duration (int sd)
void camogm_set_segment_length (int sl)
void camogm_set_save_gp (int d)
void camogm_set_prefix (const char *p)
void camogm_set_exif (int d)
void camogm_set_timescale (double d)
void camogm_set_frames_skip (int d)
 set timescale, default=1.0
void camogm_set_format (int d)
 set number of frames to skip, if negative - seconds between frames
void camogm_kml_set_enable (int d)
 kml stuff
void camogm_kml_set_horHalfFov (double dd)
void camogm_kml_set_vertHalfFov (double dd)
void camogm_kml_set_height_mode (int d)
void camogm_kml_set_height (double dd)
void camogm_kml_set_period (int d)
void camogm_kml_set_near (double dd)
int parse_cmd (FILE *npipe)
char * getLineFromPipe (FILE *npipe)
 will read from pipe, return pointer to null terminated string if available, NULL otherwise
int sendImageFrame (void)
void camogm_set_max_frames (int d)
 needed for Quicktime - maybe something else?
void camogm_set_frames_per_chunk (int d)
void camogm_set_audio_state (char *args)
void camogm_set_audio_format (char *args)
void camogm_set_sync_state (char *args)
void audio_process (void)
void audio_init (int by_command)
void audio_start (int by_command)
void audio_end (int by_command)
void audio_free (void)
void put_uint16 (void *buf, u_int16_t val)
 ======================================================================================================
void put_uint32 (void *buf, u_int32_t val)
void put_uint64 (void *buf, u_int64_t val)
void camogm_free ()
void camogm_status (char *fn, int xml)
int main (int argc, char *argv[])
void audio_init (by_command)

Variables

char trailer [TRAILER_SIZE] = {0xff,0xd9}
const char ExifFileName [] = "/dev/exif_exif"
const char HeadFileName [] = "/dev/jpeghead"
const char SensParsFileName [] = "/dev/sensorpars"
unsigned long * ccam_dma_buf
unsigned long * imageParamsR
int buff_size
static char cmdbuf [1024]
static int cmdbufp = 0
static int cmdstrt = 0
camogm_state sstate
camogm_statestate
int debug_level
FILE * debug_file
int audio_set = 0
int audio_present = 0
snd_pcm_t * capture_handle = NULL
char * sbuffer = NULL
long sbuffer_len = 0
long sample_time = 100


Define Documentation

#define AUDIO_CHANNELS_MAX   2

Definition at line 135 of file camogm.c.

Referenced by camogm_set_audio_format().

#define AUDIO_CHANNELS_MIN   1

Definition at line 136 of file camogm.c.

Referenced by camogm_set_audio_format().

#define AUDIO_RATE_MAX   44100

Definition at line 133 of file camogm.c.

Referenced by camogm_set_audio_format().

#define AUDIO_RATE_MIN   11025

Definition at line 134 of file camogm.c.

Referenced by camogm_set_audio_format().

#define COMMAND_LOOP_DELAY   500000

#define DEFAULT_AUDIO_CHANNELS   2

Definition at line 131 of file camogm.c.

#define DEFAULT_AUDIO_RATE   44100

Definition at line 130 of file camogm.c.

#define DEFAULT_DURATION   60

Definition at line 121 of file camogm.c.

#define DEFAULT_EXIF   1

Definition at line 128 of file camogm.c.

#define DEFAULT_FRAMES   16384

Next 2 for Quicktime (mostly).

Definition at line 124 of file camogm.c.

#define DEFAULT_FRAMES_PER_CHUNK   10

Definition at line 125 of file camogm.c.

#define DEFAULT_LENGTH   100000000

Definition at line 127 of file camogm.c.

#define DEFAULT_LENGTH   100000000

Definition at line 127 of file camogm.c.

#define MAP_OPTIONS   MAP_FILE|MAP_PRIVATE

Definition at line 109 of file camogm.c.

#define SBUFFER_PREFIX   16

Definition at line 1414 of file camogm.c.

Referenced by audio_init(), and audio_process().

#define TRAILER_SIZE   0x02

*************************************************************************** ! FILE NAME : camogm.c ! DESCRIPTION: Program to write captured video (and audio) to camera file system ! using Ogg container. ! Original implementation will copy package data to a buffer to use library calls? ! 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/>. ! -----------------------------------------------------------------------------** ! !

Log
camogm.c,v
! Revision 1.1.1.1 2008/11/27 20:04:02 elphel ! ! ! Revision 1.5 2008/11/20 23:21:32 elphel ! Put FIXME notes and removed parameters that are not used anymore ! ! Revision 1.4 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.3 2008/10/13 16:55:53 elphel ! removed (some) obsolete P_* parameters, renamed CIRCLSEEK to LSEEK_CIRC constants (same as other similar) ! ! Revision 1.2 2008/09/07 19:48:07 elphel ! snapshot ! ! Revision 1.1 2008/05/02 12:45:57 spectr_rain ! initial revision with the sound support ! ! Revision 1.9 2008/04/13 21:05:19 elphel ! Fixing KML generation ! ! Revision 1.8 2008/04/11 23:09:33 elphel ! modified to handle kml generation ! ! Revision 1.7 2008/04/07 09:13:34 elphel ! Changes related to new Exif generation/processing ! ! Revision 1.6 2008/01/14 22:59:00 elphel ! 7.1.7.4 - added timelapse mode to camogm ! ! Revision 1.5 2007/12/03 08:28:45 elphel ! Multiple changes, mostly cleanup ! ! Revision 1.4 2007/11/29 00:38:57 elphel ! fixed timescale bug ! ! Revision 1.3 2007/11/19 05:07:19 elphel ! fixed 2 typos ! ! Revision 1.2 2007/11/19 03:23:21 elphel ! 7.1.5.5 Added support for *.mov files in camogm. ! ! Revision 1.1 2007/11/16 08:49:56 elphel ! Initial release of camogm - program to record video/image to the camera hard drive (or other storage) !

Definition at line 108 of file camogm.c.


Function Documentation

void audio_end ( int  by_command  ) 

Definition at line 1554 of file camogm.c.

References CAMOGM_FORMAT_OGM, camogm_state::format, free(), state, stderr, and wave_end().

Referenced by camogm_stop().

void audio_free ( void   ) 

Definition at line 1577 of file camogm.c.

References stderr.

void audio_init ( by_command   ) 

Definition at line 1461 of file camogm.c.

References camogm_state::audio_channels, camogm_state::audio_enable, camogm_state::audio_format, camogm_state::audio_rate, malloc(), mask, SBUFFER_PREFIX, state, stderr, and t.

void audio_init ( int  by_command  ) 

Referenced by camogm_start().

void audio_process ( void   ) 

Definition at line 1423 of file camogm.c.

References camogm_state::audio_channels, camogm_audio_ogm_push(), CAMOGM_FORMAT_OGM, camogm_state::format, SBUFFER_PREFIX, state, stderr, and wave_push().

Referenced by main().

void audio_start ( int  by_command  ) 

Definition at line 1538 of file camogm.c.

References CAMOGM_FORMAT_OGM, camogm_state::format, camogm_state::path_prefix, state, stderr, and wave_begin().

Referenced by camogm_start().

int camogm_debug ( const char *  fname  ) 

reset circbuf read pointer

int camogm_debug_level ( int  d  ) 

void camogm_free (  ) 

Definition at line 699 of file camogm.c.

References CAMOGM_FORMAT_JPEG, CAMOGM_FORMAT_MOV, CAMOGM_FORMAT_NONE, CAMOGM_FORMAT_OGM, camogm_free_jpeg(), camogm_free_mov(), camogm_free_ogm(), f, camogm_state::format, camogm_state::formats, and state.

int camogm_init ( void   ) 

void camogm_kml_set_enable ( int  d  ) 

kml stuff

void camogm_kml_set_height ( double  dd  ) 

void camogm_kml_set_height_mode ( int  d  ) 

void camogm_kml_set_horHalfFov ( double  dd  ) 

void camogm_kml_set_near ( double  dd  ) 

void camogm_kml_set_period ( int  d  ) 

void camogm_kml_set_vertHalfFov ( double  dd  ) 

int camogm_reset ( void   ) 

void camogm_set_audio_format ( char *  args  ) 

Definition at line 1381 of file camogm.c.

References camogm_state::audio_channels, AUDIO_CHANNELS_MAX, AUDIO_CHANNELS_MIN, camogm_state::audio_rate, AUDIO_RATE_MAX, AUDIO_RATE_MIN, buf, state, and stderr.

void camogm_set_audio_state ( char *  args  ) 

Definition at line 1362 of file camogm.c.

References camogm_state::audio_enable, state, and stderr.

void camogm_set_exif ( int  d  ) 

void camogm_set_format ( int  d  ) 

set number of frames to skip, if negative - seconds between frames

void camogm_set_frames_per_chunk ( int  d  ) 

void camogm_set_frames_skip ( int  d  ) 

set timescale, default=1.0

void camogm_set_max_frames ( int  d  ) 

needed for Quicktime - maybe something else?

void camogm_set_prefix ( const char *  p  ) 

void camogm_set_save_gp ( int  d  ) 

void camogm_set_segment_duration ( int  sd  ) 

void camogm_set_segment_length ( int  sl  ) 

void camogm_set_sync_state ( char *  args  ) 

Definition at line 1372 of file camogm.c.

References camogm_state::allow_sync, and state.

void camogm_set_timescale ( double  d  ) 

int camogm_start ( int  by_command  ) 

Definition at line 327 of file camogm.c.

References audio_init(), audio_start(), camogm_state::buf_min, camogm_state::buf_overruns, CAMOGM_FORMAT_JPEG, CAMOGM_FORMAT_MOV, CAMOGM_FORMAT_NONE, CAMOGM_FORMAT_OGM, CAMOGM_FRAME_BROKEN, CAMOGM_FRAME_CHANGED, CAMOGM_FRAME_NOT_READY, camogm_init_jpeg(), camogm_init_kml(), camogm_init_mov(), camogm_init_ogm(), camogm_start_jpeg(), camogm_start_kml(), camogm_start_mov(), camogm_start_ogm(), ccam_dma_buf, CCAM_MMAP_META, CCAM_MMAP_META_SEC, camogm_state::cirbuf_rp, camogm_state::circ_buff_size, D0, D1, D3, debug_file, camogm_state::fd_circ, camogm_state::fd_head, camogm_state::format, camogm_state::formats, fp, interframe_params_t::frame_length, camogm_state::frame_params, camogm_state::frame_period, camogm_state::frameno, camogm_state::frames_per_chunk, camogm_state::frames_skip, camogm_state::frames_skip_left, G_FREECIRCBUF, camogm_state::head_size, camogm_state::height, interframe_params_t::height, imageParamsR, camogm_state::jpeg_len, camogm_state::jpegHeader, camogm_state::kml_enable, LSEEK_CIRC_LAST, LSEEK_CIRC_NEXT, LSEEK_CIRC_PREV, LSEEK_CIRC_READY, LSEEK_CIRC_VALID, camogm_state::max_frames, memcpy(), camogm_state::metadata_start, read, camogm_state::running, SEEK_END, SEEK_SET, camogm_state::set_format, camogm_state::set_frames_skip, camogm_state::set_max_frames, camogm_state::set_timescale, interframe_params_t::signffff, camogm_state::starting, state, camogm_state::this_frame_params, camogm_state::time_unit, timescale, camogm_state::timescale, interframe_params_t::timestamp_sec, interframe_params_t::timestamp_usec, camogm_state::width, and interframe_params_t::width.

void camogm_status ( char *  fn,
int  xml 
)

Definition at line 811 of file camogm.c.

References camogm_state::buf_min, camogm_state::buf_overruns, CAMOGM_FORMAT_JPEG, CAMOGM_FORMAT_MOV, CAMOGM_FORMAT_OGM, CAMSEQ_JPEG, CAMSEQ_OFF, CAMSEQ_RUN, CAMSEQ_SINGLE, CAMSEQ_STOP, camogm_state::cirbuf_rp, D0, debug_level, camogm_state::debug_name, camogm_state::exif, f, camogm_state::format, camogm_state::frame_params, camogm_state::frame_period, camogm_state::frameno, camogm_state::frames_per_chunk, camogm_state::frames_skip, camogm_state::frames_skip_left, G_CIRCBUFSIZE, G_FREECIRCBUF, camogm_state::height, imageParamsR, camogm_state::ivf, camogm_state::kml_enable, camogm_state::kml_height, camogm_state::kml_height_mode, camogm_state::kml_horHalfFov, camogm_state::kml_last_ts, camogm_state::kml_last_uts, camogm_state::kml_near, camogm_state::kml_path, camogm_state::kml_period, camogm_state::kml_used, camogm_state::kml_vertHalfFov, camogm_state::max_frames, camogm_state::path, camogm_state::path_prefix, camogm_state::running, camogm_state::save_gp, SEEK_CUR, camogm_state::segment_duration, camogm_state::segment_length, camogm_state::starting, state, stderr, stdout, camogm_state::this_frame_params, camogm_state::timescale, interframe_params_t::timestamp_sec, interframe_params_t::timestamp_usec, camogm_state::vf, and camogm_state::width.

int camogm_stop ( int  by_command  ) 

Definition at line 667 of file camogm.c.

References audio_end(), camogm_end_jpeg(), camogm_end_kml(), camogm_end_mov(), camogm_end_ogm(), CAMOGM_FORMAT_JPEG, CAMOGM_FORMAT_MOV, CAMOGM_FORMAT_NONE, CAMOGM_FORMAT_OGM, D1, D2, camogm_state::format, camogm_state::kml_used, camogm_state::last, camogm_state::running, camogm_state::starting, state, and camogm_state::vf.

char* getLineFromPipe ( FILE *  npipe  ) 

will read from pipe, return pointer to null terminated string if available, NULL otherwise

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

*************************************************************************** ! FILE NAME : autoexposure.c ! DESCRIPTION: Daemon to adjust camera exposure and white balance ! 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
autoexposure.c,v
! Revision 1.1.1.1 2008/11/27 20:04:01 elphel ! ! ! Revision 1.16 2008/11/18 19:30:16 elphel ! Added initialization of the "next" frame - otherwise it wait _very_ long if the camera frame number is reset ! ! Revision 1.15 2008/11/15 23:08:24 elphel ! 8.0.alpha17 - split autoexposure source file ! ! Revision 1.14 2008/11/15 07:05:38 elphel ! implemented analog gain control (in addition to gammas) while while balancing ! ! Revision 1.13 2008/11/15 03:10:13 elphel ! Some parameters renamed, reassigned. ! ! Revision 1.12 2008/11/14 07:13:32 elphel ! Added gammaReverse() and gammaDirect() functions, TODO lists, bug fixes ! ! Revision 1.11 2008/11/14 01:01:59 elphel ! cleared debug output ! ! Revision 1.10 2008/11/13 05:40:45 elphel ! 8.0.alpha16 - modified histogram storage, profiling ! ! Revision 1.9 2008/11/08 05:52:21 elphel ! debug feature ! ! Revision 1.8 2008/11/04 17:40:34 elphel ! comment typos ! ! Revision 1.7 2008/11/02 00:32:35 elphel ! added TODO ! ! Revision 1.6 2008/10/31 18:26:32 elphel ! Adding support for constants like SENSOR_REGS32 (defined constant plus 32 to simplify referencing sensor registers from PHP ! ! Revision 1.5 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.4 2008/10/28 07:05:12 elphel ! implemented white balance, HDR mode (1/1 and 2/2) ! ! Revision 1.3 2008/10/26 05:55:38 elphel ! snapshot ! ! Revision 1.2 2008/10/25 19:49:15 elphel ! 8.0.alpha8 - added autoexposure to the installation ! ! Revision 1.1 2008/10/24 00:34:12 elphel ! initial release !

no command line options processing yet

open Exif header file

open JPEG header file

open circbuf and mmap it (once at startup)

find total buffer length (it is in defines, actually in c313a.h

Now open/mmap file to read sensor/compressor parameters (currently - just free memory in circbuf and compressor state)

open circbuf and mmap it (once at startup)

find total buffer length

create a named pipe always delete the pipe if it existed, start a fresh one

now should not exist

now open the pipe - will block until something will be written (or just open for writing Reads themselves will not block

Here is a main loop. If recording is on, it will check for commands after each frame, if it is off - poll with fixed usleep

look at command queue first

frame sent OK, nothing to do (TODO: check file length/duration)

just wait for the frame to appear at the current pointer

we'll wait for a frame, not to waste resources. But if the compressor is stopped this program will not respond to any commands TODO - add another wait with (short) timeout?

frame parameters have changed

next file needed (need to switch to a new file (time/size exceeded limit)

invalid frame pointer

frame broken (buffer overrun)

restart the file

error with file I/O

other errors

no commands in queue,starting (but not started yet)

retry starting

file started OK, nothing to do

just wait for the frame to appear at the current pointer

we'll wait for a frame, not to waste resources. But if the compressor is stopped this program will not respond to any commands TODO - add another wait with (short) timeout?

frame parameters have changed

invalid frame pointer

frame broken (buffer overrun)

it should be not too long so empty buffer will not be overrun

error with file I/O

other errors

not running, not starting

make it longer but interruptible by signals?

Definition at line 1155 of file camogm.c.

References audio_process(), CAMOGM_FRAME_BROKEN, CAMOGM_FRAME_CHANGED, CAMOGM_FRAME_FILE_ERR, CAMOGM_FRAME_INVALID, CAMOGM_FRAME_NEXTFILE, CAMOGM_FRAME_NOT_READY, CAMOGM_FRAME_OTHER, camogm_init(), camogm_start(), camogm_stop(), ccam_dma_buf, camogm_state::circ_buff_size, COMMAND_LOOP_DELAY, D0, D1, ExifFileName, exit, camogm_state::fd_circ, camogm_state::fd_exif, camogm_state::fd_head, camogm_state::fd_sens, camogm_state::head_size, HeadFileName, imageParamsR, JPEG_HEADER_SIZE, LSEEK_CIRC_WAIT, parse_cmd(), camogm_state::running, SEEK_END, sendImageFrame(), camogm_state::senspars_size, SensParsFileName, sstate, camogm_state::starting, state, and usage.

int parse_cmd ( FILE *  npipe  ) 

void put_uint16 ( void *  buf,
u_int16_t  val 
)

======================================================================================================

Definition at line 193 of file camogm.c.

void put_uint32 ( void *  buf,
u_int32_t  val 
)

Definition at line 203 of file camogm.c.

void put_uint64 ( void *  buf,
u_int64_t  val 
)

Definition at line 215 of file camogm.c.

int sendImageFrame ( void   ) 


Variable Documentation

int audio_present = 0

Definition at line 1416 of file camogm.c.

int audio_set = 0

Definition at line 1415 of file camogm.c.

int buff_size

Definition at line 119 of file camogm.c.

snd_pcm_t* capture_handle = NULL

Definition at line 1417 of file camogm.c.

unsigned long* ccam_dma_buf

Definition at line 117 of file camogm.c.

char cmdbuf[1024] [static]

Definition at line 138 of file camogm.c.

int cmdbufp = 0 [static]

Definition at line 139 of file camogm.c.

int cmdstrt = 0 [static]

Definition at line 140 of file camogm.c.

FILE* debug_file

Definition at line 146 of file camogm.c.

int debug_level

Definition at line 145 of file camogm.c.

const char ExifFileName[] = "/dev/exif_exif"

Definition at line 113 of file camogm.c.

const char HeadFileName[] = "/dev/jpeghead"

Definition at line 115 of file camogm.c.

unsigned long* imageParamsR

Definition at line 118 of file camogm.c.

Referenced by camogm_start(), camogm_status(), and main().

long sample_time = 100

Definition at line 1420 of file camogm.c.

Referenced by Audio::Audio().

char* sbuffer = NULL

Definition at line 1418 of file camogm.c.

long sbuffer_len = 0

Definition at line 1419 of file camogm.c.

const char SensParsFileName[] = "/dev/sensorpars"

Definition at line 116 of file camogm.c.

Referenced by main().

camogm_state sstate

Definition at line 142 of file camogm.c.

camogm_state* state

Definition at line 143 of file camogm.c.

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

Definition at line 111 of file camogm.c.


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