OpenShot Library | libopenshot
0.3.3
|
Go to the documentation of this file.
30 : Thread(
"video-cache"), speed(0), last_speed(1), is_playing(false),
31 reader(NULL), current_display_frame(1), cached_frame_count(0),
32 min_frames_ahead(4), max_frames_ahead(8), should_pause_cache(false),
33 timeline_max_frame(0), should_break(false)
58 int64_t previous_frame = new_position;
66 if (previous_frame <= 0) {
73 if (new_position >= 1 && new_position <= timeline_max_frame && !reader->GetCache()->Contains(previous_frame)) {
102 if (new_speed != 0) {
112 int64_t total_bytes = 0;
113 total_bytes +=
static_cast<int64_t
>(width * height *
sizeof(char) * 4);
116 total_bytes += ((sample_rate * channels) / fps) *
sizeof(float);
143 using micro_sec = std::chrono::microseconds;
144 using double_micro_sec = std::chrono::duration<double, micro_sec::period>;
156 int current_speed =
speed;
159 int64_t increment = 1;
174 std::this_thread::sleep_for(frame_duration / 2);
177 }
else if (current_speed == 0) {
231 if (starting_frame < 1) {
235 if (ending_frame < 1) {
244 for (int64_t cache_frame = starting_frame; cache_frame != (ending_frame + increment); cache_frame += increment) {
265 std::this_thread::sleep_for(frame_duration / 2);
Header file for global Settings class.
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
VideoCacheThread()
Constructor.
float ToFloat()
Return this fraction as a float (i.e. 1/2 = 0.5)
float VIDEO_CACHE_PERCENT_AHEAD
Percentage of cache in front of the playhead (0.0 to 1.0)
int preview_width
Optional preview width of timeline image. If your preview window is smaller than the timeline,...
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
This namespace is the default namespace for all code in the openshot library.
int preview_height
Optional preview width of timeline image. If your preview window is smaller than the timeline,...
openshot::ReaderInfo info
Information about the current media file.
This class is contains settings used by libopenshot (and can be safely toggled at any point)
Header file for Timeline class.
void ClearAllCache(bool deep=false)
bool ENABLE_PLAYBACK_CACHING
Enable/Disable the cache thread to pre-fetch and cache video frames before we need them.
std::shared_ptr< Frame > last_cached_frame
int width
The width of the video (in pixesl)
void Play()
Play the video.
int VIDEO_CACHE_MAX_FRAMES
Max number of frames (when paused) to cache for playback.
Header file for CacheBase class.
Exception for frames that are out of bounds.
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
int64_t timeline_max_frame
int height
The height of the video (in pixels)
int VIDEO_CACHE_MAX_PREROLL_FRAMES
Max number of frames (ahead of playhead) to cache during playback.
~VideoCacheThread()
Destructor.
int VIDEO_CACHE_MIN_PREROLL_FRAMES
Minimum number of frames to cache before playback begins.
This class represents a timeline.
void setSpeed(int new_speed)
Set Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster,...
static Settings * Instance()
Create or get an instance of this logger singleton (invoke the class with this method)
void Stop()
Stop the audio playback.
void run()
Start the thread.
Header file for Frame class.
virtual int64_t Count()=0
Count the frames in the queue.
Source file for VideoCacheThread class.
int64_t getBytes(int width, int height, int sample_rate, int channels, float fps)
Get the size in bytes of a frame (rough estimate)
int64_t current_display_frame
int64_t cached_frame_count
Header file for OpenMPUtilities (set some common macros)
int64_t GetMaxBytes()
Gets the maximum bytes value.
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
virtual bool Contains(int64_t frame_number)=0
Check if frame is already contained in cache.
int64_t GetMaxFrame()
Look up the end frame number of the latest element on the timeline.
void Seek(int64_t new_position)
Seek the reader to a particular frame number.
int64_t requested_display_frame
int channels
The number of audio channels used in the audio stream.
bool isReady()
Is cache ready for video/audio playback.
virtual openshot::CacheBase * GetCache()=0
Get the cache object used by this reader (note: not all readers use cache)
Header file for all Exception classes.