43#define CACHE_CHECK_BIT(mask, var)  ((mask) == (mask & (var)))   
   45#define CACHE_CLOSE_NOOPT   0x00000000                           
   46#define CACHE_CLOSE_FREE    0x00000001                           
   47#define CACHE_CLOSE_DELETE  (0x00000002 | CACHE_CLOSE_FREE)      
   49#define CACHE_FLAG_RO       0x00000001                           
   50#define CACHE_FLAG_RW       0x00000002                           
  144    bool                    init(
bool erase_cache);
 
  178    virtual size_t          bufsize() 
const override;
 
  192    virtual size_t          readio(
void *data, 
size_t size) 
override;
 
  203    size_t                  read_frame(std::vector<uint8_t> * data, uint32_t frame_no);
 
  208    virtual int             error() 
const override;
 
  212    virtual int64_t         
duration() 
const override;
 
  217    virtual size_t          size() 
const override;
 
  223    virtual size_t          size(uint32_t segment_no) 
const;
 
  228    virtual size_t          tell() 
const override;
 
  234    virtual size_t          tell(uint32_t segment_no) 
const;
 
  248    virtual int             seek(int64_t offset, 
int whence) 
override;
 
  263    virtual int             seek(int64_t offset, 
int whence, uint32_t segment_no);
 
  268    virtual bool            eof() 
const override;
 
  274    virtual bool            eof(uint32_t segment_no) 
const;
 
  278    virtual void            closeio() 
override;
 
  285    size_t                  writeio(
const uint8_t* data, 
size_t length);
 
  293    size_t                  write_frame(
const uint8_t* data, 
size_t length, uint32_t frame_no);
 
  327    bool                    copy(std::vector<uint8_t> * out_data, 
size_t offset, uint32_t segment_no = 0);
 
  336    bool                    copy(uint8_t* out_data, 
size_t offset, 
size_t bufsize, uint32_t segment_no = 0);
 
  342    const std::string &     
cachefile(uint32_t segment_no) 
const;
 
  381    bool                    open_file(uint32_t segment_no, uint32_t flags, 
size_t defaultsize = 0);
 
  388    bool                    close_file(uint32_t segment_no, uint32_t flags);
 
  447    bool                    map_file(
const std::string & 
filename, 
volatile int *fd, uint8_t **p, 
size_t *filesize, 
bool *isdefaultsize, 
size_t defaultsize, 
bool truncate) 
const;
 
  457    bool                    unmap_file(
const std::string & 
filename, 
volatile int *fd, uint8_t **p, 
size_t len, 
size_t *filesize) 
const;
 
#define CACHE_CLOSE_NOOPT
Dummy, do nothing special.
std::vector< CACHEINFO > m_ci
Cache info.
virtual int64_t duration() const override
Get the duration of the file, in AV_TIME_BASE fractional seconds.
static constexpr int PREALLOC_FACTOR
PREALLOC_FACTOR - Number of elements allocated on reallocate calls Number of elements allocated on re...
virtual bool eof() const override
Check if at end of file.
void increment_pos(size_t increment)
Increment buffer position.
LPCACHEINFO cacheinfo(uint32_t segment_no)
Get cache information.
uint8_t * write_prepare(size_t length)
Prepare for the writing operation.
bool release(int flags=CACHE_CLOSE_NOOPT)
Release cache buffer.
uint32_t m_cur_open
Number of open files.
virtual int openio(LPVIRTUALFILE virtualfile) override
Open a virtual file.
bool segment_exists(uint32_t segment_no)
Check if segment exists.
void finished_segment()
Complete the segment decoding.
virtual int seek(int64_t offset, int whence) override
Seek to position in file.
size_t writeio(const uint8_t *data, size_t length)
Write data to the current position in the buffer. The position pointer will be updated.
bool clear()
Clear (delete) buffer.
bool map_file(const std::string &filename, volatile int *fd, uint8_t **p, size_t *filesize, bool *isdefaultsize, size_t defaultsize, bool truncate) const
Map memory to a file.
virtual ~Buffer()
Free Buffer object.
bool unmap_file(const std::string &filename, volatile int *fd, uint8_t **p, size_t len, size_t *filesize) const
Unmap memory from the file.
virtual void closeio() override
Close buffer.
virtual VIRTUALTYPE type() const override
Get type of this virtual file.
bool init(bool erase_cache)
Initialise cache.
std::recursive_mutex m_mutex
Access mutex.
bool is_segment_finished(uint32_t segment_no) const
Return true if transcoding of the segment is finished.
static bool remove_file(const std::string &filename)
Remove (unlink) the file.
size_t write_frame(const uint8_t *data, size_t length, uint32_t frame_no)
Write image data for the frame number into the buffer.
CACHEINFO const  * LPCCACHEINFO
Pointer to const version of CACHEINFO.
const std::string & cachefile(uint32_t segment_no) const
Get cache filename.
virtual size_t readio(void *data, size_t size) override
Not implemented.
bool have_frame(uint32_t frame_no)
Check if we have the requested frame number. Works only when processing a frame set.
bool flush()
Flush buffer to disk.
static const std::string & make_cachefile_name(std::string *cachefile, const std::string &filename, const std::string &fileext, bool is_idx)
Make up a cache file name, including the full path.
bool reserve(size_t size)
Reserve memory without changing size to reduce re-allocations.
uint32_t current_segment_no()
Get the currently selected segment.
struct Buffer::_tagCACHEINFO CACHEINFO
Structure to hold current cache state.
bool reallocate(size_t newsize)
Reallocate the buffer to a new size.
virtual int error() const override
Get last error.
bool copy(std::vector< uint8_t > *out_data, size_t offset, uint32_t segment_no=0)
Copy buffered data into output buffer.
virtual size_t bufsize() const override
Size of this buffer.
LPCCACHEINFO const_cacheinfo(uint32_t segment_no) const
Get cache information.
uint32_t segment_count()
Get segment count.
struct Buffer::_tagCACHEINFO * LPCACHEINFO
Pointer version of CACHEINFO.
virtual size_t tell() const override
Get the value of the internal read position pointer.
LPCACHEINFO m_cur_ci
Convenience pointer to current write segment.
bool set_segment(uint32_t segment_no, size_t size)
Set the current segment.
bool remove_cachefile(uint32_t segment_no=0) const
Remove the cachefile.
Buffer()
Create Buffer object.
bool is_open()
Check if the cache file is open.
virtual size_t size() const override
Get the value of the internal buffer size pointer.
bool open_file(uint32_t segment_no, uint32_t flags, size_t defaultsize=0)
Open the cache file if not already open.
bool close_file(uint32_t segment_no, uint32_t flags)
If it hasn't already been done, close the cache file.
size_t buffer_watermark(uint32_t segment_no=0) const
Return the current watermark of the file while transcoding.
size_t read_frame(std::vector< uint8_t > *data, uint32_t frame_no)
Write image data for the frame number into the buffer.
LPVIRTUALFILE virtualfile()
Get virtual file object.
const std::string & filename() const
Get source filename.
VIRTUALTYPE
Virtual file types enum.
Structure to hold current cache state.
size_t m_buffer_write_size
Sum of bytes written to the buffer.
uint8_t * m_buffer
Pointer to buffer memory.
bool m_seg_finished
True if segment completely decoded.
volatile int m_fd_idx
File handle for index.
unsigned int m_buffer_writes
Total number of writes to the buffer.
size_t m_buffer_size_idx
Size of index buffer.
uint8_t * m_buffer_idx
Pointer to index memory.
size_t m_buffer_size
Current buffer size.
std::string m_cachefile
Cache file name.
uint32_t m_flags
CACHE_FLAG_* options.
volatile int m_fd
File handle for buffer.
size_t m_buffer_watermark
Number of bytes in buffer.
size_t m_buffer_pos
Read/write position.
std::string m_cachefile_idx
Index file name.
void reset()
Reset buffer pointers.