Bug 1872951 - Remove unnecessary MOZ_CAN_RUN_SCRIPT* r=media-playback-reviewers,alwu

This patch removes unnecessary MOZ_CAN_RUN_SCRIPT* annotations in the
code.

Differential Revision: https://phabricator.services.mozilla.com/D197710
This commit is contained in:
Chun-Min Chang 2024-01-05 00:43:53 +00:00
parent 81e3221d97
commit e6b8073a63
2 changed files with 121 additions and 140 deletions

View File

@ -341,11 +341,10 @@ void DecoderTemplate<DecoderType>::ScheduleDequeueEventIfNeeded() {
}
mDequeueEventScheduled = true;
QueueATask("dequeue event task",
[self = RefPtr{this}]() MOZ_CAN_RUN_SCRIPT_BOUNDARY {
self->FireEvent(nsGkAtoms::ondequeue, u"dequeue"_ns);
self->mDequeueEventScheduled = false;
});
QueueATask("dequeue event task", [self = RefPtr{this}]() {
self->FireEvent(nsGkAtoms::ondequeue, u"dequeue"_ns);
self->mDequeueEventScheduled = false;
});
}
template <typename DecoderType>
@ -494,7 +493,7 @@ MessageProcessedResult DecoderTemplate<DecoderType>::ProcessConfigureMessage(
->Then(GetCurrentSerialEventTarget(), __func__,
[self = RefPtr{this}, id = mAgent->mId](
const DecoderAgent::ConfigurePromise::ResolveOrRejectValue&
aResult) MOZ_CAN_RUN_SCRIPT_BOUNDARY {
aResult) {
MOZ_ASSERT(self->mProcessingMessage);
MOZ_ASSERT(self->mProcessingMessage->AsConfigureMessage());
MOZ_ASSERT(self->mState == CodecState::Configured);
@ -564,7 +563,7 @@ MessageProcessedResult DecoderTemplate<DecoderType>::ProcessDecodeMessage(
// Treat it like decode error if no DecoderAgent is available or the encoded
// data is invalid.
auto closeOnError = [&]() MOZ_CAN_RUN_SCRIPT_BOUNDARY {
auto closeOnError = [&]() {
mProcessingMessage.reset();
QueueATask("Error during decode",
[self = RefPtr{this}]() MOZ_CAN_RUN_SCRIPT_BOUNDARY {
@ -589,65 +588,62 @@ MessageProcessedResult DecoderTemplate<DecoderType>::ProcessDecodeMessage(
}
mAgent->Decode(data.get())
->Then(GetCurrentSerialEventTarget(), __func__,
[self = RefPtr{this}, id = mAgent->mId](
DecoderAgent::DecodePromise::ResolveOrRejectValue&& aResult)
MOZ_CAN_RUN_SCRIPT_BOUNDARY {
MOZ_ASSERT(self->mProcessingMessage);
MOZ_ASSERT(self->mProcessingMessage->AsDecodeMessage());
MOZ_ASSERT(self->mState == CodecState::Configured);
MOZ_ASSERT(self->mAgent);
MOZ_ASSERT(id == self->mAgent->mId);
MOZ_ASSERT(self->mActiveConfig);
->Then(
GetCurrentSerialEventTarget(), __func__,
[self = RefPtr{this}, id = mAgent->mId](
DecoderAgent::DecodePromise::ResolveOrRejectValue&& aResult) {
MOZ_ASSERT(self->mProcessingMessage);
MOZ_ASSERT(self->mProcessingMessage->AsDecodeMessage());
MOZ_ASSERT(self->mState == CodecState::Configured);
MOZ_ASSERT(self->mAgent);
MOZ_ASSERT(id == self->mAgent->mId);
MOZ_ASSERT(self->mActiveConfig);
DecodeMessage* msg =
self->mProcessingMessage->AsDecodeMessage();
LOGV("%s %p, DecoderAgent #%d %s has been %s",
DecoderType::Name.get(), self.get(), id,
msg->ToString().get(),
aResult.IsResolve() ? "resolved" : "rejected");
DecodeMessage* msg = self->mProcessingMessage->AsDecodeMessage();
LOGV("%s %p, DecoderAgent #%d %s has been %s",
DecoderType::Name.get(), self.get(), id, msg->ToString().get(),
aResult.IsResolve() ? "resolved" : "rejected");
nsCString msgStr = msg->ToString();
nsCString msgStr = msg->ToString();
msg->Complete();
self->mProcessingMessage.reset();
msg->Complete();
self->mProcessingMessage.reset();
if (aResult.IsReject()) {
// The spec asks to queue a task to run close the decoder
// with an EncodingError so we log the exact error here.
const MediaResult& error = aResult.RejectValue();
LOGE("%s %p, DecoderAgent #%d %s failed: %s",
DecoderType::Name.get(), self.get(), id, msgStr.get(),
error.Description().get());
self->QueueATask(
"Error during decode runnable",
[self = RefPtr{self}]() MOZ_CAN_RUN_SCRIPT_BOUNDARY {
MOZ_ASSERT(self->mState != CodecState::Closed);
self->CloseInternal(
NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
});
return;
}
if (aResult.IsReject()) {
// The spec asks to queue a task to run close the decoder
// with an EncodingError so we log the exact error here.
const MediaResult& error = aResult.RejectValue();
LOGE("%s %p, DecoderAgent #%d %s failed: %s",
DecoderType::Name.get(), self.get(), id, msgStr.get(),
error.Description().get());
self->QueueATask(
"Error during decode runnable",
[self = RefPtr{self}]() MOZ_CAN_RUN_SCRIPT_BOUNDARY {
MOZ_ASSERT(self->mState != CodecState::Closed);
self->CloseInternal(
NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
});
return;
}
MOZ_ASSERT(aResult.IsResolve());
nsTArray<RefPtr<MediaData>> data =
std::move(aResult.ResolveValue());
if (data.IsEmpty()) {
LOGV("%s %p got no data for %s", DecoderType::Name.get(),
self.get(), msgStr.get());
} else {
LOGV("%s %p, schedule %zu decoded data output for %s",
DecoderType::Name.get(), self.get(), data.Length(),
msgStr.get());
self->QueueATask(
"Output Decoded Data",
[self = RefPtr{self}, data = std::move(data)]()
MOZ_CAN_RUN_SCRIPT_BOUNDARY {
self->OutputDecodedData(std::move(data));
});
}
self->ProcessControlMessageQueue();
})
MOZ_ASSERT(aResult.IsResolve());
nsTArray<RefPtr<MediaData>> data =
std::move(aResult.ResolveValue());
if (data.IsEmpty()) {
LOGV("%s %p got no data for %s", DecoderType::Name.get(),
self.get(), msgStr.get());
} else {
LOGV("%s %p, schedule %zu decoded data output for %s",
DecoderType::Name.get(), self.get(), data.Length(),
msgStr.get());
self->QueueATask("Output Decoded Data",
[self = RefPtr{self}, data = std::move(data)]()
MOZ_CAN_RUN_SCRIPT_BOUNDARY {
self->OutputDecodedData(std::move(data));
});
}
self->ProcessControlMessageQueue();
})
->Track(msg->Request());
return MessageProcessedResult::Processed;
@ -682,77 +678,74 @@ MessageProcessedResult DecoderTemplate<DecoderType>::ProcessFlushMessage(
}
mAgent->DrainAndFlush()
->Then(GetCurrentSerialEventTarget(), __func__,
[self = RefPtr{this}, id = mAgent->mId,
this](DecoderAgent::DecodePromise::ResolveOrRejectValue&& aResult)
MOZ_CAN_RUN_SCRIPT_BOUNDARY {
MOZ_ASSERT(self->mProcessingMessage);
MOZ_ASSERT(self->mProcessingMessage->AsFlushMessage());
MOZ_ASSERT(self->mState == CodecState::Configured);
MOZ_ASSERT(self->mAgent);
MOZ_ASSERT(id == self->mAgent->mId);
MOZ_ASSERT(self->mActiveConfig);
->Then(
GetCurrentSerialEventTarget(), __func__,
[self = RefPtr{this}, id = mAgent->mId,
this](DecoderAgent::DecodePromise::ResolveOrRejectValue&& aResult) {
MOZ_ASSERT(self->mProcessingMessage);
MOZ_ASSERT(self->mProcessingMessage->AsFlushMessage());
MOZ_ASSERT(self->mState == CodecState::Configured);
MOZ_ASSERT(self->mAgent);
MOZ_ASSERT(id == self->mAgent->mId);
MOZ_ASSERT(self->mActiveConfig);
FlushMessage* msg =
self->mProcessingMessage->AsFlushMessage();
LOG("%s %p, DecoderAgent #%d %s has been %s",
DecoderType::Name.get(), self.get(), id,
msg->ToString().get(),
aResult.IsResolve() ? "resolved" : "rejected");
FlushMessage* msg = self->mProcessingMessage->AsFlushMessage();
LOG("%s %p, DecoderAgent #%d %s has been %s",
DecoderType::Name.get(), self.get(), id, msg->ToString().get(),
aResult.IsResolve() ? "resolved" : "rejected");
nsCString msgStr = msg->ToString();
nsCString msgStr = msg->ToString();
msg->Complete();
msg->Complete();
// If flush failed, it means decoder fails to decode the data
// sent before, so we treat it like decode error. We reject
// the promise first and then queue a task to close
// VideoDecoder with an EncodingError.
if (aResult.IsReject()) {
const MediaResult& error = aResult.RejectValue();
LOGE("%s %p, DecoderAgent #%d failed to flush: %s",
DecoderType::Name.get(), self.get(), id,
error.Description().get());
RefPtr<Promise> promise = msg->TakePromise();
// Reject with an EncodingError instead of the error we got
// above.
self->QueueATask(
"Error during flush runnable",
[self = RefPtr{this}, promise]()
MOZ_CAN_RUN_SCRIPT_BOUNDARY {
promise->MaybeReject(
NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
self->mProcessingMessage.reset();
MOZ_ASSERT(self->mState != CodecState::Closed);
self->CloseInternal(
NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
});
return;
}
// If flush failed, it means decoder fails to decode the data
// sent before, so we treat it like decode error. We reject
// the promise first and then queue a task to close
// VideoDecoder with an EncodingError.
if (aResult.IsReject()) {
const MediaResult& error = aResult.RejectValue();
LOGE("%s %p, DecoderAgent #%d failed to flush: %s",
DecoderType::Name.get(), self.get(), id,
error.Description().get());
RefPtr<Promise> promise = msg->TakePromise();
// Reject with an EncodingError instead of the error we got
// above.
self->QueueATask(
"Error during flush runnable",
[self = RefPtr{this}, promise]() MOZ_CAN_RUN_SCRIPT_BOUNDARY {
promise->MaybeReject(
NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
self->mProcessingMessage.reset();
MOZ_ASSERT(self->mState != CodecState::Closed);
self->CloseInternal(
NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR);
});
return;
}
nsTArray<RefPtr<MediaData>> data =
std::move(aResult.ResolveValue());
nsTArray<RefPtr<MediaData>> data =
std::move(aResult.ResolveValue());
if (data.IsEmpty()) {
LOG("%s %p gets no data for %s", DecoderType::Name.get(),
self.get(), msgStr.get());
} else {
LOG("%s %p, schedule %zu decoded data output for %s",
DecoderType::Name.get(), self.get(), data.Length(),
msgStr.get());
}
if (data.IsEmpty()) {
LOG("%s %p gets no data for %s", DecoderType::Name.get(),
self.get(), msgStr.get());
} else {
LOG("%s %p, schedule %zu decoded data output for %s",
DecoderType::Name.get(), self.get(), data.Length(),
msgStr.get());
}
RefPtr<Promise> promise = msg->TakePromise();
self->QueueATask(
"Flush: output decoding data task",
[self = RefPtr{self}, promise, data = std::move(data)]()
MOZ_CAN_RUN_SCRIPT_BOUNDARY {
self->OutputDecodedData(std::move(data));
promise->MaybeResolveWithUndefined();
});
self->mProcessingMessage.reset();
self->ProcessControlMessageQueue();
})
RefPtr<Promise> promise = msg->TakePromise();
self->QueueATask(
"Flush: output decoding data task",
[self = RefPtr{self}, promise, data = std::move(data)]()
MOZ_CAN_RUN_SCRIPT_BOUNDARY {
self->OutputDecodedData(std::move(data));
promise->MaybeResolveWithUndefined();
});
self->mProcessingMessage.reset();
self->ProcessControlMessageQueue();
})
->Track(msg->Request());
return MessageProcessedResult::Processed;
@ -800,7 +793,7 @@ bool DecoderTemplate<DecoderType>::CreateDecoderAgent(
// Clean up all the resources when worker is going away.
RefPtr<StrongWorkerRef> workerRef = StrongWorkerRef::Create(
workerPrivate, "DecoderTemplate::CreateDecoderAgent",
[self = RefPtr{this}]() MOZ_CAN_RUN_SCRIPT_BOUNDARY {
[self = RefPtr{this}]() {
LOG("%s %p, worker is going away", DecoderType::Name.get(),
self.get());
Unused << self->ResetInternal(NS_ERROR_DOM_ABORT_ERR);
@ -836,7 +829,7 @@ bool DecoderTemplate<DecoderType>::CreateDecoderAgent(
mShutdownBlocker->ShutdownPromise()->Then(
GetCurrentSerialEventTarget(), __func__,
[self = RefPtr{this}, id = mAgent->mId,
ref = mWorkerRef](bool /* aUnUsed*/) MOZ_CAN_RUN_SCRIPT {
ref = mWorkerRef](bool /* aUnUsed*/) {
LOG("%s %p gets xpcom-will-shutdown notification for DecoderAgent #%d",
DecoderType::Name.get(), self.get(), id);
Unused << self->ResetInternal(NS_ERROR_DOM_ABORT_ERR);

View File

@ -136,19 +136,14 @@ class DecoderTemplate : public DOMEventTargetHelper {
uint32_t DecodeQueueSize() const { return mDecodeQueueSize; };
MOZ_CAN_RUN_SCRIPT
void Configure(const ConfigType& aConfig, ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT
void Decode(InputType& aInput, ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT
already_AddRefed<Promise> Flush(ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT
void Reset(ErrorResult& aRv);
MOZ_CAN_RUN_SCRIPT
void Close(ErrorResult& aRv);
/* Type conversion functions for the Decoder implementation */
@ -166,12 +161,10 @@ class DecoderTemplate : public DOMEventTargetHelper {
NS_ASSERT_OWNINGTHREAD(DecoderTemplate);
}
MOZ_CAN_RUN_SCRIPT
Result<Ok, nsresult> ResetInternal(const nsresult& aResult);
// Calling this method calls the error callback synchronously.
MOZ_CAN_RUN_SCRIPT
void CloseInternal(const nsresult& aResult);
MOZ_CAN_RUN_SCRIPT
// Calling this method doesn't call the error calback.
Result<Ok, nsresult> CloseInternalWithAbort();
@ -179,32 +172,27 @@ class DecoderTemplate : public DOMEventTargetHelper {
MOZ_CAN_RUN_SCRIPT void OutputDecodedData(
const nsTArray<RefPtr<MediaData>>&& aData);
MOZ_CAN_RUN_SCRIPT
void ScheduleDequeueEventIfNeeded();
nsresult FireEvent(nsAtom* aTypeWithOn, const nsAString& aEventType);
MOZ_CAN_RUN_SCRIPT_BOUNDARY
void ProcessControlMessageQueue();
void CancelPendingControlMessages(const nsresult& aResult);
// Queue a task to the control thread. This is to be used when a task needs to
// perform multiple steps.
template <typename Func>
MOZ_CAN_RUN_SCRIPT_BOUNDARY void QueueATask(const char* aName, Func&& aSteps);
void QueueATask(const char* aName, Func&& aSteps);
MessageProcessedResult ProcessConfigureMessage(
UniquePtr<ControlMessage>& aMessage);
MOZ_CAN_RUN_SCRIPT
MessageProcessedResult ProcessDecodeMessage(
UniquePtr<ControlMessage>& aMessage);
MOZ_CAN_RUN_SCRIPT
MessageProcessedResult ProcessFlushMessage(
UniquePtr<ControlMessage>& aMessage);
// Returns true when mAgent can be created.
MOZ_CAN_RUN_SCRIPT_BOUNDARY
bool CreateDecoderAgent(DecoderAgent::Id aId,
UniquePtr<ConfigTypeInternal>&& aConfig,
UniquePtr<TrackInfo>&& aInfo);