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-07 12:30:00 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2019-05-07 12:50:38 +0300
commit2b9965122e132a2c25652ebf62d6353183f0f644 (patch)
tree776af5327831e6e680e7e911e5ee16114a665740 /source/blender/blenkernel/intern/sound.c
parent90a9ff44083e29b4a9f557a6e039099a7115f5db (diff)
Sound: Revert all the recent changes to sound
This happened to be a bigger rabbit hole to hell than it originally seemed, and there are higher priority design tasks to be handled (at this point high priority design task is more important than high priority bug fix). After talking to Brecht the decision was made to revert to the known isolated issue, which will allow everyone in the studio work same as prior to last Friday. The remaining bits will be worked on after all the design tasks are out of the way. This commit reverts: 4cdb4b9532c Fix T64161: Crashing using undo and multiple windows 064273a4ae7 Sound: Port more cases to be a part of dependency graph 2e582f8ab53 Sound: Fix access wrong dependency graph 5fc49d9c915 Sound: add stubs to build without audaspace c68c81a870b Sound: Make sure spin lock is initialized for new sound datablocks c02534469ac Sound: Delay creating sound scene handle for until is needed 9f681bea68f Fix T64144: Crash when displaying audio waveforms in VSE 2f79286453e Cleanup: unused vars bed8ad6f95a Fix crash in background rendering after recent sound changes 773691310f9 Fix T64143: Crash when scrubbing in the graph editor 888852055c1 Sound: Fix for being unable to jump to a frame during playback with A/V sync 6ab7b384645 Sound: More fixes for access of original scene 35db1195455 Sound: Fix access original scene during playback 211c4fd2e9a Depsgraph: Make comment about evaluation more obvious c5fe16e121e Sound: Make sound handles only be in evaluated datablocks b4e1e0946bf Depsgraph: Preserve sound and audio pointers through copy-on-write 4eedf784b04 Depsgraph: Store original sequencer strip pointer 6990ef151c1 Sound: Move evaluation to dependency graph d02da8de23b Sound: Delay opening handlers for until really needed 3369b828916 Depsgraph: Add scene audio component e8f10d64757 Depsgraph: Tag sequencer for update on changes 6e4b7a6e4d9 Depsgraph: Initial work to cover sequencer 17447ac5a6b Depsgraph: Make sound ID part of the graph
Diffstat (limited to 'source/blender/blenkernel/intern/sound.c')
-rw-r--r--source/blender/blenkernel/intern/sound.c311
1 files changed, 87 insertions, 224 deletions
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index f45c53426b9..c97baf8f7dd 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -38,7 +38,6 @@
#include "DNA_screen_types.h"
#include "DNA_sound_types.h"
#include "DNA_speaker_types.h"
-#include "DNA_windowmanager_types.h"
#ifdef WITH_AUDASPACE
# include <AUD_Sound.h>
@@ -56,36 +55,12 @@
#include "BKE_sequencer.h"
#include "BKE_scene.h"
-#include "DEG_depsgraph.h"
-
#ifdef WITH_AUDASPACE
/* evil globals ;-) */
static int sound_cfra;
static char **audio_device_names = NULL;
#endif
-BLI_INLINE void sound_verify_evaluated_id(ID *id)
-{
- UNUSED_VARS_NDEBUG(id);
- /* This is a bit tricky and not quite reliable, but good enough check.
- *
- * We don't want audio system handles to be allocated on amn original datablocks, and only want
- * them to be allocated on a datablocks which are result of dependency graph evaluation.
- *
- * Datablocks which are covered by a copy-on-write system of dependency graph will have
- * LIB_TAG_COPIED_ON_WRITE tag set on them. But if some of datablocks during its evaluation
- * decides to re-allocate it's nested one (for example, object evaluation could re-allocate mesh
- * when evaluating modifier stack). Such datablocks will have LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT
- * tag set on them.
- *
- * Additionally, we also allow datablocks outside of main database. Those can not be "original"
- * and could be used as a temporary evaluated result during operations like baking.
- *
- * NOTE: We conder ID evaluated if ANY of those flags is set. We do NOT require ALL of them. */
- BLI_assert(id->tag &
- (LIB_TAG_COPIED_ON_WRITE | LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT | LIB_TAG_NO_MAIN));
-}
-
bSound *BKE_sound_new_file(Main *bmain, const char *filepath)
{
bSound *sound;
@@ -102,10 +77,7 @@ bSound *BKE_sound_new_file(Main *bmain, const char *filepath)
BLI_strncpy(sound->name, filepath, FILE_MAX);
/* sound->type = SOUND_TYPE_FILE; */ /* XXX unused currently */
- sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
- BLI_spin_init(sound->spinlock);
-
- BKE_sound_reset_runtime(sound);
+ BKE_sound_load(bmain, sound);
return sound;
}
@@ -153,18 +125,6 @@ void BKE_sound_free(bSound *sound)
sound->packedfile = NULL;
}
- BKE_sound_free_audio(sound);
- BKE_sound_free_waveform(sound);
-
- if (sound->spinlock) {
- BLI_spin_end(sound->spinlock);
- MEM_freeN(sound->spinlock);
- sound->spinlock = NULL;
- }
-}
-
-void BKE_sound_free_audio(bSound *sound)
-{
#ifdef WITH_AUDASPACE
if (sound->handle) {
AUD_Sound_free(sound->handle);
@@ -176,9 +136,15 @@ void BKE_sound_free_audio(bSound *sound)
AUD_Sound_free(sound->cache);
sound->cache = NULL;
}
-#else
- UNUSED_VARS(sound);
+
+ BKE_sound_free_waveform(sound);
+
#endif /* WITH_AUDASPACE */
+ if (sound->spinlock) {
+ BLI_spin_end(sound->spinlock);
+ MEM_freeN(sound->spinlock);
+ sound->spinlock = NULL;
+ }
}
/**
@@ -191,7 +157,7 @@ void BKE_sound_free_audio(bSound *sound)
*
* \param flag: Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
*/
-void BKE_sound_copy_data(Main *UNUSED(bmain),
+void BKE_sound_copy_data(Main *bmain,
bSound *sound_dst,
const bSound *UNUSED(sound_src),
const int UNUSED(flag))
@@ -200,8 +166,8 @@ void BKE_sound_copy_data(Main *UNUSED(bmain),
sound_dst->cache = NULL;
sound_dst->waveform = NULL;
sound_dst->playback_handle = NULL;
- sound_dst->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
- BLI_spin_init(sound_dst->spinlock);
+ sound_dst->spinlock =
+ NULL; /* Think this is OK? Otherwise, easy to create new spinlock here... */
/* Just to be sure, should not have any value actually after reading time. */
sound_dst->ipo = NULL;
@@ -211,7 +177,8 @@ void BKE_sound_copy_data(Main *UNUSED(bmain),
sound_dst->packedfile = dupPackedFile(sound_dst->packedfile);
}
- BKE_sound_reset_runtime(sound_dst);
+ /* Initialize whole runtime (audaspace) stuff. */
+ BKE_sound_load(bmain, sound_dst);
}
void BKE_sound_make_local(Main *bmain, bSound *sound, const bool lib_local)
@@ -224,15 +191,31 @@ void BKE_sound_make_local(Main *bmain, bSound *sound, const bool lib_local)
static const char *force_device = NULL;
# ifdef WITH_JACK
-static SoundJackSyncCallback sound_jack_sync_callback = NULL;
-
static void sound_sync_callback(void *data, int mode, float time)
{
- if (sound_jack_sync_callback == NULL) {
+ // Ugly: Blender doesn't like it when the animation is played back during rendering
+ if (G.is_rendering) {
return;
}
+
Main *bmain = (Main *)data;
- sound_jack_sync_callback(bmain, mode, time);
+ Scene *scene;
+
+ scene = bmain->scenes.first;
+ while (scene) {
+ if (scene->audio.flag & AUDIO_SYNC) {
+ if (mode) {
+ BKE_sound_play_scene(scene);
+ }
+ else {
+ BKE_sound_stop_scene(scene);
+ }
+ if (scene->playback_handle) {
+ AUD_Handle_setPosition(scene->playback_handle, time);
+ }
+ }
+ scene = scene->id.next;
+ }
}
# endif
@@ -315,7 +298,7 @@ void BKE_sound_init_main(Main *bmain)
AUD_setSynchronizerCallback(sound_sync_callback, bmain);
}
# else
- UNUSED_VARS(bmain);
+ (void)bmain; /* unused */
# endif
}
@@ -384,8 +367,6 @@ bSound *BKE_sound_new_limiter(Main *bmain, bSound *source, float start, float en
void BKE_sound_cache(bSound *sound)
{
- sound_verify_evaluated_id(&sound->id);
-
sound->flags |= SOUND_FLAGS_CACHING;
if (sound->cache) {
AUD_Sound_free(sound->cache);
@@ -412,50 +393,44 @@ void BKE_sound_delete_cache(bSound *sound)
void BKE_sound_load(Main *bmain, bSound *sound)
{
- sound_verify_evaluated_id(&sound->id);
- BKE_sound_load_audio(bmain, sound);
-}
-
-void BKE_sound_load_audio(Main *bmain, bSound *sound)
-{
-
- if (sound->cache) {
- AUD_Sound_free(sound->cache);
- sound->cache = NULL;
- }
+ if (sound) {
+ if (sound->cache) {
+ AUD_Sound_free(sound->cache);
+ sound->cache = NULL;
+ }
- if (sound->handle) {
- AUD_Sound_free(sound->handle);
- sound->handle = NULL;
- sound->playback_handle = NULL;
- }
+ if (sound->handle) {
+ AUD_Sound_free(sound->handle);
+ sound->handle = NULL;
+ sound->playback_handle = NULL;
+ }
- BKE_sound_free_waveform(sound);
+ BKE_sound_free_waveform(sound);
/* XXX unused currently */
# if 0
switch (sound->type) {
case SOUND_TYPE_FILE:
# endif
- {
- char fullpath[FILE_MAX];
+ {
+ char fullpath[FILE_MAX];
- /* load sound */
- PackedFile *pf = sound->packedfile;
+ /* load sound */
+ PackedFile *pf = sound->packedfile;
- /* don't modify soundact->sound->name, only change a copy */
- BLI_strncpy(fullpath, sound->name, sizeof(fullpath));
- BLI_path_abs(fullpath, ID_BLEND_PATH(bmain, &sound->id));
+ /* don't modify soundact->sound->name, only change a copy */
+ BLI_strncpy(fullpath, sound->name, sizeof(fullpath));
+ BLI_path_abs(fullpath, ID_BLEND_PATH(bmain, &sound->id));
- /* but we need a packed file then */
- if (pf) {
- sound->handle = AUD_Sound_bufferFile((unsigned char *)pf->data, pf->size);
- }
- else {
- /* or else load it from disk */
- sound->handle = AUD_Sound_file(fullpath);
+ /* but we need a packed file then */
+ if (pf) {
+ sound->handle = AUD_Sound_bufferFile((unsigned char *)pf->data, pf->size);
+ }
+ else {
+ /* or else load it from disk */
+ sound->handle = AUD_Sound_file(fullpath);
+ }
}
- }
/* XXX unused currently */
# if 0
break;
@@ -472,34 +447,34 @@ void BKE_sound_load_audio(Main *bmain, bSound *sound)
break;
}
# endif
- if (sound->flags & SOUND_FLAGS_MONO) {
- void *handle = AUD_Sound_rechannel(sound->handle, AUD_CHANNELS_MONO);
- AUD_Sound_free(sound->handle);
- sound->handle = handle;
- }
+ if (sound->flags & SOUND_FLAGS_MONO) {
+ void *handle = AUD_Sound_rechannel(sound->handle, AUD_CHANNELS_MONO);
+ AUD_Sound_free(sound->handle);
+ sound->handle = handle;
+ }
- if (sound->flags & SOUND_FLAGS_CACHING) {
- sound->cache = AUD_Sound_cache(sound->handle);
- }
+ if (sound->flags & SOUND_FLAGS_CACHING) {
+ sound->cache = AUD_Sound_cache(sound->handle);
+ }
- if (sound->cache) {
- sound->playback_handle = sound->cache;
- }
- else {
- sound->playback_handle = sound->handle;
+ if (sound->cache) {
+ sound->playback_handle = sound->cache;
+ }
+ else {
+ sound->playback_handle = sound->handle;
+ }
+
+ BKE_sound_update_sequencer(bmain, sound);
}
}
AUD_Device *BKE_sound_mixdown(Scene *scene, AUD_DeviceSpecs specs, int start, float volume)
{
- sound_verify_evaluated_id(&scene->id);
return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS);
}
void BKE_sound_create_scene(Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
/* should be done in version patch, but this gets called before */
if (scene->r.frs_sec_base == 0) {
scene->r.frs_sec_base = 1;
@@ -532,21 +507,16 @@ void BKE_sound_destroy_scene(Scene *scene)
void BKE_sound_reset_scene_specs(Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
- if (scene->sound_scene) {
- AUD_Specs specs;
+ AUD_Specs specs;
- specs.channels = AUD_Device_getChannels(sound_device);
- specs.rate = AUD_Device_getRate(sound_device);
+ specs.channels = AUD_Device_getChannels(sound_device);
+ specs.rate = AUD_Device_getRate(sound_device);
- AUD_Sequence_setSpecs(scene->sound_scene, specs);
- }
+ AUD_Sequence_setSpecs(scene->sound_scene, specs);
}
void BKE_sound_mute_scene(Scene *scene, int muted)
{
- sound_verify_evaluated_id(&scene->id);
if (scene->sound_scene) {
AUD_Sequence_setMuted(scene->sound_scene, muted);
}
@@ -554,8 +524,6 @@ void BKE_sound_mute_scene(Scene *scene, int muted)
void BKE_sound_update_fps(Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
if (scene->sound_scene) {
AUD_Sequence_setFPS(scene->sound_scene, FPS);
}
@@ -565,8 +533,6 @@ void BKE_sound_update_fps(Scene *scene)
void BKE_sound_update_scene_listener(Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
AUD_Sequence_setSpeedOfSound(scene->sound_scene, scene->audio.speed_of_sound);
AUD_Sequence_setDopplerFactor(scene->sound_scene, scene->audio.doppler_factor);
AUD_Sequence_setDistanceModel(scene->sound_scene, scene->audio.distance_model);
@@ -575,7 +541,6 @@ void BKE_sound_update_scene_listener(Scene *scene)
void *BKE_sound_scene_add_scene_sound(
Scene *scene, Sequence *sequence, int startframe, int endframe, int frameskip)
{
- sound_verify_evaluated_id(&scene->id);
if (sequence->scene && scene != sequence->scene) {
const double fps = FPS;
return AUD_Sequence_add(scene->sound_scene,
@@ -599,7 +564,6 @@ void *BKE_sound_scene_add_scene_sound_defaults(Scene *scene, Sequence *sequence)
void *BKE_sound_add_scene_sound(
Scene *scene, Sequence *sequence, int startframe, int endframe, int frameskip)
{
- sound_verify_evaluated_id(&scene->id);
/* Happens when sequence's sound datablock was removed. */
if (sequence->sound == NULL) {
return NULL;
@@ -639,14 +603,12 @@ void BKE_sound_mute_scene_sound(void *handle, char mute)
void BKE_sound_move_scene_sound(
Scene *scene, void *handle, int startframe, int endframe, int frameskip)
{
- sound_verify_evaluated_id(&scene->id);
const double fps = FPS;
AUD_SequenceEntry_move(handle, startframe / fps, endframe / fps, frameskip / fps);
}
void BKE_sound_move_scene_sound_defaults(Scene *scene, Sequence *sequence)
{
- sound_verify_evaluated_id(&scene->id);
if (sequence->scene_sound) {
BKE_sound_move_scene_sound(scene,
sequence->scene_sound,
@@ -668,7 +630,6 @@ void BKE_sound_set_cfra(int cfra)
void BKE_sound_set_scene_volume(Scene *scene, float volume)
{
- sound_verify_evaluated_id(&scene->id);
AUD_Sequence_setAnimationData(scene->sound_scene,
AUD_AP_VOLUME,
CFRA,
@@ -688,13 +649,12 @@ void BKE_sound_set_scene_sound_pitch(void *handle, float pitch, char animated)
void BKE_sound_set_scene_sound_pan(void *handle, float pan, char animated)
{
+ printf("%s\n", __func__);
AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated);
}
void BKE_sound_update_sequencer(Main *main, bSound *sound)
{
- BLI_assert(!"is not supposed to be used, is weird function.");
-
Scene *scene;
for (scene = main->scenes.first; scene; scene = scene->id.next) {
@@ -704,8 +664,6 @@ void BKE_sound_update_sequencer(Main *main, bSound *sound)
static void sound_start_play_scene(Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
if (scene->playback_handle) {
AUD_Handle_stop(scene->playback_handle);
}
@@ -719,8 +677,6 @@ static void sound_start_play_scene(Scene *scene)
void BKE_sound_play_scene(Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
AUD_Status status;
const float cur_time = (float)((double)CFRA / FPS);
@@ -763,8 +719,6 @@ void BKE_sound_stop_scene(Scene *scene)
void BKE_sound_seek_scene(Main *bmain, Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
AUD_Status status;
bScreen *screen;
int animation_playing;
@@ -829,8 +783,6 @@ void BKE_sound_seek_scene(Main *bmain, Scene *scene)
float BKE_sound_sync_scene(Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
// Ugly: Blender doesn't like it when the animation is played back during rendering
if (G.is_rendering) {
return NAN_FLT;
@@ -849,8 +801,6 @@ float BKE_sound_sync_scene(Scene *scene)
int BKE_sound_scene_playing(Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
// Ugly: Blender doesn't like it when the animation is played back during rendering
if (G.is_rendering) {
return -1;
@@ -881,9 +831,6 @@ void BKE_sound_free_waveform(bSound *sound)
sound->tags &= ~SOUND_TAGS_WAVEFORM_NO_RELOAD;
}
-/* TODO(sergey): Consider mamakinging this function fully autonomous, as in, not require having
- * an existing playback handle. That would make it easy to read waveforms, which doesn't seem to
- * be affected by evaluated scene (waveworm comes from file). */
void BKE_sound_read_waveform(bSound *sound, short *stop)
{
AUD_SoundInfo info = AUD_getInfo(sound->playback_handle);
@@ -932,14 +879,11 @@ static void sound_update_base(Scene *scene, Base *base, void *new_set)
Speaker *speaker;
float quat[4];
- sound_verify_evaluated_id(&scene->id);
- sound_verify_evaluated_id(&ob->id);
+ if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
+ return;
+ }
- // TODO(sergey): Bring the test back, or make it a part of dependency graph update.
- // if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
- // return;
- // }
- // ob->id.tag &= ~LIB_TAG_DOIT;
+ ob->id.tag &= ~LIB_TAG_DOIT;
if ((ob->type != OB_SPEAKER) || !ob->adt) {
return;
@@ -1002,8 +946,6 @@ static void sound_update_base(Scene *scene, Base *base, void *new_set)
void BKE_sound_update_scene(Main *bmain, Scene *scene)
{
- sound_verify_evaluated_id(&scene->id);
-
Base *base;
Scene *sce_it;
@@ -1013,8 +955,7 @@ void BKE_sound_update_scene(Main *bmain, Scene *scene)
/* cheap test to skip looping over all objects (no speakers is a common case) */
if (!BLI_listbase_is_empty(&bmain->speakers)) {
- // TODO(sergey): Bring the test back, or make it a part of dependency graph update.
- // BKE_main_id_tag_listbase(&bmain->objects, LIB_TAG_DOIT, true);
+ BKE_main_id_tag_listbase(&bmain->objects, LIB_TAG_DOIT, true);
for (ViewLayer *view_layer = scene->view_layers.first; view_layer;
view_layer = view_layer->next) {
@@ -1051,7 +992,6 @@ void *BKE_sound_get_factory(void *sound)
/* stupid wrapper because AUD_C-API.h includes Python.h which makesrna doesn't like */
float BKE_sound_get_length(bSound *sound)
{
- sound_verify_evaluated_id(&sound->id);
AUD_SoundInfo info = AUD_getInfo(sound->playback_handle);
return info.length;
@@ -1214,81 +1154,4 @@ char **BKE_sound_get_device_names(void)
return names;
}
-void BKE_sound_free_waveform(bSound *UNUSED(sound))
-{
-}
-
-void BKE_sound_load_audio(Main *UNUSED(bmain), bSound *UNUSED(sound))
-{
-}
-
#endif /* WITH_AUDASPACE */
-
-void BKE_sound_reset_scene_runtime(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_runtime(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);
-}
-
-void BKE_sound_jack_sync_callback_set(SoundJackSyncCallback callback)
-{
-#if defined(WITH_AUDASPACE) && defined(WITH_JACK)
- sound_jack_sync_callback = callback;
-#else
- UNUSED_VARS(callback);
-#endif
-}
-
-void BKE_sound_jack_scene_update(Scene *scene, int mode, float time)
-{
- sound_verify_evaluated_id(&scene->id);
-
- /* Ugly: Blender doesn't like it when the animation is played back during rendering. */
- if (G.is_rendering) {
- return;
- }
-
- if (mode) {
- BKE_sound_play_scene(scene);
- }
- else {
- BKE_sound_stop_scene(scene);
- }
-#ifdef WITH_AUDASPACE
- if (scene->playback_handle != NULL) {
- AUD_Handle_setPosition(scene->playback_handle, time);
- }
-#else
- UNUSED_VARS(time);
-#endif
-}
-
-void BKE_sound_evaluate(Depsgraph *depsgraph, Main *bmain, bSound *sound)
-{
- DEG_debug_print_eval(depsgraph, __func__, sound->id.name, sound);
- BKE_sound_ensure_loaded(bmain, sound);
-}