91 lines
2.6 KiB
C
91 lines
2.6 KiB
C
#include <math.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include "Python.h"
|
|
#include "recording.h"
|
|
#include "sample.h"
|
|
#include "structmember.h"
|
|
|
|
#ifndef _BPS_EXPORT_H_
|
|
#define _BPS_EXPORT_H_
|
|
|
|
/**
|
|
* @return: 1 on fail
|
|
*/
|
|
typedef int(RecordingMetaExportInit)(RecordingMeta *recording_meta, //
|
|
FILE * export_file,
|
|
void * options);
|
|
|
|
/**
|
|
* @return: 1 on fail
|
|
*/
|
|
typedef int(RecordingMetaExportFunc)(RecordingMeta *recording_meta, //
|
|
FILE * export_file,
|
|
int file_index,
|
|
FILE * recording_file,
|
|
void * options);
|
|
|
|
PyObject *export_recording_meta(const char * meta_filepath, //
|
|
const char * export_path,
|
|
RecordingMetaExportInit *init_function,
|
|
RecordingMetaExportFunc *export_function,
|
|
void * export_options) {
|
|
// open recording meta file
|
|
RecordingMeta *recording_meta = open_recording_meta_file(meta_filepath);
|
|
|
|
if (recording_meta == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
// open write file
|
|
FILE *export_file = fopen(export_path, "w");
|
|
|
|
// set buffer mode
|
|
setvbuf(export_file, NULL, _IOFBF, BUFSIZ);
|
|
|
|
// invoke init_function
|
|
if (init_function(recording_meta, export_file, export_options)) {
|
|
goto error;
|
|
}
|
|
|
|
// foreach recording file
|
|
for (unsigned int file_index = 0; file_index < recording_meta->recording_file_size; file_index++) {
|
|
RecordingFile *recording_file = ensure_recording_file(recording_meta, file_index);
|
|
|
|
if (recording_file == NULL) {
|
|
goto error;
|
|
}
|
|
|
|
// invoke export_function
|
|
if (export_function(recording_meta, export_file, file_index, recording_file->recording_file, export_options)) {
|
|
goto error;
|
|
}
|
|
|
|
// close recording file
|
|
fclose(recording_file->recording_file);
|
|
recording_file->recording_file = NULL;
|
|
}
|
|
|
|
// invoke export_function
|
|
if (export_function(recording_meta, export_file, -1, NULL, export_options)) {
|
|
goto error;
|
|
}
|
|
|
|
fclose(export_file);
|
|
|
|
// free recording meta
|
|
free_recording_meta(recording_meta);
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
error:
|
|
if (export_file != NULL) fclose(export_file);
|
|
if (recording_meta != NULL) {
|
|
free_recording_meta(recording_meta);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
#endif
|