def write_to_dvr(dvr_writer, chunk_fpath, utc_ts, duration, chunk_range): """ Все временные типы здесь - в миллисекундах """ res = True if configuration.local_dvr: dvr_dir = api.rtp2local_dvr(chunk_range.r_t_p, configuration.db_path) import o_p o_p.force_makedirs(dvr_dir) import datetime fname = "%s=%s=%s.dvr" % (api.bl_int_ts2bl_str(utc_ts), utc_ts, duration) import shutil shutil.copyfile(chunk_fpath, os.path.join(dvr_dir, fname)) else: if write_dvr_per_profile: # расчет суммы размеров очередей по всем сокетам if not "queue_size" in dir(dvr_writer): dvr_writer.queue_size = 0 obj = chunk_range def write_func(stream, is_first): if is_first: use_cmd = api.pack_rtp_cmd(WriteCmd.USE, chunk_range.r_t_p, '') stream.write(use_cmd) def on_queue_change(change): dvr_writer.queue_size += change stream.on_queue_change = on_queue_change qlbq = make_QLBQ(chunk_fpath, utc_ts, duration) pack = api.pack_cmd( "QLBQ", WriteCmd.DATA, *qlbq ) write_chunk(stream, chunk_fpath, qlbq[-1], pack) log_queue(dvr_writer.queue_size) else: obj = dvr_writer def write_func(stream, is_first): write_full_chunk( stream, chunk_range, start_ts=start_ts, duration=duration, chunk_fpath=chunk_fpath, ) res = api.connect_to_dvr(obj, (dvr_writer.host, dvr_writer.port), write_func) return res
def rtp_db2dir(rtp_db): return api.rtp2local_dvr(rtp_db.r_t_p, rtp_db.db_path)