summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-04-15 14:34:53 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-04-15 14:34:53 (GMT)
commit5f89bdd315f29b4a58612b39d30ca2c32c136b36 (patch)
tree28a8fa2edb817c9406301a875103a419b2e5447a
parent9fdfadf40d3be2f98376556622486c79dfdb809a (diff)
time boundary calculations added
-rw-r--r--src/options.c2
-rw-r--r--src/writer.c42
-rw-r--r--src/writer.h10
3 files changed, 52 insertions, 2 deletions
diff --git a/src/options.c b/src/options.c
index 3595866..e30e149 100644
--- a/src/options.c
+++ b/src/options.c
@@ -288,7 +288,7 @@ void options_print_usage()
printf(" [-s|--source] <description> a gstreamer pipeline-style description which will be used\n");
printf(" as data source, see gst-launch man-page for syntax\n");
printf(" [-d|--output-dir] <path> path to the output directory\n");
- printf(" [-f|--name-format] <format> the file name format, see manpage of date for the syntax\n");
+ printf(" [-f|--name-format] <format> the file name format, see manpage of strftime for the syntax\n");
printf(" [-i|--interval] <value> interval for time checks in ms\n");
printf(" [-o|--offset] <value> time offset for recordings in ms\n");
}
diff --git a/src/writer.c b/src/writer.c
index c8689f0..633a34e 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -38,6 +38,40 @@
#include "datatypes.h"
#include "log.h"
+static void init_time_boundaries(writer_t* writer)
+{
+ if(!writer)
+ return;
+
+ struct timespec now;
+ clock_gettime(CLOCK_REALTIME, &now);
+
+ struct tm bd_time;
+ localtime_r(&(now.tv_sec), &bd_time);
+
+ log_printf(INFO, "it's now: %02d:%02d:%02d on %d.%d.%d", bd_time.tm_hour, bd_time.tm_min, bd_time.tm_sec, bd_time.tm_mday, bd_time.tm_mon+1, bd_time.tm_year+1900);
+
+ strftime(writer->current_.name_, sizeof(writer->current_.name_), writer->name_format_, &bd_time);
+ log_printf(INFO, "current filename is: %s(.?)", writer->current_.name_);
+
+
+ bd_time.tm_sec = 0;
+ bd_time.tm_min = 0;
+
+ time_t T = mktime(&bd_time);
+ T+=3600;
+
+ localtime_r(&T, &bd_time);
+
+ log_printf(INFO, "next boundary is at: %02d:%02d:%02d on %d.%d.%d", bd_time.tm_hour, bd_time.tm_min, bd_time.tm_sec, bd_time.tm_mday, bd_time.tm_mon+1, bd_time.tm_year+1900);
+
+ strftime(writer->next_.name_, sizeof(writer->next_.name_), writer->name_format_, &bd_time);
+ log_printf(INFO, "next filename will be: %s(.?)", writer->next_.name_);
+
+ struct timespec b = { T, 0 };
+ writer->next_boundary_ = b;
+}
+
int writer_init(writer_t* writer, const char* name_format, const char* output_dir, int interval, int offset)
{
if(!writer)
@@ -57,10 +91,16 @@ int writer_init(writer_t* writer, const char* name_format, const char* output_di
writer->output_dir_ = output_dir;
writer->interval_ = interval * GST_MSECOND;
writer->offset_ = offset * GST_MSECOND;
+ init_time_boundaries(writer);
return 0;
}
+static int open_file(file_t* file)
+{
+
+}
+
static gpointer writer_thread_func(gpointer data)
{
writer_t *writer = (writer_t*)data;
@@ -79,7 +119,7 @@ static gpointer writer_thread_func(gpointer data)
struct tm now_bd;
localtime_r(&(now.tv_sec), &now_bd);
- log_printf(NOTICE, "it's now: %d:%d:%d on %d.%d.%d", now_bd.tm_hour, now_bd.tm_min, now_bd.tm_sec, now_bd.tm_mday, now_bd.tm_mon+1, now_bd.tm_year+1900);
+ log_printf(DEBUG, "it's now: %02d:%02d:%02d on %d.%d.%d", now_bd.tm_hour, now_bd.tm_min, now_bd.tm_sec, now_bd.tm_mday, now_bd.tm_mon+1, now_bd.tm_year+1900);
}
log_printf(NOTICE, "writer thread stopped");
diff --git a/src/writer.h b/src/writer.h
index 38df718..4619d95 100644
--- a/src/writer.h
+++ b/src/writer.h
@@ -29,6 +29,13 @@
#define RHARCHIVE_writer_h_INCLUDED
#include <gst/gst.h>
+#include <time.h>
+
+struct file_struct {
+ int fd_;
+ char name_[100];
+};
+typedef struct file_struct file_t;
struct writer_struct {
GstElement* sink_;
@@ -39,6 +46,9 @@ struct writer_struct {
const char* output_dir_;
GstClockTime interval_;
GstClockTime offset_;
+ file_t current_;
+ file_t next_;
+ struct timespec next_boundary_;
};
typedef struct writer_struct writer_t;