Fixes audio for Native Client, and other fixes...
authorGabriel Jacobo <gabomdq@gmail.com>
Sun, 08 Jun 2014 18:18:13 -0300
changeset 8851a7cfe554d337
parent 8850 7e248a233387
child 8852 bb99ec3b21d8
Fixes audio for Native Client, and other fixes...

- SDL_NaClMount, SDL_NaClUmount
- Default mounting of https at / in SDL's main function
- More documentation in README-nacl.txt
README-nacl.txt
configure
configure.in
include/SDL_config.h.in
include/SDL_system.h
src/audio/nacl/SDL_naclaudio.c
src/filesystem/nacl/SDL_sysfilesytem.c
src/main/nacl/SDL_nacl_main.c
test/nacl/Makefile
test/testmultiaudio.c
test/testrendercopyex.c
     1.1 --- a/README-nacl.txt	Sun Jun 08 12:05:17 2014 -0700
     1.2 +++ b/README-nacl.txt	Sun Jun 08 18:18:13 2014 -0300
     1.3 @@ -53,8 +53,23 @@
     1.4  script will give you instructions on how to do that with Python).
     1.5  
     1.6  ================================================================================
     1.7 +RWOps and nacl_io
     1.8 +================================================================================
     1.9 +
    1.10 +SDL_RWops work transparently with nacl_io. Two functions are provided to control
    1.11 +mount points:
    1.12 +    
    1.13 +    
    1.14 +    For convenience, SDL will by default
    1.15 +mount an httpfs tree at / before calling the app's main function. Such setting
    1.16 +can be overriden by calling SDL_NaCl
    1.17 +
    1.18 +For more information on how nacl_io and mount points work, see:
    1.19 +    
    1.20 +    https://developer.chrome.com/native-client/devguide/coding/nacl_io
    1.21 +
    1.22 +================================================================================
    1.23  TODO - Known Issues
    1.24  ================================================================================
    1.25 -* Audio backend is not usable yet.
    1.26  * Testing of all systems with a real application (something other than SDL's tests)
    1.27  
     2.1 --- a/configure	Sun Jun 08 12:05:17 2014 -0700
     2.2 +++ b/configure	Sun Jun 08 18:18:13 2014 -0300
     2.3 @@ -23211,6 +23211,8 @@
     2.4          CheckDummyAudio
     2.5          CheckDummyVideo
     2.6          CheckInputEvents
     2.7 +        CheckPTHREAD
     2.8 +
     2.9          # Set up files for the timer library
    2.10          if test x$enable_timers = xyes; then
    2.11              $as_echo "#define SDL_TIMER_UNIX 1" >>confdefs.h
    2.12 @@ -23218,7 +23220,15 @@
    2.13              SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
    2.14              have_timers=yes
    2.15          fi
    2.16 -        CheckPTHREAD
    2.17 +
    2.18 +        if test x$enable_filesystem = xyes; then
    2.19 +
    2.20 +$as_echo "#define SDL_FILESYSTEM_NACL 1" >>confdefs.h
    2.21 +
    2.22 +            SOURCES="$SOURCES $srcdir/src/filesystem/nacl/*.c"
    2.23 +            have_filesystem=yes
    2.24 +        fi
    2.25 +
    2.26          ;;
    2.27      *)
    2.28          as_fn_error $? "
     3.1 --- a/configure.in	Sun Jun 08 12:05:17 2014 -0700
     3.2 +++ b/configure.in	Sun Jun 08 18:18:13 2014 -0300
     3.3 @@ -3151,13 +3151,21 @@
     3.4          CheckDummyAudio
     3.5          CheckDummyVideo
     3.6          CheckInputEvents
     3.7 +        CheckPTHREAD
     3.8 +        
     3.9          # Set up files for the timer library
    3.10          if test x$enable_timers = xyes; then
    3.11              AC_DEFINE(SDL_TIMER_UNIX)
    3.12              SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
    3.13              have_timers=yes
    3.14          fi
    3.15 -        CheckPTHREAD      
    3.16 +        
    3.17 +        if test x$enable_filesystem = xyes; then
    3.18 +            AC_DEFINE(SDL_FILESYSTEM_NACL, 1, [ ])
    3.19 +            SOURCES="$SOURCES $srcdir/src/filesystem/nacl/*.c"
    3.20 +            have_filesystem=yes
    3.21 +        fi
    3.22 +        
    3.23          ;;
    3.24      *)
    3.25          AC_MSG_ERROR([
     4.1 --- a/include/SDL_config.h.in	Sun Jun 08 12:05:17 2014 -0700
     4.2 +++ b/include/SDL_config.h.in	Sun Jun 08 18:18:13 2014 -0300
     4.3 @@ -336,6 +336,7 @@
     4.4  #undef SDL_FILESYSTEM_DUMMY
     4.5  #undef SDL_FILESYSTEM_UNIX
     4.6  #undef SDL_FILESYSTEM_WINDOWS
     4.7 +#undef SDL_FILESYSTEM_NACL
     4.8  
     4.9  /* Enable assembly routines */
    4.10  #undef SDL_ASSEMBLY_ROUTINES
     5.1 --- a/include/SDL_system.h	Sun Jun 08 12:05:17 2014 -0700
     5.2 +++ b/include/SDL_system.h	Sun Jun 08 18:18:13 2014 -0300
     5.3 @@ -179,6 +179,22 @@
     5.4  
     5.5  #endif /* __WINRT__ */
     5.6  
     5.7 +#ifdef __NACL__
     5.8 +
     5.9 +/**
    5.10 + *  \name Mount/umount functions
    5.11 + *
    5.12 + *  Required for RWOps on Native Client
    5.13 + */
    5.14 +/* @{ */
    5.15 +extern DECLSPEC int SDLCALL SDL_NaClMount(const char* source, const char* target, 
    5.16 +                                        const char* filesystemtype, 
    5.17 +                                        unsigned long mountflags, const void *data);
    5.18 +
    5.19 +extern DECLSPEC int SDLCALL SDL_NaClUmount(const char *target);
    5.20 +
    5.21 +#endif /* __NACL__ */
    5.22 +
    5.23  
    5.24  /* Ends C function definitions when using C++ */
    5.25  #ifdef __cplusplus
     6.1 --- a/src/audio/nacl/SDL_naclaudio.c	Sun Jun 08 12:05:17 2014 -0700
     6.2 +++ b/src/audio/nacl/SDL_naclaudio.c	Sun Jun 08 18:18:13 2014 -0300
     6.3 @@ -49,15 +49,24 @@
     6.4      SDL_AudioDevice* _this = (SDL_AudioDevice*) data;
     6.5      
     6.6      SDL_LockMutex(private->mutex);
     6.7 -    /*if (private->opened) {*/
     6.8 -    SDL_memset(samples, _this->spec.silence, buffer_size);
     6.9 -    SDL_LockMutex(_this->mixer_lock);
    6.10 -    (*_this->spec.callback)(_this->spec.userdata, (Uint8*)samples, buffer_size);
    6.11 -    SDL_UnlockMutex(_this->mixer_lock);
    6.12 -    /*} else {
    6.13 +
    6.14 +    if (_this->enabled && !_this->paused) {
    6.15 +        if (_this->convert.needed) {
    6.16 +            SDL_LockMutex(_this->mixer_lock);
    6.17 +            (*_this->spec.callback) (_this->spec.userdata,
    6.18 +                                     (Uint8 *) _this->convert.buf,
    6.19 +                                     _this->convert.len);
    6.20 +            SDL_UnlockMutex(_this->mixer_lock);
    6.21 +            SDL_ConvertAudio(&_this->convert);
    6.22 +            SDL_memcpy(samples, _this->convert.buf, _this->convert.len_cvt);
    6.23 +        } else {
    6.24 +            SDL_LockMutex(_this->mixer_lock);
    6.25 +            (*_this->spec.callback) (_this->spec.userdata, (Uint8 *) samples, buffer_size);
    6.26 +            SDL_UnlockMutex(_this->mixer_lock);
    6.27 +        }
    6.28 +    } else {
    6.29          SDL_memset(samples, 0, buffer_size);
    6.30 -    }*/
    6.31 -    SDL_UnlockMutex(private->mutex);
    6.32 +    }
    6.33      
    6.34      return;
    6.35  }
    6.36 @@ -93,6 +102,9 @@
    6.37          PP_AUDIOSAMPLERATE_44100, 
    6.38          SAMPLE_FRAME_COUNT);
    6.39      
    6.40 +    /* Calculate the final parameters for this audio specification */
    6.41 +    SDL_CalculateAudioSpec(&_this->spec);
    6.42 +    
    6.43      private->audio = ppb_audio->Create(
    6.44          instance,
    6.45          ppb_audiocfg->CreateStereo16Bit(instance, PP_AUDIOSAMPLERATE_44100, _this->spec.samples),
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/filesystem/nacl/SDL_sysfilesytem.c	Sun Jun 08 18:18:13 2014 -0300
     7.3 @@ -0,0 +1,59 @@
     7.4 +/*
     7.5 +  Simple DirectMedia Layer
     7.6 +  Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
     7.7 +
     7.8 +  This software is provided 'as-is', without any express or implied
     7.9 +  warranty.  In no event will the authors be held liable for any damages
    7.10 +  arising from the use of this software.
    7.11 +
    7.12 +  Permission is granted to anyone to use this software for any purpose,
    7.13 +  including commercial applications, and to alter it and redistribute it
    7.14 +  freely, subject to the following restrictions:
    7.15 +
    7.16 +  1. The origin of this software must not be misrepresented; you must not
    7.17 +     claim that you wrote the original software. If you use this software
    7.18 +     in a product, an acknowledgment in the product documentation would be
    7.19 +     appreciated but is not required.
    7.20 +  2. Altered source versions must be plainly marked as such, and must not be
    7.21 +     misrepresented as being the original software.
    7.22 +  3. This notice may not be removed or altered from any source distribution.
    7.23 +*/
    7.24 +#include "../../SDL_internal.h"
    7.25 +#include "SDL_error.h"
    7.26 +#include "SDL_filesystem.h"
    7.27 +
    7.28 +#ifdef SDL_FILESYSTEM_NACL
    7.29 +
    7.30 +/* SDL_RWops on NACL are implemented using nacl_io, and require mount points
    7.31 + * to be established before actual file operations are performed
    7.32 + * 
    7.33 + * Ref: https://developers.google.com/native-client/dev/devguide/coding/nacl_io
    7.34 + */
    7.35 +
    7.36 +int 
    7.37 +SDL_NaClMount(const char* source, const char* target, const char* filesystemtype, 
    7.38 +          unsigned long mountflags, const void *data) {
    7.39 +    return mount(source, target, filesystemtype, mountflags, data);
    7.40 +}
    7.41 +
    7.42 +int 
    7.43 +SDL_NaClUmount(const char *target) {
    7.44 +    return umount(target);
    7.45 +}
    7.46 +
    7.47 +
    7.48 +char *
    7.49 +SDL_GetBasePath(void)
    7.50 +{
    7.51 +    SDL_Unsupported();
    7.52 +    return NULL;
    7.53 +}
    7.54 +
    7.55 +char *
    7.56 +SDL_GetPrefPath(const char *org, const char *app)
    7.57 +{
    7.58 +    SDL_Unsupported();
    7.59 +    return NULL;
    7.60 +}
    7.61 +
    7.62 +#endif /* __NACL__ */
    7.63 \ No newline at end of file
     8.1 --- a/src/main/nacl/SDL_nacl_main.c	Sun Jun 08 12:05:17 2014 -0700
     8.2 +++ b/src/main/nacl/SDL_nacl_main.c	Sun Jun 08 18:18:13 2014 -0300
     8.3 @@ -24,6 +24,7 @@
     8.4  
     8.5  /* Include the SDL main definition header */
     8.6  #include "SDL_main.h"
     8.7 +#include "SDL_system.h"
     8.8  
     8.9  #include "ppapi_simple/ps_main.h"
    8.10  #include "ppapi_simple/ps_event.h"
    8.11 @@ -64,6 +65,18 @@
    8.12          }
    8.13      }
    8.14      
    8.15 +    /* Do a default httpfs mount on /, 
    8.16 +     * apps can override this by unmounting / 
    8.17 +     * and remounting with the desired configuration
    8.18 +     */
    8.19 +    SDL_NaClUmount("/");
    8.20 +    SDL_NaClMount(
    8.21 +        "",  /* source */
    8.22 +        "/",  /* target */
    8.23 +        "httpfs",  /* filesystemtype */
    8.24 +        0,  /* mountflags */
    8.25 +        "");  /* data specific to the html5fs type */
    8.26 +    
    8.27      /* Everything is ready, start the user main function */
    8.28      SDL_SetMainReady();
    8.29      status = SDL_main(argc, argv);
     9.1 --- a/test/nacl/Makefile	Sun Jun 08 12:05:17 2014 -0700
     9.2 +++ b/test/nacl/Makefile	Sun Jun 08 18:18:13 2014 -0300
     9.3 @@ -13,8 +13,8 @@
     9.4  
     9.5  TARGET = sdl_app
     9.6  DEPS = ppapi_simple nacl_io
     9.7 -# ppapi_simple ends up being listed twice due to dependency solving issues -- Gabriel
     9.8 -LIBS = SDL2_test SDL2 ppapi_simple SDL2main $(DEPS) ppapi_gles2 ppapi_cpp ppapi pthread 
     9.9 +# ppapi_simple and SDL2 end up being listed twice due to dependency solving issues -- Gabriel
    9.10 +LIBS = SDL2_test SDL2 ppapi_simple SDL2main SDL2 $(DEPS) ppapi_gles2 ppapi_cpp ppapi pthread 
    9.11  
    9.12  CFLAGS := -Wall
    9.13  SOURCES ?= testgles2.c
    10.1 --- a/test/testmultiaudio.c	Sun Jun 08 12:05:17 2014 -0700
    10.2 +++ b/test/testmultiaudio.c	Sun Jun 08 18:18:13 2014 -0300
    10.3 @@ -134,16 +134,6 @@
    10.4  
    10.5      SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
    10.6      
    10.7 -    #if __NACL__
    10.8 -    SDL_RWUmount("/");
    10.9 -    SDL_RWMount(
   10.10 -        "",  /* source */
   10.11 -        "/",  /* target */
   10.12 -        "httpfs",  /* filesystemtype */
   10.13 -        0,  /* mountflags */
   10.14 -        "");  /* data specific to the html5fs type */
   10.15 -#endif
   10.16 -
   10.17      devcount = SDL_GetNumAudioDevices(0);
   10.18      if (devcount < 1) {
   10.19          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
    11.1 --- a/test/testrendercopyex.c	Sun Jun 08 12:05:17 2014 -0700
    11.2 +++ b/test/testrendercopyex.c	Sun Jun 08 18:18:13 2014 -0300
    11.3 @@ -161,16 +161,6 @@
    11.4          quit(2);
    11.5      }
    11.6  
    11.7 -#if __NACL__
    11.8 -    SDL_RWUmount("/");
    11.9 -    SDL_RWMount(
   11.10 -        "",  /* source */
   11.11 -        "/",  /* target */
   11.12 -        "httpfs",  /* filesystemtype */
   11.13 -        0,  /* mountflags */
   11.14 -        "");  /* data specific to the html5fs type */
   11.15 -#endif    
   11.16 -    
   11.17      drawstates = SDL_stack_alloc(DrawState, state->num_windows);
   11.18      for (i = 0; i < state->num_windows; ++i) {
   11.19          DrawState *drawstate = &drawstates[i];