OpenShot Library | libopenshot  0.2.0
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  std::map<string, string> metadata; ///< An optional map/dictionary of metadata for this reader
87  };
88 
89  /**
90  * @brief This abstract class is the base class, used by all readers in libopenshot.
91  *
92  * Readers are types of classes that read video, audio, and image files, and
93  * return openshot::Frame objects. The only requirements for a 'reader', are to
94  * derive from this base class, implement the GetFrame method, and call the InitFileInfo() method.
95  */
96  class ReaderBase
97  {
98  protected:
99  /// Section lock for multiple threads
100  CriticalSection getFrameCriticalSection;
101  CriticalSection processingCriticalSection;
102 
103  int max_width; ///< The maximum image width needed by this clip (used for optimizations)
104  int max_height; ///< The maximium image height needed by this clip (used for optimizations)
105 
106  public:
107 
108  /// Constructor for the base reader, where many things are initialized.
109  ReaderBase();
110 
111  /// Information about the current media file
113 
114  /// Close the reader (and any resources it was consuming)
115  virtual void Close() = 0;
116 
117  /// Display file information in the standard output stream (stdout)
118  void DisplayInfo();
119 
120  /// Get the cache object used by this reader (note: not all readers use cache)
121  virtual CacheBase* GetCache() = 0;
122 
123  /// This method is required for all derived classes of ReaderBase, and returns the
124  /// openshot::Frame object, which contains the image and audio information for that
125  /// frame of video.
126  ///
127  /// @returns The requested frame of video
128  /// @param[in] number The frame number that is requested.
129  virtual std::shared_ptr<Frame> GetFrame(int64_t number) = 0;
130 
131  /// Determine if reader is open or closed
132  virtual bool IsOpen() = 0;
133 
134  /// Return the type name of the class
135  virtual string Name() = 0;
136 
137  /// Get and Set JSON methods
138  virtual string Json() = 0; ///< Generate JSON string of this object
139  virtual void SetJson(string value) = 0; ///< Load JSON string into this object
140  virtual Json::Value JsonValue() = 0; ///< Generate Json::JsonValue for this object
141  virtual void SetJsonValue(Json::Value root) = 0; ///< Load Json::JsonValue into this object
142 
143  /// Set Max Image Size (used for performance optimization)
144  void SetMaxSize(int width, int height) { max_width = width; max_height = height; };
145 
146  /// Open the reader (and start consuming resources, such as images or video files)
147  virtual void Open() = 0;
148  };
149 
150 }
151 
152 #endif
int max_height
The maximium image height needed by this clip (used for optimizations)
Definition: ReaderBase.h:104
Header file for Fraction class.
CriticalSection getFrameCriticalSection
Section lock for multiple threads.
Definition: ReaderBase.h:100
CriticalSection processingCriticalSection
Definition: ReaderBase.h:101
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:96
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:144
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:112
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
std::map< string, string > metadata
An optional map/dictionary of metadata for this reader.
Definition: ReaderBase.h:86
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:103
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
Definition: ReaderBase.h:81