[Bf-blender-cvs] [d266ed5] gooseberry: Initial support of audio scrubbing in blenderplayer.
Antony Riakiotakis
noreply at git.blender.org
Mon May 18 19:13:55 CEST 2015
Commit: d266ed581942c4be769a3a6f671fd0686b15096b
Author: Antony Riakiotakis
Date: Mon May 18 18:49:32 2015 +0200
Branches: gooseberry
https://developer.blender.org/rBd266ed581942c4be769a3a6f671fd0686b15096b
Initial support of audio scrubbing in blenderplayer.
Still lots of corner cases to check:
* sound FPS not changing with speed settings of player
* picture and video still not 100% in synch
* Haven't checked what happens when audio is finished.
Some changes were made to make things nicer:
* Scrub now initiates on mouse click instead of mouse motion, makes
things more predictable.
* When scrubbing a movie with sound, don't pause playing after
scrubbing.
===================================================================
M source/blender/imbuf/IMB_imbuf.h
M source/blender/imbuf/intern/anim_movie.c
M source/blender/imbuf/intern/indexer.c
M source/blender/windowmanager/intern/wm_playanim.c
===================================================================
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 7c7f2db..9aa671b 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -279,7 +279,7 @@ int IMB_anim_get_duration(struct anim *anim, IMB_Timecode_Type tc);
* and frs_sec and frs_sec_base untouched if none available!)
*/
bool IMB_anim_get_fps(struct anim *anim,
- short *frs_sec, float *frs_sec_base);
+ short *frs_sec, float *frs_sec_base, bool no_av_base);
/**
*
diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index 0bb9f0f..be0b624 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -1427,11 +1427,13 @@ int IMB_anim_get_duration(struct anim *anim, IMB_Timecode_Type tc)
}
bool IMB_anim_get_fps(struct anim *anim,
- short *frs_sec, float *frs_sec_base)
+ short *frs_sec, float *frs_sec_base, bool no_av_base)
{
if (anim->frs_sec) {
*frs_sec = anim->frs_sec;
*frs_sec_base = anim->frs_sec_base;
+ if (no_av_base)
+ *frs_sec_base /= AV_TIME_BASE;
return true;
}
return false;
diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c
index 150ea09..0509dea 100644
--- a/source/blender/imbuf/intern/indexer.c
+++ b/source/blender/imbuf/intern/indexer.c
@@ -1006,7 +1006,7 @@ static AviMovie *alloc_proxy_output_avi(
* but sane defaults help anyways...*/
float frs_sec_base = 1.0;
- IMB_anim_get_fps(anim, &frs_sec, &frs_sec_base);
+ IMB_anim_get_fps(anim, &frs_sec, &frs_sec_base, false);
x = width;
y = height;
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index 7d797fd..430faa6 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -73,6 +73,10 @@
#ifdef WITH_AUDASPACE
#include "AUD_C-API.h"
+
+AUD_Sound *source = NULL;
+AUD_Handle *playback_handle = NULL;
+double fps_movie;
#endif
struct PlayState;
@@ -483,6 +487,35 @@ static void build_pict_list(PlayState *ps, const char *first, int totframes, int
ps->loading = false;
}
+static void change_frame(PlayState *ps, int cx)
+{
+ int sizex, sizey;
+ int i;
+
+ playanim_window_get_size(&sizex, &sizey);
+ ps->picture = picsbase.first;
+ /* TODO - store in ps direct? */
+ i = 0;
+ while (ps->picture) {
+ i++;
+ ps->picture = ps->picture->next;
+ }
+ i = (i * cx) / sizex;
+ if (playback_handle) {
+ AUD_seek(playback_handle, i / fps_movie);
+ }
+ ps->picture = picsbase.first;
+ for (; i > 0; i--) {
+ if (ps->picture->next == NULL) break;
+ ps->picture = ps->picture->next;
+ }
+ if (!playback_handle) {
+ ps->sstep = true;
+ ps->wait2 = false;
+ ps->next_frame = 0;
+ }
+}
+
static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
{
PlayState *ps = (PlayState *)ps_void;
@@ -733,8 +766,10 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
if (bd->button == GHOST_kButtonMaskLeft) {
if (type == GHOST_kEventButtonDown) {
- if (inside_window)
+ if (inside_window) {
g_WS.qual |= WS_QUAL_LMOUSE;
+ change_frame(ps, cx);
+ }
}
else
g_WS.qual &= ~WS_QUAL_LMOUSE;
@@ -760,31 +795,12 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
case GHOST_kEventCursorMove:
{
if (g_WS.qual & WS_QUAL_LMOUSE) {
- int sizex, sizey;
- int i;
-
GHOST_TEventCursorData *cd = GHOST_GetEventData(evt);
int cx, cy;
GHOST_ScreenToClient(g_WS.ghost_window, cd->x, cd->y, &cx, &cy);
- playanim_window_get_size(&sizex, &sizey);
- ps->picture = picsbase.first;
- /* TODO - store in ps direct? */
- i = 0;
- while (ps->picture) {
- i++;
- ps->picture = ps->picture->next;
- }
- i = (i * cx) / sizex;
- ps->picture = picsbase.first;
- for (; i > 0; i--) {
- if (ps->picture->next == NULL) break;
- ps->picture = ps->picture->next;
- }
- ps->sstep = true;
- ps->wait2 = false;
- ps->next_frame = 0;
+ change_frame(ps, cx);
}
break;
}
@@ -907,10 +923,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
PlayState ps = {0};
#ifdef WITH_AUDASPACE
- AUD_Sound *source;
- AUD_Handle *playback_handle;
AUD_DeviceSpecs specs;
- float volume = 1.0f;
specs.rate = AUD_RATE_44100;
specs.format = AUD_FORMAT_S16;
@@ -1094,6 +1107,17 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
#ifdef WITH_AUDASPACE
source = AUD_load(filepath);
playback_handle = AUD_play(source, 1);
+ {
+ struct anim *anim_movie = ((struct PlayAnimPict *)picsbase.first)->anim;
+ if (anim_movie) {
+ short frs_sec = 25;
+ float frs_sec_base = 1.0;
+
+ IMB_anim_get_fps(anim_movie, &frs_sec, &frs_sec_base, true);
+
+ fps_movie = (double) frs_sec / (double) frs_sec_base;
+ }
+ }
#endif
for (i = 2; i < argc; i++) {
@@ -1308,7 +1332,8 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
}
#ifdef WITH_AUDASPACE
- AUD_stop(playback_handle);
+ if (playback_handle)
+ AUD_stop(playback_handle);
AUD_unload(source);
AUD_exit();
#endif
More information about the Bf-blender-cvs
mailing list