From 87e2c774fddf1018124de9234e92ad2a056e22d8 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 13 Apr 2016 16:16:56 +0200 Subject: [PATCH] Added RTMP unescaping code to fix Xsplit support for wildcard streams. --- src/output/output_rtmp.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/output/output_rtmp.cpp b/src/output/output_rtmp.cpp index cc223245..8b90000f 100644 --- a/src/output/output_rtmp.cpp +++ b/src/output/output_rtmp.cpp @@ -37,6 +37,39 @@ namespace Mist { OutRTMP::~OutRTMP() {} + + /// Helper function for urlunescape. + /// Takes a single char input and outputs its integer hex value. + int unhex(char c) { + return (c >= '0' && c <= '9' ? c - '0' : c >= 'A' && c <= 'F' ? c - 'A' + 10 : c - 'a' + 10); + } + + /// Unescapes URLencoded std::string data. + std::string urlunescape(const std::string & in) { + std::string out; + for (unsigned int i = 0; i < in.length(); ++i) { + if (in[i] == '%') { + char tmp = 0; + ++i; + if (i < in.length()) { + tmp = unhex(in[i]) << 4; + } + ++i; + if (i < in.length()) { + tmp += unhex(in[i]); + } + out += tmp; + } else { + if (in[i] == '+') { + out += ' '; + } else { + out += in[i]; + } + } + } + return out; + } + void OutRTMP::parseVars(std::string data){ std::string varname; std::string varval; @@ -613,7 +646,7 @@ namespace Mist { int playTransaction = amfData.getContentP(1)->NumValue(); int playMessageType = messageType; int playStreamId = streamId; - streamName = amfData.getContentP(3)->StrValue(); + streamName = urlunescape(amfData.getContentP(3)->StrValue()); reqUrl += "/"+streamName;//LTS //handle variables