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.
5 #ifndef MEDIA_REMOTING_METRICS_H_
6 #define MEDIA_REMOTING_METRICS_H_
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"
18 // The compatibility of a media content with remoting, and the reasons for
20 // These values are persisted to logs. Entries should not be renumbered and
21 // numeric values should never be reused.
22 enum class RemotingCompatibility {
26 kIncompatibleVideoCodec = 3,
28 kIncompatibleAudioCodec = 5,
30 kDurationBelowThreshold = 7,
31 // Add new values here. Don't re-number existing values.
33 kMaxValue = kDurationBelowThreshold,
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.
42 // More than 1080p 30fps and at most 2160p 30fps.
45 kOver4kNotSupported = 3,
46 // Add new values here. Don't re-number existing values.
48 kMaxValue = kOver4kNotSupported,
51 class SessionMetricsRecorder {
53 SessionMetricsRecorder();
55 SessionMetricsRecorder(const SessionMetricsRecorder&) = delete;
56 SessionMetricsRecorder& operator=(const SessionMetricsRecorder&) = delete;
58 ~SessionMetricsRecorder();
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
64 void WillStartSession(StartTrigger trigger);
65 void DidStartSession();
66 void StartSessionFailed(mojom::RemotingStartFailReason reason);
67 void WillStopSession(StopTrigger trigger);
69 // These may be called before, during, or after a remoting session.
70 void OnPipelineMetadataChanged(const PipelineMetadata& metadata);
71 void OnRemotePlaybackDisabled(bool disabled);
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);
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);
83 // Whether audio only, video only, or both were played during the session.
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,
95 TRACK_CONFIGURATION_MAX = 3,
98 // Helper methods to record media configuration at relevant times.
99 void RecordAudioConfiguration();
100 void RecordVideoConfiguration();
101 void RecordTrackConfiguration();
103 // |start_trigger_| is set while a remoting session is active.
104 absl::optional<StartTrigger> start_trigger_;
106 // When the current (or last) remoting session started.
107 base::TimeTicks start_time_;
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_;
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_;
122 bool did_record_pixel_rate_support_ = false;
123 bool did_record_compatibility_ = false;
126 class RendererMetricsRecorder {
128 RendererMetricsRecorder();
130 RendererMetricsRecorder(const RendererMetricsRecorder&) = delete;
131 RendererMetricsRecorder& operator=(const RendererMetricsRecorder&) = delete;
133 ~RendererMetricsRecorder();
135 // Called when an "initialize success" message is received from the remote.
136 void OnRendererInitialized();
138 // Called whenever there is direct (or indirect, but close-in-time) evidence
139 // that playout has occurred.
140 void OnEvidenceOfPlayoutAtReceiver();
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);
148 const base::TimeTicks start_time_;
149 bool did_record_first_playout_ = false;
152 } // namespace remoting
155 #endif // MEDIA_REMOTING_METRICS_H_