1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
// =================================================================================================
// ADOBE SYSTEMS INCORPORATED
// Copyright 2008 Adobe Systems Incorporated
// All Rights Reserved
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it.
// =================================================================================================
#include "XDCAM_Support.hpp"
// =================================================================================================
/// \file XDCAM_Support.cpp
///
// =================================================================================================
namespace XDCAM_Support
{
// =================================================================================================
// CreateChildElement
// ==================
namespace
{
XML_Node * CreateChildElement ( XML_Node * parent, XMP_StringPtr localName, XMP_StringPtr legacyNS, int indent /* = 0 */ )
{
XML_Node * wsNode;
XML_Node * childNode = parent->GetNamedElement ( legacyNS, localName );
if ( childNode == 0 ) {
// The indenting is a hack, assuming existing 2 spaces per level.
wsNode = new XML_Node ( parent, "", kCDataNode );
wsNode->value = " "; // Add 2 spaces to the existing WS before the parent's close tag.
parent->content.push_back ( wsNode );
childNode = new XML_Node ( parent, localName, kElemNode );
childNode->ns = parent->ns;
childNode->nsPrefixLen = parent->nsPrefixLen;
childNode->name.insert ( 0, parent->name, 0, parent->nsPrefixLen );
parent->content.push_back ( childNode );
wsNode = new XML_Node ( parent, "", kCDataNode );
wsNode->value = '\n';
for ( ; indent > 1; --indent ) wsNode->value += " "; // Indent less 1, to "outdent" the parent's close.
parent->content.push_back ( wsNode );
}
return childNode;
}
}
// =================================================================================================
// XDCAM_Support::GetLegacyMetaData
// =================================
bool GetLegacyMetaData ( SXMPMeta * xmpObjPtr,
XML_NodePtr rootElem,
XMP_StringPtr legacyNS,
bool digestFound,
std::string& umid )
{
bool containsXMP = false;
XML_NodePtr legacyContext = 0, legacyProp = 0;
// UMID
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_DC, "identifier" )) ) {
legacyProp = rootElem->GetNamedElement ( legacyNS, "TargetMaterial" );
if ( (legacyProp != 0) && legacyProp->IsEmptyLeafNode() ) {
XMP_StringPtr legacyValue = legacyProp->GetAttrValue ( "umidRef" );
if ( legacyValue != 0 ) {
umid = legacyValue;
xmpObjPtr->SetProperty ( kXMP_NS_DC, "identifier", legacyValue, kXMP_DeleteExisting );
containsXMP = true;
}
}
}
// Creation date
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_XMP, "CreateDate" )) ) {
legacyProp = rootElem->GetNamedElement ( legacyNS, "CreationDate" );
if ( (legacyProp != 0) && legacyProp->IsEmptyLeafNode() ) {
XMP_StringPtr legacyValue = legacyProp->GetAttrValue ( "value" );
if ( legacyValue != 0 ) {
xmpObjPtr->SetProperty ( kXMP_NS_XMP, "CreateDate", legacyValue, kXMP_DeleteExisting );
containsXMP = true;
}
}
}
// Modify Date
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_XMP, "ModifyDate" )) ) {
legacyProp = rootElem->GetNamedElement ( legacyNS, "LastUpdate" );
if ( (legacyProp != 0) && legacyProp->IsEmptyLeafNode() ) {
XMP_StringPtr legacyValue = legacyProp->GetAttrValue ( "value" );
if ( legacyValue != 0 ) {
xmpObjPtr->SetProperty ( kXMP_NS_XMP, "ModifyDate", legacyValue, kXMP_DeleteExisting );
containsXMP = true;
}
}
}
// Metadata Modify Date
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_XMP, "MetadataDate" )) ) {
legacyProp = rootElem->GetNamedElement ( legacyNS, "lastUpdate" );
if ( (legacyProp != 0) && legacyProp->IsEmptyLeafNode() ) {
XMP_StringPtr legacyValue = legacyProp->GetAttrValue ( "value" );
if ( legacyValue != 0 ) {
xmpObjPtr->SetProperty ( kXMP_NS_XMP, "MetadataDate", legacyValue, kXMP_DeleteExisting );
containsXMP = true;
}
}
}
// Description
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_DC, "description" )) ) {
legacyProp = rootElem->GetNamedElement ( legacyNS, "Description" );
if ( (legacyProp != 0) && legacyProp->IsLeafContentNode() ) {
XMP_StringPtr legacyValue = legacyProp->GetLeafContentValue();
if ( legacyValue != 0 ) {
xmpObjPtr->SetLocalizedText ( kXMP_NS_DC, "description", "", "x-default", legacyValue, kXMP_DeleteExisting );
containsXMP = true;
}
}
}
legacyContext = rootElem->GetNamedElement ( legacyNS, "VideoFormat" );
if ( legacyContext != 0 ) {
// frame size
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_DM, "videoFrameSize" )) ) {
legacyProp = legacyContext->GetNamedElement ( legacyNS, "VideoLayout" );
if ( (legacyProp != 0) && legacyProp->IsEmptyLeafNode() ) {
XMP_StringPtr widthValue = legacyProp->GetAttrValue ( "pixel" );
XMP_StringPtr heightValue = legacyProp->GetAttrValue ( "numOfVerticalLine" );
if ( (widthValue != 0) && (heightValue != 0) ) {
xmpObjPtr->DeleteProperty ( kXMP_NS_DM, "videoFrameSize" );
xmpObjPtr->SetStructField ( kXMP_NS_DM, "videoFrameSize", kXMP_NS_XMP_Dimensions, "w", widthValue );
xmpObjPtr->SetStructField ( kXMP_NS_DM, "videoFrameSize", kXMP_NS_XMP_Dimensions, "h", heightValue );
xmpObjPtr->SetStructField ( kXMP_NS_DM, "videoFrameSize", kXMP_NS_XMP_Dimensions, "unit", "pixels" );
containsXMP = true;
}
}
}
// Aspect ratio
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_DM, "videoPixelAspectRatio" )) ) {
legacyProp = legacyContext->GetNamedElement ( legacyNS, "VideoLayout" );
if ( (legacyProp != 0) && legacyProp->IsEmptyLeafNode() ) {
XMP_StringPtr aspectRatio = legacyProp->GetAttrValue ( "aspectRatio" );
if ( aspectRatio != 0 ) {
xmpObjPtr->SetProperty ( kXMP_NS_DM, "videoPixelAspectRatio", aspectRatio, kXMP_DeleteExisting );
containsXMP = true;
}
}
}
// Frame rate
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_DM, "videoFrameRate" )) ) {
legacyProp = legacyContext->GetNamedElement ( legacyNS, "VideoFrame" );
if ( (legacyProp != 0) && legacyProp->IsEmptyLeafNode() ) {
XMP_StringPtr prop = legacyProp->GetAttrValue ( "formatFps" );
if ( prop != 0 ) {
xmpObjPtr->SetProperty ( kXMP_NS_DM, "videoFrameRate", prop, kXMP_DeleteExisting );
containsXMP = true;
}
}
}
// Video codec
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_DM, "videoCompressor" )) ) {
legacyProp = legacyContext->GetNamedElement ( legacyNS, "VideoFrame" );
if ( (legacyProp != 0) && legacyProp->IsEmptyLeafNode() ) {
XMP_StringPtr prop = legacyProp->GetAttrValue ( "videoCodec" );
if ( prop != 0 ) {
xmpObjPtr->SetProperty ( kXMP_NS_DM, "videoCompressor", prop, kXMP_DeleteExisting );
containsXMP = true;
}
}
}
} // VideoFormat
legacyContext = rootElem->GetNamedElement ( legacyNS, "AudioFormat" );
if ( legacyContext != 0 ) {
// Audio codec
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_DM, "audioCompressor" )) ) {
legacyProp = legacyContext->GetNamedElement ( legacyNS, "AudioRecPort" );
if ( (legacyProp != 0) && legacyProp->IsEmptyLeafNode() ) {
XMP_StringPtr prop = legacyProp->GetAttrValue ( "audioCodec" );
if ( prop != 0 ) {
xmpObjPtr->SetProperty ( kXMP_NS_DM, "audioCompressor", prop, kXMP_DeleteExisting );
containsXMP = true;
}
}
}
} // AudioFormat
// Duration
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_DM, "duration" )) ) {
std::string durationFrames, timecodeFPS;
legacyProp = rootElem->GetNamedElement ( legacyNS, "Duration" );
if ( legacyProp != 0 ) {
XMP_StringPtr durationValue = legacyProp->GetAttrValue ( "value" );
if ( durationValue != 0 ) durationFrames = durationValue;
}
legacyProp = rootElem->GetNamedElement ( legacyNS, "LtcChangeTable" );
if ( legacyProp != 0 ) {
// [TODO] Verify that this is the correct framerate to use from the legacy metadata. gemiller
XMP_StringPtr fps = legacyProp->GetAttrValue ( "tcFps" );
if ( fps != 0 ) {
timecodeFPS = "1/";
timecodeFPS += fps;
}
}
if ( (!timecodeFPS.empty()) && (!durationFrames.empty())) {
xmpObjPtr->DeleteProperty ( kXMP_NS_DM, "duration" );
xmpObjPtr->SetStructField ( kXMP_NS_DM, "duration", kXMP_NS_DM, "value", durationFrames );
xmpObjPtr->SetStructField ( kXMP_NS_DM, "duration", kXMP_NS_DM, "scale", timecodeFPS );
containsXMP = true;
}
}
legacyContext = rootElem->GetNamedElement ( legacyNS, "Device" );
if ( legacyContext != 0 ) {
std::string model;
// manufacturer string
XMP_StringPtr manufacturer = legacyContext->GetAttrValue ( "manufacturer" );
if ( manufacturer != 0 ) {
model += manufacturer;
}
// model string
XMP_StringPtr modelName = legacyContext->GetAttrValue ( "modelName" );
if ( modelName != 0 ) {
if ( model.size() > 0 ) {
model += " ";
}
model += modelName;
}
// For the dm::cameraModel property, concat the make and model.
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_DM, "cameraModel" )) ) {
if ( model.size() != 0 ) {
xmpObjPtr->SetProperty ( kXMP_NS_DM, "cameraModel", model, kXMP_DeleteExisting );
containsXMP = true;
}
}
// EXIF Model
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_TIFF, "Model" )) ) {
xmpObjPtr->SetProperty ( kXMP_NS_TIFF, "Model", modelName, kXMP_DeleteExisting );
}
// EXIF Make
if ( digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_TIFF, "Make" )) ) {
xmpObjPtr->SetProperty ( kXMP_NS_TIFF, "Make", manufacturer, kXMP_DeleteExisting );
}
// EXIF-AUX Serial number
XMP_StringPtr serialNumber = legacyContext->GetAttrValue ( "serialNo" );
if ( serialNumber != 0 && (digestFound || (! xmpObjPtr->DoesPropertyExist ( kXMP_NS_EXIF_Aux, "SerialNumber" ))) ) {
xmpObjPtr->SetProperty ( kXMP_NS_EXIF_Aux, "SerialNumber", serialNumber, kXMP_DeleteExisting );
}
}
return containsXMP;
}
// =================================================================================================
// XDCAM_Support::SetLegacyMetaData
// ================================
bool SetLegacyMetaData ( XML_Node * clipMetadata,
SXMPMeta * xmpObj,
XMP_StringPtr legacyNS )
{
bool updateLegacyXML = false;
bool xmpFound = false;
std::string xmpValue;
XML_Node * xmlNode = 0;
xmpFound = xmpObj->GetProperty ( kXMP_NS_DC, "title", &xmpValue, 0 );
if ( xmpFound ) {
xmlNode = CreateChildElement ( clipMetadata, "Title", legacyNS, 3 );
if ( xmpValue != xmlNode->GetLeafContentValue() ) {
xmlNode->SetLeafContentValue ( xmpValue.c_str() );
updateLegacyXML = true;
}
}
xmpFound = xmpObj->GetArrayItem ( kXMP_NS_DC, "creator", 1, &xmpValue, 0 );
if ( xmpFound ) {
xmlNode = CreateChildElement ( clipMetadata, "Creator", legacyNS, 3 );
XMP_StringPtr creatorName = xmlNode->GetAttrValue ( "name" );
if ( creatorName == 0 ) creatorName = "";
if ( xmpValue != creatorName ) {
xmlNode->SetAttrValue ( "name", xmpValue.c_str() );
updateLegacyXML = true;
}
}
xmpFound = xmpObj->GetProperty ( kXMP_NS_DC, "description", &xmpValue, 0 );
if ( xmpFound ) {
xmlNode = CreateChildElement ( clipMetadata, "Description", legacyNS, 3 );
if ( xmpValue != xmlNode->GetLeafContentValue() ) {
// description in non real time metadata is limited to 2047 bytes
if ( xmpValue.size() > 2047 ) xmpValue.resize ( 2047 );
xmlNode->SetLeafContentValue ( xmpValue.c_str() );
updateLegacyXML = true;
}
}
return updateLegacyXML;
}
// =================================================================================================
} // namespace XDCAM_Support
|