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(-) 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