Valkka  1.6.1
OpenSource Video Management
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | List of all members
ValkkaFS Class Reference

Book-keeping for ValkkaFS. More...

#include <valkkafs.h>

Inheritance diagram for ValkkaFS:
Inheritance graph
[legend]

Public Member Functions

 ValkkaFS (const char *device_file, const char *block_file, std::size_t blocksize, std::size_t n_blocks, bool init=false)
 Default Constructor. More...
 
void setVal (std::size_t i, std::size_t j, long int val)
 set tab's value at block i, row j
 
long int getVal (std::size_t i, std::size_t j)
 
std::size_t getBlockSeek (std::size_t n_block)
 
std::size_t getCurrentBlockSeek ()
 
const std::size_t getBlockSize ()
 
std::size_t get_n_blocks ()
 
std::size_t get_n_cols ()
 
void dumpTable_ ()
 dump blocktable to disk. More...
 
void updateDumpTable_ (std::size_t n_block)
 dump single row of bloctable to disk. More...
 
void dumpTable ()
 dump blocktable to disk
 
void readTable ()
 read blocktable from disk
 
std::string getDevice ()
 returns device filename
 
std::size_t getDeviceSize ()
 returns device file size
 
void clearDevice (bool writethrough=false, bool verbose=false)
 writes zero bytes to the device
 
void clearTable ()
 clears the blocktable and writes it to the disk
 
std::size_t maxFrameSize ()
 returns maximum allowed frame size in bytes
 
void reportTable (std::size_t from=0, std::size_t to=0, bool show_all=false)
 print blocktable
 
void updateTable (bool disk_write=false)
 Tell ValkkaFS to update the blocktable, even if the block hasn't finished Typically used by an external manager that needs up-to-date information about the max timestamp in the block.
 
void writeBlock (bool pycall=true, bool use_gil=true)
 Used by a writer class to inform that a new block has been written. More...
 
void markFrame (long int mstimestamp)
 Used by a writer class to inform that a non-key frame has been written.
 
virtual void markKeyFrame (long int mstimestamp)
 Used by a writer class to inform that a key frame has been written.
 
void setCurrentBlock (std::size_t n_block)
 Set block number that's being written.
 
void setBlockCallback (PyObject *pobj)
 Set a python callable that's being triggered when a new block is written.
 
void setArrayCall (PyObject *pyobj)
 Copy blocktable to a given numpy array. More...
 

Protected Member Functions

std::size_t ind (std::size_t i, std::size_t j)
 first index: block number (row), second index: column
 

Protected Attributes

std::string device_file
 
std::string block_file
 
std::size_t blocksize
 
std::size_t n_blocks
 
bool init
 Clear the blocktable or not even if it exists.
 
std::size_t device_size
 
std::vector< long int > tab
 Blocktable.
 
std::fstream os
 Write handle to blocktable file.
 
std::mutex mutex
 
long int col_0
 Current column 0 value (max keyframe timestamp)
 
long int col_1
 Current column 1 value (max anyframe timestamp)
 
long int col_0_lu
 col_0 at previous blocktable update
 
long int col_1_lu
 col_1 at previous blocktable update
 
std::size_t current_row
 Row number (block) that's being written.
 
std::size_t prev_row
 Previous row number (block)
 
PyObject * pyfunc
 A python callback that's triggered when the blocktable should be read again.
 

Static Protected Attributes

static const std::size_t n_cols = 2
 

Private Member Functions

void callPyFunc (std::string msg, bool use_gil=true)
 

Detailed Description

Book-keeping for ValkkaFS.

Parameters
device_fileFile where payload is written. Can be /dev/sdb etc., or just a plain file with some space reserved
block_fileBook-keeping of the blocks in the device file
blocksizeSize of a single block in bytes
n_blocksSize of the device (or the part we want to use) in bytes
initClear the block_file even if it exists

Actual reading and writing of frames are done by other classes (ValkkaFSWriterThread and ValkkaFSReaderThread)

When reading frames, they are passed between processes typically like this:

ValkkaFSReaderThread => CacheStream => Decoder

Constructor & Destructor Documentation

◆ ValkkaFS()

ValkkaFS::ValkkaFS ( const char *  device_file,
const char *  block_file,
std::size_t  blocksize,
std::size_t  n_blocks,
bool  init = false 
)

Default Constructor.

Parameters
device_filewhere the payload is written (a file or a disk device)
block_filewhere the filesystem (block) information is written. A dump of blocktable
blocksizesize of a block
n_blocksnumber of blocks
inittrue = init and dump blocktable to disk. false = try to read blocktable from disk (default)

ValkkaFS is designed for a case when several streams are dumped into the same file/blockdevice. However, this idea has been abandoned for the moment (although cool idea, there are several complications with it) and we have opted to have a single stream per file/blockdevice. That (more conventional) idea is implemented in ValkkaFS2. The only different is how the keyframes are marked into the blocktable.

Member Function Documentation

◆ dumpTable_()

void ValkkaFS::dumpTable_ ( )

dump blocktable to disk.

Not thread safe.

◆ setArrayCall()

void ValkkaFS::setArrayCall ( PyObject *  pyobj)

Copy blocktable to a given numpy array.

Parameters
numpyarray

The array must be created on the python side with:

a = numpy.zeros((v.get_n_blocks(), v.get_n_cols()),dtype=numpy.int_)

◆ updateDumpTable_()

void ValkkaFS::updateDumpTable_ ( std::size_t  n_block)

dump single row of bloctable to disk.

Not thread safe.

◆ writeBlock()

void ValkkaFS::writeBlock ( bool  pycall = true,
bool  use_gil = true 
)

Used by a writer class to inform that a new block has been written.

Parameters
pycall: Use the provided python callback function or not? default = true
use_gil: Acquire Python GIL or not? should be true, when evoked "autonomously" by this thread and false, when evoked from python. default = true

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