1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/* -*- 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 "RemoteCDMParent.h"
#include "RemoteMediaManagerChild.h"
#include "RemoteMediaManagerParent.h"
#include "mozilla/StaticPrefs_media.h"
namespace mozilla {
RemoteAudioDecoderChild::RemoteAudioDecoderChild(RemoteMediaIn aLocation)
: RemoteDecoderChild(aLocation) {}
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,
const Maybe<uint64_t>& aMediaEngineId, PRemoteCDMActor* aCDM) {
RefPtr<RemoteMediaManagerChild> manager =
RemoteMediaManagerChild::GetSingleton(mLocation);
// The manager isn't available because RemoteMediaManagerChild 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("RemoteMediaManager is not available."));
}
if (!manager->CanSend()) {
return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
RESULT_DETAIL("RemoteMediaManager unable to send."));
}
// If we are given a remote CDM, we need to make sure that it has been remoted
// into the same process as the decoder.
PRemoteCDMChild* cdm = nullptr;
if (aCDM) {
if (aCDM->GetLocation() != mLocation) {
return MediaResult(
NS_ERROR_DOM_MEDIA_FATAL_ERR,
RESULT_DETAIL("PRemoteCDMActor is not in same process."));
}
cdm = aCDM->AsPRemoteCDMChild();
if (!cdm) {
return MediaResult(
NS_ERROR_DOM_MEDIA_FATAL_ERR,
RESULT_DETAIL("PRemoteCDMActor is not PRemoteCDMChild."));
}
}
mIPDLSelfRef = this;
MOZ_ALWAYS_TRUE(manager->SendPRemoteDecoderConstructor(
this, aAudioInfo, aOptions, Nothing(), aMediaEngineId, Nothing(), cdm));
return NS_OK;
}
RemoteAudioDecoderParent::RemoteAudioDecoderParent(
RemoteMediaManagerParent* aParent, const AudioInfo& aAudioInfo,
const CreateDecoderParams::OptionSet& aOptions,
nsISerialEventTarget* aManagerThread, TaskQueue* aDecodeTaskQueue,
Maybe<uint64_t> aMediaEngineId, RemoteCDMParent* aCDM)
: RemoteDecoderParent(aParent, aOptions, aManagerThread, aDecodeTaskQueue,
aMediaEngineId, Nothing(), aCDM),
mAudioInfo(aAudioInfo) {}
IPCResult RemoteAudioDecoderParent::RecvConstruct(
ConstructResolver&& aResolver) {
auto params = CreateDecoderParams{
mAudioInfo, static_cast<PRemoteCDMActor*>(mCDM.get()),
mOptions, CreateDecoderParams::WrapperSet({/* No wrapper */}),
mMediaEngineId, mTrackingId};
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
|