[FFmpeg-devel] [RFC] url_write()
Michael Niedermayer
michaelni
Tue Oct 5 22:04:43 CEST 2010
On Thu, Sep 30, 2010 at 08:09:46PM +0200, Reimar D?ffinger wrote:
> On Thu, Sep 30, 2010 at 01:20:33PM +0200, Michael Niedermayer wrote:
> > What do users of url_write() prefer
> > should we always call it in a loop in the url_write() wraper or
> > should all uses be fixed and a url_write_complete() be added similar to
> > url_read()
> > ?
>
> A separate url_write_complete IMO is useless. The big difference compared to reading
> is that if latency is an issue in the write function, it is possible
> to just buffer the data.
> Thus I think there is no point in a write function that does
> incomplete writes.
Patch below, will commit in a day if there are no objections
commit 92843bc433f7d2964c9b1c0f0b7df9256fadf24b
Author: Michael Niedermayer <michaelni at gmx.at>
Date: Tue Oct 5 21:58:29 2010 +0200
Fix url_write() so it does not stop in the middle as callers do not expect this.
This fix is done in line with how url_read_complete() works.
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 4399878..7c760e2 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -240,14 +240,29 @@ int url_read_complete(URLContext *h, unsigned char *buf, int size)
int url_write(URLContext *h, const unsigned char *buf, int size)
{
- int ret;
+ int len= 0;
+ int fast_retries= 5;
if (!(h->flags & (URL_WRONLY | URL_RDWR)))
return AVERROR(EIO);
/* avoid sending too big packets */
if (h->max_packet_size && size > h->max_packet_size)
return AVERROR(EIO);
- ret = h->prot->url_write(h, buf, size);
- return ret;
+
+ while(len<size){
+ int ret= h->prot->url_write(h, buf+len, size-len);
+ if (ret == AVERROR(EAGAIN)) {
+ ret= 0;
+ if (fast_retries){
+ fast_retries--;
+ }else
+ usleep(1000);
+ } else if (ret < 1)
+ return ret < 0 ? ret : len;
+ if (ret)
+ fast_retries = FFMAX(fast_retries, 2);
+ len += ret;
+ }
+ return len;
}
int64_t url_seek(URLContext *h, int64_t pos, int whence)
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
No snowflake in an avalanche ever feels responsible. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101005/6de7fbac/attachment.pgp>
More information about the ffmpeg-devel
mailing list