{ DYDiagnosticManager *base=[[[DYDiagnosticManager alloc]init]autorelease];DYCreateParameters(base,&error);DYToolTrackingProbe *host=[[[DYToolTrackingProbe alloc]init]autorelease];host->_base=base;host->_time=kCMTimeZero;host->_state=kFxAnalysisState_NotAnalyzing; NSMutableDictionary *doc=DYMutablePlist([[[DYToolDocument alloc]init]autorelease].document),*mask=DYMutablePlist(DYNewMask(DYMaskRectangle));DYMaskParameters p=DYMaskAtTime(mask,kCMTimeZero);p.width=.65;p.height=.65;p.feather=0;mask[@"parameters"]=[NSData dataWithBytes:&p length:sizeof(p)];doc[@"baseMasks"][@"hsl"]=[NSMutableArray arrayWithObject:mask];DYWriteTools(base,doc,kCMTimeZero); idplugin=(id)[[NSClassFromString(@"DYPlugIn")alloc]initWithAPIManager:host];[(NSObject*)plugin setValue:@YES forKey:@"_toolCaptureEnabled"]; const NSUInteger tw=320,th=192;DYDiagnosticTile *frame=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:tw height:th]autorelease],*out=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:tw height:th]autorelease]; auto setFrame=[&](int step){Pixels pixels(tw*th*4);for(NSUInteger y=0;y>13;n*=1274126177u;float code=.15f+.7f*((n>>8)&255)/255.f,linear=code<=.04045f?code/12.92f:powf((code+.055f)/1.055f,2.4f);auto index=(y*tw+x)*4;pixels[index]=pixels[index+1]=pixels[index+2]=linear;pixels[index+3]=1;}[[frame metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,tw,th) mipmapLevel:0 withBytes:pixels.data() bytesPerRow:tw*8];}; auto timeAt=[](int frame){return CMTimeMake(frame*1001,24000);};auto capture=[&](int step){setFrame(step);host->_time=timeAt(step);NSData *state=nil;[plugin pluginState:&state atTime:host->_time quality:(FxQuality)0 error:&error];return [plugin renderDestinationImage:out sourceImages:@[frame] pluginState:state atTime:host->_time error:&error];}; auto request=[&](int direction){if(direction!=9)host->_state=kFxAnalysisState_NotAnalyzing;[plugin toolTrackRequested:[NSNotification notificationWithName:@"DYToolTrack" object:host userInfo:@{@"node":@"base:hsl",@"mask":mask[@"id"],@"direction":@(direction)}]];}; auto drain=[&](){double end=NSProcessInfo.processInfo.systemUptime+.15;while(NSProcessInfo.processInfo.systemUptime_time=kCMTimeInvalid;request(1); run.record(@"tracking-invalid-host-time-does-not-start-analysis",host->_forwardStarts==0&&host->_state==kFxAnalysisState_NotAnalyzing); run.need(@"tracking-renders-valid-source-before-analysis",capture(0));run.record(@"inactive-tracking-avoids-full-frame-motion-readback",[[plugin valueForKey:@"toolCaptureDevices"]count]==0);int undoBefore=base->_undoStarts;request(1);BOOL callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:&error]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:&error]; for(int i=0;i<6&&callbacks;i++){setFrame(i);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:&error];}host->_state=kFxAnalysisState_AnalysisCompleted;[plugin cleanupAnalysis:nil];drain();NSDictionary *tracked=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];DYMaskParameters end=DYMaskAtTime(tracked,timeAt(5));run.record(@"host-callback-vision-tracking-six-exact-frames",callbacks&&[tracked[@"keys"]count]==6&&fabs(end.centerX-(.5+10./tw))<.004&&fabs(end.centerY-(.5+5./th))<.004,@{@"keyCount":@([tracked[@"keys"]count]),@"centerX":@(end.centerX),@"centerY":@(end.centerY),@"error":reason(error)}); NSDictionary *lastPreview=updates.count>=2?updates[updates.count-2]:nil; DYMaskParameters shown{}; [lastPreview[@"shape"] getBytes:&shown length:sizeof(shown)]; NSData *previewPixels=lastPreview[@"rgba"]; run.record(@"mask-analysis-emits-matching-frame-geometry-and-completed-progress", [lastPreview[@"completed"]intValue]==6&&[lastPreview[@"total"]intValue]==6&& fabs([lastPreview[@"time"]doubleValue]-CMTimeGetSeconds(timeAt(5)))<1e-9&& previewPixels.length==tw*th*4&&shown.centerX==end.centerX&&shown.centerY==end.centerY&& !lastPreview[@"sourceShape"]&&![updates.lastObject[@"tracking"]boolValue]&&host->_seekCount==0); run.record(@"tracking-results-use-one-undo-action",base->_undoStarts==undoBefore+1&&base->_undoStarts==base->_undoEnds);BOOL captureFreed=YES;for(NSDictionary *entry in [[plugin valueForKey:@"toolCaptureDevices"]allValues])captureFreed&=!entry[@"encoded"]&&!entry[@"bytes"]&&!entry[@"buffer"]&&!entry[@"previewBuffer"];run.record(@"completed-tracking-releases-4k-gpu-analysis-working-images",captureFreed);int writes=base->_undoStarts;[plugin cleanupAnalysis:nil];[plugin cleanupAnalysis:nil];drain();run.record(@"duplicate-analysis-cleanup-never-commits-twice",base->_undoStarts==writes); // Mid-analysis author edits must reject the result rather than clobber them. capture(0);request(1);callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil];for(int i=0;i<3&&callbacks;i++){setFrame(i);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}NSMutableDictionary *changed=DYMutablePlist(DYReadTools(base,kCMTimeZero).document);changed[@"baseMasks"][@"hsl"][0][@"enabled"]=@NO;DYWriteTools(base,changed,kCMTimeZero);[plugin cleanupAnalysis:nil];drain();run.record(@"stale-analysis-cannot-overwrite-edited-mask",[DYReadTools(base,kCMTimeZero).document isEqual:changed]&&base->_undoStarts==writes); DYWriteTools(base,doc,kCMTimeZero);capture(0);request(1);callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil];for(int i=0;i<3&&callbacks;i++){setFrame(i);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}request(9);setFrame(3);NSError *cancelError=nil;BOOL stopped=![plugin analyzeFrame:frame atTime:timeAt(3) error:&cancelError];drain();tracked=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];run.record(@"cancel-keeps-only-contiguous-trusted-segment",callbacks&&stopped&&[tracked[@"keys"]count]==3&&base->_undoStarts==writes+1);run.record(@"cancel-sends-sdk-quiet-analysis-termination",[cancelError.domain isEqual:FxPlugErrorDomain]&&cancelError.code==kFxError_UserCancelled); [updates removeAllObjects]; DYWriteTools(base,doc,kCMTimeZero);capture(2);host->_state=kFxAnalysisState_NotAnalyzing;request(0);callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil];for(int i=2;i<6&&callbacks;i++){setFrame(i);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}[plugin cleanupAnalysis:nil];drain();BOOL backward=host->_backwardStarts==1;callbacks&=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil];for(int i=2;i>=0&&callbacks;i--){setFrame(i);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}[plugin cleanupAnalysis:nil];drain();tracked=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];run.record(@"bidirectional-passes-share-reference-and-merge-once",callbacks&&backward&&[tracked[@"keys"]count]==6&&base->_undoStarts==writes+2); NSUInteger previous=0;BOOL progress=YES,sawForward=NO,sawBackward=NO; for(NSDictionary *update in updates){ if(!update[@"shape"])continue; NSUInteger current=[update[@"completed"]unsignedIntegerValue]; progress&=current>=previous&&[update[@"total"]intValue]==6; if([update[@"backward"]boolValue])sawBackward=YES;else sawForward=YES; previous=current; } run.record(@"bidirectional-progress-counts-reference-once-and-never-regresses",progress&&sawForward&&sawBackward&&previous==6); DYWriteTools(base,doc,kCMTimeZero);capture(2);host->_timelineOffset=CMTimeMake(4,1);host->_state=kFxAnalysisState_NotAnalyzing;request(-2);BOOL range=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&CMTimeCompare(desired.start,timeAt(1))==0&&CMTimeCompare(desired.duration,timeAt(2))==0;[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil];for(int i=2;i>=1;i--){setFrame(i);[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}setFrame(0);NSError *singleStopError=nil;stopped=![plugin analyzeFrame:frame atTime:timeAt(0) error:&singleStopError];drain();tracked=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];run.record(@"backward-single-step-includes-reference-and-one-neighbor",range&&stopped&&[tracked[@"keys"]count]==2);run.record(@"single-step-sends-sdk-quiet-analysis-termination",[singleStopError.domain isEqual:FxPlugErrorDomain]&&singleStopError.code==kFxError_UserCancelled); run.record(@"backward-single-step-seeks-timeline-with-clip-offset",host->_seekCount==1&&CMTimeCompare(host->_seekTime,CMTimeAdd(CMTimeMake(4,1),timeAt(1)))==0&&CMTimeCompare(host->_time,timeAt(1))==0); DYWriteTools(base,doc,kCMTimeZero);capture(2);BOOL repeated=YES;for(int first=2;first<4;first++){request(2);repeated&=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil];for(int i=first;i<=first+1&&repeated;i++){setFrame(i);repeated&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}[plugin cleanupAnalysis:nil];drain();repeated&=CMTimeCompare(host->_time,timeAt(first+1))==0;}run.record(@"repeated-forward-single-step-continues-source-frames-at-offset-clip",repeated&&host->_seekCount==3&&CMTimeCompare(host->_seekTime,CMTimeAdd(CMTimeMake(4,1),timeAt(4)))==0); int priorWrites=0;for(int repeat=0;repeat<2;repeat++){priorWrites=base->_undoStarts;capture(2);request(2);callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil];for(int i=2;i<=3&&callbacks;i++){setFrame(i);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}[plugin cleanupAnalysis:nil];drain();}run.record(@"unchanged-single-step-still-advances-without-duplicate-author-write",callbacks&&host->_seekCount==5&&CMTimeCompare(host->_time,timeAt(3))==0&&base->_undoStarts==priorWrites,@{@"seekCount":@(host->_seekCount),@"writesBefore":@(priorWrites),@"writesAfter":@(base->_undoStarts)}); // An expected loss must end the host job, not only our local tracking state. DYWriteTools(base,doc,kCMTimeZero);capture(0);request(1);callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil];for(int i=0;i<3&&callbacks;i++){setFrame(i);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];} Pixels flat(tw*th*4,.1f);for(size_t i=3;i_state=kFxAnalysisState_AnalysisCompleted;[plugin cleanupAnalysis:nil];drain();run.record(@"boundary-seed-only-range-completes-without-author-write-or-rejected-range",callbacks&&!boundaryError&&[DYReadTools(base,kCMTimeZero).document isEqual:doc]); NSError *lateError=nil;stopped=![plugin analyzeFrame:frame atTime:timeAt(0) error:&lateError];run.record(@"late-analysis-frame-also-terminates-host-job-quietly",stopped&&[lateError.domain isEqual:FxPlugErrorDomain]&&lateError.code==kFxError_UserCancelled); // A host cache hit can move the playhead without re-entering renderDestinationImage. // Starting at a middle frame must use analyzer input even on a fresh instance. DYWriteTools(base,doc,kCMTimeZero);idcold=(id)[[NSClassFromString(@"DYPlugIn")alloc]initWithAPIManager:host];host->_time=timeAt(2);host->_state=kFxAnalysisState_NotAnalyzing;int starts=host->_forwardStarts; [cold toolTrackRequested:[NSNotification notificationWithName:@"DYToolTrack" object:host userInfo:@{@"node":@"base:hsl",@"mask":mask[@"id"],@"direction":@1}]]; callbacks=host->_forwardStarts==starts+1&&[cold desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&CMTimeCompare(desired.start,timeAt(2))==0&&[cold setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil]; for(int i=2;i<6&&callbacks;i++){setFrame(i);callbacks&=[cold analyzeFrame:frame atTime:timeAt(i) error:nil];}[cold cleanupAnalysis:nil];drain();tracked=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];run.record(@"middle-frame-start-with-no-preview-render-cache",callbacks&&[tracked[@"keys"]count]==4&&CMTimeCompare(CMTimeMake([tracked[@"keys"][0][@"value"]longLongValue],[tracked[@"keys"][0][@"scale"]intValue]),timeAt(2))==0); [cold release]; DYWriteTools(base,doc,kCMTimeZero);capture(0);host->_time=timeAt(2);request(1);callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil]; for(int i=2;i<6&&callbacks;i++){setFrame(i);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}[plugin cleanupAnalysis:nil];drain();tracked=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];run.record(@"middle-frame-start-ignores-stale-preview-cache",callbacks&&[tracked[@"keys"]count]==4); DYWriteTools(base,doc,kCMTimeZero);capture(0);request(1);callbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil]; // Deliberately different preview pixels must not veto an authoritative analysis seed. for(int i=0;i<3&&callbacks;i++){setFrame(i+2);callbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}[plugin cleanupAnalysis:nil];drain();tracked=DYReadTools(base,kCMTimeZero).document[@"baseMasks"][@"hsl"][0];run.record(@"analysis-seed-does-not-require-preview-pixel-equality",callbacks&&[tracked[@"keys"]count]==3); { const NSUInteger w=3840,h=2160;DYDiagnosticTile *fine=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease];Pixels pixels(w*h*4); for(NSUInteger y=0;y previewOnly=[(id)[[NSClassFromString(@"DYPlugIn") alloc] initWithAPIManager:host] autorelease]; NSDictionary *color=nil,*referenceColor=nil; BOOL colorOK=[previewOnly captureTrackingTile:fine gray:nullptr preview:&color error:nil]; auto full=[plugin toolGrayFrame:fine preview:&referenceColor error:nil]; BOOL noGrayBuffer=YES;for(NSDictionary *entry in [[previewOnly valueForKey:@"toolCaptureDevices"] allValues])noGrayBuffer&=entry[@"buffer"]==nil; run.record(@"mosaic-tracking-4k-color-input-matches-without-gray-buffer",colorOK&&full.valid()&&color[@"rgba"]&&[color isEqual:referenceColor]&&noGrayBuffer); } { const NSUInteger w=323,h=181; DYDiagnosticTile *tile=[[[DYDiagnosticTile alloc]initWithDevice:gpu width:w height:h]autorelease]; Pixels color(w*h*4); for(NSUInteger y=0;y legacy=[(id)[[NSClassFromString(@"DYPlugIn") alloc] initWithAPIManager:host] autorelease]; id direct=[(id)[[NSClassFromString(@"DYPlugIn") alloc] initWithAPIManager:host] autorelease]; BOOL exact=tile!=nil;NSUInteger compared=0; for(FxImageOrigin origin : {kFxImageOrigin_TOP_LEFT,kFxImageOrigin_BOTTOM_LEFT}){ [tile setDiagnosticImageOrigin:origin]; for(BOOL flip : {NO,YES}){@autoreleasepool{ NSDictionary *rgba=nil,*packet=nil; [legacy captureTrackingTile:tile gray:nullptr preview:&rgba error:nil]; [direct captureTrackingTile:tile gray:nullptr preview:&packet visionFlip:@(flip) error:nil]; CVPixelBufferRef image=(CVPixelBufferRef)packet[@"visionImage"]; NSData *reference=rgba[@"rgba"]; if(!image||!CVPixelBufferGetIOSurface(image)||packet[@"rgba"]||reference.length!=w*h*4|| CVPixelBufferGetPixelFormatType(image)!=kCVPixelFormatType_32BGRA|| CVPixelBufferLockBaseAddress(image,kCVPixelBufferLock_ReadOnly)!=kCVReturnSuccess){exact=NO;continue;} const auto *actual=static_cast(CVPixelBufferGetBaseAddress(image)); const auto *expected=static_cast(reference.bytes); const size_t stride=CVPixelBufferGetBytesPerRow(image); for(NSUInteger y=0;y_state=kFxAnalysisState_NotAnalyzing; [plugin toolTrackRequested:[NSNotification notificationWithName:@"DYToolTrack" object:host userInfo:@{@"node":@"base:hsl",@"mask":sharedID,@"direction":@1}]];int beforeShared=base->_undoStarts; BOOL sharedCallbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil]; for(int i=0;i<3&&sharedCallbacks;i++){setFrame(i);sharedCallbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];} for(NSString *alias in @[@"shared",@"base:spider",@"base:hsl"])[NSNotificationCenter.defaultCenter postNotificationName:@"DYToolCanvasSelection" object:host userInfo:@{@"node":alias,@"mask":sharedID,@"document":DYReadTools(base,kCMTimeZero).document,@"draw":@NO}]; for(int i=3;i<6&&sharedCallbacks;i++){setFrame(i);sharedCallbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}host->_state=kFxAnalysisState_AnalysisCompleted;[plugin cleanupAnalysis:nil];drain();NSDictionary *saved=DYReadTools(base,kCMTimeZero).document; run.record(@"shared-tracking-same-mask-switches-global-hsl-spider-without-interruption",sharedCallbacks&&[DYSharedMaskWithID(saved,sharedID)[@"keys"]count]==6&&DYMasksForTool(saved,@"base:hsl").firstObject==DYMasksForTool(saved,@"base:spider").firstObject&&base->_undoStarts==beforeShared+1&&base->_undoStarts==base->_undoEnds); // Removing the original UUID binding cannot delete or invalidate the shared // object while another module still references it. NSMutableDictionary *deletable=DYMutablePlist(sharedDoc);NSDictionary *extra=DYInsertTool(deletable,@"hsl",@"base:hsl");NSString *extraID=extra[@"id"];DYSetSharedMaskAssigned(deletable,sharedID,@"base:hsl",NO);DYSetSharedMaskAssigned(deletable,sharedID,extraID,YES);DYWriteTools(base,deletable,kCMTimeZero);capture(0);host->_state=kFxAnalysisState_NotAnalyzing; [plugin toolTrackRequested:[NSNotification notificationWithName:@"DYToolTrack" object:host userInfo:@{@"node":extraID,@"mask":sharedID,@"direction":@1}]];beforeShared=base->_undoStarts;sharedCallbacks=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil]; for(int i=0;i<3&&sharedCallbacks;i++){setFrame(i);sharedCallbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];} NSMutableDictionary *removed=DYMutablePlist(DYReadTools(base,kCMTimeZero).document);BOOL removedAlias=DYRemoveTool(removed,extraID);DYWriteTools(base,removed,kCMTimeZero);[NSNotificationCenter.defaultCenter postNotificationName:@"DYToolCanvasSelection" object:host userInfo:@{@"node":@"base:spider",@"mask":sharedID,@"document":removed,@"draw":@NO}]; for(int i=3;i<6&&sharedCallbacks;i++){setFrame(i);sharedCallbacks&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}host->_state=kFxAnalysisState_AnalysisCompleted;[plugin cleanupAnalysis:nil];drain();saved=DYReadTools(base,kCMTimeZero).document; run.record(@"shared-tracking-survives-removing-original-module-and-commits-one-object",removedAlias&&sharedCallbacks&&!DYToolWithID(saved,extraID)&&[DYSharedMaskWithID(saved,sharedID)[@"keys"]count]==6&&[DYMasksForTool(saved,@"base:spider").firstObject[@"id"]isEqual:sharedID]&&DYToolIDsForSharedMask(saved,sharedID).count==1&&base->_undoStarts==beforeShared+1&&base->_undoStarts==base->_undoEnds); id panel=[[[NSClassFromString(@"DYToolMaskPanel")alloc]initWithManager:host nodeID:@"base:spider"]autorelease];[panel refreshWithDocument:saved time:kCMTimeZero];[panel performSelector:@selector(canvas:)withObject:nil];BOOL aliasActive=[[panel valueForKey:@"_canvasActive"]boolValue]; [NSNotificationCenter.defaultCenter postNotificationName:@"DYToolTrackingStatus" object:host userInfo:@{@"node":@"shared",@"mask":sharedID,@"message":@"共享跟踪状态"}];BOOL statusVisible=[[[panel valueForKey:@"_status"]stringValue]isEqual:@"共享跟踪状态"]; run.record(@"shared-mask-inspector-alias-activates-canvas-and-receives-canonical-status",aliasActive&&statusVisible&&[[(NSObject*)plugin valueForKey:@"_selectedToolNode"]isEqual:@"shared"]); } { NSMutableDictionary *stampDoc=DYMutablePlist([[[DYToolDocument alloc]init]autorelease].document); NSMutableDictionary *stamp=(id)DYAddSharedMask(stampDoc,DYMaskEllipse); NSString *stampID=stamp[@"id"]; DYMaskParameters target=DYMaskAtTime(stamp,kCMTimeZero); target.centerX=.75f;target.centerY=.5f;target.width=.32f;target.height=.54f; stamp[@"parameters"]=[NSData dataWithBytes:&target length:sizeof(target)]; stamp[@"stampSource"]=@[@.25,@.5,@.32,@.54]; auto noise=[](int x,int y){ uint32_t n=uint32_t(x)*73856093u^uint32_t(y)*19349663u; n^=n>>13;n*=1274126177u; return .15f+.7f*((n>>8)&255)/255.f; }; auto pairedFrame=[&](int step,bool flatSource){ Pixels pixels(tw*th*4); for(NSUInteger y=0;y_time=timeAt(start);host->_state=kFxAnalysisState_NotAnalyzing; [plugin toolTrackRequested:[NSNotification notificationWithName:@"DYToolTrack" object:host userInfo:@{@"node":@"shared",@"mask":stampID,@"direction":@1}]]; return [plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&& [plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil]; }; auto finish=[&](){host->_state=kFxAnalysisState_AnalysisCompleted;[plugin cleanupAnalysis:nil];drain();}; DYWriteTools(base,stampDoc,kCMTimeZero); int beforeStamp=base->_undoStarts; BOOL paired=requestStamp(0); NSError *pairError=nil; for(int i=0;i<6&&paired;i++){pairedFrame(i,false);paired&=[plugin analyzeFrame:frame atTime:timeAt(i) error:&pairError];} finish(); NSDictionary *saved=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,stampID); DYStampMotion motion=DYStampMotionAtTime(saved,timeAt(5)); DYMaskParameters covered=DYMaskAtTime(saved,timeAt(5)); NSArray *sampled=DYStampSourceAtTime(saved,timeAt(5)); lastPreview=updates.count>=2?updates[updates.count-2]:nil; DYMaskParameters shownSource{},shownTarget{}; [lastPreview[@"sourceShape"] getBytes:&shownSource length:sizeof(shownSource)]; [lastPreview[@"shape"] getBytes:&shownTarget length:sizeof(shownTarget)]; run.record(@"clone-analysis-preview-displays-both-regions-on-the-same-frame", [lastPreview[@"completed"]intValue]==6&&fabs([lastPreview[@"time"]doubleValue]-CMTimeGetSeconds(timeAt(5)))<1e-9&& fabs(shownSource.centerX-[sampled[0]doubleValue])<1e-6&&shownTarget.centerX==covered.centerX&& fabs(shownTarget.width-covered.width)<1e-6&&[lastPreview[@"rgba"]length]==tw*th*4); run.record(@"host-clone-stamp-follows-two-independent-centers-and-scales", paired&&[saved[@"keys"] count]==6&&motion.active&& fabs(covered.centerX-(.75+10./tw))<.006&&fabs(covered.centerY-(.5-3.75/th))<.008&& fabs([sampled[0] doubleValue]-(.25-7.5/tw))<.006&&fabs([sampled[1] doubleValue]-(.5+5./th))<.008&& fabs(motion.targetScaleX-1.175)<.045&&fabs(motion.targetScaleY-1.175)<.045&& fabs(motion.sourceScaleX-.875)<.04&&fabs(motion.sourceScaleY-.875)<.04&&base->_undoStarts==beforeStamp+1, @{@"keys":@([saved[@"keys"] count]),@"source":sampled?:@[],@"target":@[@(covered.centerX),@(covered.centerY)], @"sourceScale":@[@(motion.sourceScaleX),@(motion.sourceScaleY)], @"targetScale":@[@(motion.targetScaleX),@(motion.targetScaleY)],@"error":reason(pairError)}); DYStampMotion restart=DYStampMotionAtTime(saved,timeAt(2)); paired=requestStamp(2); for(int i=2;i<6&&paired;i++){pairedFrame(i,false);paired&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];} finish(); saved=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,stampID); DYStampMotion resumed=DYStampMotionAtTime(saved,timeAt(2)); run.record(@"host-clone-stamp-restarts-from-current-paired-scale", paired&&[saved[@"keys"] count]==6&&resumed.active&&restart.sourceScaleX==resumed.sourceScaleX&&restart.targetScaleX==resumed.targetScaleX); DYWriteTools(base,stampDoc,kCMTimeZero); paired=requestStamp(0); for(int i=0;i<3&&paired;i++){pairedFrame(i,false);paired&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];} pairedFrame(3,true);NSError *sourceLoss=nil; BOOL ended=![plugin analyzeFrame:frame atTime:timeAt(3) error:&sourceLoss]; finish(); saved=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,stampID); run.record(@"host-clone-stamp-source-loss-stops-both-tracks-at-last-paired-frame", paired&&ended&&[saved[@"keys"] count]==3&&[sourceLoss.domain isEqual:FxPlugErrorDomain]&& sourceLoss.code==kFxError_UserCancelled&&[sourceLoss.localizedDescription containsString:@"取样区域"]); [NSNotificationCenter.defaultCenter postNotificationName:@"DYToolCanvasSelection" object:host userInfo:@{@"node":@"shared",@"mask":stampID,@"document":DYReadTools(base,kCMTimeZero).document}]; int beforeReturn=host->_seekCount; [plugin cloneStampCommand:@"return" mask:stampID atTime:timeAt(2)];drain(); run.record(@"clone-last-trusted-button-maps-input-time-to-host-timeline",host->_seekCount==beforeReturn+1&&CMTimeCompare(host->_time,timeAt(2))==0); stamp[@"stampTrackMode"]=@"linked";DYWriteTools(base,stampDoc,kCMTimeZero);paired=requestStamp(0); for(int i=0;i<6&&paired;i++){pairedFrame(i,true);paired&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];}finish(); saved=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,stampID);motion=DYStampMotionAtTime(saved,timeAt(5));covered=DYMaskAtTime(saved,timeAt(5));sampled=DYStampSourceAtTime(saved,timeAt(5)); run.record(@"linked-clone-tracks-with-completely-flat-clean-source",paired&&[saved[@"keys"]count]==6&&fabs([sampled[0]doubleValue]-(covered.centerX-.5*motion.targetScaleX))<1e-5&&fabs(motion.sourceScaleX-motion.targetScaleX)<1e-6); // A tiny flat repair ellipse follows a separate textured rectangle without // increasing the pixels that the repair covers. NSMutableDictionary *referenceDoc=DYMutablePlist(stampDoc),*referenceStamp=(id)DYSharedMaskWithID(referenceDoc,stampID); DYMaskParameters tiny=target;tiny.centerX=.86;tiny.width=.02;tiny.height=.04;referenceStamp[@"parameters"]=[NSData dataWithBytes:&tiny length:sizeof(tiny)]; BOOL referenceOK=DYSetStampReference(referenceStamp,NSMakeRect(.6,.25,.2,.5),kCMTimeZero); DYWriteTools(base,referenceDoc,kCMTimeZero);paired=requestStamp(0); for(int i=0;i<6&&paired;i++){ pairedFrame(i,true);Pixels repairPixels=read(frame,gpu);float scale=1+i*.035f,cx=.75f+i*2.f/tw+(.86f-.75f)*scale,cy=.5f-i*.75f/th; for(NSUInteger y=0;y_time=kCMTimeZero;host->_state=kFxAnalysisState_NotAnalyzing;int backwardBeforeLoss=host->_backwardStarts; [plugin toolTrackRequested:[NSNotification notificationWithName:@"DYToolTrack" object:host userInfo:@{@"node":@"shared",@"mask":stampID,@"direction":@0}]]; paired=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil]; [[frame metalTextureForDevice:gpu]replaceRegion:MTLRegionMake2D(0,0,tw,th) mipmapLevel:0 withBytes:flat.data() bytesPerRow:tw*8]; BOOL failedSeed=![plugin analyzeFrame:frame atTime:kCMTimeZero error:nil];finish();saved=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,stampID); [NSNotificationCenter.defaultCenter postNotificationName:@"DYToolCanvasSelection" object:host userInfo:@{@"node":@"shared",@"mask":stampID,@"document":DYReadTools(base,kCMTimeZero).document}]; NSDictionary *canvas=[(id)plugin toolCanvasMaskAtTime:kCMTimeZero]; run.record(@"clone-first-frame-failure-persists-canvas-reason-without-keys",paired&&failedSeed&&![saved[@"keys"]count]&&[saved[@"trackingStopped"]boolValue]&&[canvas[@"status"]containsString:@"纹理不足"]&&![canvas[@"tracking"]boolValue]&&[canvas[@"status"]containsString:@"手工关键帧"]); run.record(@"clone-bidirectional-first-loss-is-not-labelled-forward-complete",host->_backwardStarts==backwardBeforeLoss&&[saved[@"status"]containsString:@"已停止"]); [plugin cloneStampCommand:@"manual" mask:stampID atTime:kCMTimeZero];drain();saved=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,stampID); run.record(@"clone-manual-key-command-starts-after-zero-frame-failure",[saved[@"keys"]count]==1&&[saved[@"keys"][0][@"manual"]boolValue]&&!saved[@"trackingStopped"]); host->_time=timeAt(5);idcanvasHost=(id)plugin; [canvasHost toolCanvasEvent:NSEventTypeLeftMouseDown point:NSMakePoint(.25,.5) part:7 modifiers:0 key:0 time:timeAt(5)]; [canvasHost toolCanvasEvent:NSEventTypeLeftMouseDragged point:NSMakePoint(.3,.53) part:7 modifiers:0 key:0 time:timeAt(5)]; [canvasHost toolCanvasEvent:NSEventTypeLeftMouseUp point:NSMakePoint(.3,.53) part:7 modifiers:0 key:0 time:timeAt(5)];drain(); saved=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,stampID); run.record(@"clone-manual-source-drag-keys-current-frame-without-moving-earlier-source",[saved[@"keys"]count]==2&&fabs([DYStampSourceAtTime(saved,kCMTimeZero)[0]doubleValue]-.25)<1e-6&&fabs([DYStampSourceAtTime(saved,timeAt(5))[0]doubleValue]-.3)<1e-6&&fabs([saved[@"stampSource"][0]doubleValue]-.25)<1e-6); [canvasHost toolCanvasEvent:NSEventTypeLeftMouseDown point:NSMakePoint(.75,.5) part:1 modifiers:0 key:0 time:timeAt(5)]; [canvasHost toolCanvasEvent:NSEventTypeLeftMouseDragged point:NSMakePoint(.8,.52) part:1 modifiers:0 key:0 time:timeAt(5)]; [canvasHost toolCanvasEvent:NSEventTypeLeftMouseUp point:NSMakePoint(.8,.52) part:1 modifiers:0 key:0 time:timeAt(5)];drain(); saved=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,stampID); run.record(@"clone-manual-target-correction-preserves-source-key-at-same-frame",[saved[@"keys"]count]==2&&fabs(DYMaskAtTime(saved,timeAt(5)).centerX-.8)<1e-6&&fabs([DYStampSourceAtTime(saved,timeAt(5))[0]doubleValue]-.3)<1e-6); host->_time=kCMTimeZero;DYMaskParameters beforeReference=DYMaskAtTime(saved,kCMTimeZero); [plugin cloneStampCommand:@"reference" mask:stampID atTime:kCMTimeZero];drain(); [canvasHost toolCanvasEvent:NSEventTypeLeftMouseDown point:NSMakePoint(.4,.2) part:8 modifiers:0 key:0 time:kCMTimeZero]; [canvasHost toolCanvasEvent:NSEventTypeLeftMouseDragged point:NSMakePoint(.7,.7) part:8 modifiers:0 key:0 time:kCMTimeZero]; [canvasHost toolCanvasEvent:NSEventTypeLeftMouseUp point:NSMakePoint(.7,.7) part:8 modifiers:0 key:0 time:kCMTimeZero];drain(); saved=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,stampID);DYMaskParameters afterReference=DYMaskAtTime(saved,kCMTimeZero),selectedReference=DYStampReferenceAtTime(saved,kCMTimeZero); run.record(@"clone-reference-draw-gesture-preserves-repair-and-manual-keys",saved[@"stampReference"]&&[saved[@"keys"]count]==2&&beforeReference.centerX==afterReference.centerX&&beforeReference.width==afterReference.width&&fabs(selectedReference.centerX-.55)<1e-6&&fabs(selectedReference.height-.5)<1e-6); } { NSMutableDictionary *objectDoc=DYMutablePlist([[[DYToolDocument alloc]init]autorelease].document),*objectMask=(id)DYAddSharedMask(objectDoc,DYMaskRectangle); NSString *ID=objectMask[@"id"];DYMaskParameters shape=DYMaskAtTime(objectMask,kCMTimeZero);shape.width=shape.height=.45;shape.feather=0;objectMask[@"parameters"]=[NSData dataWithBytes:&shape length:sizeof(shape)]; objectDoc[@"mosaic"]=[NSMutableDictionary dictionaryWithDictionary:@{@"enabled":@YES,@"source":@"mask",@"maskIDs":@[ID],@"size":@16}]; run.record(@"mosaic-selected-mask-uses-object-tracking",DYMosaicTracksMask(objectDoc,ID)&&!DYMosaicTracksMask(objectDoc,@"missing")); shape.kind=DYMaskBezier;objectMask[@"parameters"]=[NSData dataWithBytes:&shape length:sizeof(shape)]; run.record(@"bezier-mosaic-uses-vision-object-tracking",DYMosaicTracksMask(objectDoc,ID)); shape.kind=DYMaskRectangle;objectMask[@"parameters"]=[NSData dataWithBytes:&shape length:sizeof(shape)]; objectDoc[@"mosaic"][@"enabled"]=@NO;run.record(@"disabled-mosaic-uses-precise-vision-registration",!DYMosaicTracksMask(objectDoc,ID));objectDoc[@"mosaic"][@"enabled"]=@YES; DYWriteTools(base,objectDoc,kCMTimeZero);capture(0);host->_state=kFxAnalysisState_NotAnalyzing; [plugin toolTrackRequested:[NSNotification notificationWithName:@"DYToolTrack" object:host userInfo:@{@"node":@"shared",@"mask":ID,@"direction":@1}]]; BOOL ok=[plugin desiredAnalysisTimeRange:&desired forInputWithTimeRange:inputRange error:nil]&&[plugin setupAnalysisForTimeRange:desired frameDuration:timeAt(1) error:nil]; for(int i=0;i<6&&ok;i++){setFrame(i);ok&=[plugin analyzeFrame:frame atTime:timeAt(i) error:nil];} run.record(@"mosaic-object-host-callbacks-produce-six-frames",ok&&[[(NSObject*)plugin valueForKey:@"trackingSamples"]count]==6); // Simulate cancellation while two provisional predictions are awaiting a // confirmed endpoint. Those keys must never reach the host document. [(NSObject*)plugin setValue:@2 forKey:@"trackingObjectPending"];[plugin cleanupAnalysis:nil];drain(); NSDictionary *savedMask=DYSharedMaskWithID(DYReadTools(base,kCMTimeZero).document,ID); run.record(@"object-tracking-discards-unconfirmed-tail-before-commit",[savedMask[@"keys"]count]==4&&[savedMask[@"status"]containsString:@"未确认预测"]); } [NSNotificationCenter.defaultCenter removeObserver:observer]; [plugin release]; } { dy::ObjectMotion motion;dy::ObjectBox box{.3,.4,.1,.15,.95};motion.reset(box,25);bool ok=true; for(int i=1;i<=10;i++){box.cx=.3f+.002f*i;ok&=motion.advance(box,true).valid;} auto predicted=motion.advance({},false);run.record(@"object-short-loss-predicts-prior-motion",ok&&predicted.valid&&predicted.predicted&&predicted.box.cx>box.cx&&predicted.box.confidence<.3); motion.advance({},false);box.cx=.326;auto first=motion.advance(box,true);box.cx=.328;auto second=motion.advance(box,true); run.record(@"object-reacquisition-requires-two-consistent-observations",first.predicted&&second.recovered&&second.gap==3&&!second.predicted); auto teleport=box;teleport.cx=.9;run.record(@"object-motion-rejects-distant-distractor",motion.advance(teleport,true).predicted); dy::ObjectStep last;for(int i=0;i<25;i++)last=motion.advance({},false);run.record(@"object-long-loss-stops-bounded-prediction",!last.valid&&!motion.active()); motion.reset({.5,.5,.1,.1,.9},std::numeric_limits::quiet_NaN()); run.record(@"object-invalid-fps-does-not-enable-prediction",!motion.active()); DYMaskParameters a=dyDefaultMaskParameters(),b=a;a.centerX=.2;b.centerX=.8;a.width=.1;b.width=.4; NSMutableArray *keys=[NSMutableArray arrayWithObjects:DYMaskKey(CMTimeMake(3,25),a,NO,1),DYMaskKey(CMTimeMake(2,25),a,NO,.1),DYMaskKey(CMTimeMake(1,25),a,NO,.1),nil]; BOOL repaired=DYRepairObjectTrackingGap(keys,b,2);DYMaskParameters x,y;[keys[1][@"parameters"]getBytes:&x length:sizeof(x)];[keys[2][@"parameters"]getBytes:&y length:sizeof(y)]; run.record(@"object-gap-repair-uses-both-endpoints-in-reverse-order",repaired&&fabs(x.centerX-.4)<1e-6&&fabs(y.centerX-.6)<1e-6&&[keys[1][@"value"]intValue]==2&&[keys[1][@"confidence"]floatValue]<.5); NSArray *before=[[keys copy]autorelease];run.record(@"object-gap-repair-rejects-missing-confirmed-anchor",!DYRepairObjectTrackingGap(keys,b,3)&&[keys isEqual:before]); keys[1]=DYMaskKey(CMTimeMake(2,25),a,YES,1);before=[[keys copy]autorelease];run.record(@"object-gap-repair-never-overwrites-manual-key",!DYRepairObjectTrackingGap(keys,b,2)&&[keys isEqual:before]); }