OpenShot Library | libopenshot  0.1.9
CacheBase.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Source file for CacheBase 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 #include "../include/CacheBase.h"
29 
30 using namespace std;
31 using namespace openshot;
32 
33 // Default constructor, no max frames
34 CacheBase::CacheBase() : max_bytes(0) {
35  // Init the critical section
36  cacheCriticalSection = new CriticalSection();
37 };
38 
39 // Constructor that sets the max frames to cache
40 CacheBase::CacheBase(int64_t max_bytes) : max_bytes(max_bytes) {
41  // Init the critical section
42  cacheCriticalSection = new CriticalSection();
43 };
44 
45 // Set maximum bytes to a different amount based on a ReaderInfo struct
46 void CacheBase::SetMaxBytesFromInfo(int64_t number_of_frames, int width, int height, int sample_rate, int channels)
47 {
48  // n frames X height X width X 4 colors of chars X audio channels X 4 byte floats
49  int64_t bytes = number_of_frames * (height * width * 4 + (sample_rate * channels * 4));
50  SetMaxBytes(bytes);
51 }
52 
53 // Generate Json::JsonValue for this object
54 Json::Value CacheBase::JsonValue() {
55 
56  // Create root json object
57  Json::Value root;
58  stringstream max_bytes_stream;
59  max_bytes_stream << max_bytes;
60  root["max_bytes"] = max_bytes_stream.str();
61 
62  // return JsonValue
63  return root;
64 }
65 
66 // Load Json::JsonValue into this object
67 void CacheBase::SetJsonValue(Json::Value root) {
68 
69  // Set data from Json (if key is found)
70  if (!root["max_bytes"].isNull())
71  max_bytes = atoll(root["max_bytes"].asString().c_str());
72 }
CriticalSection * cacheCriticalSection
Section lock for multiple threads.
Definition: CacheBase.h:52
void SetMaxBytesFromInfo(int64_t number_of_frames, int width, int height, int sample_rate, int channels)
Set maximum bytes to a different amount based on a ReaderInfo struct.
Definition: CacheBase.cpp:46
CacheBase()
Default constructor, no max bytes.
Definition: CacheBase.cpp:34
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
Definition: CacheBase.cpp:54
void SetMaxBytes(int64_t number_of_bytes)
Set maximum bytes to a different amount.
Definition: CacheBase.h:97
This namespace is the default namespace for all code in the openshot library.
int64_t max_bytes
This is the max number of bytes to cache (0 = no limit)
Definition: CacheBase.h:49
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
Definition: CacheBase.cpp:67