Fixed a race condition in VoD, where the page was declared "ready" before it was filled.
This commit is contained in:
parent
0789cc46d2
commit
ef29ce2ca6
1 changed files with 32 additions and 19 deletions
27
src/io.cpp
27
src/io.cpp
|
@ -91,7 +91,9 @@ namespace Mist {
|
||||||
//Initialize the bookkeeping entry, and set the current offset to 0, to allow for using it in bufferNext()
|
//Initialize the bookkeeping entry, and set the current offset to 0, to allow for using it in bufferNext()
|
||||||
pagesByTrack[tid][pageNumber].curOffset = 0;
|
pagesByTrack[tid][pageNumber].curOffset = 0;
|
||||||
|
|
||||||
|
if (myMeta.live){
|
||||||
//Register this page on the meta page
|
//Register this page on the meta page
|
||||||
|
//NOTE: It is important that this only happens if the stream is live....
|
||||||
bool inserted = false;
|
bool inserted = false;
|
||||||
for (int i = 0; i < 1024; i++) {
|
for (int i = 0; i < 1024; i++) {
|
||||||
int * tmpOffset = (int *)(metaPages[tid].mapped + (i * 8));
|
int * tmpOffset = (int *)(metaPages[tid].mapped + (i * 8));
|
||||||
|
@ -106,6 +108,7 @@ namespace Mist {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
INFO_MSG("Start buffering page %lu on track %lu~>%lu successful", pageNumber, tid, mapTid);
|
INFO_MSG("Start buffering page %lu on track %lu~>%lu successful", pageNumber, tid, mapTid);
|
||||||
///\return true if everything was successful
|
///\return true if everything was successful
|
||||||
|
@ -263,17 +266,27 @@ namespace Mist {
|
||||||
for (int i = 0; i < 1024; i++) {
|
for (int i = 0; i < 1024; i++) {
|
||||||
int * tmpOffset = (int *)(metaPages[tid].mapped + (i * 8));
|
int * tmpOffset = (int *)(metaPages[tid].mapped + (i * 8));
|
||||||
int keyNum = ntohl(tmpOffset[0]);
|
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 (!keyNum) continue;
|
||||||
if (!lowest || keyNum < lowest){
|
if (!lowest || keyNum < lowest){
|
||||||
lowest = keyNum;
|
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)
|
#if defined(__CYGWIN__) || defined(_WIN32)
|
||||||
|
|
Loading…
Add table
Reference in a new issue