void TSOutput::fillPacket(const char * data, const size_t dataLen){ if (!packData.getBytesFree()){ ///\todo only resend the PAT/PMT for HLS if ( (sendRepeatingHeaders && packCounter % 42 == 0) || !packCounter){ TS::Packet tmpPack; tmpPack.FromPointer(TS::PAT); tmpPack.setContinuityCounter(++contCounters[0]); sendTS(tmpPack.checkAndGetBuffer()); sendTS(TS::createPMT(selectedTracks, myMeta, ++contCounters[4096])); packCounter += 2; } sendTS(packData.checkAndGetBuffer()); packCounter ++; packData.clear(); } if (!dataLen){return;} if (packData.getBytesFree() == 184){ packData.clear(); packData.setPID(thisPacket.getTrackId()); packData.setContinuityCounter(++contCounters[packData.getPID()]); if (first[thisPacket.getTrackId()]){ packData.setUnitStart(1); packData.setDiscontinuity(true); if (myMeta.tracks[thisPacket.getTrackId()].type == "video"){ if (thisPacket.getInt("keyframe")){ packData.setRandomAccess(1); } packData.setPCR(thisPacket.getTime() * 27000); } first[thisPacket.getTrackId()] = false; } } int tmp = packData.fillFree(data, dataLen); if (tmp != dataLen){ return fillPacket(data+tmp, dataLen-tmp); } }
void TSOutput::fillPacket(char const * data, size_t dataLen, bool & firstPack, bool video, bool keyframe, uint32_t pkgPid, int & contPkg){ do { if (!packData.getBytesFree()){ if ( (sendRepeatingHeaders && packCounter % 42 == 0) || !packCounter){ TS::Packet tmpPack; tmpPack.FromPointer(TS::PAT); tmpPack.setContinuityCounter(++contPAT); sendTS(tmpPack.checkAndGetBuffer()); sendTS(TS::createPMT(selectedTracks, myMeta, ++contPMT)); packCounter += 2; } sendTS(packData.checkAndGetBuffer()); packCounter ++; packData.clear(); } if (!dataLen){return;} if (packData.getBytesFree() == 184){ packData.clear(); packData.setPID(pkgPid); packData.setContinuityCounter(++contPkg); if (firstPack){ packData.setUnitStart(1); if (video){ if (keyframe){ packData.setRandomAccess(true); packData.setESPriority(true); } packData.setPCR(thisPacket.getTime() * 27000); } firstPack = false; } } int tmp = packData.fillFree(data, dataLen); data += tmp; dataLen -= tmp; } while(dataLen); }