Browse code

avio: make url_read_complete() internal.

Anton Khirnov authored on 2011/03/31 23:40:31
Showing 9 changed files
... ...
@@ -184,6 +184,10 @@ int url_read(URLContext *h, unsigned char *buf, int size)
184 184
 {
185 185
     return ffurl_read(h, buf, size);
186 186
 }
187
+int url_read_complete(URLContext *h, unsigned char *buf, int size)
188
+{
189
+    return ffurl_read_complete(h, buf, size);
190
+}
187 191
 #endif
188 192
 
189 193
 #define URL_SCHEME_CHARS                        \
... ...
@@ -269,7 +273,7 @@ int ffurl_read(URLContext *h, unsigned char *buf, int size)
269 269
     return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
270 270
 }
271 271
 
272
-int url_read_complete(URLContext *h, unsigned char *buf, int size)
272
+int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
273 273
 {
274 274
     if (h->flags & URL_WRONLY)
275 275
         return AVERROR(EIO);
... ...
@@ -106,18 +106,10 @@ attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags);
106 106
 attribute_deprecated int url_connect(URLContext *h);
107 107
 attribute_deprecated int url_open(URLContext **h, const char *url, int flags);
108 108
 attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size);
109
+attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size);
109 110
 #endif
110 111
 
111 112
 /**
112
- * Read as many bytes as possible (up to size), calling the
113
- * read function multiple times if necessary.
114
- * This makes special short-read handling in applications
115
- * unnecessary, if the return value is < size then it is
116
- * certain there was either an error or the end of file was reached.
117
- */
118
-int url_read_complete(URLContext *h, unsigned char *buf, int size);
119
-
120
-/**
121 113
  * Write size bytes from buf to the resource accessed by h.
122 114
  *
123 115
  * @return the number of bytes actually written, or a negative value
... ...
@@ -79,7 +79,7 @@ static ChunkType get_chunk_header(MMSHContext *mmsh, int *len)
79 79
     ChunkType chunk_type;
80 80
     int chunk_len, res, ext_header_len;
81 81
 
82
-    res = url_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH);
82
+    res = ffurl_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH);
83 83
     if (res != CHUNK_HEADER_LENGTH) {
84 84
         av_log(NULL, AV_LOG_ERROR, "Read data packet header failed!\n");
85 85
         return AVERROR(EIO);
... ...
@@ -101,7 +101,7 @@ static ChunkType get_chunk_header(MMSHContext *mmsh, int *len)
101 101
         return AVERROR_INVALIDDATA;
102 102
     }
103 103
 
104
-    res = url_read_complete(mms->mms_hd, ext_header, ext_header_len);
104
+    res = ffurl_read_complete(mms->mms_hd, ext_header, ext_header_len);
105 105
     if (res != ext_header_len) {
106 106
         av_log(NULL, AV_LOG_ERROR, "Read ext header failed!\n");
107 107
         return AVERROR(EIO);
... ...
@@ -122,7 +122,7 @@ static int read_data_packet(MMSHContext *mmsh, const int len)
122 122
                len, sizeof(mms->in_buffer));
123 123
         return AVERROR(EIO);
124 124
     }
125
-    res = url_read_complete(mms->mms_hd, mms->in_buffer, len);
125
+    res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len);
126 126
     av_dlog(NULL, "Data packet len = %d\n", len);
127 127
     if (res != len) {
128 128
         av_log(NULL, AV_LOG_ERROR, "Read data packet failed!\n");
... ...
@@ -174,7 +174,7 @@ static int get_http_header_data(MMSHContext *mmsh)
174 174
                        len, mms->asf_header_size);
175 175
                 return AVERROR(EIO);
176 176
             }
177
-            res = url_read_complete(mms->mms_hd, mms->asf_header, len);
177
+            res = ffurl_read_complete(mms->mms_hd, mms->asf_header, len);
178 178
             if (res != len) {
179 179
                 av_log(NULL, AV_LOG_ERROR,
180 180
                        "Recv asf header data len %d != expected len %d\n", res, len);
... ...
@@ -197,7 +197,7 @@ static int get_http_header_data(MMSHContext *mmsh)
197 197
                            len, sizeof(mms->in_buffer));
198 198
                     return AVERROR(EIO);
199 199
                 }
200
-                res = url_read_complete(mms->mms_hd, mms->in_buffer, len);
200
+                res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len);
201 201
                 if (res != len) {
202 202
                     av_log(NULL, AV_LOG_ERROR, "Read other chunk type data failed!\n");
203 203
                     return AVERROR(EIO);
... ...
@@ -241,7 +241,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst)
241 241
     MMSSCPacketType packet_type= -1;
242 242
     MMSContext *mms = &mmst->mms;
243 243
     for(;;) {
244
-        read_result = url_read_complete(mms->mms_hd, mms->in_buffer, 8);
244
+        read_result = ffurl_read_complete(mms->mms_hd, mms->in_buffer, 8);
245 245
         if (read_result != 8) {
246 246
             if(read_result < 0) {
247 247
                 av_log(NULL, AV_LOG_ERROR,
... ...
@@ -261,7 +261,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst)
261 261
             int length_remaining, hr;
262 262
 
263 263
             mmst->incoming_flags= mms->in_buffer[3];
264
-            read_result= url_read_complete(mms->mms_hd, mms->in_buffer+8, 4);
264
+            read_result= ffurl_read_complete(mms->mms_hd, mms->in_buffer+8, 4);
265 265
             if(read_result != 4) {
266 266
                 av_log(NULL, AV_LOG_ERROR,
267 267
                        "Reading command packet length failed: %d (%s)\n",
... ...
@@ -281,7 +281,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst)
281 281
                        length_remaining, sizeof(mms->in_buffer) - 12);
282 282
                 return AVERROR_INVALIDDATA;
283 283
             }
284
-            read_result = url_read_complete(mms->mms_hd, mms->in_buffer + 12,
284
+            read_result = ffurl_read_complete(mms->mms_hd, mms->in_buffer + 12,
285 285
                                             length_remaining) ;
286 286
             if (read_result != length_remaining) {
287 287
                 av_log(NULL, AV_LOG_ERROR,
... ...
@@ -319,7 +319,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst)
319 319
             }
320 320
             mms->remaining_in_len    = length_remaining;
321 321
             mms->read_in_ptr         = mms->in_buffer;
322
-            read_result= url_read_complete(mms->mms_hd, mms->in_buffer, length_remaining);
322
+            read_result= ffurl_read_complete(mms->mms_hd, mms->in_buffer, length_remaining);
323 323
             if(read_result != length_remaining) {
324 324
                 av_log(NULL, AV_LOG_ERROR,
325 325
                        "Failed to read packet data of size %d: %d (%s)\n",
... ...
@@ -86,7 +86,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
86 86
 
87 87
     if (channel_id < 2) { //special case for channel number >= 64
88 88
         buf[1] = 0;
89
-        if (url_read_complete(h, buf, channel_id + 1) != channel_id + 1)
89
+        if (ffurl_read_complete(h, buf, channel_id + 1) != channel_id + 1)
90 90
             return AVERROR(EIO);
91 91
         size += channel_id + 1;
92 92
         channel_id = AV_RL16(buf) + 64;
... ...
@@ -99,28 +99,28 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
99 99
     if (hdr == RTMP_PS_ONEBYTE) {
100 100
         timestamp = prev_pkt[channel_id].ts_delta;
101 101
     } else {
102
-        if (url_read_complete(h, buf, 3) != 3)
102
+        if (ffurl_read_complete(h, buf, 3) != 3)
103 103
             return AVERROR(EIO);
104 104
         size += 3;
105 105
         timestamp = AV_RB24(buf);
106 106
         if (hdr != RTMP_PS_FOURBYTES) {
107
-            if (url_read_complete(h, buf, 3) != 3)
107
+            if (ffurl_read_complete(h, buf, 3) != 3)
108 108
                 return AVERROR(EIO);
109 109
             size += 3;
110 110
             data_size = AV_RB24(buf);
111
-            if (url_read_complete(h, buf, 1) != 1)
111
+            if (ffurl_read_complete(h, buf, 1) != 1)
112 112
                 return AVERROR(EIO);
113 113
             size++;
114 114
             type = buf[0];
115 115
             if (hdr == RTMP_PS_TWELVEBYTES) {
116
-                if (url_read_complete(h, buf, 4) != 4)
116
+                if (ffurl_read_complete(h, buf, 4) != 4)
117 117
                     return AVERROR(EIO);
118 118
                 size += 4;
119 119
                 extra = AV_RL32(buf);
120 120
             }
121 121
         }
122 122
         if (timestamp == 0xFFFFFF) {
123
-            if (url_read_complete(h, buf, 4) != 4)
123
+            if (ffurl_read_complete(h, buf, 4) != 4)
124 124
                 return AVERROR(EIO);
125 125
             timestamp = AV_RB32(buf);
126 126
         }
... ...
@@ -140,7 +140,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
140 140
     prev_pkt[channel_id].extra      = extra;
141 141
     while (data_size > 0) {
142 142
         int toread = FFMIN(data_size, chunk_size);
143
-        if (url_read_complete(h, p->data + offset, toread) != toread) {
143
+        if (ffurl_read_complete(h, p->data + offset, toread) != toread) {
144 144
             ff_rtmp_packet_destroy(p);
145 145
             return AVERROR(EIO);
146 146
         }
... ...
@@ -148,7 +148,7 @@ int ff_rtmp_packet_read(URLContext *h, RTMPPacket *p,
148 148
         offset    += chunk_size;
149 149
         size      += chunk_size;
150 150
         if (data_size > 0) {
151
-            url_read_complete(h, &t, 1); //marker
151
+            ffurl_read_complete(h, &t, 1); //marker
152 152
             size++;
153 153
             if (t != (0xC0 + channel_id))
154 154
                 return -1;
... ...
@@ -487,12 +487,12 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
487 487
     client_pos = rtmp_handshake_imprint_with_digest(tosend + 1);
488 488
 
489 489
     url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1);
490
-    i = url_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1);
490
+    i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1);
491 491
     if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) {
492 492
         av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
493 493
         return -1;
494 494
     }
495
-    i = url_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE);
495
+    i = ffurl_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE);
496 496
     if (i != RTMP_HANDSHAKE_PACKET_SIZE) {
497 497
         av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
498 498
         return -1;
... ...
@@ -818,7 +818,7 @@ void ff_rtsp_skip_packet(AVFormatContext *s)
818 818
     int ret, len, len1;
819 819
     uint8_t buf[1024];
820 820
 
821
-    ret = url_read_complete(rt->rtsp_hd, buf, 3);
821
+    ret = ffurl_read_complete(rt->rtsp_hd, buf, 3);
822 822
     if (ret != 3)
823 823
         return;
824 824
     len = AV_RB16(buf + 1);
... ...
@@ -830,7 +830,7 @@ void ff_rtsp_skip_packet(AVFormatContext *s)
830 830
         len1 = len;
831 831
         if (len1 > sizeof(buf))
832 832
             len1 = sizeof(buf);
833
-        ret = url_read_complete(rt->rtsp_hd, buf, len1);
833
+        ret = ffurl_read_complete(rt->rtsp_hd, buf, len1);
834 834
         if (ret != len1)
835 835
             return;
836 836
         len -= len1;
... ...
@@ -855,7 +855,7 @@ int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
855 855
     for (;;) {
856 856
         q = buf;
857 857
         for (;;) {
858
-            ret = url_read_complete(rt->rtsp_hd, &ch, 1);
858
+            ret = ffurl_read_complete(rt->rtsp_hd, &ch, 1);
859 859
 #ifdef DEBUG_RTP_TCP
860 860
             av_dlog(s, "ret=%d c=%02x [%c]\n", ret, ch, ch);
861 861
 #endif
... ...
@@ -903,7 +903,7 @@ int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply,
903 903
     if (content_length > 0) {
904 904
         /* leave some room for a trailing '\0' (useful for simple parsing) */
905 905
         content = av_malloc(content_length + 1);
906
-        (void)url_read_complete(rt->rtsp_hd, content, content_length);
906
+        ffurl_read_complete(rt->rtsp_hd, content, content_length);
907 907
         content[content_length] = '\0';
908 908
     }
909 909
     if (content_ptr)
... ...
@@ -28,6 +28,7 @@
28 28
 #include "os_support.h"
29 29
 #include "rtsp.h"
30 30
 #include "rdt.h"
31
+#include "url.h"
31 32
 
32 33
 //#define DEBUG
33 34
 //#define DEBUG_RTP_TCP
... ...
@@ -200,7 +201,7 @@ redo:
200 200
         if (rt->state != RTSP_STATE_STREAMING)
201 201
             return 0;
202 202
     }
203
-    ret = url_read_complete(rt->rtsp_hd, buf, 3);
203
+    ret = ffurl_read_complete(rt->rtsp_hd, buf, 3);
204 204
     if (ret != 3)
205 205
         return -1;
206 206
     id  = buf[0];
... ...
@@ -211,7 +212,7 @@ redo:
211 211
     if (len > buf_size || len < 12)
212 212
         goto redo;
213 213
     /* get the data */
214
-    ret = url_read_complete(rt->rtsp_hd, buf, len);
214
+    ret = ffurl_read_complete(rt->rtsp_hd, buf, len);
215 215
     if (ret != len)
216 216
         return -1;
217 217
     if (rt->transport == RTSP_TRANSPORT_RDT &&
... ...
@@ -69,4 +69,13 @@ int ffurl_open(URLContext **h, const char *url, int flags);
69 69
  */
70 70
 int ffurl_read(URLContext *h, unsigned char *buf, int size);
71 71
 
72
+/**
73
+ * Read as many bytes as possible (up to size), calling the
74
+ * read function multiple times if necessary.
75
+ * This makes special short-read handling in applications
76
+ * unnecessary, if the return value is < size then it is
77
+ * certain there was either an error or the end of file was reached.
78
+ */
79
+int ffurl_read_complete(URLContext *h, unsigned char *buf, int size);
80
+
72 81
 #endif //AVFORMAT_URL_H