GCC Code Coverage Report


Directory: avs_core/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 85.7% 6 / 0 / 7
Functions: 50.0% 1 / 0 / 2
Branches: -% 0 / 0 / 0

core/cache.h
Line Branch Exec Source
1 // Avisynth v2.6. Copyright 2002-2009 Ben Rudiak-Gould et al.
2 // http://avisynth.nl
3
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
17 // http://www.gnu.org/copyleft/gpl.html .
18 //
19 // Linking Avisynth statically or dynamically with other modules is making a
20 // combined work based on Avisynth. Thus, the terms and conditions of the GNU
21 // General Public License cover the whole combination.
22 //
23 // As a special exception, the copyright holders of Avisynth give you
24 // permission to link Avisynth with independent modules that communicate with
25 // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license
26 // terms of these independent modules, and to copy and distribute the
27 // resulting combined work under terms of your choice, provided that
28 // every copy of the combined work is accompanied by a complete copy of
29 // the source code of Avisynth (the version of Avisynth used to produce the
30 // combined work), being distributed under the terms of the GNU General
31 // Public License plus this exception. An independent module is a module
32 // which is not derived from or based on Avisynth, such as 3rd-party filters,
33 // import and export plugins, or graphical user interfaces.
34
35 #ifndef __Cache_H__
36 #define __Cache_H__
37
38 #include <avisynth.h>
39 #include <mutex>
40 #include <vector>
41 #include <string>
42
43 struct CachePimpl;
44 class InternalEnvironment;
45
46 class AvsCache : public IClip
47 {
48 private:
49
50 IScriptEnvironment* Env;
51 CachePimpl* _pimpl;
52 Device* device;
53 std::mutex& CacheGuardMutex; // just reference!
54
55 void FillAudioZeros(void* buf, size_t start_offset, size_t count);
56
57 public:
58 #ifdef _DEBUG
59 std::string FuncName = ""; // P.F. Invoked function's name whose queue owns the cache object
60 #endif
61 AvsCache(const PClip& child, Device* device, std::mutex &CacheGuardMutex, InternalEnvironment* env);
62 ~AvsCache();
63 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
64 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
65 const VideoInfo& __stdcall GetVideoInfo();
66 bool __stdcall GetParity(int n);
67 int __stdcall SetCacheHints(int cachehints,int frame_range);
68
69 Device* GetDevice() const { return device; }
70
71 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
72 static bool __stdcall IsCache(const PClip& c);
73
74 };
75
76 class CacheGuard : public IClip
77 {
78 private:
79 struct CacheHints {
80 size_t min, max;
81 size_t default_min, default_max;
82 CachePolicyHint AudioPolicy, default_AudioPolicy;
83 int AudioSize, default_AudioSize;
84
85 6 CacheHints() :
86 6 min(0), max(std::numeric_limits<size_t>::max()),
87 6 default_min(min), default_max(max),
88 6 AudioPolicy(CACHE_AUDIO), default_AudioPolicy(AudioPolicy),
89 6 AudioSize(0), default_AudioSize(AudioSize)
90 6 { }
91 };
92
93 PClip child;
94 VideoInfo vi;
95 IScriptEnvironment* globalEnv;
96
97 std::vector<std::pair<Device*, PClip>> deviceCaches;
98 CacheHints hints;
99 mutable std::mutex mutex;
100
101 PClip GetCache(IScriptEnvironment* env_, bool use_child_if_notfound);
102
103 void ApplyHints(int cachehints, int frame_range);
104
105 int GetOrDefault(int cachehints, int frame_range, int def);
106
107 public:
108 CacheGuard(const PClip& child, const char *name, IScriptEnvironment* env);
109 ~CacheGuard();
110 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
111 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
112 const VideoInfo& __stdcall GetVideoInfo();
113 bool __stdcall GetParity(int n);
114 int __stdcall SetCacheHints(int cachehints, int frame_range);
115
116 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
117 static bool __stdcall IsCache(const PClip& c);
118
119 private:
120 std::string name;
121 enum {
122 // Old 2.5 poorly defined cache hints.
123 // Reserve values used by 2.5 API
124 // Do not use in new filters
125 CACHE_25_NOTHING=0,
126 CACHE_25_RANGE=1,
127 CACHE_25_ALL=2,
128 CACHE_25_AUDIO=3,
129 CACHE_25_AUDIO_NONE=4,
130 CACHE_25_AUDIO_AUTO=5,
131 };
132 };
133
134 #endif // __Cache_H__
135