Bug 1362212 - Implement HTMLMediaElement.reportCanPlayTelemetry. r=gerald

Defer determining whether we have usable decoders to an off-main thread in
order to avoid janking the main thread.

MozReview-Commit-ID: Ape5zEBBMrz
This commit is contained in:
Chris Pearce
2017-05-10 11:31:16 +12:00
parent 96bd9d8648
commit 0ffdf7dd9f
4 changed files with 50 additions and 1 deletions

View File

@@ -96,11 +96,18 @@
#include "DecoderDoctorDiagnostics.h"
#include "DecoderTraits.h"
#include "MediaContainerType.h"
#include "MP4Decoder.h"
#include "ImageContainer.h"
#include "nsRange.h"
#include <algorithm>
#include <cmath>
#ifdef XP_WIN
#include "Objbase.h"
// Some Windows header defines this, so undef it as it conflicts with our
// function of the same name.
#undef GetCurrentTime
#endif
static mozilla::LazyLogModule gMediaElementLog("nsMediaElement");
static mozilla::LazyLogModule gMediaElementEventsLog("nsMediaElementEvents");
@@ -7481,5 +7488,43 @@ HTMLMediaElement::AsyncRejectSeekDOMPromiseIfExists()
}
}
void
HTMLMediaElement::ReportCanPlayTelemetry()
{
LOG(LogLevel::Debug, ("%s", __func__));
RefPtr<nsIThread> thread;
nsresult rv = NS_NewNamedThread("MediaTelemetry", getter_AddRefs(thread));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
thread->Dispatch(
NS_NewRunnableFunction([thread]() {
#if XP_WIN
// Windows Media Foundation requires MSCOM to be inited.
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
MOZ_ASSERT(hr == S_OK);
#endif
bool aac = MP4Decoder::IsSupportedType(
MediaContainerType(MEDIAMIMETYPE("audio/mp4")), nullptr);
bool h264 = MP4Decoder::IsSupportedType(
MediaContainerType(MEDIAMIMETYPE("video/mp4")), nullptr);
#if XP_WIN
CoUninitialize();
#endif
AbstractThread::MainThread()->Dispatch(
NS_NewRunnableFunction([thread, aac, h264]() {
LOG(LogLevel::Debug, ("MediaTelemetry aac=%d h264=%d", aac, h264));
Telemetry::Accumulate(
Telemetry::HistogramID::VIDEO_CAN_CREATE_AAC_DECODER, aac);
Telemetry::Accumulate(
Telemetry::HistogramID::VIDEO_CAN_CREATE_H264_DECODER, h264);
thread->AsyncShutdown();
}));
}),
NS_DISPATCH_NORMAL);
}
} // namespace dom
} // namespace mozilla

View File

@@ -102,6 +102,8 @@ public:
explicit HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
void ReportCanPlayTelemetry();
/**
* This is used when the browser is constructing a video element to play
* a channel that we've already started loading. The src attribute and

View File

@@ -181,6 +181,8 @@ private:
DECL_MEDIA_PREF("media.rust.mp4parser", EnableRustMP4Parser, bool, false);
#endif
DECL_MEDIA_PREF("media.mp4.enabled", MP4Enabled, bool, false);
// Error/warning handling, Decoder Doctor
DECL_MEDIA_PREF("media.playback.warnings-as-errors", MediaWarningsAsErrors, bool, false);
DECL_MEDIA_PREF("media.playback.warnings-as-errors.stagefright-vs-rust",

View File

@@ -181,7 +181,7 @@ MP4Decoder::IsAAC(const nsACString& aMimeType)
bool
MP4Decoder::IsEnabled()
{
return Preferences::GetBool("media.mp4.enabled", true);
return MediaPrefs::MP4Enabled();
}
// sTestH264ExtraData represents the content of the avcC atom found in