Revision 7ee7f6f9 libavformat/mxf.c

View differences:

libavformat/mxf.c
140 140
    int metadata_sets_count;
141 141
    AVFormatContext *fc;
142 142
    struct AVAES *aesc;
143
    uint8_t *local_tags;
144
    int local_tags_count;
143 145
} MXFContext;
144 146

  
145 147
typedef struct {
......
177 179
static const uint8_t mxf_essence_element_key[]             = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 };
178 180
static const uint8_t mxf_klv_key[]                         = { 0x06,0x0e,0x2b,0x34 };
179 181
/* complete keys to match */
182
static const uint8_t mxf_crypto_context_uid[]              = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x01,0x01,0x15,0x11,0x00,0x00,0x00,0x00 };
183
static const uint8_t mxf_crypto_source_container_ul[]      = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x02,0x02,0x00,0x00,0x00 };
180 184
static const uint8_t mxf_encrypted_triplet_key[]           = { 0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 };
181 185
static const uint8_t mxf_encrypted_essence_container[]     = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 };
182 186

  
......
367 371
    return AVERROR(EIO);
368 372
}
369 373

  
374
static int mxf_read_primer_pack(MXFContext *mxf)
375
{
376
    ByteIOContext *pb = mxf->fc->pb;
377
    int item_num = get_be32(pb);
378
    int item_len = get_be32(pb);
379

  
380
    if (item_len != 18) {
381
        av_log(mxf->fc, AV_LOG_ERROR, "unsupported primer pack item length\n");
382
        return -1;
383
    }
384
    if (item_num > UINT_MAX / item_len)
385
        return -1;
386
    mxf->local_tags_count = item_num;
387
    mxf->local_tags = av_malloc(item_num*item_len);
388
    if (!mxf->local_tags)
389
        return -1;
390
    get_buffer(pb, mxf->local_tags, item_num*item_len);
391
    return 0;
392
}
393

  
370 394
static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set)
371 395
{
372 396
    mxf->metadata_sets = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * sizeof(*mxf->metadata_sets));
......
377 401
    return 0;
378 402
}
379 403

  
380
static int mxf_read_metadata_cryptographic_context(MXFCryptoContext *cryptocontext, ByteIOContext *pb, int tag)
404
static int mxf_read_metadata_cryptographic_context(MXFCryptoContext *cryptocontext, ByteIOContext *pb, int tag, int size, UID uid)
381 405
{
382
    switch(tag) {
383
    case 0xFFFE:
406
    if (size != 16)
407
        return -1;
408
    if (IS_KLV_KEY(uid, mxf_crypto_context_uid))
384 409
        get_buffer(pb, cryptocontext->context_uid, 16);
385
        break;
386
    case 0xFFFD:
410
    else if (IS_KLV_KEY(uid, mxf_crypto_source_container_ul))
387 411
        get_buffer(pb, cryptocontext->source_container_ul, 16);
388
        break;
389
    }
390 412
    return 0;
391 413
}
392 414

  
......
876 898
}
877 899

  
878 900
static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
901
    { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x05,0x01,0x00 }, mxf_read_primer_pack },
879 902
    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_metadata_content_storage, 0, AnyType },
880 903
    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_metadata_source_package, sizeof(MXFPackage), SourcePackage },
881 904
    { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_metadata_material_package, sizeof(MXFPackage), MaterialPackage },
......
906 929
        int tag = get_be16(pb);
907 930
        int size = get_be16(pb); /* KLV specified by 0x53 */
908 931
        uint64_t next= url_ftell(pb) + size;
932
        UID uid;
909 933

  
910 934
        if (!size) { /* ignore empty tag, needed for some files with empty UMID tag */
911 935
            av_log(mxf->fc, AV_LOG_ERROR, "local tag 0x%04X with 0 size\n", tag);
912 936
            continue;
913 937
        }
938
        if (tag > 0x7FFF) { /* dynamic tag */
939
            int i;
940
            for (i = 0; i < mxf->local_tags_count; i++) {
941
                int local_tag = AV_RB16(mxf->local_tags+i*18);
942
                if (local_tag == tag) {
943
                    memcpy(uid, mxf->local_tags+i*18+2, 16);
944
                    dprintf(mxf->fc, "local tag 0x%04X\n", local_tag);
945
#ifdef DEBUG
946
                    PRINT_KEY(mxf->fc, "uid", uid);
947
#endif
948
                }
949
            }
950
        }
914 951
        if(ctx_size && tag == 0x3C0A)
915 952
            get_buffer(pb, ctx->uid, 16);
916 953
        else
917
            read_child(ctx, pb, tag, size);
954
            read_child(ctx, pb, tag, size, uid);
918 955

  
919 956
        url_fseek(pb, next, SEEK_SET);
920 957
    }
......
950 987

  
951 988
        for (metadata = mxf_metadata_read_table; metadata->read; metadata++) {
952 989
            if (IS_KLV_KEY(klv.key, metadata->key)) {
953
                if (mxf_read_local_tags(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type) < 0) {
990
                int (*read)() = klv.key[5] == 0x53 ? mxf_read_local_tags : metadata->read;
991
                if (read(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type) < 0) {
954 992
                    av_log(s, AV_LOG_ERROR, "error reading header metadata\n");
955 993
                    return -1;
956 994
                }
......
988 1026
    }
989 1027
    av_freep(&mxf->metadata_sets);
990 1028
    av_freep(&mxf->aesc);
1029
    av_freep(&mxf->local_tags);
991 1030
    return 0;
992 1031
}
993 1032

  

Also available in: Unified diff