summaryrefslogtreecommitdiffstats
path: root/dom/media/ipc/RemoteAudioDecoder.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/media/ipc/RemoteAudioDecoder.cpp
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/ipc/RemoteAudioDecoder.cpp')
-rw-r--r--dom/media/ipc/RemoteAudioDecoder.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/dom/media/ipc/RemoteAudioDecoder.cpp b/dom/media/ipc/RemoteAudioDecoder.cpp
new file mode 100644
index 0000000000..48250dc0c4
--- /dev/null
+++ b/dom/media/ipc/RemoteAudioDecoder.cpp
@@ -0,0 +1,117 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "RemoteAudioDecoder.h"
+
+#include "MediaDataDecoderProxy.h"
+#include "PDMFactory.h"
+#include "RemoteDecoderManagerChild.h"
+#include "RemoteDecoderManagerParent.h"
+#include "mozilla/PodOperations.h"
+
+namespace mozilla {
+
+RemoteAudioDecoderChild::RemoteAudioDecoderChild()
+ : RemoteDecoderChild(RemoteDecodeIn::RddProcess) {}
+
+MediaResult RemoteAudioDecoderChild::ProcessOutput(
+ DecodedOutputIPDL&& aDecodedData) {
+ AssertOnManagerThread();
+
+ MOZ_ASSERT(aDecodedData.type() == DecodedOutputIPDL::TArrayOfRemoteAudioData);
+ RefPtr<ArrayOfRemoteAudioData> arrayData =
+ aDecodedData.get_ArrayOfRemoteAudioData();
+
+ for (size_t i = 0; i < arrayData->Count(); i++) {
+ RefPtr<AudioData> data = arrayData->ElementAt(i);
+ if (!data) {
+ // OOM
+ return MediaResult(NS_ERROR_OUT_OF_MEMORY, __func__);
+ }
+ mDecodedData.AppendElement(data);
+ }
+ return NS_OK;
+}
+
+MediaResult RemoteAudioDecoderChild::InitIPDL(
+ const AudioInfo& aAudioInfo,
+ const CreateDecoderParams::OptionSet& aOptions) {
+ RefPtr<RemoteDecoderManagerChild> manager =
+ RemoteDecoderManagerChild::GetSingleton(mLocation);
+
+ // The manager isn't available because RemoteDecoderManagerChild has been
+ // initialized with null end points and we don't want to decode video on RDD
+ // process anymore. Return false here so that we can fallback to other PDMs.
+ if (!manager) {
+ return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
+ RESULT_DETAIL("RemoteDecoderManager is not available."));
+ }
+
+ if (!manager->CanSend()) {
+ return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
+ RESULT_DETAIL("RemoteDecoderManager unable to send."));
+ }
+
+ mIPDLSelfRef = this;
+ Unused << manager->SendPRemoteDecoderConstructor(this, aAudioInfo, aOptions,
+ Nothing());
+ return NS_OK;
+}
+
+RemoteAudioDecoderParent::RemoteAudioDecoderParent(
+ RemoteDecoderManagerParent* aParent, const AudioInfo& aAudioInfo,
+ const CreateDecoderParams::OptionSet& aOptions,
+ nsISerialEventTarget* aManagerThread, TaskQueue* aDecodeTaskQueue)
+ : RemoteDecoderParent(aParent, aOptions, aManagerThread, aDecodeTaskQueue),
+ mAudioInfo(aAudioInfo) {}
+
+IPCResult RemoteAudioDecoderParent::RecvConstruct(
+ ConstructResolver&& aResolver) {
+ auto params = CreateDecoderParams{mAudioInfo, mOptions,
+ CreateDecoderParams::NoWrapper(true)};
+
+ mParent->EnsurePDMFactory().CreateDecoder(params)->Then(
+ GetCurrentSerialEventTarget(), __func__,
+ [resolver = std::move(aResolver), self = RefPtr{this}](
+ PlatformDecoderModule::CreateDecoderPromise::ResolveOrRejectValue&&
+ aValue) {
+ if (aValue.IsReject()) {
+ resolver(aValue.RejectValue());
+ return;
+ }
+ MOZ_ASSERT(aValue.ResolveValue());
+ self->mDecoder =
+ new MediaDataDecoderProxy(aValue.ResolveValue().forget(),
+ do_AddRef(self->mDecodeTaskQueue.get()));
+ resolver(NS_OK);
+ });
+
+ return IPC_OK();
+}
+
+MediaResult RemoteAudioDecoderParent::ProcessDecodedData(
+ MediaDataDecoder::DecodedData&& aData, DecodedOutputIPDL& aDecodedData) {
+ MOZ_ASSERT(OnManagerThread());
+
+ // Converted array to array of RefPtr<AudioData>
+ nsTArray<RefPtr<AudioData>> data(aData.Length());
+ for (auto&& element : aData) {
+ MOZ_ASSERT(element->mType == MediaData::Type::AUDIO_DATA,
+ "Can only decode audio using RemoteAudioDecoderParent!");
+ AudioData* audio = static_cast<AudioData*>(element.get());
+ data.AppendElement(audio);
+ }
+ auto array = MakeRefPtr<ArrayOfRemoteAudioData>();
+ if (!array->Fill(std::move(data),
+ [&](size_t aSize) { return AllocateBuffer(aSize); })) {
+ return MediaResult(
+ NS_ERROR_OUT_OF_MEMORY,
+ "Failed in RemoteAudioDecoderParent::ProcessDecodedData");
+ }
+ aDecodedData = std::move(array);
+ return NS_OK;
+}
+
+} // namespace mozilla