b=952756 always remember offset and duration from Start() r=padenot

--HG--
extra : transplant_source : %9A%3D%12wAbL%0D%E1%16G%A9%B7%23%A9%16%7F%8C%2B%18
This commit is contained in:
Karl Tomlinson 2014-01-07 12:53:47 +13:00
Родитель edd478a6df
Коммит 9da3d20771
2 изменённых файлов: 18 добавлений и 27 удалений

Просмотреть файл

@ -472,8 +472,7 @@ AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext)
ChannelInterpretation::Speakers)
, mLoopStart(0.0)
, mLoopEnd(0.0)
, mOffset(0.0)
, mDuration(std::numeric_limits<double>::min())
// mOffset and mDuration are initialized in Start().
, mPlaybackRate(new AudioParam(MOZ_THIS_IN_INITIALIZER_LIST(),
SendPlaybackRateToStream, 1.0f))
, mLoop(false)
@ -521,19 +520,14 @@ AudioBufferSourceNode::Start(double aWhen, double aOffset,
return;
}
if (mBuffer) {
double duration = aDuration.WasPassed() ?
aDuration.Value() :
std::numeric_limits<double>::min();
SendOffsetAndDurationParametersToStream(ns, aOffset, duration);
} else {
// Remember our arguments so that we can use them once we have a buffer.
// We can't send these parameters now because we don't know the buffer
// sample rate.
// Remember our arguments so that we can use them when we get a new buffer.
mOffset = aOffset;
mDuration = aDuration.WasPassed() ?
aDuration.Value() :
std::numeric_limits<double>::min();
mDuration = aDuration.WasPassed() ? aDuration.Value()
: std::numeric_limits<double>::min();
// We can't send these parameters without a buffer because we don't know the
// buffer's sample rate or length.
if (mBuffer) {
SendOffsetAndDurationParametersToStream(ns);
}
// Don't set parameter unnecessarily
@ -558,7 +552,7 @@ AudioBufferSourceNode::SendBufferParameterToStream(JSContext* aCx)
ns->SetInt32Parameter(SAMPLE_RATE, rate);
if (mStartCalled) {
SendOffsetAndDurationParametersToStream(ns, mOffset, mDuration);
SendOffsetAndDurationParametersToStream(ns);
}
} else {
ns->SetBuffer(nullptr);
@ -566,16 +560,14 @@ AudioBufferSourceNode::SendBufferParameterToStream(JSContext* aCx)
}
void
AudioBufferSourceNode::SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream,
double aOffset,
double aDuration)
AudioBufferSourceNode::SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream)
{
NS_ASSERTION(mBuffer && mStartCalled,
"Only call this when we have a buffer and start() has been called");
float rate = mBuffer->SampleRate();
int32_t bufferLength = mBuffer->Length();
int32_t offsetSamples = std::max(0, NS_lround(aOffset * rate));
int32_t offsetSamples = std::max(0, NS_lround(mOffset * rate));
if (offsetSamples >= bufferLength) {
// The offset falls past the end of the buffer. In this case, we need to
@ -593,8 +585,8 @@ AudioBufferSourceNode::SendOffsetAndDurationParametersToStream(AudioNodeStream*
}
int32_t playingLength = bufferLength - offsetSamples;
if (aDuration != std::numeric_limits<double>::min()) {
playingLength = std::min(NS_lround(aDuration * rate), playingLength);
if (mDuration != std::numeric_limits<double>::min()) {
playingLength = std::min(NS_lround(mDuration * rate), playingLength);
}
aStream->SetInt32Parameter(DURATION, playingLength);
}

Просмотреть файл

@ -111,9 +111,10 @@ public:
private:
friend class AudioBufferSourceNodeEngine;
// START, OFFSET and DURATION are always set by start() (along with setting
// mBuffer to something non-null).
// STOP is set by stop().
// START is sent during Start().
// STOP is sent during Stop().
// OFFSET and DURATION are sent when SetBuffer() and Start() have
// been called (along with sending the buffer).
enum EngineParameters {
SAMPLE_RATE,
START,
@ -129,9 +130,7 @@ private:
void SendLoopParametersToStream();
void SendBufferParameterToStream(JSContext* aCx);
void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream,
double aOffset,
double aDuration);
void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream);
static void SendPlaybackRateToStream(AudioNode* aNode);
private: