mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 20:01:50 +00:00
Bug 1831451 - Generate a unique Id for both ConfigureMessage and DecoderAgent r=alwu
To batter tracking the ControlMessage logs, ConfigureMessage should generate a unique Id for itself and its following DecodeMessages and FlushMessages. Besides, that unique id can be assigned to DecoderAgent as well. As a result, it's easier to know what ConfigureMessage and DecoderAgent the DecodeMessage/FlushMessage belongs. This patch moves the id generation from DecoderAgent to ConfigureMessage so the id can be used for both of DecoderAgent and ConfigureMessage. Depends on D182124 Differential Revision: https://phabricator.services.mozilla.com/D182291
This commit is contained in:
parent
08b474fbb1
commit
1ed86ac7d7
@ -47,18 +47,6 @@ namespace mozilla {
|
||||
#endif // LOGV
|
||||
#define LOGV(msg, ...) LOG_INTERNAL(Verbose, msg, ##__VA_ARGS__)
|
||||
|
||||
/* static */
|
||||
already_AddRefed<DecoderAgent> DecoderAgent::Create(
|
||||
UniquePtr<TrackInfo>&& aInfo) {
|
||||
MOZ_ASSERT(aInfo);
|
||||
|
||||
// This needs to be atomic since this can run on the main thread or worker
|
||||
// thread.
|
||||
static std::atomic<Id> sNextId = None;
|
||||
RefPtr<DecoderAgent> agent = new DecoderAgent(++sNextId, std::move(aInfo));
|
||||
return agent.forget();
|
||||
}
|
||||
|
||||
DecoderAgent::DecoderAgent(Id aId, UniquePtr<TrackInfo>&& aInfo)
|
||||
: mId(aId),
|
||||
mInfo(std::move(aInfo)),
|
||||
|
@ -42,7 +42,8 @@ class DecoderAgent final {
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecoderAgent);
|
||||
|
||||
static already_AddRefed<DecoderAgent> Create(UniquePtr<TrackInfo>&& aInfo);
|
||||
using Id = uint32_t;
|
||||
DecoderAgent(Id aId, UniquePtr<TrackInfo>&& aInfo);
|
||||
|
||||
// The following APIs are owner thread only.
|
||||
|
||||
@ -57,13 +58,10 @@ class DecoderAgent final {
|
||||
// the term from MediaDataDecoder's one, we call it DrainAndFlush() here.
|
||||
RefPtr<DecodePromise> DrainAndFlush();
|
||||
|
||||
using Id = uint32_t;
|
||||
static constexpr Id None = 0;
|
||||
const Id mId; // A unique id.
|
||||
const UniquePtr<TrackInfo> mInfo;
|
||||
|
||||
private:
|
||||
DecoderAgent(Id aId, UniquePtr<TrackInfo>&& aInfo);
|
||||
~DecoderAgent();
|
||||
|
||||
// Push out all the data in the MediaDataDecoder's pipeline.
|
||||
|
@ -621,10 +621,15 @@ class ConfigureMessage final
|
||||
: public ControlMessage,
|
||||
public MessageRequestHolder<DecoderAgent::ConfigurePromise> {
|
||||
public:
|
||||
explicit ConfigureMessage(UniquePtr<VideoDecoderConfig>&& aConfig)
|
||||
: ControlMessage(nsPrintfCString(
|
||||
"%s-configuration", NS_ConvertUTF16toUTF8(aConfig->mCodec).get())),
|
||||
mConfig(std::move(aConfig)) {}
|
||||
using Id = DecoderAgent::Id;
|
||||
static constexpr Id NoId = 0;
|
||||
static ConfigureMessage* Create(UniquePtr<VideoDecoderConfig>&& aConfig) {
|
||||
// This needs to be atomic since this can run on the main thread or worker
|
||||
// thread.
|
||||
static std::atomic<Id> sNextId = NoId;
|
||||
return new ConfigureMessage(++sNextId, std::move(aConfig));
|
||||
}
|
||||
|
||||
~ConfigureMessage() = default;
|
||||
virtual void Cancel() override { Disconnect(); }
|
||||
virtual bool IsProcessing() override { return Exists(); };
|
||||
@ -632,7 +637,16 @@ class ConfigureMessage final
|
||||
const VideoDecoderConfig& Config() { return *mConfig; }
|
||||
UniquePtr<VideoDecoderConfig> TakeConfig() { return std::move(mConfig); }
|
||||
|
||||
const Id mId; // A unique id shown in log.
|
||||
|
||||
private:
|
||||
ConfigureMessage(Id aId, UniquePtr<VideoDecoderConfig>&& aConfig)
|
||||
: ControlMessage(
|
||||
nsPrintfCString("configure #%d (%s)", aId,
|
||||
NS_ConvertUTF16toUTF8(aConfig->mCodec).get())),
|
||||
mId(aId),
|
||||
mConfig(std::move(aConfig)) {}
|
||||
|
||||
UniquePtr<VideoDecoderConfig> mConfig;
|
||||
};
|
||||
|
||||
@ -663,8 +677,10 @@ class DecodeMessage final
|
||||
Maybe<uint64_t> mDuration;
|
||||
};
|
||||
|
||||
DecodeMessage(Id aId, UniquePtr<ChunkData>&& aData)
|
||||
: ControlMessage(nsPrintfCString("decode #%zu", aId)),
|
||||
DecodeMessage(Id aId, ConfigureMessage::Id aConfigId,
|
||||
UniquePtr<ChunkData>&& aData)
|
||||
: ControlMessage(
|
||||
nsPrintfCString("decode #%zu (config #%d)", aId, aConfigId)),
|
||||
mId(aId),
|
||||
mData(std::move(aData)) {}
|
||||
~DecodeMessage() = default;
|
||||
@ -690,8 +706,9 @@ class FlushMessage final
|
||||
public MessageRequestHolder<DecoderAgent::DecodePromise> {
|
||||
public:
|
||||
using Id = size_t;
|
||||
FlushMessage(Id aId, Promise* aPromise)
|
||||
: ControlMessage(nsPrintfCString("flush #%zu", aId)),
|
||||
FlushMessage(Id aId, ConfigureMessage::Id aConfigId, Promise* aPromise)
|
||||
: ControlMessage(
|
||||
nsPrintfCString("flush #%zu (config #%d)", aId, aConfigId)),
|
||||
mId(aId),
|
||||
mPromise(aPromise) {}
|
||||
~FlushMessage() = default;
|
||||
@ -763,6 +780,7 @@ VideoDecoder::VideoDecoder(nsIGlobalObject* aParent,
|
||||
mActiveConfig(nullptr),
|
||||
mDecodeQueueSize(0),
|
||||
mDequeueEventScheduled(false),
|
||||
mLatestConfigureId(ConfigureMessage::NoId),
|
||||
mDecodeCounter(0),
|
||||
mFlushCounter(0) {
|
||||
MOZ_ASSERT(mErrorCallback);
|
||||
@ -841,7 +859,8 @@ void VideoDecoder::Configure(const VideoDecoderConfig& aConfig,
|
||||
mFlushCounter = 0;
|
||||
|
||||
mControlMessageQueue.emplace(
|
||||
UniquePtr<ControlMessage>(new ConfigureMessage(std::move(config))));
|
||||
UniquePtr<ControlMessage>(ConfigureMessage::Create(std::move(config))));
|
||||
mLatestConfigureId = mControlMessageQueue.back()->AsConfigureMessage()->mId;
|
||||
LOG("VideoDecoder %p enqueues %s", this,
|
||||
mControlMessageQueue.back()->ToString().get());
|
||||
ProcessControlMessageQueue();
|
||||
@ -868,8 +887,9 @@ void VideoDecoder::Decode(EncodedVideoChunk& aChunk, ErrorResult& aRv) {
|
||||
}
|
||||
|
||||
mDecodeQueueSize += 1;
|
||||
mControlMessageQueue.emplace(UniquePtr<ControlMessage>(new DecodeMessage(
|
||||
++mDecodeCounter, MakeUnique<DecodeMessage::ChunkData>(aChunk))));
|
||||
mControlMessageQueue.emplace(UniquePtr<ControlMessage>(
|
||||
new DecodeMessage(++mDecodeCounter, mLatestConfigureId,
|
||||
MakeUnique<DecodeMessage::ChunkData>(aChunk))));
|
||||
LOGV("VideoDecoder %p enqueues %s", this,
|
||||
mControlMessageQueue.back()->ToString().get());
|
||||
ProcessControlMessageQueue();
|
||||
@ -893,8 +913,8 @@ already_AddRefed<Promise> VideoDecoder::Flush(ErrorResult& aRv) {
|
||||
|
||||
mKeyChunkRequired = true;
|
||||
|
||||
mControlMessageQueue.emplace(
|
||||
UniquePtr<ControlMessage>(new FlushMessage(++mFlushCounter, p)));
|
||||
mControlMessageQueue.emplace(UniquePtr<ControlMessage>(
|
||||
new FlushMessage(++mFlushCounter, mLatestConfigureId, p)));
|
||||
LOG("VideoDecoder %p enqueues %s", this,
|
||||
mControlMessageQueue.back()->ToString().get());
|
||||
ProcessControlMessageQueue();
|
||||
@ -1267,7 +1287,7 @@ VideoDecoder::MessageProcessedResult VideoDecoder::ProcessConfigureMessage(
|
||||
|
||||
auto i = CreateVideoInfo(msg->Config());
|
||||
if (!CanDecode(msg->Config()) || i.isErr() ||
|
||||
!CreateDecoderAgent(msg->TakeConfig(), i.unwrap())) {
|
||||
!CreateDecoderAgent(msg->mId, msg->TakeConfig(), i.unwrap())) {
|
||||
mProcessingMessage.reset();
|
||||
DebugOnly<Result<Ok, nsresult>> r =
|
||||
Close(NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR);
|
||||
@ -1535,7 +1555,8 @@ VideoDecoder::MessageProcessedResult VideoDecoder::ProcessFlushMessage(
|
||||
// ShutdownpPomise-resolver. In case 2, the entry point is in mWorkerRef's
|
||||
// shutting down callback. In case 3, the entry point is in mWorkerRef's
|
||||
// shutting down callback.
|
||||
bool VideoDecoder::CreateDecoderAgent(UniquePtr<VideoDecoderConfig>&& aConfig,
|
||||
bool VideoDecoder::CreateDecoderAgent(DecoderAgent::Id aId,
|
||||
UniquePtr<VideoDecoderConfig>&& aConfig,
|
||||
UniquePtr<TrackInfo>&& aInfo) {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(mState == CodecState::Configured);
|
||||
@ -1571,7 +1592,7 @@ bool VideoDecoder::CreateDecoderAgent(UniquePtr<VideoDecoderConfig>&& aConfig,
|
||||
mWorkerRef = new ThreadSafeWorkerRef(workerRef);
|
||||
}
|
||||
|
||||
mAgent = DecoderAgent::Create(std::move(aInfo));
|
||||
mAgent = MakeRefPtr<DecoderAgent>(aId, std::move(aInfo));
|
||||
mActiveConfig = std::move(aConfig);
|
||||
|
||||
// ShutdownBlockingTicket requires an unique name to register its own
|
||||
|
@ -154,7 +154,8 @@ class VideoDecoder final : public DOMEventTargetHelper {
|
||||
UniquePtr<ControlMessage>& aMessage);
|
||||
|
||||
// Returns true when mAgent can be created.
|
||||
bool CreateDecoderAgent(UniquePtr<VideoDecoderConfig>&& aConfig,
|
||||
bool CreateDecoderAgent(DecoderAgent::Id aId,
|
||||
UniquePtr<VideoDecoderConfig>&& aConfig,
|
||||
UniquePtr<TrackInfo>&& aInfo);
|
||||
void DestroyDecoderAgentIfAny();
|
||||
|
||||
@ -177,6 +178,9 @@ class VideoDecoder final : public DOMEventTargetHelper {
|
||||
uint32_t mDecodeQueueSize;
|
||||
bool mDequeueEventScheduled;
|
||||
|
||||
// A unique id tracking the ConfigureMessage and will be used as the
|
||||
// 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.
|
||||
size_t mDecodeCounter;
|
||||
|
Loading…
x
Reference in New Issue
Block a user