ReaderBase.h
Go to the documentation of this file.
/**
* @file
* @brief Header file for ReaderBase class
* @author Jonathan Thomas <jonathan@openshot.org>
*
* @ref License
*/
/* LICENSE
*
* Copyright (c) 2008-2019 OpenShot Studios, LLC
* <http://www.openshotstudios.com/>. This file is part of
* OpenShot Library (libopenshot), an open-source project dedicated to
* delivering high quality video editing and animation solutions to the
* world. For more information visit <http://www.openshot.org/>.
*
* OpenShot Library (libopenshot) is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* OpenShot Library (libopenshot) is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPENSHOT_READER_BASE_H
#define OPENSHOT_READER_BASE_H
#include <iostream>
#include <iomanip>
#include <memory>
#include <cstdlib>
#include <sstream>
#include "CacheMemory.h"
#include "ChannelLayouts.h"
#include "ClipBase.h"
#include "Fraction.h"
#include "Frame.h"
#include "Json.h"
#include "ZmqLogger.h"
#include <QtCore/qstring.h>
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QPixmap>
namespace openshot
{
/**
* @brief This struct contains info about a media file, such as height, width, frames per second, etc...
*
* Each derived class of ReaderBase is responsible for updating this struct to reflect accurate information
* about the streams.
*/
struct ReaderInfo
{
bool has_video; ///< Determines if this file has a video stream
bool has_audio; ///< Determines if this file has an audio stream
bool has_single_image; ///< Determines if this file only contains a single image
float duration; ///< Length of time (in seconds)
int64_t file_size; ///< Size of file (in bytes)
int height; ///< The height of the video (in pixels)
int width; ///< The width of the video (in pixesl)
int pixel_format; ///< The pixel format (i.e. YUV420P, RGB24, etc...)
openshot::Fraction fps; ///< Frames per second, as a fraction (i.e. 24/1 = 24 fps)
int video_bit_rate; ///< The bit rate of the video stream (in bytes)
openshot::Fraction pixel_ratio; ///< The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
openshot::Fraction display_ratio; ///< The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
std::string vcodec; ///< The name of the video codec used to encode / decode the video stream
int64_t video_length; ///< The number of frames in the video stream
int video_stream_index; ///< The index of the video stream
openshot::Fraction video_timebase; ///< The video timebase determines how long each frame stays on the screen
bool interlaced_frame; // Are the contents of this frame interlaced
bool top_field_first; // Which interlaced field should be displayed first
std::string acodec; ///< The name of the audio codec used to encode / decode the video stream
int audio_bit_rate; ///< The bit rate of the audio stream (in bytes)
int sample_rate; ///< The number of audio samples per second (44100 is a common sample rate)
int channels; ///< The number of audio channels used in the audio stream
openshot::ChannelLayout channel_layout; ///< The channel layout (mono, stereo, 5 point surround, etc...)
int audio_stream_index; ///< The index of the audio stream
openshot::Fraction audio_timebase; ///< The audio timebase determines how long each audio packet should be played
std::map<std::string, std::string> metadata; ///< An optional map/dictionary of metadata for this reader
};
/**
* @brief This abstract class is the base class, used by all readers in libopenshot.
*
* Readers are types of classes that read video, audio, and image files, and
* return openshot::Frame objects. The only requirements for a 'reader', are to
* derive from this base class, implement the GetFrame method, and populate ReaderInfo.
*/
class ReaderBase
{
protected:
/// Section lock for multiple threads
juce::CriticalSection getFrameCriticalSection;
juce::CriticalSection processingCriticalSection;
openshot::ClipBase* parent;
public:
/// Constructor for the base reader, where many things are initialized.
ReaderBase();
/// Information about the current media file
openshot::ReaderInfo info;
/// Parent clip object of this reader (which can be unparented and NULL)
openshot::ClipBase* GetClip();
/// Set parent clip object of this reader
void SetClip(openshot::ClipBase* clip);
/// Close the reader (and any resources it was consuming)
virtual void Close() = 0;
/// Display file information in the standard output stream (stdout)
void DisplayInfo();
/// Get the cache object used by this reader (note: not all readers use cache)
virtual openshot::CacheBase* GetCache() = 0;
/// This method is required for all derived classes of ReaderBase, and returns the
/// openshot::Frame object, which contains the image and audio information for that
/// frame of video.
///
/// @returns The requested frame of video
/// @param[in] number The frame number that is requested.
virtual std::shared_ptr<openshot::Frame> GetFrame(int64_t number) = 0;
/// Determine if reader is open or closed
virtual bool IsOpen() = 0;
/// Return the type name of the class
virtual std::string Name() = 0;
/// Get and Set JSON methods
virtual std::string Json() const = 0; ///< Generate JSON string of this object
virtual void SetJson(const std::string value) = 0; ///< Load JSON string into this object
virtual Json::Value JsonValue() const = 0; ///< Generate Json::Value for this object
virtual void SetJsonValue(const Json::Value root) = 0; ///< Load Json::Value into this object
/// Open the reader (and start consuming resources, such as images or video files)
virtual void Open() = 0;
virtual ~ReaderBase() = default;
};
}
#endif
CacheMemory.h
Header file for CacheMemory class.
ChannelLayouts.h
Header file for ChannelLayout class.
ClipBase.h
Header file for ClipBase class.
Fraction.h
Header file for Fraction class.
Frame.h
Header file for Frame class.
Json.h
Header file for JSON class.
ZmqLogger.h
Header file for ZeroMQ-based Logger class.
openshot::CacheBase
All cache managers in libopenshot are based on this CacheBase class.
Definition: CacheBase.h:50
openshot::ClipBase
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:49
openshot::Fraction
This class represents a fraction.
Definition: Fraction.h:45
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:98
openshot::ReaderBase::parent
openshot::ClipBase * parent
Definition: ReaderBase.h:103
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::getFrameCriticalSection
juce::CriticalSection getFrameCriticalSection
Section lock for multiple threads.
Definition: ReaderBase.h:101
openshot::ReaderBase::info
openshot::ReaderInfo info
Information about the current media file.
Definition: ReaderBase.h:111
openshot::ReaderBase::processingCriticalSection
juce::CriticalSection processingCriticalSection
Definition: ReaderBase.h:102
openshot::ReaderBase::Json
virtual std::string Json() const =0
Get and Set JSON methods.
openshot::ReaderBase::~ReaderBase
virtual ~ReaderBase()=default
openshot::ReaderBase::GetCache
virtual openshot::CacheBase * GetCache()=0
Get the cache object used by this reader (note: not all readers use cache)
openshot::ReaderBase::GetClip
openshot::ClipBase * GetClip()
Parent clip object of this reader (which can be unparented and NULL)
Definition: ReaderBase.cpp:254
openshot::ReaderBase::SetClip
void SetClip(openshot::ClipBase *clip)
Set parent clip object of this reader.
Definition: ReaderBase.cpp:259
openshot::ReaderBase::SetJsonValue
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition: ReaderBase.cpp:171
openshot::ReaderBase::JsonValue
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Definition: ReaderBase.cpp:116
openshot::ReaderBase::GetFrame
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
openshot::ReaderBase::SetJson
virtual void SetJson(const std::string value)=0
Load JSON string into this object.
openshot::ReaderBase::Open
virtual void Open()=0
Open the reader (and start consuming resources, such as images or video files)
openshot::ReaderBase::DisplayInfo
void DisplayInfo()
Display file information in the standard output stream (stdout)
Definition: ReaderBase.cpp:70
openshot::ReaderBase::ReaderBase
ReaderBase()
Constructor for the base reader, where many things are initialized.
Definition: ReaderBase.cpp:36
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: AudioBufferSource.h:39
openshot::ChannelLayout
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround,...
Definition: ChannelLayouts.h:47
openshot::ReaderInfo
This struct contains info about a media file, such as height, width, frames per second,...
Definition: ReaderBase.h:61
openshot::ReaderInfo::top_field_first
bool top_field_first
Definition: ReaderBase.h:79
openshot::ReaderInfo::audio_bit_rate
int audio_bit_rate
The bit rate of the audio stream (in bytes)
Definition: ReaderBase.h:81
openshot::ReaderInfo::video_bit_rate
int video_bit_rate
The bit rate of the video stream (in bytes)
Definition: ReaderBase.h:71
openshot::ReaderInfo::has_single_image
bool has_single_image
Determines if this file only contains a single image.
Definition: ReaderBase.h:64
openshot::ReaderInfo::interlaced_frame
bool interlaced_frame
Definition: ReaderBase.h:78
openshot::ReaderInfo::duration
float duration
Length of time (in seconds)
Definition: ReaderBase.h:65
openshot::ReaderInfo::audio_timebase
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
Definition: ReaderBase.h:86
openshot::ReaderInfo::width
int width
The width of the video (in pixesl)
Definition: ReaderBase.h:68
openshot::ReaderInfo::channels
int channels
The number of audio channels used in the audio stream.
Definition: ReaderBase.h:83
openshot::ReaderInfo::fps
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Definition: ReaderBase.h:70
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:73
openshot::ReaderInfo::height
int height
The height of the video (in pixels)
Definition: ReaderBase.h:67
openshot::ReaderInfo::pixel_format
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
Definition: ReaderBase.h:69
openshot::ReaderInfo::video_length
int64_t video_length
The number of frames in the video stream.
Definition: ReaderBase.h:75
openshot::ReaderInfo::acodec
std::string acodec
The name of the audio codec used to encode / decode the video stream.
Definition: ReaderBase.h:80
openshot::ReaderInfo::metadata
std::map< std::string, std::string > metadata
An optional map/dictionary of metadata for this reader.
Definition: ReaderBase.h:87
openshot::ReaderInfo::vcodec
std::string vcodec
The name of the video codec used to encode / decode the video stream.
Definition: ReaderBase.h:74
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:72
openshot::ReaderInfo::channel_layout
openshot::ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...)
Definition: ReaderBase.h:84
openshot::ReaderInfo::has_video
bool has_video
Determines if this file has a video stream.
Definition: ReaderBase.h:62
openshot::ReaderInfo::has_audio
bool has_audio
Determines if this file has an audio stream.
Definition: ReaderBase.h:63
openshot::ReaderInfo::video_timebase
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Definition: ReaderBase.h:77
openshot::ReaderInfo::video_stream_index
int video_stream_index
The index of the video stream.
Definition: ReaderBase.h:76
openshot::ReaderInfo::sample_rate
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
Definition: ReaderBase.h:82
openshot::ReaderInfo::audio_stream_index
int audio_stream_index
The index of the audio stream.
Definition: ReaderBase.h:85
openshot::ReaderInfo::file_size
int64_t file_size
Size of file (in bytes)
Definition: ReaderBase.h:66