MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / isReady

Method isReady

src/Qt/VideoCacheThread.cpp:54–92  ·  view source on GitHub ↗

Is cache ready for playback (pre-roll)

Source from the content-addressed store, hash-verified

52
53 // Is cache ready for playback (pre-roll)
54 bool VideoCacheThread::isReady()
55 {
56 if (!reader) {
57 return false;
58 }
59
60 const int64_t ready_min = min_frames_ahead.load();
61 if (ready_min < 0) {
62 return true;
63 }
64
65 const int64_t cached_index = last_cached_index.load();
66 int64_t playhead = requested_display_frame.load();
67 int dir = computeDirection();
68
69 // Near timeline boundaries, don't require more pre-roll than can exist.
70 int64_t max_frame = reader->info.video_length;
71 if (auto* timeline = dynamic_cast<Timeline*>(reader)) {
72 const int64_t timeline_max = timeline->GetMaxFrame();
73 if (timeline_max > 0) {
74 max_frame = timeline_max;
75 }
76 }
77 if (max_frame < 1) {
78 return false;
79 }
80 playhead = clampToTimelineRange(playhead, max_frame);
81
82 int64_t required_ahead = ready_min;
83 int64_t available_ahead = (dir > 0)
84 ? std::max<int64_t>(0, max_frame - playhead)
85 : std::max<int64_t>(0, playhead - 1);
86 required_ahead = std::min(required_ahead, available_ahead);
87
88 if (dir > 0) {
89 return (cached_index >= playhead + required_ahead);
90 }
91 return (cached_index <= playhead - required_ahead);
92 }
93
94 void VideoCacheThread::setSpeed(int new_speed)
95 {

Callers 3

getNextAudioBlockMethod · 0.80
runMethod · 0.80

Calls 1

GetMaxFrameMethod · 0.80

Tested by

no test coverage detected