async def netgear_async_playback(pattern): try: # define and launch Client with `receive_mode = True` server = NetGear_Async(address = PeerAddress, port = PeerPort, logging=pattern.logging) # invalid protocol server.config["generator"] = custom_frame_generator(pattern) server.launch() # define and launch Client with `receive_mode = True` and timeout = 5.0 client = NetGear_Async(port = HostPort,receive_mode=True, timeout=float("inf"), logging=pattern.logging).launch() # gather and run tasks input_coroutines = [server.task, client_iterator(client, pattern)] res = await asyncio.gather(*input_coroutines, return_exceptions=True) except Exception as e: print(e) pass finally: try: server except Exception as e: print("server undefined") else: server.close(skip_loop=True) try: client except Exception as e: print("client undefined") else: client.close(skip_loop=True)
async def test_netgear_async_addresses(address, port): try: # define and launch Client with `receive_mode = True` client = NetGear_Async(address=address, port=port, logging=True, timeout=5.0, receive_mode=True).launch() if address is None: options_gear = {"THREAD_TIMEOUT": 60} server = NetGear_Async(source=return_testvideo_path(), address=address, port=port, logging=True, **options_gear).launch() # gather and run tasks input_coroutines = [server.task, client_iterator(client)] await asyncio.gather(*input_coroutines, return_exceptions=True) else: await asyncio.ensure_future(client_iterator(client)) except Exception as e: if address == "172.31.11.15.77" or isinstance(e, queue.Empty): logger.exception(str(e)) else: pytest.fail(str(e)) finally: if address is None: server.close(skip_loop=True) client.close(skip_loop=True)
async def test_netgear_async_options(pattern, options): client = None try: # define and launch server client = NetGear_Async( source=None if options["bidirectional_mode"] != True else return_testvideo_path(), receive_mode=True, timeout=5.0, pattern=pattern, logging=True, **options) async for frame in client.recv_generator(): if not options["bidirectional_mode"]: # create target data target_data = "Client here." # send it await client.transceive_data(data=target_data) logger.warning("Failed") except Exception as e: if isinstance(e, (ValueError, asyncio.TimeoutError)): pytest.xfail(str(e)) else: pytest.fail(str(e)) finally: if not (client is None): client.close(skip_loop=True)
async def test_netgear_async_addresses(address, port): try: # define and launch Client with `receive_mode = True` client = NetGear_Async(address=address, port=port, logging=True, receive_mode=True).launch() if address is None: server = NetGear_Async(source=return_testvideo_path(), address=address, port=port, logging=True).launch() # gather and run tasks input_coroutines = [server.task, client_iterator(client)] await asyncio.gather(*input_coroutines, return_exceptions=True) else: await asyncio.ensure_future(client_iterator(client)) except Exception as e: if address == "www.idk.com": logger.exception(str(e)) else: pytest.fail(str(e)) finally: if address is None: server.close(skip_loop=True) client.close(skip_loop=True)
async def test_netgear_async_bidirectionalmode(generator, data, options_server, options_client, result): try: server = NetGear_Async(logging=True, timeout=5.0, **options_server) if not generator: cg = Custom_Generator(server, data=data) generator = cg.custom_dataframe_generator() server.config["generator"] = generator server.launch() # define and launch Client with `receive_mode = True` and timeout = 5.0 client = NetGear_Async(logging=True, receive_mode=True, timeout=5.0, **options_client).launch() # gather and run tasks input_coroutines = [ server.task, client_dataframe_iterator(client, data=data) ] res = await asyncio.gather(*input_coroutines, return_exceptions=True) except Exception as e: if result: pytest.fail(str(e)) else: pytest.xfail(str(e)) finally: server.close(skip_loop=True) client.close(skip_loop=True)
async def test_netgear_async_playback(pattern): try: # define and launch Client with `receive_mode = True` client = NetGear_Async(logging=True, pattern=pattern, receive_mode=True, timeout=7.0).launch() options_gear = {"THREAD_TIMEOUT": 60} server = NetGear_Async(source=return_testvideo_path(), pattern=pattern, timeout=7.0 if pattern == 4 else 0, logging=True, **options_gear).launch() # gather and run tasks input_coroutines = [ server.task, client_iterator(client, data=True if pattern == 4 else False), ] res = await asyncio.gather(*input_coroutines, return_exceptions=True) except Exception as e: if isinstance(e, queue.Empty): pytest.fail(str(e)) finally: server.close(skip_loop=True) client.close(skip_loop=True)
async def test_netgear_async_playback(pattern): try: # define and launch Client with `receive_mode = True` client = NetGear_Async(logging=True, pattern=pattern, receive_mode=True).launch() server = NetGear_Async(source=return_testvideo_path(), pattern=pattern, logging=True).launch() # gather and run tasks input_coroutines = [server.task, client_iterator(client)] res = await asyncio.gather(*input_coroutines, return_exceptions=True) except Exception as e: pytest.fail(str(e)) finally: server.close(skip_loop=True) client.close(skip_loop=True)
async def test_netgear_async_recv_generator(): server = None try: # define and launch server server = NetGear_Async(source=return_testvideo_path(), timeout=5.0, logging=True) async for frame in server.recv_generator(): logger.warning("Failed") except Exception as e: if isinstance(e, (ValueError, asyncio.TimeoutError)): pytest.xfail(str(e)) else: pytest.fail(str(e)) finally: if not (server is None): server.close(skip_loop=True)
async def test_benchmark_Netgear_Async(): """ Benchmark NetGear Async in FPS """ try: # launch server with valid source server = NetGear_Async(source=return_testvideo_path(), pattern=1).launch() # launch client client = NetGear_Async(receive_mode=True, pattern=1).launch() # gather and run tasks input_coroutines = [server.task, client_iterator(client)] res = await asyncio.gather(*input_coroutines, return_exceptions=True) except Exception as e: pytest.fail(str(e)) finally: # close server.close(skip_loop=True) client.close(skip_loop=True)
async def test_netgear_async_custom_server_generator(generator, result): try: server = NetGear_Async(protocol="udp", logging=True) # invalid protocol server.config["generator"] = generator server.launch() # define and launch Client with `receive_mode = True` and timeout = 5.0 client = NetGear_Async(logging=True, receive_mode=True, timeout=5.0).launch() # gather and run tasks input_coroutines = [server.task, client_iterator(client)] res = await asyncio.gather(*input_coroutines, return_exceptions=True) except Exception as e: if result: pytest.fail(str(e)) finally: if result: server.close(skip_loop=True) client.close(skip_loop=True)
async def test_netgear_async_addresses(address, port): try: server = NetGear_Async(address=address, port=port, logging=True).launch() # define and launch Client with `receive_mode = True` and timeout = 12.0 client = NetGear_Async(address=address, port=port, logging=True, receive_mode=True).launch() # gather and run tasks input_coroutines = [server.task, client_iterator(client)] res = await asyncio.gather(*input_coroutines, return_exceptions=True) except Exception as e: if address == "www.idk.com": logger.exception(str(e)) else: pytest.fail(str(e)) finally: server.close(skip_loop=True) client.close(skip_loop=True)
import asyncio # stream = ScreenGear(monitor=1).start() #initialize Server with suitable source and enable stabilization # server=NetGear_Async( address='192.168.88.221', port = '48000', protocol = 'udp', pattern=2, logging=True) from vidgear.gears.asyncio import NetGear_Async import cv2, asyncio # import libraries from vidgear.gears.asyncio import NetGear_Async import asyncio #initialize Server with suitable source and enable stabilization stream = ScreenGear(monitor=1).start() server = NetGear_Async(source=stream, stabilize=True, logging=True).launch() if __name__ == '__main__': #set event loop asyncio.set_event_loop(server.loop) try: #run your main function task until it is complete server.loop.run_until_complete(server.task) except (KeyboardInterrupt, SystemExit): #wait for interrupts pass finally: # finally close the server server.close()
# Create a async function where you want to show/manipulate your received frames async def main(): # loop over Client's Asynchronous Frame Generator async for frame in client.recv_generator(): # do something with received frames here # Show output window cv2.imshow("Output Frame", frame) key = cv2.waitKey(1) & 0xFF # await before continuing await asyncio.sleep(0.01) if __name__ == '__main__': # Set event loop to client's asyncio.set_event_loop(client.loop) try: # run your main function task until it is complete client.loop.run_until_complete(main()) except (KeyboardInterrupt, SystemExit): # wait for interrupts pass # close all output window cv2.destroyAllWindows() # safely close client client.close()
async def test_netgear_async_recv_generator(): # define and launch server server = NetGear_Async(source=return_testvideo_path(), logging=True) async for frame in server.recv_generator(): logger.error("Failed") server.close(skip_loop=True)