OpenShot Library | libopenshot 0.2.7
ReaderBase.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Header file for ReaderBase class
4 * @author Jonathan Thomas <jonathan@openshot.org>
5 *
6 * @ref License
7 */
8
9/* LICENSE
10 *
11 * Copyright (c) 2008-2019 OpenShot Studios, LLC
12 * <http://www.openshotstudios.com/>. This file is part of
13 * OpenShot Library (libopenshot), an open-source project dedicated to
14 * delivering high quality video editing and animation solutions to the
15 * world. For more information visit <http://www.openshot.org/>.
16 *
17 * OpenShot Library (libopenshot) is free software: you can redistribute it
18 * and/or modify it under the terms of the GNU Lesser General Public License
19 * as published by the Free Software Foundation, either version 3 of the
20 * License, or (at your option) any later version.
21 *
22 * OpenShot Library (libopenshot) is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public License
28 * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31#ifndef OPENSHOT_READER_BASE_H
32#define OPENSHOT_READER_BASE_H
33
34#include <iostream>
35#include <iomanip>
36#include <memory>
37#include <cstdlib>
38#include <sstream>
39#include "CacheMemory.h"
40#include "ChannelLayouts.h"
41#include "ClipBase.h"
42#include "Fraction.h"
43#include "Frame.h"
44#include "Json.h"
45#include "ZmqLogger.h"
46#include <QString>
47#include <QGraphicsItem>
48#include <QGraphicsScene>
49#include <QGraphicsPixmapItem>
50#include <QPixmap>
51
52namespace openshot
53{
54 /**
55 * @brief This struct contains info about a media file, such as height, width, frames per second, etc...
56 *
57 * Each derived class of ReaderBase is responsible for updating this struct to reflect accurate information
58 * about the streams.
59 */
61 {
62 bool has_video; ///< Determines if this file has a video stream
63 bool has_audio; ///< Determines if this file has an audio stream
64 bool has_single_image; ///< Determines if this file only contains a single image
65 float duration; ///< Length of time (in seconds)
66 int64_t file_size; ///< Size of file (in bytes)
67 int height; ///< The height of the video (in pixels)
68 int width; ///< The width of the video (in pixesl)
69 int pixel_format; ///< The pixel format (i.e. YUV420P, RGB24, etc...)
70 openshot::Fraction fps; ///< Frames per second, as a fraction (i.e. 24/1 = 24 fps)
71 int video_bit_rate; ///< The bit rate of the video stream (in bytes)
72 openshot::Fraction pixel_ratio; ///< The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
73 openshot::Fraction display_ratio; ///< The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
74 std::string vcodec; ///< The name of the video codec used to encode / decode the video stream
75 int64_t video_length; ///< The number of frames in the video stream
76 int video_stream_index; ///< The index of the video stream
77 openshot::Fraction video_timebase; ///< The video timebase determines how long each frame stays on the screen
78 bool interlaced_frame; // Are the contents of this frame interlaced
79 bool top_field_first; // Which interlaced field should be displayed first
80 std::string acodec; ///< The name of the audio codec used to encode / decode the video stream
81 int audio_bit_rate; ///< The bit rate of the audio stream (in bytes)
82 int sample_rate; ///< The number of audio samples per second (44100 is a common sample rate)
83 int channels; ///< The number of audio channels used in the audio stream
84 openshot::ChannelLayout channel_layout; ///< The channel layout (mono, stereo, 5 point surround, etc...)
85 int audio_stream_index; ///< The index of the audio stream
86 openshot::Fraction audio_timebase; ///< The audio timebase determines how long each audio packet should be played
87 std::map<std::string, std::string> metadata; ///< An optional map/dictionary of metadata for this reader
88 };
89
90 /**
91 * @brief This abstract class is the base class, used by all readers in libopenshot.
92 *
93 * Readers are types of classes that read video, audio, and image files, and
94 * return openshot::Frame objects. The only requirements for a 'reader', are to
95 * derive from this base class, implement the GetFrame method, and populate ReaderInfo.
96 */
98 {
99 protected:
100 /// Section lock for multiple threads
101 juce::CriticalSection getFrameCriticalSection;
102 juce::CriticalSection processingCriticalSection;
103 openshot::ClipBase* clip; ///< Pointer to the parent clip instance (if any)
104
105 public:
106
107 /// Constructor for the base reader, where many things are initialized.
108 ReaderBase();
109
110 /// Information about the current media file
112
113 /// Parent clip object of this reader (which can be unparented and NULL)
115
116 /// Set parent clip object of this reader
117 void ParentClip(openshot::ClipBase* new_clip);
118
119 /// Close the reader (and any resources it was consuming)
120 virtual void Close() = 0;
121
122 /// Display file information in the standard output stream (stdout)
123 void DisplayInfo();
124
125 /// Get the cache object used by this reader (note: not all readers use cache)
127
128 /// This method is required for all derived classes of ReaderBase, and returns the
129 /// openshot::Frame object, which contains the image and audio information for that
130 /// frame of video.
131 ///
132 /// @returns The requested frame of video
133 /// @param[in] number The frame number that is requested.
134 virtual std::shared_ptr<openshot::Frame> GetFrame(int64_t number) = 0;
135
136 /// Determine if reader is open or closed
137 virtual bool IsOpen() = 0;
138
139 /// Return the type name of the class
140 virtual std::string Name() = 0;
141
142 // Get and Set JSON methods
143 virtual std::string Json() const = 0; ///< Generate JSON string of this object
144 virtual void SetJson(const std::string value) = 0; ///< Load JSON string into this object
145 virtual Json::Value JsonValue() const = 0; ///< Generate Json::Value for this object
146 virtual void SetJsonValue(const Json::Value root) = 0; ///< Load Json::Value into this object
147
148 /// Open the reader (and start consuming resources, such as images or video files)
149 virtual void Open() = 0;
150
151 virtual ~ReaderBase() = default;
152 };
153
154}
155
156#endif
Header file for CacheMemory class.
Header file for ChannelLayout class.
Header file for ClipBase class.
Header file for Fraction class.
Header file for Frame class.
Header file for JSON class.
Header file for ZeroMQ-based Logger class.
All cache managers in libopenshot are based on this CacheBase class.
Definition: CacheBase.h:49
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:51
This class represents a fraction.
Definition: Fraction.h:48
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:98
virtual bool IsOpen()=0
Determine if reader is open or closed.
virtual std::string Name()=0
Return the type name of the class.
juce::CriticalSection getFrameCriticalSection
Section lock for multiple threads.
Definition: ReaderBase.h:101
openshot::ReaderInfo info
Information about the current media file.
Definition: ReaderBase.h:111
juce::CriticalSection processingCriticalSection
Definition: ReaderBase.h:102
virtual std::string Json() const =0
Generate JSON string of this object.
virtual ~ReaderBase()=default
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Definition: ReaderBase.cpp:171
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
Definition: ReaderBase.cpp:116
virtual void SetJson(const std::string value)=0
Load JSON string into this object.
virtual void Open()=0
Open the reader (and start consuming resources, such as images or video files)
void DisplayInfo()
Display file information in the standard output stream (stdout)
Definition: ReaderBase.cpp:70
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
virtual openshot::CacheBase * GetCache()=0
Get the cache object used by this reader (note: not all readers use cache)
openshot::ClipBase * clip
Pointer to the parent clip instance (if any)
Definition: ReaderBase.h:103
openshot::ClipBase * ParentClip()
Parent clip object of this reader (which can be unparented and NULL)
Definition: ReaderBase.cpp:254
ReaderBase()
Constructor for the base reader, where many things are initialized.
Definition: ReaderBase.cpp:36
virtual void Close()=0
Close the reader (and any resources it was consuming)
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround,...
This struct contains info about a media file, such as height, width, frames per second,...
Definition: ReaderBase.h:61
int audio_bit_rate
The bit rate of the audio stream (in bytes)
Definition: ReaderBase.h:81
int video_bit_rate
The bit rate of the video stream (in bytes)
Definition: ReaderBase.h:71
bool has_single_image
Determines if this file only contains a single image.
Definition: ReaderBase.h:64
float duration
Length of time (in seconds)
Definition: ReaderBase.h:65
openshot::Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
Definition: ReaderBase.h:86
int width
The width of the video (in pixesl)
Definition: ReaderBase.h:68
int channels
The number of audio channels used in the audio stream.
Definition: ReaderBase.h:83
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Definition: ReaderBase.h:70
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
int height
The height of the video (in pixels)
Definition: ReaderBase.h:67
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
Definition: ReaderBase.h:69
int64_t video_length
The number of frames in the video stream.
Definition: ReaderBase.h:75
std::string acodec
The name of the audio codec used to encode / decode the video stream.
Definition: ReaderBase.h:80
std::map< std::string, std::string > metadata
An optional map/dictionary of metadata for this reader.
Definition: ReaderBase.h:87
std::string vcodec
The name of the video codec used to encode / decode the video stream.
Definition: ReaderBase.h:74
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::ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...)
Definition: ReaderBase.h:84
bool has_video
Determines if this file has a video stream.
Definition: ReaderBase.h:62
bool has_audio
Determines if this file has an audio stream.
Definition: ReaderBase.h:63
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Definition: ReaderBase.h:77
int video_stream_index
The index of the video stream.
Definition: ReaderBase.h:76
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
Definition: ReaderBase.h:82
int audio_stream_index
The index of the audio stream.
Definition: ReaderBase.h:85
int64_t file_size
Size of file (in bytes)
Definition: ReaderBase.h:66