 +#include "../SDL_audio_c.h"
 +#include "../SDL_audiodev_c.h"
 +
-+  /* The tag name used by NACL audio */
-+#define NACLAUD_DRIVER_NAME         "nacl"
++/* The tag name used by NACL audio */
++#define NACLAUD_DRIVER_NAME "nacl"
 +
 +const uint32_t kSampleFrameCount = 4096u;
 +
 +/* Audio driver functions */
-+static int NACLAUD_OpenAudio(_THIS, SDL_AudioSpec *spec);
++static int NACLAUD_OpenAudio(_THIS, SDL_AudioSpec* spec);
 +static void NACLAUD_CloseAudio(_THIS);
 +
-+static void AudioCallback(void* samples, uint32_t buffer_size, void* data);
-+
++static void AudioCallback(void* samples, uint32_t buffer_size, PP_TimeDelta,
++                          void* data);
 +
 +/* Audio driver bootstrap functions */
 +static int NACLAUD_Available(void) {
-+  return gNaclPPInstance != 0;
-+}
-+
-+static void NACLAUD_DeleteDevice(SDL_AudioDevice *device) {
-+  // We should stop playback here, but it can only be done on the main thread :(
-+}
-+
-+static SDL_AudioDevice *NACLAUD_CreateDevice(int devindex) {
-+  SDL_AudioDevice *_this;
++  return g_nacl_pp_instance && g_nacl_get_interface;
++}
++
++static void NACLAUD_DeleteDevice(SDL_AudioDevice* device) {
++  if (device->hidden->audio) {
++    g_nacl_audio_interface->StopPlayback(device->hidden->audio);
++    g_nacl_core_interface->ReleaseResource(device->hidden->audio);
++    device->hidden->audio = 0;
++  }
++}
++
++static SDL_AudioDevice* NACLAUD_CreateDevice(int devindex) {
++  SDL_AudioDevice* _this;
 +
 +  /* Initialize all variables that we clean on shutdown */
-+  _this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
-+  if ( _this ) {
++  _this = (SDL_AudioDevice*)SDL_malloc(sizeof(SDL_AudioDevice));
++  if (_this) {
 +    SDL_memset(_this, 0, (sizeof *_this));
-+    _this->hidden = (struct SDL_PrivateAudioData *)
-+        SDL_malloc((sizeof *_this->hidden));
-+  }
-+  if ( (_this == NULL) || (_this->hidden == NULL) ) {
++    _this->hidden =
++        (struct SDL_PrivateAudioData*)SDL_malloc((sizeof *_this->hidden));
++  }
++  if ((_this == NULL) || (_this->hidden == NULL)) {
 +    SDL_OutOfMemory();
-+    if ( _this ) {
++    if (_this) {
 +      SDL_free(_this);
 +    }
-+    return(0);
++    return (0);
 +  }
 +  SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
 +

+#include <errno.h>
+#include <fcntl.h>
+#include <libtar.h>
+#include <unistd.h>
+#include <vector>
+#include <SDL.h>
+#include <SDL_nacl.h>
+#include <SDL_video.h>
+#include <SDL_main.h>
+#include <sys/mount.h>
+
+#include <ppapi/cpp/module.h>
+#include "pepper_instance.h"
+#include "nacl_io/nacl_io.h"
+
+SDLPepperInstance::SDLPepperInstance(PP_Instance instance)
+  : pp::Instance(instance),
+    width_(0),
+    height_(0) {
+  RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
+  RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD);
+}
+
+bool SDLPepperInstance::Init(uint32_t argc, const char* argn[], const char* argv[]) {
+  nacl_io_init_ppapi(pp_instance(),
+                     pp::Module::Get()->get_browser_interface());
+
+  // Copy args so they can be processed later by the SDL thread.
+  argc_ = argc;
+  argn_ = (const char**)malloc(argc*sizeof(char*));
+  argv_ = (const char**)malloc(argc*sizeof(char*));
+  memset(argn_, 0, argc*sizeof(char*));
+  memset(argv_, 0, argc*sizeof(char*));
+
+  for (int i = 0; i < argc; i++) {
+    if (argn[i])
+      argn_[i] = strdup(argn[i]);
+    if (argv[i])
+      argv_[i] = strdup(argv[i]);
+  }
+  return true;
+}
+
+void SDLPepperInstance::ProcessArgs() {
+  fprintf(stderr, "SDL: ProcessArgs %d\n", argc_);
+  bool mount_default = true;
+
+  umount("/");
+
+  for (int i = 0; i < argc_; i++) {
+    if (!strcmp(argn_[i], "ps_stdout")) {
+      int fd1 = open(argv_[i], O_WRONLY);
+      dup2(fd1, 1);
+    } else if (!strcmp(argn_[i], "ps_stderr")) {
+      int fd2 = open(argv_[i], O_WRONLY);
+      dup2(fd2, 2);
+    } else if (!strcmp(argn_[i], "sdl_mount_http")) {
+      const char* source;
+      const char* target = "/";
+      char* sep;
+      char buf[64];
+
+      const char *q, *p = argv_[i];
+      while (*p) {
+        while (*p && isspace(*p))
+          ++p;
+        if (!*p)
+          break;
+        q = p;
+        while (*p && !isspace(*p))
+          ++p;
+
+        int n = sizeof(buf) - 1;
+        if (p - q < n)
+          n = p - q;
+        strncpy(buf, q, n);
+        buf[n] = '\0';
+

 #endif
diff --git a/src/audio/nacl/SDL_naclaudio.cc b/src/audio/nacl/SDL_naclaudio.cc
new file mode 100644
index 0000000..908a498
--- /dev/null
+++ b/src/audio/nacl/SDL_naclaudio.cc
@@ -0,0 +1,150 @@
+#include "SDL_config.h"
+#include "SDL_naclaudio.h"
+
+#include <assert.h>
+
+#include <ppapi/c/pp_instance.h>
+#include <ppapi/c/ppb.h>
+#include <ppapi/c/ppb_audio.h>
+#include <ppapi/c/ppb_audio_config.h>
+#include <ppapi/c/ppb_core.h>
+
+extern PP_Instance g_nacl_pp_instance;
+extern PPB_GetInterface g_nacl_get_interface;
+extern const PPB_Core_1_0* g_nacl_core_interface;
+
+const PPB_Audio_1_1* g_nacl_audio_interface;
+const PPB_AudioConfig_1_1* g_nacl_audio_config_interface;
+
+extern "C" {
+
