2016-04-19 10:36:19 +03:00
|
|
|
/* -*- 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_
|
|
|
|
|
2017-02-21 06:07:23 +03:00
|
|
|
#include "MediaResult.h"
|
2020-10-21 02:26:27 +03:00
|
|
|
#include "mozilla/DefineEnum.h"
|
|
|
|
#include "mozilla/EnumSet.h"
|
|
|
|
#include "mozilla/EnumTypeTraits.h"
|
2021-02-25 21:07:06 +03:00
|
|
|
#include "mozilla/dom/DecoderDoctorNotificationBinding.h"
|
2016-04-22 06:42:11 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
|
2016-04-19 10:36:19 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
namespace dom {
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
|
2016-09-19 05:50:01 +03:00
|
|
|
struct DecoderDoctorEvent {
|
|
|
|
enum Domain {
|
2016-09-19 05:41:36 +03:00
|
|
|
eAudioSinkStartup,
|
2016-09-19 05:50:01 +03:00
|
|
|
} mDomain;
|
|
|
|
nsresult mResult;
|
|
|
|
};
|
|
|
|
|
2016-04-19 10:36:19 +03:00
|
|
|
// 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 {
|
2020-10-21 02:26:27 +03:00
|
|
|
friend struct IPC::ParamTraits<mozilla::DecoderDoctorDiagnostics>;
|
|
|
|
|
2016-04-19 10:36:19 +03:00
|
|
|
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.
|
2019-01-02 16:05:23 +03:00
|
|
|
void StoreFormatDiagnostics(dom::Document* aDocument,
|
|
|
|
const nsAString& aFormat, bool aCanPlay,
|
|
|
|
const char* aCallSite);
|
2016-04-22 06:42:11 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void StoreMediaKeySystemAccess(dom::Document* aDocument,
|
2016-04-22 06:42:11 +03:00
|
|
|
const nsAString& aKeySystem, bool aIsSupported,
|
|
|
|
const char* aCallSite);
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void StoreEvent(dom::Document* aDocument, const DecoderDoctorEvent& aEvent,
|
2016-09-19 05:50:01 +03:00
|
|
|
const char* aCallSite);
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void StoreDecodeError(dom::Document* aDocument, const MediaResult& aError,
|
2017-02-21 06:07:23 +03:00
|
|
|
const nsString& aMediaSrc, const char* aCallSite);
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void StoreDecodeWarning(dom::Document* aDocument, const MediaResult& aWarning,
|
2017-02-21 06:07:23 +03:00
|
|
|
const nsString& aMediaSrc, const char* aCallSite);
|
|
|
|
|
|
|
|
enum DiagnosticsType {
|
2016-04-22 06:42:11 +03:00
|
|
|
eUnsaved,
|
|
|
|
eFormatSupportCheck,
|
2016-09-19 05:50:01 +03:00
|
|
|
eMediaKeySystemAccessRequest,
|
2017-02-21 06:07:23 +03:00
|
|
|
eEvent,
|
|
|
|
eDecodeError,
|
|
|
|
eDecodeWarning
|
2016-04-22 06:42:11 +03:00
|
|
|
};
|
|
|
|
DiagnosticsType Type() const { return mDiagnosticsType; }
|
|
|
|
|
|
|
|
// Description string, for logging purposes; only call on stored diags.
|
2016-04-22 06:42:11 +03:00
|
|
|
nsCString GetDescription() const;
|
2016-04-19 10:36:19 +03:00
|
|
|
|
|
|
|
// Methods to record diagnostic information:
|
|
|
|
|
2020-10-21 02:26:27 +03:00
|
|
|
MOZ_DEFINE_ENUM_CLASS_AT_CLASS_SCOPE(
|
2021-02-25 21:07:05 +03:00
|
|
|
Flags, (CanPlay, WMFFailedToLoad, FFmpegNotFound, LibAVCodecUnsupported,
|
2020-10-21 02:26:27 +03:00
|
|
|
GMPPDMFailedToStartup, VideoNotSupported, AudioNotSupported));
|
|
|
|
using FlagsSet = mozilla::EnumSet<Flags>;
|
|
|
|
|
2016-04-22 06:42:11 +03:00
|
|
|
const nsAString& Format() const { return mFormat; }
|
2020-10-21 02:26:27 +03:00
|
|
|
bool CanPlay() const { return mFlags.contains(Flags::CanPlay); }
|
2016-04-19 10:36:19 +03:00
|
|
|
|
2020-10-21 02:26:27 +03:00
|
|
|
void SetFailureFlags(const FlagsSet& aFlags) { mFlags = aFlags; }
|
|
|
|
void SetWMFFailedToLoad() { mFlags += Flags::WMFFailedToLoad; }
|
|
|
|
bool DidWMFFailToLoad() const {
|
|
|
|
return mFlags.contains(Flags::WMFFailedToLoad);
|
|
|
|
}
|
2016-04-22 06:42:11 +03:00
|
|
|
|
2021-02-25 21:07:05 +03:00
|
|
|
void SetFFmpegNotFound() { mFlags += Flags::FFmpegNotFound; }
|
|
|
|
bool DidFFmpegNotFound() const {
|
|
|
|
return mFlags.contains(Flags::FFmpegNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetLibAVCodecUnsupported() { mFlags += Flags::LibAVCodecUnsupported; }
|
|
|
|
bool IsLibAVCodecUnsupported() const {
|
|
|
|
return mFlags.contains(Flags::LibAVCodecUnsupported);
|
2020-10-21 02:26:27 +03:00
|
|
|
}
|
2016-04-19 10:36:20 +03:00
|
|
|
|
2020-10-21 02:26:27 +03:00
|
|
|
void SetGMPPDMFailedToStartup() { mFlags += Flags::GMPPDMFailedToStartup; }
|
|
|
|
bool DidGMPPDMFailToStartup() const {
|
|
|
|
return mFlags.contains(Flags::GMPPDMFailedToStartup);
|
|
|
|
}
|
2016-08-19 13:14:28 +03:00
|
|
|
|
2020-10-21 02:26:27 +03:00
|
|
|
void SetVideoNotSupported() { mFlags += Flags::VideoNotSupported; }
|
|
|
|
void SetAudioNotSupported() { mFlags += Flags::AudioNotSupported; }
|
2016-08-19 13:14:28 +03:00
|
|
|
|
2016-04-22 06:42:11 +03:00
|
|
|
void SetGMP(const nsACString& aGMP) { mGMP = aGMP; }
|
|
|
|
const nsACString& GMP() const { return mGMP; }
|
|
|
|
|
2016-04-22 06:42:11 +03:00
|
|
|
const nsAString& KeySystem() const { return mKeySystem; }
|
|
|
|
bool IsKeySystemSupported() const { return mIsKeySystemSupported; }
|
|
|
|
enum KeySystemIssue { eUnset, eWidevineWithNoWMF };
|
|
|
|
void SetKeySystemIssue(KeySystemIssue aKeySystemIssue) {
|
|
|
|
mKeySystemIssue = aKeySystemIssue;
|
|
|
|
}
|
|
|
|
KeySystemIssue GetKeySystemIssue() const { return mKeySystemIssue; }
|
|
|
|
|
2016-09-19 05:50:01 +03:00
|
|
|
DecoderDoctorEvent event() const { return mEvent; }
|
|
|
|
|
2017-02-21 06:07:23 +03:00
|
|
|
const MediaResult& DecodeIssue() const { return mDecodeIssue; }
|
|
|
|
const nsString& DecodeIssueMediaSrc() const { return mDecodeIssueMediaSrc; }
|
|
|
|
|
2021-02-25 21:07:06 +03:00
|
|
|
// This method is only used for testing.
|
|
|
|
void SetDecoderDoctorReportType(const dom::DecoderDoctorReportType& aType);
|
|
|
|
|
2016-04-19 10:36:19 +03:00
|
|
|
private:
|
2016-04-22 06:42:11 +03:00
|
|
|
// Currently-known type of diagnostics. Set from one of the 'Store...'
|
|
|
|
// methods. This helps ensure diagnostics are only stored once, and makes it
|
|
|
|
// easy to know what information they contain.
|
|
|
|
DiagnosticsType mDiagnosticsType = eUnsaved;
|
|
|
|
|
2016-04-22 06:42:11 +03:00
|
|
|
nsString mFormat;
|
2020-10-21 02:26:27 +03:00
|
|
|
FlagsSet mFlags;
|
2016-04-22 06:42:11 +03:00
|
|
|
nsCString mGMP;
|
2016-04-22 06:42:11 +03:00
|
|
|
|
|
|
|
nsString mKeySystem;
|
|
|
|
bool mIsKeySystemSupported = false;
|
|
|
|
KeySystemIssue mKeySystemIssue = eUnset;
|
2016-09-19 05:50:01 +03:00
|
|
|
|
|
|
|
DecoderDoctorEvent mEvent;
|
2017-02-21 06:07:23 +03:00
|
|
|
|
|
|
|
MediaResult mDecodeIssue = NS_OK;
|
|
|
|
nsString mDecodeIssueMediaSrc;
|
2016-04-19 10:36:19 +03:00
|
|
|
};
|
|
|
|
|
2020-10-21 02:26:27 +03:00
|
|
|
// Used for IPDL serialization.
|
|
|
|
// The 'value' have to be the biggest enum from DecoderDoctorDiagnostics::Flags.
|
|
|
|
template <>
|
|
|
|
struct MaxEnumValue<::mozilla::DecoderDoctorDiagnostics::Flags> {
|
|
|
|
static constexpr unsigned int value =
|
|
|
|
static_cast<unsigned int>(DecoderDoctorDiagnostics::sFlagsCount);
|
|
|
|
};
|
|
|
|
|
2016-04-19 10:36:19 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|