Commit: 9aa7fcd58883418c043097f82f769daeeb15197a
Author: Antony Riakiotakis
Date:   Mon Sep 22 20:38:01 2014 +0200
Branches: terrible_consequencer
https://developer.blender.org/rB9aa7fcd58883418c043097f82f769daeeb15197a

Threaded sound strip display data loading.

Sound loading can take too much so move it to a job and continue. This makes
interaction much better. A similar system should be usable for movie previews.

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

M       intern/audaspace/intern/AUD_C-API.cpp
M       intern/audaspace/intern/AUD_C-API.h
M       release/scripts/startup/bl_ui/space_sequencer.py
M       source/blender/blenkernel/BKE_sound.h
M       source/blender/blenkernel/intern/packedFile.c
M       source/blender/blenkernel/intern/sequencer.c
M       source/blender/blenkernel/intern/sound.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/writefile.c
M       source/blender/editors/sound/sound_ops.c
M       source/blender/editors/space_sequencer/CMakeLists.txt
M       source/blender/editors/space_sequencer/sequencer_draw.c
M       source/blender/editors/space_sequencer/sequencer_intern.h
A       source/blender/editors/space_sequencer/sequencer_preview.c
M       source/blender/makesdna/DNA_sequence_types.h
M       source/blender/makesdna/DNA_sound_types.h
M       source/blender/makesrna/intern/rna_sequencer.c
M       source/blender/makesrna/intern/rna_sound.c
M       source/blender/windowmanager/WM_api.h

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

diff --git a/intern/audaspace/intern/AUD_C-API.cpp 
b/intern/audaspace/intern/AUD_C-API.cpp
index aa82e1d..976c270 100644
--- a/intern/audaspace/intern/AUD_C-API.cpp
+++ b/intern/audaspace/intern/AUD_C-API.cpp
@@ -1077,7 +1077,7 @@ int AUD_doesPlayback()
        return -1;
 }
 
-int AUD_readSound(AUD_Sound *sound, sample_t *buffer, int length, int 
samples_per_second)
+int AUD_readSound(AUD_Sound *sound, sample_t *buffer, int length, int 
samples_per_second, short *interrupt)
 {
        AUD_DeviceSpecs specs;
        sample_t *buf;
@@ -1100,6 +1100,9 @@ int AUD_readSound(AUD_Sound *sound, sample_t *buffer, int 
length, int samples_pe
        for (int i = 0; i < length; i++) {
                len = floor(samplejump * (i+1)) - floor(samplejump * i);
 
+               if (*interrupt) {
+                       return 0;
+               }
                aBuffer.assureSize(len * AUD_SAMPLE_SIZE(specs));
                buf = aBuffer.getBuffer();
 
diff --git a/intern/audaspace/intern/AUD_C-API.h 
b/intern/audaspace/intern/AUD_C-API.h
index 64a3d06..657d4e6 100644
--- a/intern/audaspace/intern/AUD_C-API.h
+++ b/intern/audaspace/intern/AUD_C-API.h
@@ -646,7 +646,7 @@ extern int AUD_doesPlayback(void);
  * \param samples_per_second How many samples to read per second of the sound.
  * \return How many samples really have been read. Always <= length.
  */
-extern int AUD_readSound(AUD_Sound *sound, sample_t *buffer, int length, int 
samples_per_second);
+extern int AUD_readSound(AUD_Sound *sound, sample_t *buffer, int length, int 
samples_per_second, short *interrupt);
 
 /**
  * Copies a sound.
diff --git a/release/scripts/startup/bl_ui/space_sequencer.py 
b/release/scripts/startup/bl_ui/space_sequencer.py
index 6c4e0eb..0d590cd 100644
--- a/release/scripts/startup/bl_ui/space_sequencer.py
+++ b/release/scripts/startup/bl_ui/space_sequencer.py
@@ -71,6 +71,7 @@ class SEQUENCER_HT_header(Header):
         row.prop(scene, "lock_frame_selection_to_range", text="", toggle=True)
 
         layout.prop(st, "view_type", expand=True, text="")
+        layout.prop(st, "waveform_draw", text="")
 
         if st.view_type in {'PREVIEW', 'SEQUENCER_PREVIEW'}:
             layout.prop(st, "display_mode", expand=True, text="")
@@ -735,7 +736,6 @@ class SEQUENCER_PT_sound(SequencerButtonsPanel, Panel):
 
             row.prop(sound, "use_memory_cache")
 
-        layout.prop(st, "waveform_draw", text="")
         if st.waveform_draw == 'DEFAULT_WAVEFORMS':
             layout.prop(strip, "show_waveform")
 
diff --git a/source/blender/blenkernel/BKE_sound.h 
b/source/blender/blenkernel/BKE_sound.h
index 7ea234d..a0724bc 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -75,7 +75,7 @@ void sound_cache_notifying(struct Main *main, struct bSound 
*sound);
 
 void sound_delete_cache(struct bSound *sound);
 
-void sound_load(struct Main *main, struct bSound *sound, bool waveform);
+void sound_load(struct Main *main, struct bSound *sound);
 
 void BKE_sound_free(struct bSound *sound);
 
@@ -132,7 +132,7 @@ int sound_scene_playing(struct Scene *scene);
 
 void sound_free_waveform(struct bSound *sound);
 
-void sound_read_waveform(struct bSound *sound);
+void sound_read_waveform(struct bSound *sound, bool locked, short *stop);
 
 void sound_update_scene(struct Main *bmain, struct Scene *scene);
 
diff --git a/source/blender/blenkernel/intern/packedFile.c 
b/source/blender/blenkernel/intern/packedFile.c
index 290ed71..d186b42 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -520,7 +520,7 @@ int unpackSound(Main *bmain, ReportList *reports, bSound 
*sound, int how)
                        freePackedFile(sound->packedfile);
                        sound->packedfile = NULL;
 
-                       sound_load(bmain, sound, true);
+                       sound_load(bmain, sound);
 
                        ret_value = RET_OK;
                }
diff --git a/source/blender/blenkernel/intern/sequencer.c 
b/source/blender/blenkernel/intern/sequencer.c
index c9647b0..38ee4a1 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -194,7 +194,7 @@ static void BKE_sequence_free_ex(Scene *scene, Sequence 
*seq, const bool do_cach
        if (seq->sound) {
                ((ID *)seq->sound)->us--; 
        }
-
+       
        /* clipboard has no scene and will never have a sound handle or be 
active
         * same goes to sequences copy for proxy rebuild job
         */
diff --git a/source/blender/blenkernel/intern/sound.c 
b/source/blender/blenkernel/intern/sound.c
index 25c92e5..a42fc0d 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -36,6 +36,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
+#include "BLI_threads.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_object_types.h"
@@ -86,7 +87,7 @@ bSound *sound_new_file(struct Main *bmain, const char 
*filename)
        BLI_strncpy(sound->name, filename, FILE_MAX);
        /* sound->type = SOUND_TYPE_FILE; */ /* XXX unused currently */
 
-       sound_load(bmain, sound, true);
+       sound_load(bmain, sound);
 
        if (!sound->playback_handle) {
                BKE_libblock_free(bmain, sound);
@@ -116,6 +117,12 @@ void BKE_sound_free(bSound *sound)
        }
 
        sound_free_waveform(sound);
+       
+       if (sound->mutex) {
+               BLI_mutex_free(sound->mutex);
+               sound->mutex = NULL;
+       }
+       
 #endif  /* WITH_AUDASPACE */
 }
 
@@ -312,7 +319,7 @@ void sound_delete_cache(bSound *sound)
        }
 }
 
-void sound_load(struct Main *bmain, bSound *sound, bool waveform)
+void sound_load(struct Main *bmain, bSound *sound)
 {
        if (sound) {
                if (sound->cache) {
@@ -326,8 +333,7 @@ void sound_load(struct Main *bmain, bSound *sound, bool 
waveform)
                        sound->playback_handle = NULL;
                }
 
-               if (waveform)
-                       sound_free_waveform(sound);
+               sound_free_waveform(sound);
 
 /* XXX unused currently */
 #if 0
@@ -681,7 +687,7 @@ void sound_free_waveform(bSound *sound)
        sound->waveform = NULL;
 }
 
-void sound_read_waveform(bSound *sound)
+void sound_read_waveform(bSound *sound, bool locked, short *stop)
 {
        AUD_SoundInfo info;
 
@@ -692,10 +698,21 @@ void sound_read_waveform(bSound *sound)
                int length = info.length * SOUND_WAVE_SAMPLES_PER_SECOND;
 
                waveform->data = MEM_mallocN(length * sizeof(float) * 3, 
"SoundWaveform.samples");
-               waveform->length = AUD_readSound(sound->playback_handle, 
waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND);
+               waveform->length = AUD_readSound(sound->playback_handle, 
waveform->data, length, SOUND_WAVE_SAMPLES_PER_SECOND, stop);
 
+               if (*stop) {
+                       MEM_freeN(waveform->data);
+                       MEM_freeN(waveform);
+                       return;
+               }
+               
                sound_free_waveform(sound);
+               
+               if (locked)
+                       BLI_mutex_lock(sound->mutex);
                sound->waveform = waveform;
+               if (locked)
+                       BLI_mutex_unlock(sound->mutex);
        }
 }
 
@@ -831,7 +848,7 @@ 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 NAN_FLT; }
 int sound_scene_playing(struct Scene *UNUSED(scene)) { return -1; }
-void sound_read_waveform(struct bSound *UNUSED(sound)) {}
+void sound_read_waveform(struct bSound *UNUSED(sound), bool locked) {}
 void sound_init_main(struct Main *UNUSED(bmain)) {}
 void sound_set_cfra(int UNUSED(cfra)) {}
 void sound_update_sequencer(struct Main *UNUSED(main), struct bSound 
*UNUSED(sound)) {}
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 780857d..9f45c4f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6702,23 +6702,19 @@ static void direct_link_sound(FileData *fd, bSound 
*sound)
 {
        sound->handle = NULL;
        sound->playback_handle = NULL;
+       sound->waveform = NULL;
 
-       if (!(sound->flags & SOUND_FLAGS_WAVEFORM_SAVED)) {
-               sound->waveform = NULL;
-       }
-       else {
-               if (sound->waveform) {
-                       SoundWaveform *waveform = sound->waveform = 
newdataadr(fd, sound->waveform);
-                       waveform->data = newdataadr(fd, waveform->data);
-                       /* waveform has been read, restore the flag */
-                       sound->flags &= ~SOUND_FLAGS_WAVEFORM_SAVED;
-               }       
-       }
        // versioning stuff, if there was a cache, then we enable caching:
        if (sound->cache) {
                sound->flags |= SOUND_FLAGS_CACHING;
                sound->cache = NULL;
        }
+       
+       if (sound->mutex)
+               sound->mutex = BLI_mutex_alloc();
+       
+       /* clear waveform loading flag */
+       sound->flags &= ~SOUND_FLAGS_WAVEFORM_LOADING;
 
        sound->packedfile = direct_link_packedfile(fd, sound->packedfile);
        sound->newpackedfile = direct_link_packedfile(fd, sound->newpackedfile);
@@ -6733,7 +6729,7 @@ static void lib_link_sound(FileData *fd, Main *main)
                        sound->id.flag -= LIB_NEED_LINK;
                        sound->ipo = newlibadr_us(fd, sound->id.lib, 
sound->ipo); // XXX deprecated - old animation system
                        
-                       sound_load(main, sound, false);
+                       sound_load(main, sound);
                }
        }
 }
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index fa327b0..67ffd69 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2344,7 +2344,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                        SEQ_BEGIN (ed, seq)
                        {
                                if (seq->strip) seq->strip->done = false;
-                               writestruct(wd, DATA, "Sequence", 1, seq);
+                               writestruct(wd, DATA, "Sequence", 1, seq);      
                
                        }
                        SEQ_END
                        
@@ -2375,7 +2375,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                                                        break;
                                                }
                                        }
-                                       
+                                                                               
                                        strip= seq->strip;
                                        writestruct(wd, DATA, "Strip", 1, 
strip);
                                        if (seq->flag & SEQ_USE_CROP && 
strip->crop) {
@@ -2908,18 +2908,9 @@ static void write_sounds(WriteData *wd, ListBase *idbase)
        while (sound) {
                if (sound->id.us>0 || wd->current) {
                        /* write LibData */
-                       if (sound->waveform)
-                               sound->flags |= SOUND_FLAGS_WAVEFORM_SAVED;
-
                        writestruct(wd, ID_SO, "bSound", 1, sound);
                        if (sound->id.properties) 
IDP_WriteProperty(sound->id.properties, wd);
 
-                       if (sound->waveform) {
-                               SoundWaveform *waveform = sound->waveform;
-                               writedata(wd, DATA, sizeof(SoundWaveform), 
waveform);
-                               writedata(wd, DATA, sizeof(float) * 3 * 
waveform->length, waveform->data);
-                       }
-                       
                        if (sound->packedfile) {
                                pf = sound->packedfile;
                                writestruct(wd, DATA, "PackedFile", 1, pf);
d

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to