Sound: Move evaluation to dependency graph

The sound handles are still in the original datablocks, so it's easier
to test since there should be no functional changes.
This commit is contained in:
2019-05-01 15:57:16 +02:00
parent d02da8de23
commit 6990ef151c
5 changed files with 67 additions and 28 deletions

View File

@@ -240,6 +240,14 @@ void BKE_scene_cursor_quat_to_rot(struct View3DCursor *cursor,
const float quat[4],
bool use_compat);
/* Evaluation. */
/* Evaluate parts of sequences which needs to be done as a part of a dependency graph evaluation.
* This does NOT include actual rendering of the strips, but rather makes them up-to-date for
* animation playback and makes them ready for the sequencer's rendering pipeline to render them.
*/
void BKE_scene_eval_sequencer_sequences(struct Depsgraph *depsgraph, struct Scene *scene);
#ifdef __cplusplus
}
#endif

View File

@@ -154,4 +154,10 @@ float BKE_sound_get_length(struct bSound *sound);
char **BKE_sound_get_device_names(void);
/* Evaluation. */
struct Depsgraph;
void BKE_sound_evaluate(struct Depsgraph *depsgraph, struct Main *bmain, struct bSound *sound);
#endif /* __BKE_SOUND_H__ */

View File

@@ -1511,31 +1511,6 @@ static void scene_update_sound(Depsgraph *depsgraph, Main *bmain)
{
Scene *scene = DEG_get_input_scene(depsgraph);
BKE_sound_ensure_scene(scene);
/* Ensure audio for sound datablocks is loaded. */
for (bSound *sound = bmain->sounds.first; sound != NULL; sound = sound->id.next) {
bSound *sound_eval = (bSound *)DEG_get_evaluated_id(depsgraph, &sound->id);
if (sound_eval->playback_handle == NULL) {
BKE_sound_load(bmain, sound_eval);
}
}
/* Make sure sequencer audio is up to date. */
if (scene->ed != NULL) {
Sequence *seq;
bool something_loaded = false;
SEQ_BEGIN (scene->ed, seq) {
if (seq->sound != NULL && seq->scene_sound == NULL) {
printf("Loading sequencer sound\n");
seq->scene_sound = BKE_sound_add_scene_sound_defaults(scene, seq);
something_loaded = true;
}
}
SEQ_END;
if (something_loaded) {
BKE_sequencer_update_muting(scene->ed);
BKE_sequencer_update_sound_bounds_all(scene);
}
}
/* Update scene sound. */
BKE_sound_update_scene(bmain, scene);
}
@@ -2417,3 +2392,29 @@ void BKE_scene_cursor_quat_to_rot(View3DCursor *cursor, const float quat[4], boo
}
/** \} */
/* Evaluation. */
void BKE_scene_eval_sequencer_sequences(Depsgraph *depsgraph, Scene *scene)
{
DEG_debug_print_eval(depsgraph, __func__, scene->id.name, scene);
/* TODO(sergey): For now we keep sound handlers in an original IDs, but it
* should really be moved to an evaluated one. */
if (!DEG_is_active(depsgraph)) {
return;
}
Scene *scene_orig = (Scene *)DEG_get_original_id(&scene->id);
if (scene_orig->ed == NULL) {
return;
}
BKE_sound_ensure_scene(scene_orig);
Sequence *seq;
SEQ_BEGIN (scene_orig->ed, seq) {
if (seq->sound != NULL && seq->scene_sound == NULL) {
seq->scene_sound = BKE_sound_add_scene_sound_defaults(scene_orig, seq);
}
}
SEQ_END;
BKE_sequencer_update_muting(scene_orig->ed);
BKE_sequencer_update_sound_bounds_all(scene_orig);
}

View File

@@ -55,6 +55,9 @@
#include "BKE_sequencer.h"
#include "BKE_scene.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#ifdef WITH_AUDASPACE
/* evil globals ;-) */
static int sound_cfra;
@@ -1183,3 +1186,15 @@ void BKE_sound_ensure_loaded(Main *bmain, bSound *sound)
}
BKE_sound_load(bmain, sound);
}
void BKE_sound_evaluate(Depsgraph *depsgraph, Main *bmain, bSound *sound)
{
DEG_debug_print_eval(depsgraph, __func__, sound->id.name, sound);
/* TODO(sergey): For now we keep sound handlers in an original IDs, but it
* should really be moved to an evaluated one. */
if (!DEG_is_active(depsgraph)) {
return;
}
bSound *sound_orig = (bSound *)DEG_get_original_id(&sound->id);
BKE_sound_ensure_loaded(bmain, sound_orig);
}

View File

@@ -90,6 +90,7 @@ extern "C" {
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_rigidbody.h"
#include "BKE_scene.h"
#include "BKE_sequencer.h"
#include "BKE_shader_fx.h"
#include "BKE_sound.h"
@@ -1562,8 +1563,12 @@ void DepsgraphNodeBuilder::build_sound(bSound *sound)
if (built_map_.checkIsBuiltAndTag(sound)) {
return;
}
/* Placeholder so we can add relations and tag ID node for update. */
add_operation_node(&sound->id, NodeType::AUDIO, OperationCode::SOUND_EVAL);
add_id_node(&sound->id);
bSound *sound_cow = get_cow_datablock(sound);
add_operation_node(&sound->id,
NodeType::AUDIO,
OperationCode::SOUND_EVAL,
function_bind(BKE_sound_evaluate, _1, bmain_, sound_cow));
build_animdata(&sound->id);
build_parameters(&sound->id);
}
@@ -1573,7 +1578,11 @@ void DepsgraphNodeBuilder::build_sequencer(Scene *scene)
if (scene->ed == NULL) {
return;
}
add_operation_node(&scene->id, NodeType::SEQUENCER, OperationCode::SEQUENCES_EVAL);
Scene *scene_cow = get_cow_datablock(scene_);
add_operation_node(&scene->id,
NodeType::SEQUENCER,
OperationCode::SEQUENCES_EVAL,
function_bind(BKE_scene_eval_sequencer_sequences, _1, scene_cow));
/* Make sure data for sequences is in the graph. */
Sequence *seq;
SEQ_BEGIN (scene->ed, seq) {