级别: 圣骑士
- 注册时间:
- 2006-08-17
- 在线时间:
- 146小时
- 发帖:
- 215
|
- ---------------------------------- cache.cpp ----------------------------------
- index 87cc346..f813ae4 100644
- @@ -54,6 +54,7 @@ struct {
- extern const AVSFunction Cache_filters[] = {
- { "Cache", "c", Cache::Create_Cache },
- { "InternalCache", "c", Cache::Create_Cache },
- + { "SetCache", "c[range]i", Cache::Create_Cache2 },
- { 0 }
- };
-
- @@ -81,7 +82,10 @@ Cache::Cache(PClip _child, IScriptEnvironment* env)
- // InitializeCriticalSectionAndSpinCount(&cs_cache_V, 4000);
- // InitializeCriticalSectionAndSpinCount(&cs_cache_A, 4000);
-
- - h_policy = CACHE_ALL; // Since hints are not used per default, this is to describe the lowest default cache mode.
- + max_tracked_frame = 30;
- + max_tracked_vf_scaled = max_tracked_frame << CACHE_SCALE_SHIFT;
- + max_tracked_misses = max_tracked_frame/2;
- + h_policy = CACHE_NOTHING; // Since hints are not used per default, this is to describe the lowest default cache mode.
- h_audiopolicy = CACHE_NOTHING; // Don't cache audio per default.
-
- cache_limit = CACHE_SCALE_FACTOR / 2; // Start half way towards 1 buffer
- @@ -411,14 +415,14 @@ PVideoFrame __stdcall Cache::GetFrame(int n, IScriptEnvironment* env)
- minframe = iminframe;
- }
-
- - if (cache_limit > MAX_CACHED_VF_SCALED) cache_limit = MAX_CACHED_VF_SCALED;
- + if (cache_limit > max_tracked_vf_scaled) cache_limit = max_tracked_vf_scaled;
-
- _RPT4(0, "Cache:%x: size %d, limit %d, fault %d\n", this, c, cache_limit, fault_rate);
-
- } // if (n>=minframe
- else { // This frame is not in the range we are currently tracking
- InterlockedIncrement(&g_Cache_stats.vfb_never);
- - if (InterlockedIncrement(&miss_count) > MAX_CACHE_MISSES) {
- + if (InterlockedIncrement(&miss_count) > max_tracked_misses) {
- ResetCache(env); // The cache isn't being accessed, reset it!
- miss_count = 0x80000000; // Hugh negative
- }
- @@ -535,7 +539,7 @@ Cache::CachedVideoFrame* Cache::GetACachedVideoFrame(const PVideoFrame& frame, I
- ReturnVideoFrameBuffer(j, env); // Return out of range vfb to vfb pool for early reuse
- }
-
- - if (count >= MAX_CACHED_VIDEO_FRAMES) return video_frames.prev; // to many entries just steal the oldest CachedVideoFrame
- + if (count >= max_tracked_frame) return video_frames.prev; // to many entries just steal the oldest CachedVideoFrame
-
- return new CachedVideoFrame; // need a new one
- }
- @@ -833,7 +837,7 @@ int __stdcall Cache::SetCacheHints(int cachehints, int frame_range) {
-
-
- if (cachehints == CACHE_ALL) {
- - int _cache_init = min(MAX_CACHED_VIDEO_FRAMES, frame_range);
- + int _cache_init = min(max_tracked_frame, frame_range);
-
- if (_cache_init > cache_init) // The max of all requests
- cache_init = _cache_init;
- @@ -852,14 +856,14 @@ int __stdcall Cache::SetCacheHints(int cachehints, int frame_range) {
-
- }
- else if (cachehints == CACHE_RANGE) {
- -
- + max_tracked_frame = frame_range*2+1;
- + max_tracked_vf_scaled = max_tracked_frame << CACHE_SCALE_SHIFT;
- + max_tracked_misses = max_tracked_frame/2;
- if (frame_range > h_span) // Use the largest size when we have multiple clients
- - h_span = min(MAX_CACHE_RANGE, frame_range);
- + h_span = min(max_tracked_frame, frame_range);
-
- h_policy = CACHE_RANGE; // An explicit cache of radius "frame_range" around the current frame, n.
- -
- }
- -
- return 0;
- }
-
- @@ -912,3 +916,27 @@ AVSValue __cdecl Cache::Create_Cache(AVSValue args, void*, IScriptEnvironment* e
- return p;
- }
-
- +AVSValue __cdecl Cache::Create_Cache2(AVSValue args, void*, IScriptEnvironment* env)
- +{
- + PClip p=0;
- + PClip r=0;
- + int _framerange;
- +
- + p = args[0].AsClip();
- + _framerange = args[1].AsInt(1);
- +
- + if (p) {
- + int q = 0;
- +
- + if (p->GetVersion() >= 5) // AVISYNTH_INTERFACE_VERSION which supports this
- + q = p->SetCacheHints(GetMyThis, 0); // Check if "p" is a cache instance
- +
- + // Do not cache another cache!
- + if (q != (int)(void *)p) {
- + r = new Cache(p, env);
- + r->SetCacheHints(CACHE_RANGE, _framerange);
- + return r;
- + }
- + }
- + return p;
- +}
- \ No newline at end of file
- ----------------------------------- cache.h -----------------------------------
- index 2f02bed..8c0f989 100644
- @@ -55,6 +55,7 @@ public:
- PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
- int __stdcall SetCacheHints(int cachehints,int frame_range);
- static AVSValue __cdecl Create_Cache(AVSValue args, void*, IScriptEnvironment* env);
- + static AVSValue __cdecl Create_Cache2(AVSValue args, void*, IScriptEnvironment* env);
- void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env);
-
- protected:
- @@ -131,6 +132,9 @@ private:
-
- // Cached range limits
- int minframe, maxframe;
- + int max_tracked_frame;
- + int max_tracked_vf_scaled;
- + int max_tracked_misses;
- int cache_init; // The Initial cache size
- long cache_limit; // 16 time the current maximum number of CachedVideoFrame entries
- long fault_rate; // A decaying average of 100 times the peak fault count, used to control vfb auto-locking
- ----------------------------------- main.cpp -----------------------------------
- index 1b82226..2324e60 100644
- @@ -648,10 +648,10 @@ bool CAVIFileSynth::DelayInit2() {
- if (!AllowFloatAudio) // Ensure samples are int
- filter_graph = ConvertAudio::Create(filter_graph, SAMPLE_INT8|SAMPLE_INT16|SAMPLE_INT24|SAMPLE_INT32, SAMPLE_INT16);
-
- - filter_graph = Cache::Create_Cache(AVSValue(filter_graph), 0, env).AsClip();
- + /*filter_graph = Cache::Create_Cache(AVSValue(filter_graph), 0, env).AsClip();
-
- - filter_graph->SetCacheHints(CACHE_ALL, 999); // Give the top level cache a big head start!!
- - }
- + filter_graph->SetCacheHints(CACHE_ALL, 999); // Give the top level cache a big head start!!*/
- + }
- else
- throw AvisynthError("The script's return value was not a video clip");
-
- ---------------------------- parser/expression.cpp ----------------------------
- index 07e212f..b7b86cd 100644
- @@ -508,9 +508,9 @@ AVSValue ExpVariableReference::Evaluate(IScriptEnvironment* env)
- }
- }
- // Add cache to Bracketless call of argless function
- - if (result.IsClip()) { // Tritical Jan 2006
- +/* if (result.IsClip()) { // Tritical Jan 2006
- return Cache::Create_Cache(result, 0, env);
- - }
- + }*/
- return result;
- }
-
- @@ -603,9 +603,9 @@ AVSValue ExpFunctionCall::Evaluate(IScriptEnvironment* env)
- {
- AVSValue result = Call(env);
-
- - if (result.IsClip()) {
- +/* if (result.IsClip()) {
- return Cache::Create_Cache(result, 0, env);
- - }
- + }*/
-
- return result;
- }
懒得检查有没有问题,不会自动插入cache,可以用SetCache(int range)在脚本里手动插入,每个Cache最大存range*2+1帧
|