Loading Makefile +2 −3 Original line number Diff line number Diff line Loading @@ -17,9 +17,8 @@ PROGS = camogm PHPFILES = camogmstate.php SRCS = camogm.c camogm_ogm.c camogm_jpeg.c camogm_mov.c camogm_kml.c camogm_read.c OBJS = camogm.o camogm_ogm.o camogm_jpeg.o camogm_mov.o camogm_kml.o camogm_read.o SRCS = camogm.c camogm_ogm.c camogm_jpeg.c camogm_mov.c camogm_kml.c camogm_read.c index_list.c OBJS = camogm.o camogm_ogm.o camogm_jpeg.o camogm_mov.o camogm_kml.o camogm_read.o index_list.o CFLAGS += -Wall -I$(ELPHEL_KERNEL_DIR)/include/elphel #CFLAGS += -Wall -I$(INCDIR) -I$(ELPHEL_KERNEL_DIR)/include/elphel Loading camogm_read.c +3 −124 Original line number Diff line number Diff line Loading @@ -47,11 +47,14 @@ #include <sys/stat.h> #include "camogm_read.h" #include "index_list.h" /** @brief Offset in Exif where TIFF header starts */ #define TIFF_HDR_OFFSET 12 /** @brief The date and time format of Exif field */ #define EXIF_DATE_TIME_FORMAT "%Y:%m:%d %H:%M:%S" /** @brief The format string used for file parameters reporting. Time and port number are extracted from Exif */ #define INDEX_FORMAT_STR "port_number=%d;unix_time=%ld;usec_time=%06u;offset=0x%010llx;file_size=%u\n" /** @brief The delimiters used to separate several commands in one command string sent over socket */ #define CMD_DELIMITER "/?" /** @brief The length of a buffer for command string */ Loading @@ -60,8 +63,6 @@ #define SMALL_BUFF_LEN 32 /** @brief 64 bit mask to align offsets to 4 kb page boundary */ #define PAGE_BOUNDARY_MASK 0xffffffffffffe000 /** @brief The format string used for file parameters reporting. Time and port number are extracted from Exif */ #define INDEX_FORMAT_STR "port_number=%d;unix_time=%ld;usec_time=%06u;offset=0x%010llx;file_size=%u\n" /** @brief The size of read buffer in bytes. The data will be read from disk in blocks of this size */ #define PHY_BLK_SZ 4096 /** @brief Include or exclude file start and stop markers from resulting file. This must be set to 1 for JPEG files */ Loading Loading @@ -247,128 +248,6 @@ void dump_index_dir(const struct disk_idir *idir) } } /** * @brief Create a new node in a linked list of disk indexes * @param[in,out] index pointer to a newly allocated structure * @return 0 in case a new disk index structure was successfully created and -1 otherwise */ int create_node(struct disk_index **index) { if (*index != NULL) return -1; *index = malloc(sizeof(struct disk_index)); if (*index != NULL) { memset(*index, 0, sizeof(struct disk_index)); return 0; } else { return -1; } } /** * @brief Add a new index node to disk index directory * @param[in,out] idir pointer to disk index directory * @param[in] index pointer to index node to be added to disk index directory * @return The number of entries in disk index directory */ int add_node(struct disk_idir *idir, struct disk_index *index) { if (idir->head == NULL && idir->tail == NULL) { idir->head = index; idir->tail = index; idir->size = 1; } else { index->prev = idir->tail; idir->tail->next = index; idir->tail = index; idir->size++; } return idir->size; } /** * @brief Find index node by its start offset * @param[in] idir pointer to disk index directory * @param[in] offset the offset of the file which should be found * @return pointer to disk index node or NULL if the corresponding file was not found */ struct disk_index *find_by_offset(const struct disk_idir *idir, uint64_t offset) { struct disk_index *index = idir->head; while (index != NULL) { if (index->f_offset == offset) break; index = index->next; } return index; } /** * @brief Remove a single index node from disk index directory * @param[in,out] idir pointer to disk index directory * @param[in] node pointer to the index node which should be removed * @return The number of entries in disk index directory */ int remove_node(struct disk_idir *idir, struct disk_index *node) { if (node == NULL) return -1; if (node == idir->head) { idir->head = node->next; idir->head->prev = NULL; } else if (node == idir->tail) { idir->tail = node->prev; idir->tail->next = NULL; } else { struct disk_index *ind = idir->head; while (ind != NULL) { if (ind == node) { ind->prev->next = ind->next; ind->next->prev = ind->prev; break; } ind = ind->next; } } free(node); node = NULL; idir->size--; return idir->size; } /** * Remove all entries from disk index directory an free memory * @param[in] idir pointer to disk index directory * @return 0 in case the directory was successfully deleted and -1 if the directory was empty */ int delete_idir(struct disk_idir *idir) { struct disk_index *curr_ind; struct disk_index *next_ind; if (idir == NULL || idir->head == NULL) return -1; curr_ind = idir->head; next_ind = curr_ind->next; while (curr_ind != NULL) { free(curr_ind); curr_ind = next_ind; if (curr_ind != NULL) next_ind = curr_ind->next; } idir->head = idir->tail = NULL; idir->size = 0; return 0; } /** * @brief Find pattern in a data buffer * Loading camogm_read.h +0 −46 Original line number Diff line number Diff line Loading @@ -19,52 +19,6 @@ #include "camogm.h" /** * @struct disk_index * @brief Contains a single entry into disk index directory. Each node in * the disk index directory corresponds to a file in the raw device buffer and * hold its starting offset, sensor port number, time stamp and file size. * @var disk_index::next * Pointer to the next index node * @var disk_index::prev * Pointer to the previous disk index node * @var disk_index::rawtime * Time stamp in UNIX format * @var disk_index::usec * The microsecond part of the time stamp * @var disk_index::port * The sensor port number this frame was captured from * @var disk_index::f_size * File size in bytes * @var disk_index::f_offset * The offset of the file start in the raw device buffer (in bytes) */ struct disk_index { struct disk_index *next; struct disk_index *prev; time_t rawtime; unsigned int usec; uint32_t port; size_t f_size; uint64_t f_offset; }; /** * @struct disk_idir * @brief Contains pointers to disk index directory * @var disk_idir::head * Pointer to the first node of disk index directory * @var disk_idir::tail * Pointer to the last node of disk index directory * @var disk_idir::size * The number of nodes in disk index directory */ struct disk_idir { struct disk_index *head; struct disk_index *tail; size_t size; }; /** * @struct range * @brief Container for offsets in raw device buffer Loading index_list.c 0 → 100644 +143 −0 Original line number Diff line number Diff line /** @file index_list.c * @brief Provides data structures and functions for working with disk index directory * @copyright Copyright (C) 2016 Elphel, Inc. * * <b>License:</b> * 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/>. */ #include <stdlib.h> #include <string.h> #include "index_list.h" /** * @brief Create a new node in a linked list of disk indexes * @param[in,out] index pointer to a newly allocated structure * @return 0 in case a new disk index structure was successfully created and -1 otherwise */ int create_node(struct disk_index **index) { if (*index != NULL) return -1; *index = malloc(sizeof(struct disk_index)); if (*index != NULL) { memset(*index, 0, sizeof(struct disk_index)); return 0; } else { return -1; } } /** * @brief Add a new index node to disk index directory * @param[in,out] idir pointer to disk index directory * @param[in] index pointer to index node to be added to disk index directory * @return The number of entries in disk index directory */ int add_node(struct disk_idir *idir, struct disk_index *index) { if (idir->head == NULL && idir->tail == NULL) { idir->head = index; idir->tail = index; idir->size = 1; } else { index->prev = idir->tail; idir->tail->next = index; idir->tail = index; idir->size++; } return idir->size; } /** * @brief Find index node by its start offset * @param[in] idir pointer to disk index directory * @param[in] offset the offset of the file which should be found * @return pointer to disk index node or NULL if the corresponding file was not found */ struct disk_index *find_by_offset(const struct disk_idir *idir, uint64_t offset) { struct disk_index *index = idir->head; while (index != NULL) { if (index->f_offset == offset) break; index = index->next; } return index; } /** * @brief Remove a single index node from disk index directory * @param[in,out] idir pointer to disk index directory * @param[in] node pointer to the index node which should be removed * @return The number of entries in disk index directory */ int remove_node(struct disk_idir *idir, struct disk_index *node) { if (node == NULL) return -1; if (node == idir->head) { idir->head = node->next; idir->head->prev = NULL; } else if (node == idir->tail) { idir->tail = node->prev; idir->tail->next = NULL; } else { struct disk_index *ind = idir->head; while (ind != NULL) { if (ind == node) { ind->prev->next = ind->next; ind->next->prev = ind->prev; break; } ind = ind->next; } } free(node); node = NULL; idir->size--; return idir->size; } /** * Remove all entries from disk index directory an free memory * @param[in] idir pointer to disk index directory * @return 0 in case the directory was successfully deleted and -1 if the directory was empty */ int delete_idir(struct disk_idir *idir) { struct disk_index *curr_ind; struct disk_index *next_ind; if (idir == NULL || idir->head == NULL) return -1; curr_ind = idir->head; next_ind = curr_ind->next; while (curr_ind != NULL) { free(curr_ind); curr_ind = next_ind; if (curr_ind != NULL) next_ind = curr_ind->next; } idir->head = idir->tail = NULL; idir->size = 0; return 0; } index_list.h 0 → 100644 +75 −0 Original line number Diff line number Diff line /** @file index_list.h * @brief Provides data structures and functions for working with disk index directory * @copyright Copyright (C) 2016 Elphel, Inc. * * <b>License:</b> * 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/>. */ #ifndef _INDEX_LIST_H #define _INDEX_LIST_H #include <stdint.h> /** * @struct disk_index * @brief Contains a single entry into disk index directory. Each node in * the disk index directory corresponds to a file in the raw device buffer and * hold its starting offset, sensor port number, time stamp and file size. * @var disk_index::next * Pointer to the next index node * @var disk_index::prev * Pointer to the previous disk index node * @var disk_index::rawtime * Time stamp in UNIX format * @var disk_index::usec * The microsecond part of the time stamp * @var disk_index::port * The sensor port number this frame was captured from * @var disk_index::f_size * File size in bytes * @var disk_index::f_offset * The offset of the file start in the raw device buffer (in bytes) */ struct disk_index { struct disk_index *next; struct disk_index *prev; time_t rawtime; unsigned int usec; uint32_t port; size_t f_size; uint64_t f_offset; }; /** * @struct disk_idir * @brief Contains pointers to disk index directory * @var disk_idir::head * Pointer to the first node of disk index directory * @var disk_idir::tail * Pointer to the last node of disk index directory * @var disk_idir::size * The number of nodes in disk index directory */ struct disk_idir { struct disk_index *head; struct disk_index *tail; size_t size; }; void dump_index_dir(const struct disk_idir *idir); int create_node(struct disk_index **index); int add_node(struct disk_idir *idir, struct disk_index *index); struct disk_index *find_by_offset(const struct disk_idir *idir, uint64_t offset); int remove_node(struct disk_idir *idir, struct disk_index *node); int delete_idir(struct disk_idir *idir); #endif /* _INDEX_LIST_H */ Loading
Makefile +2 −3 Original line number Diff line number Diff line Loading @@ -17,9 +17,8 @@ PROGS = camogm PHPFILES = camogmstate.php SRCS = camogm.c camogm_ogm.c camogm_jpeg.c camogm_mov.c camogm_kml.c camogm_read.c OBJS = camogm.o camogm_ogm.o camogm_jpeg.o camogm_mov.o camogm_kml.o camogm_read.o SRCS = camogm.c camogm_ogm.c camogm_jpeg.c camogm_mov.c camogm_kml.c camogm_read.c index_list.c OBJS = camogm.o camogm_ogm.o camogm_jpeg.o camogm_mov.o camogm_kml.o camogm_read.o index_list.o CFLAGS += -Wall -I$(ELPHEL_KERNEL_DIR)/include/elphel #CFLAGS += -Wall -I$(INCDIR) -I$(ELPHEL_KERNEL_DIR)/include/elphel Loading
camogm_read.c +3 −124 Original line number Diff line number Diff line Loading @@ -47,11 +47,14 @@ #include <sys/stat.h> #include "camogm_read.h" #include "index_list.h" /** @brief Offset in Exif where TIFF header starts */ #define TIFF_HDR_OFFSET 12 /** @brief The date and time format of Exif field */ #define EXIF_DATE_TIME_FORMAT "%Y:%m:%d %H:%M:%S" /** @brief The format string used for file parameters reporting. Time and port number are extracted from Exif */ #define INDEX_FORMAT_STR "port_number=%d;unix_time=%ld;usec_time=%06u;offset=0x%010llx;file_size=%u\n" /** @brief The delimiters used to separate several commands in one command string sent over socket */ #define CMD_DELIMITER "/?" /** @brief The length of a buffer for command string */ Loading @@ -60,8 +63,6 @@ #define SMALL_BUFF_LEN 32 /** @brief 64 bit mask to align offsets to 4 kb page boundary */ #define PAGE_BOUNDARY_MASK 0xffffffffffffe000 /** @brief The format string used for file parameters reporting. Time and port number are extracted from Exif */ #define INDEX_FORMAT_STR "port_number=%d;unix_time=%ld;usec_time=%06u;offset=0x%010llx;file_size=%u\n" /** @brief The size of read buffer in bytes. The data will be read from disk in blocks of this size */ #define PHY_BLK_SZ 4096 /** @brief Include or exclude file start and stop markers from resulting file. This must be set to 1 for JPEG files */ Loading Loading @@ -247,128 +248,6 @@ void dump_index_dir(const struct disk_idir *idir) } } /** * @brief Create a new node in a linked list of disk indexes * @param[in,out] index pointer to a newly allocated structure * @return 0 in case a new disk index structure was successfully created and -1 otherwise */ int create_node(struct disk_index **index) { if (*index != NULL) return -1; *index = malloc(sizeof(struct disk_index)); if (*index != NULL) { memset(*index, 0, sizeof(struct disk_index)); return 0; } else { return -1; } } /** * @brief Add a new index node to disk index directory * @param[in,out] idir pointer to disk index directory * @param[in] index pointer to index node to be added to disk index directory * @return The number of entries in disk index directory */ int add_node(struct disk_idir *idir, struct disk_index *index) { if (idir->head == NULL && idir->tail == NULL) { idir->head = index; idir->tail = index; idir->size = 1; } else { index->prev = idir->tail; idir->tail->next = index; idir->tail = index; idir->size++; } return idir->size; } /** * @brief Find index node by its start offset * @param[in] idir pointer to disk index directory * @param[in] offset the offset of the file which should be found * @return pointer to disk index node or NULL if the corresponding file was not found */ struct disk_index *find_by_offset(const struct disk_idir *idir, uint64_t offset) { struct disk_index *index = idir->head; while (index != NULL) { if (index->f_offset == offset) break; index = index->next; } return index; } /** * @brief Remove a single index node from disk index directory * @param[in,out] idir pointer to disk index directory * @param[in] node pointer to the index node which should be removed * @return The number of entries in disk index directory */ int remove_node(struct disk_idir *idir, struct disk_index *node) { if (node == NULL) return -1; if (node == idir->head) { idir->head = node->next; idir->head->prev = NULL; } else if (node == idir->tail) { idir->tail = node->prev; idir->tail->next = NULL; } else { struct disk_index *ind = idir->head; while (ind != NULL) { if (ind == node) { ind->prev->next = ind->next; ind->next->prev = ind->prev; break; } ind = ind->next; } } free(node); node = NULL; idir->size--; return idir->size; } /** * Remove all entries from disk index directory an free memory * @param[in] idir pointer to disk index directory * @return 0 in case the directory was successfully deleted and -1 if the directory was empty */ int delete_idir(struct disk_idir *idir) { struct disk_index *curr_ind; struct disk_index *next_ind; if (idir == NULL || idir->head == NULL) return -1; curr_ind = idir->head; next_ind = curr_ind->next; while (curr_ind != NULL) { free(curr_ind); curr_ind = next_ind; if (curr_ind != NULL) next_ind = curr_ind->next; } idir->head = idir->tail = NULL; idir->size = 0; return 0; } /** * @brief Find pattern in a data buffer * Loading
camogm_read.h +0 −46 Original line number Diff line number Diff line Loading @@ -19,52 +19,6 @@ #include "camogm.h" /** * @struct disk_index * @brief Contains a single entry into disk index directory. Each node in * the disk index directory corresponds to a file in the raw device buffer and * hold its starting offset, sensor port number, time stamp and file size. * @var disk_index::next * Pointer to the next index node * @var disk_index::prev * Pointer to the previous disk index node * @var disk_index::rawtime * Time stamp in UNIX format * @var disk_index::usec * The microsecond part of the time stamp * @var disk_index::port * The sensor port number this frame was captured from * @var disk_index::f_size * File size in bytes * @var disk_index::f_offset * The offset of the file start in the raw device buffer (in bytes) */ struct disk_index { struct disk_index *next; struct disk_index *prev; time_t rawtime; unsigned int usec; uint32_t port; size_t f_size; uint64_t f_offset; }; /** * @struct disk_idir * @brief Contains pointers to disk index directory * @var disk_idir::head * Pointer to the first node of disk index directory * @var disk_idir::tail * Pointer to the last node of disk index directory * @var disk_idir::size * The number of nodes in disk index directory */ struct disk_idir { struct disk_index *head; struct disk_index *tail; size_t size; }; /** * @struct range * @brief Container for offsets in raw device buffer Loading
index_list.c 0 → 100644 +143 −0 Original line number Diff line number Diff line /** @file index_list.c * @brief Provides data structures and functions for working with disk index directory * @copyright Copyright (C) 2016 Elphel, Inc. * * <b>License:</b> * 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/>. */ #include <stdlib.h> #include <string.h> #include "index_list.h" /** * @brief Create a new node in a linked list of disk indexes * @param[in,out] index pointer to a newly allocated structure * @return 0 in case a new disk index structure was successfully created and -1 otherwise */ int create_node(struct disk_index **index) { if (*index != NULL) return -1; *index = malloc(sizeof(struct disk_index)); if (*index != NULL) { memset(*index, 0, sizeof(struct disk_index)); return 0; } else { return -1; } } /** * @brief Add a new index node to disk index directory * @param[in,out] idir pointer to disk index directory * @param[in] index pointer to index node to be added to disk index directory * @return The number of entries in disk index directory */ int add_node(struct disk_idir *idir, struct disk_index *index) { if (idir->head == NULL && idir->tail == NULL) { idir->head = index; idir->tail = index; idir->size = 1; } else { index->prev = idir->tail; idir->tail->next = index; idir->tail = index; idir->size++; } return idir->size; } /** * @brief Find index node by its start offset * @param[in] idir pointer to disk index directory * @param[in] offset the offset of the file which should be found * @return pointer to disk index node or NULL if the corresponding file was not found */ struct disk_index *find_by_offset(const struct disk_idir *idir, uint64_t offset) { struct disk_index *index = idir->head; while (index != NULL) { if (index->f_offset == offset) break; index = index->next; } return index; } /** * @brief Remove a single index node from disk index directory * @param[in,out] idir pointer to disk index directory * @param[in] node pointer to the index node which should be removed * @return The number of entries in disk index directory */ int remove_node(struct disk_idir *idir, struct disk_index *node) { if (node == NULL) return -1; if (node == idir->head) { idir->head = node->next; idir->head->prev = NULL; } else if (node == idir->tail) { idir->tail = node->prev; idir->tail->next = NULL; } else { struct disk_index *ind = idir->head; while (ind != NULL) { if (ind == node) { ind->prev->next = ind->next; ind->next->prev = ind->prev; break; } ind = ind->next; } } free(node); node = NULL; idir->size--; return idir->size; } /** * Remove all entries from disk index directory an free memory * @param[in] idir pointer to disk index directory * @return 0 in case the directory was successfully deleted and -1 if the directory was empty */ int delete_idir(struct disk_idir *idir) { struct disk_index *curr_ind; struct disk_index *next_ind; if (idir == NULL || idir->head == NULL) return -1; curr_ind = idir->head; next_ind = curr_ind->next; while (curr_ind != NULL) { free(curr_ind); curr_ind = next_ind; if (curr_ind != NULL) next_ind = curr_ind->next; } idir->head = idir->tail = NULL; idir->size = 0; return 0; }
index_list.h 0 → 100644 +75 −0 Original line number Diff line number Diff line /** @file index_list.h * @brief Provides data structures and functions for working with disk index directory * @copyright Copyright (C) 2016 Elphel, Inc. * * <b>License:</b> * 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/>. */ #ifndef _INDEX_LIST_H #define _INDEX_LIST_H #include <stdint.h> /** * @struct disk_index * @brief Contains a single entry into disk index directory. Each node in * the disk index directory corresponds to a file in the raw device buffer and * hold its starting offset, sensor port number, time stamp and file size. * @var disk_index::next * Pointer to the next index node * @var disk_index::prev * Pointer to the previous disk index node * @var disk_index::rawtime * Time stamp in UNIX format * @var disk_index::usec * The microsecond part of the time stamp * @var disk_index::port * The sensor port number this frame was captured from * @var disk_index::f_size * File size in bytes * @var disk_index::f_offset * The offset of the file start in the raw device buffer (in bytes) */ struct disk_index { struct disk_index *next; struct disk_index *prev; time_t rawtime; unsigned int usec; uint32_t port; size_t f_size; uint64_t f_offset; }; /** * @struct disk_idir * @brief Contains pointers to disk index directory * @var disk_idir::head * Pointer to the first node of disk index directory * @var disk_idir::tail * Pointer to the last node of disk index directory * @var disk_idir::size * The number of nodes in disk index directory */ struct disk_idir { struct disk_index *head; struct disk_index *tail; size_t size; }; void dump_index_dir(const struct disk_idir *idir); int create_node(struct disk_index **index); int add_node(struct disk_idir *idir, struct disk_index *index); struct disk_index *find_by_offset(const struct disk_idir *idir, uint64_t offset); int remove_node(struct disk_idir *idir, struct disk_index *node); int delete_idir(struct disk_idir *idir); #endif /* _INDEX_LIST_H */