From c0e7df75b1d76e0b315cc74027b68a3696fe016c Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 11 Mar 2018 14:11:41 +0100 Subject: Fix invalid arg_verbose pointer for VLC arguments --- src/VLCInput.cpp | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp index 6519d49..fac734e 100644 --- a/src/VLCInput.cpp +++ b/src/VLCInput.cpp @@ -182,50 +182,37 @@ void VLCInput::prepare() prepareRender_address, (long long int)(intptr_t)this); -#define VLC_ARGS_LEN 32 - const char* vlc_args[VLC_ARGS_LEN]; - size_t arg_ix = 0; - std::stringstream arg_verbose; - arg_verbose << "--verbose=" << m_verbosity; - vlc_args[arg_ix++] = arg_verbose.str().c_str(); - - std::string arg_network_caching; + vector vlc_args; + vlc_args.push_back("--verbose=" + to_string(m_verbosity)); + if (not m_cache.empty()) { - stringstream ss; - ss << "--network-caching=" << m_cache; - arg_network_caching = ss.str(); - vlc_args[arg_ix++] = arg_network_caching.c_str(); + vlc_args.push_back("--network-caching=" + m_cache); } - std::string arg_gain; if (not m_gain.empty()) { - stringstream ss; - ss << "--compressor-makeup=" << m_gain; - arg_gain = ss.str(); - vlc_args[arg_ix++] = arg_gain.c_str(); + vlc_args.push_back("--compressor-makeup=" + m_gain); } - vlc_args[arg_ix++] = "--sout"; - vlc_args[arg_ix++] = smem_options; // Stream to memory + vlc_args.push_back("--sout"); + vlc_args.push_back(smem_options); // Stream to memory - for (const auto& opt : m_additional_opts) { - if (arg_ix < VLC_ARGS_LEN) { - vlc_args[arg_ix++] = opt.c_str(); - } - else { - throw runtime_error("Too many VLC options given"); - } - } + copy(m_additional_opts.begin(), m_additional_opts.end(), + back_inserter(vlc_args)); if (m_verbosity) { fprintf(stderr, "Initialising VLC with options:\n"); - for (size_t i = 0; i < arg_ix; i++) { - fprintf(stderr, " %s\n", vlc_args[i]); + for (const auto& arg : vlc_args) { + fprintf(stderr, " %s\n", arg.c_str()); } } // Launch VLC - m_vlc = libvlc_new(arg_ix, vlc_args); + vector vlc_args_c; + for (const auto& arg : vlc_args) { + vlc_args_c.push_back(arg.c_str()); + } + + m_vlc = libvlc_new(vlc_args_c.size(), vlc_args_c.data()); if (m_vlc == nullptr) { throw runtime_error("VLC initialisation failed"); -- cgit v1.2.3