文件
dayu-color/大鱼调色/Plugin/DYScopeDisplayTime.h
T

36 行
2.4 KiB
Objective-C

#pragma once
#import <CoreMedia/CoreMedia.h>
// FCP can expose the exclusive input out point to custom views while its viewer
// holds the last visible frame. Only that exact boundary has a previous frame.
static inline CMTime DYScopeDisplayTime(CMTime requested,CMTime start,CMTime duration,CMTime frame){
if(!CMTIME_IS_NUMERIC(requested)||!CMTIME_IS_NUMERIC(start)||!CMTIME_IS_NUMERIC(duration)||!CMTIME_IS_NUMERIC(frame)||duration.value<=0||frame.value<=0||duration.epoch||frame.epoch)return requested;
CMTime end=CMTimeAdd(start,duration);if(!CMTIME_IS_NUMERIC(end)||CMTimeCompare(requested,end)!=0)return requested;
CMTime last=CMTimeSubtract(end,frame);return CMTimeCompare(last,start)<0?start:last;
}
// Custom-view time can land between rendered input frames. A cached frame
// covers its own interval only; the next frame boundary must get a fresh sample.
static inline bool DYScopeFrameContainsTime(CMTime captured,CMTime requested,CMTime frame,bool exclusiveEnd){
if(!CMTIME_IS_NUMERIC(captured)||!CMTIME_IS_NUMERIC(requested)||captured.epoch!=requested.epoch)return false;
int comparison=CMTimeCompare(captured,requested);
if(comparison==0)return !exclusiveEnd;
if(comparison>0||!CMTIME_IS_NUMERIC(frame)||frame.value<=0||frame.epoch)return false;
CMTime delta=CMTimeSubtract(requested,captured);
if(exclusiveEnd){
// FCP holds its last presented project frame at the exclusive clip end.
// Allow a final project frame as slow as 23.976 even for faster source media.
return CMTimeCompare(delta,CMTimeMaximum(frame,CMTimeMake(1001,24000)))<=0;
}
return CMTimeCompare(delta,frame)<0;
}
#import <FxPlug/FxPlugSDK.h>
// Caller must already hold a custom parameter action. OSC events keep their
// provided time; this only normalizes the custom-view clock used to guard them.
static inline CMTime DYHostDisplayedFrameTime(id<PROAPIAccessing> host,CMTime current,CMTime *frameDuration=nullptr){
id<FxTimingAPI_v4>timing=[host apiForProtocol:@protocol(FxTimingAPI_v4)];CMTime start=kCMTimeInvalid,duration=kCMTimeInvalid,frame=kCMTimeInvalid;
if([timing respondsToSelector:@selector(startTimeOfInputToFilter:)]&&[timing respondsToSelector:@selector(durationTimeOfInputToFilter:)]&&[timing respondsToSelector:@selector(frameDuration:)]){[timing startTimeOfInputToFilter:&start];[timing durationTimeOfInputToFilter:&duration];[timing frameDuration:&frame];}
if(frameDuration)*frameDuration=frame;
return DYScopeDisplayTime(current,start,duration,frame);
}