Bug 768000 - Don't race when destroying plugin audio tracks on Android r=blassey

--HG--
extra : rebase_source : 5e15ec8e1132cbc862b3f7f69555432beb0b9169
This commit is contained in:
James Willcox 2013-01-23 15:18:36 -05:00
parent 5b106e3b14
commit 208cbe223c

View File

@ -14,6 +14,7 @@
#include "ANPBase.h"
#include "nsIThread.h"
#include "nsThreadUtils.h"
#include "mozilla/Mutex.h"
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPluginsAudio" , ## args)
#define ASSIGN(obj, name) (obj)->name = anp_audio_##name
@ -97,6 +98,8 @@ struct ANPAudioTrack {
unsigned int isStopped;
unsigned int keepGoing;
mozilla::Mutex* lock;
void* user;
ANPAudioCallbackProc proc;
ANPSampleFormat format;
@ -142,13 +145,20 @@ AudioRunnable::Run()
buffer.format = mTrack->format;
buffer.bufferData = (void*) byte;
while (mTrack->keepGoing)
while (true)
{
// reset the buffer size
buffer.size = mTrack->bufferSize;
{
mozilla::MutexAutoLock lock(*mTrack->lock);
// Get data from the plugin
mTrack->proc(kMoreData_ANPAudioEvent, mTrack->user, &buffer);
if (!mTrack->keepGoing)
break;
// Get data from the plugin
mTrack->proc(kMoreData_ANPAudioEvent, mTrack->user, &buffer);
}
if (buffer.size == 0) {
LOG("%p - kMoreData_ANPAudioEvent", mTrack);
@ -178,6 +188,8 @@ AudioRunnable::Run()
jenv->DeleteGlobalRef(mTrack->output_unit);
jenv->DeleteGlobalRef(mTrack->at_class);
delete mTrack->lock;
free(mTrack);
jenv->ReleaseByteArrayElements(bytearray, byte, 0);
@ -210,6 +222,7 @@ anp_audio_newTrack(uint32_t sampleRate, // sampling rate in Hz
s->user = user;
s->proc = proc;
s->format = format;
s->lock = new mozilla::Mutex("ANPAudioTrack");
int jformat;
switch (format) {
@ -275,6 +288,7 @@ anp_audio_deleteTrack(ANPAudioTrack* s)
return;
}
mozilla::MutexAutoLock lock(*s->lock);
s->keepGoing = false;
// deallocation happens in the AudioThread. There is a