Fixed a race condition in VoD, where the page was declared "ready" before it was filled.

This commit is contained in:
Erik Zandvliet 2015-06-14 09:43:05 +02:00 committed by Thulinma
parent 0789cc46d2
commit ef29ce2ca6

View file

@ -91,7 +91,9 @@ namespace Mist {
//Initialize the bookkeeping entry, and set the current offset to 0, to allow for using it in bufferNext()
pagesByTrack[tid][pageNumber].curOffset = 0;
if (myMeta.live){
//Register this page on the meta page
//NOTE: It is important that this only happens if the stream is live....
bool inserted = false;
for (int i = 0; i < 1024; i++) {
int * tmpOffset = (int *)(metaPages[tid].mapped + (i * 8));
@ -106,6 +108,7 @@ namespace Mist {
break;
}
}
}
INFO_MSG("Start buffering page %lu on track %lu~>%lu successful", pageNumber, tid, mapTid);
///\return true if everything was successful
@ -263,17 +266,27 @@ namespace Mist {
for (int i = 0; i < 1024; i++) {
int * tmpOffset = (int *)(metaPages[tid].mapped + (i * 8));
int keyNum = ntohl(tmpOffset[0]);
int keyAmount = ntohl(tmpOffset[1]);
if (!inserted){
if (myMeta.live){
if(keyNum == curPageNum[tid] && keyAmount == 1000){
tmpOffset[1] = htonl(pagesByTrack[tid][curPageNum[tid]].keyNum);
inserted = true;
}
}else{
//in case of vod, insert at the first "empty" spot
if(keyNum == 0){
tmpOffset[0] = htonl(curPageNum[tid]);
tmpOffset[1] = htonl(pagesByTrack[tid][curPageNum[tid]].keyNum);
inserted = true;
}
}
}
keyNum = ntohl(tmpOffset[0]);
if (!keyNum) continue;
if (!lowest || keyNum < lowest){
lowest = keyNum;
}
int keyAmount = ntohl(tmpOffset[1]);
if (!inserted && keyNum == curPageNum[tid]){
if (keyAmount == 1000){
tmpOffset[1] = htonl(pagesByTrack[tid][curPageNum[tid]].keyNum);
}
inserted = true;
}
}
#if defined(__CYGWIN__) || defined(_WIN32)