[FFmpeg-devel] UDP Timeout
JULIAN GARDNER
joolzg at btinternet.com
Sun Jun 5 22:10:03 CEST 2011
----- Original Message -----
> From: Michael Niedermayer <michaelni at gmx.at>
> To: FFmpeg development discussions and patches <ffmpeg-devel at ffmpeg.org>
> Cc:
> Sent: Sunday, 5 June 2011, 19:46
> Subject: Re: [FFmpeg-devel] UDP Timeout
>
> On Sun, Jun 05, 2011 at 03:01:26PM +0100, JULIAN GARDNER wrote:
>>
>>
>>
>>
>> ----- Original Message -----
>> > From: Michael Niedermayer <michaelni at gmx.at>
>> > To: FFmpeg development discussions and patches
> <ffmpeg-devel at ffmpeg.org>
>> > Cc:
>> > Sent: Saturday, 4 June 2011, 15:48
>> > Subject: Re: [FFmpeg-devel] UDP Timeout
>> >
>> > On Sat, Jun 04, 2011 at 04:41:55PM +0200, Michael Niedermayer wrote:
>> >> On Sat, Jun 04, 2011 at 02:07:14PM +0100, JULIAN GARDNER wrote:
>> >> >
>> >> >
>> >> >
>> >> > >________________________________
>> >> > >From: Michael Niedermayer <michaelni at gmx.at>
>> >> > >To: FFmpeg development discussions and patches
>> > <ffmpeg-devel at ffmpeg.org>
>> >> > >Sent: Friday, 3 June 2011, 15:10
>> >> > >Subject: Re: [FFmpeg-devel] UDP Timeout
>> >> > >
>> >> > >On Fri, Jun 03, 2011 at 09:51:48AM +0100, JULIAN GARDNER
> wrote:
>> >> > >> Seeing a small problem in that if you have a UDP
> stream that
>> > stops running, we dont get a timeout from either ffmpeg or ffplay, i
> tracked
>> > this down to udp.c, not sure if it was my version or the modified
> verision.
>> >> > >>
>> >> > >> Small mod here to return back if the return from
> select is an
>> > error or a timeout, my current version ran for 86mins, with
> modification, 20
>> > seconds
>> >> > >
>> >> > >thats strange, the code looks like it would timeout
> after 1 second
>> >> > >(tv.tv_sec = 1;) with your modification
>> >> > >?
>> >> [...]
>> >> > whilst your right about the 1 second timeout you will see if
> you look
>> > the code that the only way to leave the while loop is for an error or
> data to
>> > arrive.
>> >> >
>> >> > The check <0 is only for errors, when no data is
> available we get a
>> > return of 0 as you said after 1 second.
>> >> >
>> >> > Please check again.
>> >>
>> >> i know, we misunderstand each other
>> >> 1 second is too short for a timeout that results after your patch
>> >> i understand it doesnt timeout before your patch
>> >>
>> >> also maybe ff_network_wait_fd() should not be run after the
> select
>> >> loop
>> >
>> > also the AVIO_FLAG_NONBLOCK flag should be used to select behavior
>> >
>> > [...]
>> >
>> > --
>> > Michael GnuPG fingerprint:
> 9FF2128B147EF6730BADF133611EC787040B0FAB
>> >
>> > In fact, the RIAA has been known to suggest that students drop out
>> > of college or go to community college in order to be able to afford
>> > settlements. -- The RIAA
>> >
>> > _______________________________________________
>> > ffmpeg-devel mailing list
>> > ffmpeg-devel at ffmpeg.org
>> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> >
>> OK ive changed the code to use the ff_network_wait_fd, and added a timeout
> counter, mainly for the reason that is we have no data coming in ffmpeg just
> waits forever
>>
>> joolz
>> udp.c | 35 ++++++++++++++++++++---------------
>> 1 file changed, 20 insertions(+), 15 deletions(-)
>> 5b6a5d0eb9afda998d3fcb0b3f7e98e021a2755d udp.diff
>> diff --git a/libavformat/udp.c b/libavformat/udp.c
>> index 7c18fb7..e56816e 100644
>> --- a/libavformat/udp.c
>> +++ b/libavformat/udp.c
>> @@ -536,38 +536,43 @@ static int udp_read(URLContext *h, uint8_t *buf, int
> size)
>> UDPContext *s = h->priv_data;
>> int ret;
>> int avail;
>> - fd_set rfds;
>> - struct timeval tv;
>>
>> + ret = 0;
>> if (s->fifo) {
>> + int timeout = 10;
>>
>> do {
>> avail = av_fifo_size(s->fifo);
>> + av_log( NULL, AV_LOG_INFO, "Udp data available
> %d\n", avail);
>> if (avail) { // >=size) {
>>
>> + timeout = 10;
>> // Maximum amount available
>> size = FFMIN( avail, size);
>> av_fifo_generic_read(s->fifo, buf, size, NULL);
>> return size;
>
> timeout is never read here, so setting it to 10 is unneeded
>
>
>> }
>> else {
>> + if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
>> + ret = ff_network_wait_fd(s->udp_fd, 0);
>> + if (ret < 0)
>> + return ff_neterrno();
>> + }
>> + else {
>> + return 0;
>
> i suspect that should be AVERROR(EAGAIN)
>
>
>> + }
>> }
>> + } while( --timeout);
>
> i dont see how this timeout can reach 0
> please correct me if iam wrong but this can only be reached when
> data is available for 10 seconds time and at the same time
> the 2nd thread reads none of it
>
> [... ]
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> In fact, the RIAA has been known to suggest that students drop out
> of college or go to community college in order to be able to afford
> settlements. -- The RIAA
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
The first timeout sorry is unneeded.
Ok here goes, timeout = 10;
>> avail = av_fifo_size(s->fifo);
>> if (avail) { // >=size) {
>> // Maximum amount available
>> size = FFMIN( avail, size);
>> av_fifo_generic_read(s->fifo, buf, size, NULL);
>> return size;
>> }
>> else {
// avail = 0; no data available in fifo
>> + if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
>> + ret = ff_network_wait_fd(s->udp_fd, 0);
>> + if (ret < 0)
// Only return on network error, if still no data after timeout we drop down to the "while( --timeout)"
>> + return ff_neterrno();
>> + }
>> + else {
// AVIO_FLAG_NONBLOCK set
>> + return 0;
>>
>> + }
>> }
>> + } while( --timeout);
>
Tested on a working sytem, without timeout, runs forever, with timeout ~20 seconds before ffmpeg drops out.
joolz
More information about the ffmpeg-devel
mailing list