OpenShot Library | libopenshot  0.3.2
ChunkReader.h
Go to the documentation of this file.
1 
9 // Copyright (c) 2008-2019 OpenShot Studios, LLC
10 //
11 // SPDX-License-Identifier: LGPL-3.0-or-later
12 
13 #ifndef OPENSHOT_CHUNK_READER_H
14 #define OPENSHOT_CHUNK_READER_H
15 
16 #include <string>
17 #include <memory>
18 
19 #include "ReaderBase.h"
20 #include "Json.h"
21 
22 namespace openshot
23 {
24  class CacheBase;
25  class Frame;
34  {
35  int64_t number;
36  int64_t frame;
37  };
38 
50  {
54  };
55 
78  class ChunkReader : public ReaderBase
79  {
80  private:
81  std::string path;
82  bool is_open;
83  int64_t chunk_size;
84  openshot::ReaderBase *local_reader;
85  ChunkLocation previous_location;
86  ChunkVersion version;
87  std::shared_ptr<openshot::Frame> last_frame;
88 
90  bool does_folder_exist(std::string path);
91 
93  ChunkLocation find_chunk_frame(int64_t requested_frame);
94 
96  std::string get_chunk_path(int64_t chunk_number, std::string folder, std::string extension);
97 
99  void load_json();
100 
101  public:
102 
107  ChunkReader(std::string path, ChunkVersion chunk_version);
108 
110  void Close() override;
111 
114  int64_t GetChunkSize() { return chunk_size; };
115 
118  void SetChunkSize(int64_t new_size) { chunk_size = new_size; };
119 
121  openshot::CacheBase* GetCache() override { return nullptr; };
122 
126  std::shared_ptr<openshot::Frame> GetFrame(int64_t requested_frame) override;
127 
129  bool IsOpen() override { return is_open; };
130 
132  std::string Name() override { return "ChunkReader"; };
133 
134  // Get and Set JSON methods
135  std::string Json() const override;
136  void SetJson(const std::string value) override;
137  Json::Value JsonValue() const override;
138  void SetJsonValue(const Json::Value root) override;
139 
141  void Open() override;
142  };
143 
144 }
145 
146 #endif
openshot::ChunkReader::SetJson
void SetJson(const std::string value) override
Load JSON string into this object.
Definition: ChunkReader.cpp:267
openshot::ChunkReader::GetFrame
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
Get an openshot::Frame object for a specific frame number of this reader.
Definition: ChunkReader.cpp:183
openshot::ChunkReader::GetChunkSize
int64_t GetChunkSize()
Get the chunk size (number of frames to write in each chunk)
Definition: ChunkReader.h:114
openshot::ChunkReader
This class reads a special chunk-formatted file, which can be easily shared in a distributed environm...
Definition: ChunkReader.h:78
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:28
openshot::ChunkReader::SetChunkSize
void SetChunkSize(int64_t new_size)
Set the chunk size (number of frames to write in each chunk)
Definition: ChunkReader.h:118
openshot::ChunkLocation
This struct holds the location of a frame within a chunk.
Definition: ChunkReader.h:33
openshot::ChunkReader::SetJsonValue
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Definition: ChunkReader.cpp:283
openshot::CacheBase
All cache managers in libopenshot are based on this CacheBase class.
Definition: CacheBase.h:34
openshot::ChunkReader::GetCache
openshot::CacheBase * GetCache() override
Get the cache object used by this reader (always return NULL for this reader)
Definition: ChunkReader.h:121
path
path
Definition: FFmpegWriter.cpp:1444
openshot::ChunkLocation::number
int64_t number
The chunk number.
Definition: ChunkReader.h:35
openshot::ChunkReader::Json
std::string Json() const override
Generate JSON string of this object.
Definition: ChunkReader.cpp:244
ReaderBase.h
Header file for ReaderBase class.
openshot::ChunkReader::Close
void Close() override
Close the reader.
Definition: ChunkReader.cpp:149
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:75
openshot::ChunkLocation::frame
int64_t frame
The frame number.
Definition: ChunkReader.h:36
openshot::ChunkReader::IsOpen
bool IsOpen() override
Determine if reader is open or closed.
Definition: ChunkReader.h:129
Json.h
Header file for JSON class.
openshot::ChunkReader::Open
void Open() override
Open the reader. This is required before you can access frames or data from the reader.
Definition: ChunkReader.cpp:135
openshot::ChunkReader::Name
std::string Name() override
Return the type name of the class.
Definition: ChunkReader.h:132
openshot::ChunkVersion
ChunkVersion
This enumeration allows the user to choose which version of the chunk they would like (low,...
Definition: ChunkReader.h:49
openshot::THUMBNAIL
@ THUMBNAIL
The lowest quality stream contained in this chunk file.
Definition: ChunkReader.h:51
openshot::ChunkReader::ChunkReader
ChunkReader(std::string path, ChunkVersion chunk_version)
Constructor for ChunkReader. This automatically opens the chunk file or folder and loads frame 1,...
Definition: ChunkReader.cpp:23
openshot::ChunkReader::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: ChunkReader.cpp:251
openshot::FINAL
@ FINAL
The highest quality stream contained in this chunk file.
Definition: ChunkReader.h:53
openshot::PREVIEW
@ PREVIEW
The medium quality stream contained in this chunk file.
Definition: ChunkReader.h:52