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) {
190 bytes_per_frame =
getBytes(t->preview_width, t->preview_height,
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);
This class is contains settings used by libopenshot (and can be safely toggled at any point) ...
void setSpeed(int new_speed)
Set Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster, -1=rewind, etc...)
VideoCacheThread()
Constructor.
Source file for VideoCacheThread class.
void Play()
Play the video.
int width
The width of the video (in pixesl)
virtual bool Contains(int64_t frame_number)=0
Check if frame is already contained in cache.
void ClearAllCache(bool deep=false)
float ToFloat()
Return this fraction as a float (i.e. 1/2 = 0.5)
Header file for OpenMPUtilities (set some common macros)
int64_t timeline_max_frame
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
~VideoCacheThread()
Destructor.
Header file for Timeline class.
std::shared_ptr< Frame > last_cached_frame
Header file for CacheBase class.
virtual std::shared_ptr< openshot::Frame > GetFrame(int64_t number)=0
Header file for all Exception classes.
virtual openshot::CacheBase * GetCache()=0
Get the cache object used by this reader (note: not all readers use cache)
bool isReady()
Is cache ready for video/audio playback.
Header file for Frame class.
int height
The height of the video (in pixels)
void Stop()
Stop the audio playback.
virtual int64_t Count()=0
Count the frames in the queue.
int VIDEO_CACHE_MIN_PREROLL_FRAMES
Minimum number of frames to cache before playback begins.
int64_t getBytes(int width, int height, int sample_rate, int channels, float fps)
Get the size in bytes of a frame (rough estimate)
Header file for global Settings class.
bool ENABLE_PLAYBACK_CACHING
Enable/Disable the cache thread to pre-fetch and cache video frames before we need them...
int64_t cached_frame_count
openshot::ReaderInfo info
Information about the current media file.
Exception for frames that are out of bounds.
void run()
Start the thread.
This namespace is the default namespace for all code in the openshot library.
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.
int VIDEO_CACHE_MAX_PREROLL_FRAMES
Max number of frames (ahead of playhead) to cache during playback.
static Settings * Instance()
Create or get an instance of this logger singleton (invoke the class with this method) ...
int64_t GetMaxBytes()
Gets the maximum bytes value.
int64_t current_display_frame
int channels
The number of audio channels used in the audio stream.
int VIDEO_CACHE_MAX_FRAMES
Max number of frames (when paused) to cache for playback.
float VIDEO_CACHE_PERCENT_AHEAD
Percentage of cache in front of the playhead (0.0 to 1.0)
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
int64_t requested_display_frame
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
This class represents a timeline.