Working multi-input

This commit is contained in:
Erik Zandvliet 2015-04-02 09:56:47 +02:00
parent 9b6312ca01
commit d370ef4eac
31 changed files with 1264 additions and 690 deletions

View file

@ -13,7 +13,6 @@
#include "output.h"
namespace Mist {
Util::Config * Output::config = NULL;
JSON::Value Output::capa = JSON::Value();
int getDTSCLen(char * mapped, long long int offset){
@ -61,13 +60,15 @@ namespace Mist {
void Output::updateMeta(){
//read metadata from page to myMeta variable
IPC::semaphore liveMeta(std::string("liveMeta@" + streamName).c_str(), O_CREAT | O_RDWR, ACCESSPERMS, 1);
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);
bool lock = myMeta.live;
if (lock){
liveMeta.wait();
}
if (streamIndex.mapped){
DTSC::Packet tmpMeta(streamIndex.mapped, streamIndex.len, true);
if (metaPages[0].mapped){
DTSC::Packet tmpMeta(metaPages[0].mapped, metaPages[0].len, true);
if (tmpMeta.getVersion()){
myMeta.reinit(tmpMeta);
}
@ -85,150 +86,11 @@ namespace Mist {
myConn.close();
}
void Output::negotiateWithBuffer(int tid){
//Check whether the track exists
if (!meta_out.tracks.count(tid)) {
return;
}
//Do not re-negotiate already confirmed tracks
if (trackMap.count(tid)){
return;
}
//Do not re-negotiate if already at maximum for push tracks
if (trackMap.size() >= 5){
DEBUG_MSG(DLVL_FAIL, "Failed to negotiate for incoming track %d, already at maximum number of tracks", tid);
return;
}
char * tmp = playerConn.getData();
if (!tmp){
DEBUG_MSG(DLVL_FAIL, "Failed to negotiate for incoming track %d, there does not seem to be a connection with the buffer", tid);
return;
}
int bufConnOffset = trackMap.size();
DEBUG_MSG(DLVL_DEVEL, "Starting negotiation for incoming track %d, at offset %d", tid, bufConnOffset);
memset(tmp + 6 * bufConnOffset, 0, 4);
tmp[6 * bufConnOffset] = 0x80;
tmp[6 * bufConnOffset + 4] = 0xFF;
tmp[6 * bufConnOffset + 5] = 0xFF;
playerConn.keepAlive();
unsigned int newTid = 0x80000000u;
while (newTid == 0x80000000u){
Util::sleep(100);
newTid = ((long)(tmp[6 * bufConnOffset]) << 24) | ((long)(tmp[6 * bufConnOffset + 1]) << 16) | ((long)(tmp[6 * bufConnOffset + 2]) << 8) | tmp[6 * bufConnOffset + 3];
}
DEBUG_MSG(DLVL_VERYHIGH, "Track %d temporarily mapped to %d", tid, newTid);
char pageName[100];
sprintf(pageName, "liveStream_%s%d", streamName.c_str(), newTid);
IPC::sharedPage metaPage(pageName, 8 * 1024 * 1024);
DTSC::Meta tmpMeta = meta_out;
tmpMeta.tracks.clear();
tmpMeta.tracks[newTid] = meta_out.tracks[tid];
tmpMeta.tracks[newTid].trackID = newTid;
JSON::Value tmpVal = tmpMeta.toJSON();
std::string tmpStr = tmpVal.toNetPacked();
memcpy(metaPage.mapped, tmpStr.data(), tmpStr.size());
DEBUG_MSG(DLVL_VERYHIGH, "Temporary metadata written for incoming track %d, handling as track %d", tid, newTid);
unsigned short firstPage = 0xFFFF;
unsigned int finalTid = newTid;
while (firstPage == 0xFFFF){
DEBUG_MSG(DLVL_VERYHIGH, "Re-checking at offset %d", bufConnOffset);
Util::sleep(100);
finalTid = ((long)(tmp[6 * bufConnOffset]) << 24) | ((long)(tmp[6 * bufConnOffset + 1]) << 16) | ((long)(tmp[6 * bufConnOffset + 2]) << 8) | tmp[6 * bufConnOffset + 3];
firstPage = ((long)(tmp[6 * bufConnOffset + 4]) << 8) | tmp[6 * bufConnOffset + 5];
if (finalTid == 0xFFFFFFFF){
WARN_MSG("Buffer has declined incoming track %d", tid);
return;
}
}
//Reinitialize so we make sure we got the right values here
finalTid = ((long)(tmp[6 * bufConnOffset]) << 24) | ((long)(tmp[6 * bufConnOffset + 1]) << 16) | ((long)(tmp[6 * bufConnOffset + 2]) << 8) | tmp[6 * bufConnOffset + 3];
firstPage = ((long)(tmp[6 * bufConnOffset + 4]) << 8) | tmp[6 * bufConnOffset + 5];
if (finalTid == 0xFFFFFFFF){
WARN_MSG("Buffer has declined incoming track %d", tid);
memset(tmp + 6 * bufConnOffset, 0, 6);
return;
}
INFO_MSG("Buffer has indicated that incoming track %d should start writing on track %d, page %d", tid, finalTid, firstPage);
memset(pageName, 0, 100);
sprintf(pageName, "%s%d_%d", streamName.c_str(), finalTid, firstPage);
curPages[finalTid].init(pageName, DEFAULT_DATA_PAGE_SIZE);
trackMap[tid] = finalTid;
bookKeeping[finalTid] = DTSCPageData();
}
void Output::negotiatePushTracks() {
int i = 0;
for (std::map<unsigned int, DTSC::Track>::iterator it = meta_out.tracks.begin(); it != meta_out.tracks.end() && i < 5; it++){
negotiateWithBuffer(it->first);
i++;
}
}
void Output::bufferPacket(JSON::Value & pack){
if (!pack["trackid"].asInt()){return;}
if (myMeta.tracks[pack["trackid"].asInt()].type != "video"){
if ((pack["time"].asInt() - bookKeeping[trackMap[pack["trackid"].asInt()]].lastKeyTime) >= 5000){
pack["keyframe"] = 1LL;
bookKeeping[trackMap[pack["trackid"].asInt()]].lastKeyTime = pack["time"].asInt();
}
}
if (pack["trackid"].asInt() == 0){
return;
}
//Re-negotiate declined tracks on each keyframe, to compensate for "broken" tracks
if (!trackMap.count(pack["trackid"].asInt()) || !trackMap[pack["trackid"].asInt()]){
if (pack.isMember("keyframe") && pack["keyframe"]){
negotiateWithBuffer(pack["trackid"].asInt());
}
}
if (!trackMap.count(pack["trackid"].asInt()) || !trackMap[pack["trackid"].asInt()]){
//declined track;
return;
}
pack["trackid"] = trackMap[pack["trackid"].asInt()];
long long unsigned int tNum = pack["trackid"].asInt();
if (!bookKeeping.count(tNum)){
return;
}
int pageNum = bookKeeping[tNum].pageNum;
std::string tmp = pack.toNetPacked();
if (bookKeeping[tNum].curOffset > FLIP_DATA_PAGE_SIZE && pack.isMember("keyframe") && pack["keyframe"]){
//open new page
char nextPage[100];
sprintf(nextPage, "%s%llu_%d", streamName.c_str(), tNum, bookKeeping[tNum].pageNum + bookKeeping[tNum].keyNum);
INFO_MSG("Continuing track %llu on page %d, from pos %llu", tNum, bookKeeping[tNum].pageNum + bookKeeping[tNum].keyNum, bookKeeping[tNum].curOffset);
curPages[tNum].init(nextPage, DEFAULT_DATA_PAGE_SIZE);
bookKeeping[tNum].pageNum += bookKeeping[tNum].keyNum;
bookKeeping[tNum].keyNum = 0;
bookKeeping[tNum].curOffset = 0;
}
if (!curPages[tNum].mapped){
//prevent page init failures from crashing everything.
myConn.close();//closes the connection to trigger a clean shutdown
return;
}
if (bookKeeping[tNum].curOffset + tmp.size() < (unsigned long long)curPages[tNum].len){
bookKeeping[tNum].keyNum += (pack.isMember("keyframe") && pack["keyframe"]);
memcpy(curPages[tNum].mapped + bookKeeping[tNum].curOffset, tmp.data(), tmp.size());
bookKeeping[tNum].curOffset += tmp.size();
}else{
bookKeeping[tNum].curOffset += tmp.size();
DEBUG_MSG(DLVL_WARN, "Can't buffer frame on page %d, track %llu, time %lld, keyNum %d, offset %llu", pageNum, tNum, pack["time"].asInt(), bookKeeping[tNum].pageNum + bookKeeping[tNum].keyNum, bookKeeping[tNum].curOffset);
}
}
void Output::initialize(){
if (isInitialized){
return;
}
if (streamIndex.mapped){
if (metaPages[0].mapped){
return;
}
if (streamName.size() < 1){
@ -240,14 +102,20 @@ namespace Mist {
return;
}
isInitialized = true;
streamIndex.init(streamName, DEFAULT_META_PAGE_SIZE);
if (!streamIndex.mapped){
char pageId[NAME_BUFFER_SIZE];
snprintf(pageId, NAME_BUFFER_SIZE, SHM_STREAM_INDEX, streamName.c_str());
metaPages[0].init(pageId, DEFAULT_META_PAGE_SIZE);
if (!metaPages[0].mapped){
DEBUG_MSG(DLVL_FAIL, "Could not connect to server for %s\n", streamName.c_str());
onFail();
return;
}
statsPage = IPC::sharedClient("statistics", STAT_EX_SIZE, true);
playerConn = IPC::sharedClient(streamName + "_users", PLAY_EX_SIZE , true);
statsPage = IPC::sharedClient(SHM_STATISTICS, STAT_EX_SIZE, true);
char userPageName[NAME_BUFFER_SIZE];
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
if (!userClient.getData()){
userClient = IPC::sharedClient(userPageName, PLAY_EX_SIZE, true);
}
updateMeta();
selectDefaultTracks();
sought = false;
@ -259,14 +127,14 @@ namespace Mist {
return;
}
//check which tracks don't actually exist
std::set<long unsigned int> toRemove;
for (std::set<long unsigned int>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){
std::set<unsigned long> toRemove;
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){
if (!myMeta.tracks.count(*it)){
toRemove.insert(*it);
}
}
//remove those from selectedtracks
for (std::set<long unsigned int>::iterator it = toRemove.begin(); it != toRemove.end(); it++){
for (std::set<unsigned long>::iterator it = toRemove.begin(); it != toRemove.end(); it++){
selectedTracks.erase(*it);
}
@ -282,7 +150,7 @@ namespace Mist {
if ((*itb).size() > 0){
bool found = false;
for (JSON::ArrIter itc = (*itb).ArrBegin(); itc != (*itb).ArrEnd() && !found; itc++){
for (std::set<long unsigned int>::iterator itd = selectedTracks.begin(); itd != selectedTracks.end(); itd++){
for (std::set<unsigned long>::iterator itd = selectedTracks.begin(); itd != selectedTracks.end(); itd++){
if (myMeta.tracks[*itd].codec == (*itc).asStringRef()){
selCounter++;
found = true;
@ -321,12 +189,10 @@ namespace Mist {
if ((*itb).size() && myMeta.tracks.size()){
bool found = false;
for (JSON::ArrIter itc = (*itb).ArrBegin(); itc != (*itb).ArrEnd() && !found; itc++){
if (selectedTracks.size()){
for (std::set<long unsigned int>::iterator itd = selectedTracks.begin(); itd != selectedTracks.end(); itd++){
if (myMeta.tracks[*itd].codec == (*itc).asStringRef()){
found = true;
break;
}
for (std::set<unsigned long>::iterator itd = selectedTracks.begin(); itd != selectedTracks.end(); itd++){
if (myMeta.tracks[*itd].codec == (*itc).asStringRef()){
found = true;
break;
}
}
if (!found){
@ -385,17 +251,17 @@ namespace Mist {
}
int Output::pageNumForKey(long unsigned int trackId, long long int keyNum){
if (!indexPages.count(trackId)){
char id[100];
sprintf(id, "%s%lu", streamName.c_str(), trackId);
indexPages[trackId].init(id, 8 * 1024);
if (!metaPages.count(trackId)){
char id[NAME_BUFFER_SIZE];
snprintf(id, NAME_BUFFER_SIZE, SHM_TRACK_INDEX, streamName.c_str(), trackId);
metaPages[trackId].init(id, 8 * 1024);
}
char * mpd = indexPages[trackId].mapped;
int len = indexPages[trackId].len / 8;
int len = metaPages[trackId].len / 8;
for (int i = 0; i < len; i++){
long amountKey = ntohl((((long long int*)mpd)[i]) & 0xFFFFFFFF);
int * tmpOffset = (int *)(metaPages[trackId].mapped + (i * 8));
long amountKey = ntohl(tmpOffset[1]);
if (amountKey == 0){continue;}
long tmpKey = ntohl(((((long long int*)mpd)[i]) >> 32) & 0xFFFFFFFF);
long tmpKey = ntohl(tmpOffset[0]);
if (tmpKey <= keyNum && ((tmpKey?tmpKey:1) + amountKey) > keyNum){
return tmpKey;
}
@ -405,20 +271,20 @@ namespace Mist {
void Output::loadPageForKey(long unsigned int trackId, long long int keyNum){
if (myMeta.vod && keyNum > myMeta.tracks[trackId].keys.rbegin()->getNumber()){
curPages.erase(trackId);
curPage.erase(trackId);
currKeyOpen.erase(trackId);
return;
}
DEBUG_MSG(DLVL_HIGH, "Loading track %lu, containing key %lld", trackId, keyNum);
unsigned int timeout = 0;
int pageNum = pageNumForKey(trackId, keyNum);
unsigned long pageNum = pageNumForKey(trackId, keyNum);
while (pageNum == -1){
if (!timeout){
DEBUG_MSG(DLVL_DEVEL, "Requesting/waiting for page that has key %lu:%lld...", trackId, keyNum);
}
if (timeout++ > 100){
DEBUG_MSG(DLVL_FAIL, "Timeout while waiting for requested page. Aborting.");
curPages.erase(trackId);
curPage.erase(trackId);
currKeyOpen.erase(trackId);
return;
}
@ -443,11 +309,11 @@ namespace Mist {
if (currKeyOpen.count(trackId) && currKeyOpen[trackId] == (unsigned int)pageNum){
return;
}
char id[100];
snprintf(id, 100, "%s%lu_%d", streamName.c_str(), trackId, pageNum);
curPages[trackId].init(id, DEFAULT_DATA_PAGE_SIZE);
if (!(curPages[trackId].mapped)){
DEBUG_MSG(DLVL_FAIL, "Initializing page %s failed", curPages[trackId].name.c_str());
char id[NAME_BUFFER_SIZE];
snprintf(id, NAME_BUFFER_SIZE, SHM_TRACK_DATA, streamName.c_str(), trackId, pageNum);
curPage[trackId].init(id, DEFAULT_DATA_PAGE_SIZE);
if (!(curPage[trackId].mapped)){
DEBUG_MSG(DLVL_FAIL, "Initializing page %s failed", curPage[trackId].name.c_str());
return;
}
currKeyOpen[trackId] = pageNum;
@ -461,8 +327,10 @@ namespace Mist {
initialize();
}
buffer.clear();
currentPacket.null();
updateMeta();
thisPacket.null();
if (myMeta.live){
updateMeta();
}
DEBUG_MSG(DLVL_MEDIUM, "Seeking to %llums", pos);
for (std::set<long unsigned int>::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){
seek(*it, pos);
@ -471,7 +339,7 @@ namespace Mist {
bool Output::seek(unsigned int tid, unsigned long long pos, bool getNextKey){
loadPageForKey(tid, getKeyForTime(tid, pos) + (getNextKey?1:0));
if (!curPages.count(tid) || !curPages[tid].mapped){
if (!curPage.count(tid) || !curPage[tid].mapped){
DEBUG_MSG(DLVL_DEVEL, "Aborting seek to %llums in track %u, not available.", pos, tid);
return false;
}
@ -479,9 +347,9 @@ namespace Mist {
tmp.tid = tid;
tmp.offset = 0;
DTSC::Packet tmpPack;
tmpPack.reInit(curPages[tid].mapped + tmp.offset, 0, true);
tmpPack.reInit(curPage[tid].mapped + tmp.offset, 0, true);
tmp.time = tmpPack.getTime();
char * mpd = curPages[tid].mapped;
char * mpd = curPage[tid].mapped;
while ((long long)tmp.time < pos && tmpPack){
tmp.offset += tmpPack.getDataLen();
tmpPack.reInit(mpd + tmp.offset, 0, true);
@ -492,15 +360,15 @@ namespace Mist {
return true;
}else{
//don't print anything for empty packets - not sign of corruption, just unfinished stream.
if (curPages[tid].mapped[tmp.offset] != 0){
if (curPage[tid].mapped[tmp.offset] != 0){
DEBUG_MSG(DLVL_FAIL, "Noes! Couldn't find packet on track %d because of some kind of corruption error or somesuch.", tid);
}else{
DEBUG_MSG(DLVL_FAIL, "Track %d no data (key %u @ %u) - waiting...", tid, getKeyForTime(tid, pos) + (getNextKey?1:0), tmp.offset);
unsigned int i = 0;
while (curPages[tid].mapped[tmp.offset] == 0 && ++i < 42){
while (curPage[tid].mapped[tmp.offset] == 0 && ++i < 42){
Util::wait(100);
}
if (curPages[tid].mapped[tmp.offset] == 0){
if (curPage[tid].mapped[tmp.offset] == 0){
DEBUG_MSG(DLVL_FAIL, "Track %d no data (key %u) - timeout", tid, getKeyForTime(tid, pos) + (getNextKey?1:0));
}else{
return seek(tid, pos, getNextKey);
@ -539,7 +407,7 @@ namespace Mist {
sendHeader();
}
prepareNext();
if (currentPacket){
if (thisPacket){
sendNext();
}else{
if (!onFinish()){
@ -550,7 +418,7 @@ namespace Mist {
}
DEBUG_MSG(DLVL_MEDIUM, "MistOut client handler shutting down: %s, %s, %s", myConn.connected() ? "conn_active" : "conn_closed", wantRequest ? "want_request" : "no_want_request", parseData ? "parsing_data" : "not_parsing_data");
stats();
playerConn.finish();
userClient.finish();
statsPage.finish();
myConn.close();
return 0;
@ -575,7 +443,22 @@ namespace Mist {
if (!sought){
if (myMeta.live){
long unsigned int mainTrack = getMainSelectedTrack();
unsigned long long seekPos = myMeta.tracks[mainTrack].keys.begin()->getTime();
if (myMeta.tracks[mainTrack].keys.size() < 2){
if (!myMeta.tracks[mainTrack].keys.size()){
myConn.close();
return;
}else{
seek(myMeta.tracks[mainTrack].keys.begin()->getTime());
prepareNext();
return;
}
}
unsigned int skip = ((myMeta.tracks[mainTrack].keys.size()-1) * config->getInteger("startpos")) / 1000u;
std::deque<DTSC::Key>::iterator it = myMeta.tracks[mainTrack].keys.begin();
for (unsigned int i = 0; i < skip; ++i){
++it;
}
unsigned long long seekPos = it->getTime();
if (seekPos < 5000){
seekPos = 0;
}
@ -586,7 +469,7 @@ namespace Mist {
}
static unsigned int emptyCount = 0;
if (!buffer.size()){
currentPacket.null();
thisPacket.null();
DEBUG_MSG(DLVL_DEVEL, "Buffer completely played out");
onFinish();
return;
@ -596,15 +479,15 @@ namespace Mist {
DEBUG_MSG(DLVL_DONTEVEN, "Loading track %u (next=%lu), %llu ms", nxt.tid, nxtKeyNum[nxt.tid], nxt.time);
if (nxt.offset >= curPages[nxt.tid].len){
nxtKeyNum[nxt.tid] = getKeyForTime(nxt.tid, currentPacket.getTime());
if (nxt.offset >= curPage[nxt.tid].len){
nxtKeyNum[nxt.tid] = getKeyForTime(nxt.tid, thisPacket.getTime());
loadPageForKey(nxt.tid, ++nxtKeyNum[nxt.tid]);
nxt.offset = 0;
if (curPages.count(nxt.tid) && curPages[nxt.tid].mapped){
if (getDTSCTime(curPages[nxt.tid].mapped, nxt.offset) < nxt.time){
if (curPage.count(nxt.tid) && curPage[nxt.tid].mapped){
if (getDTSCTime(curPage[nxt.tid].mapped, nxt.offset) < nxt.time){
ERROR_MSG("Time going backwards in track %u - dropping track.", nxt.tid);
}else{
nxt.time = getDTSCTime(curPages[nxt.tid].mapped, nxt.offset);
nxt.time = getDTSCTime(curPage[nxt.tid].mapped, nxt.offset);
buffer.insert(nxt);
}
prepareNext();
@ -612,7 +495,7 @@ namespace Mist {
}
}
if (!curPages.count(nxt.tid) || !curPages[nxt.tid].mapped){
if (!curPage.count(nxt.tid) || !curPage[nxt.tid].mapped){
//mapping failure? Drop this track and go to next.
//not an error - usually means end of stream.
DEBUG_MSG(DLVL_DEVEL, "Track %u no page - dropping track.", nxt.tid);
@ -621,7 +504,7 @@ namespace Mist {
}
//have we arrived at the end of the memory page? (4 zeroes mark the end)
if (!memcmp(curPages[nxt.tid].mapped + nxt.offset, "\000\000\000\000", 4)){
if (!memcmp(curPage[nxt.tid].mapped + nxt.offset, "\000\000\000\000", 4)){
//if we don't currently know where we are, we're lost. We should drop the track.
if (!nxt.time){
DEBUG_MSG(DLVL_DEVEL, "Timeless empty packet on track %u - dropping track.", nxt.tid);
@ -645,11 +528,11 @@ namespace Mist {
updateMeta();
}else{
//if we're not live, we've simply reached the end of the page. Load the next key.
nxtKeyNum[nxt.tid] = getKeyForTime(nxt.tid, currentPacket.getTime());
nxtKeyNum[nxt.tid] = getKeyForTime(nxt.tid, thisPacket.getTime());
loadPageForKey(nxt.tid, ++nxtKeyNum[nxt.tid]);
nxt.offset = 0;
if (curPages.count(nxt.tid) && curPages[nxt.tid].mapped){
unsigned long long nextTime = getDTSCTime(curPages[nxt.tid].mapped, nxt.offset);
if (curPage.count(nxt.tid) && curPage[nxt.tid].mapped){
unsigned long long nextTime = getDTSCTime(curPage[nxt.tid].mapped, nxt.offset);
if (nextTime && nextTime < nxt.time){
DEBUG_MSG(DLVL_DEVEL, "Time going backwards in track %u - dropping track.", nxt.tid);
}else{
@ -666,29 +549,29 @@ namespace Mist {
prepareNext();
return;
}
currentPacket.reInit(curPages[nxt.tid].mapped + nxt.offset, 0, true);
if (currentPacket){
if (currentPacket.getTime() != nxt.time && nxt.time){
DEBUG_MSG(DLVL_MEDIUM, "ACTUALLY Loaded track %ld (next=%lu), %llu ms", currentPacket.getTrackId(), nxtKeyNum[nxt.tid], currentPacket.getTime());
thisPacket.reInit(curPage[nxt.tid].mapped + nxt.offset, 0, true);
if (thisPacket){
if (thisPacket.getTime() != nxt.time && nxt.time){
DEBUG_MSG(DLVL_MEDIUM, "ACTUALLY Loaded track %ld (next=%lu), %llu ms", thisPacket.getTrackId(), nxtKeyNum[nxt.tid], thisPacket.getTime());
}
if ((myMeta.tracks[nxt.tid].type == "video" && currentPacket.getFlag("keyframe")) || (++nonVideoCount % 30 == 0)){
if ((myMeta.tracks[nxt.tid].type == "video" && thisPacket.getFlag("keyframe")) || (++nonVideoCount % 30 == 0)){
if (myMeta.live){
updateMeta();
}
nxtKeyNum[nxt.tid] = getKeyForTime(nxt.tid, currentPacket.getTime());
DEBUG_MSG(DLVL_VERYHIGH, "Track %u @ %llums = key %lu", nxt.tid, currentPacket.getTime(), nxtKeyNum[nxt.tid]);
nxtKeyNum[nxt.tid] = getKeyForTime(nxt.tid, thisPacket.getTime());
DEBUG_MSG(DLVL_VERYHIGH, "Track %u @ %llums = key %lu", nxt.tid, thisPacket.getTime(), nxtKeyNum[nxt.tid]);
}
emptyCount = 0;
}
nxt.offset += currentPacket.getDataLen();
nxt.offset += thisPacket.getDataLen();
if (realTime){
while (nxt.time > (Util::getMS() - firstTime + maxSkipAhead)*1000/realTime) {
Util::sleep(nxt.time - (Util::getMS() - firstTime + minSkipAhead)*1000/realTime);
}
}
if (curPages[nxt.tid]){
if (nxt.offset < curPages[nxt.tid].len){
unsigned long long nextTime = getDTSCTime(curPages[nxt.tid].mapped, nxt.offset);
if (curPage[nxt.tid]){
if (nxt.offset < curPage[nxt.tid].len){
unsigned long long nextTime = getDTSCTime(curPage[nxt.tid].mapped, nxt.offset);
if (nextTime){
nxt.time = nextTime;
}else{
@ -721,8 +604,8 @@ namespace Mist {
tmpEx.up(myConn.dataUp());
tmpEx.down(myConn.dataDown());
tmpEx.time(now - myConn.connTime());
if (currentPacket){
tmpEx.lastSecond(currentPacket.getTime());
if (thisPacket){
tmpEx.lastSecond(thisPacket.getTime());
}else{
tmpEx.lastSecond(0);
}
@ -730,18 +613,20 @@ namespace Mist {
}
}
int tNum = 0;
if (!playerConn.getData()){
playerConn = IPC::sharedClient(streamName + "_users", PLAY_EX_SIZE, true);
if (!playerConn.getData()){
if (!userClient.getData()){
char userPageName[NAME_BUFFER_SIZE];
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
userClient = IPC::sharedClient(userPageName, PLAY_EX_SIZE, true);
if (!userClient.getData()){
DEBUG_MSG(DLVL_WARN, "Player connection failure - aborting output");
myConn.close();
return;
}
}
if (trackMap.size()){
for (std::map<int, int>::iterator it = trackMap.begin(); it != trackMap.end() && tNum < 5; it++){
for (std::map<unsigned long, unsigned long>::iterator it = trackMap.begin(); it != trackMap.end() && tNum < 5; it++){
unsigned int tId = it->second;
char * thisData = playerConn.getData() + (6 * tNum);
char * thisData = userClient.getData() + (6 * tNum);
thisData[0] = ((tId >> 24) & 0xFF);
thisData[1] = ((tId >> 16) & 0xFF);
thisData[2] = ((tId >> 8) & 0xFF);
@ -753,7 +638,7 @@ namespace Mist {
}else{
for (std::set<unsigned long>::iterator it = selectedTracks.begin(); it != selectedTracks.end() && tNum < 5; it++){
unsigned int tId = *it;
char * thisData = playerConn.getData() + (6 * tNum);
char * thisData = userClient.getData() + (6 * tNum);
thisData[0] = ((tId >> 24) & 0xFF);
thisData[1] = ((tId >> 16) & 0xFF);
thisData[2] = ((tId >> 8) & 0xFF);
@ -763,7 +648,7 @@ namespace Mist {
tNum ++;
}
}
playerConn.keepAlive();
userClient.keepAlive();
if (tNum >= 5){
DEBUG_MSG(DLVL_WARN, "Too many tracks selected, using only first 5");
}
@ -779,5 +664,4 @@ namespace Mist {
//just set the sentHeader bool to true, by default
sentHeader = true;
}
}

View file

@ -9,6 +9,7 @@
#include <mist/dtsc.h>
#include <mist/socket.h>
#include <mist/shared_memory.h>
#include "../io.h"
namespace Mist {
@ -26,24 +27,13 @@ namespace Mist {
unsigned int offset;
};
struct DTSCPageData {
DTSCPageData() : pageNum(0), keyNum(0), partNum(0), dataSize(0), curOffset(0), firstTime(0), lastKeyTime(-5000){}
int pageNum;///<The current page number
int keyNum;///<The number of keyframes in this page.
int partNum;///<The number of parts in this page.
unsigned long long int dataSize;///<The full size this page should be.
unsigned long long int curOffset;///<The current write offset in the page.
unsigned long long int firstTime;///<The first timestamp of the page.
long long int lastKeyTime;///<The time of the last keyframe of the page.
};
/// The output class is intended to be inherited by MistOut process classes.
/// The output class is intended to be inherited by MistOut process classes.
/// It contains all generic code and logic, while the child classes implement
/// anything specific to particular protocols or containers.
/// It contains several virtual functions, that may be overridden to "hook" into
/// the streaming process at those particular points, simplifying child class
/// logic and implementation details.
class Output {
class Output : public InOutBase {
public:
//constructor and destructor
Output(Socket::Connection & conn);
@ -66,7 +56,9 @@ namespace Mist {
virtual void sendNext() {}//REQUIRED! Others are optional.
virtual void prepareNext();
virtual void onRequest();
virtual bool onFinish(){return false;}
virtual bool onFinish() {
return false;
}
virtual void initialize();
virtual void sendHeader();
virtual void onFail();
@ -85,14 +77,6 @@ namespace Mist {
bool isBlocking;///< If true, indicates that myConn is blocking.
unsigned int crc;///< Checksum, if any, for usage in the stats.
unsigned int getKeyForTime(long unsigned int trackId, long long timeStamp);
IPC::sharedPage streamIndex;///< Shared memory used for metadata
std::map<int,IPC::sharedPage> indexPages;///< Maintains index pages of each track, holding information about available pages with DTSC packets.
std::map<int,IPC::sharedPage> curPages;///< Holds the currently used pages with DTSC packets for each track.
/// \todo Privitize keyTimes
IPC::sharedClient playerConn;///< Shared memory used for connection to MistIn process.
std::map<int,std::set<int> > keyTimes;///< Per-track list of keyframe times, for keyframe detection.
//static member for initialization
static Util::Config * config;///< Static, global configuration for the MistOut process
//stream delaying variables
unsigned int maxSkipAhead;///< Maximum ms that we will go ahead of the intended timestamps.
@ -101,26 +85,14 @@ namespace Mist {
//Read/write status variables
Socket::Connection & myConn;///< Connection to the client.
std::string streamName;///< Name of the stream that will be opened by initialize()
std::set<unsigned long> selectedTracks; ///< Tracks that are selected for playback
bool wantRequest;///< If true, waits for a request.
bool parseData;///< If true, triggers initalization if not already done, sending of header, sending of packets.
bool isInitialized;///< If false, triggers initialization if parseData is true.
bool sentHeader;///< If false, triggers sendHeader if parseData is true.
//Read-only stream data variables
DTSC::Packet currentPacket;///< The packet that is ready for sending now.
DTSC::Meta myMeta;///< Up to date stream metadata
//For pushing data through an output into the buffer process
void negotiateWithBuffer(int tid);
void negotiatePushTracks();
void bufferPacket(JSON::Value & pack);
DTSC::Meta meta_out;
std::deque<JSON::Value> preBuf;
std::map<int,int> trackMap;
std::map<int,DTSCPageData> bookKeeping;
};

View file

@ -163,14 +163,14 @@ namespace Mist {
}
void OutHDS::sendNext(){
if (currentPacket.getTime() >= playUntil){
if (thisPacket.getTime() >= playUntil){
DEBUG_MSG(DLVL_HIGH, "(%d) Done sending fragment", getpid() );
stop();
wantRequest = true;
H.Chunkify("", 0, myConn);
return;
}
tag.DTSCLoader(currentPacket, myMeta.tracks[currentPacket.getTrackId()]);
tag.DTSCLoader(thisPacket, myMeta.tracks[thisPacket.getTrackId()]);
H.Chunkify(tag.data, tag.len, myConn);
}

View file

@ -65,7 +65,7 @@ namespace Mist {
}
void OutHSS::sendNext() {
if (currentPacket.getTime() >= playUntil) {
if (thisPacket.getTime() >= playUntil) {
stop();
wantRequest = true;
H.Chunkify("", 0, myConn);
@ -74,7 +74,7 @@ namespace Mist {
}
char * dataPointer = 0;
unsigned int len = 0;
currentPacket.getString("data", dataPointer, len);
thisPacket.getString("data", dataPointer, len);
H.Chunkify(dataPointer, len, myConn);
}
@ -149,7 +149,13 @@ namespace Mist {
}
}
seek(seekTime);
playUntil = (*(keyTimes[tid].upper_bound(seekTime)));
///\todo Rewrite to fragments
for (std::deque<DTSC::Key>::iterator it2 = myMeta.tracks[tid].keys.begin(); it2 != myMeta.tracks[tid].keys.end(); it2++) {
if (it2->getTime() > seekTime){
playUntil = it2->getTime();
break;
}
}
myTrackStor = tid;
myKeyStor = seekTime;
keysToSend = 1;
@ -450,11 +456,6 @@ namespace Mist {
void OutHSS::initialize() {
Output::initialize();
for (std::map<unsigned int, DTSC::Track>::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++) {
for (std::deque<DTSC::Key>::iterator it2 = it->second.keys.begin(); it2 != it->second.keys.end(); it2++) {
keyTimes[it->first].insert(it2->getTime());
}
}
}
}

View file

@ -9,7 +9,7 @@ namespace Mist {
static void init(Util::Config * cfg);
void onHTTP();
void sendNext();
void initialize();
void initialize();/*LTS*/
void sendHeader();
protected:
JSON::Value encryption;

View file

@ -167,7 +167,7 @@ namespace Mist {
if (handler != capa["name"].asStringRef() || H.GetVar("stream") != streamName){
DEBUG_MSG(DLVL_MEDIUM, "Switching from %s (%s) to %s (%s)", capa["name"].asStringRef().c_str(), streamName.c_str(), handler.c_str(), H.GetVar("stream").c_str());
streamName = H.GetVar("stream");
playerConn.finish();
userClient.finish();
statsPage.finish();
reConnector(handler);
H.Clean();

View file

@ -26,7 +26,7 @@ namespace Mist {
}
first = false;
}
myConn.SendNow(currentPacket.toJSON().toString());
myConn.SendNow(thisPacket.toJSON().toString());
}
void OutJSON::sendHeader(){

View file

@ -31,7 +31,7 @@ namespace Mist {
}
void OutProgressiveFLV::sendNext(){
tag.DTSCLoader(currentPacket, myMeta.tracks[currentPacket.getTrackId()]);
tag.DTSCLoader(thisPacket, myMeta.tracks[thisPacket.getTrackId()]);
myConn.SendNow(tag.data, tag.len);
}

View file

@ -19,7 +19,7 @@ namespace Mist {
void OutProgressiveMP3::sendNext(){
char * dataPointer = 0;
unsigned int len = 0;
currentPacket.getString("data", dataPointer, len);
thisPacket.getString("data", dataPointer, len);
myConn.SendNow(dataPointer, len);
}

View file

@ -460,16 +460,16 @@ namespace Mist {
static bool perfect = true;
char * dataPointer = 0;
unsigned int len = 0;
currentPacket.getString("data", dataPointer, len);
if ((unsigned long)currentPacket.getTrackId() != sortSet.begin()->trackID || currentPacket.getTime() != sortSet.begin()->time){
if (currentPacket.getTime() >= sortSet.begin()->time || (unsigned long)currentPacket.getTrackId() >= sortSet.begin()->trackID){
thisPacket.getString("data", dataPointer, len);
if ((unsigned long)thisPacket.getTrackId() != sortSet.begin()->trackID || thisPacket.getTime() != sortSet.begin()->time){
if (thisPacket.getTime() >= sortSet.begin()->time || (unsigned long)thisPacket.getTrackId() >= sortSet.begin()->trackID){
if (perfect){
DEBUG_MSG(DLVL_WARN, "Warning: input is inconsistent. Expected %lu:%llu but got %ld:%llu - cancelling playback", sortSet.begin()->trackID, sortSet.begin()->time, currentPacket.getTrackId(), currentPacket.getTime());
DEBUG_MSG(DLVL_WARN, "Warning: input is inconsistent. Expected %lu:%llu but got %ld:%llu - cancelling playback", sortSet.begin()->trackID, sortSet.begin()->time, thisPacket.getTrackId(), thisPacket.getTime());
perfect = false;
myConn.close();
}
}else{
DEBUG_MSG(DLVL_HIGH, "Did not receive expected %lu:%llu but got %ld:%llu - throwing it away", sortSet.begin()->trackID, sortSet.begin()->time, currentPacket.getTrackId(), currentPacket.getTime());
DEBUG_MSG(DLVL_HIGH, "Did not receive expected %lu:%llu but got %ld:%llu - throwing it away", sortSet.begin()->trackID, sortSet.begin()->time, thisPacket.getTrackId(), thisPacket.getTime());
}
return;
}

View file

@ -27,43 +27,31 @@ namespace Mist {
}
void OutProgressiveOGG::sendNext(){
unsigned int track = currentPacket.getTrackId();
unsigned int track = thisPacket.getTrackId();
OGG::oggSegment newSegment;
currentPacket.getString("data", newSegment.dataString);
// if (currentPacket.getTime() > 315800){// && currentPacket.getTime() < 316200){
//INFO_MSG("Found a packet of time %llu, size: %d", currentPacket.getTime(), newSegment.dataString.size());
//}
pageBuffer[track].totalFrames = ((double)currentPacket.getTime() / (1000000.0f / myMeta.tracks[track].fpks)) + 1.5; //should start at 1. added .5 for rounding.
// INFO_MSG("track: %u totalFrames %llu timestamp: %llu totalframe value: %f", track, pageBuffer[track].totalFrames, currentPacket.getTime(), ((double)currentPacket.getTime() / (1000000.0f / myMeta.tracks[track].fpks)) + 1);
thisPacket.getString("data", newSegment.dataString);
pageBuffer[track].totalFrames = ((double)thisPacket.getTime() / (1000000.0f / myMeta.tracks[track].fpks)) + 1.5; //should start at 1. added .5 for rounding.
if (pageBuffer[track].codec == OGG::THEORA){
newSegment.isKeyframe = currentPacket.getFlag("keyframe");
newSegment.isKeyframe = thisPacket.getFlag("keyframe");
if (newSegment.isKeyframe == true){
pageBuffer[track].sendTo(myConn);//send data remaining in buffer (expected to fit on a page), keyframe will allways start on new page
// INFO_MSG("segments left in buffer: %d", pageBuffer[track].oggSegments.size());
pageBuffer[track].lastKeyFrame = pageBuffer[track].totalFrames;
}
newSegment.framesSinceKeyFrame = pageBuffer[track].totalFrames - pageBuffer[track].lastKeyFrame;
newSegment.lastKeyFrameSeen = pageBuffer[track].lastKeyFrame;
// theora::frame tmpFrame;
// tmpFrame.read(newSegment.dataString.data(),newSegment.dataString.size());
// INFO_MSG("FTYPE: %d ISKEYFRAME: %d",tmpFrame.getFTYPE(),newSegment.isKeyframe );
}
newSegment.frameNumber = pageBuffer[track].totalFrames;
newSegment.timeStamp = currentPacket.getTime();
newSegment.timeStamp = thisPacket.getTime();
pageBuffer[track].oggSegments.push_back(newSegment);
if (pageBuffer[track].codec == OGG::VORBIS){
pageBuffer[track].vorbisStuff();//this updates lastKeyFrame
}
// while (pageBuffer[track].oggSegments.size()){
//pageBuffer[track].sendTo(myConn);
//}
while (pageBuffer[track].shouldSend()){
pageBuffer[track].sendTo(myConn);
}

View file

@ -59,7 +59,7 @@ namespace Mist {
}
void OutRaw::sendNext(){
myConn.SendNow(currentPacket.getData(), currentPacket.getDataLen());
myConn.SendNow(thisPacket.getData(), thisPacket.getDataLen());
}
void OutRaw::sendHeader(){

View file

@ -89,7 +89,7 @@ namespace Mist {
pos = nextpos + 1;
}
if (trackSwitch){
seek(currentPacket.getTime());
seek(thisPacket.getTime());
}
}
@ -133,8 +133,8 @@ namespace Mist {
unsigned int dheader_len = 1;
char * tmpData = 0;//pointer to raw media data
unsigned int data_len = 0;//length of processed media data
currentPacket.getString("data", tmpData, data_len);
DTSC::Track & track = myMeta.tracks[currentPacket.getTrackId()];
thisPacket.getString("data", tmpData, data_len);
DTSC::Track & track = myMeta.tracks[thisPacket.getTrackId()];
//set msg_type_id
if (track.type == "video"){
@ -143,8 +143,8 @@ namespace Mist {
dheader_len += 4;
dataheader[0] = 7;
dataheader[1] = 1;
if (currentPacket.getInt("offset") > 0){
long long offset = currentPacket.getInt("offset");
if (thisPacket.getInt("offset") > 0){
long long offset = thisPacket.getInt("offset");
dataheader[2] = (offset >> 16) & 0xFF;
dataheader[3] = (offset >> 8) & 0xFF;
dataheader[4] = offset & 0xFF;
@ -153,12 +153,12 @@ namespace Mist {
if (track.codec == "H263"){
dataheader[0] = 2;
}
if (currentPacket.getFlag("keyframe")){
if (thisPacket.getFlag("keyframe")){
dataheader[0] |= 0x10;
}else{
dataheader[0] |= 0x20;
}
if (currentPacket.getFlag("disposableframe")){
if (thisPacket.getFlag("disposableframe")){
dataheader[0] |= 0x30;
}
}
@ -189,7 +189,7 @@ namespace Mist {
}
data_len += dheader_len;
unsigned int timestamp = currentPacket.getTime();
unsigned int timestamp = thisPacket.getTime();
bool allow_short = RTMPStream::lastsend.count(4);
RTMPStream::Chunk & prev = RTMPStream::lastsend[4];
@ -808,22 +808,43 @@ namespace Mist {
F.ChunkLoader(next);
JSON::Value pack_out = F.toJSON(meta_out);
if ( !pack_out.isNull()){
//Check for backwards timestamps
if (pack_out["time"].asInt() < meta_out.tracks[pack_out["trackid"].asInt()].lastms){
///Reset all internals
sending = false;
counter = 0;
preBuf.clear();
meta_out = DTSC::Meta();
pack_out = F.toJSON(meta_out);//Reinitialize the metadata with this packet.
///Reset negotiation with buffer
userClient.finish();
userClient = IPC::sharedClient(streamName + "_users", PLAY_EX_SIZE, true);
}
if ( !sending){
counter++;
if (counter > 8){
sending = true;
myMeta = meta_out;
negotiatePushTracks();
if (!userClient.getData()){
char userPageName[NAME_BUFFER_SIZE];
snprintf(userPageName, NAME_BUFFER_SIZE, SHM_USERS, streamName.c_str());
userClient = IPC::sharedClient(userPageName, 30, true);
}
for (std::map<unsigned int,DTSC::Track>::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++){
DEBUG_MSG(DLVL_MEDIUM, "Starting negotiation for track %d", it->first);
continueNegotiate(it->first);
}
//negotiatePushTracks();
for (std::deque<JSON::Value>::iterator it = preBuf.begin(); it != preBuf.end(); it++){
bufferPacket((*it));
bufferLivePacket((*it));
}
preBuf.clear(); //clear buffer
bufferPacket(pack_out);
bufferLivePacket(pack_out);
}else{
preBuf.push_back(pack_out);
}
}else{
bufferPacket(pack_out);
bufferLivePacket(pack_out);
}
}
break;

View file

@ -25,17 +25,17 @@ namespace Mist {
void OutProgressiveSRT::sendNext(){
char * dataPointer = 0;
unsigned int len = 0;
currentPacket.getString("data", dataPointer, len);
thisPacket.getString("data", dataPointer, len);
std::stringstream tmp;
if(!webVTT) {
tmp << lastNum++ << std::endl;
}
long long unsigned int time = currentPacket.getTime();
long long unsigned int time = thisPacket.getTime();
char tmpBuf[50];
int tmpLen = sprintf(tmpBuf, "%.2llu:%.2llu:%.2llu,%.3llu", (time / 3600000), ((time % 3600000) / 60000), (((time % 3600000) % 60000) / 1000), time % 1000);
tmp.write(tmpBuf, tmpLen);
tmp << " --> ";
time += currentPacket.getInt("duration");
time += thisPacket.getInt("duration");
tmpLen = sprintf(tmpBuf, "%.2llu:%.2llu:%.2llu,%.3llu", (time / 3600000), ((time % 3600000) / 60000), (((time % 3600000) % 60000) / 1000), time % 1000);
tmp.write(tmpBuf, tmpLen);
tmp << std::endl;

View file

@ -31,18 +31,18 @@ namespace Mist {
if (packData.getBytesFree() == 184){
packData.clear();
packData.setPID(0x100 - 1 + currentPacket.getTrackId());
packData.setPID(0x100 - 1 + thisPacket.getTrackId());
packData.setContinuityCounter(++contCounters[packData.getPID()]);
if (first[currentPacket.getTrackId()]){
if (first[thisPacket.getTrackId()]){
packData.setUnitStart(1);
packData.setDiscontinuity(true);
if (myMeta.tracks[currentPacket.getTrackId()].type == "video"){
if (currentPacket.getInt("keyframe")){
if (myMeta.tracks[thisPacket.getTrackId()].type == "video"){
if (thisPacket.getInt("keyframe")){
packData.setRandomAccess(1);
}
packData.setPCR(currentPacket.getTime() * 27000);
packData.setPCR(thisPacket.getTime() * 27000);
}
first[currentPacket.getTrackId()] = false;
first[thisPacket.getTrackId()] = false;
}
}
@ -53,11 +53,11 @@ namespace Mist {
}
void TSOutput::sendNext(){
first[currentPacket.getTrackId()] = true;
first[thisPacket.getTrackId()] = true;
char * dataPointer = 0;
unsigned int dataLen = 0;
currentPacket.getString("data", dataPointer, dataLen); //data
if (currentPacket.getTime() >= until){ //this if should only trigger for HLS
thisPacket.getString("data", dataPointer, dataLen); //data
if (thisPacket.getTime() >= until){ //this if should only trigger for HLS
stop();
wantRequest = true;
parseData = false;
@ -66,16 +66,16 @@ namespace Mist {
}
std::string bs;
//prepare bufferstring
if (myMeta.tracks[currentPacket.getTrackId()].type == "video"){
if (myMeta.tracks[thisPacket.getTrackId()].type == "video"){
unsigned int extraSize = 0;
//dataPointer[4] & 0x1f is used to check if this should be done later: fillPacket("\000\000\000\001\011\360", 6);
if (myMeta.tracks[currentPacket.getTrackId()].codec == "H264" && (dataPointer[4] & 0x1f) != 0x09){
if (myMeta.tracks[thisPacket.getTrackId()].codec == "H264" && (dataPointer[4] & 0x1f) != 0x09){
extraSize += 6;
}
if (currentPacket.getInt("keyframe")){
if (myMeta.tracks[currentPacket.getTrackId()].codec == "H264"){
if (thisPacket.getInt("keyframe")){
if (myMeta.tracks[thisPacket.getTrackId()].codec == "H264"){
if (!haveAvcc){
avccbox.setPayload(myMeta.tracks[currentPacket.getTrackId()].init);
avccbox.setPayload(myMeta.tracks[thisPacket.getTrackId()].init);
haveAvcc = true;
}
bs = avccbox.asAnnexB();
@ -91,16 +91,16 @@ namespace Mist {
while (currPack <= splitCount){
unsigned int alreadySent = 0;
bs = TS::Packet::getPESVideoLeadIn((currPack != splitCount ? watKunnenWeIn1Ding : dataLen+extraSize - currPack*watKunnenWeIn1Ding), currentPacket.getTime() * 90, currentPacket.getInt("offset") * 90, !currPack);
bs = TS::Packet::getPESVideoLeadIn((currPack != splitCount ? watKunnenWeIn1Ding : dataLen+extraSize - currPack*watKunnenWeIn1Ding), thisPacket.getTime() * 90, thisPacket.getInt("offset") * 90, !currPack);
fillPacket(bs.data(), bs.size());
if (!currPack){
if (myMeta.tracks[currentPacket.getTrackId()].codec == "H264" && (dataPointer[4] & 0x1f) != 0x09){
if (myMeta.tracks[thisPacket.getTrackId()].codec == "H264" && (dataPointer[4] & 0x1f) != 0x09){
//End of previous nal unit, if not already present
fillPacket("\000\000\000\001\011\360", 6);
alreadySent += 6;
}
if (currentPacket.getInt("keyframe")){
if (myMeta.tracks[currentPacket.getTrackId()].codec == "H264"){
if (thisPacket.getInt("keyframe")){
if (myMeta.tracks[thisPacket.getTrackId()].codec == "H264"){
bs = avccbox.asAnnexB();
fillPacket(bs.data(), bs.size());
alreadySent += bs.size();
@ -137,32 +137,32 @@ namespace Mist {
if (alreadySent == watKunnenWeIn1Ding){
packData.addStuffing();
fillPacket(0, 0);
first[currentPacket.getTrackId()] = true;
first[thisPacket.getTrackId()] = true;
break;
}
}
currPack++;
}
}else if (myMeta.tracks[currentPacket.getTrackId()].type == "audio"){
}else if (myMeta.tracks[thisPacket.getTrackId()].type == "audio"){
long unsigned int tempLen = dataLen;
if ( myMeta.tracks[currentPacket.getTrackId()].codec == "AAC"){
if ( myMeta.tracks[thisPacket.getTrackId()].codec == "AAC"){
tempLen += 7;
}
long long unsigned int tempTime;
if (appleCompat){
tempTime = 0;// myMeta.tracks[currentPacket.getTrackId()].rate / 1000;
tempTime = 0;// myMeta.tracks[thisPacket.getTrackId()].rate / 1000;
}else{
tempTime = currentPacket.getTime() * 90;
tempTime = thisPacket.getTime() * 90;
}
///\todo stuur 70ms aan audio per PES pakket om applecompat overbodig te maken.
//static unsigned long long lastSent=currentPacket.getTime() * 90;
//if( (currentPacket.getTime() * 90)-lastSent >= 70*90 ){
// lastSent=(currentPacket.getTime() * 90);
//static unsigned long long lastSent=thisPacket.getTime() * 90;
//if( (thisPacket.getTime() * 90)-lastSent >= 70*90 ){
// lastSent=(thisPacket.getTime() * 90);
//}
bs = TS::Packet::getPESAudioLeadIn(tempLen, tempTime);// myMeta.tracks[currentPacket.getTrackId()].rate / 1000 );
bs = TS::Packet::getPESAudioLeadIn(tempLen, tempTime);// myMeta.tracks[thisPacket.getTrackId()].rate / 1000 );
fillPacket(bs.data(), bs.size());
if (myMeta.tracks[currentPacket.getTrackId()].codec == "AAC"){
bs = TS::getAudioHeader(dataLen, myMeta.tracks[currentPacket.getTrackId()].init);
if (myMeta.tracks[thisPacket.getTrackId()].codec == "AAC"){
bs = TS::getAudioHeader(dataLen, myMeta.tracks[thisPacket.getTrackId()].init);
fillPacket(bs.data(), bs.size());
}
fillPacket(dataPointer,dataLen);