more red diffs, remove hevc framereader stuff and two unused classes

old-commit-hash: d4f89430755445338270bb0a4c63d44404422fd6
This commit is contained in:
George Hotz
2020-04-24 12:15:50 -07:00
parent cc6477015a
commit 7eb4fabe97
3 changed files with 0 additions and 584 deletions
-125
View File
@@ -413,131 +413,6 @@ def index_pstream(fns, typ, cache_prefix=None):
with atomic_write_in_dir(cache_path, mode="wb", overwrite=True) as cache_file:
pickle.dump(segment_index, cache_file, -1)
def gpu_info():
ret = []
for fn in glob.glob("/proc/driver/nvidia/gpus/*/information"):
with open(fn, "r") as f:
dat = f.read()
kvs = dat.strip().split("\n")
kv = {}
for s in kvs:
k, v = s.split(":", 1)
kv[k] = v.strip()
ret.append(kv)
return ret
def gpu_supports_hevc(gpuinfo):
return ("GTX 10" in gpuinfo['Model'] or "GTX 20" in gpuinfo['Model'] or gpuinfo['Model'] == "Graphics Device")
def find_hevc_gpu():
for gpuinfo in gpu_info():
if gpu_supports_hevc(gpuinfo):
return int(gpuinfo['Device Minor'])
return None
def _ffmpeg_fcamera_input_for_frame_info(frame_info):
st = time.time()
fn, num, count, cache_prefix = frame_info
assert fn.endswith('.hevc')
sindex = index_stream(fn, "hevc", cache_prefix=cache_prefix)
index = sindex['index']
prefix = sindex['global_prefix']
probe = sindex['probe']
frame_e = num + count
frame_b = num
# must start decoding on an i-frame
while index[frame_b, 0] != HEVC_SLICE_I:
frame_b -= 1
offset_b = index[frame_b, 1]
offset_e = index[frame_e, 1]
assert frame_b <= num < frame_e
skip = num - frame_b
w = probe['streams'][0]['width']
h = probe['streams'][0]['height']
assert (h, w) == (874, 1164)
st2 = time.time()
with FileReader(fn) as f:
f.seek(offset_b)
input_data = f.read(offset_e - offset_b)
et = time.time()
get_time = et-st
get_time2 = et-st2
if get_time > 10.0:
print("TOOK OVER 10 seconds to fetch %r %f %f" % (frame_info, get_time, get_time2))
return prefix, input_data, skip, count
def _ffmpeg_fcamera_input_for_frame(pair):
cookie, frame_info = pair
try:
return cookie, _ffmpeg_fcamera_input_for_frame_info(frame_info)
except Exception as e:
# Let the caller handle exceptions.
return cookie, e
def _feed_ffmpeg_fcamera_input_work_loop(frames, proc_stdin, select_pipe_fd, cookie_queue):
last_prefix = None
"""
with ThreadPoolExecutor(64) as pool:
futures = []
for f in frames:
futures.append(pool.submit(_ffmpeg_fcamera_input_for_frame, f))
for f in as_completed(futures):
cookie, data = f.result()
if isinstance(data, Exception):
# Just print exceptions for now.
print(data)
continue
prefix, input_data, skip, count = data
cookie_queue.put((cookie, count))
# Write zeros for skipped frames, ones for keep frames.
os.write(select_pipe_fd, b"\x00" * skip + b"\x01" * count)
if prefix != last_prefix:
proc_stdin.write(prefix)
last_prefix = prefix
proc_stdin.write(input_data)
"""
num_threads = 64
for cookie, data in async_generator(
num_threads, 8 * num_threads, 8 * num_threads,
reliable=False)(_ffmpeg_fcamera_input_for_frame)(frames):
if isinstance(data, Exception):
# Just print exceptions for now.
print(data)
continue
prefix, input_data, skip, count = data
cookie_queue.put((cookie, count))
# Write zeros for skipped frames, ones for keep frames.
os.write(select_pipe_fd, b"\x00" * skip + b"\x01" * count)
if prefix != last_prefix:
proc_stdin.write(prefix)
last_prefix = prefix
proc_stdin.write(input_data)
_FCAMERA_FEED_SUCCESS = object()
def feed_ffmpeg_fcamera_input(frames, proc_stdin, select_pipe_fd, cookie_queue):
print("Feed started on {}".format(threading.current_thread().name))
try:
_feed_ffmpeg_fcamera_input_work_loop(frames, proc_stdin, select_pipe_fd, cookie_queue)
cookie_queue.put((_FCAMERA_FEED_SUCCESS, None))
finally:
# Always close ffmpeg input.
proc_stdin.close()
def read_file_check_size(f, sz, cookie):
buff = bytearray(sz)
bytes_read = f.readinto(buff)