Commit e119b208 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Minor updates to doxygen documentation

parent 2f60099a
...@@ -371,7 +371,7 @@ INLINE_GROUPED_CLASSES = NO ...@@ -371,7 +371,7 @@ INLINE_GROUPED_CLASSES = NO
# Man pages) or section (for LaTeX and RTF). # Man pages) or section (for LaTeX and RTF).
# The default value is: NO. # The default value is: NO.
INLINE_SIMPLE_STRUCTS = NO INLINE_SIMPLE_STRUCTS = YES
# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or # When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or
# enum is documented as struct, union, or enum with the name of the typedef. So # enum is documented as struct, union, or enum with the name of the typedef. So
......
...@@ -118,8 +118,8 @@ void camogm_set_ignore_fps(camogm_state *state, int d); ...@@ -118,8 +118,8 @@ void camogm_set_ignore_fps(camogm_state *state, int d);
void camogm_set_save_gp(camogm_state *state, int d); void camogm_set_save_gp(camogm_state *state, int d);
void camogm_set_prefix(camogm_state *state, const char * p, path_type type); void camogm_set_prefix(camogm_state *state, const char * p, path_type type);
void camogm_set_exif(camogm_state *state, int d); void camogm_set_exif(camogm_state *state, int d);
void camogm_set_timescale(camogm_state *state, double d); //! set timescale, default=1.0 void camogm_set_timescale(camogm_state *state, double d); // set timescale, default=1.0
void camogm_set_frames_skip(camogm_state *state, int d); //! set number of frames to skip, if negative - seconds between frames void camogm_set_frames_skip(camogm_state *state, int d); // set number of frames to skip, if negative - seconds between frames
void camogm_set_format(camogm_state *state, int d); void camogm_set_format(camogm_state *state, int d);
void camogm_kml_set_enable(camogm_state *state, int d); void camogm_kml_set_enable(camogm_state *state, int d);
...@@ -190,6 +190,7 @@ void put_uint64(void *buf, u_int64_t val) ...@@ -190,6 +190,7 @@ void put_uint64(void *buf, u_int64_t val)
* @brief Initialize the state of the program * @brief Initialize the state of the program
* @param[in] state pointer to #camogm_state structure containing program state * @param[in] state pointer to #camogm_state structure containing program state
* @param[in] pipe_name pointer to command pipe name string * @param[in] pipe_name pointer to command pipe name string
* @param[in] port_num communication socket port number
* @return none * @return none
*/ */
void camogm_init(camogm_state *state, char *pipe_name, uint16_t port_num) void camogm_init(camogm_state *state, char *pipe_name, uint16_t port_num)
...@@ -296,8 +297,8 @@ int camogm_start(camogm_state *state) ...@@ -296,8 +297,8 @@ int camogm_start(camogm_state *state)
D1(fprintf(debug_file, "Starting recording\n")); D1(fprintf(debug_file, "Starting recording\n"));
double dtime_stamp; double dtime_stamp;
state->frameno = 0; state->frameno = 0;
state->timescale = state->set_timescale; //! current timescale, default 1 state->timescale = state->set_timescale; // current timescale, default 1
///debug // debug
int * ifp = (int*)&(state->frame_params[port]); int * ifp = (int*)&(state->frame_params[port]);
int * ifp_this = (int*)&(state->this_frame_params[port]); int * ifp_this = (int*)&(state->this_frame_params[port]);
if (state->kml_enable) camogm_init_kml(); // do nothing if (state->kml_enable) camogm_init_kml(); // do nothing
...@@ -311,7 +312,7 @@ int camogm_start(camogm_state *state) ...@@ -311,7 +312,7 @@ int camogm_start(camogm_state *state)
case CAMOGM_FORMAT_MOV: rslt = camogm_init_mov(); break; case CAMOGM_FORMAT_MOV: rslt = camogm_init_mov(); break;
} }
state->formats |= 1 << (state->format); state->formats |= 1 << (state->format);
//! exit on unknown formats? // exit on unknown formats?
} }
state->max_frames = state->set_max_frames; state->max_frames = state->set_max_frames;
state->frames_per_chunk = state->set_frames_per_chunk; state->frames_per_chunk = state->set_frames_per_chunk;
...@@ -319,17 +320,17 @@ int camogm_start(camogm_state *state) ...@@ -319,17 +320,17 @@ int camogm_start(camogm_state *state)
state->prog_state = STATE_STARTING; state->prog_state = STATE_STARTING;
pthread_mutex_unlock(&state->mutex); pthread_mutex_unlock(&state->mutex);
FOR_EACH_PORT(int, chn) { FOR_EACH_PORT(int, chn) {
//! Check/set circbuf read pointer // Check/set circbuf read pointer
D3(fprintf(debug_file, "1: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn])); D3(fprintf(debug_file, "1: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn]));
if ((state->cirbuf_rp[chn] < 0) || (lseek(state->fd_circ[chn], state->cirbuf_rp[chn], SEEK_SET) < 0) || (lseek(state->fd_circ[chn], LSEEK_CIRC_VALID, SEEK_END) < 0 )) { if ((state->cirbuf_rp[chn] < 0) || (lseek(state->fd_circ[chn], state->cirbuf_rp[chn], SEEK_SET) < 0) || (lseek(state->fd_circ[chn], LSEEK_CIRC_VALID, SEEK_END) < 0 )) {
D3(fprintf(debug_file, "2: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn])); D3(fprintf(debug_file, "2: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn]));
/* In "greedy" mode try to save as many frames from the circbuf as possible */ /* In "greedy" mode try to save as many frames from the circbuf as possible */
state->cirbuf_rp[chn] = lseek(state->fd_circ[chn], state->greedy ? LSEEK_CIRC_SCND : LSEEK_CIRC_LAST, SEEK_END); state->cirbuf_rp[chn] = lseek(state->fd_circ[chn], state->greedy ? LSEEK_CIRC_SCND : LSEEK_CIRC_LAST, SEEK_END);
if (!state->ignore_fps) { // don't even try in ignore mode if (!state->ignore_fps) { // don't even try in ignore mode
if (((fp = lseek(state->fd_circ[chn], LSEEK_CIRC_PREV, SEEK_END))) >= 0) state->cirbuf_rp[chn] = fp; //!try to have 2 frames available for fps if (((fp = lseek(state->fd_circ[chn], LSEEK_CIRC_PREV, SEEK_END))) >= 0) state->cirbuf_rp[chn] = fp;//try to have 2 frames available for fps
} }
state->buf_overruns[chn]++; state->buf_overruns[chn]++;
//! file pointer here should match state->rp; so no need to do lseek(state->fd_circ,state->cirbuf_rp,SEEK_SET); // file pointer here should match state->rp; so no need to do lseek(state->fd_circ,state->cirbuf_rp,SEEK_SET);
state->buf_min[chn] = getGPValue(chn, G_FREECIRCBUF); state->buf_min[chn] = getGPValue(chn, G_FREECIRCBUF);
} else { } else {
...@@ -339,16 +340,16 @@ int camogm_start(camogm_state *state) ...@@ -339,16 +340,16 @@ int camogm_start(camogm_state *state)
D3(fprintf(debug_file, "3: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn])); D3(fprintf(debug_file, "3: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn]));
D3(fprintf(debug_file, "4:lseek(state->fd_circ,LSEEK_CIRC_READY,SEEK_END)=%d\n", (int)lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END))); D3(fprintf(debug_file, "4:lseek(state->fd_circ,LSEEK_CIRC_READY,SEEK_END)=%d\n", (int)lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END)));
//! is this frame ready? // is this frame ready?
if (lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END) < 0) return -CAMOGM_FRAME_NOT_READY; //! frame pointer valid, but no frames yet if (lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END) < 0) return -CAMOGM_FRAME_NOT_READY; // frame pointer valid, but no frames yet
D3(fprintf(debug_file, "5: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn])); D3(fprintf(debug_file, "5: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn]));
state->metadata_start = (state->cirbuf_rp[chn]) - 32; state->metadata_start = (state->cirbuf_rp[chn]) - 32;
if (state->metadata_start < 0) state->metadata_start += state->circ_buff_size[chn]; if (state->metadata_start < 0) state->metadata_start += state->circ_buff_size[chn];
///================================== // ==================================
memcpy(&(state->frame_params[chn]), (unsigned long* )&ccam_dma_buf[chn][state->metadata_start >> 2], 32); memcpy(&(state->frame_params[chn]), (unsigned long* )&ccam_dma_buf[chn][state->metadata_start >> 2], 32);
state->jpeg_len = state->frame_params[chn].frame_length; //! frame_params.frame_length are now the length of bitstream state->jpeg_len = state->frame_params[chn].frame_length; // frame_params.frame_length are now the length of bitstream
if (state->frame_params[chn].signffff != 0xffff) { if (state->frame_params[chn].signffff != 0xffff) {
...@@ -359,13 +360,13 @@ int camogm_start(camogm_state *state) ...@@ -359,13 +360,13 @@ int camogm_start(camogm_state *state)
D1(fprintf(debug_file, "%08x %08x %08x %08x %08x %08x %08x %08x\r\n", ifp[0], ifp[1], ifp[2], ifp[3], ifp[4], ifp[5], ifp[6], ifp[7])); D1(fprintf(debug_file, "%08x %08x %08x %08x %08x %08x %08x %08x\r\n", ifp[0], ifp[1], ifp[2], ifp[3], ifp[4], ifp[5], ifp[6], ifp[7]));
return -CAMOGM_FRAME_BROKEN; return -CAMOGM_FRAME_BROKEN;
} }
//! find location of the timestamp and copy it to the frame_params structure // find location of the timestamp and copy it to the frame_params structure
///================================== // ==================================
timestamp_start = (state->cirbuf_rp[chn]) + ((state->jpeg_len + CCAM_MMAP_META + 3) & (~0x1f)) + 32 - CCAM_MMAP_META_SEC; //! magic shift - should index first byte of the time stamp timestamp_start = (state->cirbuf_rp[chn]) + ((state->jpeg_len + CCAM_MMAP_META + 3) & (~0x1f)) + 32 - CCAM_MMAP_META_SEC; // magic shift - should index first byte of the time stamp
if (timestamp_start >= state->circ_buff_size[chn]) timestamp_start -= state->circ_buff_size[chn]; if (timestamp_start >= state->circ_buff_size[chn]) timestamp_start -= state->circ_buff_size[chn];
memcpy(&(state->frame_params[chn].timestamp_sec), (unsigned long* )&ccam_dma_buf[chn][timestamp_start >> 2], 8); memcpy(&(state->frame_params[chn].timestamp_sec), (unsigned long* )&ccam_dma_buf[chn][timestamp_start >> 2], 8);
/// New - see if current timestamp is later than start one, if not return "CAMOGM_TOO_EARLY" reset read pointer and buffer read pointer // New - see if current timestamp is later than start one, if not return "CAMOGM_TOO_EARLY" reset read pointer and buffer read pointer
if (state->start_after_timestamp > 0.0) { /// don't bother if it is 0 if (state->start_after_timestamp > 0.0) { // don't bother if it is 0
dtime_stamp = 0.000001 * state->frame_params[chn].timestamp_usec + state->frame_params[chn].timestamp_sec; dtime_stamp = 0.000001 * state->frame_params[chn].timestamp_usec + state->frame_params[chn].timestamp_sec;
if (dtime_stamp < state->start_after_timestamp) { if (dtime_stamp < state->start_after_timestamp) {
state->cirbuf_rp[chn] = -1; state->cirbuf_rp[chn] = -1;
...@@ -374,20 +375,20 @@ int camogm_start(camogm_state *state) ...@@ -374,20 +375,20 @@ int camogm_start(camogm_state *state)
} }
} }
D3(fprintf(debug_file, "6: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn])); D3(fprintf(debug_file, "6: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn]));
//! see if next frame is available // see if next frame is available
if ((lseek(state->fd_circ[chn], LSEEK_CIRC_NEXT, SEEK_END) < 0 ) || if ((lseek(state->fd_circ[chn], LSEEK_CIRC_NEXT, SEEK_END) < 0 ) ||
//! is that next frame ready? // is that next frame ready?
(((fp = lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END))) < 0)) { (((fp = lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END))) < 0)) {
D3(fprintf(debug_file, "6a:lseek(state->fd_circ,LSEEK_CIRC_NEXT,SEEK_END)=0x%x, fp=0x%x\n", (int)lseek(state->fd_circ[chn], LSEEK_CIRC_NEXT, SEEK_END), (int)lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END))); D3(fprintf(debug_file, "6a:lseek(state->fd_circ,LSEEK_CIRC_NEXT,SEEK_END)=0x%x, fp=0x%x\n", (int)lseek(state->fd_circ[chn], LSEEK_CIRC_NEXT, SEEK_END), (int)lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END)));
lseek(state->fd_circ[chn], state->cirbuf_rp[chn], SEEK_SET); //!just in case - restore pointer lseek(state->fd_circ[chn], state->cirbuf_rp[chn], SEEK_SET); // just in case - restore pointer
return -CAMOGM_FRAME_NOT_READY; //! frame pointer valid, but no frames yet return -CAMOGM_FRAME_NOT_READY; // frame pointer valid, but no frames yet
} }
next_metadata_start = fp - 32; next_metadata_start = fp - 32;
if (next_metadata_start < 0) next_metadata_start += state->circ_buff_size[chn]; if (next_metadata_start < 0) next_metadata_start += state->circ_buff_size[chn];
memcpy(&(state->this_frame_params[chn]), (unsigned long* )&ccam_dma_buf[chn][next_metadata_start >> 2], 32); memcpy(&(state->this_frame_params[chn]), (unsigned long* )&ccam_dma_buf[chn][next_metadata_start >> 2], 32);
next_jpeg_len = state->this_frame_params[chn].frame_length; //! frame_params.frame_length are now the length of bitstream next_jpeg_len = state->this_frame_params[chn].frame_length; // frame_params.frame_length are now the length of bitstream
if (state->this_frame_params[chn].signffff != 0xffff) { //! should not happen ever if (state->this_frame_params[chn].signffff != 0xffff) { // should not happen ever
D0(fprintf(debug_file, "%s:%d: wrong signature - %d\r\n", __FILE__, __LINE__, (int)state->this_frame_params[chn].signffff)); D0(fprintf(debug_file, "%s:%d: wrong signature - %d\r\n", __FILE__, __LINE__, (int)state->this_frame_params[chn].signffff));
ifp_this = (int *) &state->this_frame_params[chn]; ifp_this = (int *) &state->this_frame_params[chn];
D1(fprintf(debug_file, "fp=0x%x\r\n", (int)fp)); D1(fprintf(debug_file, "fp=0x%x\r\n", (int)fp));
...@@ -397,30 +398,30 @@ int camogm_start(camogm_state *state) ...@@ -397,30 +398,30 @@ int camogm_start(camogm_state *state)
} }
D3(fprintf(debug_file, "7: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn])); D3(fprintf(debug_file, "7: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn]));
//! find location of the timestamp and copy it to the frame_params structure // find location of the timestamp and copy it to the frame_params structure
timestamp_start = fp + ((next_jpeg_len + CCAM_MMAP_META + 3) & (~0x1f)) + 32 - CCAM_MMAP_META_SEC; //! magic shift - should index first byte of the time stamp timestamp_start = fp + ((next_jpeg_len + CCAM_MMAP_META + 3) & (~0x1f)) + 32 - CCAM_MMAP_META_SEC; // magic shift - should index first byte of the time stamp
if (timestamp_start >= state->circ_buff_size[chn]) timestamp_start -= state->circ_buff_size[chn]; if (timestamp_start >= state->circ_buff_size[chn]) timestamp_start -= state->circ_buff_size[chn];
memcpy(&(state->this_frame_params[chn].timestamp_sec), (unsigned long* )&ccam_dma_buf[chn][timestamp_start >> 2], 8); memcpy(&(state->this_frame_params[chn].timestamp_sec), (unsigned long* )&ccam_dma_buf[chn][timestamp_start >> 2], 8);
//! verify that the essential current frame params did not change, if they did - return an error (need new file header) // verify that the essential current frame params did not change, if they did - return an error (need new file header)
if (!state->ignore_fps && ((state->frame_params[chn].width != state->this_frame_params[chn].width) || if (!state->ignore_fps && ((state->frame_params[chn].width != state->this_frame_params[chn].width) ||
(state->frame_params[chn].height != state->this_frame_params[chn].height))) { (state->frame_params[chn].height != state->this_frame_params[chn].height))) {
//! Advance frame pointer to the next (caller should try again) // Advance frame pointer to the next (caller should try again)
state->cirbuf_rp[chn] = fp; state->cirbuf_rp[chn] = fp;
return -CAMOGM_FRAME_CHANGED; // no yet checking for the FPS return -CAMOGM_FRAME_CHANGED; // no yet checking for the FPS
} }
D3(fprintf(debug_file, "8: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn])); D3(fprintf(debug_file, "8: state->cirbuf_rp=0x%x\n", state->cirbuf_rp[chn]));
//! calcualte the frame period - time difference (in microseconds) // calcualte the frame period - time difference (in microseconds)
state->frame_period[chn] = (state->this_frame_params[chn].timestamp_usec - state->frame_params[chn].timestamp_usec) + state->frame_period[chn] = (state->this_frame_params[chn].timestamp_usec - state->frame_params[chn].timestamp_usec) +
1000000 * (state->this_frame_params[chn].timestamp_sec - state->frame_params[chn].timestamp_sec); 1000000 * (state->this_frame_params[chn].timestamp_sec - state->frame_params[chn].timestamp_sec);
//! correct for timelapse modes: // correct for timelapse modes:
state->frames_skip = state->set_frames_skip; state->frames_skip = state->set_frames_skip;
if (state->frames_skip > 0) { if (state->frames_skip > 0) {
state->frames_skip_left[chn] = 0; state->frames_skip_left[chn] = 0;
state->frame_period[chn] *= (state->frames_skip + 1); state->frame_period[chn] *= (state->frames_skip + 1);
} else if (state->frames_skip < 0) { } else if (state->frames_skip < 0) {
state->frame_period[chn] = -(state->frames_skip); //! actual frame period will fluctuate to the nearest frame acquired (free running) state->frame_period[chn] = -(state->frames_skip); // actual frame period will fluctuate to the nearest frame acquired (free running)
state->frames_skip_left[chn] = state->frame_params[chn].timestamp_sec; state->frames_skip_left[chn] = state->frame_params[chn].timestamp_sec;
} }
D3(fprintf(debug_file, "9: state->frame_period=0x%x\n", state->frame_period[chn])); D3(fprintf(debug_file, "9: state->frame_period=0x%x\n", state->frame_period[chn]));
...@@ -429,22 +430,22 @@ int camogm_start(camogm_state *state) ...@@ -429,22 +430,22 @@ int camogm_start(camogm_state *state)
state->width = state->frame_params[chn].width; state->width = state->frame_params[chn].width;
state->height = state->frame_params[chn].height; state->height = state->frame_params[chn].height;
//!read JPEG header - it should stay the same for the whole file (restart new file if any parameters changed) // read JPEG header - it should stay the same for the whole file (restart new file if any parameters changed)
//!rebuild JPEG header: // rebuild JPEG header:
lseek(state->fd_head[chn], state->cirbuf_rp[chn] + 1, SEEK_END); //!+1 to avoid condition when jpeg_start==0. overloaded lseek will ignore 5 LSBs when SEEK_END lseek(state->fd_head[chn], state->cirbuf_rp[chn] + 1, SEEK_END); // +1 to avoid condition when jpeg_start==0. overloaded lseek will ignore 5 LSBs when SEEK_END
state->head_size[chn] = lseek(state->fd_head[chn], 0, SEEK_END); /// In 8.0 the header size might change for some jp4 modes state->head_size[chn] = lseek(state->fd_head[chn], 0, SEEK_END); // In 8.0 the header size might change for some jp4 modes
if (state->head_size[chn] > JPEG_HEADER_MAXSIZE) { if (state->head_size[chn] > JPEG_HEADER_MAXSIZE) {
D0(fprintf(debug_file, "%s:%d: Too big JPEG header (%d > %d)", __FILE__, __LINE__, state->head_size[chn], JPEG_HEADER_MAXSIZE )); D0(fprintf(debug_file, "%s:%d: Too big JPEG header (%d > %d)", __FILE__, __LINE__, state->head_size[chn], JPEG_HEADER_MAXSIZE ));
return -2; return -2;
} }
//! and read it // and read it
lseek(state->fd_head[chn], 0, 0); lseek(state->fd_head[chn], 0, 0);
read(state->fd_head[chn], state->jpegHeader[chn], state->head_size[chn]); read(state->fd_head[chn], state->jpegHeader[chn], state->head_size[chn]);
//! Restore read pointer to the original (now there may be no frame ready there yet) // Restore read pointer to the original (now there may be no frame ready there yet)
lseek(state->fd_circ[chn], state->cirbuf_rp[chn], SEEK_SET); lseek(state->fd_circ[chn], state->cirbuf_rp[chn], SEEK_SET);
} }
//!here we are ready to initialize Ogm (or other) file // here we are ready to initialize Ogm (or other) file
switch (state->format) { switch (state->format) {
case CAMOGM_FORMAT_NONE: rslt = 0; break; case CAMOGM_FORMAT_NONE: rslt = 0; break;
case CAMOGM_FORMAT_OGM: rslt = camogm_start_ogm(state); break; case CAMOGM_FORMAT_OGM: rslt = camogm_start_ogm(state); break;
...@@ -479,56 +480,56 @@ int sendImageFrame(camogm_state *state) ...@@ -479,56 +480,56 @@ int sendImageFrame(camogm_state *state)
int fp; int fp;
int port = state->port_num; int port = state->port_num;
//! This is probably needed only for Quicktime (not to exceed already allocated frame index) // This is probably needed only for Quicktime (not to exceed already allocated frame index)
if (state->frameno >= (state->max_frames)) { if (state->frameno >= (state->max_frames)) {
D3(fprintf(debug_file, "sendImageFrame:1: state->frameno(0x%x) >= state->max_frames(0x%x)\n", state->frameno, state->max_frames)); D3(fprintf(debug_file, "sendImageFrame:1: state->frameno(0x%x) >= state->max_frames(0x%x)\n", state->frameno, state->max_frames));
return -CAMOGM_FRAME_CHANGED; return -CAMOGM_FRAME_CHANGED;
} }
//! Format changed? // Format changed?
// D3(fprintf (debug_file,"sendImageFrame: format=%d, set_format=%d\n", state->format, state->set_format)); // D3(fprintf (debug_file,"sendImageFrame: format=%d, set_format=%d\n", state->format, state->set_format));
if (state->format != state->set_format) { if (state->format != state->set_format) {
D3(fprintf(debug_file, "sendImageFrame:2: state->format(0x%x) != state->set_format(0x%x)\n", state->format, state->set_format)); D3(fprintf(debug_file, "sendImageFrame:2: state->format(0x%x) != state->set_format(0x%x)\n", state->format, state->set_format));
return -CAMOGM_FRAME_CHANGED; return -CAMOGM_FRAME_CHANGED;
} }
//! check if file size is exceeded (assuming fopen),-CAMOGM_FRAME_CHANGED will trigger a new segment // check if file size is exceeded (assuming fopen),-CAMOGM_FRAME_CHANGED will trigger a new segment
if ((state->vf) && (state->segment_length >= 0) && (ftell(state->vf) > state->segment_length)) { if ((state->vf) && (state->segment_length >= 0) && (ftell(state->vf) > state->segment_length)) {
D3(fprintf(debug_file, "sendImageFrame:3: segment length exceeded\n")); D3(fprintf(debug_file, "sendImageFrame:3: segment length exceeded\n"));
return -CAMOGM_FRAME_CHANGED; return -CAMOGM_FRAME_CHANGED;
} }
//!same for open //same for open
if (((state->ivf) >= 0) && (state->segment_length >= 0) && (lseek(state->ivf, 0, SEEK_CUR) > state->segment_length)) { if (((state->ivf) >= 0) && (state->segment_length >= 0) && (lseek(state->ivf, 0, SEEK_CUR) > state->segment_length)) {
D3(fprintf(debug_file, "sendImageFrame:4: segment length exceeded\n")); D3(fprintf(debug_file, "sendImageFrame:4: segment length exceeded\n"));
return -CAMOGM_FRAME_CHANGED; return -CAMOGM_FRAME_CHANGED;
} }
//! check the frame pointer is valid // check the frame pointer is valid
if ((fp = lseek(state->fd_circ[port], state->cirbuf_rp[port], SEEK_SET)) < 0) { if ((fp = lseek(state->fd_circ[port], state->cirbuf_rp[port], SEEK_SET)) < 0) {
D3(fprintf(debug_file, "sendImageFrame:5: invalid frame\n")); D3(fprintf(debug_file, "sendImageFrame:5: invalid frame\n"));
return -CAMOGM_FRAME_INVALID; //!it will probably be that allready return -CAMOGM_FRAME_INVALID; //it will probably be that allready
} }
//! is the frame ready? // is the frame ready?
if (lseek(state->fd_circ[port], LSEEK_CIRC_READY, SEEK_END) < 0) { if (lseek(state->fd_circ[port], LSEEK_CIRC_READY, SEEK_END) < 0) {
D3(fprintf(debug_file, "?6,fp=0x%x ", fp)); //frame not ready, frame pointer seems valid, but not ready D3(fprintf(debug_file, "?6,fp=0x%x ", fp)); //frame not ready, frame pointer seems valid, but not ready
return -CAMOGM_FRAME_NOT_READY; //! frame pointer valid, but no frames yet return -CAMOGM_FRAME_NOT_READY; // frame pointer valid, but no frames yet
} }
//! process skipping frames. TODO: add - skipping time between frames (or better - actual time period - use the nearest frame) instead of the frame number // process skipping frames. TODO: add - skipping time between frames (or better - actual time period - use the nearest frame) instead of the frame number
if ( (state->frames_skip > 0) && (state->frames_skip_left[port] > 0 )) { //!skipping frames, not seconds. if ( (state->frames_skip > 0) && (state->frames_skip_left[port] > 0 )) { //skipping frames, not seconds.
state->cirbuf_rp[port] = lseek(state->fd_circ[port], LSEEK_CIRC_NEXT, SEEK_END); state->cirbuf_rp[port] = lseek(state->fd_circ[port], LSEEK_CIRC_NEXT, SEEK_END);
//!optionally save it to global read pointer (i.e. for debugging with imgsrv "/pointers") //optionally save it to global read pointer (i.e. for debugging with imgsrv "/pointers")
if (state->save_gp) lseek(state->fd_circ[port], LSEEK_CIRC_SETP, SEEK_END); if (state->save_gp) lseek(state->fd_circ[port], LSEEK_CIRC_SETP, SEEK_END);
state->frames_skip_left[port]--; state->frames_skip_left[port]--;
D3(fprintf(debug_file, "?7 ")); //frame not ready D3(fprintf(debug_file, "?7 ")); //frame not ready
return -CAMOGM_FRAME_NOT_READY; //! the required frame is not ready return -CAMOGM_FRAME_NOT_READY; // the required frame is not ready
} }
//! Get metadata // Get metadata
D3(fprintf(debug_file, "_1_")); D3(fprintf(debug_file, "_1_"));
state->metadata_start = state->cirbuf_rp[port] - 32; state->metadata_start = state->cirbuf_rp[port] - 32;
if (state->metadata_start < 0) state->metadata_start += state->circ_buff_size[port]; if (state->metadata_start < 0) state->metadata_start += state->circ_buff_size[port];
memcpy(&(state->this_frame_params[port]), (unsigned long* )&ccam_dma_buf[state->port_num][state->metadata_start >> 2], 32); memcpy(&(state->this_frame_params[port]), (unsigned long* )&ccam_dma_buf[state->port_num][state->metadata_start >> 2], 32);
state->jpeg_len = state->this_frame_params[port].frame_length; //! frame_params.frame_length are now the length of bitstream state->jpeg_len = state->this_frame_params[port].frame_length; // frame_params.frame_length are now the length of bitstream
if (state->this_frame_params[port].signffff != 0xffff) { if (state->this_frame_params[port].signffff != 0xffff) {
D0(fprintf(debug_file, "%s:%d: wrong signature - %d\r\n", __FILE__, __LINE__, (int)state->this_frame_params[port].signffff)); D0(fprintf(debug_file, "%s:%d: wrong signature - %d\r\n", __FILE__, __LINE__, (int)state->this_frame_params[port].signffff));
D1(fprintf(debug_file, "state->cirbuf_rp=0x%x\r\n", (int)state->cirbuf_rp[port])); D1(fprintf(debug_file, "state->cirbuf_rp=0x%x\r\n", (int)state->cirbuf_rp[port]));
...@@ -538,41 +539,41 @@ int sendImageFrame(camogm_state *state) ...@@ -538,41 +539,41 @@ int sendImageFrame(camogm_state *state)
return -CAMOGM_FRAME_BROKEN; return -CAMOGM_FRAME_BROKEN;
} }
D3(fprintf(debug_file, "_2_")); D3(fprintf(debug_file, "_2_"));
//! find location of the timestamp and copy it to the frame_params structure // find location of the timestamp and copy it to the frame_params structure
timestamp_start = state->cirbuf_rp[port] + ((state->jpeg_len + CCAM_MMAP_META + 3) & (~0x1f)) + 32 - CCAM_MMAP_META_SEC; //! magic shift - should index first byte of the time stamp timestamp_start = state->cirbuf_rp[port] + ((state->jpeg_len + CCAM_MMAP_META + 3) & (~0x1f)) + 32 - CCAM_MMAP_META_SEC; // magic shift - should index first byte of the time stamp
if (timestamp_start >= state->circ_buff_size[port]) timestamp_start -= state->circ_buff_size[port]; if (timestamp_start >= state->circ_buff_size[port]) timestamp_start -= state->circ_buff_size[port];
D3(fprintf(debug_file, "_3_")); D3(fprintf(debug_file, "_3_"));
memcpy(&(state->this_frame_params[port].timestamp_sec), (unsigned long* )&ccam_dma_buf[state->port_num][timestamp_start >> 2], 8); memcpy(&(state->this_frame_params[port].timestamp_sec), (unsigned long* )&ccam_dma_buf[state->port_num][timestamp_start >> 2], 8);
//! verify that the essential current frame params did not change, if they did - return an error (need new file header) // verify that the essential current frame params did not change, if they did - return an error (need new file header)
if (!state->ignore_fps && ((state->frame_params[port].width != state->this_frame_params[port].width) || if (!state->ignore_fps && ((state->frame_params[port].width != state->this_frame_params[port].width) ||
(state->frame_params[port].height != state->this_frame_params[port].height))) { (state->frame_params[port].height != state->this_frame_params[port].height))) {
D3(fprintf(debug_file, "sendImageFrame:9: WOI changed\n")); D3(fprintf(debug_file, "sendImageFrame:9: WOI changed\n"));
return -CAMOGM_FRAME_CHANGED; //! not yet checking for the FPS return -CAMOGM_FRAME_CHANGED; // not yet checking for the FPS
} }
//! check if file duration (in seconds) exceeded ,-CAMOGM_FRAME_CHANGED will trigger a new segment // check if file duration (in seconds) exceeded ,-CAMOGM_FRAME_CHANGED will trigger a new segment
if ((state->segment_duration > 0) && if ((state->segment_duration > 0) &&
((state->this_frame_params[port].timestamp_sec - state->frame_params[port].timestamp_sec) > state->segment_duration)) { ((state->this_frame_params[port].timestamp_sec - state->frame_params[port].timestamp_sec) > state->segment_duration)) {
D3(fprintf(debug_file, "sendImageFrame:10: segment duration in seconds exceeded\n")); D3(fprintf(debug_file, "sendImageFrame:10: segment duration in seconds exceeded\n"));
return -CAMOGM_FRAME_CHANGED; return -CAMOGM_FRAME_CHANGED;
} }
//! check if (in timelapse mode) it is too early for the frame to be stored // check if (in timelapse mode) it is too early for the frame to be stored
if ((state->frames_skip < 0) && (state->frames_skip_left[port] > state->this_frame_params[port].timestamp_sec) ) { if ((state->frames_skip < 0) && (state->frames_skip_left[port] > state->this_frame_params[port].timestamp_sec) ) {
state->cirbuf_rp[port] = lseek(state->fd_circ[port], LSEEK_CIRC_NEXT, SEEK_END); state->cirbuf_rp[port] = lseek(state->fd_circ[port], LSEEK_CIRC_NEXT, SEEK_END);
//!optionally save it to global read pointer (i.e. for debugging with imgsrv "/pointers") //optionally save it to global read pointer (i.e. for debugging with imgsrv "/pointers")
if (state->save_gp) lseek(state->fd_circ[port], LSEEK_CIRC_SETP, SEEK_END); if (state->save_gp) lseek(state->fd_circ[port], LSEEK_CIRC_SETP, SEEK_END);
D3(fprintf(debug_file, "sendImageFrame:11: timelapse: frame will be skipped\n")); D3(fprintf(debug_file, "sendImageFrame:11: timelapse: frame will be skipped\n"));
return -CAMOGM_FRAME_NOT_READY; //! the required frame is not ready return -CAMOGM_FRAME_NOT_READY; // the required frame is not ready
} }
D3(fprintf(debug_file, "_4_")); D3(fprintf(debug_file, "_4_"));
if (state->exif) { if (state->exif) {
D3(fprintf(debug_file, "_5_")); D3(fprintf(debug_file, "_5_"));
//! update the Exif header with the current frame metadata // update the Exif header with the current frame metadata
state->exifSize[port] = lseek(state->fd_exif[port], 1, SEEK_END); // at the beginning of page 1 - position == page length state->exifSize[port] = lseek(state->fd_exif[port], 1, SEEK_END); // at the beginning of page 1 - position == page length
if (state->exifSize > 0) { if (state->exifSize > 0) {
//state->this_frame_params.meta_index //state->this_frame_params.meta_index
lseek(state->fd_exif[port], state->this_frame_params[port].meta_index, SEEK_END); //! select meta page to use (matching frame) lseek(state->fd_exif[port], state->this_frame_params[port].meta_index, SEEK_END); // select meta page to use (matching frame)
rslt = read(state->fd_exif[port], state->ed[port], state->exifSize[port]); rslt = read(state->fd_exif[port], state->ed[port], state->exifSize[port]);
if (rslt < 0) rslt = 0; if (rslt < 0) rslt = 0;
state->exifSize[port] = rslt; state->exifSize[port] = rslt;
...@@ -581,11 +582,11 @@ int sendImageFrame(camogm_state *state) ...@@ -581,11 +582,11 @@ int sendImageFrame(camogm_state *state)
D3(fprintf(debug_file, "_6_")); D3(fprintf(debug_file, "_6_"));
//! prepare a packet to be sent (a lst of memory chunks) // prepare a packet to be sent (a lst of memory chunks)
state->chunk_index = 0; state->chunk_index = 0;
state->packetchunks[state->chunk_index ].bytes = 1; state->packetchunks[state->chunk_index ].bytes = 1;
state->packetchunks[state->chunk_index++].chunk = &frame_packet_type; state->packetchunks[state->chunk_index++].chunk = &frame_packet_type;
if (state->exif > 0) { //! insert Exif if (state->exif > 0) { // insert Exif
D3(fprintf(debug_file, "_7_")); D3(fprintf(debug_file, "_7_"));
state->packetchunks[state->chunk_index ].bytes = 2; state->packetchunks[state->chunk_index ].bytes = 2;
state->packetchunks[state->chunk_index++].chunk = state->jpegHeader[port]; state->packetchunks[state->chunk_index++].chunk = state->jpegHeader[port];
...@@ -600,19 +601,19 @@ int sendImageFrame(camogm_state *state) ...@@ -600,19 +601,19 @@ int sendImageFrame(camogm_state *state)
} }
D3(fprintf(debug_file, "_9_")); D3(fprintf(debug_file, "_9_"));
/*! JPEG image data may be split in two segments (rolled over buffer end) - process both variants */ /* JPEG image data may be split in two segments (rolled over buffer end) - process both variants */
if ((state->cirbuf_rp[port] + state->jpeg_len) > state->circ_buff_size[port]) { //! two segments if ((state->cirbuf_rp[port] + state->jpeg_len) > state->circ_buff_size[port]) { // two segments
/*! copy from the beginning of the frame to the end of the buffer */ /* copy from the beginning of the frame to the end of the buffer */
D3(fprintf(debug_file, "_10_")); D3(fprintf(debug_file, "_10_"));
state->packetchunks[state->chunk_index ].bytes = state->circ_buff_size[port] - state->cirbuf_rp[port]; state->packetchunks[state->chunk_index ].bytes = state->circ_buff_size[port] - state->cirbuf_rp[port];
state->packetchunks[state->chunk_index++].chunk = (unsigned char*)&ccam_dma_buf[state->port_num][state->cirbuf_rp[port] >> 2]; state->packetchunks[state->chunk_index++].chunk = (unsigned char*)&ccam_dma_buf[state->port_num][state->cirbuf_rp[port] >> 2];
/*! copy from the beginning of the buffer to the end of the frame */ /* copy from the beginning of the buffer to the end of the frame */
state->packetchunks[state->chunk_index ].bytes = state->jpeg_len - (state->circ_buff_size[port] - state->cirbuf_rp[port]); state->packetchunks[state->chunk_index ].bytes = state->jpeg_len - (state->circ_buff_size[port] - state->cirbuf_rp[port]);
state->packetchunks[state->chunk_index++].chunk = (unsigned char*)&ccam_dma_buf[state->port_num][0]; state->packetchunks[state->chunk_index++].chunk = (unsigned char*)&ccam_dma_buf[state->port_num][0];
} else { // single segment } else { // single segment
D3(fprintf(debug_file, "_11_")); D3(fprintf(debug_file, "_11_"));
/*! copy from the beginning of the frame to the end of the frame (no buffer rollovers) */ /* copy from the beginning of the frame to the end of the frame (no buffer rollovers) */
state->packetchunks[state->chunk_index ].bytes = state->jpeg_len; state->packetchunks[state->chunk_index ].bytes = state->jpeg_len;
state->packetchunks[state->chunk_index++].chunk = (unsigned char*)&ccam_dma_buf[state->port_num][state->cirbuf_rp[port] >> 2]; state->packetchunks[state->chunk_index++].chunk = (unsigned char*)&ccam_dma_buf[state->port_num][state->cirbuf_rp[port] >> 2];
} }
...@@ -635,10 +636,10 @@ int sendImageFrame(camogm_state *state) ...@@ -635,10 +636,10 @@ int sendImageFrame(camogm_state *state)
if (rslt) return rslt; if (rslt) return rslt;
D3(fprintf(debug_file, "_14_")); D3(fprintf(debug_file, "_14_"));
//!advance frame pointer // advance frame pointer
state->frameno++; state->frameno++;
state->cirbuf_rp[port] = lseek(state->fd_circ[port], LSEEK_CIRC_NEXT, SEEK_END); state->cirbuf_rp[port] = lseek(state->fd_circ[port], LSEEK_CIRC_NEXT, SEEK_END);
//!optionally save it to global read pointer (i.e. for debugging with imgsrv "/pointers") // optionally save it to global read pointer (i.e. for debugging with imgsrv "/pointers")
if (state->save_gp) lseek(state->fd_circ[port], LSEEK_CIRC_SETP, SEEK_END); if (state->save_gp) lseek(state->fd_circ[port], LSEEK_CIRC_SETP, SEEK_END);
D3(fprintf(debug_file, "_15_\n")); D3(fprintf(debug_file, "_15_\n"));
if (state->frames_skip > 0) { if (state->frames_skip > 0) {
...@@ -677,9 +678,9 @@ int camogm_stop(camogm_state *state) ...@@ -677,9 +678,9 @@ int camogm_stop(camogm_state *state)
case CAMOGM_FORMAT_OGM: rslt = camogm_end_ogm(state); break; case CAMOGM_FORMAT_OGM: rslt = camogm_end_ogm(state); break;
case CAMOGM_FORMAT_JPEG: rslt = camogm_end_jpeg(state); break; case CAMOGM_FORMAT_JPEG: rslt = camogm_end_jpeg(state); break;
case CAMOGM_FORMAT_MOV: rslt = camogm_end_mov(state); break; case CAMOGM_FORMAT_MOV: rslt = camogm_end_mov(state); break;
/// default: return 0; // do nothing // default: return 0; // do nothing
} }
//! now close video file (if it is open) // now close video file (if it is open)
if (state->vf) fclose(state->vf); if (state->vf) fclose(state->vf);
state->vf = NULL; state->vf = NULL;
if (rslt) return rslt; if (rslt) return rslt;
...@@ -820,8 +821,8 @@ void camogm_set_prefix(camogm_state *state, const char * p, path_type type) ...@@ -820,8 +821,8 @@ void camogm_set_prefix(camogm_state *state, const char * p, path_type type)
} }
} }
/** @brief Set timescale @e d */ /** @brief Set timescale @e d, default = 1,000,000 */
void camogm_set_timescale(camogm_state *state, double d) //! set timescale, default=1,000,000 void camogm_set_timescale(camogm_state *state, double d)
{ {
state->set_timescale = d; state->set_timescale = d;
if (state->prog_state == STATE_STOPPED) { if (state->prog_state == STATE_STOPPED) {
...@@ -830,7 +831,7 @@ void camogm_set_timescale(camogm_state *state, double d) //! set timescale, d ...@@ -830,7 +831,7 @@ void camogm_set_timescale(camogm_state *state, double d) //! set timescale, d
} }
/** @brief Set the number of frames @e d to be skipped during recording. This values is common for each sensor port */ /** @brief Set the number of frames @e d to be skipped during recording. This values is common for each sensor port */
void camogm_set_frames_skip(camogm_state *state, int d) //! set frames to skip (for time lapse) void camogm_set_frames_skip(camogm_state *state, int d)
{ {
state->set_frames_skip = d; state->set_frames_skip = d;
if (state->prog_state == STATE_STOPPED) { if (state->prog_state == STATE_STOPPED) {
...@@ -908,7 +909,7 @@ void camogm_status(camogm_state *state, char * fn, int xml) ...@@ -908,7 +909,7 @@ void camogm_status(camogm_state *state, char * fn, int xml)
_kml_enable = state->kml_enable ? "yes" : "no"; _kml_enable = state->kml_enable ? "yes" : "no";
_kml_used = state->kml_used ? "yes" : "no"; _kml_used = state->kml_used ? "yes" : "no";
_kml_height_mode = state->kml_height_mode ? "GPS altitude" : "map ground level"; //! 1 - actual, 0 - ground _kml_height_mode = state->kml_height_mode ? "GPS altitude" : "map ground level"; // 1 - actual, 0 - ground
for (int chn = 0; chn < SENSOR_PORTS; chn++) { for (int chn = 0; chn < SENSOR_PORTS; chn++) {
_b_free[chn] = getGPValue(chn, G_FREECIRCBUF); _b_free[chn] = getGPValue(chn, G_FREECIRCBUF);
...@@ -951,8 +952,8 @@ void camogm_status(camogm_state *state, char * fn, int xml) ...@@ -951,8 +952,8 @@ void camogm_status(camogm_state *state, char * fn, int xml)
return; return;
} }
} }
if (state->vf) _len = ftell(state->vf); //! for ogm if (state->vf) _len = ftell(state->vf); // for ogm
else if ((state->ivf) >= 0) _len = lseek(state->ivf, 0, SEEK_CUR); //!for mov else if ((state->ivf) >= 0) _len = lseek(state->ivf, 0, SEEK_CUR); //for mov
switch (state->prog_state) { switch (state->prog_state) {
case STATE_STOPPED: case STATE_STOPPED:
_state = "stopped"; _state = "stopped";
...@@ -1127,8 +1128,8 @@ void camogm_status(camogm_state *state, char * fn, int xml) ...@@ -1127,8 +1128,8 @@ void camogm_status(camogm_state *state, char * fn, int xml)
} }
} }
if ((f != stdout) && (f != stderr)) fclose(f); if ((f != stdout) && (f != stderr)) fclose(f);
FOR_EACH_PORT(int, chn) {if (state->buf_overruns[chn] >= 0) state->buf_overruns[chn] = 0;} //! resets overruns after reading status , so "overruns" means since last reading status FOR_EACH_PORT(int, chn) {if (state->buf_overruns[chn] >= 0) state->buf_overruns[chn] = 0;} // resets overruns after reading status , so "overruns" means since last reading status
state->last_error_code = 0; //! Reset error state->last_error_code = 0; // Reset error
FOR_EACH_PORT(int, chn) {state->buf_min[chn] = _b_free[chn];} FOR_EACH_PORT(int, chn) {state->buf_min[chn] = _b_free[chn];}
} }
...@@ -1145,22 +1146,22 @@ char * getLineFromPipe(FILE* npipe) ...@@ -1145,22 +1146,22 @@ char * getLineFromPipe(FILE* npipe)
static int cmdbufp = 0; // current input pointer in the command buffer (read from pipe) static int cmdbufp = 0; // current input pointer in the command buffer (read from pipe)
static int cmdstrt = 0; // start of the next partial command static int cmdstrt = 0; // start of the next partial command
//!remove used string if any //remove used string if any
if (cmdstrt > 0) { if (cmdstrt > 0) {
//!moving overlapping strings //moving overlapping strings
memmove(cmdbuf, &cmdbuf[cmdstrt], sizeof(cmdbuf) - cmdstrt); memmove(cmdbuf, &cmdbuf[cmdstrt], sizeof(cmdbuf) - cmdstrt);
cmdbufp -= cmdstrt; cmdbufp -= cmdstrt;
cmdstrt = 0; cmdstrt = 0;
} }
//! is there any complete string in a buffer? // is there any complete string in a buffer?
if (!cmdbufp) cmdbuf[cmdbufp] = 0; //!null-terminate first access (probably not needed for the static buffer if (!cmdbufp) cmdbuf[cmdbufp] = 0; //null-terminate first access (probably not needed for the static buffer
nlp = strpbrk(cmdbuf, ";\n"); nlp = strpbrk(cmdbuf, ";\n");
if (!nlp) { //!no complete string, try to read more if (!nlp) { //no complete string, try to read more
fl = fread(&cmdbuf[cmdbufp], 1, sizeof(cmdbuf) - cmdbufp - 1, npipe); fl = fread(&cmdbuf[cmdbufp], 1, sizeof(cmdbuf) - cmdbufp - 1, npipe);
cmdbuf[cmdbufp + fl] = 0; cmdbuf[cmdbufp + fl] = 0;
//! is there any complete string in a buffer after reading? // is there any complete string in a buffer after reading?
nlp = strpbrk(&cmdbuf[cmdbufp], ";\n"); //! there were no new lines before cmdbufp nlp = strpbrk(&cmdbuf[cmdbufp], ";\n"); // there were no new lines before cmdbufp
cmdbufp += fl; //!advance pointer after pipe read cmdbufp += fl; //advance pointer after pipe read
} }
if (nlp) { if (nlp) {
nlp[0] = 0; nlp[0] = 0;
...@@ -1187,33 +1188,33 @@ int parse_cmd(camogm_state *state, FILE* npipe) ...@@ -1187,33 +1188,33 @@ int parse_cmd(camogm_state *state, FILE* npipe)
int d; int d;
double dd; double dd;
//!skip empty commands //skip empty commands
while (((cmd = getLineFromPipe(npipe))) && !cmd[0]) ; while (((cmd = getLineFromPipe(npipe))) && !cmd[0]) ;
if (!cmd) return 0; //! nothing in the pipe if (!cmd) return 0; // nothing in the pipe
D2(fprintf(debug_file, "Got command: '%s'\n", cmd)); D2(fprintf(debug_file, "Got command: '%s'\n", cmd));
#ifdef DISABLE_CODE #ifdef DISABLE_CODE
/// Acknowledge received command by copying frame number to per-daemon parameter // Acknowledge received command by copying frame number to per-daemon parameter
// GLOBALPARS(state->port_num, G_DAEMON_ERR + lastDaemonBit[state->port_num]) = GLOBALPARS(state->port_num, G_THIS_FRAME); // GLOBALPARS(state->port_num, G_DAEMON_ERR + lastDaemonBit[state->port_num]) = GLOBALPARS(state->port_num, G_THIS_FRAME);
setGValue(state->port_num, G_DAEMON_ERR + lastDaemonBit[state->port_num], getGPValue(state->port_num, G_THIS_FRAME)); setGValue(state->port_num, G_DAEMON_ERR + lastDaemonBit[state->port_num], getGPValue(state->port_num, G_THIS_FRAME));
#endif /* DISABLE_CODE */ #endif /* DISABLE_CODE */
args = strpbrk(cmd, "= \t"); args = strpbrk(cmd, "= \t");
//! is it just a single word command or does it have parameters? // is it just a single word command or does it have parameters?
if (args) { if (args) {
args[0] = 0; args[0] = 0;
args++; args++;
while (strchr("= \t", args[0])) args++; while (strchr("= \t", args[0])) args++;
if (args[0]) { if (args[0]) {
//! ltrim (args) // ltrim (args)
for (argse = strchr(args, '\0') - 1; strchr("= \t", argse[0]); argse--) argse[0] = '\0'; for (argse = strchr(args, '\0') - 1; strchr("= \t", argse[0]); argse--) argse[0] = '\0';
} }
if (!args[0]) args = NULL; if (!args[0]) args = NULL;
} }
//! now cmd is trimmed, arg is NULL or a pointer to trimmed command arguments // now cmd is trimmed, arg is NULL or a pointer to trimmed command arguments
if (strcmp(cmd, "start") == 0) { if (strcmp(cmd, "start") == 0) {
camogm_start(state); camogm_start(state);
return 1; return 1;
} else if (strcmp(cmd, "reset") == 0) { //! will reset pointer to the last acquired frame (if any) } else if (strcmp(cmd, "reset") == 0) { // will reset pointer to the last acquired frame (if any)
camogm_reset(state); camogm_reset(state);
return 2; return 2;
} else if (strcmp(cmd, "stop") == 0) { } else if (strcmp(cmd, "stop") == 0) {
...@@ -1254,15 +1255,15 @@ int parse_cmd(camogm_state *state, FILE* npipe) ...@@ -1254,15 +1255,15 @@ int parse_cmd(camogm_state *state, FILE* npipe)
dd = strtod(args, NULL); dd = strtod(args, NULL);
camogm_set_timescale(state, dd ? dd : 1.0); camogm_set_timescale(state, dd ? dd : 1.0);
return 10; return 10;
//!TODO: fix period calculation/check for frame skipping (just disable in frame skip mode?) //TODO: fix period calculation/check for frame skipping (just disable in frame skip mode?)
//!TODO: add time period (system clock), not just frame skipping //TODO: add time period (system clock), not just frame skipping
} else if (strcmp(cmd, "frameskip") == 0) { } else if (strcmp(cmd, "frameskip") == 0) {
d = strtol(args, NULL, 10); d = strtol(args, NULL, 10);
camogm_set_frames_skip(state, d); camogm_set_frames_skip(state, d);
return 11; return 11;
} else if (strcmp(cmd, "timelapse") == 0) { //! period (in seconds) between stored frames } else if (strcmp(cmd, "timelapse") == 0) { // period (in seconds) between stored frames
d = strtol(args, NULL, 10); d = strtol(args, NULL, 10);
camogm_set_frames_skip(state, -d); camogm_set_frames_skip(state, -d);
return 11; return 11;
...@@ -1779,7 +1780,7 @@ int waitDaemonEnabled(unsigned int port, int daemonBit) // <0 - use default ...@@ -1779,7 +1780,7 @@ int waitDaemonEnabled(unsigned int port, int daemonBit) // <0 - use default
unsigned long this_frame = GLOBALPARS(port, G_THIS_FRAME); unsigned long this_frame = GLOBALPARS(port, G_THIS_FRAME);
// No semaphors, so it is possible to miss event and wait until the streamer will be re-enabled before sending message, // No semaphors, so it is possible to miss event and wait until the streamer will be re-enabled before sending message,
// but it seems not so terrible // but it seems not so terrible
lseek(state->fd_circ[state->port_num], LSEEK_DAEMON_CIRCBUF + lastDaemonBit[port], SEEK_END); /// lseek(state->fd_circ[state->port_num], LSEEK_DAEMON_CIRCBUF + lastDaemonBit[port], SEEK_END);
if (this_frame == GLOBALPARS(port, G_THIS_FRAME)) return 1; if (this_frame == GLOBALPARS(port, G_THIS_FRAME)) return 1;
return 0; return 0;
} }
......
...@@ -53,12 +53,12 @@ int camogm_start_jpeg(camogm_state *state) ...@@ -53,12 +53,12 @@ int camogm_start_jpeg(camogm_state *state)
int rslt; int rslt;
if (!state->rawdev_op) { if (!state->rawdev_op) {
strcpy(state->path, state->path_prefix); //!make state->path a directory name (will be replaced when the frames will be written) strcpy(state->path, state->path_prefix); // make state->path a directory name (will be replaced when the frames will be written)
slash = strrchr(state->path, '/'); slash = strrchr(state->path, '/');
D2(fprintf(debug_file, "camogm_start_jpeg\n")); D2(fprintf(debug_file, "camogm_start_jpeg\n"));
if (slash) { if (slash) {
D3(fprintf(debug_file, "Full path %s\n", state->path)); D3(fprintf(debug_file, "Full path %s\n", state->path));
slash[0] = '\0'; //! truncate path to the directory name slash[0] = '\0'; // truncate path to the directory name
D3(fprintf(debug_file, "directory path %s\n", state->path)); D3(fprintf(debug_file, "directory path %s\n", state->path));
rslt = mkdir(state->path, 0777); rslt = mkdir(state->path, 0777);
D3(fprintf(debug_file, "mkdir (%s, 0777) returned %d, errno=%d\n", state->path, rslt, errno)); D3(fprintf(debug_file, "mkdir (%s, 0777) returned %d, errno=%d\n", state->path, rslt, errno));
......
...@@ -311,7 +311,7 @@ int parse_special(void) ...@@ -311,7 +311,7 @@ int parse_special(void)
// a hack - invlude length'skip if data position (header size is known and there is a gap) // a hack - invlude length'skip if data position (header size is known and there is a gap)
if (strcmp(str, "data_size") == 0) { if (strcmp(str, "data_size") == 0) {
gap = headerSize - lseek(ofd, 0, SEEK_CUR) - 8; gap = headerSize - lseek(ofd, 0, SEEK_CUR) - 8;
if (gap > 0) { //!it should be exactly 0 if there is no gap or >8 if there is if (gap > 0) { //it should be exactly 0 if there is no gap or >8 if there is
D4(fprintf(debug_file, "Inserting a skip tag to compensate for a gap (%d bytes) between the header and the frame data\n", gap)); D4(fprintf(debug_file, "Inserting a skip tag to compensate for a gap (%d bytes) between the header and the frame data\n", gap));
if (gap < 8) { if (gap < 8) {
D0(fprintf(debug_file, "not enough room to insret 'skip' tag - %d (need 8)\n", gap)); D0(fprintf(debug_file, "not enough room to insret 'skip' tag - %d (need 8)\n", gap));
...@@ -321,7 +321,7 @@ int parse_special(void) ...@@ -321,7 +321,7 @@ int parse_special(void)
putBigEndian(gap, 4); putBigEndian(gap, 4);
D4(fprintf(debug_file, "writing string <%s>\n", "skip")); D4(fprintf(debug_file, "writing string <%s>\n", "skip"));
write(ofd, "skip", 4); write(ofd, "skip", 4);
lseek(ofd, gap - 8, SEEK_CUR); //! lseek over the gap and proceed as before lseek(ofd, gap - 8, SEEK_CUR); // lseek over the gap and proceed as before
} }
if (sizes != NULL) { if (sizes != NULL) {
l = 0; l = 0;
......
...@@ -178,7 +178,7 @@ int camogm_frame_ogm(camogm_state *state) ...@@ -178,7 +178,7 @@ int camogm_frame_ogm(camogm_state *state)
* @brief Finish OGM file operation * @brief Finish OGM file operation
* @param[in] state a pointer to a structure containing current state * @param[in] state a pointer to a structure containing current state
* @return 0 if file was saved successfully and negative error code otherwise * @return 0 if file was saved successfully and negative error code otherwise
* @note: zero packets are OK, use them to end file with "last" turned on * @note Zero packets are OK, use them to end file with "last" turned on
*/ */
int camogm_end_ogm(camogm_state *state) int camogm_end_ogm(camogm_state *state)
{ {
......
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
/** @brief The size of file search window. This window is memory mapped. */ /** @brief The size of file search window. This window is memory mapped. */
#define SEARCH_SIZE_WINDOW ((uint64_t)4 * (uint64_t)1048576) #define SEARCH_SIZE_WINDOW ((uint64_t)4 * (uint64_t)1048576)
/** @brief Time window (in seconds) used for disk index search. Index within this window is considered a candidate */ /** @brief Time window (in seconds) used for disk index search. Index within this window is considered a candidate */
#define SEARCH_TIME_WINDOW 600 #define SEARCH_TIME_WINDOW 60
/** @brief File starting marker on a raw device. It corresponds to SOI JPEG marker */ /** @brief File starting marker on a raw device. It corresponds to SOI JPEG marker */
static unsigned char elphelst[] = {0xff, 0xd8}; static unsigned char elphelst[] = {0xff, 0xd8};
/** @brief File ending marker on a raw device. It corresponds to EOI JPEG marker */ /** @brief File ending marker on a raw device. It corresponds to EOI JPEG marker */
...@@ -253,7 +253,6 @@ void dump_index_dir(const struct disk_idir *idir) ...@@ -253,7 +253,6 @@ void dump_index_dir(const struct disk_idir *idir)
{ {
struct disk_index *ind = idir->head; struct disk_index *ind = idir->head;
printf("Head pointer = 0x%p, tail pointer = 0x%p\n", idir->head, idir->tail);
while (ind != NULL) { while (ind != NULL) {
fprintf(debug_file, INDEX_FORMAT_STR, fprintf(debug_file, INDEX_FORMAT_STR,
ind->port, ind->rawtime, ind->usec, ind->f_offset, ind->f_size); ind->port, ind->rawtime, ind->usec, ind->f_offset, ind->f_size);
...@@ -993,7 +992,7 @@ static struct disk_index *find_disk_index(rawdev_buffer *rawdev, struct disk_idi ...@@ -993,7 +992,7 @@ static struct disk_index *find_disk_index(rawdev_buffer *rawdev, struct disk_idi
* @return None * @return None
* @warning The main processing loop of the function is enclosed in @e pthread_cleanup_push and @e pthread_cleanup_pop * @warning The main processing loop of the function is enclosed in @e pthread_cleanup_push and @e pthread_cleanup_pop
* calls. The effect of use of normal @b return or @b break to prematurely leave this loop is undefined. * calls. The effect of use of normal @b return or @b break to prematurely leave this loop is undefined.
* @todo print unrecognized command to debug output file * @todo Print unrecognized command to debug output file
*/ */
void *reader(void *arg) void *reader(void *arg)
{ {
...@@ -1106,6 +1105,7 @@ void *reader(void *arg) ...@@ -1106,6 +1105,7 @@ void *reader(void *arg)
} }
break; break;
case CMD_READ_FILE: case CMD_READ_FILE:
// read single file by offset given
if (index_dir.size > 0) { if (index_dir.size > 0) {
struct disk_index indx; struct disk_index indx;
if (get_indx_args(cmd_ptr, &indx) > 0 && if (get_indx_args(cmd_ptr, &indx) > 0 &&
...@@ -1115,6 +1115,7 @@ void *reader(void *arg) ...@@ -1115,6 +1115,7 @@ void *reader(void *arg)
} }
break; break;
case CMD_FIND_FILE: { case CMD_FIND_FILE: {
// find file by time stamp
struct disk_index indx; struct disk_index indx;
struct disk_index *indx_ptr = NULL; struct disk_index *indx_ptr = NULL;
if (get_timestamp_args(cmd_ptr, &indx) > 0) { if (get_timestamp_args(cmd_ptr, &indx) > 0) {
...@@ -1124,12 +1125,6 @@ void *reader(void *arg) ...@@ -1124,12 +1125,6 @@ void *reader(void *arg)
index_sparse.curr_indx = indx_ptr; index_sparse.curr_indx = indx_ptr;
} else { } else {
indx_ptr = find_nearest_by_time(&index_dir, indx.rawtime); indx_ptr = find_nearest_by_time(&index_dir, indx.rawtime);
/* debug code follows */
if (indx_ptr != NULL)
printf("Index found in pre-built index directory: offset = 0x%llx\n", indx_ptr->f_offset);
else
printf("Index NOT found in pre-built index directory. Probably it should be rebuilt\n");
/* end of debug code */
} }
if (indx_ptr != NULL) if (indx_ptr != NULL)
send_file(rawdev, indx_ptr, fd); send_file(rawdev, indx_ptr, fd);
...@@ -1137,6 +1132,7 @@ void *reader(void *arg) ...@@ -1137,6 +1132,7 @@ void *reader(void *arg)
break; break;
} }
case CMD_NEXT_FILE: { case CMD_NEXT_FILE: {
// read next file after previously found file
struct range rng; struct range rng;
struct disk_index *new_indx = NULL; struct disk_index *new_indx = NULL;
struct disk_index *indx_ptr = NULL; struct disk_index *indx_ptr = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment