Bug 1130826: Run range removal algorithm when setting mediasource duration. r=cajbir a=lmandel
--- a/dom/media/mediasource/SourceBuffer.cpp
+++ b/dom/media/mediasource/SourceBuffer.cpp
@@ -67,26 +67,31 @@ private:
nsRefPtr<LargeDataBuffer> mData;
double mTimestampOffset;
uint32_t mUpdateID;
};
class RangeRemovalRunnable : public nsRunnable {
public:
RangeRemovalRunnable(SourceBuffer* aSourceBuffer,
- double aStart,
- double aEnd)
+ double aStart,
+ double aEnd)
: mSourceBuffer(aSourceBuffer)
, mStart(aStart)
, mEnd(aEnd)
{ }
NS_IMETHOD Run() MOZ_OVERRIDE MOZ_FINAL {
+ if (!mSourceBuffer->mUpdating) {
+ // abort was called in between.
+ return NS_OK;
+ }
mSourceBuffer->DoRangeRemoval(mStart, mEnd);
+ mSourceBuffer->StopUpdating();
return NS_OK;
}
private:
nsRefPtr<SourceBuffer> mSourceBuffer;
double mStart;
double mEnd;
@@ -255,44 +260,41 @@ SourceBuffer::Remove(double aStart, doub
}
if (mUpdating) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
mMediaSource->SetReadyState(MediaSourceReadyState::Open);
}
- RangeRemoval(aStart, aEnd);
+
+ StartUpdating();
+ nsRefPtr<nsIRunnable> task = new RangeRemovalRunnable(this, aStart, aEnd);
+ NS_DispatchToMainThread(task);
}
void
SourceBuffer::RangeRemoval(double aStart, double aEnd)
{
StartUpdating();
-
- nsRefPtr<nsIRunnable> task = new RangeRemovalRunnable(this, aStart, aEnd);
+ DoRangeRemoval(aStart, aEnd);
+ nsRefPtr<nsIRunnable> task =
+ NS_NewRunnableMethod(this, &SourceBuffer::StopUpdating);
NS_DispatchToMainThread(task);
}
void
SourceBuffer::DoRangeRemoval(double aStart, double aEnd)
{
- MSE_DEBUG("SourceBuffer(%p)::DoRangeRemoval (updating:%d)",
- this, mUpdating);
- if (!mUpdating) {
- // abort was called in between.
- return;
- }
+ MSE_DEBUG("SourceBuffer(%p)::DoRangeRemoval", this);
if (mTrackBuffer && !IsInfinite(aStart)) {
int64_t start = aStart * USECS_PER_S;
int64_t end = IsInfinite(aEnd) ? INT64_MAX : (int64_t)(aEnd * USECS_PER_S);
mTrackBuffer->RangeRemoval(start, end);
}
-
- StopUpdating();
}
void
SourceBuffer::Detach()
{
MOZ_ASSERT(NS_IsMainThread());
MSE_DEBUG("SourceBuffer(%p)::Detach", this);
AbortBufferAppend();
--- a/dom/media/mediasource/SourceBuffer.h
+++ b/dom/media/mediasource/SourceBuffer.h
@@ -108,29 +108,30 @@ public:
// Evict data in the source buffer in the given time range.
void Evict(double aStart, double aEnd);
double GetBufferedStart();
double GetBufferedEnd();
// Runs the range removal algorithm as defined by the MSE spec.
- // RangeRemoval will queue a call to DoRangeRemoval.
void RangeRemoval(double aStart, double aEnd);
+ // Actually remove data between aStart and aEnd
void DoRangeRemoval(double aStart, double aEnd);
#if defined(DEBUG)
void Dump(const char* aPath);
#endif
private:
~SourceBuffer();
friend class AsyncEventRunner<SourceBuffer>;
friend class AppendDataRunnable;
+ friend class RangeRemovalRunnable;
void DispatchSimpleEvent(const char* aName);
void QueueAsyncSimpleEvent(const char* aName);
// Update mUpdating and fire the appropriate events.
void StartUpdating();
void StopUpdating();
void AbortUpdating();