@@ -12,13 +12,10 @@ class serves as a wrapper for accessing and manipulating the stream data between
1212import multiprocessing
1313import time
1414import cv2
15- import numpy as np
16- from multiprocessing import managers
17- from typing import Dict , Optional
15+ from typing import Dict
1816from flask import Flask , Response , stream_with_context
19- from werkzeug .serving import make_server
2017from .LogOperator import getChildLogger
21- from .. Constants . AgentConstants import Proxy
18+ from .StreamProxy import StreamProxy
2219from ..Utils .network import DEVICEIP
2320
2421Sentinel = getChildLogger ("Stream_Operator" )
@@ -153,75 +150,3 @@ def close_stream(self, name: str):
153150 Sentinel .info (f"Closed stream: { name } " )
154151
155152
156- class StreamProxy (Proxy ):
157- """Wrapper for accessing and manipulating a stream from another process.
158-
159- This class extends the DictProxy used to transfer data
160- between processes, specifically for MJPEG video streaming.
161-
162- Attributes:
163- __streamDict (managers.DictProxy): The underlying dictionary proxy
164- holding stream data.
165- """
166-
167- def __init__ (self , streamDict : managers .DictProxy , streamPath : str ):
168- """Initializes a StreamProxy instance.
169-
170- Args:
171- streamDict (managers.DictProxy): Proxy for accessing shared data.
172- streamPath (str): URL path of the video stream.
173- """
174- self .__streamDict = streamDict
175- self .__streamDict ["stream_path" ] = streamPath
176- self .__streamDict ["frame_count" ] = 0
177-
178- def put (self , frame : np .ndarray ) -> None :
179- """Stores a new video frame in the proxy.
180-
181- Args:
182- frame (np.ndarray): The video frame to store.
183- """
184- self .__streamDict ["frame" ] = frame
185- self .__streamDict ["frame_count" ] = self .__streamDict .get ("frame_count" , 0 ) + 1
186-
187- def get (self ) -> Optional [np .ndarray ]:
188- """Retrieves the current video frame from the proxy.
189-
190- Returns:
191- Optional[np.ndarray]: The latest frame, or None if no frame is available.
192- """
193- return self .__streamDict .get ("frame" )
194-
195- def getFrameCount (self ) -> int :
196- """Gets the current count of frames stored in the proxy.
197-
198- Returns:
199- int: The total number of frames sent.
200- """
201- return self .__streamDict ["frame_count" ]
202-
203- def getStreamPath (self ) -> str :
204- """Gets the URL path of the video stream.
205-
206- Returns:
207- str: The path where the stream can be accessed.
208- """
209- return self .__streamDict ["stream_path" ]
210-
211- def __getstate__ (self ):
212- """Returns the state of the StreamProxy for pickling.
213-
214- This method enables the StreamProxy to be correctly serialized.
215-
216- Returns:
217- managers.DictProxy: The underlying stream dictionary proxy.
218- """
219- return self .__streamDict
220-
221- def __setstate__ (self , state ):
222- """Restores the state of the StreamProxy from a pickled state.
223-
224- Args:
225- state (dict): The state to restore from.
226- """
227- self .__streamDict = state
0 commit comments