зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1290284 - Centralise string comparisons for H264 and VPX detection. r=cpearce
Remove string comparisons to determine from mime types if content is VPX or H264. Replace with calls to VPXDecoder::IsVPX or MP4Decoder::IsH264 to centralise such logic. This patch introduces MP4Decoder:IsH264, and moves the similar functionality out of H264Convertor for the sake of consistently having these functions in decoders. MozReview-Commit-ID: 5nfYusYHrUR --HG-- extra : rebase_source : c013c4ebe28d5afedbb91ddfffadb40d23fd0ee3
This commit is contained in:
Родитель
e47f652b04
Коммит
dc49694098
|
@ -171,6 +171,14 @@ MP4Decoder::CanHandleMediaType(const nsAString& aContentType,
|
|||
aDiagnostics);
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool
|
||||
MP4Decoder::IsH264(const nsACString& aMimeType)
|
||||
{
|
||||
return aMimeType.EqualsLiteral("video/mp4") ||
|
||||
aMimeType.EqualsLiteral("video/avc");
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool
|
||||
MP4Decoder::IsEnabled()
|
||||
|
|
|
@ -38,6 +38,11 @@ public:
|
|||
static bool CanHandleMediaType(const nsAString& aMIMEType,
|
||||
DecoderDoctorDiagnostics* aDiagnostics);
|
||||
|
||||
// Return true if aMimeType is a one of the strings used by our demuxers to
|
||||
// identify H264. Does not parse general content type strings, i.e. white
|
||||
// space matters.
|
||||
static bool IsH264(const nsACString& aMimeType);
|
||||
|
||||
// Returns true if the MP4 backend is preffed on.
|
||||
static bool IsEnabled();
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
|
||||
#include "DecoderDoctorDiagnostics.h"
|
||||
|
||||
#include "MP4Decoder.h"
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -183,7 +185,7 @@ PDMFactory::CreateDecoderWithPDM(PlatformDecoderModule* aPDM,
|
|||
CreateDecoderParams params = aParams;
|
||||
params.mCallback = callback;
|
||||
|
||||
if (H264Converter::IsH264(config)) {
|
||||
if (MP4Decoder::IsH264(config.mMimeType)) {
|
||||
RefPtr<H264Converter> h = new H264Converter(aPDM, params);
|
||||
const nsresult rv = h->GetLastError();
|
||||
if (NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_INITIALIZED) {
|
||||
|
|
|
@ -39,7 +39,9 @@ public:
|
|||
VP9 = 1 << 1
|
||||
};
|
||||
|
||||
// Return true if mimetype is a VPX codec of given types.
|
||||
// Return true if aMimeType is a one of the strings used by our demuxers to
|
||||
// identify VPX of the specified type. Does not parse general content type
|
||||
// strings, i.e. white space matters.
|
||||
static bool IsVPX(const nsACString& aMimeType, uint8_t aCodecMask=VP8|VP9);
|
||||
static bool IsVP8(const nsACString& aMimeType);
|
||||
static bool IsVP9(const nsACString& aMimeType);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "MediaInfo.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "GMPDecoderModule.h"
|
||||
#include "MP4Decoder.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -292,9 +293,7 @@ EMEDecoderModule::CreateAudioDecoder(const CreateDecoderParams& aParams)
|
|||
PlatformDecoderModule::ConversionRequired
|
||||
EMEDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
|
||||
{
|
||||
if (aConfig.IsVideo() &&
|
||||
(aConfig.mMimeType.EqualsLiteral("video/avc") ||
|
||||
aConfig.mMimeType.EqualsLiteral("video/mp4"))) {
|
||||
if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
|
||||
return kNeedAVCC;
|
||||
} else {
|
||||
return kNeedNone;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "GMPVideoEncodedFrameImpl.h"
|
||||
#include "mozilla/CDMProxy.h"
|
||||
#include "MediaData.h"
|
||||
#include "MP4Decoder.h"
|
||||
#include "VPXDecoder.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -37,8 +38,7 @@ void
|
|||
EMEVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
|
||||
{
|
||||
VideoInfo config = GetConfig();
|
||||
if (config.mMimeType.EqualsLiteral("video/avc") ||
|
||||
config.mMimeType.EqualsLiteral("video/mp4")) {
|
||||
if (MP4Decoder::IsH264(config.mMimeType)) {
|
||||
aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
|
||||
} else if (VPXDecoder::IsVP8(config.mMimeType)) {
|
||||
aTags.AppendElement(NS_LITERAL_CSTRING("vp8"));
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "mozilla/StaticMutex.h"
|
||||
#include "gmp-audio-decode.h"
|
||||
#include "gmp-video-decode.h"
|
||||
#include "MP4Decoder.h"
|
||||
#include "VPXDecoder.h"
|
||||
#ifdef XP_WIN
|
||||
#include "WMFDecoderModule.h"
|
||||
|
@ -49,8 +50,7 @@ CreateDecoderWrapper(MediaDataDecoderCallback* aCallback)
|
|||
already_AddRefed<MediaDataDecoder>
|
||||
GMPDecoderModule::CreateVideoDecoder(const CreateDecoderParams& aParams)
|
||||
{
|
||||
if (!aParams.mConfig.mMimeType.EqualsLiteral("video/avc") &&
|
||||
!aParams.mConfig.mMimeType.EqualsLiteral("video/mp4") &&
|
||||
if (!MP4Decoder::IsH264(aParams.mConfig.mMimeType) &&
|
||||
!VPXDecoder::IsVP8(aParams.mConfig.mMimeType) &&
|
||||
!VPXDecoder::IsVP9(aParams.mConfig.mMimeType)) {
|
||||
return nullptr;
|
||||
|
@ -93,9 +93,7 @@ PlatformDecoderModule::ConversionRequired
|
|||
GMPDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
|
||||
{
|
||||
// GMPVideoCodecType::kGMPVideoCodecH264 specifies that encoded frames must be in AVCC format.
|
||||
if (aConfig.IsVideo() &&
|
||||
(aConfig.mMimeType.EqualsLiteral("video/avc") ||
|
||||
aConfig.mMimeType.EqualsLiteral("video/mp4"))) {
|
||||
if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
|
||||
return kNeedAVCC;
|
||||
} else {
|
||||
return kNeedNone;
|
||||
|
@ -203,8 +201,7 @@ GMPDecoderModule::PreferredGMP(const nsACString& aMimeType)
|
|||
}
|
||||
}
|
||||
|
||||
if (aMimeType.EqualsLiteral("video/avc") ||
|
||||
aMimeType.EqualsLiteral("video/mp4")) {
|
||||
if (MP4Decoder::IsH264(aMimeType)) {
|
||||
switch (MediaPrefs::GMPH264Preferred()) {
|
||||
case 1: rv.emplace(nsCString(kEMEKeySystemClearkey)); break;
|
||||
case 2: rv.emplace(nsCString(kEMEKeySystemPrimetime)); break;
|
||||
|
@ -220,18 +217,12 @@ bool
|
|||
GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType,
|
||||
const Maybe<nsCString>& aGMP)
|
||||
{
|
||||
const bool isAAC = aMimeType.EqualsLiteral("audio/mp4a-latm");
|
||||
const bool isH264 = aMimeType.EqualsLiteral("video/avc") ||
|
||||
aMimeType.EqualsLiteral("video/mp4");
|
||||
const bool isVP8 = VPXDecoder::IsVP8(aMimeType);
|
||||
const bool isVP9 = VPXDecoder::IsVP9(aMimeType);
|
||||
|
||||
StaticMutexAutoLock lock(sGMPCodecsMutex);
|
||||
for (GMPCodecs& gmp : sGMPCodecs) {
|
||||
if (((isAAC && gmp.mHasAAC) ||
|
||||
(isH264 && gmp.mHasH264) ||
|
||||
(isVP8 && gmp.mHasVP8) ||
|
||||
(isVP9 && gmp.mHasVP9)) &&
|
||||
if (((aMimeType.EqualsLiteral("audio/mp4a-latm") && gmp.mHasAAC) ||
|
||||
(MP4Decoder::IsH264(aMimeType) && gmp.mHasH264) ||
|
||||
(VPXDecoder::IsVP8(aMimeType) && gmp.mHasVP8) ||
|
||||
(VPXDecoder::IsVP9(aMimeType) && gmp.mHasVP9)) &&
|
||||
(aGMP.isNothing() || aGMP.value().EqualsASCII(gmp.mKeySystem))) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -156,8 +156,7 @@ GMPVideoDecoder::GMPVideoDecoder(const GMPVideoDecoderParams& aParams)
|
|||
void
|
||||
GMPVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
|
||||
{
|
||||
if (mConfig.mMimeType.EqualsLiteral("video/avc") ||
|
||||
mConfig.mMimeType.EqualsLiteral("video/mp4")) {
|
||||
if (MP4Decoder::IsH264(mConfig.mMimeType)) {
|
||||
aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
|
||||
const Maybe<nsCString> gmp(
|
||||
GMPDecoderModule::PreferredGMP(NS_LITERAL_CSTRING("video/avc")));
|
||||
|
@ -249,8 +248,7 @@ GMPVideoDecoder::GMPInitDone(GMPVideoDecoderProxy* aGMP, GMPVideoHost* aHost)
|
|||
|
||||
codec.mGMPApiVersion = kGMPVersion33;
|
||||
nsTArray<uint8_t> codecSpecific;
|
||||
if (mConfig.mMimeType.EqualsLiteral("video/avc") ||
|
||||
mConfig.mMimeType.EqualsLiteral("video/mp4")) {
|
||||
if (MP4Decoder::IsH264(mConfig.mMimeType)) {
|
||||
codec.mCodecType = kGMPVideoCodecH264;
|
||||
codecSpecific.AppendElement(0); // mPacketizationMode.
|
||||
codecSpecific.AppendElements(mConfig.mExtraData->Elements(),
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "ImageContainer.h"
|
||||
|
||||
#include "MediaInfo.h"
|
||||
#include "VPXDecoder.h"
|
||||
#include "MP4Decoder.h"
|
||||
|
||||
#include "FFmpegVideoDecoder.h"
|
||||
#include "FFmpegLog.h"
|
||||
|
@ -338,7 +340,7 @@ FFmpegVideoDecoder<LIBAV_VER>::~FFmpegVideoDecoder()
|
|||
AVCodecID
|
||||
FFmpegVideoDecoder<LIBAV_VER>::GetCodecId(const nsACString& aMimeType)
|
||||
{
|
||||
if (aMimeType.EqualsLiteral("video/avc") || aMimeType.EqualsLiteral("video/mp4")) {
|
||||
if (MP4Decoder::IsH264(aMimeType)) {
|
||||
return AV_CODEC_ID_H264;
|
||||
}
|
||||
|
||||
|
@ -347,13 +349,13 @@ FFmpegVideoDecoder<LIBAV_VER>::GetCodecId(const nsACString& aMimeType)
|
|||
}
|
||||
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 54
|
||||
if (aMimeType.EqualsLiteral("video/webm; codecs=vp8")) {
|
||||
if (VPXDecoder::IsVP8(aMimeType)) {
|
||||
return AV_CODEC_ID_VP8;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIBAVCODEC_VERSION_MAJOR >= 55
|
||||
if (aMimeType.EqualsLiteral("video/webm; codecs=vp9")) {
|
||||
if (VPXDecoder::IsVP9(aMimeType)) {
|
||||
return AV_CODEC_ID_VP9;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "GonkOmxPlatformLayer.h"
|
||||
#endif
|
||||
|
||||
#include "VPXDecoder.h"
|
||||
|
||||
#ifdef LOG
|
||||
#undef LOG
|
||||
|
@ -278,7 +279,7 @@ OmxPlatformLayer::CompressionFormat()
|
|||
return OMX_VIDEO_CodingMPEG4;
|
||||
} else if (mInfo->mMimeType.EqualsLiteral("video/3gpp")) {
|
||||
return OMX_VIDEO_CodingH263;
|
||||
} else if (mInfo->mMimeType.EqualsLiteral("video/webm; codecs=vp8")) {
|
||||
} else if (VPXDecoder::IsVP8(mInfo->mMimeType)) {
|
||||
return static_cast<OMX_VIDEO_CODINGTYPE>(OMX_VIDEO_CodingVP8);
|
||||
} else {
|
||||
MOZ_ASSERT_UNREACHABLE("Unsupported compression format");
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "prsystem.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "MP4Decoder.h"
|
||||
#include "VPXDecoder.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -193,9 +195,7 @@ WMFDecoderModule::SupportsMimeType(const nsACString& aMimeType,
|
|||
WMFDecoderModule::HasAAC()) {
|
||||
return true;
|
||||
}
|
||||
if ((aMimeType.EqualsLiteral("video/avc") ||
|
||||
aMimeType.EqualsLiteral("video/mp4")) &&
|
||||
WMFDecoderModule::HasH264()) {
|
||||
if (MP4Decoder::IsH264(aMimeType) && WMFDecoderModule::HasH264()) {
|
||||
return true;
|
||||
}
|
||||
if (aMimeType.EqualsLiteral("audio/mpeg") &&
|
||||
|
@ -203,11 +203,11 @@ WMFDecoderModule::SupportsMimeType(const nsACString& aMimeType,
|
|||
return true;
|
||||
}
|
||||
if (MediaPrefs::PDMWMFIntelDecoderEnabled() && sDXVAEnabled) {
|
||||
if (aMimeType.EqualsLiteral("video/webm; codecs=vp8") &&
|
||||
if (VPXDecoder::IsVP8(aMimeType) &&
|
||||
CanCreateWMFDecoder<CLSID_WebmMfVp8Dec>()) {
|
||||
return true;
|
||||
}
|
||||
if (aMimeType.EqualsLiteral("video/webm; codecs=vp9") &&
|
||||
if (VPXDecoder::IsVP9(aMimeType) &&
|
||||
CanCreateWMFDecoder<CLSID_WebmMfVp9Dec>()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -220,9 +220,7 @@ WMFDecoderModule::SupportsMimeType(const nsACString& aMimeType,
|
|||
PlatformDecoderModule::ConversionRequired
|
||||
WMFDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
|
||||
{
|
||||
if (aConfig.IsVideo() &&
|
||||
(aConfig.mMimeType.EqualsLiteral("video/avc") ||
|
||||
aConfig.mMimeType.EqualsLiteral("video/mp4"))) {
|
||||
if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
|
||||
return kNeedAnnexB;
|
||||
} else {
|
||||
return kNeedNone;
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "nsPrintfCString.h"
|
||||
#include "MediaTelemetryConstants.h"
|
||||
#include "GMPUtils.h" // For SplitAt. TODO: Move SplitAt to a central place.
|
||||
#include "MP4Decoder.h"
|
||||
#include "VPXDecoder.h"
|
||||
|
||||
#define LOG(...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
|
||||
|
||||
|
@ -95,12 +97,11 @@ WMFVideoMFTManager::WMFVideoMFTManager(
|
|||
MOZ_COUNT_CTOR(WMFVideoMFTManager);
|
||||
|
||||
// Need additional checks/params to check vp8/vp9
|
||||
if (aConfig.mMimeType.EqualsLiteral("video/mp4") ||
|
||||
aConfig.mMimeType.EqualsLiteral("video/avc")) {
|
||||
if (MP4Decoder::IsH264(aConfig.mMimeType)) {
|
||||
mStreamType = H264;
|
||||
} else if (aConfig.mMimeType.EqualsLiteral("video/webm; codecs=vp8")) {
|
||||
} else if (VPXDecoder::IsVP8(aConfig.mMimeType)) {
|
||||
mStreamType = VP8;
|
||||
} else if (aConfig.mMimeType.EqualsLiteral("video/webm; codecs=vp9")) {
|
||||
} else if (VPXDecoder::IsVP9(aConfig.mMimeType)) {
|
||||
mStreamType = VP9;
|
||||
} else {
|
||||
mStreamType = Unknown;
|
||||
|
|
|
@ -241,12 +241,4 @@ H264Converter::UpdateConfigFromExtraData(MediaByteBuffer* aExtraData)
|
|||
mCurrentConfig.mExtraData = aExtraData;
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool
|
||||
H264Converter::IsH264(const TrackInfo& aConfig)
|
||||
{
|
||||
return aConfig.mMimeType.EqualsLiteral("video/avc") ||
|
||||
aConfig.mMimeType.EqualsLiteral("video/mp4");
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -39,8 +39,6 @@ public:
|
|||
return "H264Converter decoder (pending)";
|
||||
}
|
||||
|
||||
// Return true if mimetype is H.264.
|
||||
static bool IsH264(const TrackInfo& aConfig);
|
||||
nsresult GetLastError() const { return mLastError; }
|
||||
|
||||
private:
|
||||
|
|
Загрузка…
Ссылка в новой задаче