Skip to content

Commit

Permalink
evc: run websocket client on osx
Browse files Browse the repository at this point in the history
  • Loading branch information
pengsida.psd authored and dendenxu committed Apr 6, 2024
1 parent 0e016ad commit de09205
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 0 additions & 1 deletion easyvolcap/runners/volumetric_video_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,6 @@ def glfw_framebuffer_size_callback(self, window, width, height):
ori_W = self.W
self.H = height
self.W = width

if ori_W > 0 and ori_H > 0:
ratio = min(self.W / ori_W, self.H / ori_H)
self.camera.K[0, 0] *= ratio # only update one of them
Expand Down
26 changes: 17 additions & 9 deletions scripts/websocket/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class Viewer(VolumetricVideoViewer):
def __init__(self,
window_size: List[int] = [1080, 1920], # height, width
window_size: List[int] = [768, 1366], # height, width
window_title: str = f'EasyVolcap WebSocket Client', # MARK: global config

font_size: int = 18,
Expand Down Expand Up @@ -122,8 +122,12 @@ def render(self):
global image
event.wait()
event.clear()
if image.shape[0] == self.H and image.shape[1] == self.W:
self.quad.copy_to_texture(image)

with lock:
buffer = image

if buffer.shape[0] == self.H and buffer.shape[1] == self.W:
self.quad.copy_to_texture(buffer)
self.quad.draw()
return None, None

Expand Down Expand Up @@ -162,22 +166,26 @@ async def websocket_client():
await websocket.send(camera_data)
timer.record('send')

# await websocket.send('')
# timer.record('send')

buffer = await websocket.recv()
timer.record('receive')
try:
buffer = decode_jpeg(torch.from_numpy(np.frombuffer(buffer, np.uint8)), device='cuda') # 10ms for 1080p...
except RuntimeError as e:
buffer = decode_jpeg(torch.from_numpy(np.frombuffer(buffer, np.uint8)), device='cpu') # 10ms for 1080p...
buffer = buffer.permute(1, 2, 0)
buffer = torch.cat([buffer, torch.ones_like(buffer[..., :1])], dim=-1)

with lock:
image = buffer # might be a cuda tensor or cpu tensor

image = decode_jpeg(torch.from_numpy(np.frombuffer(buffer, np.uint8)), device='cuda') # 10ms for 1080p...
image = image.permute(1, 2, 0)
image = torch.cat([image, torch.ones_like(image[..., :1])], dim=-1)
# image = torch.from_numpy(np.frombuffer(buffer, np.uint8)).to('cuda', non_blocking=True)
event.set() # explicit synchronization
timer.record('decode')

uri = "ws://10.76.5.252:1024"
image = None
viewer = Viewer()
lock = threading.Lock()
event = threading.Event()
timer.disabled = False

Expand Down

0 comments on commit de09205

Please sign in to comment.