[Bf-blender-cvs] [d02da8de23b] master: Sound: Delay opening handlers for until really needed

Sergey Sharybin noreply at git.blender.org
Fri May 3 15:52:45 CEST 2019


Commit: d02da8de23b1d5f64695d3e7e91384d5e2f24e4c
Author: Sergey Sharybin
Date:   Wed May 1 15:12:38 2019 +0200
Branches: master
https://developer.blender.org/rBd02da8de23b1d5f64695d3e7e91384d5e2f24e4c

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.

===================================================================

M	source/blender/blenkernel/BKE_sound.h
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/sequencer.c
M	source/blender/blenkernel/intern/sound.c
M	source/blender/blenloader/intern/readfile.c

===================================================================

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);
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 7f62369647a..3326e2c02dc 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6488,7 +6488,7 @@ static void lib_link_scene(FileData *fd, Main *main)
           }
           if (seq->sound) {
             id_us_plus_no_lib((ID *)seq->sound);
-            seq->scene_sound = BKE_sound_add_scene_sound_defaults(sce, seq);
+            seq->scene_sound = NULL;
           }
         }
         if (seq->type == SEQ_TYPE_TEXT) {
@@ -6507,9 +6507,6 @@ static void lib_link_scene(FileData *fd, Main *main)
         }
       }
 
-      BKE_sequencer_update_muting(sce->ed);
-      BKE_sequencer_update_sound_bounds_all(sce);
-
       /* rigidbody world relies on it's linked collections */
       if (sce->rigidbody_world) {
         RigidBodyWorld *rbw = sce->rigidbody_world;
@@ -6681,7 +6678,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
   memset(&sce->customdata_mask, 0, sizeof(sce->customdata_mask));
   memset(&sce->customdata_mask_modal, 0, sizeof(sce->customdata_mask_modal));
 
-  BKE_sound_create_scene(sce);
+  BKE_sound_reset_scene_pointers(sce);
 
   /* set users to one by default, not in lib-link, this will increase it for compo nodes */
   id_us_ensure_real(&sce->id);
@@ -8426,7 +8423,7 @@ static void lib_link_sound(FileData *fd, Main *main)
       sound->ipo = newlibadr_us(
           fd, sound->id.lib, sound->ipo);  // XXX deprecated - old animation system
 
-      BKE_sound_load(main, sound);
+      BKE_sound_reset_pointers(sound);
 
       sound->id.tag &= ~LIB_TAG_NEED_LINK;
     }



More information about the Bf-blender-cvs mailing list