Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef DecoderDoctorDiagnostics_h_
8 : #define DecoderDoctorDiagnostics_h_
9 :
10 : #include "MediaResult.h"
11 : #include "nsString.h"
12 :
13 : class nsIDocument;
14 :
15 : namespace mozilla {
16 :
17 : struct DecoderDoctorEvent {
18 : enum Domain {
19 : eAudioSinkStartup,
20 : } mDomain;
21 : nsresult mResult;
22 : };
23 :
24 : // DecoderDoctorDiagnostics class, used to gather data from PDMs/DecoderTraits,
25 : // and then notify the user about issues preventing (or worsening) playback.
26 : //
27 : // The expected usage is:
28 : // 1. Instantiate a DecoderDoctorDiagnostics in a function (close to the point
29 : // where a webpage is trying to know whether some MIME types can be played,
30 : // or trying to play a media file).
31 : // 2. Pass a pointer to the DecoderDoctorDiagnostics structure to one of the
32 : // CanPlayStatus/IsTypeSupported/(others?). During that call, some PDMs may
33 : // add relevant diagnostic information.
34 : // 3. Analyze the collected diagnostics, and optionally dispatch an event to the
35 : // UX, to notify the user about potential playback issues and how to resolve
36 : // them.
37 : //
38 : // This class' methods must be called from the main thread.
39 :
40 0 : class DecoderDoctorDiagnostics
41 : {
42 : public:
43 : // Store the diagnostic information collected so far on a document for a
44 : // given format. All diagnostics for a document will be analyzed together
45 : // within a short timeframe.
46 : // Should only be called once.
47 : void StoreFormatDiagnostics(nsIDocument* aDocument,
48 : const nsAString& aFormat,
49 : bool aCanPlay,
50 : const char* aCallSite);
51 :
52 : void StoreMediaKeySystemAccess(nsIDocument* aDocument,
53 : const nsAString& aKeySystem,
54 : bool aIsSupported,
55 : const char* aCallSite);
56 :
57 : void StoreEvent(nsIDocument* aDocument,
58 : const DecoderDoctorEvent& aEvent,
59 : const char* aCallSite);
60 :
61 : void StoreDecodeError(nsIDocument* aDocument,
62 : const MediaResult& aError,
63 : const nsString& aMediaSrc,
64 : const char* aCallSite);
65 :
66 : void StoreDecodeWarning(nsIDocument* aDocument,
67 : const MediaResult& aWarning,
68 : const nsString& aMediaSrc,
69 : const char* aCallSite);
70 :
71 : enum DiagnosticsType
72 : {
73 : eUnsaved,
74 : eFormatSupportCheck,
75 : eMediaKeySystemAccessRequest,
76 : eEvent,
77 : eDecodeError,
78 : eDecodeWarning
79 : };
80 0 : DiagnosticsType Type() const { return mDiagnosticsType; }
81 :
82 : // Description string, for logging purposes; only call on stored diags.
83 : nsCString GetDescription() const;
84 :
85 : // Methods to record diagnostic information:
86 :
87 0 : const nsAString& Format() const { return mFormat; }
88 0 : bool CanPlay() const { return mCanPlay; }
89 :
90 0 : void SetWMFFailedToLoad() { mWMFFailedToLoad = true; }
91 : bool DidWMFFailToLoad() const { return mWMFFailedToLoad; }
92 :
93 0 : void SetFFmpegFailedToLoad() { mFFmpegFailedToLoad = true; }
94 0 : bool DidFFmpegFailToLoad() const { return mFFmpegFailedToLoad; }
95 :
96 0 : void SetGMPPDMFailedToStartup() { mGMPPDMFailedToStartup = true; }
97 : bool DidGMPPDMFailToStartup() const { return mGMPPDMFailedToStartup; }
98 :
99 0 : void SetVideoNotSupported() { mVideoNotSupported = true; }
100 0 : void SetAudioNotSupported() { mAudioNotSupported = true; }
101 :
102 : void SetGMP(const nsACString& aGMP) { mGMP = aGMP; }
103 : const nsACString& GMP() const { return mGMP; }
104 :
105 0 : const nsAString& KeySystem() const { return mKeySystem; }
106 0 : bool IsKeySystemSupported() const { return mIsKeySystemSupported; }
107 : enum KeySystemIssue {
108 : eUnset,
109 : eWidevineWithNoWMF
110 : };
111 : void SetKeySystemIssue(KeySystemIssue aKeySystemIssue)
112 : {
113 : mKeySystemIssue = aKeySystemIssue;
114 : }
115 0 : KeySystemIssue GetKeySystemIssue() const
116 : {
117 0 : return mKeySystemIssue;
118 : }
119 :
120 : DecoderDoctorEvent event() const
121 : {
122 : return mEvent;
123 : }
124 :
125 0 : const MediaResult& DecodeIssue() const { return mDecodeIssue; }
126 0 : const nsString& DecodeIssueMediaSrc() const
127 : {
128 0 : return mDecodeIssueMediaSrc;
129 : }
130 :
131 : private:
132 : // Currently-known type of diagnostics. Set from one of the 'Store...' methods.
133 : // This helps ensure diagnostics are only stored once,
134 : // and makes it easy to know what information they contain.
135 : DiagnosticsType mDiagnosticsType = eUnsaved;
136 :
137 : nsString mFormat;
138 : // True if there is at least one decoder that can play that format.
139 : bool mCanPlay = false;
140 :
141 : bool mWMFFailedToLoad = false;
142 : bool mFFmpegFailedToLoad = false;
143 : bool mGMPPDMFailedToStartup = false;
144 : bool mVideoNotSupported = false;
145 : bool mAudioNotSupported = false;
146 : nsCString mGMP;
147 :
148 : nsString mKeySystem;
149 : bool mIsKeySystemSupported = false;
150 : KeySystemIssue mKeySystemIssue = eUnset;
151 :
152 : DecoderDoctorEvent mEvent;
153 :
154 : MediaResult mDecodeIssue = NS_OK;
155 : nsString mDecodeIssueMediaSrc;
156 : };
157 :
158 : } // namespace mozilla
159 :
160 : #endif
|