VideoHashFilesystemCache

Struct VideoHashFilesystemCache 

Source
pub struct VideoHashFilesystemCache(/* private fields */);
Expand description

A disk-backed cache for hashes of videos on the filesystem. This is a utility struct for long term storage of VideoHashes. The cache tracks modification times of the underlying video files, and will automatically recalculate hashes based on this.

Cache entries are created and retrieved by calling fetch_update with the path to a video on disk. If there is no entry in the cache, or the modification time of the video is newer then the cache will create a video hash for the underlying file. If the video is already cached then the cache will supply its cached data

Hashes can be obtained from the cache without visiting the underlying video on the filesystem with fetch.

To update all hashes within a given directory (or set of directories) use update_using_fs

§A note on interior mutability

All methods on this struct and its underlying implementation are use interior mutability allow for operations to occur in parallel.

Implementations§

Source§

impl VideoHashFilesystemCache

Source

pub fn new( cache_save_thresold: u32, cache_path: PathBuf, ) -> Result<Self, VdfCacheError>

Load a VideoHash cache from disk the specified path. If no cache exists at cache_path then a new cache will be created.

The cache will automatically save its contents to disk when cache_save_threshold write/delete operations have occurred to the cache.

Note: The cache does not automatically save its contents when it goes out of scope. You must manually call save after you have made the last modification to the chache contents.

Returns an error if it was not possible to load the cache or create a new one.

Source

pub fn fetch( &self, src_path: impl AsRef<Path>, ) -> Result<VideoHash, VdfCacheError>

Fetch the hash for the video file at the given source path. If the cache does not already contain a hash will not create one. This method does not read src_path on the filesystem.

Returns an error if the cache has no entry for src_path .

Source

pub fn all_cached_paths(&self) -> Vec<PathBuf>

Get the paths of all VideoHashes stored in the cache.

Source

pub fn fetch_update( &self, src_path: impl AsRef<Path>, ) -> Result<Option<Result<VideoHash, HashCreationErrorKind>>, VdfCacheError>

If src_path has not been modified since it was cached, then return the cached hash. If src_path has been deleted, then remove it from the cache and return None. Otherwise create a new hash, insert it into the cache, and return it.

Returns an error if it was not possible to generate a hash from src_path.

Source

pub fn save(&self) -> Result<(), VdfCacheError>

Save the cache to disk.

Returns an error if it was not possible to write the cache to disk.

Source

pub fn update_using_fs( &self, file_projection: &FileProjection, ) -> Result<Vec<VdfCacheError>, VdfCacheError>

For all files on the filesystem matching file_projection, update the cache for all new or modified files. Also, remove items from the cache if they no longer exist in the underlying filesystem.

§Return values

This function will return Err if any fatal error occurs. Otherwise, it returns a group of nonfatal errors, typically a list of paths for which a VideoHash could not be generated.

§Fatal errors
  • Unable to read any of the starting directories in file_projection
  • Any Io error when reading/writing to the cache file itself.
§Nonfatal errors
  • Failure to create a hash from any individual file.
  • Failure to remove an item from the cache (This is unlikely and should only occur if calling this function more than once at the same time with overlapping paths)
§Parallelism

To speed up loading there is a cargo feature to allow hashes to be created from videos in parallel. Parallel loading is much faster than sequential loading but be aware that since Ffmpeg is already multithreaded this can use up a lot of CPU time.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V