blob: 74f201e8c45f53f567ee0c9759f8598cb7344f7d [file] [log] [blame]
Ilya Nikolaevskiy94150ee2018-05-23 11:53:19 +02001/*
2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef VIDEO_VIDEO_QUALITY_OBSERVER_H_
12#define VIDEO_VIDEO_QUALITY_OBSERVER_H_
13
14#include <stdint.h>
15#include <vector>
16
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020017#include "absl/types/optional.h"
Niels Möller22b70ff2018-11-20 11:06:58 +010018#include "api/video/video_codec_type.h"
Ilya Nikolaevskiy94150ee2018-05-23 11:53:19 +020019#include "api/video/video_content_type.h"
Ilya Nikolaevskiy94150ee2018-05-23 11:53:19 +020020#include "rtc_base/numerics/sample_counter.h"
21
22namespace webrtc {
23
24// Calculates spatial and temporal quality metrics and reports them to UMA
25// stats.
26class VideoQualityObserver {
27 public:
28 // Use either VideoQualityObserver::kBlockyQpThresholdVp8 or
29 // VideoQualityObserver::kBlockyQpThresholdVp9.
30 explicit VideoQualityObserver(VideoContentType content_type);
31 ~VideoQualityObserver();
32
Danil Chapovalovb9b146c2018-06-15 12:28:07 +020033 void OnDecodedFrame(absl::optional<uint8_t> qp,
Ilya Nikolaevskiy94150ee2018-05-23 11:53:19 +020034 int width,
35 int height,
36 int64_t now_ms,
37 VideoCodecType codec);
Ilya Nikolaevskiycdc959f2018-10-10 13:15:09 +020038 void OnRenderedFrame(int64_t now_ms);
Ilya Nikolaevskiy94150ee2018-05-23 11:53:19 +020039
40 void OnStreamInactive();
41
42 private:
43 void UpdateHistograms();
44
45 enum Resolution {
46 Low = 0,
47 Medium = 1,
48 High = 2,
49 };
50
51 int64_t last_frame_decoded_ms_;
Ilya Nikolaevskiycdc959f2018-10-10 13:15:09 +020052 int64_t last_frame_rendered_ms_;
Ilya Nikolaevskiy94150ee2018-05-23 11:53:19 +020053 int64_t num_frames_decoded_;
Ilya Nikolaevskiycdc959f2018-10-10 13:15:09 +020054 int64_t num_frames_rendered_;
Ilya Nikolaevskiy94150ee2018-05-23 11:53:19 +020055 int64_t first_frame_decoded_ms_;
56 int64_t last_frame_pixels_;
57 uint8_t last_frame_qp_;
58 // Decoded timestamp of the last delayed frame.
59 int64_t last_unfreeze_time_;
Ilya Nikolaevskiycdc959f2018-10-10 13:15:09 +020060 rtc::SampleCounter render_interframe_delays_;
61 rtc::SampleCounter decode_interframe_delays_;
Ilya Nikolaevskiy94150ee2018-05-23 11:53:19 +020062 // An inter-frame delay is counted as a freeze if it's significantly longer
63 // than average inter-frame delay.
64 rtc::SampleCounter freezes_durations_;
65 // Time between freezes.
66 rtc::SampleCounter smooth_playback_durations_;
67 // Counters for time spent in different resolutions. Time between each two
68 // Consecutive frames is counted to bin corresponding to the first frame
69 // resolution.
70 std::vector<int64_t> time_in_resolution_ms_;
71 // Resolution of the last decoded frame. Resolution enum is used as an index.
72 Resolution current_resolution_;
73 int num_resolution_downgrades_;
74 // Similar to resolution, time spent in high-QP video.
75 int64_t time_in_blocky_video_ms_;
76 // Content type of the last decoded frame.
77 VideoContentType content_type_;
78 bool is_paused_;
79};
80
81} // namespace webrtc
82
83#endif // VIDEO_VIDEO_QUALITY_OBSERVER_H_