Fixing [#28907] Frozen playback.
authorJoerg Mueller <nexyon@gmail.com>
Thu, 13 Oct 2011 22:19:29 +0000 (22:19 +0000)
committerJoerg Mueller <nexyon@gmail.com>
Thu, 13 Oct 2011 22:19:29 +0000 (22:19 +0000)
Also fixing two more crashes when audio files don't exist/cannot be read and apply a changed file path of a sound, reported by Jens Verwiebe in IRC.

intern/audaspace/intern/AUD_NULLDevice.cpp
source/blender/blenkernel/intern/sound.c
source/blender/editors/space_sequencer/sequencer_draw.c
source/blender/makesrna/intern/rna_sequencer.c
source/blender/windowmanager/intern/wm_event_system.c

index b7d658aafe68c319249577e3582df6451267c737..cb76f9eab88eaed95c79abb75643691857cd2eaf 100644 (file)
@@ -69,7 +69,7 @@ bool AUD_NULLDevice::AUD_NULLHandle::seek(float position)
 
 float AUD_NULLDevice::AUD_NULLHandle::getPosition()
 {
-       return 0.0f;
+       return std::numeric_limits<float>::quiet_NaN();
 }
 
 AUD_Status AUD_NULLDevice::AUD_NULLHandle::getStatus()
@@ -79,7 +79,7 @@ AUD_Status AUD_NULLDevice::AUD_NULLHandle::getStatus()
 
 float AUD_NULLDevice::AUD_NULLHandle::getVolume()
 {
-       return 0.0f;
+       return std::numeric_limits<float>::quiet_NaN();
 }
 
 bool AUD_NULLDevice::AUD_NULLHandle::setVolume(float volume)
@@ -89,7 +89,7 @@ bool AUD_NULLDevice::AUD_NULLHandle::setVolume(float volume)
 
 float AUD_NULLDevice::AUD_NULLHandle::getPitch()
 {
-       return 0.0f;
+       return std::numeric_limits<float>::quiet_NaN();
 }
 
 bool AUD_NULLDevice::AUD_NULLHandle::setPitch(float pitch)
@@ -153,7 +153,7 @@ void AUD_NULLDevice::unlock()
 
 float AUD_NULLDevice::getVolume() const
 {
-       return 0;
+       return std::numeric_limits<float>::quiet_NaN();
 }
 
 void AUD_NULLDevice::setVolume(float volume)
index f2d92154c66762dce7152b5034fdbcc14fa01c7b..649b4f0b724c04c747a23e732a7130da93aeeea8 100644 (file)
@@ -295,7 +295,10 @@ void sound_cache(struct bSound* sound)
                AUD_unload(sound->cache);
 
        sound->cache = AUD_bufferSound(sound->handle);
-       sound->playback_handle = sound->cache;
+       if(sound->cache)
+               sound->playback_handle = sound->cache;
+       else
+               sound->playback_handle = sound->handle;
 }
 
 void sound_cache_notifying(struct Main* main, struct bSound* sound)
@@ -332,6 +335,8 @@ void sound_load(struct Main *bmain, struct bSound* sound)
                        sound->playback_handle = NULL;
                }
 
+               sound_free_waveform(sound);
+
 // XXX unused currently
 #if 0
                switch(sound->type)
@@ -625,7 +630,7 @@ float sound_sync_scene(struct Scene *scene)
                else
                        return AUD_getPosition(scene->sound_scene_handle);
        }
-       return 0.0f;
+       return .0f/.0f;
 }
 
 int sound_scene_playing(struct Scene *scene)
@@ -782,7 +787,7 @@ static void sound_start_play_scene(struct Scene *UNUSED(scene)) {}
 void sound_play_scene(struct Scene *UNUSED(scene)) {}
 void sound_stop_scene(struct Scene *UNUSED(scene)) {}
 void sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) {}
-float sound_sync_scene(struct Scene *UNUSED(scene)) { return 0.0f; }
+float sound_sync_scene(struct Scene *UNUSED(scene)) { return .0f/.0f; }
 int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; }
 int sound_read_sound_buffer(struct bSound* UNUSED(sound), float* UNUSED(buffer), int UNUSED(length), float UNUSED(start), float UNUSED(end)) { return 0; }
 void sound_read_waveform(struct bSound* sound) { (void)sound; }
index 8f1ea6fe254f318ecaa7aaf9a0e9aa1a50eeb7dc..13e54c9a4c00e36a902f96a93b715e379454a676 100644 (file)
@@ -192,6 +192,9 @@ static void drawseqwave(Scene *scene, Sequence *seq, float x1, float y1, float x
 
                waveform = seq->sound->waveform;
 
+               if(!waveform)
+                       return;
+
                startsample = floor((seq->startofs + seq->anim_startofs)/FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
                endsample = ceil((seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp)/FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
                samplestep = (endsample-startsample) * stepsize / (x2-x1);
index a75166c3e9982adb57933a1d4d40ebfb84eb2cae..92739148b995e4f397a7fe4745a7e80a263ad9af 100644 (file)
@@ -453,6 +453,8 @@ static void rna_Sequence_filepath_set(PointerRNA *ptr, const char *value)
                PointerRNA id_ptr;
                RNA_id_pointer_create((ID *)seq->sound, &id_ptr);
                RNA_string_set(&id_ptr, "filepath", value);
+               sound_load(G.main, seq->sound);
+               sound_update_scene_sound(seq->scene_sound, seq->sound);
        }
 
        BLI_split_dirfile(value, dir, name);
index cafee6b49caf521e50b471368894b7c360957d54..074151c9abe52300716214735a951e6be2738c66 100644 (file)
@@ -1790,11 +1790,14 @@ void wm_event_do_handlers(bContext *C)
                                        }
                                        
                                        if(playing == 0) {
-                                               int ncfra = sound_sync_scene(scene) * (float)FPS + 0.5f;
-                                               if(ncfra != scene->r.cfra)      {
-                                                       scene->r.cfra = ncfra;
-                                                       ED_update_for_newframe(CTX_data_main(C), scene, win->screen, 1);
-                                                       WM_event_add_notifier(C, NC_WINDOW, NULL);
+                                               float time = sound_sync_scene(scene);
+                                               if(finite(time)) {
+                                                       int ncfra = sound_sync_scene(scene) * (float)FPS + 0.5f;
+                                                       if(ncfra != scene->r.cfra)      {
+                                                               scene->r.cfra = ncfra;
+                                                               ED_update_for_newframe(CTX_data_main(C), scene, win->screen, 1);
+                                                               WM_event_add_notifier(C, NC_WINDOW, NULL);
+                                                       }
                                                }
                                        }