[FFmpeg-devel] [PATCH 1/4] URLContext: introduce a slave URLContext.

Nicolas George nicolas.george
Fri Feb 18 18:59:20 CET 2011


A lot of protocols rely on an underlying, lower-level protocol connection to
do their work, for example HTTP relies on TCP. This connection is usually
stored as a field in the private protocol context. Making part of the common
context allows to automatically forward functions like url_get_file_handle.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavformat/avio.c |    2 ++
 libavformat/avio.h |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index a19ec37..4d2848a 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -313,6 +313,8 @@ int64_t url_filesize(URLContext *h)
 
 int url_get_file_handle(URLContext *h)
 {
+    while (!h->prot->url_get_file_handle && h->slave)
+        h = h->slave;
     if (!h->prot->url_get_file_handle)
         return -1;
     return h->prot->url_get_file_handle(h);
diff --git a/libavformat/avio.h b/libavformat/avio.h
index c899c0d..2faf5b4 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -55,6 +55,12 @@ typedef struct URLContext {
     void *priv_data;
     char *filename; /**< specified URL */
     int is_connected;
+    /**
+     * Underlying, lower-level protocol connection.
+     * Some operations, like url_get_file_handle, will be automatically be
+     * forwarded to it.
+     */
+    struct URLContext *slave;
 } URLContext;
 
 typedef struct URLPollEntry {
-- 
1.7.2.3




More information about the ffmpeg-devel mailing list