Skip to content

Commit

Permalink
Changed utf8 decoding to avoid crashes with invalid characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilianavt committed Aug 7, 2021
1 parent 22384e3 commit 84c81f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions dshowcapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_devices(self):

def get_device(self, device_number):
self.lib.get_device(self.cap, device_number, self.name_buffer, 255)
name_str = str(self.name_buffer.value.decode('utf8'))
name_str = str(self.name_buffer.value.decode('utf8', 'surrogateescape'))
return name_str

def get_info(self):
Expand All @@ -113,7 +113,7 @@ def get_info(self):
json_length = self.lib.get_json_length(self.cap);
json_buffer = create_string_buffer(json_length)
self.lib.get_json(self.cap, json_buffer, json_length);
json_text = str(json_buffer.value.decode('utf8'))
json_text = str(json_buffer.value.decode('utf8', 'surrogateescape'))
self.info = json.loads(json_text)
for cam in self.info:
cam["type"] = "DirectShow"
Expand All @@ -124,7 +124,7 @@ def get_info(self):
json_length = self.bm_lib.get_json_length();
json_buffer = create_string_buffer(json_length)
self.bm_lib.get_json(json_buffer, json_length);
json_text = str(json_buffer.value.decode('utf8'))
json_text = str(json_buffer.value.decode('utf8', 'surrogateescape'))
bm_info = json.loads(json_text)
dshow_len = len(self.info)
for cam in bm_info:
Expand Down
4 changes: 2 additions & 2 deletions input_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, capture, width, height, fps):
self.fps = fps
self.device = capture
escapi.count_capture_devices()
self.name = str(escapi.device_name(self.device).decode('utf8'))
self.name = str(escapi.device_name(self.device).decode('utf8', 'surrogateescape'))
self.buffer = escapi.init_camera(self.device, self.width, self.height, self.fps)
escapi.do_capture(self.device)
def is_open(self):
Expand Down Expand Up @@ -212,7 +212,7 @@ def __init__(self, capture, raw_rgb, width, height, fps, use_dshowcapture=False,
devices = escapi.count_capture_devices()
found = None
for i in range(devices):
escapi_name = str(escapi.device_name(i).decode('utf8'))
escapi_name = str(escapi.device_name(i).decode('utf8', 'surrogateescape'))
if name == escapi_name:
found = i
if found is None:
Expand Down

0 comments on commit 84c81f6

Please sign in to comment.