Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 598914c

Browse files
committed
Bug 1891082 - Enable decoder reconfiguration in DecoderAgent for AAC/ADTS data through MediaChangeMonitor r=media-playback-reviewers,padenot
This patch enhances `DecoderAgent` by enabling it to reconfigure the underlying decoder when processing *AAC/ADTS* data via `MediaChangeMonitor`. In cases where the `description` field is absent in the `AudioDecoderConfig` for `mp4a.*` (*AAC*) codec, the data stream is assumed to be in *ADTS* format. However, some websites provide raw AAC data under these circumstances, leading to decoding failure since the underlying decoder requires AAC-specific configuration. This patch resolves the issue by allowing the underling decoder to be reconfigured - recreated and reinitialized - through `MediaChangeMonitor` whenever an AAV format change is detected. This process mirros the handling of video format changes, such as when H264 data format changes between AnnexB and AVCC. With this change, `DecoderAgent` simply cues the `PDMFactory` to create a `MediaChangeMonitor` that wraps the underlying decoder, similar to the approach used for video decoders, ensuring correct handling of both AAC and ADTS formats without altering other components. Depends on D220505 Differential Revision: https://phabricator.services.mozilla.com/D220506
1 parent 9b6fc77 commit 598914c

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
lines changed

dom/media/platforms/PDMFactory.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ PDMFactory::CreateDecoderWithPDM(PlatformDecoderModule* aPDM,
409409
}
410410

411411
if (config.IsAudio()) {
412+
if (MP4Decoder::IsAAC(config.mMimeType) && !aParams.mUseNullDecoder.mUse &&
413+
aParams.mWrappers.contains(media::Wrapper::MediaChangeMonitor)) {
414+
// If AudioTrimmer is needed, MediaChangeMonitor will request it.
415+
return MediaChangeMonitor::Create(this, aParams);
416+
}
412417
RefPtr<PlatformDecoderModule::CreateDecoderPromise> p;
413418
p = aPDM->AsyncCreateDecoder(aParams)->Then(
414419
GetCurrentSerialEventTarget(), __func__,

dom/media/platforms/PlatformDecoderModule.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ MOZ_DEFINE_ENUM_CLASS_WITH_BASE_AND_TOSTRING(Wrapper, uint8_t,
8787
MediaChangeMonitor));
8888
using WrapperSet = EnumSet<Wrapper>;
8989
static WrapperSet GetDefaultWrapperSet(const TrackInfo& aInfo) {
90+
// MediaChangeMonitor can work with some audio codecs like AAC but only
91+
// WebCodecs needs it, so it's only enabled for video by default.
9092
WrapperSet set;
9193
if (aInfo.IsVideo()) {
9294
set += Wrapper::MediaChangeMonitor;
@@ -188,6 +190,10 @@ struct MOZ_STACK_CLASS CreateDecoderParams final {
188190
return *mConfig.GetAsAudioInfo();
189191
}
190192

193+
bool IsVideo() const { return mConfig.IsVideo(); }
194+
195+
bool IsAudio() const { return mConfig.IsAudio(); }
196+
191197
layers::LayersBackend GetLayersBackend() const {
192198
if (mKnowsCompositor) {
193199
return mKnowsCompositor->GetCompositorBackendType();

dom/media/platforms/wrappers/MediaChangeMonitor.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ MediaChangeMonitor::MediaChangeMonitor(
662662
MediaDataDecoder* aDecoder, const CreateDecoderParams& aParams)
663663
: mChangeMonitor(std::move(aCodecChangeMonitor)),
664664
mPDMFactory(aPDMFactory),
665-
mCurrentConfig(aParams.VideoConfig()),
665+
mCurrentConfig(aParams.mConfig.Clone()),
666666
mDecoder(aDecoder),
667667
mParams(aParams) {}
668668

@@ -671,20 +671,25 @@ RefPtr<PlatformDecoderModule::CreateDecoderPromise> MediaChangeMonitor::Create(
671671
PDMFactory* aPDMFactory, const CreateDecoderParams& aParams) {
672672
LOG("MediaChangeMonitor::Create, params = %s", aParams.ToString().get());
673673
UniquePtr<CodecChangeMonitor> changeMonitor;
674-
const VideoInfo& currentConfig = aParams.VideoConfig();
675-
if (VPXDecoder::IsVPX(currentConfig.mMimeType)) {
676-
changeMonitor = MakeUnique<VPXChangeMonitor>(currentConfig);
674+
if (aParams.IsVideo()) {
675+
const VideoInfo& config = aParams.VideoConfig();
676+
if (VPXDecoder::IsVPX(config.mMimeType)) {
677+
changeMonitor = MakeUnique<VPXChangeMonitor>(config);
677678
#ifdef MOZ_AV1
678-
} else if (AOMDecoder::IsAV1(currentConfig.mMimeType)) {
679-
changeMonitor = MakeUnique<AV1ChangeMonitor>(currentConfig);
679+
} else if (AOMDecoder::IsAV1(config.mMimeType)) {
680+
changeMonitor = MakeUnique<AV1ChangeMonitor>(config);
680681
#endif
681-
} else if (MP4Decoder::IsHEVC(currentConfig.mMimeType)) {
682-
changeMonitor = MakeUnique<HEVCChangeMonitor>(currentConfig);
682+
} else if (MP4Decoder::IsHEVC(config.mMimeType)) {
683+
changeMonitor = MakeUnique<HEVCChangeMonitor>(config);
684+
} else {
685+
MOZ_ASSERT(MP4Decoder::IsH264(config.mMimeType));
686+
changeMonitor = MakeUnique<H264ChangeMonitor>(
687+
config, aParams.mOptions.contains(
688+
CreateDecoderParams::Option::FullH264Parsing));
689+
}
683690
} else {
684-
MOZ_ASSERT(MP4Decoder::IsH264(currentConfig.mMimeType));
685-
changeMonitor = MakeUnique<H264ChangeMonitor>(
686-
currentConfig, aParams.mOptions.contains(
687-
CreateDecoderParams::Option::FullH264Parsing));
691+
MOZ_ASSERT(MP4Decoder::IsAAC(aParams.AudioConfig().mMimeType));
692+
changeMonitor = MakeUnique<AACCodecChangeMonitor>(aParams.AudioConfig());
688693
}
689694

690695
// The change monitor may have an updated track config. E.g. the h264 monitor
@@ -920,8 +925,8 @@ void MediaChangeMonitor::SetSeekThreshold(const media::TimeUnit& aTime) {
920925

921926
RefPtr<MediaChangeMonitor::CreateDecoderPromise>
922927
MediaChangeMonitor::CreateDecoder() {
923-
mCurrentConfig = *mChangeMonitor->Config().GetAsVideoInfo();
924-
CreateDecoderParams currentParams = {mCurrentConfig, mParams};
928+
mCurrentConfig = mChangeMonitor->Config().Clone();
929+
CreateDecoderParams currentParams = {*mCurrentConfig, mParams};
925930
currentParams.mWrappers -= media::Wrapper::MediaChangeMonitor;
926931
LOG("MediaChangeMonitor::CreateDecoder, current params = %s",
927932
currentParams.ToString().get());

dom/media/platforms/wrappers/MediaChangeMonitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class MediaChangeMonitor final
127127

128128
UniquePtr<CodecChangeMonitor> mChangeMonitor;
129129
RefPtr<PDMFactory> mPDMFactory;
130-
VideoInfo mCurrentConfig;
130+
UniquePtr<TrackInfo> mCurrentConfig;
131131
nsCOMPtr<nsISerialEventTarget> mThread;
132132
RefPtr<MediaDataDecoder> mDecoder;
133133
MozPromiseRequestHolder<CreateDecoderPromise> mDecoderRequest;

dom/media/webcodecs/DecoderAgent.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "DecoderAgent.h"
88

99
#include "ImageContainer.h"
10+
#include "MP4Decoder.h"
1011
#include "MediaDataDecoderProxy.h"
1112
#include "PDMFactory.h"
1213
#include "VideoUtils.h"
@@ -105,6 +106,10 @@ RefPtr<DecoderAgent::ConfigurePromise> DecoderAgent::Configure(
105106
if (aLowLatency) {
106107
params.mOptions += CreateDecoderParams::Option::LowLatency;
107108
}
109+
// MediaChangeMonitor is requested to decode raw AAC in ADTS.
110+
if (MP4Decoder::IsAAC(mInfo->mMimeType)) {
111+
params.mWrappers += media::Wrapper::MediaChangeMonitor;
112+
}
108113
// This should only be used for testing.
109114
if (StaticPrefs::media_test_null_decoder_creation_failure()) {
110115
params.mUseNullDecoder = CreateDecoderParams::UseNullDecoder(true);
@@ -114,10 +119,10 @@ RefPtr<DecoderAgent::ConfigurePromise> DecoderAgent::Configure(
114119
// decoded video frames.
115120
params.mOptions += CreateDecoderParams::Option::KeepOriginalPts;
116121

117-
LOG("DecoderAgent #%d (%p) is creating a decoder - PreferSW: %s, "
118-
"low-latency: %s",
119-
mId, this, aPreferSoftwareDecoder ? "yes" : "no",
120-
aLowLatency ? "yes" : "no");
122+
LOG("DecoderAgent #%d (%p) is creating a decoder (mime: %s) - PreferSW: %s, "
123+
"low-latency: %s, create-decoder-params: %s",
124+
mId, this, mInfo->mMimeType.get(), aPreferSoftwareDecoder ? "yes" : "no",
125+
aLowLatency ? "yes" : "no", params.ToString().get());
121126

122127
RefPtr<ConfigurePromise> p = mConfigurePromise.Ensure(__func__);
123128

0 commit comments

Comments
 (0)