Thanks for the response, it works! :) I was thinking to put such a code within 
a thread. Whenever "avformat_open_input" finds a stream at the given address, 
then the thread can be terminated. In the meantime, the program can do other 
stuffs. But do you know how I can make a thread with libavcodec functions?

----------------------------------------
> From: gri...@yandex.ru
> To: libav-user@ffmpeg.org
> Date: Sun, 12 Jan 2014 22:38:51 +0600
> Subject: Re: [Libav-user] Check an address to see if there is any video 
> stream on it or not
>
>
> 12.01.2014, 22:23, "Hadi" <hadi.hadiza...@hotmail.com>:
>> 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
>> Libav-user@ffmpeg.org
>> 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: gri...@yandex.ru
> jabber: joffad...@jabber.ufanet.ru
> ICQ : 387906261
> _______________________________________________
> Libav-user mailing list
> Libav-user@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user                                 
>           
_______________________________________________
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to