Permalink
Browse files

now the audio callback runs in a different ithread, which is initiali…

…zed at the moment you set the callback, but only once.
  • Loading branch information...
1 parent e906fa3 commit 4e5315f69cb1be0edb6f8246a246c032f2c510ea @ruoso ruoso committed Jan 2, 2010
Showing with 15 additions and 19 deletions.
  1. +3 −1 Build.PL
  2. +11 −18 src/Core/objects/AudioSpec.xs
  3. +1 −0 src/SDL.xs
View
4 Build.PL
@@ -411,9 +411,10 @@ $arch->write_sdl_config( $build_systems );
# and fetch all of the information needed to compile
my $defines = $arch->build_defines( \%libraries, $build_systems );
-my $includes = $arch->build_includes( \%libraries, $build_systems );
+my $includes = $arch->build_includes( \%libraries, $build_systems);
my $links = $arch->build_links( \%libraries, $build_systems );
+
# mangle the compilable files into a format Module::Build can understand
my %xs = map { $subsystems{$_}{file}{from} => $subsystems{$_}{file}{to} }
keys %subsystems;
@@ -457,6 +458,7 @@ if($arch eq 'Darwin')
}
# and here's where the real (and ugly) magic works... see SDL::Build
+
$build->set_flags(
\%subsystems,
$build_systems,
View
29 src/Core/objects/AudioSpec.xs
@@ -37,25 +37,17 @@ extern PerlInterpreter *parent_perl;
#endif
-
+PerlInterpreter * perl_for_audio_cb = NULL;
#include <SDL.h>
#include <SDL_audio.h>
-static char* callbacksv;
-
-static PerlInterpreter * orig_perl=NULL;
-static PerlInterpreter * perl_for_cb=NULL;
-
-
void
audio_callback ( void* data, Uint8 *stream, int len )
{
- PERL_SET_CONTEXT(orig_perl);
- perl_for_cb = perl_clone(orig_perl, CLONEf_KEEP_PTR_TABLE);
- PERL_SET_CONTEXT(perl_for_cb);
+ PERL_SET_CONTEXT(perl_for_audio_cb);
dSP;
@@ -76,7 +68,7 @@ audio_callback ( void* data, Uint8 *stream, int len )
XPUSHs(sv_2mortal(newRV_inc(sv)));
PUTBACK;
- call_pv(callbacksv,G_VOID|G_DISCARD);
+ call_pv(data,G_VOID|G_DISCARD);
SvPV_set(sv,old);
SvCUR_set(sv,1);
@@ -86,8 +78,6 @@ audio_callback ( void* data, Uint8 *stream, int len )
FREETMPS;
LEAVE;
- PERL_SET_CONTEXT(orig_perl);
- perl_free(perl_for_cb);
}
@@ -123,7 +113,6 @@ audiospec_new (CLASS)
char* CLASS
CODE:
RETVAL = safemalloc(sizeof(SDL_AudioSpec));
- orig_perl = PERL_GET_CONTEXT;
OUTPUT:
RETVAL
@@ -169,11 +158,15 @@ audiospec_callback( audiospec, cb )
SDL_AudioSpec *audiospec
char* cb
CODE:
-
- callbacksv = cb;
+ // the audio callback will happen in a different thread.
+ // so we're going to leave a cloned interpreter available
+ // but still remain in the current one.
+ if (perl_for_audio_cb == NULL) {
+ perl_for_audio_cb = perl_clone(my_perl, CLONEf_KEEP_PTR_TABLE);
+ PERL_SET_CONTEXT(my_perl);
+ }
+ audiospec->userdata = cb;
audiospec->callback = audio_callback;
-
-
void
audiospec_DESTROY(self)
View
1 src/SDL.xs
@@ -49,6 +49,7 @@
#include <SDL_sound.h>
#endif
+
//#ifdef HAVE_SDL_MIXER
//#include <SDL_mixer.h>
//void (*mix_music_finished_cv)();

0 comments on commit 4e5315f

Please sign in to comment.