Commit 31d89b53 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Add basic multichannel support

All functions except a pointer to state struct, but process fork is not
added yet. Code compiles but has not been tested yet.
parent 786c0e75
This diff is collapsed.
#ifndef _CAMOGM_H
#define _CAMOGM_H
#define CAMOGM_FRAME_NOT_READY 1 // frame pointer valid, but not yet acquired #define CAMOGM_FRAME_NOT_READY 1 // frame pointer valid, but not yet acquired
#define CAMOGM_FRAME_INVALID 2 // invalid frame pointer #define CAMOGM_FRAME_INVALID 2 // invalid frame pointer
#define CAMOGM_FRAME_CHANGED 3 // frame parameters have changed #define CAMOGM_FRAME_CHANGED 3 // frame parameters have changed
...@@ -155,16 +158,18 @@ typedef struct { ...@@ -155,16 +158,18 @@ typedef struct {
int kml_last_uts; //! last generated kml file timestamp, microseconds int kml_last_uts; //! last generated kml file timestamp, microseconds
struct exif_dir_table_t kml_exif[ExifKmlNumber]; //! store locations of the fields needed for KML generations in the Exif block struct exif_dir_table_t kml_exif[ExifKmlNumber]; //! store locations of the fields needed for KML generations in the Exif block
unsigned int port_num;
} camogm_state; } camogm_state;
extern int debug_level; extern int debug_level;
extern FILE* debug_file; extern FILE* debug_file;
extern camogm_state * state; //extern camogm_state * state;
void put_uint16(void *buf, u_int16_t val); void put_uint16(void *buf, u_int16_t val);
void put_uint32(void *buf, u_int32_t val); void put_uint32(void *buf, u_int32_t val);
void put_uint64(void *buf, u_int64_t val); void put_uint64(void *buf, u_int64_t val);
unsigned long getGPValue(unsigned long GPNumber); unsigned long getGPValue(unsigned int port, unsigned long GPNumber);
void setGValue(unsigned long GNumber, unsigned long value); //void setGValue(unsigned long GNumber, unsigned long value);
int waitDaemonEnabled(int daemonBit); // <0 - use default //int waitDaemonEnabled(int daemonBit); // <0 - use default
int isDaemonEnabled(int daemonBit); // <0 - use default //int isDaemonEnabled(int daemonBit); // <0 - use default
#endif /* _CAMOGM_H */
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
#include "ogmstreams.h" // move it to <>? #include "ogmstreams.h" // move it to <>?
#include "camogm_jpeg.h" #include "camogm_jpeg.h"
#include "camogm.h"
//! may add something - called first time format is changed to this one (only once) recording is stopped //! may add something - called first time format is changed to this one (only once) recording is stopped
int camogm_init_jpeg(void) int camogm_init_jpeg(void)
{ {
...@@ -72,7 +72,7 @@ void camogm_free_jpeg(void) ...@@ -72,7 +72,7 @@ void camogm_free_jpeg(void)
{ {
} }
int camogm_start_jpeg(void) int camogm_start_jpeg(camogm_state *state)
{ {
//!TODO: make directory if it does not exist (find the last "/" in the state->path //!TODO: make directory if it does not exist (find the last "/" in the state->path
char * slash; char * slash;
...@@ -94,7 +94,8 @@ int camogm_start_jpeg(void) ...@@ -94,7 +94,8 @@ int camogm_start_jpeg(void)
} }
return 0; return 0;
} }
int camogm_frame_jpeg(void)
int camogm_frame_jpeg(camogm_state *state)
{ {
int i, j; int i, j;
// int fd; // int fd;
......
#ifndef _CAMOGM_JPEG_H
#define _CAMOGM_JPEG_H
#include "camogm.h"
int camogm_init_jpeg(void); int camogm_init_jpeg(void);
int camogm_start_jpeg(void); int camogm_start_jpeg(camogm_state *state);
int camogm_frame_jpeg(void); int camogm_frame_jpeg(camogm_state *state);
int camogm_end_jpeg(void); int camogm_end_jpeg(void);
void camogm_free_jpeg(void); void camogm_free_jpeg(void);
#endif /* _CAMOGM_JPEG_H */
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
#include "ogmstreams.h" // move it to <>? #include "ogmstreams.h" // move it to <>?
#include "camogm_kml.h" #include "camogm_kml.h"
#include "camogm.h"
const char ExifDirFileName[] = "/dev/exif_metadir"; const char ExifDirFileName[] = "/dev/exif_metadir";
//! may add something - called first time format is changed to this one (only once) recording is stopped //! may add something - called first time format is changed to this one (only once) recording is stopped
...@@ -93,7 +93,7 @@ void camogm_free_kml(void) ...@@ -93,7 +93,7 @@ void camogm_free_kml(void)
} }
*/ */
int camogm_start_kml(void) int camogm_start_kml(camogm_state *state)
{ {
// struct exif_dir_table_t kml_exif[ExifKmlNumber] ; //! store locations of the fields needed for KML generations in the Exif block // struct exif_dir_table_t kml_exif[ExifKmlNumber] ; //! store locations of the fields needed for KML generations in the Exif block
///exif_metadir ///exif_metadir
...@@ -152,7 +152,7 @@ int camogm_start_kml(void) ...@@ -152,7 +152,7 @@ int camogm_start_kml(void)
return 0; return 0;
} }
int camogm_frame_kml(void) int camogm_frame_kml(camogm_state *state)
{ {
char JPEGFileName[300]; char JPEGFileName[300];
char * filename; char * filename;
...@@ -316,7 +316,7 @@ int camogm_frame_kml(void) ...@@ -316,7 +316,7 @@ int camogm_frame_kml(void)
} }
int camogm_end_kml(void) int camogm_end_kml(camogm_state *state)
{ {
if (state->kml_file) { if (state->kml_file) {
...@@ -327,4 +327,3 @@ int camogm_end_kml(void) ...@@ -327,4 +327,3 @@ int camogm_end_kml(void)
} }
return 0; return 0;
} }
int camogm_init_kml(void); #ifndef _CAMOGM_KML_H
int camogm_start_kml(void); #define _CAMOGM_KML_H
int camogm_frame_kml(void);
int camogm_end_kml(void);
void camogm_free_kml(void);
#include "camogm.h"
int camogm_init_kml(void);
int camogm_start_kml(camogm_state *state);
int camogm_frame_kml(camogm_state *state);
int camogm_end_kml(camogm_state *state);
void camogm_free_kml(void);
#endif /* _CAMOGM_KML_H */
/* /*
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
......
...@@ -66,7 +66,6 @@ ...@@ -66,7 +66,6 @@
#include "ogmstreams.h" // move it to <>? #include "ogmstreams.h" // move it to <>?
#include "camogm_mov.h" #include "camogm_mov.h"
#include "camogm.h"
#define QUICKTIME_MIN_HEADER 0x300 // Quicktime header length (w/o index tables) enough to accomodate #define QUICKTIME_MIN_HEADER 0x300 // Quicktime header length (w/o index tables) enough to accomodate
// static data . // static data .
...@@ -93,7 +92,8 @@ long headerSize = 0; ...@@ -93,7 +92,8 @@ long headerSize = 0;
const char *iFile = NULL; const char *iFile = NULL;
int quicktime_template_parser(const char * i_iFile, //! now - string containing header template int quicktime_template_parser(camogm_state *state,
const char * i_iFile, //! now - string containing header template
int i_ofd, //!output file descriptor (opened) int i_ofd, //!output file descriptor (opened)
int i_width, // width in pixels int i_width, // width in pixels
int i_height, int i_height,
...@@ -107,7 +107,7 @@ int quicktime_template_parser(const char * i_iFile, //! now - string contain ...@@ -107,7 +107,7 @@ int quicktime_template_parser(const char * i_iFile, //! now - string contain
); );
void putBigEndian(unsigned long d, int l); void putBigEndian(unsigned long d, int l);
int parse_special(void); int parse_special(void);
int parse(int top); int parse(camogm_state *state, int top);
//! called first time format is changed to this one (only once) recording is stopped //! called first time format is changed to this one (only once) recording is stopped
//! read frame template from the file if it is not done yet //! read frame template from the file if it is not done yet
int camogm_init_mov(void) int camogm_init_mov(void)
...@@ -147,7 +147,7 @@ void camogm_free_mov(void) ...@@ -147,7 +147,7 @@ void camogm_free_mov(void)
} }
} }
int camogm_start_mov(void) int camogm_start_mov(camogm_state *state)
{ {
//! allocate memory for the frame index table //! allocate memory for the frame index table
...@@ -165,7 +165,7 @@ int camogm_start_mov(void) ...@@ -165,7 +165,7 @@ int camogm_start_mov(void)
return 0; return 0;
} }
int camogm_frame_mov(void) int camogm_frame_mov(camogm_state *state)
{ {
int i, j; int i, j;
ssize_t iovlen, l; ssize_t iovlen, l;
...@@ -188,8 +188,13 @@ int camogm_frame_mov(void) ...@@ -188,8 +188,13 @@ int camogm_frame_mov(void)
state->frame_lengths[state->frameno] = l; state->frame_lengths[state->frameno] = l;
return 0; return 0;
} }
//!move to the start of the file and insert generated header
int camogm_end_mov(void) /**
* @brief Move to the start of the file and insert generated header
* @param[in] state pointer to the #camogm_state structure for current sensor port
* @return this function is always successful and returns 0
*/
int camogm_end_mov(camogm_state *state)
{ {
off_t l/*,he; off_t l/*,he;
unsigned char mdat_tag[8]; unsigned char mdat_tag[8];
...@@ -201,7 +206,8 @@ int camogm_end_mov(void) ...@@ -201,7 +206,8 @@ int camogm_end_mov(void)
// lseek(state->ivf, state->frame_data_start, SEEK_SET); // lseek(state->ivf, state->frame_data_start, SEEK_SET);
// fill in the header in the beginning of the file // fill in the header in the beginning of the file
lseek(state->ivf, 0, SEEK_SET); lseek(state->ivf, 0, SEEK_SET);
quicktime_template_parser(q_template, //! now - string containing header template quicktime_template_parser(state,
q_template, //! now - string containing header template
state->ivf, //!output file descriptor (opened) state->ivf, //!output file descriptor (opened)
state->width, //! width in pixels state->width, //! width in pixels
state->height, state->height,
...@@ -240,13 +246,14 @@ int camogm_end_mov(void) ...@@ -240,13 +246,14 @@ int camogm_end_mov(void)
return 0; return 0;
} }
/* /**
starts with the input file pointer just after the opening "{", * @brief Starts with the input file pointer just after the opening "{",
and output file - at the beginning of it's output * and output file - at the beginning of it's output
on exit - input pointer - after closing "}", output after it's output * on exit - input pointer - after closing "}", output after it's output
* @param[in] d
* @param[in] l
* @return none
*/ */
void putBigEndian(unsigned long d, int l) void putBigEndian(unsigned long d, int l)
{ {
unsigned char od[4]; unsigned char od[4];
...@@ -258,6 +265,7 @@ void putBigEndian(unsigned long d, int l) ...@@ -258,6 +265,7 @@ void putBigEndian(unsigned long d, int l)
if (l) write(ofd, &od[4 - l], l); if (l) write(ofd, &od[4 - l], l);
// oPos+=l; // oPos+=l;
} }
//!temporary replacement for fgets to read from string //!temporary replacement for fgets to read from string
char * sfgets(char * str, int size, const char * stream, int * pos) char * sfgets(char * str, int size, const char * stream, int * pos)
{ {
...@@ -367,9 +375,7 @@ int parse_special(void) ...@@ -367,9 +375,7 @@ int parse_special(void)
return -1; return -1;
} }
int parse(camogm_state *state, int top) // if top - will not include length
int parse(int top) // if top - will not include length
{ {
long out_start, out_end; long out_start, out_end;
char c; char c;
...@@ -395,7 +401,7 @@ int parse(int top) // if top - will not include length ...@@ -395,7 +401,7 @@ int parse(int top) // if top - will not include length
} }
// children atoms // children atoms
else if (c == '{') { else if (c == '{') {
if (parse(0) < 0) return -1; if (parse(state, 0) < 0) return -1;
// skip comments // skip comments
// } else if (c=='#') fgets( comStr, sizeof(comStr), infile); // } else if (c=='#') fgets( comStr, sizeof(comStr), infile);
} else if (c == '#') sfgets( comStr, sizeof(comStr), iFile, &iPos); } else if (c == '#') sfgets( comStr, sizeof(comStr), iFile, &iPos);
...@@ -455,7 +461,8 @@ int parse(int top) // if top - will not include length ...@@ -455,7 +461,8 @@ int parse(int top) // if top - will not include length
} }
int quicktime_template_parser(const char * i_iFile, //! now - string containing header template int quicktime_template_parser( camogm_state *state,
const char * i_iFile, //! now - string containing header template
int i_ofd, //!output file descriptor (opened) int i_ofd, //!output file descriptor (opened)
int i_width, // width in pixels int i_width, // width in pixels
int i_height, int i_height,
...@@ -486,7 +493,7 @@ int quicktime_template_parser(const char * i_iFile, //! now - string contain ...@@ -486,7 +493,7 @@ int quicktime_template_parser(const char * i_iFile, //! now - string contain
D3(fprintf(debug_file, "PASS I\n")); D3(fprintf(debug_file, "PASS I\n"));
// while ( feof(infile) == 0 ) parse(1); // pass 1 // while ( feof(infile) == 0 ) parse(1); // pass 1
while ( iPos < iFileLen ) parse(1); // pass 1 while ( iPos < iFileLen ) parse(state, 1); // pass 1
// headerSize=ftell (outfile); // headerSize=ftell (outfile);
// fseek (outfile,0,SEEK_SET); // rewind for pass 2 // fseek (outfile,0,SEEK_SET); // rewind for pass 2
// fseek (infile, 0,SEEK_SET); // // fseek (infile, 0,SEEK_SET); //
...@@ -498,7 +505,7 @@ int quicktime_template_parser(const char * i_iFile, //! now - string contain ...@@ -498,7 +505,7 @@ int quicktime_template_parser(const char * i_iFile, //! now - string contain
D3(fprintf(debug_file, "PASS II\n")); D3(fprintf(debug_file, "PASS II\n"));
// while ( feof(infile) == 0 ) parse(1); // pass 2 // while ( feof(infile) == 0 ) parse(1); // pass 2
while ( iPos < iFileLen ) parse(1); // pass 2 while ( iPos < iFileLen ) parse(state, 1); // pass 2
//fclose (infile); //fclose (infile);
//fclose (outfile); //fclose (outfile);
......
#ifndef _CAMOGM_MOV_H
#define _CAMOG_MOV_H
#include "camogm.h"
int camogm_init_mov(void); int camogm_init_mov(void);
int camogm_start_mov(void); int camogm_start_mov(camogm_state *state);
int camogm_frame_mov(void); int camogm_frame_mov(camogm_state *state);
int camogm_end_mov(void); int camogm_end_mov(camogm_state *state);
void camogm_free_mov(void); void camogm_free_mov(void);
#endif /* _CAMOGM_MOV_H */
...@@ -54,12 +54,11 @@ ...@@ -54,12 +54,11 @@
#include <c313a.h> #include <c313a.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <ogg/ogg.h> // has to be before ogmstreams.h #include <ogg/ogg.h> // has to be before ogmstreams.h
#include "ogmstreams.h" // move it to <>? #include "ogmstreams.h" // move it to <>?
#include "camogm_ogm.h" #include "camogm_ogm.h"
#include "camogm.h"
//! may add something - called first time format is changed to this one (only once) recording is stopped //! may add something - called first time format is changed to this one (only once) recording is stopped
int camogm_init_ogm(void) int camogm_init_ogm(void)
{ {
...@@ -69,8 +68,7 @@ void camogm_free_ogm(void) ...@@ -69,8 +68,7 @@ void camogm_free_ogm(void)
{ {
} }
int camogm_start_ogm(camogm_state *state)
int camogm_start_ogm(void)
{ {
char vendor[] = "ElphelOgm v 0.1"; char vendor[] = "ElphelOgm v 0.1";
int pos; int pos;
...@@ -171,7 +169,7 @@ int camogm_start_ogm(void) ...@@ -171,7 +169,7 @@ int camogm_start_ogm(void)
return 0; return 0;
} }
int camogm_frame_ogm(void) int camogm_frame_ogm(camogm_state *state)
{ {
int indx; int indx;
elph_ogg_packet elp_packet; elph_ogg_packet elp_packet;
...@@ -219,10 +217,9 @@ int camogm_frame_ogm(void) ...@@ -219,10 +217,9 @@ int camogm_frame_ogm(void)
return 0; return 0;
} }
//!Zero packets are OK, use them to end file with "last" turned on //!Zero packets are OK, use them to end file with "last" turned on
int camogm_end_ogm(void) int camogm_end_ogm(camogm_state *state)
{ {
//! put zero-packet it into stream //! put zero-packet it into stream
ogg_packet ogg_header; ogg_packet ogg_header;
...@@ -245,6 +242,3 @@ int camogm_end_ogm(void) ...@@ -245,6 +242,3 @@ int camogm_end_ogm(void)
} }
return 0; return 0;
} }
#ifndef _CAMOGM_OGM_H
#define _CAMOGM_OGM_H
#include "camogm.h"
int camogm_init_ogm(void); int camogm_init_ogm(void);
int camogm_start_ogm(void); int camogm_start_ogm(camogm_state *state);
int camogm_frame_ogm(void); int camogm_frame_ogm(camogm_state *state);
int camogm_end_ogm(void); int camogm_end_ogm(camogm_state *state);
void camogm_free_ogm(void); void camogm_free_ogm(void);
#endif /* _CAMOGM_OGM_H */
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