1 // =================================================================================================
2 // ADOBE SYSTEMS INCORPORATED
3 // Copyright 2015 Adobe Systems Incorporated
4 // All Rights Reserved
5 //
6 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
7 // of the Adobe license agreement accompanying it.
8 // =================================================================================================
9
10 // =================================================================================================
11 //
12 // This handler will handle FAM/FTP variant of XDCAM.
13 // More information could be found in XDCAM_Handler.cpp
14 //
15 // =================================================================================================
16
17 #include "public/include/XMP_Environment.h" // ! XMP_Environment.h must be the first included header.
18
19 #include "public/include/XMP_Const.h"
20 #include "public/include/XMP_IO.hpp"
21
22 #include "XMPFiles/source/XMPFiles_Impl.hpp"
23 #include "source/XMPFiles_IO.hpp"
24 #include "source/XIO.hpp"
25 #include "source/IOUtils.hpp"
26
27 #include "XMPFiles/source/FileHandlers/XDCAMFAM_Handler.hpp"
28 #include "XMPFiles/source/FormatSupport/XDCAM_Support.hpp"
29 #include "XMPFiles/source/FormatSupport/PackageFormat_Support.hpp"
30
XDCAMFAM_CheckFormat(XMP_FileFormat format,const std::string & rootPath,const std::string & groupName,const std::string & parentName,const std::string & leafName,XMPFiles *)31 bool XDCAMFAM_CheckFormat ( XMP_FileFormat format,
32 const std::string & rootPath,
33 const std::string & groupName,
34 const std::string & parentName,
35 const std::string & leafName,
36 XMPFiles * /*parent*/ )
37 {
38 /* isXDStyle = true Means SxS Memory or XDStyle
39 , = false Means Professional Disk */
40 bool isXDStyle = false;
41 if ( (format != kXMP_XDCAM_FAMFile) && (format != kXMP_UnknownFile) ) return false;
42 if ( groupName.empty() != parentName.empty() ) return false;
43
44 if ( groupName.empty() && ( Host_IO::GetChildMode ( rootPath.c_str(), "PROAV" ) == Host_IO::kFMode_IsFolder ) ) return false;
45
46 std::string tempPath = rootPath;
47
48 if ( !parentName.empty() )
49 {
50 // Real Absolute Path exists
51 if ( ! ( parentName == "CLIP" || parentName == "SUB" || parentName == "LOCAL" ) )
52 return false;
53 tempPath += kDirChar + groupName;
54 }
55
56 // Some basic Checks
57 if ( Host_IO::GetChildMode ( tempPath.c_str(), "DISCMETA.XML" ) != Host_IO::kFMode_IsFile ) return false;
58 if ( Host_IO::GetChildMode( tempPath.c_str(), "MEDIAPRO.XML" ) != Host_IO::kFMode_IsFile ) return false;
59 if ( ( Host_IO::GetChildMode( tempPath.c_str(), "Take" ) == Host_IO::kFMode_IsFolder ) || ( Host_IO::GetChildMode( tempPath.c_str(), "Local" ) == Host_IO::kFMode_IsFolder ) )
60 isXDStyle = true;
61
62 // XDStyle can't have INDEX.XML
63 if ( isXDStyle && ( Host_IO::GetChildMode( tempPath.c_str(), "INDEX.XML" ) == Host_IO::kFMode_IsFile ) )
64 return false;
65 // XDStyle can't have ALIAS.XML
66 if( isXDStyle && ( Host_IO::GetChildMode( tempPath.c_str(), "ALIAS.XML" ) == Host_IO::kFMode_IsFile ) )
67 return false;
68 // Non-XDStyle can't have CUEUP.XML file
69 if( ( !isXDStyle ) && ( Host_IO::GetChildMode( tempPath.c_str(), "CUEUP.XML" ) == Host_IO::kFMode_IsFile ) )
70 return false;
71
72 // We will get metadata from NRT file inside Clip folder only
73 tempPath += kDirChar;
74 tempPath += "Clip";
75 tempPath += kDirChar;
76
77 std::string clipName = leafName;
78 size_t length = clipName.length();
79
80 // Proxy file support
81 if ( ( parentName == "SUB" ) )
82 {
83 if( clipName.at( length - 3 ) != 'S' || ( ! IsDigit( clipName.at( length - 2 ) ) ) || ( ! IsDigit( clipName.at( length - 1 ) ) ) )
84 return false;
85 clipName.erase( clipName.begin() + length - 3, clipName.end() );
86 }
87
88 tempPath += clipName;
89
90 // .MXF file Existence with case sensitive is the new check inserted
91 std::string mxfPath = tempPath + ".MXF";
92 if ( Host_IO::GetFileMode ( mxfPath.c_str() ) != Host_IO::kFMode_IsFile )
93 {
94 mxfPath = tempPath + ".mxf";
95 if ( Host_IO::GetFileMode ( mxfPath.c_str() ) != Host_IO::kFMode_IsFile )
96 return false;
97 }
98
99 tempPath += "M01.XML";
100 if ( Host_IO::GetFileMode ( tempPath.c_str() ) != Host_IO::kFMode_IsFile )
101 return false;
102 return true;
103
104 } // XDCAMFAM_CheckFormat
105
XDCAMFAM_MetaHandlerCTor(XMPFiles * parent)106 XMPFileHandler * XDCAMFAM_MetaHandlerCTor ( XMPFiles * parent )
107 {
108 return new XDCAMFAM_MetaHandler ( parent );
109
110 } // XDCAM_MetaHandlerCTor
111
112 // =================================================================================================
113 // XDCAMFAM_MetaHandler::XDCAMFAM_MetaHandler
114 // ====================================
XDCAMFAM_MetaHandler(XMPFiles * _parent)115 XDCAMFAM_MetaHandler::XDCAMFAM_MetaHandler ( XMPFiles * _parent ) : XDCAM_MetaHandler(_parent), isXDStyle( false )
116 {
117 this->handlerFlags = kXDCAMFAM_HandlerFlags;
118 // Setting the various path variables
119 this->SetPathVariables ( this->parent->GetFilePath() );
120 } // XDCAMFAM_MetaHandler::XDCAMFAM_MetaHandler
121
122
123 // =================================================================================================
124 // XDCAMFAM_MetaHandler::SetPathVariables
125 // ====================================
SetPathVariables(const std::string & clientPath)126 void XDCAMFAM_MetaHandler::SetPathVariables ( const std::string & clientPath )
127 {
128 // No need to check for existing or non existing as would have been done at check file format if ForceGivenHandler flag is not provided
129 std::string tempPath = clientPath;
130 std::string parentName, GroupName;
131 std::string ignored;
132
133 XIO::SplitLeafName ( &tempPath, &this->clipName );
134
135 this->rootPath = tempPath;
136
137 if ( ! Host_IO::Exists( clientPath.c_str() ) )
138 {
139 // Logical Path exists
140 // No need to extract extension as clipname is given without extension
141 if ( ( Host_IO::GetChildMode( tempPath.c_str(), "INDEX.XML" ) != Host_IO::kFMode_IsFile ) )
142 this->isXDStyle = true;
143 tempPath += kDirChar;
144 tempPath += "Clip";
145 XMP_Assert( Host_IO::GetFileMode( tempPath.c_str() ) == Host_IO::kFMode_IsFolder );
146 }
147 else
148 {
149 // Real Absolute Path exists
150 XIO::SplitFileExtension ( &this->clipName, &ignored );
151 XIO::SplitLeafName ( &tempPath, &parentName );
152 if ( ( Host_IO::GetChildMode( tempPath.c_str(), "INDEX.XML" ) != Host_IO::kFMode_IsFile ) )
153 this->isXDStyle = true;
154 this->rootPath = tempPath;
155
156 size_t length = this->clipName.length();
157
158 // Proxy file support
159 if ( parentName == "Sub" )
160 {
161 XMP_Assert( IsDigit( clipName.at( length - 2 ) ) && IsDigit( clipName.at( length - 1 ) ) );
162 XMP_Assert( this->clipName.at( length - 3 ) == 'S' );
163 this->clipName.erase( this->clipName.begin() + length - 3, clipName.end() );
164 tempPath += kDirChar ;
165 tempPath += "Clip";
166 }
167 else
168 tempPath += kDirChar + parentName;
169 }
170
171 // Checks for Clip folder in XDCAM
172 XMP_Assert ( Host_IO::GetChildMode ( rootPath.c_str(), "Clip" ) == Host_IO::kFMode_IsFolder );
173
174 tempPath += kDirChar;
175 tempPath += this->clipName;
176 std::string mxfPath;
177
178 // Case sensitive Extension support to check for clipname.MXF or clipname.mxf as already cover in Checkformat
179 if ( !( MakeClipFilePath( &mxfPath, ".MXF", true ) || MakeClipFilePath( &mxfPath, ".mxf", true ) ) )
180 {
181 XMP_Error error( kXMPErr_FilePathNotAFile, "Clip MXF file must be exist" );
182 NotifyClient( &this->parent->errorCallback, kXMPErrSev_FileFatal, error );
183 }
184
185 // NRT file Check as already cover in checkformat
186 if ( ! MakeClipFilePath ( &this->mNRTFilePath, "M01.XML", true ) )
187 {
188 XMP_Error error( kXMPErr_FilePathNotAFile, "Clip NRT XML file must be exist" );
189 NotifyClient( &this->parent->errorCallback, kXMPErrSev_FileFatal, error );
190 }
191
192 // Setting correct sidecar path
193 if ( this->isXDStyle || (Host_IO::GetChildMode ( rootPath.c_str(), "UserData" ) == Host_IO::kFMode_IsFolder ) )
194 {
195 if ( ! ( MakeClipFilePath( &this->sidecarPath, ".xmp", true ) || MakeClipFilePath( &this->sidecarPath, ".XMP", true ) ) )
196 this->sidecarPath = mxfPath + ".xmp";
197 }
198 else
199 {
200 if ( ! ( MakeClipFilePath( &this->sidecarPath, "M01.XMP", true ) || MakeClipFilePath( &this->sidecarPath, "M01.xmp", true ) ) )
201 this->sidecarPath = tempPath + "M01.XMP";
202 }
203
204 } // XDCAMFAM_MetaHandler::SetPathVariables
205
206 // =================================================================================================
207 // XDCAMFAM_MetaHandler::FillAssociatedResources
208 // ====================================
FillAssociatedResources(std::vector<std::string> * resourceList)209 void XDCAMFAM_MetaHandler::FillAssociatedResources( std::vector<std::string> * resourceList )
210 {
211 //Add RootPath
212 std::string filePath = rootPath + kDirChar;
213 PackageFormat_Support::AddResourceIfExists( resourceList, filePath );
214
215 // Get the files present directly inside root folder.
216 filePath = rootPath + kDirChar + "ALIAS.XML";
217 PackageFormat_Support::AddResourceIfExists(resourceList, filePath);
218
219 // INDEX.XML doesn't exist for XDStyle
220 if( ! this->isXDStyle )
221 {
222 filePath = rootPath + kDirChar + "INDEX.XML";
223 PackageFormat_Support::AddResourceIfExists(resourceList, filePath);
224 }
225
226 filePath = rootPath + kDirChar + "DISCMETA.XML";
227 PackageFormat_Support::AddResourceIfExists(resourceList, filePath);
228
229 filePath = rootPath + kDirChar + "MEDIAPRO.XML";
230 PackageFormat_Support::AddResourceIfExists(resourceList, filePath);
231 filePath = rootPath + kDirChar + "MEDIAPRO.BUP";
232 PackageFormat_Support::AddResourceIfExists(resourceList, filePath);
233
234 // CUEUP.XML don't exist for Professional Disk XDCAM
235 if( this->isXDStyle )
236 {
237 filePath = rootPath + kDirChar + "CUEUP.XML";
238 PackageFormat_Support::AddResourceIfExists(resourceList, filePath);
239 filePath = rootPath + kDirChar + "CUEUP.BUP";
240 PackageFormat_Support::AddResourceIfExists(resourceList, filePath);
241 }
242
243 // Add the UserData folder
244 filePath = rootPath + kDirChar + "UserData" + kDirChar;
245 PackageFormat_Support::AddResourceIfExists(resourceList, filePath);
246
247
248 // Get the files present inside clip folder.
249 XMP_VarString clipPath = rootPath + kDirChar + "Clip" + kDirChar ;
250 size_t oldCount = resourceList->size();
251
252 XMP_VarString regExp1;
253 XMP_StringVector regExpVec;
254
255 regExp1 = "^" + clipName + ".MXF$";
256 regExpVec.push_back ( regExp1 );
257 regExp1 = "^" + clipName + "M\\d\\d.XML$";
258 regExpVec.push_back ( regExp1 );
259 if ( this->isXDStyle )
260 {
261 regExp1 = "^" + clipName + "R\\d\\d.BIM$";
262 regExpVec.push_back ( regExp1 );
263 }
264 else
265 {
266 regExp1 = "^" + clipName + "M\\d\\d.KLV$";
267 regExpVec.push_back ( regExp1 );
268 }
269 IOUtils::GetMatchingChildren ( *resourceList, clipPath, regExpVec, false, true, true );
270 PackageFormat_Support::AddResourceIfExists( resourceList, this->sidecarPath);
271 if ( resourceList->size() <= oldCount )
272 {
273 PackageFormat_Support::AddResourceIfExists(resourceList, clipPath);
274 }
275
276 //Get the files Under Sub folder
277 clipPath = rootPath + kDirChar + "Sub" + kDirChar ;
278 regExpVec.clear();
279 regExp1 = "^" + clipName + "S\\d\\d.MXF$";
280 regExpVec.push_back ( regExp1 );
281 oldCount = resourceList->size();
282 IOUtils::GetMatchingChildren ( *resourceList, clipPath, regExpVec, false, true, true );
283 // Add Sub folder if no file inside this, was added.
284 if ( resourceList->size() <= oldCount )
285 {
286 PackageFormat_Support::AddResourceIfExists(resourceList, clipPath);
287 }
288
289 // Get the files Under Local folder if it is XDStyle
290 if ( isXDStyle )
291 {
292 clipPath = rootPath + kDirChar + "Local" + kDirChar ;
293 regExpVec.clear();
294 // ClipInfo file
295 regExp1 = "^" + clipName + "C\\d\\d.SMI$";
296 regExpVec.push_back ( regExp1 );
297 // Picture pointer file
298 regExp1 = "^" + clipName + "I\\d\\d.PPN$";
299 regExpVec.push_back ( regExp1 );
300 oldCount = resourceList->size();
301 IOUtils::GetMatchingChildren ( *resourceList, clipPath, regExpVec, false, true, true );
302 // Add Local folder if no file inside this, was added.
303 if ( resourceList->size() <= oldCount )
304 {
305 PackageFormat_Support::AddResourceIfExists(resourceList, clipPath);
306 }
307 }
308
309 // Add the Edit lists associated to this clip
310 XMP_StringVector editInfoList;
311 bool atLeastOneFileAdded = false;
312 clipPath = rootPath + kDirChar + "Edit" + kDirChar ;
313 if ( GetInfoFiles ( editInfoList , clipPath ) )
314 {
315 size_t noOfEditInfoFiles = editInfoList.size() ;
316 for( size_t count = 0; count < noOfEditInfoFiles; count++ )
317 {
318 atLeastOneFileAdded = PackageFormat_Support::AddResourceIfExists(resourceList, editInfoList[count]) ? true : atLeastOneFileAdded;
319
320 XMP_VarString editNRTFile = editInfoList[count] ;
321 size_t filenamelen = editNRTFile.length() ;
322 if ( editNRTFile[ filenamelen - 7 ] == 'E'
323 && IsDigit( editNRTFile[ filenamelen - 6 ] )
324 && IsDigit( editNRTFile[ filenamelen - 5 ] ) )
325 {
326 editNRTFile.erase( editNRTFile.begin() + filenamelen - 7, editNRTFile.end() ) ;
327 }
328 else
329 {
330 editNRTFile.erase( editNRTFile.begin() + filenamelen - 4, editNRTFile.end() ) ;
331 }
332
333 XMP_VarString fileName;
334 size_t pos = editNRTFile.find_last_of ( kDirChar );
335 fileName = editNRTFile.substr ( pos + 1 );
336 XMP_VarString regExp = "^" + fileName + "M\\d\\d.XML$";
337 oldCount = resourceList->size();
338 IOUtils::GetMatchingChildren ( *resourceList, clipPath, regExp, false, true, true );
339 atLeastOneFileAdded = resourceList->size() > oldCount;
340
341 }
342 }
343 // Add Edit folder if no file inside this, was added.
344 if ( !atLeastOneFileAdded )
345 {
346 PackageFormat_Support::AddResourceIfExists(resourceList, clipPath);
347 }
348
349 atLeastOneFileAdded = false;
350
351 // Add the Takes associated to this clip,
352 // Take folder exists only for XDStyle
353 if( this->isXDStyle )
354 {
355 XMP_StringVector takeList;
356 clipPath = rootPath + kDirChar + "Take" + kDirChar ;
357 if( GetInfoFiles ( takeList , clipPath ) )
358 {
359 size_t noOfTakes = takeList.size() ;
360 for( size_t count = 0; count < noOfTakes; count++ )
361 {
362 atLeastOneFileAdded = PackageFormat_Support::AddResourceIfExists(resourceList, takeList[count]) ? true : atLeastOneFileAdded;
363 XMP_VarString takeNRTFile = takeList[count] ;
364 size_t filenamelen = takeList[count].length() ;
365 if ( takeNRTFile[ filenamelen - 7 ] == 'U'
366 && IsDigit( takeNRTFile[ filenamelen - 6 ] )
367 && IsDigit( takeNRTFile[ filenamelen - 5 ] ) )
368 {
369 takeNRTFile.erase( takeNRTFile.begin() + filenamelen - 7, takeNRTFile.end() ) ;
370 }
371 else
372 {
373 takeNRTFile.erase( takeNRTFile.begin() + filenamelen - 4, takeNRTFile.end() ) ;
374 }
375
376 XMP_VarString fileName;
377 size_t pos = takeNRTFile.find_last_of ( kDirChar );
378 fileName = takeNRTFile.substr ( pos + 1 );
379 XMP_VarString regExp = "^" + fileName + "M\\d\\d.XML$";
380 oldCount = resourceList->size();
381 IOUtils::GetMatchingChildren ( *resourceList, clipPath, regExp, false, true, true );
382 atLeastOneFileAdded = resourceList->size() > oldCount;
383 }
384 }
385 // Add Take folder if no file inside this, was added.
386 if(!atLeastOneFileAdded)
387 {
388 filePath = rootPath + kDirChar + "Take" + kDirChar;
389 PackageFormat_Support::AddResourceIfExists(resourceList, filePath);
390 }
391 }
392
393 // Add the Planning Metadata Files associated to this clip
394 // Planning Metadata exist for both SxS and Professional Disk
395 XMP_StringVector planList;
396 clipPath = rootPath + kDirChar + "General" + kDirChar + "Sony" + kDirChar+ "Planning" + kDirChar;
397 if( GetPlanningFiles ( planList , clipPath ) )
398 {
399 size_t noOfPlans = planList.size() ;
400 for( size_t count = 0; count < noOfPlans; count++ )
401 {
402 resourceList->push_back( planList[count] );
403 }
404 }
405 } // XDCAMFAM_MetaHandler::FillAssociatedResources
406
407 // =================================================================================================
408 // XDCAMFAM_MetaHandler::MakeClipFilePath
409 // ====================================
MakeClipFilePath(std::string * path,XMP_StringPtr suffix,bool checkFile)410 bool XDCAMFAM_MetaHandler::MakeClipFilePath ( std::string * path, XMP_StringPtr suffix, bool checkFile /* = false */ )
411 {
412
413 *path = this->rootPath;
414 *path += kDirChar;
415
416 *path += "Clip"; // ! Yes, mixed case.
417
418 *path += kDirChar;
419 *path += this->clipName;
420 *path += suffix;
421
422 if ( ! checkFile ) return true;
423 return Host_IO::Exists ( path->c_str() );
424
425 } // XDCAMFAM_MetaHandler::MakeClipFilePath
426
427 // =================================================================================================
428 // XDCAMFAM_MetaHandler::MakeLocalFilePath
429 // ====================================
MakeLocalFilePath(std::string * path,XMP_Uns8 fileType,bool checkFile)430 bool XDCAMFAM_MetaHandler::MakeLocalFilePath ( std::string * path, XMP_Uns8 fileType, bool checkFile /* = false */ )
431 {
432
433 *path = this->rootPath;
434 *path += kDirChar;
435
436 *path += "Local"; // ! Yes, mixed case.
437
438 *path += kDirChar;
439 *path += this->clipName;
440
441 if( fileType == k_LocalPPNFile )
442 *path += "I01.PPN";
443 else if ( fileType == k_LocalClipInfoFile )
444 *path += "S01.SMI";
445 else
446 return false;
447
448 if ( ! checkFile ) return true;
449 return Host_IO::Exists ( path->c_str() );
450
451 } // XDCAMFAM_MetaHandler::MakeLocalFilePath
452
453
454 // =================================================================================================
455 // XDCAMFAM_MetaHandler::GetMediaProMetadata
456 // ====================================
GetMediaProMetadata(SXMPMeta * xmpObjPtr,const std::string & clipUMID,bool digestFound)457 bool XDCAMFAM_MetaHandler::GetMediaProMetadata ( SXMPMeta * xmpObjPtr,
458 const std::string& clipUMID,
459 bool digestFound )
460 {
461 // Build a directory string to the MEDIAPRO file.
462 std::string mediaproPath;
463 MakeMediaproPath ( &mediaproPath );
464 return XDCAM_Support::GetMediaProLegacyMetadata ( xmpObjPtr, clipUMID, mediaproPath, digestFound );
465 } // XDCAMFAM_MetaHandler::GetMediaProMetadata
466
467 // =================================================================================================
468 // XDCAMFAM_MetaHandler::GetPlanningFiles
469 // ====================================
GetPlanningFiles(std::vector<std::string> & planInfoList,std::string pathToFolder)470 bool XDCAMFAM_MetaHandler::GetPlanningFiles ( std::vector<std::string> &planInfoList, std::string pathToFolder)
471 {
472 std::string clipUmid;
473 bool found = false;
474
475 if( GetClipUmid ( clipUmid ) )
476 {
477 if ( Host_IO::Exists( pathToFolder.c_str() ) &&
478 Host_IO::GetFileMode( pathToFolder.c_str() ) == Host_IO::kFMode_IsFolder
479 )
480 {
481 Host_IO::AutoFolder planFolder;
482 std::string listChild;
483
484 planFolder.folder = Host_IO::OpenFolder ( pathToFolder.c_str() );
485 while ( Host_IO::GetNextChild ( planFolder.folder, &listChild ) ) {
486 size_t filenamelen = listChild.size();
487 std::string listFilePath = pathToFolder + listChild ;
488 if ( ! ( filenamelen > 4 &&
489 ( listChild.compare ( filenamelen - 4, 4 , ".XML" ) == 0
490 ||
491 listChild.compare ( filenamelen - 4, 4 , ".xml" ) == 0
492 )
493 &&
494 Host_IO::GetFileMode( listFilePath.c_str() ) == Host_IO::kFMode_IsFile
495 ) ) continue;
496 if( IsClipsPlanning ( clipUmid , listFilePath.c_str() ) )
497 {
498 found = true ;
499 planInfoList.push_back( listFilePath );
500 }
501 }
502 }
503 }
504 return found;
505 } // XDCAMFAM_MetaHandler::GetPlanningFiles
506
507 // =================================================================================================
508 // XDCAMFAM_MetaHandler::IsClipsPlanning
509 // ====================================
IsClipsPlanning(std::string clipUmid,XMP_StringPtr planPath)510 bool XDCAMFAM_MetaHandler::IsClipsPlanning ( std::string clipUmid , XMP_StringPtr planPath )
511 {
512 ExpatAdapter* planniingExpat = 0 ;
513 XMP_StringPtr nameSpace = 0 ;
514 try {
515 readXMLFile( planPath, planniingExpat );
516 if ( planniingExpat != 0 )
517 {
518 XML_Node & xmlTree = planniingExpat->tree;
519 XML_NodePtr rootElem = 0;
520
521 for ( size_t i = 0, limit = xmlTree.content.size(); i < limit; ++i ) {
522 if ( xmlTree.content[i]->kind == kElemNode ) {
523 rootElem = xmlTree.content[i];
524 }
525 }
526 if ( rootElem != 0 )
527 {
528 XMP_StringPtr rootLocalName = rootElem->name.c_str() + rootElem->nsPrefixLen;
529
530 if ( XMP_LitMatch ( rootLocalName, "PlanningMetadata" ) )
531 {
532 nameSpace = rootElem->ns.c_str() ;
533 size_t noOfMaterialGroups = rootElem->CountNamedElements ( nameSpace, "MaterialGroup" ) ;
534 while( noOfMaterialGroups-- )
535 {
536 XML_NodePtr mgNode = rootElem->GetNamedElement( nameSpace, "MaterialGroup" );
537 size_t noOfMaterialElements = mgNode->CountNamedElements ( nameSpace, "Material" ) ;
538 while( noOfMaterialElements-- )
539 {
540 XML_NodePtr materialNode = mgNode->GetNamedElement( nameSpace, "Material" );
541 XMP_StringPtr materialType = materialNode->GetAttrValue ( "type" );
542 if ( materialType && XMP_LitMatch( materialType , "clip" ) )
543 {
544 XMP_StringPtr umidValue = materialNode->GetAttrValue ( "umidRef" );
545 if ( umidValue != 0 && XMP_LitMatch( umidValue , clipUmid.c_str() ) )
546 {
547 delete ( planniingExpat ) ;
548 return true;
549 }
550 }
551
552 }
553 }
554 }
555 }
556 }
557
558 } catch ( ... ) {
559 }
560 delete ( planniingExpat ) ;
561 return false;
562 } // XDCAMFAM_MetaHandler::IsClipsPlanning
563
564 // =================================================================================================
565 // XDCAMFAM_MetaHandler::GetInfoFiles
566 // ====================================
GetInfoFiles(std::vector<std::string> & infoList,std::string pathToFolder)567 bool XDCAMFAM_MetaHandler::GetInfoFiles ( std::vector<std::string> &infoList, std::string pathToFolder)
568 {
569 std::string clipUmid;
570 bool found = false;
571
572 if( GetClipUmid ( clipUmid ) )
573 {
574 if ( Host_IO::Exists( pathToFolder.c_str() ) &&
575 Host_IO::GetFileMode( pathToFolder.c_str() ) == Host_IO::kFMode_IsFolder
576 )
577 {
578 Host_IO::AutoFolder infoFolder;
579 std::string listChild;
580
581 infoFolder.folder = Host_IO::OpenFolder ( pathToFolder.c_str() );
582 while ( Host_IO::GetNextChild ( infoFolder.folder, &listChild ) ) {
583 size_t filenamelen = listChild.size();
584 std::string listFilePath = pathToFolder + listChild ;
585 if ( ! ( filenamelen > 7 &&
586 listChild.compare ( filenamelen - 4, 4 , ".SMI" ) == 0 &&
587 Host_IO::GetFileMode( listFilePath.c_str() ) == Host_IO::kFMode_IsFile
588 ) ) continue;
589 if( RefersClipUmid ( clipUmid , listFilePath.c_str() ) )
590 {
591 found = true ;
592 infoList.push_back( listFilePath );
593 }
594 }
595 }
596 }
597 return found;
598 } // XDCAMFAM_MetaHandler::GetInfoFiles
599
600 // =================================================================================================
601 // XDCAMFAM_MetaHandler::GetClipUmid
602 // ==============================
GetClipUmid(std::string & clipUmid)603 bool XDCAMFAM_MetaHandler::GetClipUmid ( std::string &clipUmid )
604 {
605 std::string clipInfoPath;
606 ExpatAdapter* clipInfoExpat = 0 ;
607 bool umidFound = false;
608 XMP_StringPtr nameSpace = 0;
609 try {
610 if ( this->MakeLocalFilePath ( &clipInfoPath, k_LocalClipInfoFile, true ) )
611 {
612 readXMLFile( clipInfoPath.c_str(), clipInfoExpat );
613 if ( clipInfoExpat != 0 )
614 {
615 XML_Node & xmlTree = clipInfoExpat->tree;
616 XML_NodePtr rootElem = 0;
617
618 for ( size_t i = 0, limit = xmlTree.content.size(); i < limit; ++i ) {
619 if ( xmlTree.content[i]->kind == kElemNode ) {
620 rootElem = xmlTree.content[i];
621 }
622 }
623 if ( rootElem != 0 )
624 {
625 XMP_StringPtr rootLocalName = rootElem->name.c_str() + rootElem->nsPrefixLen;
626
627 if ( XMP_LitMatch ( rootLocalName, "smil" ) )
628 {
629 XMP_StringPtr umidValue = rootElem->GetAttrValue ( "umid" );
630 if ( umidValue != 0 ) {
631 clipUmid = umidValue;
632 umidFound = true;
633 }
634 }
635 }
636 }
637 }
638 if( ! umidFound )
639 { //try to get the umid from the NRT metadata
640 delete ( clipInfoExpat ) ; clipInfoExpat = 0;
641 this->MakeClipFilePath ( &clipInfoPath, "M01.XML" ) ;
642 readXMLFile( clipInfoPath.c_str(), clipInfoExpat ) ;
643 if ( clipInfoExpat != 0 )
644 {
645 XML_Node & xmlTree = clipInfoExpat->tree;
646 XML_NodePtr rootElem = 0;
647 for ( size_t i = 0, limit = xmlTree.content.size(); i < limit; ++i ) {
648 if ( xmlTree.content[i]->kind == kElemNode ) {
649 rootElem = xmlTree.content[i];
650 }
651 }
652 if ( rootElem != 0 )
653 {
654 XMP_StringPtr rootLocalName = rootElem->name.c_str() + rootElem->nsPrefixLen;
655
656 if ( XMP_LitMatch ( rootLocalName, "NonRealTimeMeta" ) )
657 {
658 nameSpace = rootElem->ns.c_str() ;
659 XML_NodePtr targetProp = rootElem->GetNamedElement ( nameSpace, "TargetMaterial" );
660 if ( (targetProp != 0) && targetProp->IsEmptyLeafNode() ) {
661 XMP_StringPtr umidValue = targetProp->GetAttrValue ( "umidRef" );
662 if ( umidValue != 0 ) {
663 clipUmid = umidValue;
664 umidFound = true;
665 }
666 }
667 }
668 }
669 }
670 }
671 } catch ( ... ) {
672 }
673 delete ( clipInfoExpat ) ;
674 return umidFound;
675 } // XDCAMFAM_MetaHandler::GetClipUmid
676
677 // =================================================================================================
678