Blender  V3.3
sequence_lookup.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. All rights reserved. */
3 
8 #include "SEQ_sequencer.h"
9 #include "sequencer.h"
10 
11 #include "DNA_listBase.h"
12 #include "DNA_scene_types.h"
13 #include "DNA_sequence_types.h"
14 
15 #include "SEQ_iterator.h"
16 
17 #include "BLI_ghash.h"
18 #include "BLI_listbase.h"
19 #include "BLI_string.h"
20 #include "BLI_sys_types.h"
21 #include "BLI_threads.h"
22 #include <string.h>
23 
24 #include "MEM_guardedalloc.h"
25 
27 
28 typedef struct SequenceLookup {
34 
36 {
37  lookup->seq_by_name = BLI_ghash_str_new(__func__);
38  lookup->meta_by_seq = BLI_ghash_ptr_new(__func__);
39  lookup->effects_by_seq = BLI_ghash_ptr_new(__func__);
41 }
42 
44  Sequence *effect,
45  struct SequenceLookup *lookup)
46 {
47  if (input == NULL) {
48  return;
49  }
50 
51  SeqCollection *effects = BLI_ghash_lookup(lookup->effects_by_seq, input);
52  if (effects == NULL) {
53  effects = SEQ_collection_create(__func__);
54  BLI_ghash_insert(lookup->effects_by_seq, input, effects);
55  }
56 
57  SEQ_collection_append_strip(effect, effects);
58 }
59 
61 {
62  if ((seq->type & SEQ_TYPE_EFFECT) == 0) {
63  return;
64  }
65 
68 }
69 
71  const ListBase *seqbase,
72  struct SequenceLookup *lookup)
73 {
74  LISTBASE_FOREACH (Sequence *, seq, seqbase) {
75  BLI_ghash_insert(lookup->seq_by_name, seq->name + 2, seq);
76  BLI_ghash_insert(lookup->meta_by_seq, seq, parent_meta);
78 
79  if (seq->type == SEQ_TYPE_META) {
81  }
82  }
83 }
84 
85 static void seq_sequence_lookup_build(const struct Scene *scene, struct SequenceLookup *lookup)
86 {
90 }
91 
93 {
94  SequenceLookup *lookup = MEM_callocN(sizeof(SequenceLookup), __func__);
96  return lookup;
97 }
98 
100 {
101  if (*lookup == NULL) {
102  return;
103  }
104 
105  BLI_ghash_free((*lookup)->seq_by_name, NULL, NULL);
106  BLI_ghash_free((*lookup)->meta_by_seq, NULL, NULL);
107  BLI_ghash_free((*lookup)->effects_by_seq, NULL, SEQ_collection_free_void_p);
108  (*lookup)->seq_by_name = NULL;
109  (*lookup)->meta_by_seq = NULL;
110  (*lookup)->effects_by_seq = NULL;
111  MEM_freeN(*lookup);
112  *lookup = NULL;
113 }
114 
115 static void seq_sequence_lookup_rebuild(const struct Scene *scene, struct SequenceLookup **lookup)
116 {
120 }
121 
123 {
124  return (lookup->tag & SEQ_LOOKUP_TAG_INVALID) == 0;
125 }
126 
128  struct SequenceLookup **lookup)
129 {
130  if (!scene->ed) {
131  return;
132  }
134  return;
135  }
136 
138 }
139 
141 {
142  BLI_assert(scene->ed);
147 }
148 
150 {
151  BLI_assert(scene->ed);
155  Sequence *seq = BLI_ghash_lookup(lookup->seq_by_name, key);
157  return seq;
158 }
159 
161 {
162  BLI_assert(scene->ed);
166  Sequence *seq = BLI_ghash_lookup(lookup->meta_by_seq, key);
168  return seq;
169 }
170 
172 {
173  BLI_assert(scene->ed);
177  SeqCollection *effects = BLI_ghash_lookup(lookup->effects_by_seq, key);
179  return effects;
180 }
181 
183 {
184  if (!scene->ed) {
185  return;
186  }
187 
190  if (lookup != NULL) {
191  lookup->tag |= tag;
192  }
194 }
#define BLI_assert(a)
Definition: BLI_assert.h:46
GHash * BLI_ghash_str_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:734
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:710
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:863
GHash * BLI_ghash_ptr_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define BLI_MUTEX_INITIALIZER
Definition: BLI_threads.h:83
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:373
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:378
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:82
These structs are the foundation for all linked lists in the library system.
@ SEQ_TYPE_META
@ SEQ_TYPE_EFFECT
Read Guarded memory(de)allocation.
#define SEQ_collection_free_void_p
Definition: SEQ_iterator.h:135
eSequenceLookupTag
@ SEQ_LOOKUP_TAG_INVALID
Scene scene
SeqCollection * SEQ_collection_create(const char *name)
Definition: iterator.c:87
bool SEQ_collection_append_strip(Sequence *seq, SeqCollection *collection)
Definition: iterator.c:117
ccl_global KernelShaderEvalInput * input
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
GAttributeReader lookup(const void *owner, const AttributeIDRef &attribute_id)
static void seq_sequence_lookup_build_effect(Sequence *seq, struct SequenceLookup *lookup)
Sequence * SEQ_sequence_lookup_seq_by_name(const Scene *scene, const char *key)
static void seq_sequence_lookup_init(struct SequenceLookup *lookup)
struct SequenceLookup SequenceLookup
static bool seq_sequence_lookup_is_valid(const struct SequenceLookup *lookup)
static SequenceLookup * seq_sequence_lookup_new(void)
static void seq_sequence_lookup_build_from_seqbase(Sequence *parent_meta, const ListBase *seqbase, struct SequenceLookup *lookup)
static void seq_sequence_lookup_append_effect(Sequence *input, Sequence *effect, struct SequenceLookup *lookup)
static void seq_sequence_lookup_free(struct SequenceLookup **lookup)
SeqCollection * seq_sequence_lookup_effects_by_seq(const Scene *scene, const Sequence *key)
void SEQ_sequence_lookup_free(const Scene *scene)
static void seq_sequence_lookup_rebuild(const struct Scene *scene, struct SequenceLookup **lookup)
static void seq_sequence_lookup_build(const struct Scene *scene, struct SequenceLookup *lookup)
static ThreadMutex lookup_lock
Sequence * seq_sequence_lookup_meta_by_seq(const Scene *scene, const Sequence *key)
static void seq_sequence_lookup_update_if_needed(const struct Scene *scene, struct SequenceLookup **lookup)
void SEQ_sequence_lookup_tag(const Scene *scene, eSequenceLookupTag tag)
Editing * SEQ_editing_get(const Scene *scene)
Definition: sequencer.c:241
struct SequenceLookup * sequence_lookup
ListBase seqbase
EditingRuntime runtime
struct Editing * ed
GHash * effects_by_seq
eSequenceLookupTag tag
struct Sequence * seq1
struct Sequence * seq2