Commit 6be06d67 authored by Andrey Filippov's avatar Andrey Filippov

Before overlapping raw write

parent 8ec453e8
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.compiler.option.include.paths.864295621" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.compiler.option.include.paths.864295621" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include&quot;"/> <listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include-uapi&quot;"/> <listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include-uapi&quot;"/>
<listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include/ogg&quot;"/>
</option> </option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.2002029678" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.2002029678" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool> </tool>
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.1604866480" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.include.paths.1604866480" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include&quot;"/> <listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include-uapi&quot;"/> <listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include-uapi&quot;"/>
<listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include/ogg&quot;"/>
</option> </option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.preprocessor.def.symbols.1399974758" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.c.compiler.option.preprocessor.def.symbols.1399974758" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="__arm__=1"/> <listOptionValue builtIn="false" value="__arm__=1"/>
...@@ -51,6 +53,7 @@ ...@@ -51,6 +53,7 @@
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.both.asm.option.include.paths.1372301239" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.both.asm.option.include.paths.1372301239" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include&quot;"/> <listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include-uapi&quot;"/> <listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include-uapi&quot;"/>
<listOptionValue builtIn="false" value="&quot;${PWD}/sysroots/usr/include/ogg&quot;"/>
</option> </option>
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.308294150" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> <inputType id="cdt.managedbuild.tool.gnu.assembler.input.308294150" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool> </tool>
...@@ -95,4 +98,4 @@ ...@@ -95,4 +98,4 @@
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject> </cproject>
\ No newline at end of file
...@@ -573,7 +573,7 @@ int sendImageFrame(camogm_state *state) ...@@ -573,7 +573,7 @@ int sendImageFrame(camogm_state *state)
} }
// 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\n", 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
} }
...@@ -583,7 +583,7 @@ int sendImageFrame(camogm_state *state) ...@@ -583,7 +583,7 @@ int sendImageFrame(camogm_state *state)
//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\n")); //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
} }
...@@ -691,7 +691,7 @@ int sendImageFrame(camogm_state *state) ...@@ -691,7 +691,7 @@ int sendImageFrame(camogm_state *state)
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];
state->writer_params.segments = 1; state->writer_params.segments = 1;
} }
D3(fprintf(debug_file, "\tcirbuf_rp = 0x%x\t", state->cirbuf_rp[port])); D3(fprintf(debug_file, "\tcirbuf_rp[%d] = 0x%x\t", port, state->cirbuf_rp[port]));
D3(fprintf(debug_file, "_12_")); D3(fprintf(debug_file, "_12_"));
if (state->this_frame_params[port].color != COLORMODE_RAW) { // Tiff if (state->this_frame_params[port].color != COLORMODE_RAW) { // Tiff
state->packetchunks[state->chunk_index ].bytes = 2; state->packetchunks[state->chunk_index ].bytes = 2;
...@@ -1673,10 +1673,10 @@ int listener_loop(camogm_state *state) ...@@ -1673,10 +1673,10 @@ int listener_loop(camogm_state *state)
} }
#endif #endif
} else if (state->prog_state == STATE_RUNNING) { // no commands in queue, started } else if (state->prog_state == STATE_RUNNING) { // no commands in queue, started
D6(fprintf(debug_file, "state->prog_state == STATE_RUNNING ")); D6(fprintf(debug_file, "state->prog_state == STATE_RUNNING "));
switch ((rslt = -sendImageFrame(state))) { rslt = -sendImageFrame(state);
D6(fprintf(debug_file, " ==> %d",rslt)); D6(fprintf(debug_file, " ==> %d",rslt));
switch (rslt) {
case 0: case 0:
break; // frame sent OK, nothing to do (TODO: check file length/duration) break; // frame sent OK, nothing to do (TODO: check file length/duration)
case CAMOGM_FRAME_NOT_READY: // just wait for the frame to appear at the current pointer case CAMOGM_FRAME_NOT_READY: // just wait for the frame to appear at the current pointer
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
/** @brief This define is needed to use lseek64 and should be set before includes */ /** @brief This define is needed to use lseek64 and should be set before includes */
#define _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE
#define ALIGN_INTERFRAME // New alignment mode - add zeros between frames (TIFF also), not inside JPEG with app15 (JPEG only)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -31,6 +31,7 @@ static unsigned char app15[ALIGNMENT_SIZE] = {0xff, 0xef}; ...@@ -31,6 +31,7 @@ static unsigned char app15[ALIGNMENT_SIZE] = {0xff, 0xef};
static inline size_t get_size_from(const struct iovec *vects, int index, size_t offset, int all); static inline size_t get_size_from(const struct iovec *vects, int index, size_t offset, int all);
static inline size_t align_bytes_num(size_t data_len, size_t align_len); static inline size_t align_bytes_num(size_t data_len, size_t align_len);
static inline void vectcpy(struct iovec *dest, void *src, size_t len); static inline void vectcpy(struct iovec *dest, void *src, size_t len);
static inline void vectset(struct iovec *dest, int src, size_t len);
static inline void vectshrink(struct iovec *vec, size_t len); static inline void vectshrink(struct iovec *vec, size_t len);
static inline void vectshrinkhead(struct iovec *vec, size_t len); static inline void vectshrinkhead(struct iovec *vec, size_t len);
static inline unsigned char *vectrpos(struct iovec *vec, size_t offset); static inline unsigned char *vectrpos(struct iovec *vec, size_t offset);
...@@ -61,6 +62,17 @@ static inline void vectcpy(struct iovec *dest, void *src, size_t len) ...@@ -61,6 +62,17 @@ static inline void vectcpy(struct iovec *dest, void *src, size_t len)
dest->iov_len += len; dest->iov_len += len;
} }
/** Set @e len bytes with @e src to buffer pointed by @e dest vector */
static inline void vectset(struct iovec *dest, int src, size_t len)
{
unsigned char *d = (unsigned char *)dest->iov_base;
memset(d + dest->iov_len, src, len);
dest->iov_len += len;
}
/** Shrink vector length by @len bytes */ /** Shrink vector length by @len bytes */
static inline void vectshrink(struct iovec *vec, size_t len) static inline void vectshrink(struct iovec *vec, size_t len)
{ {
...@@ -110,7 +122,7 @@ static inline size_t get_size_from(const struct iovec *vects, int index, size_t ...@@ -110,7 +122,7 @@ static inline size_t get_size_from(const struct iovec *vects, int index, size_t
return total; return total;
} }
/** Return the number of bytes needed to align @e data_len to @e align_len boundary */ /** Return the number of bytes needed to be inserted to align @e data_len to @e align_len boundary */
static inline size_t align_bytes_num(size_t data_len, size_t align_len) static inline size_t align_bytes_num(size_t data_len, size_t align_len)
{ {
size_t rem = data_len % align_len; size_t rem = data_len % align_len;
...@@ -160,10 +172,12 @@ static void remap_vectors(camogm_state *state, struct iovec *chunks) ...@@ -160,10 +172,12 @@ static void remap_vectors(camogm_state *state, struct iovec *chunks)
chunks[CHUNK_DATA_1].iov_base = chunks[CHUNK_DATA_0].iov_base; chunks[CHUNK_DATA_1].iov_base = chunks[CHUNK_DATA_0].iov_base;
chunks[CHUNK_DATA_1].iov_len = 0; chunks[CHUNK_DATA_1].iov_len = 0;
} }
chunks[CHUNK_TRAILER].iov_base = (void *)state->packetchunks[chunk_index].chunk; // chunks[CHUNK_TRAILER].iov_base = (void *)state->packetchunks[chunk_index].chunk;
if (is_tiff) { // Tiff if (is_tiff) { // Tiff
chunks[CHUNK_TRAILER].iov_base = (void *)state->packetchunks[chunk_index-1].chunk; // last used chunk (valid)
chunks[CHUNK_TRAILER].iov_len = 0; chunks[CHUNK_TRAILER].iov_len = 0;
} else { } else {
chunks[CHUNK_TRAILER].iov_base = (void *)state->packetchunks[chunk_index].chunk;
chunks[CHUNK_TRAILER].iov_len = state->packetchunks[chunk_index].bytes; chunks[CHUNK_TRAILER].iov_len = state->packetchunks[chunk_index].bytes;
} }
...@@ -288,7 +302,7 @@ void align_frame(camogm_state *state) ...@@ -288,7 +302,7 @@ void align_frame(camogm_state *state)
remap_vectors(state, chunks); remap_vectors(state, chunks);
total_sz = get_size_from(chunks, 0, 0, INCLUDE_REM) + rbuff->iov_len; total_sz = get_size_from(chunks, 0, 0, INCLUDE_REM) + rbuff->iov_len;
D4(fprintf(debug_file, "total_sz = %d\n", total_sz)); D4(fprintf(debug_file, "total_sz = %d, rbuff->iov_len=%d\n", total_sz, (int)(rbuff->iov_len)));
if (total_sz < PHY_BLOCK_SIZE) { if (total_sz < PHY_BLOCK_SIZE) {
/* the frame length is less than sector size, delay this frame */ /* the frame length is less than sector size, delay this frame */
if (rbuff->iov_len != 0) { if (rbuff->iov_len != 0) {
...@@ -321,6 +335,14 @@ void align_frame(camogm_state *state) ...@@ -321,6 +335,14 @@ void align_frame(camogm_state *state)
vectshrink(rbuff, rbuff->iov_len); vectshrink(rbuff, rbuff->iov_len);
} }
/*Calculate alignment size and add zeros here*/
#ifdef ALIGN_INTERFRAME
// calculate length after adding CHUNK_LEADER, CHUNK_EXIF and CHUNK_HEADER to the current cbuf
data_len = cbuff->iov_len + chunks[CHUNK_LEADER].iov_len + chunks[CHUNK_EXIF].iov_len+ chunks[CHUNK_HEADER].iov_len;
len = align_bytes_num(data_len, ALIGNMENT_SIZE);
dev_dbg(dev, "total number of stuffing bytes between frames: %u\n", len);
vectset(cbuff, 0, len);
#endif
/* copy JPEG marker if present */ /* copy JPEG marker if present */
if (chunks[CHUNK_LEADER].iov_len != 0) { if (chunks[CHUNK_LEADER].iov_len != 0) {
len = chunks[CHUNK_LEADER].iov_len; len = chunks[CHUNK_LEADER].iov_len;
...@@ -336,6 +358,16 @@ void align_frame(camogm_state *state) ...@@ -336,6 +358,16 @@ void align_frame(camogm_state *state)
vectshrink(&chunks[CHUNK_EXIF], chunks[CHUNK_EXIF].iov_len); vectshrink(&chunks[CHUNK_EXIF], chunks[CHUNK_EXIF].iov_len);
} }
#ifdef ALIGN_INTERFRAME
/* copy JPEG JPEG header data excluding leading marker if present */
if (chunks[CHUNK_HEADER].iov_len != 0) {
len = chunks[CHUNK_HEADER].iov_len;
dev_dbg(dev, "copy %u bytes from LEADER to common buffer\n", len);
vectcpy(cbuff, chunks[CHUNK_HEADER].iov_base, len);
vectshrink(&chunks[CHUNK_HEADER], chunks[CHUNK_HEADER].iov_len);
}
#else // old way with app15
if (chunks[CHUNK_HEADER].iov_len != 0){ // only if it is not TIFF if (chunks[CHUNK_HEADER].iov_len != 0){ // only if it is not TIFF
/* align common buffer to ALIGNMENT boundary, APP15 marker should be placed before header data */ /* align common buffer to ALIGNMENT boundary, APP15 marker should be placed before header data */
data_len = cbuff->iov_len + chunks[CHUNK_HEADER].iov_len; data_len = cbuff->iov_len + chunks[CHUNK_HEADER].iov_len;
...@@ -362,13 +394,13 @@ void align_frame(camogm_state *state) ...@@ -362,13 +394,13 @@ void align_frame(camogm_state *state)
vectshrinkhead(&chunks[CHUNK_DATA_0],len); vectshrinkhead(&chunks[CHUNK_DATA_0],len);
} }
} }
#endif
/* check if there is enough data to continue - JPEG data length can be too short */ /* check if there is enough data to continue - JPEG data length can be too short */
len = get_size_from(chunks, CHUNK_DATA_0, 0, EXCLUDE_REM); len = get_size_from(chunks, CHUNK_DATA_0, 0, EXCLUDE_REM);
if (len < PHY_BLOCK_SIZE) { if (len < PHY_BLOCK_SIZE) {
size_t num = align_bytes_num(cbuff->iov_len, PHY_BLOCK_SIZE); size_t num = align_bytes_num(cbuff->iov_len, PHY_BLOCK_SIZE);
dev_dbg(dev, "jpeg data is too short, delay this frame\n"); dev_dbg(dev, "jpeg data is too short, delay this frame\n"); // never happened?
if (len >= num) { if (len >= num) {
/* there is enough data to align common buffer to sector boundary */ /* there is enough data to align common buffer to sector boundary */
if (num >= chunks[CHUNK_DATA_0].iov_len) { if (num >= chunks[CHUNK_DATA_0].iov_len) {
......
...@@ -193,6 +193,7 @@ def get_disk_size(dev_path): ...@@ -193,6 +193,7 @@ def get_disk_size(dev_path):
return 0 return 0
if (label == 'unknown'): if (label == 'unknown'):
#print("unknown label, running parted -s /dev/sda mklabel msdos!") #print("unknown label, running parted -s /dev/sda mklabel msdos!")
print ("Disregard 'Error: /dev/sda: unrecognised disk label' above ")
try: try:
parted_print = subprocess.check_output(['parted', '-s', dev_path, 'mklabel', 'msdos']) parted_print = subprocess.check_output(['parted', '-s', dev_path, 'mklabel', 'msdos'])
except: except:
...@@ -266,7 +267,7 @@ if __name__ == "__main__": ...@@ -266,7 +267,7 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description = "Prepare and partition new disk for fast recording from camogm") parser = argparse.ArgumentParser(description = "Prepare and partition new disk for fast recording from camogm")
parser.add_argument('disk_path', nargs = '?', help = "path to a disk which should be partitioned, e.g /dev/sda") parser.add_argument('disk_path', nargs = '?', help = "path to a disk which should be partitioned, e.g /dev/sda")
parser.add_argument('-l', '--list', action = 'store_true', help = "list attached disk(s) suitable for partitioning along " + parser.add_argument('-l', '--list', action = 'store_true', help = "list attached disk(s) suitable for partitioning along " +
"with their totals sizes and possible system partition sizes separated by colon") "with their totals sizes and possible system partition sizes separated by colon. -lf - include already partitioned.")
parser.add_argument('-e', '--errno', nargs = 1, type = int, help = "convert error number returned by the script to error message") parser.add_argument('-e', '--errno', nargs = 1, type = int, help = "convert error number returned by the script to error message")
parser.add_argument('-d', '--dry_run', action = 'store_true', help = "execute the script but do not actually create partitions") parser.add_argument('-d', '--dry_run', action = 'store_true', help = "execute the script but do not actually create partitions")
parser.add_argument('-f', '--force', action = 'store_true', help = "force 'mkfs' to create a file system and re-format existing partitions") parser.add_argument('-f', '--force', action = 'store_true', help = "force 'mkfs' to create a file system and re-format existing partitions")
...@@ -295,18 +296,19 @@ if __name__ == "__main__": ...@@ -295,18 +296,19 @@ if __name__ == "__main__":
disks = find_disks(True) disks = find_disks(True)
if disks: if disks:
disk_path = disks[0] disk_path = disks[0]
"""
if (disk_path != ""): # if (disk_path != ""):
print (disk_path) # print (disk_path) #first line output
else: # else:
print ("disk_path empty") # print ("disk_path empty")
"""
if (disk_path != ""): if (disk_path != ""):
with open("/proc/mounts", "r") as file: with open("/proc/mounts", "r") as file:
content = file.read() content = file.read()
if (content.find(disk_path) > 0): # <0 - not founed if (content.find(disk_path) > 0): # <0 - not founed
# print (disk_path+" is mounted") # print (disk_path+" is mounted")
mount_point = content[content.find(disk_path):].split()[1] mount_point = content[content.find(disk_path):].split()[1]
# print ("mount_point=",mount_point)
# try to unmount # try to unmount
try: try:
subprocess.check_output(['umount', mount_point]) subprocess.check_output(['umount', mount_point])
...@@ -315,6 +317,8 @@ if __name__ == "__main__": ...@@ -315,6 +317,8 @@ if __name__ == "__main__":
ret_code.err_code = ErrCodes.PART_MOUINTED ret_code.err_code = ErrCodes.PART_MOUINTED
print(ret_code.err2str()) print(ret_code.err2str())
sys.exit(ret_code.err_code) sys.exit(ret_code.err_code)
# print ("umount")
disk_name = disk_path[:8]# /dev/sdx disk_name = disk_path[:8]# /dev/sdx
#delete MBR on this device : dd if=/dev/zero of=/dev/sda bs=512 count=1 #delete MBR on this device : dd if=/dev/zero of=/dev/sda bs=512 count=1
try: try:
...@@ -361,6 +365,7 @@ if __name__ == "__main__": ...@@ -361,6 +365,7 @@ if __name__ == "__main__":
ret_code.err_code = ErrCodes.WRONG_PATH ret_code.err_code = ErrCodes.WRONG_PATH
else: else:
ret_code.err_code = ErrCodes.WRONG_PATH ret_code.err_code = ErrCodes.WRONG_PATH
if ret_code.err_code != ErrCodes.OK: if ret_code.err_code != ErrCodes.OK:
print(ret_code.err2str()) print(ret_code.err2str())
sys.exit(ret_code.err_code) sys.exit(ret_code.err_code)
......
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