OpenShot Library | libopenshot  0.2.3
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 "ClipBase.h"
39 #include "Fraction.h"
40 #include "Frame.h"
41 #include "Json.h"
42 #include "ZmqLogger.h"
43 #include <QtCore/qstring.h>
44 #include <QGraphicsItem>
45 #include <QGraphicsScene>
46 #include <QGraphicsPixmapItem>
47 #include <QPixmap>
48 
49 using namespace std;
50 
51 namespace openshot
52 {
53  /**
54  * @brief This struct contains info about a media file, such as height, width, frames per second, etc...
55  *
56  * Each derived class of ReaderBase is responsible for updating this struct to reflect accurate information
57  * about the streams. Derived classes of ReaderBase should call the InitFileInfo() method to initialize the
58  * default values of this struct.
59  */
60  struct ReaderInfo
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  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  Fraction pixel_ratio; ///< The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
73  Fraction display_ratio; ///< The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
74  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  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  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  ChannelLayout channel_layout; ///< The channel layout (mono, stereo, 5 point surround, etc...)
85  int audio_stream_index; ///< The index of the audio stream
86  Fraction audio_timebase; ///< The audio timebase determines how long each audio packet should be played
87  std::map<string, 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 call the InitFileInfo() method.
96  */
97  class ReaderBase
98  {
99  protected:
100  /// Section lock for multiple threads
101  CriticalSection getFrameCriticalSection;
102  CriticalSection processingCriticalSection;
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)
114  ClipBase* GetClip();
115 
116  /// Set parent clip object of this reader
117  void SetClip(ClipBase* 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)
126  virtual CacheBase* GetCache() = 0;
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<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 string Name() = 0;
141 
142  /// Get and Set JSON methods
143  virtual string Json() = 0; ///< Generate JSON string of this object
144  virtual void SetJson(string value) = 0; ///< Load JSON string into this object
145  virtual Json::Value JsonValue() = 0; ///< Generate Json::JsonValue for this object
146  virtual void SetJsonValue(Json::Value root) = 0; ///< Load Json::JsonValue 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 
152 }
153 
154 #endif
Header file for Fraction class.
CriticalSection getFrameCriticalSection
Section lock for multiple threads.
Definition: ReaderBase.h:101
Header file for ClipBase class.
CriticalSection processingCriticalSection
Definition: ReaderBase.h:102
ChannelLayout channel_layout
The channel layout (mono, stereo, 5 point surround, etc...)
Definition: ReaderBase.h:84
int width
The width of the video (in pixesl)
Definition: ReaderBase.h:68
float duration
Length of time (in seconds)
Definition: ReaderBase.h:65
string acodec
The name of the audio codec used to encode / decode the video stream.
Definition: ReaderBase.h:80
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:97
bool has_video
Determines if this file has a video stream.
Definition: ReaderBase.h:62
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
Header file for CacheMemory class.
int64_t file_size
Size of file (in bytes)
Definition: ReaderBase.h:66
int audio_bit_rate
The bit rate of the audio stream (in bytes)
Definition: ReaderBase.h:81
bool has_audio
Determines if this file has an audio stream.
Definition: ReaderBase.h:63
Header file for Frame class.
int audio_stream_index
The index of the audio stream.
Definition: ReaderBase.h:85
int64_t video_length
The number of frames in the video stream.
Definition: ReaderBase.h:75
int height
The height of the video (in pixels)
Definition: ReaderBase.h:67
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:60
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:64
ChannelLayout
This enumeration determines the audio channel layout (such as stereo, mono, 5 point surround...
This abstract class is the base class, used by all clips in libopenshot.
Definition: ClipBase.h:53
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:70
Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Definition: ReaderBase.h:77
std::map< string, string > metadata
An optional map/dictionary of metadata for this reader.
Definition: ReaderBase.h:87
Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
Definition: ReaderBase.h:72
int pixel_format
The pixel format (i.e. YUV420P, RGB24, etc...)
Definition: ReaderBase.h:69
int video_bit_rate
The bit rate of the video stream (in bytes)
Definition: ReaderBase.h:71
Fraction audio_timebase
The audio timebase determines how long each audio packet should be played.
Definition: ReaderBase.h:86
string vcodec
The name of the video codec used to encode / decode the video stream.
Definition: ReaderBase.h:74
int channels
The number of audio channels used in the audio stream.
Definition: ReaderBase.h:83
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