Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2019-05-01 16:12:38 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2019-05-03 16:50:40 +0300
commitd02da8de23b1d5f64695d3e7e91384d5e2f24e4c (patch)
treebe0dbaad0ab75d068b5384e19096e7abd1bc8df4 /source/blender/blenkernel
parent3369b8289167ddf3dbca0e3895d598bf73534124 (diff)
Sound: Delay opening handlers for until really needed
Needs to be done in order to localize sound handlers to the evaluated IDs only. This commit might not be fully optimal, since it does more things on every scene update request, but that will be solved by the upcoming change which will put those updates to a dependency graph.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_sound.h4
-rw-r--r--source/blender/blenkernel/intern/scene.c52
-rw-r--r--source/blender/blenkernel/intern/sequencer.c5
-rw-r--r--source/blender/blenkernel/intern/sound.c32
4 files changed, 76 insertions, 17 deletions
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index 91e23d35f0e..b35a0fd16f5 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -71,7 +71,9 @@ void BKE_sound_cache(struct bSound *sound);
void BKE_sound_delete_cache(struct bSound *sound);
+void BKE_sound_reset_pointers(struct bSound *sound);
void BKE_sound_load(struct Main *main, struct bSound *sound);
+void BKE_sound_ensure_loaded(struct Main *bmain, struct bSound *sound);
void BKE_sound_free(struct bSound *sound);
@@ -86,7 +88,9 @@ void BKE_sound_make_local(struct Main *bmain, struct bSound *sound, const bool l
AUD_Device *BKE_sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume);
#endif
+void BKE_sound_reset_scene_pointers(struct Scene *scene);
void BKE_sound_create_scene(struct Scene *scene);
+void BKE_sound_ensure_scene(struct Scene *scene);
void BKE_sound_destroy_scene(struct Scene *scene);
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 714261ce4ab..e9772a14829 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -37,6 +37,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_sequence_types.h"
+#include "DNA_sound_types.h"
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
#include "DNA_windowmanager_types.h"
@@ -308,8 +309,7 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons
flag_subdata);
}
- /* before scene copy */
- BKE_sound_create_scene(sce_dst);
+ BKE_sound_reset_scene_pointers(sce_dst);
/* Copy sequencer, this is local data! */
if (sce_src->ed) {
@@ -399,8 +399,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
sce_copy->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties);
}
- /* before scene copy */
- BKE_sound_create_scene(sce_copy);
+ BKE_sound_reset_scene_pointers(sce_copy);
/* grease pencil */
sce_copy->gpd = NULL;
@@ -780,7 +779,7 @@ void BKE_scene_init(Scene *sce)
srv = sce->r.views.last;
BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
- BKE_sound_create_scene(sce);
+ BKE_sound_reset_scene_pointers(sce);
/* color management */
colorspace_name = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_SEQUENCER);
@@ -1508,6 +1507,38 @@ static void prepare_mesh_for_viewport_render(Main *bmain, const ViewLayer *view_
}
}
+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);
+}
+
/* TODO(sergey): This actually should become view_layer_graph or so.
* Same applies to update_for_newframe.
*/
@@ -1536,10 +1567,9 @@ void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain)
* by depgraph or manual, no layer check here, gets correct flushed.
*/
DEG_evaluate_on_refresh(depsgraph);
- /* Update sound system animation (TODO, move to depsgraph). */
- BKE_sound_update_scene(bmain, scene);
-
- /* Notify python about depsgraph update */
+ /* Update sound system. */
+ scene_update_sound(depsgraph, bmain);
+ /* Notify python about depsgraph update. */
if (run_callbacks) {
BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_DEPSGRAPH_UPDATE_POST);
}
@@ -1574,8 +1604,8 @@ void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph, Main *bmain)
* by depgraph or manual, no layer check here, gets correct flushed.
*/
DEG_evaluate_on_framechange(bmain, depsgraph, ctime);
- /* Update sound system animation (TODO, move to depsgraph). */
- BKE_sound_update_scene(bmain, scene);
+ /* Update sound system animation. */
+ scene_update_sound(depsgraph, bmain);
/* Notify editors and python about recalc. */
BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_POST);
/* Inform editors about possible changes. */
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 9035c7ff1ac..f593713b79c 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -5747,10 +5747,7 @@ static Sequence *seq_dupli(const Scene *scene_src,
}
else if (seq->type == SEQ_TYPE_SOUND_RAM) {
seqn->strip->stripdata = MEM_dupallocN(seq->strip->stripdata);
- if (seq->scene_sound) {
- seqn->scene_sound = BKE_sound_add_scene_sound_defaults(scene_dst, seqn);
- }
-
+ seqn->scene_sound = NULL;
if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
id_us_plus((ID *)seqn->sound);
}
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index c97baf8f7dd..3b46677828d 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -463,8 +463,6 @@ void BKE_sound_load(Main *bmain, bSound *sound)
else {
sound->playback_handle = sound->handle;
}
-
- BKE_sound_update_sequencer(bmain, sound);
}
}
@@ -1155,3 +1153,33 @@ char **BKE_sound_get_device_names(void)
}
#endif /* WITH_AUDASPACE */
+
+void BKE_sound_reset_scene_pointers(Scene *scene)
+{
+ scene->sound_scene = NULL;
+ scene->playback_handle = NULL;
+ scene->sound_scrub_handle = NULL;
+ scene->speaker_handles = NULL;
+}
+
+void BKE_sound_ensure_scene(struct Scene *scene)
+{
+ if (scene->sound_scene != NULL) {
+ return;
+ }
+ BKE_sound_create_scene(scene);
+}
+
+void BKE_sound_reset_pointers(bSound *sound)
+{
+ sound->cache = NULL;
+ sound->playback_handle = NULL;
+}
+
+void BKE_sound_ensure_loaded(Main *bmain, bSound *sound)
+{
+ if (sound->cache != NULL) {
+ return;
+ }
+ BKE_sound_load(bmain, sound);
+}