VSE: don't add crop and transform data for sound strips

This also fixes commit rB1fd7b380f4cf8a0489b405de2819f228a4da5ea2 which
didn't do allocation for effect strips properly.

Reviewed By: brecht, campbellbarton

Differential Revision: https://developer.blender.org/D4970
This commit is contained in:
Richard Antalik 2019-05-30 15:19:02 -07:00
parent fc336f973d
commit 7ccc7ef61f
Notes: blender-bot 2023-02-14 03:46:57 +01:00
Referenced by issue #69440, VSE: Memory leak adding strips via python
6 changed files with 34 additions and 57 deletions

View File

@ -459,7 +459,7 @@ typedef struct SeqLoadInfo {
/* use as an api function */
typedef struct Sequence *(*SeqLoadFunc)(struct bContext *, ListBase *, struct SeqLoadInfo *);
struct Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine);
struct Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine, int type);
void BKE_sequence_alpha_mode_from_extension(struct Sequence *seq);
void BKE_sequence_init_colorspace(struct Sequence *seq);

View File

@ -5353,16 +5353,20 @@ static void seq_load_apply(Main *bmain, Scene *scene, Sequence *seq, SeqLoadInfo
}
}
static Strip *seq_strip_alloc(void)
static Strip *seq_strip_alloc(int type)
{
Strip *strip = MEM_callocN(sizeof(Strip), "strip");
strip->transform = MEM_callocN(sizeof(struct StripTransform), "StripTransform");
strip->crop = MEM_callocN(sizeof(struct StripCrop), "StripCrop");
if (ELEM(type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD) == 0) {
strip->transform = MEM_callocN(sizeof(struct StripTransform), "StripTransform");
strip->crop = MEM_callocN(sizeof(struct StripCrop), "StripCrop");
}
strip->us = 1;
return strip;
}
Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine)
Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine, int type)
{
Sequence *seq;
@ -5381,7 +5385,9 @@ Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine)
seq->volume = 1.0f;
seq->pitch = 1.0f;
seq->scene_sound = NULL;
seq->type = type;
seq->strip = seq_strip_alloc(type);
seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Sequence Stereo Format");
seq->cache_flag = SEQ_CACHE_ALL_TYPES;
@ -5465,15 +5471,13 @@ Sequence *BKE_sequencer_add_image_strip(bContext *C, ListBase *seqbasep, SeqLoad
Sequence *seq;
Strip *strip;
seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel);
seq->type = SEQ_TYPE_IMAGE;
seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel, SEQ_TYPE_IMAGE);
seq->blend_mode = SEQ_TYPE_ALPHAOVER;
/* basic defaults */
seq->strip = strip = seq_strip_alloc();
seq->len = seq_load->len ? seq_load->len : 1;
strip->us = 1;
strip = seq->strip;
strip->stripdata = MEM_callocN(seq->len * sizeof(StripElem), "stripelem");
BLI_strncpy(strip->dir, seq_load->path, sizeof(strip->dir));
@ -5517,19 +5521,16 @@ Sequence *BKE_sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoad
return NULL;
}
seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel);
seq->type = SEQ_TYPE_SOUND_RAM;
seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel, SEQ_TYPE_SOUND_RAM);
seq->sound = sound;
BLI_strncpy(seq->name + 2, "Sound", SEQ_NAME_MAXSTR - 2);
BKE_sequence_base_unique_name_recursive(&scene->ed->seqbase, seq);
/* basic defaults */
seq->strip = strip = seq_strip_alloc();
/* We add a very small negative offset here, because
* ceil(132.0) == 133.0, not nice with videos, see T47135. */
seq->len = (int)ceil((double)info.length * FPS - 1e-4);
strip->us = 1;
strip = seq->strip;
/* we only need 1 element to store the filename */
strip->stripdata = se = MEM_callocN(sizeof(StripElem), "stripelem");
@ -5622,7 +5623,7 @@ Sequence *BKE_sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoad
}
}
seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel);
seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel, SEQ_TYPE_MOVIE);
/* multiview settings */
if (seq_load->stereo3d_format) {
@ -5630,8 +5631,6 @@ Sequence *BKE_sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoad
seq->views_format = seq_load->views_format;
}
seq->flag |= seq_load->flag & SEQ_USE_VIEWS;
seq->type = SEQ_TYPE_MOVIE;
seq->blend_mode = SEQ_TYPE_ALPHAOVER;
for (i = 0; i < totfiles; i++) {
@ -5657,9 +5656,8 @@ Sequence *BKE_sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoad
}
/* basic defaults */
seq->strip = strip = seq_strip_alloc();
seq->len = IMB_anim_get_duration(anim_arr[0], IMB_TC_RECORD_RUN);
strip->us = 1;
strip = seq->strip;
BLI_strncpy(seq->strip->colorspace_settings.name,
colorspace,

View File

@ -718,16 +718,18 @@ static void do_version_constraints_copy_scale_power(ListBase *lb)
static void do_versions_seq_alloc_transform_and_crop(ListBase *seqbase)
{
for (Sequence *seq = seqbase->first; seq != NULL; seq = seq->next) {
if (seq->strip->transform == NULL) {
seq->strip->transform = MEM_callocN(sizeof(struct StripTransform), "StripTransform");
}
if (ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD) == 0) {
if (seq->strip->transform == NULL) {
seq->strip->transform = MEM_callocN(sizeof(struct StripTransform), "StripTransform");
}
if (seq->strip->crop == NULL) {
seq->strip->crop = MEM_callocN(sizeof(struct StripCrop), "StripCrop");
}
if (seq->strip->crop == NULL) {
seq->strip->crop = MEM_callocN(sizeof(struct StripCrop), "StripCrop");
}
if (seq->seqbase.first != NULL) {
do_versions_seq_alloc_transform_and_crop(&seq->seqbase);
if (seq->seqbase.first != NULL) {
do_versions_seq_alloc_transform_and_crop(&seq->seqbase);
}
}
}
}

View File

@ -318,7 +318,6 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op)
Scene *sce_seq;
Sequence *seq; /* generic strip vars */
Strip *strip;
int start_frame, channel; /* operator props */
@ -332,16 +331,13 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel);
seq->type = SEQ_TYPE_SCENE;
seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel, SEQ_TYPE_SCENE);
seq->blend_mode = SEQ_TYPE_ALPHAOVER;
seq->scene = sce_seq;
/* basic defaults */
seq->strip = strip = MEM_callocN(sizeof(Strip), "strip");
seq->len = sce_seq->r.efra - sce_seq->r.sfra + 1;
strip->us = 1;
BLI_strncpy(seq->name + 2, sce_seq->id.name + 2, sizeof(seq->name) - 2);
BKE_sequence_base_unique_name_recursive(&ed->seqbase, seq);
@ -406,7 +402,6 @@ static int sequencer_add_movieclip_strip_exec(bContext *C, wmOperator *op)
MovieClip *clip;
Sequence *seq; /* generic strip vars */
Strip *strip;
int start_frame, channel; /* operator props */
@ -420,17 +415,14 @@ static int sequencer_add_movieclip_strip_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel);
seq->type = SEQ_TYPE_MOVIECLIP;
seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel, SEQ_TYPE_MOVIECLIP);
seq->blend_mode = SEQ_TYPE_ALPHAOVER;
seq->clip = clip;
id_us_ensure_real(&seq->clip->id);
/* basic defaults */
seq->strip = strip = MEM_callocN(sizeof(Strip), "strip");
seq->len = BKE_movieclip_get_duration(clip);
strip->us = 1;
BLI_strncpy(seq->name + 2, clip->id.name + 2, sizeof(seq->name) - 2);
BKE_sequence_base_unique_name_recursive(&ed->seqbase, seq);
@ -492,7 +484,6 @@ static int sequencer_add_mask_strip_exec(bContext *C, wmOperator *op)
Mask *mask;
Sequence *seq; /* generic strip vars */
Strip *strip;
int start_frame, channel; /* operator props */
@ -506,17 +497,14 @@ static int sequencer_add_mask_strip_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel);
seq->type = SEQ_TYPE_MASK;
seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel, SEQ_TYPE_MASK);
seq->blend_mode = SEQ_TYPE_ALPHAOVER;
seq->mask = mask;
id_us_ensure_real(&seq->mask->id);
/* basic defaults */
seq->strip = strip = MEM_callocN(sizeof(Strip), "strip");
seq->len = BKE_mask_get_duration(mask);
strip->us = 1;
BLI_strncpy(seq->name + 2, mask->id.name + 2, sizeof(seq->name) - 2);
BKE_sequence_base_unique_name_recursive(&ed->seqbase, seq);
@ -1041,7 +1029,6 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op)
Editing *ed = BKE_sequencer_editing_get(scene, true);
Sequence *seq; /* generic strip vars */
Strip *strip;
struct SeqEffectHandle sh;
int start_frame, end_frame, channel, type; /* operator props */
@ -1068,8 +1055,7 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel);
seq->type = type;
seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel, type);
BLI_strncpy(seq->name + 2, BKE_sequence_give_name(seq), sizeof(seq->name) - 2);
BKE_sequence_base_unique_name_recursive(&ed->seqbase, seq);
@ -1091,10 +1077,6 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op)
BKE_sequence_calc(scene, seq);
/* basic defaults */
seq->strip = strip = MEM_callocN(sizeof(Strip), "strip");
strip->us = 1;
if (seq->type == SEQ_TYPE_COLOR) {
SolidColorVars *colvars = (SolidColorVars *)seq->effectdata;
RNA_float_get_array(op->ptr, "color", colvars->col);

View File

@ -2660,9 +2660,8 @@ static int sequencer_meta_make_exec(bContext *C, wmOperator *op)
/* remove all selected from main list, and put in meta */
seqm = BKE_sequence_alloc(ed->seqbasep, 1, 1); /* channel number set later */
seqm = BKE_sequence_alloc(ed->seqbasep, 1, 1, SEQ_TYPE_META); /* channel number set later */
strcpy(seqm->name + 2, "MetaStrip");
seqm->type = SEQ_TYPE_META;
seqm->flag = SELECT;
seq = ed->seqbasep->first;
@ -2679,9 +2678,6 @@ static int sequencer_meta_make_exec(bContext *C, wmOperator *op)
seqm->machine = last_seq ? last_seq->machine : channel_max;
BKE_sequence_calc(scene, seqm);
seqm->strip = MEM_callocN(sizeof(Strip), "metastrip");
seqm->strip->us = 1;
BKE_sequencer_active_set(scene, seqm);
if (BKE_sequence_test_overlap(ed->seqbasep, seqm)) {

View File

@ -81,8 +81,7 @@ static Sequence *alloc_generic_sequence(
Strip *strip;
StripElem *se;
seq = BKE_sequence_alloc(ed->seqbasep, frame_start, channel);
seq->type = type;
seq = BKE_sequence_alloc(ed->seqbasep, frame_start, channel, type);
BLI_strncpy(seq->name + 2, name, sizeof(seq->name) - 2);
BKE_sequence_base_unique_name_recursive(&ed->seqbase, seq);