Skip to content

Commit

Permalink
[sailfishos][media] Enable ffmpeg decoding. Fixes JB#49556
Browse files Browse the repository at this point in the history
Require ffmpeg for build.
  • Loading branch information
rainemak committed May 27, 2020
1 parent 50fc4fa commit 6c03611
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 9 deletions.
10 changes: 8 additions & 2 deletions dom/media/platforms/PDMFactory.cpp
Expand Up @@ -44,7 +44,9 @@

#include "DecoderDoctorDiagnostics.h"

#if defined(MOZ_FMP4)
#include "MP4Decoder.h"
#endif
#include "mozilla/dom/RemoteVideoDecoder.h"

#ifdef XP_WIN
Expand Down Expand Up @@ -122,6 +124,7 @@ class SupportChecker
RefPtr<MediaByteBuffer> extraData = aTrackConfig.GetAsVideoInfo()->mExtraData;
AddToCheckList(
[mimeType, extraData]() {
#if defined(MOZ_FMP4)
if (MP4Decoder::IsH264(mimeType)) {
mp4_demuxer::SPSData spsdata;
// WMF H.264 Video Decoder and Apple ATDecoder
Expand All @@ -139,6 +142,7 @@ class SupportChecker
" with YUV444 chroma subsampling.")));
}
}
#endif
return CheckResult(SupportChecker::Reason::kSupported);
});
}
Expand Down Expand Up @@ -302,7 +306,7 @@ PDMFactory::CreateDecoderWithPDM(PlatformDecoderModule* aPDM,

CreateDecoderParams params = aParams;
params.mCallback = callback;

#if defined(MOZ_FMP4)
if (MP4Decoder::IsH264(config.mMimeType) && !aParams.mUseBlankDecoder) {
RefPtr<H264Converter> h = new H264Converter(aPDM, params);
const nsresult rv = h->GetLastError();
Expand All @@ -312,7 +316,9 @@ PDMFactory::CreateDecoderWithPDM(PlatformDecoderModule* aPDM,
// problem, for example WMF DLLs were missing.
m = h.forget();
}
} else {
} else
#endif
{
m = aPDM->CreateVideoDecoder(params);
}

Expand Down
13 changes: 12 additions & 1 deletion dom/media/platforms/agnostic/BlankDecoderModule.cpp
Expand Up @@ -13,7 +13,9 @@
#include "mozilla/TaskQueue.h"
#include "mp4_demuxer/AnnexB.h"
#include "mp4_demuxer/H264.h"
#if defined(MOZ_FMP4)
#include "MP4Decoder.h"
#endif
#include "nsAutoPtr.h"
#include "nsRect.h"
#include "PlatformDecoderModule.h"
Expand All @@ -33,12 +35,17 @@ class BlankMediaDataDecoder : public MediaDataDecoder {
const CreateDecoderParams& aParams)
: mCreator(aCreator)
, mCallback(aParams.mCallback)
, mMaxRefFrames(aParams.mConfig.GetType() == TrackInfo::kVideoTrack &&
, mMaxRefFrames(
#if defined(MOZ_FMP4)
aParams.mConfig.GetType() == TrackInfo::kVideoTrack &&
MP4Decoder::IsH264(aParams.mConfig.mMimeType)
? mp4_demuxer::AnnexB::HasSPS(aParams.VideoConfig().mExtraData)
? mp4_demuxer::H264::ComputeMaxRefFrames(aParams.VideoConfig().mExtraData)
: 16
: 0)
#else
0)
#endif
, mType(aParams.mConfig.GetType())
{
}
Expand Down Expand Up @@ -260,11 +267,15 @@ class BlankDecoderModule : public PlatformDecoderModule {
ConversionRequired
DecoderNeedsConversion(const TrackInfo& aConfig) const override
{
#if defined(MOZ_FMP4)
if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
return ConversionRequired::kNeedAVCC;
} else {
return ConversionRequired::kNeedNone;
}
#else
return ConversionRequired::kNeedNone;
#endif
}

};
Expand Down
8 changes: 7 additions & 1 deletion dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
Expand Up @@ -16,7 +16,10 @@
#include "MediaInfo.h"
#include "nsClassHashtable.h"
#include "GMPDecoderModule.h"

#if defined(MOZ_FMP4)
#include "MP4Decoder.h"
#endif

namespace mozilla {

Expand Down Expand Up @@ -288,9 +291,12 @@ EMEDecoderModule::CreateAudioDecoder(const CreateDecoderParams& aParams)
PlatformDecoderModule::ConversionRequired
EMEDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
{
#if defined(MOZ_FMP4)
if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
return ConversionRequired::kNeedAVCC;
} else {
} else
#endif
{
return ConversionRequired::kNeedNone;
}
}
Expand Down
10 changes: 10 additions & 0 deletions dom/media/platforms/agnostic/eme/EMEVideoDecoder.cpp
Expand Up @@ -8,7 +8,9 @@
#include "GMPVideoEncodedFrameImpl.h"
#include "mozilla/CDMProxy.h"
#include "MediaData.h"
#if defined(MOZ_FMP4)
#include "MP4Decoder.h"
#endif
#include "VPXDecoder.h"

namespace mozilla {
Expand Down Expand Up @@ -39,13 +41,21 @@ void
EMEVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
{
VideoInfo config = GetConfig();
#if defined(MOZ_FMP4)
if (MP4Decoder::IsH264(config.mMimeType)) {
aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
} else if (VPXDecoder::IsVP8(config.mMimeType)) {
aTags.AppendElement(NS_LITERAL_CSTRING("vp8"));
} else if (VPXDecoder::IsVP9(config.mMimeType)) {
aTags.AppendElement(NS_LITERAL_CSTRING("vp9"));
}
#else
if (VPXDecoder::IsVP8(config.mMimeType)) {
aTags.AppendElement(NS_LITERAL_CSTRING("vp8"));
} else if (VPXDecoder::IsVP9(config.mMimeType)) {
aTags.AppendElement(NS_LITERAL_CSTRING("vp9"));
}
#endif
aTags.AppendElement(NS_ConvertUTF16toUTF8(mProxy->KeySystem()));
}

Expand Down
20 changes: 19 additions & 1 deletion dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
Expand Up @@ -17,7 +17,9 @@
#include "mozilla/StaticMutex.h"
#include "gmp-audio-decode.h"
#include "gmp-video-decode.h"
#if defined(MOZ_FMP4)
#include "MP4Decoder.h"
#endif
#include "VPXDecoder.h"
#ifdef XP_WIN
#include "WMFDecoderModule.h"
Expand Down Expand Up @@ -51,11 +53,18 @@ CreateDecoderWrapper(MediaDataDecoderCallback* aCallback)
already_AddRefed<MediaDataDecoder>
GMPDecoderModule::CreateVideoDecoder(const CreateDecoderParams& aParams)
{
#if defined(MOZ_FMP4)
if (!MP4Decoder::IsH264(aParams.mConfig.mMimeType) &&
!VPXDecoder::IsVP8(aParams.mConfig.mMimeType) &&
!VPXDecoder::IsVP9(aParams.mConfig.mMimeType)) {
return nullptr;
}
#else
if (!VPXDecoder::IsVP8(aParams.mConfig.mMimeType) &&
!VPXDecoder::IsVP9(aParams.mConfig.mMimeType)) {
return nullptr;
}
#endif

if (aParams.mDiagnostics) {
const Maybe<nsCString> preferredGMP = PreferredGMP(aParams.mConfig.mMimeType);
Expand Down Expand Up @@ -94,9 +103,12 @@ PlatformDecoderModule::ConversionRequired
GMPDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
{
// GMPVideoCodecType::kGMPVideoCodecH264 specifies that encoded frames must be in AVCC format.
#if defined(MOZ_FMP4)
if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
return ConversionRequired::kNeedAVCC;
} else {
} else
#endif
{
return ConversionRequired::kNeedNone;
}
}
Expand All @@ -114,13 +126,15 @@ GMPDecoderModule::PreferredGMP(const nsACString& aMimeType)
}
}

#if defined(MOZ_FMP4)
if (MP4Decoder::IsH264(aMimeType)) {
switch (MediaPrefs::GMPH264Preferred()) {
case 1: rv.emplace(kEMEKeySystemClearkey); break;
case 2: rv.emplace(kEMEKeySystemPrimetime); break;
default: break;
}
}
#endif

return rv;
}
Expand All @@ -134,10 +148,12 @@ GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType,
return false;
}

#if defined(MOZ_FMP4)
if (MP4Decoder::IsH264(aMimeType)) {
return HaveGMPFor(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
{ NS_LITERAL_CSTRING("h264"), aGMP.value()});
}
#endif

if (VPXDecoder::IsVP9(aMimeType)) {
return HaveGMPFor(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
Expand All @@ -149,10 +165,12 @@ GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType,
{ NS_LITERAL_CSTRING("vp8"), aGMP.value()});
}

#if defined(MOZ_FMP4)
if (MP4Decoder::IsAAC(aMimeType)) {
return HaveGMPFor(NS_LITERAL_CSTRING(GMP_API_AUDIO_DECODER),
{ NS_LITERAL_CSTRING("aac"), aGMP.value()});
}
#endif

return false;
}
Expand Down
10 changes: 8 additions & 2 deletions dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
Expand Up @@ -160,14 +160,17 @@ GMPVideoDecoder::GMPVideoDecoder(const GMPVideoDecoderParams& aParams)
void
GMPVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
{
#if defined(MOZ_FMP4)
if (MP4Decoder::IsH264(mConfig.mMimeType)) {
aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
const Maybe<nsCString> gmp(
GMPDecoderModule::PreferredGMP(NS_LITERAL_CSTRING("video/avc")));
if (gmp.isSome()) {
aTags.AppendElement(gmp.value());
}
} else if (VPXDecoder::IsVP8(mConfig.mMimeType)) {
} else
#endif
if (VPXDecoder::IsVP8(mConfig.mMimeType)) {
aTags.AppendElement(NS_LITERAL_CSTRING("vp8"));
} else if (VPXDecoder::IsVP9(mConfig.mMimeType)) {
aTags.AppendElement(NS_LITERAL_CSTRING("vp9"));
Expand Down Expand Up @@ -254,12 +257,15 @@ GMPVideoDecoder::GMPInitDone(GMPVideoDecoderProxy* aGMP, GMPVideoHost* aHost)

codec.mGMPApiVersion = kGMPVersion33;
nsTArray<uint8_t> codecSpecific;
#if defined(MOZ_FMP4)
if (MP4Decoder::IsH264(mConfig.mMimeType)) {
codec.mCodecType = kGMPVideoCodecH264;
codecSpecific.AppendElement(0); // mPacketizationMode.
codecSpecific.AppendElements(mConfig.mExtraData->Elements(),
mConfig.mExtraData->Length());
} else if (VPXDecoder::IsVP8(mConfig.mMimeType)) {
} else
#endif
if (VPXDecoder::IsVP8(mConfig.mMimeType)) {
codec.mCodecType = kGMPVideoCodecVP8;
} else if (VPXDecoder::IsVP9(mConfig.mMimeType)) {
codec.mCodecType = kGMPVideoCodecVP9;
Expand Down
4 changes: 4 additions & 0 deletions dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
Expand Up @@ -11,7 +11,9 @@

#include "MediaInfo.h"
#include "VPXDecoder.h"
#if defined(MOZ_FMP4)
#include "MP4Decoder.h"
#endif

#include "FFmpegVideoDecoder.h"
#include "FFmpegLog.h"
Expand Down Expand Up @@ -367,9 +369,11 @@ FFmpegVideoDecoder<LIBAV_VER>::~FFmpegVideoDecoder()
AVCodecID
FFmpegVideoDecoder<LIBAV_VER>::GetCodecId(const nsACString& aMimeType)
{
#if defined(MOZ_FMP4)
if (MP4Decoder::IsH264(aMimeType)) {
return AV_CODEC_ID_H264;
}
#endif

if (aMimeType.EqualsLiteral("video/x-vnd.on2.vp6")) {
return AV_CODEC_ID_VP6F;
Expand Down
9 changes: 8 additions & 1 deletion dom/media/platforms/wmf/WMFDecoderModule.cpp
Expand Up @@ -26,7 +26,9 @@
#include "mozilla/Maybe.h"
#include "mozilla/StaticMutex.h"
#include "mozilla/WindowsVersion.h"
#if defined(MOZ_FMP4)
#include "MP4Decoder.h"
#endif
#include "VPXDecoder.h"

namespace mozilla {
Expand Down Expand Up @@ -210,6 +212,7 @@ WMFDecoderModule::Supports(const TrackInfo& aTrackInfo,
WMFDecoderModule::HasAAC()) {
return true;
}
#if defined(MOZ_FMP4)
if (MP4Decoder::IsH264(aTrackInfo.mMimeType) && WMFDecoderModule::HasH264()) {
const VideoInfo* videoInfo = aTrackInfo.GetAsVideoInfo();
MOZ_ASSERT(videoInfo);
Expand All @@ -228,6 +231,7 @@ WMFDecoderModule::Supports(const TrackInfo& aTrackInfo,
}
return true;
}
#endif
if (aTrackInfo.mMimeType.EqualsLiteral("audio/mpeg") &&
CanCreateWMFDecoder<CLSID_CMP3DecMediaObject>()) {
return true;
Expand All @@ -247,9 +251,12 @@ WMFDecoderModule::Supports(const TrackInfo& aTrackInfo,
PlatformDecoderModule::ConversionRequired
WMFDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
{
#if defined(MOZ_FMP4)
if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
return ConversionRequired::kNeedAnnexB;
} else {
} else
#endif
{
return ConversionRequired::kNeedNone;
}
}
Expand Down
7 changes: 6 additions & 1 deletion dom/media/platforms/wmf/WMFVideoMFTManager.cpp
Expand Up @@ -29,7 +29,9 @@
#include "nsPrintfCString.h"
#include "MediaTelemetryConstants.h"
#include "GMPUtils.h" // For SplitAt. TODO: Move SplitAt to a central place.
#if defined(MOZ_FMP4)
#include "MP4Decoder.h"
#endif
#include "VPXDecoder.h"
#include "mozilla/SyncRunnable.h"

Expand Down Expand Up @@ -98,10 +100,13 @@ WMFVideoMFTManager::WMFVideoMFTManager(
{
MOZ_COUNT_CTOR(WMFVideoMFTManager);

#if defined(MOZ_FMP4)
// Need additional checks/params to check vp8/vp9
if (MP4Decoder::IsH264(aConfig.mMimeType)) {
mStreamType = H264;
} else if (VPXDecoder::IsVP8(aConfig.mMimeType)) {
} else
#endif
if (VPXDecoder::IsVP8(aConfig.mMimeType)) {
mStreamType = VP8;
} else if (VPXDecoder::IsVP9(aConfig.mMimeType)) {
mStreamType = VP9;
Expand Down

0 comments on commit 6c03611

Please sign in to comment.