Fix FullScreen crash in Webapp
[platform/framework/web/chromium-efl.git] / media / remoting / metrics.h
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_REMOTING_METRICS_H_
6 #define MEDIA_REMOTING_METRICS_H_
7
8 #include "base/time/time.h"
9 #include "media/base/pipeline_metadata.h"
10 #include "media/mojo/mojom/remoting_common.mojom.h"
11 #include "media/remoting/triggers.h"
12 #include "third_party/abseil-cpp/absl/types/optional.h"
13 #include "ui/gfx/geometry/size.h"
14
15 namespace media {
16 namespace remoting {
17
18 // The compatibility of a media content with remoting, and the reasons for
19 // incompatibilities.
20 // These values are persisted to logs. Entries should not be renumbered and
21 // numeric values should never be reused.
22 enum class RemotingCompatibility {
23   kCompatible = 0,
24   kNoAudioNorVideo = 1,
25   kEncryptedVideo = 2,
26   kIncompatibleVideoCodec = 3,
27   kEncryptedAudio = 4,
28   kIncompatibleAudioCodec = 5,
29   kDisabledByPage = 6,
30   kDurationBelowThreshold = 7,
31   // Add new values here. Don't re-number existing values.
32
33   kMaxValue = kDurationBelowThreshold,
34 };
35
36 // The rate of pixels in a video and whether the receiver supports its playback.
37 // These values are persisted to logs. Entries should not be renumbered and
38 // numeric values should never be reused.
39 enum class PixelRateSupport {
40   // Pixels per second is at most the equivalent of 1080p 30fps.
41   k2kSupported = 0,
42   // More than 1080p 30fps and at most 2160p 30fps.
43   k4kSupported = 1,
44   k4kNotSupported = 2,
45   kOver4kNotSupported = 3,
46   // Add new values here. Don't re-number existing values.
47
48   kMaxValue = kOver4kNotSupported,
49 };
50
51 class SessionMetricsRecorder {
52  public:
53   SessionMetricsRecorder();
54
55   SessionMetricsRecorder(const SessionMetricsRecorder&) = delete;
56   SessionMetricsRecorder& operator=(const SessionMetricsRecorder&) = delete;
57
58   ~SessionMetricsRecorder();
59
60   // When attempting to start a remoting session, WillStartSession() is called,
61   // followed by either OnSessionStartSucceeded() or OnSessionStop() to indicate
62   // whether the start succeeded. Later, OnSessionStop() is called when the
63   // session ends.
64   void WillStartSession(StartTrigger trigger);
65   void DidStartSession();
66   void StartSessionFailed(mojom::RemotingStartFailReason reason);
67   void WillStopSession(StopTrigger trigger);
68
69   // These may be called before, during, or after a remoting session.
70   void OnPipelineMetadataChanged(const PipelineMetadata& metadata);
71   void OnRemotePlaybackDisabled(bool disabled);
72
73   // Records the rate of pixels in a video (bucketed into FHD, 4K, etc.) and
74   // whether the receiver supports its playback. Records only on the first call
75   // for the recorder instance.
76   void RecordVideoPixelRateSupport(PixelRateSupport support);
77
78   // Records the compatibility of a media content with remoting. Records only on
79   // the first call for the recorder instance.
80   void RecordCompatibility(RemotingCompatibility compatibility);
81
82  private:
83   // Whether audio only, video only, or both were played during the session.
84   //
85   // NOTE: Never re-number or re-use numbers here. These are used in UMA
86   // histograms, and must remain backwards-compatible for all time. However,
87   // *do* change TRACK_CONFIGURATION_MAX to one after the greatest value when
88   // adding new ones. Also, don't forget to update histograms.xml!
89   enum TrackConfiguration {
90     NEITHER_AUDIO_NOR_VIDEO = 0,
91     AUDIO_ONLY = 1,
92     VIDEO_ONLY = 2,
93     AUDIO_AND_VIDEO = 3,
94
95     TRACK_CONFIGURATION_MAX = 3,
96   };
97
98   // Helper methods to record media configuration at relevant times.
99   void RecordAudioConfiguration();
100   void RecordVideoConfiguration();
101   void RecordTrackConfiguration();
102
103   // |start_trigger_| is set while a remoting session is active.
104   absl::optional<StartTrigger> start_trigger_;
105
106   // When the current (or last) remoting session started.
107   base::TimeTicks start_time_;
108
109   // Last known audio and video configuration. These can change before/after a
110   // remoting session as well as during one.
111   AudioCodec last_audio_codec_;
112   ChannelLayout last_channel_layout_;
113   int last_sample_rate_;
114   VideoCodec last_video_codec_;
115   VideoCodecProfile last_video_profile_;
116   gfx::Size last_natural_size_;
117
118   // Last known disabled playback state. This can change before/after a remoting
119   // session as well as during one.
120   absl::optional<bool> remote_playback_is_disabled_;
121
122   bool did_record_pixel_rate_support_ = false;
123   bool did_record_compatibility_ = false;
124 };
125
126 class RendererMetricsRecorder {
127  public:
128   RendererMetricsRecorder();
129
130   RendererMetricsRecorder(const RendererMetricsRecorder&) = delete;
131   RendererMetricsRecorder& operator=(const RendererMetricsRecorder&) = delete;
132
133   ~RendererMetricsRecorder();
134
135   // Called when an "initialize success" message is received from the remote.
136   void OnRendererInitialized();
137
138   // Called whenever there is direct (or indirect, but close-in-time) evidence
139   // that playout has occurred.
140   void OnEvidenceOfPlayoutAtReceiver();
141
142   // These are called at regular intervals throughout the session to provide
143   // estimated data flow rates.
144   void OnAudioRateEstimate(int kilobits_per_second);
145   void OnVideoRateEstimate(int kilobits_per_second);
146
147  private:
148   const base::TimeTicks start_time_;
149   bool did_record_first_playout_ = false;
150 };
151
152 }  // namespace remoting
153 }  // namespace media
154
155 #endif  // MEDIA_REMOTING_METRICS_H_