diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-05-02 15:31:33 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-05-03 16:50:40 +0300 |
commit | c5fe16e121eefe5dd02cc9f9ba572053c383ccfa (patch) | |
tree | aa74a6fff290294220faf9c4a77aef4e17da250b /source/blender/windowmanager | |
parent | b4e1e0946bf124f95e1d9fa1a6ffa1cbc143c7d6 (diff) |
Sound: Make sound handles only be in evaluated datablocks
Quite straightforward change, which makes it so audio handles are
only created inside of evaluated datablocks.
Exception is adding sound strip to the sequencer, which needs an
audio handle to query length and number of channels. This is done
by temporarily loading sound file into an original datablock, and
then tossing it away.
There is an assert in sound.c which verifies that audio system is
used from an evaluated domain, which should help porting all the
cases which are likely missed by this commit.
Some annoying parts:
- `BKE_sound_update_scene()` is iterating over all bases, and does
special ID tags to see whether sound has been handled or not
already. This can not be done the old fashion now.
Ideally, this will be done as a speaker datablock evaluation,
but seems that would require a lock since audio API is not safe
for threading. So this is not a desired way i'd say.
Possible solution here would be to iterate over ID datablocks
using dependency graph query API.
- Frame jump needs to call `BKE_sound_seek_scene()` directly
because there might be some flags assigned to the scene which
could be clear after operator execution is over.
Need to verify if that's the case though. This is a bit hairy
code, so sticking to a safest and known to work approach for
now.
- Removed check for format when opening new sound file.
Maybe we can have some utility function which queries channel
and duration information, leaving the caller's code clean and
tidy.
Tested following cases:
- Adding/removing/moving sequencer's sound strips.
- Adding/moving speakers in viewport.
- Rendering audio.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D4779
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 6 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 28 |
2 files changed, 32 insertions, 2 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 13b6260e2b9..a13b28b7853 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -86,6 +86,7 @@ #include "RNA_enum_types.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" /* Motion in pixels allowed before we don't consider single/double click, * or detect the start of a tweak event. */ @@ -3090,10 +3091,12 @@ void wm_event_do_handlers(bContext *C) wm_event_free_all(win); } else { + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = WM_window_get_active_scene(win); + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); if (scene) { - int is_playing_sound = BKE_sound_scene_playing(scene); + const int is_playing_sound = BKE_sound_scene_playing(scene_eval); if (is_playing_sound != -1) { bool is_playing_screen; @@ -3113,7 +3116,6 @@ void wm_event_do_handlers(bContext *C) int ncfra = time * (float)FPS + 0.5f; if (ncfra != scene->r.cfra) { scene->r.cfra = ncfra; - Depsgraph *depsgraph = CTX_data_depsgraph(C); ED_update_for_newframe(CTX_data_main(C), depsgraph); WM_event_add_notifier(C, NC_WINDOW, NULL); } diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 97ba9190351..5529aec1aa5 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -64,6 +64,8 @@ #include "BKE_node.h" #include "BKE_report.h" #include "BKE_screen.h" +#include "BKE_scene.h" +#include "BKE_sound.h" #include "BKE_keyconfig.h" #include "BKE_addon.h" @@ -122,6 +124,7 @@ #include "COM_compositor.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "DRW_engine.h" @@ -194,6 +197,30 @@ void WM_init_opengl(Main *bmain) opengl_is_init = true; } +static void sound_jack_sync_callback(Main *bmain, int mode, float time) +{ + /* Ugly: Blender doesn't like it when the animation is played back during rendering. */ + if (G.is_rendering) { + return; + } + + wmWindowManager *wm = bmain->wm.first; + + for (wmWindow *window = wm->windows.first; window != NULL; window = window->next) { + Scene *scene = WM_window_get_active_scene(window); + if ((scene->audio.flag & AUDIO_SYNC) == 0) { + continue; + } + ViewLayer *view_layer = WM_window_get_active_view_layer(window); + Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, false); + if (depsgraph == NULL) { + continue; + } + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); + BKE_sound_jack_scene_update(scene_eval, mode, time); + } +} + /* only called once, for startup */ void WM_init(bContext *C, int argc, const char **argv) { @@ -201,6 +228,7 @@ void WM_init(bContext *C, int argc, const char **argv) if (!G.background) { wm_ghost_init(C); /* note: it assigns C to ghost! */ wm_init_cursor_data(); + BKE_sound_jack_sync_callback_set(sound_jack_sync_callback); } GHOST_CreateSystemPaths(); |