static int asf_read_payload(AVFormatContext *s, AVPacket *pkt)

{

    ASFContext *asf = s->priv_data;

    AVIOContext *pb = s->pb;

    int ret, i;

    ASFPacket *asf_pkt = NULL;



    if (!asf->sub_left) {

        uint32_t off_len, media_len;

        uint8_t stream_num;



        stream_num = avio_r8(pb);

        asf->stream_index = stream_num & ASF_STREAM_NUM;

        for (i = 0; i < asf->nb_streams; i++) {

            if (asf->stream_index == asf->asf_st[i]->stream_index) {

                asf_pkt               = &asf->asf_st[i]->pkt;

                asf_pkt->stream_index = asf->asf_st[i]->index;

                break;

            }

        }

        if (!asf_pkt)

            return AVERROR_INVALIDDATA;

        if (stream_num >> 7)

            asf_pkt->flags |= AV_PKT_FLAG_KEY;

        READ_LEN(asf->prop_flags & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE,

                 ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_, media_len);

        READ_LEN(asf->prop_flags & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE,

                 ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_, off_len);

        READ_LEN(asf->prop_flags & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE,

                 ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_, asf->rep_data_len);

        if (asf_pkt->size_left && (asf_pkt->frame_num != media_len)) {

            av_log(s, AV_LOG_WARNING, "Unfinished frame will be ignored\n");

            reset_packet(asf_pkt);

        }

        asf_pkt->frame_num = media_len;

        asf->sub_dts = off_len;

        if (asf->nb_mult_left) {

            if ((ret = asf_read_multiple_payload(s, pkt, asf_pkt)) < 0)

                return ret;

        } else if (asf->rep_data_len == 1) {

            asf->sub_left = 1;

            asf->state    = READ_SINGLE;

            pkt->flags    = asf_pkt->flags;

            if ((ret = asf_read_subpayload(s, pkt, 1)) < 0)

                return ret;

        } else {

            if ((ret = asf_read_single_payload(s, pkt, asf_pkt)) < 0)

                return ret;

        }

    } else {

        for (i = 0; i <= asf->nb_streams; i++) {

            if (asf->stream_index == asf->asf_st[i]->stream_index) {

                asf_pkt = &asf->asf_st[i]->pkt;

                break;

            }

        }

        if (!asf_pkt)

            return AVERROR_INVALIDDATA;

        pkt->flags         = asf_pkt->flags;

        pkt->dts           = asf_pkt->dts;

        pkt->stream_index  = asf->asf_st[i]->index;

        if ((ret = asf_read_subpayload(s, pkt, 0)) < 0) // read subpayload without its header

            return ret;

    }



    return 0;

}

static int asf_read_payload(AVFormatContext *s, AVPacket *pkt)

{

    ASFContext *asf = s->priv_data;

    AVIOContext *pb = s->pb;

    int ret, i;

    ASFPacket *asf_pkt = NULL;



    if (!asf->sub_left) {

        uint32_t off_len, media_len;

        uint8_t stream_num;



        stream_num = avio_r8(pb);

        asf->stream_index = stream_num & ASF_STREAM_NUM;

        for (i = 0; i < asf->nb_streams; i++) {

            if (asf->stream_index == asf->asf_st[i]->stream_index) {

                asf_pkt               = &asf->asf_st[i]->pkt;

                asf_pkt->stream_index = asf->asf_st[i]->index;

                break;

            }

        }

        if (!asf_pkt)

            return AVERROR_INVALIDDATA;

        if (stream_num >> 7)

            asf_pkt->flags |= AV_PKT_FLAG_KEY;

        READ_LEN(asf->prop_flags & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE,

                 ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_, media_len);

        READ_LEN(asf->prop_flags & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE,

                 ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_, off_len);

        READ_LEN(asf->prop_flags & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE,

                 ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_, asf->rep_data_len);

        if (asf_pkt->size_left && (asf_pkt->frame_num != media_len)) {

            av_log(s, AV_LOG_WARNING, "Unfinished frame will be ignored\n");

            reset_packet(asf_pkt);

        }

        asf_pkt->frame_num = media_len;

        asf->sub_dts = off_len;

        if (asf->nb_mult_left) {

            if ((ret = asf_read_multiple_payload(s, pkt, asf_pkt)) < 0)

                return ret;

        } else if (asf->rep_data_len == 1) {

            asf->sub_left = 1;

            asf->state    = READ_SINGLE;

            pkt->flags    = asf_pkt->flags;

            if ((ret = asf_read_subpayload(s, pkt, 1)) < 0)

                return ret;

        } else {

            if ((ret = asf_read_single_payload(s, pkt, asf_pkt)) < 0)

                return ret;

        }

    } else {

        for (i = 0; i <= asf->nb_streams; i++) {

            if (asf->stream_index == asf->asf_st[i]->stream_index) {

                asf_pkt = &asf->asf_st[i]->pkt;

                break;

            }

        }

        if (!asf_pkt)

            return AVERROR_INVALIDDATA;

        pkt->flags         = asf_pkt->flags;

        pkt->dts           = asf_pkt->dts;

        pkt->stream_index  = asf->asf_st[i]->index;

        if ((ret = asf_read_subpayload(s, pkt, 0)) < 0) 

            return ret;

    }



    return 0;

}

        if (!asf_pkt)             return AVERROR_INVALIDDATA;
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    ASFContext *asf = VAR_0->priv_data;

    AVIOContext *pb = VAR_0->pb;

    int VAR_2, VAR_3;

    ASFPacket *asf_pkt = NULL;



    if (!asf->sub_left) {

        uint32_t off_len, media_len;

        uint8_t stream_num;



        stream_num = avio_r8(pb);

        asf->stream_index = stream_num & ASF_STREAM_NUM;

        for (VAR_3 = 0; VAR_3 < asf->nb_streams; VAR_3++) {

            if (asf->stream_index == asf->asf_st[VAR_3]->stream_index) {

                asf_pkt               = &asf->asf_st[VAR_3]->VAR_1;

                asf_pkt->stream_index = asf->asf_st[VAR_3]->index;

                break;

            }

        }

        if (!asf_pkt)

            return AVERROR_INVALIDDATA;

        if (stream_num >> 7)

            asf_pkt->flags |= AV_PKT_FLAG_KEY;

        READ_LEN(asf->prop_flags & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE,

                 ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_, media_len);

        READ_LEN(asf->prop_flags & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE,

                 ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_, off_len);

        READ_LEN(asf->prop_flags & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE,

                 ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_, asf->rep_data_len);

        if (asf_pkt->size_left && (asf_pkt->frame_num != media_len)) {

            av_log(VAR_0, AV_LOG_WARNING, "Unfinished frame will be ignored\n");

            reset_packet(asf_pkt);

        }

        asf_pkt->frame_num = media_len;

        asf->sub_dts = off_len;

        if (asf->nb_mult_left) {

            if ((VAR_2 = asf_read_multiple_payload(VAR_0, VAR_1, asf_pkt)) < 0)

                return VAR_2;

        } else if (asf->rep_data_len == 1) {

            asf->sub_left = 1;

            asf->state    = READ_SINGLE;

            VAR_1->flags    = asf_pkt->flags;

            if ((VAR_2 = asf_read_subpayload(VAR_0, VAR_1, 1)) < 0)

                return VAR_2;

        } else {

            if ((VAR_2 = asf_read_single_payload(VAR_0, VAR_1, asf_pkt)) < 0)

                return VAR_2;

        }

    } else {

        for (VAR_3 = 0; VAR_3 <= asf->nb_streams; VAR_3++) {

            if (asf->stream_index == asf->asf_st[VAR_3]->stream_index) {

                asf_pkt = &asf->asf_st[VAR_3]->VAR_1;

                break;

            }

        }

        if (!asf_pkt)

            return AVERROR_INVALIDDATA;

        VAR_1->flags         = asf_pkt->flags;

        VAR_1->dts           = asf_pkt->dts;

        VAR_1->stream_index  = asf->asf_st[VAR_3]->index;

        if ((VAR_2 = asf_read_subpayload(VAR_0, VAR_1, 0)) < 0) 

            return VAR_2;

    }



    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ ASFContext *asf = VAR_0->priv_data; AVIOContext *pb = VAR_0->pb; int VAR_2, VAR_3; ASFPacket *asf_pkt = NULL; if (!asf->sub_left) { uint32_t off_len, media_len; uint8_t stream_num; stream_num = avio_r8(pb); asf->stream_index = stream_num & ASF_STREAM_NUM; for (VAR_3 = 0; VAR_3 < asf->nb_streams; VAR_3++) { if (asf->stream_index == asf->asf_st[VAR_3]->stream_index) { asf_pkt               = &asf->asf_st[VAR_3]->VAR_1; asf_pkt->stream_index = asf->asf_st[VAR_3]->index; break; } } if (!asf_pkt)
return AVERROR_INVALIDDATA; if (stream_num >> 7)
asf_pkt->flags |= AV_PKT_FLAG_KEY; READ_LEN(asf->prop_flags & ASF_PL_MASK_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_SIZE,
ASF_PL_FLAG_MEDIA_OBJECT_NUMBER_LENGTH_FIELD_, media_len); READ_LEN(asf->prop_flags & ASF_PL_MASK_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_SIZE,
ASF_PL_FLAG_OFFSET_INTO_MEDIA_OBJECT_LENGTH_FIELD_, off_len); READ_LEN(asf->prop_flags & ASF_PL_MASK_REPLICATED_DATA_LENGTH_FIELD_SIZE,
ASF_PL_FLAG_REPLICATED_DATA_LENGTH_FIELD_, asf->rep_data_len); if (asf_pkt->size_left && (asf_pkt->frame_num != media_len)) { av_log(VAR_0, AV_LOG_WARNING, "Unfinished frame will be ignored\n"); reset_packet(asf_pkt); } asf_pkt->frame_num = media_len; asf->sub_dts = off_len; if (asf->nb_mult_left) { if ((VAR_2 = asf_read_multiple_payload(VAR_0, VAR_1, asf_pkt)) < 0)
return VAR_2; } else if (asf->rep_data_len == 1) { asf->sub_left = 1; asf->state    = READ_SINGLE; VAR_1->flags    = asf_pkt->flags; if ((VAR_2 = asf_read_subpayload(VAR_0, VAR_1, 1)) < 0)
return VAR_2; } else { if ((VAR_2 = asf_read_single_payload(VAR_0, VAR_1, asf_pkt)) < 0)
return VAR_2; } } else { for (VAR_3 = 0; VAR_3 <= asf->nb_streams; VAR_3++) { if (asf->stream_index == asf->asf_st[VAR_3]->stream_index) { asf_pkt = &asf->asf_st[VAR_3]->VAR_1; break; } } if (!asf_pkt)
return AVERROR_INVALIDDATA; VAR_1->flags         = asf_pkt->flags; VAR_1->dts           = asf_pkt->dts; VAR_1->stream_index  = asf->asf_st[VAR_3]->index; if ((VAR_2 = asf_read_subpayload(VAR_0, VAR_1, 0)) < 0)
return VAR_2; } return 0; }