import os import sys proto_dir = os.path.join(os.path.dirname(__file__), 'message_queue', 'proto') if proto_dir not in sys.path: sys.path.append(proto_dir) import shared_manager from cvStreamer import cvStreamer from message_queue.proto.Message_pb2 import Message from message_queue.proto.TrackCommandMessage_pb2 import TrackCommand from message_queue.proto.enums_pb2 import MessageType from video_streamer.gst_video_streamer import GstVideoStreamer def findUsbCams(): cv_cameras = [] for i in range(50): cap = cvStreamer(i) if cap.isOpened(): cv_cameras.append(cap) return cv_cameras core = "a" def manager_callback(msg_str): msg = Message() msg.ParseFromString(msg_str) if msg.msgType == MessageType.MESSAGE_TYPE_TOGGLE_TRACK: if msg.track_cmd.command == TrackCommand.TRACK_COMMAND_STOP: core.stop_track() elif msg.track_cmd.command == TrackCommand.TRACK_COMMAND_START: core.start_track(msg.track_cmd.x, msg.track_cmd.y, msg.track_cmd.w, msg.track_cmd.h) elif msg.track_cmd.command == TrackCommand.TRACK_COMMAND_START_DETECT: core.start_detect(msg.track_cmd.x, msg.track_cmd.y, msg.track_cmd.w, msg.track_cmd.h) elif msg.msgType == MessageType.MESSAGE_TYPE_TRACK_SETTINGS: core.set_thickness(msg.track_settings.thickness) elif msg.msgType == MessageType.MESSAGE_TYPE_SWITCH_CAMERA: print(f"switch camera detected ,primary value is : {msg.cam_switch.primaryCamType}") print(f"switch camera detected ,secondary value is : {msg.cam_switch.secondaryCamType}") core.set_source(msg.cam_switch.primaryCamType) elif msg.msgType == MessageType.MESSAGE_TYPE_SET_CAMERA: if msg.cam_set.cameraSource == 1: print(f"set camera source to network") ip = msg.cam_set.ip videoStreamers = [] for src in range(2): rtsp_link = f'rtsp://admin:Abc.12345@{ip}:554/ch{src}/stream0' # ic(rtsp_link) videoStreamer = GstVideoStreamer(rtsp_link, [1920, 1080, 3], str(src), fps=15) videoStreamer.cameraStatus.connect(handle_camera_status) print(f'{videoStreamer.id} connected') videoStreamers.append(videoStreamer) core.set_video_sources(videoStreamers) # videoStreamers = [] # for idx, rtsp_link in enumerate(rtsp_links): # videoStreamer = GstVideoStreamer(rtsp_link, [1920, 1080, 3], str(idx), fps=15) # videoStreamer.cameraStatus.connect(handle_camera_status) # print(f'{videoStreamer.id} connected') # videoStreamers.append(videoStreamer) # core.set_video_sources(videoStreamers) else: sources = findUsbCams() if len(sources) >= 2: print("set camera source to captutre card") core.set_video_sources(findUsbCams()) def handle_camera_status(status: int): m = Message() m.msgType = MessageType.MESSAGE_TYPE_CAMERA_CONNECTION_STATUS m.cam_status.status = status shared_manager.manager.send_message(m.SerializeToString())