From af4caded70a8e2bc9f355eeb98a848b8e200c95e Mon Sep 17 00:00:00 2001 From: Thulinma Date: Mon, 11 Feb 2013 12:43:02 +0100 Subject: [PATCH] Fixed handling of stuffing bytes in TS packets. --- lib/ts_packet.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/ts_packet.cpp b/lib/ts_packet.cpp index 83289d95..24b95d7a 100644 --- a/lib/ts_packet.cpp +++ b/lib/ts_packet.cpp @@ -323,19 +323,23 @@ void TS::Packet::AddStuffing(int NumBytes){ return; } if (AdaptationField() == 3){ - int Offset = strBuf[4]; - strBuf[4] = Offset + NumBytes - 1; - strBuf.resize(5 + Offset + NumBytes - 2); - for (int i = 0; i < (NumBytes - 2); i++){ - strBuf[5 + Offset + i] = FILLER_DATA[i % sizeof(FILLER_DATA)]; + strBuf.resize(5 + strBuf[4]); + strBuf[4] += NumBytes; + for (int i = 0; i < NumBytes; i++){ + strBuf.append(FILLER_DATA + (i % sizeof(FILLER_DATA)), 1); } }else{ AdaptationField(3); - strBuf.resize(6); - strBuf[4] = (char)(NumBytes - 1); - strBuf[5] = (char)0x00; - for (int i = 0; i < (NumBytes - 2); i++){ - strBuf += FILLER_DATA[i % sizeof(FILLER_DATA)]; + if (NumBytes > 1){ + strBuf.resize(6); + strBuf[4] = (char)(NumBytes - 1); + strBuf[5] = (char)0x00; + for (int i = 0; i < (NumBytes - 2); i++){ + strBuf += FILLER_DATA[i % sizeof(FILLER_DATA)]; + } + }else{ + strBuf.resize(5); + strBuf[4] = (char)(NumBytes - 1); } } }