Loading...
Searching...
No Matches
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:

## Public Member Functions

void | Close () override
| Close File.
| DummyReader ()
| Blank constructor for DummyReader, with default settings.
| DummyReader (openshot::Fraction fps, int width, int height, int sample_rate, int channels, float duration)
| Constructor for 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.
CacheMemory * | GetCache () override
| Get the cache object used by this reader (always returns NULL for this reader).
std::shared_ptr< openshot::Frame > | GetFrame (int64_t requested_frame) override
bool | IsOpen () override
| Determine if reader is open or closed.
std::string | Json () const override
| Generate JSON string of this object.
Json::Value | JsonValue () const override
| Generate Json::Value for this object.
std::string | Name () override
| Return the type name of the class.
void | Open () override
| Open File - which is called by the constructor automatically.
void | SetJson (const std::string value) override
| Load JSON string into this object.
void | SetJsonValue (const Json::Value root) override
| Load Json::Value into this object.
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).
openshot::ClipBase * | ParentClip ()
| Parent clip object of this reader (which can be unparented and NULL).
void | ParentClip (openshot::ClipBase *new_clip)
| Set parent clip object of this reader.
| ReaderBase ()
| Constructor for the base reader, where many things are initialized.
virtual | ~ReaderBase ()=default

## Additional Inherited Members

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

## 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()
openshot::CacheMemory
This class is a memory-based cache manager for Frame objects.
Definition CacheMemory.h:29
openshot::CacheMemory::Add
void Add(std::shared_ptr< openshot::Frame > frame)
Add a Frame to the cache.
Definition CacheMemory.cpp:47
openshot::CacheMemory::Clear
void Clear()
Clear the cache of all frames.
Definition CacheMemory.cpp:238
openshot::DummyReader
This class is used as a simple, dummy reader, which can be very useful when writing unit tests....
Definition DummyReader.h:86
openshot::Fraction
This class represents a fraction.
Definition Fraction.h:30

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 | ( |  | ) |

override virtual

Close File.

Implements openshot::ReaderBase.

Definition at line 93 of file DummyReader.cpp.

## GetCache()

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

inline override virtual

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 | ) |

override virtual

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_frame | The frame number that is requested.

Implements openshot::ReaderBase.

Definition at line 105 of file DummyReader.cpp.

## IsOpen()

bool openshot::DummyReader::IsOpen | ( |  | ) |

inline override virtual

Determine if reader is open or closed.

Implements openshot::ReaderBase.

Definition at line 123 of file DummyReader.h.

## Json()

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

override virtual

Generate JSON string of this object.

Implements openshot::ReaderBase.

Definition at line 149 of file DummyReader.cpp.

## JsonValue()

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

override virtual

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 | ( |  | ) |

inline override virtual

Return the type name of the class.

Implements openshot::ReaderBase.

Definition at line 126 of file DummyReader.h.

## Open()

void DummyReader::Open | ( |  | ) |

override virtual

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 | ) |

override virtual

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 | ) |

override virtual

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:

- DummyReader.h
- DummyReader.cpp