Now compiles with DTSC multibitrate library.
This commit is contained in:
parent
d1dc4943de
commit
2644e9575e
8 changed files with 40 additions and 43 deletions
|
@ -50,6 +50,7 @@ namespace Buffer {
|
||||||
///\brief A function running in a thread to handle a new user connection.
|
///\brief A function running in a thread to handle a new user connection.
|
||||||
///\param v_usr The user that is connected.
|
///\param v_usr The user that is connected.
|
||||||
void handleUser(void * v_usr){
|
void handleUser(void * v_usr){
|
||||||
|
std::set<int> newSelect;
|
||||||
user * usr = (user*)v_usr;
|
user * usr = (user*)v_usr;
|
||||||
thisStream->addUser(usr);
|
thisStream->addUser(usr);
|
||||||
#if DEBUG >= 5
|
#if DEBUG >= 5
|
||||||
|
@ -65,7 +66,7 @@ namespace Buffer {
|
||||||
|
|
||||||
while (usr->S.connected()){
|
while (usr->S.connected()){
|
||||||
Util::sleep(5); //sleep 5ms
|
Util::sleep(5); //sleep 5ms
|
||||||
if ( !usr->myRing->playCount || !usr->Send()){
|
if ( !usr->myRing->playCount || !usr->Send(newSelect)){
|
||||||
if (usr->myRing->updated){
|
if (usr->myRing->updated){
|
||||||
Stream::get()->getReadLock();
|
Stream::get()->getReadLock();
|
||||||
usr->S.SendNow(Stream::get()->getStream()->metadata.toNetPacked());
|
usr->S.SendNow(Stream::get()->getStream()->metadata.toNetPacked());
|
||||||
|
@ -110,21 +111,24 @@ namespace Buffer {
|
||||||
thisStream->saveStats(usr->MyStr, usr->tmpStats);
|
thisStream->saveStats(usr->MyStr, usr->tmpStats);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 't': {
|
||||||
|
newSelect.clear();
|
||||||
|
std::string tmp = usr->S.Received().get().substr(2);
|
||||||
|
while (tmp != ""){
|
||||||
|
newSelect.insert(atoi(tmp.substr(0,tmp.find(' ')).c_str()));
|
||||||
|
if (tmp.find(' ') != std::string::npos){
|
||||||
|
tmp.erase(0,tmp.find(' ')+1);
|
||||||
|
}else{
|
||||||
|
tmp = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 's': { //second-seek
|
case 's': { //second-seek
|
||||||
unsigned int ms = JSON::Value(usr->S.Received().get().substr(2)).asInt();
|
unsigned int ms = JSON::Value(usr->S.Received().get().substr(2)).asInt();
|
||||||
usr->myRing->waiting = false;
|
usr->myRing->waiting = false;
|
||||||
usr->myRing->starved = false;
|
usr->myRing->starved = false;
|
||||||
usr->myRing->b = thisStream->getStream()->msSeek(ms);
|
usr->myRing->b = thisStream->getStream()->msSeek(ms, newSelect);
|
||||||
if (usr->myRing->playCount > 0){
|
|
||||||
usr->myRing->playCount = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'f': { //frame-seek
|
|
||||||
unsigned int frameno = JSON::Value(usr->S.Received().get().substr(2)).asInt();
|
|
||||||
usr->myRing->waiting = false;
|
|
||||||
usr->myRing->starved = false;
|
|
||||||
usr->myRing->b = thisStream->getStream()->frameSeek(frameno);
|
|
||||||
if (usr->myRing->playCount > 0){
|
if (usr->myRing->playCount > 0){
|
||||||
usr->myRing->playCount = 0;
|
usr->myRing->playCount = 0;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +180,6 @@ namespace Buffer {
|
||||||
if (((now - timeDiff) >= lastPacket) || (lastPacket - (now - timeDiff) > 15000)){
|
if (((now - timeDiff) >= lastPacket) || (lastPacket - (now - timeDiff) > 15000)){
|
||||||
thisStream->getWriteLock();
|
thisStream->getWriteLock();
|
||||||
if (thisStream->getStream()->parsePacket(inBuffer)){
|
if (thisStream->getStream()->parsePacket(inBuffer)){
|
||||||
thisStream->getStream()->outPacket(0);
|
|
||||||
lastPacket = thisStream->getStream()->getTime();
|
lastPacket = thisStream->getStream()->getTime();
|
||||||
if ((now - timeDiff - lastPacket) > 15000 || (now - timeDiff - lastPacket < -15000)){
|
if ((now - timeDiff - lastPacket) > 15000 || (now - timeDiff - lastPacket < -15000)){
|
||||||
timeDiff = now - lastPacket;
|
timeDiff = now - lastPacket;
|
||||||
|
@ -208,7 +211,6 @@ namespace Buffer {
|
||||||
do{
|
do{
|
||||||
thisStream->getWriteLock();
|
thisStream->getWriteLock();
|
||||||
if (thisStream->getStream()->parsePacket(thisStream->getIPInput().Received())){
|
if (thisStream->getStream()->parsePacket(thisStream->getIPInput().Received())){
|
||||||
thisStream->getStream()->outPacket(0);
|
|
||||||
thisStream->dropWriteLock(true);
|
thisStream->dropWriteLock(true);
|
||||||
packed_parsed = true;
|
packed_parsed = true;
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -178,13 +178,6 @@ namespace Buffer {
|
||||||
///\brief Drops a previously obtained write lock.
|
///\brief Drops a previously obtained write lock.
|
||||||
///\param newPacketsAvailable Whether new packets are available to update the index.
|
///\param newPacketsAvailable Whether new packets are available to update the index.
|
||||||
void Stream::dropWriteLock(bool newPacketsAvailable){
|
void Stream::dropWriteLock(bool newPacketsAvailable){
|
||||||
if (newPacketsAvailable){
|
|
||||||
if (Strm->getPacket(0).isMember("keyframe")){
|
|
||||||
stats_mutex.lock();
|
|
||||||
Strm->updateHeaders();
|
|
||||||
stats_mutex.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rw_mutex.lock();
|
rw_mutex.lock();
|
||||||
writers--;
|
writers--;
|
||||||
rw_mutex.unlock();
|
rw_mutex.unlock();
|
||||||
|
|
|
@ -68,7 +68,7 @@ namespace Buffer {
|
||||||
///\brief Try to send the current buffer.
|
///\brief Try to send the current buffer.
|
||||||
///
|
///
|
||||||
///\return True if the send was succesful, false otherwise.
|
///\return True if the send was succesful, false otherwise.
|
||||||
bool user::Send(){
|
bool user::Send(std::set<int> & allowedTracks){
|
||||||
if ( !myRing){
|
if ( !myRing){
|
||||||
return false;
|
return false;
|
||||||
} //no ring!
|
} //no ring!
|
||||||
|
@ -105,11 +105,11 @@ namespace Buffer {
|
||||||
if (doSend(Stream::get()->getStream()->outPacket(myRing->b).c_str(), Stream::get()->getStream()->outPacket(myRing->b).length())){
|
if (doSend(Stream::get()->getStream()->outPacket(myRing->b).c_str(), Stream::get()->getStream()->outPacket(myRing->b).length())){
|
||||||
//switch to next buffer
|
//switch to next buffer
|
||||||
currsend = 0;
|
currsend = 0;
|
||||||
if (myRing->b <= 0){
|
if (Stream::get()->getStream()->isNewest(myRing->b)){
|
||||||
myRing->waiting = true;
|
myRing->waiting = true;
|
||||||
return false;
|
return false;
|
||||||
} //no next buffer? go in waiting mode.
|
} //no next buffer? go in waiting mode.
|
||||||
myRing->b--;
|
myRing->b = Stream::get()->getStream()->getNext(myRing->b, allowedTracks);
|
||||||
if (Stream::get()->getStream()->getPacket(myRing->b).isMember("keyframe") && myRing->playCount > 0){
|
if (Stream::get()->getStream()->getPacket(myRing->b).isMember("keyframe") && myRing->playCount > 0){
|
||||||
myRing->playCount--;
|
myRing->playCount--;
|
||||||
if ( !myRing->playCount){
|
if ( !myRing->playCount){
|
||||||
|
|
|
@ -51,6 +51,6 @@ namespace Buffer {
|
||||||
/// Has a side effect of dropping the connection if send will never complete.
|
/// Has a side effect of dropping the connection if send will never complete.
|
||||||
bool doSend(const char * ptr, int len);
|
bool doSend(const char * ptr, int len);
|
||||||
/// Try to send data to this user. Disconnects if any problems occur.
|
/// Try to send data to this user. Disconnects if any problems occur.
|
||||||
bool Send();
|
bool Send(std::set<int> & allowedTracks);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,10 +212,11 @@ namespace Connector_HTTP {
|
||||||
printf("Quality: %s, Seg %d Frag %d\n", Quality.c_str(), Segment, ReqFragment);
|
printf("Quality: %s, Seg %d Frag %d\n", Quality.c_str(), Segment, ReqFragment);
|
||||||
#endif
|
#endif
|
||||||
if (Strm.metadata.isMember("live")){
|
if (Strm.metadata.isMember("live")){
|
||||||
int seekable = Strm.canSeekFrame(ReqFragment);
|
/// \todo Convert to MS seeking
|
||||||
|
int seekable = -1;//Strm.canSeekFrame(ReqFragment);
|
||||||
if (seekable == 0){
|
if (seekable == 0){
|
||||||
// iff the fragment in question is available, check if the next is available too
|
// iff the fragment in question is available, check if the next is available too
|
||||||
seekable = Strm.canSeekFrame(ReqFragment + 1);
|
//seekable = Strm.canSeekFrame(ReqFragment + 1);
|
||||||
}
|
}
|
||||||
if (seekable < 0){
|
if (seekable < 0){
|
||||||
HTTP_S.Clean();
|
HTTP_S.Clean();
|
||||||
|
@ -283,17 +284,17 @@ namespace Connector_HTTP {
|
||||||
//fill buffer with init data, if needed.
|
//fill buffer with init data, if needed.
|
||||||
if (Strm.metadata.isMember("audio") && Strm.metadata["audio"].isMember("init")){
|
if (Strm.metadata.isMember("audio") && Strm.metadata["audio"].isMember("init")){
|
||||||
tmp.DTSCAudioInit(Strm);
|
tmp.DTSCAudioInit(Strm);
|
||||||
tmp.tagTime(Strm.getPacket(0)["time"].asInt());
|
tmp.tagTime(Strm.getPacket()["time"].asInt());
|
||||||
FlashBuf.push_back(std::string(tmp.data, tmp.len));
|
FlashBuf.push_back(std::string(tmp.data, tmp.len));
|
||||||
FlashBufSize += tmp.len;
|
FlashBufSize += tmp.len;
|
||||||
}
|
}
|
||||||
if (Strm.metadata.isMember("video") && Strm.metadata["video"].isMember("init")){
|
if (Strm.metadata.isMember("video") && Strm.metadata["video"].isMember("init")){
|
||||||
tmp.DTSCVideoInit(Strm);
|
tmp.DTSCVideoInit(Strm);
|
||||||
tmp.tagTime(Strm.getPacket(0)["time"].asInt());
|
tmp.tagTime(Strm.getPacket()["time"].asInt());
|
||||||
FlashBuf.push_back(std::string(tmp.data, tmp.len));
|
FlashBuf.push_back(std::string(tmp.data, tmp.len));
|
||||||
FlashBufSize += tmp.len;
|
FlashBufSize += tmp.len;
|
||||||
}
|
}
|
||||||
FlashBufTime = Strm.getPacket(0)["time"].asInt();
|
FlashBufTime = Strm.getPacket()["time"].asInt();
|
||||||
}
|
}
|
||||||
tmp.DTSCLoader(Strm);
|
tmp.DTSCLoader(Strm);
|
||||||
FlashBuf.push_back(std::string(tmp.data, tmp.len));
|
FlashBuf.push_back(std::string(tmp.data, tmp.len));
|
||||||
|
|
|
@ -165,7 +165,8 @@ namespace Connector_HTTP {
|
||||||
temp = HTTP_R.url.find("_", temp) + 1;
|
temp = HTTP_R.url.find("_", temp) + 1;
|
||||||
int frameCount = atoi(HTTP_R.url.substr(temp, HTTP_R.url.find(".ts", temp) - temp).c_str());
|
int frameCount = atoi(HTTP_R.url.substr(temp, HTTP_R.url.find(".ts", temp) - temp).c_str());
|
||||||
if (Strm.metadata.isMember("live")){
|
if (Strm.metadata.isMember("live")){
|
||||||
int seekable = Strm.canSeekFrame(Segment);
|
/// \todo Update to MS seeking.
|
||||||
|
int seekable = Strm.canSeekms(Segment);
|
||||||
if (seekable < 0){
|
if (seekable < 0){
|
||||||
HTTP_S.Clean();
|
HTTP_S.Clean();
|
||||||
HTTP_S.SetBody("The requested fragment is no longer kept in memory on the server and cannot be served.\n");
|
HTTP_S.SetBody("The requested fragment is no longer kept in memory on the server and cannot be served.\n");
|
||||||
|
@ -262,9 +263,9 @@ namespace Connector_HTTP {
|
||||||
int PIDno = 0;
|
int PIDno = 0;
|
||||||
char * ContCounter = 0;
|
char * ContCounter = 0;
|
||||||
if (Strm.lastType() == DTSC::VIDEO){
|
if (Strm.lastType() == DTSC::VIDEO){
|
||||||
IsKeyFrame = Strm.getPacket(0).isMember("keyframe");
|
IsKeyFrame = Strm.getPacket().isMember("keyframe");
|
||||||
if (IsKeyFrame){
|
if (IsKeyFrame){
|
||||||
TimeStamp = (Strm.getPacket(0)["time"].asInt() * 27000);
|
TimeStamp = (Strm.getPacket()["time"].asInt() * 27000);
|
||||||
}
|
}
|
||||||
ToPack.append(avccbox.asAnnexB());
|
ToPack.append(avccbox.asAnnexB());
|
||||||
while (Strm.lastData().size()){
|
while (Strm.lastData().size()){
|
||||||
|
@ -278,13 +279,13 @@ namespace Connector_HTTP {
|
||||||
Strm.lastData().erase(0, ThisNaluSize + 4);
|
Strm.lastData().erase(0, ThisNaluSize + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ToPack.prepend(TS::Packet::getPESVideoLeadIn(0ul, Strm.getPacket(0)["time"].asInt() * 90));
|
ToPack.prepend(TS::Packet::getPESVideoLeadIn(0ul, Strm.getPacket()["time"].asInt() * 90));
|
||||||
PIDno = 0x100;
|
PIDno = 0x100;
|
||||||
ContCounter = &VideoCounter;
|
ContCounter = &VideoCounter;
|
||||||
}else if (Strm.lastType() == DTSC::AUDIO){
|
}else if (Strm.lastType() == DTSC::AUDIO){
|
||||||
ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.getTrackById(audioTrackID)["init"].asString()));
|
ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.getTrackById(audioTrackID)["init"].asString()));
|
||||||
ToPack.append(Strm.lastData());
|
ToPack.append(Strm.lastData());
|
||||||
ToPack.prepend(TS::Packet::getPESAudioLeadIn(ToPack.bytes(1073741824ul), Strm.getPacket(0)["time"].asInt() * 90));
|
ToPack.prepend(TS::Packet::getPESAudioLeadIn(ToPack.bytes(1073741824ul), Strm.getPacket()["time"].asInt() * 90));
|
||||||
PIDno = 0x101;
|
PIDno = 0x101;
|
||||||
ContCounter = &AudioCounter;
|
ContCounter = &AudioCounter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,9 +82,9 @@ namespace Connector_TS {
|
||||||
int PIDno = 0;
|
int PIDno = 0;
|
||||||
char * ContCounter = 0;
|
char * ContCounter = 0;
|
||||||
if (Strm.lastType() == DTSC::VIDEO){
|
if (Strm.lastType() == DTSC::VIDEO){
|
||||||
IsKeyFrame = Strm.getPacket(0).isMember("keyframe");
|
IsKeyFrame = Strm.getPacket().isMember("keyframe");
|
||||||
if (IsKeyFrame){
|
if (IsKeyFrame){
|
||||||
TimeStamp = (Strm.getPacket(0)["time"].asInt() * 27000);
|
TimeStamp = (Strm.getPacket()["time"].asInt() * 27000);
|
||||||
}
|
}
|
||||||
ToPack.append(avccbox.asAnnexB());
|
ToPack.append(avccbox.asAnnexB());
|
||||||
while (Strm.lastData().size()){
|
while (Strm.lastData().size()){
|
||||||
|
@ -98,13 +98,13 @@ namespace Connector_TS {
|
||||||
Strm.lastData().erase(0, ThisNaluSize + 4);
|
Strm.lastData().erase(0, ThisNaluSize + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ToPack.prepend(TS::Packet::getPESVideoLeadIn(0ul, Strm.getPacket(0)["time"].asInt() * 90));
|
ToPack.prepend(TS::Packet::getPESVideoLeadIn(0ul, Strm.getPacket()["time"].asInt() * 90));
|
||||||
PIDno = 0x100;
|
PIDno = 0x100;
|
||||||
ContCounter = &VideoCounter;
|
ContCounter = &VideoCounter;
|
||||||
}else if (Strm.lastType() == DTSC::AUDIO){
|
}else if (Strm.lastType() == DTSC::AUDIO){
|
||||||
ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.metadata["audio"]["init"].asString()));
|
ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.metadata["audio"]["init"].asString()));
|
||||||
ToPack.append(Strm.lastData());
|
ToPack.append(Strm.lastData());
|
||||||
ToPack.prepend(TS::Packet::getPESAudioLeadIn(ToPack.bytes(1073741824ul), Strm.getPacket(0)["time"].asInt() * 90));
|
ToPack.prepend(TS::Packet::getPESAudioLeadIn(ToPack.bytes(1073741824ul), Strm.getPacket()["time"].asInt() * 90));
|
||||||
PIDno = 0x101;
|
PIDno = 0x101;
|
||||||
ContCounter = &AudioCounter;
|
ContCounter = &AudioCounter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,9 @@ namespace Converters {
|
||||||
int PIDno = 0;
|
int PIDno = 0;
|
||||||
char * ContCounter = 0;
|
char * ContCounter = 0;
|
||||||
if (Strm.lastType() == DTSC::VIDEO){
|
if (Strm.lastType() == DTSC::VIDEO){
|
||||||
IsKeyFrame = Strm.getPacket(0).isMember("keyframe");
|
IsKeyFrame = Strm.getPacket().isMember("keyframe");
|
||||||
if (IsKeyFrame){
|
if (IsKeyFrame){
|
||||||
TimeStamp = (Strm.getPacket(0)["time"].asInt() * 27000);
|
TimeStamp = (Strm.getPacket()["time"].asInt() * 27000);
|
||||||
}
|
}
|
||||||
ToPack.append(avccbox.asAnnexB());
|
ToPack.append(avccbox.asAnnexB());
|
||||||
while (Strm.lastData().size()){
|
while (Strm.lastData().size()){
|
||||||
|
@ -79,13 +79,13 @@ namespace Converters {
|
||||||
Strm.lastData().erase(0, ThisNaluSize + 4);
|
Strm.lastData().erase(0, ThisNaluSize + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ToPack.prepend(TS::Packet::getPESVideoLeadIn(0ul, Strm.getPacket(0)["time"].asInt() * 90));
|
ToPack.prepend(TS::Packet::getPESVideoLeadIn(0ul, Strm.getPacket()["time"].asInt() * 90));
|
||||||
PIDno = 0x100;
|
PIDno = 0x100;
|
||||||
ContCounter = &VideoCounter;
|
ContCounter = &VideoCounter;
|
||||||
}else if (Strm.lastType() == DTSC::AUDIO){
|
}else if (Strm.lastType() == DTSC::AUDIO){
|
||||||
ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.metadata["audio"]["init"].asString()));
|
ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.metadata["audio"]["init"].asString()));
|
||||||
ToPack.append(Strm.lastData());
|
ToPack.append(Strm.lastData());
|
||||||
ToPack.prepend(TS::Packet::getPESAudioLeadIn(ToPack.bytes(1073741824ul), Strm.getPacket(0)["time"].asInt() * 90));
|
ToPack.prepend(TS::Packet::getPESAudioLeadIn(ToPack.bytes(1073741824ul), Strm.getPacket()["time"].asInt() * 90));
|
||||||
PIDno = 0x101;
|
PIDno = 0x101;
|
||||||
ContCounter = &AudioCounter;
|
ContCounter = &AudioCounter;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue