Commit bff5f99c authored by Andrey Filippov's avatar Andrey Filippov

minor cleanup before increasing threads

parent 1070f517
......@@ -281,12 +281,10 @@ void camogm_init(camogm_state *state, char *pipe_name, uint16_t port_num)
state->rawdev.mmap_default_size = MMAP_CHUNK_SIZE; // only used for camogm_read
state->sock_port = port_num;
// state->writer_params.data_ready = false;
state->writer_params.chunk_page_prep = 0; // will prepare page 0
state->writer_params.chunk_page_write = 0; // will write page 0
state->writer_params.writev_run = false;
state->writer_params.exit_thread = false;
state->writer_params.state = STATE_STOPPED;
......@@ -559,7 +557,7 @@ int sendImageFrame(camogm_state *state)
// This is probably needed only for Quicktime (not to exceed already allocated frame index)
if (!state->rawdev_op && (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_NEXTFILE;
}
// Format changed?
// D3(fprintf (debug_file,"sendImageFrame: format=%d, set_format=%d\n", state->format, state->set_format));
......@@ -569,14 +567,14 @@ int sendImageFrame(camogm_state *state)
return -CAMOGM_FRAME_CHANGED;
}
// 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->rawdev_op && (state->vf) && (state->segment_length >= 0) && (ftell(state->vf) > state->segment_length)) {
D3(fprintf(debug_file, "sendImageFrame:3: segment length exceeded\n"));
return -CAMOGM_FRAME_CHANGED;
return -CAMOGM_FRAME_NEXTFILE;
}
//same for open
if (!state->rawdev_op && ((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"));
return -CAMOGM_FRAME_CHANGED;
return -CAMOGM_FRAME_NEXTFILE;
}
// check the frame pointer is valid
if ((fp = lseek(state->fd_circ[port], state->cirbuf_rp[port], SEEK_SET)) < 0) {
......@@ -733,7 +731,7 @@ int sendImageFrame(camogm_state *state)
state->frameno++;
state->cirbuf_rp[port] = lseek(state->fd_circ[port], LSEEK_CIRC_NEXT, SEEK_END);
if (state->cirbuf_rp[port] < 0) {
D2(fprintf(debug_file, "_14a_: sendImageFrame(): frame broken - buffer overrun\n"));
D0(fprintf(debug_file, "_14a_: sendImageFrame(): frame broken - buffer overrun\n"));
return -CAMOGM_FRAME_BROKEN;
}
......@@ -748,16 +746,6 @@ int sendImageFrame(camogm_state *state)
}
D3(fprintf(debug_file,"cirbuf_rp to next frame = 0x%x\n", state->cirbuf_rp[port]));
// end_time = get_fpga_time(state->fd_fparmsall[port], port);
// unsigned int mbps; // write speed, MB/s
// unsigned long long time_diff; // time elapsed, in microseconds
// time_diff = ((end_time.tv_sec * 1000000 + end_time.tv_usec) - (start_time.tv_sec * 1000000 + start_time.tv_usec));
// mbps = ((double)state->rawdev.last_jpeg_size / (double)1048576) / ((double)time_diff / (double)1000000);
// D6(fprintf(debug_file, "Frame start time: %ld:%ld; frame end time: %ld:%ld; last frame size: %lu\n",
// start_time.tv_sec, start_time.tv_usec,
// end_time.tv_sec, end_time.tv_usec,
// state->rawdev.last_jpeg_size));
// D6(fprintf(debug_file, "Write speed: %d MB/s\n", mbps));
D6(fprintf(debug_file, "Exit sendImageFrame() OK @ %07d\n",get_fpga_usec(state->fd_fparmsall[0], 0)));
return 0;
......@@ -1718,29 +1706,13 @@ int listener_loop(camogm_state *state)
D6(fprintf(debug_file, "No compressed frame ready, waited for the next frame sync for port %d @ %07d\n",curr_port,get_fpga_usec(state->fd_fparmsall[0], 0)));
break;
// do not analyze next frame (may be non-existing), will do that next time
/*
fp0 = lseek(state->fd_circ[curr_port], 0, SEEK_CUR); // need to skip uncompressed frame, LWIR16 turns compressor off
if (fp0 < 0) {
D0(fprintf(debug_file, "%s:line %d got broken frame (%d) before waiting for ready\n", __FILE__, __LINE__, fp0));
rslt = CAMOGM_FRAME_BROKEN;
} else {
fp1 = lseek(state->fd_circ[curr_port], LSEEK_CIRC_WAIT, SEEK_END);
if (fp1 < 0) {
D0(fprintf(debug_file, "%s:line %d got broken frame (%d) while waiting for ready. Before that fp0=0x%x\n", __FILE__, __LINE__, fp1, fp0));
rslt = CAMOGM_FRAME_BROKEN;
} else {
D6(fprintf(debug_file, "No compressed frame ready, skipped 1 frame sync for port %d @ %07d\n",curr_port,get_fpga_usec(state->fd_fparmsall[0], 0)));
break;
}
}
*/
// no break
case CAMOGM_FRAME_CHANGED: // frame parameters have changed
case CAMOGM_FRAME_NEXTFILE: // next file needed (need to switch to a new file (time/size exceeded limit)
case CAMOGM_FRAME_INVALID: // invalid frame pointer
case CAMOGM_FRAME_BROKEN: // frame broken (buffer overrun)
// restart the file
D3(fprintf(debug_file,"%s:line %d - sendImageFrame() returned -%d\n", __FILE__, __LINE__, rslt));
D0(fprintf(debug_file,"%s:line %d - sendImageFrame() returned -%d\n", __FILE__, __LINE__, rslt));
camogm_stop(state);
state->prog_state = STATE_RESTARTING;
camogm_start(state);
......@@ -2048,8 +2020,6 @@ unsigned int select_port(camogm_state *state)
}
}
if ((state->prog_state == STATE_STARTING) || (state->prog_state == STATE_RUNNING)) {
// if (lseek(state->fd_circ[port], LSEEK_CIRC_READY, SEEK_END) < 0) {
// fprintf(debug_file, "selected port: %i, min free size = %08ld @ %07d\n", chn, min_sz, get_fpga_usec(state->fd_fparmsall[0], 0));
D1(if ((chn >=0) && (lseek(state->fd_circ[chn], LSEEK_CIRC_READY, SEEK_END) >= 0)) \
fprintf(debug_file, "selected port: %i, min free size = %08ld ", chn, min_sz); \
else if (debug_level >= 6) fprintf(debug_file,"no port is ready @ %07d\n", get_fpga_usec(state->fd_fparmsall[0], 0)));
......
......@@ -92,7 +92,6 @@
#define JPEG_TRAILER_LEN 2 ///< The size in bytes of JPEG trailer
#define CIRCBUF_ALIGNMENT_SIZE 32 ///< Align of CIRCBUF entries
// Switching CHUNK -> SEGMENT
#define PAGE_PHYS 4096 // 512 // alignment size for O_DIRECT, may be different from LBA block size that is 512
enum segments {
......
......@@ -323,7 +323,7 @@ void reset_segments(camogm_state *state, int all, int page)
}
/** Convert LBA to byte offset used for lseek */
off64_t lba_to_offset(uint64_t lba)
uint64_t lba_to_offset(uint64_t lba)
//uint64_t lba_to_offset(uint64_t lba)
{
return lba * PHY_BLOCK_SIZE;
......
......@@ -24,24 +24,10 @@
#include "camogm.h"
// TODO: Change PHY_BLOCK_SIZE to 4096 as it is 4096 - no, most SSDs are still 512
#define PHY_BLOCK_SIZE 512 ///< Physical disk block size - still 512 even for the OS with 4096
//#define PHY_BLOCK_SIZE 4096 ///< Physical disk block size
//#define JPEG_MARKER_LEN 2 ///< The size in bytes of JPEG marker
#define JPEG_SIZE_LEN 2 ///< The size in bytes of JPEG marker length field
#define INCLUDE_REM 1 ///< Include REM buffer to total size calculation
#define EXCLUDE_REM 0 ///< Exclude REM buffer from total size calculation
#if 0
#define MAX_DATA_CHUNKS 9 ///< An array or JPEG frame chunks contains pointers to JPEG leading marker,
///< JPEG header, Exif data if present, stuffing bytes chunk which aligns
///< the frame size to disk sector boundary, JPEG data which
///< can be split into two chunks, align buffers, JPEG
///< trailing marker, and pointer to a buffer containing the remainder of a
///< frame. Nine chunks of data in total.
///
#define ALIGNMENT_SIZE 32 ///< Align buffers length to this amount of bytes
/** Common buffer should be large enough to contain JPEG header, Exif, some alignment bytes and remainder from previous frame */
#define COMMON_BUFF_SZ MAX_EXIF_SIZE + JPEG_HEADER_MAXSIZE + ALIGNMENT_SIZE + 2 * PHY_BLOCK_SIZE
#define REM_BUFF_SZ 2 * PHY_BLOCK_SIZE
#endif
/** Symbolic names for slots in buffer pointers. Buffer alignment function relies on the order of these names, so
* new names can be added but the overall order should not be changed */
......@@ -62,7 +48,7 @@ int init_align_buffers(camogm_state *state);
void deinit_align_buffers(camogm_state *state);
void reset_segments(camogm_state *state, int all, int page);
size_t remap_vectors(camogm_state *state); //, struct iovec *chunks);
off64_t lba_to_offset(uint64_t lba);
uint64_t lba_to_offset(uint64_t lba);
int vectaligntail(struct iovec *dest);
......
This diff is collapsed.
......@@ -727,7 +727,7 @@ static void start_test(camogm_state *state, const unsigned long max_cntr, const
{
int fd;
bool report_lba = true;
off64_t pos, current_lba, end_pos;
uint64_t pos, current_lba, end_pos;
unsigned int cntr, error_lba_cntr;
unsigned int data[BLOCK_SIZE_DW] = {0};
......
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