CAVAPA-GUI  30.5.2014
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
Public Member Functions | Static Public Member Functions | List of all members
cavapa_gui::Recorder Class Reference

The buffered recorder class creates the video file from the images. More...

#include <recorder.h>

Public Member Functions

 DISALLOW_COPY_AND_ASSIGN (Recorder)
 Copy and assign of the class is not allowed.
 
unsigned int countBuffered ()
 Counts the currently buffered images. More...
 
unsigned int getMissedFrames ()
 Returns the count of the missed frames. More...
 
unsigned int getRecordedFrames ()
 Returns the recorded frames. More...
 
bool isOpen ()
 Returns the initialization status of the recorder. More...
 
bool isTerminated ()
 Retrieves the recorder status. More...
 
bool open (const std::string &filename, int fourcc, double fps, cv::Size frameSize, bool isColor=true)
 Opens the video recorder. More...
 
RecorderStats push (const cv::Mat &image)
 Pushes the new image to the buffer. More...
 
bool repush ()
 Repushes the last image again to the buffer. More...
 
void stop ()
 Softly stops the recording. More...
 

Static Public Member Functions

static void detach (std::unique_ptr< Recorder > &&ptr)
 Detaches the recorder. More...
 

Detailed Description

The buffered recorder class creates the video file from the images.

This is basically just a wrapper around cv::VideoWriter so that there is a simple buffer that allows multithreading. The class should only be used for one video file recording and then deleted. Once the recorder is succesfully opened, it cannot be re-opened even after termination.

When the recorder is to be opened, it is provided with all necessary information for the video file creation. The images are added to the buffer with push(). Recorder will write the contents of the buffer to the video file with the initialized parameters, and will continue to do so until it is terminated. Recorder can be stopped with stop() in order to finish writing the buffer contents. This allows it to flush the buffer contents and close the file properly.

Method isTerminated() can be used to check when Recorder has finished flushing the buffer after stop() signal. If Recorder object is destroyed before termination is successful, it will also destroy the rest of the buffer contents, thus leading into lost video frames. The destruction of Recorder should not leave video files corrupted, as it tries to close the files properly.

Author
Petri Partanen
Remarks
All public methods are thread-safe.

Member Function Documentation

unsigned int cavapa_gui::Recorder::countBuffered ( )

Counts the currently buffered images.

Returns
The number of images in the buffer.
static void cavapa_gui::Recorder::detach ( std::unique_ptr< Recorder > &&  ptr)
inlinestatic

Detaches the recorder.

It adds the recorder to a cleanup list that holds unfinished records, and let's them flush their buffer peacefully. The recorders on this list are destroyed on flushDetached() call, unless they have not yet terminated.

Parameters
ptrThe recorder to be detached.
Remarks
Recorder should be stopped at this point already.
unsigned int cavapa_gui::Recorder::getMissedFrames ( )

Returns the count of the missed frames.

The missed frames tell the amount of the frames that have been lost due to file writing errors. Most likely the file has no longer been open when the frames were supposed to be written.

Returns
The missed frames.
Remarks
Untested. Not sure if OpenCV actually even fails when the file is no longer open.
unsigned int cavapa_gui::Recorder::getRecordedFrames ( )

Returns the recorded frames.

Returns
The succesfully recorded frames.
Remarks
The images currently in the buffer are not counted.
bool cavapa_gui::Recorder::isOpen ( )
inline

Returns the initialization status of the recorder.

Returns
True if the file writer was opened, false otherwise.
Remarks
This does NOT change if the file is closed!
bool cavapa_gui::Recorder::isTerminated ( )

Retrieves the recorder status.

Returns
True if the recorder has finished writing frames and can be killed without destroying any unwritten frames.
bool cavapa_gui::Recorder::open ( const std::string &  filename,
int  fourcc,
double  fps,
cv::Size  frameSize,
bool  isColor = true 
)

Opens the video recorder.

The parameters are the same as in cv::VideoWriter, and are passed directly to cv::VideoWriter::open.

Parameters
filenameThe name of the output video file.
fourccThe 4-character code of codec.
fpsThe framerate of the created video.
frameSizeThe size of the video frames.
isColorIf it is not false, the encoder will expect and encode color frames.
Returns
True if the file was opened successfully or false otherwise.
RecorderStats cavapa_gui::Recorder::push ( const cv::Mat &  image)

Pushes the new image to the buffer.

Parameters
imageThe new OpenCV image. All the images buffered must match in size, otherwise the video file gets broken.
Returns
The current statistics of the Recorder.
bool cavapa_gui::Recorder::repush ( )

Repushes the last image again to the buffer.

Returns
True if repushing was done or false otherwise.
Remarks
Does nothing if no image exists.
void cavapa_gui::Recorder::stop ( )

Softly stops the recording.

This allows the recorder to write the rest of the frames to the buffer. Recorder cannot be restarted after this. If the recorder is deleted before the buffer has finished writing, the frames will be lost forever. Use terminated() to see when the buffer has finished flushing.

Remarks
In order to leave Recorder to peacefully write rest of the frames, it should be detached().

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