From 9ddfa9714866e558129c7b9c4d5a8411bcdf4f0d Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sat, 15 Apr 2017 13:30:14 +0200 Subject: [PATCH] Added automatic User-Agent stream tagging --- src/output/output.cpp | 12 ++++++++++++ src/output/output.h | 2 ++ src/output/output_dash_mp4.cpp | 5 ++++- src/output/output_hds.cpp | 2 ++ src/output/output_hls.cpp | 1 + src/output/output_hss.cpp | 5 ++++- src/output/output_http.cpp | 7 +++++-- src/output/output_rtmp.cpp | 3 +++ 8 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/output/output.cpp b/src/output/output.cpp index 04917cb2..3db1f7d7 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -67,6 +67,7 @@ namespace Mist{ lastStats = 0; maxSkipAhead = 7500; minSkipAhead = 5000; + uaDelay = 10; realTime = 1000; lastRecv = Util::epoch(); if (myConn){ @@ -1207,6 +1208,17 @@ namespace Mist{ }else{ tmpEx.lastSecond(0); } + /*LTS-START*/ + //Tag the session with the user agent + static bool newUA = true;//we only do this once per connection + if (newUA && ((now - myConn.connTime()) >= uaDelay || !myConn) && UA.size()){ + std::string APIcall = "{\"tag_sessid\":{\"" + tmpEx.getSessId() + "\":" + JSON::string_escape("UA:"+UA) + "}}"; + Socket::UDPConnection uSock; + uSock.SetDestination("localhost", 4242); + uSock.SendNow(APIcall); + newUA = false; + } + /*LTS-END*/ statsPage.keepAlive(); } doSync(); diff --git a/src/output/output.h b/src/output/output.h index ff249a4b..7454fa84 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -100,6 +100,8 @@ namespace Mist { bool sought;/// namespace Mist { - OutDashMP4::OutDashMP4(Socket::Connection & conn) : HTTPOutput(conn){realTime = 0;} + OutDashMP4::OutDashMP4(Socket::Connection & conn) : HTTPOutput(conn){ + uaDelay = 0; + realTime = 0; + } OutDashMP4::~OutDashMP4(){} std::string OutDashMP4::makeTime(uint64_t time){ diff --git a/src/output/output_hds.cpp b/src/output/output_hds.cpp index 66377080..3ce0d9e6 100644 --- a/src/output/output_hds.cpp +++ b/src/output/output_hds.cpp @@ -131,6 +131,8 @@ namespace Mist { } //BuildManifest OutHDS::OutHDS(Socket::Connection & conn) : HTTPOutput(conn) { + uaDelay = 0; + realTime = 0; audioTrack = 0; playUntil = 0; } diff --git a/src/output/output_hls.cpp b/src/output/output_hls.cpp index c18865e4..99f1f1f2 100644 --- a/src/output/output_hls.cpp +++ b/src/output/output_hls.cpp @@ -258,6 +258,7 @@ namespace Mist { OutHLS::OutHLS(Socket::Connection & conn) : TSOutput(conn) { + uaDelay = 0; realTime = 0; until=0xFFFFFFFFFFFFFFFFull; } diff --git a/src/output/output_hss.cpp b/src/output/output_hss.cpp index 01f51672..96a6b0b5 100644 --- a/src/output/output_hss.cpp +++ b/src/output/output_hss.cpp @@ -46,7 +46,10 @@ std::string toUTF16(std::string original) { namespace Mist { - OutHSS::OutHSS(Socket::Connection & conn) : HTTPOutput(conn){realTime = 0;} + OutHSS::OutHSS(Socket::Connection & conn) : HTTPOutput(conn){ + uaDelay = 0; + realTime = 0; + } OutHSS::~OutHSS(){} void OutHSS::init(Util::Config * cfg) { diff --git a/src/output/output_http.cpp b/src/output/output_http.cpp index aa8d62a6..4c4ca5a4 100644 --- a/src/output/output_http.cpp +++ b/src/output/output_http.cpp @@ -213,6 +213,9 @@ namespace Mist { void HTTPOutput::onRequest(){ while (H.Read(myConn)){ + if (H.hasHeader("User-Agent")){ + UA = H.GetHeader("User-Agent"); + } if (hasSessionIDs()){ if (H.GetVar("sessId").size()){ std::string ua = H.GetVar("sessId"); @@ -222,8 +225,8 @@ namespace Mist { crc = checksum::crc32(0, ua.data(), ua.size()); } }else{ - std::string ua = H.GetHeader("User-Agent") + H.GetHeader("X-Playback-Session-Id"); - crc = checksum::crc32(0, ua.data(), ua.size()); + std::string mixed_ua = UA + H.GetHeader("X-Playback-Session-Id"); + crc = checksum::crc32(0, mixed_ua.data(), mixed_ua.size()); } INFO_MSG("Received request %s", H.getUrl().c_str()); diff --git a/src/output/output_rtmp.cpp b/src/output/output_rtmp.cpp index 563044e9..f66d6c18 100644 --- a/src/output/output_rtmp.cpp +++ b/src/output/output_rtmp.cpp @@ -597,6 +597,9 @@ namespace Mist { if (amfData.getContentP(2)->getContentP("objectEncoding")) { objencoding = amfData.getContentP(2)->getContentP("objectEncoding")->NumValue(); } + if (amfData.getContentP(2)->getContentP("flashVer")) { + UA = amfData.getContentP(2)->getContentP("flashVer")->StrValue(); + } app_name = amfData.getContentP(2)->getContentP("tcUrl")->StrValue(); reqUrl = app_name;//LTS app_name = app_name.substr(app_name.find('/', 7) + 1);