Loading...
Searching...
No Matches
ReaderBase.h
Go to the documentation of this file.
// Copyright (c) 2008-2019 OpenShot Studios, LLC
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef OPENSHOT_READER_BASE_H
#define OPENSHOT_READER_BASE_H
#include <map>
#include <memory>
#include <mutex>
#include <iostream>
#include <string>
#include <vector>
#include "ChannelLayouts.h"
#include "Fraction.h"
#include "Json.h"
namespace openshot
{
class CacheBase;
class ClipBase;
class Frame;
struct ReaderInfo
{
bool has_video;
bool has_audio;
bool has_single_image;
float duration;
int64_t file_size;
int height;
int width;
int pixel_format;
openshot::Fraction fps;
int video_bit_rate;
openshot::Fraction pixel_ratio;
openshot::Fraction display_ratio;
std::string vcodec;
int64_t video_length;
int video_stream_index;
openshot::Fraction video_timebase;
bool interlaced_frame; // Are the contents of this frame interlaced
bool top_field_first; // Which interlaced field should be displayed first
std::string acodec;
int audio_bit_rate;
int sample_rate;
int channels;
openshot::ChannelLayout channel_layout;
int audio_stream_index;
openshot::Fraction audio_timebase;
std::map<std::string, std::string> metadata;
};
class ReaderBase
{
protected:
std::recursive_mutex getFrameMutex;
openshot::ClipBase* clip;
public:
ReaderBase();
openshot::ReaderInfo info;
openshot::ClipBase* ParentClip();
void ParentClip(openshot::ClipBase* new_clip);
virtual void Close() = 0;
void DisplayInfo(std::ostream* out=&std::cout);
virtual openshot::CacheBase* GetCache() = 0;
virtual std::shared_ptr<openshot::Frame> GetFrame(int64_t number) = 0;
virtual bool IsOpen() = 0;
virtual std::string Name() = 0;
// Get and Set JSON methods
virtual std::string Json() const = 0;
virtual void SetJson(const std::string value) = 0;
virtual Json::Value JsonValue() const = 0;
virtual void SetJsonValue(const Json::Value root) = 0;
virtual void Open() = 0;
virtual ~ReaderBase() = default;
};
}
#endif
ChannelLayouts.h
Header file for ChannelLayout class.
Fraction.h
Header file for Fraction class.
Json.h
Header file for JSON class.
openshot::CacheBase
All cache managers in libopenshot are based on this CacheBase class.
Definition CacheBase.h:35
openshot::ClipBase
This abstract class is the base class, used by all clips in libopenshot.
Definition ClipBase.h:32
openshot::Fraction
This class represents a fraction.
Definition Fraction.h:30
openshot::Frame
This class represents a single frame of video (i.e. image & audio data).
Definition Frame.h:89
openshot::ReaderBase::IsOpen
virtual bool IsOpen()=0
Determine if reader is open or closed.
openshot::ReaderBase::Name
virtual std::string Name()=0
Return the type name of the class.
openshot::ReaderBase::info
openshot::ReaderInfo info
Information about the current media file.
Definition ReaderBase.h:88
openshot::ReaderBase::Json
virtual std::string Json() const =0
Generate JSON string of this object.
openshot::ReaderBase::~ReaderBase
virtual ~ReaderBase()=default
openshot::ReaderBase::SetJsonValue
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition ReaderBase.cpp:157
openshot::ReaderBase::JsonValue
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Definition ReaderBase.cpp:106
openshot::ReaderBase::getFrameMutex
std::recursive_mutex getFrameMutex
Mutex for multiple threads.
Definition ReaderBase.h:79
openshot::ReaderBase::SetJson
virtual void SetJson(const std::string value)=0
Load JSON string into this object.
openshot::ReaderBase::DisplayInfo
void DisplayInfo(std::ostream *out=&std::cout)
Display file information in the standard output stream (stdout).
Definition ReaderBase.cpp:60
openshot::ReaderBase::Open
virtual void Open()=0
Open the reader (and start consuming resources, such as images or video files).
openshot::ReaderBase::GetFrame
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
openshot::ReaderBase::GetCache
virtual openshot::CacheBase * GetCache()=0
Get the cache object used by this reader (note: not all readers use cache).
openshot::ReaderBase::clip
openshot::ClipBase * clip
Pointer to the parent clip instance (if any).
Definition ReaderBase.h:80
openshot::ReaderBase::ParentClip
openshot::ClipBase * ParentClip()
Parent clip object of this reader (which can be unparented and NULL).
Definition ReaderBase.cpp:240
openshot::ReaderBase::ReaderBase
ReaderBase()
Constructor for the base reader, where many things are initialized.
Definition ReaderBase.cpp:26
openshot::ReaderBase::Close
virtual void Close()=0
Close the reader (and any resources it was consuming).
openshot
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
openshot::ChannelLayout
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround,...
Definition ChannelLayouts.h:29
openshot::ReaderInfo
This struct contains info about a media file, such as height, width, frames per second,...
Definition ReaderBase.h:39
openshot::ReaderInfo::top_field_first
bool top_field_first
Definition ReaderBase.h:57
openshot::ReaderInfo::audio_bit_rate
int audio_bit_rate
The bit rate of the audio stream (in bytes).
Definition ReaderBase.h:59
openshot::ReaderInfo::video_bit_rate
int video_bit_rate
The bit rate of the video stream (in bytes).
Definition ReaderBase.h:49
openshot::ReaderInfo::has_single_image
bool has_single_image
Determines if this file only contains a single image.
Definition ReaderBase.h:42
openshot::ReaderInfo::interlaced_frame
bool interlaced_frame
Definition ReaderBase.h:56
openshot::ReaderInfo::duration
float duration
Length of time (in seconds).
Definition ReaderBase.h:43
openshot::ReaderInfo::audio_timebase
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
Definition ReaderBase.h:64
openshot::ReaderInfo::width
int width
The width of the video (in pixesl).
Definition ReaderBase.h:46
openshot::ReaderInfo::channels
int channels
The number of audio channels used in the audio stream.
Definition ReaderBase.h:61
openshot::ReaderInfo::fps
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps).
Definition ReaderBase.h:48
openshot::ReaderInfo::display_ratio
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3).
Definition ReaderBase.h:51
openshot::ReaderInfo::height
int height
The height of the video (in pixels).
Definition ReaderBase.h:45
openshot::ReaderInfo::pixel_format
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...).
Definition ReaderBase.h:47
openshot::ReaderInfo::video_length
int64_t video_length
The number of frames in the video stream.
Definition ReaderBase.h:53
openshot::ReaderInfo::acodec
std::string acodec
The name of the audio codec used to encode / decode the video stream.
Definition ReaderBase.h:58
openshot::ReaderInfo::metadata
std::map< std::string, std::string > metadata
An optional map/dictionary of metadata for this reader.
Definition ReaderBase.h:65
openshot::ReaderInfo::vcodec
std::string vcodec
The name of the video codec used to encode / decode the video stream.
Definition ReaderBase.h:52
openshot::ReaderInfo::pixel_ratio
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square).
Definition ReaderBase.h:50
openshot::ReaderInfo::channel_layout
openshot::ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...).
Definition ReaderBase.h:62
openshot::ReaderInfo::has_video
bool has_video
Determines if this file has a video stream.
Definition ReaderBase.h:40
openshot::ReaderInfo::has_audio
bool has_audio
Determines if this file has an audio stream.
Definition ReaderBase.h:41
openshot::ReaderInfo::video_timebase
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Definition ReaderBase.h:55
openshot::ReaderInfo::video_stream_index
int video_stream_index
The index of the video stream.
Definition ReaderBase.h:54
openshot::ReaderInfo::sample_rate
int sample_rate
The number of audio samples per second (44100 is a common sample rate).
Definition ReaderBase.h:60
openshot::ReaderInfo::audio_stream_index
int audio_stream_index
The index of the audio stream.
Definition ReaderBase.h:63
openshot::ReaderInfo::file_size
int64_t file_size
Size of file (in bytes).
Definition ReaderBase.h:44