Bug 1330284 - Use MediaContentType in DecoderTraits:IsHttpLiveStreamingType - r?jya
MozReview-Commit-ID: I0C3ulkYiGX
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -45,41 +45,25 @@
#include "FlacDemuxer.h"
#include "nsPluginHost.h"
#include "MediaPrefs.h"
namespace mozilla
{
-template <class String>
static bool
-CodecListContains(char const *const * aCodecs, const String& aCodec)
+IsHttpLiveStreamingType(const MediaContentType& aType)
{
- for (int32_t i = 0; aCodecs[i]; ++i) {
- if (aCodec.EqualsASCII(aCodecs[i]))
- return true;
- }
- return false;
-}
-
-static char const *const gHttpLiveStreamingTypes[] = {
- // For m3u8.
- // https://tools.ietf.org/html/draft-pantos-http-live-streaming-19#section-10
- "application/vnd.apple.mpegurl",
- // Some sites serve these as the informal m3u type.
- "application/x-mpegurl",
- "audio/x-mpegurl",
- nullptr
-};
-
-static bool
-IsHttpLiveStreamingType(const nsACString& aType)
-{
- return CodecListContains(gHttpLiveStreamingTypes, aType);
+ return // For m3u8.
+ // https://tools.ietf.org/html/draft-pantos-http-live-streaming-19#section-10
+ aType.Type() == MEDIAMIMETYPE("application/vnd.apple.mpegurl")
+ // Some sites serve these as the informal m3u type.
+ || aType.Type() == MEDIAMIMETYPE("application/x-mpegurl")
+ || aType.Type() == MEDIAMIMETYPE("audio/x-mpegurl");
}
#ifdef MOZ_ANDROID_OMX
static bool
IsAndroidMediaType(const MediaContentType& aType)
{
if (!MediaDecoder::IsAndroidMediaPluginEnabled()) {
return false;
@@ -188,17 +172,17 @@ CanHandleCodecsType(const MediaContentTy
static
CanPlayStatus
CanHandleMediaType(const MediaContentType& aType,
DecoderDoctorDiagnostics* aDiagnostics)
{
MOZ_ASSERT(NS_IsMainThread());
- if (IsHttpLiveStreamingType(aType.Type().AsString())) {
+ if (IsHttpLiveStreamingType(aType)) {
Telemetry::Accumulate(Telemetry::MEDIA_HLS_CANPLAY_REQUESTED, true);
}
if (aType.ExtendedType().HaveCodecs()) {
CanPlayStatus result = CanHandleCodecsType(aType, aDiagnostics);
if (result == CANPLAY_NO || result == CANPLAY_YES) {
return result;
}
@@ -339,17 +323,17 @@ InstantiateDecoder(const MediaContentTyp
// Note: DirectShow should come before WMF, so that we prefer DirectShow's
// MP3 support over WMF's.
if (DirectShowDecoder::GetSupportedCodecs(aType, nullptr)) {
decoder = new DirectShowDecoder(aOwner);
return decoder.forget();
}
#endif
- if (IsHttpLiveStreamingType(aType.Type().AsString())) {
+ if (IsHttpLiveStreamingType(aType)) {
// We don't have an HLS decoder.
Telemetry::Accumulate(Telemetry::MEDIA_HLS_DECODER_SUCCESS, false);
}
return nullptr;
}
/* static */