Bug 547707: replaced hardcoded strings by definitions in nsMimeTypes.h
MozReview-Commit-ID: 6f85pRUe8Tg
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -102,16 +102,17 @@
#include "DecoderTraits.h"
#include "MediaContainerType.h"
#include "MP4Decoder.h"
#include "FrameStatistics.h"
#include "nsIFrame.h"
#include "nsDisplayList.h"
#include "SVGObserverUtils.h"
+#include "nsMimeTypes.h"
#ifdef MOZ_ANDROID_HLS_SUPPORT
#include "HLSDecoder.h"
#endif
#include "ImageContainer.h"
#include "nsRange.h"
#include <algorithm>
@@ -7812,19 +7813,19 @@ HTMLMediaElement::ReportCanPlayTelemetry
"dom::HTMLMediaElement::ReportCanPlayTelemetry",
[thread, abstractThread]() {
#if XP_WIN
// Windows Media Foundation requires MSCOM to be inited.
DebugOnly<HRESULT> hr = CoInitializeEx(0, COINIT_MULTITHREADED);
MOZ_ASSERT(hr == S_OK);
#endif
bool aac = MP4Decoder::IsSupportedType(
- MediaContainerType(MEDIAMIMETYPE("audio/mp4")), nullptr);
+ MediaContainerType(MEDIAMIMETYPE(AUDIO_MP4)), nullptr);
bool h264 = MP4Decoder::IsSupportedType(
- MediaContainerType(MEDIAMIMETYPE("video/mp4")), nullptr);
+ MediaContainerType(MEDIAMIMETYPE(VIDEO_MP4)), nullptr);
#if XP_WIN
CoUninitialize();
#endif
abstractThread->Dispatch(NS_NewRunnableFunction(
"dom::HTMLMediaElement::ReportCanPlayTelemetry",
[thread, aac, h264]() {
LOG(LogLevel::Debug, ("MediaTelemetry aac=%d h264=%d", aac, h264));
Telemetry::Accumulate(
--- a/dom/media/eme/MediaKeySystemAccess.cpp
+++ b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -5,16 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/MediaKeySystemAccess.h"
#include "mozilla/dom/MediaKeySystemAccessBinding.h"
#include "mozilla/dom/MediaKeySession.h"
#include "mozilla/Preferences.h"
#include "MediaContainerType.h"
#include "MediaPrefs.h"
+#include "nsMimeTypes.h"
#ifdef XP_WIN
#include "WMFDecoderModule.h"
#endif
#include "nsContentCID.h"
#include "nsServiceManagerUtils.h"
#include "mozIGeckoMediaPluginService.h"
#include "VideoUtils.h"
#include "mozilla/Services.h"
@@ -335,23 +336,23 @@ GetSupportedKeySystems()
typedef struct {
const nsCString& mMimeType;
const nsCString& mEMECodecType;
const char16_t* mCodecType;
KeySystemContainerSupport* mSupportType;
} DataForValidation;
DataForValidation validationList[] = {
- { nsCString("video/mp4"), EME_CODEC_H264, MediaDrmProxy::AVC, &widevine.mMP4 },
- { nsCString("video/mp4"), EME_CODEC_VP9, MediaDrmProxy::AVC, &widevine.mMP4 },
- { nsCString("audio/mp4"), EME_CODEC_AAC, MediaDrmProxy::AAC, &widevine.mMP4 },
- { nsCString("video/webm"), EME_CODEC_VP8, MediaDrmProxy::VP8, &widevine.mWebM },
- { nsCString("video/webm"), EME_CODEC_VP9, MediaDrmProxy::VP9, &widevine.mWebM},
- { nsCString("audio/webm"), EME_CODEC_VORBIS, MediaDrmProxy::VORBIS, &widevine.mWebM},
- { nsCString("audio/webm"), EME_CODEC_OPUS, MediaDrmProxy::OPUS, &widevine.mWebM},
+ { nsCString(VIDEO_MP4), EME_CODEC_H264, MediaDrmProxy::AVC, &widevine.mMP4 },
+ { nsCString(VIDEO_MP4), EME_CODEC_VP9, MediaDrmProxy::AVC, &widevine.mMP4 },
+ { nsCString(AUDIO_MP4), EME_CODEC_AAC, MediaDrmProxy::AAC, &widevine.mMP4 },
+ { nsCString(VIDEO_WEBM), EME_CODEC_VP8, MediaDrmProxy::VP8, &widevine.mWebM },
+ { nsCString(VIDEO_WEBM), EME_CODEC_VP9, MediaDrmProxy::VP9, &widevine.mWebM},
+ { nsCString(AUDIO_WEBM), EME_CODEC_VORBIS, MediaDrmProxy::VORBIS, &widevine.mWebM},
+ { nsCString(AUDIO_WEBM), EME_CODEC_OPUS, MediaDrmProxy::OPUS, &widevine.mWebM},
};
for (const auto& data: validationList) {
if (MediaDrmProxy::IsCryptoSchemeSupported(kEMEKeySystemWidevine,
data.mMimeType)) {
if (MediaDrmProxy::CanDecode(data.mCodecType)) {
data.mSupportType->SetCanDecryptAndDecode(data.mEMECodecType);
} else {
--- a/dom/media/gtest/TestMediaDataDecoder.cpp
+++ b/dom/media/gtest/TestMediaDataDecoder.cpp
@@ -7,16 +7,17 @@
#include "Benchmark.h"
#include "MockMediaResource.h"
#include "DecoderTraits.h"
#include "MediaContainerType.h"
#include "MP4Demuxer.h"
#include "WebMDecoder.h"
#include "WebMDemuxer.h"
#include "mozilla/AbstractThread.h"
+#include "nsMimeTypes.h"
using namespace mozilla;
class BenchmarkRunner
{
public:
explicit BenchmarkRunner(Benchmark* aBenchmark)
: mBenchmark(aBenchmark) {}
@@ -40,32 +41,32 @@ public:
private:
RefPtr<Benchmark> mBenchmark;
};
TEST(MediaDataDecoder, H264)
{
if (!DecoderTraits::IsMP4SupportedType(
- MediaContainerType(MEDIAMIMETYPE("video/mp4")),
+ MediaContainerType(MEDIAMIMETYPE(VIDEO_MP4)),
/* DecoderDoctorDiagnostics* */ nullptr)) {
EXPECT_TRUE(true);
} else {
RefPtr<MockMediaResource> resource = new MockMediaResource("gizmo.mp4");
nsresult rv = resource->Open();
EXPECT_TRUE(NS_SUCCEEDED(rv));
BenchmarkRunner runner(new Benchmark(new MP4Demuxer(resource)));
EXPECT_GT(runner.Run(), 0u);
}
}
TEST(MediaDataDecoder, VP9)
{
- if (!WebMDecoder::IsSupportedType(MediaContainerType(MEDIAMIMETYPE("video/webm")))) {
+ if (!WebMDecoder::IsSupportedType(MediaContainerType(MEDIAMIMETYPE(VIDEO_WEBM)))) {
EXPECT_TRUE(true);
} else {
RefPtr<MockMediaResource> resource = new MockMediaResource("vp9cake.webm");
nsresult rv = resource->Open();
EXPECT_TRUE(NS_SUCCEEDED(rv));
BenchmarkRunner runner(new Benchmark(new WebMDemuxer(resource)));
EXPECT_GT(runner.Run(), 0u);
--- a/dom/media/gtest/TestVideoUtils.cpp
+++ b/dom/media/gtest/TestVideoUtils.cpp
@@ -1,23 +1,24 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "gtest/gtest.h"
+#include "nsMimeTypes.h"
#include "nsString.h"
#include "VideoUtils.h"
using namespace mozilla;
TEST(MediaMIMETypes, IsMediaMIMEType)
{
- EXPECT_TRUE(IsMediaMIMEType("audio/mp4"));
- EXPECT_TRUE(IsMediaMIMEType("video/mp4"));
+ EXPECT_TRUE(IsMediaMIMEType(AUDIO_MP4));
+ EXPECT_TRUE(IsMediaMIMEType(VIDEO_MP4));
EXPECT_TRUE(IsMediaMIMEType("application/x-mp4"));
EXPECT_TRUE(IsMediaMIMEType("audio/m"));
EXPECT_FALSE(IsMediaMIMEType("audio/"));
EXPECT_FALSE(IsMediaMIMEType("vide/mp4"));
EXPECT_FALSE(IsMediaMIMEType("videos/mp4"));
--- a/dom/media/mediasource/ContainerParser.cpp
+++ b/dom/media/mediasource/ContainerParser.cpp
@@ -10,16 +10,17 @@
#include "mozilla/EndianUtils.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/ErrorResult.h"
#include "MoofParser.h"
#include "mozilla/Logging.h"
#include "mozilla/Maybe.h"
#include "mozilla/Result.h"
#include "MediaData.h"
+#include "nsMimeTypes.h"
#ifdef MOZ_FMP4
#include "AtomType.h"
#include "BufferReader.h"
#include "Index.h"
#include "MP4Interval.h"
#include "ByteStream.h"
#endif
#include "nsAutoPtr.h"
@@ -847,24 +848,24 @@ public:
return 0;
}
};
#endif // MOZ_FMP4
/*static*/ ContainerParser*
ContainerParser::CreateForMIMEType(const MediaContainerType& aType)
{
- if (aType.Type() == MEDIAMIMETYPE("video/webm") ||
- aType.Type() == MEDIAMIMETYPE("audio/webm")) {
+ if (aType.Type() == MEDIAMIMETYPE(VIDEO_WEBM) ||
+ aType.Type() == MEDIAMIMETYPE(AUDIO_WEBM)) {
return new WebMContainerParser(aType);
}
#ifdef MOZ_FMP4
- if (aType.Type() == MEDIAMIMETYPE("video/mp4") ||
- aType.Type() == MEDIAMIMETYPE("audio/mp4")) {
+ if (aType.Type() == MEDIAMIMETYPE(VIDEO_MP4) ||
+ aType.Type() == MEDIAMIMETYPE(AUDIO_MP4)) {
return new MP4ContainerParser(aType);
}
if (aType.Type() == MEDIAMIMETYPE("audio/aac")) {
return new ADTSContainerParser(aType);
}
#endif
return new ContainerParser(aType);
--- a/dom/media/mediasource/MediaSource.cpp
+++ b/dom/media/mediasource/MediaSource.cpp
@@ -25,16 +25,17 @@
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/HTMLMediaElement.h"
#include "mozilla/mozalloc.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsIRunnable.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsPIDOMWindow.h"
+#include "nsMimeTypes.h"
#include "nsString.h"
#include "nsThreadUtils.h"
#include "mozilla/Logging.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/Sprintf.h"
#ifdef MOZ_WIDGET_ANDROID
@@ -81,17 +82,17 @@ namespace mozilla {
// * N/KN editions (Europe and Korea) of Windows 7/8/8.1/10 without the
// optional "Windows Media Feature Pack"
// 2. If H264 hardware acceleration is not available.
// 3. The CPU is considered to be fast enough
static bool
IsWebMForced(DecoderDoctorDiagnostics* aDiagnostics)
{
bool mp4supported =
- DecoderTraits::IsMP4SupportedType(MediaContainerType(MEDIAMIMETYPE("video/mp4")),
+ DecoderTraits::IsMP4SupportedType(MediaContainerType(MEDIAMIMETYPE(VIDEO_MP4)),
aDiagnostics);
bool hwsupported = gfx::gfxVars::CanUseHardwareVideoDecoding();
#ifdef MOZ_WIDGET_ANDROID
return !mp4supported || !hwsupported || VP9Benchmark::IsVP9DecodeFast() ||
java::HardwareCodecCapabilityUtils::HasHWVP9();
#else
return !mp4supported || !hwsupported || VP9Benchmark::IsVP9DecodeFast();
#endif
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -6,16 +6,17 @@
#include "TrackBuffersManager.h"
#include "ContainerParser.h"
#include "MediaPrefs.h"
#include "MediaSourceDemuxer.h"
#include "MediaSourceUtils.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/Preferences.h"
+#include "nsMimeTypes.h"
#include "SourceBuffer.h"
#include "SourceBufferResource.h"
#include "SourceBufferTask.h"
#include "WebMDemuxer.h"
#ifdef MOZ_FMP4
#include "MP4Demuxer.h"
#endif
@@ -891,26 +892,26 @@ TrackBuffersManager::ShutdownDemuxers()
mLastParsedEndTime.reset();
}
void
TrackBuffersManager::CreateDemuxerforMIMEType()
{
ShutdownDemuxers();
- if (mType.Type() == MEDIAMIMETYPE("video/webm") ||
- mType.Type() == MEDIAMIMETYPE("audio/webm")) {
+ if (mType.Type() == MEDIAMIMETYPE(VIDEO_WEBM) ||
+ mType.Type() == MEDIAMIMETYPE(AUDIO_WEBM)) {
mInputDemuxer = new WebMDemuxer(mCurrentInputBuffer, true /* IsMediaSource*/ );
DDLINKCHILD("demuxer", mInputDemuxer.get());
return;
}
#ifdef MOZ_FMP4
- if (mType.Type() == MEDIAMIMETYPE("video/mp4") ||
- mType.Type() == MEDIAMIMETYPE("audio/mp4")) {
+ if (mType.Type() == MEDIAMIMETYPE(VIDEO_MP4) ||
+ mType.Type() == MEDIAMIMETYPE(AUDIO_MP4)) {
mInputDemuxer = new MP4Demuxer(mCurrentInputBuffer);
DDLINKCHILD("demuxer", mInputDemuxer.get());
return;
}
#endif
NS_WARNING("Not supported (yet)");
}
--- a/dom/media/ogg/OggDecoder.cpp
+++ b/dom/media/ogg/OggDecoder.cpp
@@ -3,34 +3,35 @@
/* 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 "OggDecoder.h"
#include "MediaPrefs.h"
#include "MediaContainerType.h"
#include "MediaDecoder.h"
+#include "nsMimeTypes.h"
namespace mozilla {
/* static */
bool
OggDecoder::IsSupportedType(const MediaContainerType& aContainerType)
{
if (!MediaPrefs::OggEnabled()) {
return false;
}
- if (aContainerType.Type() != MEDIAMIMETYPE("audio/ogg") &&
- aContainerType.Type() != MEDIAMIMETYPE("video/ogg") &&
+ if (aContainerType.Type() != MEDIAMIMETYPE(AUDIO_OGG) &&
+ aContainerType.Type() != MEDIAMIMETYPE(VIDEO_OGG) &&
aContainerType.Type() != MEDIAMIMETYPE("application/ogg")) {
return false;
}
- const bool isOggVideo = (aContainerType.Type() != MEDIAMIMETYPE("audio/ogg"));
+ const bool isOggVideo = (aContainerType.Type() != MEDIAMIMETYPE(AUDIO_OGG));
const MediaCodecs& codecs = aContainerType.ExtendedType().Codecs();
if (codecs.IsEmpty()) {
// WebM guarantees that the only codecs it contained are vp8, vp9, opus or vorbis.
return true;
}
// Verify that all the codecs specified are ones that we expect that
// we can play.