Fixed TS-output (=HLS) related SIGABRT problem

This commit is contained in:
Thulinma 2018-11-01 16:25:10 +01:00
parent 24006648f9
commit 425e98c6fd
2 changed files with 86 additions and 79 deletions

View file

@ -1,9 +1,9 @@
#include "output_ts_base.h"
#include <mist/bitfields.h>
namespace Mist {
TSOutput::TSOutput(Socket::Connection & conn) : TS_BASECLASS(conn){
packCounter=0;
haveAvcc = false;
ts_from = 0;
setBlocking(true);
sendRepeatingHeaders = 0;
@ -48,7 +48,7 @@ namespace Mist {
}
}
int tmp = packData.fillFree(data, dataLen);
size_t tmp = packData.fillFree(data, dataLen);
data += tmp;
dataLen -= tmp;
} while(dataLen);
@ -67,8 +67,9 @@ namespace Mist {
firstPack = true;
char * dataPointer = 0;
unsigned int dataLen = 0;
thisPacket.getString("data", dataPointer, dataLen); //data
unsigned int tmpDataLen = 0;
thisPacket.getString("data", dataPointer, tmpDataLen); //data
uint64_t dataLen = tmpDataLen;
//apple compatibility timestamp correction
if (appleCompat){
packTime -= ts_from;
@ -80,6 +81,7 @@ namespace Mist {
std::string bs;
//prepare bufferstring
if (video){
if (Trk.codec == "H264"){
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 (Trk.codec == "H264" && (dataPointer[4] & 0x1f) != 0x09){
@ -87,10 +89,8 @@ namespace Mist {
}
if (keyframe){
if (Trk.codec == "H264"){
if (!haveAvcc){
MP4::AVCC avccbox;
avccbox.setPayload(Trk.init);
haveAvcc = true;
}
bs = avccbox.asAnnexB();
extraSize += bs.size();
}
@ -99,7 +99,7 @@ namespace Mist {
unsigned int watKunnenWeIn1Ding = 65490-13;
unsigned int splitCount = (dataLen+extraSize) / watKunnenWeIn1Ding;
unsigned int currPack = 0;
unsigned int ThisNaluSize = 0;
uint64_t ThisNaluSize = 0;
unsigned int i = 0;
unsigned int nalLead = 0;
uint64_t offset = thisPacket.getInt("offset") * 90;
@ -116,6 +116,8 @@ namespace Mist {
}
if (keyframe){
if (Trk.codec == "H264"){
MP4::AVCC avccbox;
avccbox.setPayload(Trk.init);
bs = avccbox.asAnnexB();
fillPacket(bs.data(), bs.size(), firstPack, video, keyframe, pkgPid, contPkg);
alreadySent += bs.size();
@ -130,9 +132,9 @@ namespace Mist {
nalLead = 0;
}
if (!ThisNaluSize){
ThisNaluSize = (dataPointer[i] << 24) + (dataPointer[i+1] << 16) + (dataPointer[i+2] << 8) + dataPointer[i+3];
if (ThisNaluSize + i + 4 > (unsigned int)dataLen){
DEBUG_MSG(DLVL_WARN, "Too big NALU detected (%u > %d) - skipping!", ThisNaluSize + i + 4, dataLen);
ThisNaluSize = Bit::btohl(dataPointer + i);
if (ThisNaluSize + i + 4 > dataLen){
WARN_MSG("Too big NALU detected (%" PRIu64 " > %" PRIu64 ") - skipping!", ThisNaluSize + i + 4, dataLen);
break;
}
if (alreadySent + 4 > watKunnenWeIn1Ding){
@ -166,12 +168,19 @@ namespace Mist {
}
currPack++;
}
}else{
uint64_t offset = thisPacket.getInt("offset") * 90;
bs = TS::Packet::getPESVideoLeadIn(0, packTime, offset, true, Trk.bps);
fillPacket(bs.data(), bs.size(), firstPack, video, keyframe, pkgPid, contPkg);
fillPacket(dataPointer, dataLen, firstPack, video, keyframe, pkgPid, contPkg);
}
}else if (Trk.type == "audio"){
long unsigned int tempLen = dataLen;
if (Trk.codec == "AAC"){
tempLen += 7;
}
bs = TS::Packet::getPESAudioLeadIn(tempLen, packTime, Trk.bps);// myMeta.tracks[thisPacket.getTrackId()].rate / 1000 );
bs = TS::Packet::getPESAudioLeadIn(tempLen, packTime, Trk.bps);
fillPacket(bs.data(), bs.size(), firstPack, video, keyframe, pkgPid, contPkg);
if (Trk.codec == "AAC"){
bs = TS::getAudioHeader(dataLen, Trk.init);

View file

@ -25,8 +25,6 @@ namespace Mist {
int contSDT;
unsigned int packCounter; ///\todo update constructors?
TS::Packet packData;
bool haveAvcc;
MP4::AVCC avccbox;
bool appleCompat;
uint64_t sendRepeatingHeaders; ///< Amount of ms between PAT/PMT. Zero means do not repeat.
uint64_t lastHeaderTime; ///< Timestamp last PAT/PMT were sent.