[FFmpeg-devel] [PATCH] add timeout to udp_read

Michael Niedermayer michaelni
Fri Sep 11 02:43:26 CEST 2009


On Wed, Sep 09, 2009 at 10:56:30PM +0200, Hagen Schmidt wrote:
> On 25.08.2009 at 00:57, Michael Niedermayer wrote:
> > On Mon, Aug 24, 2009 at 10:57:07PM +0200, Hagen Schmidt wrote:
> > > Hi
> > >
> > > On 20.08.2009 at 11:26, Luca Abeni wrote:
> > > > On Thu, 2009-08-20 at 05:17 -0400, Ronald S. Bultje wrote:
> > > > > Hi,
> > > > >
> > > > > On Thu, Aug 20, 2009 at 5:08 AM, Luca
> > > > > Abeni<lucabe72 at email.it>
> > >
> > > wrote:
> > > > > > On Mon, 2009-08-17 at 21:46 +0200, Hagen Schmidt wrote:
> > > > > >> to fix issue 539 the attached patch introduces an timeout
> > > > > >> [seconds] which returns while waiting for an udp stream:
> > > > > >> ffplay udp://235.2.2.2:5000?recv_timeout=5
> > > > > >
> > > > > > Maybe this is a trivial question, but... Why cannot the
> > > > > > problem be resolved by implementing the timeout at
> > > > > > application level?
> > > > >
> > > > > It's a good suggestion, but should be implemented in ffplay
> > > > > before we suggest others to do the same thing...
> > > >
> > > > Well, you know... Patches are welcome ;-)
> > >
> > > Ok, I agree, a more general solution is possible by implementing
> > > the timeout in ffplay. The patch extends the callback function
> > > which is used during both udp and tcp blocking read operations.
> >
> > iam ok with this though
> > the timeout should be user configureable
> > there should be a clear error message (dunno if there is one
> > alraedy but id suspect not)
> 
> The updated patch incorporates both a configurable timeout and an 
> additional error message (existing standard message is "Unknown 
> format").
> 
> Hagen

>  doc/ffplay-doc.texi |    3 +++
>  ffplay.c            |   11 ++++++++++-
>  2 files changed, 13 insertions(+), 1 deletion(-)
> b63886a8e1ea76ca2c5dab7f0ef9d3ab5a96cdd2  timeout.diff
> Index: ffplay.c
> ===================================================================
> --- ffplay.c	(Revision 19799)
> +++ ffplay.c	(Arbeitskopie)
> @@ -1863,10 +1863,14 @@
>  /* since we have only one decoding thread, we can use a global
>     variable instead of a thread local variable */
>  static VideoState *global_video_state;
> +static int64_t reference_time = 0;
> +static int timeout_network = 0;
> +static int timeout_expired = 0;
>  
>  static int decode_interrupt_cb(void)
>  {
> -    return (global_video_state && global_video_state->abort_request);
> +    return (global_video_state && global_video_state->abort_request) ||
> +           (timeout_expired = reference_time && timeout_network && av_gettime() - reference_time > timeout_network * 1000000);
>  }
>  
>  /* this thread gets the stream from the disk or the network */
> @@ -1896,8 +1900,12 @@
>      ap->time_base= (AVRational){1, 25};
>      ap->pix_fmt = frame_pix_fmt;
>  
> +    reference_time = av_gettime();
>      err = av_open_input_file(&ic, is->filename, is->iformat, 0, ap);
> +    reference_time = 0;
>      if (err < 0) {
> +        if (timeout_expired)
> +            fprintf(stderr, "Timeout expired during opening network stream after %i seconds\n", timeout_network);

the error message could be printed by decode_interrupt_cb()
nicer if the code is used more than once ...


[...]
> Index: doc/ffplay-doc.texi
> ===================================================================
> --- doc/ffplay-doc.texi	(Revision 19799)
> +++ doc/ffplay-doc.texi	(Arbeitskopie)
> @@ -102,6 +102,9 @@
>  refers to the list of all the input subtitle streams. If it is greater
>  than the number of subtitle streams minus one, then the last one is
>  selected, if it is negative the subtitle rendering is disabled.
> + at item -nto @var{seconds}
> +Set timeout in seconds when opening a network stream shall be aborted.
> +Default is 0 which waits endlessly.

seconds seems like a somewhat big unit for a timeout

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct awnser.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090911/082158b2/attachment.pgp>



More information about the ffmpeg-devel mailing list