[FFmpeg-devel] [PATCH] Make ff_url_split() and ff_url_join() public.

Stefano Sabatini stefano.sabatini-lala
Sat May 22 21:57:21 CEST 2010


---
 libavformat/avformat.h  |   45 ++++++++++++++++++++++++++++++++++++++++++++
 libavformat/internal.h  |   42 +++-------------------------------------
 libavformat/rtmpproto.c |    4 +-
 libavformat/utils.c     |   48 +++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 93 insertions(+), 46 deletions(-)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 91d6911..2978b90 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1185,6 +1185,51 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index,
 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
 
 /**
+ * Splits an URL string into components. To reassemble components back into
+ * a URL, use av_url_join() instead of using snprintf() directly.
+ *
+ * The pointers to buffers for storing individual components may be null,
+ * in order to ignore that component. Buffers for components not found are
+ * set to empty strings. If the port isn't found, it is set to a negative
+ *
+ * @param proto the buffer for the protocol
+ * @param proto_size the size of the proto buffer
+ * @param authorization the buffer for the authorization
+ * @param authorization_size the size of the authorization buffer
+ * @param hostname the buffer for the host name
+ * @param hostname_size the size of the hostname buffer
+ * @param port_ptr a pointer to store the port number in
+ * @param path the buffer for the path
+ * @param path_size the size of the path buffer
+ * @param url the URL to split
+ */
+void av_url_split(char *proto,         int proto_size,
+                  char *authorization, int authorization_size,
+                  char *hostname,      int hostname_size,
+                  int *port_ptr,
+                  char *path,          int path_size,
+                  const char *url);
+
+/**
+ * Assembles an URL string from components. This is the reverse operation
+ * of av_url_split().
+ *
+ * @param buf the buffer to fill with the url
+ * @param buf_size the size in bytes of the buf buffer
+ * @param proto the protocol identifier. If null, the separator
+ *              after the identifier is left out, too.
+ * @param authorization an optional authorization string, may be null
+ * @param hostname the host name string
+ * @param port the port number, left out from the string if negative
+ * @param fmt a generic format string for everything to add after the
+ *            host/port, may be null
+ * @return the number of characters written to the destination buffer
+ */
+int av_url_join(char *buf, int buf_size, const char *proto,
+                const char *authorization, const char *hostname,
+                int port, const char *fmt, ...);
+
+/**
  * Allocates the stream private data and writes the stream header to an
  * output media file.
  *
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 358959c..142c4bc 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -89,27 +89,9 @@ int ff_probe_input_buffer(ByteIOContext **pb, AVInputFormat **fmt,
                           const char *filename, void *logctx,
                           unsigned int offset, unsigned int max_probe_size);
 
+#if LIBAVFORMAT_VERSION_MAJOR < 53
 /**
- * Splits a URL string into components. To reassemble components back into
- * a URL, use ff_url_join instead of using snprintf directly.
- *
- * The pointers to buffers for storing individual components may be null,
- * in order to ignore that component. Buffers for components not found are
- * set to empty strings. If the port isn't found, it is set to a negative
- * value.
- *
- * @see ff_url_join
- *
- * @param proto the buffer for the protocol
- * @param proto_size the size of the proto buffer
- * @param authorization the buffer for the authorization
- * @param authorization_size the size of the authorization buffer
- * @param hostname the buffer for the host name
- * @param hostname_size the size of the hostname buffer
- * @param port_ptr a pointer to store the port number in
- * @param path the buffer for the path
- * @param path_size the size of the path buffer
- * @param url the URL to split
+ * @deprecated Use av_url_split() instead.
  */
 void ff_url_split(char *proto, int proto_size,
                   char *authorization, int authorization_size,
@@ -119,28 +101,12 @@ void ff_url_split(char *proto, int proto_size,
                   const char *url);
 
 /**
- * Assembles a URL string from components. This is the reverse operation
- * of ff_url_split.
- *
- * Note, this requires networking to be initialized, so the caller must
- * ensure ff_network_init has been called.
- *
- * @see ff_url_split
- *
- * @param str the buffer to fill with the url
- * @param size the size of the str buffer
- * @param proto the protocol identifier, if null, the separator
- *              after the identifier is left out, too
- * @param authorization an optional authorization string, may be null
- * @param hostname the host name string
- * @param port the port number, left out from the string if negative
- * @param fmt a generic format string for everything to add after the
- *            host/port, may be null
- * @return the number of characters written to the destination buffer
+ * @deprecated Use av_url_join() instead.
  */
 int ff_url_join(char *str, int size, const char *proto,
                 const char *authorization, const char *hostname,
                 int port, const char *fmt, ...);
+#endif
 
 /**
  * Appends the media-specific SDP fragment for the media stream c
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index 4edbffa..de63d79 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -114,7 +114,7 @@ static void gen_connect(URLContext *s, RTMPContext *rt, const char *proto,
     ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 4096);
     p = pkt.data;
 
-    ff_url_join(tcurl, sizeof(tcurl), proto, NULL, host, port, "/%s", rt->app);
+    ff_join_url(tcurl, sizeof(tcurl), proto, NULL, host, port, "/%s", rt->app);
     ff_amf_write_string(&p, "connect");
     ff_amf_write_number(&p, 1.0);
     ff_amf_write_object_start(&p);
@@ -818,7 +818,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags)
 
     if (port < 0)
         port = RTMP_DEFAULT_PORT;
-    ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
+    ff_join_url(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
 
     if (url_open(&rt->stream, buf, URL_RDWR) < 0) {
         av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf);
diff --git a/libavformat/utils.c b/libavformat/utils.c
index e5a6ce1..bc8ebf5 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3450,6 +3450,7 @@ void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload)
     pkt_dump_internal(avcl, NULL, level, pkt, dump_payload);
 }
 
+#if LIBAVFORMAT_VERSION_MAJOR < 53
 void ff_url_split(char *proto, int proto_size,
                   char *authorization, int authorization_size,
                   char *hostname, int hostname_size,
@@ -3457,6 +3458,22 @@ void ff_url_split(char *proto, int proto_size,
                   char *path, int path_size,
                   const char *url)
 {
+    av_url_split(proto, proto_size,
+                 authorization, authorization_size,
+                 hostname, hostname_size,
+                 port_ptr,
+                 path, path_size,
+                 url);
+}
+#endif
+
+void av_url_split(char *proto, int proto_size,
+                  char *authorization, int authorization_size,
+                  char *hostname, int hostname_size,
+                  int *port_ptr,
+                  char *path, int path_size,
+                  const char *url)
+{
     const char *p, *ls, *at, *col, *brk;
 
     if (port_ptr)               *port_ptr = -1;
@@ -3547,9 +3564,9 @@ void av_set_pts_info(AVStream *s, int pts_wrap_bits,
         s->time_base.num= s->time_base.den= 0;
 }
 
-int ff_url_join(char *str, int size, const char *proto,
-                const char *authorization, const char *hostname,
-                int port, const char *fmt, ...)
+static int av_url_vjoin(char *str, int size, const char *proto,
+                        const char *authorization, const char *hostname,
+                        int port, const char *fmt, va_list vl)
 {
 #if CONFIG_NETWORK
     struct addrinfo hints, *ai;
@@ -3582,12 +3599,9 @@ int ff_url_join(char *str, int size, const char *proto,
     if (port >= 0)
         av_strlcatf(str, size, ":%d", port);
     if (fmt) {
-        va_list vl;
         int len = strlen(str);
 
-        va_start(vl, fmt);
         vsnprintf(str + len, size > len ? size - len : 0, fmt, vl);
-        va_end(vl);
     }
     return strlen(str);
 }
@@ -3610,3 +3624,25 @@ int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
     return av_write_frame(dst, &local_pkt);
 }
 
+int av_url_join(char *str, int size, const char *proto,
+                const char *authorization, const char *hostname,
+                int port, const char *fmt, ...)
+{
+    va_list vl;
+    va_start(vl, fmt);
+    return av_url_vjoin(str, size, proto, authorization, hostname, port, fmt, vl);
+    va_end(vl);
+}
+
+#if LIBAVFORMAT_VERSION_MAJOR < 53
+int ff_url_join(char *str, int size, const char *proto,
+                const char *authorization, const char *hostname,
+                int port, const char *fmt, ...)
+{
+    va_list vl;
+    va_start(vl, fmt);
+    return av_url_vjoin(str, size, proto, authorization, hostname, port, fmt, vl);
+    va_end(vl);
+}
+#endif
+
-- 
1.7.1




More information about the ffmpeg-devel mailing list