From 267a74f0f6d44b928b99312b356a3080579fdc1c Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 4 Aug 2022 16:43:04 +0200 Subject: [PATCH] Fix track selector logic when multiple selections are considered --- lib/stream.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/stream.cpp b/lib/stream.cpp index 6036a8fd..715015d6 100644 --- a/lib/stream.cpp +++ b/lib/stream.cpp @@ -1249,7 +1249,7 @@ std::set Util::wouldSelect(const DTSC::Meta &M, const std::map result; /*LTS-START*/ - bool noSelAudio = false, noSelVideo = false, noSelSub = false; + bool noSelAudio = false, noSelVideo = false, noSelSub = false, noSelMeta = false; // Then, select the tracks we've been asked to select. if (targetParams.count("audio") && targetParams.at("audio").size()){ if (targetParams.at("audio") != "-1" && targetParams.at("audio") != "none"){ @@ -1270,6 +1270,11 @@ std::set Util::wouldSelect(const DTSC::Meta &M, const std::map tracks = Util::findTracks(M, capa, "meta", targetParams.at("meta"), UA); + result.insert(tracks.begin(), tracks.end()); + noSelMeta = true; + } /*LTS-END*/ std::set validTracks = M.getValidTracks(); @@ -1291,6 +1296,7 @@ std::set Util::wouldSelect(const DTSC::Meta &M, const std::map Util::wouldSelect(const DTSC::Meta &M, const std::map Util::wouldSelect(const DTSC::Meta &M, const std::map 0){ jsonForEachConst((*it), itb){ if ((*itb).size() > 0){ @@ -1360,6 +1368,26 @@ std::set Util::wouldSelect(const DTSC::Meta &M, const std::map::iterator itd = validTracks.begin(); itd != validTracks.end(); itd++){ + if ((!byType && M.getCodec(*itd) == strRef.substr(shift)) || + (byType && M.getType(*itd) == strRef.substr(shift)) || strRef.substr(shift) == "*"){ + // user-agent-check + bool problems = false; + if (capa.isMember("exceptions") && capa["exceptions"].isObject() && + capa["exceptions"].size()){ + jsonForEachConst(capa["exceptions"], ex){ + if (ex.key() == "codec:" + strRef.substr(shift)){ + problems = !Util::checkException(*ex, UA); + break; + } + } + } + if (problems){break;} + extraCounter++; if (!multiSel){break;} } } @@ -1367,8 +1395,9 @@ std::set Util::wouldSelect(const DTSC::Meta &M, const std::map bestSoFarCount){ + if (selCounter > bestSoFarCount || (selCounter == bestSoFarCount && extraCounter > bestSoFarCountExtra)){ bestSoFarCount = selCounter; + bestSoFarCountExtra = extraCounter; bestSoFar = index; HIGH_MSG("Matched %u: %s", selCounter, (*it).toString().c_str()); }