From 7e58050590c556643869a1cc57215026ff88b0db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 1 Dec 2011 11:44:21 +0200 Subject: proto: Use .priv_data_size to allocate the private context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ö --- libavformat/rtpproto.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'libavformat/rtpproto.c') diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index 9707bdc..93cad3c 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -136,7 +136,7 @@ static void build_udp_url(char *buf, int buf_size, static int rtp_open(URLContext *h, const char *uri, int flags) { - RTPContext *s; + RTPContext *s = h->priv_data; int rtp_port, rtcp_port, ttl, connect, local_rtp_port, local_rtcp_port, max_packet_size; @@ -145,11 +145,6 @@ static int rtp_open(URLContext *h, const char *uri, int flags) char path[1024]; const char *p; - s = av_mallocz(sizeof(RTPContext)); - if (!s) - return AVERROR(ENOMEM); - h->priv_data = s; - av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port, path, sizeof(path), uri); /* extract parameters */ @@ -213,7 +208,6 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ffurl_close(s->rtp_hd); if (s->rtcp_hd) ffurl_close(s->rtcp_hd); - av_free(s); return AVERROR(EIO); } @@ -290,7 +284,6 @@ static int rtp_close(URLContext *h) ffurl_close(s->rtp_hd); ffurl_close(s->rtcp_hd); - av_free(s); return 0; } @@ -336,4 +329,5 @@ URLProtocol ff_rtp_protocol = { .url_write = rtp_write, .url_close = rtp_close, .url_get_file_handle = rtp_get_file_handle, + .priv_data_size = sizeof(RTPContext), }; -- cgit v1.1