#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_state * | state |
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 AUDIO_CHANNELS_MAX 2 |
#define AUDIO_CHANNELS_MIN 1 |
#define AUDIO_RATE_MAX 44100 |
#define AUDIO_RATE_MIN 11025 |
#define COMMAND_LOOP_DELAY 500000 |
#define DEFAULT_FRAMES 16384 |
#define SBUFFER_PREFIX 16 |
#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/>. ! -----------------------------------------------------------------------------** ! !
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_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 | ) |
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 | ) |
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/>. ! -----------------------------------------------------------------------------** ! !
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 | |||
) |
int sendImageFrame | ( | void | ) |
int audio_present = 0 |
snd_pcm_t* capture_handle = NULL |
unsigned long* ccam_dma_buf |
FILE* debug_file |
int debug_level |
const char ExifFileName[] = "/dev/exif_exif" |
const char HeadFileName[] = "/dev/jpeghead" |
unsigned long* imageParamsR |
long sample_time = 100 |
long sbuffer_len = 0 |
const char SensParsFileName[] = "/dev/sensorpars" |