Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/mix.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,16 @@ struct mix {
mix_time_rec_h *time_rec_h;
mix_talk_detect_h *talk_detect_h;
enum mix_rec rec_state;
struct mix_rec_s {
char base[PATH_SZ];
char name[PATH_SZ];
char full[PATH_SZ];
} rec;
char path[PATH_SZ];
};



struct user {
char id[USERID_SZ];
int pidx; /* Video position index, 0 => disabled */
Expand Down
67 changes: 55 additions & 12 deletions src/mix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <time.h>
#include <unistd.h>
#include <sys/wait.h>
#include <mix.h>

extern const char *GIT_TAG;
Expand Down Expand Up @@ -315,12 +316,41 @@ enum mix_rec slmix_rec_state(struct mix *m)
}


static int rec_zip_folder(void *arg)
{
struct mix_rec_s *r = arg;
int status;

if (!str_isset(r->base) || !str_isset(r->name)) {
mem_deref(r);
return EINVAL;
}

pid_t pid = fork();
if (pid < 0) {
warning("slmix: fork failed for zip: %m\n", errno);
mem_deref(r);
return errno;
}
else if (pid == 0) {
if (chdir(r->base) != 0)
_exit(126);
char zipname[PATH_SZ];
re_snprintf(zipname, sizeof(zipname), "%s.zip", r->name);
execlp("zip", "zip", "-r", zipname, r->name, (char *)NULL);
_exit(127);
}
waitpid(pid, &status, 0);
mem_deref(r);
return WEXITSTATUS(status);
}


void slmix_record(struct mix *m, enum mix_rec state)
{
struct tm tm;
time_t now = time(NULL);
char folder[PATH_SZ] = {0};
int err = 0;
time_t now = time(NULL);
int err = 0;

if (!m || !m->video_rec_h || !m->audio_rec_h) {
warning("slmix: record init state %s failed\n",
Expand All @@ -338,27 +368,40 @@ void slmix_record(struct mix *m, enum mix_rec state)
}

info("slmix: record stopped\n");

/* zip files if record was started before */
if (m->rec_state > REC_DISABLED) {
struct mix_rec_s *r =
mem_zalloc(sizeof(struct mix_rec_s), NULL);
if (!r)
goto out;

*r = m->rec;
re_thread_async(rec_zip_folder, NULL, r);
}

goto out;
}

localtime_r(&now, &tm);

(void)re_snprintf(folder, sizeof(folder), "webui/public/download/%s",
m->token_download);
fs_mkdir(folder, 0755);
(void)re_snprintf(m->rec.base, sizeof(m->rec.base),
"webui/public/download/%s", m->token_download);
fs_mkdir(m->rec.base, 0755);

(void)re_snprintf(folder, sizeof(folder),
"webui/public/download/%s/%H-%s", m->token_download,
timestamp_print, &tm, mix.room);
fs_mkdir(folder, 0755);
(void)re_snprintf(m->rec.name, sizeof(m->rec.name), "%H-%s",
timestamp_print, &tm, m->room);

(void)re_snprintf(m->rec.full, sizeof(m->rec.full), "%s/%s",
m->rec.base, m->rec.name);
fs_mkdir(m->rec.full, 0755);

if (state & REC_VIDEO) {
err = m->video_rec_h(folder, true);
err = m->video_rec_h(m->rec.full, true);
}

if (state & REC_AUDIO) {
err |= m->audio_rec_h(folder, true);
err |= m->audio_rec_h(m->rec.full, true);
}

if (err) {
Expand Down
Loading