mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-06-01 04:18:55 +00:00
Make RangeRemoval use promises
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user