This mail starts a serie of patches that at the end will allow accepting
multiple connections to only one AVIOContext generating a new AVIOContext to
 control the new connection.

The motivation for these patches is allowing a server to use any/some of the
possibilities offered by libavformat providing AVIOContext to any demuxer.

---
 libavformat/avio.h    |   11 +++++++++++
 libavformat/aviobuf.c |   29 +++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/libavformat/avio.h b/libavformat/avio.h
index 10c0a12..703b913 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -346,6 +346,17 @@ int avio_open2(AVIOContext **s, const char *url, int flags,
                const AVIOInterruptCB *int_cb, AVDictionary **options);
 
 /**
+ * Use an initialized AVIOContext to accept an incomming new connection
+ * and produce an AVIOContext with the new connection.
+ *
+ * @param s Initialised context capable of receiving new connections
+ * @param c Used to return the pointer to the creadted AVIOContext
+ * @return 0 in case of success, a negative value corresponding to an
+ * AVERROR code in case of failure
+ */
+int avio_accept(AVIOContext *s, AVIOContext **c, int timeout);
+
+/**
  * Close the resource accessed by the AVIOContext s and free it.
  * This function can only be used if s was opened by avio_open().
  *
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 0353a17..dbf13ce 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -754,6 +754,35 @@ int avio_open2(AVIOContext **s, const char *filename, int 
flags,
     return 0;
 }
 
+int avio_accept(AVIOContext *srvavio, AVIOContext **clntavio, int timeout) {
+    URLContext *srvctx = srvavio->opaque;
+    URLContext *clientctx = NULL;
+    int ret;
+    if (!srvctx) {
+        av_log(srvavio, AV_LOG_ERROR, "avio_accept. No allocated context\n");
+        return AVERROR_BUG;
+    }
+    if (!srvctx->prot->url_accept) {
+        av_log(srvavio, AV_LOG_ERROR, "Protocol %s does not support accept\n",
+            srvctx->prot->name);
+        return AVERROR_BUG;
+    }
+    if (ret = srvctx->prot->url_accept(srvctx, &clientctx,
+                                    timeout)) {
+        av_log(srvavio, AV_LOG_ERROR, "Error on Accept\n");
+        return ret;
+    }
+    if (!clientctx) // url_accept timed out
+        return 0;
+    if (ret = ffio_fdopen(clntavio, clientctx)) {
+        av_log(srvavio, AV_LOG_ERROR, "Unable to open accept client"
+               " context\n");
+        return ret;
+    }
+
+    return 0;
+}
+
 int avio_close(AVIOContext *s)
 {
     URLContext *h;
-- 
1.7.10.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to