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_INVALID 2 // invalid frame pointer
#define CAMOGM_FRAME_CHANGED 3 // frame parameters have changed
......@@ -155,16 +158,18 @@ typedef struct {
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
unsigned int port_num;
} camogm_state;
extern int debug_level;
extern FILE* debug_file;
extern camogm_state * state;
//extern camogm_state * state;
void put_uint16(void *buf, u_int16_t val);
void put_uint32(void *buf, u_int32_t val);
void put_uint64(void *buf, u_int64_t val);
unsigned long getGPValue(unsigned long GPNumber);
void setGValue(unsigned long GNumber, unsigned long value);
int waitDaemonEnabled(int daemonBit); // <0 - use default
int isDaemonEnabled(int daemonBit); // <0 - use default
unsigned long getGPValue(unsigned int port, unsigned long GPNumber);
//void setGValue(unsigned long GNumber, unsigned long value);
//int waitDaemonEnabled(int daemonBit); // <0 - use default
//int isDaemonEnabled(int daemonBit); // <0 - use default
#endif /* _CAMOGM_H */
......@@ -62,7 +62,7 @@
#include "ogmstreams.h" // move it to <>?
#include "camogm_jpeg.h"
#include "camogm.h"
//! may add something - called first time format is changed to this one (only once) recording is stopped
int camogm_init_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
char * slash;
......@@ -94,7 +94,8 @@ int camogm_start_jpeg(void)
}
return 0;
}
int camogm_frame_jpeg(void)
int camogm_frame_jpeg(camogm_state *state)
{
int i, j;
// int fd;
......
#ifndef _CAMOGM_JPEG_H
#define _CAMOGM_JPEG_H
#include "camogm.h"
int camogm_init_jpeg(void);
int camogm_start_jpeg(void);
int camogm_frame_jpeg(void);
int camogm_start_jpeg(camogm_state *state);
int camogm_frame_jpeg(camogm_state *state);
int camogm_end_jpeg(void);
void camogm_free_jpeg(void);
#endif /* _CAMOGM_JPEG_H */
......@@ -63,7 +63,7 @@
#include "ogmstreams.h" // move it to <>?
#include "camogm_kml.h"
#include "camogm.h"
const char ExifDirFileName[] = "/dev/exif_metadir";
//! 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)
}
*/
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
///exif_metadir
......@@ -152,7 +152,7 @@ int camogm_start_kml(void)
return 0;
}
int camogm_frame_kml(void)
int camogm_frame_kml(camogm_state *state)
{
char JPEGFileName[300];
char * filename;
......@@ -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) {
......@@ -327,4 +327,3 @@ int camogm_end_kml(void)
}
return 0;
}
int camogm_init_kml(void);
int camogm_start_kml(void);
int camogm_frame_kml(void);
int camogm_end_kml(void);
void camogm_free_kml(void);
#ifndef _CAMOGM_KML_H
#define _CAMOGM_KML_H
#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"?>
......
......@@ -66,7 +66,6 @@
#include "ogmstreams.h" // move it to <>?
#include "camogm_mov.h"
#include "camogm.h"
#define QUICKTIME_MIN_HEADER 0x300 // Quicktime header length (w/o index tables) enough to accomodate
// static data .
......@@ -93,7 +92,8 @@ long headerSize = 0;
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_width, // width in pixels
int i_height,
......@@ -107,7 +107,7 @@ int quicktime_template_parser(const char * i_iFile, //! now - string contain
);
void putBigEndian(unsigned long d, int l);
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
//! read frame template from the file if it is not done yet
int camogm_init_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
......@@ -165,7 +165,7 @@ int camogm_start_mov(void)
return 0;
}
int camogm_frame_mov(void)
int camogm_frame_mov(camogm_state *state)
{
int i, j;
ssize_t iovlen, l;
......@@ -188,8 +188,13 @@ int camogm_frame_mov(void)
state->frame_lengths[state->frameno] = l;
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;
unsigned char mdat_tag[8];
......@@ -201,7 +206,8 @@ int camogm_end_mov(void)
// lseek(state->ivf, state->frame_data_start, SEEK_SET);
// fill in the header in the beginning of the file
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->width, //! width in pixels
state->height,
......@@ -240,13 +246,14 @@ int camogm_end_mov(void)
return 0;
}
/*
starts with the input file pointer just after the opening "{",
and output file - at the beginning of it's output
on exit - input pointer - after closing "}", output after it's output
/**
* @brief Starts with the input file pointer just after the opening "{",
* and output file - at the beginning of 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)
{
unsigned char od[4];
......@@ -258,6 +265,7 @@ void putBigEndian(unsigned long d, int l)
if (l) write(ofd, &od[4 - l], l);
// oPos+=l;
}
//!temporary replacement for fgets to read from string
char * sfgets(char * str, int size, const char * stream, int * pos)
{
......@@ -367,9 +375,7 @@ int parse_special(void)
return -1;
}
int parse(int top) // if top - will not include length
int parse(camogm_state *state, int top) // if top - will not include length
{
long out_start, out_end;
char c;
......@@ -395,7 +401,7 @@ int parse(int top) // if top - will not include length
}
// children atoms
else if (c == '{') {
if (parse(0) < 0) return -1;
if (parse(state, 0) < 0) return -1;
// skip comments
// } else if (c=='#') fgets( comStr, sizeof(comStr), infile);
} else if (c == '#') sfgets( comStr, sizeof(comStr), iFile, &iPos);
......@@ -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_width, // width in pixels
int i_height,
......@@ -486,7 +493,7 @@ int quicktime_template_parser(const char * i_iFile, //! now - string contain
D3(fprintf(debug_file, "PASS I\n"));
// 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);
// fseek (outfile,0,SEEK_SET); // rewind for pass 2
// fseek (infile, 0,SEEK_SET); //
......@@ -498,7 +505,7 @@ int quicktime_template_parser(const char * i_iFile, //! now - string contain
D3(fprintf(debug_file, "PASS II\n"));
// 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 (outfile);
......
#ifndef _CAMOGM_MOV_H
#define _CAMOG_MOV_H
#include "camogm.h"
int camogm_init_mov(void);
int camogm_start_mov(void);
int camogm_frame_mov(void);
int camogm_end_mov(void);
int camogm_start_mov(camogm_state *state);
int camogm_frame_mov(camogm_state *state);
int camogm_end_mov(camogm_state *state);
void camogm_free_mov(void);
#endif /* _CAMOGM_MOV_H */
......@@ -54,12 +54,11 @@
#include <c313a.h>
#include <asm/byteorder.h>
#include <ogg/ogg.h> // has to be before ogmstreams.h
#include "ogmstreams.h" // move it to <>?
#include "camogm_ogm.h"
#include "camogm.h"
//! may add something - called first time format is changed to this one (only once) recording is stopped
int camogm_init_ogm(void)
{
......@@ -69,8 +68,7 @@ void camogm_free_ogm(void)
{
}
int camogm_start_ogm(void)
int camogm_start_ogm(camogm_state *state)
{
char vendor[] = "ElphelOgm v 0.1";
int pos;
......@@ -171,7 +169,7 @@ int camogm_start_ogm(void)
return 0;
}
int camogm_frame_ogm(void)
int camogm_frame_ogm(camogm_state *state)
{
int indx;
elph_ogg_packet elp_packet;
......@@ -219,10 +217,9 @@ int camogm_frame_ogm(void)
return 0;
}
//!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
ogg_packet ogg_header;
......@@ -245,6 +242,3 @@ int camogm_end_ogm(void)
}
return 0;
}
#ifndef _CAMOGM_OGM_H
#define _CAMOGM_OGM_H
#include "camogm.h"
int camogm_init_ogm(void);
int camogm_start_ogm(void);
int camogm_frame_ogm(void);
int camogm_end_ogm(void);
int camogm_start_ogm(camogm_state *state);
int camogm_frame_ogm(camogm_state *state);
int camogm_end_ogm(camogm_state *state);
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