20void DummyReader::init(
Fraction fps,
int width,
int height,
int sample_rate,
int channels,
float duration) {
22 info.has_audio =
false;
23 info.has_video =
true;
24 info.file_size =
static_cast<size_t>(width) * height *
sizeof(
int);
29 info.sample_rate = sample_rate;
30 info.channels = channels;
31 info.duration = duration;
33 info.pixel_ratio.num = 1;
34 info.pixel_ratio.den = 1;
39 Fraction size(
info.width *
info.pixel_ratio.num,
info.height *
info.pixel_ratio.den);
45 info.display_ratio.num = size.num;
46 info.display_ratio.den = size.den;
53 init(
Fraction(24,1), 1280, 768, 44100, 2, 30.0);
58 dummy_cache(NULL), last_cached_frame(NULL), image_frame(NULL), is_open(false) {
61 init(fps, width, height, sample_rate, channels, duration);
66 CacheBase* cache) : last_cached_frame(NULL), image_frame(NULL), is_open(false) {
69 init(fps, width, height, sample_rate, channels, duration);
85 image_frame = std::make_shared<Frame>(1,
info.width,
info.height,
"#000000",
info.sample_rate,
info.channels);
109 throw ReaderClosed(
"The ImageReader is closed. Call Open() before calling this method.",
"dummy");
111 int dummy_cache_count = 0;
113 dummy_cache_count = dummy_cache->Count();
116 if (dummy_cache_count == 0 && image_frame) {
118 const std::lock_guard<std::recursive_mutex> lock(
getFrameMutex);
121 image_frame->number = requested_frame;
122 last_cached_frame = image_frame;
125 }
else if (dummy_cache_count > 0) {
127 const std::lock_guard<std::recursive_mutex> lock(
getFrameMutex);
130 std::shared_ptr<openshot::Frame> f = dummy_cache->GetFrame(requested_frame);
133 last_cached_frame = f;
135 }
else if (last_cached_frame) {
137 return last_cached_frame;
140 throw InvalidFile(
"Requested frame not found. You can only access Frame numbers that exist in the Cache object.",
"dummy");
145 throw InvalidFile(
"No frame could be created from this type of file.",
"dummy");
160 root[
"type"] =
"DummyReader";
176 catch (
const std::exception& e)
179 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
Header file for DummyReader class.
Header file for all Exception classes.
Header file for Frame class.
All cache managers in libopenshot are based on this CacheBase class.
DummyReader()
Blank constructor for DummyReader, with default settings.
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
void SetJson(const std::string value) override
Load JSON string into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
std::string Json() const override
Generate JSON string of this object.
void Open() override
Open File - which is called by the constructor automatically.
void Close() override
Close File.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
This class represents a fraction.
float ToFloat()
Return this fraction as a float (i.e. 1/2 = 0.5).
Fraction Reciprocal() const
Return the reciprocal as a Fraction.
Exception for files that can not be found or opened.
Exception for invalid JSON.
openshot::ReaderInfo info
Information about the current media file.
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
std::recursive_mutex getFrameMutex
Mutex for multiple threads.
Exception when a reader is closed, and a frame is requested.
This namespace is the default namespace for all code in the openshot library.
const Json::Value stringToJson(const std::string value)