#include #include "cfg.h" #include "utils.h" #ifdef WITH_GWAVI #include "target_avi.h" #else #include "target_ffmpeg.h" #endif #include "log.h" std::string describe_interface(const instance_t *const inst, const interface *const i) { std::string inst_url = url_escape(inst -> name); std::string module_int = i -> get_id(); std::string type = "!!!", div = "some_section"; switch(i -> get_class_type()) { case CT_HTTPSERVER: type = "HTTP server"; div = "http-server"; break; case CT_MOTIONTRIGGER: type = "motion trigger"; div = "motion-trigger"; break; case CT_TARGET: type = "stream writer"; div = "stream-writer"; break; case CT_SOURCE: type = "source"; div = "source"; break; case CT_LOOPBACK: type = "video4linux loopback"; div = "v4l-loopback"; break; case CT_VIEW: type = "view"; div = "view"; break; case CT_NONE: type = "???"; break; } std::string out = std::string("

" + type + "

description: " + i -> get_descr() + "
type: " + type + "

"; return out; } bool pause(instance_t *const cfg, const std::string & which, const bool p) { bool rc = false; interface *i = find_interface_by_id(cfg, which); if (i != NULL) { if (p) rc = i -> pause(); else { i -> unpause(); rc = true; } } return rc; } bool start_stop(interface *const i, const bool strt) { bool rc = false; if (i != NULL) { if (strt) i -> start(); else i -> stop(); // FIXME time-out? rc = true; } return rc; } bool take_a_picture(source *const s, const std::string & snapshot_dir, const int quality, const bool repeat) { uint64_t prev_ts = get_us(); int w = -1, h = -1; uint8_t *work = NULL; size_t work_len = 0; if (!s -> get_frame(E_JPEG, quality, &prev_ts, &w, &h, &work, &work_len, repeat)) return false; std::string name = gen_filename(s, default_fmt, snapshot_dir, "snapshot-", "jpg", get_us(), 0); create_path(name); log(LL_INFO, "Snapshot will be written to %s", name.c_str()); FILE *fh = fopen(name.c_str(), "w"); if (!fh) { log(LL_ERR, "open_memstream() failed"); free(work); return false; } bool rc = fwrite(work, 1, work_len, fh) == work_len; fclose(fh); free(work); return rc; } interface * start_a_video(source *const s, const std::string & snapshot_dir, const int quality, configuration_t *const cfg, const bool is_view_proxy) { const std::string id = myformat("%ld", rand()); // FIXME better rand const std::string descr = "snapshot started by HTTP server"; std::vector *const filters = new std::vector(); #ifdef WITH_GWAVI interface *i = new target_avi(id, descr, s, snapshot_dir, "snapshot-", default_fmt, quality, -1, -1, filters, "", "", "", -1, cfg, is_view_proxy, false); #else interface *i = new target_ffmpeg(id, descr, "", s, snapshot_dir, "snapshot-", default_fmt, -1, -1, "mp4", 201000, filters, "", "", "", -1, cfg, is_view_proxy, false); #endif i -> start(); return i; } bool validate_file(const std::string & snapshot_dir, const std::string & filename) { bool rc = false; auto *files = load_filelist(snapshot_dir, ""); for(auto cur : *files) { if (cur.name == filename) { rc = true; break; } } delete files; return rc; } view *find_view(instance_t *const views, const std::string & id) { if (!views) return NULL; for(interface *cur : views -> interfaces) { view *v = (view *)cur; if (v -> get_id() == id) return v; } return NULL; }