Skip to content

Commit

Permalink
add VDADecoder support for 10.6.3->10.7 platforms (centralle)
Browse files Browse the repository at this point in the history
getting a little ahead of myself with the stupid block in 10.7, but this has to happen anyways.

i dont think VDADecoder will work on a VM, but only on a mac with actual hardware.

lmk
  • Loading branch information
i3roly committed Dec 12, 2024
1 parent a1663d6 commit a2a6532
Show file tree
Hide file tree
Showing 5 changed files with 872 additions and 13 deletions.
46 changes: 34 additions & 12 deletions dom/media/platforms/apple/AppleDecoderModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include "AppleATDecoder.h"
#include "AppleVTDecoder.h"
#include "AppleVDADecoder.h"

#include "MP4Decoder.h"
#include "VideoUtils.h"
#include "VPXDecoder.h"
Expand Down Expand Up @@ -42,7 +44,6 @@ void AppleDecoderModule::Init() {
if (sInitialized) {
return;
}

sInitialized = true;
if (RegisterSupplementalVP9Decoder()) {
sCanUseVP9Decoder = CanCreateHWDecoder(MediaCodec::VP9);
Expand All @@ -63,11 +64,19 @@ already_AddRefed<MediaDataDecoder> AppleDecoderModule::CreateVideoDecoder(
.isEmpty()) {
return nullptr;
}

RefPtr<MediaDataDecoder> decoder;
if (IsVideoSupported(aParams.VideoConfig(), aParams.mOptions)) {
decoder = new AppleVTDecoder(aParams.VideoConfig(), aParams.mImageContainer,
aParams.mOptions, aParams.mKnowsCompositor,
aParams.mTrackingId);

if(__builtin_available(macOS 10.8, *)) {
if (IsVideoSupported(aParams.VideoConfig(), aParams.mOptions)) {
decoder = new AppleVTDecoder(aParams.VideoConfig(), aParams.mImageContainer,
aParams.mOptions, aParams.mKnowsCompositor,
aParams.mTrackingId);
}
} else {
decoder = new AppleVDADecoder(aParams.VideoConfig(), aParams.mImageContainer,
aParams.mOptions, aParams.mKnowsCompositor,
aParams.mTrackingId);
}
return decoder.forget();
}
Expand Down Expand Up @@ -250,24 +259,36 @@ bool AppleDecoderModule::CanCreateHWDecoder(MediaCodec aCodec) {
vtReportsSupport = false;
break;
}
} else if (__builtin_available(macOS 10.7, *)) { //VTDecoder is only 10.7 and up.
} else if (__builtin_available(macOS 10.6.3, *)) { //HW decoder is 10.6.3 and up
if (aCodec == media::MediaCodec::H264) {
// VTIsHardwareDecodeSupported function is only available on 10.13+.
// For earlier versions, we must check H264 support by always
// For earlier versions (10.6.3+), we must check H264 support by always
// attempting to create a decoder.
info.mMimeType = "video/avc";
vtReportsSupport = true;
}
}
// VT reports HW decode is supported -- verify by creating an actual decoder
if (vtReportsSupport) {
RefPtr<AppleVTDecoder> decoder =
new AppleVTDecoder(info, nullptr, {}, nullptr, Nothing());
MediaResult rv = decoder->InitializeSession();
RefPtr<MediaDataDecoder> decoder;
MediaResult rv;
char *type;
if(__builtin_available(macOS 10.8, *)) {
RefPtr<AppleVTDecoder> decoder =
new AppleVTDecoder(info, nullptr, {}, nullptr, Nothing());
rv = decoder->InitializeSession();
type = strdup("VT");
} else {
RefPtr<AppleVDADecoder> decoder =
new AppleVDADecoder(info, nullptr, {}, nullptr, Nothing());
rv = decoder->InitializeSession();
type = strdup("VDA");
}
if (!NS_SUCCEEDED(rv)) {
MOZ_LOG(
sPDMLog, LogLevel::Debug,
("Apple HW decode failure while initializing VT decoder session"));
("Apple HW decode failure while initializing %s decoder session", type));
free(type);
return false;
}
nsAutoCString failureReason;
Expand All @@ -278,8 +299,9 @@ bool AppleDecoderModule::CanCreateHWDecoder(MediaCodec aCodec) {
aCodec == MediaCodec::H264;
if (!hwSupport) {
MOZ_LOG(sPDMLog, LogLevel::Debug,
("Apple HW decode failure: '%s'", failureReason.BeginReading()));
("Apple %s HW decode failure: '%s'", type, failureReason.BeginReading()));
}
free(type);
decoder->Shutdown();
return hwSupport;
}
Expand Down
1 change: 0 additions & 1 deletion dom/media/platforms/apple/AppleDecoderModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class AppleDecoderModule : public PlatformDecoderModule {

static constexpr int kCMVideoCodecType_H264{'avc1'};
static constexpr int kCMVideoCodecType_VP9{'vp09'};

private:
AppleDecoderModule() = default;
virtual ~AppleDecoderModule() = default;
Expand Down
Loading

0 comments on commit a2a6532

Please sign in to comment.