Index: libraries/openal-soft/nacl-openal-soft.patch |
diff --git a/libraries/openal-soft/nacl-openal-soft.patch b/libraries/openal-soft/nacl-openal-soft.patch |
index 4fac7f7712f69239359fde4ff91b7fd5c1888fca..410aac5f7ea0d0966aea6af8d30e62e205fa19e7 100644 |
--- a/libraries/openal-soft/nacl-openal-soft.patch |
+++ b/libraries/openal-soft/nacl-openal-soft.patch |
@@ -21,10 +21,10 @@ diff -Naur openal-soft-1.13/Alc/ALc.c openal-soft-1.13-nacl/Alc/ALc.c |
{ "null", alc_null_init, alc_null_deinit, alc_null_probe, EmptyFuncs }, |
#ifdef HAVE_WAVE |
{ "wave", alc_wave_init, alc_wave_deinit, alc_wave_probe, EmptyFuncs }, |
-diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13.nacl/Alc/ppapi.c |
--- openal-soft-1.13/Alc/ppapi.c 1969-12-31 16:00:00.000000000 -0800 |
-+++ openal-soft-1.13-nacl/Alc/ppapi.c 2012-01-23 15:46:21.000000000 -0800 |
-@@ -0,0 +1,411 @@ |
++++ openal-soft-1.13.nacl/Alc/ppapi.c 2013-01-30 13:53:29.840835797 -0800 |
+@@ -0,0 +1,458 @@ |
+/** |
+ * OpenAL cross platform audio library |
+ * Copyright (C) 2012 |
@@ -62,7 +62,8 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+/* The output buffer will be this multiple of the OpenAL device update size. |
+ * This needs to be at least 2 or we can't buffer output properly. |
+ */ |
-+const ALuint kBufferPadMult = 4; |
++const ALuint kBufferPadMult = 3; |
++ |
+/* How many samples for each frame will be buffered to Pepper. |
+ * Keep this low for low latency, but not too low or we will be CPU bound. |
+ */ |
@@ -84,13 +85,15 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ PP_Resource audio_config_resource; |
+ PP_Resource audio_resource; |
+ ALuint sample_frame_count; |
-+ |
++ |
+ volatile ALuint read_ptr; |
+ volatile ALuint write_ptr; |
++ pthread_mutex_t mutex; |
++ pthread_cond_t cond; |
+ |
+ ALCdevice *device; |
+ |
-+ volatile int killNow; |
++ int killNow; |
+ ALvoid *thread; |
+ volatile ALuint main_thread_init_status; |
+ ALuint buffer_ready; |
@@ -106,7 +109,7 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+} |
+ |
+/* This is the callback from PPAPI to fill in the audio buffer. */ |
-+void PPAPI_Audio_Callback(void *sample_buffer, |
++static void PPAPI_Audio_Callback(void *sample_buffer, |
+ uint32_t buffer_size_in_bytes, |
+ void* user_data) |
+{ |
@@ -117,10 +120,11 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ if (data->read_ptr > data->write_ptr) |
+ write_proxy = data->write_ptr + data->size; |
+ |
-+ if (data->read_ptr + buffer_size_in_bytes > write_proxy) |
++ int available_bytes = write_proxy - data->read_ptr; |
++ if (available_bytes < buffer_size_in_bytes) |
+ { |
-+ AL_PRINT("buffer underrun\n"); |
-+ return; |
++ AL_PRINT("buffer underrun (buffer size=%d) (only buffering %d)\n", buffer_size_in_bytes, available_bytes); |
++ buffer_size_in_bytes = available_bytes; |
elijahtaylor1
2013/01/31 00:32:24
If you're going to fill in part of the buffer, you
Sam Clegg
2013/01/31 17:13:45
Done.
|
+ } |
+ |
+ if (data->read_ptr + buffer_size_in_bytes > data->size) |
@@ -140,9 +144,13 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ buffer_size_in_bytes); |
+ } |
+ |
++ pthread_mutex_lock(&data->mutex); |
+ data->read_ptr += buffer_size_in_bytes; |
++ // wrap read_ptr in circular buffer; |
+ if (data->read_ptr >= data->size) |
+ data->read_ptr -= data->size; |
++ pthread_cond_signal(&data->cond); |
++ pthread_mutex_unlock(&data->mutex); |
nfullagar1
2013/01/30 22:19:31
Putting locks in the audio callback is usually not
Sam Clegg
2013/01/31 17:13:45
Removed the pthread stuff from this change.
|
+} |
+ |
+static const ALCchar ppapiDevice[] = "PPAPI Output"; |
@@ -154,40 +162,71 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ |
+ ALuint UpdateSizeInBytes = Device->UpdateSize * kFrameSizeInBytes; |
+ ALuint SampleFrameInBytes = data->sample_frame_count * kFrameSizeInBytes; |
++ |
+ /* Start to buffer when less than this many bytes are buffered. Keep this |
+ * small for low latency but large enough so we don't starve Pepper. |
++ * |
++ * SampleFrameInBytes is the size of the buffer that PPAPI asks for each |
++ * callback. We want to keep twice this amount in the buffer at any given |
++ * time. |
+ */ |
-+ const ALuint MinBufferSizeInBytes = |
-+ min(max(SampleFrameInBytes*4, UpdateSizeInBytes), data->size/2); |
++ const ALuint MinBufferSizeInBytes = max(SampleFrameInBytes, |
elijahtaylor1
2013/01/31 00:32:24
Did you mean (SampleFrameInBytes*2, UpdateSizeInBy
Sam Clegg
2013/01/31 17:13:45
Done.
|
++ UpdateSizeInBytes*2); |
+ |
-+ while(!data->killNow && Device->Connected) |
++ pthread_mutex_lock(&data->mutex); |
++ while (!data->killNow && Device->Connected) |
+ { |
+ ALuint write_proxy = data->write_ptr; |
++ |
+ if (data->read_ptr > data->write_ptr) |
+ write_proxy = data->write_ptr + data->size; |
+ |
-+ if (data->read_ptr + MinBufferSizeInBytes >= write_proxy) |
++ ALuint bytes_in_buffer = write_proxy - data->read_ptr; |
++ if (bytes_in_buffer < MinBufferSizeInBytes) |
+ { |
-+ aluMixData(Device, |
-+ data->buffer + data->write_ptr, |
-+ Device->UpdateSize); |
-+ if (data->write_ptr + UpdateSizeInBytes > data->size) |
++ // Time to buffer more data |
++ pthread_mutex_unlock(&data->mutex); |
++ |
++ // Mix samples into buffer in UpdateSizeInBytes chunks |
++ // untill there are more then MinBufferSizeInBytes available. |
elijahtaylor1
2013/01/31 00:32:24
until
than
Sam Clegg
2013/01/31 17:13:45
Reverted this stuff until we can find a non-busy s
|
++ while (bytes_in_buffer < MinBufferSizeInBytes) |
+ { |
-+ /* Spilled over the edge, copy the last bits to the beginning |
-+ * of the buffer. |
-+ */ |
-+ memcpy(data->buffer, |
-+ data->buffer + data->size, |
-+ UpdateSizeInBytes - (data->size - data->write_ptr)); |
++ aluMixData(Device, |
++ data->buffer + data->write_ptr, |
++ Device->UpdateSize); |
++ if (data->write_ptr + UpdateSizeInBytes > data->size) |
++ { |
++ /* Spilled over the edge, copy the last bits to the beginning |
elijahtaylor1
2013/01/31 00:32:24
80 cols. I know it's annoying because there might
Sam Clegg
2013/01/31 17:13:45
Reverted this stuff until we can find a non-busy s
|
++ * of the buffer. |
++ */ |
++ memcpy(data->buffer, |
++ data->buffer + data->size, |
++ UpdateSizeInBytes - (data->size - data->write_ptr)); |
++ } |
++ |
++ data->write_ptr += UpdateSizeInBytes; |
++ if (data->write_ptr >= data->size) |
++ data->write_ptr -= data->size; |
++ |
++ bytes_in_buffer += UpdateSizeInBytes; |
+ } |
+ |
-+ data->write_ptr += UpdateSizeInBytes; |
-+ if (data->write_ptr >= data->size) |
-+ data->write_ptr -= data->size; |
++ pthread_mutex_lock(&data->mutex); |
++ } |
++ else |
++ { |
++ // The first time we finished buffering we trigger the reader to |
++ // start reading |
++ if (!data->buffer_ready) |
++ { |
++ data->buffer_ready = 1; |
++ } |
++ |
++ // Wait for reader to read more data |
++ pthread_cond_wait(&data->cond, &data->mutex); |
+ } |
-+ /* Small 1 ms sleep so we don't use too much CPU time. */ |
-+ Sleep(1); |
+ } |
++ pthread_mutex_unlock(&data->mutex); |
+ |
+ return 0; |
+} |
@@ -210,13 +249,14 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ rate, |
+ kRequestedFrameCount); |
+ |
++ //AL_PRINT("recommend frames: %d (rate=%d) (size=%d)\n", data->sample_frame_count, rate, data->sample_frame_count*2*2); |
+ data->audio_config_resource = |
+ data->audio_config->CreateStereo16Bit(gInstance, |
+ rate, |
+ data->sample_frame_count); |
+ |
+ if (PP_FALSE == data->audio_config->IsAudioConfig(data->audio_config_resource)) { |
-+ AL_PRINT("PPAPI initialization: audio config creation failed."); |
++ AL_PRINT("PPAPI initialization: audio config creation failed."); |
+ data->main_thread_init_status = -1; |
+ return; |
+ } |
@@ -227,13 +267,13 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ (void*)data); |
+ |
+ if (PP_FALSE == data->audio->IsAudio(data->audio_resource)) { |
-+ AL_PRINT("PPAPI initialization: audio resource creation failed."); |
++ AL_PRINT("PPAPI initialization: audio resource creation failed."); |
+ data->main_thread_init_status = -1; |
+ return; |
+ } |
+ |
+ if (PP_FALSE == data->audio->StartPlayback(data->audio_resource)) { |
-+ AL_PRINT("PPAPI initialization: start playback failed."); |
++ AL_PRINT("PPAPI initialization: start playback failed."); |
+ data->main_thread_init_status = -1; |
+ return; |
+ } |
@@ -246,9 +286,9 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+{ |
+ ppapi_data *data; |
+ |
-+ if(!deviceName) |
++ if (!deviceName) |
+ deviceName = ppapiDevice; |
-+ else if(strcmp(deviceName, ppapiDevice) != 0) |
++ else if (strcmp(deviceName, ppapiDevice) != 0) |
+ return ALC_FALSE; |
+ |
+ int channels = ChannelsFromDevFmt(device->FmtChans); |
@@ -271,6 +311,8 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ } |
+ |
+ data = (ppapi_data*)calloc(1, sizeof(*data)); |
++ pthread_mutex_init(&data->mutex, NULL); |
++ pthread_cond_init(&data->cond, NULL); |
+ |
+ device->szDeviceName = strdup(deviceName); |
+ device->ExtraData = data; |
@@ -353,13 +395,15 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ ppapi_data *data = (ppapi_data*)device->ExtraData; |
+ |
+ ALuint UpdateSizeInBytes = device->UpdateSize * kFrameSizeInBytes; |
++ ALuint SampleFrameInBytes = data->sample_frame_count * kFrameSizeInBytes; |
+ /* kBufferPadMult is added to protect against buffer underruns. */ |
-+ data->size = UpdateSizeInBytes * kBufferPadMult; |
++ data->size = max(UpdateSizeInBytes, SampleFrameInBytes) * kBufferPadMult; |
++ |
+ /* Extra UpdateSize added so we can read off the end of the buffer in one |
+ * shot from aluMixData, but treat the buffer like it's of size data->size. |
+ */ |
+ data->buffer = calloc(1, data->size + UpdateSizeInBytes); |
-+ if(!data->buffer) |
++ if (!data->buffer) |
+ { |
+ AL_PRINT("buffer malloc failed\n"); |
+ return ALC_FALSE; |
@@ -369,13 +413,12 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ data->read_ptr = 0; |
+ data->write_ptr = 0; |
+ data->thread = StartThread(PpapiProc, device); |
-+ if(data->thread == NULL) |
++ if (data->thread == NULL) |
+ { |
+ free(data->buffer); |
+ data->buffer = NULL; |
+ return ALC_FALSE; |
+ } |
-+ data->buffer_ready = 1; |
+ return ALC_TRUE; |
+} |
+ |
@@ -383,15 +426,19 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+{ |
+ ppapi_data *data = (ppapi_data*)device->ExtraData; |
+ |
-+ if(!data->thread) |
++ if (!data->thread) |
+ return; |
+ |
++ // Signal thread to die |
++ pthread_mutex_lock(&data->mutex); |
+ data->killNow = 1; |
++ pthread_cond_signal(&data->cond); |
++ pthread_mutex_unlock(&data->mutex); |
++ |
+ StopThread(data->thread); |
-+ data->thread = NULL; |
+ |
++ data->thread = NULL; |
+ data->killNow = 0; |
-+ |
+ data->buffer_ready = 0; |
+ free(data->buffer); |
+ data->buffer = NULL; |
@@ -431,9 +478,9 @@ diff -Naur openal-soft-1.13/Alc/ppapi.c openal-soft-1.13-nacl/Alc/ppapi.c |
+ |
+void alc_ppapi_probe(int type) |
+{ |
-+ if(type == DEVICE_PROBE) |
++ if (type == DEVICE_PROBE) |
+ AppendDeviceList(ppapiDevice); |
-+ else if(type == ALL_DEVICE_PROBE) |
++ else if (type == ALL_DEVICE_PROBE) |
+ AppendAllDeviceList(ppapiDevice); |
+} |
diff -Naur openal-soft-1.13/Alc/wave.c openal-soft-1.13-nacl/Alc/wave.c |