FFmpegfs Fuse Multi Media Filesystem 2.16
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
Cache_Entry Class Reference

The Cache_Entry class. More...

#include <cache_entry.h>

Collaboration diagram for Cache_Entry:
Collaboration graph
[legend]

Public Member Functions

Cache_Entryoperator= (Cache_Entry const &other)=delete
 operator = declared deleted, should use create to get this object to maintain reference count. More...
 
bool destroy ()
 Destroy this Cache_Entry object. More...
 
bool openio (bool create_cache=true)
 Open the cache file. More...
 
bool flush ()
 Flush current memory cache to disk. More...
 
void clear (bool fetch_file_time=true)
 Clear the cache entry. More...
 
size_t size () const
 Return size of output file, as computed by encoder. More...
 
uint32_t video_frame_count () const
 Get the video frame count. More...
 
time_t age () const
 Get the age of the cache entry. More...
 
time_t last_access () const
 Get last access time. More...
 
bool expired () const
 Check if cache entry expired. More...
 
bool suspend_timeout () const
 Check for decode suspend timeout. More...
 
bool decode_timeout () const
 Check for decode timeout. More...
 
const char * filename () const
 Return source filename. More...
 
const char * destname () const
 Return destination filename. More...
 
const char * virtname () const
 Return virtual filename. Same as destination filename, but with virtual (mount) path.. More...
 
bool update_access (bool update_database=false)
 Update last access time. More...
 
void lock ()
 Lock the access mutex. More...
 
void unlock ()
 Unlock the access mutex. More...
 
int ref_count () const
 Get the current reference counter. More...
 
int inc_refcount ()
 Increment the current reference counter. More...
 
int decr_refcount ()
 Decrement the current reference counter. More...
 
bool outdated () const
 Check if cache entry needs to be recoded. More...
 
LPVIRTUALFILE virtualfile ()
 Get the underlying VIRTUALFILE object. More...
 
bool closeio (int flags)
 Close the cache entry. More...
 
void update_read_count ()
 Update read counter. More...
 
unsigned int read_count () const
 Get read counter. More...
 
bool is_finished () const
 Get if cache has been finished. More...
 
bool is_finished_incomplete () const
 Get if cache has been finished, but not completely filled. More...
 
bool is_finished_success () const
 Get if cache has been finished and filled successfully. More...
 
bool is_finished_error () const
 Get if cache has been finished and with an error. More...
 

Static Public Member Functions

static Cache_Entrycreate (Cache *owner, LPVIRTUALFILE virtualfile)
 Create a new Cache_Entry object. More...
 

Public Attributes

std::unique_ptr< Bufferm_buffer
 Buffer object. More...
 
std::atomic_bool m_is_decoding
 true while file is decoding More...
 
std::recursive_mutex m_active_mutex
 Mutex while thread is active. More...
 
std::recursive_mutex m_restart_mutex
 Mutex while thread is restarted. More...
 
std::atomic_bool m_suspend_timeout
 true to temporarly disable read_frame timeout More...
 
CACHE_INFO m_cache_info
 Info about cached object. More...
 
ID3v1 m_id3v1
 ID3v1 structure which is used to send to clients. More...
 
std::atomic_uint32_t m_seek_to_no
 If not 0, seeks to specified frame. More...
 

Protected Member Functions

void close_buffer (int flags)
 Close buffer object. More...
 
bool read_info ()
 Read cache info. More...
 
bool write_info ()
 Write cache info. More...
 
bool delete_info ()
 Delete cache info. More...
 

Protected Attributes

Cachem_owner
 Owner cache object. More...
 
std::recursive_mutex m_mutex
 Access mutex. More...
 
std::atomic_int m_ref_count
 Reference counter. More...
 
LPVIRTUALFILE m_virtualfile
 Underlying virtual file object. More...
 

Private Member Functions

 Cache_Entry (Cache *owner, LPVIRTUALFILE virtualfile)
 Create Cache_Entry object. More...
 
 Cache_Entry (Cache_Entry &)=delete
 Copy constructor declared deleted, should use create to get this object to maintain reference count.
 
virtual ~Cache_Entry ()
 Destroy Cache_Entry object. More...
 

Detailed Description

The Cache_Entry class.

Definition at line 48 of file cache_entry.h.

Constructor & Destructor Documentation

◆ Cache_Entry()

Cache_Entry::Cache_Entry ( Cache owner,
LPVIRTUALFILE  virtualfile 
)
explicitprivate

◆ ~Cache_Entry()

Cache_Entry::~Cache_Entry ( )
privatevirtual

Destroy Cache_Entry object.

Definition at line 65 of file cache_entry.cc.

References filename(), m_active_mutex, Logging::trace(), and unlock().

Member Function Documentation

◆ age()

time_t Cache_Entry::age ( ) const

Get the age of the cache entry.

Returns
Returns the age of the cache entry in seconds since epoch.

Definition at line 286 of file cache_entry.cc.

References m_cache_info, and CACHE_INFO::m_creation_time.

Referenced by expired().

◆ clear()

void Cache_Entry::clear ( bool  fetch_file_time = true)

◆ close_buffer()

void Cache_Entry::close_buffer ( int  flags)
protected

Close buffer object.

Parameters
[in]flags- one of the CACHE_CLOSE_* flags

Definition at line 206 of file cache_entry.cc.

References delete_info(), and m_buffer.

Referenced by closeio().

◆ closeio()

bool Cache_Entry::closeio ( int  flags)

Close the cache entry.

Parameters
[in]flags- one of the CACHE_CLOSE_* flags
Returns
Returns true if entry may be deleted, false if still in use.

Definition at line 217 of file cache_entry.cc.

References close_buffer(), flush(), m_buffer, m_ref_count, and write_info().

◆ create()

Cache_Entry * Cache_Entry::create ( Cache owner,
LPVIRTUALFILE  virtualfile 
)
static

Create a new Cache_Entry object.

Parameters
[in]owner- Cache object of owner.
[in]virtualfile- Requesting virtual file.
Returns
On success, returns a Cache_Entry object; on error (out of memory) returns a nullptr

Definition at line 74 of file cache_entry.cc.

References Cache_Entry(), and virtualfile().

◆ decode_timeout()

bool Cache_Entry::decode_timeout ( ) const

Check for decode timeout.

Returns
Returns true if decoding timed out.

Definition at line 306 of file cache_entry.cc.

References CACHE_INFO::m_access_time, m_cache_info, FFMPEGFS_PARAMS::m_max_inactive_abort, m_ref_count, and params.

Referenced by transcode().

◆ decr_refcount()

int Cache_Entry::decr_refcount ( )

Decrement the current reference counter.

Returns
Returns the current reference counter.

Definition at line 346 of file cache_entry.cc.

References m_ref_count.

◆ delete_info()

bool Cache_Entry::delete_info ( )
protected

Delete cache info.

Returns
On success, returns true; returns false on error.

Definition at line 141 of file cache_entry.cc.

References Cache::delete_info(), filename(), m_cache_info, CACHE_INFO::m_desttype, and m_owner.

Referenced by close_buffer().

◆ destname()

const char * Cache_Entry::destname ( ) const

Return destination filename.

Returns
Returns the name of the transcoded file.

Definition at line 316 of file cache_entry.cc.

References VIRTUALFILE::m_destfile, and m_virtualfile.

◆ destroy()

bool Cache_Entry::destroy ( )

Destroy this Cache_Entry object.

Returns
true if object was destroyed right away; false if it will be destroyed later (NOT IMPLEMENTED, WILL BE DESTROYED AT ONCE).
Todo:
Implement delete later mechanism
Todo:
Return true when deleted, false if kept for delete later

Definition at line 79 of file cache_entry.cc.

◆ expired()

bool Cache_Entry::expired ( ) const

Check if cache entry expired.

Checks if entry is older or larger than the limit.

Returns
If entry is expired, returns true.

Definition at line 296 of file cache_entry.cc.

References age(), FFMPEGFS_PARAMS::m_expiry_time, and params.

◆ filename()

const char * Cache_Entry::filename ( ) const

Return source filename.

Returns
Returns the name of the transcoded file.

Definition at line 311 of file cache_entry.cc.

References VIRTUALFILE::m_origfile, and m_virtualfile.

Referenced by Cache_Entry(), clear(), delete_info(), openio(), outdated(), transcode(), transcoder_new(), and ~Cache_Entry().

◆ flush()

bool Cache_Entry::flush ( )

Flush current memory cache to disk.

Returns
On success returns true; on error returns false and errno contains the error code.

Definition at line 246 of file cache_entry.cc.

References m_buffer.

Referenced by closeio(), and transcode_finish().

◆ inc_refcount()

int Cache_Entry::inc_refcount ( )

Increment the current reference counter.

Returns
Returns the current reference counter.

Definition at line 341 of file cache_entry.cc.

References m_ref_count.

◆ is_finished()

bool Cache_Entry::is_finished ( ) const

Get if cache has been finished.

Returns
Returns true if cache is finished, false if not.

Definition at line 435 of file cache_entry.cc.

References m_cache_info, CACHE_INFO::m_result, and NONE.

Referenced by openio(), transcode(), and transcode_until().

◆ is_finished_error()

bool Cache_Entry::is_finished_error ( ) const

Get if cache has been finished and with an error.

Returns
Returns true if cache is finished with error, false if not.

Definition at line 450 of file cache_entry.cc.

References FINISHED_ERROR, m_cache_info, and CACHE_INFO::m_result.

◆ is_finished_incomplete()

bool Cache_Entry::is_finished_incomplete ( ) const

Get if cache has been finished, but not completely filled.

Returns
Returns true if cache is finished, but not completely filled, false if not.

Definition at line 440 of file cache_entry.cc.

References FINISHED_INCOMPLETE, m_cache_info, and CACHE_INFO::m_result.

◆ is_finished_success()

bool Cache_Entry::is_finished_success ( ) const

Get if cache has been finished and filled successfully.

Returns
Returns true if cache is finished successfully, false if not.

Definition at line 445 of file cache_entry.cc.

References FINISHED_SUCCESS, m_cache_info, and CACHE_INFO::m_result.

Referenced by transcoder_new(), and transcoder_read().

◆ last_access()

time_t Cache_Entry::last_access ( ) const

Get last access time.

Returns
Returns last access time in seconds since epoch.

Definition at line 291 of file cache_entry.cc.

References CACHE_INFO::m_access_time, and m_cache_info.

◆ lock()

void Cache_Entry::lock ( )

Lock the access mutex.

Definition at line 326 of file cache_entry.cc.

References m_mutex.

Referenced by transcoder_new().

◆ openio()

bool Cache_Entry::openio ( bool  create_cache = true)

Open the cache file.

Parameters
[in]create_cache- If true, the cache will be created if it does not yet exist.
Returns
On success returns true; on error returns false and errno contains the error code.

Definition at line 160 of file cache_entry.cc.

References clear(), filename(), is_finished(), m_buffer, m_cache_info, m_ref_count, CACHE_INFO::m_result, read_info(), Logging::trace(), and update_access().

Referenced by transcode(), and transcoder_new().

◆ operator=()

Cache_Entry & Cache_Entry::operator= ( Cache_Entry const &  other)
delete

operator = declared deleted, should use create to get this object to maintain reference count.

Parameters
[in]other- Assignment object
Returns
Pointer to this

◆ outdated()

bool Cache_Entry::outdated ( ) const

◆ read_count()

unsigned int Cache_Entry::read_count ( ) const

Get read counter.

This is the number of read accesses to the cache entry.

Returns
Returns current read counter

Definition at line 430 of file cache_entry.cc.

References CACHE_INFO::m_access_count, and m_cache_info.

◆ read_info()

bool Cache_Entry::read_info ( )
protected

Read cache info.

Returns
On success, returns true; returns false on error.

Definition at line 131 of file cache_entry.cc.

References m_cache_info, m_owner, and Cache::read_info().

Referenced by openio().

◆ ref_count()

int Cache_Entry::ref_count ( ) const

Get the current reference counter.

Returns
Returns the current reference counter.

Definition at line 336 of file cache_entry.cc.

References m_ref_count.

Referenced by transcode().

◆ size()

size_t Cache_Entry::size ( ) const

Return size of output file, as computed by encoder.

Returns the file size, either the predicted size (which may be inaccurate) or the real size (which is only available once the file was completely recoded).

Returns
The size of the file. Function never fails.

Definition at line 260 of file cache_entry.cc.

References m_buffer, m_cache_info, CACHE_INFO::m_encoded_filesize, and CACHE_INFO::m_predicted_filesize.

Referenced by transcoder_get_size().

◆ suspend_timeout()

bool Cache_Entry::suspend_timeout ( ) const

Check for decode suspend timeout.

Returns
Returns true if decoding was suspended.

Definition at line 301 of file cache_entry.cc.

References CACHE_INFO::m_access_time, m_cache_info, FFMPEGFS_PARAMS::m_max_inactive_suspend, m_ref_count, and params.

Referenced by transcode().

◆ unlock()

void Cache_Entry::unlock ( )

Unlock the access mutex.

Definition at line 331 of file cache_entry.cc.

References m_mutex.

Referenced by transcoder_new(), and ~Cache_Entry().

◆ update_access()

bool Cache_Entry::update_access ( bool  update_database = false)

Update last access time.

Parameters
[in]update_database- If true, also persist in SQL database.
Returns
If update was successful, returns true; returns false on error.

Definition at line 146 of file cache_entry.cc.

References CACHE_INFO::m_access_time, m_cache_info, m_owner, and Cache::write_info().

Referenced by openio(), transcode(), transcoder_read(), and transcoder_read_frame().

◆ update_read_count()

void Cache_Entry::update_read_count ( )

Update read counter.

Definition at line 425 of file cache_entry.cc.

References CACHE_INFO::m_access_count, and m_cache_info.

Referenced by transcoder_read(), and transcoder_read_frame().

◆ video_frame_count()

uint32_t Cache_Entry::video_frame_count ( ) const

Get the video frame count.

Returns
On success, returns the number of frames; on error, returns 0 (calculation failed or no video source file).

Definition at line 281 of file cache_entry.cc.

References m_cache_info, and CACHE_INFO::m_video_frame_count.

◆ virtname()

const char * Cache_Entry::virtname ( ) const

Return virtual filename. Same as destination filename, but with virtual (mount) path..

Returns
Returns the name of the transcoded file.

Definition at line 321 of file cache_entry.cc.

References VIRTUALFILE::m_virtfile, and m_virtualfile.

Referenced by transcode(), transcode_until(), transcoder_new(), transcoder_read(), transcoder_read_frame(), transcoder_set_filesize(), and transcoder_thread().

◆ virtualfile()

LPVIRTUALFILE Cache_Entry::virtualfile ( )

Get the underlying VIRTUALFILE object.

Returns
Return the underlying VIRTUALFILE object.

Definition at line 420 of file cache_entry.cc.

References m_virtualfile.

Referenced by Cache_Entry(), create(), ffmpegfs_release(), transcode(), and transcoder_read().

◆ write_info()

bool Cache_Entry::write_info ( )
protected

Write cache info.

Returns
On success, returns true; returns false on error.

Definition at line 136 of file cache_entry.cc.

References m_cache_info, m_owner, and Cache::write_info().

Referenced by closeio().

Member Data Documentation

◆ m_active_mutex

std::recursive_mutex Cache_Entry::m_active_mutex

Mutex while thread is active.

Definition at line 273 of file cache_entry.h.

Referenced by transcoder_thread(), and ~Cache_Entry().

◆ m_buffer

std::unique_ptr<Buffer> Cache_Entry::m_buffer

◆ m_cache_info

CACHE_INFO Cache_Entry::m_cache_info

◆ m_id3v1

ID3v1 Cache_Entry::m_id3v1

ID3v1 structure which is used to send to clients.

Definition at line 279 of file cache_entry.h.

Referenced by clear(), and transcode().

◆ m_is_decoding

std::atomic_bool Cache_Entry::m_is_decoding

true while file is decoding

Definition at line 272 of file cache_entry.h.

Referenced by clear(), transcode(), transcode_finish(), transcode_until(), transcoder_new(), transcoder_read_frame(), and transcoder_thread().

◆ m_mutex

std::recursive_mutex Cache_Entry::m_mutex
protected

Access mutex.

Definition at line 264 of file cache_entry.h.

Referenced by lock(), and unlock().

◆ m_owner

Cache* Cache_Entry::m_owner
protected

Owner cache object.

Definition at line 263 of file cache_entry.h.

Referenced by delete_info(), read_info(), update_access(), and write_info().

◆ m_ref_count

std::atomic_int Cache_Entry::m_ref_count
protected

Reference counter.

Definition at line 266 of file cache_entry.h.

Referenced by closeio(), decode_timeout(), decr_refcount(), inc_refcount(), openio(), ref_count(), and suspend_timeout().

◆ m_restart_mutex

std::recursive_mutex Cache_Entry::m_restart_mutex

Mutex while thread is restarted.

Definition at line 274 of file cache_entry.h.

Referenced by transcoder_thread().

◆ m_seek_to_no

std::atomic_uint32_t Cache_Entry::m_seek_to_no

If not 0, seeks to specified frame.

Definition at line 281 of file cache_entry.h.

Referenced by transcode(), transcoder_read(), transcoder_read_frame(), and transcoder_thread().

◆ m_suspend_timeout

std::atomic_bool Cache_Entry::m_suspend_timeout

true to temporarly disable read_frame timeout

Definition at line 275 of file cache_entry.h.

Referenced by transcode(), and transcoder_read_frame().

◆ m_virtualfile

LPVIRTUALFILE Cache_Entry::m_virtualfile
protected

Underlying virtual file object.

Definition at line 268 of file cache_entry.h.

Referenced by destname(), filename(), virtname(), and virtualfile().


The documentation for this class was generated from the following files: