blob: 8ba4af39842a8de010683e1cda7448c1f6d3dbb1 [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"
Ilya Nikolaevskiy94150ee2018-05-23 11:53:19 +020018#include "api/video/video_content_type.h"
19#include "common_types.h" // NOLINT(build/include)
20#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);
38
39 void OnStreamInactive();
40
41 private:
42 void UpdateHistograms();
43
44 enum Resolution {
45 Low = 0,
46 Medium = 1,
47 High = 2,
48 };
49
50 int64_t last_frame_decoded_ms_;
51 int64_t num_frames_decoded_;
52 int64_t first_frame_decoded_ms_;
53 int64_t last_frame_pixels_;
54 uint8_t last_frame_qp_;
55 // Decoded timestamp of the last delayed frame.
56 int64_t last_unfreeze_time_;
57 rtc::SampleCounter interframe_delays_;
58 // An inter-frame delay is counted as a freeze if it's significantly longer
59 // than average inter-frame delay.
60 rtc::SampleCounter freezes_durations_;
61 // Time between freezes.
62 rtc::SampleCounter smooth_playback_durations_;
63 // Counters for time spent in different resolutions. Time between each two
64 // Consecutive frames is counted to bin corresponding to the first frame
65 // resolution.
66 std::vector<int64_t> time_in_resolution_ms_;
67 // Resolution of the last decoded frame. Resolution enum is used as an index.
68 Resolution current_resolution_;
69 int num_resolution_downgrades_;
70 // Similar to resolution, time spent in high-QP video.
71 int64_t time_in_blocky_video_ms_;
72 // Content type of the last decoded frame.
73 VideoContentType content_type_;
74 bool is_paused_;
75};
76
77} // namespace webrtc
78
79#endif // VIDEO_VIDEO_QUALITY_OBSERVER_H_