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; }
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; }
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; }