コード例 #1
0
/* note: keep in sync with mxf_get_set_len */
int mxf_write_set(MXFFile* mxfFile, MXFMetadataSet* set)
{
    MXFListIterator iter;
    uint64_t setLen = 0;
    uint64_t setSize = 0;
    
    mxf_initialise_list_iter(&iter, &set->items);
    while (mxf_next_list_iter_element(&iter))
    {
        setLen += ((MXFMetadataItem*)mxf_get_iter_element(&iter))->length + 4;
    }
 
    if (mxf_get_llen(mxfFile, setLen) <= 4)
    {
        /* spec says preferred 4-byte BER encoded len for sets */ 
        CHK_ORET(mxf_write_fixed_kl(mxfFile, &set->key, 4, setLen));
        setSize = mxfKey_extlen + 4 + setLen;
    }
    else
    {
        CHK_ORET(mxf_write_kl(mxfFile, &set->key, setLen));
        setSize = mxfKey_extlen + mxf_get_llen(mxfFile, setLen) + setLen;
    }
    
    mxf_initialise_list_iter(&iter, &set->items);
    while (mxf_next_list_iter_element(&iter))
    {
        CHK_ORET(mxf_write_item(mxfFile, (MXFMetadataItem*)mxf_get_iter_element(&iter)));
    }
    
    if (set->fixedSpaceAllocation > 0)
    {
        /* check that we can achieve the fixed size, possibly using a filler */
        CHK_ORET(setSize == set->fixedSpaceAllocation || 
            (setSize < set->fixedSpaceAllocation && 
                setSize + mxf_get_min_llen(mxfFile) + mxfKey_extlen <= set->fixedSpaceAllocation));
            
        if (setSize < set->fixedSpaceAllocation)
        {
            /* add filler */
            CHK_ORET(mxf_write_fill(mxfFile, (uint32_t)(set->fixedSpaceAllocation - setSize)));
        }
    }
    
    return 1;
}
コード例 #2
0
ファイル: test_file.c プロジェクト: DukhKamael/ebu-libmxf
int do_write(MXFFile *mxfFile)
{
    memset(data, 0xaa, 256);

    CHK_ORET(mxf_file_write(mxfFile, NULL, 0) == 0);
    CHK_ORET(mxf_file_write(mxfFile, data, 0) == 0);
    CHK_ORET(mxf_file_write(mxfFile, data, 100) == 100);
    CHK_ORET(mxf_file_putc(mxfFile, 0xff));
    CHK_ORET(mxf_file_putc(mxfFile, 0xff));
    CHK_ORET(mxf_write_uint8(mxfFile, 0x0f));
    CHK_ORET(mxf_write_uint16(mxfFile, 0x0f00));
    CHK_ORET(mxf_write_uint32(mxfFile, 0x0f000000));
    CHK_ORET(mxf_write_uint64(mxfFile, 0x0f00000000000000LL));
    CHK_ORET(mxf_write_int8(mxfFile, -0x0f));
    CHK_ORET(mxf_write_int16(mxfFile, -0x0f00));
    CHK_ORET(mxf_write_int32(mxfFile, -0x0f000000));
    CHK_ORET(mxf_write_int64(mxfFile, -0x0f00000000000000LL));
    CHK_ORET(mxf_write_local_tag(mxfFile, 0xffaa));
    CHK_ORET(mxf_write_k(mxfFile, &someKey));
    CHK_ORET(mxf_write_l(mxfFile, 0x01) == 1);
    CHK_ORET(mxf_write_l(mxfFile, 0x80) == 2);
    CHK_ORET(mxf_write_l(mxfFile, 0x8000) == 3);
    CHK_ORET(mxf_write_l(mxfFile, 0x800000) == 4);
    CHK_ORET(mxf_write_l(mxfFile, 0x80000000) == 5);
    CHK_ORET(mxf_write_l(mxfFile, 0x8000000000LL) == 6);
    CHK_ORET(mxf_write_l(mxfFile, 0x800000000000LL) == 7);
    CHK_ORET(mxf_write_l(mxfFile, 0x80000000000000LL) == 8);
    CHK_ORET(mxf_write_l(mxfFile, 0x8000000000000000LL) == 9);
    CHK_ORET(mxf_write_kl(mxfFile, &someKey, 0xf100));
    CHK_ORET(mxf_write_fixed_l(mxfFile, 8, 0x10));
    CHK_ORET(mxf_write_fixed_l(mxfFile, 4, 0x10));
    CHK_ORET(mxf_write_fixed_kl(mxfFile, &someKey, 8, 0x1000));
    CHK_ORET(mxf_write_ul(mxfFile, &someUL));
    CHK_ORET(mxf_write_uid(mxfFile, &someUID));
    CHK_ORET(mxf_write_uuid(mxfFile, &someUUID));
    CHK_ORET(mxf_write_batch_header(mxfFile, 2, 16));
    CHK_ORET(mxf_write_array_header(mxfFile, 4, 32));

    return 1;
}
コード例 #3
0
ファイル: mxf_partition.c プロジェクト: Limecraft/ebu-libmxf
int mxf_write_partition(MXFFile *mxfFile, MXFPartition *partition)
{
    uint32_t essenceContainerLen = (uint32_t)mxf_get_list_length(&partition->essenceContainers);
    uint64_t packLen = 88 + mxfUL_extlen * essenceContainerLen;
    int64_t filePos;
    MXFListIterator iter;

    CHK_ORET((filePos = mxf_file_tell(mxfFile)) >= 0);
    partition->thisPartition = filePos - mxf_get_runin_len(mxfFile);
    if (mxf_is_footer_partition_pack(&partition->key))
    {
        partition->footerPartition = partition->thisPartition;
    }

    CHK_ORET(mxf_write_kl(mxfFile, &partition->key, packLen));

    CHK_ORET(mxf_write_uint16(mxfFile, partition->majorVersion));
    CHK_ORET(mxf_write_uint16(mxfFile, partition->minorVersion));
    CHK_ORET(mxf_write_uint32(mxfFile, partition->kagSize));
    CHK_ORET(mxf_write_uint64(mxfFile, partition->thisPartition));
    CHK_ORET(mxf_write_uint64(mxfFile, partition->previousPartition));
    CHK_ORET(mxf_write_uint64(mxfFile, partition->footerPartition));
    CHK_ORET(mxf_write_uint64(mxfFile, partition->headerByteCount));
    CHK_ORET(mxf_write_uint64(mxfFile, partition->indexByteCount));
    CHK_ORET(mxf_write_uint32(mxfFile, partition->indexSID));
    CHK_ORET(mxf_write_uint64(mxfFile, partition->bodyOffset));
    CHK_ORET(mxf_write_uint32(mxfFile, partition->bodySID));
    CHK_ORET(mxf_write_ul(mxfFile, &partition->operationalPattern));
    CHK_ORET(mxf_write_batch_header(mxfFile, essenceContainerLen, mxfUL_extlen));

    mxf_initialise_list_iter(&iter, &partition->essenceContainers);
    while (mxf_next_list_iter_element(&iter))
    {
        CHK_ORET(mxf_write_ul(mxfFile, (mxfUL*)mxf_get_iter_element(&iter)));
    }

    return 1;
}