From 0589da0aa525e4ba7c554408339fa3e862402af5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 31 Mar 2011 16:25:10 +0200 Subject: avio: make url_open() internal. --- libavformat/mmst.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libavformat/mmst.c') diff --git a/libavformat/mmst.c b/libavformat/mmst.c index ba29b9e05b..fa17fe524b 100644 --- a/libavformat/mmst.c +++ b/libavformat/mmst.c @@ -35,6 +35,7 @@ #include "libavutil/intreadwrite.h" #include "libavcodec/bytestream.h" #include "network.h" +#include "url.h" #define LOCAL_ADDRESS 0xc0a80081 // FIXME get and use correct local ip address. #define LOCAL_PORT 1037 // as above. @@ -522,7 +523,7 @@ static int mms_open(URLContext *h, const char *uri, int flags) // establish tcp connection. ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL); - err = url_open(&mms->mms_hd, tcpname, URL_RDWR); + err = ffurl_open(&mms->mms_hd, tcpname, URL_RDWR); if (err) goto fail; -- cgit v1.2.3 From dce375645945e31687493ebe82a7a89623e49bdc Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 31 Mar 2011 16:40:31 +0200 Subject: avio: make url_read_complete() internal. --- libavformat/avio.c | 6 +++++- libavformat/avio.h | 10 +--------- libavformat/mmsh.c | 10 +++++----- libavformat/mmst.c | 8 ++++---- libavformat/rtmppkt.c | 16 ++++++++-------- libavformat/rtmpproto.c | 4 ++-- libavformat/rtsp.c | 8 ++++---- libavformat/rtspdec.c | 5 +++-- libavformat/url.h | 9 +++++++++ 9 files changed, 41 insertions(+), 35 deletions(-) (limited to 'libavformat/mmst.c') diff --git a/libavformat/avio.c b/libavformat/avio.c index 0e1ebaacdd..4f56286f8d 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -184,6 +184,10 @@ int url_read(URLContext *h, unsigned char *buf, int size) { return ffurl_read(h, buf, size); } +int url_read_complete(URLContext *h, unsigned char *buf, int size) +{ + return ffurl_read_complete(h, buf, size); +} #endif #define URL_SCHEME_CHARS \ @@ -269,7 +273,7 @@ int ffurl_read(URLContext *h, unsigned char *buf, int size) return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read); } -int url_read_complete(URLContext *h, unsigned char *buf, int size) +int ffurl_read_complete(URLContext *h, unsigned char *buf, int size) { if (h->flags & URL_WRONLY) return AVERROR(EIO); diff --git a/libavformat/avio.h b/libavformat/avio.h index 84062eb3ce..2b1c6ff913 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -106,17 +106,9 @@ attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags); attribute_deprecated int url_connect(URLContext *h); attribute_deprecated int url_open(URLContext **h, const char *url, int flags); attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size); +attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size); #endif -/** - * Read as many bytes as possible (up to size), calling the - * read function multiple times if necessary. - * This makes special short-read handling in applications - * unnecessary, if the return value is < size then it is - * certain there was either an error or the end of file was reached. - */ -int url_read_complete(URLContext *h, unsigned char *buf, int size); - /** * Write size bytes from buf to the resource accessed by h. * diff --git a/libavformat/mmsh.c b/libavformat/mmsh.c index cacebfc639..32f8e4d4e0 100644 --- a/libavformat/mmsh.c +++ b/libavformat/mmsh.c @@ -79,7 +79,7 @@ static ChunkType get_chunk_header(MMSHContext *mmsh, int *len) ChunkType chunk_type; int chunk_len, res, ext_header_len; - res = url_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH); + res = ffurl_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH); if (res != CHUNK_HEADER_LENGTH) { av_log(NULL, AV_LOG_ERROR, "Read data packet header failed!\n"); return AVERROR(EIO); @@ -101,7 +101,7 @@ static ChunkType get_chunk_header(MMSHContext *mmsh, int *len) return AVERROR_INVALIDDATA; } - res = url_read_complete(mms->mms_hd, ext_header, ext_header_len); + res = ffurl_read_complete(mms->mms_hd, ext_header, ext_header_len); if (res != ext_header_len) { av_log(NULL, AV_LOG_ERROR, "Read ext header failed!\n"); return AVERROR(EIO); @@ -122,7 +122,7 @@ static int read_data_packet(MMSHContext *mmsh, const int len) len, sizeof(mms->in_buffer)); return AVERROR(EIO); } - res = url_read_complete(mms->mms_hd, mms->in_buffer, len); + res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len); av_dlog(NULL, "Data packet len = %d\n", len); if (res != len) { av_log(NULL, AV_LOG_ERROR, "Read data packet failed!\n"); @@ -174,7 +174,7 @@ static int get_http_header_data(MMSHContext *mmsh) len, mms->asf_header_size); return AVERROR(EIO); } - res = url_read_complete(mms->mms_hd, mms->asf_header, len); + res = ffurl_read_complete(mms->mms_hd, mms->asf_header, len); if (res != len) { av_log(NULL, AV_LOG_ERROR, "Recv asf header data len %d != expected len %d\n", res, len); @@ -197,7 +197,7 @@ static int get_http_header_data(MMSHContext *mmsh) len, sizeof(mms->in_buffer)); return AVERROR(EIO); } - res = url_read_complete(mms->mms_hd, mms->in_buffer, len); + res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len); if (res != len) { av_log(NULL, AV_LOG_ERROR, "Read other chunk type data failed!\n"); return AVERROR(EIO); diff --git a/libavformat/mmst.c b/libavformat/mmst.c index fa17fe524b..d28a6ca6a8 100644 --- a/libavformat/mmst.c +++ b/libavformat/mmst.c @@ -241,7 +241,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst) MMSSCPacketType packet_type= -1; MMSContext *mms = &mmst->mms; for(;;) { - read_result = url_read_complete(mms->mms_hd, mms->in_buffer, 8); + read_result = ffurl_read_complete(mms->mms_hd, mms->in_buffer, 8); if (read_result != 8) { if(read_result < 0) { av_log(NULL, AV_LOG_ERROR, @@ -261,7 +261,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst) int length_remaining, hr; mmst->incoming_flags= mms->in_buffer[3]; - read_result= url_read_complete(mms->mms_hd, mms->in_buffer+8, 4); + read_result= ffurl_read_complete(mms->mms_hd, mms->in_buffer+8, 4); if(read_result != 4) { av_log(NULL, AV_LOG_ERROR, "Reading command packet length failed: %d (%s)\n", @@ -281,7 +281,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst) length_remaining, sizeof(mms->in_buffer) - 12); return AVERROR_INVALIDDATA; } - read_result = url_read_complete(mms->mms_hd, mms->in_buffer + 12, + read_result = ffurl_read_complete(mms->mms_hd, mms->in_buffer + 12, length_remaining) ; if (read_result != length_remaining) { av_log(NULL, AV_LOG_ERROR, @@ -319,7 +319,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst) } mms->remaining_in_len = length_remaining; mms->read_in_ptr = mms->in_buffer; - read_result= url_read_complete(mms->mms_hd, mms->in_buffer, length_remaining); + read_result= ffurl_read_complete(mms->mms_hd, mms->in_buffer, length_remaining); if(read_result != length_remaining) { av_log(NULL, AV_LOG_ERROR, "Failed to read packet data of size %d: %d (%s)\n", diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index b979566972..ca2ce09ff9 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -86,7 +86,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, if (channel_id < 2) { //special case for channel number >= 64 buf[1] = 0; - if (url_read_complete(h, buf, channel_id + 1) != channel_id + 1) + if (ffurl_read_complete(h, buf, channel_id + 1) != channel_id + 1) return AVERROR(EIO); size += channel_id + 1; channel_id = AV_RL16(buf) + 64; @@ -99,28 +99,28 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, if (hdr == RTMP_PS_ONEBYTE) { timestamp = prev_pkt[channel_id].ts_delta; } else { - if (url_read_complete(h, buf, 3) != 3) + if (ffurl_read_complete(h, buf, 3) != 3) return AVERROR(EIO); size += 3; timestamp = AV_RB24(buf); if (hdr != RTMP_PS_FOURBYTES) { - if (url_read_complete(h, buf, 3) != 3) + if (ffurl_read_complete(h, buf, 3) != 3) return AVERROR(EIO); size += 3; data_size = AV_RB24(buf); - if (url_read_complete(h, buf, 1) != 1) + if (ffurl_read_complete(h, buf, 1) != 1) return AVERROR(EIO); size++; type = buf[0]; if (hdr == RTMP_PS_TWELVEBYTES) { - if (url_read_complete(h, buf, 4) != 4) + if (ffurl_read_complete(h, buf, 4) != 4) return AVERROR(EIO); size += 4; extra = AV_RL32(buf); } } if (timestamp == 0xFFFFFF) { - if (url_read_complete(h, buf, 4) != 4) + if (ffurl_read_complete(h, buf, 4) != 4) return AVERROR(EIO); timestamp = AV_RB32(buf); } @@ -140,7 +140,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, prev_pkt[channel_id].extra = extra; while (data_size > 0) { int toread = FFMIN(data_size, chunk_size); - if (url_read_complete(h, p->data + offset, toread) != toread) { + if (ffurl_read_complete(h, p->data + offset, toread) != toread) { ff_rtmp_packet_destroy(p); return AVERROR(EIO); } @@ -148,7 +148,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p, offset += chunk_size; size += chunk_size; if (data_size > 0) { - url_read_complete(h, &t, 1); //marker + ffurl_read_complete(h, &t, 1); //marker size++; if (t != (0xC0 + channel_id)) return -1; diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 7c21ff7bfe..0d1bc8e196 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -487,12 +487,12 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) client_pos = rtmp_handshake_imprint_with_digest(tosend + 1); url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1); - i = url_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1); + i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1); if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) { av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); return -1; } - i = url_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE); + i = ffurl_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE); if (i != RTMP_HANDSHAKE_PACKET_SIZE) { av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); return -1; diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index cf36814afa..15999b8617 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -818,7 +818,7 @@ void ff_rtsp_skip_packet(AVFormatContext *s) int ret, len, len1; uint8_t buf[1024]; - ret = url_read_complete(rt->rtsp_hd, buf, 3); + ret = ffurl_read_complete(rt->rtsp_hd, buf, 3); if (ret != 3) return; len = AV_RB16(buf + 1); @@ -830,7 +830,7 @@ void ff_rtsp_skip_packet(AVFormatContext *s) len1 = len; if (len1 > sizeof(buf)) len1 = sizeof(buf); - ret = url_read_complete(rt->rtsp_hd, buf, len1); + ret = ffurl_read_complete(rt->rtsp_hd, buf, len1); if (ret != len1) return; len -= len1; @@ -855,7 +855,7 @@ int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, for (;;) { q = buf; for (;;) { - ret = url_read_complete(rt->rtsp_hd, &ch, 1); + ret = ffurl_read_complete(rt->rtsp_hd, &ch, 1); #ifdef DEBUG_RTP_TCP av_dlog(s, "ret=%d c=%02x [%c]\n", ret, ch, ch); #endif @@ -903,7 +903,7 @@ int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, if (content_length > 0) { /* leave some room for a trailing '\0' (useful for simple parsing) */ content = av_malloc(content_length + 1); - (void)url_read_complete(rt->rtsp_hd, content, content_length); + ffurl_read_complete(rt->rtsp_hd, content, content_length); content[content_length] = '\0'; } if (content_ptr) diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c index e2ba76e636..866f313d10 100644 --- a/libavformat/rtspdec.c +++ b/libavformat/rtspdec.c @@ -28,6 +28,7 @@ #include "os_support.h" #include "rtsp.h" #include "rdt.h" +#include "url.h" //#define DEBUG //#define DEBUG_RTP_TCP @@ -200,7 +201,7 @@ redo: if (rt->state != RTSP_STATE_STREAMING) return 0; } - ret = url_read_complete(rt->rtsp_hd, buf, 3); + ret = ffurl_read_complete(rt->rtsp_hd, buf, 3); if (ret != 3) return -1; id = buf[0]; @@ -211,7 +212,7 @@ redo: if (len > buf_size || len < 12) goto redo; /* get the data */ - ret = url_read_complete(rt->rtsp_hd, buf, len); + ret = ffurl_read_complete(rt->rtsp_hd, buf, len); if (ret != len) return -1; if (rt->transport == RTSP_TRANSPORT_RDT && diff --git a/libavformat/url.h b/libavformat/url.h index 799b80c395..8d1a7f702c 100644 --- a/libavformat/url.h +++ b/libavformat/url.h @@ -69,4 +69,13 @@ int ffurl_open(URLContext **h, const char *url, int flags); */ int ffurl_read(URLContext *h, unsigned char *buf, int size); +/** + * Read as many bytes as possible (up to size), calling the + * read function multiple times if necessary. + * This makes special short-read handling in applications + * unnecessary, if the return value is < size then it is + * certain there was either an error or the end of file was reached. + */ +int ffurl_read_complete(URLContext *h, unsigned char *buf, int size); + #endif //AVFORMAT_URL_H -- cgit v1.2.3 From 925e908bc7a3ddbd31f94ae9a67fbee170fef3d3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 31 Mar 2011 16:48:01 +0200 Subject: avio: make url_write() internal. --- libavformat/avio.c | 6 +++++- libavformat/avio.h | 9 +-------- libavformat/aviobuf.c | 2 +- libavformat/gopher.c | 2 +- libavformat/http.c | 12 ++++++------ libavformat/md5proto.c | 2 +- libavformat/mmst.c | 2 +- libavformat/rtmppkt.c | 6 +++--- libavformat/rtmpproto.c | 6 +++--- libavformat/rtpdec.c | 9 +++++---- libavformat/rtpproto.c | 2 +- libavformat/rtsp.c | 4 ++-- libavformat/rtspenc.c | 3 ++- libavformat/sapenc.c | 4 ++-- libavformat/url.h | 8 ++++++++ 15 files changed, 42 insertions(+), 35 deletions(-) (limited to 'libavformat/mmst.c') diff --git a/libavformat/avio.c b/libavformat/avio.c index 4f56286f8d..568f6885df 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -188,6 +188,10 @@ int url_read_complete(URLContext *h, unsigned char *buf, int size) { return ffurl_read_complete(h, buf, size); } +int url_write(URLContext *h, const unsigned char *buf, int size) +{ + return ffurl_write(h, buf, size); +} #endif #define URL_SCHEME_CHARS \ @@ -280,7 +284,7 @@ int ffurl_read_complete(URLContext *h, unsigned char *buf, int size) return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read); } -int url_write(URLContext *h, const unsigned char *buf, int size) +int ffurl_write(URLContext *h, const unsigned char *buf, int size) { if (!(h->flags & (URL_WRONLY | URL_RDWR))) return AVERROR(EIO); diff --git a/libavformat/avio.h b/libavformat/avio.h index 2b1c6ff913..41b3cafbd2 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -107,16 +107,9 @@ attribute_deprecated int url_connect(URLContext *h); attribute_deprecated int url_open(URLContext **h, const char *url, int flags); attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size); attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size); +attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size); #endif -/** - * Write size bytes from buf to the resource accessed by h. - * - * @return the number of bytes actually written, or a negative value - * corresponding to an AVERROR code in case of failure - */ -int url_write(URLContext *h, const unsigned char *buf, int size); - /** * Passing this as the "whence" parameter to a seek function causes it to * return the filesize without seeking anywhere. Supporting this is optional. diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index a8c59b7cc8..c7bdec8492 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -846,7 +846,7 @@ int ffio_fdopen(AVIOContext **s, URLContext *h) if (ffio_init_context(*s, buffer, buffer_size, (h->flags & URL_WRONLY || h->flags & URL_RDWR), h, - ffurl_read, url_write, url_seek) < 0) { + ffurl_read, ffurl_write, url_seek) < 0) { av_free(buffer); av_freep(s); return AVERROR(EIO); diff --git a/libavformat/gopher.c b/libavformat/gopher.c index 53f7617fb1..c4c895df73 100644 --- a/libavformat/gopher.c +++ b/libavformat/gopher.c @@ -35,7 +35,7 @@ typedef struct { static int gopher_write(URLContext *h, const uint8_t *buf, int size) { GopherContext *s = h->priv_data; - return url_write(s->hd, buf, size); + return ffurl_write(s->hd, buf, size); } static int gopher_connect(URLContext *h, const char *path) diff --git a/libavformat/http.c b/libavformat/http.c index 2bd223891e..61ae3f438c 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -333,7 +333,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, authstr ? authstr : ""); av_freep(&authstr); - if (url_write(s->hd, s->buffer, strlen(s->buffer)) < 0) + if (ffurl_write(s->hd, s->buffer, strlen(s->buffer)) < 0) return AVERROR(EIO); /* init input buffer */ @@ -427,7 +427,7 @@ static int http_write(URLContext *h, const uint8_t *buf, int size) if (s->chunksize == -1) { /* non-chunked data is sent without any special encoding */ - return url_write(s->hd, buf, size); + return ffurl_write(s->hd, buf, size); } /* silently ignore zero-size data since chunk encoding that would @@ -436,9 +436,9 @@ static int http_write(URLContext *h, const uint8_t *buf, int size) /* upload data using chunked encoding */ snprintf(temp, sizeof(temp), "%x\r\n", size); - if ((ret = url_write(s->hd, temp, strlen(temp))) < 0 || - (ret = url_write(s->hd, buf, size)) < 0 || - (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0) + if ((ret = ffurl_write(s->hd, temp, strlen(temp))) < 0 || + (ret = ffurl_write(s->hd, buf, size)) < 0 || + (ret = ffurl_write(s->hd, crlf, sizeof(crlf) - 1)) < 0) return ret; } return size; @@ -452,7 +452,7 @@ static int http_close(URLContext *h) /* signal end of chunked encoding if used */ if ((h->flags & URL_WRONLY) && s->chunksize != -1) { - ret = url_write(s->hd, footer, sizeof(footer) - 1); + ret = ffurl_write(s->hd, footer, sizeof(footer) - 1); ret = ret > 0 ? 0 : ret; } diff --git a/libavformat/md5proto.c b/libavformat/md5proto.c index 23815095d1..ae3e96de72 100644 --- a/libavformat/md5proto.c +++ b/libavformat/md5proto.c @@ -68,7 +68,7 @@ static int md5_close(URLContext *h) err = ffurl_open(&out, filename, URL_WRONLY); if (err) return err; - err = url_write(out, buf, i*2+1); + err = ffurl_write(out, buf, i*2+1); url_close(out); } else { if (fwrite(buf, 1, i*2+1, stdout) < i*2+1) diff --git a/libavformat/mmst.c b/libavformat/mmst.c index d28a6ca6a8..b843b6472b 100644 --- a/libavformat/mmst.c +++ b/libavformat/mmst.c @@ -139,7 +139,7 @@ static int send_command_packet(MMSTContext *mmst) memset(mms->write_out_ptr, 0, exact_length - len); // write it out. - write_result= url_write(mms->mms_hd, mms->out_buffer, exact_length); + write_result= ffurl_write(mms->mms_hd, mms->out_buffer, exact_length); if(write_result != exact_length) { av_log(NULL, AV_LOG_ERROR, "Failed to write data of length %d: %d (%s)\n", diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c index ca2ce09ff9..63b0628799 100644 --- a/libavformat/rtmppkt.c +++ b/libavformat/rtmppkt.c @@ -215,15 +215,15 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt, } prev_pkt[pkt->channel_id].extra = pkt->extra; - url_write(h, pkt_hdr, p-pkt_hdr); + ffurl_write(h, pkt_hdr, p-pkt_hdr); size = p - pkt_hdr + pkt->data_size; while (off < pkt->data_size) { int towrite = FFMIN(chunk_size, pkt->data_size - off); - url_write(h, pkt->data + off, towrite); + ffurl_write(h, pkt->data + off, towrite); off += towrite; if (off < pkt->data_size) { uint8_t marker = 0xC0 | pkt->channel_id; - url_write(h, &marker, 1); + ffurl_write(h, &marker, 1); size++; } } diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 0d1bc8e196..98babcfc3b 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -486,7 +486,7 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) tosend[i] = av_lfg_get(&rnd) >> 24; client_pos = rtmp_handshake_imprint_with_digest(tosend + 1); - url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1); + ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1); i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1); if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) { av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); @@ -532,9 +532,9 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt) tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32); // write reply back to the server - url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE); + ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE); } else { - url_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE); + ffurl_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE); } return 0; diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 281f51c443..43305a30c7 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -25,6 +25,7 @@ #include "libavcodec/get_bits.h" #include "avformat.h" #include "mpegts.h" +#include "url.h" #include #include @@ -325,8 +326,8 @@ int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count) if ((len > 0) && buf) { int result; av_dlog(s->ic, "sending %d bytes of RR\n", len); - result= url_write(s->rtp_ctx, buf, len); - av_dlog(s->ic, "result from url_write: %d\n", result); + result= ffurl_write(s->rtp_ctx, buf, len); + av_dlog(s->ic, "result from ffurl_write: %d\n", result); av_free(buf); } return 0; @@ -351,7 +352,7 @@ void rtp_send_punch_packets(URLContext* rtp_handle) avio_flush(pb); len = avio_close_dyn_buf(pb, &buf); if ((len > 0) && buf) - url_write(rtp_handle, buf, len); + ffurl_write(rtp_handle, buf, len); av_free(buf); /* Send a minimal RTCP RR */ @@ -366,7 +367,7 @@ void rtp_send_punch_packets(URLContext* rtp_handle) avio_flush(pb); len = avio_close_dyn_buf(pb, &buf); if ((len > 0) && buf) - url_write(rtp_handle, buf, len); + ffurl_write(rtp_handle, buf, len); av_free(buf); } diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index 1691f3cb48..22e59859d3 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -297,7 +297,7 @@ static int rtp_write(URLContext *h, const uint8_t *buf, int size) hd = s->rtp_hd; } - ret = url_write(hd, buf, size); + ret = ffurl_write(hd, buf, size); #if 0 { struct timespec ts; diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 15999b8617..caa66c60cc 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -983,14 +983,14 @@ static int ff_rtsp_send_cmd_with_content_async(AVFormatContext *s, av_dlog(s, "Sending:\n%s--\n", buf); - url_write(rt->rtsp_hd_out, out_buf, strlen(out_buf)); + ffurl_write(rt->rtsp_hd_out, out_buf, strlen(out_buf)); if (send_content_length > 0 && send_content) { if (rt->control_transport == RTSP_MODE_TUNNEL) { av_log(s, AV_LOG_ERROR, "tunneling of RTSP requests " "with content data not supported\n"); return AVERROR_PATCHWELCOME; } - url_write(rt->rtsp_hd_out, send_content, send_content_length); + ffurl_write(rt->rtsp_hd_out, send_content, send_content_length); } rt->last_cmd_time = av_gettime(); diff --git a/libavformat/rtspenc.c b/libavformat/rtspenc.c index 7f52b1fdb1..b4b26204f9 100644 --- a/libavformat/rtspenc.c +++ b/libavformat/rtspenc.c @@ -32,6 +32,7 @@ #include "avio_internal.h" #include "libavutil/intreadwrite.h" #include "libavutil/avstring.h" +#include "url.h" #define SDP_MAX_SIZE 16384 @@ -158,7 +159,7 @@ static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st) interleave_header[0] = '$'; interleave_header[1] = id; AV_WB16(interleave_header + 2, packet_len); - url_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len); + ffurl_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len); ptr += packet_len; size -= packet_len; } diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c index c811d2f001..25354208b7 100644 --- a/libavformat/sapenc.c +++ b/libavformat/sapenc.c @@ -54,7 +54,7 @@ static int sap_write_close(AVFormatContext *s) if (sap->last_time && sap->ann && sap->ann_fd) { sap->ann[0] |= 4; /* Session deletion*/ - url_write(sap->ann_fd, sap->ann, sap->ann_size); + ffurl_write(sap->ann_fd, sap->ann, sap->ann_size); } av_freep(&sap->ann); @@ -239,7 +239,7 @@ static int sap_write_packet(AVFormatContext *s, AVPacket *pkt) int64_t now = av_gettime(); if (!sap->last_time || now - sap->last_time > 5000000) { - int ret = url_write(sap->ann_fd, sap->ann, sap->ann_size); + int ret = ffurl_write(sap->ann_fd, sap->ann, sap->ann_size); /* Don't abort even if we get "Destination unreachable" */ if (ret < 0 && ret != AVERROR(ECONNREFUSED)) return ret; diff --git a/libavformat/url.h b/libavformat/url.h index 8d1a7f702c..45bf8c9397 100644 --- a/libavformat/url.h +++ b/libavformat/url.h @@ -78,4 +78,12 @@ int ffurl_read(URLContext *h, unsigned char *buf, int size); */ int ffurl_read_complete(URLContext *h, unsigned char *buf, int size); +/** + * Write size bytes from buf to the resource accessed by h. + * + * @return the number of bytes actually written, or a negative value + * corresponding to an AVERROR code in case of failure + */ +int ffurl_write(URLContext *h, const unsigned char *buf, int size); + #endif //AVFORMAT_URL_H -- cgit v1.2.3 From e52a9145c8bf0748ae970e210e528ff56508964c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 31 Mar 2011 17:36:06 +0200 Subject: avio: make url_close() internal. --- libavformat/applehttpproto.c | 4 ++-- libavformat/avio.c | 12 ++++++++---- libavformat/avio.h | 10 +--------- libavformat/aviobuf.c | 4 ++-- libavformat/concat.c | 4 ++-- libavformat/gopher.c | 2 +- libavformat/http.c | 10 +++++----- libavformat/md5proto.c | 2 +- libavformat/mmsh.c | 4 ++-- libavformat/mmst.c | 2 +- libavformat/rtmpproto.c | 2 +- libavformat/rtpproto.c | 8 ++++---- libavformat/rtsp.c | 10 +++++----- libavformat/sapdec.c | 2 +- libavformat/sapenc.c | 2 +- libavformat/url.h | 9 +++++++++ 16 files changed, 46 insertions(+), 41 deletions(-) (limited to 'libavformat/mmst.c') diff --git a/libavformat/applehttpproto.c b/libavformat/applehttpproto.c index fbc243e534..c7e12a9fb8 100644 --- a/libavformat/applehttpproto.c +++ b/libavformat/applehttpproto.c @@ -246,7 +246,7 @@ start: return ret; } if (s->seg_hd) { - url_close(s->seg_hd); + ffurl_close(s->seg_hd); s->seg_hd = NULL; s->cur_seq_no++; } @@ -292,7 +292,7 @@ static int applehttp_close(URLContext *h) free_segment_list(s); free_variant_list(s); - url_close(s->seg_hd); + ffurl_close(s->seg_hd); av_free(s); return 0; } diff --git a/libavformat/avio.c b/libavformat/avio.c index 8f13e5f6e5..b372ee376d 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -164,7 +164,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up, if (!ret) return 0; fail: - url_close(*puc); + ffurl_close(*puc); *puc = NULL; return ret; } @@ -196,6 +196,10 @@ int64_t url_seek(URLContext *h, int64_t pos, int whence) { return ffurl_seek(h, pos, whence); } +int url_close(URLContext *h) +{ + return ffurl_close(h); +} #endif #define URL_SCHEME_CHARS \ @@ -239,7 +243,7 @@ int ffurl_open(URLContext **puc, const char *filename, int flags) ret = ffurl_connect(*puc); if (!ret) return 0; - url_close(*puc); + ffurl_close(*puc); *puc = NULL; return ret; } @@ -309,7 +313,7 @@ int64_t ffurl_seek(URLContext *h, int64_t pos, int whence) return ret; } -int url_close(URLContext *h) +int ffurl_close(URLContext *h) { int ret = 0; if (!h) return 0; /* can happen when ffurl_open fails */ @@ -330,7 +334,7 @@ int url_exist(const char *filename) URLContext *h; if (ffurl_open(&h, filename, URL_RDONLY) < 0) return 0; - url_close(h); + ffurl_close(h); return 1; } diff --git a/libavformat/avio.h b/libavformat/avio.h index 7f53fdddc6..cd78d932d9 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -109,17 +109,9 @@ attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size); attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size); attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size); attribute_deprecated int64_t url_seek(URLContext *h, int64_t pos, int whence); +attribute_deprecated int url_close(URLContext *h); #endif -/** - * Close the resource accessed by the URLContext h, and free the - * memory used by it. - * - * @return a negative value if an error condition occurred, 0 - * otherwise - */ -int url_close(URLContext *h); - /** * Return a non-zero value if the resource indicated by url * exists, 0 otherwise. diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 306fe1c653..3d088ddcc7 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -950,7 +950,7 @@ int avio_open(AVIOContext **s, const char *filename, int flags) return err; err = ffio_fdopen(s, h); if (err < 0) { - url_close(h); + ffurl_close(h); return err; } return 0; @@ -962,7 +962,7 @@ int avio_close(AVIOContext *s) av_free(s->buffer); av_free(s); - return url_close(h); + return ffurl_close(h); } #if FF_API_OLD_AVIO diff --git a/libavformat/concat.c b/libavformat/concat.c index 0f3ecb0d21..40317de69e 100644 --- a/libavformat/concat.c +++ b/libavformat/concat.c @@ -47,7 +47,7 @@ static av_cold int concat_close(URLContext *h) struct concat_nodes *nodes = data->nodes; for (i = 0; i != data->length; i++) - err |= url_close(nodes[i].uc); + err |= ffurl_close(nodes[i].uc); av_freep(&data->nodes); av_freep(&h->priv_data); @@ -106,7 +106,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags) /* creating size */ if ((size = url_filesize(uc)) < 0) { - url_close(uc); + ffurl_close(uc); err = AVERROR(ENOSYS); break; } diff --git a/libavformat/gopher.c b/libavformat/gopher.c index c4c895df73..dfb79c9965 100644 --- a/libavformat/gopher.c +++ b/libavformat/gopher.c @@ -69,7 +69,7 @@ static int gopher_close(URLContext *h) { GopherContext *s = h->priv_data; if (s->hd) { - url_close(s->hd); + ffurl_close(s->hd); s->hd = NULL; } av_freep(&h->priv_data); diff --git a/libavformat/http.c b/libavformat/http.c index 61ae3f438c..bb756c2843 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -134,7 +134,7 @@ static int http_open_cnx(URLContext *h) goto fail; if (s->http_code == 401) { if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) { - url_close(hd); + ffurl_close(hd); goto redo; } else goto fail; @@ -142,7 +142,7 @@ static int http_open_cnx(URLContext *h) if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307) && location_changed == 1) { /* url moved, get next */ - url_close(hd); + ffurl_close(hd); if (redirects++ >= MAX_REDIRECTS) return AVERROR(EIO); location_changed = 0; @@ -151,7 +151,7 @@ static int http_open_cnx(URLContext *h) return 0; fail: if (hd) - url_close(hd); + ffurl_close(hd); s->hd = NULL; return AVERROR(EIO); } @@ -457,7 +457,7 @@ static int http_close(URLContext *h) } if (s->hd) - url_close(s->hd); + ffurl_close(s->hd); return ret; } @@ -493,7 +493,7 @@ static int64_t http_seek(URLContext *h, int64_t off, int whence) s->off = old_off; return -1; } - url_close(old_hd); + ffurl_close(old_hd); return off; } diff --git a/libavformat/md5proto.c b/libavformat/md5proto.c index ae3e96de72..3f2755eb98 100644 --- a/libavformat/md5proto.c +++ b/libavformat/md5proto.c @@ -69,7 +69,7 @@ static int md5_close(URLContext *h) if (err) return err; err = ffurl_write(out, buf, i*2+1); - url_close(out); + ffurl_close(out); } else { if (fwrite(buf, 1, i*2+1, stdout) < i*2+1) err = AVERROR(errno); diff --git a/libavformat/mmsh.c b/libavformat/mmsh.c index 32f8e4d4e0..bf872b3dd5 100644 --- a/libavformat/mmsh.c +++ b/libavformat/mmsh.c @@ -64,7 +64,7 @@ static int mmsh_close(URLContext *h) MMSHContext *mmsh = (MMSHContext *)h->priv_data; MMSContext *mms = &mmsh->mms; if (mms->mms_hd) - url_close(mms->mms_hd); + ffurl_close(mms->mms_hd); av_free(mms->streams); av_free(mms->asf_header); av_freep(&h->priv_data); @@ -259,7 +259,7 @@ static int mmsh_open(URLContext *h, const char *uri, int flags) } // close the socket and then reopen it for sending the second play request. - url_close(mms->mms_hd); + ffurl_close(mms->mms_hd); memset(headers, 0, sizeof(headers)); if (ffurl_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) { return AVERROR(EIO); diff --git a/libavformat/mmst.c b/libavformat/mmst.c index b843b6472b..cba65e2ee5 100644 --- a/libavformat/mmst.c +++ b/libavformat/mmst.c @@ -464,7 +464,7 @@ static int mms_close(URLContext *h) MMSContext *mms = &mmst->mms; if(mms->mms_hd) { send_close_packet(mmst); - url_close(mms->mms_hd); + ffurl_close(mms->mms_hd); } /* free all separately allocated pointers in mms */ diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 98babcfc3b..b87e4b8b0d 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -786,7 +786,7 @@ static int rtmp_close(URLContext *h) gen_delete_stream(h, rt); av_freep(&rt->flv_data); - url_close(rt->stream); + ffurl_close(rt->stream); av_free(rt); return 0; } diff --git a/libavformat/rtpproto.c b/libavformat/rtpproto.c index 22e59859d3..8772510ac5 100644 --- a/libavformat/rtpproto.c +++ b/libavformat/rtpproto.c @@ -212,9 +212,9 @@ static int rtp_open(URLContext *h, const char *uri, int flags) fail: if (s->rtp_hd) - url_close(s->rtp_hd); + ffurl_close(s->rtp_hd); if (s->rtcp_hd) - url_close(s->rtcp_hd); + ffurl_close(s->rtcp_hd); av_free(s); return AVERROR(EIO); } @@ -313,8 +313,8 @@ static int rtp_close(URLContext *h) { RTPContext *s = h->priv_data; - url_close(s->rtp_hd); - url_close(s->rtcp_hd); + ffurl_close(s->rtp_hd); + ffurl_close(s->rtcp_hd); av_free(s); return 0; } diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index caa66c60cc..ac40430c57 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -509,7 +509,7 @@ void ff_rtsp_undo_setup(AVFormatContext *s) } rtsp_st->transport_priv = NULL; if (rtsp_st->rtp_handle) - url_close(rtsp_st->rtp_handle); + ffurl_close(rtsp_st->rtp_handle); rtsp_st->rtp_handle = NULL; } } @@ -1297,8 +1297,8 @@ fail: void ff_rtsp_close_connections(AVFormatContext *s) { RTSPState *rt = s->priv_data; - if (rt->rtsp_hd_out != rt->rtsp_hd) url_close(rt->rtsp_hd_out); - url_close(rt->rtsp_hd); + if (rt->rtsp_hd_out != rt->rtsp_hd) ffurl_close(rt->rtsp_hd_out); + ffurl_close(rt->rtsp_hd); rt->rtsp_hd = rt->rtsp_hd_out = NULL; } @@ -1888,7 +1888,7 @@ static int rtp_read_header(AVFormatContext *s, break; } getsockname(url_get_file_handle(in), (struct sockaddr*) &addr, &addrlen); - url_close(in); + ffurl_close(in); in = NULL; memset(&codec, 0, sizeof(codec)); @@ -1927,7 +1927,7 @@ static int rtp_read_header(AVFormatContext *s, fail: if (in) - url_close(in); + ffurl_close(in); ff_network_close(); return ret; } diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c index c8cbde8e44..c3e7a8bbc0 100644 --- a/libavformat/sapdec.c +++ b/libavformat/sapdec.c @@ -54,7 +54,7 @@ static int sap_read_close(AVFormatContext *s) if (sap->sdp_ctx) av_close_input_stream(sap->sdp_ctx); if (sap->ann_fd) - url_close(sap->ann_fd); + ffurl_close(sap->ann_fd); av_freep(&sap->sdp); ff_network_close(); return 0; diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c index 25354208b7..ad8cbac52f 100644 --- a/libavformat/sapenc.c +++ b/libavformat/sapenc.c @@ -59,7 +59,7 @@ static int sap_write_close(AVFormatContext *s) av_freep(&sap->ann); if (sap->ann_fd) - url_close(sap->ann_fd); + ffurl_close(sap->ann_fd); ff_network_close(); return 0; } diff --git a/libavformat/url.h b/libavformat/url.h index ad0f35de79..2ec3eb4a46 100644 --- a/libavformat/url.h +++ b/libavformat/url.h @@ -102,4 +102,13 @@ int ffurl_write(URLContext *h, const unsigned char *buf, int size); */ int64_t ffurl_seek(URLContext *h, int64_t pos, int whence); +/** + * Close the resource accessed by the URLContext h, and free the + * memory used by it. + * + * @return a negative value if an error condition occurred, 0 + * otherwise + */ +int ffurl_close(URLContext *h); + #endif //AVFORMAT_URL_H -- cgit v1.2.3