OpenShot Library | libopenshot  0.3.3
Public Member Functions | List of all members
openshot::DummyReader Class Reference

This class is used as a simple, dummy reader, which can be very useful when writing unit tests. It can return a single blank frame or it can return custom frame objects which were passed into the constructor with a Cache object. More...

#include <DummyReader.h>

Inheritance diagram for openshot::DummyReader:
[legend]
Collaboration diagram for openshot::DummyReader:
[legend]

Public Member Functions

void Close () override
 Close File. More...
 
 DummyReader ()
 Blank constructor for DummyReader, with default settings. More...
 
 DummyReader (openshot::Fraction fps, int width, int height, int sample_rate, int channels, float duration)
 Constructor for DummyReader. More...
 
 DummyReader (openshot::Fraction fps, int width, int height, int sample_rate, int channels, float duration, CacheBase *cache)
 Constructor for DummyReader which takes a frame cache object. More...
 
CacheMemoryGetCache () override
 Get the cache object used by this reader (always returns NULL for this reader) More...
 
std::shared_ptr< openshot::FrameGetFrame (int64_t requested_frame) override
 
bool IsOpen () override
 Determine if reader is open or closed. More...
 
std::string Json () const override
 Generate JSON string of this object. More...
 
Json::Value JsonValue () const override
 Generate Json::Value for this object. More...
 
std::string Name () override
 Return the type name of the class. More...
 
void Open () override
 Open File - which is called by the constructor automatically. More...
 
void SetJson (const std::string value) override
 Load JSON string into this object. More...
 
void SetJsonValue (const Json::Value root) override
 Load Json::Value into this object. More...
 
virtual ~DummyReader ()
 
- Public Member Functions inherited from openshot::ReaderBase
void DisplayInfo (std::ostream *out=&std::cout)
 Display file information in the standard output stream (stdout) More...
 
openshot::ClipBaseParentClip ()
 Parent clip object of this reader (which can be unparented and NULL) More...
 
void ParentClip (openshot::ClipBase *new_clip)
 Set parent clip object of this reader. More...
 
 ReaderBase ()
 Constructor for the base reader, where many things are initialized. More...
 
virtual ~ReaderBase ()=default
 

Additional Inherited Members

- Public Attributes inherited from openshot::ReaderBase
openshot::ReaderInfo info
 Information about the current media file. More...
 
- Protected Attributes inherited from openshot::ReaderBase
openshot::ClipBaseclip
 Pointer to the parent clip instance (if any) More...
 
std::recursive_mutex getFrameMutex
 Mutex for multiple threads. More...
 

Detailed Description

This class is used as a simple, dummy reader, which can be very useful when writing unit tests. It can return a single blank frame or it can return custom frame objects which were passed into the constructor with a Cache object.

A dummy reader can be created with any framerate or samplerate. This is useful in unit tests that need to test different framerates or samplerates.

Note
Timeline does buffering by requesting more frames than it strictly needs. Thus if you use this DummyReader with a custom cache in a Timeline, make sure it has enough frames. Specifically you need some frames after the last frame you plan to access through the Timeline.
// Create cache object to store fake Frame objects
CacheMemory cache;
// Now let's create some test frames
for (int64_t frame_number = 1; frame_number <= 30; frame_number++)
{
// Create blank frame (with specific frame #, samples, and channels)
// Sample count should be 44100 / 30 fps = 1470 samples per frame
int sample_count = 1470;
auto f = std::make_shared<openshot::Frame>(frame_number, sample_count, 2);
// Create test samples with incrementing value
float *audio_buffer = new float[sample_count];
for (int64_t sample_number = 0; sample_number < sample_count; sample_number++)
{
// Generate an incrementing audio sample value (just as an example)
audio_buffer[sample_number] = float(frame_number) + (float(sample_number) / float(sample_count));
}
// Add custom audio samples to Frame (bool replaceSamples, int destChannel, int destStartSample, const float* source,
// int numSamples, float gainToApplyToSource = 1.0f)
f->AddAudio(true, 0, 0, audio_buffer, sample_count, 1.0); // add channel 1
f->AddAudio(true, 1, 0, audio_buffer, sample_count, 1.0); // add channel 2
// Add test frame to cache
cache.Add(f);
}
// Create a reader (Fraction fps, int width, int height, int sample_rate, int channels, float duration, CacheBase* cache)
openshot::DummyReader r(openshot::Fraction(30, 1), 1920, 1080, 44100, 2, 30.0, &cache);
r.Open(); // Open the reader
// Now let's verify our DummyReader works
std::shared_ptr<openshot::Frame> f = r.GetFrame(1);
// r.GetFrame(1)->GetAudioSamples(0)[1] should equal 1.00068033 based on our above calculations
// Clean up
r.Close();
cache.Clear()

Definition at line 85 of file DummyReader.h.

Constructor & Destructor Documentation

◆ DummyReader() [1/3]

DummyReader::DummyReader ( )

Blank constructor for DummyReader, with default settings.

Definition at line 50 of file DummyReader.cpp.

◆ DummyReader() [2/3]

DummyReader::DummyReader ( openshot::Fraction  fps,
int  width,
int  height,
int  sample_rate,
int  channels,
float  duration 
)

Constructor for DummyReader.

Definition at line 57 of file DummyReader.cpp.

◆ DummyReader() [3/3]

DummyReader::DummyReader ( openshot::Fraction  fps,
int  width,
int  height,
int  sample_rate,
int  channels,
float  duration,
CacheBase cache 
)

Constructor for DummyReader which takes a frame cache object.

Definition at line 65 of file DummyReader.cpp.

◆ ~DummyReader()

DummyReader::~DummyReader ( )
virtual

Definition at line 75 of file DummyReader.cpp.

Member Function Documentation

◆ Close()

void DummyReader::Close ( )
overridevirtual

Close File.

Implements openshot::ReaderBase.

Definition at line 93 of file DummyReader.cpp.

◆ GetCache()

CacheMemory* openshot::DummyReader::GetCache ( )
inlineoverridevirtual

Get the cache object used by this reader (always returns NULL for this reader)

Implements openshot::ReaderBase.

Definition at line 113 of file DummyReader.h.

◆ GetFrame()

std::shared_ptr< Frame > DummyReader::GetFrame ( int64_t  requested_frame)
overridevirtual

Get an openshot::Frame object for a specific frame number of this reader. All numbers return the same Frame, since they all share the same image data.

Returns
The requested frame (containing the image)
Parameters
requested_frameThe frame number that is requested.

Implements openshot::ReaderBase.

Definition at line 105 of file DummyReader.cpp.

◆ IsOpen()

bool openshot::DummyReader::IsOpen ( )
inlineoverridevirtual

Determine if reader is open or closed.

Implements openshot::ReaderBase.

Definition at line 123 of file DummyReader.h.

◆ Json()

std::string DummyReader::Json ( ) const
overridevirtual

Generate JSON string of this object.

Implements openshot::ReaderBase.

Definition at line 149 of file DummyReader.cpp.

◆ JsonValue()

Json::Value DummyReader::JsonValue ( ) const
overridevirtual

Generate Json::Value for this object.

Implements openshot::ReaderBase.

Definition at line 156 of file DummyReader.cpp.

Referenced by Json().

◆ Name()

std::string openshot::DummyReader::Name ( )
inlineoverridevirtual

Return the type name of the class.

Implements openshot::ReaderBase.

Definition at line 126 of file DummyReader.h.

◆ Open()

void DummyReader::Open ( )
overridevirtual

Open File - which is called by the constructor automatically.

Implements openshot::ReaderBase.

Definition at line 79 of file DummyReader.cpp.

◆ SetJson()

void DummyReader::SetJson ( const std::string  value)
overridevirtual

Load JSON string into this object.

Implements openshot::ReaderBase.

Definition at line 167 of file DummyReader.cpp.

◆ SetJsonValue()

void DummyReader::SetJsonValue ( const Json::Value  root)
overridevirtual

Load Json::Value into this object.

Implements openshot::ReaderBase.

Definition at line 184 of file DummyReader.cpp.

Referenced by SetJson().


The documentation for this class was generated from the following files:
openshot::Fraction
This class represents a fraction.
Definition: Fraction.h:30
openshot::DummyReader
This class is used as a simple, dummy reader, which can be very useful when writing unit tests....
Definition: DummyReader.h:85