From 43e82f8c875f3544327c265a8b59e8a4ab5f074d Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 14 Mar 2017 10:11:56 +0100 Subject: [PATCH] Fix for Windows semaphore problem in live streams --- src/input/input_buffer.cpp | 31 ++++++++++++++++--------------- src/input/input_buffer.h | 1 + 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/input/input_buffer.cpp b/src/input/input_buffer.cpp index c70e83f2..1d71d224 100644 --- a/src/input/input_buffer.cpp +++ b/src/input/input_buffer.cpp @@ -18,6 +18,7 @@ namespace Mist { inputBuffer::inputBuffer(Util::Config * cfg) : Input(cfg) { + liveMeta = 0; capa["name"] = "Buffer"; JSON::Value option; option["arg"] = "integer"; @@ -95,10 +96,11 @@ namespace Mist { } } } - char pageName[NAME_BUFFER_SIZE]; - snprintf(pageName, NAME_BUFFER_SIZE, SEM_LIVE, streamName.c_str()); - IPC::semaphore liveMeta(pageName, O_CREAT | O_RDWR, ACCESSPERMS, 1); - liveMeta.unlink(); + if (liveMeta){ + liveMeta->unlink(); + delete liveMeta; + liveMeta = 0; + } } @@ -120,13 +122,9 @@ namespace Mist { memset(tmp.mapped, 0xFF, size); } } - + //Delete the live stream semaphore, if any. + if (liveMeta){liveMeta->unlink();} { - //Delete the live stream semaphore, if any. - snprintf(pageName, NAME_BUFFER_SIZE, SEM_LIVE, streamName.c_str()); - IPC::semaphore liveMeta(pageName, O_CREAT | O_RDWR, ACCESSPERMS, 1); - liveMeta.unlink(); - }{ //Delete the stream index metapage. snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_INDEX, streamName.c_str()); IPC::sharedPage erasePage(pageName, DEFAULT_STRM_PAGE_SIZE, false, false); @@ -192,10 +190,13 @@ namespace Mist { myMeta.bufferWindow = lastms - firstms; myMeta.vod = false; myMeta.live = true; - static char liveSemName[NAME_BUFFER_SIZE]; - snprintf(liveSemName, NAME_BUFFER_SIZE, SEM_LIVE, streamName.c_str()); - IPC::semaphore liveMeta(liveSemName, O_CREAT | O_RDWR, ACCESSPERMS, 1); - liveMeta.wait(); + if (!liveMeta){ + static char liveSemName[NAME_BUFFER_SIZE]; + snprintf(liveSemName, NAME_BUFFER_SIZE, SEM_LIVE, streamName.c_str()); + liveMeta = new IPC::semaphore(liveSemName, O_CREAT | O_RDWR, ACCESSPERMS, 1); + } + liveMeta->wait(); + if (!nProxy.metaPages.count(0) || !nProxy.metaPages[0].mapped) { char pageName[NAME_BUFFER_SIZE]; snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_INDEX, streamName.c_str()); @@ -204,7 +205,7 @@ namespace Mist { } myMeta.writeTo(nProxy.metaPages[0].mapped); memset(nProxy.metaPages[0].mapped + myMeta.getSendLen(), 0, (nProxy.metaPages[0].len > myMeta.getSendLen() ? std::min(nProxy.metaPages[0].len - myMeta.getSendLen(), 4ll) : 0)); - liveMeta.post(); + liveMeta->post(); } ///Checks if removing a key from this track is allowed/safe, and if so, removes it. diff --git a/src/input/input_buffer.h b/src/input/input_buffer.h index 914cc14c..21ff4446 100644 --- a/src/input/input_buffer.h +++ b/src/input/input_buffer.h @@ -13,6 +13,7 @@ namespace Mist { unsigned int cutTime; bool hasPush; bool resumeMode; + IPC::semaphore * liveMeta; protected: //Private Functions bool setup();