int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
                     const uint8_t *buf, int len)
{
    unsigned int ssrc, h;
    int payload_type, seq, ret, flags = 0;
    AVStream *st;
    uint32_t timestamp;
    int rv= 0;
    if (!buf) {
        if(s->st && s->parse_packet) {
            timestamp = RTP_NOTS_VALUE;
            rv= s->parse_packet(s->ic, s->dynamic_protocol_context,
                                s->st, pkt, &timestamp, NULL, 0, flags);
            finalize_packet(s, pkt, timestamp);
            return rv;
        } else {
            if (s->read_buf_index >= s->read_buf_size)
                return -1;
            ret = ff_mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index,
                                      s->read_buf_size - s->read_buf_index);
            if (ret < 0)
                return -1;
            s->read_buf_index += ret;
            if (s->read_buf_index < s->read_buf_size)
                return 1;
            else
                return 0;
        }
    }
    if (len < 12)
        return -1;
    if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
        return -1;
    if (buf[1] >= RTCP_SR && buf[1] <= RTCP_APP) {
        return rtcp_parse_packet(s, buf, len);
    }
    payload_type = buf[1] & 0x7f;
    if (buf[1] & 0x80)
        flags |= RTP_FLAG_MARKER;
    seq  = AV_RB16(buf + 2);
    timestamp = AV_RB32(buf + 4);
    ssrc = AV_RB32(buf + 8);
    s->ssrc = ssrc;
    if (s->payload_type != payload_type)
        return -1;
    st = s->st;
    if(!rtp_valid_packet_in_sequence(&s->statistics, seq))
    {
        av_log(st?st->codec:NULL, AV_LOG_ERROR, "RTP: PT=%02x: bad cseq %04x expected=%04x\n",
               payload_type, seq, ((s->seq + 1) & 0xffff));
        return -1;
    }
    s->seq = seq;
    len -= 12;
    buf += 12;
    if (!st) {
        ret = ff_mpegts_parse_packet(s->ts, pkt, buf, len);
        if (ret < 0)
            return -1;
        if (ret < len) {
            s->read_buf_size = len - ret;
            memcpy(s->buf, buf + ret, s->read_buf_size);
            s->read_buf_index = 0;
            return 1;
        }
        return 0;
    } else if (s->parse_packet) {
        rv = s->parse_packet(s->ic, s->dynamic_protocol_context,
                             s->st, pkt, &timestamp, buf, len, flags);
    } else {
        switch(st->codec->codec_id) {
        case CODEC_ID_MP2:
        case CODEC_ID_MP3:
            if (len <= 4)
                return -1;
            h = AV_RB32(buf);
            len -= 4;
            buf += 4;
            av_new_packet(pkt, len);
            memcpy(pkt->data, buf, len);
            break;
        case CODEC_ID_MPEG1VIDEO:
        case CODEC_ID_MPEG2VIDEO:
            if (len <= 4)
                return -1;
            h = AV_RB32(buf);
            buf += 4;
            len -= 4;
            if (h & (1 << 26)) {
                if (len <= 4)
                    return -1;
                buf += 4;
                len -= 4;
            }
            av_new_packet(pkt, len);
            memcpy(pkt->data, buf, len);
            break;
        default:
            av_new_packet(pkt, len);
            memcpy(pkt->data, buf, len);
            break;
        }
        pkt->stream_index = st->index;
    }
    finalize_packet(s, pkt, timestamp);
    return rv;
}
['int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,\n                     const uint8_t *buf, int len)\n{\n    unsigned int ssrc, h;\n    int payload_type, seq, ret, flags = 0;\n    AVStream *st;\n    uint32_t timestamp;\n    int rv= 0;\n    if (!buf) {\n        if(s->st && s->parse_packet) {\n            timestamp = RTP_NOTS_VALUE;\n            rv= s->parse_packet(s->ic, s->dynamic_protocol_context,\n                                s->st, pkt, &timestamp, NULL, 0, flags);\n            finalize_packet(s, pkt, timestamp);\n            return rv;\n        } else {\n            if (s->read_buf_index >= s->read_buf_size)\n                return -1;\n            ret = ff_mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index,\n                                      s->read_buf_size - s->read_buf_index);\n            if (ret < 0)\n                return -1;\n            s->read_buf_index += ret;\n            if (s->read_buf_index < s->read_buf_size)\n                return 1;\n            else\n                return 0;\n        }\n    }\n    if (len < 12)\n        return -1;\n    if ((buf[0] & 0xc0) != (RTP_VERSION << 6))\n        return -1;\n    if (buf[1] >= RTCP_SR && buf[1] <= RTCP_APP) {\n        return rtcp_parse_packet(s, buf, len);\n    }\n    payload_type = buf[1] & 0x7f;\n    if (buf[1] & 0x80)\n        flags |= RTP_FLAG_MARKER;\n    seq  = AV_RB16(buf + 2);\n    timestamp = AV_RB32(buf + 4);\n    ssrc = AV_RB32(buf + 8);\n    s->ssrc = ssrc;\n    if (s->payload_type != payload_type)\n        return -1;\n    st = s->st;\n    if(!rtp_valid_packet_in_sequence(&s->statistics, seq))\n    {\n        av_log(st?st->codec:NULL, AV_LOG_ERROR, "RTP: PT=%02x: bad cseq %04x expected=%04x\\n",\n               payload_type, seq, ((s->seq + 1) & 0xffff));\n        return -1;\n    }\n    s->seq = seq;\n    len -= 12;\n    buf += 12;\n    if (!st) {\n        ret = ff_mpegts_parse_packet(s->ts, pkt, buf, len);\n        if (ret < 0)\n            return -1;\n        if (ret < len) {\n            s->read_buf_size = len - ret;\n            memcpy(s->buf, buf + ret, s->read_buf_size);\n            s->read_buf_index = 0;\n            return 1;\n        }\n        return 0;\n    } else if (s->parse_packet) {\n        rv = s->parse_packet(s->ic, s->dynamic_protocol_context,\n                             s->st, pkt, &timestamp, buf, len, flags);\n    } else {\n        switch(st->codec->codec_id) {\n        case CODEC_ID_MP2:\n        case CODEC_ID_MP3:\n            if (len <= 4)\n                return -1;\n            h = AV_RB32(buf);\n            len -= 4;\n            buf += 4;\n            av_new_packet(pkt, len);\n            memcpy(pkt->data, buf, len);\n            break;\n        case CODEC_ID_MPEG1VIDEO:\n        case CODEC_ID_MPEG2VIDEO:\n            if (len <= 4)\n                return -1;\n            h = AV_RB32(buf);\n            buf += 4;\n            len -= 4;\n            if (h & (1 << 26)) {\n                if (len <= 4)\n                    return -1;\n                buf += 4;\n                len -= 4;\n            }\n            av_new_packet(pkt, len);\n            memcpy(pkt->data, buf, len);\n            break;\n        default:\n            av_new_packet(pkt, len);\n            memcpy(pkt->data, buf, len);\n            break;\n        }\n        pkt->stream_index = st->index;\n    }\n    finalize_packet(s, pkt, timestamp);\n    return rv;\n}', 'static av_always_inline av_const uint16_t av_bswap16(uint16_t x)\n{\n    x= (x>>8) | (x<<8);\n    return x;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n    x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n    x= (x>>16) | (x<<16);\n    return x;\n}', 'static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq)\n{\n    uint16_t udelta= seq - s->max_seq;\n    const int MAX_DROPOUT= 3000;\n    const int MAX_MISORDER = 100;\n    const int MIN_SEQUENTIAL = 2;\n    if(s->probation)\n    {\n        if(seq==s->max_seq + 1) {\n            s->probation--;\n            s->max_seq= seq;\n            if(s->probation==0) {\n                rtp_init_sequence(s, seq);\n                s->received++;\n                return 1;\n            }\n        } else {\n            s->probation= MIN_SEQUENTIAL - 1;\n            s->max_seq = seq;\n        }\n    } else if (udelta < MAX_DROPOUT) {\n        if(seq < s->max_seq) {\n            s->cycles += RTP_SEQ_MOD;\n        }\n        s->max_seq= seq;\n    } else if (udelta <= RTP_SEQ_MOD - MAX_MISORDER) {\n        if(seq==s->bad_seq) {\n            rtp_init_sequence(s, seq);\n        } else {\n            s->bad_seq= (seq + 1) & (RTP_SEQ_MOD-1);\n            return 0;\n        }\n    } else {\n    }\n    s->received++;\n    return 1;\n}', 'int av_new_packet(AVPacket *pkt, int size)\n{\n    uint8_t *data= NULL;\n    if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n        data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n    if (data){\n        memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n    }else\n        size=0;\n    av_init_packet(pkt);\n    pkt->data = data;\n    pkt->size = size;\n    pkt->destruct = av_destruct_packet;\n    if(!data)\n        return AVERROR(ENOMEM);\n    return 0;\n}', 'void *av_malloc(unsigned int size)\n{\n    void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n    long diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    ptr = malloc(size+16);\n    if(!ptr)\n        return ptr;\n    diff= ((-(long)ptr - 1)&15) + 1;\n    ptr = (char*)ptr + diff;\n    ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr,16,size))\n        ptr = NULL;\n#elif HAVE_MEMALIGN\n    ptr = memalign(16,size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}', 'void av_init_packet(AVPacket *pkt)\n{\n    pkt->pts   = AV_NOPTS_VALUE;\n    pkt->dts   = AV_NOPTS_VALUE;\n    pkt->pos   = -1;\n    pkt->duration = 0;\n    pkt->convergence_duration = 0;\n    pkt->flags = 0;\n    pkt->stream_index = 0;\n    pkt->destruct= NULL;\n}']