dusty-nv / jetson-utils

C++/CUDA/Python multimedia utilities for NVIDIA Jetson

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

multiple RTSP videosource causing timeout randomly

lallous34 opened this issue · comments

i opened the same issue here

i am using the C++ code to capture from multiple RTSP sources the capture is done in a thread then the processing of each frame is done in a separate thread.

for the capture thread i did the following:

void captureThread(int skip_rate, int channel, string address)
{
videoOptions options;
options.codec = videoOptions::CODEC_H264;
videoSource * input = videoSource::Create(address.c_str(), options);

if (!input)
{
    cout<<"Error Creating source"<<endl;
    return ;
}
while (true)
{
        uchar3* image = NULL;
        int status = 0;
        if (!input->Capture(&image, Globals::timeout, &status))
        {
            if (status == videoSource::TIMEOUT)
            {
                cout<<"Getting Image Timed Out"<<endl;
                continue;
            }
            break;
        }
            int w = input->GetWidth();
            int h = input->GetHeight();
            CUDA(cudaDeviceSynchronize());
            Mat im = cv::Mat(h, w, CV_8UC3, (void*) image);     //Convert cudxa array to opencv Mat

             ... //Rest of the code to push to a thread safe queue
}
SAFE_DELETE(input);

return;

}
Then i pop element from the thread safe queue to do some processing.

Issue is while running i randomly get a timeout on a random camera that persists until i restart the code. after restart, the same camera captures images then after some time processing a random camera or more (same camera or another one that used to capture) re enter into timeout. am i missing something?

@lallous34 I don't believe this is specific to multiple threads / multiple input sources, but rather the fact that RTSP streams sometime disconnect from rtspsrc (GStreamer element) and it's difficult to get them to reconnect without recreating the whole pipeline.

What I would recommend doing, is if one of your video sources timeouts for N number of frames, to delete that video source and re-create it again. This should re-establish the RTSP connection. Or you can try input->Close() followed by input->Open()