[FFmpeg-devel] [PATCH] add timeout to udp_read
Michael Niedermayer
michaelni
Tue Sep 15 03:03:00 CEST 2009
On Mon, Sep 14, 2009 at 10:29:53PM +0200, Hagen Schmidt wrote:
> On 11.09.2009 at 02:43, Michael Niedermayer wrote:
> [...]
> > > 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 ...
> ok, done
>
> > [...]
> >
> > > 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
> ok, changed unit to milliseconds.
> Thanks for all hints.
>
> Hagen
> doc/ffplay-doc.texi | 3 +++
> ffplay.c | 10 +++++++++-
> 2 files changed, 12 insertions(+), 1 deletion(-)
> bfb89aafa9238a91f01626291e34d9d042e1db89 timeout.diff
> Index: ffplay.c
> ===================================================================
> --- ffplay.c (Revision 19841)
> +++ ffplay.c (Arbeitskopie)
> @@ -1863,10 +1863,16 @@
> /* 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 decode_interrupt_cb(void)
> {
> - return (global_video_state && global_video_state->abort_request);
> + static int timeout_expired = 0;
> + if (timeout_network && !timeout_expired && reference_time &&
> + (timeout_expired = av_gettime() - reference_time > timeout_network * 1000))
> + fprintf(stderr, "Timeout for receiving network stream expired after %i msec\n", timeout_network);
> + return (global_video_state && global_video_state->abort_request) || timeout_expired;
> }
>
> /* this thread gets the stream from the disk or the network */
i would suggest to write this slightly less obfuscated
maybe doing the assignment outside a multiline conditional ...
also i wonder how timeout_expired could be reset or what good that function
is once its non zero
> @@ -1896,6 +1902,7 @@
> 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);
> if (err < 0) {
> print_error(is->filename, err);
i dont see reference_time time being reset or otherwise the timeout being
disabled, maybe iam missing something but doesnt that kill ffplay at that
time even long after av_open_input_file() ?
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The greatest way to live with honor in this world is to be what we pretend
to be. -- Socrates
-------------- 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/20090915/48f8b260/attachment.pgp>
More information about the ffmpeg-devel
mailing list