blob: 95ca5fa887f2341412510e46fa396b98152d3b1e [file] [log] [blame]
Niels Möller213618e2018-07-24 07:29:581/*
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
Jonas Oreland6c2dae22022-09-29 08:28:2411#ifndef VIDEO_VIDEO_STREAM_ENCODER_OBSERVER_H_
12#define VIDEO_VIDEO_STREAM_ENCODER_OBSERVER_H_
Niels Möller213618e2018-07-24 07:29:5813
Erik Språnge2fd86a72018-10-24 09:32:3914#include <string>
Niels Möller213618e2018-07-24 07:29:5815#include <vector>
16
Evan Shrubsoledff79252020-04-16 09:34:3217#include "api/video/video_adaptation_counters.h"
Evan Shrubsolece0a11d2020-04-16 09:36:5518#include "api/video/video_adaptation_reason.h"
Evan Shrubsolecc62b162019-09-09 09:26:4519#include "api/video/video_bitrate_allocation.h"
Niels Möller213618e2018-07-24 07:29:5820#include "api/video_codecs/video_encoder.h"
Jonas Oreland6c2dae22022-09-29 08:28:2421#include "video/config/video_encoder_config.h"
Niels Möller213618e2018-07-24 07:29:5822
23namespace webrtc {
24
25// TODO(nisse): Used for the OnSendEncodedImage callback below. The callback
26// wants metadata such as size, encode timing, qp, but doesn't need actual
27// encoded data. So use some other type to represent that.
28class EncodedImage;
29
Evan Shrubsole09da10e2022-10-14 14:38:3130struct EncoderImplementation {
31 const std::string& name;
32 bool is_hardware_accelerated;
33};
34
Niels Möller213618e2018-07-24 07:29:5835// Broken out into a base class, with public inheritance below, only to ease
36// unit testing of the internal class OveruseFrameDetector.
37class CpuOveruseMetricsObserver {
38 public:
39 virtual ~CpuOveruseMetricsObserver() = default;
40 virtual void OnEncodedFrameTimeMeasured(int encode_duration_ms,
41 int encode_usage_percent) = 0;
42};
43
44class VideoStreamEncoderObserver : public CpuOveruseMetricsObserver {
45 public:
Evan Shrubsoledff79252020-04-16 09:34:3246 struct AdaptationSettings {
47 AdaptationSettings()
48 : resolution_scaling_enabled(false), framerate_scaling_enabled(false) {}
49
50 AdaptationSettings(bool resolution_scaling_enabled,
51 bool framerate_scaling_enabled)
52 : resolution_scaling_enabled(resolution_scaling_enabled),
53 framerate_scaling_enabled(framerate_scaling_enabled) {}
54
55 bool resolution_scaling_enabled;
56 bool framerate_scaling_enabled;
57 };
58
Niels Möller213618e2018-07-24 07:29:5859 enum class DropReason {
60 kSource,
Markus Handell254e2302023-11-23 12:40:4961 kBadTimestamp,
Niels Möller213618e2018-07-24 07:29:5862 kEncoderQueue,
63 kEncoder,
Ying Wang9b881ab2020-02-07 13:29:3264 kMediaOptimization,
65 kCongestionWindow
Niels Möller213618e2018-07-24 07:29:5866 };
67
Mirko Bonadei8fdcac32018-08-28 14:30:1868 ~VideoStreamEncoderObserver() override = default;
Niels Möller213618e2018-07-24 07:29:5869
70 virtual void OnIncomingFrame(int width, int height) = 0;
71
Niels Möller6939f632022-07-05 06:55:1972 // TODO(bugs.webrtc.org/8504): Merge into one callback per encoded frame.
Niels Möller213618e2018-07-24 07:29:5873 using CpuOveruseMetricsObserver::OnEncodedFrameTimeMeasured;
74 virtual void OnSendEncodedImage(const EncodedImage& encoded_image,
75 const CodecSpecificInfo* codec_info) = 0;
76
Erik Språnge2fd86a72018-10-24 09:32:3977 virtual void OnEncoderImplementationChanged(
Evan Shrubsole09da10e2022-10-14 14:38:3178 EncoderImplementation implementation) = 0;
Erik Språnge2fd86a72018-10-24 09:32:3979
Niels Möller213618e2018-07-24 07:29:5880 virtual void OnFrameDropped(DropReason reason) = 0;
81
82 // Used to indicate change in content type, which may require a change in
83 // how stats are collected and set the configured preferred media bitrate.
84 virtual void OnEncoderReconfigured(
85 const VideoEncoderConfig& encoder_config,
86 const std::vector<VideoStream>& streams) = 0;
87
Evan Shrubsoledff79252020-04-16 09:34:3288 virtual void OnAdaptationChanged(
Evan Shrubsolece0a11d2020-04-16 09:36:5589 VideoAdaptationReason reason,
Evan Shrubsoledff79252020-04-16 09:34:3290 const VideoAdaptationCounters& cpu_steps,
91 const VideoAdaptationCounters& quality_steps) = 0;
92 virtual void ClearAdaptationStats() = 0;
93
94 virtual void UpdateAdaptationSettings(
95 AdaptationSettings cpu_settings,
96 AdaptationSettings quality_settings) = 0;
Niels Möller213618e2018-07-24 07:29:5897 virtual void OnMinPixelLimitReached() = 0;
98 virtual void OnInitialQualityResolutionAdaptDown() = 0;
99
100 virtual void OnSuspendChange(bool is_suspended) = 0;
101
Evan Shrubsolecc62b162019-09-09 09:26:45102 virtual void OnBitrateAllocationUpdated(
103 const VideoCodec& codec,
104 const VideoBitrateAllocation& allocation) {}
105
Ilya Nikolaevskiyeac08bf2020-03-10 09:50:26106 // Informes observer if an internal encoder scaler has reduced video
Artem Titov0e61fdd2021-07-25 19:50:14107 // resolution or not. `is_scaled` is a flag indicating if the video is scaled
Ilya Nikolaevskiyeac08bf2020-03-10 09:50:26108 // down.
109 virtual void OnEncoderInternalScalerUpdate(bool is_scaled) {}
110
Niels Möller6939f632022-07-05 06:55:19111 // TODO(bugs.webrtc.org/14246): VideoStreamEncoder wants to query the stats,
112 // which makes this not a pure observer. GetInputFrameRate is needed for the
113 // cpu adaptation, so can be deleted if that responsibility is moved out to a
114 // VideoStreamAdaptor class.
Niels Möller213618e2018-07-24 07:29:58115 virtual int GetInputFrameRate() const = 0;
116};
117
118} // namespace webrtc
Jonas Oreland6c2dae22022-09-29 08:28:24119
120#endif // VIDEO_VIDEO_STREAM_ENCODER_OBSERVER_H_