blob: b940efdf1150031f104e2a3971d8e73460eb57d3 [file] [log] [blame]
Niels Möller213618e2018-07-24 09:29:58 +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 API_VIDEO_VIDEO_STREAM_ENCODER_OBSERVER_H_
12#define API_VIDEO_VIDEO_STREAM_ENCODER_OBSERVER_H_
13
14#include <vector>
15
16#include "absl/types/optional.h"
17#include "api/video_codecs/video_encoder.h"
18#include "api/video_codecs/video_encoder_config.h"
19
20namespace webrtc {
21
22// TODO(nisse): Used for the OnSendEncodedImage callback below. The callback
23// wants metadata such as size, encode timing, qp, but doesn't need actual
24// encoded data. So use some other type to represent that.
25class EncodedImage;
26
27// Broken out into a base class, with public inheritance below, only to ease
28// unit testing of the internal class OveruseFrameDetector.
29class CpuOveruseMetricsObserver {
30 public:
31 virtual ~CpuOveruseMetricsObserver() = default;
32 virtual void OnEncodedFrameTimeMeasured(int encode_duration_ms,
33 int encode_usage_percent) = 0;
34};
35
36class VideoStreamEncoderObserver : public CpuOveruseMetricsObserver {
37 public:
38 // Number of resolution and framerate reductions (unset if disabled).
39 struct AdaptationSteps {
Mirko Bonadei8fdcac32018-08-28 16:30:18 +020040 AdaptationSteps();
Niels Möller213618e2018-07-24 09:29:58 +020041 absl::optional<int> num_resolution_reductions = 0;
42 absl::optional<int> num_framerate_reductions = 0;
43 };
44
45 // TODO(nisse): There are too many enums to represent this. Besides
46 // this one, see AdaptationObserverInterface::AdaptReason and
47 // WebRtcVideoChannel::AdaptReason.
48 enum class AdaptationReason {
49 kNone, // Used for reset of counters.
50 kCpu,
51 kQuality,
52 };
53
54 // TODO(nisse): Duplicates enum EncodedImageCallback::DropReason.
55 enum class DropReason {
56 kSource,
57 kEncoderQueue,
58 kEncoder,
59 kMediaOptimization
60 };
61
Mirko Bonadei8fdcac32018-08-28 16:30:18 +020062 ~VideoStreamEncoderObserver() override = default;
Niels Möller213618e2018-07-24 09:29:58 +020063
64 virtual void OnIncomingFrame(int width, int height) = 0;
65
66 // TODO(nisse): Merge into one callback per encoded frame.
67 using CpuOveruseMetricsObserver::OnEncodedFrameTimeMeasured;
68 virtual void OnSendEncodedImage(const EncodedImage& encoded_image,
69 const CodecSpecificInfo* codec_info) = 0;
70
71 virtual void OnFrameDropped(DropReason reason) = 0;
72
73 // Used to indicate change in content type, which may require a change in
74 // how stats are collected and set the configured preferred media bitrate.
75 virtual void OnEncoderReconfigured(
76 const VideoEncoderConfig& encoder_config,
77 const std::vector<VideoStream>& streams) = 0;
78
79 virtual void OnAdaptationChanged(AdaptationReason reason,
80 const AdaptationSteps& cpu_steps,
81 const AdaptationSteps& quality_steps) = 0;
82 virtual void OnMinPixelLimitReached() = 0;
83 virtual void OnInitialQualityResolutionAdaptDown() = 0;
84
85 virtual void OnSuspendChange(bool is_suspended) = 0;
86
87 // TODO(nisse): VideoStreamEncoder wants to query the stats, which makes this
88 // not a pure observer. GetInputFrameRate is needed for the cpu adaptation, so
89 // can be deleted if that responsibility is moved out to a VideoStreamAdaptor
90 // class.
91 virtual int GetInputFrameRate() const = 0;
92};
93
94} // namespace webrtc
95#endif // API_VIDEO_VIDEO_STREAM_ENCODER_OBSERVER_H_