Loading...
Searching...
No Matches
openshot::VideoCacheThread Class Reference

Handles prefetching and caching of video/audio frames for smooth playback. More...

`#include <Qt/VideoCacheThread.h>`

Inheritance diagram for openshot::VideoCacheThread:

## Public Member Functions

int | getSpeed () const
bool | isReady ()
void | Play ()
| Play method is unimplemented.
void | Reader (ReaderBase *new_reader)
| Attach a ReaderBase (e.g. Timeline, FFmpegReader) and begin caching.
void | Seek (int64_t new_position)
| Seek to a specific frame (no preroll).
void | Seek (int64_t new_position, bool start_preroll)
| Seek to a specific frame and optionally start a preroll (cache reset).
void | setSpeed (int new_speed)
| Set playback speed/direction. Positive = forward, negative = rewind, zero = pause.
bool | StartThread ()
| Start the cache thread at high priority. Returns true if it’s actually running.
void | Stop ()
| Stop method is unimplemented.
bool | StopThread (int timeoutMs=0)
| Stop the cache thread (wait up to timeoutMs ms). Returns true if it stopped.
| VideoCacheThread ()
| Constructor: initializes member variables and assumes forward direction on first launch.
| ~VideoCacheThread () override

## Protected Member Functions

bool | clearCacheIfPaused (int64_t playhead, bool paused, CacheBase *cache)
| When paused and playhead is outside current cache, clear all frames.
int | computeDirection () const
void | computeWindowBounds (int64_t playhead, int dir, int64_t ahead_count, int64_t timeline_end, int64_t &window_begin, int64_t &window_end) const
| Compute the “window” of frames to cache around playhead.
int64_t | getBytes (int width, int height, int sample_rate, int channels, float fps)
| Estimate memory usage for a single frame (video + audio).
void | handleUserSeek (int64_t playhead, int dir)
| If userSeeked is true, reset last_cached_index just behind the playhead.
bool | prefetchWindow (CacheBase *cache, int64_t window_begin, int64_t window_end, int dir, ReaderBase *reader)
| Prefetch all missing frames in [window_begin ... window_end] or [window_end ... window_begin].
void | run () override
| Thread entry point: loops until threadShouldExit() is true.

## Protected Attributes

int64_t | cached_frame_count
| Estimated count of frames currently stored in cache.
int64_t | current_display_frame
| Currently displayed frame (unused here, reserved).
bool | force_directional_cache
| (Reserved for future use).
std::shared_ptr< Frame > | last_cached_frame
| Last frame pointer added to cache.
int64_t | last_cached_index
| Index of the most recently cached frame.
int | last_dir
| Last direction sign (+1 forward, –1 backward).
int | last_speed
| Last non-zero speed (for tracking).
int64_t | min_frames_ahead
| Minimum number of frames considered “ready” (pre-roll).
ReaderBase * | reader
| The source reader (e.g., Timeline, FFmpegReader).
int64_t | requested_display_frame
| Frame index the user requested.
int | speed
| Current playback speed (0=paused, >0 forward, <0 backward).
int64_t | timeline_max_frame
| Highest valid frame index in the timeline.
bool | userSeeked
| True if Seek(..., true) was called (forces a cache reset).

## Detailed Description

Handles prefetching and caching of video/audio frames for smooth playback.

This thread continuously maintains a “window” of cached frames in the current playback direction (forward or backward). When paused, it continues to fill that same window; when seeking, it resets to cache around the new position.

Definition at line 33 of file VideoCacheThread.h.

## Constructor & Destructor Documentation

## VideoCacheThread()

openshot::VideoCacheThread::VideoCacheThread | ( |  | ) |

Constructor: initializes member variables and assumes forward direction on first launch.

Definition at line 26 of file VideoCacheThread.cpp.

## ~VideoCacheThread()

openshot::VideoCacheThread::~VideoCacheThread | ( |  | ) |

override

Definition at line 44 of file VideoCacheThread.cpp.

## Member Function Documentation

## clearCacheIfPaused()

bool openshot::VideoCacheThread::clearCacheIfPaused | ( | int64_t | playhead,
|  | bool | paused,
|  | CacheBase * | cache )

protected

When paused and playhead is outside current cache, clear all frames.

Parameters

  playhead | Current requested_display_frame
  paused | True if speed == 0
  cache | Pointer to CacheBase

Returns
  True if ClearAllCache() was invoked.

Definition at line 141 of file VideoCacheThread.cpp.

Referenced by run().

## computeDirection()

int openshot::VideoCacheThread::computeDirection | ( |  | ) | const

protected

Returns
  Effective playback direction (+1 forward, –1 backward), preserving last_dir if speed == 0.

Definition at line 129 of file VideoCacheThread.cpp.

Referenced by run().

## computeWindowBounds()

void openshot::VideoCacheThread::computeWindowBounds | ( | int64_t | playhead,
|  | int | dir,
|  | int64_t | ahead_count,
|  | int64_t | timeline_end,
|  | int64_t & | window_begin,
|  | int64_t & | window_end ) const

protected

Compute the “window” of frames to cache around playhead.

Parameters

  | playhead | Current requested_display_frame
  | dir | Effective direction (±1)
  | ahead_count | Number of frames ahead/back to cache
  | timeline_end | Last valid frame index
  [out] | window_begin | Lower bound (inclusive) of caching window
  [out] | window_end | Upper bound (inclusive) of caching window

If dir > 0: window = [playhead ... playhead + ahead_count] If dir < 0: window = [playhead – ahead_count ... playhead] Always clamps to [1 ... timeline_end].

Definition at line 155 of file VideoCacheThread.cpp.

Referenced by run().

## getBytes()

int64_t openshot::VideoCacheThread::getBytes | ( | int | width,
|  | int | height,
|  | int | sample_rate,
|  | int | channels,
|  | float | fps )

protected

Estimate memory usage for a single frame (video + audio).

Parameters

  width | Frame width (pixels)
  height | Frame height (pixels)
  sample_rate | Audio sample rate (e.g. 48000)
  channels | Number of audio channels
  fps | Frames per second

Returns
  Approximate size in bytes for one frame

Definition at line 73 of file VideoCacheThread.cpp.

Referenced by run().

## getSpeed()

int openshot::VideoCacheThread::getSpeed | ( |  | ) | const

inline

Returns
  The current speed (1=normal, 2=fast, –1=rewind, etc.)

Definition at line 59 of file VideoCacheThread.h.

## handleUserSeek()

void openshot::VideoCacheThread::handleUserSeek | ( | int64_t | playhead,
|  | int | dir )

protected

If userSeeked is true, reset last_cached_index just behind the playhead.

Parameters

  playhead | Current requested_display_frame
  dir | Effective direction (±1)

Definition at line 135 of file VideoCacheThread.cpp.

Referenced by run().

## isReady()

bool openshot::VideoCacheThread::isReady | ( |  | ) |

Returns
  True if at least min_frames_ahead frames have been cached.

Definition at line 49 of file VideoCacheThread.cpp.

## Play()

void openshot::VideoCacheThread::Play | ( |  | ) |

inline

Play method is unimplemented.

Definition at line 44 of file VideoCacheThread.h.

Referenced by Reader().

## prefetchWindow()

bool openshot::VideoCacheThread::prefetchWindow | ( | CacheBase * | cache,
|  | int64_t | window_begin,
|  | int64_t | window_end,
|  | int | dir,
|  | ReaderBase * | reader )

protected

Prefetch all missing frames in [window_begin ... window_end] or [window_end ... window_begin].

Parameters

  cache | Pointer to CacheBase
  window_begin | Inclusive lower bound of the window
  window_end | Inclusive upper bound of the window
  dir | Effective direction (±1)
  reader | Pointer to ReaderBase to call GetFrame()

Returns
  True if the window was already full (no new frames added)

Internally, this method iterates from last_cached_index + dir toward window_end (or window_begin) and calls GetFrame()/Add() for each missing frame until hitting the window boundary or an OOB. It also breaks early if threadShouldExit() or userSeeked becomes true.

Definition at line 177 of file VideoCacheThread.cpp.

Referenced by run().

## Reader()

void openshot::VideoCacheThread::Reader | ( | ReaderBase * | new_reader | ) |

inline

Attach a ReaderBase (e.g. Timeline, FFmpegReader) and begin caching.

Parameters

  new_reader |

Definition at line 81 of file VideoCacheThread.h.

## run()

void openshot::VideoCacheThread::run | ( |  | ) |

override protected

Thread entry point: loops until threadShouldExit() is true.

Definition at line 221 of file VideoCacheThread.cpp.

## Seek() [1/2]

void openshot::VideoCacheThread::Seek | ( | int64_t | new_position | ) |

Seek to a specific frame (no preroll).

Definition at line 124 of file VideoCacheThread.cpp.

Referenced by Seek().

## Seek() [2/2]

void openshot::VideoCacheThread::Seek | ( | int64_t | new_position,
|  | bool | start_preroll )

Seek to a specific frame and optionally start a preroll (cache reset).

Parameters

  new_position | Frame index to jump to.
  start_preroll | If true, forces cache to rebuild around new_position.

Definition at line 102 of file VideoCacheThread.cpp.

## setSpeed()

void openshot::VideoCacheThread::setSpeed | ( | int | new_speed | ) |

Set playback speed/direction. Positive = forward, negative = rewind, zero = pause.

Parameters

  new_speed |

If new_speed != 0, last_speed and last_dir are updated. If new_speed == 0, last_dir is left unchanged so that pausing does not flip direction.

Definition at line 62 of file VideoCacheThread.cpp.

## StartThread()

bool openshot::VideoCacheThread::StartThread | ( |  | ) |

Start the cache thread at high priority. Returns true if it’s actually running.

Start the cache thread at high priority, and return true if it’s actually running.

Definition at line 87 of file VideoCacheThread.cpp.

## Stop()

void openshot::VideoCacheThread::Stop | ( |  | ) |

inline

Stop method is unimplemented.

Definition at line 47 of file VideoCacheThread.h.

## StopThread()

bool openshot::VideoCacheThread::StopThread | ( | int | timeoutMs = 0 | ) |

Stop the cache thread (wait up to timeoutMs ms). Returns true if it stopped.

Stop the cache thread, waiting up to timeoutMs ms. Returns true if it actually stopped.

Definition at line 96 of file VideoCacheThread.cpp.

## Member Data Documentation

## cached_frame_count

int64_t openshot::VideoCacheThread::cached_frame_count

protected

Estimated count of frames currently stored in cache.

Definition at line 169 of file VideoCacheThread.h.

Referenced by clearCacheIfPaused(), isReady(), prefetchWindow(), run(), Seek(), and VideoCacheThread().

## current_display_frame

int64_t openshot::VideoCacheThread::current_display_frame

protected

Currently displayed frame (unused here, reserved).

Definition at line 168 of file VideoCacheThread.h.

Referenced by VideoCacheThread().

## force_directional_cache

bool openshot::VideoCacheThread::force_directional_cache

protected

(Reserved for future use).

Definition at line 175 of file VideoCacheThread.h.

Referenced by VideoCacheThread().

## last_cached_frame

std::shared_ptr<Frame> openshot::VideoCacheThread::last_cached_frame

protected

Last frame pointer added to cache.

Definition at line 160 of file VideoCacheThread.h.

## last_cached_index

int64_t openshot::VideoCacheThread::last_cached_index

protected

Index of the most recently cached frame.

Definition at line 177 of file VideoCacheThread.h.

Referenced by handleUserSeek(), prefetchWindow(), run(), and VideoCacheThread().

## last_dir

int openshot::VideoCacheThread::last_dir

protected

Last direction sign (+1 forward, –1 backward).

Definition at line 164 of file VideoCacheThread.h.

Referenced by computeDirection(), run(), setSpeed(), and VideoCacheThread().

## last_speed

int openshot::VideoCacheThread::last_speed

protected

Last non-zero speed (for tracking).

Definition at line 163 of file VideoCacheThread.h.

Referenced by setSpeed(), and VideoCacheThread().

## min_frames_ahead

int64_t openshot::VideoCacheThread::min_frames_ahead

protected

Minimum number of frames considered “ready” (pre-roll).

Definition at line 171 of file VideoCacheThread.h.

Referenced by isReady(), run(), and VideoCacheThread().

## reader

ReaderBase* openshot::VideoCacheThread::reader

protected

The source reader (e.g., Timeline, FFmpegReader).

Definition at line 174 of file VideoCacheThread.h.

Referenced by clearCacheIfPaused(), isReady(), prefetchWindow(), Reader(), run(), Seek(), and VideoCacheThread().

## requested_display_frame

int64_t openshot::VideoCacheThread::requested_display_frame

protected

Frame index the user requested.

Definition at line 167 of file VideoCacheThread.h.

Referenced by run(), Seek(), and VideoCacheThread().

## speed

int openshot::VideoCacheThread::speed

protected

Current playback speed (0=paused, >0 forward, <0 backward).

Definition at line 162 of file VideoCacheThread.h.

Referenced by computeDirection(), getSpeed(), run(), setSpeed(), and VideoCacheThread().

## timeline_max_frame

int64_t openshot::VideoCacheThread::timeline_max_frame

protected

Highest valid frame index in the timeline.

Definition at line 172 of file VideoCacheThread.h.

Referenced by VideoCacheThread().

## userSeeked

bool openshot::VideoCacheThread::userSeeked

protected

True if Seek(..., true) was called (forces a cache reset).

Definition at line 165 of file VideoCacheThread.h.

Referenced by prefetchWindow(), run(), Seek(), and VideoCacheThread().

The documentation for this class was generated from the following files:

- Qt/VideoCacheThread.h
- Qt/VideoCacheThread.cpp