summaryrefslogtreecommitdiff
path: root/libav
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2002-07-24 17:50:23 +0000
committerFabrice Bellard <fabrice@bellard.org>2002-07-24 17:50:23 +0000
commit8a9488b5500bc607fd3bef89c928c52eb4e4da9f (patch)
tree2e55ff9c9afc70608bd2586b65f4adf918016d3b /libav
parentf031df23feb2b4211a96fc0ac602dc1f6a0432a7 (diff)
added url_get_max_packet_size() support - added URL_RDWR flag
Originally committed as revision 795 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libav')
-rw-r--r--libav/avio.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/libav/avio.c b/libav/avio.c
index 63095fd172..37af56f9af 100644
--- a/libav/avio.c
+++ b/libav/avio.c
@@ -58,15 +58,18 @@ int url_open(URLContext **puc, const char *filename, int flags)
goto found;
up = up->next;
}
- return -ENOENT;
+ err = -ENOENT;
+ goto fail;
found:
uc = av_malloc(sizeof(URLContext));
- if (!uc)
- return -ENOMEM;
+ if (!uc) {
+ err = -ENOMEM;
+ goto fail;
+ }
uc->prot = up;
uc->flags = flags;
uc->is_streamed = 0; /* default = not streamed */
- uc->packet_size = 1; /* default packet size */
+ uc->max_packet_size = 0; /* default: stream file */
err = up->url_open(uc, filename, flags);
if (err < 0) {
av_free(uc);
@@ -75,6 +78,9 @@ int url_open(URLContext **puc, const char *filename, int flags)
}
*puc = uc;
return 0;
+ fail:
+ *puc = NULL;
+ return err;
}
int url_read(URLContext *h, unsigned char *buf, int size)
@@ -89,8 +95,11 @@ int url_read(URLContext *h, unsigned char *buf, int size)
int url_write(URLContext *h, unsigned char *buf, int size)
{
int ret;
- if (!(h->flags & URL_WRONLY))
+ if (!(h->flags & (URL_WRONLY | URL_RDWR)))
return -EIO;
+ /* avoid sending too big packets */
+ if (h->max_packet_size && size > h->max_packet_size)
+ return -EIO;
ret = h->prot->url_write(h, buf, size);
return ret;
}
@@ -132,3 +141,16 @@ offset_t url_filesize(URLContext *h)
url_seek(h, pos, SEEK_SET);
return size;
}
+
+/*
+ * Return the maximum packet size associated to packetized file
+ * handle. If the file is not packetized (stream like http or file on
+ * disk), then 0 is returned.
+ *
+ * @param h file handle
+ * @return maximum packet size in bytes
+ */
+int url_get_max_packet_size(URLContext *h)
+{
+ return h->max_packet_size;
+}