MCPcopy Create free account
hub / github.com/ARM-software/AVH / VideoServer

Class VideoServer

interface/vstream/python/vsi_video_server.py:59–731  ·  view source on GitHub ↗

Implements a TCP server for video streaming and frame I/O. Supports both video and image files as input/output, and can interface with a camera device. Listens for commands from a client (such as setting mode, filename, configuring stream, enabling/disabling stream, reading/writing fram

Source from the content-addressed store, hash-verified

57MODE_VIDEO_OUTPUT = 1
58
59class VideoServer:
60 """Implements a TCP server for video streaming and frame I/O.
61
62 Supports both video and image files as input/output, and can interface with a camera device.
63 Listens for commands from a client (such as setting mode, filename, configuring stream,
64 enabling/disabling stream, reading/writing frames), and performs the requested video
65 operations using OpenCV.
66 """
67 def __init__(self, address, authkey):
68 """
69 Initialize the VideoServer.
70
71 Sets up command codes, color space constants, and initializes all state variables.
72 Creates a Listener object for incoming client connections.
73 Args:
74 address: The (IP, port) tuple for the server to listen on.
75 authkey: The authorization key for client connections.
76 Returns:
77 None
78 """
79 # Server commands
80 self.SET_MODE = 1
81 self.SET_DEVICE = 2
82 self.SET_FILENAME = 3
83 self.STREAM_CONFIGURE = 4
84 self.STREAM_ENABLE = 5
85 self.STREAM_DISABLE = 6
86 self.FRAME_READ = 7
87 self.FRAME_WRITE = 8
88 self.CLOSE_SERVER = 9
89 # Color space
90 self.GRAYSCALE8 = 0
91 self.RGB888 = 1
92 self.BGR565 = 2
93 self.YUV420 = 3
94 self.NV12 = 4
95 self.NV21 = 5
96 # Variables
97 self.listener = Listener(address, authkey=authkey.encode('utf-8'))
98 self.device = 0
99 self.filename = None
100 self.mode = MODE_VIDEO_INPUT
101 self.active = False
102 self.video = True
103 self.stream = None
104 self.frame_ratio = 0
105 self.frame_drop = 0
106 self.eos = False
107 # Stream configuration
108 self.frame_width = None
109 self.frame_height = None
110 self.frame_color = None
111 self.frame_rate = None
112
113
114 def _setMode(self, mode):
115 """
116 Set the stream mode to input (camera/file) or output (display/file).

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected