summaryrefslogtreecommitdiff
path: root/libavformat/udp.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2011-12-01 11:44:21 +0200
committerMartin Storsjö <martin@martin.st>2011-12-01 13:47:26 +0200
commit7e58050590c556643869a1cc57215026ff88b0db (patch)
tree13d62d154bc9e260991985dbb94b3ae04e034ea9 /libavformat/udp.c
parent9c6777bd9367e8680bb7ada9852f5760dc8a8594 (diff)
proto: Use .priv_data_size to allocate the private context
This simplifies the open functions by avoiding one function call that needs error checking, reducing the amount of extra bulk code. Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/udp.c')
-rw-r--r--libavformat/udp.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 178cef477a..529114a860 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -306,7 +306,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
{
char hostname[1024], localaddr[1024] = "";
int port, udp_fd = -1, tmp, bind_ret = -1;
- UDPContext *s = NULL;
+ UDPContext *s = h->priv_data;
int is_output;
const char *p;
char buf[256];
@@ -319,11 +319,6 @@ static int udp_open(URLContext *h, const char *uri, int flags)
is_output = !(flags & AVIO_FLAG_READ);
- s = av_mallocz(sizeof(UDPContext));
- if (!s)
- return AVERROR(ENOMEM);
-
- h->priv_data = s;
s->ttl = 16;
s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE;
@@ -440,7 +435,6 @@ static int udp_open(URLContext *h, const char *uri, int flags)
fail:
if (udp_fd >= 0)
closesocket(udp_fd);
- av_free(s);
return AVERROR(EIO);
}
@@ -486,7 +480,6 @@ static int udp_close(URLContext *h)
if (s->is_multicast && (h->flags & AVIO_FLAG_READ))
udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
closesocket(s->udp_fd);
- av_free(s);
return 0;
}
@@ -497,4 +490,5 @@ URLProtocol ff_udp_protocol = {
.url_write = udp_write,
.url_close = udp_close,
.url_get_file_handle = udp_get_file_handle,
+ .priv_data_size = sizeof(UDPContext),
};