[vlc-commits] http-put: access output module using HTTP PUT (fixes #20000)

Rémi Denis-Courmont git at videolan.org
Sun Oct 4 16:19:26 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Oct  4 17:14:25 2020 +0300| [5b780b313ef34dffe2404cf47a2d2331c9593555] | committer: Rémi Denis-Courmont

http-put: access output module using HTTP PUT (fixes #20000)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5b780b313ef34dffe2404cf47a2d2331c9593555
---

 NEWS                              |   1 +
 modules/access_output/Makefile.am |   5 ++
 modules/access_output/http-put.c  | 135 ++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                    |   1 +
 4 files changed, 142 insertions(+)

diff --git a/NEWS b/NEWS
index 7eb1a72567..d2ddb1651a 100644
--- a/NEWS
+++ b/NEWS
@@ -69,6 +69,7 @@ Access:
 
 Access output:
  * Added support for the RIST (Reliable Internet Stream Transport) Protocol
+ * Added support for HTTP PUT (HTTP upload)
 
 Video output:
  * Added X11 RENDER video output plugin
diff --git a/modules/access_output/Makefile.am b/modules/access_output/Makefile.am
index f6f78c0b73..5a6e82d80f 100644
--- a/modules/access_output/Makefile.am
+++ b/modules/access_output/Makefile.am
@@ -26,6 +26,11 @@ libaccess_output_shout_plugin_la_LIBADD = $(SHOUT_LIBS) $(SOCKET_LIBS)
 access_out_LTLIBRARIES += $(LTLIBaccess_output_shout)
 EXTRA_LTLIBRARIES += libaccess_output_shout_plugin.la
 
+libaccess_http_put_plugin_la_SOURCES = access_output/http-put.c
+libaccess_http_put_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/access/http
+libaccess_http_put_plugin_la_LIBADD = libvlc_http.la
+access_out_LTLIBRARIES += libaccess_http_put_plugin.la
+
 ### SRT ###
 libaccess_output_srt_plugin_la_SOURCES = access_output/srt.c access/srt_common.c access/srt_common.h dummy.cpp
 libaccess_output_srt_plugin_la_CFLAGS = $(AM_CFLAGS) $(SRT_CFLAGS)
diff --git a/modules/access_output/http-put.c b/modules/access_output/http-put.c
new file mode 100644
index 0000000000..872efe5f2d
--- /dev/null
+++ b/modules/access_output/http-put.c
@@ -0,0 +1,135 @@
+/*****************************************************************************
+ * http-put.c
+ *****************************************************************************
+ * Copyright (C) 2020 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_sout.h>
+#include <vlc_block.h>
+#include <vlc_strings.h>
+#include "connmgr.h"
+#include "outfile.h"
+
+#define SOUT_CFG_PREFIX "sout-http-put-"
+
+struct sout_http_put {
+    struct vlc_http_mgr *manager;
+    struct vlc_http_outfile *file;
+};
+
+static ssize_t Write(sout_access_out_t *access, block_t *block)
+{
+    struct sout_http_put *sys = access->p_sys;
+
+    return vlc_http_outfile_write(sys->file, block);
+}
+
+static int Control(sout_access_out_t *access, int query, va_list args)
+{
+    (void) access;
+
+    switch (query)
+    {
+        case ACCESS_OUT_CONTROLS_PACE:
+            *va_arg(args, bool *) = true;
+            break;
+
+        case ACCESS_OUT_CAN_SEEK:
+            *va_arg(args, bool *) = false;
+            break;
+
+        default:
+            return VLC_EGENERIC;
+    }
+
+    return VLC_SUCCESS;
+}
+
+static const char *const sout_options[] = {
+    "user", "pwd", NULL
+};
+
+static int Open(vlc_object_t *obj)
+{
+    sout_access_out_t *access = (sout_access_out_t *)obj;
+
+    struct sout_http_put *sys = vlc_obj_malloc(obj, sizeof (*sys));
+    if (unlikely(sys == NULL))
+        return VLC_ENOMEM;
+
+    sys->manager = vlc_http_mgr_create(obj, NULL);
+    if (sys->manager == NULL)
+        return VLC_ENOMEM;
+
+    config_ChainParse(obj, SOUT_CFG_PREFIX, sout_options, access->p_cfg);
+
+    char *ua = var_InheritString(obj, "http-user-agent");
+    char *user = var_GetString(obj, SOUT_CFG_PREFIX"user");
+    char *pwd = var_GetString(obj, SOUT_CFG_PREFIX"pwd");
+
+    /* XXX: Empty user / password strings are not the same as NULL. No ways to
+     * distinguish with the VLC APIs.
+     */
+
+    sys->file = vlc_http_outfile_create(sys->manager, access->psz_path, ua,
+                                        user, pwd);
+    free(pwd);
+    free(user);
+    free(ua);
+
+    if (sys->file == NULL) {
+        msg_Err(obj, "cannot create HTTP resource %s", access->psz_path);
+        vlc_http_mgr_destroy(sys->manager);
+        return VLC_EGENERIC;
+    }
+
+    access->p_sys = sys;
+    access->pf_write = Write;
+    access->pf_control = Control;
+
+    return VLC_SUCCESS;
+}
+
+static void Close(vlc_object_t *obj)
+{
+    sout_access_out_t *access = (sout_access_out_t *)obj;
+    struct sout_http_put *sys = access->p_sys;
+
+    if (vlc_http_outfile_close(sys->file))
+        msg_Err(obj, "server error while writing file");
+
+    vlc_http_mgr_destroy(sys->manager);
+}
+
+vlc_module_begin()
+    set_description(N_("HTTP PUT stream output"))
+    set_shortname(N_("HTTP PUT"))
+    set_capability("sout access", 0)
+    set_category(CAT_SOUT)
+    set_subcategory(SUBCAT_SOUT_ACO)
+    add_shortcut("http-put")
+    add_string(SOUT_CFG_PREFIX"user", NULL, N_("Username"), N_("Username"),
+               true)
+    add_password(SOUT_CFG_PREFIX"pwd", NULL, N_("Password"), N_("Password"))
+    set_callbacks(Open, Close)
+vlc_module_end()
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6ed746ad46..de3ce1fb6e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -215,6 +215,7 @@ modules/access/wasapi.c
 modules/access_output/dummy.c
 modules/access_output/file.c
 modules/access_output/http.c
+modules/access_output/http-put.c
 modules/access_output/livehttp.c
 modules/access_output/rist.c
 modules/access_output/shout.c



More information about the vlc-commits mailing list