Example #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;
}
Example #2
0
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;
}
int test_create_and_write(const char *filename)
{
    MXFFile *mxfFile = NULL;
    MXFFilePartitions partitions;
    MXFPartition *headerPartition = NULL;
    MXFPartition *bodyPartition1 = NULL;
    MXFPartition *bodyPartition2 = NULL;
    MXFPartition *footerPartition = NULL;
    MXFEssenceElement *essenceElement = NULL;
    uint8_t essenceData[1024];
    memset(essenceData, 0, 1024);


    if (!mxf_disk_file_open_new(filename, &mxfFile))
    {
        mxf_log_error("Failed to create '%s'" LOG_LOC_FORMAT, filename, LOG_LOC_PARAMS);
        return 0;
    }

    mxf_initialise_file_partitions(&partitions);

    /* TEST */

    /* write the header pp */
    CHK_OFAIL(mxf_append_new_partition(&partitions, &headerPartition));
    headerPartition->key = MXF_PP_K(ClosedComplete, Header);
    headerPartition->bodySID = 1;
    CHK_OFAIL(mxf_append_partition_esscont_label(headerPartition, &MXF_EC_L(BWFFrameWrapped)));
    CHK_OFAIL(mxf_append_partition_esscont_label(headerPartition, &MXF_EC_L(BWFClipWrapped)));
    CHK_OFAIL(mxf_write_partition(mxfFile, headerPartition));

    /* write essence element directly */
    CHK_OFAIL(mxf_write_fixed_kl(mxfFile, &g_bwfFrameWrappedEEKey, 4, 256));
    CHK_OFAIL(mxf_file_write(mxfFile, essenceData, 256));

    /* write the body pp 1 */
    CHK_OFAIL(mxf_append_new_from_partition(&partitions, headerPartition, &bodyPartition1));
    bodyPartition1->key = MXF_PP_K(ClosedComplete, Body);
    bodyPartition1->bodySID = 2;
    CHK_OFAIL(mxf_write_partition(mxfFile, bodyPartition1));

    /* write using MXFEssenceElement with known length */
    CHK_OFAIL(mxf_open_essence_element_write(mxfFile, &g_bwfClipWrappedEEKey, 8, 1024, &essenceElement));
    CHK_OFAIL(mxf_write_essence_element_data(mxfFile, essenceElement, essenceData, 1024));
    mxf_close_essence_element(&essenceElement);


    /* write the body pp 2 */
    CHK_OFAIL(mxf_append_new_from_partition(&partitions, headerPartition, &bodyPartition2));
    bodyPartition2->key = MXF_PP_K(ClosedComplete, Body);
    bodyPartition2->bodySID = 3;
    CHK_OFAIL(mxf_write_partition(mxfFile, bodyPartition2));

    /* write using MXFEssenceElement with uknown length */
    CHK_OFAIL(mxf_open_essence_element_write(mxfFile, &g_bwfClipWrappedEEKey, 8, 0, &essenceElement));
    CHK_OFAIL(mxf_write_essence_element_data(mxfFile, essenceElement, essenceData, 256));
    CHK_OFAIL(mxf_write_essence_element_data(mxfFile, essenceElement, essenceData, 512));
    CHK_OFAIL(mxf_write_essence_element_data(mxfFile, essenceElement, essenceData, 256));
    CHK_ORET(mxf_finalize_essence_element_write(mxfFile, essenceElement));
    mxf_close_essence_element(&essenceElement);


    /* write the footer pp */
    CHK_OFAIL(mxf_append_new_from_partition(&partitions, headerPartition, &footerPartition));
    footerPartition->key = MXF_PP_K(ClosedComplete, Footer);
    CHK_OFAIL(mxf_write_partition(mxfFile, footerPartition));

    /* update the partitions */
    CHK_OFAIL(mxf_update_partitions(mxfFile, &partitions));


    mxf_file_close(&mxfFile);
    mxf_clear_file_partitions(&partitions);
    mxf_close_essence_element(&essenceElement);
    return 1;

fail:
    mxf_file_close(&mxfFile);
    mxf_clear_file_partitions(&partitions);
    mxf_close_essence_element(&essenceElement);
    return 0;
}