def make_QLBQ(path_payload, start, duration): payloadlen = os.stat(path_payload).st_size is_pvr = True logger.debug('[DVRWriter] => start = {0}, {1}'.format(api.bl_int_ts2bl_str(start), start)) logger.debug('[DVRWriter] => duration = {0}'.format(duration)) logger.debug('[DVRWriter] => is_pvr = {0}'.format(is_pvr)) logger.debug('[DVRWriter] => payloadlen = {0}'.format(payloadlen)) logger.debug('[DVRWriter] => path_payload = {0}'.format(path_payload)) return start, duration, is_pvr, payloadlen
def request_names(rtp_db, startstamp, duration): dvr_lst = load_dvr_lst(rtp_db) if dvr_lst: if is_internal_pts_sort: def make_fname(int_ts): return "=%s=" % int_ts def un_fname(x): return int(x.split("=")[1]) def less_op(x1, x2): return un_fname(x1) < un_fname(x2) beg = bisect_left(dvr_lst, make_fname(startstamp), less_op=less_op) end = bisect_right(dvr_lst, make_fname(startstamp+duration), less_op=less_op) else: beg = bisect_left(dvr_lst, api.bl_int_ts2bl_str(startstamp)) end = bisect_right(dvr_lst, api.bl_int_ts2bl_str(startstamp+duration)) lst = dvr_lst[beg:end] else: lst = [] return lst
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
#!/usr/bin/env python3 # coding: utf-8 if __name__ == '__main__': import api for date_str in ["161005131708.111", "19700101000200.000"]: ts = api.parse_bl_ts(date_str) #print(ts) date_str2 = api.bl_int_ts2bl_str(ts) assert date_str == date_str2 if False: full_lst = [chr(idx) for idx in range(ord('a'), ord('z') + 1)] stream_range = { "names": "a, b, c, d, p-x", #"part": "1, 4 - 6 / 6", #"python": [[1, [4, 6]], 6], "size": 10, } stream_lst = api.calc_from_stream_range(full_lst, stream_range) print(stream_lst) if False: import datetime now = datetime.datetime.utcnow() print(now) res = api.calc_flv_ts(now) print("%x" % res)
#!/usr/bin/env python3 # coding: utf-8 if __name__ == "__main__": import api for date_str in ["161005131708.111", "19700101000200.000"]: ts = api.parse_bl_ts(date_str) # print(ts) date_str2 = api.bl_int_ts2bl_str(ts) assert date_str == date_str2 if False: full_lst = [chr(idx) for idx in range(ord("a"), ord("z") + 1)] stream_range = { "names": "a, b, c, d, p-x", # "part": "1, 4 - 6 / 6", # "python": [[1, [4, 6]], 6], "size": 10, } stream_lst = api.calc_from_stream_range(full_lst, stream_range) print(stream_lst) if False: import datetime now = datetime.datetime.utcnow() print(now) res = api.calc_flv_ts(now) print("%x" % res)