static int pva_read_packet(AVFormatContext *s, AVPacket *pkt) {

    ByteIOContext *pb = s->pb;

    PVAContext *pvactx = s->priv_data;

    int ret, syncword, streamid, reserved, flags, length, pts_flag;

    int64_t pva_pts = AV_NOPTS_VALUE;



recover:

    syncword = get_be16(pb);

    streamid = get_byte(pb);

    get_byte(pb);               /* counter not used */

    reserved = get_byte(pb);

    flags    = get_byte(pb);

    length   = get_be16(pb);



    pts_flag = flags & 0x10;



    if (syncword != PVA_MAGIC) {

        av_log(s, AV_LOG_ERROR, "invalid syncword\n");

        return AVERROR(EIO);

    }

    if (streamid != PVA_VIDEO_PAYLOAD && streamid != PVA_AUDIO_PAYLOAD) {

        av_log(s, AV_LOG_ERROR, "invalid streamid\n");

        return AVERROR(EIO);

    }

    if (reserved != 0x55) {

        av_log(s, AV_LOG_WARNING, "expected reserved byte to be 0x55\n");

    }

    if (length > PVA_MAX_PAYLOAD_LENGTH) {

        av_log(s, AV_LOG_ERROR, "invalid payload length %u\n", length);

        return AVERROR(EIO);

    }



    if (streamid == PVA_VIDEO_PAYLOAD && pts_flag) {

        pva_pts = get_be32(pb);

        length -= 4;

    } else if (streamid == PVA_AUDIO_PAYLOAD) {

        /* PVA Audio Packets either start with a signaled PES packet or

         * are a continuation of the previous PES packet. New PES packets

         * always start at the beginning of a PVA Packet, never somewhere in

         * the middle. */

        if (!pvactx->continue_pes) {

            int pes_signal, pes_header_data_length, pes_packet_length,

                pes_flags;

            unsigned char pes_header_data[256];



            pes_signal             = get_be24(pb);

            get_byte(pb);

            pes_packet_length      = get_be16(pb);

            pes_flags              = get_be16(pb);

            pes_header_data_length = get_byte(pb);



            if (pes_signal != 1) {

                av_log(s, AV_LOG_WARNING, "expected signaled PES packet, "

                                          "trying to recover\n");

                url_fskip(pb, length - 9);

                goto recover;

            }



            get_buffer(pb, pes_header_data, pes_header_data_length);

            length -= 9 + pes_header_data_length;



            pes_packet_length -= 3 + pes_header_data_length;



            pvactx->continue_pes = pes_packet_length;



            if (pes_flags & 0x80 && (pes_header_data[0] & 0xf0) == 0x20)

                pva_pts = ff_parse_pes_pts(pes_header_data);

        }



        pvactx->continue_pes -= length;



        if (pvactx->continue_pes < 0) {

            av_log(s, AV_LOG_WARNING, "audio data corruption\n");

            pvactx->continue_pes = 0;

        }

    }



    if ((ret = av_get_packet(pb, pkt, length)) <= 0)

        return AVERROR(EIO);



    pkt->stream_index = streamid - 1;

    if (pva_pts != AV_NOPTS_VALUE)

        pkt->pts = pva_pts;



    return ret;

}

static int pva_read_packet(AVFormatContext *s, AVPacket *pkt) {

    ByteIOContext *pb = s->pb;

    PVAContext *pvactx = s->priv_data;

    int ret, syncword, streamid, reserved, flags, length, pts_flag;

    int64_t pva_pts = AV_NOPTS_VALUE;



recover:

    syncword = get_be16(pb);

    streamid = get_byte(pb);

    get_byte(pb);               

    reserved = get_byte(pb);

    flags    = get_byte(pb);

    length   = get_be16(pb);



    pts_flag = flags & 0x10;



    if (syncword != PVA_MAGIC) {

        av_log(s, AV_LOG_ERROR, "invalid syncword\n");

        return AVERROR(EIO);

    }

    if (streamid != PVA_VIDEO_PAYLOAD && streamid != PVA_AUDIO_PAYLOAD) {

        av_log(s, AV_LOG_ERROR, "invalid streamid\n");

        return AVERROR(EIO);

    }

    if (reserved != 0x55) {

        av_log(s, AV_LOG_WARNING, "expected reserved byte to be 0x55\n");

    }

    if (length > PVA_MAX_PAYLOAD_LENGTH) {

        av_log(s, AV_LOG_ERROR, "invalid payload length %u\n", length);

        return AVERROR(EIO);

    }



    if (streamid == PVA_VIDEO_PAYLOAD && pts_flag) {

        pva_pts = get_be32(pb);

        length -= 4;

    } else if (streamid == PVA_AUDIO_PAYLOAD) {

        







        if (!pvactx->continue_pes) {

            int pes_signal, pes_header_data_length, pes_packet_length,

                pes_flags;

            unsigned char pes_header_data[256];



            pes_signal             = get_be24(pb);

            get_byte(pb);

            pes_packet_length      = get_be16(pb);

            pes_flags              = get_be16(pb);

            pes_header_data_length = get_byte(pb);



            if (pes_signal != 1) {

                av_log(s, AV_LOG_WARNING, "expected signaled PES packet, "

                                          "trying to recover\n");

                url_fskip(pb, length - 9);

                goto recover;

            }



            get_buffer(pb, pes_header_data, pes_header_data_length);

            length -= 9 + pes_header_data_length;



            pes_packet_length -= 3 + pes_header_data_length;



            pvactx->continue_pes = pes_packet_length;



            if (pes_flags & 0x80 && (pes_header_data[0] & 0xf0) == 0x20)

                pva_pts = ff_parse_pes_pts(pes_header_data);

        }



        pvactx->continue_pes -= length;



        if (pvactx->continue_pes < 0) {

            av_log(s, AV_LOG_WARNING, "audio data corruption\n");

            pvactx->continue_pes = 0;

        }

    }



    if ((ret = av_get_packet(pb, pkt, length)) <= 0)

        return AVERROR(EIO);



    pkt->stream_index = streamid - 1;

    if (pva_pts != AV_NOPTS_VALUE)

        pkt->pts = pva_pts;



    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1) {

    ByteIOContext *pb = VAR_0->pb;

    PVAContext *pvactx = VAR_0->priv_data;

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;

    int64_t pva_pts = AV_NOPTS_VALUE;



recover:

    VAR_3 = get_be16(pb);

    VAR_4 = get_byte(pb);

    get_byte(pb);               

    VAR_5 = get_byte(pb);

    VAR_6    = get_byte(pb);

    VAR_7   = get_be16(pb);



    VAR_8 = VAR_6 & 0x10;



    if (VAR_3 != PVA_MAGIC) {

        av_log(VAR_0, AV_LOG_ERROR, "invalid VAR_3\n");

        return AVERROR(EIO);

    }

    if (VAR_4 != PVA_VIDEO_PAYLOAD && VAR_4 != PVA_AUDIO_PAYLOAD) {

        av_log(VAR_0, AV_LOG_ERROR, "invalid VAR_4\n");

        return AVERROR(EIO);

    }

    if (VAR_5 != 0x55) {

        av_log(VAR_0, AV_LOG_WARNING, "expected VAR_5 byte to be 0x55\n");

    }

    if (VAR_7 > PVA_MAX_PAYLOAD_LENGTH) {

        av_log(VAR_0, AV_LOG_ERROR, "invalid payload VAR_7 %u\n", VAR_7);

        return AVERROR(EIO);

    }



    if (VAR_4 == PVA_VIDEO_PAYLOAD && VAR_8) {

        pva_pts = get_be32(pb);

        VAR_7 -= 4;

    } else if (VAR_4 == PVA_AUDIO_PAYLOAD) {

        







        if (!pvactx->continue_pes) {

            int VAR_9, VAR_10, VAR_11,

                VAR_12;

            unsigned char VAR_13[256];



            VAR_9             = get_be24(pb);

            get_byte(pb);

            VAR_11      = get_be16(pb);

            VAR_12              = get_be16(pb);

            VAR_10 = get_byte(pb);



            if (VAR_9 != 1) {

                av_log(VAR_0, AV_LOG_WARNING, "expected signaled PES packet, "

                                          "trying to recover\n");

                url_fskip(pb, VAR_7 - 9);

                goto recover;

            }



            get_buffer(pb, VAR_13, VAR_10);

            VAR_7 -= 9 + VAR_10;



            VAR_11 -= 3 + VAR_10;



            pvactx->continue_pes = VAR_11;



            if (VAR_12 & 0x80 && (VAR_13[0] & 0xf0) == 0x20)

                pva_pts = ff_parse_pes_pts(VAR_13);

        }



        pvactx->continue_pes -= VAR_7;



        if (pvactx->continue_pes < 0) {

            av_log(VAR_0, AV_LOG_WARNING, "audio data corruption\n");

            pvactx->continue_pes = 0;

        }

    }



    if ((VAR_2 = av_get_packet(pb, VAR_1, VAR_7)) <= 0)

        return AVERROR(EIO);



    VAR_1->stream_index = VAR_4 - 1;

    if (pva_pts != AV_NOPTS_VALUE)

        VAR_1->pts = pva_pts;



    return VAR_2;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1) { ByteIOContext *pb = VAR_0->pb; PVAContext *pvactx = VAR_0->priv_data; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; int64_t pva_pts = AV_NOPTS_VALUE; recover:
VAR_3 = get_be16(pb); VAR_4 = get_byte(pb); get_byte(pb); VAR_5 = get_byte(pb); VAR_6    = get_byte(pb); VAR_7   = get_be16(pb); VAR_8 = VAR_6 & 0x10; if (VAR_3 != PVA_MAGIC) { av_log(VAR_0, AV_LOG_ERROR, "invalid VAR_3\n"); return AVERROR(EIO); } if (VAR_4 != PVA_VIDEO_PAYLOAD && VAR_4 != PVA_AUDIO_PAYLOAD) { av_log(VAR_0, AV_LOG_ERROR, "invalid VAR_4\n"); return AVERROR(EIO); } if (VAR_5 != 0x55) { av_log(VAR_0, AV_LOG_WARNING, "expected VAR_5 byte to be 0x55\n"); } if (VAR_7 > PVA_MAX_PAYLOAD_LENGTH) { av_log(VAR_0, AV_LOG_ERROR, "invalid payload VAR_7 %u\n", VAR_7); return AVERROR(EIO); } if (VAR_4 == PVA_VIDEO_PAYLOAD && VAR_8) { pva_pts = get_be32(pb); VAR_7 -= 4; } else if (VAR_4 == PVA_AUDIO_PAYLOAD) { if (!pvactx->continue_pes) { int VAR_9, VAR_10, VAR_11,
VAR_12; unsigned char VAR_13[256]; VAR_9             = get_be24(pb); get_byte(pb); VAR_11      = get_be16(pb); VAR_12              = get_be16(pb); VAR_10 = get_byte(pb); if (VAR_9 != 1) { av_log(VAR_0, AV_LOG_WARNING, "expected signaled PES packet, "
"trying to recover\n"); url_fskip(pb, VAR_7 - 9); goto recover; } get_buffer(pb, VAR_13, VAR_10); VAR_7 -= 9 + VAR_10; VAR_11 -= 3 + VAR_10; pvactx->continue_pes = VAR_11; if (VAR_12 & 0x80 && (VAR_13[0] & 0xf0) == 0x20)
pva_pts = ff_parse_pes_pts(VAR_13); } pvactx->continue_pes -= VAR_7; if (pvactx->continue_pes < 0) { av_log(VAR_0, AV_LOG_WARNING, "audio data corruption\n"); pvactx->continue_pes = 0; } } if ((VAR_2 = av_get_packet(pb, VAR_1, VAR_7)) <= 0)
return AVERROR(EIO); VAR_1->stream_index = VAR_4 - 1; if (pva_pts != AV_NOPTS_VALUE)
VAR_1->pts = pva_pts; return VAR_2; }