12.01.2014, 22:23, "Hadi" <[email protected]>:
> I want to read a video stream from a UDP address using libavcodec functions. 
> To do so, I use the following code:
>
> char *url = "udp://127.0.0.1:1000";
> AVFormatContext *oc = NULL;
> avformat_open_input(&oc, url, NULL , NULL);
>
> If we run this code, then function "avformat_open_input" starts listening on 
> the given UDP address, and it looks like the program is halted if there is no 
> video stream at the given UDP address.
>
> Now, I want to write a code to first check the given UDP address quickly to 
> see whether there is any data on it or not, if there is no data then the 
> program should neglect running "avformat_open_input", otherwise it should run 
> this function so that I can avoid the halting situation.
>
> Any idea how I can do this? Thanks!
> _______________________________________________
> Libav-user mailing list
> [email protected]
> http://ffmpeg.org/mailman/listinfo/libav-user

use interrupt_callback function to "unblock" avformat_open_input(...);
concept:

time_t check_timestamp;

static int interrupt_cb(void* inputdata)
{
  time_t current_timestamp;
  current_timestamp = time(0)
  if (current_timestamp - check_timestamp >= 10)
    return true;  // interrupt blocked function
  else
    return false; // NOT interrupt, wait more seconds...
}
...
oc = avformat_allocate_context();
oc->interrupt_callbacl = (AVIOInterruptCB){interrupt_cb, NULL};
checl_timestamp = time(0);
if (avformat_open_input(&oc, url, NULL , NULL) < 0)
{
   // error processing
}

something like that :) if avformat_open_input frezzes more than 10 seconds (in 
this example), interrupt_cb will break it execution.

--
С уважением, Евгений Гарифуллин.
e-mail: [email protected]
jabber: [email protected]
ICQ : 387906261
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to