Skip to content

Commit

Permalink
easyvolcap: slow recv & decode
Browse files Browse the repository at this point in the history
  • Loading branch information
dendenxu committed Apr 6, 2024
1 parent f7e76a1 commit 5670d2a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
9 changes: 4 additions & 5 deletions easyvolcap/runners/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@ def __init__(self,

# Socket related initialization
host: str = '0.0.0.0',
send_port: int = 1024,
recv_port: int = 1025,
port: int = 1024,

# Camera related config
camera_cfg: dotdict = dotdict(H=1080, W=1920),
camera_cfg: dotdict = dotdict(),
jpeg_quality: int = 75,

**kwargs,
):

# Socket related initialization
self.host = host
self.send_port = send_port
self.port = port
self.recv_port = recv_port

# Initialize server-side camera in case there's lag
Expand All @@ -78,7 +77,7 @@ def start_server():
asyncio.set_event_loop(loop)

log('Preparing websocket server for sending images & receiving cameras')
server = websockets.serve(self.server_loop, self.host, self.send_port)
server = websockets.serve(self.server_loop, self.host, self.port)

loop.run_until_complete(server)
loop.run_forever()
Expand Down
40 changes: 23 additions & 17 deletions scripts/websocket/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

font_size: int = 18,
Expand Down Expand Up @@ -118,17 +118,21 @@ def init_camera(self, camera_cfg: dotdict):
self.camera.front = self.camera.front # perform alignment correction

def render(self):
global image
event.wait()
event.clear()
buffer = image
if buffer is not None:
if buffer.shape[1] == self.H and buffer.shape[2] == self.W:
buffer = buffer.permute(1, 2, 0)
buffer = torch.cat([buffer, torch.ones_like(buffer[..., :1])], dim=-1)
self.quad.copy_to_texture(buffer)
self.quad.draw()
image = image.permute(1, 2, 0)
image = torch.cat([image, torch.ones_like(image[..., :1])], dim=-1)
self.quad.copy_to_texture(image)
self.quad.draw()
return None, None

def draw_banner_gui(self, batch: dotdict = dotdict(), output: dotdict = dotdict()):
imgui.push_font(self.bold_font)
imgui.text(f'EasyVolcap WebSocket Viewer')
imgui.text(f'Running on remote: {uri}')
imgui.pop_font()

def draw_rendering_gui(self, batch: dotdict = dotdict(), output: dotdict = dotdict()):

# Other rendering options like visualization type
Expand All @@ -140,6 +144,9 @@ def draw_rendering_gui(self, batch: dotdict = dotdict(), output: dotdict = dotdi
def draw_model_gui(self, batch: dotdict = dotdict(), output: dotdict = dotdict()):
pass

def draw_model_gui(self, batch: dotdict = dotdict(), output: dotdict = dotdict()):
pass


async def websocket_client():
global image
Expand All @@ -148,21 +155,20 @@ async def websocket_client():

while True:
timer.record('other')
buffer = await websocket.recv()
timer.record('receive')

buffer = decode_jpeg(torch.from_numpy(np.frombuffer(buffer, np.uint8)), device='cuda') # 10ms for 1080p...
image = buffer
event.set()
timer.record('decode')

camera = deepcopy(viewer.camera)
camera_data = zlib.compress(camera.to_string().encode('ascii'))
camera_data = zlib.compress(viewer.camera.to_string().encode('ascii'))
timer.record('compress')

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

buffer = await websocket.recv()
timer.record('receive')

image = decode_jpeg(torch.from_numpy(np.frombuffer(buffer, np.uint8)), device='cuda') # 10ms for 1080p...
event.set()
timer.record('decode')

uri = "ws://10.76.5.252:1024"
image = None
viewer = Viewer()
Expand Down

0 comments on commit 5670d2a

Please sign in to comment.