From: Philip de N. <ph...@us...> - 2011-01-25 17:39:58
|
Update of /cvsroot/ingex/ingex/libMXF/examples/avidmxfinfo In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv12118/examples/avidmxfinfo Modified Files: avid_mxf_info.c avid_mxf_info.h Log Message: parse avid tagged value attribute list - based on patch provided by Jeremy James at forbidden.co.uk Index: avid_mxf_info.c =================================================================== RCS file: /cvsroot/ingex/ingex/libMXF/examples/avidmxfinfo/avid_mxf_info.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** avid_mxf_info.c 10 Jan 2011 17:05:15 -0000 1.14 --- avid_mxf_info.c 25 Jan 2011 17:39:49 -0000 1.15 *************** *** 132,135 **** --- 132,159 ---- } + static void free_avid_tagged_values(AvidTaggedValue* value, int numValues) + { + int i, j; + + if (value == NULL) + { + return; + } + + for (i = 0; i < numValues; i++) + { + SAFE_FREE(&value[i].name); + SAFE_FREE(&value[i].value); + for (j = 0; j < value[i].numAttributes; j++) + { + SAFE_FREE(&value[i].attributes[j].name); + SAFE_FREE(&value[i].attributes[j].value); + } + SAFE_FREE(&value[i].attributes); + } + + free(value); + } + static int get_string_value(MXFMetadataSet* set, const mxfKey* itemKey, char** str, int printDebugError) { *************** *** 151,154 **** --- 175,251 ---- } + static int get_package_tagged_values(MXFMetadataSet* packageSet, const mxfKey* itemKey, int* numValues, AvidTaggedValue **values, int printDebugError) + { + MXFMetadataSet* taggedValueSet; + uint32_t count; + uint32_t i; + uint8_t* element; + mxfUTF16Char* taggedValueName = NULL; + mxfUTF16Char* taggedValueValue = NULL; + AvidTaggedValue* newValues = NULL; + int index; + MXFListIterator namesIter; + MXFListIterator valuesIter; + MXFList* taggedValueNames = NULL; + MXFList* taggedValueValues = NULL; + + FCHECK(mxf_have_item(packageSet, itemKey)); + + CHK_OFAIL(mxf_get_array_item_count(packageSet, itemKey, &count)); + + FCHECK((newValues = (AvidTaggedValue*)malloc(count * sizeof(AvidTaggedValue))) != NULL); + memset(newValues, 0, count * sizeof(AvidTaggedValue)); + + for (i = 0; i < count; i++) + { + CHK_OFAIL(mxf_get_array_item_element(packageSet, itemKey, i, &element)); + CHK_OFAIL(mxf_get_strongref(packageSet->headerMetadata, element, &taggedValueSet)); + + CHK_OFAIL(mxf_avid_read_string_tagged_value(taggedValueSet, &taggedValueName, &taggedValueValue)); + + FCHECK(convert_string(taggedValueName, &newValues[i].name, printDebugError)); + FCHECK(convert_string(taggedValueValue, &newValues[i].value, printDebugError)); + SAFE_FREE(&taggedValueName); + SAFE_FREE(&taggedValueValue); + + /* Check for any attributes */ + if (mxf_have_item(taggedValueSet, &MXF_ITEM_K(TaggedValue, TaggedValueAttributeList))) + { + CHK_OFAIL(mxf_avid_read_string_tagged_values(taggedValueSet, &MXF_ITEM_K(TaggedValue, TaggedValueAttributeList), &taggedValueNames, &taggedValueValues)); + newValues[i].numAttributes = (int)mxf_get_list_length(taggedValueNames); + + FCHECK((newValues[i].attributes = (AvidNameValuePair*)malloc(newValues[i].numAttributes * sizeof(AvidNameValuePair))) != NULL); + memset(newValues[i].attributes, 0, newValues[i].numAttributes * sizeof(AvidNameValuePair)); + + index = 0; + mxf_initialise_list_iter(&namesIter, taggedValueNames); + mxf_initialise_list_iter(&valuesIter, taggedValueValues); + while (mxf_next_list_iter_element(&namesIter) && mxf_next_list_iter_element(&valuesIter)) + { + FCHECK(convert_string(mxf_get_iter_element(&namesIter), &newValues[i].attributes[index].name, printDebugError)); + FCHECK(convert_string(mxf_get_iter_element(&valuesIter), &newValues[i].attributes[index].value, printDebugError)); + + index++; + } + + mxf_free_list(&taggedValueNames); + mxf_free_list(&taggedValueValues); + } + } + + *values = newValues; + *numValues = count; + + return 1; + + fail: + free_avid_tagged_values(newValues, count); + SAFE_FREE(&taggedValueName); + SAFE_FREE(&taggedValueValue); + mxf_free_list(&taggedValueNames); + mxf_free_list(&taggedValueValues); + return 0; + } + static int get_single_track_component(MXFMetadataSet* trackSet, const mxfKey* componentSetKey, MXFMetadataSet** componentSet, int printDebugError) { *************** *** 368,373 **** MXFList* list = NULL; MXFListIterator listIter; - MXFListIterator namesIter; - MXFListIterator valuesIter; MXFArrayItemIterator arrayIter; MXFFile* mxfFile = NULL; --- 465,468 ---- *************** *** 392,396 **** MXFList* taggedValueValues = NULL; const mxfUTF16Char* taggedValue; - int index; mxfUL dataDef; mxfUMID sourcePackageID; --- 487,490 ---- *************** *** 497,554 **** /* get the material package user comments */ - if (mxf_have_item(materialPackageSet, &MXF_ITEM_K(GenericPackage, UserComments))) { ! DCHECK(mxf_avid_read_string_user_comments(materialPackageSet, &taggedValueNames, &taggedValueValues)); ! info->numUserComments = (int)mxf_get_list_length(taggedValueNames); ! ! DCHECK((info->userComments = (AvidNameValuePair*)malloc(info->numUserComments * sizeof(AvidNameValuePair))) != NULL); ! memset(info->userComments, 0, info->numUserComments * sizeof(AvidNameValuePair)); ! ! index = 0; ! mxf_initialise_list_iter(&namesIter, taggedValueNames); ! mxf_initialise_list_iter(&valuesIter, taggedValueValues); ! while (mxf_next_list_iter_element(&namesIter) && mxf_next_list_iter_element(&valuesIter)) ! { ! DCHECK(convert_string((const mxfUTF16Char*)mxf_get_iter_element(&namesIter), ! &info->userComments[index].name, printDebugError)); ! DCHECK(convert_string((const mxfUTF16Char*)mxf_get_iter_element(&valuesIter), ! &info->userComments[index].value, printDebugError)); ! ! index++; ! } ! } - mxf_free_list(&taggedValueNames); - mxf_free_list(&taggedValueValues); - /* get the material package attributes */ - if (mxf_have_item(materialPackageSet, &MXF_ITEM_K(GenericPackage, MobAttributeList))) { ! DCHECK(mxf_avid_read_string_mob_attributes(materialPackageSet, &taggedValueNames, &taggedValueValues)); ! info->numMaterialPackageAttributes = (int)mxf_get_list_length(taggedValueNames); ! ! DCHECK((info->materialPackageAttributes = (AvidNameValuePair*)malloc(info->numMaterialPackageAttributes * sizeof(AvidNameValuePair))) != NULL); ! memset(info->materialPackageAttributes, 0, info->numMaterialPackageAttributes * sizeof(AvidNameValuePair)); ! ! index = 0; ! mxf_initialise_list_iter(&namesIter, taggedValueNames); ! mxf_initialise_list_iter(&valuesIter, taggedValueValues); ! while (mxf_next_list_iter_element(&namesIter) && mxf_next_list_iter_element(&valuesIter)) ! { ! DCHECK(convert_string((const mxfUTF16Char*)mxf_get_iter_element(&namesIter), ! &info->materialPackageAttributes[index].name, printDebugError)); ! DCHECK(convert_string((const mxfUTF16Char*)mxf_get_iter_element(&valuesIter), ! &info->materialPackageAttributes[index].value, printDebugError)); ! ! index++; ! } ! } - mxf_free_list(&taggedValueNames); - mxf_free_list(&taggedValueValues); - /* get the top level file source package and info */ --- 591,604 ---- /* get the material package user comments */ if (mxf_have_item(materialPackageSet, &MXF_ITEM_K(GenericPackage, UserComments))) { ! DCHECK(get_package_tagged_values(materialPackageSet, &MXF_ITEM_K(GenericPackage, UserComments), &info->numUserComments, &info->userComments, printDebugError)); } /* get the material package attributes */ if (mxf_have_item(materialPackageSet, &MXF_ITEM_K(GenericPackage, MobAttributeList))) { ! DCHECK(get_package_tagged_values(materialPackageSet, &MXF_ITEM_K(GenericPackage, MobAttributeList), &info->numMaterialPackageAttributes, &info->materialPackageAttributes, printDebugError)); } /* get the top level file source package and info */ *************** *** 1256,1261 **** void ami_free_info(AvidMXFInfo* info) { - int i; - SAFE_FREE(&info->clipName); SAFE_FREE(&info->projectName); --- 1306,1309 ---- *************** *** 1265,1284 **** if (info->userComments != NULL) { ! for (i = 0; i < info->numUserComments; i++) ! { ! SAFE_FREE(&info->userComments[i].name); ! SAFE_FREE(&info->userComments[i].value); ! } ! SAFE_FREE(&info->userComments); } if (info->materialPackageAttributes != NULL) { ! for (i = 0; i < info->numMaterialPackageAttributes; i++) ! { ! SAFE_FREE(&info->materialPackageAttributes[i].name); ! SAFE_FREE(&info->materialPackageAttributes[i].value); ! } ! SAFE_FREE(&info->materialPackageAttributes); } } --- 1313,1322 ---- if (info->userComments != NULL) { ! free_avid_tagged_values(info->userComments, info->numUserComments); } if (info->materialPackageAttributes != NULL) { ! free_avid_tagged_values(info->materialPackageAttributes, info->numMaterialPackageAttributes); } } *************** *** 1286,1290 **** void ami_print_info(AvidMXFInfo* info) { ! int i; printf("Project name = %s\n", (info->projectName == NULL) ? "": info->projectName); --- 1324,1328 ---- void ami_print_info(AvidMXFInfo* info) { ! int i, j; printf("Project name = %s\n", (info->projectName == NULL) ? "": info->projectName); *************** *** 1338,1341 **** --- 1376,1383 ---- { printf(" %s = %s\n", info->userComments[i].name, info->userComments[i].value); + for (j = 0; j < info->userComments[i].numAttributes; j++) + { + printf(" %s = %s\n", info->userComments[i].attributes[j].name, info->userComments[i].attributes[j].value); + } } } *************** *** 1346,1349 **** --- 1388,1395 ---- { printf(" %s = %s\n", info->materialPackageAttributes[i].name, info->materialPackageAttributes[i].value); + for (j = 0; j < info->materialPackageAttributes[i].numAttributes; j++) + { + printf(" %s = %s\n", info->materialPackageAttributes[i].attributes[j].name, info->materialPackageAttributes[i].attributes[j].value); + } } } Index: avid_mxf_info.h =================================================================== RCS file: /cvsroot/ingex/ingex/libMXF/examples/avidmxfinfo/avid_mxf_info.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** avid_mxf_info.h 29 Mar 2010 15:15:57 -0000 1.5 --- avid_mxf_info.h 25 Jan 2011 17:39:49 -0000 1.6 *************** *** 96,99 **** --- 96,107 ---- typedef struct { + char* name; + char* value; + AvidNameValuePair *attributes; + int numAttributes; + } AvidTaggedValue; + + typedef struct + { /* clip info */ char* clipName; *************** *** 103,109 **** int64_t clipDuration; mxfUMID materialPackageUID; ! AvidNameValuePair* userComments; int numUserComments; ! AvidNameValuePair* materialPackageAttributes; int numMaterialPackageAttributes; /* TODO: handle complexity of __AttributeList in attributes */ --- 111,117 ---- int64_t clipDuration; mxfUMID materialPackageUID; ! AvidTaggedValue* userComments; int numUserComments; ! AvidTaggedValue* materialPackageAttributes; int numMaterialPackageAttributes; /* TODO: handle complexity of __AttributeList in attributes */ |