Ejemplo n.º 1
0
int test_modify(const char* filename)
{
    MXFFile* mxfFile = NULL;
    
    
    if (!mxf_disk_file_open_modify(filename, &mxfFile))
    {
        mxf_log_error("Failed to open modify '%s'" LOG_LOC_FORMAT, filename, LOG_LOC_PARAMS);
        return 0;
    }

    /* TEST */

    CHK_OFAIL(do_write(mxfFile));
    
    mxf_file_close(&mxfFile);
    
    CHK_OFAIL(test_read(filename));
    
    return 1;
    
fail:
    mxf_file_close(&mxfFile);
    return 0;
}
Ejemplo n.º 2
0
int main(int argv, const char* argc[])
{
    FILE* dv50File = NULL;
    MXFFile* mxfFile = NULL;
    int result;
    int cmdlnIndex = 1;
    int test = 0;
    
    if (argv < 3 || argv > 4)
    {
        usage(argc[0]);
        return 1;
    }
    
    if (argv == 4)
    {
        if (strcmp(argc[cmdlnIndex], "--test") != 0)
        {
            usage(argc[0]);
            return 1;
        }
        test = 1;
        
        cmdlnIndex++;
    }
    
    if ((dv50File = fopen(argc[cmdlnIndex], "rb")) == NULL)
    {
        fprintf(stderr, "Failed to open %s for reading\n", argc[1]);
        return 1;
    }
    cmdlnIndex++;
    
    if (!mxf_disk_file_open_new(argc[cmdlnIndex], &mxfFile))
    {
        fprintf(stderr, "Failed to open %s for writing\n", argc[2]);
        fclose(dv50File);
        return 1;
    }
    cmdlnIndex++;

    
    if (!write_dv50(dv50File, mxfFile, test))
    {
        result = 1;
    }
    else
    {
        result = 0;
    }

    
    fclose(dv50File);
    mxf_file_close(&mxfFile);
    
    return result;
}
Ejemplo n.º 3
0
int archive_mxf_is_metadata_only(const char* filename)
{
    MXFPageFile* mxfPageFile = NULL;
    MXFFile* mxfFile = NULL;
    mxfKey key;
    uint8_t llen;
    uint64_t len;
    MXFPartition* headerPartition = NULL;
    int result;
    
    /* open MXF file */
    if (strstr(filename, "%d") != NULL)
    {
        CHK_OFAIL_NOMSG(mxf_page_file_open_read(filename, &mxfPageFile));
        mxfFile = mxf_page_file_get_file(mxfPageFile);
    }
    else
    {
        CHK_OFAIL_NOMSG(mxf_disk_file_open_read(filename, &mxfFile));
    }
    
    /* read header partition pack */
    if (!mxf_read_header_pp_kl_with_runin(mxfFile, &key, &llen, &len) ||
        !mxf_read_partition(mxfFile, &key, &headerPartition))
    {
        return 0;
    }
    
    /* check whether there is an essence container label */
    result = (mxf_get_list_length(&headerPartition->essenceContainers) == 0);

    mxf_free_partition(&headerPartition);
    mxf_file_close(&mxfFile);
    return result;

fail:
    mxf_free_partition(&headerPartition);
    mxf_file_close(&mxfFile);
    return 0;
}
Ejemplo n.º 4
0
int mxf_page_file_open_new(const char *filenameTemplate, int64_t pageSize, MXFPageFile **mxfPageFile)
{
    MXFFile *newMXFFile = NULL;

    if (strstr(filenameTemplate, "%d") == NULL)
    {
        mxf_log_error("Filename template '%s' doesn't contain %%d\n", filenameTemplate);
        return 0;
    }

    CHK_MALLOC_ORET(newMXFFile, MXFFile);
    memset(newMXFFile, 0, sizeof(*newMXFFile));

    newMXFFile->close           = page_file_close;
    newMXFFile->read            = page_file_read;
    newMXFFile->write           = page_file_write;
    newMXFFile->get_char        = page_file_getchar;
    newMXFFile->put_char        = page_file_putchar;
    newMXFFile->eof             = page_file_eof;
    newMXFFile->seek            = page_file_seek;
    newMXFFile->tell            = page_file_tell;
    newMXFFile->is_seekable     = page_file_is_seekable;
    newMXFFile->size            = page_file_size;
    newMXFFile->free_sys_data   = free_page_file;


    CHK_MALLOC_OFAIL(newMXFFile->sysData, MXFFileSysData);
    memset(newMXFFile->sysData, 0, sizeof(*newMXFFile->sysData));

    CHK_OFAIL((newMXFFile->sysData->filenameTemplate = strdup(filenameTemplate)) != NULL);
    newMXFFile->sysData->pageSize = pageSize;
    newMXFFile->sysData->mode = WRITE_MODE;
    newMXFFile->sysData->mxfPageFile.mxfFile = newMXFFile;


    *mxfPageFile = &newMXFFile->sysData->mxfPageFile;
    return 1;

fail:
    if (newMXFFile != NULL)
    {
        mxf_file_close(&newMXFFile);
    }
    return 0;
}
Ejemplo n.º 5
0
int mxf_mem_file_open_read(const unsigned char *data, int64_t size, int64_t virtualStartPos, MXFMemoryFile **mxfMemFile)
{
    MXFFile *newMXFFile = NULL;

    CHK_MALLOC_ORET(newMXFFile, MXFFile);
    memset(newMXFFile, 0, sizeof(*newMXFFile));

    newMXFFile->close           = mem_file_close;
    newMXFFile->read            = mem_file_read;
    newMXFFile->write           = mem_file_write;
    newMXFFile->get_char        = mem_file_getchar;
    newMXFFile->put_char        = mem_file_putchar;
    newMXFFile->eof             = mem_file_eof;
    newMXFFile->seek            = mem_file_seek;
    newMXFFile->tell            = mem_file_tell;
    newMXFFile->is_seekable     = mem_file_is_seekable;
    newMXFFile->size            = mem_file_size;
    newMXFFile->free_sys_data   = free_mem_file;


    CHK_MALLOC_OFAIL(newMXFFile->sysData, MXFFileSysData);
    memset(newMXFFile->sysData, 0, sizeof(*newMXFFile->sysData));

    newMXFFile->sysData->virtualStartPos    = virtualStartPos;
    newMXFFile->sysData->readOnly           = 1;
    newMXFFile->sysData->mxfMemFile.mxfFile = newMXFFile;


    CHK_MALLOC_OFAIL(newMXFFile->sysData->chunks, Chunk);

    newMXFFile->sysData->chunks->data      = (unsigned char*)data;
    newMXFFile->sysData->chunks->allocSize = size;
    newMXFFile->sysData->chunks->size      = size;
    newMXFFile->sysData->numChunks++;


    *mxfMemFile = &newMXFFile->sysData->mxfMemFile;
    return 1;

fail:
    if (newMXFFile)
        mxf_file_close(&newMXFFile);
    return 0;
}
Ejemplo n.º 6
0
int mxf_mem_file_open_new(uint32_t chunkSize, int64_t virtualStartPos, MXFMemoryFile **mxfMemFile)
{
    MXFFile *newMXFFile = NULL;

    CHK_MALLOC_ORET(newMXFFile, MXFFile);
    memset(newMXFFile, 0, sizeof(*newMXFFile));

    newMXFFile->close           = mem_file_close;
    newMXFFile->read            = mem_file_read;
    newMXFFile->write           = mem_file_write;
    newMXFFile->get_char        = mem_file_getchar;
    newMXFFile->put_char        = mem_file_putchar;
    newMXFFile->eof             = mem_file_eof;
    newMXFFile->seek            = mem_file_seek;
    newMXFFile->tell            = mem_file_tell;
    newMXFFile->is_seekable     = mem_file_is_seekable;
    newMXFFile->size            = mem_file_size;
    newMXFFile->free_sys_data   = free_mem_file;


    CHK_MALLOC_OFAIL(newMXFFile->sysData, MXFFileSysData);
    memset(newMXFFile->sysData, 0, sizeof(*newMXFFile->sysData));

    newMXFFile->sysData->chunkSize          = (chunkSize == 0 ? DEFAULT_CHUNK_SIZE : chunkSize);
    newMXFFile->sysData->virtualStartPos    = virtualStartPos;
    newMXFFile->sysData->mxfMemFile.mxfFile = newMXFFile;


    *mxfMemFile = &newMXFFile->sysData->mxfMemFile;
    return 1;

fail:
    if (newMXFFile)
        mxf_file_close(&newMXFFile);
    return 0;
}
Ejemplo n.º 7
0
int archive_mxf_read_footer_metadata(const char* filename, MXFDataModel* dataModel, MXFHeaderMetadata** headerMetadata)
{
    MXFPageFile* mxfPageFile = NULL;
    MXFFile* mxfFile = NULL;
    MXFRIP rip;
    MXFRIPEntry* lastRIPEntry = NULL;
    mxfKey key;
    uint8_t llen;
    uint64_t len;
    MXFPartition* footerPartition = NULL;
    int result = 0;
    MXFHeaderMetadata* newHeaderMetadata = NULL;
    
    memset(&rip, 0, sizeof(rip));
 
    
    /* open MXF file */    
    if (strstr(filename, "%d") != NULL)
    {
        CHK_OFAIL_NOMSG(mxf_page_file_open_read(filename, &mxfPageFile));
        mxfFile = mxf_page_file_get_file(mxfPageFile);
    }
    else
    {
        CHK_OFAIL_NOMSG(mxf_disk_file_open_read(filename, &mxfFile));
    }
    
    /* read the RIP */
    CHK_OFAIL_NOMSG(mxf_read_rip(mxfFile, &rip));
    
    /* read footer partition pack */
    CHK_OFAIL_NOMSG((lastRIPEntry = (MXFRIPEntry*)mxf_get_last_list_element(&rip.entries)) != NULL);
    CHK_OFAIL_NOMSG(mxf_file_seek(mxfFile, mxf_get_runin_len(mxfFile) + lastRIPEntry->thisPartition, SEEK_SET));
    CHK_OFAIL_NOMSG(mxf_read_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL_NOMSG(mxf_is_partition_pack(&key));
    result = 2; /* the file is complete and the presence, or not, of the header metadata will not change */
    *headerMetadata = NULL;
    
    CHK_OFAIL_NOMSG(mxf_is_footer_partition_pack(&key));
    CHK_OFAIL_NOMSG(mxf_read_partition(mxfFile, &key, &footerPartition));
    
    /* read the header metadata */
    CHK_OFAIL_NOMSG(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL_NOMSG(mxf_is_header_metadata(&key));
    CHK_OFAIL_NOMSG(mxf_create_header_metadata(&newHeaderMetadata, dataModel));
    CHK_OFAIL_NOMSG(mxf_read_header_metadata(mxfFile, newHeaderMetadata, 
        footerPartition->headerByteCount, &key, llen, len));

    mxf_free_partition(&footerPartition);
    mxf_clear_rip(&rip);
    mxf_file_close(&mxfFile);
    
    *headerMetadata = newHeaderMetadata;
    newHeaderMetadata = NULL;
    return 1;
 
    
fail:
    mxf_free_header_metadata(&newHeaderMetadata);
    mxf_free_partition(&footerPartition);
    mxf_clear_rip(&rip);
    mxf_file_close(&mxfFile);
    return result;
}
Ejemplo n.º 8
0
int mxf_page_file_open_modify(const char *filenameTemplate, int64_t pageSize, MXFPageFile **mxfPageFile)
{
    MXFFile *newMXFFile = NULL;
    int pageCount;
    int allocatedPages;
    char filename[4096];
    FILE *file;
    int64_t fileSize;


    if (strstr(filenameTemplate, "%d") == NULL)
    {
        mxf_log_error("Filename template '%s' doesn't contain %%d\n", filenameTemplate);
        return 0;
    }

    /* count number of page files */
    pageCount = 0;
    for(;;)
    {
        mxf_snprintf(filename, sizeof(filename), filenameTemplate, pageCount);
        if ((file = fopen(filename, "rb")) == NULL)
        {
            break;
        }
        fclose(file);
        pageCount++;
    }

    if (pageCount == 0)
    {
        /* file not found */
        return 0;
    }

    /* check the size of the first file equals the pageSize */
    if (pageCount > 1)
    {
        mxf_snprintf(filename, sizeof(filename), filenameTemplate, 0);
        fileSize = disk_file_size(filename);
        if (fileSize < 0)
        {
            mxf_log_error("Failed to stat file '%s': %s\n", filename, strerror(errno));
            return 0;
        }
        if (pageSize != fileSize)
        {
            mxf_log_error("Size of first file '%s' (%"PRId64" does not equal page size %"PRId64"\n", filename, fileSize, pageSize);
            return 0;
        }
    }


    CHK_MALLOC_ORET(newMXFFile, MXFFile);
    memset(newMXFFile, 0, sizeof(*newMXFFile));

    newMXFFile->close           = page_file_close;
    newMXFFile->read            = page_file_read;
    newMXFFile->write           = page_file_write;
    newMXFFile->get_char        = page_file_getchar;
    newMXFFile->put_char        = page_file_putchar;
    newMXFFile->eof             = page_file_eof;
    newMXFFile->seek            = page_file_seek;
    newMXFFile->tell            = page_file_tell;
    newMXFFile->is_seekable     = page_file_is_seekable;
    newMXFFile->size            = page_file_size;
    newMXFFile->free_sys_data   = free_page_file;


    CHK_MALLOC_OFAIL(newMXFFile->sysData, MXFFileSysData);
    memset(newMXFFile->sysData, 0, sizeof(*newMXFFile->sysData));

    CHK_OFAIL((newMXFFile->sysData->filenameTemplate = strdup(filenameTemplate)) != NULL);
    newMXFFile->sysData->pageSize = pageSize;
    newMXFFile->sysData->mode = MODIFY_MODE;
    newMXFFile->sysData->mxfPageFile.mxfFile = newMXFFile;


    /* allocate pages */
    allocatedPages = (pageCount < PAGE_ALLOC_INCR) ? PAGE_ALLOC_INCR : pageCount;
    CHK_MALLOC_ARRAY_ORET(newMXFFile->sysData->pages, Page, allocatedPages);
    memset(newMXFFile->sysData->pages, 0, allocatedPages * sizeof(Page));
    newMXFFile->sysData->numPages = pageCount;
    newMXFFile->sysData->numPagesAllocated = allocatedPages;
    for (pageCount = 0; pageCount < newMXFFile->sysData->numPages; pageCount++)
    {
        newMXFFile->sysData->pages[pageCount].index = pageCount;
        newMXFFile->sysData->pages[pageCount].size = pageSize;
    }

    /* set the files size of the last file, which could have size < pageSize */
    mxf_snprintf(filename, sizeof(filename), filenameTemplate, newMXFFile->sysData->numPages - 1);
    fileSize = disk_file_size(filename);
    if (fileSize < 0)
    {
        mxf_log_error("Failed to stat file '%s': %s\n", filename, strerror(errno));
        goto fail;
    }
    newMXFFile->sysData->pages[newMXFFile->sysData->numPages - 1].size = fileSize;


    *mxfPageFile = &newMXFFile->sysData->mxfPageFile;
    return 1;

fail:
    if (newMXFFile != NULL)
    {
        mxf_file_close(&newMXFFile);
    }
    return 0;
}
Ejemplo n.º 9
0
int main()
{
    MXFPageFile *mxfPageFile;
    MXFFile *mxfFile;
    uint8_t *data;
    int i;

    data = malloc(DATA_SIZE);


    remove_test_files();


    CHECK(mxf_page_file_open_new(g_testFile, PAGE_SIZE, &mxfPageFile));
    mxfFile = mxf_page_file_get_file(mxfPageFile);

    memset(data, 0, DATA_SIZE);

    CHECK(mxf_file_write(mxfFile, data, DATA_SIZE) == DATA_SIZE);

    mxf_file_close(&mxfFile);



    CHECK(mxf_page_file_open_modify(g_testFile, PAGE_SIZE, &mxfPageFile));
    mxfFile = mxf_page_file_get_file(mxfPageFile);

    memset(data, 1, DATA_SIZE);

    CHECK(mxf_file_size(mxfFile) == DATA_SIZE);
    CHECK(mxf_file_read(mxfFile, data, DATA_SIZE) == DATA_SIZE);
    CHECK(mxf_file_eof(mxfFile));
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE);

    CHECK(mxf_file_write(mxfFile, data, DATA_SIZE) == DATA_SIZE);
    CHECK(mxf_file_eof(mxfFile));
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE * 2);

    CHECK(mxf_file_seek(mxfFile, 0, SEEK_SET));
    CHECK(mxf_file_tell(mxfFile) == 0);
    CHECK(mxf_file_write(mxfFile, data, DATA_SIZE) == DATA_SIZE);

    mxf_file_close(&mxfFile);



    CHECK(mxf_page_file_open_read(g_testFile, &mxfPageFile));
    mxfFile = mxf_page_file_get_file(mxfPageFile);

    memset(data, 1, DATA_SIZE);

    CHECK(mxf_file_size(mxfFile) == DATA_SIZE * 2);
    CHECK(mxf_file_read(mxfFile, data, DATA_SIZE) == DATA_SIZE);
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE);
    CHECK(mxf_file_read(mxfFile, data, DATA_SIZE) == DATA_SIZE);
    CHECK(mxf_file_eof(mxfFile));
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE * 2);
    CHECK(mxf_file_seek(mxfFile, 0, SEEK_SET));
    CHECK(mxf_file_tell(mxfFile) == 0);
    CHECK(mxf_file_read(mxfFile, data, DATA_SIZE) == DATA_SIZE);
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE);
    CHECK(mxf_file_seek(mxfFile, DATA_SIZE + 1, SEEK_SET));
    CHECK(mxf_file_read(mxfFile, data, DATA_SIZE - 1) == DATA_SIZE - 1);
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE * 2);
    CHECK(mxf_file_seek(mxfFile, DATA_SIZE - 1, SEEK_SET));
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE - 1);
    CHECK(mxf_file_seek(mxfFile, DATA_SIZE * 2, SEEK_SET));
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE * 2);
    CHECK(mxf_file_seek(mxfFile, 0, SEEK_END));
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE * 2);
    CHECK(mxf_file_seek(mxfFile, -DATA_SIZE * 2, SEEK_END));
    CHECK(mxf_file_tell(mxfFile) == 0);
    CHECK(mxf_file_seek(mxfFile, DATA_SIZE - 5, SEEK_CUR));
    CHECK(mxf_file_tell(mxfFile) == DATA_SIZE - 5);
    CHECK(mxf_file_read(mxfFile, data, DATA_SIZE) == DATA_SIZE);

    mxf_file_close(&mxfFile);



    CHECK(mxf_page_file_open_new("pagetest_out__%d.mxf", PAGE_SIZE, &mxfPageFile));
    mxfFile = mxf_page_file_get_file(mxfPageFile);

    CHECK(mxf_file_write(mxfFile, data, DATA_SIZE) == DATA_SIZE);

    mxf_file_close(&mxfFile);

    CHECK(mxf_page_file_remove("pagetest_out__%d.mxf"));


    /* test forward truncate */

    CHECK(mxf_page_file_open_new(g_testFile, PAGE_SIZE, &mxfPageFile));
    mxfFile = mxf_page_file_get_file(mxfPageFile);

    memset(data, 0, DATA_SIZE);

    for (i = 0; i < 10; i++)
    {
        CHECK(mxf_file_write(mxfFile, data, DATA_SIZE) == DATA_SIZE);
    }

    mxf_file_close(&mxfFile);


    CHECK(mxf_page_file_open_modify(g_testFile, PAGE_SIZE, &mxfPageFile));
    mxfFile = mxf_page_file_get_file(mxfPageFile);

    memset(data, 1, DATA_SIZE);

    CHECK(mxf_page_file_forward_truncate(mxfPageFile));

    for (i = 0; i < 5; i++)
    {
        CHECK(mxf_file_read(mxfFile, data, DATA_SIZE) == DATA_SIZE);
    }
    CHECK(mxf_page_file_forward_truncate(mxfPageFile));

    for (i = 0; i < 4; i++)
    {
        CHECK(mxf_file_read(mxfFile, data, DATA_SIZE) == DATA_SIZE);
    }
    CHECK(mxf_page_file_forward_truncate(mxfPageFile));

    CHECK(mxf_file_read(mxfFile, data, DATA_SIZE) == DATA_SIZE);
    CHECK(mxf_page_file_forward_truncate(mxfPageFile));

    mxf_file_close(&mxfFile);

    CHECK(mxf_page_file_remove(g_testFile));


    free(data);

    return 0;
}
Ejemplo n.º 10
0
int test_create_and_write(const char *filename)
{
    MXFFile *mxfFile = NULL;
    uint8_t runin[RUNIN_LEN];
    MXFFilePartitions partitions;
    MXFPartition *headerPartition = NULL;
    MXFPartition *bodyPartition1 = NULL;
    MXFPartition *bodyPartition2 = NULL;
    MXFPartition *footerPartition = NULL;


    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 8 bytes of runin */
    memset(runin, 0, RUNIN_LEN);
    CHK_OFAIL(mxf_file_write(mxfFile, runin, RUNIN_LEN) == RUNIN_LEN);

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

    /* write empty header metadata */
    CHK_OFAIL(mxf_mark_header_start(mxfFile, headerPartition));
    CHK_OFAIL(mxf_allocate_space(mxfFile, 1024));
    CHK_OFAIL(mxf_mark_header_end(mxfFile, headerPartition));

    /* 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 the body pp 2, with KAG 256 */
    CHK_OFAIL(mxf_append_new_from_partition(&partitions, headerPartition, &bodyPartition2));
    bodyPartition2->key = MXF_PP_K(ClosedComplete, Body);
    bodyPartition2->bodySID = 3;
    bodyPartition2->kagSize = 256;
    CHK_OFAIL(mxf_write_partition(mxfFile, bodyPartition2));
    CHK_OFAIL(mxf_fill_to_kag(mxfFile, bodyPartition2));

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

    /* write RIP */
    CHK_OFAIL(mxf_write_rip(mxfFile, &partitions));

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


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

fail:
    mxf_file_close(&mxfFile);
    mxf_clear_file_partitions(&partitions);
    return 0;
}
Ejemplo n.º 11
0
int test_read(const char *filename)
{
    MXFFile *mxfFile = NULL;
    MXFFilePartitions partitions;
    MXFPartition *headerPartition = NULL;
    mxfKey key;
    uint8_t llen;
    uint64_t len;
    int i;
    int k;
    MXFIndexTableSegment *indexSegment = NULL;
    MXFDeltaEntry *deltaEntry;
    MXFIndexEntry *indexEntry;


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

    mxf_initialise_file_partitions(&partitions);

    /* read header pp */
    CHK_OFAIL(mxf_read_header_pp_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_read_partition(mxfFile, &key, len, &headerPartition));
    CHK_OFAIL(mxf_append_partition(&partitions, headerPartition));


    /* TEST */

    /* read index table segment */

    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_is_index_table_segment(&key));
    CHK_OFAIL(mxf_read_index_table_segment(mxfFile, len, &indexSegment));
    CHK_OFAIL(indexSegment->indexEditRate.numerator == 25 && indexSegment->indexEditRate.denominator == 1);
    CHK_OFAIL(indexSegment->indexStartPosition == 0);
    CHK_OFAIL(indexSegment->indexDuration == 0x64);
    CHK_OFAIL(indexSegment->editUnitByteCount == 0x100);
    CHK_OFAIL(indexSegment->indexSID == 1);
    CHK_OFAIL(indexSegment->bodySID == 2);
    CHK_OFAIL(indexSegment->sliceCount == 0);
    CHK_OFAIL(indexSegment->posTableCount == 0);
    CHK_OFAIL(indexSegment->extStartOffset == 0);
    CHK_OFAIL(indexSegment->vbeByteCount == 0);
    CHK_OFAIL(indexSegment->singleIndexLocation == MXF_OPT_BOOL_NOT_PRESENT);
    CHK_OFAIL(indexSegment->singleEssenceLocation == MXF_OPT_BOOL_NOT_PRESENT);
    CHK_OFAIL(indexSegment->forwardIndexDirection == MXF_OPT_BOOL_NOT_PRESENT);
    CHK_OFAIL(indexSegment->deltaEntryArray != 0);
    CHK_OFAIL(indexSegment->indexEntryArray == 0);
    deltaEntry = indexSegment->deltaEntryArray;
    for (i = 0; i < 4; i++)
    {
        CHK_OFAIL(deltaEntry != 0);

        CHK_OFAIL(deltaEntry->posTableIndex == i);
        CHK_OFAIL(deltaEntry->slice == i);
        CHK_OFAIL((int)deltaEntry->elementData == i);

        deltaEntry = deltaEntry->next;
    }

    mxf_free_index_table_segment(&indexSegment);

    /* read index table segment */

    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_is_index_table_segment(&key));
    CHK_OFAIL(mxf_read_index_table_segment(mxfFile, len, &indexSegment));
    CHK_OFAIL(indexSegment->indexEditRate.numerator == 25 && indexSegment->indexEditRate.denominator == 1);
    CHK_OFAIL(indexSegment->indexStartPosition == 0);
    CHK_OFAIL(indexSegment->indexDuration == 0x0a);
    CHK_OFAIL(indexSegment->editUnitByteCount == 0);
    CHK_OFAIL(indexSegment->indexSID == 1);
    CHK_OFAIL(indexSegment->bodySID == 2);
    CHK_OFAIL(indexSegment->sliceCount == 2);
    CHK_OFAIL(indexSegment->posTableCount == 2);
    CHK_OFAIL(indexSegment->extStartOffset == 0);
    CHK_OFAIL(indexSegment->vbeByteCount == 1);
    CHK_OFAIL(indexSegment->singleIndexLocation == MXF_OPT_BOOL_NOT_PRESENT);
    CHK_OFAIL(indexSegment->singleEssenceLocation == MXF_OPT_BOOL_TRUE);
    CHK_OFAIL(indexSegment->forwardIndexDirection == MXF_OPT_BOOL_FALSE);
    CHK_OFAIL(indexSegment->deltaEntryArray == 0);
    CHK_OFAIL(indexSegment->indexEntryArray != 0);
    indexEntry = indexSegment->indexEntryArray;
    for (i = 0; i < indexSegment->indexDuration; i++)
    {
        CHK_OFAIL(indexEntry != 0);

        CHK_OFAIL(indexEntry->temporalOffset == i);
        CHK_OFAIL(indexEntry->keyFrameOffset == i);
        CHK_OFAIL(indexEntry->flags == i);
        CHK_OFAIL((int)indexEntry->streamOffset == i);

        for (k = 0; k < indexSegment->sliceCount; k++)
        {
            CHK_OFAIL((int)indexEntry->sliceOffset[k] == i);
        }

        for (k = 0; k < indexSegment->posTableCount; k++)
        {
            CHK_OFAIL(indexEntry->posTable[k].numerator == i);
            CHK_OFAIL(indexEntry->posTable[k].denominator == i + 1);
        }
        indexEntry = indexEntry->next;
    }



    mxf_free_index_table_segment(&indexSegment);
    mxf_file_close(&mxfFile);
    mxf_clear_file_partitions(&partitions);
    return 1;

fail:
    mxf_free_index_table_segment(&indexSegment);
    mxf_file_close(&mxfFile);
    mxf_clear_file_partitions(&partitions);
    return 0;
}
Ejemplo n.º 12
0
int test_create_and_write(const char *filename)
{
    MXFFile *mxfFile = NULL;
    MXFFilePartitions partitions;
    MXFPartition *headerPartition = NULL;
    MXFIndexTableSegment *indexSegment = NULL;
    uint32_t sliceOffset[2];
    mxfRational posTable[2];
    const mxfRational editRate = {25, 1};
    int i;
    int k;


    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->kagSize = 256;
    CHK_OFAIL(mxf_write_partition(mxfFile, headerPartition));

    /* write index table segment */
    CHK_OFAIL(mxf_mark_index_start(mxfFile, headerPartition));

    CHK_OFAIL(mxf_create_index_table_segment(&indexSegment));
    mxf_generate_uuid(&indexSegment->instanceUID);
    indexSegment->indexEditRate = editRate;
    indexSegment->indexDuration = 0x64;
    indexSegment->editUnitByteCount = 0x100;
    indexSegment->indexSID = 1;
    indexSegment->bodySID = 2;
    for (i = 0; i < 4; i++)
    {
        CHK_OFAIL(mxf_default_add_delta_entry(NULL, 0, indexSegment, i, i, i));
    }
    CHK_OFAIL(mxf_write_index_table_segment(mxfFile, indexSegment));

    CHK_OFAIL(mxf_fill_to_kag(mxfFile, headerPartition));

    CHK_OFAIL(mxf_mark_index_end(mxfFile, headerPartition));

    mxf_free_index_table_segment(&indexSegment);


    /* write index table segment */
    CHK_OFAIL(mxf_mark_index_start(mxfFile, headerPartition));

    CHK_OFAIL(mxf_create_index_table_segment(&indexSegment));
    mxf_generate_uuid(&indexSegment->instanceUID);
    indexSegment->indexEditRate = editRate;
    indexSegment->indexDuration = 0x0a;
    indexSegment->editUnitByteCount = 0;
    indexSegment->indexSID = 1;
    indexSegment->bodySID = 2;
    indexSegment->sliceCount = 2;
    indexSegment->posTableCount = 2;
    indexSegment->vbeByteCount = 1;
    indexSegment->singleEssenceLocation = MXF_OPT_BOOL_TRUE;
    indexSegment->forwardIndexDirection = MXF_OPT_BOOL_FALSE;
    for (i = 0; i < indexSegment->indexDuration; i++)
    {
        for (k = 0; k < indexSegment->sliceCount; k++)
        {
            sliceOffset[k] = i;
        }
        for (k = 0; k < indexSegment->posTableCount; k++)
        {
            posTable[k].numerator = i;
            posTable[k].denominator = i + 1;
        }
        CHK_OFAIL(mxf_default_add_index_entry(NULL, 0, indexSegment, i, i, i, i,
            sliceOffset, posTable));
    }
    CHK_OFAIL(mxf_write_index_table_segment(mxfFile, indexSegment));

    CHK_OFAIL(mxf_fill_to_kag(mxfFile, headerPartition));

    CHK_OFAIL(mxf_mark_index_end(mxfFile, headerPartition));



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


    mxf_file_close(&mxfFile);
    mxf_clear_file_partitions(&partitions);
    mxf_free_index_table_segment(&indexSegment);
    return 1;

fail:
    mxf_file_close(&mxfFile);
    mxf_clear_file_partitions(&partitions);
    mxf_free_index_table_segment(&indexSegment);
    return 0;
}
Ejemplo n.º 13
0
int test_read(const char *filename)
{
    MXFFile *mxfFile = NULL;
    MXFFilePartitions partitions;
    MXFPartition *headerPartition = NULL;
    MXFPartition *bodyPartition1 = NULL;
    MXFPartition *bodyPartition2 = NULL;
    MXFPartition *footerPartition = NULL;
    mxfKey key;
    uint8_t llen;
    uint64_t len;
    uint8_t essenceData[1024];
    MXFEssenceElement *essenceElement = NULL;
    uint32_t numRead;

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

    mxf_initialise_file_partitions(&partitions);


    /* TEST */

    /* read header pp */
    CHK_OFAIL(mxf_read_header_pp_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_read_partition(mxfFile, &key, &headerPartition));
    CHK_OFAIL(mxf_append_partition(&partitions, headerPartition));

    /* read essence data directly */
    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_is_gc_essence_element(&key));
    CHK_OFAIL(llen == 4 && len == 256);
    CHK_OFAIL(mxf_file_read(mxfFile, essenceData, (uint32_t)len));

    /* read body pp 1 */
    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_is_partition_pack(&key));
    CHK_OFAIL(mxf_read_partition(mxfFile, &key, &bodyPartition1));
    CHK_OFAIL(mxf_append_partition(&partitions, bodyPartition1));

    /* read essence data using MXFEssenceElement */
    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_open_essence_element_read(mxfFile, &key, llen, len, &essenceElement));
    CHK_OFAIL(llen == 8 && len == 1024);
    CHK_OFAIL(mxf_read_essence_element_data(mxfFile, essenceElement, (uint32_t)len, essenceData, &numRead));
    CHK_OFAIL(numRead == len);
    mxf_close_essence_element(&essenceElement);


    /* read body pp 2 */
    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_is_partition_pack(&key));
    CHK_OFAIL(mxf_read_partition(mxfFile, &key, &bodyPartition2));
    CHK_OFAIL(mxf_append_partition(&partitions, bodyPartition2));

    /* read essence data using MXFEssenceElement */
    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_open_essence_element_read(mxfFile, &key, llen, len, &essenceElement));
    CHK_OFAIL(llen == 8 && len == 1024);
    CHK_OFAIL(mxf_read_essence_element_data(mxfFile, essenceElement, 256, essenceData, &numRead));
    CHK_OFAIL(numRead == 256);
    CHK_OFAIL(mxf_read_essence_element_data(mxfFile, essenceElement, 768, &essenceData[256], &numRead));
    CHK_OFAIL(numRead == 768);
    mxf_close_essence_element(&essenceElement);


    /* read footer pp */
    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_is_partition_pack(&key));
    CHK_OFAIL(mxf_read_partition(mxfFile, &key, &footerPartition));
    CHK_OFAIL(mxf_append_partition(&partitions, footerPartition));



    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;
}
Ejemplo n.º 14
0
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;
}
Ejemplo n.º 15
0
static int test1(const char* mxfFilename, MXFTimecode* startTimecode, int sourceTimecodeCount, const char* outFilename)
{
    MXFReader* input;
    MXFClip* clip;
    int64_t frameCount;
    int64_t frameNumber;
    MXFReaderListenerData data;
    MXFReaderListener listener;
    MXFFile* stdinMXFFile = NULL;
    MXFTimecode playoutTimecode;
    int i;
    MXFTimecode sourceTimecode;
    int type;
    int count;
    int result;
    uint32_t archiveCRC32;

    memset(&data, 0, sizeof(MXFReaderListenerData));
    listener.data = &data;
    listener.accept_frame = accept_frame;
    listener.allocate_buffer = allocate_buffer;
    listener.deallocate_buffer = deallocate_buffer;
    listener.receive_frame = receive_frame;

    if (strcmp("-", mxfFilename) != 0)
    {
        if (!open_mxf_reader(mxfFilename, &input))
        {
            fprintf(stderr, "Failed to open MXF reader\n");
            return 0;
        }
    }
    else
    {
        if (!mxf_stdin_wrap_read(&stdinMXFFile))
        {
            fprintf(stderr, "Failed to open standard input MXF file\n");
            return 0;
        }
        if (!init_mxf_reader(&stdinMXFFile, &input))
        {
            mxf_file_close(&stdinMXFFile);
            fprintf(stderr, "Failed to open MXF reader using standard input\n");
            return 0;
        }
    }
    listener.data->input = input;

    if ((data.outFile = fopen(outFilename, "wb")) == NULL)
    {
        fprintf(stderr, "Failed to open output data file\n");
        return 0;
    }

    clip = get_mxf_clip(input);
    printf("Clip frame rate = %d/%d fps\n", clip->frameRate.numerator, clip->frameRate.denominator);
    printf("Clip duration = %"PFi64" frames\n", clip->duration);

    if (startTimecode->hour != INVALID_TIMECODE_HOUR)
    {
        if (sourceTimecodeCount < 0)
        {
            if (!position_at_playout_timecode(input, startTimecode))
            {
                fprintf(stderr, "Failed to position files at start playout timecode\n");
                return 0;
            }
        }
        else
        {
            if (!position_at_source_timecode(input, startTimecode, SYSTEM_ITEM_TC_ARRAY_TIMECODE,
                                             sourceTimecodeCount))
            {
                fprintf(stderr, "Failed to position files at start source timecode\n");
                return 0;
            }
        }
    }

    frameCount = 0;
    while (read_next_frame(input, &listener) == 1)
    {
        frameNumber = get_frame_number(input);
        printf("frame =  %"PFi64"\n", frameNumber);
        get_playout_timecode(input, &playoutTimecode);
        printf("playout timecode = ");
        print_timecode(&playoutTimecode);
        printf("\n");
        for (i = 0; i < get_num_source_timecodes(input); i++)
        {
            if ((result = get_source_timecode(input, i, &sourceTimecode, &type, &count)) == 1)
            {
                printf("source timecode (type = %d, count = %d) = ", type, count);
                print_timecode(&sourceTimecode);
                printf("\n");
            }
            else if (result == -1)
            {
                printf("source timecode (type = %d, count = %d) unavailable", type, count);
                printf("\n");
            }
        }
        for (i = 0; i < get_num_archive_crc32(input); i++)
        {
            if (get_archive_crc32(input, i, &archiveCRC32))
            {
                printf("crc32 %d = 0x%08x\n", i, archiveCRC32);
            }
            else
            {
                printf("Failed to get archive crc-32\n");
            }
        }
        frameCount++;
    }
    if (clip->duration != -1 && frameCount != clip->duration)
    {
        fprintf(stderr, "1) Frame count %"PFi64" != duration %"PFi64"\n", frameCount, clip->duration);
        return 0;
    }

    close_mxf_reader(&input);
    fclose(data.outFile);
    if (data.buffer != NULL)
    {
        free(data.buffer);
    }

    return 1;
}
Ejemplo n.º 16
0
int test_read(const char* filename)
{
    MXFFile* mxfFile = NULL;
    mxfKey key;
    uint8_t llen;
    uint64_t len;
    mxfLocalTag tag;
    uint8_t indata[256];
    uint8_t valueu8;
    uint16_t valueu16;
    uint32_t valueu32;
    uint64_t valueu64;
    int8_t value8;
    int16_t value16;
    int32_t value32;
    int64_t value64;
    mxfUL ul;
    mxfUID uid;
    mxfUUID uuid;
    uint32_t ablen;
    uint32_t abelen;

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

    /* TEST */
    CHK_OFAIL(mxf_file_read(mxfFile, indata, 100) == 100);
    CHK_OFAIL(memcmp(data, indata, 100) == 0);
    CHK_OFAIL(mxf_file_getc(mxfFile) == 0xff);
    CHK_OFAIL(mxf_file_getc(mxfFile) == 0xff);
    CHK_OFAIL(mxf_read_uint8(mxfFile, &valueu8));
    CHK_OFAIL(valueu8 == 0x0f);
    CHK_OFAIL(mxf_read_uint16(mxfFile, &valueu16));
    CHK_OFAIL(valueu16 == 0x0f00);
    CHK_OFAIL(mxf_read_uint32(mxfFile, &valueu32));
    CHK_OFAIL(valueu32 == 0x0f000000);
    CHK_OFAIL(mxf_read_uint64(mxfFile, &valueu64));
    CHK_OFAIL(valueu64 == 0x0f00000000000000LL);
    CHK_OFAIL(mxf_read_int8(mxfFile, &value8));
    CHK_OFAIL(value8 == -0x0f);
    CHK_OFAIL(mxf_read_int16(mxfFile, &value16));
    CHK_OFAIL(value16 == -0x0f00);
    CHK_OFAIL(mxf_read_int32(mxfFile, &value32));
    CHK_OFAIL(value32 == -0x0f000000);
    CHK_OFAIL(mxf_read_int64(mxfFile, &value64));
    CHK_OFAIL(value64 == -0x0f00000000000000LL);
    CHK_OFAIL(mxf_read_local_tag(mxfFile, &tag));
    CHK_OFAIL(tag == 0xffaa);
    CHK_OFAIL(mxf_read_k(mxfFile, &key));
    CHK_OFAIL(mxf_equals_key(&key, &someKey));
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 1 && len == 0x01);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 2 && len == 0x80);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 3 && len == 0x8000);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 4 && len == 0x800000);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 5 && len == 0x80000000);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 6 && len == 0x8000000000LL);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 7 && len == 0x800000000000LL);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 8 && len == 0x80000000000000LL);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 9 && len == 0x8000000000000000LL);
    CHK_OFAIL(mxf_read_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_equals_key(&key, &someKey));
    CHK_OFAIL(llen == 3 && len == 0xf100);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 8 && len == 0x10);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 4 && len == 0x10);
    CHK_OFAIL(mxf_read_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_equals_key(&key, &someKey));
    CHK_OFAIL(llen == 8 && len == 0x1000);
    CHK_OFAIL(mxf_read_ul(mxfFile, &ul));
    CHK_OFAIL(mxf_equals_ul(&ul, &someUL));
    CHK_OFAIL(mxf_read_uid(mxfFile, &uid));
    CHK_OFAIL(mxf_equals_uid(&uid, &someUID));
    CHK_OFAIL(mxf_read_uuid(mxfFile, &uuid));
    CHK_OFAIL(mxf_equals_uuid(&uuid, &someUUID));
    CHK_OFAIL(mxf_read_batch_header(mxfFile, &ablen, &abelen));
    CHK_OFAIL(ablen == 2 && abelen == 16);
    CHK_OFAIL(mxf_read_array_header(mxfFile, &ablen, &abelen));
    CHK_OFAIL(ablen == 4 && abelen == 32);


    mxf_file_close(&mxfFile);

    
    /* test reading from a byte buffer */
    
    const uint8_t data[5] = {1, 2, 3, 4, 5};
    
    if (!mxf_byte_array_wrap_read(data, sizeof(data), &mxfFile))
    {
        mxf_log_error("Failed to open byte array as MXF file" LOG_LOC_FORMAT, LOG_LOC_PARAMS);
        return 0;
    }

    CHK_OFAIL(mxf_file_tell(mxfFile) == 0);
    CHK_OFAIL(mxf_file_getc(mxfFile) == 1);
    CHK_OFAIL(mxf_file_tell(mxfFile) == 1);
    CHK_OFAIL(mxf_file_read(mxfFile, indata, 4));
    CHK_OFAIL(indata[0] == 2 && indata[1] == 3 && indata[2] == 4 && indata[3] == 5);
    CHK_OFAIL(mxf_file_tell(mxfFile) == 5);
    CHK_OFAIL(mxf_file_eof(mxfFile));
    CHK_OFAIL(mxf_file_getc(mxfFile) == EOF);
    CHK_OFAIL(mxf_file_seek(mxfFile, 0, SEEK_SET));
    CHK_OFAIL(mxf_file_tell(mxfFile) == 0);
    CHK_OFAIL(mxf_file_getc(mxfFile) == 1);
    CHK_OFAIL(mxf_file_seek(mxfFile, 2, SEEK_CUR));
    CHK_OFAIL(mxf_file_tell(mxfFile) == 3);
    CHK_OFAIL(mxf_file_getc(mxfFile) == 4);
    CHK_OFAIL(mxf_file_seek(mxfFile, 0, SEEK_END));
    CHK_OFAIL(mxf_file_tell(mxfFile) == 4);
    CHK_OFAIL(mxf_file_getc(mxfFile) == 5);
    CHK_OFAIL(!mxf_file_seek(mxfFile, 5, SEEK_END)); /* should fail */
    CHK_OFAIL(mxf_file_tell(mxfFile) == 5);
    
    
    mxf_file_close(&mxfFile);

    
    return 1;
    
fail:
    mxf_file_close(&mxfFile);
    return 0;
}
Ejemplo n.º 17
0
static int test3(const char* mxfFilename, const char* outFilename)
{
    MXFReader* input;
    int64_t frameCount;
    MXFClip* clip;
    MXFReaderListenerData data;
    MXFReaderListener listener;
    int64_t frameNumber;
    MXFFile* stdinMXFFile = NULL;
    MXFTimecode playoutTimecode;
    int i;
    MXFTimecode sourceTimecode;
    int type;
    int count;
    int result;

    memset(&data, 0, sizeof(MXFReaderListenerData));
    listener.data = &data;
    listener.accept_frame = accept_frame;
    listener.allocate_buffer = allocate_buffer;
    listener.deallocate_buffer = deallocate_buffer;
    listener.receive_frame = receive_frame;


    if (strcmp("-", mxfFilename) != 0)
    {
        if (!open_mxf_reader(mxfFilename, &input))
        {
            fprintf(stderr, "Failed to open MXF reader\n");
            return 0;
        }
    }
    else
    {
        if (!mxf_stdin_wrap_read(&stdinMXFFile))
        {
            fprintf(stderr, "Failed to open standard input MXF file\n");
            return 0;
        }
        if (!init_mxf_reader(&stdinMXFFile, &input))
        {
            mxf_file_close(&stdinMXFFile);
            fprintf(stderr, "Failed to open MXF reader using standard input\n");
            return 0;
        }
    }
    listener.data->input = input;

    if ((data.outFile = fopen(outFilename, "wb")) == NULL)
    {
        fprintf(stderr, "Failed to open output data file\n");
        return 0;
    }

    clip = get_mxf_clip(input);

    if (!position_at_frame(input, 10))
    {
        fprintf(stderr, "Failed to position at frame 10\n");
        return 0;
    }
    frameCount = 10;
    while (read_next_frame(input, &listener) == 1)
    {
        frameNumber = get_frame_number(input);
        printf("frame =  %"PFi64"\n", frameNumber);
        get_playout_timecode(input, &playoutTimecode);
        printf("playout timecode = ");
        print_timecode(&playoutTimecode);
        printf("\n");
        for (i = 0; i < get_num_source_timecodes(input); i++)
        {
            if ((result = get_source_timecode(input, i, &sourceTimecode, &type, &count)) == 1)
            {
                printf("source timecode (type = %d, count = %d) = ", type, count);
                print_timecode(&sourceTimecode);
                printf("\n");
            }
            else if (result == -1)
            {
                printf("source timecode (type = %d, count = %d) unavailable", type, count);
                printf("\n");
            }
        }
        frameCount++;
    }
    if (clip->duration != -1 && frameCount != clip->duration)
    {
        fprintf(stderr, "2) Frame count %"PFi64" != duration %"PFi64"\n", frameCount, clip->duration);
        return 0;
    }

    if (!position_at_frame(input, 0))
    {
        fprintf(stderr, "Failed to position at frame 0\n");
        return 0;
    }
    frameCount = 0;
    while (read_next_frame(input, &listener) == 1)
    {
        frameNumber = get_frame_number(input);
        printf("frame =  %"PFi64"\n", frameNumber);
        get_playout_timecode(input, &playoutTimecode);
        printf("playout timecode = ");
        print_timecode(&playoutTimecode);
        printf("\n");
        for (i = 0; i < get_num_source_timecodes(input); i++)
        {
            if ((result = get_source_timecode(input, i, &sourceTimecode, &type, &count)) == 1)
            {
                printf("source timecode (type = %d, count = %d) = ", type, count);
                print_timecode(&sourceTimecode);
                printf("\n");
            }
            else if (result == -1)
            {
                printf("source timecode (type = %d, count = %d) unavailable", type, count);
                printf("\n");
            }
        }
        frameCount++;
    }

    if (clip->duration != -1 && frameCount != clip->duration)
    {
        fprintf(stderr, "3) Frame count %"PFi64" != duration %"PFi64"\n", frameCount, clip->duration);
        return 0;
    }

    if (!position_at_frame(input, 5))
    {
        fprintf(stderr, "Failed to position at frame 5\n");
        return 0;
    }
    frameCount = 0;
    while (read_next_frame(input, &listener) == 1)
    {
        frameNumber = get_frame_number(input);
        printf("frame =  %"PFi64"\n", frameNumber);
        get_playout_timecode(input, &playoutTimecode);
        printf("playout timecode = ");
        print_timecode(&playoutTimecode);
        printf("\n");
        for (i = 0; i < get_num_source_timecodes(input); i++)
        {
            if ((result = get_source_timecode(input, i, &sourceTimecode, &type, &count)) == 1)
            {
                printf("source timecode (type = %d, count = %d) = ", type, count);
                print_timecode(&sourceTimecode);
                printf("\n");
            }
            else if (result == -1)
            {
                printf("source timecode (type = %d, count = %d) unavailable", type, count);
                printf("\n");
            }
        }
        frameCount++;
    }

    if (clip->duration != -1 && frameCount + 5 != clip->duration)
    {
        fprintf(stderr, "4) Frame count %"PFi64" != duration %"PFi64"\n", frameCount + 5, clip->duration);
        return 0;
    }


    close_mxf_reader(&input);
    fclose(data.outFile);
    if (data.buffer != NULL)
    {
        free(data.buffer);
    }

    return 1;
}
Ejemplo n.º 18
0
int test_read(const char *filename)
{
    MXFFile *mxfFile = NULL;
    MXFFilePartitions partitions;
    MXFPartition *headerPartition = NULL;
    MXFPartition *bodyPartition1 = NULL;
    MXFPartition *bodyPartition2 = NULL;
    MXFPartition *footerPartition = NULL;
    MXFListIterator iter;
    mxfKey key;
    uint8_t llen;
    uint64_t len;
    int i;
    MXFRIP rip;

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

    mxf_initialise_file_partitions(&partitions);


    /* TEST */

    /* read RIP */
    CHK_OFAIL(mxf_read_rip(mxfFile, &rip));
    CHK_OFAIL(mxf_get_list_length(&rip.entries) == 4);
    CHK_OFAIL(mxf_file_seek(mxfFile, 0, SEEK_SET));
    mxf_initialise_list_iter(&iter, &rip.entries);
    i = 0;
    while (mxf_next_list_iter_element(&iter))
    {
        MXFRIPEntry *entry = (MXFRIPEntry*)mxf_get_iter_element(&iter);
        if (i == 0)
        {
            CHK_OFAIL(entry->bodySID == 0);
            CHK_OFAIL(entry->thisPartition == RUNIN_LEN);
        }
        else if (i == 1)
        {
            CHK_OFAIL(entry->bodySID == 2);
            CHK_OFAIL(entry->thisPartition == RUNIN_LEN + 1161);
        }
        else if (i == 2)
        {
            CHK_OFAIL(entry->bodySID == 3);
            CHK_OFAIL(entry->thisPartition == RUNIN_LEN + 1298);
        }
        else
        {
            CHK_OFAIL(entry->bodySID == 0);
            CHK_OFAIL(entry->thisPartition == RUNIN_LEN + 1554);
        }
        i++;
    }

    /* read header pp, allowing for runin */
    CHK_OFAIL(mxf_read_header_pp_kl_with_runin(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_read_partition(mxfFile, &key, &headerPartition));
    CHK_OFAIL(mxf_append_partition(&partitions, headerPartition));
    CHK_OFAIL(headerPartition->indexSID == 1);
    CHK_OFAIL(headerPartition->bodySID == 0);
    CHK_OFAIL(mxf_get_list_length(&headerPartition->essenceContainers) == 2);
    mxf_initialise_list_iter(&iter, &headerPartition->essenceContainers);
    i = 0;
    while (mxf_next_list_iter_element(&iter))
    {
        mxfUL *label = (mxfUL*)mxf_get_iter_element(&iter);
        if (i == 0)
        {
            CHK_OFAIL(mxf_equals_ul(label, &MXF_EC_L(SD_Unc_625_50i_422_135_FrameWrapped)));
        }
        else
        {
            CHK_OFAIL(mxf_equals_ul(label, &MXF_EC_L(BWFFrameWrapped)));
        }
        i++;
    }

    /* skip filler and read body pp 1 */
    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_is_partition_pack(&key));
    CHK_OFAIL(mxf_read_partition(mxfFile, &key, &bodyPartition1));
    CHK_OFAIL(bodyPartition1->indexSID == 0);
    CHK_OFAIL(bodyPartition1->bodySID == 2);
    CHK_OFAIL(mxf_append_partition(&partitions, bodyPartition1));

    /* skip filler and read body pp 2 */
    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_is_partition_pack(&key));
    CHK_OFAIL(mxf_read_partition(mxfFile, &key, &bodyPartition2));
    CHK_OFAIL(bodyPartition2->indexSID == 0);
    CHK_OFAIL(bodyPartition2->bodySID == 3);
    CHK_OFAIL(mxf_append_partition(&partitions, bodyPartition2));

    /* skip filler and read footer pp */
    CHK_OFAIL(mxf_read_next_nonfiller_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_is_partition_pack(&key));
    CHK_OFAIL(mxf_read_partition(mxfFile, &key, &footerPartition));
    CHK_OFAIL(footerPartition->bodySID == 0);
    CHK_OFAIL(footerPartition->indexSID == 1);
    CHK_OFAIL(mxf_append_partition(&partitions, footerPartition));
    mxf_initialise_list_iter(&iter, &footerPartition->essenceContainers);
    i = 0;
    while (mxf_next_list_iter_element(&iter))
    {
        mxfUL *label = (mxfUL*)mxf_get_iter_element(&iter);
        if (i == 0)
        {
            CHK_OFAIL(mxf_equals_ul(label, &MXF_EC_L(SD_Unc_625_50i_422_135_FrameWrapped)));
        }
        else
        {
            CHK_OFAIL(mxf_equals_ul(label, &MXF_EC_L(BWFFrameWrapped)));
        }
        i++;
    }



    mxf_clear_rip(&rip);
    mxf_file_close(&mxfFile);
    mxf_clear_file_partitions(&partitions);
    return 1;

fail:
    mxf_clear_rip(&rip);
    mxf_file_close(&mxfFile);
    mxf_clear_file_partitions(&partitions);
    return 0;
}
Ejemplo n.º 19
0
int test_read(const char *filename)
{
    MXFFile *mxfFile = NULL;
    mxfKey key;
    uint8_t llen;
    uint64_t len;
    mxfLocalTag tag;
    uint8_t indata[256];
    uint8_t valueu8;
    uint16_t valueu16;
    uint32_t valueu32;
    uint64_t valueu64;
    int8_t value8;
    int16_t value16;
    int32_t value32;
    int64_t value64;
    mxfUL ul;
    mxfUID uid;
    mxfUUID uuid;
    uint32_t ablen;
    uint32_t abelen;

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

    /* TEST */
    CHK_OFAIL(mxf_file_read(mxfFile, indata, 100) == 100);
    CHK_OFAIL(memcmp(data, indata, 100) == 0);
    CHK_OFAIL(mxf_file_getc(mxfFile) == 0xff);
    CHK_OFAIL(mxf_file_getc(mxfFile) == 0xff);
    CHK_OFAIL(mxf_read_uint8(mxfFile, &valueu8));
    CHK_OFAIL(valueu8 == 0x0f);
    CHK_OFAIL(mxf_read_uint16(mxfFile, &valueu16));
    CHK_OFAIL(valueu16 == 0x0f00);
    CHK_OFAIL(mxf_read_uint32(mxfFile, &valueu32));
    CHK_OFAIL(valueu32 == 0x0f000000);
    CHK_OFAIL(mxf_read_uint64(mxfFile, &valueu64));
    CHK_OFAIL(valueu64 == 0x0f00000000000000LL);
    CHK_OFAIL(mxf_read_int8(mxfFile, &value8));
    CHK_OFAIL(value8 == -0x0f);
    CHK_OFAIL(mxf_read_int16(mxfFile, &value16));
    CHK_OFAIL(value16 == -0x0f00);
    CHK_OFAIL(mxf_read_int32(mxfFile, &value32));
    CHK_OFAIL(value32 == -0x0f000000);
    CHK_OFAIL(mxf_read_int64(mxfFile, &value64));
    CHK_OFAIL(value64 == -0x0f00000000000000LL);
    CHK_OFAIL(mxf_read_local_tag(mxfFile, &tag));
    CHK_OFAIL(tag == 0xffaa);
    CHK_OFAIL(mxf_read_k(mxfFile, &key));
    CHK_OFAIL(mxf_equals_key(&key, &someKey));
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 1 && len == 0x01);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 2 && len == 0x80);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 3 && len == 0x8000);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 4 && len == 0x800000);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 5 && len == 0x80000000);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 6 && len == 0x8000000000LL);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 7 && len == 0x800000000000LL);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 8 && len == 0x80000000000000LL);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 9 && len == 0x8000000000000000LL);
    CHK_OFAIL(mxf_read_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_equals_key(&key, &someKey));
    CHK_OFAIL(llen == 3 && len == 0xf100);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 8 && len == 0x10);
    CHK_OFAIL(mxf_read_l(mxfFile, &llen, &len));
    CHK_OFAIL(llen == 4 && len == 0x10);
    CHK_OFAIL(mxf_read_kl(mxfFile, &key, &llen, &len));
    CHK_OFAIL(mxf_equals_key(&key, &someKey));
    CHK_OFAIL(llen == 8 && len == 0x1000);
    CHK_OFAIL(mxf_read_ul(mxfFile, &ul));
    CHK_OFAIL(mxf_equals_ul(&ul, &someUL));
    CHK_OFAIL(mxf_read_uid(mxfFile, &uid));
    CHK_OFAIL(mxf_equals_uid(&uid, &someUID));
    CHK_OFAIL(mxf_read_uuid(mxfFile, &uuid));
    CHK_OFAIL(mxf_equals_uuid(&uuid, &someUUID));
    CHK_OFAIL(mxf_read_batch_header(mxfFile, &ablen, &abelen));
    CHK_OFAIL(ablen == 2 && abelen == 16);
    CHK_OFAIL(mxf_read_array_header(mxfFile, &ablen, &abelen));
    CHK_OFAIL(ablen == 4 && abelen == 32);


    mxf_file_close(&mxfFile);


    return 1;

fail:
    mxf_file_close(&mxfFile);
    return 0;
}