static int asf_read_single_payload(AVFormatContext *s, AVPacket *pkt,

                               ASFPacket *asf_pkt)

{

    ASFContext *asf = s->priv_data;

    AVIOContext *pb = s->pb;

    int64_t  offset;

    uint64_t size;

    unsigned char *p;

    int ret;



    if (!asf_pkt->data_size) {

        asf_pkt->data_size = asf_pkt->size_left = avio_rl32(pb); // read media object size

        if (asf_pkt->data_size <= 0)

            return AVERROR_EOF;

        if ((ret = av_new_packet(&asf_pkt->avpkt, asf_pkt->data_size)) < 0)

            return ret;

    } else

        avio_skip(pb, 4); // skip media object size

    asf_pkt->dts = avio_rl32(pb); // read presentation time

    if (asf->rep_data_len >= 8)

        avio_skip(pb, asf->rep_data_len - 8); // skip replicated data

    offset = avio_tell(pb);



    // size of the payload - size of the packet without header and padding

    if (asf->packet_size_internal)

        size = asf->packet_size_internal - offset + asf->packet_offset - asf->pad_len;

    else

        size = asf->packet_size - offset + asf->packet_offset - asf->pad_len;

    if (size > asf->packet_size) {

        av_log(s, AV_LOG_ERROR,

               "Error: invalid data packet size, offset %"PRId64".\n",

               avio_tell(pb));

        return AVERROR_INVALIDDATA;

    }

    p = asf_pkt->avpkt.data + asf_pkt->data_size - asf_pkt->size_left;

    if (size > asf_pkt->size_left || asf_pkt->size_left <= 0)

        return AVERROR_INVALIDDATA;

    if (asf_pkt->size_left > size)

        asf_pkt->size_left -= size;

    else

        asf_pkt->size_left = 0;

    if ((ret = avio_read(pb, p, size)) < 0)

        return ret;

    if (s->key && s->keylen == 20)

            ff_asfcrypt_dec(s->key, p, ret);

    if (asf->packet_size_internal)

        avio_skip(pb, asf->packet_size - asf->packet_size_internal);

    avio_skip(pb, asf->pad_len); // skip padding



    return 0;

}

static int asf_read_single_payload(AVFormatContext *s, AVPacket *pkt,

                               ASFPacket *asf_pkt)

{

    ASFContext *asf = s->priv_data;

    AVIOContext *pb = s->pb;

    int64_t  offset;

    uint64_t size;

    unsigned char *p;

    int ret;



    if (!asf_pkt->data_size) {

        asf_pkt->data_size = asf_pkt->size_left = avio_rl32(pb); 

        if (asf_pkt->data_size <= 0)

            return AVERROR_EOF;

        if ((ret = av_new_packet(&asf_pkt->avpkt, asf_pkt->data_size)) < 0)

            return ret;

    } else

        avio_skip(pb, 4); 

    asf_pkt->dts = avio_rl32(pb); 

    if (asf->rep_data_len >= 8)

        avio_skip(pb, asf->rep_data_len - 8); 

    offset = avio_tell(pb);



    

    if (asf->packet_size_internal)

        size = asf->packet_size_internal - offset + asf->packet_offset - asf->pad_len;

    else

        size = asf->packet_size - offset + asf->packet_offset - asf->pad_len;

    if (size > asf->packet_size) {

        av_log(s, AV_LOG_ERROR,

               "Error: invalid data packet size, offset %"PRId64".\n",

               avio_tell(pb));

        return AVERROR_INVALIDDATA;

    }

    p = asf_pkt->avpkt.data + asf_pkt->data_size - asf_pkt->size_left;

    if (size > asf_pkt->size_left || asf_pkt->size_left <= 0)

        return AVERROR_INVALIDDATA;

    if (asf_pkt->size_left > size)

        asf_pkt->size_left -= size;

    else

        asf_pkt->size_left = 0;

    if ((ret = avio_read(pb, p, size)) < 0)

        return ret;

    if (s->key && s->keylen == 20)

            ff_asfcrypt_dec(s->key, p, ret);

    if (asf->packet_size_internal)

        avio_skip(pb, asf->packet_size - asf->packet_size_internal);

    avio_skip(pb, asf->pad_len); 



    return 0;

}

    int ret;         if (asf_pkt->data_size <= 0)         if ((ret = av_new_packet(&asf_pkt->avpkt, asf_pkt->data_size)) < 0)     int ret;         if (asf_pkt->data_size <= 0)         if ((ret = av_new_packet(&asf_pkt->avpkt, asf_pkt->data_size)) < 0)
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1,

                               ASFPacket *VAR_2)

{

    ASFContext *asf = VAR_0->priv_data;

    AVIOContext *pb = VAR_0->pb;

    int64_t  offset;

    uint64_t size;

    unsigned char *VAR_3;

    int VAR_4;



    if (!VAR_2->data_size) {

        VAR_2->data_size = VAR_2->size_left = avio_rl32(pb); 

        if (VAR_2->data_size <= 0)

            return AVERROR_EOF;

        if ((VAR_4 = av_new_packet(&VAR_2->avpkt, VAR_2->data_size)) < 0)

            return VAR_4;

    } else

        avio_skip(pb, 4); 

    VAR_2->dts = avio_rl32(pb); 

    if (asf->rep_data_len >= 8)

        avio_skip(pb, asf->rep_data_len - 8); 

    offset = avio_tell(pb);



    

    if (asf->packet_size_internal)

        size = asf->packet_size_internal - offset + asf->packet_offset - asf->pad_len;

    else

        size = asf->packet_size - offset + asf->packet_offset - asf->pad_len;

    if (size > asf->packet_size) {

        av_log(VAR_0, AV_LOG_ERROR,

               "Error: invalid data packet size, offset %"PRId64".\n",

               avio_tell(pb));

        return AVERROR_INVALIDDATA;

    }

    VAR_3 = VAR_2->avpkt.data + VAR_2->data_size - VAR_2->size_left;

    if (size > VAR_2->size_left || VAR_2->size_left <= 0)

        return AVERROR_INVALIDDATA;

    if (VAR_2->size_left > size)

        VAR_2->size_left -= size;

    else

        VAR_2->size_left = 0;

    if ((VAR_4 = avio_read(pb, VAR_3, size)) < 0)

        return VAR_4;

    if (VAR_0->key && VAR_0->keylen == 20)

            ff_asfcrypt_dec(VAR_0->key, VAR_3, VAR_4);

    if (asf->packet_size_internal)

        avio_skip(pb, asf->packet_size - asf->packet_size_internal);

    avio_skip(pb, asf->pad_len); 



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1,
ASFPacket *VAR_2)
{ ASFContext *asf = VAR_0->priv_data; AVIOContext *pb = VAR_0->pb; int64_t  offset; uint64_t size; unsigned char *VAR_3; int VAR_4; if (!VAR_2->data_size) { VAR_2->data_size = VAR_2->size_left = avio_rl32(pb); if (VAR_2->data_size <= 0)
return AVERROR_EOF; if ((VAR_4 = av_new_packet(&VAR_2->avpkt, VAR_2->data_size)) < 0)
return VAR_4; } else avio_skip(pb, 4); VAR_2->dts = avio_rl32(pb); if (asf->rep_data_len >= 8)
avio_skip(pb, asf->rep_data_len - 8); offset = avio_tell(pb); if (asf->packet_size_internal)
size = asf->packet_size_internal - offset + asf->packet_offset - asf->pad_len; else
size = asf->packet_size - offset + asf->packet_offset - asf->pad_len; if (size > asf->packet_size) { av_log(VAR_0, AV_LOG_ERROR,
"Error: invalid data packet size, offset %"PRId64".\n",
avio_tell(pb)); return AVERROR_INVALIDDATA; } VAR_3 = VAR_2->avpkt.data + VAR_2->data_size - VAR_2->size_left; if (size > VAR_2->size_left || VAR_2->size_left <= 0)
return AVERROR_INVALIDDATA; if (VAR_2->size_left > size)
VAR_2->size_left -= size; else
VAR_2->size_left = 0; if ((VAR_4 = avio_read(pb, VAR_3, size)) < 0)
return VAR_4; if (VAR_0->key && VAR_0->keylen == 20)
ff_asfcrypt_dec(VAR_0->key, VAR_3, VAR_4); if (asf->packet_size_internal)
avio_skip(pb, asf->packet_size - asf->packet_size_internal); avio_skip(pb, asf->pad_len); return 0; }