Commit 0589da0a authored by Anton Khirnov's avatar Anton Khirnov

avio: make url_open() internal.

parent 62eaaeac
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "url.h"
#include <unistd.h> #include <unistd.h>
/* /*
...@@ -274,7 +275,7 @@ retry: ...@@ -274,7 +275,7 @@ retry:
} }
url = s->segments[s->cur_seq_no - s->start_seq_no]->url, url = s->segments[s->cur_seq_no - s->start_seq_no]->url,
av_log(NULL, AV_LOG_DEBUG, "opening %s\n", url); av_log(NULL, AV_LOG_DEBUG, "opening %s\n", url);
ret = url_open(&s->seg_hd, url, URL_RDONLY); ret = ffurl_open(&s->seg_hd, url, URL_RDONLY);
if (ret < 0) { if (ret < 0) {
if (url_interrupt_cb()) if (url_interrupt_cb())
return AVERROR_EXIT; return AVERROR_EXIT;
......
...@@ -176,6 +176,10 @@ int url_connect(URLContext* uc) ...@@ -176,6 +176,10 @@ int url_connect(URLContext* uc)
{ {
return ffurl_connect(uc); return ffurl_connect(uc);
} }
int url_open(URLContext **puc, const char *filename, int flags)
{
return ffurl_open(puc, filename, flags);
}
#endif #endif
#define URL_SCHEME_CHARS \ #define URL_SCHEME_CHARS \
...@@ -211,7 +215,7 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags) ...@@ -211,7 +215,7 @@ int ffurl_alloc(URLContext **puc, const char *filename, int flags)
return AVERROR(ENOENT); return AVERROR(ENOENT);
} }
int url_open(URLContext **puc, const char *filename, int flags) int ffurl_open(URLContext **puc, const char *filename, int flags)
{ {
int ret = ffurl_alloc(puc, filename, flags); int ret = ffurl_alloc(puc, filename, flags);
if (ret) if (ret)
...@@ -292,7 +296,7 @@ int64_t url_seek(URLContext *h, int64_t pos, int whence) ...@@ -292,7 +296,7 @@ int64_t url_seek(URLContext *h, int64_t pos, int whence)
int url_close(URLContext *h) int url_close(URLContext *h)
{ {
int ret = 0; int ret = 0;
if (!h) return 0; /* can happen when url_open fails */ if (!h) return 0; /* can happen when ffurl_open fails */
if (h->is_connected && h->prot->url_close) if (h->is_connected && h->prot->url_close)
ret = h->prot->url_close(h); ret = h->prot->url_close(h);
...@@ -308,7 +312,7 @@ int url_close(URLContext *h) ...@@ -308,7 +312,7 @@ int url_close(URLContext *h)
int url_exist(const char *filename) int url_exist(const char *filename)
{ {
URLContext *h; URLContext *h;
if (url_open(&h, filename, URL_RDONLY) < 0) if (ffurl_open(&h, filename, URL_RDONLY) < 0)
return 0; return 0;
url_close(h); url_close(h);
return 1; return 1;
......
...@@ -104,21 +104,9 @@ attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol ...@@ -104,21 +104,9 @@ attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol
const char *url, int flags); const char *url, int flags);
attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags); attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags);
attribute_deprecated int url_connect(URLContext *h); attribute_deprecated int url_connect(URLContext *h);
attribute_deprecated int url_open(URLContext **h, const char *url, int flags);
#endif #endif
/**
* Create an URLContext for accessing to the resource indicated by
* url, and open it.
*
* @param puc pointer to the location where, in case of success, the
* function puts the pointer to the created URLContext
* @param flags flags which control how the resource indicated by url
* is to be opened
* @return 0 in case of success, a negative value corresponding to an
* AVERROR code in case of failure
*/
int url_open(URLContext **h, const char *url, int flags);
/** /**
* Read up to size bytes from the resource accessed by h, and store * Read up to size bytes from the resource accessed by h, and store
* the read bytes in buf. * the read bytes in buf.
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "avio.h" #include "avio.h"
#include "avio_internal.h" #include "avio_internal.h"
#include "internal.h" #include "internal.h"
#include "url.h"
#include <stdarg.h> #include <stdarg.h>
#define IO_BUFFER_SIZE 32768 #define IO_BUFFER_SIZE 32768
...@@ -944,7 +945,7 @@ int avio_open(AVIOContext **s, const char *filename, int flags) ...@@ -944,7 +945,7 @@ int avio_open(AVIOContext **s, const char *filename, int flags)
URLContext *h; URLContext *h;
int err; int err;
err = url_open(&h, filename, flags); err = ffurl_open(&h, filename, flags);
if (err < 0) if (err < 0)
return err; return err;
err = ffio_fdopen(s, h); err = ffio_fdopen(s, h);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "avformat.h" #include "avformat.h"
#include "libavutil/avstring.h" #include "libavutil/avstring.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "url.h"
#define AV_CAT_SEPARATOR "|" #define AV_CAT_SEPARATOR "|"
...@@ -100,7 +101,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags) ...@@ -100,7 +101,7 @@ static av_cold int concat_open(URLContext *h, const char *uri, int flags)
uri += len + strspn(uri+len, AV_CAT_SEPARATOR); uri += len + strspn(uri+len, AV_CAT_SEPARATOR);
/* creating URLContext */ /* creating URLContext */
if ((err = url_open(&uc, node_uri, flags)) < 0) if ((err = ffurl_open(&uc, node_uri, flags)) < 0)
break; break;
/* creating size */ /* creating size */
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "avformat.h" #include "avformat.h"
#include "internal.h" #include "internal.h"
#include "network.h" #include "network.h"
#include "url.h"
typedef struct { typedef struct {
URLContext *hd; URLContext *hd;
...@@ -99,7 +100,7 @@ static int gopher_open(URLContext *h, const char *uri, int flags) ...@@ -99,7 +100,7 @@ static int gopher_open(URLContext *h, const char *uri, int flags)
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
s->hd = NULL; s->hd = NULL;
err = url_open(&s->hd, buf, URL_RDWR); err = ffurl_open(&s->hd, buf, URL_RDWR);
if (err < 0) if (err < 0)
goto fail; goto fail;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "http.h" #include "http.h"
#include "os_support.h" #include "os_support.h"
#include "httpauth.h" #include "httpauth.h"
#include "url.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
/* XXX: POST protocol is not completely implemented because ffmpeg uses /* XXX: POST protocol is not completely implemented because ffmpeg uses
...@@ -123,7 +124,7 @@ static int http_open_cnx(URLContext *h) ...@@ -123,7 +124,7 @@ static int http_open_cnx(URLContext *h)
port = 80; port = 80;
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
err = url_open(&hd, buf, URL_RDWR); err = ffurl_open(&hd, buf, URL_RDWR);
if (err < 0) if (err < 0)
goto fail; goto fail;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "libavutil/error.h" #include "libavutil/error.h"
#include "avformat.h" #include "avformat.h"
#include "avio.h" #include "avio.h"
#include "url.h"
#define PRIV_SIZE 128 #define PRIV_SIZE 128
...@@ -64,7 +65,7 @@ static int md5_close(URLContext *h) ...@@ -64,7 +65,7 @@ static int md5_close(URLContext *h)
av_strstart(filename, "md5:", &filename); av_strstart(filename, "md5:", &filename);
if (*filename) { if (*filename) {
err = url_open(&out, filename, URL_WRONLY); err = ffurl_open(&out, filename, URL_WRONLY);
if (err) if (err)
return err; return err;
err = url_write(out, buf, i*2+1); err = url_write(out, buf, i*2+1);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavcodec/bytestream.h" #include "libavcodec/bytestream.h"
#include "network.h" #include "network.h"
#include "url.h"
#define LOCAL_ADDRESS 0xc0a80081 // FIXME get and use correct local ip address. #define LOCAL_ADDRESS 0xc0a80081 // FIXME get and use correct local ip address.
#define LOCAL_PORT 1037 // as above. #define LOCAL_PORT 1037 // as above.
...@@ -522,7 +523,7 @@ static int mms_open(URLContext *h, const char *uri, int flags) ...@@ -522,7 +523,7 @@ static int mms_open(URLContext *h, const char *uri, int flags)
// establish tcp connection. // establish tcp connection.
ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL); 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) if (err)
goto fail; goto fail;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "flv.h" #include "flv.h"
#include "rtmp.h" #include "rtmp.h"
#include "rtmppkt.h" #include "rtmppkt.h"
#include "url.h"
/* we can't use av_log() with URLContext yet... */ /* we can't use av_log() with URLContext yet... */
#if FF_API_URL_CLASS #if FF_API_URL_CLASS
...@@ -820,7 +821,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) ...@@ -820,7 +821,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
port = RTMP_DEFAULT_PORT; port = RTMP_DEFAULT_PORT;
ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
if (url_open(&rt->stream, buf, URL_RDWR) < 0) { if (ffurl_open(&rt->stream, buf, URL_RDWR) < 0) {
av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf); av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf);
goto fail; goto fail;
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "avformat.h" #include "avformat.h"
#include "avio_internal.h" #include "avio_internal.h"
#include "rtpdec.h" #include "rtpdec.h"
#include "url.h"
#include <unistd.h> #include <unistd.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -189,7 +190,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ...@@ -189,7 +190,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
build_udp_url(buf, sizeof(buf), build_udp_url(buf, sizeof(buf),
hostname, rtp_port, local_rtp_port, ttl, max_packet_size, hostname, rtp_port, local_rtp_port, ttl, max_packet_size,
connect); connect);
if (url_open(&s->rtp_hd, buf, flags) < 0) if (ffurl_open(&s->rtp_hd, buf, flags) < 0)
goto fail; goto fail;
if (local_rtp_port>=0 && local_rtcp_port<0) if (local_rtp_port>=0 && local_rtcp_port<0)
local_rtcp_port = ff_udp_get_local_port(s->rtp_hd) + 1; local_rtcp_port = ff_udp_get_local_port(s->rtp_hd) + 1;
...@@ -197,7 +198,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) ...@@ -197,7 +198,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
build_udp_url(buf, sizeof(buf), build_udp_url(buf, sizeof(buf),
hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size, hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size,
connect); connect);
if (url_open(&s->rtcp_hd, buf, flags) < 0) if (ffurl_open(&s->rtcp_hd, buf, flags) < 0)
goto fail; goto fail;
/* just to ease handle access. XXX: need to suppress direct handle /* just to ease handle access. XXX: need to suppress direct handle
......
...@@ -1116,14 +1116,14 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, ...@@ -1116,14 +1116,14 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
"?localport=%d", j); "?localport=%d", j);
/* we will use two ports per rtp stream (rtp and rtcp) */ /* we will use two ports per rtp stream (rtp and rtcp) */
j += 2; j += 2;
if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) if (ffurl_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0)
goto rtp_opened; goto rtp_opened;
} }
} }
#if 0 #if 0
/* then try on any port */ /* then try on any port */
if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) { if (ffurl_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) {
err = AVERROR_INVALIDDATA; err = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
...@@ -1269,7 +1269,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, ...@@ -1269,7 +1269,7 @@ int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port,
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
ff_url_join(url, sizeof(url), "rtp", NULL, namebuf, ff_url_join(url, sizeof(url), "rtp", NULL, namebuf,
port, "?ttl=%d", ttl); port, "?ttl=%d", ttl);
if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { if (ffurl_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {
err = AVERROR_INVALIDDATA; err = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
...@@ -1460,7 +1460,7 @@ redirect: ...@@ -1460,7 +1460,7 @@ redirect:
} else { } else {
/* open the tcp connection */ /* open the tcp connection */
ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL); ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL);
if (url_open(&rt->rtsp_hd, tcpname, URL_RDWR) < 0) { if (ffurl_open(&rt->rtsp_hd, tcpname, URL_RDWR) < 0) {
err = AVERROR(EIO); err = AVERROR(EIO);
goto fail; goto fail;
} }
...@@ -1807,7 +1807,7 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -1807,7 +1807,7 @@ static int sdp_read_header(AVFormatContext *s, AVFormatParameters *ap)
namebuf, rtsp_st->sdp_port, namebuf, rtsp_st->sdp_port,
"?localport=%d&ttl=%d", rtsp_st->sdp_port, "?localport=%d&ttl=%d", rtsp_st->sdp_port,
rtsp_st->sdp_ttl); rtsp_st->sdp_ttl);
if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { if (ffurl_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {
err = AVERROR_INVALIDDATA; err = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
...@@ -1863,7 +1863,7 @@ static int rtp_read_header(AVFormatContext *s, ...@@ -1863,7 +1863,7 @@ static int rtp_read_header(AVFormatContext *s,
if (!ff_network_init()) if (!ff_network_init())
return AVERROR(EIO); return AVERROR(EIO);
ret = url_open(&in, s->filename, URL_RDONLY); ret = ffurl_open(&in, s->filename, URL_RDONLY);
if (ret) if (ret)
goto fail; goto fail;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "os_support.h" #include "os_support.h"
#include "internal.h" #include "internal.h"
#include "avio_internal.h" #include "avio_internal.h"
#include "url.h"
#if HAVE_POLL_H #if HAVE_POLL_H
#include <poll.h> #include <poll.h>
#endif #endif
...@@ -84,7 +85,7 @@ static int sap_read_header(AVFormatContext *s, ...@@ -84,7 +85,7 @@ static int sap_read_header(AVFormatContext *s,
ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d", ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d",
port); port);
ret = url_open(&sap->ann_fd, url, URL_RDONLY); ret = ffurl_open(&sap->ann_fd, url, URL_RDONLY);
if (ret) if (ret)
goto fail; goto fail;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "network.h" #include "network.h"
#include "os_support.h" #include "os_support.h"
#include "rtpenc_chain.h" #include "rtpenc_chain.h"
#include "url.h"
struct SAPState { struct SAPState {
uint8_t *ann; uint8_t *ann;
...@@ -145,7 +146,7 @@ static int sap_write_header(AVFormatContext *s) ...@@ -145,7 +146,7 @@ static int sap_write_header(AVFormatContext *s)
"?ttl=%d", ttl); "?ttl=%d", ttl);
if (!same_port) if (!same_port)
base_port += 2; base_port += 2;
ret = url_open(&fd, url, URL_WRONLY); ret = ffurl_open(&fd, url, URL_WRONLY);
if (ret) { if (ret) {
ret = AVERROR(EIO); ret = AVERROR(EIO);
goto fail; goto fail;
...@@ -157,7 +158,7 @@ static int sap_write_header(AVFormatContext *s) ...@@ -157,7 +158,7 @@ static int sap_write_header(AVFormatContext *s)
ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port, ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port,
"?ttl=%d&connect=1", ttl); "?ttl=%d&connect=1", ttl);
ret = url_open(&sap->ann_fd, url, URL_WRONLY); ret = ffurl_open(&sap->ann_fd, url, URL_WRONLY);
if (ret) { if (ret) {
ret = AVERROR(EIO); ret = AVERROR(EIO);
goto fail; goto fail;
......
...@@ -45,4 +45,17 @@ int ffurl_alloc(URLContext **h, const char *url, int flags); ...@@ -45,4 +45,17 @@ int ffurl_alloc(URLContext **h, const char *url, int flags);
*/ */
int ffurl_connect(URLContext *h); int ffurl_connect(URLContext *h);
/**
* Create an URLContext for accessing to the resource indicated by
* url, and open it.
*
* @param puc pointer to the location where, in case of success, the
* function puts the pointer to the created URLContext
* @param flags flags which control how the resource indicated by url
* is to be opened
* @return 0 in case of success, a negative value corresponding to an
* AVERROR code in case of failure
*/
int ffurl_open(URLContext **h, const char *url, int flags);
#endif //AVFORMAT_URL_H #endif //AVFORMAT_URL_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment