Edits to accomodate with abstracted semaphore class
This commit is contained in:
parent
ee93e80b8d
commit
10ce807f6f
5 changed files with 80 additions and 54 deletions
|
@ -114,7 +114,11 @@ namespace Mist {
|
|||
}else{
|
||||
//after this player functionality
|
||||
|
||||
metaPage.init(config->getString("streamname"), (isBuffer ? 8388608 : myMeta.getSendLen()), true);
|
||||
#ifdef __CYGWIN__
|
||||
metaPage.init(config->getString("streamname"), 8 * 1024 * 1024, true);
|
||||
#else
|
||||
metaPage.init(config->getString("streamname"), (isBuffer ? 8 * 1024 * 1024 : myMeta.getSendLen()), true);
|
||||
#endif
|
||||
myMeta.writeTo(metaPage.mapped);
|
||||
userPage.init(config->getString("streamname") + "_users", 30, true);
|
||||
|
||||
|
@ -125,13 +129,13 @@ namespace Mist {
|
|||
}
|
||||
}
|
||||
|
||||
sem_t * waiting = sem_open(std::string("/wait_" + config->getString("streamname")).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 0);
|
||||
if (waiting == SEM_FAILED){
|
||||
IPC::semaphore waiting(std::string("/wait_" + config->getString("streamname")).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 0);
|
||||
if (!waiting){
|
||||
DEBUG_MSG(DLVL_FAIL, "Failed to open semaphore - cancelling");
|
||||
return -1;
|
||||
}
|
||||
sem_post(waiting);
|
||||
sem_close(waiting);
|
||||
waiting.post();
|
||||
waiting.close();
|
||||
|
||||
DEBUG_MSG(DLVL_HIGH,"Pre-While");
|
||||
|
||||
|
@ -213,10 +217,10 @@ namespace Mist {
|
|||
|
||||
char tmpId[20];
|
||||
sprintf(tmpId, "%d", tid);
|
||||
indexPages[tid].init(config->getString("streamname") + tmpId, 8192, true);//Pages of 8kb in size, room for 512 parts.
|
||||
indexPages[tid].init(config->getString("streamname") + tmpId, 8 * 1024, true);//Pages of 8kb in size, room for 512 parts.
|
||||
}
|
||||
if (myMeta.tracks[tid].keys[bookKeeping[tid].curKey].getParts() == curData[tid].partNum){
|
||||
if (curData[tid].dataSize > 8388608) {
|
||||
if (curData[tid].dataSize > 8 * 1024 * 1024) {
|
||||
pagesByTrack[tid][bookKeeping[tid].first] = curData[tid];
|
||||
bookKeeping[tid].first += curData[tid].keyNum;
|
||||
curData[tid].keyNum = 0;
|
||||
|
@ -267,7 +271,11 @@ namespace Mist {
|
|||
char pageId[100];
|
||||
int pageIdLen = sprintf(pageId, "%s%d_%d", config->getString("streamname").c_str(), track, pageNum);
|
||||
std::string tmpString(pageId, pageIdLen);
|
||||
#ifdef __CYGWIN__
|
||||
dataPages[track][pageNum].init(tmpString, 26 * 1024 * 1024, true);
|
||||
#else
|
||||
dataPages[track][pageNum].init(tmpString, it->second.dataSize, true);
|
||||
#endif
|
||||
DEBUG_MSG(DLVL_DEVEL, "Buffering track %d page %d through %d", track, pageNum, pageNum-1 + it->second.keyNum);
|
||||
|
||||
std::stringstream trackSpec;
|
||||
|
|
|
@ -14,8 +14,8 @@ int main(int argc, char * argv[]) {
|
|||
Util::Config conf(argv[0], PACKAGE_VERSION);
|
||||
mistIn conv(&conf);
|
||||
if (conf.parseArgs(argc, argv)) {
|
||||
sem_t * playerLock = sem_open(std::string("/lock_" + conf.getString("streamname")).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
if (sem_trywait(playerLock) == -1){
|
||||
IPC::semaphore playerLock(std::string("/lock_" + conf.getString("streamname")).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 1);
|
||||
if (!playerLock.tryWait()){
|
||||
DEBUG_MSG(DLVL_DEVEL, "A player for stream %s is already running", conf.getString("streamname").c_str());
|
||||
return 1;
|
||||
}
|
||||
|
@ -23,30 +23,29 @@ int main(int argc, char * argv[]) {
|
|||
while (conf.is_active){
|
||||
int pid = fork();
|
||||
if (pid == 0){
|
||||
sem_close(playerLock);
|
||||
playerLock.close();
|
||||
return conv.run();
|
||||
}
|
||||
if (pid == -1){
|
||||
DEBUG_MSG(DLVL_FAIL, "Unable to spawn player process");
|
||||
sem_post(playerLock);
|
||||
playerLock.post();
|
||||
return 2;
|
||||
}
|
||||
//wait for the process to exit
|
||||
int status;
|
||||
while (waitpid(pid, &status, 0) != pid && errno == EINTR) continue;
|
||||
//clean up the semaphore by waiting for it, if it's non-zero
|
||||
sem_t * waiting = sem_open(std::string("/wait_" + conf.getString("streamname")).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 0);
|
||||
if (waiting == SEM_FAILED){
|
||||
IPC::semaphore waiting(std::string("/wait_" + conf.getString("streamname")).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 0);
|
||||
if (!waiting){
|
||||
DEBUG_MSG(DLVL_FAIL, "Failed to open semaphore - cancelling");
|
||||
return -1;
|
||||
}
|
||||
int sem_val = 0;
|
||||
sem_getvalue(waiting, &sem_val);
|
||||
int sem_val = waiting.getVal();
|
||||
while (sem_val){
|
||||
while (sem_wait(waiting) == -1 && errno == EINTR) continue;
|
||||
sem_getvalue(waiting, &sem_val);
|
||||
waiting.wait();
|
||||
sem_val = waiting.getVal();
|
||||
}
|
||||
sem_close(waiting);
|
||||
waiting.close();
|
||||
//if the exit was clean, don't restart it
|
||||
if (WIFEXITED(status) && (WEXITSTATUS(status) == 0)){
|
||||
DEBUG_MSG(DLVL_MEDIUM, "Finished player succesfully");
|
||||
|
@ -57,8 +56,8 @@ int main(int argc, char * argv[]) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
sem_post(playerLock);
|
||||
sem_close(playerLock);
|
||||
playerLock.post();
|
||||
playerLock.close();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace Mist {
|
|||
return;
|
||||
}
|
||||
isInitialized = true;
|
||||
streamIndex.init(streamName,0);
|
||||
streamIndex.init(streamName,8 * 1024 * 1024);
|
||||
if (!streamIndex.mapped){
|
||||
DEBUG_MSG(DLVL_FAIL, "Could not connect to server for %s\n", streamName.c_str());
|
||||
onFail();
|
||||
|
@ -239,7 +239,7 @@ namespace Mist {
|
|||
if (!indexPages.count(trackId)){
|
||||
char id[100];
|
||||
sprintf(id, "%s%lu", streamName.c_str(), trackId);
|
||||
indexPages[trackId].init(id, 8192);
|
||||
indexPages[trackId].init(id, 8 * 1024);
|
||||
}
|
||||
while (pageNum == -1 || keyAmount == -1){
|
||||
for (int i = 0; i < indexPages[trackId].len / 8; i++){
|
||||
|
@ -285,7 +285,7 @@ namespace Mist {
|
|||
}
|
||||
char id[100];
|
||||
sprintf(id, "%s%lu_%d", streamName.c_str(), trackId, pageNum);
|
||||
curPages[trackId].init(std::string(id),0);
|
||||
curPages[trackId].init(std::string(id),26 * 1024 * 1024);
|
||||
if (!(curPages[trackId].mapped)){
|
||||
DEBUG_MSG(DLVL_FAIL, "Initializing page %s failed", curPages[trackId].name.c_str());
|
||||
return;
|
||||
|
|
|
@ -609,7 +609,7 @@ namespace Mist {
|
|||
//open new page
|
||||
char nextPage[100];
|
||||
sprintf(nextPage, "%s%llu_%d", streamName.c_str(), tNum, bookKeeping[tNum].pageNum + bookKeeping[tNum].keyNum);
|
||||
curPages[tNum].init(nextPage, 0, false);
|
||||
curPages[tNum].init(nextPage, 26 * 1024 * 1024);
|
||||
bookKeeping[tNum].pageNum += bookKeeping[tNum].keyNum;
|
||||
bookKeeping[tNum].keyNum = 0;
|
||||
bookKeeping[tNum].curOffset = 0;
|
||||
|
@ -667,7 +667,7 @@ namespace Mist {
|
|||
for (std::map<int, int>::iterator it = trackMap.begin(); it != trackMap.end(); it++){
|
||||
char tmp[100];
|
||||
sprintf( tmp, "liveStream_%s%d", streamName.c_str(), it->second);
|
||||
metaPages[it->second].init(std::string(tmp), 0, false);
|
||||
metaPages[it->second].init(std::string(tmp), 8 * 1024 * 1024);
|
||||
DTSC::Meta tmpMeta = meta_out;
|
||||
tmpMeta.tracks.clear();
|
||||
tmpMeta.tracks[it->second] = meta_out.tracks[it->first];
|
||||
|
@ -719,7 +719,7 @@ namespace Mist {
|
|||
}else{
|
||||
char firstPage[100];
|
||||
sprintf(firstPage, "%s%lu_%d", streamName.c_str(), tNum, 0);
|
||||
curPages[tNum].init(firstPage, 0, false);
|
||||
curPages[tNum].init(firstPage, 8 * 1024 * 1024);
|
||||
bookKeeping[tNum] = DTSCPageData();
|
||||
DEBUG_MSG(DLVL_WARN, "Buffer accepted track %lu", tNum);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue