Skip to content

Commit d1a32d5

Browse files
committed
Cache: Avoid naming collision
1 parent 91fc408 commit d1a32d5

4 files changed

Lines changed: 37 additions & 37 deletions

File tree

avs_core/core/avisynth.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ class ScriptEnvironment {
10701070
typedef std::vector<DebugTimestampedFrame> VideoFrameArrayType;
10711071
typedef std::map<VideoFrameBuffer *, VideoFrameArrayType> FrameBufferRegistryType;
10721072
typedef std::map<size_t, FrameBufferRegistryType> FrameRegistryType2; // post r1825 P.F.
1073-
typedef mapped_list<Cache*> CacheRegistryType;
1073+
typedef mapped_list<AvsCache*> CacheRegistryType;
10741074

10751075

10761076
FrameRegistryType2 FrameRegistry2; // P.F.
@@ -1080,7 +1080,7 @@ class ScriptEnvironment {
10801080

10811081
std::unique_ptr<DeviceManager> Devices;
10821082
CacheRegistryType CacheRegistry;
1083-
Cache* FrontCache;
1083+
AvsCache* FrontCache;
10841084
VideoFrame* GetNewFrame(size_t vfb_size, size_t margin, Device* device);
10851085
VideoFrame* GetFrameFromRegistry(size_t vfb_size, Device* device);
10861086
void ShrinkCache(Device* device);
@@ -3605,7 +3605,7 @@ VideoFrame* ScriptEnvironment::GetNewFrame(size_t vfb_size, size_t margin, Devic
36053605
for (auto &cit: CacheRegistry)
36063606
{
36073607
cache_counter++;
3608-
Cache* cache = cit;
3608+
AvsCache* cache = cit;
36093609
int cache_size = cache->SetCacheHints(CACHE_GET_SIZE, 0);
36103610
_RPT4(0, " cache#%d cache_ptr=%p cache_size=%d \n", cache_counter, (void*)cache, cache_size); // let's see what's in the cache
36113611
}
@@ -3729,7 +3729,7 @@ void ScriptEnvironment::ShrinkCache(Device *device)
37293729

37303730
// We try to shrink least recently used caches first.
37313731

3732-
Cache* cache = cit;
3732+
AvsCache* cache = cit;
37333733
if (cache->GetDevice() != device) {
37343734
continue;
37353735
}
@@ -4206,7 +4206,7 @@ void* ScriptEnvironment::ManageCache(int key, void* data) {
42064206
// Called by Cache instances upon creation
42074207
case MC_RegisterCache:
42084208
{
4209-
Cache* cache = reinterpret_cast<Cache*>(data);
4209+
AvsCache* cache = reinterpret_cast<AvsCache*>(data);
42104210
if (FrontCache != NULL)
42114211
CacheRegistry.push_back(FrontCache);
42124212
FrontCache = cache;
@@ -4215,7 +4215,7 @@ void* ScriptEnvironment::ManageCache(int key, void* data) {
42154215
// Called by Cache instances upon destruction
42164216
case MC_UnRegisterCache:
42174217
{
4218-
Cache* cache = reinterpret_cast<Cache*>(data);
4218+
AvsCache* cache = reinterpret_cast<AvsCache*>(data);
42194219
if (FrontCache == cache)
42204220
FrontCache = NULL;
42214221
else
@@ -4225,7 +4225,7 @@ void* ScriptEnvironment::ManageCache(int key, void* data) {
42254225
// Called by Cache instances when they want to expand their limit
42264226
case MC_NodAndExpandCache:
42274227
{
4228-
Cache* cache = reinterpret_cast<Cache*>(data);
4228+
AvsCache* cache = reinterpret_cast<AvsCache*>(data);
42294229

42304230
// Nod
42314231
if (cache != FrontCache)
@@ -4249,7 +4249,7 @@ void* ScriptEnvironment::ManageCache(int key, void* data) {
42494249
// If we don't have enough free reserves, take away a cache slot from
42504250
// a cache instance that hasn't been used since long.
42514251

4252-
for (Cache* old_cache : CacheRegistry)
4252+
for (AvsCache* old_cache : CacheRegistry)
42534253
{
42544254
if (old_cache->GetDevice() != device) {
42554255
continue;
@@ -4272,7 +4272,7 @@ void* ScriptEnvironment::ManageCache(int key, void* data) {
42724272
// Called by Cache instances when they are accessed
42734273
case MC_NodCache:
42744274
{
4275-
Cache* cache = reinterpret_cast<Cache*>(data);
4275+
AvsCache* cache = reinterpret_cast<AvsCache*>(data);
42764276
if (cache == FrontCache) {
42774277
return 0;
42784278
}
@@ -5127,11 +5127,11 @@ bool ScriptEnvironment::Invoke_(AVSValue *result, const AVSValue& implicit_last,
51275127
#ifdef _DEBUG
51285128
if (PrevFrontCache != FrontCache && FrontCache != NULL) // cache registering swaps frontcache to the current
51295129
{
5130-
_RPT2(0, "ScriptEnvironment::Invoke done Cache::Create %s cache_id=%p\r\n", name, (void*)FrontCache);
5130+
_RPT2(0, "ScriptEnvironment::Invoke done AvsCache::Create %s cache_id=%p\r\n", name, (void*)FrontCache);
51315131
FrontCache->FuncName = name; // helps debugging. See also in cache.cpp
51325132
}
51335133
else {
5134-
_RPT1(0, "ScriptEnvironment::Invoke done Cache::Create %s\r\n", name);
5134+
_RPT1(0, "ScriptEnvironment::Invoke done AvsCache::Create %s\r\n", name);
51355135
}
51365136
#endif
51375137
}

avs_core/core/cache.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ struct CachePimpl
117117
};
118118

119119

120-
Cache::Cache(const PClip& _child, Device* device, std::mutex& CacheGuardMutex, InternalEnvironment* env) :
120+
AvsCache::AvsCache(const PClip& _child, Device* device, std::mutex& CacheGuardMutex, InternalEnvironment* env) :
121121
Env(env),
122122
_pimpl(NULL),
123123
device(device),
124124
CacheGuardMutex(CacheGuardMutex)
125125
{
126126
_pimpl = new CachePimpl(_child, env->GetCacheMode());
127127
env->ManageCache(MC_RegisterCache, reinterpret_cast<void*>(this));
128-
_RPT5(0, "Cache::Cache registered. cache_id=%p child=%p w=%d h=%d VideoCacheSize=%Iu\n", (void*)this, (void*)_child, _pimpl->vi.width, _pimpl->vi.height, _pimpl->VideoCache->size());
128+
_RPT5(0, "AvsCache::AvsCache registered. cache_id=%p child=%p w=%d h=%d VideoCacheSize=%Iu\n", (void*)this, (void*)_child, _pimpl->vi.width, _pimpl->vi.height, _pimpl->VideoCache->size());
129129

130130
const int dummy = 0;
131131
// child is usually MTGuard, which forwards this request to its child filter - the real one
@@ -150,14 +150,14 @@ Cache::Cache(const PClip& _child, Device* device, std::mutex& CacheGuardMutex, I
150150
}
151151
}
152152

153-
Cache::~Cache()
153+
AvsCache::~AvsCache()
154154
{
155-
_RPT5(0, "Cache::Cache unregister. cache_id=%p child=%p w=%d h=%d VideoCacheSize=%Iu\n", (void *)this, (void *)_pimpl->child, _pimpl->vi.width, _pimpl->vi.height, _pimpl->VideoCache->size()); // P.F.
155+
_RPT5(0, "AvsCache::AvsCache unregister. cache_id=%p child=%p w=%d h=%d VideoCacheSize=%Iu\n", (void *)this, (void *)_pimpl->child, _pimpl->vi.width, _pimpl->vi.height, _pimpl->VideoCache->size()); // P.F.
156156
Env->ManageCache(MC_UnRegisterCache, reinterpret_cast<void*>(this));
157157
delete _pimpl;
158158
}
159159

160-
PVideoFrame __stdcall Cache::GetFrame(int n, IScriptEnvironment* env_)
160+
PVideoFrame __stdcall AvsCache::GetFrame(int n, IScriptEnvironment* env_)
161161
{
162162
#ifdef _DEBUG
163163
constexpr auto BUFSIZE = 255;
@@ -186,10 +186,10 @@ PVideoFrame __stdcall Cache::GetFrame(int n, IScriptEnvironment* env_)
186186
LruLookupResult LruLookupRes = _pimpl->VideoCache->lookup(n, &cache_handle, true, result, &env->GetSupressCaching());
187187
/*
188188
std::string name = FuncName;
189-
snprintf(buf.get(), BUFSIZE, "Cache::GetFrame lookup follows: [%s] n=%6d Thread=%zu", name.c_str(), n, env->GetEnvProperty(AEP_THREAD_ID));
189+
snprintf(buf.get(), BUFSIZE, "AvsCache::GetFrame lookup follows: [%s] n=%6d Thread=%zu", name.c_str(), n, env->GetEnvProperty(AEP_THREAD_ID));
190190
_RPT0(0, buf.get());
191191
192-
snprintf(buf.get(), BUFSIZE, "Cache::GetFrame lookup ready: [%s] n=%6d Thread=%zu res=%d", name.c_str(), n, env->GetEnvProperty(AEP_THREAD_ID), (int)LruLookupRes);
192+
snprintf(buf.get(), BUFSIZE, "AvsCache::GetFrame lookup ready: [%s] n=%6d Thread=%zu res=%d", name.c_str(), n, env->GetEnvProperty(AEP_THREAD_ID), (int)LruLookupRes);
193193
_RPT0(0, buf.get());
194194
*/
195195

@@ -208,7 +208,7 @@ PVideoFrame __stdcall Cache::GetFrame(int n, IScriptEnvironment* env_)
208208
try
209209
{
210210
#ifdef _DEBUG
211-
snprintf(buf.get(), BUFSIZE, "Cache::GetFrame LRU_LOOKUP_NOT_FOUND: [%s] n=%6d child=%p\n", name.c_str(), n, (void*)_pimpl->child); // P.F.
211+
snprintf(buf.get(), BUFSIZE, "AvsCache::GetFrame LRU_LOOKUP_NOT_FOUND: [%s] n=%6d child=%p\n", name.c_str(), n, (void*)_pimpl->child); // P.F.
212212
_RPT0(0, buf.get());
213213
#endif
214214
//cache_handle.first->value = _pimpl->child->GetFrame(n, env);
@@ -238,10 +238,10 @@ PVideoFrame __stdcall Cache::GetFrame(int n, IScriptEnvironment* env_)
238238
std::chrono::duration<double> elapsed_seconds = t_end - t_start;
239239
std::string name = FuncName;
240240
if (NULL == cache_handle.first->value) {
241-
snprintf(buf.get(), BUFSIZE, "Cache::GetFrame LRU_LOOKUP_NOT_FOUND: HEY! got nulled! [%s] n=%6d child=%p frame=%p framebefore=%p SeekTimeWithGetFrame:%f\n", name.c_str(), n, (void *)_pimpl->child, (void *)cache_handle.first->value, (void *)result, elapsed_seconds.count()); // P.F.
241+
snprintf(buf.get(), BUFSIZE, "AvsCache::GetFrame LRU_LOOKUP_NOT_FOUND: HEY! got nulled! [%s] n=%6d child=%p frame=%p framebefore=%p SeekTimeWithGetFrame:%f\n", name.c_str(), n, (void *)_pimpl->child, (void *)cache_handle.first->value, (void *)result, elapsed_seconds.count()); // P.F.
242242
_RPT0(0, buf.get());
243243
} else {
244-
snprintf(buf.get(), BUFSIZE, "Cache::GetFrame LRU_LOOKUP_NOT_FOUND: [%s] n=%6d child=%p frame=%p framebefore=%p videoCacheSize=%zu SeekTimeWithGetFrame:%f\n", name.c_str(), n, (void *)_pimpl->child, (void *)cache_handle.first->value, (void *)result, _pimpl->VideoCache->size(), elapsed_seconds.count()); // P.F.
244+
snprintf(buf.get(), BUFSIZE, "AvsCache::GetFrame LRU_LOOKUP_NOT_FOUND: [%s] n=%6d child=%p frame=%p framebefore=%p videoCacheSize=%zu SeekTimeWithGetFrame:%f\n", name.c_str(), n, (void *)_pimpl->child, (void *)cache_handle.first->value, (void *)result, _pimpl->VideoCache->size(), elapsed_seconds.count()); // P.F.
245245
_RPT0(0, buf.get());
246246
}
247247
#endif
@@ -261,7 +261,7 @@ PVideoFrame __stdcall Cache::GetFrame(int n, IScriptEnvironment* env_)
261261
t_end = std::chrono::high_resolution_clock::now();
262262
std::chrono::duration<double> elapsed_seconds = t_end - t_start;
263263
std::string name = FuncName;
264-
snprintf(buf.get(), BUFSIZE, "Cache::GetFrame LRU_LOOKUP_FOUND_AND_READY: [%s] n=%6d child=%p frame=%p vfb=%p videoCacheSize=%zu SeekTime :%f\n", name.c_str(), n, (void *)_pimpl->child, (void *)result, (void *)result->GetFrameBuffer(), _pimpl->VideoCache->size(), elapsed_seconds.count());
264+
snprintf(buf.get(), BUFSIZE, "AvsCache::GetFrame LRU_LOOKUP_FOUND_AND_READY: [%s] n=%6d child=%p frame=%p vfb=%p videoCacheSize=%zu SeekTime :%f\n", name.c_str(), n, (void *)_pimpl->child, (void *)result, (void *)result->GetFrameBuffer(), _pimpl->VideoCache->size(), elapsed_seconds.count());
265265
_RPT0(0, buf.get());
266266
assert(result != NULL);
267267
#endif
@@ -270,14 +270,14 @@ PVideoFrame __stdcall Cache::GetFrame(int n, IScriptEnvironment* env_)
270270
case LRU_LOOKUP_NO_CACHE:
271271
{
272272
#ifdef _DEBUG
273-
snprintf(buf.get(), BUFSIZE, "Cache::GetFrame <Before GetFrame> LRU_LOOKUP_NO_CACHE: [%s] n=%6d child=%p\n", name.c_str(), n, (void*)_pimpl->child); // P.F.
273+
snprintf(buf.get(), BUFSIZE, "AvsCache::GetFrame <Before GetFrame> LRU_LOOKUP_NO_CACHE: [%s] n=%6d child=%p\n", name.c_str(), n, (void*)_pimpl->child); // P.F.
274274
_RPT0(0, buf.get());
275275
#endif
276276
result = _pimpl->child->GetFrame(n, env);
277277
#ifdef _DEBUG
278278
t_end = std::chrono::high_resolution_clock::now();
279279
std::chrono::duration<double> elapsed_seconds = t_end - t_start;
280-
snprintf(buf.get(), BUFSIZE, "Cache::GetFrame <After GetFrame> LRU_LOOKUP_NO_CACHE: [%s] n=%6d child=%p frame=%p vfb=%p videoCacheSize=%zu SeekTime :%f\n", name.c_str(), n, (void *)_pimpl->child, (void *)result, (void *)result->GetFrameBuffer(), _pimpl->VideoCache->size(), elapsed_seconds.count()); // P.F.
280+
snprintf(buf.get(), BUFSIZE, "AvsCache::GetFrame <After GetFrame> LRU_LOOKUP_NO_CACHE: [%s] n=%6d child=%p frame=%p vfb=%p videoCacheSize=%zu SeekTime :%f\n", name.c_str(), n, (void *)_pimpl->child, (void *)result, (void *)result->GetFrameBuffer(), _pimpl->VideoCache->size(), elapsed_seconds.count()); // P.F.
281281
_RPT0(0, buf.get());
282282
#endif
283283
break;
@@ -293,13 +293,13 @@ PVideoFrame __stdcall Cache::GetFrame(int n, IScriptEnvironment* env_)
293293
return result;
294294
}
295295

296-
void Cache::FillAudioZeros(void* buf, size_t start_offset, size_t count) {
296+
void AvsCache::FillAudioZeros(void* buf, size_t start_offset, size_t count) {
297297
const int bps = _pimpl->vi.BytesPerAudioSample();
298298
unsigned char* byte_buf = (unsigned char*)buf;
299299
memset(byte_buf + start_offset * bps, 0, count * bps);
300300
}
301301

302-
void __stdcall Cache::GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env)
302+
void __stdcall AvsCache::GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env)
303303
{
304304
if (count <= 0)
305305
return;
@@ -439,19 +439,19 @@ void __stdcall Cache::GetAudio(void* buf, int64_t start, int64_t count, IScriptE
439439

440440
}
441441

442-
const VideoInfo& __stdcall Cache::GetVideoInfo()
442+
const VideoInfo& __stdcall AvsCache::GetVideoInfo()
443443
{
444444
return _pimpl->vi;
445445
}
446446

447-
bool __stdcall Cache::GetParity(int n)
447+
bool __stdcall AvsCache::GetParity(int n)
448448
{
449449
return _pimpl->child->GetParity(n);
450450
}
451451

452-
int __stdcall Cache::SetCacheHints(int cachehints, int frame_range)
452+
int __stdcall AvsCache::SetCacheHints(int cachehints, int frame_range)
453453
{
454-
// _RPT3(0, "Cache::SetCacheHints called. cache=%p hint=%d frame_range=%d\n", (void *)this, cachehints, frame_range);
454+
// _RPT3(0, "AvsCache::SetCacheHints called. cache=%p hint=%d frame_range=%d\n", (void *)this, cachehints, frame_range);
455455
switch(cachehints)
456456
{
457457
/*********************************************
@@ -490,7 +490,7 @@ int __stdcall Cache::SetCacheHints(int cachehints, int frame_range)
490490
_pimpl->VideoCache->limits(&min, &max);
491491
max = frame_range;
492492
_pimpl->VideoCache->set_limits(min, max);
493-
_RPT3(0, "Cache::SetCacheHints CACHE_SET_MAX_CAPACITY cache=%p hint=%d frame_range=%d\n", (void *)this, cachehints, frame_range);
493+
_RPT3(0, "AvsCache::SetCacheHints CACHE_SET_MAX_CAPACITY cache=%p hint=%d frame_range=%d\n", (void *)this, cachehints, frame_range);
494494
break;
495495
}
496496

@@ -636,7 +636,7 @@ PClip CacheGuard::GetCache(IScriptEnvironment* env_)
636636
}
637637

638638
// not found for current device, create it
639-
Cache* cache = new Cache(child, device, /*ref*/mutex, static_cast<InternalEnvironment*>(globalEnv));
639+
AvsCache* cache = new AvsCache(child, device, /*ref*/mutex, static_cast<InternalEnvironment*>(globalEnv));
640640

641641
// apply cache hints if it is changed
642642
if (hints.min != hints.default_min)

avs_core/core/cache.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
struct CachePimpl;
4444
class InternalEnvironment;
4545

46-
class Cache : public IClip
46+
class AvsCache : public IClip
4747
{
4848
private:
4949

@@ -58,8 +58,8 @@ class Cache : public IClip
5858
#ifdef _DEBUG
5959
std::string FuncName = ""; // P.F. Invoked function's name whose queue owns the cache object
6060
#endif
61-
Cache(const PClip& child, Device* device, std::mutex &CacheGuardMutex, InternalEnvironment* env);
62-
~Cache();
61+
AvsCache(const PClip& child, Device* device, std::mutex &CacheGuardMutex, InternalEnvironment* env);
62+
~AvsCache();
6363
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
6464
void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
6565
const VideoInfo& __stdcall GetVideoInfo();

avs_core/include/avisynth.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ class VideoFrameBuffer {
10071007
volatile long sequence_number;
10081008

10091009
friend class VideoFrame;
1010-
friend class Cache;
1010+
friend class AvsCache;
10111011
friend class ScriptEnvironment;
10121012
volatile long refcount;
10131013

@@ -1101,7 +1101,7 @@ class VideoFrame {
11011101
void Release();
11021102

11031103
friend class ScriptEnvironment;
1104-
friend class Cache;
1104+
friend class AvsCache;
11051105

11061106
VideoFrame(VideoFrameBuffer* _vfb, AVSMap* avsmap, int _offset, int _pitch, int _row_size, int _height, int _pixel_type);
11071107
VideoFrame(VideoFrameBuffer* _vfb, AVSMap* avsmap, int _offset, int _pitch, int _row_size, int _height, int _offsetU, int _offsetV, int _pitchUV, int _row_sizeUV, int _heightUV, int _pixel_type);

0 commit comments

Comments
 (0)