101 void invalidate(
const std::string &source_filepath);
125 if (oldest_index == -1) {
151 const std::optional<int> view_id)
159 const bool use_multiview = view_id.has_value() && (strip.flag &
SEQ_USE_VIEWS) != 0 &&
163 const char *suffix =
nullptr;
165 scene, filepath, *view_id, filepath_view,
sizeof(filepath_view), &suffix))
184 const int frame_index,
195 int best_score = std::numeric_limits<int>::max();
198 for (
const std::unique_ptr<MovieReaderCacheEntry> &candidate :
entries_) {
199 if (candidate->is_accessed || candidate->invalidated || candidate->owner != owner ||
204 const int distance = frame_index - candidate->frame_index;
206 if (score < best_score) {
207 best = candidate.get();
212 if (best ==
nullptr) {
216 auto entry = std::make_unique<MovieReaderCacheEntry>();
218 entry->owner = owner;
239 bool best_is_initialized =
false;
240 for (
const std::unique_ptr<MovieReaderCacheEntry> &candidate :
entries_) {
241 if (candidate->is_accessed || candidate->invalidated || !(candidate->key == key)) {
244 const bool candidate_is_initialized = candidate->reader !=
nullptr &&
246 if (best ==
nullptr || (candidate_is_initialized && !best_is_initialized) ||
247 (candidate_is_initialized == best_is_initialized &&
250 best = candidate.get();
251 best_is_initialized = candidate_is_initialized;
255 if (best ==
nullptr) {
256 auto entry = std::make_unique<MovieReaderCacheEntry>();
272 std::lock_guard failure_lock(
mutex_);
280 if (entry.
reader !=
nullptr) {
291 if (entry.
reader ==
nullptr) {
309 if (entry.
reader ==
nullptr) {
317 if (ibuf ==
nullptr) {
371 : cache_(cache), entry_(entry)
376 : cache_(other.cache_), entry_(other.entry_)
378 other.cache_ =
nullptr;
379 other.entry_ =
nullptr;
384 if (
this != &other) {
386 cache_ = other.cache_;
387 entry_ = other.entry_;
388 other.cache_ =
nullptr;
389 other.entry_ =
nullptr;
399void MovieReaderAccessor::release()
401 if (cache_ !=
nullptr) {
408MovieReaderAccessor::operator bool()
const
410 return entry_ !=
nullptr && entry_->reader !=
nullptr;
416 if (ibuf !=
nullptr) {
417 entry_->frame_index = frame_index;
424 return entry_ !=
nullptr && !entry_->key.multiview_filepath.empty();
429 return entry_ ? entry_->reader :
nullptr;
434 return entry_ ? entry_->reader :
nullptr;
438 const Scene &key_scene,
440 const int frame_index)
447 const Scene &key_scene,
450 const int frame_index)
483 const bool use_multiview = (strip.flag &
SEQ_USE_VIEWS) != 0 &&
488 if (files_num <= 0) {
494 return bool(primary_reader);
497 bool all_readers_open = bool(primary_reader);
498 readers.
append(std::move(primary_reader));
499 for (
int view_id = 1; view_id < files_num && all_readers_open; view_id++) {
501 all_readers_open = bool(readers.
last());
503 if (all_readers_open) {
512 return MEM_new<MovieReaderCache>(__func__);
#define BLI_path_join(...)
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
Read Blender memory allocation and freeing.
void append(const T &value)
const T & last(const int64_t n=0) const
const T & data(const Action &owning_action) const
MovieReaderAccessor & operator=(const MovieReaderAccessor &)=delete
ImBuf * decode_frame(int frame_index, IMB_Proxy_Size proxy_size)
MovieReaderAccessor()=default
bool uses_multiview_filepath() const
float distance(float, float) RET
static std::atomic< int > next_owner
MovieReaderAccessor movie_reader_cache_acquire_view(Scene &cache_scene, const Scene &key_scene, const Strip &strip, const int view_id, const int frame_index)
void movie_reader_cache_timestamp_bump()
void movie_reader_cache_clear(Scene &scene)
static void movie_reader_source_filepath_get(const Scene &scene, const Strip &strip, char r_filepath[FILE_MAX])
static uint64_t current_owner_get()
MovieReaderAccessor movie_reader_cache_acquire_any(const Scene &scene, const Strip &strip)
void movie_reader_cache_invalidate(Scene &scene, const Strip &strip)
int seq_multiview_num_files_get(const Scene *scene, eImageFormat_ViewsFormat views_format)
void seq_proxy_index_dir_set(MovieReader *anim, const char *base_dir)
bool seq_multiview_view_filepath_get(const Scene &scene, const char *filepath, const int view_id, char *r_filepath, const size_t r_filepath_maxncpy, const char **r_suffix)
static MovieReaderAccessor movie_reader_cache_acquire_any_view(const Scene &scene, const Strip &strip, const int view_id)
MovieReaderCache * movie_reader_cache_create()
static MovieReaderAccessor movie_reader_cache_acquire_any_base(const Scene &scene, const Strip &strip)
static uint64_t current_timestamp
static MovieReaderKey movie_reader_key_get(const Scene &scene, const Strip &strip, const std::optional< int > view_id)
static std::atomic< uint64_t > next_timestamp
bool seq_proxy_get_custom_dir(const Editing &ed, const Strip &strip, char r_dirpath[FILE_MAX])
MovieReaderAccessor movie_reader_cache_acquire(Scene &cache_scene, const Scene &key_scene, const Strip &strip, const int frame_index)
bool movie_reader_cache_can_produce_frames(const Scene &scene, const Strip &strip)
void movie_reader_cache_destroy(MovieReaderCache *cache)
bool MOV_is_initialized_and_valid(const MovieReader *anim)
unsigned __int64 uint64_t
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
void MOV_close(MovieReader *anim)
ImBuf * MOV_decode_frame(MovieReader *anim, int frame_index, IMB_Proxy_Size preview_size)
void MOV_set_multiview_suffix(MovieReader *anim, const char *suffix)
MovieReader * MOV_open_file(const char *filepath, const ImBufFlags ib_flags, const int streamindex, const bool keep_original_colorspace, ColorManagedColorspaceSettings *colorspace_settings)
void IMB_freeImBuf(ImBuf *ibuf)
void IMB_colormanagement_colorspace_settings_set(ColorManagedColorspaceSettings *settings, const char *name)
seq::EditingRuntime * runtime
MovieReaderCache * movie_reader_cache
void invalidate(const std::string &source_filepath)
MovieReaderCache()=default
MovieReaderAccessor acquire(const MovieReaderKey &key, int frame_index, uint64_t timestamp)
Vector< std::unique_ptr< MovieReaderCacheEntry > > entries_
void release(MovieReaderCacheEntry &entry)
void remove_excess_entries()
static constexpr int64_t max_entries
~MovieReaderCache()=default
uint64_t timestamp_counter_
void reader_open(MovieReaderCacheEntry &entry)
MovieReaderAccessor acquire_any(const MovieReaderKey &key)
static constexpr int backward_seek_penalty
bool remove_oldest_stale_entry()
static constexpr uint64_t stale_after_timestamps
bool reader_ensure_initialized(MovieReaderCacheEntry &entry)
bool operator==(const MovieReaderKey &other) const =default
std::string multiview_suffix
std::string multiview_filepath
std::string source_filepath