Ticket #2147: pes_assembler_fixes.diff

File pes_assembler_fixes.diff, 4.1 KB (added by Janne <janne-mythtv@…>, 13 years ago)
  • libs/libmythtv/mpeg/pespacket.cpp

    old new using namespace std; 
    2020// return true if complete or broken
    2121bool PESPacket::AddTSPacket(const TSPacket* packet)
    2222{
    23     // +3 = first 3 bytes of pespacket header, not included in Length()
    24     uint tlen = Length() + (_pesdata - _fullbuffer) +3;
    25 
    2623    if (!tsheader()->PayloadStart())
    2724    {
    2825        VERBOSE(VB_RECORD, "Error: We started a PES packet, "
    bool PESPacket::AddTSPacket(const TSPack 
    7572    else
    7673    {
    7774        VERBOSE(VB_RECORD, "AddTSPacket: Out of sync!!! "
    78                 "Need to wait for next payloadStart");
     75                "Need to wait for next payloadStart" +
     76                QString(" PID: 0x%1, continuity counter: %2 (expected %3).")
     77                .arg(packet->PID(),0,16).arg(cc).arg(ccExp));
    7978        return true;
    8079    }
    8180
    82     if (_pesdataSize >= tlen)
     81    // check if it's safe to call Length
     82    if ((_psiOffset + 1 + 3) <=  _pesdataSize)
    8383    {
    84         _badPacket = !VerifyCRC();
    85         return true;
     84        // +3 = first 3 bytes of pespacket header, not included in Length()
     85        uint tlen = Length() + (_pesdata - _fullbuffer) +3;
     86
     87        if (_pesdataSize >= tlen)
     88        {
     89            _badPacket = !VerifyCRC();
     90            return true;
     91        }
    8692    }
    8793
    8894    return false;
  • libs/libmythtv/mpeg/mpegstreamdata.cpp

    old new PSIPTable* MPEGStreamData::AssemblePSIP( 
    204204    PESPacket* partial = GetPartialPES(tspacket->PID());
    205205    if (partial && partial->AddTSPacket(tspacket))
    206206    {
     207        // check if it's safe to read pespacket's Length()
     208        if ((partial->PSIOffset() + 1 + 3) > partial->TSSizeInBuffer())
     209        {
     210            VERBOSE(VB_RECORD,
     211                    QString("Discarding broken PES packet. Packet's length at "
     212                            "position %1 isn't in the buffer of %2 bytes.")
     213                    .arg(partial->PSIOffset() + 1 + 3)
     214                    .arg(partial->TSSizeInBuffer()));
     215            DeletePartialPES(tspacket->PID());
     216            return NULL;
     217        }
     218
    207219        // Discard broken packets
    208220        bool buggy = _have_CRC_bug &&
    209221        ((TableID::PMT == partial->StreamID()) ||
    PSIPTable* MPEGStreamData::AssemblePSIP( 
    242254                return psip;
    243255            }
    244256        }
     257        // discard incomplete packets
     258        if (packetStart > partial->TSSizeInBuffer())
     259        {
     260            VERBOSE(VB_RECORD,
     261                    QString("Discarding broken PES packet. Packet with %1 bytes"
     262                            " doesn't fit into a buffer of %2 bytes.")
     263                    .arg(packetStart).arg(partial->TSSizeInBuffer()));
     264            delete psip;
     265            psip = NULL;
     266        }
    245267
    246268        moreTablePackets = false;
    247269        DeletePartialPES(tspacket->PID());
    PSIPTable* MPEGStreamData::AssemblePSIP( 
    275297
    276298    const unsigned char* pesdata = tspacket->data() + offset;
    277299    const int pes_length = (pesdata[2] & 0x0f) << 8 | pesdata[3];
    278     const PESPacket pes = PESPacket::View(*tspacket);
    279300    if ((pes_length + offset + extra_offset) > 188)
    280301    {
    281302        SavePartialPES(tspacket->PID(), new PESPacket(*tspacket));
  • libs/libmythtv/mpeg/pespacket.h

    old new class PESPacket 
    3030            VERBOSE(VB_IMPORTANT, "Started PESPacket, but !payloadStart()");
    3131            _psiOffset = tspacket.AFCOffset();
    3232        }
    33         _pesdata = tspacket.data() + tspacket.AFCOffset() + 1;
     33        _pesdata = tspacket.data() + _psiOffset + 1;
    3434
    3535        _badPacket = true;
    3636        // first check if Length() will return something useful and