-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added syphon support - sadly with a bad performance
- Loading branch information
Showing
9 changed files
with
144 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from abc import ABC, abstractmethod | ||
from sys import platform | ||
from typing import Optional, Any | ||
|
||
import numpy as np | ||
|
||
class FrameBufferSharingServer(ABC): | ||
def __init__(self, name: str): | ||
self.name = name | ||
|
||
@abstractmethod | ||
def send_texture(self, texture_id: int, width: int, height: int, is_flipped: bool = False): | ||
pass | ||
|
||
@abstractmethod | ||
def can_memory_buffer(self): | ||
pass | ||
|
||
@abstractmethod | ||
def create_memory_buffer(self, texture_name: str, size: int): | ||
pass | ||
|
||
@abstractmethod | ||
def write_memory_buffer(self, texture_name: str, buffer): | ||
pass | ||
|
||
@staticmethod | ||
def create(name: str): | ||
if platform.startswith("darwin"): | ||
from spyphon.fbs.syphon.SyphonServer import SyphonServer | ||
return SyphonServer(name) | ||
elif platform.startswith("win"): | ||
from spyphon.fbs.spout.SpoutServer import SpoutServer | ||
return SpoutServer(name) | ||
else: | ||
raise Exception(f"Platform {platform} is not supported!") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import logging | ||
from argparse import ArgumentParser, Namespace | ||
from typing import Optional | ||
|
||
import SpoutGL | ||
import numpy as np | ||
import bgl | ||
|
||
from spyphon.fbs.FrameBufferSharingServer import FrameBufferSharingServer | ||
|
||
|
||
class SpoutServer(FrameBufferSharingServer): | ||
def __init__(self, name: str = "SpoutServer"): | ||
super().__init__(name) | ||
self.ctx: Optional[SpoutGL.SpoutSender] = None | ||
|
||
def setup(self): | ||
# setup spout | ||
self.ctx = SpoutGL.SpoutSender() | ||
self.ctx.setSenderName(self.name) | ||
|
||
def send_texture(self, texture_id: int, width: int, height: int, is_flipped: bool = False): | ||
success = self.ctx.sendTexture( | ||
texture_id, bgl.GL_TEXTURE_2D, width, height, is_flipped, 0) | ||
|
||
if not success: | ||
logging.warning("Could not send spout texture.") | ||
return | ||
|
||
self.ctx.setFrameSync(self.name) | ||
|
||
def can_memory_buffer(self): | ||
return True | ||
|
||
def create_memory_buffer(self, texture_name: str, size: int): | ||
success = self.ctx.createMemoryBuffer(texture_name, size) | ||
|
||
if not success: | ||
logging.warning("Could not create memory buffer.") | ||
|
||
return | ||
|
||
def write_memory_buffer(self, texture_name: str, buffer): | ||
success = self.ctx.writeMemoryBuffer(texture_name, buffer, len(buffer)) | ||
|
||
if not success: | ||
logging.warning("Could not write memory buffer.") | ||
|
||
return | ||
|
||
def release(self): | ||
self.ctx.releaseSender() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from argparse import Namespace, ArgumentParser | ||
from typing import Optional, Any | ||
|
||
import numpy as np | ||
import syphonpy | ||
|
||
import logging | ||
|
||
from spyphon.fbs.FrameBufferSharingServer import FrameBufferSharingServer | ||
|
||
|
||
class SyphonServer(FrameBufferSharingServer): | ||
def __init__(self, name: str = "SyphonServer"): | ||
super().__init__(name) | ||
|
||
self.ctx: Optional[syphonpy.SyphonServer] = None | ||
|
||
def setup(self): | ||
# setup spout | ||
self.ctx = syphonpy.SyphonServer(self.name) | ||
if self.ctx.error_state(): | ||
logging.error("error in Syphonserver") | ||
|
||
def send_texture(self, texture_id: int, width: int, height: int, is_flipped: bool = False): | ||
self.ctx.publish_frame_texture(texture_id, | ||
syphonpy.MakeRect(0, 0, width, height), | ||
syphonpy.MakeSize(width, height), is_flipped) | ||
|
||
def can_memory_buffer(self): | ||
return False | ||
|
||
def release(self): | ||
self.ctx.stop() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters