62#define MOD_NAME "[export] "
92 TRED(
"--record")
"[=<dir>[:limit=<n>[:exit_on_limit]][:noaudio]"
93 "[:novideo][:override][:paused]] ")
"\n" "\t" TBOLD(
TRED(
"-E")
94 "[<dir>[:<opts>]]")
"\n\t" TBOLD(
"--record=help | -Ehelp")
"\n");
97 " most <n> video frames (with optional exit)\n");
99 " - export even if it would override "
100 "existing files in the given directory\n");
102 color_printf(
TERM_BOLD "\tpaused" TERM_RESET " - use specified directory but do not export immediately (can be started with a key or through control socket)\n");
112 snprintf(buf,
sizeof buf,
"%s", ccfg);
114 char *save_ptr = NULL;
116 while ((
item = strtok_r(cfg,
":", &save_ptr)) != NULL) {
120 }
else if (strstr(
item,
"noaudio") ==
item) {
122 }
else if (strstr(
item,
"novideo") ==
item) {
124 }
else if (strstr(
item,
"override") ==
item) {
126 }
else if (strstr(
item,
"paused") ==
item) {
127 *should_export =
false;
128 }
else if (strstr(
item,
"limit=") ==
item) {
129 s->
limit = strtoll(
item + strlen(
"limit="), NULL, 0);
134 }
else if (strcmp(
item,
"exit_on_limit") == 0) {
136 }
else if (s->
dir == NULL && cfg != NULL) {
147#define HANDLE_ERROR export_destroy(s); return NULL;
152 pthread_mutex_init(&s->
lock, NULL);
158 if (s->
dir == NULL) {
192 snprintf(
name,
sizeof name,
"%s/sound.wav", s->
dir);
220 for (
int i = 1; i <= MAX_EXPORTS; i++) {
222 time_t t = time(NULL);
223 struct tm tm_buf = { 0 };
225 snprintf(
name,
sizeof name,
"%s/", prefix);
227 "export.%Y%m%d", &tm_buf);
230 sizeof name - strlen(
name),
"-%d", i);
232 int ret = mkdir(
name, S_IRWXU | S_IRWXG | S_IRWXO);
234 if(errno == EEXIST) {
238 MOD_NAME "Directory creation failed: %s\n",
248 DIR *d = opendir(dir);
254 bool ret = readdir(d) == NULL;
265 int ret = mkdir(s->
dir, S_IRWXU | S_IRWXG | S_IRWXO);
267 if(errno != EEXIST) {
268 perror(
"[Export] Directory creation failed");
277 "Warning: directory %s exists and is not "
278 "an empty directory! Trying to create "
281 char *prefix = s->
dir;
311 pthread_mutex_destroy(&s->
lock);
321 pthread_mutex_lock(&s->
lock);
323 if (strcmp(
msg->text,
"toggle") == 0) {
331 }
else if (strcmp(
msg->text,
"status") == 0) {
336 pthread_mutex_unlock(&s->
lock);
349 pthread_mutex_lock(&s->
lock);
353 pthread_mutex_unlock(&s->
lock);
364 pthread_mutex_lock(&s->
lock);
369 if (--s->
limit == 0) {
377 pthread_mutex_unlock(&s->
lock);
struct video_frame * frame
struct audio_export * audio_export_init(const char *filename)
void audio_export_destroy(struct audio_export *s)
void audio_export(struct audio_export *s, const struct audio_frame *frame)
int color_printf(const char *format,...)
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_NOTICE
information that may be interesting
#define LOG_LEVEL_ERROR
general errors
#define LOG_LEVEL_WARNING
less severe errors
void export_audio(struct exporter *s, struct audio_frame *frame)
static bool enable_export(struct exporter *s)
static void process_messages(struct exporter *s)
void export_video(struct exporter *s, struct video_frame *frame)
static bool parse_options(struct exporter *s, const char *ccfg, bool *should_export)
static void disable_export(struct exporter *s)
static bool create_dir(struct exporter *s)
void export_destroy(struct exporter *s)
static void new_msg(struct module *mod)
static bool dir_is_empty(const char *dir)
struct exporter * export_init(struct module *parent, const char *cfg, bool should_export)
static char * create_implicit_dir(const char *prefix)
void module_init_default(struct module *module_data)
void module_register(struct module *module_data, struct module *parent)
void module_done(struct module *module_data)
@ STR_LEN
"standard" string length placeholder
void free_message(struct message *msg, struct response *r)
struct response * new_response(int status, const char *text)
struct message * check_message(struct module *mod)
#define RESPONSE_NOT_FOUND
const char * ug_strerror(int errnum)
struct used to comunicate with audio capture/playback device
struct video_export * video_export
struct audio_export * audio_export
long long int limit
number of video frames to record, -1 == unlimited (default)
notify_t new_message
if set, notifies module that new message is in queue, receiver lock is hold during the call
Struct video_frame represents a video frame and contains video description.
void video_export(struct video_export *s, struct video_frame *frame)
void video_export_destroy(struct video_export *s)
struct video_export * video_export_init(const char *path)