Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTSPPusher write_header() gets blocked if rtsp server is not available #387

Open
Vinayak-YB opened this issue Sep 23, 2024 · 0 comments
Open

Comments

@Vinayak-YB
Copy link
Collaborator

Describe the bug
In processSOS of RTSPPusher we make a call to write_header() function which internally calls avformat_write_header with outContext. If the RTSP server is not available then the function does not return anything blocking the process. There are comments added below the avformat_write_header pointing to this issue.

To Reproduce
Steps to reproduce the behavior: Run RTSP Pusher tests without the rtsp server and observe behaviour in procesSOS function.

Solution:
Add an interrupt callback to outContext with timeout logic before calling avformat_write_header(). Please find the associated code below. We need to add test cases for this scenario in rtsppusher_tests.

typedef struct 
{
    AVFormatContext* formatContext;
    int timeout_ms;       
    uint64_t start_time_ms;    
} InterruptCallbackData;

static int rtspInterruptCallback(void *ctx) 
{
      LOG_TRACE<<"Callback triggered";
      InterruptCallbackData* callbackData = reinterpret_cast<InterruptCallbackData*>(ctx);
      std::chrono::time_point<std::chrono::system_clock> t = std::chrono::system_clock::now();
      auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(t.time_since_epoch());
      uint64_t current_time = dur.count();
      if ((current_time - callbackData->start_time_ms) > callbackData->timeout_ms) 
      {
          LOG_INFO<<"Timeout reached in callback, returning error";
          return -1; 
      }
      return 0; 
}

//Interrupt callback 
InterruptCallbackData callbackData;
callbackData.formatContext = outContext;
callbackData.timeout_ms = rtspTimeout;  //This value is passed as props for rtspPusher module
std::chrono::time_point<std::chrono::system_clock> t = std::chrono::system_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(t.time_since_epoch());
uint64_t now = dur.count();
callbackData.start_time_ms = now; 
outContext->interrupt_callback.callback = rtspInterruptCallback;
outContext->interrupt_callback.opaque = &callbackData;
outContext->flags = outContext->flags | AVFMT_FLAG_NONBLOCK;
ret = avformat_write_header(outContext, &options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant