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