1 // Copyright 2015 The Chromium Authors. All rights reserved.
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_CAST_SENDER_PERFORMANCE_METRICS_OVERLAY_H_
6 #define MEDIA_CAST_SENDER_PERFORMANCE_METRICS_OVERLAY_H_
7 
8 #include "base/time/time.h"
9 #include "media/base/video_frame.h"
10 
11 // This module provides a display of frame-level performance metrics, rendered
12 // in the lower-right corner of a VideoFrame.  It looks like this:
13 //
14 // +---------------------------------------------------------------------+
15 // |                         @@@@@@@@@@@@@@@@@@@@@@@                     |
16 // |                 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                     |
17 // |              @@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@                   |
18 // |             @@@@@@@@@@@@@                    @@@@                   |
19 // |            @@@@@@@@@@                        @@@@                   |
20 // |           @@@@@  @@@               @@@       @@@@                   |
21 // |           @@@     @    @@@         @@@@      @@@@                   |
22 // |          @@@@          @@@@                  @@@@                   |
23 // |          @@@@                  @@@           @@@                    |
24 // |            @@@@                 @@           @@@                    |
25 // |             @@@@@      @@@            @@@   @@@                     |
26 // |              @@@@@     @@@@@        @@@@   @@@@                     |
27 // |               @@@@@      @@@@@@@@@@@@@    @@@@                      |
28 // |                @@@@@@                    @@@@           1  45%  75% |
29 // |                    @@@@@@@@         @@@@@@            22  400. 4000 |
30 // |                         @@@@@@@@@@@@@@@@      16.7 1280x720 0:15.12 |
31 // +---------------------------------------------------------------------+
32 //
33 // Line 1: Reads as, "1 frame ago, the encoder utilization for the frame was 45%
34 // and the lossy utilization was 75%."  For CPU-bound encoders, encoder
35 // utilization is usually measured as the amount of real-world time it took to
36 // encode the frame, divided by the maximum amount of time allowed.  Lossy
37 // utilization is the amount of "complexity" in the frame's content versus the
38 // target encoded byte size, where a value over 100% means the frame's content
39 // is too complex to encode within the target number of bytes.
40 //
41 // Line 2: Reads as, "Capture of this frame took 22 ms.  The current target
42 // playout delay is 400 ms and low-latency adjustment mode is not active.  The
43 // target bitrate for this frame is 4000 kbps."  If there were an exclamation
44 // mark (!) after the playout delay number instead of a period (.), it would
45 // indicate low-latency adjustment mode is active.  See VideoSender for more
46 // details.
47 //
48 // Line 3: Contains the frame's duration (16.7 milliseconds), resolution, and
49 // media timestamp in minutes:seconds.hundredths format.
50 
51 namespace media {
52 namespace cast {
53 
54 // If the user has requested VideoFrames have a performance metrics overlay
55 // rendered on them, this function copies the |source| frame and then renders an
56 // overlay on the copy. Frame-level performance metrics will be rendered in the
57 // lower-right corner of the frame, as described in the module-level comments
58 // above.
59 //
60 // The verbose logging level for video_frame_overlay.cc determines which lines,
61 // if any, are rendered: no VLOG level does nothing, level 1 renders the bottom
62 // line only, level 2 renders the bottom and middle lines, and level 3 renders
63 // all three lines. So, use the --vmodule=performance_metrics_overlay=3 command
64 // line argument to turn on rendering of the entire overlay.
65 //
66 // Note: If |source| is an unsupported format, or no pixels need to be modified,
67 // this function will just return |source|.
68 scoped_refptr<VideoFrame> MaybeRenderPerformanceMetricsOverlay(
69     base::TimeDelta target_playout_delay,
70     bool in_low_latency_mode,
71     int target_bitrate,
72     int frames_ago,
73     double encoder_utilization,
74     double lossy_utilization,
75     scoped_refptr<VideoFrame> source);
76 
77 }  // namespace cast
78 }  // namespace media
79 
80 #endif  // MEDIA_CAST_SENDER_PERFORMANCE_METRICS_OVERLAY_H_
81