Commit 786c0e75 authored by Mikhail Karpenko's avatar Mikhail Karpenko
Browse files

Fix formatting

Fix source code formatting with 'uncrustify' command-line utility
parent 045b76e0
Loading
Loading
Loading
Loading
+1123 −1093
Original line number Original line Diff line number Diff line
 
/*!***************************************************************************
/*!***************************************************************************
   *! FILE NAME  : camogm.c
   *! FILE NAME  : camogm.c
   *! DESCRIPTION: Program to write captured video (and audio) to camera file system
   *! DESCRIPTION: Program to write captured video (and audio) to camera file system
@@ -126,7 +125,6 @@
#include <exifa.h>
#include <exifa.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 <>?


@@ -153,7 +151,6 @@ struct framepars_all_t *frameParsAll;
struct framepars_t       *framePars;
struct framepars_t       *framePars;
unsigned long            *globalPars; /// parameters that are not frame-related, their changes do not initiate any actions
unsigned long            *globalPars; /// parameters that are not frame-related, their changes do not initiate any actions



int buff_size;
int buff_size;


#define DEFAULT_DURATION 60             /*!default segment duration (seconds) */
#define DEFAULT_DURATION 60             /*!default segment duration (seconds) */
@@ -179,15 +176,8 @@ camogm_state * state;
int debug_level;
int debug_level;
FILE* debug_file;
FILE* debug_file;



int camogm_init(void);
int camogm_init(void);
int camogm_start(void);
int camogm_start(void);






int camogm_stop(void);
int camogm_stop(void);
int camogm_reset(void); //! reset circbuf read pointer
int camogm_reset(void); //! reset circbuf read pointer
int camogm_debug(const char * fname);
int camogm_debug(const char * fname);
@@ -212,7 +202,6 @@ void camogm_kml_set_height(double dd);
void  camogm_kml_set_period(int d);
void  camogm_kml_set_period(int d);
void  camogm_kml_set_near(double dd); // distance to PhotoOverlay
void  camogm_kml_set_near(double dd); // distance to PhotoOverlay



int   parse_cmd(FILE* npipe);
int   parse_cmd(FILE* npipe);
char * getLineFromPipe(FILE* npipe);
char * getLineFromPipe(FILE* npipe);


@@ -262,9 +251,11 @@ void put_uint64(void *buf, u_int64_t val)
	tmp[7] = (val >>= 8) & 0xff;
	tmp[7] = (val >>= 8) & 0xff;
}
}


int camogm_init(void) {
int camogm_init(void)
{
	const char sserial[] = "elp0";
	const char sserial[] = "elp0";
	int * ipser = (int*)sserial;
	int * ipser = (int*)sserial;

	state->running = 0;     // mo
	state->running = 0;     // mo
	state->starting = 0;    // mo
	state->starting = 0;    // mo
	state->vf = NULL;
	state->vf = NULL;
@@ -308,8 +299,10 @@ int camogm_init(void) {
}
}




int camogm_debug(const char * fname) {
int camogm_debug(const char * fname)
{
	int none = 1;
	int none = 1;

	if (fname && strlen(fname) && strcmp(fname, "none") && strcmp(fname, "null")  && strcmp(fname, "/dev/null")) none = 0;
	if (fname && strlen(fname) && strcmp(fname, "none") && strcmp(fname, "null")  && strcmp(fname, "/dev/null")) none = 0;
	if (debug_file) {
	if (debug_file) {
		if (strcmp(state->debug_name, "stdout") && strcmp(state->debug_name, "stderr")) fclose(debug_file);
		if (strcmp(state->debug_name, "stdout") && strcmp(state->debug_name, "stderr")) fclose(debug_file);
@@ -328,18 +321,18 @@ int camogm_debug(const char * fname) {
	return 0;
	return 0;
}
}


int camogm_debug_level(int d) {
int camogm_debug_level(int d)
{
	debug_level = d;
	debug_level = d;
	return 0;
	return 0;
}
}



int camogm_start(void)

{

int camogm_start(void) {
	int timestamp_start;
	int timestamp_start;
	int rslt;
	int rslt;
	int next_metadata_start, next_jpeg_len, fp;
	int next_metadata_start, next_jpeg_len, fp;

	D1(fprintf(debug_file, "Starting recording\n"));
	D1(fprintf(debug_file, "Starting recording\n"));
	double dtime_stamp;
	double dtime_stamp;
	state->frameno = 0;
	state->frameno = 0;
@@ -511,7 +504,8 @@ D0(fprintf (debug_file,"camogm_start() error, rslt=0x%x\n",rslt));
}
}




int  sendImageFrame (void) {
int  sendImageFrame(void)
{
	int rslt;
	int rslt;
	unsigned char frame_packet_type = PACKET_IS_SYNCPOINT;
	unsigned char frame_packet_type = PACKET_IS_SYNCPOINT;
	int timestamp_start;
	int timestamp_start;
@@ -694,8 +688,10 @@ D3(fprintf (debug_file,"_15_\n"));






int camogm_stop(void) {
int camogm_stop(void)
{
	int rslt = 0;
	int rslt = 0;

	if (!state->running) {
	if (!state->running) {
		if (!state->starting) {
		if (!state->starting) {
			D2(fprintf(debug_file, "Recording was not running, nothing to stop\n"));
			D2(fprintf(debug_file, "Recording was not running, nothing to stop\n"));
@@ -725,8 +721,10 @@ int camogm_stop(void) {
	return 0;
	return 0;
}
}


void camogm_free() {
void camogm_free()
{
	int f;
	int f;

//! free all file format handlers that were used
//! free all file format handlers that were used
//add kml when needed
//add kml when needed
	for (f = 0; f < 31; f++) {
	for (f = 0; f < 31; f++) {
@@ -742,72 +740,89 @@ void camogm_free() {
	state->formats = 0;
	state->formats = 0;
}
}


int camogm_reset(void) { //! reset circbuf read pointer
int camogm_reset(void)   //! reset circbuf read pointer
{
	state->cirbuf_rp = -1;
	state->cirbuf_rp = -1;
	state->buf_overruns = -1; //!first will not count
	state->buf_overruns = -1; //!first will not count
	return 0;
	return 0;
}
}


///kml stuff
///kml stuff
void  camogm_kml_set_enable(int d) {
void  camogm_kml_set_enable(int d)
{
	state->kml_enable = d;
	state->kml_enable = d;
}
}
void  camogm_kml_set_horHalfFov (double dd) {
void  camogm_kml_set_horHalfFov(double dd)
{
	state->kml_horHalfFov = dd;
	state->kml_horHalfFov = dd;
}
}
void  camogm_kml_set_vertHalfFov(double dd) {
void  camogm_kml_set_vertHalfFov(double dd)
{
	state->kml_vertHalfFov = dd;
	state->kml_vertHalfFov = dd;
}
}
void  camogm_kml_set_height_mode(int d) {
void  camogm_kml_set_height_mode(int d)
{
	state->kml_height_mode = d;
	state->kml_height_mode = d;
}
}
void  camogm_kml_set_height(double dd) {
void  camogm_kml_set_height(double dd)
{
	state->kml_height = dd;
	state->kml_height = dd;
}
}
void  camogm_kml_set_period(int d) {
void  camogm_kml_set_period(int d)
{
	state->kml_period = d;
	state->kml_period = d;
	state->kml_last_ts = 0;
	state->kml_last_ts = 0;
	state->kml_last_uts = 0;
	state->kml_last_uts = 0;
}
}
void  camogm_kml_set_near(double dd) { // distance to PhotoOverlay
void  camogm_kml_set_near(double dd)   // distance to PhotoOverlay
{
	state->kml_near = dd;
	state->kml_near = dd;
}
}




void  camogm_set_segment_duration(int sd) {
void  camogm_set_segment_duration(int sd)
{
	state->segment_duration = sd;
	state->segment_duration = sd;
}
}
void  camogm_set_segment_length(int sl) {
void  camogm_set_segment_length(int sl)
{
	state->segment_length =   sl;
	state->segment_length =   sl;
}
}
void  camogm_set_save_gp(int d) {
void  camogm_set_save_gp(int d)
{
	state->save_gp =   d;
	state->save_gp =   d;
}
}
void  camogm_set_exif(int d) {
void  camogm_set_exif(int d)
{
	state->exif =   d;
	state->exif =   d;
}
}




void  camogm_set_greedy(int d) {
void  camogm_set_greedy(int d)
{
	state->greedy =   d ? 1 : 0;
	state->greedy =   d ? 1 : 0;
}
}
void  camogm_set_ignore_fps(int d){
void  camogm_set_ignore_fps(int d)
{
	state->ignore_fps =   d ? 1 : 0;
	state->ignore_fps =   d ? 1 : 0;
}
}


void  camogm_set_prefix (const char * p) {
void  camogm_set_prefix(const char * p)
{
	strncpy(state->path_prefix, p, sizeof(state->path_prefix) - 1);
	strncpy(state->path_prefix, p, sizeof(state->path_prefix) - 1);
	state->path_prefix[sizeof(state->path_prefix) - 1] = '\0';
	state->path_prefix[sizeof(state->path_prefix) - 1] = '\0';
}
}


void  camogm_set_timescale(double d) { //! set timescale, default=1,000,000
void  camogm_set_timescale(double d)   //! set timescale, default=1,000,000
{
	state->set_timescale =  d;
	state->set_timescale =  d;
	if ((state->running == 0) && (state->starting == 0)) {
	if ((state->running == 0) && (state->starting == 0)) {
		state->timescale = state->set_timescale;
		state->timescale = state->set_timescale;
	}
	}
}
}


void  camogm_set_frames_skip(int d) { //! set frames to skip (for time lapse)
void  camogm_set_frames_skip(int d)   //! set frames to skip (for time lapse)
{
	state->set_frames_skip =  d;
	state->set_frames_skip =  d;
	if ((state->running == 0) && (state->starting == 0)) {
	if ((state->running == 0) && (state->starting == 0)) {
		state->frames_skip =      state->set_frames_skip;
		state->frames_skip =      state->set_frames_skip;
@@ -817,8 +832,10 @@ void camogm_set_frames_skip(int d) { //! set frames to skip (for time lapse)
}
}




void  camogm_set_format(int d) {
void  camogm_set_format(int d)
{
	int rslt = 0;
	int rslt = 0;

	state->set_format =  d;
	state->set_format =  d;
	if ((state->running == 0) && (state->starting == 0)) {
	if ((state->running == 0) && (state->starting == 0)) {
		state->format =  state->set_format;
		state->format =  state->set_format;
@@ -835,20 +852,24 @@ void camogm_set_format(int d) {
	}
	}
}
}
//! needed for Quicktime - maybe something else?
//! needed for Quicktime - maybe something else?
void  camogm_set_max_frames(int d) {
void  camogm_set_max_frames(int d)
{
	state->set_max_frames =  d;
	state->set_max_frames =  d;
	if ((state->running == 0) && (state->starting == 0)) state->max_frames =  d;
	if ((state->running == 0) && (state->starting == 0)) state->max_frames =  d;
}
}
void  camogm_set_frames_per_chunk(int d) {
void  camogm_set_frames_per_chunk(int d)
{
	state->set_frames_per_chunk =  d;
	state->set_frames_per_chunk =  d;
	if ((state->running == 0) && (state->starting == 0)) state->frames_per_chunk =  d;
	if ((state->running == 0) && (state->starting == 0)) state->frames_per_chunk =  d;
}
}
void  camogm_set_start_after_timestamp(double d) {
void  camogm_set_start_after_timestamp(double d)
{
	state->start_after_timestamp =  d;
	state->start_after_timestamp =  d;
}
}




void  camogm_status(char * fn, int xml) {
void  camogm_status(char * fn, int xml)
{
	int _len = 0;
	int _len = 0;
	int _dur, _udur;
	int _dur, _udur;
//TODO:make it XML file
//TODO:make it XML file
@@ -1021,9 +1042,11 @@ void camogm_status(char * fn, int xml) {
}
}


//! will read from pipe, return pointer to null terminated string if available, NULL otherwise
//! will read from pipe, return pointer to null terminated string if available, NULL otherwise
char * getLineFromPipe(FILE* npipe) {
char * getLineFromPipe(FILE* npipe)
{
	int fl;
	int fl;
	char * nlp;
	char * nlp;

//!remove used string if any
//!remove used string if any
	if (cmdstrt > 0) {
	if (cmdstrt > 0) {
//!moving overlapping strings
//!moving overlapping strings
@@ -1058,12 +1081,14 @@ char * getLineFromPipe(FILE* npipe) {
	}
	}
}
}
// command[= \t]*args[ \t]*
// command[= \t]*args[ \t]*
int parse_cmd(FILE* npipe) {
int parse_cmd(FILE* npipe)
{
	char * cmd;
	char * cmd;
	char * args;
	char * args;
	char * argse;
	char * argse;
	int d;
	int d;
	double dd;
	double dd;

//  if (!((cmd=getLineFromPipe(npipe)))) return 0; //! nothing in the pipe
//  if (!((cmd=getLineFromPipe(npipe)))) return 0; //! nothing in the pipe
//!skip empty commands
//!skip empty commands
	while (((cmd = getLineFromPipe(npipe))) && !cmd[0]) ;
	while (((cmd = getLineFromPipe(npipe))) && !cmd[0]) ;
@@ -1233,6 +1258,7 @@ int main(int argc, char *argv[])
	int cmd;
	int cmd;
	int i, rslt;
	int i, rslt;
	int fp0, fp1;           // debugging
	int fp0, fp1;           // debugging

	state = &sstate;        //extern
	state = &sstate;        //extern
//! no command line options processing yet
//! no command line options processing yet
	if ((argc < 2) || (argv[1][1] == '-')) {
	if ((argc < 2) || (argv[1][1] == '-')) {
@@ -1432,7 +1458,8 @@ int main(int argc, char *argv[])
 * @param GPNumber parameter number (as defined in c313a.h), G_* parameters have numbers above FRAMEPAR_GLOBALS, P_* - below)
 * @param GPNumber parameter number (as defined in c313a.h), G_* parameters have numbers above FRAMEPAR_GLOBALS, P_* - below)
 * @return parameter value
 * @return parameter value
 */
 */
unsigned long getGPValue(unsigned long GPNumber) {
unsigned long getGPValue(unsigned long GPNumber)
{
	return (GPNumber >= FRAMEPAR_GLOBALS) ?
	return (GPNumber >= FRAMEPAR_GLOBALS) ?
	       GLOBALPARS(GPNumber) :
	       GLOBALPARS(GPNumber) :
	       framePars[GLOBALPARS(G_THIS_FRAME) & PARS_FRAMES_MASK].pars[GPNumber];
	       framePars[GLOBALPARS(G_THIS_FRAME) & PARS_FRAMES_MASK].pars[GPNumber];
@@ -1443,7 +1470,8 @@ unsigned long getGPValue(unsigned long GPNumber) {
 * @param GNumber - parameter number (as defined in c313a.h)
 * @param GNumber - parameter number (as defined in c313a.h)
 * @param value  - value to set
 * @param value  - value to set
 */
 */
void setGValue(unsigned long  GNumber,   unsigned long value) {
void setGValue(unsigned long GNumber,   unsigned long value)
{
	GLOBALPARS(GNumber) = value;
	GLOBALPARS(GNumber) = value;
}
}


@@ -1453,7 +1481,8 @@ void setGValue(unsigned long GNumber, unsigned long value) {
 * @param daemonBit - bit number to accept control in P_DAEMON_EN parameter
 * @param daemonBit - bit number to accept control in P_DAEMON_EN parameter
 * @return (after possible waiting) true if there was no waiting, false if there was waiting
 * @return (after possible waiting) true if there was no waiting, false if there was waiting
 */
 */
int  waitDaemonEnabled(int daemonBit) { // <0 - use default
int  waitDaemonEnabled(int daemonBit)   // <0 - use default
{
	if ((daemonBit >= 0) && (daemonBit < 32)) lastDaemonBit = daemonBit;
	if ((daemonBit >= 0) && (daemonBit < 32)) lastDaemonBit = daemonBit;
	unsigned long this_frame = this_frame = GLOBALPARS(G_THIS_FRAME);
	unsigned long this_frame = this_frame = GLOBALPARS(G_THIS_FRAME);
/// No semaphors, so it is possible to miss event and wait until the streamer will be re-enabled before sending message,
/// No semaphors, so it is possible to miss event and wait until the streamer will be re-enabled before sending message,
@@ -1468,7 +1497,8 @@ int waitDaemonEnabled(int daemonBit) { // <0 - use default
 * @param daemonBit - bit number to accept control in P_DAEMON_EN parameter
 * @param daemonBit - bit number to accept control in P_DAEMON_EN parameter
 * @return (after possible waiting) true if there was no waiting, false if there was waiting
 * @return (after possible waiting) true if there was no waiting, false if there was waiting
 */
 */
int  isDaemonEnabled(int daemonBit) { // <0 - use default
int  isDaemonEnabled(int daemonBit)   // <0 - use default
{
	if ((daemonBit >= 0) && (daemonBit < 32)) lastDaemonBit = daemonBit;
	if ((daemonBit >= 0) && (daemonBit < 32)) lastDaemonBit = daemonBit;
	return ((framePars[GLOBALPARS(G_THIS_FRAME) & PARS_FRAMES_MASK].pars[P_DAEMON_EN] & (1 << lastDaemonBit)) != 0);
	return ((framePars[GLOBALPARS(G_THIS_FRAME) & PARS_FRAMES_MASK].pars[P_DAEMON_EN] & (1 << lastDaemonBit)) != 0);
}
}
+91 −84
Original line number Original line Diff line number Diff line
@@ -64,16 +64,20 @@
#include "camogm_jpeg.h"
#include "camogm_jpeg.h"
#include "camogm.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)
{
	return 0;
	return 0;
}
}
void camogm_free_jpeg(void) {
void camogm_free_jpeg(void)
{
}
}


int camogm_start_jpeg(void) {
int camogm_start_jpeg(void)
{
//!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;
	int rslt;
	int rslt;

	strcpy(state->path, state->path_prefix); //!make state->path a directory name (will be replaced when the frames will be written)
	strcpy(state->path, state->path_prefix); //!make state->path a directory name (will be replaced when the frames will be written)
	slash = strrchr(state->path, '/');
	slash = strrchr(state->path, '/');
	D2(fprintf(debug_file, "camogm_start_jpeg\n"));
	D2(fprintf(debug_file, "camogm_start_jpeg\n"));
@@ -90,11 +94,13 @@ D2(fprintf (debug_file, "camogm_start_jpeg\n"));
	}
	}
	return 0;
	return 0;
}
}
int camogm_frame_jpeg(void){
int camogm_frame_jpeg(void)
{
	int i, j;
	int i, j;
//   int fd;
//   int fd;
	ssize_t iovlen, l;
	ssize_t iovlen, l;
	struct iovec chunks_iovec[7];
	struct iovec chunks_iovec[7];

	l = 0;
	l = 0;
	for (i = 0; i < (state->chunk_index) - 1; i++) {
	for (i = 0; i < (state->chunk_index) - 1; i++) {
		chunks_iovec[i].iov_base = state->packetchunks[i + 1].chunk;
		chunks_iovec[i].iov_base = state->packetchunks[i + 1].chunk;
@@ -122,6 +128,7 @@ int camogm_frame_jpeg(void){
	return 0;
	return 0;
}
}


int camogm_end_jpeg(void){
int camogm_end_jpeg(void)
{
	return 0;
	return 0;
}
}
+255 −248
Original line number Original line Diff line number Diff line
@@ -67,10 +67,12 @@
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
int camogm_init_kml(void) {
int camogm_init_kml(void)
{
	return 0;
	return 0;
}
}
void camogm_free_kml(void) {
void camogm_free_kml(void)
{
}
}
/*
/*
   int camogm_start_mov(void) {
   int camogm_start_mov(void) {
@@ -91,7 +93,8 @@ int camogm_start_mov(void) {
   }
   }


 */
 */
int camogm_start_kml(void) {
int camogm_start_kml(void)
{
//  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
///    state->kml_exif[i]
///    state->kml_exif[i]
@@ -99,6 +102,7 @@ int camogm_start_kml(void) {
	struct exif_dir_table_t dir_table_entry;
	struct exif_dir_table_t dir_table_entry;
	int fd_ExifDir;
	int fd_ExifDir;
	int indx;
	int indx;

	for (indx = 0; indx < ExifKmlNumber; indx++) state->kml_exif[indx].ltag = 0;
	for (indx = 0; indx < ExifKmlNumber; indx++) state->kml_exif[indx].ltag = 0;
//! open Exif header directory file
//! open Exif header directory file
	fd_ExifDir = open(ExifDirFileName, O_RDONLY);
	fd_ExifDir = open(ExifDirFileName, O_RDONLY);
@@ -148,7 +152,8 @@ int camogm_start_kml(void) {
	return 0;
	return 0;
}
}


int camogm_frame_kml(void){
int camogm_frame_kml(void)
{
	char JPEGFileName[300];
	char JPEGFileName[300];
	char * filename;
	char * filename;
	int fd_JPEG;
	int fd_JPEG;
@@ -160,6 +165,7 @@ int camogm_frame_kml(void){
	int hours = 0, minutes = 0;
	int hours = 0, minutes = 0;
	double seconds = 0.0;
	double seconds = 0.0;
	int * ip;
	int * ip;

	if (state->kml_file) { // probably not needed
	if (state->kml_file) { // probably not needed
		i = state->this_frame_params.timestamp_sec - (state->kml_last_ts + state->kml_period);
		i = state->this_frame_params.timestamp_sec - (state->kml_last_ts + state->kml_period);
		if ((i > 1) || ((i == 0) && ( state->this_frame_params.timestamp_usec > state->kml_last_uts  ))) {
		if ((i > 1) || ((i == 0) && ( state->this_frame_params.timestamp_usec > state->kml_last_uts  ))) {
@@ -310,7 +316,8 @@ int camogm_frame_kml(void){
}
}




int camogm_end_kml(void){
int camogm_end_kml(void)
{


	if (state->kml_file) {
	if (state->kml_file) {
		fprintf(state->kml_file, "</Document>\n");
		fprintf(state->kml_file, "</Document>\n");
+376 −341
Original line number Original line Diff line number Diff line
@@ -110,9 +110,11 @@ int parse_special(void);
int parse(int top);
int parse(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)
{
	FILE* qt_header;
	FILE* qt_header;
	int size;
	int size;

	if ((qt_header = fopen(qtSourceFileName, "r")) == NULL) {
	if ((qt_header = fopen(qtSourceFileName, "r")) == NULL) {
		D0(fprintf(debug_file, "Error opening Quicktime header template %s for reading\n", qtSourceFileName));
		D0(fprintf(debug_file, "Error opening Quicktime header template %s for reading\n", qtSourceFileName));
		return -CAMOGM_FRAME_FILE_ERR;
		return -CAMOGM_FRAME_FILE_ERR;
@@ -137,14 +139,16 @@ int camogm_init_mov(void) {
	return 0;
	return 0;
}
}


void camogm_free_mov(void) {
void camogm_free_mov(void)
{
	if (q_template) {
	if (q_template) {
		free(q_template);
		free(q_template);
		q_template = NULL;
		q_template = NULL;
	}
	}
}
}


int camogm_start_mov(void) {
int camogm_start_mov(void)
{


//! allocate memory for the frame index table
//! allocate memory for the frame index table
	if (!((state->frame_lengths = malloc(4 * state->max_frames)))) return -CAMOGM_FRAME_MALLOC;
	if (!((state->frame_lengths = malloc(4 * state->max_frames)))) return -CAMOGM_FRAME_MALLOC;
@@ -161,10 +165,12 @@ int camogm_start_mov(void) {
	return 0;
	return 0;
}
}


int camogm_frame_mov(void){
int camogm_frame_mov(void)
{
	int i, j;
	int i, j;
	ssize_t iovlen, l;
	ssize_t iovlen, l;
	struct iovec chunks_iovec[7];
	struct iovec chunks_iovec[7];

	l = 0;
	l = 0;
	for (i = 0; i < (state->chunk_index) - 1; i++) {
	for (i = 0; i < (state->chunk_index) - 1; i++) {
		chunks_iovec[i].iov_base = state->packetchunks[i + 1].chunk;
		chunks_iovec[i].iov_base = state->packetchunks[i + 1].chunk;
@@ -183,10 +189,12 @@ int camogm_frame_mov(void){
	return 0;
	return 0;
}
}
//!move to the start of the file and insert generated header
//!move to the start of the file and insert generated header
int camogm_end_mov(void){
int camogm_end_mov(void)
{
	off_t l/*,he;
	off_t l/*,he;
	          unsigned char mdat_tag[8];
	          unsigned char mdat_tag[8];
	          unsigned char skip_tag[]="\0\0\0\0skip"*/;
	          unsigned char skip_tag[]="\0\0\0\0skip"*/;

	timescale = 10000;                                                      //! frame period measured in 1/10000 of a second?
	timescale = 10000;                                                      //! frame period measured in 1/10000 of a second?
	//! that was in old code. If that works - try to switch to microseconds
	//! that was in old code. If that works - try to switch to microseconds
	l = lseek(state->ivf, 0, SEEK_CUR) - (state->frame_data_start) + 8;     //!4-byte length+"mdat"
	l = lseek(state->ivf, 0, SEEK_CUR) - (state->frame_data_start) + 8;     //!4-byte length+"mdat"
@@ -239,8 +247,10 @@ int camogm_end_mov(void){


 */
 */


void putBigEndian(unsigned long d, int l) {
void putBigEndian(unsigned long d, int l)
{
	unsigned char od[4];
	unsigned char od[4];

	od[3] = d;
	od[3] = d;
	od[2] = d >> 8;
	od[2] = d >> 8;
	od[1] = d >> 16;
	od[1] = d >> 16;
@@ -249,9 +259,11 @@ unsigned char od[4];
//    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)
{
	int l;
	int l;
	const char * eol = strchr(&stream[*pos], '\n');
	const char * eol = strchr(&stream[*pos], '\n');

	if (!eol) eol = stream + (strlen(stream) - 1);  //!pointer to last before \0
	if (!eol) eol = stream + (strlen(stream) - 1);  //!pointer to last before \0
	l = (eol - stream) - (*pos);
	l = (eol - stream) - (*pos);
//     if (l >= size) eol=stream+ (*pos+size-1);
//     if (l >= size) eol=stream+ (*pos+size-1);
@@ -262,7 +274,8 @@ char * sfgets(char * str, int size, const char * stream, int * pos) {
	return str;
	return str;
}
}


int parse_special(void) {
int parse_special(void)
{


	time_t ltime;
	time_t ltime;
	int n, j, l;
	int n, j, l;
@@ -270,21 +283,40 @@ int parse_special(void) {
	char c;
	char c;
	int i = 0;
	int i = 0;
	int gap;
	int gap;

//	while (((c=fgetc(infile))!=0x20) && (c!=0x09) && (c!=0x0a) && (c!=0x0d) && (c!=0x0) && (i<255) && ( feof(infile) == 0 )) str[i++]=c;
//	while (((c=fgetc(infile))!=0x20) && (c!=0x09) && (c!=0x0a) && (c!=0x0d) && (c!=0x0) && (i<255) && ( feof(infile) == 0 )) str[i++]=c;
	while (((c = iFile[iPos++]) != 0x20) && (c != 0x09) && (c != 0x0a) && (c != 0x0d) && (c != 0x0) && (i < 255) && ( iPos < iFileLen )) str[i++] = c;
	while (((c = iFile[iPos++]) != 0x20) && (c != 0x09) && (c != 0x0a) && (c != 0x0d) && (c != 0x0) && (i < 255) && ( iPos < iFileLen )) str[i++] = c;
	str[i] = 0;
	str[i] = 0;


	D4(fprintf(debug_file, "parse_special, str=!%s\n", str));
	D4(fprintf(debug_file, "parse_special, str=!%s\n", str));


	if (strcmp(str,"mdata")==0)  {putBigEndian(headerSize, 4);return 0;} // will put zeroes on pass 1
	if (strcmp(str, "mdata") == 0) {
	if (strcmp(str,"height")==0) {putBigEndian(height,2);return 0;}
		putBigEndian(headerSize, 4); return 0;
	if (strcmp(str,"width")==0)  {putBigEndian(width,2);return 0;}
	}                                                                    // will put zeroes on pass 1
	if (strcmp(str,"width")==0)  {putBigEndian(width,2);return 0;}
	if (strcmp(str, "height") == 0) {
	if (strcmp(str,"nframes")==0)  {putBigEndian(nframes,4);return 0;}
		putBigEndian(height, 2); return 0;
	if (strcmp(str,"timescale")==0)  {putBigEndian(timescale,4);return 0;}
	}
	if (strcmp(str,"duration")==0)  {putBigEndian(nframes*sample_dur,4);return 0;}
	if (strcmp(str, "width") == 0) {
	if (strcmp(str,"frame_duration")==0)  {putBigEndian(sample_dur,4);return 0;}
		putBigEndian(width, 2); return 0;
	if (strcmp(str,"samples_chunk")==0)  {putBigEndian(samplesPerChunk, 4);return 0;} // will put zeroes on pass 1
	}
	if (strcmp(str, "width") == 0) {
		putBigEndian(width, 2); return 0;
	}
	if (strcmp(str, "nframes") == 0) {
		putBigEndian(nframes, 4); return 0;
	}
	if (strcmp(str, "timescale") == 0) {
		putBigEndian(timescale, 4); return 0;
	}
	if (strcmp(str, "duration") == 0) {
		putBigEndian(nframes * sample_dur, 4); return 0;
	}
	if (strcmp(str, "frame_duration") == 0) {
		putBigEndian(sample_dur, 4); return 0;
	}
	if (strcmp(str, "samples_chunk") == 0) {
		putBigEndian(samplesPerChunk, 4); return 0;
	}                                                                                 // will put zeroes on pass 1
	if (strcmp(str, "sample_sizes") == 0) {
	if (strcmp(str, "sample_sizes") == 0) {
		if (sizes != NULL) for (i = 0; i < nframes; i++) putBigEndian(sizes[i], 4);
		if (sizes != NULL) for (i = 0; i < nframes; i++) putBigEndian(sizes[i], 4);
		else for (i = 0; i < nframes; i++) putBigEndian(framesize, 4);
		else for (i = 0; i < nframes; i++) putBigEndian(framesize, 4);
@@ -337,11 +369,13 @@ int parse_special(void) {






int parse (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;
	unsigned long d, l;
	unsigned long d, l;
	char * cp;
	char * cp;

	D4(fprintf(debug_file, "parse(%x)\n", top));
	D4(fprintf(debug_file, "parse(%x)\n", top));
//	c=fgetc(infile);
//	c=fgetc(infile);
	c = iFile[iPos++];
	c = iFile[iPos++];
@@ -432,7 +466,8 @@ int quicktime_template_parser (const char * i_iFile, //! now - string containing
			      int i_timescale,
			      int i_timescale,
			      int * i_sizes,
			      int * i_sizes,
			      int data_start // zero if dfata is not written yet (will be no gap)
			      int data_start // zero if dfata is not written yet (will be no gap)
         ) {
			      )
{
	iFile =           i_iFile;
	iFile =           i_iFile;
	width =           i_width;
	width =           i_width;
	height =          i_height;
	height =          i_height;
+155 −148
Original line number Original line Diff line number Diff line
@@ -61,19 +61,23 @@
#include "camogm_ogm.h"
#include "camogm_ogm.h"
#include "camogm.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)
{
	return 0;
	return 0;
}
}
void camogm_free_ogm(void) {
void camogm_free_ogm(void)
{
}
}




int camogm_start_ogm(void) {
int camogm_start_ogm(void)
{
	char vendor[] = "ElphelOgm v 0.1";
	char vendor[] = "ElphelOgm v 0.1";
	int pos;
	int pos;
	stream_header sh;
	stream_header sh;
	char hdbuf[sizeof(sh) + 1];
	char hdbuf[sizeof(sh) + 1];
	ogg_packet ogg_header;
	ogg_packet ogg_header;

	sprintf(state->path, "%s%010ld_%06ld.ogm", state->path_prefix, state->frame_params.timestamp_sec, state->frame_params.timestamp_usec);
	sprintf(state->path, "%s%010ld_%06ld.ogm", state->path_prefix, state->frame_params.timestamp_sec, state->frame_params.timestamp_usec);
	if (!((state->vf = fopen(state->path, "w+"))) ) {
	if (!((state->vf = fopen(state->path, "w+"))) ) {
		D0(fprintf(debug_file, "Error opening %s for writing\n", state->path));
		D0(fprintf(debug_file, "Error opening %s for writing\n", state->path));
@@ -167,9 +171,11 @@ state->granulepos= (ogg_int64_t) ( (((double) state->frame_params.timestamp_usec
	return 0;
	return 0;
}
}


int camogm_frame_ogm(void){
int camogm_frame_ogm(void)
{
	int indx;
	int indx;
	elph_ogg_packet elp_packet;
	elph_ogg_packet elp_packet;

	elp_packet.bytes = 0;
	elp_packet.bytes = 0;
	for (indx = 0; indx < state->chunk_index; indx++) elp_packet.bytes += state->packetchunks[indx].bytes;
	for (indx = 0; indx < state->chunk_index; indx++) elp_packet.bytes += state->packetchunks[indx].bytes;
	elp_packet.packet = state->packetchunks;
	elp_packet.packet = state->packetchunks;
@@ -216,7 +222,8 @@ int camogm_frame_ogm(void){


//!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(void)
{
//! put zero-packet it into stream
//! put zero-packet it into stream
	ogg_packet ogg_header;
	ogg_packet ogg_header;


+140 −140

File changed.

Contains only whitespace changes.

+44 −44

File changed.

Contains only whitespace changes.

+56 −56

File changed.

Contains only whitespace changes.

Loading