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

{

    KLVPacket klv;



    while (!s->pb->eof_reached) {

        if (klv_read_packet(&klv, s->pb) < 0)

            return -1;

        PRINT_KEY(s, "read packet", klv.key);

        av_dlog(s, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset);

        if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) {

            int res = mxf_decrypt_triplet(s, pkt, &klv);

            if (res < 0) {

                av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n");

                return -1;

            }

            return 0;

        }

        if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {

            int index = mxf_get_stream_index(s, &klv);

            if (index < 0) {

                av_log(s, AV_LOG_ERROR, "error getting stream index %d\n", AV_RB32(klv.key+12));

                goto skip;

            }

            if (s->streams[index]->discard == AVDISCARD_ALL)

                goto skip;

            /* check for 8 channels AES3 element */

            if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) {

                if (mxf_get_d10_aes3_packet(s->pb, s->streams[index], pkt, klv.length) < 0) {

                    av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n");

                    return -1;

                }

            } else

                av_get_packet(s->pb, pkt, klv.length);

            pkt->stream_index = index;

            pkt->pos = klv.offset;

            return 0;

        } else

        skip:

            avio_skip(s->pb, klv.length);

    }

    return AVERROR_EOF;

}

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

{

    KLVPacket klv;



    while (!s->pb->eof_reached) {

        if (klv_read_packet(&klv, s->pb) < 0)

            return -1;

        PRINT_KEY(s, "read packet", klv.key);

        av_dlog(s, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset);

        if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) {

            int res = mxf_decrypt_triplet(s, pkt, &klv);

            if (res < 0) {

                av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n");

                return -1;

            }

            return 0;

        }

        if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {

            int index = mxf_get_stream_index(s, &klv);

            if (index < 0) {

                av_log(s, AV_LOG_ERROR, "error getting stream index %d\n", AV_RB32(klv.key+12));

                goto skip;

            }

            if (s->streams[index]->discard == AVDISCARD_ALL)

                goto skip;

            

            if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) {

                if (mxf_get_d10_aes3_packet(s->pb, s->streams[index], pkt, klv.length) < 0) {

                    av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n");

                    return -1;

                }

            } else

                av_get_packet(s->pb, pkt, klv.length);

            pkt->stream_index = index;

            pkt->pos = klv.offset;

            return 0;

        } else

        skip:

            avio_skip(s->pb, klv.length);

    }

    return AVERROR_EOF;

}

            } else                 av_get_packet(s->pb, pkt, klv.length);
static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    KLVPacket klv;



    while (!VAR_0->pb->eof_reached) {

        if (klv_read_packet(&klv, VAR_0->pb) < 0)

            return -1;

        PRINT_KEY(VAR_0, "read packet", klv.key);

        av_dlog(VAR_0, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset);

        if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) {

            int VAR_2 = mxf_decrypt_triplet(VAR_0, VAR_1, &klv);

            if (VAR_2 < 0) {

                av_log(VAR_0, AV_LOG_ERROR, "invalid encoded triplet\n");

                return -1;

            }

            return 0;

        }

        if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) {

            int VAR_3 = mxf_get_stream_index(VAR_0, &klv);

            if (VAR_3 < 0) {

                av_log(VAR_0, AV_LOG_ERROR, "error getting stream VAR_3 %d\n", AV_RB32(klv.key+12));

                goto skip;

            }

            if (VAR_0->streams[VAR_3]->discard == AVDISCARD_ALL)

                goto skip;

            

            if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) {

                if (mxf_get_d10_aes3_packet(VAR_0->pb, VAR_0->streams[VAR_3], VAR_1, klv.length) < 0) {

                    av_log(VAR_0, AV_LOG_ERROR, "error reading D-10 aes3 frame\n");

                    return -1;

                }

            } else

                av_get_packet(VAR_0->pb, VAR_1, klv.length);

            VAR_1->stream_index = VAR_3;

            VAR_1->pos = klv.offset;

            return 0;

        } else

        skip:

            avio_skip(VAR_0->pb, klv.length);

    }

    return AVERROR_EOF;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ KLVPacket klv; while (!VAR_0->pb->eof_reached) { if (klv_read_packet(&klv, VAR_0->pb) < 0)
return -1; PRINT_KEY(VAR_0, "read packet", klv.key); av_dlog(VAR_0, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset); if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) { int VAR_2 = mxf_decrypt_triplet(VAR_0, VAR_1, &klv); if (VAR_2 < 0) { av_log(VAR_0, AV_LOG_ERROR, "invalid encoded triplet\n"); return -1; } return 0; } if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) { int VAR_3 = mxf_get_stream_index(VAR_0, &klv); if (VAR_3 < 0) { av_log(VAR_0, AV_LOG_ERROR, "error getting stream VAR_3 %d\n", AV_RB32(klv.key+12)); goto skip; } if (VAR_0->streams[VAR_3]->discard == AVDISCARD_ALL)
goto skip; if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) { if (mxf_get_d10_aes3_packet(VAR_0->pb, VAR_0->streams[VAR_3], VAR_1, klv.length) < 0) { av_log(VAR_0, AV_LOG_ERROR, "error reading D-10 aes3 frame\n"); return -1; } } else av_get_packet(VAR_0->pb, VAR_1, klv.length); VAR_1->stream_index = VAR_3; VAR_1->pos = klv.offset; return 0; } else skip:
avio_skip(VAR_0->pb, klv.length); } return AVERROR_EOF; }