From 1e6143bc88ec6f81e7c76295647ff4377329b82c Mon Sep 17 00:00:00 2001
From: Thulinma <jaron@vietors.com>
Date: Fri, 11 Feb 2022 17:53:59 +0100
Subject: [PATCH] Further fixes to WS/MP4 (implemented "auto" track,
 implemented dropping video voluntarily)

---
 src/output/output_mp4.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/output/output_mp4.cpp b/src/output/output_mp4.cpp
index 822aa81b..3f8a0611 100644
--- a/src/output/output_mp4.cpp
+++ b/src/output/output_mp4.cpp
@@ -1506,14 +1506,14 @@ namespace Mist{
       webSock->sendFrame("{\"type\":\"pause\",\"paused\":true}");
     }else if (command["type"] == "tracks") {
       if (command.isMember("audio")){
-        if (!command["audio"].isNull()){
+        if (!command["audio"].isNull() && command["audio"] != "auto"){
           targetParams["audio"] = command["audio"].asString();
         }else{
           targetParams.erase("audio");
         }
       }
       if (command.isMember("video")){
-        if (!command["video"].isNull()){
+        if (!command["video"].isNull() && command["video"] != "auto"){
           targetParams["video"] = command["video"].asString();
         }else{
           targetParams.erase("video");
@@ -1552,8 +1552,12 @@ namespace Mist{
       return false;
     }
     if (seekTarget != currentTime()){prevVidTrack = INVALID_TRACK_ID;}
+    bool hasVideo = false;
+    for (std::map<size_t, Comms::Users>::iterator it = userSelect.begin(); it != userSelect.end(); it++){
+      if (M.getType(it->first) == "video"){hasVideo = true;}
+    }
     // Add the previous video track back, if we had one.
-    if (prevVidTrack != INVALID_TRACK_ID && !userSelect.count(prevVidTrack)){
+    if (prevVidTrack != INVALID_TRACK_ID && !userSelect.count(prevVidTrack) && hasVideo){
       userSelect[prevVidTrack].reload(streamName, prevVidTrack);
       seek(seekTarget);
       std::set<size_t> newSelTracks;