static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, int (*read_child)(), int ctx_size, enum MXFMetadataSetType type)

{

    ByteIOContext *pb = mxf->fc->pb;

    MXFMetadataSet *ctx = ctx_size ? av_mallocz(ctx_size) : mxf;

    uint64_t klv_end = url_ftell(pb) + klv->length;



    if (!ctx)

        return -1;

    while (url_ftell(pb) + 4 < klv_end) {

        int tag = get_be16(pb);

        int size = get_be16(pb); /* KLV specified by 0x53 */

        uint64_t next = url_ftell(pb) + size;

        UID uid;



        if (!size) { /* ignore empty tag, needed for some files with empty UMID tag */

            av_log(mxf->fc, AV_LOG_ERROR, "local tag 0x%04X with 0 size\n", tag);

            continue;

        }

        if (tag > 0x7FFF) { /* dynamic tag */

            int i;

            for (i = 0; i < mxf->local_tags_count; i++) {

                int local_tag = AV_RB16(mxf->local_tags+i*18);

                if (local_tag == tag) {

                    memcpy(uid, mxf->local_tags+i*18+2, 16);

                    dprintf(mxf->fc, "local tag 0x%04X\n", local_tag);

#ifdef DEBUG

                    PRINT_KEY(mxf->fc, "uid", uid);

#endif

                }

            }

        }

        if (ctx_size && tag == 0x3C0A)

            get_buffer(pb, ctx->uid, 16);

        else

            read_child(ctx, pb, tag, size, uid);



        url_fseek(pb, next, SEEK_SET);

    }

    if (ctx_size) ctx->type = type;

    return ctx_size ? mxf_add_metadata_set(mxf, ctx) : 0;

}

static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, int (*read_child)(), int ctx_size, enum MXFMetadataSetType type)

{

    ByteIOContext *pb = mxf->fc->pb;

    MXFMetadataSet *ctx = ctx_size ? av_mallocz(ctx_size) : mxf;

    uint64_t klv_end = url_ftell(pb) + klv->length;



    if (!ctx)

        return -1;

    while (url_ftell(pb) + 4 < klv_end) {

        int tag = get_be16(pb);

        int size = get_be16(pb); 

        uint64_t next = url_ftell(pb) + size;

        UID uid;



        if (!size) { 

            av_log(mxf->fc, AV_LOG_ERROR, "local tag 0x%04X with 0 size\n", tag);

            continue;

        }

        if (tag > 0x7FFF) { 

            int i;

            for (i = 0; i < mxf->local_tags_count; i++) {

                int local_tag = AV_RB16(mxf->local_tags+i*18);

                if (local_tag == tag) {

                    memcpy(uid, mxf->local_tags+i*18+2, 16);

                    dprintf(mxf->fc, "local tag 0x%04X\n", local_tag);

#ifdef DEBUG

                    PRINT_KEY(mxf->fc, "uid", uid);

#endif

                }

            }

        }

        if (ctx_size && tag == 0x3C0A)

            get_buffer(pb, ctx->uid, 16);

        else

            read_child(ctx, pb, tag, size, uid);



        url_fseek(pb, next, SEEK_SET);

    }

    if (ctx_size) ctx->type = type;

    return ctx_size ? mxf_add_metadata_set(mxf, ctx) : 0;

}

static int FUNC_0(MXFContext *VAR_0, KLVPacket *VAR_1, int (*VAR_2)(), int VAR_3, enum MXFMetadataSetType VAR_4)

{

    ByteIOContext *pb = VAR_0->fc->pb;

    MXFMetadataSet *ctx = VAR_3 ? av_mallocz(VAR_3) : VAR_0;

    uint64_t klv_end = url_ftell(pb) + VAR_1->length;



    if (!ctx)

        return -1;

    while (url_ftell(pb) + 4 < klv_end) {

        int VAR_5 = get_be16(pb);

        int VAR_6 = get_be16(pb); 

        uint64_t next = url_ftell(pb) + VAR_6;

        UID uid;



        if (!VAR_6) { 

            av_log(VAR_0->fc, AV_LOG_ERROR, "local VAR_5 0x%04X with 0 VAR_6\n", VAR_5);

            continue;

        }

        if (VAR_5 > 0x7FFF) { 

            int VAR_7;

            for (VAR_7 = 0; VAR_7 < VAR_0->local_tags_count; VAR_7++) {

                int local_tag = AV_RB16(VAR_0->local_tags+VAR_7*18);

                if (local_tag == VAR_5) {

                    memcpy(uid, VAR_0->local_tags+VAR_7*18+2, 16);

                    dprintf(VAR_0->fc, "local VAR_5 0x%04X\n", local_tag);

#ifdef DEBUG

                    PRINT_KEY(VAR_0->fc, "uid", uid);

#endif

                }

            }

        }

        if (VAR_3 && VAR_5 == 0x3C0A)

            get_buffer(pb, ctx->uid, 16);

        else

            VAR_2(ctx, pb, VAR_5, VAR_6, uid);



        url_fseek(pb, next, SEEK_SET);

    }

    if (VAR_3) ctx->VAR_4 = VAR_4;

    return VAR_3 ? mxf_add_metadata_set(VAR_0, ctx) : 0;

}

static int FUNC_0(MXFContext *VAR_0, KLVPacket *VAR_1, int (*VAR_2)(), int VAR_3, enum MXFMetadataSetType VAR_4)
{ ByteIOContext *pb = VAR_0->fc->pb; MXFMetadataSet *ctx = VAR_3 ? av_mallocz(VAR_3) : VAR_0; uint64_t klv_end = url_ftell(pb) + VAR_1->length; if (!ctx)
return -1; while (url_ftell(pb) + 4 < klv_end) { int VAR_5 = get_be16(pb); int VAR_6 = get_be16(pb); uint64_t next = url_ftell(pb) + VAR_6; UID uid; if (!VAR_6) { av_log(VAR_0->fc, AV_LOG_ERROR, "local VAR_5 0x%04X with 0 VAR_6\n", VAR_5); continue; } if (VAR_5 > 0x7FFF) { int VAR_7; for (VAR_7 = 0; VAR_7 < VAR_0->local_tags_count; VAR_7++) { int local_tag = AV_RB16(VAR_0->local_tags+VAR_7*18); if (local_tag == VAR_5) { memcpy(uid, VAR_0->local_tags+VAR_7*18+2, 16); dprintf(VAR_0->fc, "local VAR_5 0x%04X\n", local_tag); #ifdef DEBUG
PRINT_KEY(VAR_0->fc, "uid", uid); #endif
} } } if (VAR_3 && VAR_5 == 0x3C0A)
get_buffer(pb, ctx->uid, 16); else
VAR_2(ctx, pb, VAR_5, VAR_6, uid); url_fseek(pb, next, SEEK_SET); } if (VAR_3) ctx->VAR_4 = VAR_4; return VAR_3 ? mxf_add_metadata_set(VAR_0, ctx) : 0; }