Video-viewer 4 rtp. How to check if one input rtp stream is broken?

Hi,

I am using dusty nv project and have modified the video-viewer.py to view 4 rtp stream from 4 other nanos. It is fine until I stop a rtp streaming program in another nano. The whole display freeze until I re-establish the rtp stream from another nano again. (in the display, other 3 rtp videos freeze too)

I am trying cameraX.IsStraming() to check if the rtp streamming is available but it seems not working…

Below is my program, btw, I need to put the IP address instead of “@”, not sure why… Thx

import jetson.inference
import jetson.utils
import argparse
import sys

# parse command line
parser = argparse.ArgumentParser(description="View various types of video streams", 
                                 formatter_class=argparse.RawTextHelpFormatter, 
                                 epilog=jetson.utils.videoSource.Usage() + jetson.utils.videoOutput.Usage() + jetson.utils.logUsage())

parser.add_argument("input_URI", type=str, help="URI of the input stream")
parser.add_argument("output_URI", type=str, default="", nargs='?', help="URI of the output stream")
opt = parser.parse_known_args()[0]

#try:
#	opt = parser.parse_known_args()[0]
#except:
#	print("")
#	parser.print_help()
#	sys.exit(0)

camera0 = jetson.utils.videoSource("rtp://@:1234", argv=sys.argv)
camera1 = jetson.utils.videoSource("rtp://@:1235", argv=sys.argv)
camera2 = jetson.utils.videoSource("rtp://@:1236", argv=sys.argv)
camera3 = jetson.utils.videoSource("rtp://@:1237", argv=sys.argv)
display = jetson.utils.videoOutput("display://0") # 'my_video.mp4' for file

img0 = camera0.Capture()
windowSizeX = int(img0.width*2)
windowSizeY = int(img0.height*2)
big_mem = jetson.utils.cudaAllocMapped(width=windowSizeX,
                                         height=windowSizeY,
                                         format=img0.format)
try:
    jetson.utils.cudaOverlay(camera0.Capture(), big_mem, 0, 0)
    jetson.utils.cudaOverlay(camera1.Capture(), big_mem, 0, windowSizeY/2)
    jetson.utils.cudaOverlay(camera2.Capture(), big_mem, windowSizeX/2, 0)
    jetson.utils.cudaOverlay(camera3.Capture(), big_mem, windowSizeX/2, windowSizeY/2)
except:
    print("skip initialization")

while display.IsStreaming():
    if(camera0.IsStreaming()):
        try:
	        jetson.utils.cudaOverlay(camera0.Capture(), big_mem, 0, 0)
        except:
            print("skip camera0")
            camera0 = jetson.utils.videoSource("rtp://@:1234", argv=sys.argv)
    if(camera1.IsStreaming()):
        try:
    	    jetson.utils.cudaOverlay(camera1.Capture(), big_mem, 0, windowSizeY/2)
        except:
            print("skip camera1")
            camera1 = jetson.utils.videoSource("rtp://@:1235", argv=sys.argv)
    if(camera2.IsStreaming()):
        try:
    	    jetson.utils.cudaOverlay(camera2.Capture(), big_mem, windowSizeX/2, 0)
        except:
            print("skip camera2")
            camera2 = jetson.utils.videoSource("rtp://@:1236", argv=sys.argv)

    if(camera3.IsStreaming()):
        try:
    	    jetson.utils.cudaOverlay(camera3.Capture(), big_mem, windowSizeX/2, windowSizeY/2)
        except:
            print("skip camera3")
            camera3 = jetson.utils.videoSource("rtp://@:1237", argv=sys.argv)


    display.Render(big_mem)
    display.SetStatus("Display 4 views | Network {:.0f} FPS".format(display.GetFrameRate()))


Hi @AK51, my guess is that the whole app freezes because the videoSource.Capture() call blocks until it receives another frame. However you can specify the timeout argument to videoSource.Capture(), which sets the number of milliseconds before it returns:

# a timeout of -1 means wait forever for a new frame (which is the default)
# a timeout of 0 means return immediately if a new frame isn't ready
# a timeout of >0 sets the number of milliseconds before returning if a new frame isn't ready
camera0.Capture(timeout=0)

If the timeout occurs, it will return an exception - so you won’t necessarily want to re-create the videoSource interface every time an exception occurs like you are doing now.

1 Like

Yes, it is working. Thanks Dusty
Cheers

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.