FFmpegfs Fuse Multi Media Filesystem 2.16
cache_entry.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017-2024 by Norbert Schlia (nschlia@oblivion-software.de)
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 3 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 * On Debian systems, the complete text of the GNU General Public License
19 * Version 3 can be found in `/usr/share/common-licenses/GPL-3'.
20 */
21
32#ifndef CACHE_ENTRY_H
33#define CACHE_ENTRY_H
34
35#pragma once
36
37#include "cache.h"
38
39#include "id3v1tag.h"
40
41#include <atomic>
42
43class Buffer;
44
49{
50private:
64 virtual ~Cache_Entry();
65
66public:
72 Cache_Entry & operator= (Cache_Entry const & other) = delete;
73
85 bool destroy();
86
92 bool openio(bool create_cache = true);
97 bool flush();
102 void clear(bool fetch_file_time = true);
110 size_t size() const;
115 uint32_t video_frame_count() const;
120 time_t age() const;
125 time_t last_access() const;
133 bool expired() const;
138 bool suspend_timeout() const;
143 bool decode_timeout() const;
148 const char * filename() const;
153 const char * destname() const;
158 const char * virtname() const;
164 bool update_access(bool update_database = false);
168 void lock();
172 void unlock();
177 int ref_count() const;
182 int inc_refcount();
187 int decr_refcount();
188
192 bool outdated() const;
193
199
205 bool closeio(int flags);
209 void update_read_count();
217 unsigned int read_count() const;
218
223 bool is_finished() const;
228 bool is_finished_incomplete() const;
233 bool is_finished_success() const;
238 bool is_finished_error() const;
239
240protected:
245 void close_buffer(int flags);
250 bool read_info();
255 bool write_info();
260 bool delete_info();
261
262protected:
264 std::recursive_mutex m_mutex;
266 std::atomic_int m_ref_count;
270public:
271 std::unique_ptr<Buffer> m_buffer;
272 std::atomic_bool m_is_decoding;
273 std::recursive_mutex m_active_mutex;
274 std::recursive_mutex m_restart_mutex;
275 std::atomic_bool m_suspend_timeout;
281 std::atomic_uint32_t m_seek_to_no;
282};
283
284#endif // CACHE_ENTRY_H
Data cache management.
The Buffer class.
Definition: buffer.h:56
The Cache_Entry class.
Definition: cache_entry.h:49
std::recursive_mutex m_restart_mutex
Mutex while thread is restarted.
Definition: cache_entry.h:274
size_t size() const
Return size of output file, as computed by encoder.
Definition: cache_entry.cc:260
CACHE_INFO m_cache_info
Info about cached object.
Definition: cache_entry.h:277
bool update_access(bool update_database=false)
Update last access time.
Definition: cache_entry.cc:146
bool is_finished_error() const
Get if cache has been finished and with an error.
Definition: cache_entry.cc:450
static Cache_Entry * create(Cache *owner, LPVIRTUALFILE virtualfile)
Create a new Cache_Entry object.
Definition: cache_entry.cc:74
std::atomic_bool m_suspend_timeout
true to temporarly disable read_frame timeout
Definition: cache_entry.h:275
time_t age() const
Get the age of the cache entry.
Definition: cache_entry.cc:286
bool is_finished() const
Get if cache has been finished.
Definition: cache_entry.cc:435
std::recursive_mutex m_mutex
Access mutex.
Definition: cache_entry.h:264
bool suspend_timeout() const
Check for decode suspend timeout.
Definition: cache_entry.cc:301
Cache * m_owner
Owner cache object.
Definition: cache_entry.h:263
int ref_count() const
Get the current reference counter.
Definition: cache_entry.cc:336
void lock()
Lock the access mutex.
Definition: cache_entry.cc:326
std::atomic_bool m_is_decoding
true while file is decoding
Definition: cache_entry.h:272
void close_buffer(int flags)
Close buffer object.
Definition: cache_entry.cc:206
const char * virtname() const
Return virtual filename. Same as destination filename, but with virtual (mount) path....
Definition: cache_entry.cc:321
LPVIRTUALFILE m_virtualfile
Underlying virtual file object.
Definition: cache_entry.h:268
void clear(bool fetch_file_time=true)
Clear the cache entry.
Definition: cache_entry.cc:85
const char * destname() const
Return destination filename.
Definition: cache_entry.cc:316
LPVIRTUALFILE virtualfile()
Get the underlying VIRTUALFILE object.
Definition: cache_entry.cc:420
bool write_info()
Write cache info.
Definition: cache_entry.cc:136
bool destroy()
Destroy this Cache_Entry object.
Definition: cache_entry.cc:79
bool openio(bool create_cache=true)
Open the cache file.
Definition: cache_entry.cc:160
Cache_Entry(Cache *owner, LPVIRTUALFILE virtualfile)
Create Cache_Entry object.
Definition: cache_entry.cc:39
void update_read_count()
Update read counter.
Definition: cache_entry.cc:425
std::atomic_int m_ref_count
Reference counter.
Definition: cache_entry.h:266
const char * filename() const
Return source filename.
Definition: cache_entry.cc:311
int decr_refcount()
Decrement the current reference counter.
Definition: cache_entry.cc:346
time_t last_access() const
Get last access time.
Definition: cache_entry.cc:291
std::recursive_mutex m_active_mutex
Mutex while thread is active.
Definition: cache_entry.h:273
ID3v1 m_id3v1
ID3v1 structure which is used to send to clients.
Definition: cache_entry.h:279
uint32_t video_frame_count() const
Get the video frame count.
Definition: cache_entry.cc:281
bool closeio(int flags)
Close the cache entry.
Definition: cache_entry.cc:217
unsigned int read_count() const
Get read counter.
Definition: cache_entry.cc:430
int inc_refcount()
Increment the current reference counter.
Definition: cache_entry.cc:341
bool flush()
Flush current memory cache to disk.
Definition: cache_entry.cc:246
bool decode_timeout() const
Check for decode timeout.
Definition: cache_entry.cc:306
void unlock()
Unlock the access mutex.
Definition: cache_entry.cc:331
bool is_finished_incomplete() const
Get if cache has been finished, but not completely filled.
Definition: cache_entry.cc:440
bool is_finished_success() const
Get if cache has been finished and filled successfully.
Definition: cache_entry.cc:445
bool outdated() const
Check if cache entry needs to be recoded.
Definition: cache_entry.cc:351
std::atomic_uint32_t m_seek_to_no
If not 0, seeks to specified frame.
Definition: cache_entry.h:281
std::unique_ptr< Buffer > m_buffer
Buffer object.
Definition: cache_entry.h:271
Cache_Entry & operator=(Cache_Entry const &other)=delete
operator = declared deleted, should use create to get this object to maintain reference count.
bool delete_info()
Delete cache info.
Definition: cache_entry.cc:141
virtual ~Cache_Entry()
Destroy Cache_Entry object.
Definition: cache_entry.cc:65
bool read_info()
Read cache info.
Definition: cache_entry.cc:131
bool expired() const
Check if cache entry expired.
Definition: cache_entry.cc:296
Cache_Entry(Cache_Entry &)=delete
Copy constructor declared deleted, should use create to get this object to maintain reference count.
The Cache class.
Definition: cache.h:105
ID3v1 tag structure
Cache information block.
Definition: cache.h:71
ID3 version 1 tag
Definition: id3v1tag.h:42
Virtual file definition.
Definition: fileio.h:123