Optimized TS and HLS

This commit is contained in:
Erik Zandvliet 2014-08-27 13:34:47 +02:00
parent e34bb0b14e
commit 194d1ae9a3
2 changed files with 37 additions and 25 deletions

View file

@ -528,39 +528,51 @@ namespace TS {
/// \param maxLen The maximum amount of bytes to store. /// \param maxLen The maximum amount of bytes to store.
int Packet::FillFree(const char * NewVal, int maxLen) { int Packet::FillFree(const char * NewVal, int maxLen) {
int toWrite = std::min((int)BytesFree(), maxLen); int toWrite = std::min((int)BytesFree(), maxLen);
strBuf += std::string(NewVal, toWrite); strBuf.append(NewVal, toWrite);
return toWrite; return toWrite;
} }
/// Adds stuffing to the Packet depending on how much content you want to send. /// Adds stuffing to the Packet depending on how much content you want to send.
/// \param NumBytes the amount of non-stuffing content bytes you want to send. /// \param NumBytes the amount of non-stuffing content bytes you want to send.
/// \return The amount of content bytes that can be send. /// \return The amount of content bytes that can be send.
unsigned int Packet::AddStuffing(int NumBytes) { void Packet::AddStuffing() {
if (BytesFree() <= NumBytes) { int numBytes = BytesFree();
return BytesFree(); if (!numBytes) {
return;
} }
NumBytes = BytesFree() - NumBytes;
if (AdaptationField() == 3) { if (AdaptationField() == 2){
strBuf.resize(5 + strBuf[4]); FAIL_MSG("Can not handle adaptation field 2");
strBuf[4] += NumBytes; return;
for (int i = 0; i < NumBytes; i++) { }
strBuf.append(FILLER_DATA[i % sizeof(FILLER_DATA)], 0);
}
} else { if (AdaptationField() == 1){
//Convert adaptationfield to 3
strBuf.insert(4, 1, (char)0);
AdaptationField(3); AdaptationField(3);
if (NumBytes > 1) { numBytes --;
strBuf.resize(6); }
strBuf[4] = (char)(NumBytes - 1);
strBuf[5] = (char)0x00; if (AdaptationField() == 3 && numBytes ) {
for (int i = 0; i < (NumBytes - 2); i++) { if (strBuf[4] == 0){
strBuf += FILLER_DATA[i % sizeof(FILLER_DATA)]; strBuf.insert(5, numBytes, '$');
} }else{
} else { strBuf.insert(6 + strBuf[4], numBytes, '$');
strBuf.resize(5); }
strBuf[4] = (char)(NumBytes - 1); strBuf[4] += numBytes;
}
if (numBytes){
if (numBytes == strBuf[4]){
strBuf[5] = 0x00;
numBytes --;
}
for (int i = 0; i < numBytes; i++) {
strBuf[5+(strBuf[4] - numBytes)+i] = FILLER_DATA[i % sizeof(FILLER_DATA)];
} }
} }
return BytesFree();
} }
///Gets the string buffer, containing the raw packet data as a string ///Gets the string buffer, containing the raw packet data as a string

View file

@ -85,7 +85,7 @@ namespace TS {
void FillFree(std::string & PackageData); void FillFree(std::string & PackageData);
int FillFree(const char * PackageData, int maxLen); int FillFree(const char * PackageData, int maxLen);
unsigned int AddStuffing(int NumBytes); void AddStuffing();
protected: protected:
std::string strBuf;///<The actual data std::string strBuf;///<The actual data
//char Buffer[188];///< The actual data //char Buffer[188];///< The actual data