summaryrefslogtreecommitdiffstats
path: root/dom/media/webcodecs/DecoderTemplate.h
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/webcodecs/DecoderTemplate.h')
-rw-r--r--dom/media/webcodecs/DecoderTemplate.h39
1 files changed, 23 insertions, 16 deletions
diff --git a/dom/media/webcodecs/DecoderTemplate.h b/dom/media/webcodecs/DecoderTemplate.h
index fe0cb5baee..69d4e2f03d 100644
--- a/dom/media/webcodecs/DecoderTemplate.h
+++ b/dom/media/webcodecs/DecoderTemplate.h
@@ -9,6 +9,8 @@
#include <queue>
+#include "SimpleMap.h"
+#include "WebCodecsUtils.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/DecoderAgent.h"
#include "mozilla/MozPromise.h"
@@ -18,7 +20,6 @@
#include "mozilla/dom/WorkerRef.h"
#include "mozilla/media/MediaUtils.h"
#include "nsStringFwd.h"
-#include "WebCodecsUtils.h"
namespace mozilla {
@@ -76,7 +77,8 @@ class DecoderTemplate : public DOMEventTargetHelper {
const ConfigTypeInternal& Config() { return *mConfig; }
UniquePtr<ConfigTypeInternal> TakeConfig() { return std::move(mConfig); }
- const Id mId; // A unique id shown in log.
+ // The id of a configure request.
+ const Id mId;
private:
ConfigureMessage(Id aId, UniquePtr<ConfigTypeInternal>&& aConfig);
@@ -88,16 +90,18 @@ class DecoderTemplate : public DOMEventTargetHelper {
: public ControlMessage,
public MessageRequestHolder<DecoderAgent::DecodePromise> {
public:
- using Id = size_t;
+ using SeqId = size_t;
using ConfigId = typename Self::ConfigureMessage::Id;
- DecodeMessage(Id aId, ConfigId aConfigId,
+ DecodeMessage(SeqId aSeqId, ConfigId aConfigId,
UniquePtr<InputTypeInternal>&& aData);
~DecodeMessage() = default;
virtual void Cancel() override { Disconnect(); }
virtual bool IsProcessing() override { return Exists(); };
virtual DecodeMessage* AsDecodeMessage() override { return this; }
- const Id mId; // A unique id shown in log.
+ // The sequence id of a decode request associated with a specific
+ // configuration.
+ const SeqId mSeqId;
UniquePtr<InputTypeInternal> mData;
};
@@ -105,20 +109,18 @@ class DecoderTemplate : public DOMEventTargetHelper {
: public ControlMessage,
public MessageRequestHolder<DecoderAgent::DecodePromise> {
public:
- using Id = size_t;
+ using SeqId = size_t;
using ConfigId = typename Self::ConfigureMessage::Id;
- FlushMessage(Id aId, ConfigId aConfigId, Promise* aPromise);
+ FlushMessage(SeqId aSeqId, ConfigId aConfigId);
~FlushMessage() = default;
virtual void Cancel() override { Disconnect(); }
virtual bool IsProcessing() override { return Exists(); };
virtual FlushMessage* AsFlushMessage() override { return this; }
- already_AddRefed<Promise> TakePromise() { return mPromise.forget(); }
- void RejectPromiseIfAny(const nsresult& aReason);
-
- const Id mId; // A unique id shown in log.
- private:
- RefPtr<Promise> mPromise;
+ // The sequence id of a flush request associated with a specific
+ // configuration.
+ const SeqId mSeqId;
+ const int64_t mUniqueId;
};
protected:
@@ -176,7 +178,7 @@ class DecoderTemplate : public DOMEventTargetHelper {
nsresult FireEvent(nsAtom* aTypeWithOn, const nsAString& aEventType);
void ProcessControlMessageQueue();
- void CancelPendingControlMessages(const nsresult& aResult);
+ void CancelPendingControlMessagesAndFlushPromises(const nsresult& aResult);
// Queue a task to the control thread. This is to be used when a task needs to
// perform multiple steps.
@@ -209,6 +211,11 @@ class DecoderTemplate : public DOMEventTargetHelper {
std::queue<UniquePtr<ControlMessage>> mControlMessageQueue;
UniquePtr<ControlMessage> mProcessingMessage;
+ // When a flush request is initiated, a promise is created and stored in
+ // mPendingFlushPromises until it is settled in the task delivering the flush
+ // result or Reset() is called before the promise is settled.
+ SimpleMap<int64_t, RefPtr<Promise>> mPendingFlushPromises;
+
uint32_t mDecodeQueueSize;
bool mDequeueEventScheduled;
@@ -216,10 +223,10 @@ class DecoderTemplate : public DOMEventTargetHelper {
// DecoderAgent's Id.
uint32_t mLatestConfigureId;
// Tracking how many decode data has been enqueued and this number will be
- // used as the DecodeMessage's Id.
+ // used as the DecodeMessage's sequence Id.
size_t mDecodeCounter;
// Tracking how many flush request has been enqueued and this number will be
- // used as the FlushMessage's Id.
+ // used as the FlushMessage's sequence Id.
size_t mFlushCounter;
// DecoderAgent will be created every time "configure" is being processed, and