comparison http.c @ 6164:72ea866c62fd libavformat

Make the http protocol open the connection immediately in http_open again Also make the RTSP protocol use url_alloc and url_connect instead of relying on the delay open behaviour.
author mstorsjo
date Tue, 22 Jun 2010 14:15:00 +0000
parents 2e0ee73855cd
children 4fc5e0e4e1cd
comparison
equal deleted inserted replaced
6163:2e0ee73855cd 6164:72ea866c62fd
46 int http_code; 46 int http_code;
47 int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */ 47 int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */
48 int64_t off, filesize; 48 int64_t off, filesize;
49 char location[URL_SIZE]; 49 char location[URL_SIZE];
50 HTTPAuthState auth_state; 50 HTTPAuthState auth_state;
51 int init;
52 unsigned char headers[BUFFER_SIZE]; 51 unsigned char headers[BUFFER_SIZE];
53 } HTTPContext; 52 } HTTPContext;
54 53
55 #define OFFSET(x) offsetof(HTTPContext, x) 54 #define OFFSET(x) offsetof(HTTPContext, x)
56 static const AVOption options[] = { 55 static const AVOption options[] = {
97 int port, use_proxy, err, location_changed = 0, redirects = 0; 96 int port, use_proxy, err, location_changed = 0, redirects = 0;
98 HTTPAuthType cur_auth_type; 97 HTTPAuthType cur_auth_type;
99 HTTPContext *s = h->priv_data; 98 HTTPContext *s = h->priv_data;
100 URLContext *hd = NULL; 99 URLContext *hd = NULL;
101 100
102 s->init = 1;
103 proxy_path = getenv("http_proxy"); 101 proxy_path = getenv("http_proxy");
104 use_proxy = (proxy_path != NULL) && !getenv("no_proxy") && 102 use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
105 av_strstart(proxy_path, "http://", NULL); 103 av_strstart(proxy_path, "http://", NULL);
106 104
107 /* fill the dest addr */ 105 /* fill the dest addr */
163 h->is_streamed = 1; 161 h->is_streamed = 1;
164 162
165 s->filesize = -1; 163 s->filesize = -1;
166 av_strlcpy(s->location, uri, URL_SIZE); 164 av_strlcpy(s->location, uri, URL_SIZE);
167 165
168 return 0; 166 return http_open_cnx(h);
169 } 167 }
170 static int http_getc(HTTPContext *s) 168 static int http_getc(HTTPContext *s)
171 { 169 {
172 int len; 170 int len;
173 if (s->buf_ptr >= s->buf_end) { 171 if (s->buf_ptr >= s->buf_end) {
366 static int http_read(URLContext *h, uint8_t *buf, int size) 364 static int http_read(URLContext *h, uint8_t *buf, int size)
367 { 365 {
368 HTTPContext *s = h->priv_data; 366 HTTPContext *s = h->priv_data;
369 int len; 367 int len;
370 368
371 if (!s->init) {
372 int ret = http_open_cnx(h);
373 if (ret != 0)
374 return ret;
375 }
376 if (!s->hd)
377 return AVERROR(EIO);
378
379 /* A size of zero can be used to force
380 * initializaton of the connection. */
381 if (!size)
382 return 0;
383
384 if (s->chunksize >= 0) { 369 if (s->chunksize >= 0) {
385 if (!s->chunksize) { 370 if (!s->chunksize) {
386 char line[32]; 371 char line[32];
387 372
388 for(;;) { 373 for(;;) {
426 char temp[11] = ""; /* 32-bit hex + CRLF + nul */ 411 char temp[11] = ""; /* 32-bit hex + CRLF + nul */
427 int ret; 412 int ret;
428 char crlf[] = "\r\n"; 413 char crlf[] = "\r\n";
429 HTTPContext *s = h->priv_data; 414 HTTPContext *s = h->priv_data;
430 415
431 if (!s->init) {
432 int ret = http_open_cnx(h);
433 if (ret != 0)
434 return ret;
435 }
436 if (!s->hd)
437 return AVERROR(EIO);
438
439 if (s->chunksize == -1) { 416 if (s->chunksize == -1) {
440 /* non-chunked data is sent without any special encoding */ 417 /* non-chunked data is sent without any special encoding */
441 return url_write(s->hd, buf, size); 418 return url_write(s->hd, buf, size);
442 } 419 }
443 420
477 HTTPContext *s = h->priv_data; 454 HTTPContext *s = h->priv_data;
478 URLContext *old_hd = s->hd; 455 URLContext *old_hd = s->hd;
479 int64_t old_off = s->off; 456 int64_t old_off = s->off;
480 uint8_t old_buf[BUFFER_SIZE]; 457 uint8_t old_buf[BUFFER_SIZE];
481 int old_buf_size; 458 int old_buf_size;
482
483 if (!s->init) {
484 int ret = http_open_cnx(h);
485 if (ret != 0)
486 return ret;
487 }
488 if (!s->hd)
489 return AVERROR(EIO);
490 459
491 if (whence == AVSEEK_SIZE) 460 if (whence == AVSEEK_SIZE)
492 return s->filesize; 461 return s->filesize;
493 else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed) 462 else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed)
494 return -1; 463 return -1;