• DepthAI-v2ROS
  • Connection Closure with OAK Camera Upon Stopping Stream

Hello everyone,

I've been working with RTSP video streaming using the OAK camera. I've noticed a peculiar behavior: when I stop the video stream, the connection to the OAK camera is closed. To monitor this, I've been utilizing the isClosed() method.

Upon detecting the closed connection, my node then attempts to reestablish it. I'm trying to understand the underlying reason for this behavior. Why does the connection close when I stop the video stream? Is this expected or is there something I might be overlooking in my setup?

Any insights or experiences related to this would be greatly appreciated.

  • erik replied to this.
  • Hi Anas_Khan
    One idea, I think the device might be closing because the code exits out of the with statement. Maybe try switching that with device.startPipeline() and device.close().

    Thanks,
    Jaka

    Hi Anas_Khan ,
    How are you stopping/starting video stream?
    This works for me as expected:

    I am running the while True loop in a separate thread. I don't want to close the connection to the camera, not sure why it closes.

    Here's an example of what that looks like:

        def start_stream(self):
            self.stream_running = True
    
            def streaming():
                with self.device:
                    encoded = self.device.getOutputQueue("encoded", maxSize=30, blocking=True)
                    try:
                        while self.stream_running: #when this loop breaks, it closes connection to the cam
                            if encoded.has():
                                data = encoded.get().getData()
                                self.server.send_data(data) # This is defined in a separate class
                    except Exception as e:
                        rospy.logerr(f"Exception: {e}")
    
            self.oak_thread = threading.Thread(target=streaming)
            self.oak_thread.start()
       def stop_stream():
          self.stream_running = False 
          if self.oak_thread and self.oak_thread.is_alive():
                self.oak_thread.join(timeout=5.0) 

    I monitor if the device is closed in a separate function:

    while not rospy.is_shutdown():
        if self.device.isClosed():
            rospy.logerr('connection was closed.')
            self.initalize_camera() # This function establishes the connection and create the DAI pipeline

      Hi Anas_Khan
      I'd suggest adding some logging statements between to see what the cause is. Looks more like a simple bug, rather then a firmware problem.

      Thanks,
      Jaka

      Hi Jaka,

      The connection to the camera closes when I call the function stop_stream which sets self.streamrunning to False. Where would you recommend I add the log statement to check the cause?

        Hi Anas_Khan
        One idea, I think the device might be closing because the code exits out of the with statement. Maybe try switching that with device.startPipeline() and device.close().

        Thanks,
        Jaka

          I will try implementing that and let you know. Thank you for the suggestion.