Make RangeRemoval use promises

This commit is contained in:
trav90
2017-05-04 02:23:56 -05:00
committed by roytam1
parent 11cc3e6cb8
commit 319f10d372
5 changed files with 14 additions and 54 deletions
+7 -45
View File
@@ -64,34 +64,6 @@ private:
uint32_t mUpdateID;
};
class RangeRemovalRunnable : public nsRunnable {
public:
RangeRemovalRunnable(SourceBuffer* aSourceBuffer,
double aStart,
double aEnd)
: mSourceBuffer(aSourceBuffer)
, mStart(aStart)
, mEnd(aEnd)
{ }
NS_IMETHOD Run() override 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;
};
void
SourceBuffer::SetMode(SourceBufferAppendMode aMode, ErrorResult& aRv)
{
@@ -251,29 +223,19 @@ SourceBuffer::Remove(double aStart, double aEnd, ErrorResult& aRv)
mMediaSource->SetReadyState(MediaSourceReadyState::Open);
}
StartUpdating();
nsRefPtr<nsIRunnable> task = new RangeRemovalRunnable(this, aStart, aEnd);
NS_DispatchToMainThread(task);
RangeRemoval(aStart, aEnd);
}
void
SourceBuffer::RangeRemoval(double aStart, double aEnd)
{
StartUpdating();
DoRangeRemoval(aStart, aEnd);
nsRefPtr<nsIRunnable> task =
NS_NewRunnableMethod(this, &SourceBuffer::StopUpdating);
NS_DispatchToMainThread(task);
}
void
SourceBuffer::DoRangeRemoval(double aStart, double aEnd)
{
MSE_DEBUG("DoRangeRemoval(%f, %f)", aStart, aEnd);
if (mContentManager && !IsInfinite(aStart)) {
mContentManager->RangeRemoval(TimeUnit::FromSeconds(aStart),
TimeUnit::FromSeconds(aEnd));
}
nsRefPtr<SourceBuffer> self = this;
mContentManager->RangeRemoval(TimeUnit::FromSeconds(aStart),
TimeUnit::FromSeconds(aEnd))
->Then(AbstractThread::MainThread(), __func__,
[self] (bool) { self->StopUpdating(); },
[]() { MOZ_ASSERT(false); });
}
void
-3
View File
@@ -117,8 +117,6 @@ public:
// Runs the range removal algorithm as defined by the MSE spec.
void RangeRemoval(double aStart, double aEnd);
// Actually remove data between aStart and aEnd
void DoRangeRemoval(double aStart, double aEnd);
bool IsActive() const
{
@@ -134,7 +132,6 @@ private:
friend class AsyncEventRunner<SourceBuffer>;
friend class BufferAppendRunnable;
friend class RangeRemovalRunnable;
void DispatchSimpleEvent(const char* aName);
void QueueAsyncSimpleEvent(const char* aName);
@@ -24,6 +24,7 @@ public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SourceBufferContentManager);
typedef MediaPromise<bool, nsresult, /* IsExclusive = */ true> AppendPromise;
typedef AppendPromise RangeRemovalPromise;
static already_AddRefed<SourceBufferContentManager>
CreateManager(MediaSourceDecoder* aParentDecoder, const nsACString& aType);
@@ -48,7 +49,7 @@ public:
// Runs MSE range removal algorithm.
// http://w3c.github.io/media-source/#sourcebuffer-coded-frame-removal
virtual bool RangeRemoval(TimeUnit aStart, TimeUnit aEnd) = 0;
virtual nsRefPtr<RangeRemovalPromise> RangeRemoval(TimeUnit aStart, TimeUnit aEnd) = 0;
enum class EvictDataResult : int8_t
{
+4 -4
View File
@@ -1068,7 +1068,7 @@ TrackBuffer::RemoveDecoder(SourceBufferDecoder* aDecoder)
aDecoder->GetReader()->GetTaskQueue()->Dispatch(task);
}
bool
nsRefPtr<TrackBuffer::RangeRemovalPromise>
TrackBuffer::RangeRemoval(TimeUnit aStart, TimeUnit aEnd)
{
MOZ_ASSERT(NS_IsMainThread());
@@ -1080,14 +1080,14 @@ TrackBuffer::RangeRemoval(TimeUnit aStart, TimeUnit aEnd)
if (!buffered.Length() || aStart > bufferedEnd || aEnd < bufferedStart) {
// Nothing to remove.
return false;
return RangeRemovalPromise::CreateAndResolve(false, __func__);
}
if (aStart > bufferedStart && aEnd < bufferedEnd) {
// TODO. We only handle trimming and removal from the start.
NS_WARNING("RangeRemoval unsupported arguments. "
"Can only handle trimming (trim left or trim right");
return false;
return RangeRemovalPromise::CreateAndResolve(false, __func__);
}
nsTArray<SourceBufferDecoder*> decoders;
@@ -1130,7 +1130,7 @@ TrackBuffer::RangeRemoval(TimeUnit aStart, TimeUnit aEnd)
RemoveEmptyDecoders(decoders);
NotifyTimeRangesChanged();
return true;
return RangeRemovalPromise::CreateAndResolve(true, __func__);
}
void
+1 -1
View File
@@ -48,7 +48,7 @@ public:
// of the buffer through to aTime.
void EvictBefore(TimeUnit aTime) override;
bool RangeRemoval(TimeUnit aStart, TimeUnit aEnd) override;
nsRefPtr<RangeRemovalPromise> RangeRemoval(TimeUnit aStart, TimeUnit aEnd) override;
void AbortAppendData() override;