Bug 1118589: MSE: Run appendBuffer internal's asynchronously. r=cajbir

This commit is contained in:
Jean-Yves Avenard 2015-01-26 21:33:56 +11:00
Родитель 5a0fe42e33
Коммит 78c29d212d
2 изменённых файлов: 55 добавлений и 25 удалений

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

@ -19,6 +19,7 @@
#include "nsIRunnable.h"
#include "nsThreadUtils.h"
#include "prlog.h"
#include <time.h>
struct JSContext;
class JSObject;
@ -36,14 +37,37 @@ extern PRLogModuleInfo* GetMediaSourceAPILog();
#define MSE_API(...)
#endif
// RangeRemoval must be synchronous if appendBuffer is also synchronous.
// While waiting for bug 1118589 to land, ensure RangeRemoval is synchronous
#define APPENDBUFFER_IS_SYNCHRONOUS
namespace mozilla {
namespace dom {
class AppendDataRunnable : public nsRunnable {
public:
AppendDataRunnable(SourceBuffer* aSourceBuffer,
const uint8_t* aData,
uint32_t aLength,
double aTimestampOffset)
: mSourceBuffer(aSourceBuffer)
, mTimestampOffset(aTimestampOffset)
{
mData.AppendElements(aData, aLength);
}
NS_IMETHOD Run() MOZ_OVERRIDE MOZ_FINAL {
mSourceBuffer->AppendData(mData.Elements(),
mData.Length(),
mTimestampOffset);
return NS_OK;
}
private:
nsRefPtr<SourceBuffer> mSourceBuffer;
nsTArray<uint8_t> mData;
double mTimestampOffset;
};
class RangeRemovalRunnable : public nsRunnable {
public:
RangeRemovalRunnable(SourceBuffer* aSourceBuffer,
@ -240,18 +264,8 @@ SourceBuffer::RangeRemoval(double aStart, double aEnd)
{
StartUpdating();
#if defined(APPENDBUFFER_IS_SYNCHRONOUS)
DoRangeRemoval(aStart, aEnd);
// Run the final step of the buffer append algorithm asynchronously to
// ensure the SourceBuffer's updating flag transition behaves as required
// by the spec.
nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &SourceBuffer::StopUpdating);
NS_DispatchToMainThread(event);
#else
nsRefPtr<nsIRunnable> task = new RangeRemovalRunnable(this, aStart, aEnd);
NS_DispatchToMainThread(task);
#endif
}
void
@ -267,9 +281,7 @@ SourceBuffer::DoRangeRemoval(double aStart, double aEnd)
mTrackBuffer->RangeRemoval(start, end);
}
#if !defined(APPENDBUFFER_IS_SYNCHRONOUS)
StopUpdating();
#endif
}
void
@ -405,10 +417,29 @@ SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aR
MOZ_ASSERT(mAppendMode == SourceBufferAppendMode::Segments,
"We don't handle timestampOffset for sequence mode yet");
nsRefPtr<nsIRunnable> task =
new AppendDataRunnable(this, aData, aLength, mTimestampOffset);
NS_DispatchToMainThread(task);
}
void
SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, double aTimestampOffset)
{
if (!mUpdating) {
// The buffer append algorithm has been interrupted by abort().
//
// If the sequence appendBuffer(), abort(), appendBuffer() occurs before
// the first StopUpdating() runnable runs, then a second StopUpdating()
// runnable will be scheduled, but still only one (the first) will queue
// events.
return;
}
MOZ_ASSERT(mMediaSource);
if (aLength) {
if (!mTrackBuffer->AppendData(aData, aLength, mTimestampOffset * USECS_PER_S)) {
nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethodWithArg<bool>(this, &SourceBuffer::AppendError, true);
NS_DispatchToMainThread(event);
if (!mTrackBuffer->AppendData(aData, aLength, aTimestampOffset * USECS_PER_S)) {
AppendError(true);
return;
}
@ -419,12 +450,8 @@ SourceBuffer::AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aR
CheckEndTime();
}
// Run the final step of the buffer append algorithm asynchronously to
// ensure the SourceBuffer's updating flag transition behaves as required
// by the spec.
nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &SourceBuffer::StopUpdating);
NS_DispatchToMainThread(event);
}
StopUpdating();
}
void
SourceBuffer::AppendError(bool aDecoderError)

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

@ -122,6 +122,7 @@ private:
~SourceBuffer();
friend class AsyncEventRunner<SourceBuffer>;
friend class AppendDataRunnable;
void DispatchSimpleEvent(const char* aName);
void QueueAsyncSimpleEvent(const char* aName);
@ -137,6 +138,8 @@ private:
// Shared implementation of AppendBuffer overloads.
void AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv);
void AppendData(const uint8_t* aData, uint32_t aLength,
double aTimestampOffset);
// Implement the "Append Error Algorithm".
// Will call endOfStream() with "decode" error if aDecodeError is true.