aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Shishkov2009-06-04 06:25:53 +0000
committerKostya Shishkov2009-06-04 06:25:53 +0000
commit0e848977cedb7345398f583d5cca5e81a4d9e45a (patch)
tree9b64d0a0c45e93d8f3dfbdc2e64b07efa6abe15c
parent989b7181acbaa5ed3d731dc479a204874fee9141 (diff)
Move function for reading whole specified amount of data from RTSP
demuxer into more common place. Originally committed as revision 19087 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavformat/avio.c14
-rw-r--r--libavformat/avio.h1
-rw-r--r--libavformat/rtsp.c26
3 files changed, 21 insertions, 20 deletions
diff --git a/libavformat/avio.c b/libavformat/avio.c
index b7d3c23ac8..b6329a927d 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -149,6 +149,20 @@ int url_read(URLContext *h, unsigned char *buf, int size)
return ret;
}
+int url_read_complete(URLContext *h, unsigned char *buf, int size)
+{
+ int ret, len;
+
+ len = 0;
+ while (len < size) {
+ ret = url_read(h, buf+len, size-len);
+ if (ret < 1)
+ return ret;
+ len += ret;
+ }
+ return len;
+}
+
int url_write(URLContext *h, unsigned char *buf, int size)
{
int ret;
diff --git a/libavformat/avio.h b/libavformat/avio.h
index a814759bec..d44e300497 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -69,6 +69,7 @@ int url_open_protocol (URLContext **puc, struct URLProtocol *up,
const char *filename, int flags);
int url_open(URLContext **h, const char *filename, int flags);
int url_read(URLContext *h, unsigned char *buf, int size);
+int url_read_complete(URLContext *h, unsigned char *buf, int size);
int url_write(URLContext *h, unsigned char *buf, int size);
int64_t url_seek(URLContext *h, int64_t pos, int whence);
int url_close(URLContext *h);
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 340bae5db8..1e9f2877df 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -703,20 +703,6 @@ void rtsp_parse_line(RTSPMessageHeader *reply, const char *buf)
}
}
-static int url_readbuf(URLContext *h, unsigned char *buf, int size)
-{
- int ret, len;
-
- len = 0;
- while (len < size) {
- ret = url_read(h, buf+len, size-len);
- if (ret < 1)
- return ret;
- len += ret;
- }
- return len;
-}
-
/* skip a RTP/TCP interleaved packet */
static void rtsp_skip_packet(AVFormatContext *s)
{
@@ -724,7 +710,7 @@ static void rtsp_skip_packet(AVFormatContext *s)
int ret, len, len1;
uint8_t buf[1024];
- ret = url_readbuf(rt->rtsp_hd, buf, 3);
+ ret = url_read_complete(rt->rtsp_hd, buf, 3);
if (ret != 3)
return;
len = AV_RB16(buf + 1);
@@ -736,7 +722,7 @@ static void rtsp_skip_packet(AVFormatContext *s)
len1 = len;
if (len1 > sizeof(buf))
len1 = sizeof(buf);
- ret = url_readbuf(rt->rtsp_hd, buf, len1);
+ ret = url_read_complete(rt->rtsp_hd, buf, len1);
if (ret != len1)
return;
len -= len1;
@@ -782,7 +768,7 @@ rtsp_read_reply (AVFormatContext *s, RTSPMessageHeader *reply,
for(;;) {
q = buf;
for(;;) {
- ret = url_readbuf(rt->rtsp_hd, &ch, 1);
+ ret = url_read_complete(rt->rtsp_hd, &ch, 1);
#ifdef DEBUG_RTP_TCP
dprintf(s, "ret=%d c=%02x [%c]\n", ret, ch, ch);
#endif
@@ -829,7 +815,7 @@ 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_readbuf(rt->rtsp_hd, content, content_length);
+ (void)url_read_complete(rt->rtsp_hd, content, content_length);
content[content_length] = '\0';
}
if (content_ptr)
@@ -1329,7 +1315,7 @@ static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
break;
/* XXX: parse message */
}
- ret = url_readbuf(rt->rtsp_hd, buf, 3);
+ ret = url_read_complete(rt->rtsp_hd, buf, 3);
if (ret != 3)
return -1;
id = buf[0];
@@ -1340,7 +1326,7 @@ static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
if (len > buf_size || len < 12)
goto redo;
/* get the data */
- ret = url_readbuf(rt->rtsp_hd, buf, len);
+ ret = url_read_complete(rt->rtsp_hd, buf, len);
if (ret != len)
return -1;
if (rt->transport == RTSP_TRANSPORT_RDT &&