Ticket #565: offset.diff
File offset.diff, 4.0 KB (added by , 18 years ago) |
---|
-
pespacket.cpp
9 9 10 10 using namespace std; 11 11 12 static inline uint calcOffset(uint cnt)13 {14 return (cnt * TSPacket::PAYLOAD_SIZE) + TSPacket::HEADER_SIZE;15 }16 17 12 // return true if complete or broken 18 13 bool PESPacket::AddTSPacket(const TSPacket* packet) 19 14 { … … 33 28 34 29 const int cc = packet->ContinuityCounter(); 35 30 const int ccExp = (_ccLast + 1) & 0xf; 31 32 uint payloadSize; 33 uint payloadStart; 34 35 // If the next TS has an offset, we need to strip it out. 36 // The offset will be used when a new PESPacket is created. 37 if (packet->PayloadStart()) 38 { 39 payloadSize = TSPacket::PAYLOAD_SIZE - 1; 40 payloadStart = TSPacket::HEADER_SIZE + 1; 41 } 42 else 43 { 44 payloadSize = TSPacket::PAYLOAD_SIZE; 45 payloadStart = TSPacket::HEADER_SIZE; 46 } 47 36 48 if (ccExp == cc) 37 49 { 38 if ( calcOffset(_cnt+1)>= _allocSize)50 if (_pesdataSize + payloadSize >= _allocSize) 39 51 { 40 52 uint sz = (((_allocSize * 2) + 4095) / 4096) * 4096; 41 53 unsigned char *nbuf = pes_alloc(sz); 42 memcpy(nbuf, _fullbuffer, _ allocSize);54 memcpy(nbuf, _fullbuffer, _pesdataSize); 43 55 pes_free(_fullbuffer); 44 56 _fullbuffer = nbuf; 45 57 _allocSize = sz; 46 58 } 47 memcpy(_fullbuffer + calcOffset(_cnt),48 packet->data() + TSPacket::HEADER_SIZE,49 TSPacket::PAYLOAD_SIZE);50 59 60 memcpy(_fullbuffer + _pesdataSize, 61 packet->data() + payloadStart, 62 payloadSize); 63 51 64 _ccLast = cc; 52 _ cnt++;65 _pesdataSize += payloadSize; 53 66 } 54 67 else if (int(_ccLast) == cc) 55 68 { … … 62 75 return true; 63 76 } 64 77 65 if ( calcOffset(_cnt)>= tlen)78 if (_pesdataSize >= tlen) 66 79 { 67 80 if (CalcCRC()==CRC()) 68 81 { -
pespacket.h
49 49 protected: 50 50 // does not create it's own data 51 51 PESPacket(const TSPacket* tspacket, bool) 52 : _pesdata(0), _fullbuffer(0), _allocSize(0) 52 : _pesdata(0), _fullbuffer(0), _allocSize(0), _pesdataSize(188) 53 53 { 54 54 InitPESPacket(const_cast<TSPacket&>(*tspacket)); 55 55 _fullbuffer = const_cast<unsigned char*>(tspacket->data()); … … 64 64 PESPacket(const PESPacket& pkt) 65 65 : _pesdata(0), 66 66 _psiOffset(pkt._psiOffset), 67 _ccLast(pkt._ccLast), _cnt(pkt._cnt),67 _ccLast(pkt._ccLast), 68 68 _allocSize((pkt._allocSize) ? pkt._allocSize : 188), 69 _pesdataSize(pkt._pesdataSize), 69 70 _badPacket(pkt._badPacket) 70 71 { // clone 71 72 _fullbuffer = pes_alloc(_allocSize); … … 75 76 76 77 // may be modified 77 78 PESPacket(const TSPacket& tspacket) 78 : _ccLast(tspacket.ContinuityCounter()), _ cnt(1)79 : _ccLast(tspacket.ContinuityCounter()), _pesdataSize(188) 79 80 { // clone 80 81 InitPESPacket(const_cast<TSPacket&>(tspacket)); // sets _psiOffset 81 82 … … 118 119 unsigned int Length() const 119 120 { return (pesdata()[2] & 0x0f) << 8 | pesdata()[3]; } 120 121 121 unsigned int TSSizeInBuffer() const 122 { return (_cnt * TSPacket::PAYLOAD_SIZE) + TSPacket::HEADER_SIZE; } 122 unsigned int TSSizeInBuffer() const { return _pesdataSize; } 123 123 unsigned int PSIOffset() const { return _psiOffset; } 124 124 125 125 const unsigned char* pesdata() const { return _pesdata; } … … 188 188 private: 189 189 uint _psiOffset; ///< AFCOffset + StartOfFieldPointer 190 190 uint _ccLast; ///< Continuity counter of last inserted TS Packet 191 uint _cnt; ///< Number of tspackets contained in PES Packet192 191 uint _allocSize; ///< number of bytes we allocated 192 uint _pesdataSize; ///< Number of bytes containing PES data 193 193 bool _badPacket; ///< true if a CRC is not good yet 194 194 }; 195 195