зеркало из https://github.com/mozilla/pjs.git
Bug 623444 - Remove unused non-blocking code from nsAudioStream. r=doublec
This commit is contained in:
Родитель
df359a60f6
Коммит
3bbc045139
|
@ -226,7 +226,7 @@ nsHTMLAudioElement::MozWriteAudio(const jsval &aData, JSContext *aCx, PRUint32 *
|
|||
// Don't write more than can be written without blocking.
|
||||
PRUint32 writeLen = NS_MIN(mAudioStream->Available(), dataLength);
|
||||
|
||||
nsresult rv = mAudioStream->Write(JS_GetTypedArrayData(tsrc), writeLen, PR_TRUE);
|
||||
nsresult rv = mAudioStream->Write(JS_GetTypedArrayData(tsrc), writeLen);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ class nsAudioStreamLocal : public nsAudioStream
|
|||
|
||||
nsresult Init(PRInt32 aNumChannels, PRInt32 aRate, SampleFormat aFormat);
|
||||
void Shutdown();
|
||||
nsresult Write(const void* aBuf, PRUint32 aCount, PRBool aBlocking);
|
||||
nsresult Write(const void* aBuf, PRUint32 aCount);
|
||||
PRUint32 Available();
|
||||
void SetVolume(double aVolume);
|
||||
void Drain();
|
||||
|
@ -110,12 +110,6 @@ class nsAudioStreamLocal : public nsAudioStream
|
|||
|
||||
SampleFormat mFormat;
|
||||
|
||||
// When a Write() request is made, and the number of samples
|
||||
// requested to be written exceeds the buffer size of the audio
|
||||
// backend, the remaining samples are stored in this variable. They
|
||||
// will be written on the next Write() request.
|
||||
nsTArray<short> mBufferOverflow;
|
||||
|
||||
// PR_TRUE if this audio stream is paused.
|
||||
PRPackedBool mPaused;
|
||||
|
||||
|
@ -134,7 +128,7 @@ class nsAudioStreamRemote : public nsAudioStream
|
|||
|
||||
nsresult Init(PRInt32 aNumChannels, PRInt32 aRate, SampleFormat aFormat);
|
||||
void Shutdown();
|
||||
nsresult Write(const void* aBuf, PRUint32 aCount, PRBool aBlocking);
|
||||
nsresult Write(const void* aBuf, PRUint32 aCount);
|
||||
PRUint32 Available();
|
||||
void SetVolume(double aVolume);
|
||||
void Drain();
|
||||
|
@ -452,7 +446,7 @@ void nsAudioStreamLocal::Shutdown()
|
|||
mInError = PR_TRUE;
|
||||
}
|
||||
|
||||
nsresult nsAudioStreamLocal::Write(const void* aBuf, PRUint32 aCount, PRBool aBlocking)
|
||||
nsresult nsAudioStreamLocal::Write(const void* aBuf, PRUint32 aCount)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aCount % mChannels == 0,
|
||||
"Buffer size must be divisible by channel count");
|
||||
|
@ -461,24 +455,16 @@ nsresult nsAudioStreamLocal::Write(const void* aBuf, PRUint32 aCount, PRBool aBl
|
|||
if (mInError)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRUint32 offset = mBufferOverflow.Length();
|
||||
PRUint32 count = aCount + offset;
|
||||
|
||||
nsAutoArrayPtr<short> s_data(new short[count]);
|
||||
nsAutoArrayPtr<short> s_data(new short[aCount]);
|
||||
|
||||
if (s_data) {
|
||||
for (PRUint32 i=0; i < offset; ++i) {
|
||||
s_data[i] = mBufferOverflow.ElementAt(i);
|
||||
}
|
||||
mBufferOverflow.Clear();
|
||||
|
||||
double scaled_volume = GetVolumeScale() * mVolume;
|
||||
switch (mFormat) {
|
||||
case FORMAT_U8: {
|
||||
const PRUint8* buf = static_cast<const PRUint8*>(aBuf);
|
||||
PRInt32 volume = PRInt32((1 << 16) * scaled_volume);
|
||||
for (PRUint32 i = 0; i < aCount; ++i) {
|
||||
s_data[i + offset] = short(((PRInt32(buf[i]) - 128) * volume) >> 8);
|
||||
s_data[i] = short(((PRInt32(buf[i]) - 128) * volume) >> 8);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -490,7 +476,7 @@ nsresult nsAudioStreamLocal::Write(const void* aBuf, PRUint32 aCount, PRBool aBl
|
|||
#if defined(IS_BIG_ENDIAN)
|
||||
s = ((s & 0x00ff) << 8) | ((s & 0xff00) >> 8);
|
||||
#endif
|
||||
s_data[i + offset] = short((PRInt32(s) * volume) >> 16);
|
||||
s_data[i] = short((PRInt32(s) * volume) >> 16);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -499,11 +485,11 @@ nsresult nsAudioStreamLocal::Write(const void* aBuf, PRUint32 aCount, PRBool aBl
|
|||
for (PRUint32 i = 0; i < aCount; ++i) {
|
||||
float scaled_value = floorf(0.5 + 32768 * buf[i] * scaled_volume);
|
||||
if (buf[i] < 0.0) {
|
||||
s_data[i + offset] = (scaled_value < -32768.0) ?
|
||||
s_data[i] = (scaled_value < -32768.0) ?
|
||||
-32768 :
|
||||
short(scaled_value);
|
||||
} else {
|
||||
s_data[i+offset] = (scaled_value > 32767.0) ?
|
||||
s_data[i] = (scaled_value > 32767.0) ?
|
||||
32767 :
|
||||
short(scaled_value);
|
||||
}
|
||||
|
@ -512,20 +498,9 @@ nsresult nsAudioStreamLocal::Write(const void* aBuf, PRUint32 aCount, PRBool aBl
|
|||
}
|
||||
}
|
||||
|
||||
if (!aBlocking) {
|
||||
// We're running in non-blocking mode, crop the data to the amount
|
||||
// which is available in the audio buffer, and save the rest for
|
||||
// subsequent calls.
|
||||
PRUint32 available = Available();
|
||||
if (available < count) {
|
||||
mBufferOverflow.AppendElements(s_data.get() + available, (count - available));
|
||||
count = available;
|
||||
}
|
||||
}
|
||||
|
||||
if (sa_stream_write(static_cast<sa_stream_t*>(mAudioHandle),
|
||||
s_data.get(),
|
||||
count * sizeof(short)) != SA_SUCCESS)
|
||||
aCount * sizeof(short)) != SA_SUCCESS)
|
||||
{
|
||||
PR_LOG(gAudioStreamLog, PR_LOG_ERROR, ("nsAudioStreamLocal: sa_stream_write error"));
|
||||
mInError = PR_TRUE;
|
||||
|
@ -569,16 +544,6 @@ void nsAudioStreamLocal::Drain()
|
|||
if (mInError)
|
||||
return;
|
||||
|
||||
// Write any remaining unwritten sound data in the overflow buffer
|
||||
if (!mBufferOverflow.IsEmpty()) {
|
||||
if (sa_stream_write(static_cast<sa_stream_t*>(mAudioHandle),
|
||||
mBufferOverflow.Elements(),
|
||||
mBufferOverflow.Length() * sizeof(short)) != SA_SUCCESS)
|
||||
PR_LOG(gAudioStreamLog, PR_LOG_ERROR, ("nsAudioStreamLocal: sa_stream_write error"));
|
||||
mInError = PR_TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
int r = sa_stream_drain(static_cast<sa_stream_t*>(mAudioHandle));
|
||||
if (r != SA_SUCCESS && r != SA_ERROR_INVALID) {
|
||||
PR_LOG(gAudioStreamLog, PR_LOG_ERROR, ("nsAudioStreamLocal: sa_stream_drain error"));
|
||||
|
@ -703,9 +668,7 @@ nsAudioStreamRemote::Shutdown()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsAudioStreamRemote::Write(const void* aBuf,
|
||||
PRUint32 aCount,
|
||||
PRBool aBlocking)
|
||||
nsAudioStreamRemote::Write(const void* aBuf, PRUint32 aCount)
|
||||
{
|
||||
if (!mAudioChild)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
|
@ -85,11 +85,10 @@ public:
|
|||
|
||||
// Write sound data to the audio hardware. aBuf is an array of samples in
|
||||
// the format specified by mFormat of length aCount. aCount should be
|
||||
// evenly divisible by the number of channels in this audio stream.
|
||||
// When aBlocking is PR_TRUE, we'll block until the write has completed,
|
||||
// otherwise we'll buffer any data we can't write immediately, and write
|
||||
// it in a later call.
|
||||
virtual nsresult Write(const void* aBuf, PRUint32 aCount, PRBool aBlocking) = 0;
|
||||
// evenly divisible by the number of channels in this audio stream. If
|
||||
// aCount is larger than the result of Available(), the write will block
|
||||
// until sufficient buffer space is available.
|
||||
virtual nsresult Write(const void* aBuf, PRUint32 aCount) = 0;
|
||||
|
||||
// Return the number of sound samples that can be written to the audio device
|
||||
// without blocking.
|
||||
|
|
|
@ -729,7 +729,7 @@ PRUint32 nsBuiltinDecoderStateMachine::PlaySilence(PRUint32 aSamples,
|
|||
PRUint32 numValues = samples * aChannels;
|
||||
nsAutoArrayPtr<SoundDataValue> buf(new SoundDataValue[numValues]);
|
||||
memset(buf.get(), 0, sizeof(SoundDataValue) * numValues);
|
||||
mAudioStream->Write(buf, numValues, PR_TRUE);
|
||||
mAudioStream->Write(buf, numValues);
|
||||
// Dispatch events to the DOM for the audio just written.
|
||||
mEventManager.QueueWrittenAudioData(buf.get(), numValues,
|
||||
(aSampleOffset + samples) * aChannels);
|
||||
|
@ -760,8 +760,7 @@ PRUint32 nsBuiltinDecoderStateMachine::PlayFromAudioQueue(PRUint64 aSampleOffset
|
|||
// audio stream.
|
||||
if (!mAudioStream->IsPaused()) {
|
||||
mAudioStream->Write(sound->mAudioData,
|
||||
sound->AudioDataLength(),
|
||||
PR_TRUE);
|
||||
sound->AudioDataLength());
|
||||
|
||||
offset = sound->mOffset;
|
||||
samples = sound->mSamples;
|
||||
|
|
|
@ -57,7 +57,7 @@ class AudioWriteEvent : public nsRunnable
|
|||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
mOwner->Write(mData.get(), mCount, true);
|
||||
mOwner->Write(mData.get(), mCount);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче