Class TVideosCache
Unit
CastleVideos
Declaration
type TVideosCache = class(TObject)
Description
A cache of loaded videos.
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 FileName, 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 FileNames must be absolute, already expanded paths. In the future it's expected that this (just like TVideo.LoadFromFile, actually) will be extended to load videos from URLs.
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.
Video_DecReference alwas sets Video to Nil , like FreeAndNil.
All videos handled here are always loaded. So Video_IncReference always returns TVideo with TVideo.Loaded = True . And you are forbidden from closing this video by TVideo.Close yourself.
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.
Hierarchy
Overview
Methods
Properties
 |
property OnEmpty: TProcedure read FOnEmpty write FOnEmpty; |
Description
Methods
 |
constructor Create; |
|
 |
destructor Destroy; override; |
|
 |
procedure Video_DecReference(var Video: TVideo); |
|
 |
function Empty: boolean; virtual; |
|
Properties
 |
property OnEmpty: TProcedure read FOnEmpty write FOnEmpty; |
Called when cache becomes empty. This is only for internal usage by X3DNodes unit for now.
|
Generated by PasDoc 0.12.1 on 2013-02-04 20:26:53
|