Bug 1248507 - p2. DecoderDoctorDiagnostics boilerplate - r=jya
Minimal DecoderDoctorDiagnostics interface and skeleton implementation.
MozReview-Commit-ID: EUXRABPeoIg
new file mode 100644
--- /dev/null
+++ b/dom/media/DecoderDoctorDiagnostics.cpp
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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 "DecoderDoctorDiagnostics.h"
+
+#include "mozilla/Logging.h"
+
+static mozilla::LazyLogModule sDecoderDoctorLog("DecoderDoctor");
+#define DD_LOG(level, arg, ...) MOZ_LOG(sDecoderDoctorLog, level, (arg, ##__VA_ARGS__))
+#define DD_DEBUG(arg, ...) DD_LOG(mozilla::LogLevel::Debug, arg, ##__VA_ARGS__)
+#define DD_WARN(arg, ...) DD_LOG(mozilla::LogLevel::Warning, arg, ##__VA_ARGS__)
+
+namespace mozilla
+{
+
+void
+DecoderDoctorDiagnostics::StoreDiagnostics(nsIDocument* aDocument,
+ const nsAString& aFormat,
+ const char* aCallSite)
+{
+ if (NS_WARN_IF(!aDocument)) {
+ DD_WARN("DecoderDoctorDiagnostics[%p]::StoreDiagnostics(nsIDocument* aDocument=nullptr, format='%s', call site '%s')",
+ this, NS_ConvertUTF16toUTF8(aFormat).get(), aCallSite);
+ return;
+ }
+
+ // TODO: Actually analyze data.
+ DD_DEBUG("DecoderDoctorDiagnostics[%p]::StoreDiagnostics(nsIDocument* aDocument=%p, format='%s', call site '%s')",
+ this, aDocument, NS_ConvertUTF16toUTF8(aFormat).get(), aCallSite);
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/DecoderDoctorDiagnostics.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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/. */
+
+#ifndef DecoderDoctorDiagnostics_h_
+#define DecoderDoctorDiagnostics_h_
+
+class nsIDocument;
+class nsAString;
+
+namespace mozilla {
+
+// DecoderDoctorDiagnostics class, used to gather data from PDMs/DecoderTraits,
+// and then notify the user about issues preventing (or worsening) playback.
+//
+// The expected usage is:
+// 1. Instantiate a DecoderDoctorDiagnostics in a function (close to the point
+// where a webpage is trying to know whether some MIME types can be played,
+// or trying to play a media file).
+// 2. Pass a pointer to the DecoderDoctorDiagnostics structure to one of the
+// CanPlayStatus/IsTypeSupported/(others?). During that call, some PDMs may
+// add relevant diagnostic information.
+// 3. Analyze the collected diagnostics, and optionally dispatch an event to the
+// UX, to notify the user about potential playback issues and how to resolve
+// them.
+//
+// This class' methods must be called from the main thread.
+
+class DecoderDoctorDiagnostics
+{
+public:
+ // Store the diagnostic information collected so far on a document for a
+ // given format. All diagnostics for a document will be analyzed together
+ // within a short timeframe.
+ // Should only be called once.
+ void StoreDiagnostics(nsIDocument* aDocument,
+ const nsAString& aFormat,
+ const char* aCallSite);
+
+ // Methods to record diagnostic information:
+
+ void SetCanPlay() { mCanPlay = true; }
+ bool CanPlay() const { return mCanPlay; }
+
+private:
+ // True if there is at least one decoder that can play the media.
+ bool mCanPlay = false;
+};
+
+} // namespace mozilla
+
+#endif
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -93,16 +93,17 @@ EXPORTS += [
'AudioMixer.h',
'AudioPacketizer.h',
'AudioSampleFormat.h',
'AudioSegment.h',
'AudioStream.h',
'Benchmark.h',
'BufferMediaResource.h',
'CubebUtils.h',
+ 'DecoderDoctorDiagnostics.h',
'DecoderTraits.h',
'DOMMediaStream.h',
'EncodedBufferCache.h',
'FileBlockCache.h',
'FlushableTaskQueue.h',
'FrameStatistics.h',
'Intervals.h',
'Latency.h',
@@ -203,16 +204,17 @@ UNIFIED_SOURCES += [
'AudioSegment.cpp',
'AudioStream.cpp',
'AudioStreamTrack.cpp',
'AudioTrack.cpp',
'AudioTrackList.cpp',
'Benchmark.cpp',
'CanvasCaptureMediaStream.cpp',
'CubebUtils.cpp',
+ 'DecoderDoctorDiagnostics.cpp',
'DOMMediaStream.cpp',
'EncodedBufferCache.cpp',
'FileBlockCache.cpp',
'FlushableTaskQueue.cpp',
'GetUserMediaRequest.cpp',
'GraphDriver.cpp',
'Latency.cpp',
'MediaCache.cpp',