From 6f933bdb978f19b910b057a688e2795177bffb0a Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 7 May 2015 12:02:49 +0200 Subject: [PATCH 1/3] Fixed live pushing when more than 2 tracks present. --- src/input/input_buffer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/input/input_buffer.cpp b/src/input/input_buffer.cpp index bc357bab..6abc42c4 100644 --- a/src/input/input_buffer.cpp +++ b/src/input/input_buffer.cpp @@ -328,7 +328,9 @@ namespace Mist { metaPages[value].master = true; metaPages.erase(value); - int finalMap = (trackMeta.tracks.find(value)->second.type == "video" ? 1 : 2); + int finalMap = 3; + if (trackMeta.tracks.find(value)->second.type == "video"){finalMap = 1;} + if (trackMeta.tracks.find(value)->second.type == "audio"){finalMap = 2;} //Resume either if we have more than 1 keyframe on the replacement track (assume it was already pushing before the track "dissapeared") //or if the firstms of the replacement track is later than the lastms on the existing track if (!myMeta.tracks.count(finalMap) || trackMeta.tracks.find(value)->second.keys.size() > 1 || trackMeta.tracks.find(value)->second.firstms >= myMeta.tracks[finalMap].lastms) { From ccaec3d2f8e1eab92f629e9a6ac11c5960ed52e5 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 7 May 2015 19:00:01 +0200 Subject: [PATCH 2/3] Fixed live stream memory leak in Windows builds --- src/io.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/io.cpp b/src/io.cpp index 11f5ae95..94c84dd9 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -259,18 +259,34 @@ namespace Mist { //Keep track of registering the page on the track's index page bool inserted = false; + int lowest = 0; for (int i = 0; i < 1024; i++) { int * tmpOffset = (int *)(metaPages[tid].mapped + (i * 8)); int keyNum = ntohl(tmpOffset[0]); + if (!keyNum) continue; + if (!lowest || keyNum < lowest){ + lowest = keyNum; + } int keyAmount = ntohl(tmpOffset[1]); - if (keyNum == curPageNum[tid]){ + if (!inserted && keyNum == curPageNum[tid]){ if (keyAmount == 1000){ tmpOffset[1] = htonl(pagesByTrack[tid][curPageNum[tid]].keyNum); } inserted = true; - break; } } + +#if defined(__CYGWIN__) || defined(_WIN32) + static int wipedAlready = 0; + if (lowest && lowest > wipedAlready + 1){ + for (int curr = wipedAlready + 1; curr < lowest; ++curr){ + char pageId[NAME_BUFFER_SIZE]; + snprintf(pageId, NAME_BUFFER_SIZE, SHM_TRACK_DATA, streamName.c_str(), mapTid, curr); + IPC::releasePage(std::string(pageId)); + } + } +#endif + //Print a message about registering the page or not. if (!inserted) { INFO_MSG("Can't register page %lu on the metaPage of track %lu~>%lu, No empty spots left within 'should be' amount of slots", curPageNum[tid], tid, mapTid); From 2845cbedcb6bc15c052833f24b391ccdf385d82e Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 11 May 2015 19:11:00 +0200 Subject: [PATCH 3/3] More fixes to Windows live metadata handling. --- src/io.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/io.cpp b/src/io.cpp index 94c84dd9..b1934d87 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -466,6 +466,9 @@ namespace Mist { trackState[tid] = FILL_NEW; return; } + #if defined(__CYGWIN__) || defined(_WIN32) + static std::map preservedTempMetas; + #endif switch (trackState[tid]) { case FILL_NEW: { unsigned long newTid = ((long)(tmp[offset]) << 24) | ((long)(tmp[offset + 1]) << 16) | ((long)(tmp[offset + 2]) << 8) | tmp[offset + 3]; @@ -488,6 +491,10 @@ namespace Mist { memcpy(metaPages[tid].mapped, tmpStr.data(), tmpStr.size()); INFO_MSG("Temporary metadata written for incoming track %lu, handling as track %lu", tid, newTid); //Not actually removing the page, because we set master to false + #if defined(__CYGWIN__) || defined(_WIN32) + IPC::preservePage(pageName); + preservedTempMetas[tid] = pageName; + #endif metaPages.erase(tid); trackState[tid] = FILL_NEG; trackMap[tid] = newTid; @@ -500,6 +507,10 @@ namespace Mist { INFO_MSG("Negotiating, but firstPage not yet set, waiting for buffer"); break; } + #if defined(__CYGWIN__) || defined(_WIN32) + IPC::releasePage(preservedTempMetas[tid]); + preservedTempMetas.erase(tid); + #endif if (finalTid == 0xFFFFFFFF) { WARN_MSG("Buffer has declined incoming track %lu", tid); memset(tmp + offset, 0, 6);