The idea is that instead of creating TVideo instance and calling TVideo.LoadFromFile, you instead call Video := Cache.Video_IncReference(...). Later, instead of freeing this video, call Video_DecReference(Video). From your point of view, things will work the same. But if you expect to load many videos from the same URL, then you will get a great speed and memory saving, because video will only be actually loaded once. This may happen e.g. if you have a VRML / X3D file with lots of MovieTexture nodes with the same urls.
Notes:
All passed here URLs must be absolute.
Note that in case of problems with loading, Video_IncReference may raise an exception, just like normal TVideo.LoadFromFile. In this case it's guaranteed that no reference will be incremented, of course. If Video_IncReference returns in a normal way, then it will return something non-Nil for sure.
Note that before destroying this object you must free all videos, i.e. call Video_DecReference for all videos allocated by Video_IncReference. This class is not a lousy way of avoiding memory leaks — it would be a bad idea, because it would cause sloppy programming, where memory is unnecessarily allocated for a long time. In fact, this class asserts in destructor that no videos are in cache anymore, so if you compiled with assertions enabled, this class does the job of memory-leak detector.
If cache is empty, calls OnEmpty. Note that OnEmpty may destroy current instance, so call CheckEmpty only when you finished processing — Self may be invalid afterwards.
constructor Create;
destructor Destroy; override;
function Video_IncReference(const URL: string; out AlphaChannel: TAlphaChannel): TVideo;